/* ============================================================
   World Clock — GPX Stream design system
   Token subset lifted from ~/.claude/skills/gpx-stream-design-system/tokens.css
   Brand red is a LOCKED hex. Ramps stay oklch. Do not eyeball new colors.
   ============================================================ */

@font-face {
  font-family: "Tactic Sans Extended";
  src: url("fonts/TacticSansExtExd-Blk.ttf") format("truetype");
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "SF Mono";
  src: url("fonts/SFMonoRegular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "SF Mono";
  src: url("fonts/SFMonoMedium.otf") format("opentype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "SF Mono";
  src: url("fonts/SFMonoBold.otf") format("opentype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Brand — LOCKED */
  --gpx-red: #ef3340;
  --gpx-red-hover: #f55f66;
  --gpx-red-active: #d12029;

  --red-500: #ef3340;
  --red-700: oklch(46% 0.18 24.4);
  --red-800: oklch(36% 0.14 24.4);
  --red-900: oklch(26% 0.1 24.4);

  /* Neutral (warm) */
  --neutral-0: #ffffff;
  --neutral-50: oklch(97% 0.006 60);
  --neutral-100: oklch(93% 0.01 60);
  --neutral-200: oklch(86% 0.015 60);
  --neutral-300: oklch(75% 0.015 60);
  --neutral-400: oklch(58% 0.012 60);
  --neutral-500: oklch(43% 0.01 60);
  --neutral-600: oklch(31% 0.008 60);
  --neutral-700: oklch(22% 0.006 60);
  --neutral-800: oklch(16% 0.005 60);
  --neutral-900: oklch(10% 0.004 60);

  /* Status */
  --success-500: #12b76a;
  --success-900: oklch(30% 0.08 155);
  --warning-500: #f79009;
  --warning-900: oklch(34% 0.09 45);
  --error-500: #e04438;
  --error-900: oklch(26% 0.09 28);
  --telemetry-400: oklch(67% 0.13 215);
  --telemetry-900: oklch(23% 0.05 215);

  /* Semantic surfaces — dark is the default stage */
  --bg: var(--neutral-900);
  --surface: var(--neutral-800);
  --surface-raised: var(--neutral-700);
  --border: var(--neutral-700);
  --border-subtle: rgba(41, 37, 31, 0.5);

  --fg-1: var(--neutral-0);
  --fg-2: var(--neutral-200);
  --fg-3: var(--neutral-300);
  --fg-4: var(--neutral-400);

  --font-display: "Tactic Sans Extended", "Barlow Condensed", sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, monospace;

  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 8px;
  --radius-full: 9999px;

  --shadow-sm: 0 0 0 1px rgb(255 255 255 / 0.04) inset, 0 2px 4px 0 rgb(0 0 0 / 0.85),
    0 1px 0 0 rgb(255 255 255 / 0.06) inset;
  --shadow-lg: 0 0 0 1px rgb(255 255 255 / 0.06) inset, 0 1px 0 0 rgb(255 255 255 / 0.1) inset,
    0 28px 48px -10px rgb(0 0 0 / 1), 0 12px 24px -6px rgb(0 0 0 / 0.9);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;

  --ease-out: cubic-bezier(0, 0, 0.2, 1);
  --dur-fast: 120ms;

  /* ---------- Card watermark + asphalt, tuned by eye ----------
     Circuits sit at 0.01 because the knockout does the work of making the
     shape read; the generated city plans are strokes with no knockout, so
     they need 0.07 to show at all. */
  --outline-alpha: 0.01;
  --outline-alpha-hover: 0.04;
  --outline-alpha-source: 0.08;
  --city-alpha: 0.07;
  --city-alpha-hover: 0.154;
  --city-alpha-source: 0.238;
  --outline-scale: 1.3;
  --outline-x: 3%;
  --outline-y: 0%;
  --outline-rotate: -70deg;
  --map-knock: 1;

  /* Grain at full strength, pure black, coarse enough not to read as static.
     Baked from feTurbulence baseFrequency 0.361 / 3 octaves on a 319px tile. */
  --grit-alpha: 1;
  --grit-color: #000000;
  /* Colour of the circuit/street watermark. Flips to ink in light mode. */
  --map-ink: #ffffff;
  --grit-size: 319px;
  --grit-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20width%3D%27319%27%20height%3D%27319%27%3E%3Cfilter%20id%3D%27n%27%3E%3CfeTurbulence%20type%3D%27fractalNoise%27%20baseFrequency%3D%270.361%27%20numOctaves%3D%273%27%20stitchTiles%3D%27stitch%27%2F%3E%3CfeColorMatrix%20type%3D%27matrix%27%20values%3D%270%200%200%200%201%200%200%200%200%201%200%200%200%200%201%201%200%200%200%200%27%2F%3E%3CfeComponentTransfer%3E%3CfeFuncA%20type%3D%27linear%27%20slope%3D%271.9%27%20intercept%3D%27-0.42%27%2F%3E%3C%2FfeComponentTransfer%3E%3C%2Ffilter%3E%3Crect%20width%3D%27100%25%27%20height%3D%27100%25%27%20filter%3D%27url(%23n)%27%2F%3E%3C%2Fsvg%3E");
}

:root,
:root[data-theme="dark"] {
  color-scheme: dark;
}

/* ---------- Light theme ----------
   Declared twice because plain CSS cannot share a block: once for an explicit
   [data-theme="light"], once under prefers-color-scheme for the auto setting.
   Keep the two lists identical. */
:root[data-theme="light"] {
  --bg: var(--neutral-50);
  --surface: var(--neutral-0);
  --surface-raised: var(--neutral-0);
  --border: var(--neutral-200);
  --border-subtle: rgba(188, 180, 169, 0.5);
  --fg-1: var(--neutral-900);
  --fg-2: var(--neutral-700);
  --fg-3: var(--neutral-500);
  --fg-4: var(--neutral-400);
  --red-900: oklch(94% 0.03 24.4);
  --warning-900: oklch(95% 0.04 75);
  --telemetry-900: oklch(95% 0.03 215);
  --success-900: oklch(94% 0.04 155);
  color-scheme: light;
  --shadow-sm: 0 1px 2px 0 rgb(11 9 8 / 0.05);
  --shadow-lg: 0 4px 6px -2px rgb(11 9 8 / 0.05), 0 12px 24px -4px rgb(11 9 8 / 0.12);
  /* Watermarks are drawn in ink, not light, once the card is white. */
  --map-ink: #000000;
  /* No asphalt on a white card. The grain is a dark-surface texture — on white
     it reads as dirt on the screen rather than tarmac, so light mode drops it
     and leans on the watermark instead. */
  --grit-alpha: 0;
  /* Ink on white carries far further than light on near-black, so every step
     is smaller here — and the hover step has to sit ABOVE the resting value.
     Reusing the dark literals made hover paler than rest. */
  --outline-alpha: 0.055;
  --outline-alpha-hover: 0.09;
  --outline-alpha-source: 0.14;
  --city-alpha: 0.11;
  --city-alpha-hover: 0.15;
  --city-alpha-source: 0.2;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]):not([data-theme="light"]) {
    --bg: var(--neutral-50);
    --surface: var(--neutral-0);
    --surface-raised: var(--neutral-0);
    --border: var(--neutral-200);
    --border-subtle: rgba(188, 180, 169, 0.5);
    --fg-1: var(--neutral-900);
    --fg-2: var(--neutral-700);
    --fg-3: var(--neutral-500);
    --fg-4: var(--neutral-400);
    --red-900: oklch(94% 0.03 24.4);
    --warning-900: oklch(95% 0.04 75);
    --telemetry-900: oklch(95% 0.03 215);
    --success-900: oklch(94% 0.04 155);
    color-scheme: light;
    --shadow-sm: 0 1px 2px 0 rgb(11 9 8 / 0.05);
    --shadow-lg: 0 4px 6px -2px rgb(11 9 8 / 0.05), 0 12px 24px -4px rgb(11 9 8 / 0.12);
    --map-ink: #000000;
    --grit-alpha: 0;
    --outline-alpha: 0.055;
    --outline-alpha-hover: 0.09;
    --outline-alpha-source: 0.14;
    --city-alpha: 0.11;
    --city-alpha-hover: 0.15;
    --city-alpha-source: 0.2;
  }
}

* {
  box-sizing: border-box;
}

/* Any `display` rule outranks the UA's [hidden] {display:none}. Without this,
   hidden flex/grid elements (the DST warning, the "back to now" button) render
   as empty boxes. */
[hidden] {
  display: none !important;
}

/* Keeps its box, so showing and hiding it never reflows anything. */
.invisible {
  visibility: hidden;
  pointer-events: none;
}

html {
  /* Reserve the scrollbar gutter permanently. Opening the picker sheet adds
     enough page height to summon a scrollbar, which otherwise narrows the
     viewport and shifts the whole grid sideways. */
  scrollbar-gutter: stable;
}

/* Sticky alone does not pin a footer on a screen taller than the content —
   there is nothing to stick to, so it sits wherever the cards happen to end.
   A full-height flex column pushes it down in that case; sticky then takes
   over once the grid is long enough to scroll. */
body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg-1);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 20px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.wrap {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  /* No bottom padding: the sticky footer occupies that space itself. */
  padding: 0 var(--space-4);
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
}

/* Controls stay put while the grid scrolls under them. The background is
   opaque so tiles do not show through, and the search dropdown needs a higher
   stacking context than the tiles it overlaps. */
.sticky-top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding: var(--space-6) 0 var(--space-3);
  margin-bottom: var(--space-3);
}
/* A whisper of a fade so tiles scrolling underneath are not hard-chopped —
   any stronger and it reads as a drop shadow sitting on the top row. */
.sticky-top::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  height: 10px;
  background: linear-gradient(color-mix(in srgb, var(--bg) 55%, transparent), transparent);
  pointer-events: none;
}

svg {
  display: block;
  flex-shrink: 0;
}

button {
  font: inherit;
  font-family: var(--font-mono);
  cursor: pointer;
  border: 1px solid transparent;
  background: none;
  color: inherit;
  border-radius: var(--radius-md);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out);
}
button:focus-visible {
  outline: 2px solid var(--gpx-red);
  outline-offset: 2px;
}

/* ── Header ──────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

h1 {
  font-family: var(--font-display);
  font-size: 26px;
  line-height: 30px;
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 0;
  color: var(--fg-1);
}
/* Drawn, not typed. Tactic Sans Extended's period has a negative left
   sidebearing, so the character tucked under the preceding E and sat off the
   baseline. A square sized in em scales with the heading and lands exactly
   where it is told. */
h1 .hot {
  color: var(--gpx-red);
}

h1 .dot {
  display: inline-block;
  width: 0.16em;
  height: 0.16em;
  /* Clear of the E at any heading size; em keeps the gap proportional. */
  margin-left: 0.2em;
  /* Uppercase glyphs rest on the baseline, and an inline-block's baseline is
     its bottom margin edge — so this puts the square's bottom edge exactly on
     the bottom of the E. */
  vertical-align: baseline;
  /* Matches "Track" rather than "Time" — currentColor picks up the heading's
     own colour, so it flips with the theme for free. */
  background: currentColor;
  border-radius: 1px;
  /* Push the literal "." out of view; the box is the mark now. */
  text-indent: 110%;
  overflow: hidden;
  white-space: nowrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-color: var(--border);
  background: var(--surface);
  color: var(--fg-3);
  padding: 6px 10px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.btn:hover {
  color: var(--fg-1);
  border-color: var(--neutral-500);
}
.btn.brand {
  border-color: var(--gpx-red);
  color: var(--gpx-red);
  background: transparent;
}
.btn.brand:hover {
  background: var(--red-900);
  color: var(--gpx-red-hover);
}
.btn.on {
  border-color: var(--gpx-red);
  background: var(--gpx-red);
  color: var(--neutral-0);
}

/* ── Scrubber ────────────────────────────────────────────────────── */
.scrub {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4) var(--space-2);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-sm);
}
.scrub.pinned {
  border-color: var(--gpx-red);
  box-shadow: var(--shadow-brand, 0 12px 15px -14px rgb(239 51 64 / 1)), var(--shadow-sm);
}

.scrub-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
  /* Fixed so the row cannot change height when the button toggles. */
  min-height: 30px;
}

.scrub-state {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.eyebrow {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--gpx-red);
  white-space: nowrap;
}
.eyebrow.live {
  color: var(--fg-4);
}

.scrub-delta {
  font-size: 13px;
  color: var(--fg-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scrub-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.nudge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-color: var(--border);
  background: var(--bg);
  color: var(--fg-3);
  flex-shrink: 0;
}
.nudge:hover {
  color: var(--gpx-red);
  border-color: var(--gpx-red);
}

/* Native range gives us drag, touch, and arrow keys for free. */
.scrub-range {
  flex: 1;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  height: 30px;
  margin: 0;
  cursor: ew-resize;
}
.scrub-range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: var(--radius-full);
  background: linear-gradient(
    90deg,
    var(--border) 0%,
    var(--neutral-500) 50%,
    var(--border) 100%
  );
}
.scrub-range::-moz-range-track {
  height: 4px;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--border), var(--neutral-500) 50%, var(--border));
}
.scrub-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 22px;
  margin-top: -9px;
  border-radius: var(--radius-sm);
  background: var(--gpx-red);
  border: 1px solid var(--gpx-red-active);
  box-shadow: 0 0 12px rgb(239 51 64 / 0.5);
}
.scrub-range::-moz-range-thumb {
  width: 12px;
  height: 22px;
  border-radius: var(--radius-sm);
  background: var(--gpx-red);
  border: 1px solid var(--gpx-red-active);
  box-shadow: 0 0 12px rgb(239 51 64 / 0.5);
}

/* Ticks are absolutely placed because the range is asymmetric — "now" sits at
   12.5%, not the middle. */
.scrub-ticks {
  position: relative;
  height: 14px;
  margin: 2px 34px 0;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--fg-4);
  text-transform: uppercase;
  pointer-events: none;
}
.scrub-ticks span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
}
.scrub-ticks span:first-child {
  transform: none;
}
.scrub-ticks span:last-child {
  transform: translateX(-100%);
}
#tick-mid {
  color: var(--gpx-red);
}

.scrub-hint {
  font-size: 11px;
  color: var(--fg-4);
  text-align: center;
  padding-top: 2px;
  letter-spacing: 0.02em;
}

.warn {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  background: var(--warning-900);
  border: 1px solid var(--warning-500);
  color: var(--warning-500);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  margin-bottom: var(--space-3);
  font-size: 13px;
  line-height: 18px;
}

/* ── Search ──────────────────────────────────────────────────────── */
.search {
  position: relative;
  margin-bottom: var(--space-3);
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg-4);
  pointer-events: none;
}
#search {
  width: 100%;
  font: inherit;
  font-family: var(--font-mono);
  color: var(--fg-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 11px 12px 11px 38px;
  outline: none;
}
#search::placeholder {
  color: var(--fg-4);
}
#search:focus {
  border-color: var(--gpx-red);
}
#search::-webkit-search-cancel-button {
  filter: grayscale(1) opacity(0.5);
}

.results {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: min(60vh, 440px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-1);
}

.res-group {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--fg-4);
  padding: 10px 10px 4px;
}

.res {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: var(--radius-md);
}
.res:hover,
.res.active {
  background: var(--surface-raised);
}
.res-main {
  flex: 1;
  min-width: 0;
}
.res-name {
  display: block;
  font-size: 14px;
  color: var(--fg-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.res-name mark {
  background: none;
  color: var(--gpx-red);
  font-weight: 700;
}
.res-sub {
  display: block;
  font-size: 12px;
  line-height: 16px;
  color: var(--fg-4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.res-dupe {
  color: var(--warning-500);
}
.res-time {
  font-size: 13px;
  color: var(--fg-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  letter-spacing: 0.02em;
}
.res-empty {
  padding: 16px 10px;
  color: var(--fg-3);
}

/* ── Drag to reorder ─────────────────────────────────────────────── */
.card {
  cursor: grab;
  touch-action: manipulation;
}
.card.dragging {
  cursor: grabbing;
  z-index: 50;
  opacity: 0.92;
  box-shadow: var(--shadow-lg);
  border-color: var(--gpx-red);
  transition: none;
}
.card.drop-target {
  border-color: var(--gpx-red);
  border-style: dashed;
}
/* Kill text selection and hover states for the duration of a drag. */
body.is-dragging {
  user-select: none;
  cursor: grabbing;
}
body.is-dragging .card:not(.dragging) {
  transition: transform var(--dur-fast) var(--ease-out);
}
/* Controls stay clickable, so they must not advertise the grab cursor. */
.card button,
.card [contenteditable="true"] {
  cursor: pointer;
}
.card [contenteditable="true"] {
  cursor: text;
}

/* Adding a place you already have points you at it instead of duplicating. */
.card.flash {
  border-color: var(--gpx-red);
  animation: flash 900ms var(--ease-out);
}
@keyframes flash {
  0%,
  100% {
    box-shadow: var(--shadow-sm);
  }
  30% {
    box-shadow: 0 0 0 3px var(--red-900), var(--shadow-sm);
  }
}
@media (prefers-reduced-motion: reduce) {
  .card.flash {
    animation: none;
  }
}

/* ── Cards ───────────────────────────────────────────────────────── */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(196px, 1fr));
  gap: var(--space-2);
  align-items: start;
}

.card {
  position: relative;
  /* Own stacking context, so the grit (0) / map (1) / text (2) order inside a
     tile can never be reinterpreted against something outside it. */
  isolation: isolate;
  display: flex;
  flex-direction: column;
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* The picker is a sheet pinned to the bottom of the viewport. Expanding a tile
   in place used to shove every other tile around, which read as a glitch. */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  background: var(--surface);
  border-top: 1px solid var(--gpx-red);
  box-shadow: var(--shadow-lg);
  padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom));
  max-height: 72vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: sheet-in 160ms var(--ease-out);
}
.sheet > .picker {
  max-width: 728px;
  margin: 0 auto;
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}
@keyframes sheet-in {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .sheet {
    animation: none;
  }
}
/* Keep the last row of tiles reachable above the sheet. */
body.sheet-open .wrap {
  padding-bottom: 60vh;
}
/* Home gets the brand bar — it is the reference every other row is read against. */
/* Above the grit: a pseudo-element with z-index auto paints before ::after in
   DOM order, so without this the grain sits on the brand bar and dirties it. */
.card.is-home::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 3;
  width: 3px;
  background: var(--gpx-red);
}
.card.is-source {
  border-color: var(--gpx-red);
}

.card-top {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}
/* The circuit's own shape, straight off the dash3 Circuit record — a watermark
   sitting on the card background, under every bit of text. */
/* The box is deliberately taller than the card. Combined with "meet" the
   circuit scales up past the card edges and clips a little top and bottom,
   which reads better than either a tiny centred shape or the unrecognisable
   sliver that "slice" produces on a 6:1 card. */
/* Above the grit (z-index 0), below the text (z-index 2) — the grain belongs
   to the card surface, not to the map drawn on it. */
.card-outline {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  pointer-events: none;
}

/* Generated street plan for city tiles. Strokes, not fill — roads are lines.
   The size/rotation tuners exist to frame real circuit outlines, whose source
   viewBoxes vary; a generated plan is already drawn to fit, so it opts out. */
.card-outline.is-city svg {
  fill: none;
  stroke: var(--map-ink);
  vector-effect: non-scaling-stroke;
  transform: none;
}
/* Roads are strokes, so their knockout is a wider stroke in the surface colour
   rather than a fill. */
.card-outline.is-city .w-knock {
  fill: none;
  stroke: var(--surface);
  stroke-opacity: var(--map-knock);
  stroke-linejoin: round;
}
.card-outline.is-city .w-knock-minor {
  stroke-width: 0.9;
}
.card-outline.is-city .w-knock-major {
  stroke-width: 1.6;
}
.card-outline.is-city .w-knock-water {
  stroke-width: 3.9;
  stroke-linecap: round;
}

/* Same literal-per-state treatment as the circuit fill: the 0.07 base, then
   2.2x on hover and 3.4x as the source card, with minor roads at 0.55 of the
   majors and the river at 0.8. */
.card-outline.is-city .w-minor,
.card-outline.is-city .w-major,
.card-outline.is-city .w-water {
  transition: stroke-opacity var(--dur-fast) var(--ease-out);
}
.card-outline.is-city .w-minor {
  stroke-width: 0.5;
  stroke-opacity: calc(var(--city-alpha) * 0.55);
}
.card-outline.is-city .w-major {
  stroke-width: 1.1;
  stroke-opacity: var(--city-alpha);
  stroke-linejoin: round;
}
.card-outline.is-city .w-water {
  stroke-width: 3.2;
  stroke-opacity: calc(var(--city-alpha) * 0.8);
  stroke-linecap: round;
}
.card:hover .card-outline.is-city .w-minor {
  stroke-opacity: calc(var(--city-alpha-hover) * 0.55);
}
.card:hover .card-outline.is-city .w-major {
  stroke-opacity: var(--city-alpha-hover);
}
.card:hover .card-outline.is-city .w-water {
  stroke-opacity: calc(var(--city-alpha-hover) * 0.8);
}
.card.is-source .card-outline.is-city .w-minor {
  stroke-opacity: calc(var(--city-alpha-source) * 0.55);
}
.card.is-source .card-outline.is-city .w-major {
  stroke-opacity: var(--city-alpha-source);
}
.card.is-source .card-outline.is-city .w-water {
  stroke-opacity: calc(var(--city-alpha-source) * 0.8);
}
.card.is-source .card-outline.is-city .w-major,
.card.is-source .card-outline.is-city .w-minor,
.card.is-source .card-outline.is-city .w-water {
  stroke: var(--gpx-red);
}
/* The tarmac itself, filled — a wireframe of a circuit reads as noise at this
   size. Pure white at low alpha so it sits in the surface rather than on it.
   Scaled past the tile edges on purpose; the card clips it. */
.card-outline svg {
  width: 100%;
  height: 100%;
  transform: translate(var(--outline-x, 0%), var(--outline-y, 0%))
    rotate(var(--outline-rotate, 0deg)) scale(var(--outline-scale, 1.3));
  transform-origin: 50% 50%;
  stroke-width: 0.75;
  stroke-linejoin: round;
}
/* Repaints the card surface inside the tarmac, wiping the grit out of the map
   area. At 0 the grain runs straight through the shape; at 1 the map is clean. */
.card-outline .w-knock {
  fill: var(--surface);
  fill-opacity: var(--map-knock);
  stroke: none;
}
/* Literal values per state rather than calc(var() * var()). Chrome does not
   reliably re-evaluate a calc-with-custom-property on SVG paint properties
   when an ancestor's variable changes, so hover simply never fired. These are
   the tuned 0.01 base at 1x / 4x / 8x. */
.card-outline .w-fill {
  fill: var(--map-ink);
  fill-opacity: var(--outline-alpha);
  stroke: var(--map-ink);
  stroke-opacity: var(--outline-alpha);
  transition: fill-opacity var(--dur-fast) var(--ease-out),
    stroke-opacity var(--dur-fast) var(--ease-out);
}
.card:hover .card-outline .w-fill {
  fill-opacity: var(--outline-alpha-hover);
  stroke-opacity: var(--outline-alpha-hover);
}
.card.is-source .card-outline .w-fill {
  fill: var(--gpx-red);
  stroke: var(--gpx-red);
  fill-opacity: var(--outline-alpha-source);
  stroke-opacity: var(--outline-alpha-source);
}

/* Asphalt tooth. Generated noise painted through an alpha mask so its colour
   is a real, tunable value rather than a blend-mode side effect. */
.card::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: var(--grit-alpha);
  /* Tone is a real colour, not a blend mode: the grain is painted through a
     noise mask, so black grain darkens and white grain lifts by an absolute
     amount. Blending multiply over a near-black card moved a pixel by two or
     three values and was invisible. */
  background-color: var(--grit-color);
  -webkit-mask-image: var(--grit-image);
  mask-image: var(--grit-image);
  -webkit-mask-size: var(--grit-size) var(--grit-size);
  mask-size: var(--grit-size) var(--grit-size);
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
}

/* Everything else stacks above the watermark. */
.card-head,
.card-clock,
.picker {
  position: relative;
  z-index: 2;
}

.card-head {
  min-height: 0;
  /* Keep the name clear of the floating corner buttons. */
  padding-right: 24px;
}
/* "UTC+2 · +7h" — plain text under the name, flush left with it. */
.card-metaline {
  position: relative;
  z-index: 2;
  margin-top: 4px;
  font-size: 12px;
  line-height: 16px;
  color: var(--fg-3);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-metaline .sep {
  color: var(--fg-4);
  padding: 0 5px;
}

.card-id {
  min-width: 0;
}

/* Long names clamp instead of pushing the clock out of a fixed-height tile. */
.card-label {
  font-size: 15px;
  line-height: 19px;
  font-weight: 500;
  color: var(--fg-1);
  border-radius: var(--radius-sm);
  /* Outline, not border/padding — it cannot add width, so the label can never
     push past the tile. */
  outline: 1px solid transparent;
  outline-offset: 2px;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-label:hover {
  outline-color: var(--border);
}
/* While editing, show the whole thing rather than a clamped fragment. */
.card-label:focus {
  outline-color: var(--gpx-red);
  -webkit-line-clamp: unset;
  line-clamp: unset;
  overflow: auto;
  max-height: 76px;
}

/* Bottom line of the tile: reference detail, not a heading. */
.card-sub {
  position: relative;
  z-index: 2;
  font-size: 11px;
  line-height: 15px;
  color: var(--fg-4);
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-sub .zone {
  color: var(--neutral-500);
}

/* The clock owns the middle of the tile. */
.card-clock {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: var(--space-2) 0;
}
/* Times are telemetry: mono, tabular, tight. */
.card-time {
  display: block;
  font-family: var(--font-mono);
  font-size: clamp(24px, 4.4vw, 32px);
  line-height: 1.05;
  font-weight: 500;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--fg-1);
  padding: 3px 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  white-space: nowrap;
}
.card-time:hover {
  border-color: var(--border);
  background: var(--bg);
}
.card-time .secs {
  font-size: 0.52em;
  color: var(--fg-4);
}
.card-time .ampm {
  font-size: 0.44em;
  color: var(--fg-3);
  margin-left: 4px;
  letter-spacing: 0.06em;
}

.card-date {
  font-size: 12px;
  line-height: 16px;
  color: var(--fg-3);
  margin-top: var(--space-1);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  letter-spacing: 0.02em;
  text-align: center;
}
.card-date .roll {
  color: var(--warning-500);
}


/* Corner buttons float over the tile so they cost no layout space. Both are
   vertically centred on the first line of the name: card padding, plus half a
   label line, minus half the button. */
.card-corner {
  position: absolute;
  top: calc(var(--space-3) + (19px - 24px) / 2);
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-md);
  color: var(--fg-4);
  opacity: 0.45;
}
/* Same slot: the local card is the one card with no remove button, so the
   locate button simply takes its place. */
.card-remove,
.card-locate {
  right: 6px;
}
.card-corner:hover {
  opacity: 1;
}
.card-remove:hover {
  color: var(--error-500);
  background: var(--error-900);
}
.card-locate:hover {
  color: var(--telemetry-400);
  background: var(--telemetry-900);
}
.card-locate.located {
  color: var(--telemetry-400);
  opacity: 0.8;
}
.card-locate.spin svg {
  animation: spin 900ms linear infinite;
}
/* No hover on touch, so keep them permanently legible there. */
@media (hover: none) {
  .card-corner {
    opacity: 0.7;
  }
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .card-locate.spin svg {
    animation: none;
  }
}

/* ── Tap-only time picker ────────────────────────────────────────── */
.picker {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
}
.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.picker-title {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--fg-4);
}
/* Day / hour / minute are three separate decisions, so they get three ruled,
   labelled blocks rather than three anonymous rows of pills. */
.picker-section {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--border);
}
.picker-legend {
  flex: 0 0 56px;
  padding-top: 6px;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg-4);
}
.picker-row {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
/* Hours come in three bands: a compressed overnight row, the daylight grid,
   then the late row. Seven columns throughout keeps the rhythm aligned. */
.picker-hourgroups {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.picker-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}
.picker-quiet-row {
  display: flex;
  gap: 4px;
}
/* Sized to exactly one seventh of the row, so both overnight bands fit on a
   single line and line up with the daylight grid above and below. */
.picker-quiet-row .pk {
  flex: 0 1 calc((100% - 24px) / 7);
  min-width: 0;
  font-size: 11px;
  padding: 3px 2px;
}
@media (max-width: 620px) {
  .picker-section {
    flex-direction: column;
    /* Stacked, the legend sits above the buttons, so children must fill the
       width. flex-start in a column shrinks them to content and left a dead
       gap down the right of the hour grid. */
    align-items: stretch;
    gap: 6px;
    padding: var(--space-2) 0;
  }
  .picker-legend {
    flex: none;
    padding-top: 0;
  }
  /* Seven columns leaves ~46px a cell on a phone, and "12 PM" needs ~36px of
     that — legible, but squeezed against both edges. Five wider columns give
     the labels room to breathe; the overnight rows keep their own 1/7 sizing
     since "12a" has width to spare. */
  .picker-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
  /* Day and minute pills spread across the row rather than bunching left. */
  .picker-row .pk {
    flex: 1 1 auto;
  }
}

.pk {
  /* Flex-centred on both axes: text-align alone left the shorter overnight
     buttons sitting off-centre once their padding changed. */
  display: flex;
  align-items: center;
  justify-content: center;
  border-color: var(--border);
  background: var(--bg);
  color: var(--fg-3);
  padding: 6px 8px;
  font-size: 12px;
  line-height: 16px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
  /* Last-resort guard: a label can never paint outside its own button. */
  overflow: hidden;
}
.pk:hover {
  border-color: var(--gpx-red);
  color: var(--fg-1);
  opacity: 1;
}
/* Overnight hours: still there, just not competing with the daylight ones.
   Hover and selection are identical to any other hour. */
.pk-quiet {
  opacity: 0.42;
}
.pk.sel {
  background: var(--gpx-red);
  border-color: var(--gpx-red);
  color: var(--neutral-0);
  /* A selected overnight hour is a normal selection, not a quiet one. */
  opacity: 1;
}
.pk.wide {
  padding: 6px 12px;
}

.picker-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding-top: var(--space-1);
}
.picker-preview {
  font-size: 12px;
  color: var(--fg-3);
  font-variant-numeric: tabular-nums;
}
.picker-preview b {
  color: var(--fg-1);
  font-weight: 500;
}


/* ── Saved-locations drawer ──────────────────────────────────────── */
.btn-icon {
  padding: 6px 8px;
}

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgb(0 0 0 / 0.45);
  animation: fade-in 120ms var(--ease-out);
}
/* Overlays the page rather than pushing it, so the grid never reflows. */
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 71;
  width: min(340px, 100%);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: drawer-in 160ms var(--ease-out);
}
@keyframes drawer-in {
  from {
    transform: translateX(16px);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .drawer,
  .drawer-scrim {
    animation: none;
  }
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.drawer-legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--fg-4);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-2);
}
.drawer-clear {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--fg-4);
  padding: 2px 4px;
}
.drawer-clear:hover {
  color: var(--error-500);
}
.drawer-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.drawer-empty {
  margin: 0;
  font-size: 12px;
  line-height: 17px;
  color: var(--fg-4);
}

.drawer-row {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: var(--radius-md);
}
.drawer-row:hover {
  background: var(--bg);
}
.drawer-main {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto auto;
  grid-template-areas: "name time state" "sub time state";
  align-items: center;
  gap: 0 var(--space-2);
  text-align: left;
  padding: 7px 8px;
}
.drawer-name {
  grid-area: name;
  font-size: 13px;
  color: var(--fg-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drawer-sub {
  grid-area: sub;
  font-size: 11px;
  color: var(--fg-4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drawer-time {
  grid-area: time;
  font-size: 12px;
  color: var(--fg-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.drawer-state {
  grid-area: state;
  display: flex;
  color: var(--fg-4);
}
.drawer-row.on-board .drawer-state {
  color: var(--gpx-red);
}
.drawer-pin {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  color: var(--fg-4);
  opacity: 0.5;
}
.drawer-pin:hover {
  opacity: 1;
  color: var(--gpx-red);
}
.drawer-pin.on {
  opacity: 1;
  color: var(--gpx-red);
}

.drawer-drop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  color: var(--fg-4);
  opacity: 0.4;
}
.drawer-drop:hover {
  opacity: 1;
  color: var(--error-500);
  background: var(--error-900);
}

/* Card pin: bottom-right, hover only. */
.card-pin {
  position: absolute;
  right: 6px;
  bottom: 6px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-md);
  color: var(--fg-4);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.card:hover .card-pin,
.card-pin:focus-visible {
  opacity: 0.55;
}
.card:hover .card-pin:hover {
  opacity: 1;
  color: var(--gpx-red);
  background: var(--red-900);
}
/* A pinned card keeps it visible — that is the state being communicated. */
.card-pin.on,
.card:hover .card-pin.on {
  opacity: 1;
  color: var(--gpx-red);
}
@media (hover: none) {
  .card-pin {
    opacity: 0.5;
  }
}

/* ── Confirmation modal ──────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: rgb(0 0 0 / 0.55);
  backdrop-filter: blur(3px);
  animation: fade-in 120ms var(--ease-out);
}
.modal-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 2px solid var(--gpx-red);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-4);
  animation: modal-in 140ms var(--ease-out);
}
.modal-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-1);
  margin: 0 0 var(--space-2);
}
.modal-body {
  margin: 0 0 var(--space-4);
  font-size: 13px;
  line-height: 19px;
  color: var(--fg-3);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}
@keyframes fade-in {
  from {
    opacity: 0;
  }
}
@keyframes modal-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .modal,
  .modal-card {
    animation: none;
  }
}

.empty {
  color: var(--fg-3);
  text-align: center;
  padding: 32px 0;
}

/* Pinned to the bottom of the viewport, opaque so tiles scroll under it. */
.foot {
  position: sticky;
  bottom: 0;
  z-index: 15;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  /* auto, not a fixed gap: on a short page this is what pushes the footer to
     the bottom of the viewport. */
  margin-top: auto;
  padding: 9px 0 calc(9px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-4);
}
/* Count and reset read as one unit, so they sit together rather than at
   opposite ends of the row. */
.foot-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.foot-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-md);
  color: var(--fg-4);
}
.foot-icon:hover {
  color: var(--gpx-red);
  background: var(--red-900);
}

.foot-brand {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Every state spelled out — :link and :visited otherwise fall back to the
   browser's blue, which is what happened when only `a` was styled. */
.foot-brand a,
.foot-brand a:link,
.foot-brand a:visited,
.foot-brand a:active {
  font-weight: 700;
  color: var(--gpx-red);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  transition: color var(--dur-fast) var(--ease-out);
}
.foot-brand a:hover {
  color: var(--gpx-red-hover);
  text-decoration-thickness: 2px;
}
.foot-brand a:focus-visible {
  outline: 2px solid var(--gpx-red);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
.foot button {
  color: var(--fg-4);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 4px;
}
.foot button:hover {
  color: var(--gpx-red);
}

@media (max-width: 560px) {
  /* One column on a phone — a full-width tile keeps the time big and the
     circuit outline readable. */
  .cards {
    grid-template-columns: minmax(0, 1fr);
  }
  /* "Showing the time right now" truncated to "Showing the tim…" here, and the
     LIVE eyebrow beside it already says the same thing. */
  .scrub.live .scrub-delta {
    display: none;
  }
  .card {
    padding: var(--space-3) var(--space-4);
  }
  .card-time {
    font-size: clamp(30px, 11vw, 44px);
  }
  .card-acts button {
    width: 24px;
    height: 24px;
  }
  h1 {
    font-size: 20px;
  }
  .scrub-ticks {
    margin: 2px 0 0;
  }
}
