/* WingFoil Lab — dark sports-data styling.
   Palette roles follow the repo's validated data-viz palette (same steps
   lab/tools/plot_turns.py uses, re-stepped for the dark surface):
     series-1 blue   #3987e5  foiling / Doppler
     status  good    #0ca30c  flew through
     status  warning #fab219  touchdown
     status  critical#d03b3b  fell in
   The green/amber/red status ramp cannot pass a CVD check (deutan ΔE ~4 green↔red),
   so **shape carries the state everywhere** and colour only reinforces it; every
   outcome has its own marker and its own legend label. The wind arrow is drawn in
   secondary ink with a direct label rather than a fifth hue, because an orange
   annotation sits only ΔE 6.8 from the critical red for normal vision.

   The presentation values themselves live in design/tokens.json and arrive through
   css/tokens.css (loaded first, generated, CI-checked) — see docs/presentation.md
   "Enforcement". The names below are this app's *roles*; the tokens are the values,
   shared with the iOS app so neither can drift alone. */

:root {
  color-scheme: dark;
  --surface-0: #101010;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --line:      #333331;
  --line-soft: #2a2a29;

  --ink:       #ffffff;
  --ink-2:     #c3c2b7;
  --ink-3:     #8a8a80;

  /* The app's own blue: chrome, links, buttons and the Doppler trace. Not a presentation
     token — the phase tints below are, and a track tinted with the brand colour reads as
     chrome rather than as a category (docs/presentation.md "Phase tints"). */
  --series-1:  #3987e5;
  --series-1-tint: #7fb0e8;
  /* Phase tints, from design/tokens.json: teal on foil, secondary grey off it — what the
     iOS app's .teal / .secondary render as on dark. */
  --foil:      var(--wf-phase-flying);
  --track:     var(--wf-phase-off-foil);
  --effort:    var(--wf-effort-window);

  --good:      var(--wf-outcome-flew);
  --warn:      var(--wf-outcome-touchdown);
  --bad:       var(--wf-outcome-fell-in);
  --reject:    var(--wf-outcome-course-change);

  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Phone geometry, in one place so every rule below reads from the same numbers.
   --pad-x is the page gutter, widened to clear a landscape notch; --tap is the minimum
   touch target (Apple HIG says 44 pt and the whole app has to honour it). */
:root {
  --pad-x: 20px;
  --pad-x-l: max(var(--pad-x), env(safe-area-inset-left));
  --pad-x-r: max(var(--pad-x), env(safe-area-inset-right));
  --tap: 44px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;          /* iOS: 100vh is the *largest* viewport, so it overflows */
  background: var(--surface-0);
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  /* Nothing in this app is a horizontally scrollable page. Wide things (tables, figures)
     scroll inside their own box; if one ever escapes, this is the guard rail. */
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* Visually hidden but still a real, focusable, label-addressable control. */
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 18px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-2); }
p  { margin: 0; }
a  { color: var(--series-1); }
code { font-family: var(--mono); font-size: 0.92em; color: var(--ink-2); }

.muted { color: var(--ink-2); }
.small { font-size: 13px; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(14px + env(safe-area-inset-top)) var(--pad-x-r) 14px var(--pad-x-l);
  border-bottom: 1px solid var(--line-soft);
  background: var(--surface-1); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { white-space: nowrap; }
/* In the analyzer the brand is the link back to the project homepage at the site root, so
   it has to shed the anchor's colour and underline and keep looking like a wordmark. */
a.brand { color: inherit; text-decoration: none; }
a.brand:hover .mark { box-shadow: inset 0 0 0 1px #ffffff55; }
a.brand:focus-visible { outline: 2px solid var(--series-1); outline-offset: 3px; border-radius: 8px; }
.brand .sub { font-size: 12.5px; color: var(--ink-3); }
.mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: linear-gradient(140deg, var(--series-1), #1c5fae);
  box-shadow: inset 0 0 0 1px #ffffff22;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.chip {
  font: 600 11.5px/1 var(--mono); color: var(--ink-3);
  padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px;
}

main {
  max-width: 1120px; margin: 0 auto;
  padding: 22px var(--pad-x-r) 40px var(--pad-x-l);
}
/* One <div> per view; only one is ever un-hidden. Each keeps the panel rhythm. */
/* minmax(0,1fr) rather than the default `auto`: a grid item's automatic minimum is its
   min-content width, which is how a wide table pushes the whole page sideways. */
main > div { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
main > div[hidden], [hidden] { display: none !important; }

/* ------------------------------------------------------------------- view tabs */

.views { display: flex; gap: 2px; background: var(--surface-2); border-radius: 8px; padding: 3px; }
.views button {
  background: transparent; color: var(--ink-3); border: 0; padding: 7px 12px;
  border-radius: 6px; display: inline-flex; align-items: center; gap: 7px;
}
.views button:hover { color: var(--ink-2); }
.views button[aria-current=page] { background: var(--surface-0); color: var(--ink); }
.views .count {
  font: 600 10.5px/1 var(--mono); color: var(--ink-3);
  background: var(--surface-2); border-radius: 999px; padding: 3px 6px;
}
.views button[aria-current=page] .count { background: var(--surface-2); color: var(--ink-2); }

/* --------------------------------------------------------- session sections */

/* The session view's second-level switcher (js/sections.js). `display: none` here is the
   DESKTOP BEHAVIOUR, not a fallback: app-ui-review.md §3.4 lists tabbing the desktop web
   session view under "deliberately not recommended" — at 1120 px it is a document, and the
   34-row turns table and the 23-row flight-ends table want the continuous page. The chips
   exist only inside the phone block below. */
.sections { display: none; }

/* --------------------------------------------------------------- update banner */

.update-banner {
  display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap;
  padding: 11px var(--pad-x-r) 11px var(--pad-x-l);
  background: #14293f; border-bottom: 1px solid #2a5a91;
  color: #d9e8fb; font-size: 13.5px;
}
.update-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ---------------------------------------------------------------- controls */

/* `.btn` exists so the file-picker <label> is indistinguishable from a button. */
button, .btn {
  font: 600 13.5px/1 var(--sans); border-radius: 8px; cursor: pointer;
  padding: 9px 14px; border: 1px solid transparent;
  transition: background .12s, border-color .12s;
  touch-action: manipulation;              /* no 300 ms double-tap-zoom delay */
  -webkit-tap-highlight-color: transparent;
}
.btn { display: inline-flex; align-items: center; justify-content: center; }
button.primary, .btn.primary { background: var(--series-1); color: #fff; }
button.primary:hover, .btn.primary:hover { background: #2d76d0; }
button.ghost, .btn.ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
button.ghost:hover, .btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
button:disabled { opacity: .5; cursor: default; }
/* A touch device has no hover; the :hover styles above must not stick after a tap. */
@media (hover: none) {
  button.primary:hover, .btn.primary:hover { background: var(--series-1); }
  button.ghost:hover, .btn.ghost:hover { background: transparent; color: var(--ink-2); }
  .views button:hover { color: var(--ink-3); }
  .views button[aria-current=page]:hover { color: var(--ink); }
  tbody tr:hover td { background: none; }
}

input[type=text], input[type=password] {
  background: var(--surface-0); color: var(--ink); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font: 13.5px var(--mono);
  min-width: 200px; max-width: 100%;
}
input:focus-visible, button:focus-visible, .btn:focus-visible, .dropzone:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 2px;
}
/* The file input is .sr-only, so keyboard focus has to show up on its label instead. */
.drop-hint:has(#file:focus-visible) #pick { outline: 2px solid var(--series-1); outline-offset: 2px; }

/* -------------------------------------------------------------- drop zone */

.dropzone {
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  background: var(--surface-1); padding: 34px 20px; text-align: center;
  transition: border-color .12s, background .12s;
}
.dropzone.hot { border-color: var(--series-1); background: #17283c; }
.dropzone.compact { padding: 16px; }
.dropzone.compact .drop-icon, .dropzone.compact .privacy { display: none; }
.dropzone.compact .drop-title { font-size: 14px; }
.drop-inner { display: grid; gap: 10px; justify-items: center; }
.drop-icon { width: 40px; height: 40px; color: var(--ink-3); }
.drop-title { font-size: 16px; }
.privacy { font-size: 12.5px; color: var(--ink-3); }
/* "…or try the example session". Subordinate to the real intake above it — this is the
   way in for a visitor with no .fit file to hand, not the way in. */
.drop-alt { font-size: 13.5px; color: var(--ink-2); }
.drop-alt .dim { color: var(--ink-3); }
.dropzone.compact .drop-alt { display: none; }
/* A button that reads as a link: it is a real <button> because it runs script rather than
   navigating, and the underline is what says it is pressable at that size. */
.linkish {
  background: none; border: 0; padding: 0; font: inherit; color: var(--series-1);
  text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.linkish:hover { color: #6fa9ea; }
.linkish:disabled { color: var(--ink-3); cursor: default; text-decoration: none; }

/* ------------------------------------------------------------------ panels */

.panel {
  background: var(--surface-1); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 18px 20px;
}
.panel-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 14px;
}
.panel-head > div { display: grid; gap: 4px; }
.panel.error { border-color: var(--bad); }
.panel.error pre {
  font: 12.5px/1.5 var(--mono); white-space: pre-wrap; color: var(--ink-2);
  margin: 8px 0 0; max-height: 240px; overflow: auto;
}

.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge {
  font: 600 11.5px/1 var(--sans); letter-spacing: .04em; text-transform: uppercase;
  padding: 6px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2);
}
.badge.accent { border-color: #2a5a91; background: #14293f; color: #9ec8f5; }
.tag {
  font: 600 10.5px/1 var(--sans); text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); border: 1px solid var(--line); border-radius: 999px; padding: 4px 7px;
  vertical-align: middle; margin-left: 6px;
}

/* ------------------------------------------------------------------- steps */

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.steps li { display: flex; align-items: center; gap: 10px; color: var(--ink-3); font-size: 13.5px; }
.steps .dot {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  border: 1.5px solid var(--line); background: transparent;
}
.steps li[data-state=active] { color: var(--ink); }
.steps li[data-state=active] .dot {
  border-color: var(--series-1); background: var(--series-1);
  animation: pulse 1.1s ease-in-out infinite;
}
.steps li[data-state=done] { color: var(--ink-2); }
.steps li[data-state=done] .dot { border-color: var(--good); background: var(--good); }
.steps .detail { font: 12px var(--mono); color: var(--ink-3); }
/* The elapsed clock. Same ink as the step it sits in when that step is active, so the
   number a stalled-looking page is judged by is the readable thing on the card. */
.steps .elapsed {
  margin-left: 8px; font-variant-numeric: tabular-nums; color: var(--ink-2);
}
.steps li[data-state=active] .elapsed { color: var(--ink); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

/* The card's footer: what to expect on the left, the way out on the right. Wraps to two
   rows on a phone, where the Cancel button then goes full width like every other one. */
.progress-foot {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-top: 14px;
}
.progress-foot > div { display: grid; gap: 4px; flex: 1 1 260px; }
.progress-foot p { margin: 0; }

/* ------------------------------------------------------------------- tiles */

/* The key-metrics block: four rows above the tiles, numbers big and labels small — the
   same block, in the same order, as the iOS app's `KeyMetricsView`. It is deliberately
   NOT a `.tiles` grid: the tile wall makes every cell the same size, which is exactly the
   "nothing is the headline" defect this block exists to fix (docs/app-ui-review.md §4). */
.keys { display: grid; gap: 14px; margin-bottom: 14px; }
.key-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
/* One cell on its own row stays one cell — a 3-up `auto-fit` would stretch the best-2 s
   number across the whole panel. */
.key-row:has(> .key.hero) { grid-template-columns: 1fr; }
.key .v { font: 650 26px/1.15 var(--sans); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.key.hero .v { font-size: 32px; }
.key .k {
  font: 600 10.5px/1.3 var(--sans); text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-3); margin-top: 3px;
}
/* The outcome ladder is a verdict scale and the tally is a verdict, so it carries the
   ladder's own inks straight from design/tokens.json (docs/presentation.md). The dots
   between them are not part of the scale and stay recessive.

   Written unscoped rather than under `.key`, because the library table's `outcomes`
   column draws the same three numbers on the same three inks (app-ui-review.md §5.6) and
   two copies of a colour rule is how the two surfaces come to disagree. */
.tally .flew { color: var(--wf-outcome-flew); }
.tally .touchdown { color: var(--wf-outcome-touchdown); }
.tally .fell { color: var(--wf-outcome-fell-in); }
.tally i { color: var(--ink-3); font-style: normal; margin: 0 5px; }
/* Tighter between the table's columns than in the key-metrics block, where the tally is
   a headline with a whole cell to itself. */
.lib-table .tally i { margin: 0 3px; }

.tiles {
  display: grid; gap: 1px; background: var(--line-soft);
  border: 1px solid var(--line-soft); border-radius: 8px; overflow: hidden;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.tile { background: var(--surface-1); padding: 13px 14px; display: grid; gap: 3px; }
.tile .k {
  font: 600 10.5px/1.3 var(--sans); text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-3);
}
.tile .v { font: 650 22px/1.15 var(--sans); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tile .v small { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-left: 5px; }
.tile .n { font: 12px/1.35 var(--sans); color: var(--ink-3); }

/* ----------------------------------------------------------------- figures */

.figure { background: var(--surface-1); border-radius: 8px; overflow: hidden; }
.figure svg { display: block; width: 100%; height: auto; }
.figure svg text { font-family: var(--sans); }
/* The two interactive figures. `pan-y` keeps the page scrollable with a vertical swipe
   over them, while horizontal drags (scrub) and two-finger gestures (pinch-zoom) reach the
   handlers instead of the browser. `touch-action` is latched when the *first* finger lands,
   so it cannot express "one finger scrolls, two fingers pinch" — js/session.js says that
   half with preventDefault on the second touch (see `lockTwoFingerScroll`). */
.figure svg.scrubbable { touch-action: pan-y; cursor: crosshair; }
/* A zoomed map is a map: one finger drags it, so the browser gets no gesture at all. At
   1× the class is off again and a swipe over it scrolls the page as before. */
.figure.panning svg.scrubbable { touch-action: none; cursor: grab; }
.figure.panning svg.scrubbable:active { cursor: grabbing; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 12px; }
.legend .item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); }
.legend .item svg { width: 16px; height: 16px; flex: none; overflow: visible; }
.legend .muted-item { color: var(--ink-3); }
.legend-note {
  flex: 1 1 100%; font-size: 12px; line-height: 1.5; color: var(--ink-3); margin: 2px 0 0;
}

/* --- legend chips: the map/chart filter.
   Three states, deliberately distinguishable without colour vision (the iOS legend makes
   the same split): ON = filled capsule; OFF = dimmed, struck-through label, dashed
   outline; ABSENT = no capsule at all and not a button, because there is nothing to
   toggle — the vocabulary still reads. */
.legend .chip {
  border-radius: 999px; padding: 5px 10px; gap: 6px;
  border: 1px solid transparent; background: var(--surface-2); color: var(--ink-2);
  font: 500 12.5px/1.25 var(--sans);
}
.legend button.chip { cursor: pointer; }
.legend .chip .n {
  font: 600 10.5px/1 var(--mono); color: var(--ink-3);
  background: var(--surface-0); border-radius: 999px; padding: 3px 5px;
}
.legend .chip.off {
  background: transparent; border: 1px dashed var(--line); opacity: .62;
}
.legend .chip.off span:not(.n) { text-decoration: line-through; }
.legend .chip.off svg { opacity: .55; }
.legend .chip.off-empty {
  background: transparent; padding: 5px 0; opacity: .45; color: var(--ink-3);
}
.legend button.chip:hover { background: var(--surface-0); color: var(--ink); }
.legend .zoom-state { gap: 10px; color: var(--ink-2); flex: 1 1 100%; }
/* The zoom controls: the non-gesture way in and out, on both figures. A pinch is awkward
   one-handed, so these are real targets rather than icons — 44 px square on a phone. */
.legend .zoom-btns { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.legend .zoom-btn {
  min-width: 34px; font: 600 15px/1 var(--sans); font-variant-numeric: tabular-nums;
}
.legend .zoom-btns button { white-space: nowrap; }

/* --- the playhead readout: one line, tabular, above the speed strip. */
.readout {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 18px;
  padding: 9px 12px; margin-bottom: 10px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--line-soft);
}
.readout .ro { display: flex; align-items: baseline; gap: 5px; }
.readout .ro b { font: 650 17px/1.1 var(--sans); font-variant-numeric: tabular-nums; }
.readout .ro small { font-size: 11px; color: var(--ink-3); }
.readout .phase {
  font: 600 11px/1 var(--sans); text-transform: uppercase; letter-spacing: .06em;
  padding: 5px 9px; border-radius: 999px; color: var(--ink-3); background: var(--surface-0);
}
.readout .phase.flying {
  color: var(--foil); background: color-mix(in srgb, var(--foil) 20%, var(--surface-0));
}
.readout #clear-playhead { margin-left: auto; }

/* --- marker popover: the facts of one event, verbatim from the analysis document. */
.popover {
  position: fixed; z-index: 45; min-width: 210px;
  max-width: min(300px, calc(100vw - 24px));
  background: #0b0b0bf2; border: 1px solid var(--line); border-radius: 9px;
  box-shadow: 0 10px 30px #000000a8; font: 12.5px/1.5 var(--sans); color: var(--ink);
}
.pop-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 8px 9px 12px; border-bottom: 1px solid var(--line-soft);
}
.pop-close {
  background: transparent; border: 0; color: var(--ink-3); font-size: 17px; line-height: 1;
  padding: 4px 8px; border-radius: 6px;
}
.pop-close:hover { color: var(--ink); background: var(--surface-2); }
/* The pairing line (docs/presentation.md): which flight this mark belongs to, and what
   became of it. Tap-only, so it is never on screen uninvited — and set in the accent so it
   reads as the answer rather than as one more row of the table under it. */
.pop-pair {
  margin: 0; padding: 8px 12px 0; color: var(--series-1-tint);
  font-weight: 600; font-variant-numeric: tabular-nums;
}
.pop-rows { padding: 6px 12px 10px; display: grid; gap: 4px; }
.pop-rows > div { display: flex; justify-content: space-between; gap: 14px; }
.pop-rows span:first-child { color: var(--ink-3); }
.pop-rows span:last-child { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ tables */

/* Wide tables (turns, flight ends) scroll inside this box and never move the page.
   `overscroll-behavior-x: contain` stops the swipe turning into a Safari back-gesture. */
.table-scroll {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain; max-width: 100%;
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  text-align: right; padding: 7px 9px; white-space: nowrap;
  border-bottom: 1px solid var(--line-soft); font-variant-numeric: tabular-nums;
}
th {
  position: sticky; top: 0; background: var(--surface-1); z-index: 1;
  font: 600 10.5px/1.4 var(--sans); text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); border-bottom-color: var(--line);
}
th:first-child, td:first-child, th.l, td.l { text-align: left; }
tbody tr:hover td { background: var(--surface-2); }
td.dim { color: var(--ink-3); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font: 600 11.5px/1 var(--sans); padding: 4px 8px 4px 6px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--ink-2);
}
.pill svg { width: 11px; height: 11px; overflow: visible; }
.pill.flew_through { color: #7fd67f; border-color: #245a24; background: #11240f; }
.pill.touchdown    { color: #f6c86a; border-color: #6a5117; background: #26200c; }
.pill.fell_in      { color: #ee8b8b; border-color: #6b2626; background: #2a1414; }
/* A glide-out is the green end of the ladder — a flight that ended without drama — and
   only `unknown` (a recording that stopped) is a non-verdict grey. */
.pill.glide_out    { color: #7fd67f; border-color: #245a24; background: #11240f; }
.pill.unknown      { color: var(--ink-3); }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 20px; }
.kv .row { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px;
           border-bottom: 1px solid var(--line-soft); padding-bottom: 6px; }
.kv .row span:first-child { color: var(--ink-3); }
.kv .row span:last-child { font-variant-numeric: tabular-nums; }

.note {
  border-left: 2px solid var(--line); padding: 8px 0 8px 12px;
  color: var(--ink-3); font-size: 13px;
}

/* ----------------------------------------------------------------- the library */

.head-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

button.small-btn { font-size: 12px; padding: 5px 9px; }
button.ghost.danger { color: #ee8b8b; }
button.ghost.danger:hover { background: #2a1414; border-color: #6b2626; color: #ffb4b4; }

.lib-table td { padding-top: 9px; padding-bottom: 9px; }
.lib-table th:nth-child(2), .lib-table td:nth-child(2) { width: 99%; }
.lib-spot { display: block; }
.lib-file { display: block; font: 11.5px var(--mono); color: var(--ink-3); }
.lib-row-actions { display: flex; gap: 6px; white-space: nowrap; }

.highlight-note {
  border-left-color: var(--ink); color: var(--ink-2);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}

/* ------------------------------------------------------------------ the trends */

.sub-head {
  font-size: 12.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-3); margin: 26px 0 4px;
}
#trend-totals { margin-bottom: 6px; }
.trend-chart { margin-top: 16px; }
.trend-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.trend-unit { font: 12px var(--sans); color: var(--ink-3); }
.trend-head h4 { margin: 0; font: 600 13px/1.3 var(--sans); color: var(--ink-2); }
#records-table tbody tr { cursor: default; }

/* --------------------------------------------------------------------- icu */

.icu-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin: 14px 0 6px; }
.icu-form label { display: grid; gap: 5px; font: 600 11px/1 var(--sans);
                  text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.icu-status { font-size: 13px; color: var(--ink-2); min-height: 20px; }
.icu-status.bad { color: #ee8b8b; }
.icu-list { display: grid; gap: 6px; margin-top: 12px; }
.icu-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 12px; border: 1px solid var(--line-soft); border-radius: 8px;
  background: var(--surface-0); font-size: 13.5px;
}
.icu-row .meta { color: var(--ink-3); font-size: 12.5px; }

footer {
  border-top: 1px solid var(--line-soft);
  padding: 18px var(--pad-x-r) calc(30px + env(safe-area-inset-bottom)) var(--pad-x-l);
  color: var(--ink-3); font-size: 12.5px; text-align: center;
}

/* --------------------------------------------------------------- tooltip */

.tip {
  position: fixed; left: 0; top: 0; z-index: 40; pointer-events: none; opacity: 0;
  background: #000000e6; border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 9px; font: 12px/1.45 var(--sans); color: var(--ink);
  transition: opacity .08s; max-width: 260px;
}
.tip.on { opacity: 1; }
.tip b { font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Phones.  Reference widths: 375×667 (SE), 390×844 (15/17 Pro), 430×932 (Max).
   Two rules govern everything below:
     1. the page itself never scrolls horizontally — wide content scrolls in its own box,
        or restacks into cards;
     2. anything you tap is at least --tap tall.
   ========================================================================== */

@media (max-width: 760px) {
  :root { --pad-x: 14px; }

  /* --- topbar: brand + intervals.icu on row one, the tabs full-width on row two.
     `display: contents` dissolves .topbar-right so its three children can be ordered
     independently — otherwise the tabs and the buttons cannot split across rows. */
  .topbar {
    flex-wrap: wrap; gap: 8px 10px;
    padding: calc(10px + env(safe-area-inset-top)) var(--pad-x-r) 10px var(--pad-x-l);
  }
  .topbar-right { display: contents; }
  .brand { flex: 1 1 auto; gap: 10px; }
  .brand .sub { display: none; }               /* the tagline is desktop-only chrome */
  .views { flex: 1 1 100%; order: 3; }
  .views button { flex: 1 1 0; justify-content: center; padding: 0 6px; min-height: var(--tap); }
  .wide-only { display: none; }
  #save-session { width: 100%; }
  #icu-toggle { order: 2; min-height: var(--tap); }
  #engine-chip { order: 1; }

  /* --- the session section chips: the same control family as .views, one level down.
     Identical trough, radius and active treatment, so the row below the view tabs reads as
     the same kind of choice about a smaller thing (app-ui-review.md §3.4). Full width with
     an equal share each and the --tap floor, because §7.1's rule holds here too: anything
     you tap is at least 44 px. A quarter of a 375 px screen is ~75 px of label, which is
     what "Map · Speed" measures at 12.5 px with nothing to spare — so the type is a point
     smaller than the view tabs' and the chip is allowed to wrap to a second line rather
     than clip. Two lines at 1.2 still sit inside the 44 px box. */
  .sections {
    display: flex; gap: 2px; margin: 14px 0;
    background: var(--surface-2); border-radius: 8px; padding: 3px;
  }
  .sections button {
    flex: 1 1 0; min-width: 0; background: transparent; color: var(--ink-3); border: 0;
    border-radius: 6px; padding: 0 5px; min-height: var(--tap);
    display: inline-flex; align-items: center; justify-content: center;
    font: 600 12.5px/1.2 var(--sans); text-align: center;
  }
  .sections button[aria-current=page] { background: var(--surface-0); color: var(--ink); }

  main { padding-top: 16px; padding-bottom: 28px; }
  main > div { gap: 14px; }
  .panel { padding: 14px; border-radius: 8px; }
  .panel-head { gap: 10px; margin-bottom: 12px; }
  /* The panel head stacks: title block, then the badges + primary action, full bleed.
     (`.panel-head > div` makes both halves grids; the 1fr column is what lets the primary
     action span the card instead of shrink-wrapping the badge row above it.) */
  .panel-head > div { grid-template-columns: minmax(0, 1fr); }
  .head-right { flex: 1 1 100%; justify-content: flex-start; }

  /* --- touch targets */
  button, .btn { min-height: var(--tap); padding: 10px 14px; }
  button.small-btn { min-height: 38px; padding: 6px 11px; font-size: 12.5px; }
  .dropzone { padding: 22px 14px; }
  .dropzone .btn { width: 100%; }
  .drop-hint { width: 100%; }
  /* The example link is a real tap target (the 44 px minimum still applies) but it sits
     inside a sentence, so it keeps its inline metrics rather than the button padding —
     14 px of side padding on a word mid-sentence reads as a typo, not as a control. */
  .linkish { min-height: var(--tap); padding: 0; }
  /* Cancel goes full width like every other phone-width action: it is the only way out of
     a several-minute analysis and it should not be a small target. */
  .progress-foot button { width: 100%; }

  /* --- iOS zooms the whole page when a focused input is under 16px. */
  input[type=text], input[type=password] { font-size: 16px; min-width: 0; width: 100%; }
  .icu-form { gap: 12px; }
  .icu-form label { width: 100%; }
  .icu-form button { width: 100%; }
  .icu-row { flex-wrap: wrap; gap: 8px; }
  .icu-row button { width: 100%; }

  /* The key block keeps its rows on a phone — three numbers across a 430 px screen is
     still readable at 22 px, and reflowing them would lose the row grouping that carries
     the meaning. Only the type comes down. */
  .keys { gap: 12px; }
  .key-row { gap: 10px; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
  .key .v { font-size: 22px; }
  .key.hero .v { font-size: 27px; }

  .tiles { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); }
  .tile { padding: 11px 12px; }
  .tile .v { font-size: 19px; }

  .legend { gap: 8px 10px; }
  /* The chips are the map's filter, so they are real touch targets like every other
     control — 44 px tall, wrapping into as many rows as it takes. */
  .legend button.chip { min-height: var(--tap); padding: 8px 12px; font-size: 13px; }
  .legend .chip.off-empty { padding: 6px 0; }
  /* The zoom buttons are the fallback for a gesture that is awkward one-handed, so they
     are full touch targets, not 12 px chips. */
  .legend .zoom-btn { min-width: var(--tap); min-height: var(--tap); font-size: 18px; }
  .legend .zoom-state button.small-btn { min-height: var(--tap); }
  .readout { padding: 10px 12px; gap: 8px 14px; }
  .readout .ro b { font-size: 16px; }
  .readout #clear-playhead { margin-left: 0; flex: 1 1 100%; }
  .kv { grid-template-columns: 1fr; gap: 8px; }

  .update-banner { padding: 10px var(--pad-x-r) 10px var(--pad-x-l); }
  .update-actions { width: 100%; }
  .update-actions button { flex: 1 1 0; }

  footer { padding-top: 14px; }

  /* --- restacked tables.
     The turns / flight-ends tables stay tabular and scroll sideways in their box: 34 rows
     × 16 fields as cards would be a mile of page. The two *browsing* tables (library rows,
     records) become cards instead, because on a phone they are read one row at a time.
     Every <td> carries data-th, written by the same code that writes the <th>. */
  table.stack-sm { display: block; font-size: 13.5px; }
  table.stack-sm thead { display: none; }
  table.stack-sm tbody { display: block; }
  table.stack-sm tr {
    display: block; background: var(--surface-0);
    border: 1px solid var(--line-soft); border-radius: 8px;
    padding: 4px 12px 8px; margin-bottom: 10px;
  }
  table.stack-sm tr:last-child { margin-bottom: 0; }
  table.stack-sm td {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    text-align: right; white-space: normal; padding: 6px 0;
    border-bottom: 1px solid var(--line-soft);
  }
  table.stack-sm td:last-child { border-bottom: 0; }
  table.stack-sm td:nth-child(n) { width: auto; }   /* beats .lib-table td:nth-child(2) */
  table.stack-sm td::before {
    content: attr(data-th); flex: none; text-align: left;
    font: 600 10.5px/1.4 var(--sans); text-transform: uppercase; letter-spacing: .06em;
    color: var(--ink-3); padding-top: 2px;
  }
  table.stack-sm td[data-th=""]::before { display: none; }
  /* The row's headline (date, or the record's name) leads the card at full width. */
  table.stack-sm td.stack-lead {
    display: block; text-align: left; font-weight: 650; font-size: 14.5px;
    padding-top: 8px; padding-bottom: 8px;
  }
  table.stack-sm td.stack-lead::before { display: none; }
  /* A cell whose own content is already two stacked lines (spot + filename): let it flow. */
  table.stack-sm td.stack-block { display: block; text-align: left; padding-top: 0; }
  table.stack-sm td.stack-block::before { display: none; }
  table.stack-sm td.stack-actions { display: block; padding-top: 10px; }
  table.stack-sm td.lib-row-actions {         /* four actions: two rows of two */
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;
    white-space: normal; padding-top: 10px;
  }
  table.stack-sm td.stack-actions button { width: 100%; }
  .lib-file { word-break: break-all; }
}

/* Below ~560 the engine chip is the first thing that can go: it is a diagnostic, and the
   same string is in the console and in the PWA update banner. */
@media (max-width: 560px) {
  #engine-chip { display: none !important; }
}

/* Landscape phone: the sticky topbar would otherwise eat a third of the screen. */
@media (max-height: 460px) and (orientation: landscape) {
  .topbar { position: static; }
}
