:root {
  color-scheme: dark;
  --bg: #071015;
  --bg-2: #0d171d;
  --panel: rgba(12, 19, 25, 0.84);
  --panel-strong: rgba(8, 14, 19, 0.96);
  --line: rgba(122, 185, 207, 0.16);
  --line-strong: rgba(122, 185, 207, 0.28);
  --text: #e8f4fb;
  --muted: #8aa4b3;
  --cyan: #61d2ff;
  --cyan-soft: rgba(97, 210, 255, 0.16);
  --amber: #f7be55;
  --green: #7ee787;
  --red: #ff8585;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 11px;
  --font-head: "Bahnschrift", "Aptos Display", "Segoe UI", sans-serif;
  --font-body: "Segoe UI", "Aptos", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, rgba(97, 210, 255, 0.08), transparent 24%),
    radial-gradient(circle at 85% 0%, rgba(247, 190, 85, 0.06), transparent 22%),
    linear-gradient(180deg, #050a0e 0%, var(--bg) 50%, #04080c 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 36px 36px;
  opacity: 0.3;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.72), transparent 92%);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100vw - 20px));
  margin: 10px auto 18px;
  min-height: calc(100vh - 28px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(13, 20, 27, 0.95), rgba(8, 14, 19, 0.88));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: none;
}

.brand-mark svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.ring.outer {
  fill: none;
  stroke: rgba(97, 210, 255, 0.8);
  stroke-width: 2.4;
  stroke-dasharray: 1.5 3.4;
}

.ring.middle {
  fill: none;
  stroke: rgba(97, 210, 255, 0.55);
  stroke-width: 2;
}

.ring.inner {
  fill: none;
  stroke: rgba(247, 190, 85, 0.96);
  stroke-width: 2;
}

.dot {
  fill: var(--text);
}

.brand-copy {
  min-width: 0;
}

.brand-title {
  font-family: var(--font-head);
  font-size: 1.42rem;
  line-height: 1;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.brand-subtitle {
  margin-top: 4px;
  font-size: 0.84rem;
  color: var(--muted);
}

.topbar-badge,
.result-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(97, 210, 255, 0.26);
  background: rgba(97, 210, 255, 0.08);
  color: #cceffc;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.topbar-badge.is-live,
.result-pill.is-live {
  border-color: rgba(126, 231, 135, 0.3);
  background: rgba(126, 231, 135, 0.08);
  color: #cdfad2;
}

.topbar-badge.is-warn,
.result-pill.is-warn {
  border-color: rgba(247, 190, 85, 0.34);
  background: rgba(247, 190, 85, 0.09);
  color: #ffe1a4;
}

.topbar-badge.is-bad,
.result-pill.is-bad {
  border-color: rgba(255, 133, 133, 0.28);
  background: rgba(255, 133, 133, 0.08);
  color: #ffc5c5;
}

.shell-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.scanner-panel,
.result-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(12, 19, 25, 0.92), rgba(8, 13, 18, 0.88));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.scanner-panel {
  padding: 14px;
}

.result-panel {
  padding: 14px;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head.compact {
  margin-bottom: 10px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--cyan);
  font-size: 0.88rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: var(--font-head);
  letter-spacing: 0.01em;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 2.45rem);
  line-height: 1;
}

h2 {
  font-size: clamp(1.25rem, 2.6vw, 1.7rem);
  line-height: 1.08;
}

.header-note {
  color: var(--muted);
  font-size: 0.88rem;
  text-align: right;
  white-space: nowrap;
}

.stage {
  position: relative;
  min-height: min(72vh, 760px);
  border: 1px solid rgba(122, 185, 207, 0.18);
  border-radius: 24px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 40%, rgba(97, 210, 255, 0.1), transparent 36%),
    linear-gradient(180deg, rgba(7, 13, 17, 0.96), rgba(11, 17, 22, 0.88));
}

#previewCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.idle-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  pointer-events: none;
}

.idle-state[hidden] {
  display: none;
}

.idle-state h2 {
  margin-bottom: 8px;
  font-size: clamp(1.35rem, 4vw, 2rem);
}

.idle-state p {
  margin: 0;
  max-width: 28rem;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.5;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.action-btn,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid rgba(122, 185, 207, 0.18);
  background: linear-gradient(180deg, rgba(16, 25, 33, 0.96), rgba(10, 17, 23, 0.94));
  color: var(--text);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.14);
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease,
    opacity 150ms ease;
}

.action-btn:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(97, 210, 255, 0.42);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.2);
}

.action-btn.primary {
  border-color: rgba(97, 210, 255, 0.5);
  background: linear-gradient(180deg, rgba(20, 47, 62, 0.96), rgba(11, 27, 36, 0.98));
  color: #d8f6ff;
}

.ghost-btn {
  background: linear-gradient(180deg, rgba(12, 18, 24, 0.95), rgba(8, 13, 18, 0.92));
}

.ghost-btn.small {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 12px;
}

.result-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.details-btn {
  display: none;
}

.icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.icon svg {
  width: 100%;
  height: 100%;
}

.hint-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.hint-row span:first-child {
  color: var(--cyan);
  font-weight: 650;
}

.result-card {
  display: grid;
  gap: 14px;
}

.result-details {
  display: grid;
  gap: 14px;
}

.result-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.result-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.ups-summary {
  padding: 15px;
  border: 1px solid rgba(97, 210, 255, 0.3);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(16, 41, 52, 0.92), rgba(8, 20, 27, 0.94));
}

.ups-summary[hidden] {
  display: none;
}

.ups-summary-head {
  display: grid;
  gap: 4px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(122, 185, 207, 0.16);
}

.ups-summary span,
.ups-fields span {
  color: var(--muted);
  font-size: 0.78rem;
}

.ups-summary-head strong {
  color: #f2fbff;
  font-family: "Consolas", "SFMono-Regular", "Cascadia Mono", monospace;
  font-size: clamp(1rem, 3.4vw, 1.24rem);
  overflow-wrap: anywhere;
}

.ups-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px 14px;
  padding-top: 12px;
}

.ups-fields div {
  display: grid;
  gap: 3px;
}

.ups-fields strong {
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.ups-detail-section {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid rgba(122, 185, 207, 0.16);
}

.ups-detail-section h3 {
  margin: 0;
  color: #d8f6ff;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ups-detail-fields {
  padding-top: 10px;
}

.ups-detail-fields .wide {
  grid-column: 1 / -1;
}

.result-text {
  margin: 0;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid rgba(122, 185, 207, 0.16);
  background: rgba(6, 11, 15, 0.72);
  color: #f2fbff;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Consolas", "SFMono-Regular", "Cascadia Mono", monospace;
  font-size: 0.94rem;
  line-height: 1.6;
  min-height: 150px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  padding: 12px 13px;
  border-radius: 16px;
  border: 1px solid rgba(122, 185, 207, 0.14);
  background: rgba(10, 15, 20, 0.72);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.metric strong {
  display: block;
  font-size: 0.98rem;
  font-weight: 650;
  line-height: 1.25;
}

.raw-bytes {
  border: 1px solid rgba(122, 185, 207, 0.14);
  border-radius: 16px;
  background: rgba(10, 15, 20, 0.72);
  padding: 12px 13px;
}

.raw-bytes summary {
  cursor: pointer;
  color: var(--cyan);
  font-weight: 650;
  list-style: none;
}

.raw-bytes summary::-webkit-details-marker {
  display: none;
}

.raw-bytes pre {
  margin: 10px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Consolas", "SFMono-Regular", "Cascadia Mono", monospace;
  font-size: 0.88rem;
  line-height: 1.55;
  color: #dbeff8;
}

.result-note {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

@media (min-width: 920px) {
  .shell-grid {
    grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.82fr);
    align-items: start;
  }

  .scanner-panel,
  .result-panel {
    position: sticky;
    top: 10px;
  }

  .scanner-panel {
    padding: 16px;
  }

  .result-panel {
    padding: 16px;
  }
}

@media (max-width: 919px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-badge {
    align-self: flex-start;
  }

  .header-note {
    text-align: left;
  }
}

@media (max-width: 700px) {
  body {
    --mobile-result-height: 140px;
  }

  body.is-scan-complete {
    --mobile-result-height: min(220px, 34svh);
  }

  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app-shell {
    width: 100%;
    height: 100svh;
    min-height: 100svh;
    margin: 0;
  }

  .topbar {
    position: fixed;
    z-index: 50;
    inset: calc(8px + env(safe-area-inset-top)) 8px auto;
    min-height: 56px;
    margin: 0;
    padding: 8px 10px;
    flex-direction: row;
    align-items: center;
    border-radius: 18px;
    background: rgba(7, 13, 18, 0.78);
    box-shadow: 0 12px 38px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(22px) saturate(1.25);
  }

  .brand {
    gap: 8px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand-title {
    font-size: 1.05rem;
  }

  .brand-subtitle {
    display: none;
  }

  .topbar-badge {
    min-height: 28px;
    padding: 0 10px;
    align-self: center;
    font-size: 0.74rem;
  }

  .shell-grid,
  .scanner-panel {
    display: block;
    width: 100%;
    height: 100%;
  }

  .scanner-panel {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: #070d12;
    box-shadow: none;
  }

  .scanner-panel > .panel-head {
    position: fixed;
    z-index: 35;
    top: calc(72px + env(safe-area-inset-top));
    left: 12px;
    right: 12px;
    margin: 0;
    pointer-events: none;
  }

  .scanner-panel > .panel-head > div:first-child {
    display: none;
  }

  .header-note {
    max-width: min(72vw, 28rem);
    padding: 7px 10px;
    overflow: hidden;
    border: 1px solid rgba(122, 185, 207, 0.2);
    border-radius: 999px;
    background: rgba(7, 13, 18, 0.68);
    color: rgba(232, 244, 251, 0.82);
    text-align: left;
    text-overflow: ellipsis;
    backdrop-filter: blur(14px);
  }

  .stage {
    position: fixed;
    inset: 0;
    min-height: 0;
    border: 0;
    border-radius: 0;
    background: #070d12;
  }

  .idle-state {
    padding: 92px 24px 250px;
  }

  .idle-state h2 {
    font-size: 1.35rem;
  }

  .idle-state p {
    max-width: 20rem;
    font-size: 0.88rem;
  }

  .action-row {
    position: fixed;
    z-index: 46;
    left: 10px;
    right: 10px;
    bottom: calc(var(--mobile-result-height) + 16px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin: 0;
    padding: 7px;
    border: 1px solid rgba(122, 185, 207, 0.2);
    border-radius: 20px;
    background: rgba(7, 13, 18, 0.72);
    box-shadow: 0 16px 42px rgba(0, 0, 0, 0.34);
    backdrop-filter: blur(20px) saturate(1.2);
    transition:
      opacity 180ms ease,
      transform 180ms ease,
      bottom 220ms ease;
  }

  body.is-result-expanded .action-row {
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
  }

  .action-btn,
  .ghost-btn {
    min-height: 52px;
  }

  .action-row .action-btn,
  .action-row .ghost-btn {
    flex-direction: column;
    gap: 3px;
    padding: 4px;
    border-radius: 14px;
    font-size: 0.72rem;
  }

  .action-row .icon {
    width: 20px;
    height: 20px;
  }

  body.is-camera-active #cameraBtn {
    border-color: rgba(247, 190, 85, 0.62);
    background: rgba(92, 55, 13, 0.72);
    color: #ffe1a4;
  }

  .hint-row {
    display: none;
  }

  .result-panel {
    position: fixed;
    z-index: 45;
    left: 8px;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    height: var(--mobile-result-height);
    padding: 10px;
    overflow: hidden;
    border-radius: 22px;
    background: rgba(8, 14, 19, 0.9);
    box-shadow: 0 18px 54px rgba(0, 0, 0, 0.46);
    backdrop-filter: blur(24px) saturate(1.25);
    transition:
      height 220ms ease,
      inset 220ms ease,
      border-radius 220ms ease;
  }

  .result-panel.is-expanded {
    top: calc(72px + env(safe-area-inset-top));
    height: auto;
    max-height: none;
    overflow-y: auto;
    border-radius: 24px;
  }

  .result-panel .panel-head.compact {
    align-items: center;
    margin-bottom: 7px;
  }

  .result-panel .panel-head.compact h2 {
    display: none;
  }

  .result-panel .eyebrow {
    margin: 0;
    font-size: 0.78rem;
  }

  .result-actions {
    gap: 6px;
  }

  .details-btn {
    display: inline-flex;
  }

  body.is-scan-complete:not(.is-result-expanded) .details-btn {
    border-color: rgba(97, 210, 255, 0.56);
    background: rgba(20, 47, 62, 0.92);
    color: #d8f6ff;
  }

  .ghost-btn.small {
    min-height: 30px;
    padding: 0 10px;
    border-radius: 10px;
    font-size: 0.76rem;
  }

  .result-card {
    gap: 7px;
  }

  .result-pill {
    min-height: 26px;
    padding: 0 10px;
    font-size: 0.74rem;
  }

  .result-meta {
    font-size: 0.76rem;
  }

  .result-text {
    min-height: 0;
    max-height: 44px;
    padding: 8px 10px;
    overflow: auto;
    border-radius: 12px;
    font-size: 0.8rem;
    line-height: 1.35;
  }

  .result-details {
    display: none;
  }

  .result-panel.is-expanded .panel-head.compact h2 {
    display: block;
    margin-top: 4px;
    font-size: 1.35rem;
  }

  .result-panel.is-expanded .result-text {
    max-height: none;
    padding: 14px;
    overflow: visible;
    font-size: 0.9rem;
  }

  .result-panel.is-expanded .result-details {
    display: grid;
    gap: 10px;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric {
    padding: 10px 11px;
    border-radius: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition-duration: 0ms !important;
  }
}
