:root {
  --navy-950: #070F1A;
  --navy-900: #0B1B2B;
  --navy-800: #102438;
  --navy-700: #1A3147;
  --teal:     #3DD9C7;
  --teal-soft:#7CE8DB;
  --red:      #FF6B6B;
  --green:    #2EE6A6;
  --hairline: rgba(255,255,255,0.10);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  background: var(--navy-900); color: #fff;
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow: hidden;
}
button {
  font: inherit; color: inherit;
  border: 0; background: transparent; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Small corner progress indicator — dashed-border "box" with a teal
   fill that grows as the 4 ONNX models stream in. No labels.
   Position: top-right of the viewport, offset from the flip-cam
   button. Fades when the preload completes. */
/* Status pill at the top of the viewport — explains what the
   system is doing while models download. Visible only when there's
   a real network fetch in flight. Compact text label + mini bar. */
.preload-bar {
  position: fixed;
  /* Below the brand-bar (logo at top:14, ~28 px tall, 14 padding) so
     the pill doesn't visually collide with the logo on narrow
     screens. */
  top: 60px; left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  pointer-events: none;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px 10px;
  /* Wrap on narrow screens: the label takes the first row, the track +
     percentage drop to a second row INSIDE the pill. Fixes the mobile
     overflow where a long label pushed the bar out past the capsule's
     right edge (first iPhone test, 2026-07-26). Desktop stays one row. */
  flex-wrap: wrap;
  padding: 8px 16px;
  border-radius: 18px;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.12);
  font-size: 12.5px; font-weight: 500; color: #fff;
  max-width: calc(100vw - 28px);
  transition: opacity 0.6s ease 0.4s;
}
.preload-label {
  white-space: nowrap;
  letter-spacing: 0.01em;
  /* If even the label alone is wider than the pill, truncate rather
     than overflow the capsule. */
  max-width: calc(100vw - 60px);
  overflow: hidden;
  text-overflow: ellipsis;
}
.preload-track {
  width: 70px; height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,0.16);
  overflow: hidden;
  flex: 0 0 auto;
}
.preload-fill {
  height: 100%;
  width: 0%;
  background: var(--teal);
  border-radius: 2px;
  transition: width 0.3s ease;
  box-shadow: 0 0 6px rgba(61,217,199,0.55);
}
.preload-pct {
  font-family: ui-monospace, 'JetBrains Mono', SFMono-Regular, monospace;
  font-size: 11.5px;
  color: rgba(255,255,255,0.7);
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: right;
}
.preload-bar.done   { opacity: 0; }
.preload-bar.hidden { display: none; }

/* Offline-state message + retry layout, reusing #screen-error. */
.error-message {
  max-width: 360px;
  margin: 0 auto;
  line-height: 1.5;
  color: rgba(255,255,255,0.85);
  font-size: 14px;
}

/* Single full-screen stage; one of three screens visible at a time. */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.screen { display: none; flex: 1; flex-direction: column; min-height: 0; }
.screen.active { display: flex; }

/* ---------- Brand bar (small, top) ---------- */
.brand-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 18px; flex: 0 0 auto;
}
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: rgba(61,217,199,0.15); border: 1px solid rgba(61,217,199,0.4);
  display: inline-flex; align-items: center; justify-content: center;
}
.brand-mark::after {
  content: ''; width: 8px; height: 8px; border-radius: 2px;
  background: var(--teal); box-shadow: 0 0 10px var(--teal);
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.brand-link {
  display: inline-flex; align-items: center; gap: 8px;
  color: inherit; text-decoration: none; cursor: pointer;
}

/* Diagnostic toggle — small button at the top-right of the scan
   screen's brand bar. Tap to flip body.diag-mode (which reveals
   the telemetry ribbon + models grid). Persisted in localStorage.
   Dark backdrop + blur so it stays readable on light camera input
   (same treatment as .hint-pill / .flip-cam). */
.diag-toggle {
  margin-left: auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; font-weight: 600; letter-spacing: 0.5px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.diag-toggle:hover { background: rgba(0,0,0,0.7); border-color: rgba(255,255,255,0.32); }
body.diag-mode .diag-toggle {
  background: rgba(61,217,199,0.85);
  color: var(--navy-900);
  border-color: var(--teal);
}
/* Make the scan-screen brand-bar full-width so the toggle pins to
   the right edge regardless of logo width. */
#screen-scan .brand-bar { right: 0; }

/* ---------- INIT screen (start scanning) ---------- */
#screen-init { justify-content: center; align-items: center; padding: 32px; text-align: center; }
#screen-init h1 {
  font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 12px;
}
#screen-init p { color: rgba(255,255,255,0.65); max-width: 360px; margin: 0 0 28px; }
.btn-primary {
  background: var(--teal); color: #06121E; font-weight: 600;
  padding: 14px 28px; border-radius: 10px; font-size: 16px;
  box-shadow: 0 12px 32px -10px rgba(61,217,199,0.55);
  transition: transform 0.15s ease, background 0.15s ease;
}
.btn-primary:active { transform: translateY(1px); background: var(--teal-soft); }

/* Consent checkbox for "share captures to Azure". Off by default; gates
   the /api/captures upload from scan-app.js. Spec: this is the user's
   only meaningful control on the init screen. */
.consent-row {
  margin: 22px auto 0;
  display: flex; align-items: center; gap: 10px;
  max-width: 360px;
  cursor: pointer;
  user-select: none;
}
.consent-row input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--teal);
  flex-shrink: 0;
  cursor: pointer;
}
.consent-label-text {
  font-size: 14px; color: rgba(255,255,255,0.88); text-align: left;
}
.consent-help {
  margin: 8px auto 0 !important;
  max-width: 360px; text-align: left;
  font-size: 12px; color: rgba(255,255,255,0.5); line-height: 1.5;
}

.trust-row {
  margin-top: 22px;
  display: flex; gap: 14px; flex-wrap: wrap; justify-content: center;
  font-size: 12px; color: rgba(255,255,255,0.55);
}
.trust-row span { display: inline-flex; align-items: center; gap: 6px; }
.trust-row span::before {
  content: ''; width: 5px; height: 5px; border-radius: 999px; background: var(--teal);
  box-shadow: 0 0 6px var(--teal);
}

/* ---------- SCAN screen ---------- */
#screen-scan { position: relative; }
/* Proof layout (specs/mrz-scan-cache-strategy.md / pipeline-transparency
   brief): viewfinder takes top 60 % of the screen, proof panel takes
   the remaining 40 % showing per-stage status + timing. */
.viewfinder {
  position: relative; flex: 0 0 60%;
  background: #000; overflow: hidden;
}
.proof-panel {
  flex: 1 1 40%;
  background: var(--navy-900);
  border-top: 1px solid var(--hairline);
  padding: 14px 16px 22px;
  overflow: hidden;
  display: flex; flex-direction: column; gap: 8px;
  min-height: 0;
}
.proof-progress {
  display: flex; gap: 4px;
  margin-bottom: 4px;
}
.proof-progress > span {
  flex: 1; height: 3px; border-radius: 2px;
  background: rgba(255,255,255,0.08);
  transition: background 0.15s;
}
.proof-progress > span.running {
  background: rgba(61,217,199,0.45);
}
.proof-progress > span.ok   { background: var(--teal); }
.proof-progress > span.fail { background: var(--red); }

.stage-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 9px 12px; border-radius: 12px;
  background: rgba(255,255,255,0.025);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05);
  transition: background 0.2s, box-shadow 0.2s, opacity 0.2s;
}
.stage-row.running {
  background: rgba(61,217,199,0.05);
  box-shadow: inset 0 0 0 1px rgba(61,217,199,0.22);
}
.stage-row.ok {
  background: rgba(61,217,199,0.06);
  box-shadow: inset 0 0 0 1px rgba(61,217,199,0.20);
}
.stage-row.fail {
  background: rgba(255,107,107,0.08);
  box-shadow: inset 0 0 0 1px rgba(255,107,107,0.35);
}
.stage-row.skipped { opacity: 0.45; }
.stage-icon {
  width: 22px; height: 22px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0; position: relative;
}
.stage-row.pending .stage-icon { box-shadow: inset 0 0 0 1.5px rgba(255,255,255,0.32); }
.stage-row.running .stage-icon {
  box-shadow: inset 0 0 0 2px var(--teal);
}
.stage-row.running .stage-icon::after {
  content: ''; position: absolute; inset: 0;
  border-radius: 999px;
  border: 2px solid transparent;
  border-top-color: var(--teal);
  animation: stage-spin 0.8s linear infinite;
}
@keyframes stage-spin { to { transform: rotate(360deg); } }
.stage-row.ok .stage-icon { background: var(--teal); color: var(--navy-900); }
.stage-row.ok .stage-icon::before { content: '\2713'; }
.stage-row.fail .stage-icon { background: var(--red); color: var(--navy-900); }
.stage-row.fail .stage-icon::before { content: '!'; }
.stage-body { flex: 1; min-width: 0; }
.stage-name {
  font-size: 13px; font-weight: 500; color: #fff; line-height: 1.2;
}
.stage-row.pending .stage-name { color: rgba(255,255,255,0.55); }
.stage-desc {
  font-size: 11px; line-height: 1.4; margin-top: 2px;
  color: rgba(255,255,255,0.55);
}
.stage-row.fail .stage-desc { color: rgba(255,255,255,0.85); }
.stage-ms {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px; color: rgba(255,255,255,0.45);
  letter-spacing: 0.3px; flex-shrink: 0; padding-top: 3px;
  font-variant-numeric: tabular-nums;
}

/* Per-stage thumbnails — visible only when the row has produced its
   output (running/ok/fail). Each row sizes its own canvas to match
   the aspect of its content. */
.stage-thumb {
  display: none;
  margin-top: 6px;
  border-radius: 4px;
  overflow: hidden;
  background: rgba(15,35,54,0.8);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
  width: max-content;
}
.stage-row.ok .stage-thumb,
.stage-row.fail .stage-thumb,
.stage-row.running .stage-thumb { display: block; }
.stage-thumb canvas { display: block; }
.stage-row[data-stage="align"] .stage-thumb canvas { width: 88px; height: 56px; }
.stage-row[data-stage="spot"]  .stage-thumb canvas { width: 200px; height: 30px; }

/* OCR text readout in the 'ocr' row — visible after the recognizer
   has produced some lines (whether or not checksums verified). */
.stage-ocr {
  display: none;
  margin-top: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 9px; line-height: 1.4;
  letter-spacing: 0.4px;
  color: var(--teal);
  background: rgba(15,35,54,0.8);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
  padding: 5px 7px;
  border-radius: 4px;
  white-space: pre;
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis;
}
.stage-row[data-stage="ocr"].ok   .stage-ocr,
.stage-row[data-stage="ocr"].fail .stage-ocr { display: block; }
.stage-row[data-stage="ocr"].fail .stage-ocr { color: var(--red); }

/* Allow the panel to scroll if all the thumbnails together push past
   the 40 % budget on small screens. */
.proof-panel { overflow-y: auto; }

/* Diagnostic-mode telemetry ribbon (?diag=1) — shows all six pipeline
   stages with running ms timers, overlaying the top of the camera.
   Solid dark backdrop + blur (was gradient fading to transparent —
   illegible on light camera backgrounds). */
.telemetry-ribbon {
  display: none;
  position: absolute;
  top: 56px; left: 0; right: 0;
  z-index: 3;
  padding: 10px 12px 12px;
  background: rgba(7,15,26,0.78);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255,255,255,0.08);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  pointer-events: none;
}
body.diag-mode .telemetry-ribbon { display: block; }
.telemetry-ribbon .telemetry-head {
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 6px; padding: 0 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px; color: rgba(255,255,255,0.55);
  letter-spacing: 0.5px;
}
.telemetry-ribbon .telemetry-head .pulse {
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--teal);
  box-shadow: 0 0 8px var(--teal);
  animation: telemetry-pulse 1.4s infinite;
}
@keyframes telemetry-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}
.telemetry-stages { display: flex; gap: 4px; }
.telemetry-chip {
  flex: 1; min-width: 0; height: 38px; border-radius: 7px;
  background: rgba(255,255,255,0.08);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
  padding: 5px 6px; box-sizing: border-box;
  display: flex; flex-direction: column; justify-content: space-between;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.telemetry-chip .chip-label {
  font-size: 9px; letter-spacing: 0.5px;
  color: rgba(255,255,255,0.55);
}
.telemetry-chip .chip-ms {
  font-size: 10px; color: rgba(255,255,255,0.75);
  font-variant-numeric: tabular-nums;
}
.telemetry-chip.running { background: rgba(61,217,199,0.12); box-shadow: inset 0 0 0 1px var(--teal); }
.telemetry-chip.running .chip-label,
.telemetry-chip.running .chip-ms { color: var(--teal); }
.telemetry-chip.ok      { background: rgba(61,217,199,0.16); box-shadow: inset 0 0 0 1px rgba(61,217,199,0.30); }
.telemetry-chip.ok      .chip-label,
.telemetry-chip.ok      .chip-ms { color: var(--teal); }
.telemetry-chip.fail    { background: rgba(255,107,107,0.16); box-shadow: inset 0 0 0 1px var(--red); }
.telemetry-chip.fail    .chip-label,
.telemetry-chip.fail    .chip-ms { color: var(--red); }

/* Models-cached grid in diagnostic ribbon — shows whether each of the
   4 ONNX models is sitting in the Cache API (✓) or not (·). Polled
   every few seconds while diag is on. */
.telemetry-models { margin-top: 8px; }
.telemetry-models .telemetry-head { margin-bottom: 4px; }
.models-grid { display: flex; gap: 4px; }
.model-chip {
  flex: 1; min-width: 0; height: 32px;
  padding: 4px 6px; box-sizing: border-box;
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  display: flex; flex-direction: column; justify-content: space-between;
}
.model-chip .m-label {
  font-size: 8px; letter-spacing: 0.5px;
  color: rgba(255,255,255,0.55);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.model-chip .m-state-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 10px; color: rgba(255,255,255,0.75);
  font-variant-numeric: tabular-nums;
}
.model-chip.cached {
  background: rgba(61,217,199,0.12);
  box-shadow: inset 0 0 0 1px rgba(61,217,199,0.3);
}
.model-chip.cached .m-label,
.model-chip.cached .m-state-row { color: var(--teal); }

/* Tap-to-expand on the Proof-panel thumbnails / OCR text. Visible
   cue: a faint outline ring on hover/focus + cursor: pointer. */
.stage-row .stage-thumb,
.stage-row[data-stage="ocr"] .stage-ocr {
  cursor: zoom-in;
  -webkit-tap-highlight-color: rgba(61,217,199,0.25);
}
.stage-row .stage-thumb:hover,
.stage-row[data-stage="ocr"] .stage-ocr:hover {
  box-shadow: inset 0 0 0 1px rgba(61,217,199,0.5);
}

/* Lightbox — full-screen modal on top of #screen-scan, dim
   backdrop, X to close. Tap outside content area also closes. */
.lightbox {
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(0, 0, 0, 0.86);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; flex-direction: column;
  padding: 14px 14px 26px;
  animation: lightbox-in 0.15s ease-out;
}
.lightbox.hidden { display: none; }
@keyframes lightbox-in {
  from { opacity: 0; transform: scale(0.98); }
  to   { opacity: 1; transform: scale(1);    }
}
.lightbox-head {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 4px 14px;
  color: #fff;
}
.lightbox-title {
  font-size: 14px; font-weight: 600; letter-spacing: 0.01em;
}
.lightbox-sub {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px; color: rgba(255,255,255,0.55);
  margin-left: auto;
}
.lightbox-close {
  width: 36px; height: 36px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.06);
  color: #fff; font-size: 18px; line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.lightbox-body {
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: auto;
}
.lightbox-body canvas {
  display: block;
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  background: #0F2336;
  border-radius: 6px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06);
  image-rendering: pixelated;   /* keep crisp at large size */
}
.lightbox-body pre {
  width: 100%; max-width: 720px;
  margin: 0; padding: 14px 16px;
  background: #0F2336;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px; line-height: 1.5;
  color: var(--teal);
  white-space: pre-wrap; word-break: break-all;
  user-select: text; -webkit-user-select: text;
}
.lightbox-body pre.fail { color: var(--red); }
.viewfinder video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.viewfinder canvas.overlay {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
/* Selfie-style mirror when the front camera is active. Applied to the
   video AND the quad-overlay canvas (so the live quad still tracks
   the visible passport). NOT applied to scanline / hint / flip
   button — they stay correctly oriented. captureFrame(video) reads
   raw video pixels via drawImage, NOT affected by CSS transforms,
   so the ML pipeline still gets the un-mirrored bytes the OCR needs. */
.viewfinder.front-cam video,
.viewfinder.front-cam canvas.overlay {
  transform: scaleX(-1);
}
/* Full-screen scan line — same animation as the landing-page hero
   passport mockup. Top-to-bottom sweep, ~3 sec loop, teal gradient.
   Decorative-only; the ML detection runs continuously regardless.
   Hidden during the capture/processing phase via .viewfinder.busy
   so the user isn't distracted from the result. */
.scanline {
  position: absolute;
  left: 0; right: 0;
  height: 3px;
  pointer-events: none;
  background: linear-gradient(180deg,
    transparent 0%,
    rgba(61,217,199,0.85) 50%,
    transparent 100%);
  box-shadow: 0 0 18px rgba(61,217,199,0.6);
  animation: scanline-sweep 3.2s ease-in-out infinite;
}
@keyframes scanline-sweep {
  0%   { transform: translateY(0%);    opacity: 0; }
  8%   { opacity: 1; }
  92%  { opacity: 1; }
  100% { transform: translateY(100vh); opacity: 0; }
}
.viewfinder.busy .scanline { display: none; }

/* Hint text near bottom of viewfinder */
.hint-row {
  position: absolute; left: 0; right: 0; bottom: 28px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none;
  transition: opacity 0.18s ease;
}
/* When the in-camera step card is showing, the hint pill at the
   bottom would say the same thing twice ("Reading the passport").
   Fade it out for the duration of the capture so the step card is
   the single source of in-camera status. Returns when the card
   fades on success/fail. */
.viewfinder:has(.step-card:not(.hidden)) .hint-row {
  opacity: 0;
}
.hint-pill {
  background: rgba(0,0,0,0.55); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding: 10px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 500; color: #fff;
  border: 1px solid var(--hairline);
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.hint-pill.preparing { background: rgba(0,0,0,0.65); }
/* Engine cold-start progress (spec: mrz-scan-gpu-on-demand.md). */
.engine-bar { width: 180px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: rgba(255,255,255,0.18); overflow: hidden; }
.engine-bar[hidden] { display: none; }
.engine-fill { height: 100%; width: 0; background: var(--green); transition: width 0.25s linear; }
.hint-pill.ready { background: rgba(46,230,166,0.20); color: var(--green); border-color: rgba(46,230,166,0.45); }

/* Step card — full-screen progress overlay during a capture.
   Spec: specs/mrz-scan-camera-ux-polish.md. Per Almir's feedback
   2026-05-13 ("this should be the main focus, zoom across the
   complete screen"), the card now fills most of the viewfinder
   during the reading-the-passport / reading-the-MRZ phases. The
   live camera dims behind so the user knows it's still alive but
   the active thumbnail dominates. */
.step-card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(82vw, 560px);
  background: rgba(0,0,0,0.82);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid var(--teal);
  box-shadow: 0 24px 60px -16px rgba(0,0,0,0.7), 0 0 36px -8px rgba(61,217,199,0.35);
  border-radius: 18px;
  padding: 18px 18px 16px;
  z-index: 3;
  pointer-events: auto;
  text-align: center;
  opacity: 1;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.step-card.hidden {
  opacity: 0;
  transform: translate(-50%, calc(-50% + 8px));
  pointer-events: none;
}
.step-card-thumb {
  display: block;
  width: 100%;
  max-width: 100%;
  height: clamp(150px, 32vh, 320px);
  border-radius: 12px;
  background: #000;
  object-fit: contain;
  margin: 0 auto;
}
.step-card-label {
  display: block;
  margin-top: 14px;
  font-size: 16px; font-weight: 600;
  color: #fff;
  letter-spacing: 0.01em;
  line-height: 1.3;
}
.step-card-mark {
  position: absolute;
  top: -14px; right: -14px;
  width: 36px; height: 36px;
  border-radius: 999px;
  font-size: 20px; font-weight: 700;
  display: none;
  align-items: center; justify-content: center;
  box-shadow: 0 6px 16px -2px rgba(0,0,0,0.6);
}
.step-card.ok .step-card-mark {
  display: flex;
  background: var(--green); color: #06121E;
}
.step-card.ok .step-card-mark::before { content: '✓'; }
.step-card.fail .step-card-mark {
  display: flex;
  background: #ff6b6b; color: #fff;
}
.step-card.fail .step-card-mark::before { content: '✗'; }
/* When the step card is active, dim the live camera behind it so the
   thumbnail is unambiguously the focus. Re-engaged on .hidden so live
   camera returns to full opacity instantly when the card vanishes. */
.viewfinder:has(.step-card:not(.hidden)) > video {
  opacity: 0.28;
  transition: opacity 0.22s ease;
}
.viewfinder > video {
  transition: opacity 0.22s ease;
}
@media (prefers-reduced-motion: reduce) {
  .step-card { transition: opacity 0.18s linear; transform: translate(-50%, -50%); }
  .step-card.hidden { transform: translate(-50%, -50%); }
  .viewfinder:has(.step-card:not(.hidden)) > video,
  .viewfinder > video { transition: opacity 0.18s linear; }
}
@media (max-height: 560px) {
  /* Short viewports (landscape phone) — keep the thumbnail tall
     enough to read but trim the surrounding padding. */
  .step-card { padding: 12px 12px 10px; width: min(74vw, 440px); }
  .step-card-thumb { height: clamp(110px, 38vh, 220px); }
  .step-card-label { font-size: 14px; margin-top: 10px; }
}

/* Camera-flip button — only shown when ≥2 video inputs exist (i.e. on
   phones with both front + back cameras; hidden on most laptops). Sits
   in the top-right corner of the viewfinder. .processing.on covers it
   during the capture phase via stacking order (button declared before
   processing in DOM). */
.flip-cam {
  /* Bottom-right of the viewfinder, not the top — top-right is now
     the </> diagnostic toggle in the brand bar. */
  position: absolute; bottom: 14px; right: 14px;
  width: 44px; height: 44px; border-radius: 999px;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.flip-cam:hover  { background: rgba(0,0,0,0.6); border-color: rgba(255,255,255,0.32); }
.flip-cam:active { transform: scale(0.92); background: rgba(61,217,199,0.25); border-color: rgba(61,217,199,0.6); }
.flip-cam:disabled { opacity: 0.5; pointer-events: none; }
.flip-cam[hidden] { display: none; }
.flip-cam svg { width: 22px; height: 22px; }

/* Capture flash overlay */
.flash {
  position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none;
  transition: opacity 0.06s linear;
}
.flash.on { opacity: 0.9; }

/* Hint-pill colour for "in progress" / "step succeeded" states.
   Replaces the old centered-blur processing overlay (per Almir's
   feedback: "I find it much better than this blurry overlay").
   Visually similar to the .ready variant but neutral white-ish so
   it reads as "system status" rather than "you're good to go". */
.hint-pill.processing {
  background: rgba(7,15,26,0.85);
  color: #fff;
  border-color: rgba(255,255,255,0.16);
}

/* ---------- RESULT screen ---------- */
#screen-result {
  padding: 28px 22px 36px; justify-content: center; align-items: stretch;
}
.result-card {
  max-width: 480px; margin: 0 auto;
  background: var(--navy-800); border: 1px solid var(--hairline);
  border-radius: 16px; padding: 24px 22px;
}
.verdict {
  display: flex; align-items: center; gap: 10px;
  font-size: 15px; font-weight: 600; margin-bottom: 18px;
}
.verdict.ok { color: var(--green); }
.verdict.fail { color: var(--red); }
.verdict-icon {
  width: 24px; height: 24px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
}
.verdict.ok .verdict-icon { background: rgba(46,230,166,0.18); }
.verdict.fail .verdict-icon { background: rgba(255,107,107,0.18); }

dl.fields { margin: 0 0 22px; padding: 0; display: grid; grid-template-columns: 90px 1fr; gap: 10px 16px; }
dl.fields dt { color: rgba(255,255,255,0.5); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; align-self: center; }
dl.fields dd { margin: 0; font-family: ui-monospace, 'JetBrains Mono', SFMono-Regular, monospace; font-size: 15px; letter-spacing: 0.04em; word-break: break-all; }

.fail-message {
  margin: 0 0 22px;
  color: rgba(255,255,255,0.75); font-size: 15px; line-height: 1.5;
}

.actions { display: flex; gap: 12px; flex-direction: column; }
.btn-secondary {
  background: rgba(255,255,255,0.04); color: #fff;
  padding: 13px 22px; border-radius: 10px; font-weight: 600;
  border: 1px solid var(--hairline);
}
.btn-secondary:active { background: rgba(255,255,255,0.08); }

/* "View past scans →" link on the result card, below the primary
   Scan-another / Try-again button. */
.btn-secondary-link {
  text-align: center;
  padding: 11px 22px;
  border-radius: 10px;
  background: rgba(61,217,199,0.08);
  border: 1px solid rgba(61,217,199,0.30);
  color: var(--teal);
  text-decoration: none;
  font-size: 14px; font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}
.btn-secondary-link:hover {
  background: rgba(61,217,199,0.18);
  border-color: rgba(61,217,199,0.55);
}

/* ---------- ERROR screen ---------- */
#screen-error { padding: 32px; justify-content: center; align-items: center; text-align: center; }
#screen-error h2 { color: var(--red); margin: 0 0 10px; }
#screen-error pre {
  max-width: 420px; max-height: 200px; overflow: auto;
  padding: 12px; background: rgba(0,0,0,0.45); border: 1px solid var(--hairline);
  border-radius: 8px; font-size: 12px; text-align: left; color: rgba(255,255,255,0.75);
  white-space: pre-wrap;
}
/* ── Server timing breakdown ───────────────────────────────────────────────
   Per-stage cost as measured by the ENGINE, shown under the Proof rows once
   a scan returns. The rows above are browser wall-clock and fold network into
   whichever step was running; these are the numbers that show which stage is
   actually expensive. */
.server-breakdown {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.sb-head {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.55;
  margin-bottom: 8px;
}
.sb-row {
  display: grid;
  grid-template-columns: 108px 1fr 62px;
  align-items: center;
  gap: 10px;
  padding: 3px 0;
  font-size: 12px;
}
.sb-label { opacity: 0.75; }
.sb-bar {
  height: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}
.sb-bar i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: #2EE6A6;
}
.sb-ms {
  text-align: right;
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}
.sb-total {
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-weight: 600;
}
.sb-total .sb-label { opacity: 0.9; }
.sb-waited .sb-label { opacity: 1; }
.sb-net {
  font-weight: 400;
  opacity: 0.55;
  font-size: 11px;
}

/* Specimen button under „Start scanning" (no passport at hand). */
#btn-specimen { margin-top: 14px; cursor: pointer; font: inherit; font-size: 14px; }
#btn-specimen:disabled { opacity: .7; cursor: wait; }
