/* FT — Flight Tracker. Dark aviation-console default, light mode as a first-class
   peer. Every colour is a variable so the theme switch is a single attribute flip. */

:root {
  --bg: #0b1017;
  --panel: rgba(16, 23, 33, 0.92);
  --panel-solid: #101721;
  --panel-line: rgba(255, 255, 255, 0.10);
  --ink: #e8eef6;
  --ink-dim: #93a3b8;
  --ink-faint: #64748b;
  --accent: #38bdf8;
  --accent-ink: #04141f;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --chip: rgba(255, 255, 255, 0.06);
  --chip-on: rgba(56, 189, 248, 0.18);
  --field: rgba(255, 255, 255, 0.05);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  --radius: 12px;
  --topbar-h: 56px;

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #eef2f7;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-solid: #ffffff;
  --panel-line: rgba(15, 23, 42, 0.12);
  --ink: #0f172a;
  --ink-dim: #475569;
  --ink-faint: #94a3b8;
  --accent: #0284c7;
  --accent-ink: #ffffff;
  --good: #059669;
  --warn: #b45309;
  --bad: #dc2626;
  --chip: rgba(15, 23, 42, 0.06);
  --chip-on: rgba(2, 132, 199, 0.15);
  --field: rgba(15, 23, 42, 0.04);
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.18);

  color-scheme: light;
}

* { box-sizing: border-box; }

/* Any author `display` beats the UA sheet's `[hidden] { display: none }`, which
   silently leaves panels like .drawer (display:flex) on screen. Restate it. */
[hidden] { display: none !important; }

/* A full-screen map is an app surface, not a document. Pinning the body and
   killing overscroll stops the whole page being panned or rubber-banded around
   underneath the map — which reads as the app sliding off screen. */
html {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Gestures over the map belong to MapLibre. Without this the browser claims
   two-finger pans and pinches for itself and drags the page instead. */
#map { touch-action: none; }

/* Panels still scroll, but their scroll must not chain to the document. */
.drawer-body,
.option-list,
.search-results {
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

/* Removes the double-tap-to-zoom delay and its accidental page zoom. */
button, .chip, .seg-btn, .tb, .btn { touch-action: manipulation; }

.mono { font-family: "Cascadia Mono", ui-monospace, "SF Mono", Consolas, monospace; }
.muted { color: var(--ink-dim); }
.sep { color: var(--ink-faint); margin: 0 2px; }

#map { position: absolute; inset: 0; }

/* MapLibre's own chrome needs to sit under ours. */
.maplibregl-ctrl-bottom-right { margin-bottom: 4px; }
.maplibregl-ctrl-attrib { font-size: 10px; opacity: 0.7; }
.maplibregl-ctrl-top-right { top: calc(var(--topbar-h) + 8px); }

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

.topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--panel-line);
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.brand-mark { width: 22px; height: 22px; color: var(--accent); fill: none; }
.brand-name { font-weight: 650; letter-spacing: 0.2px; white-space: nowrap; }

/* min-width:0 is load-bearing: a flex item defaults to min-width:auto and
   refuses to shrink below its content, so the search box pushed the topbar
   buttons off the right edge on narrow screens instead of giving up width. */
.search-wrap { position: relative; flex: 1 1 auto; min-width: 0; max-width: 420px; }
#btn-search { display: none; }

#search {
  width: 100%;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-line);
  background: var(--field);
  color: var(--ink);
  font-size: 13px;
  outline: none;
}
#search:focus { border-color: var(--accent); }
#search::-webkit-search-cancel-button { filter: invert(0.5); }

.search-results {
  position: absolute;
  top: 40px; left: 0; right: 0;
  max-height: 320px;
  overflow-y: auto;
  background: var(--panel-solid);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 4px;
  z-index: 40;
}
.search-results .row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 7px 10px; border-radius: 8px; cursor: pointer;
}
.search-results .row:hover, .search-results .row.on { background: var(--chip); }
.search-results .row b { font-family: "Cascadia Mono", ui-monospace, monospace; }
.search-results .row small { color: var(--ink-dim); margin-left: auto; }
.search-results .empty { padding: 12px; color: var(--ink-dim); text-align: center; }

.topbar-actions { display: flex; gap: 6px; flex: 0 0 auto; margin-left: auto; }

.tb {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-line);
  background: var(--field);
  color: var(--ink);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.tb:hover { border-color: var(--accent); }
.tb[aria-pressed="true"] { background: var(--chip-on); border-color: var(--accent); color: var(--accent); }
.tb svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Mode switch lives in the topbar next to the other controls, so it matches
   their height rather than the taller segmented controls in the panels. */
.mode-seg { flex: 0 0 auto; height: 34px; align-items: center; }
.mode-seg .seg-btn { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; height: 28px; white-space: nowrap; }
.mode-ico { width: 15px; height: 15px; display: none; fill: currentColor; }

@media (max-width: 900px) {
  .mode-seg .seg-btn { padding: 0 9px; font-size: 11.5px; }
}

.pill {
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

/* Spin, with its speed stepper. The minus and plus are deliberately narrow —
   the topbar is already tight at 360px, so they read as affordances on the
   button rather than as two more buttons competing with it. */
.spin-group { display: flex; align-items: center; flex: 0 0 auto; }
.spin-main { border-radius: 0; }
.spin-step {
  width: 22px; height: 34px;
  border: 1px solid var(--panel-line);
  background: var(--field);
  color: var(--ink-dim);
  font-size: 14px; line-height: 1; cursor: pointer;
}
.spin-step:hover { color: var(--accent); border-color: var(--accent); }
.spin-step:disabled { opacity: 0.35; cursor: default; }
#spin-down { border-radius: 999px 0 0 999px; border-right: 0; }
#spin-up { border-radius: 0 999px 999px 0; border-left: 0; }
.spin-level {
  min-width: 14px; padding: 0 3px;
  font-size: 11px; font-weight: 700;
  color: var(--accent);
}

/* ------------------------------------------------- 2D / 3D map mode switch */

.map-mode { display: flex; overflow: hidden; }
.map-mode button {
  width: 29px; height: 29px;
  border: 0; background: transparent;
  color: #333; font-size: 11px; font-weight: 700;
  cursor: pointer;
}
.map-base button { width: auto; min-width: 42px; height: 26px; padding: 0 7px; font-size: 10px; }
.map-mode button + button { border-left: 1px solid rgba(0, 0, 0, 0.1); }
.map-mode button:hover { background: rgba(0, 0, 0, 0.05); }
.map-mode button.on { background: var(--accent); color: var(--accent-ink); }

/* Four basemaps read better as a 2x2 block than a long row hanging off the
   edge of the map. Dividers are drawn per cell rather than with the adjacent
   sibling rule above, which only knows about a single row. */
.map-base { display: grid; grid-template-columns: 1fr 1fr; }
.map-base button + button { border-left: 0; }
.map-base button:nth-child(odd) { border-right: 1px solid rgba(0, 0, 0, 0.1); }
.map-base button:nth-child(-n + 2) { border-bottom: 1px solid rgba(0, 0, 0, 0.1); }

/* MapLibre's control chrome is light-on-white in both themes, so the switch
   matches it rather than the app's panels. */
:root[data-theme="dark"] .map-mode button { color: #333; }

/* --------------------------------------------------------------- statusbar */

/* Stacked in a column wrapper rather than each pinned to its own offset: the
   status bar wraps to two lines on narrow screens, and any hardcoded top for
   the panel beneath it then overlaps. */
.hud-left {
  position: absolute;
  top: calc(var(--topbar-h) + 8px); left: 12px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  z-index: 20;
  pointer-events: none;
}
.hud-left > * { pointer-events: auto; }

.statusbar {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 12px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  font-size: 12px;
  z-index: 20;
  box-shadow: var(--shadow);
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-faint); margin-right: 4px;
  transition: background 0.3s;
}
.dot.live { background: var(--good); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18); }
.dot.err  { background: var(--bad);  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.18); }

/* ----------------------------------------------------------------- reentries
   Sits directly beneath the status bar and only in satellite mode, where the
   counts above it are satellites rather than aircraft. */

.decaybar {
  width: 232px;
  padding: 9px 12px 10px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 20;
}

.decay-head { display: flex; align-items: center; gap: 8px; }
.decay-title {
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.7px; text-transform: uppercase;
  color: var(--ink-dim); white-space: nowrap;
}
.decay-spark { flex: 1 1 auto; height: 18px; overflow: visible; }
.decay-spark polyline { fill: none; stroke: var(--warn); stroke-width: 1.4; stroke-linejoin: round; }
.decay-spark .base { stroke: var(--panel-line); stroke-width: 1; }

.decay-stats {
  display: flex; justify-content: space-between; gap: 4px;
  margin-top: 7px;
}
.decay-stat { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.decay-stat b {
  font-family: "Cascadia Mono", ui-monospace, monospace;
  font-size: 14px; font-weight: 700; line-height: 1.1;
}
.decay-stat small { font-size: 9.5px; color: var(--ink-faint); margin-top: 1px; }

.decay-note { margin-top: 7px; font-size: 9.5px; line-height: 1.35; color: var(--ink-faint); }

@media (max-width: 640px) {
  .decaybar { width: auto; align-self: stretch; }
}

/* ------------------------------------------------------------------ drawer */

.drawer {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 380px; max-width: 92vw;
  display: flex; flex-direction: column;
  background: var(--panel-solid);
  border-left: 1px solid var(--panel-line);
  box-shadow: var(--shadow);
  z-index: 60;
  animation: slide-in 0.18s ease-out;
}
/* Rises rather than sliding in from the right: a right-anchored panel animating
   on translateX overflows the viewport for the length of the animation, which
   shows up as phantom horizontal overflow in layout audits. */
@keyframes slide-in { from { transform: translateY(10px); opacity: 0; } }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--panel-line);
}
.drawer-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 4px 16px 16px; }
.drawer-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--panel-line);
}

.icon-btn {
  width: 30px; height: 30px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--ink-dim);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: var(--chip); color: var(--ink); }

.fgroup { padding: 14px 0; border-bottom: 1px solid var(--panel-line); }
.fgroup:last-child { border-bottom: 0; }
.fgroup h3 {
  margin: 0 0 10px;
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.7px; text-transform: uppercase;
  color: var(--ink-dim);
}
.hint { margin: 8px 0 0; font-size: 11.5px; color: var(--ink-faint); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--panel-line);
  background: var(--chip);
  color: var(--ink-dim);
  font-size: 12.5px; cursor: pointer;
}
.chip:hover { color: var(--ink); }
.chip.on { background: var(--chip-on); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip .sw {
  display: inline-block;
  width: 9px; height: 9px;
  margin-right: 6px;
  border-radius: 50%;
  vertical-align: baseline;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}
.chip .sw[hidden] { display: none; }

.legend-kinds { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 6px; margin-top: 6px; }
.legend-kinds .lk { display: flex; align-items: center; gap: 5px; font-size: 10px; color: var(--ink-dim); white-space: nowrap; }
.legend-kinds .lk i { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }

.field {
  width: 100%; height: 34px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid var(--panel-line);
  background: var(--field);
  color: var(--ink);
  font-size: 13px; outline: none;
}
.field:focus { border-color: var(--accent); }
.field.small { width: auto; min-width: 92px; height: 30px; }
select.field { cursor: pointer; }

.option-list {
  max-height: 240px; overflow-y: auto;
  margin-top: 8px;
  border: 1px solid var(--panel-line);
  border-radius: 9px;
}
.option-list .opt {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; cursor: pointer; font-size: 13px;
}
.option-list .opt:hover { background: var(--chip); }
.option-list .opt-group {
  position: sticky; top: 0; z-index: 1;
  padding: 6px 10px;
  background: var(--panel-solid);
  border-bottom: 1px solid var(--panel-line);
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.7px; text-transform: uppercase;
  color: var(--ink-faint);
}
.option-list .opt.on { background: var(--chip-on); color: var(--accent); }
.option-list .opt code {
  font-family: "Cascadia Mono", ui-monospace, monospace;
  font-size: 11px; color: var(--ink-faint);
  min-width: 30px;
}
.option-list .opt .kind { margin-left: auto; font-size: 10.5px; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.4px; }

.selected-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.selected-list:empty { display: none; }
.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  background: var(--chip-on);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 12px; font-weight: 600;
}
.tag button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; }

.range-row { display: flex; gap: 12px; flex-wrap: wrap; }
.range-row label, .row-label { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-dim); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 9px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

.seg { display: inline-flex; padding: 3px; gap: 3px; background: var(--field); border-radius: 10px; border: 1px solid var(--panel-line); }
.seg-btn {
  padding: 6px 14px; border: 0; border-radius: 7px;
  background: transparent; color: var(--ink-dim);
  font-size: 12.5px; font-weight: 500; cursor: pointer;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.btn {
  height: 34px; padding: 0 16px;
  border-radius: 9px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-ink);
  font-size: 13px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; text-decoration: none;
}
.btn.ghost { background: transparent; border-color: var(--panel-line); color: var(--ink); }
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn[aria-pressed="true"] { background: var(--chip-on); border-color: var(--accent); color: var(--accent); }

/* ------------------------------------------------------------------ detail */

.detail {
  position: absolute;
  left: 12px; bottom: 12px;
  width: 340px; max-width: calc(100vw - 24px);
  padding: 16px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--panel-line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 25;
  animation: slide-in 0.16s ease-out;
}
.detail-close { position: absolute; top: 8px; right: 8px; }
.detail-head { display: flex; align-items: flex-start; gap: 12px; padding-right: 28px; }
.d-callsign { font-size: 20px; font-weight: 700; letter-spacing: 0.5px; }
.d-operator { font-size: 12.5px; color: var(--ink-dim); margin-top: 2px; }
.d-badge {
  margin-left: auto; padding: 3px 9px;
  border-radius: 999px; background: var(--chip);
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--ink-dim); white-space: nowrap;
}

.d-route {
  margin-top: 12px; padding: 9px 11px;
  background: var(--chip);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
}
.d-route-pair { display: flex; align-items: center; gap: 10px; }
.d-chain {
  margin-top: 7px; padding-top: 6px;
  border-top: 1px solid var(--panel-line);
  font-size: 10.5px; color: var(--ink-faint);
  letter-spacing: 0.3px;
}
.d-route-end { flex: 1 1 0; min-width: 0; }
.d-route-end span { display: block; font-size: 15px; font-weight: 700; letter-spacing: 0.5px; }
.d-route-end small {
  display: block; margin-top: 1px;
  font-size: 11px; color: var(--ink-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.d-route-end:last-child { text-align: right; }
.d-route-arrow { color: var(--accent); font-size: 15px; flex: 0 0 auto; }

.d-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px 14px; margin: 14px 0 0;
}
.d-grid .wide { grid-column: 1 / -1; }
.d-grid dt { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--ink-faint); }
.d-grid dd { margin: 2px 0 0; font-size: 13.5px; font-weight: 600; }
.detail-actions { margin-top: 14px; display: flex; gap: 8px; }

/* ------------------------------------------------------------------ legend */

.legend {
  position: absolute;
  right: 12px; bottom: 26px;
  /* Sized to content rather than fixed: the category key is two columns of
     labels, and a hard width made the right-hand column spill out of the box. */
  min-width: 150px; max-width: 210px;
  padding: 9px 11px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  z-index: 20;
  font-size: 11px;
}
.legend-title { color: var(--ink-dim); font-size: 10px; text-transform: uppercase; letter-spacing: 0.6px; }
.legend-bar {
  height: 7px; margin: 6px 0 4px; border-radius: 4px;
  background: linear-gradient(90deg, #22d3ee 0%, #34d399 25%, #facc15 50%, #fb923c 75%, #f472b6 100%);
}
.legend-scale { display: flex; justify-content: space-between; color: var(--ink-faint); font-size: 10px; }

/* ------------------------------------------------------------- scrim/toast */

.scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 50; }

.toast {
  position: absolute;
  bottom: 22px; left: 50%; transform: translateX(-50%);
  padding: 9px 16px;
  background: var(--panel-solid);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 13px;
  z-index: 70;
}
.toast.bad { border-color: var(--bad); color: var(--bad); }

/* ---------------------------------------------------------------- responsive
   Verified at 1536 / 1366 / 1317 / 1152 (13.8" Surface) and mobile. */

@media (max-width: 1152px) {
  .legend { min-width: 128px; max-width: 190px; }
}

@media (max-width: 900px) {
  .tb-label { display: none; }
  .tb { padding: 0 10px; }
  .search-wrap { max-width: none; }
}

@media (max-width: 640px) {
  :root { --topbar-h: 52px; }
  .topbar { gap: 6px; }

  /* Below this width the search box, the mode switch, the spin stepper and four
     buttons cannot all share one row — the search was being squeezed to zero.
     It becomes an icon that expands over the bar, which is the one element that
     works fine as an overlay. */
  #btn-search { display: inline-flex; }

  /* Every control has to fit one row down to ~360px, so trim the padding
     rather than dropping a feature. */
  .tb { padding: 0 8px; }
  .spin-step { width: 18px; }
  .spin-level { min-width: 10px; padding: 0 2px; font-size: 10px; }
  .mode-seg .seg-btn { padding: 0 8px; }
  .topbar { padding: 0 6px; }

  /* Nine controls will not fit one row on the narrowest phones. The spin
     steppers drop out first because the same setting has a slider in
     Settings, so the capability survives; the Spin toggle and its level
     readout stay. */
  @media (max-width: 400px) {
    .spin-step { display: none; }
    /* A third mode button landed here; everything gets a little tighter so the
       row still fits an iPhone-width viewport with nothing dropped. */
    .topbar { gap: 4px; padding: 0 4px; }
    .tb { padding: 0 6px; }
    .mode-seg { padding: 2px; gap: 2px; }
    .mode-seg .seg-btn { padding: 0 7px; }
    .spin-level { display: none; }
  }

  .search-wrap {
    position: absolute; left: 8px; right: 8px; top: 9px;
    max-width: none; z-index: 35; display: none;
  }
  .topbar.searching .search-wrap { display: block; }
  .topbar.searching .brand,
  .topbar.searching .topbar-actions { visibility: hidden; }
  /* Icons only: the two word labels were the widest thing in the topbar and
     squeezed the search box down to a few unusable pixels. */
  .mode-label { display: none; }
  .mode-ico { display: block; }
  .mode-seg .seg-btn { padding: 0 10px; }
  #search { font-size: 12px; padding: 0 10px; }
  .brand-name { display: none; }
  .hud-left { left: 8px; right: 8px; }
  .statusbar { justify-content: center; font-size: 11px; align-self: stretch; }
  .drawer { width: 100%; max-width: 100%; }
  .legend { display: none; }
  .detail {
    left: 8px; right: 8px; bottom: 8px;
    width: auto;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .d-grid { grid-template-columns: 1fr 1fr; gap: 9px 12px; }
  .topbar { padding: 0 8px; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .drawer, .detail { animation: none; }
}

/* ------------------------------------------------------------------- stats */

.stat-row { display: flex; gap: 10px; }
.stat-big { flex: 1 1 0; min-width: 0; text-align: center; padding: 8px 4px; background: var(--chip); border-radius: 10px; }
.stat-big b {
  display: block;
  font-family: "Cascadia Mono", ui-monospace, monospace;
  font-size: 17px; font-weight: 700; line-height: 1.15;
}
.stat-big small { display: block; margin-top: 2px; font-size: 10px; color: var(--ink-faint); }

.stat-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 2px; }
.stat-table th, .stat-table td { padding: 5px 4px; text-align: right; white-space: nowrap; }
.stat-table thead th {
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase;
  color: var(--ink-faint); border-bottom: 1px solid var(--panel-line); vertical-align: bottom;
}
.stat-table .th-sub { font-weight: 500; letter-spacing: 0; text-transform: none; }
.stat-table tbody th { text-align: left; font-weight: 600; color: var(--ink-dim); }
.stat-table tbody td { font-family: "Cascadia Mono", ui-monospace, monospace; }
.stat-table tbody tr + tr th, .stat-table tbody tr + tr td { border-top: 1px solid var(--panel-line); }
.stat-table.wide-first th:first-child, .stat-table.wide-first td:first-child {
  text-align: left; white-space: normal; width: 40%;
}
.stat-table .sub { display: block; font-size: 10px; color: var(--ink-faint); font-weight: 400; }

.year-bars { display: flex; flex-direction: column; gap: 5px; margin-top: 2px; }
.year-bar { display: flex; align-items: center; gap: 8px; font-size: 11.5px; }
.year-bar .yr { font-family: "Cascadia Mono", ui-monospace, monospace; color: var(--ink-dim); width: 34px; }
.year-bar .track { flex: 1 1 auto; height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.year-bar .fill { height: 100%; background: var(--accent); border-radius: 4px; }
.year-bar .n { font-family: "Cascadia Mono", ui-monospace, monospace; width: 42px; text-align: right; }

input[type="range"].small { width: 96px; min-width: 0; padding: 0; accent-color: var(--accent); }

/* ------------------------------------------------------------------ ground */

/* Agency chips carry a colour swatch like constellation chips; the transit-mode
   chips reuse the same .chip/.sw pattern so the three filter families read as
   one system. */
#agency-chips .chip .sw, #gmode-chips .chip .sw { display: inline-block; }
.chip .fly {
  margin-left: 6px; padding: 0 4px;
  border-left: 1px solid var(--panel-line);
  color: var(--ink-dim); font-size: 13px; line-height: 1;
}
.chip .fly:hover { color: var(--accent); }
.chip.on .fly { border-left-color: rgba(56, 189, 248, 0.35); }
