/* NYPD Pursuit: page shell, HUD, menus and touch controls (DOM built by js/hud.js).
 *
 * Everything inside #ui is sized in em off one fluid root size, so the whole
 * interface scales from 360 px phones to 4K. Anything that changes while
 * racing moves with transform/opacity (set from JS or by keyframes); the
 * looping effects only run while their screen or state is active. */

:root {
  --red: #ff2d46;
  --red-deep: #c90f2c;
  --blue: #2f6bff;
  --blue-bright: #5b8cff;
  --blue-deep: #1a3fd1;
  --cyan: #22e6ff;
  --cyan-pale: #b8fbff;
  --amber: #ffc23d;
  --gold: #ffd54a;
  --ink: #f4f7ff;
  --ink-2: rgba(226, 233, 255, 0.74);
  --ink-3: rgba(200, 212, 245, 0.5);
  --glass: rgba(9, 12, 25, 0.7);
  --glass-deep: rgba(6, 8, 18, 0.88);
  --edge: rgba(255, 255, 255, 0.11);
  --edge-2: rgba(255, 255, 255, 0.2);
  --shadow: 0 0.5em 1.6em rgba(0, 0, 0, 0.32);
  --f-display: 'Russo One', 'Arial Black', 'Segoe UI Black', Impact, sans-serif;
  --f-ui: 'Rajdhani', Bahnschrift, 'DIN Alternate', 'Roboto Condensed', 'Arial Narrow', system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05070f;
}

body {
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

#game-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  outline: none;
  touch-action: none;
}

/* ------------------------------------------------------------------ root */

#ui {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  /* ~13 px at 1280x720, 18.5 px at 1080p, 35 px at 4K, never below 11 px */
  font-size: clamp(11px, calc(0.46vw + 0.68vh + 2.4px), 38px);
  --tb: max(56px, 5.6em); /* touch button size */
  font-family: var(--f-ui);
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-font-smoothing: antialiased;
}

/* Zero specificity, so every button class below can set its own font. */
:where(.ui) button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

:where(.ui) svg {
  display: block;
}

.label {
  font-size: 0.72em;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
}

.ui kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.85em;
  height: 1.85em;
  padding: 0 0.45em;
  font: 700 0.78em/1 var(--f-ui);
  letter-spacing: 0.04em;
  color: #fff;
  background: linear-gradient(180deg, #2c3456, #161b31);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-bottom-width: 0.2em;
  border-radius: 0.35em;
}

/* Glass panel with the red/blue light-bar accent along its top edge. */
.panel {
  position: relative;
  background: var(--glass);
  border: 1px solid var(--edge);
  border-radius: 0.7em;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.panel::before {
  content: '';
  position: absolute;
  left: 1em;
  right: 1em;
  top: -1px;
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--red) 18%, var(--red) 49%, var(--blue) 51%, var(--blue) 82%, transparent);
  opacity: 0.9;
}

/* A light blur makes the glass read as glass; skipped on Low for weak GPUs. */
.ui:not(.q-low) .panel {
  -webkit-backdrop-filter: blur(8px) saturate(1.15);
  backdrop-filter: blur(8px) saturate(1.15);
}

.panel__title {
  margin: 0 0 0.75em;
  font: 400 0.95em/1 var(--f-display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* Horizontal meter. JS slides .meter__win right and .meter__fill back left by
   the same amount, revealing a fixed gradient without resizing anything. */
.meter {
  position: relative;
  overflow: hidden;
  height: 0.62em;
  border-radius: 0.2em;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
}

.meter__win,
.meter__fill {
  position: absolute;
  inset: 0;
  will-change: transform;
}

.meter__win {
  overflow: hidden;
  transform: translateX(-100%);
}

.meter__fill {
  transform: translateX(100%);
}

.meter__cells {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 calc(10% - 0.14em), rgba(5, 8, 18, 0.85) calc(10% - 0.14em) 10%);
}

/* ------------------------------------------------------------------ fx layer */

.fx,
.fx-bust,
.fx-bust i,
.fx-damage {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.fx-bust {
  opacity: 0;
  transition: opacity 0.25s linear;
}

.fx-bust i {
  opacity: 0.35;
}

.fx-bust__red {
  background:
    linear-gradient(90deg, rgba(255, 36, 64, 0.8), rgba(255, 36, 64, 0.28) 5%, rgba(255, 36, 64, 0) 24%),
    linear-gradient(180deg, rgba(255, 36, 64, 0.35), rgba(255, 36, 64, 0) 14%);
}

.fx-bust__blue {
  background:
    linear-gradient(270deg, rgba(47, 107, 255, 0.85), rgba(47, 107, 255, 0.3) 5%, rgba(47, 107, 255, 0) 24%),
    linear-gradient(0deg, rgba(47, 107, 255, 0.35), rgba(47, 107, 255, 0) 14%);
}

.fx-bust.is-on .fx-bust__red {
  animation: strobe-a 0.9s linear infinite;
}

.fx-bust.is-on .fx-bust__blue {
  animation: strobe-b 0.9s linear infinite;
}

.fx-bust.is-fast i {
  animation-duration: 0.46s;
}

.fx-damage {
  opacity: 0;
  background: radial-gradient(ellipse 75% 70% at 50% 50%, rgba(255, 20, 30, 0) 42%, rgba(255, 20, 30, 0.32) 70%, rgba(170, 0, 12, 0.85) 100%);
}

/* Police strobe: red and blue take turns, each with a quick double flash. */
@keyframes strobe-a {
  0%, 44%, 100% { opacity: 1; }
  12%, 32% { opacity: 0.3; }
  22% { opacity: 0.85; }
  50%, 94% { opacity: 0.12; }
}

@keyframes strobe-b {
  0%, 44%, 100% { opacity: 0.12; }
  50%, 94% { opacity: 1; }
  62%, 82% { opacity: 0.3; }
  72% { opacity: 0.85; }
}

/* ------------------------------------------------------------------ in-race HUD */

.hud {
  position: absolute;
  inset: 0;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.3s linear, visibility 0s linear 0.3s;
}

.ui[data-screen='hud'] .hud,
.ui[data-screen='pause'] .hud {
  visibility: visible;
  opacity: 1;
  transition: opacity 0.3s linear;
}

.hud__frame {
  position: absolute;
  inset: 0;
  padding: calc(var(--safe-t) + 1em) calc(var(--safe-r) + 1.2em) calc(var(--safe-b) + 1.1em) calc(var(--safe-l) + 1.2em);
}

.hud-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-areas: 'race route side';
  align-items: start;
  gap: 1em;
}

/* --- race panel: clock, score, close calls */

.race {
  grid-area: race;
  justify-self: start;
  min-width: 13em;
  padding: 0.65em 1em 0.7em;
  contain: layout style;
}

.race__time {
  display: flex;
  flex-direction: column;
  gap: 0.1em;
}

.race__clock {
  font: 700 2.35em/1 var(--f-ui);
  letter-spacing: 0.01em;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}

.cell {
  display: inline-block;
  width: 0.54em;
  text-align: center;
}

.cell--sep {
  width: 0.27em;
}

.cell.is-lead {
  opacity: 0.25;
}

.race__row {
  display: flex;
  gap: 1.3em;
  margin-top: 0.5em;
  padding-top: 0.45em;
  border-top: 1px solid var(--edge);
}

.race__stat {
  display: flex;
  flex-direction: column;
  gap: 0.15em;
  min-width: 0;
}

.race__v {
  font: 700 1.38em/1 var(--f-ui);
  white-space: nowrap;
}

.race__v > span {
  display: inline-block;
}

.combo {
  display: inline-block;
  margin-left: 0.4em;
  padding: 0.12em 0.36em 0.08em;
  font: 400 0.68em/1 var(--f-display);
  vertical-align: 0.18em;
  color: #1c1200;
  background: linear-gradient(180deg, #ffe07a, var(--amber));
  border-radius: 0.25em;
  box-shadow: 0 0 0.8em rgba(255, 194, 61, 0.55);
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.18s linear, transform 0.25s var(--ease-out);
}

.combo.is-on {
  opacity: 1;
  transform: none;
}

/* --- route panel: progress from start to finish */

.route {
  grid-area: route;
  width: 30em;
  max-width: 100%;
  padding: 0.85em 1.25em 0.6em;
  contain: layout style;
}

.route__track {
  position: relative;
  height: 0.5em;
  margin: 0.45em 0.2em 1.35em;
  border-radius: 0.25em;
  background: rgba(255, 255, 255, 0.13);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.55);
}

.route__fill {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  transform-origin: 0 50%;
  transform: scaleX(0);
  background: linear-gradient(90deg, rgba(184, 251, 255, 0.15), rgba(184, 251, 255, 0.85));
  will-change: transform;
}

.route__start,
.route__finish,
.route__cop,
.route__player {
  position: absolute;
  top: 50%;
}

.route__start {
  left: 0;
  width: 0.2em;
  height: 1.1em;
  margin: -0.55em 0 0 -0.1em;
  border-radius: 0.1em;
  background: rgba(255, 255, 255, 0.75);
}

.route__finish {
  right: 0;
  width: 1em;
  height: 1.3em;
  margin: -0.65em -0.5em 0 0;
  border-radius: 0.12em;
  background: repeating-conic-gradient(#fff 0 25%, #10131f 0 50%) 0 0 / 0.5em 0.433em;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85), 0 0 0.7em rgba(255, 255, 255, 0.35);
}

/* Cops ride in their own lane under the track so they stay visible when
   they're right on the player's tail. */
.route__cops {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 0.62em);
  height: 0;
}

.route__cop {
  left: 0;
  display: none;
  width: 0.72em;
  height: 0.72em;
  margin: -0.36em 0 0 -0.36em;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 0.14em rgba(6, 8, 18, 0.9), 0 0 0.6em rgba(255, 45, 70, 0.75);
  will-change: transform;
}

.route__cop.is-on {
  display: block;
}

.route__cop::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--blue-bright);
  box-shadow: 0 0 0.6em rgba(47, 107, 255, 0.9);
  opacity: 0;
}

.ui[data-screen='hud'] .route__cop.is-on::after {
  animation: cop-flash 0.62s steps(1) infinite;
}

@keyframes cop-flash {
  50% { opacity: 1; }
}

.route__player {
  left: 0;
  z-index: 1;
  width: 1.2em;
  height: 1.2em;
  margin: -0.6em 0 0 -0.6em;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 34%, var(--cyan) 38% 100%);
  box-shadow: 0 0 0 0.15em #fff, 0 0 0 0.3em rgba(6, 8, 18, 0.85), 0 0 1em rgba(34, 230, 255, 0.85);
  will-change: transform;
}

.route__dist {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 0.45em;
}

.route__v {
  font: 700 1.3em/1 var(--f-ui);
  white-space: nowrap;
}

/* --- top-right: bust meter + pause */

.hud-top__side {
  grid-area: side;
  justify-self: end;
  display: flex;
  align-items: flex-start;
  gap: 0.6em;
}

.icon-btn {
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 2.9em;
  height: 2.9em;
  padding: 0;
  background: var(--glass);
  border: 1px solid var(--edge-2);
  border-radius: 0.7em;
  box-shadow: var(--shadow);
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}

.icon-btn:hover {
  background: rgba(30, 36, 64, 0.85);
  border-color: rgba(255, 255, 255, 0.4);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn:focus-visible {
  outline: 0.16em solid var(--cyan);
  outline-offset: 0.16em;
}

.pause-btn {
  order: 2;
  grid-auto-flow: column;
  gap: 0.28em;
  place-content: center;
}

.pause-btn i {
  width: 0.3em;
  height: 1.05em;
  border-radius: 0.1em;
  background: currentColor;
}

.bust {
  width: 13em;
  padding: 0.6em 0.9em 0.65em;
  contain: layout style;
}

.bust__head {
  display: flex;
  align-items: center;
  gap: 0.4em;
  margin-bottom: 0.45em;
}

.bust__icon svg {
  width: 1.15em;
  height: 1.15em;
  fill: var(--red);
}

.bust__icon .i-ray {
  fill: none;
  stroke: var(--blue-bright);
  stroke-width: 2;
  stroke-linecap: round;
}

.bust__label {
  flex: 1;
  font: 400 0.92em/1 var(--f-display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.bust__pct {
  font: 700 1.05em/1 var(--f-ui);
  color: var(--ink-2);
}

.bust__fill {
  background: linear-gradient(90deg, var(--blue-deep), var(--blue) 30%, #9b3cff 62%, var(--red) 88%, #ff6b6b);
}

.bust__cop {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.6em;
  margin-top: 0.5em;
}

.bust__dist {
  font: 700 1.05em/1 var(--f-ui);
  white-space: nowrap;
}

.bust__dist.is-near {
  color: #ff8a97;
}

/* Rising risk: amber edge, then a flashing red/blue frame and label. */
.bust::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  box-shadow: 0 0 0 1px var(--red), 0 0 1.1em rgba(255, 45, 70, 0.7), inset 0 0 1.2em rgba(255, 45, 70, 0.35);
}

.bust.is-warn::after {
  opacity: 0.6;
  box-shadow: 0 0 0 1px var(--amber), 0 0 0.9em rgba(255, 194, 61, 0.45);
}

.bust.is-warn .bust__pct {
  color: var(--amber);
}

.ui[data-screen='hud'] .bust.is-high::after {
  animation: pulse 0.5s ease-in-out infinite alternate;
}

.bust.is-high .bust__pct,
.bust.is-high .bust__label {
  color: #fff;
}

.bust.is-high .bust__head {
  position: relative;
}

.ui[data-screen='hud'] .bust.is-high .bust__icon {
  animation: pulse 0.25s steps(1) infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.35; }
  to { opacity: 1; }
}

/* --- speedometer + nitro (bottom right) */

.speedo {
  position: absolute;
  right: calc(var(--safe-r) + 1.2em);
  bottom: calc(var(--safe-b) + 0.6em);
  width: 16.5em;
  contain: layout style;
}

.gauge {
  width: 100%;
  height: auto;
  overflow: visible;
}

.gauge__rim {
  fill: none;
  stroke: rgba(255, 255, 255, 0.1);
  stroke-width: 1;
}

.gauge__track,
.gauge__zone,
.gauge__fill,
.gauge__glow {
  fill: none;
  stroke-linecap: butt;
}

.gauge__track {
  stroke: rgba(255, 255, 255, 0.12);
  stroke-width: 9;
}

.gauge__zone {
  stroke: rgba(34, 230, 255, 0.26);
  stroke-width: 9;
}

.gauge__fill,
.gauge__glow {
  stroke: var(--spd);
  stroke-dasharray: 1000 1000;
  stroke-dashoffset: 1000;
}

.gauge__fill {
  stroke-width: 9;
}

.gauge__glow {
  stroke-width: 19;
  opacity: 0.2;
}

.speedo.is-boost .gauge__fill,
.speedo.is-boost .gauge__glow {
  stroke: var(--nos);
}

.speedo.is-boost .gauge__glow {
  opacity: 0.4;
}

.gauge__scale {
  display: none;
}

.gauge__scale.is-on {
  display: inline;
}

.gauge__tick {
  stroke: rgba(255, 255, 255, 0.45);
  stroke-width: 1.2;
}

.gauge__tick.is-major {
  stroke: #fff;
  stroke-width: 2.2;
}

.gauge__tick.is-zone {
  stroke: var(--cyan);
}

.gauge__num {
  font: 700 11.5px var(--f-ui);
  fill: rgba(255, 255, 255, 0.78);
  text-anchor: middle;
  dominant-baseline: central;
}

.gauge__num.is-zone {
  fill: var(--cyan);
}

.gauge__needle {
  transform-origin: 100px 100px;
  transform: rotate(135deg);
}

.gauge__needle path {
  stroke: #fff;
  stroke-width: 3.4;
  stroke-linecap: round;
}

.speedo__readout {
  position: absolute;
  left: 0;
  right: 0;
  top: 37.5%;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.speedo__num {
  font: 700 3.6em/0.9 var(--f-ui);
  white-space: nowrap;
  text-shadow: 0 0.04em 0.12em rgba(0, 0, 0, 0.6);
}

.speedo__num .cell {
  width: 0.52em;
}

.speedo__unit {
  display: flex;
  align-items: center;
  gap: 0.4em;
  margin-top: 0.2em;
  font: 700 0.84em/1 var(--f-ui);
  letter-spacing: 0.22em;
  color: var(--ink-2);
}

.speedo__rev {
  display: none;
  padding: 0.12em 0.32em 0.08em;
  font: 400 0.9em/1 var(--f-display);
  letter-spacing: 0;
  color: #fff;
  background: var(--red);
  border-radius: 0.2em;
}

.speedo.is-reverse .speedo__rev {
  display: inline-block;
}

.speedo.is-boost .speedo__num {
  color: var(--cyan-pale);
  text-shadow: 0 0 0.25em rgba(34, 230, 255, 0.8), 0 0.04em 0.12em rgba(0, 0, 0, 0.6);
}

.nitro {
  position: absolute;
  left: 24%;
  right: 24%;
  top: 76%;
}

.nitro__head {
  display: flex;
  align-items: center;
  gap: 0.35em;
  margin-bottom: 0.32em;
  font-size: 0.82em;
}

.nitro__label {
  display: flex;
  align-items: center;
  gap: 0.2em;
  font: 400 1em/1 var(--f-display);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--cyan);
}

.nitro__label svg {
  width: 1.1em;
  height: 1.1em;
  fill: currentColor;
}

.nitro__state {
  flex: 1;
  font: 700 1.1em/1 var(--f-ui);
  text-align: right;
  color: var(--ink);
}

.nitro__key kbd {
  font-size: 0.72em;
  height: 1.7em;
}

.nitro__bar {
  position: relative;
}

.nitro__meter {
  height: 0.72em;
}

.nitro__fill {
  overflow: hidden;
  background: linear-gradient(90deg, #1f5dff, #1fa4ff 30%, var(--cyan) 65%, var(--cyan-pale));
}

.nitro__halo {
  position: absolute;
  inset: -0.2em;
  border-radius: 0.35em;
  box-shadow: 0 0 0.9em 0.15em rgba(34, 230, 255, 0.85), 0 0 0 1px rgba(184, 251, 255, 0.9);
  opacity: 0;
}

.nitro__sheen {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 28%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0));
  transform: translateX(-110%);
}

.nitro.is-low .nitro__label,
.nitro.is-low .nitro__state {
  color: #ff8a97;
}

.nitro.is-full .nitro__state,
.nitro.is-boost .nitro__state {
  font-family: var(--f-display);
  font-weight: 400;
  font-size: 0.95em;
  letter-spacing: 0.08em;
  color: var(--cyan);
  text-shadow: 0 0 0.6em rgba(34, 230, 255, 0.8);
}

.ui[data-screen='hud'] .nitro.is-full .nitro__halo {
  animation: halo 0.9s ease-in-out infinite alternate;
}

.nitro.is-boost .nitro__halo {
  opacity: 1;
}

.ui[data-screen='hud'] .nitro.is-boost .nitro__sheen {
  animation: sheen 0.55s linear infinite;
}

.ui[data-screen='hud'] .nitro.is-boost .nitro__fill {
  animation: boost-flash 0.16s steps(1) infinite;
}

@keyframes halo {
  from { opacity: 0.15; }
  to { opacity: 1; }
}

@keyframes sheen {
  from { transform: translateX(-110%); }
  to { transform: translateX(380%); }
}

@keyframes boost-flash {
  50% { opacity: 0.72; }
}

/* --- callouts */

.popups {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--safe-t) + max(21vh, 9.5em));
  pointer-events: none;
}

.popup {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  display: flex;
  justify-content: center;
  font-size: 1.42em;
  transition: transform 0.3s var(--ease-out);
}

.popup__in {
  will-change: transform, opacity;
}

.popup__body {
  --k: #fff;
  --kglow: rgba(255, 255, 255, 0.45);
  display: flex;
  align-items: center;
  gap: 0.55em;
  padding: 0.34em 0.9em 0.3em 0.75em;
  transform: skewX(-12deg);
  background: linear-gradient(90deg, rgba(7, 10, 22, 0.9), rgba(7, 10, 22, 0.78));
  border-left: 0.24em solid var(--k);
  border-radius: 0.2em;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1) inset, 0 0.35em 1.1em rgba(0, 0, 0, 0.4), -0.2em 0 1em var(--kglow);
  white-space: nowrap;
}

.popup__text {
  font: 400 1em/1.05 var(--f-display);
  letter-spacing: 0.05em;
  color: #fff;
  text-shadow: 0 0 0.5em var(--kglow);
}

.popup__val {
  padding: 0.14em 0.4em 0.1em;
  font: 700 0.8em/1 var(--f-ui);
  letter-spacing: 0.08em;
  color: var(--k);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid color-mix(in srgb, var(--k) 45%, transparent);
  border-radius: 0.2em;
}

.popup[data-kind='closecall'] .popup__body {
  --k: var(--gold);
  --kglow: rgba(255, 213, 74, 0.45);
}

.popup[data-kind='closecall'] .popup__val,
.popup[data-kind='nitro'] .popup__val {
  color: var(--cyan);
  border-color: rgba(34, 230, 255, 0.5);
}

.popup[data-kind='oncoming'] .popup__body {
  --k: #ff8a2a;
  --kglow: rgba(255, 138, 42, 0.55);
  font-size: 1.08em;
}

.popup[data-kind='oncoming'] .popup__val {
  color: var(--cyan);
  border-color: rgba(34, 230, 255, 0.5);
}

.popup[data-kind='crash'] .popup__body {
  --k: #fff;
  --kglow: rgba(255, 45, 70, 0.7);
  background: linear-gradient(90deg, rgba(200, 16, 42, 0.94), rgba(150, 8, 30, 0.88));
  font-size: 1.12em;
}

.popup[data-kind='nitro'] .popup__body {
  --k: var(--cyan);
  --kglow: rgba(34, 230, 255, 0.6);
}

.popup[data-kind='nitro'] .popup__text {
  color: var(--cyan-pale);
}

.popup[data-kind='warning'] .popup__body {
  --k: var(--red);
  --kglow: rgba(255, 45, 70, 0.55);
}

.popup[data-kind='warning'] .popup__text {
  color: #ffb3bb;
}

.popup[data-kind='info'] .popup__body {
  --k: var(--blue-bright);
  --kglow: rgba(91, 140, 255, 0.45);
}

/* --- countdown */

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  visibility: hidden;
  pointer-events: none;
}

.countdown.is-on {
  visibility: visible;
}

.countdown > * {
  grid-area: 1 / 1;
}

.countdown__num {
  --cd: var(--red);
  font: 400 clamp(6rem, 32vmin, 24rem)/1 var(--f-display);
  letter-spacing: -0.02em;
  color: #fff;
  opacity: 0;
  transform: scale(0.5);
  text-shadow:
    0 0.02em 0 rgba(0, 0, 0, 0.55),
    0 0 0.05em rgba(0, 0, 0, 0.75),
    0 0 0.18em var(--cd),
    0 0 0.5em var(--cd);
  will-change: transform, opacity;
}

.countdown__ring {
  --cd: var(--red);
  width: 44vmin;
  height: 44vmin;
  border-radius: 50%;
  border: 1.1vmin solid var(--cd);
  box-shadow: 0 0 5vmin var(--cd), inset 0 0 5vmin var(--cd);
  opacity: 0;
  will-change: transform, opacity;
}

.countdown[data-kind='blue'] > * {
  --cd: var(--blue);
}

.countdown[data-kind='go'] > * {
  --cd: var(--cyan);
}

.countdown[data-kind='go'] .countdown__num {
  font-style: italic;
  color: var(--cyan-pale);
  transform: skewX(-8deg);
}

/* --- touch controls */

.touch {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 calc(var(--safe-r) + 1.1em) calc(var(--safe-b) + 1.1em) calc(var(--safe-l) + 1.1em);
  pointer-events: none;
}

.ui.is-touch .touch {
  display: flex;
}

.touch__steer {
  display: flex;
  gap: 0.8em;
}

.touch__pedals {
  display: grid;
  grid-template-areas: 'nitro nitro' 'brake gas';
  justify-items: end;
  align-items: end;
  gap: 0.7em 0.8em;
}

.tbtn {
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0.25em;
  width: var(--tb);
  height: var(--tb);
  padding: 0;
  color: #fff;
  font: 400 0.82em/1 var(--f-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(8, 11, 24, 0.5);
  border: 0.14em solid rgba(255, 255, 255, 0.3);
  border-radius: 1.2em;
  box-shadow: 0 0.4em 1.2em rgba(0, 0, 0, 0.3);
  transition: transform 0.08s ease-out, background-color 0.08s, border-color 0.08s;
}

.tbtn svg {
  width: 46%;
  height: auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tbtn.is-down {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.3);
  border-color: #fff;
}

.tbtn--brake {
  grid-area: brake;
  height: calc(var(--tb) * 1.05);
  border-color: rgba(255, 45, 70, 0.7);
  background: rgba(120, 8, 24, 0.42);
}

.tbtn--brake.is-down {
  background: rgba(255, 45, 70, 0.55);
  border-color: #ffb3bb;
}

.tbtn--gas {
  grid-area: gas;
  height: calc(var(--tb) * 1.5);
  border-color: rgba(91, 140, 255, 0.8);
  background: rgba(20, 50, 150, 0.45);
}

.tbtn--gas.is-down {
  background: rgba(47, 107, 255, 0.62);
  border-color: #cddcff;
}

.tbtn--nitro {
  grid-area: nitro;
  width: calc(var(--tb) * 1.2);
  height: calc(var(--tb) * 0.95);
  border-radius: 50%;
  color: var(--cyan);
  border-color: rgba(34, 230, 255, 0.75);
  background: rgba(6, 60, 80, 0.45);
}

.tbtn--nitro svg {
  width: 34%;
  fill: currentColor;
  stroke: none;
}

.tbtn--nitro span {
  font-size: 0.85em;
}

.tbtn--nitro.is-ready {
  box-shadow: 0 0 1.4em rgba(34, 230, 255, 0.7), inset 0 0 0.8em rgba(34, 230, 255, 0.4);
  border-color: var(--cyan-pale);
}

.tbtn--nitro.is-empty {
  opacity: 0.45;
}

.tbtn--nitro.is-down {
  background: rgba(34, 230, 255, 0.45);
  color: #fff;
}

/* Touch layout: the controls own both bottom corners and the car fills the
   bottom middle, so the dial stacks above the nitro button and pedals. */
.ui.is-touch .speedo {
  right: calc(var(--safe-r) + 1.1em);
  bottom: calc(var(--safe-b) + 2.4em + var(--tb) * 2.45);
  width: 12em;
}

.ui.is-touch .nitro__key,
.ui.is-touch .card__hint {
  display: none;
}

.ui.is-touch .pause-btn {
  width: 3.4em;
  height: 3.4em;
}

/* ------------------------------------------------------------------ screens */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: calc(var(--safe-t) + 1.4em) calc(var(--safe-r) + 1.4em) calc(var(--safe-b) + 1.4em) calc(var(--safe-l) + 1.4em);
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.28s linear, visibility 0s linear 0.28s;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
}

.screen.is-active {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.35s linear;
}

.screen__inner {
  position: relative;
  margin: auto;
}

/* --- buttons */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6em;
  min-height: 2.9em;
  padding: 0.7em 1.5em 0.62em;
  font: 700 1.12em/1 var(--f-ui);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.04));
  border: 1px solid var(--edge-2);
  border-radius: 0.55em;
  overflow: hidden;
  transition: transform 0.1s ease-out, background-color 0.15s, border-color 0.15s, box-shadow 0.15s, filter 0.15s;
}

.btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.45);
}

.btn:active {
  transform: translateY(1px) scale(0.98);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 0.14em #05070f, 0 0 0 0.3em var(--cyan), 0 0 1.4em rgba(34, 230, 255, 0.55);
}

.btn > span {
  position: relative;
}

.btn--primary {
  color: #fff;
  background: linear-gradient(180deg, #4a82ff, var(--blue) 45%, var(--blue-deep));
  border-color: rgba(160, 190, 255, 0.7);
  box-shadow: 0 0.5em 1.5em rgba(47, 107, 255, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
}

/* Red "light-bar" stripe on the leading edge. */
.btn--primary::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0.35em;
  background: var(--red);
  box-shadow: 0 0 0.8em var(--red);
}

.btn--primary:hover {
  filter: brightness(1.12);
  border-color: #cddcff;
}

.btn--danger {
  background: linear-gradient(180deg, #ff5064, var(--red) 45%, var(--red-deep));
  border-color: rgba(255, 180, 190, 0.7);
  box-shadow: 0 0.5em 1.5em rgba(255, 45, 70, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.btn--danger::before {
  background: var(--blue);
  box-shadow: 0 0 0.8em var(--blue);
}

.btn--xl {
  min-height: 3.3em;
  padding: 0.85em 2em 0.8em 2.2em;
  font: 400 1.5em/1 var(--f-display);
  letter-spacing: 0.1em;
}

.btn--xl svg {
  position: relative;
  width: 0.85em;
  height: 0.85em;
  fill: currentColor;
}

/* A slow shine sweeping across the call-to-action. */
.btn--xl::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40%;
  background: linear-gradient(100deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0));
  transform: translateX(-120%) skewX(-18deg);
  pointer-events: none;
}

.screen.is-active .btn--xl::after {
  animation: shine 3.4s ease-in-out 0.8s infinite;
}

@keyframes shine {
  0% { transform: translateX(-120%) skewX(-18deg); }
  40%, 100% { transform: translateX(320%) skewX(-18deg); }
}

/* --- segmented settings */

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
}

.field + .field {
  margin-top: 0.6em;
}

.field__label {
  font-size: 0.8em;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.seg {
  display: inline-flex;
  flex-shrink: 0;
  gap: 0.2em;
  padding: 0.2em;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--edge);
  border-radius: 0.5em;
}

.seg__btn {
  min-width: 3.3em;
  min-height: 2.2em;
  padding: 0.35em 0.75em 0.3em;
  font-size: 0.92em;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: 0.35em;
  transition: background-color 0.15s, color 0.15s;
}

.seg__btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.seg__btn[aria-pressed='true'] {
  color: #0a0e1c;
  background: linear-gradient(180deg, #ffffff, #dde5ff);
  box-shadow: 0 0.15em 0.6em rgba(0, 0, 0, 0.35);
}

.seg__btn:focus-visible {
  outline: 0.15em solid var(--cyan);
  outline-offset: 0.12em;
  box-shadow: 0 0 1.1em rgba(34, 230, 255, 0.55);
}

/* --- brand */

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.lightbar {
  display: flex;
  gap: 0.3em;
  width: 8.5em;
  height: 0.55em;
  margin-bottom: 0.9em;
}

.lightbar__half {
  flex: 1;
  border-radius: 0.3em;
}

.lightbar__half--red {
  background: linear-gradient(180deg, #ff7a88, var(--red));
  box-shadow: 0 0 1.1em 0.15em rgba(255, 45, 70, 0.8);
}

.lightbar__half--blue {
  background: linear-gradient(180deg, #9cb9ff, var(--blue));
  box-shadow: 0 0 1.1em 0.15em rgba(47, 107, 255, 0.85);
}

.screen.is-active .lightbar__half--red {
  animation: strobe-a 1.1s linear infinite;
}

.screen.is-active .lightbar__half--blue {
  animation: strobe-b 1.1s linear infinite;
}

.brand__title {
  position: relative;
  z-index: 0;
  margin: 0;
  font: 400 4.4em/0.92 var(--f-display);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

/* Dark outline + drop shadow behind the gradient text (text-shadow would
   paint over a background-clipped fill), so it reads over a bright sky. */
.brand__title::before {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  z-index: -1;
  color: rgba(4, 6, 14, 0.9);
  -webkit-text-stroke: 0.1em rgba(4, 6, 14, 0.85);
  text-shadow: 0 0.06em 0.2em rgba(0, 0, 0, 0.6);
}

/* The light-bar gradient sweeps through the letters. */
.brand__grad {
  display: inline-block;
  color: transparent;
  background: linear-gradient(100deg, #fff 0%, #ffd9dd 12%, var(--red) 24%, #fff 36%, #fff 44%, var(--blue-bright) 56%, #dfe8ff 68%, #fff 80%, var(--red) 92%, #fff 100%) 0 0 / 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
}

.screen.is-active .brand__grad {
  animation: lightbar-sweep 4.5s linear infinite;
}

@keyframes lightbar-sweep {
  to { background-position: -250% 0; }
}

.brand__tag {
  display: flex;
  align-items: center;
  margin: 0.8em 0 0;
  font-size: 0.98em;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-2);
  text-shadow: 0 1px 0.4em rgba(0, 0, 0, 0.7);
  white-space: nowrap;
}

.brand__tag i {
  flex-shrink: 0;
  width: 0.4em;
  height: 0.4em;
  margin: 0 1.6em 0 0.6em;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0.9em 0 0 var(--blue);
}

/* --- loading */

.screen--loading {
  background:
    radial-gradient(90% 55% at 50% 118%, rgba(255, 110, 50, 0.4), rgba(255, 110, 50, 0) 70%),
    radial-gradient(70% 50% at 50% -8%, rgba(47, 107, 255, 0.22), rgba(47, 107, 255, 0) 70%),
    linear-gradient(180deg, #060913 0%, #0a0e20 55%, #170c1d 100%);
}

/* Red and blue "lights on the walls" either side, taking turns. */
.screen--loading::before,
.screen--loading::after {
  content: '';
  position: fixed;
  top: 0;
  bottom: 0;
  width: 60%;
  pointer-events: none;
  opacity: 0;
}

.screen--loading::before {
  left: 0;
  background: radial-gradient(60% 55% at 0% 45%, rgba(255, 45, 70, 0.32), rgba(255, 45, 70, 0) 70%);
}

.screen--loading::after {
  right: 0;
  background: radial-gradient(60% 55% at 100% 45%, rgba(47, 107, 255, 0.36), rgba(47, 107, 255, 0) 70%);
}

.screen--loading.is-active::before {
  animation: strobe-a 1.6s linear infinite;
}

.screen--loading.is-active::after {
  animation: strobe-b 1.6s linear infinite;
}

.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(34em, 100%);
  text-align: center;
}

.brand--xl {
  align-items: center;
  margin-bottom: 2.4em;
}

.brand--xl .lightbar {
  width: 11em;
  height: 0.65em;
  margin-bottom: 1.1em;
}

.brand--xl .brand__title {
  font-size: min(5.6em, 12.5vw);
}

.brand--xl .brand__tag {
  justify-content: center;
  font-size: min(1.05em, 3.4vw);
}

.loading__bar {
  width: 100%;
  height: 0.5em;
  border-radius: 0.25em;
}

.loading__fill {
  overflow: hidden;
  background: linear-gradient(90deg, var(--red-deep), var(--red) 30%, #fff 50%, var(--blue-bright) 70%, var(--blue-deep));
}

.loading__fill::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 25%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0));
  transform: translateX(-100%);
}

.screen--loading.is-active .loading__fill::after {
  animation: sheen 1.4s linear infinite;
}

.loading__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1em;
  width: 100%;
  margin-top: 0.7em;
  font-size: 0.95em;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
  text-align: left;
}

.loading__pct {
  font-size: 1.1em;
  letter-spacing: 0.04em;
  color: #fff;
}

.loading__tip {
  margin: 3em 0 0;
  max-width: 28em;
  font-size: 0.95em;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink-3);
}

.loading__tip b {
  margin-right: 0.7em;
  padding: 0.14em 0.45em 0.1em;
  font: 400 0.8em/1 var(--f-display);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #0a0e1c;
  background: var(--ink-2);
  border-radius: 0.2em;
  vertical-align: 0.1em;
}

/* --- title */

.screen--title {
  background:
    linear-gradient(90deg, rgba(4, 6, 14, 0.86) 0%, rgba(4, 6, 14, 0.55) 30%, rgba(4, 6, 14, 0.08) 50%, rgba(4, 6, 14, 0.4) 72%, rgba(4, 6, 14, 0.8) 100%),
    linear-gradient(0deg, rgba(4, 6, 14, 0.6), rgba(4, 6, 14, 0) 35%);
}

.title {
  display: grid;
  grid-template-columns: minmax(0, 30em) minmax(0, 1fr) minmax(0, 24em);
  grid-template-areas:
    'brand . settings'
    'main  . settings'
    'main  . controls';
  grid-template-rows: auto auto 1fr;
  align-items: start;
  gap: 2em 2em;
  width: 100%;
  max-width: 100em;
  padding: 1.6em 1.6em;
}

.title__brand {
  grid-area: brand;
  align-self: end;
}

.title__main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.4em;
}

.title__main > .btn--xl {
  width: 100%;
  max-width: 17em;
}

.title__diff {
  width: 100%;
  max-width: 25.5em;
  padding: 0.9em 1em;
  background: rgba(6, 8, 18, 0.55);
  border: 1px solid var(--edge);
  border-radius: 0.7em;
}

.title__diff-info {
  margin: 0.6em 0 0;
  font-size: 0.92em;
  font-weight: 600;
  color: var(--ink-3);
}

.title__best {
  display: flex;
  align-items: baseline;
  gap: 0.8em;
  margin: 0;
}

.title__best b {
  font: 700 1.5em/1 var(--f-ui);
  color: var(--gold);
  text-shadow: 0 0 0.6em rgba(255, 213, 74, 0.45);
}

.title__settings,
.title__controls {
  padding: 1.1em 1.2em 1.15em;
}

.title__settings {
  grid-area: settings;
}

.title__controls {
  grid-area: controls;
}

.keys {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5em 1.2em;
  margin: 0;
  padding: 0;
  list-style: none;
}

.keys li {
  display: flex;
  align-items: center;
  gap: 0.55em;
  min-width: 0;
  font-size: 0.92em;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
}

.keys__k {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2em;
}

.title__touch-hint {
  display: none;
  margin: 0;
  font-size: 0.98em;
  line-height: 1.45;
  color: var(--ink-2);
}

.title__touch-hint b {
  color: #fff;
}

.ui.is-touch .keys {
  display: none;
}

.ui.is-touch .title__touch-hint {
  display: block;
}

/* --- cards (pause, results, busted) */

.screen--pause,
.screen--results {
  background: radial-gradient(ellipse at 50% 45%, rgba(4, 6, 14, 0.55), rgba(4, 6, 14, 0.82));
}

.ui:not(.q-low) .screen--pause {
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.card {
  width: min(27em, 100%);
  padding: 1.8em 1.9em 1.7em;
  background: linear-gradient(180deg, rgba(16, 20, 40, 0.94), rgba(8, 10, 22, 0.95));
  border: 1px solid var(--edge-2);
  border-radius: 1em;
  box-shadow: 0 1.5em 4em rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.card::before {
  content: '';
  position: absolute;
  left: 1.6em;
  right: 1.6em;
  top: -1px;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent, var(--red) 15%, var(--red) 49%, var(--blue) 51%, var(--blue) 85%, transparent);
  box-shadow: 0 0 1em rgba(255, 45, 70, 0.5), 0 0 1em rgba(47, 107, 255, 0.5);
}

.card__title {
  margin: 0 0 1em;
  font: 400 2.2em/1 var(--f-display);
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
}

.card__stack {
  display: flex;
  flex-direction: column;
  gap: 0.7em;
}

.card__settings {
  margin-top: 1.4em;
  padding-top: 1.2em;
  border-top: 1px solid var(--edge);
}

.card__hint {
  margin: 1.3em 0 0;
  font-size: 0.9em;
  font-weight: 600;
  text-align: center;
  color: var(--ink-3);
}

.card__actions {
  display: flex;
  gap: 0.8em;
  margin-top: 1.5em;
}

.card__actions .btn {
  flex: 1;
}

/* --- results */

.card--results {
  width: min(38em, 100%);
  padding: 1.7em 1.9em 1.8em;
}

.result-head {
  text-align: center;
}

.result-head__kicker {
  margin: 0 0 0.4em;
  font-size: 0.85em;
  font-weight: 700;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.result-head__title {
  position: relative;
  z-index: 0;
  margin: 0;
  font: 400 4.2em/1 var(--f-display);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.result-head__grad {
  display: inline-block;
  color: transparent;
  background: linear-gradient(180deg, #ffffff 20%, var(--cyan-pale) 58%, var(--cyan) 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

/* Glow copy behind the gradient text (a text-shadow would cover the fill). */
.result-head__title--win::before {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  z-index: -1;
  color: rgba(4, 30, 40, 0.9);
  text-shadow: 0 0 0.3em rgba(34, 230, 255, 0.6), 0 0.04em 0.08em rgba(0, 0, 0, 0.6);
}

.result-head__sub {
  margin: 0.45em 0 0;
  font-size: 1.05em;
  font-weight: 600;
  color: var(--ink-2);
}

.stats {
  margin-top: 1.5em;
}

.stats__hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8em;
}

.hero-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35em;
  padding: 0.85em 0.6em 0.8em;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--edge);
  border-radius: 0.7em;
}

.hero-stat .label {
  display: flex;
  align-items: center;
  gap: 0.6em;
}

.hero-stat__v {
  font: 700 2.4em/1 var(--f-ui);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.screen.is-new-best .hero-stat--best {
  border-color: rgba(255, 213, 74, 0.55);
  background: rgba(255, 213, 74, 0.08);
  box-shadow: 0 0 1.5em rgba(255, 213, 74, 0.18);
}

.screen.is-new-best .hero-stat--best .hero-stat__v {
  color: var(--gold);
}

.badge-new {
  display: inline-block;
  padding: 0.25em 0.5em 0.2em;
  font: 400 0.95em/1 var(--f-display);
  letter-spacing: 0.08em;
  color: #1c1200;
  background: linear-gradient(180deg, #fff1b0, var(--gold));
  border-radius: 0.25em;
  box-shadow: 0 0 1em rgba(255, 213, 74, 0.7);
}

.screen.is-active .badge-new {
  animation: badge 0.8s ease-in-out infinite alternate;
}

@keyframes badge {
  from { transform: scale(1); }
  to { transform: scale(1.12); }
}

.stats__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6em;
  margin-top: 0.8em;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35em;
  padding: 0.7em 0.4em 0.65em;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--edge);
  border-radius: 0.6em;
  text-align: center;
}

.tile .label {
  white-space: normal;
}

.tile__v {
  font: 700 1.6em/1 var(--f-ui);
  white-space: nowrap;
}

.tile__v small {
  margin-left: 0.25em;
  font-size: 0.5em;
  letter-spacing: 0.12em;
  color: var(--ink-3);
}

.stats__score {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1em;
  margin-top: 0.8em;
  padding: 0.75em 1.1em;
  background: linear-gradient(90deg, rgba(255, 213, 74, 0.12), rgba(255, 213, 74, 0.02));
  border: 1px solid rgba(255, 213, 74, 0.3);
  border-radius: 0.7em;
}

.stats__score .label {
  font-size: 0.85em;
  color: rgba(255, 229, 150, 0.85);
}

.stats__score-v {
  font: 700 2.3em/1 var(--f-ui);
  color: var(--gold);
  text-shadow: 0 0 0.5em rgba(255, 213, 74, 0.35);
}

/* --- busted */

.screen--busted {
  background: radial-gradient(ellipse at 50% 50%, rgba(8, 4, 12, 0.5), rgba(8, 4, 12, 0.84));
}

.busted-fx,
.busted-fx i {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.busted-fx {
  position: fixed;
}

.busted-fx i {
  opacity: 0;
}

.busted-fx__red {
  background: radial-gradient(75% 95% at 0% 50%, rgba(255, 30, 55, 0.62), rgba(255, 30, 55, 0) 70%);
}

.busted-fx__blue {
  background: radial-gradient(75% 95% at 100% 50%, rgba(40, 95, 255, 0.66), rgba(40, 95, 255, 0) 70%);
}

.screen--busted.is-active .busted-fx__red {
  animation: strobe-a 0.95s linear infinite;
}

.screen--busted.is-active .busted-fx__blue {
  animation: strobe-b 0.95s linear infinite;
}

/* Police tape behind the card. */
.tape {
  position: fixed;
  left: -10%;
  right: -10%;
  top: calc(var(--safe-t) + 12%);
  overflow: hidden;
  height: 2.5em;
  transform: rotate(-4deg);
  background:
    linear-gradient(180deg, #151515 0 0.18em, transparent 0.18em calc(100% - 0.18em), #151515 calc(100% - 0.18em)),
    linear-gradient(180deg, #ffe14a, #ffcc00);
  box-shadow: 0 0.4em 1.2em rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.tape__run {
  display: flex;
  width: max-content;
  height: 100%;
  align-items: center;
}

.tape__run span {
  padding: 0 1.1em;
  font: 400 1.05em/1 var(--f-display);
  letter-spacing: 0.12em;
  color: #121212;
  white-space: nowrap;
}

.tape__run span:nth-child(3n) {
  color: #0d2a8a;
}

.screen--busted.is-active .tape__run {
  animation: tape 22s linear infinite;
}

@keyframes tape {
  to { transform: translateX(-50%); }
}

.card--busted {
  box-shadow: 0 1.5em 4em rgba(0, 0, 0, 0.55), 0 0 3em rgba(255, 45, 70, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.result-head__title--busted {
  display: grid;
}

.result-head__title--busted .bt {
  grid-area: 1 / 1;
}

.bt--red {
  color: #ff4a5e;
  text-shadow: 0 0 0.3em rgba(255, 45, 70, 0.75), 0 0.05em 0.1em rgba(0, 0, 0, 0.5);
}

.bt--blue {
  color: #6f9bff;
  text-shadow: 0 0 0.3em rgba(47, 107, 255, 0.85), 0 0.05em 0.1em rgba(0, 0, 0, 0.5);
  opacity: 0;
}

.screen--busted.is-active .bt--blue {
  animation: busted-swap 0.95s steps(1) infinite;
}

@keyframes busted-swap {
  50% { opacity: 1; }
}

/* ------------------------------------------------------------------ responsive */

/* Mid-size: the title stacks into one centred column. */
@media (max-width: 1000px), (max-aspect-ratio: 5/4) {
  /* One column sits over the middle of the view, so the scrim covers it all. */
  .screen--title {
    background:
      linear-gradient(180deg, rgba(4, 6, 14, 0.5), rgba(4, 6, 14, 0.72) 45%, rgba(4, 6, 14, 0.88)),
      rgba(4, 6, 14, 0.2);
  }

  .title {
    grid-template-columns: minmax(0, 31em);
    grid-template-areas: 'brand' 'main' 'settings' 'controls';
    grid-template-rows: none;
    justify-content: center;
    gap: 1.4em;
    padding: 0.4em 0;
  }

  .title__brand,
  .title__main {
    align-items: center;
    text-align: center;
  }

  .title__brand {
    align-self: auto;
  }

  .title__brand .brand__title {
    font-size: min(4.4em, 12.5vw);
  }

  .title__brand .brand__tag {
    font-size: min(0.98em, 3.3vw);
  }

  .title__main > .btn--xl {
    max-width: none;
  }

  .title__diff {
    max-width: none;
    text-align: left;
  }
}

/* Short landscape screens (phones on their side): the title keeps two
   columns so it fits without much scrolling. */
@media (max-height: 500px) and (min-aspect-ratio: 5/4) {
  .title {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: 'brand settings' 'main settings' 'main controls';
    grid-template-rows: auto auto 1fr;
    gap: 1em 1.6em;
    max-width: 62em;
    padding: 0;
  }

  .title__brand,
  .title__main {
    align-items: flex-start;
    text-align: left;
  }

  .title__brand .brand__title {
    font-size: min(3.4em, 7vw);
  }

  .title__brand .lightbar {
    margin-bottom: 0.6em;
  }

  .title__main {
    gap: 0.9em;
  }

  .card {
    padding: 1.2em 1.4em;
  }

  .card__title {
    margin-bottom: 0.6em;
  }

  .result-head__title {
    font-size: 3em;
  }

  .stats {
    margin-top: 0.9em;
  }

  .card__actions {
    margin-top: 1em;
  }

  /* Keep the dial small and low so it doesn't sit on top of the car. */
  .speedo {
    width: 13.5em;
    bottom: calc(var(--safe-b) + 0.2em);
  }

  .ui.is-touch .speedo {
    width: 9.6em;
    bottom: calc(var(--safe-b) + 2.2em + var(--tb) * 2.45);
  }
}

/* Narrow screens: the HUD's top row splits into two rows. */
@media (max-width: 720px) {
  .hud-top {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: 'race side' 'route route';
    gap: 0.6em;
  }

  .route {
    width: 100%;
    padding: 0.6em 1.1em 0.5em;
  }

  .race {
    min-width: 0;
    padding: 0.55em 0.8em 0.6em;
  }

  .race__clock {
    font-size: 2em;
  }

  .race__row {
    gap: 0.9em;
  }

  .bust {
    width: 11.5em;
    padding: 0.55em 0.75em 0.6em;
  }

  .hud__frame {
    padding: calc(var(--safe-t) + 0.75em) calc(var(--safe-r) + 0.8em) calc(var(--safe-b) + 0.8em) calc(var(--safe-l) + 0.8em);
  }

  .speedo {
    right: calc(var(--safe-r) + 0.8em);
    width: 13em;
  }

  .popups {
    top: calc(var(--safe-t) + max(24vh, 14em));
  }

  .popup {
    font-size: min(1.22em, 3.9vw);
  }

  .stats__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .result-head__title {
    font-size: min(4.2em, 13vw);
  }

  .card {
    padding: 1.4em 1.2em 1.3em;
  }

  .screen {
    padding: calc(var(--safe-t) + 1em) calc(var(--safe-r) + 0.9em) calc(var(--safe-b) + 1em) calc(var(--safe-l) + 0.9em);
  }
}

@media (max-width: 400px) {
  .keys {
    grid-template-columns: 1fr;
  }

  .seg__btn {
    min-width: 2.9em;
    padding-inline: 0.55em;
  }

  .field {
    gap: 0.6em;
  }

  .hero-stat__v {
    font-size: 2em;
  }
}

/* Portrait touch: the car fills the lower middle and the controls the bottom
   edge, so speed + nitro become a compact pill under the top panels. */
@media (max-aspect-ratio: 1/1) {
  .ui.is-touch .speedo {
    top: calc(var(--safe-t) + 14.5em);
    bottom: auto;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 0.9em;
    width: 15em;
    margin: 0 auto;
    padding: 0.5em 0.9em 0.55em;
    background: var(--glass);
    border: 1px solid var(--edge);
    border-radius: 0.7em;
    box-shadow: var(--shadow);
  }

  .ui.is-touch .gauge {
    display: none;
  }

  .ui.is-touch .speedo__readout,
  .ui.is-touch .nitro {
    position: static;
  }

  .ui.is-touch .speedo__readout {
    flex-shrink: 0;
  }

  .ui.is-touch .speedo__num {
    font-size: 2.3em;
  }

  .ui.is-touch .speedo__unit {
    margin-top: 0.1em;
    font-size: 0.72em;
  }

  .ui.is-touch .nitro {
    flex: 1;
    min-width: 0;
  }

  .ui.is-touch .popups {
    top: calc(var(--safe-t) + 21.5em);
  }
}

@media (prefers-reduced-motion: reduce) {
  .fx-bust.is-on i,
  .screen.is-active .lightbar__half,
  .screen--loading.is-active::before,
  .screen--loading.is-active::after,
  .screen--busted.is-active .busted-fx__red,
  .screen--busted.is-active .busted-fx__blue {
    animation-duration: 3s;
  }

  .screen.is-active .brand__grad,
  .screen.is-active .btn--xl::after,
  .screen--busted.is-active .tape__run {
    animation: none;
  }
}
