/* Peak Racer. The diorama is loud; the frame around it is quiet: one docked panel, hairlines,
   condensed signage type for names, mono for numbers, and signal yellow for whatever is selected.
   The game wears the same frame. */
:root {
  --ink: #12161c;
  --ink-2: #4b5360;
  --ink-3: #7d8592;
  --paper: #f6f7f9;
  --hover: rgba(18, 22, 28, 0.045);
  --rule: rgba(18, 22, 28, 0.12);
  --rule-strong: rgba(18, 22, 28, 0.3);
  --accent: #ffd60a;
  --accent-hover: #f5c800;
  --hover-solid: #eceef2;
  --ahead: #13844a;  /* timing: ahead of / behind the record */
  --behind: #d4283b;
  --plate: #12161c;  /* event plates over the scene: dark in either theme, like the map labels */
  --plate-ahead: #13844a;
  --plate-behind: #d4283b;
  /* instrument: snow-free ground, sun map, daylight track */
  --bare: #b8a78e;
  --night: #2a3349;
  --shade: #c9d3e3;
  --sun: #ffc53d;
  --dawn: #ef9a6f;
  --low-sun: #ffc53d;
  --high-sun: #ffe49a;

  /* motion: ease-out for anything entering or answering a press (EASE_OUT in util.js); springs move the camera and the sheet */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --press: 140ms;

  --f-display: "Barlow Condensed", "Roboto Condensed", "Arial Narrow", sans-serif;
  --f-body: "Barlow", "Helvetica Neue", Arial, sans-serif;
  --f-mono: "Martian Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  /* type: one scale. Condensed caps for names and controls, mono for readouts, Barlow for prose.
     Caps open up as they get smaller: titles .01em, names .03em, labels and controls .08em. */
  --fs-micro: 9px;    /* chart ticks, map annotations */
  --fs-data: 11px;    /* mono readouts */
  --fs-label: 13px;   /* caps labels, segmented controls, small prose */
  --fs-ui: 15px;      /* buttons, run names in lists, body */
  --fs-head: 22px;    /* legendary runs, live figures in the game bar */
  --fs-figure: 28px;  /* key numbers */
  --fs-title: 32px;   /* run names, card titles */
  --tr-title: .01em;
  --tr-name: .03em;
  --tr-label: .08em;
  /* controls: one height for everything you can press */
  --ctl: 44px;

  --bar-h: var(--ctl);
  --sheet-w: 380px;
  --gut: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #eef1f5; --ink-2: #aab3bf; --ink-3: #6f7a88;
    --paper: #121519; --hover: rgba(255, 255, 255, 0.05); --hover-solid: #1c2026; --ahead: #45d483; --behind: #ff6b78;
    --rule: rgba(255, 255, 255, 0.1); --rule-strong: rgba(255, 255, 255, 0.28);
    --bare: #7a6c58; --night: #0b0e14; --shade: #2e394b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #eef1f5; --ink-2: #aab3bf; --ink-3: #6f7a88;
  --paper: #121519; --hover: rgba(255, 255, 255, 0.05); --hover-solid: #1c2026; --ahead: #45d483; --behind: #ff6b78;
  --rule: rgba(255, 255, 255, 0.1); --rule-strong: rgba(255, 255, 255, 0.28);
  --bare: #7a6c58; --night: #0b0e14; --shade: #2e394b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
/* Mobile Safari tints its bars from fixed elements at the edges, then from the page background: the top bar and
   the bottom sheet are fixed and paper-coloured, and so is the page behind them (html = top edge, body = bottom). */
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; background: var(--paper); }
body {
  background: var(--paper); color: var(--ink);
  font: 400 var(--fs-ui)/1.5 var(--f-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
/* controls answer on touch-down, never zoom on double tap, never select their own label */
button, summary, [role="button"], .lbl-run { touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
::selection { background: var(--accent); color: #12161c; }
[hidden] { display: none !important; }

.app { position: fixed; inset: 0; overflow: hidden; }
.sky { position: absolute; inset: 0; background: linear-gradient(to bottom, var(--sky-top, #79b8f5), var(--sky-bottom, #e3f2ff)); transition: background .6s; }
.sky::after { /* faint survey grid behind the diorama */
  content: ""; position: absolute; inset: 0;
  background-image: linear-gradient(to right, rgba(255,255,255,var(--grid-a, .16)) 1px, transparent 1px), linear-gradient(to bottom, rgba(255,255,255,var(--grid-a, .16)) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 50% 60%, black 20%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 60%, black 20%, transparent 75%);
}
.scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

/* ------------------------------------------------------------------ map labels (part of the artwork: always dark on light) */
.labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl { position: absolute; left: 0; top: 0; will-change: transform; white-space: nowrap; transition: opacity .2s, scale var(--press) var(--ease-out); }
.lbl-peak { display: flex; flex-direction: column; align-items: center; transform-origin: 50% 100%; }
.lbl-peak .t { font: 700 12px/1 var(--f-display); letter-spacing: .07em; text-transform: uppercase; color: #12161c; text-shadow: 0 0 2px #fff, 0 0 3px #fff, 0 0 6px rgba(255,255,255,.9); }
.lbl-peak .e { font: 500 var(--fs-micro)/1 var(--f-mono); color: #2c3440; margin-top: 3px; text-shadow: 0 0 2px #fff, 0 0 4px #fff; }
.lbl-peak .tick { width: 1px; height: 10px; background: #12161c; margin-top: 3px; box-shadow: 0 0 0 1px rgba(255,255,255,.7); }
.lbl-peak.hero .t { font-size: 15px; }
.lbl-place { font: 500 var(--fs-micro)/1 var(--f-mono); letter-spacing: .14em; text-transform: uppercase; color: #fff; background: rgba(18,22,28,.72); padding: 3px 5px 3px 6px; }
.lbl-run {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 7px 3px 4px;
  background: #fff; color: #12161c; box-shadow: 0 1px 0 rgba(10,20,40,.35);
  font: 700 12px/1 var(--f-display); letter-spacing: .05em; text-transform: uppercase;
  pointer-events: auto; cursor: pointer;
}
.lbl-run:active { scale: .96; }
.lbl-run.sel { background: var(--accent); }
.lbl-run.hot { outline: 1.5px solid #12161c; }
.lbl-run.dim { opacity: .55; }
.lbl-lift { font: 500 var(--fs-micro)/1 var(--f-mono); color: #12161c; background: rgba(255,255,255,.9); padding: 2px 4px; }
.glyph { display: inline-flex; flex: none; }
.glyph svg { display: block; }

/* ------------------------------------------------------------------ bar */
.bar {
  position: fixed; z-index: 20; inset: 0 0 auto 0;
  height: calc(var(--bar-h) + var(--safe-t)); padding: var(--safe-t) max(var(--gut), var(--safe-r)) 0 max(var(--gut), var(--safe-l));
  display: flex; align-items: stretch;
  background: var(--paper); color: var(--ink); border-bottom: 1px solid var(--rule);
}
.wordmark { display: none; align-self: center; font: 700 16px/1 var(--f-display); letter-spacing: .16em; text-transform: uppercase; }
.mountains { flex: 1; min-width: 0; display: flex; overflow-x: auto; scrollbar-width: none; margin-left: -10px; }
.mountains::-webkit-scrollbar { display: none; }
.mountains button {
  flex: none; position: relative; padding: 0 10px;
  font: 600 var(--fs-label)/1 var(--f-display); letter-spacing: var(--tr-label); text-transform: uppercase; color: var(--ink-2); white-space: nowrap;
}
.mountains button:active { color: var(--ink); }
.mountains button[aria-current="true"] { color: var(--ink); }
.mountains button[aria-current="true"]::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px; background: var(--accent); }
.tool { flex: none; display: flex; align-items: center; justify-content: center; gap: 8px; min-width: var(--ctl); padding: 0 12px; border-left: 1px solid var(--rule); font: 400 var(--fs-data)/1 var(--f-mono); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tool:last-child { margin-right: -12px; }
.tool svg { width: 20px; height: 20px; }
.tool:active { background: var(--hover); }
.tool[aria-expanded="true"] { background: var(--ink); color: var(--paper); }
.tool .wide { color: var(--ink-2); }
.tool[aria-expanded="true"] .wide { color: inherit; }

/* ------------------------------------------------------------------ panel: bottom sheet on phones, docked left on desktop */
.sheet {
  position: fixed; z-index: 18; left: 0; right: 0; bottom: 0; height: 200px; /* height and motion: UI.setSheet */
  display: flex; flex-direction: column; padding-bottom: var(--safe-b);
  background: var(--paper); color: var(--ink); border-top: 1px solid var(--rule);
}
.sheet-grip { flex: none; height: 20px; display: grid; place-items: center; cursor: grab; touch-action: none; }
.sheet-grip span { width: 36px; height: 4px; border-radius: 2px; background: var(--rule-strong); }
.sheet-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 0 max(var(--gut), var(--safe-r)) 32px max(var(--gut), var(--safe-l)); scrollbar-width: thin; scrollbar-color: var(--rule-strong) transparent; }

/* run list */
.runs { list-style: none; margin: 0; padding: 0; }
.runs + .runs { margin-top: 28px; }
.run {
  display: grid; grid-template-columns: 22px minmax(0, 1fr) 64px 56px; align-items: center; gap: 10px;
  width: 100%; padding: 9px 0; text-align: left; border-bottom: 1px solid var(--rule);
}
.run:active { background: var(--hover); }
.run .glyph { justify-content: center; }
.run .nm { font: 600 var(--fs-ui)/1.15 var(--f-display); letter-spacing: var(--tr-name); text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run .v { font: 400 var(--fs-data)/1 var(--f-mono); color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.run.big { padding: 14px 0; }
.run.big .nm { font-size: var(--fs-head); font-weight: 700; line-height: 1; letter-spacing: .02em; white-space: normal; text-wrap: balance; }
.run.big .v { color: var(--ink); }
.sil { display: block; width: 64px; height: 24px; overflow: visible; }
.sil .line { fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.sil .fill { fill: currentColor; opacity: .08; }
.run:not(.big) .sil { opacity: .55; }

/* run */
.rd-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: 10px; }
.rd-head .glyph { margin-top: 5px; }
.rd-head h2 { margin: 0; font: 700 var(--fs-title)/.95 var(--f-display); letter-spacing: var(--tr-title); text-transform: uppercase; text-wrap: balance; overflow-wrap: anywhere; }
.close { width: var(--ctl); height: var(--ctl); margin: -10px -12px 0 0; display: grid; place-items: center; color: var(--ink-2); }
.close { transition: scale var(--press) var(--ease-out); }
.close:active { scale: .92; }
.close svg { width: 16px; height: 16px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.btn { height: var(--ctl); border: 1px solid var(--rule-strong); font: 700 var(--fs-ui)/1 var(--f-display); letter-spacing: var(--tr-label); text-transform: uppercase; transition: scale var(--press) var(--ease-out); }
.btn:active { scale: .97; }
.btn.primary { background: var(--accent); color: #12161c; border-color: transparent; }
.nums { display: flex; flex-wrap: wrap; gap: 6px 24px; margin: 20px 0 0; }
.nums dt { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.nums dd { margin: 0; font: 600 var(--fs-figure)/1 var(--f-display); font-variant-numeric: tabular-nums; white-space: nowrap; }
.nums small { font: 500 var(--fs-label)/1 var(--f-display); color: var(--ink-2); margin-left: 3px; }
.nums .pre { font: 500 var(--fs-ui)/1 var(--f-mono); margin: 0 4px 0 0; vertical-align: 3px; }
.nums i { display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: 4px; }

.inst { position: relative; margin: 16px 0 0; color: var(--ink); }
.inst svg { display: block; width: 100%; height: auto; overflow: visible; user-select: none; -webkit-user-select: none; }
.inst text { font: 400 var(--fs-micro) var(--f-mono); fill: var(--ink-3); font-variant-numeric: tabular-nums; }
.inst text.strong { fill: var(--ink); font-weight: 500; }
.inst .grid { stroke: var(--rule); }
.inst .area { fill: currentColor; opacity: .05; }
.inst .seg { stroke-width: 2.6; stroke-linecap: round; }
.inst .max { fill: none; stroke: var(--ink); stroke-width: 1.2; }
.inst .snowline line { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 3 3; }
.inst .flake { stroke: var(--ink-3); stroke-width: 1.1; fill: none; }
.inst .cursor line, .inst line.cursor { stroke: var(--ink); stroke-width: 1; }
.inst .cursor circle { fill: var(--accent); stroke: #12161c; stroke-width: 1.5; }
.inst-profile { touch-action: pan-y; cursor: crosshair; }
.inst-sun { margin-top: 4px; touch-action: none; cursor: crosshair; }
.inst-sun .c0 { fill: var(--night); }
.inst-sun .c1 { fill: var(--shade); }
.inst-sun .c2 { fill: var(--sun); }
.inst .now line { stroke: var(--ink); stroke-width: 1.5; }
.inst .now rect { fill: var(--paper); }
.inst-tip {
  position: absolute; top: -8px; transform: translateX(-50%); pointer-events: none;
  display: flex; align-items: center; gap: 6px; padding: 4px 6px; white-space: nowrap;
  background: var(--ink); color: var(--paper); font: 400 var(--fs-data)/1 var(--f-mono); font-variant-numeric: tabular-nums;
}
.inst-tip b { font-weight: 500; }
.inst-tip i { width: 8px; height: 8px; }

.challenge { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--rule); }
.score { margin: 0; font: 600 var(--fs-ui)/1 var(--f-display); letter-spacing: var(--tr-label); text-transform: uppercase; color: var(--ink-2); }
.score b { font: 600 var(--fs-figure)/1 var(--f-display); color: var(--ink); letter-spacing: 0; font-variant-numeric: tabular-nums; }
.score small { font: 500 var(--fs-label)/1 var(--f-display); letter-spacing: 0; color: var(--ink-2); margin: 0 6px 0 2px; }
.challenge ul { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 5px; }
.challenge li { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 10px; font: 400 var(--fs-label)/1.45 var(--f-body); color: var(--ink-2); text-wrap: pretty; }
.challenge li span { font: 400 var(--fs-data)/1.75 var(--f-mono); color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }
.story { margin: 22px 0 0; font: 400 var(--fs-ui)/1.55 var(--f-body); max-width: 62ch; text-wrap: pretty; }
.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); margin: 16px 0 0; border-top: 1px solid var(--rule); }
.facts dt, .facts dd { margin: 0; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.facts dt { padding-right: 16px; font: 400 var(--fs-label)/1.4 var(--f-body); color: var(--ink-2); }
.facts dd { font: 400 var(--fs-data)/1.65 var(--f-mono); text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ popovers */
.pop {
  position: absolute; z-index: 30; top: calc(var(--bar-h) + var(--safe-t) + 8px); right: max(var(--gut), var(--safe-r));
  width: min(340px, calc(100vw - 2 * var(--gut))); max-height: calc(100% - var(--bar-h) - var(--safe-t) - 24px); overflow-y: auto;
  display: grid; gap: 12px; padding: 12px;
  background: var(--paper); color: var(--ink); border: 1px solid var(--rule-strong); box-shadow: 0 16px 32px -20px rgba(0, 0, 0, .5);
  /* grows out of its button (origin set on open), leaves a little faster than it came */
  transition: opacity .18s var(--ease-out), transform .18s var(--ease-out), display .18s allow-discrete;
}
.pop[hidden] { opacity: 0; transform: scale(.97); transition-duration: .12s; }
@starting-style { .pop:not([hidden]) { opacity: 0; transform: scale(.96); } }
.seg { display: flex; flex-wrap: wrap; gap: 1px; background: var(--rule); border: 1px solid var(--rule); }
.seg button {
  flex: 1 1 auto; height: var(--ctl); padding: 0 9px; background: var(--paper); color: var(--ink-2);
  font: 600 var(--fs-label)/1 var(--f-display); letter-spacing: var(--tr-label); text-transform: uppercase; white-space: nowrap;
}
.seg button:active { color: var(--ink); background: var(--hover-solid); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.seg.grid { display: grid; grid-template-columns: repeat(3, 1fr); }
.time { display: grid; grid-template-columns: 46px minmax(0, 1fr); align-items: center; gap: 10px; }
.time output { font: 500 var(--fs-data)/1 var(--f-mono); font-variant-numeric: tabular-nums; }
.time input { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; margin: 0; background: transparent; cursor: pointer; }
.time input::-webkit-slider-runnable-track { height: 8px; background: var(--day); }
.time input::-moz-range-track { height: 8px; background: var(--day); }
.time input::-webkit-slider-thumb { -webkit-appearance: none; width: 8px; height: 24px; margin-top: -8px; background: var(--ink); border: 2px solid var(--paper); }
.time input::-moz-range-thumb { width: 8px; height: 24px; background: var(--ink); border: 2px solid var(--paper); border-radius: 0; }

/* ------------------------------------------------------------------ map HUD (over the artwork: dark on light) */
.maphud {
  position: absolute; z-index: 15; right: max(var(--gut), var(--safe-r)); bottom: 12px; /* rides on the sheet: UI.showSheet */
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none;
}
.maphud > * { pointer-events: auto; }
.compass { width: var(--ctl); height: var(--ctl); border-radius: 50%; background: var(--paper); border: 1px solid var(--rule-strong); color: var(--ink); transition: scale var(--press) var(--ease-out); }
.compass:active { scale: .9; }
.compass svg { width: 100%; height: 100%; display: block; }
.scalebar { display: flex; align-items: flex-end; gap: 6px; pointer-events: none; }
.scalebar span { height: 6px; border: 1.5px solid #12161c; border-top: 0; box-shadow: 0 1px 0 rgba(255,255,255,.8); }
.scalebar b, .attrib summary { font: 500 var(--fs-micro)/1 var(--f-mono); color: #12161c; text-shadow: 0 0 2px #fff, 0 0 4px #fff; font-variant-numeric: tabular-nums; }
.attrib { max-width: min(300px, calc(100vw - 2 * var(--gut))); text-align: right; }
.attrib summary { list-style: none; cursor: pointer; font-weight: 400; padding: 8px 0 8px 16px; margin: -8px 0; } /* bigger target than the text */
.attrib summary::-webkit-details-marker { display: none; }
.attrib p { margin: 6px 0 0; padding: 8px 10px; text-align: left; background: var(--paper); color: var(--ink-2); border: 1px solid var(--rule-strong); font: 400 var(--fs-label)/1.45 var(--f-body); }
.attrib a { color: var(--ink); }
.slope-key { display: flex; pointer-events: none; }
.slope-key span { width: 28px; font: 500 var(--fs-micro)/18px var(--f-mono); text-align: center; color: #12161c; }
.tag {
  position: absolute; z-index: 25; left: 0; top: 0; pointer-events: none;
  display: flex; align-items: center; gap: 6px; padding: 6px 8px; white-space: nowrap;
  background: var(--ink); color: var(--paper); font: 400 var(--fs-data)/1 var(--f-mono); font-variant-numeric: tabular-nums;
  transition: opacity .12s var(--ease-out), scale .14s var(--ease-out), display .12s allow-discrete;
}
.tag[hidden] { opacity: 0; }
.tag.touch { transform-origin: 50% 100%; } /* a long-press reading grows up out of the finger */
@starting-style { .tag.touch:not([hidden]) { opacity: 0; scale: .9; } }
.tag b { font-weight: 500; }
.tag i { width: 8px; height: 8px; }

/* ------------------------------------------------------------------ loader */
.loader { position: absolute; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: start; gap: 14px; background: var(--paper); color: var(--ink); transition: opacity .45s var(--ease-out); }
.loader.done { opacity: 0; pointer-events: none; }
.loader-title { font: 700 44px/1 var(--f-display); letter-spacing: .14em; text-transform: uppercase; }
.loader-bar { width: min(300px, 70vw); height: 2px; background: var(--rule); }
.loader-bar span { display: block; height: 100%; background: var(--ink); transform: scaleX(0); transform-origin: left; transition: transform .3s var(--ease-out); }
.loader-line { max-width: min(300px, 70vw); font: 400 var(--fs-data)/1.5 var(--f-mono); color: var(--ink-2); }
.loader-line:empty { display: none; }

/* ------------------------------------------------------------------ desktop */
@media (min-width: 860px) {
  .wordmark { display: block; width: calc(var(--sheet-w) - var(--gut)); flex: none; }
  .mountains { margin-left: 0; }
  .sheet { top: calc(var(--bar-h) + var(--safe-t)); right: auto; width: var(--sheet-w); height: auto !important; border-top: 0; border-right: 1px solid var(--rule); }
  .sheet-grip { display: none; }
  .sheet-scroll { padding: 18px 20px 32px max(20px, var(--safe-l)); }
  .maphud { bottom: calc(16px + var(--safe-b)); }
}
/* hover only where there is a real pointer: on touch a tap would leave it stuck */
@media (hover: hover) and (pointer: fine) {
  .mountains button:hover, .seg button:hover { color: var(--ink); }
  .tool:not([aria-expanded="true"]):hover, .run:hover, .btn:hover, .close:hover { background: var(--hover); }
  .btn.primary:hover { background: var(--accent-hover); }
  .close:hover { color: var(--ink); }
}
@media (max-width: 480px) {
  .tool .wide { display: none; }
  .rd-head h2 { font-size: var(--fs-figure); }
}

/* ------------------------------------------------------------------ game: the map's frame, re-dressed for a run */
.app[data-mode="game"] > :is(.bar, .sheet, .maphud, .labels, .tag, .pop) { display: none; }
.game { position: absolute; inset: 0; z-index: 40; pointer-events: none; color: var(--ink); }
.game > * { pointer-events: auto; }
/* top bar: run and race time | speed | pause, sound, exit (the map bar's cells and tools) */
.g-cell { display: flex; align-items: center; gap: 8px; padding: 0 12px; min-width: 0; white-space: nowrap; }
.g-run { flex: 1; padding-left: 0; gap: 14px; }
.g-name { overflow: hidden; text-overflow: ellipsis; font: 600 var(--fs-label)/1 var(--f-display); letter-spacing: var(--tr-label); text-transform: uppercase; color: var(--ink-2); }
.g-fig { font: 600 var(--fs-head)/1 var(--f-display); font-variant-numeric: tabular-nums; }
.g-speed { display: grid; grid-auto-flow: column; align-content: center; align-items: baseline; column-gap: 4px; border-left: 1px solid var(--rule); } /* figure and unit share a baseline with the clock */
.g-speed .g-fig { min-width: 2.2ch; text-align: right; }
.g-speed small { font: 500 var(--fs-label)/1 var(--f-display); color: var(--ink-2); }
.tool.g-go { padding: 0 18px; background: var(--accent); color: #12161c; border-left: 0; font: 700 var(--fs-ui)/1 var(--f-display); letter-spacing: var(--tr-label); text-transform: uppercase; }
/* a split chip under the clock: sector, then the gap to the record */
.g-split {
  position: absolute; top: calc(var(--bar-h) + var(--safe-t) + 10px); left: max(var(--gut), var(--safe-l)); pointer-events: none;
  display: flex; font: 500 var(--fs-data)/1 var(--f-mono); font-variant-numeric: tabular-nums; color: #fff;
  transition: opacity .18s var(--ease-out), translate .18s var(--ease-out), display .18s allow-discrete;
}
.g-split[hidden] { opacity: 0; }
@starting-style { .g-split:not([hidden]) { opacity: 0; translate: 0 -6px; } }
.g-split span, .g-split b { padding: 7px 9px; font-weight: 500; }
.g-split span { background: var(--plate); }
.g-split.ahead b { background: var(--plate-ahead); }
.g-split.behind b { background: var(--plate-behind); }
/* events: one word on a plate, broadcast style */
.g-center { position: absolute; left: 50%; top: 36%; transform: translate(-50%, -50%); pointer-events: none; }
.g-flash { display: grid; justify-items: center; gap: 2px; animation: gflash .9s var(--ease-out) forwards; }
.g-big { padding: .1em .24em .04em; background: var(--plate); color: var(--accent); font: 700 clamp(44px, 13vw, 76px)/1 var(--f-display); letter-spacing: var(--tr-title); text-transform: uppercase; font-variant-numeric: tabular-nums; white-space: nowrap; }
.g-msg { padding: 7px 10px; background: var(--plate); color: #fff; font: 500 var(--fs-data)/1 var(--f-mono); letter-spacing: var(--tr-label); text-transform: uppercase; }
@keyframes gflash { 0% { opacity: 0; transform: translateY(8px) scale(.96); } 14% { opacity: 1; transform: none; } 78% { opacity: 1; } 100% { opacity: 0; } }
@keyframes gfade { 0% { opacity: 0; } 14% { opacity: 1; } 78% { opacity: 1; } 100% { opacity: 0; } }
/* controls, shown at the start of a run */
.g-hint {
  position: absolute; left: 50%; bottom: calc(var(--safe-b) + 76px); transform: translateX(-50%); pointer-events: none;
  display: flex; gap: 16px; padding: 8px 12px; background: var(--plate); color: #fff; white-space: nowrap;
  font: 400 var(--fs-data)/1 var(--f-mono);
}
.g-hint span { display: flex; align-items: center; }
.g-hint kbd { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; margin-right: 4px; border: 1px solid rgba(255, 255, 255, .4); font: inherit; font-weight: 500; }
.g-touch { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; touch-action: none; }
.g-touch > div { display: flex; align-items: flex-end; padding: 0 var(--gut) calc(var(--safe-b) + 128px); pointer-events: none; }
.g-touch > div:last-child { justify-content: flex-end; }
.g-touch svg { width: 56px; height: 56px; padding: 16px; background: var(--plate); color: #fff; opacity: 0; transition: opacity .3s var(--ease-out); }
.g-touch.show svg { opacity: .9; }
/* where you are on the run, and (on race courses) where the record would be */
.g-prog {
  position: absolute; left: 50%; bottom: calc(var(--safe-b) + 12px); transform: translateX(-50%); pointer-events: none;
  width: min(640px, calc(100% - 2 * var(--gut))); height: 40px; padding: 6px 8px;
  background: var(--paper); border: 1px solid var(--rule-strong);
}
.g-prog svg { display: block; width: 100%; height: 100%; overflow: visible; }
.g-prog .area { fill: var(--ink); opacity: .07; }
.g-prog .line { fill: none; stroke: var(--ink); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.g-prog .you { fill: var(--accent); stroke: #12161c; stroke-width: 1.5; }
.g-prog .ghost { fill: var(--paper); stroke: var(--ink); stroke-width: 1.5; }
/* cards sit where the run panel sits: bottom sheet on phones, top left on desktop */
.g-card {
  position: absolute; left: 50%; bottom: calc(var(--safe-b) + 64px); transform: translateX(-50%);
  width: min(380px, calc(100% - 2 * var(--gut))); display: grid; gap: 16px; padding: 20px;
  background: var(--paper); border: 1px solid var(--rule-strong); box-shadow: 0 16px 32px -20px rgba(0, 0, 0, .5);
  transition: opacity .22s var(--ease-out), translate .22s var(--ease-out);
}
@starting-style { .g-card:not([hidden]) { opacity: 0; translate: 0 8px; } }
.g-card h2 { margin: 0; font: 700 var(--fs-title)/.95 var(--f-display); letter-spacing: var(--tr-title); text-transform: uppercase; text-wrap: balance; overflow-wrap: anywhere; }
.g-card :is(.actions, .facts) { margin: 0; }
.g-card .actions { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 1fr; }
.g-card .seg button { flex: 1 1 0; }
.g-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 24px; margin: 0; }
.g-stats dt { font: 600 var(--fs-label)/1 var(--f-display); letter-spacing: var(--tr-label); text-transform: uppercase; color: var(--ink-2); }
.g-stats dd { margin: 6px 0 0; font: 600 var(--fs-figure)/1 var(--f-display); font-variant-numeric: tabular-nums; }
.g-stats small { margin-left: 3px; font: 500 var(--fs-label)/1 var(--f-display); color: var(--ink-2); }
.delta { font-weight: 500; }
.delta.ahead { color: var(--ahead); }
.delta.behind { color: var(--behind); }
@media (min-width: 860px) {
  .g-card { left: max(var(--gut), var(--safe-l)); top: calc(var(--bar-h) + var(--safe-t) + var(--gut)); bottom: auto; transform: none; }
}
@media (max-width: 600px) {
  .g-run:has(.g-fig) .g-name { display: none; } /* the clock gets the room */
}

/* reduced motion: fades stay (they explain what changed), movement goes. The camera, sheet, terrain rise and
   panel slide check reducedMotion() in JS. */
@media (prefers-reduced-motion: reduce) {
  .pop[hidden], .lbl-run:active, .btn:active, .close:active, .compass:active { transform: none; scale: none; }
  @starting-style { .pop:not([hidden]) { transform: none; } .tag.touch:not([hidden]) { scale: none; } }
  .g-flash { animation-name: gfade; }
  @starting-style { .g-split:not([hidden]), .g-card:not([hidden]) { translate: none; } }
}
