/* Bike Fit Lab — "fitter's tape" direction.
   A light workshop surface (brushed alloy, white fit sheets, graphite ink) around a true-black video well.
   Tape-measure yellow marks measurement: the primary action, target bands and the gauges. Nothing else. */
:root {
  --alloy: #e9ebee;        /* page: brushed aluminium, cool not cream */
  --sheet: #ffffff;        /* setup and report surfaces */
  --sheet-2: #f4f5f7;      /* inset fields and quiet fills */
  --rule: #d5d9de;         /* hairlines and control borders */
  --ink: #1c2126;          /* graphite text */
  --muted: #5b6570;        /* secondary text (5:1 on alloy) */
  --tape: #ffc21a;         /* tape-measure yellow: fills only, never text */
  --tape-soft: #ffe9a8;
  --well: #000;            /* the video stage */
  --good: #17803d;
  --close: #b45309;
  --bad: #c2261d;
  --calib: #db2777;        /* calibration clicks, matching the canvas markers */
  --sans: "Archivo", ui-sans-serif, system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--alloy);
  color: var(--ink);
  font: 400 15.5px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
.mono { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--muted); }
.offscreen { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; left: -9999px; }
::selection { background: var(--tape-soft); color: var(--ink); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Numerals and display type use Archivo's condensed width: the look of figures stamped on a tool. */
.brand h1, .placeholder .big, .countdown, .live dd, .verdict-title, .sheet-meta dd,
.sugg-n, .fitdata dd, .g-value { font-stretch: 75%; font-variant-numeric: tabular-nums; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  max-width: 1500px; margin: 0 auto; padding: 18px 24px 6px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { width: 38px; height: 26px; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.brand h1 { font-size: 27px; font-weight: 760; letter-spacing: -0.01em; }
.topbar-end { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* Model status reads as an instrument light, not a badge. */
.pill { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--muted); }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #aab1b8; }
.pill.ok::before { background: var(--good); }
.pill.err { color: var(--bad); }
.pill.err::before { background: var(--bad); }

.lang-switch { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; background: var(--sheet); overflow: hidden; }
.lang-switch button {
  appearance: none; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13.5px; font-weight: 600;
  padding: 4px 11px; cursor: pointer;
}
.lang-switch button + button { border-left: 1px solid var(--rule); }
.lang-switch button:hover { color: var(--ink); }
.lang-switch button[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* ---------- Intro: one line of purpose above the workbench ---------- */
.intro { max-width: 1500px; margin: 0 auto; padding: 14px 24px 2px; }
.intro h2 { font-stretch: 75%; font-size: clamp(30px, 3.6vw, 44px); font-weight: 800; line-height: 1.02; letter-spacing: -0.01em; }
.intro p { margin: 8px 0 0; max-width: 72ch; font-size: 16px; color: #3a424b; }
.intro a, .about a { color: var(--ink); font-weight: 600; text-decoration-thickness: 1.5px; text-underline-offset: 3px; white-space: nowrap; }

/* ---------- Workbench layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px;
  padding: 14px 24px 24px; max-width: 1500px; margin: 0 auto;
}
@media (max-width: 960px) { .layout { grid-template-columns: 1fr; padding: 12px 16px 20px; } }

.stage {
  position: relative; background: var(--well); border-radius: 4px; overflow: hidden;
  aspect-ratio: var(--ar, 16 / 9); display: grid; place-items: center; container-type: inline-size;
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
/* Portrait footage: as tall as the viewport allows, centred in the column. */
.stage.portrait { width: min(100%, calc(80svh * var(--ar))); margin-inline: auto; }
.stage.calibrating canvas { cursor: crosshair; }

.placeholder { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; color: #a9afb6; max-width: 560px; margin: auto; }
.placeholder .big { color: #fff; font-size: 32px; font-weight: 720; line-height: 1.08; margin: 0 0 10px; }
.placeholder p { margin: 0; }

.countdown {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  font-size: 128px; font-weight: 800; line-height: 1; color: #fff; background: rgba(0, 0, 0, 0.5);
}
.countdown small { display: block; margin-top: 10px; font-stretch: 100%; font-size: 18px; font-weight: 500; }
.rec-badge {
  position: absolute; top: 12px; right: 12px; display: flex; align-items: center; gap: 8px;
  background: rgba(0, 0, 0, 0.75); color: #fff; padding: 5px 12px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: #ef4444; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

/* Sits under the video (never over it) so the tire and bottom bracket stay clickable on short phone stages. */
.calib-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 12px;
  background: var(--sheet); border: 1.5px solid var(--calib); border-radius: 8px; padding: 9px 12px; font-size: 14.5px;
}
.calib-msg { margin: 0; flex: 1 1 260px; }
.calib-actions { display: flex; gap: 8px; margin-left: auto; }
.calib-step { font-weight: 700; color: var(--calib); margin-right: 4px; font-variant-numeric: tabular-nums; }

.toolbar, .file-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 12px; }
.tool-group { display: flex; flex-wrap: wrap; gap: 8px; }
/* The session group stays right-aligned even when it wraps, so the primary action never strands on the left. */
.tool-group.end { margin-left: auto; justify-content: flex-end; }
.file-controls input[type=range] { flex: 1; min-width: 160px; accent-color: var(--ink); }

/* ---------- Controls ---------- */
.btn {
  appearance: none; border: 1px solid var(--rule); background: var(--sheet); color: var(--ink);
  padding: 9px 16px; border-radius: 6px; font: inherit; font-weight: 600; line-height: 1.3; cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover:not(:disabled):not([aria-disabled="true"]) { border-color: #8e969f; }
/* Disabled is a flat slab with no edge; enabled ghost buttons keep their outline, so the two never read alike. */
.btn:disabled, .btn[aria-disabled="true"] { color: #80878f; background: rgba(28, 33, 38, 0.05); border-color: transparent; cursor: not-allowed; }
.btn[aria-disabled="true"] { pointer-events: none; }
.btn.primary { background: var(--tape); border-color: #c99500; color: var(--ink); }
.btn.primary:hover:not(:disabled) { background: #ffd04d; border-color: #a87d00; }
.btn.primary:disabled { background: rgba(28, 33, 38, 0.05); border-color: transparent; color: #80878f; }
.btn.ghost { background: transparent; border-color: #aab1b8; }
.btn.small { padding: 6px 12px; font-size: 14px; }
a.btn { display: inline-block; text-decoration: none; }

.toast {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 12px 0 0; padding: 10px 14px; border-radius: 8px;
  background: #fbeaea; border: 1px solid #efb9b5; color: #7d1a14;
}
.toast p { margin: 0; flex: 1 1 280px; }
.toast.info { background: var(--sheet); border-color: var(--rule); color: var(--ink); }
.toast-actions { display: flex; gap: 8px; }

/* ---------- Side column: setup sheet, live readout, tips ---------- */
.panel { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--sheet); border-radius: 10px; padding: 18px; }
.card h2 { font-size: 17px; font-weight: 700; margin-bottom: 12px; }
.card .group + .group { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--rule); }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--ink); font-weight: 500; margin-bottom: 12px; }
.field .hint { display: block; font-size: 13px; font-weight: 400; color: var(--muted); margin-top: 1px; }
.field-error { font-size: 13.5px; color: var(--bad); }
.height-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.height-inputs { display: flex; align-items: center; gap: 6px; flex: 1 1 140px; min-width: 0; }
.height-inputs input { width: 100%; min-width: 0; }
#heightImpBox input { width: 4.2em; flex: 0 1 auto; }
.height-inputs .unit { font-size: 14px; color: var(--muted); font-weight: 500; }
.unit-switch { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; flex: none; }
.unit-switch button { appearance: none; border: 0; background: var(--sheet); color: var(--muted); font: inherit; font-size: 13.5px; font-weight: 600; padding: 8px 10px; cursor: pointer; }
.unit-switch button + button { border-left: 1px solid var(--rule); }
.unit-switch button:hover { color: var(--ink); }
.unit-switch button[aria-pressed="true"] { background: var(--ink); color: #fff; }
/* 16px keeps iOS Safari from zooming the page when a field gets focus. */
select, input[type=number] {
  font: inherit; font-size: 16px; font-weight: 400; color: var(--ink); background: var(--sheet-2); border: 1px solid var(--rule);
  border-radius: 6px; padding: 8px 10px; min-width: 0;
}
select:hover, input[type=number]:hover { border-color: #8e969f; }
input[aria-invalid="true"] { border-color: var(--bad); }
::placeholder { color: #656e78; opacity: 1; }
.inline { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); }
.inline select { padding: 4px 8px; font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14.5px; }
.check input { accent-color: var(--ink); width: 16px; height: 16px; }

.calib-status { font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.calib-status strong { color: var(--ink); }
.calib-status .ok { color: var(--good); }
.calib-status .warn { color: var(--close); }

/* Live angles are read from the saddle, a couple of metres away: big stamped numerals. */
.live { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; margin: 0; font-size: 14.5px; align-items: baseline; }
.live dt { color: var(--muted); }
.live dd { margin: 0; font-size: 23px; font-weight: 750; text-align: right; }
.live dd.good { color: var(--good); }
.live dd.close { color: var(--close); }
.live dd.bad { color: var(--bad); }
.live .live-empty { grid-column: 1 / -1; font-size: 14px; }

.tips { background: transparent; padding: 4px 2px; }
.tips summary { cursor: pointer; font-weight: 600; }
.tips ol { margin: 10px 0 0; padding-left: 20px; color: var(--muted); font-size: 14.5px; }
.tips li { margin-bottom: 6px; }

.muted-note { margin: 0; color: var(--muted); font-size: 14.5px; }

/* ---------- Fit sheet (report) ---------- */
.report { max-width: 1500px; margin: 4px auto 0; padding: 0 24px 24px; }
.report-sheet { background: var(--sheet); border-radius: 10px; padding: 28px 32px 30px; }
.report-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 32px; align-items: end; padding-bottom: 22px; border-bottom: 1px solid var(--rule); }
.report-head h2 { grid-column: 1 / -1; font-size: 15px; font-weight: 600; color: var(--muted); }
.verdict-title { margin: 0; font-size: clamp(40px, 5vw, 58px); font-weight: 800; line-height: 0.98; letter-spacing: -0.01em; text-wrap: balance; }
.verdict-sub { margin: 10px 0 0; font-size: 17px; }
.verdict-sub .in-range { display: block; color: var(--muted); font-size: 15px; }
.sheet-meta { display: flex; gap: 24px; margin: 0; }
.sheet-meta dt { font-size: 13px; color: var(--muted); }
.sheet-meta dd { margin: 0; font-size: 21px; font-weight: 720; white-space: nowrap; }

.report-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 40px; align-items: start; padding-top: 24px; }
.report-grid .col { display: flex; flex-direction: column; gap: 30px; min-width: 0; }
.report-grid h3 { font-size: 19px; font-weight: 700; margin-bottom: 6px; }
.section-intro { margin: 0 0 12px; color: var(--muted); font-size: 14.5px; max-width: 60ch; }
@media (max-width: 1100px) { .report-grid { grid-template-columns: 1fr; } }
@media (max-width: 960px) { .report { padding: 0 16px 16px; } }

/* Adjustments are a real sequence (change one thing at a time, in this order), so they are numbered. */
.suggestions { list-style: none; margin: 0; padding: 0; }
.sugg { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 0 12px; padding: 14px 0; border-top: 1px solid var(--rule); }
.sugg:first-child { border-top: 0; padding-top: 4px; }
.sugg-n { font-size: 36px; font-weight: 800; line-height: 0.9; }
.sugg-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 0 0 3px; font-size: 13.5px; color: var(--muted); }
.prio { font-weight: 700; font-size: 12.5px; padding: 1px 8px; border-radius: 999px; background: var(--sheet-2); color: var(--ink); }
.sugg.p1 .prio { background: #fbe4e2; color: #8f1b14; }
.sugg.p2 .prio { background: #fdecd6; color: #7c3a06; }
.sugg h4 { font-size: 17px; font-weight: 700; margin: 0 0 4px; }
.sugg p { margin: 0 0 8px; color: #3a424b; max-width: 66ch; }
.sugg .action { margin: 0; color: var(--ink); font-weight: 600; }
.sugg .action b { font-weight: 700; padding: 1px 6px; margin-right: 6px; background: var(--tape); border-radius: 3px; }

.fd-source { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3px 14px; margin: 0 0 14px; font-size: 14.5px; }
.fd-source dt { color: var(--muted); }
.fd-source dd { margin: 0; }
.fitdata { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 0; }
.fitdata div { background: var(--sheet-2); border-radius: 6px; padding: 10px 12px; }
.fitdata dt { font-size: 13px; color: var(--muted); }
.fitdata dd { margin: 2px 0 0; font-size: 28px; font-weight: 800; }
.fitdata dd small { font-stretch: 100%; font-size: 13px; font-weight: 500; color: var(--muted); }
.notes { margin: 14px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.notes li { margin-bottom: 4px; }

/* The signature: every measurement laid on a strip of tape. Target band in yellow, your value as the needle. */
.gauges { list-style: none; margin: 0; padding: 0; }
.gauge-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 84px minmax(0, 1.25fr); gap: 4px 16px; align-items: center;
  padding: 12px 0; border-top: 1px solid var(--rule);
}
.gauge-row:first-child { border-top: 0; padding-top: 2px; }
.g-name h4 { font-size: 15px; font-weight: 600; }
.g-name .help { margin: 1px 0 0; font-size: 13px; color: var(--muted); line-height: 1.4; }
.g-value { margin: 0; text-align: right; font-size: 28px; font-weight: 800; white-space: nowrap; }
.s-good .g-value { color: var(--good); }
.s-close .g-value { color: var(--close); }
.s-bad .g-value { color: var(--bad); }
.s-na .g-value { color: var(--muted); }
.g-value small { font-size: 14px; font-weight: 600; font-stretch: 100%; color: var(--muted); }
.gauge { position: relative; height: 26px; background: #fbfbfa; border: 1px solid var(--rule); border-radius: 3px; overflow: hidden; }
.gauge .ticks { position: absolute; inset: 0; width: 100%; height: 100%; }
.gauge .ticks line { stroke: #a3aab2; stroke-width: 1; }
.gauge .ticks line.major { stroke: #5b6570; }
.gauge .band { position: absolute; top: 0; bottom: 0; background: color-mix(in srgb, var(--tape) 55%, transparent); border-inline: 1.5px solid #c99500; }
.gauge .band.open-lo { border-left: 0; }
.gauge .band.open-hi { border-right: 0; }
.gauge .needle { position: absolute; top: -1px; bottom: -1px; width: 3px; margin-left: -1.5px; background: var(--ink); border-radius: 1px; animation: needle-in 0.8s cubic-bezier(0.16, 1, 0.3, 1) backwards; }
.s-good .needle { background: var(--good); }
.s-close .needle { background: var(--close); }
.s-bad .needle { background: var(--bad); }
@keyframes needle-in { from { left: var(--from); } }
.gauge-row:nth-child(2) .needle { animation-delay: 40ms; } .gauge-row:nth-child(3) .needle { animation-delay: 80ms; }
.gauge-row:nth-child(4) .needle { animation-delay: 120ms; } .gauge-row:nth-child(5) .needle { animation-delay: 160ms; }
.gauge-row:nth-child(6) .needle { animation-delay: 200ms; } .gauge-row:nth-child(7) .needle { animation-delay: 240ms; }
.gauge-row:nth-child(n+8) .needle { animation-delay: 280ms; }
.g-target { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 5px 0 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip { display: inline-block; font-size: 12.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.chip.good { background: #e1f2e6; color: #12612f; }
.chip.close { background: #fdecd6; color: #7c3a06; }
.chip.bad { background: #fbe4e2; color: #8f1b14; }
.chip.na { background: var(--sheet-2); color: var(--muted); }

.snaps { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.snaps figure { margin: 0; }
.snaps img { width: 100%; border-radius: 4px; display: block; background: var(--well); }
.snaps figcaption { font-size: 13.5px; color: var(--muted); margin-top: 6px; }

.report-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--rule); }

/* ---------- About: why the site exists, and where it stops ---------- */
.about { max-width: 1500px; margin: 8px auto 0; padding: 0 24px; scroll-margin-top: 16px; }
.about-sheet { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px 48px; background: var(--sheet); border-radius: 10px; padding: 30px 32px; }
.about h2 { font-stretch: 75%; font-size: clamp(28px, 3vw, 36px); font-weight: 800; line-height: 1.05; margin-bottom: 12px; }
.about-story p { margin: 0 0 12px; max-width: 62ch; font-size: 16.5px; line-height: 1.6; }
.about h3 { font-size: 16px; font-weight: 700; margin: 0 0 6px; }
.about ul { margin: 0 0 20px; padding-left: 18px; color: #3a424b; }
.about ul:last-child { margin-bottom: 0; }
.about li { margin-bottom: 4px; }
.about li::marker { color: var(--muted); }
@media (max-width: 860px) { .about-sheet { grid-template-columns: 1fr; padding: 22px 18px; } }
@media (max-width: 960px) { .about { padding: 0 16px; } }

/* ---------- Chart ---------- */
.chart-wrap { position: relative; margin-top: 4px; }
.chart-plot { width: 100%; min-height: 200px; }
.chart-wrap svg { display: block; overflow: visible; touch-action: pan-y; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 2px 16px; font-size: 13.5px; color: var(--muted); margin-bottom: 4px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 14px; height: 2px; border-radius: 2px; display: inline-block; }
.chart-legend .legend-band { display: none; }
.chart-wrap.narrow .chart-legend .legend-band { display: inline-flex; }
.chart-legend .legend-band i { height: 10px; border-radius: 2px; background: color-mix(in srgb, var(--tape) 45%, transparent); }
.chart-tip {
  position: absolute; pointer-events: none; background: var(--ink); color: #fff; border-radius: 6px;
  padding: 6px 10px; font-size: 13px; white-space: nowrap; transform: translate(-50%, -110%);
}
.chart-tip b { font-variant-numeric: tabular-nums; }
.chart-caption { margin: 6px 0 0; color: var(--muted); font-size: 13.5px; }
.chart-wrap text { fill: var(--muted); font-size: 12px; font-family: inherit; }
.chart-wrap text.direct { fill: var(--ink); font-weight: 700; }
.chart-wrap text.band-label { font-size: 11.5px; fill: #6b5000; }
.chart-wrap .grid { stroke: var(--rule); stroke-width: 1; }
.chart-wrap .band { fill: color-mix(in srgb, var(--tape) 30%, transparent); }
.chart-wrap .cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }

.foot { max-width: 1500px; margin: 0 auto; padding: 8px 24px 32px; color: var(--muted); font-size: 13.5px; }

/* Balanced headings, no single-word last lines in running text. */
h1, h2, h3, h4, .placeholder .big { text-wrap: balance; }
p, li, .help { text-wrap: pretty; }

/* ---------- Empty-stage demo rider (lives in the black well) ---------- */
.rider-demo { width: min(240px, 60%); height: auto; margin: 0 auto 16px; overflow: visible; }
.rider-demo .rd-bike { fill: none; stroke: #4a5058; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.rider-demo .rd-torso { stroke: #fb923c; stroke-width: 3.5; stroke-linecap: round; }
.rider-demo .rd-head { fill: none; stroke: #fb923c; stroke-width: 2.5; }
.rider-demo .rd-arm { fill: none; stroke: #c084fc; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.rider-demo .rd-leg { fill: none; stroke: #60a5fa; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.rider-demo .rd-crank { stroke: #cbd5e1; stroke-width: 2.5; stroke-linecap: round; }
.rider-demo .rd-joint { fill: #e5e7eb; }
.rider-demo .rd-pedal { fill: #facc15; }
.rider-demo .rd-tag { fill: var(--tape); stroke: none; }
.rider-demo .rd-tag-text { fill: var(--ink); font: 700 9px var(--sans); font-variant-numeric: tabular-nums; }
/* Short stages keep the words, drop the drawing. */
@container (max-width: 520px) { .rider-demo { display: none; } }

.countdown .cd-n { display: block; animation: cd-pop 0.45s cubic-bezier(0.16, 1, 0.3, 1); }
.countdown.go { background: transparent; color: var(--tape); }
.countdown.go .cd-n { font-size: 0.8em; animation: cd-go 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards; }
@keyframes cd-pop { from { transform: scale(1.35); opacity: 0.3; } }
@keyframes cd-go { 0% { transform: scale(0.8); opacity: 0; } 30% { transform: scale(1.05); opacity: 1; } 100% { transform: scale(1.15); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .rec-dot, .countdown .cd-n, .countdown.go .cd-n, .gauge .needle { animation: none; }
  .btn { transition: none; }
}

/* ---------- Phones & narrow tablets ---------- */
@media (max-width: 960px) {
  /* Empty stage sizes to its content instead of a 16:9 box that clips the copy on narrow screens. */
  .stage:has(> .placeholder:not([hidden])) { aspect-ratio: auto; }
  .stage:has(> .placeholder:not([hidden])) .placeholder { position: static; padding: 28px 20px; }
  .stage:has(> .placeholder:not([hidden])) .rider-demo { display: block; width: min(220px, 70%); }
}
@media (max-width: 720px) {
  .report-sheet { padding: 20px 18px 22px; }
  .report-head { grid-template-columns: 1fr; }
  .gauge-row { grid-template-columns: minmax(0, 1fr) auto; }
  .gauge-row .g-scale { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .topbar { flex-wrap: nowrap; padding: 14px 16px 4px; }
  .intro { padding: 10px 16px 0; }
  .intro p { font-size: 15px; }
  /* Once footage is loaded, the intro steps aside so the video and its buttons fit on the screen. */
  body:has(#placeholder[hidden]) .intro { display: none; }
  .brand { gap: 8px; min-width: 0; }
  .brand svg { width: 32px; height: 22px; flex: none; }
  .brand h1 { font-size: 24px; white-space: nowrap; }
  .topbar-end { flex-wrap: nowrap; gap: 8px; }
  /* "Ready" is implied by the enabled buttons; keep it for screen readers, free the row for the brand. Loading and errors stay visible. */
  .pill.ok { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .lang-switch button { padding: 7px 12px; }

  .layout { padding: 10px 16px 16px; gap: 16px; }
  .placeholder .big { font-size: 27px; }
  /* Leave room under portrait footage for the toolbar, so the primary action is on screen without scrolling. */
  .stage.portrait { width: min(100%, calc(62svh * var(--ar))); }

  /* Two even columns of thumb-sized buttons; the primary action lands bottom-right. */
  .toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .tool-group { display: contents; }
  .toolbar .btn { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 12px; text-align: center; line-height: 1.25; }

  .file-controls { gap: 8px 12px; }
  .file-controls input[type=range] { order: -1; flex: 1 0 100%; height: 32px; margin: 0; }
  .file-controls .btn { min-height: 40px; min-width: 72px; }
  .file-controls .inline { margin-left: auto; }
  .inline select { font-size: 16px; padding: 6px 8px; }

  .btn.small { min-height: 40px; }
  .calib-actions { margin-left: 0; width: 100%; }
  .calib-actions .btn { flex: 1; }
  .toast-actions { width: 100%; justify-content: flex-end; }

  .sheet-meta { flex-wrap: wrap; gap: 6px 18px; }
  .report-actions { display: grid; grid-template-columns: 1fr 1fr; align-items: stretch; }
  .report-actions #recordingSlot { display: contents; }
  .report-actions .muted-note { grid-column: 1 / -1; }
  .report-actions .btn { display: flex; align-items: center; justify-content: center; min-height: 44px; text-align: center; }
  .fitdata { grid-template-columns: 1fr 1fr; }
  .snaps { grid-template-columns: 1fr; }
  /* Portrait snapshots stay side by side; stacked they would each fill the screen. */
  .snaps.portrait { grid-template-columns: 1fr 1fr; gap: 8px; }
  .foot { padding: 8px 16px 28px; }
}

/* ---------- Print: the fit sheet alone ---------- */
@media print {
  body { background: #fff; }
  .topbar, .intro, .layout, .report-actions, .about, .foot { display: none !important; }
  .report { display: block !important; padding: 0; }
  .report-sheet { padding: 0; }
  .gauge .band, .chip, .sugg .action b, .prio { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .gauge .needle { animation: none; }
}
