/* ──────────────────────────────────────────────────────────────────────────
 * ex-count.css — styles for /ex-count ONLY.
 *
 * ISOLATED: this file is loaded by frontend/ex-count.html and nothing else. It
 * defines no global element rules that could leak into the Labbie application,
 * imports no shared stylesheet, and every class is `exc-` prefixed.
 *
 * Design language: warm cream paper, black type, one red, monospace technical
 * labels, one condensed display face. Mobile first — every size below is tuned
 * for a ~360–430 px phone and only relaxes upward.
 * ────────────────────────────────────────────────────────────────────────── */

/* Self-hosted (SIL OFL 1.1 — see fonts/OFL.txt). No Google Fonts, no CDN, no
   external request of any kind from this page. */
@font-face {
  font-family: 'Anton';
  src: url('/assets/ex-count/fonts/anton-latin.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F, U+2122, U+2191, U+2193, U+2212;
}

:root {
  --paper:      #ece5da;
  --card:       #f7f3ec;
  --card-warm:  #f1ebe1;
  --ink:        #16130f;
  --ink-soft:   #554d43;
  --ink-mute:   #8d8478;
  --red:        #e0301e;
  --red-dark:   #c9291a;
  --line:       rgba(22, 19, 15, 0.14);
  --line-soft:  rgba(22, 19, 15, 0.08);
  --panel:      #131211;
  --panel-line: rgba(255, 255, 255, 0.09);

  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", "Courier New", monospace;
  --display: 'Anton', Impact, 'Haettenschweiler', 'Arial Narrow Bold', 'Franklin Gothic Medium', sans-serif;

  --radius: 14px;

  /* ── Background artwork ─────────────────────────────────────────────────
     TWO purpose-made images: a landscape collage for desktop and a portrait
     one for phones. They are switched by redefining --exc-bg-image inside the
     720px media query further down, so .exc-bg itself has a single rule and
     only ONE of the two is ever requested by the browser.

     `none` means that asset is not committed yet, and CSS makes no request for
     it — the page falls back to plain --paper cream with nothing in anyone's
     network log.

     TO ENABLE, per image, change the one line:
       --exc-bg-desktop: url('/assets/ex-count/background-desktop.png');
       --exc-bg-mobile:  url('/assets/ex-count/background-mobile.png');
     backend/tests/ex-count-check.js compares each declaration against the file
     on disk and fails if they disagree, so a declaration and its asset cannot
     drift apart in either direction. */
  --exc-bg-desktop: url('/assets/ex-count/background-desktop.png');
  --exc-bg-mobile:  url('/assets/ex-count/background-mobile.png');
  --exc-bg-image:   var(--exc-bg-desktop);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;          /* no horizontal scroll, ever */
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

/* ── background artwork ───────────────────────────────────────────────────
 * Sits behind everything, fixed to the viewport so it neither tiles nor
 * stretches with page height, and `cover` keeps its aspect ratio intact.
 * Explicit z-index ladder: artwork 0 → grain 1 → content 2. */
.exc-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: var(--exc-bg-image);
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}

/* A soft cream bloom over the MIDDLE only. The collage's decorative edges stay
   fully visible while the centre calms down enough for the card to read
   cleanly on top of it — no full-page veil, which would mute the artwork. */
.exc-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 62% 56% at 50% 46%,
    rgba(246, 241, 232, 0.88) 0%,
    rgba(246, 241, 232, 0.52) 46%,
    rgba(246, 241, 232, 0) 76%);
}

/* Barely-there paper grain. Fixed + non-interactive so it never affects layout. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.32;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.16'/%3E%3C/svg%3E");
}

img, svg, video, canvas { max-width: 100%; display: block; }

.exc-skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  font-size: 12px;
  z-index: 20;
}
.exc-skip:focus { left: 8px; top: 8px; }

/* ── shell ───────────────────────────────────────────────────────────── */
.exc {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding:
    calc(14px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right))
    calc(26px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
}

/* When a friend opens a shared link the report is the FIRST thing they see. */
.exc.is-shared .exc-card--report { order: -1; }

.exc-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 20px 18px 22px;
  box-shadow: 0 1px 2px rgba(22, 19, 15, 0.04), 0 10px 30px -22px rgba(22, 19, 15, 0.4);
}

/* ── technical microcopy ─────────────────────────────────────────────── */
.exc-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  font-size: 9px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.exc-meta-left  { display: flex; flex-direction: column; gap: 3px; }
.exc-meta-right { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.exc-meta-right--red { color: var(--red); font-weight: 600; }

.exc-led {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--red);
  display: inline-block;
  flex: none;
}
.exc-led--live { animation: exc-blink 1.6s steps(1, end) infinite; }
@keyframes exc-blink { 0%, 60% { opacity: 1; } 61%, 100% { opacity: 0.25; } }

/* Corner registration ticks on the scanner card. */
.exc-tick {
  position: absolute;
  width: 13px; height: 13px;
  border: 1.5px solid var(--red);
  pointer-events: none;
}
.exc-tick--tl { top: 52px;    left: 14px;  border-right: 0; border-bottom: 0; }
.exc-tick--tr { top: 52px;    right: 14px; border-left: 0;  border-bottom: 0; }
.exc-tick--bl { bottom: 14px; left: 14px;  border-right: 0; border-top: 0; }
.exc-tick--br { bottom: 14px; right: 14px; border-left: 0;  border-top: 0; }

/* ── headline ────────────────────────────────────────────────────────── */
.exc-hero { padding: 16px 6px 0; text-align: center; }

.exc-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  line-height: 0.87;
  letter-spacing: 0.005em;
  text-transform: uppercase;
}
.exc-title-line { display: block; font-size: clamp(50px, 16.4vw, 74px); }
.exc-title-line--red { color: var(--red); }

.exc-sub {
  margin: 14px auto 0;
  max-width: 33ch;
  font-size: 11.5px;
  line-height: 1.62;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
}

/* ── the dark instrument ─────────────────────────────────────────────── */
.exc-panel {
  margin-top: 18px;
  background: var(--panel);
  border-radius: 12px;
  overflow: hidden;
  line-height: 0;   /* the panel is exactly the stage — no stray inline gap */
}

/* The checklist that used to sit under this panel is gone, and the freed
   height goes to the subject: a portrait 4:5 frame shows a face far larger
   than the old 4:3 letterbox at the same card width. */
.exc-stage {
  position: relative;
  aspect-ratio: 4 / 5;
  background: #0d0c0b;
  overflow: hidden;
  isolation: isolate;
}
.exc-stage > video,
.exc-stage > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* Selfie view is mirrored; the mesh canvas rides the same transform so the
   landmarks stay welded to the face. Uploaded photos are never mirrored. */
.exc-stage.is-mirrored > video,
.exc-stage.is-mirrored > canvas { transform: scaleX(-1); }

#excMesh {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Scan beam — position is driven from JS, synchronised to the same 6 s clock
   that drives the percentage. */
.exc-beam {
  position: absolute;
  left: 0; right: 0;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, rgba(224,48,30,0) 0%, #ff3a24 12%, #ff6a55 50%, #ff3a24 88%, rgba(224,48,30,0) 100%);
  box-shadow: 0 0 14px 2px rgba(255, 58, 36, 0.55);
  opacity: 0;
  transform: translateY(0);
  pointer-events: none;
}
.exc-stage.is-scanning .exc-beam { opacity: 1; }

.exc-bracket {
  position: absolute;
  width: 26px; height: 26px;
  border: 2.5px solid var(--red);
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.exc-stage.is-live .exc-bracket { opacity: 1; }
.exc-bracket--tl { top: 14px;    left: 14px;  border-right: 0; border-bottom: 0; }
.exc-bracket--tr { top: 14px;    right: 14px; border-left: 0;  border-bottom: 0; }
.exc-bracket--bl { bottom: 14px; left: 14px;  border-right: 0; border-top: 0; }
.exc-bracket--br { bottom: 14px; right: 14px; border-left: 0;  border-top: 0; }

.exc-stage-bar {
  position: absolute;
  top: 12px; left: 12px; right: 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}
.exc-stage-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}

.exc-ring { position: relative; width: 46px; height: 46px; flex: none; opacity: 0; transition: opacity 0.25s ease; }
.exc-stage.is-live .exc-ring { opacity: 1; }
.exc-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.exc-ring circle { fill: none; stroke-width: 2.5; }
.exc-ring-track { stroke: rgba(255, 255, 255, 0.18); stroke-dasharray: 2 4; stroke-linecap: round; }
.exc-ring-value {
  stroke: var(--red);
  stroke-linecap: round;
  stroke-dasharray: 119.4;      /* 2πr, r = 19 */
  stroke-dashoffset: 119.4;
}
.exc-ring-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.exc-ring-num em { font-style: normal; font-size: 7px; align-self: flex-start; margin-top: 3px; opacity: 0.75; }

.exc-idle {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: rgba(255, 255, 255, 0.34);
  background:
    repeating-linear-gradient(0deg,  rgba(255,255,255,0.030) 0 1px, transparent 1px 34px),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.030) 0 1px, transparent 1px 34px);
}
.exc-idle-glyph { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 1.4; }
.exc-idle-text { margin: 0; font-size: 9.5px; letter-spacing: 0.2em; }

.exc-count {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-family: var(--display);
  font-size: 96px;
  color: #fff;
  text-shadow: 0 4px 40px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}
.exc-count.is-on { display: flex; animation: exc-pop 0.85s ease-out; }
@keyframes exc-pop {
  0%   { transform: scale(1.45); opacity: 0; }
  22%  { transform: scale(1);    opacity: 1; }
  100% { transform: scale(1);    opacity: 0.85; }
}

.exc-notice {
  position: absolute;
  left: 12px; right: 12px; bottom: 12px;
  margin: 0;
  padding: 7px 9px;
  border-radius: 4px;
  background: rgba(10, 9, 8, 0.78);
  border-left: 2px solid var(--red);
  color: #fff;
  font-size: 9px;
  letter-spacing: 0.09em;
  line-height: 1.45;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.exc-notice.is-on { opacity: 1; transform: none; }

/* ── buttons ─────────────────────────────────────────────────────────── */
.exc-actions { display: flex; flex-direction: column; gap: 9px; margin-top: 16px; }

.exc-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-height: 52px;
  padding: 14px 16px;
  border: 1.5px solid var(--ink);
  border-radius: 7px;
  background: var(--ink);
  color: #fff;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, background 0.16s ease, opacity 0.16s ease;
}
.exc-btn:active { transform: translateY(1px); }
.exc-btn[disabled] { opacity: 0.45; cursor: default; }
.exc-btn--ghost { background: transparent; color: var(--ink); }
.exc-btn--red { background: var(--red); border-color: var(--red); color: #fff; }
.exc-btn--red:active { background: var(--red-dark); }
.exc-arrow { font-size: 13px; }

.exc-ico { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.exc-ico--sm { width: 13px; height: 13px; }

/* Real, focusable file input kept out of sight; the visible <button> above it
   is the control users and screen readers actually operate. */
.exc-file {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.exc-lock {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 16px 0 0;
  font-size: 8.6px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.exc-error {
  margin: 14px 0 0;
  padding: 11px 12px;
  border: 1px solid rgba(224, 48, 30, 0.4);
  border-left: 3px solid var(--red);
  border-radius: 4px;
  background: rgba(224, 48, 30, 0.06);
  color: var(--ink);
  font-size: 11px;
  line-height: 1.55;
}

/* ── report ──────────────────────────────────────────────────────────── */
.exc-someone {
  margin: 18px 0 -6px;
  font-size: 9.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

.exc-verdict {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}
.exc-verdict-main { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.exc-bignum {
  font-family: var(--display);
  font-size: clamp(64px, 22vw, 92px);
  line-height: 0.8;
  color: var(--red);
}
.exc-bigword {
  font-family: var(--display);
  font-size: clamp(24px, 7.6vw, 34px);
  line-height: 1;
  letter-spacing: 0.005em;
  text-transform: uppercase;
}

.exc-stamp {
  flex: none;
  max-width: 43%;
  padding: 7px 10px;
  border: 2px solid var(--red);
  border-radius: 4px;
  color: var(--red);
  font-family: var(--display);
  font-size: clamp(12px, 3.7vw, 16px);
  line-height: 1.08;
  letter-spacing: 0.02em;
  text-align: center;
  text-transform: uppercase;
  transform: rotate(-4.5deg);
}

.exc-roast {
  margin: 16px 0 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ink-soft);
}

/* Metric table — label · bar · value · descriptor, exactly as approved. The
   columns are fluid so nothing ever pushes the page sideways on a small phone. */
.exc-metrics {
  margin: 18px 0 0;
  padding: 14px 0 0;
  list-style: none;
  border-top: 1px solid var(--line);
}
/* Every row is its own grid, so the tracks must be width-independent of the row
   CONTENT or the bars and numbers would step in and out per row instead of
   forming the clean column the approved design has. Hence: two fixed tracks
   (bar, value) and two flexible ones that resolve from the container width,
   which is identical for every row. The bar is sized at ~19% of the card, the
   proportion it holds in the reference. */
.exc-metric {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px 52px minmax(72px, 0.85fr);
  align-items: center;
  gap: 6px;
  padding: 7px 0;
  min-height: 30px;
}
.exc-metric-label {
  font-size: clamp(6.9px, 1.95vw, 9.2px);
  letter-spacing: 0.02em;
  line-height: 1.35;
  text-transform: uppercase;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.exc-metric-bar {
  height: 4px;
  border-radius: 2px;
  background: rgba(22, 19, 15, 0.13);
  overflow: hidden;
}
.exc-metric-fill {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--red);
  width: 0;
  transition: width 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}
.exc-metric-value {
  font-size: clamp(8.2px, 2.5vw, 10.5px);
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  text-align: left;
}
.exc-metric-desc {
  font-size: clamp(7.4px, 2.25vw, 9.6px);
  font-style: italic;
  line-height: 1.35;
  color: var(--ink-mute);
  overflow-wrap: anywhere;
}

.exc-note {
  display: flex;
  gap: 11px;
  margin-top: 18px;
  padding: 13px 13px 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--card-warm);
}
.exc-note-ico { width: 17px; height: 17px; flex: none; margin-top: 1px; fill: none; stroke: var(--ink-mute); stroke-width: 1.3; stroke-linejoin: round; stroke-linecap: round; }
.exc-note-label {
  margin: 0 0 5px;
  font-size: 8.6px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.exc-note-body { margin: 0; font-size: 11px; line-height: 1.6; color: var(--ink); }

.exc-result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 18px;
}
.exc-result-actions .exc-btn { font-size: clamp(9.4px, 2.9vw, 11.5px); letter-spacing: 0.08em; gap: 7px; padding: 14px 8px; }

.exc-result-minor {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 15px;
}
.exc-again, .exc-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
  border: 0;
  background: none;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.exc-copy { text-decoration: underline; text-underline-offset: 3px; color: var(--ink-mute); font-size: 10px; }
.exc-again:hover, .exc-copy:hover { color: var(--ink); }

.exc-scanself { margin-top: 16px; }

.exc-toast {
  margin: 13px 0 0;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--red);
}

.exc-foot {
  margin: 6px 0 0;
  text-align: center;
  font-size: 9.4px;
  line-height: 1.6;
  letter-spacing: 0.045em;
  color: var(--ink-mute);
}

/* ── focus + motion ──────────────────────────────────────────────────── */
:where(button, [href], input, [tabindex]):focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Phones: the artwork is atmosphere, not the subject. It is pulled back so the
   detector card stays the thing you look at, and `cover` on a portrait viewport
   crops to the centre of the collage rather than squashing it. */
@media (max-width: 719px) {
  /* Swap to the PORTRAIT artwork. Redefining the variable (rather than giving
     .exc-bg a second background-image rule) means the browser resolves exactly
     one url() and downloads exactly one of the two images. */
  :root { --exc-bg-image: var(--exc-bg-mobile); }

  /* The phone artwork is purpose-composed for portrait with its own clear
     centre, so it does not need the desktop crop's heavy damping — a lighter
     bloom is enough to keep the card's edges legible without muting the
     collage that is the whole point of it. */
  .exc-bg::after {
    background: radial-gradient(ellipse 88% 44% at 50% 44%,
      rgba(246, 241, 232, 0.80) 0%,
      rgba(246, 241, 232, 0.42) 55%,
      rgba(246, 241, 232, 0) 100%);
  }
  /* Lift the card off busy artwork so its edges stay legible. */
  .exc-card { box-shadow: 0 2px 6px rgba(22, 19, 15, 0.06), 0 14px 38px -20px rgba(22, 19, 15, 0.5); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  body::before { display: none; }
}

/* ── larger phones / desktop ─────────────────────────────────────────── */
@media (min-width: 430px) {
  .exc-card { padding: 22px 22px 24px; }
  .exc-sub  { font-size: 12.5px; }
}

@media (min-width: 720px) {
  .exc { padding-top: 30px; padding-bottom: 40px; gap: 16px; }
}
