/* Crash Quota - page shell, menu screens, HUD and touch controls.

   Look: proving-ground signage. Hazard yellow, near-black and signal white with teal
   and safety-orange accents; diagonal hazard stripes as trim; chunky condensed capitals
   from system font stacks; panels built like painted metal signs with rivets.
   Everything here is drawn with CSS: no images, no web fonts.

   Contents
     1. tokens            5. menu screens       9. motion
     2. page shell        6. HUD               10. reduced motion
     3. type and signs    7. callouts
     4. buttons           8. touch controls                                         */

/* ------------------------------------------------------------------ 1. tokens */
:root {
  --yellow: #ffc61a;
  --yellow-hi: #ffdd66;
  --ink: #1d1d21;
  --white: #f7f6f0;
  --teal: #11a39b;
  --teal-hi: #3bdacf;
  --orange: #ff6a13;
  --red: #e5372b;
  --green: #45e08b;
  --steel: #aab2bb;
  --panel: rgba(29, 29, 33, 0.9);
  --plate: rgba(26, 26, 30, 0.78);

  --display: Impact, "HelveticaNeue-CondensedBlack", "Avenir Next Condensed", "Arial Narrow Bold",
    "Arial Narrow", "Roboto Condensed", "Liberation Sans Narrow", sans-serif-condensed, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, 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);

  /* One em of menu text and one em of HUD text; every size below hangs off these two. */
  --m: clamp(12px, 0.9vmin + 7.6px, 17px);
  --h: clamp(12px, 1.1vmin + 6.2px, 19px);
  --gut: clamp(8px, 2.2vmin, 28px);
  --hud-pad: clamp(6px, 1.6vmin, 18px);
  --map: clamp(72px, 16vmin, 168px);

  /* Touch controls. The HUD reads the same numbers to keep clear of them. */
  --tb: clamp(64px, 18vmin, 88px);
  --tb-mod: clamp(46px, 12vmin, 60px);
  --tb-util: clamp(44px, 11vmin, 52px);
  --tb-gap: 8px;
  --tb-edge: clamp(8px, 2.4vmin, 16px);
  --util-h: calc(var(--tb-util) + 10px);

  --stripes: repeating-linear-gradient(-45deg, var(--yellow) 0 0.5em, var(--ink) 0.5em 1em);
  --outline: 0.07em 0 0 var(--ink), -0.07em 0 0 var(--ink), 0 0.07em 0 var(--ink), 0 -0.07em 0 var(--ink),
    0.05em 0.05em 0 var(--ink), -0.05em 0.05em 0 var(--ink), 0.05em -0.05em 0 var(--ink),
    -0.05em -0.05em 0 var(--ink), 0 0.15em 0 rgba(0, 0, 0, 0.4);
  --rivet: radial-gradient(circle at 36% 34%, #f1f4f6 0 16%, #8d96a0 18% 56%, transparent 60%);

  --pop: cubic-bezier(0.2, 1.5, 0.4, 1);
  --out: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ------------------------------------------------------------------ 2. page shell */
*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

html {
  background: var(--ink);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  color: var(--white);
  font: 400 16px/1.35 var(--body);
  font-synthesis: none;
  /* A sunny stand-in until the first frame is drawn. */
  background: linear-gradient(180deg, #2f7fd6 0%, #c4e6f7 58%, #86c05a 58%, #5c9a3e 100%);
  cursor: default;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#scene,
#ui {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

#scene {
  display: block;
  outline: 0;
  touch-action: none;
}

/* The overlay itself lets touches through; only its controls take them. */
#ui {
  overflow: hidden;
  pointer-events: none;
}

.ui {
  position: absolute;
  inset: 0;
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--ink);
  background: var(--yellow);
  font: 500 18px/1.4 var(--body);
  text-align: center;
}

/* ------------------------------------------------------------------ 3. type and signs */
.logo,
.banner,
.sign-title,
.stencil,
.lbl,
.tag,
.btn,
.tab,
.best,
.car-name,
.car-num,
.car-best,
.garage-count,
.loading-hint,
.verdict-kicker,
.verdict-title,
.rs-score,
.newbest,
.clock,
.score-val,
.lap-row,
.goal-n,
.pip,
.speed b,
.meter-lbl,
.combo,
.wrongway,
.chip,
.toast,
.countdown,
.tbtn-word,
.pad i {
  font-family: var(--display);
  font-weight: 700;
  font-style: normal;
  text-transform: uppercase;
}

/* The logo: two plates, one word each, with a crash-test target for the O. */
.logo {
  display: inline-grid;
  justify-items: center;
  margin: 0;
  font-size: var(--logo, clamp(40px, 13vmin, 118px));
  line-height: 1;
  white-space: nowrap;
  transform: rotate(-2.5deg);
}

.logo-plate {
  display: inline-flex;
  padding: 0.055em;
  border-radius: 0.12em;
  background: var(--ink);
  box-shadow: 0 0.08em 0 var(--ink);
  transform: skewX(-8deg);
}

.logo-w1,
.logo-w2 {
  padding: 0.11em 0.17em 0.03em;
  letter-spacing: 0.012em;
}

.logo-w1 {
  padding-left: 0.2em;
  border-radius: 0.07em 0 0 0.07em;
  color: var(--ink);
  background: var(--yellow);
}

.logo-w2 {
  display: inline-flex;
  align-items: baseline;
  padding-right: 0.2em;
  color: var(--yellow);
  background: var(--ink);
}

.logo-o {
  width: 0.65em;
  height: 0.65em;
  margin: 0 0.05em;
  border-radius: 50%;
  background: conic-gradient(var(--yellow) 0 25%, var(--ink) 0 50%, var(--yellow) 0 75%, var(--ink) 0);
  box-shadow: 0 0 0 0.05em var(--yellow);
}

.logo-tag {
  margin-top: 0.75em;
  padding: 0.4em 0.9em 0.32em;
  border-radius: 0.3em;
  color: var(--white);
  background: var(--ink);
  font-size: max(0.16em, 9.5px);
  letter-spacing: 0.26em;
}

/* A painted metal sign: dark plate, yellow rim, a rivet in each corner. */
.sign {
  position: relative;
  padding: 1.1em 1.3em;
  border: 3px solid var(--yellow);
  border-radius: 0.8em;
  color: var(--white);
  background-color: var(--panel);
  background-image: var(--rivet), var(--rivet), var(--rivet), var(--rivet);
  background-repeat: no-repeat;
  background-position: left 4px top 4px, right 4px top 4px, left 4px bottom 4px, right 4px bottom 4px;
  background-size: 7px 7px;
  box-shadow: 0 0 0 3px var(--ink), 0 0.5em 0 rgba(0, 0, 0, 0.28);
}

/* The same sign with a band of hazard tape across the top. */
.sign-striped {
  overflow: hidden;
  padding-top: 2.1em;
  background-image: none;
}

.sign-striped::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 1em;
  background: var(--stripes);
}

.sign-title {
  margin: 0;
  color: var(--yellow);
  font-size: 2.7em;
  letter-spacing: 0.08em;
  line-height: 1;
}

.stencil {
  margin: 0;
  color: var(--yellow);
  font-size: 1.08em;
  letter-spacing: 0.15em;
  line-height: 1.1;
}

.lbl {
  color: var(--yellow);
  font-size: 0.78em;
  letter-spacing: 0.14em;
}

.tag {
  flex: none;
  min-width: 5.4em;
  padding: 0.24em 0.5em 0.12em;
  border-radius: 0.3em;
  color: var(--ink);
  background: var(--yellow);
  font-size: 0.95em;
  letter-spacing: 0.1em;
  line-height: 1.1;
  text-align: center;
}

.tag-wrecks {
  background: var(--orange);
}

.tag-dummies {
  background: var(--teal-hi);
}

em {
  color: var(--yellow-hi);
  font-style: normal;
  white-space: nowrap;
}

.key {
  display: inline-grid;
  place-items: center;
  min-width: 1.8em;
  height: 1.8em;
  padding: 0 0.36em;
  border-radius: 0.3em;
  color: var(--ink);
  background: var(--white);
  box-shadow: 0 0.17em 0 #a9adb2, 0 0 0 1px rgba(0, 0, 0, 0.4);
  font: 700 0.84em/1 var(--body);
}

/* ------------------------------------------------------------------ 4. buttons */
.btn,
.tab,
.arrow-btn {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-width: 44px;
  min-height: 46px;
  padding: 0.12em 1.1em 0;
  border: 3px solid var(--ink);
  border-radius: 0.5em;
  color: var(--ink);
  background: var(--white);
  box-shadow: 0 4px 0 var(--ink);
  font-size: 1.3em;
  letter-spacing: 0.05em;
  line-height: 1;
  white-space: nowrap;
  transition: transform 90ms var(--out), box-shadow 90ms var(--out), background-color 90ms linear;
}

.btn:active,
.arrow-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

/* The one control the keyboard, the gamepad or the mouse is on: white ring, black ring. */
.btn:focus,
.tab:focus,
.arrow-btn:focus,
.arcade-link:focus {
  outline: 0;
}

.btn.is-focus,
.btn:focus-visible,
.arrow-btn:focus-visible {
  outline: 3px solid var(--white);
  outline-offset: 3px;
  box-shadow: 0 4px 0 var(--ink), 0 0 0 9px var(--ink);
}

.btn.is-focus:active {
  box-shadow: 0 1px 0 var(--ink), 0 0 0 9px var(--ink);
}

/* The main button of a screen: hazard yellow with striped end caps. */
.btn-big {
  overflow: hidden;
  min-height: 58px;
  padding: 0.1em 1.6em 0;
  background: var(--yellow);
  box-shadow: 0 5px 0 var(--ink);
  font-size: 2.1em;
  letter-spacing: 0.07em;
}

.btn-big::before,
.btn-big::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0.58em;
  background: repeating-linear-gradient(-45deg, var(--ink) 0 0.19em, var(--yellow) 0.19em 0.38em);
}

.btn-big::before {
  left: 0;
}

.btn-big::after {
  right: 0;
}

.btn-big.is-focus,
.btn-big:focus-visible {
  background: var(--yellow-hi);
  box-shadow: 0 5px 0 var(--ink), 0 0 0 9px var(--ink);
}

.btn-small {
  min-height: 44px;
  padding: 0.12em 0.8em 0;
  font-size: 1.08em;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.7em;
}

.lamp {
  width: 0.72em;
  height: 0.72em;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: #7a7e85;
}

[aria-pressed="true"] > .lamp {
  background: #20c06a;
}

.toggle-state {
  min-width: 1.75em;
  font-weight: 700;
  text-align: left;
}

.btn.only-compact {
  display: none;
}

.tabs {
  display: inline-flex;
  gap: 0.35em;
}

.tab {
  min-width: 44px;
  min-height: 44px;
  padding: 0.14em 0.9em 0;
  border: 2px solid var(--yellow);
  border-radius: 0.45em;
  color: var(--yellow);
  background: transparent;
  font-size: 0.98em;
  letter-spacing: 0.1em;
  line-height: 1;
}

.tab[aria-pressed="true"] {
  color: var(--ink);
  background: var(--yellow);
}

.tab.is-focus,
.tab:focus-visible {
  outline: 3px solid var(--white);
  outline-offset: 2px;
}

.arcade-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 0.9em;
  border-radius: 0.5em;
  color: var(--white);
  background: rgba(29, 29, 33, 0.72);
  font-size: 0.98em;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 0.22em;
  cursor: pointer;
}

.arcade-link::before {
  content: "\2039";
  margin-right: 0.4em;
  font-size: 1.3em;
  line-height: 1;
  text-decoration: none;
}

.arcade-link.is-focus,
.arcade-link:focus-visible {
  outline: 3px solid var(--white);
  outline-offset: -3px;
  background: var(--ink);
}

/* ------------------------------------------------------------------ 5. menu screens */
.screen,
.boot {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  overflow: hidden;
  /* 'clip' also stops Tab or a focus call from scrolling a screen that must never scroll. */
  overflow: clip;
  padding: calc(var(--safe-t) + var(--gut)) calc(var(--safe-r) + var(--gut)) calc(var(--safe-b) + var(--gut))
    calc(var(--safe-l) + var(--gut));
  font-size: var(--m);
  /* A layout that says how many ems it needs (--fit-rows tall, --fit-cols wide) has its type
     scaled down until that many fit inside the window, like a poster on a smaller sheet. */
  font-size: min(var(--m), calc((100vh - 2 * var(--gut) - var(--safe-t) - var(--safe-b)) / var(--fit-rows, 1)),
    calc((100vw - 2 * var(--gut) - var(--safe-l) - var(--safe-r)) / var(--fit-cols, 1)));
  font-size: min(var(--m), calc((100dvh - 2 * var(--gut) - var(--safe-t) - var(--safe-b)) / var(--fit-rows, 1)),
    calc((100vw - 2 * var(--gut) - var(--safe-l) - var(--safe-r)) / var(--fit-cols, 1)));
  pointer-events: auto;
}

/* ---- loading, the static boot splash and the error screen share one sunny poster */
.boot,
.screen-loading,
.screen-error {
  background:
    linear-gradient(0deg, var(--ink) 0 0.35em, transparent 0.35em) bottom / 100% 1.6em no-repeat,
    repeating-linear-gradient(-45deg, var(--yellow) 0 0.8em, var(--ink) 0.8em 1.6em) bottom / 100% 1.6em no-repeat,
    linear-gradient(180deg, #2f7fd6 0%, #c4e6f7 60%, #86c05a 60%, #5c9a3e 100%);
}

.boot {
  z-index: 50;
}

.poster {
  display: grid;
  justify-items: center;
  gap: 1.5em;
  max-width: 100%;
  text-align: center;
}

.loading-hint {
  margin: 0;
  padding: 0.3em 0.9em 0.2em;
  border-radius: 0.3em;
  color: var(--ink);
  background: var(--white);
  box-shadow: 0 0 0 3px var(--ink);
  font-size: 1.1em;
  letter-spacing: 0.16em;
}

.loadbar {
  width: min(70vw, 18em);
  height: 0.9em;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 0.5em;
  background: var(--ink);
}

.loadbar > i {
  display: block;
  width: 200%;
  height: 100%;
  background: repeating-linear-gradient(-45deg, var(--yellow) 0 0.6em, var(--ink) 0.6em 1.2em);
  animation: load-slide 0.9s linear infinite;
}

.loadbar.is-known > i {
  width: 100%;
  background: var(--yellow);
  transform-origin: left center;
  animation: none;
}

/* ---- title */
.screen-title {
  background: linear-gradient(180deg, rgba(22, 22, 26, 0.12), rgba(22, 22, 26, 0.34));
}

.title-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "head" "brief" "legend" "actions";
  justify-items: center;
  gap: 0.85em;
  width: min(100%, 34em);
}

.title-head {
  grid-area: head;
  padding: 0.2em 0 0.3em;
}

.title-brief {
  grid-area: brief;
  width: 100%;
}

.title-legend {
  grid-area: legend;
  width: 100%;
}

.premise {
  margin: 0 0 0.9em;
  font-size: 1.04em;
  line-height: 1.42;
  text-wrap: pretty;
}

.ways {
  display: grid;
  gap: 0.45em;
  margin: 0.6em 0 0;
  padding: 0;
  list-style: none;
}

.ways li {
  display: flex;
  align-items: center;
  gap: 0.7em;
}

.way-text {
  line-height: 1.25;
}

.ways-note {
  margin: 0.8em 0 0;
  color: var(--yellow-hi);
  font-size: 0.95em;
}

.title-actions {
  grid-area: actions;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  gap: 0.85em;
  width: 100%;
  min-width: 0;
}

.toggles {
  flex-wrap: nowrap;
}

.toggles .btn {
  flex: 0 1 auto;
  min-width: 44px;
}

.title-actions .best {
  margin-bottom: 0.3em;
}

.title-actions .btn-big {
  width: min(100%, 13em);
}

.best {
  max-width: 100%;
  margin: 0;
  padding: 0.3em 0.8em 0.2em;
  border-radius: 0.3em;
  color: var(--yellow);
  background: var(--ink);
  font-size: 1.05em;
  letter-spacing: 0.14em;
  line-height: 1.1;
  text-align: center;
}

/* ---- the controls legend (title, pause and the controls sheet) */
.legend {
  display: grid;
  gap: 0.8em;
}

.legend-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5em 1em;
}

.legend[data-tab="keys"] .legend-touch,
.legend[data-tab="touch"] .legend-keys {
  display: none;
}

.keylist {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5em 1em;
  margin: 0;
  padding: 0;
  list-style: none;
}

.keylist li {
  display: flex;
  align-items: center;
  gap: 0.55em;
  min-width: 0;
}

.keys {
  display: inline-flex;
  flex: none;
  gap: 0.22em;
}

.key-what {
  line-height: 1.2;
}

.legend-note {
  margin: 0.8em 0 0;
  color: rgba(247, 246, 240, 0.82);
  font-size: 0.92em;
}

/* A little picture of the touch layout. */
.pad {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: min(100%, 23em);
  margin: 0 auto;
  padding: 0.5em;
  aspect-ratio: 16 / 7.4;
  border: 3px solid var(--steel);
  border-radius: 0.9em;
  background: linear-gradient(180deg, #3d86d6 0%, #c4e6f7 60%, #7bb556 60%, #5c9a3e 100%);
}

.pad-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}

.pad-top {
  align-items: flex-start;
}

.pad-group,
.pad-steer {
  display: inline-flex;
  gap: 0.3em;
}

.pad i {
  display: grid;
  place-items: center;
  color: var(--white);
  background: rgba(29, 29, 33, 0.82);
  letter-spacing: 0.06em;
  line-height: 1;
}

.pad .pu {
  width: 1.55em;
  height: 1.55em;
  border-radius: 50%;
}

.pad .pb {
  width: 4.1em;
  height: 4.1em;
  border-radius: 0.8em;
  font-size: 0.66em;
}

.pad .pb-gas {
  color: var(--ink);
  background: rgba(255, 198, 26, 0.92);
}

.pad .pm {
  width: 4.1em;
  height: 2.3em;
  border-radius: 0.7em;
  font-size: 0.66em;
}

.pad svg {
  width: 0.95em;
  height: 0.95em;
}

.pad .pb svg {
  width: 2em;
  height: 2em;
}

.pad .snd-off {
  display: none;
}

.pad-pedals {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0.3em;
}

.pad-notes {
  display: grid;
  gap: 0.3em;
  margin: 0.8em 0 0;
  padding: 0;
  list-style: none;
  line-height: 1.3;
}

.pad-notes b {
  color: var(--yellow);
}

/* ---- garage: the car sits on a turntable behind the screen, so the middle stays empty */
.screen-garage {
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "head head head" "prev . next" "card card card";
  place-items: stretch;
  gap: 0.7em;
  background: linear-gradient(180deg, rgba(22, 22, 26, 0.45) 0%, rgba(22, 22, 26, 0) 24%, rgba(22, 22, 26, 0) 56%, rgba(22, 22, 26, 0.5) 100%);
}

.garage-head {
  grid-area: head;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 0.6em;
}

.btn-back {
  justify-self: start;
}

.btn-back {
  gap: 0.25em;
  padding-left: 0.55em;
}

.btn-back svg {
  width: 0.9em;
  height: 0.9em;
  margin-top: -0.12em;
}

.banner {
  margin: 0;
  padding: 0.2em 0.7em 0.08em;
  border: 3px solid var(--ink);
  border-radius: 0.25em;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 0 4px 0 var(--ink);
  font-size: clamp(1.35em, 5.4vw, 2em);
  letter-spacing: 0.06em;
  line-height: 1.1;
  white-space: nowrap;
  transform: rotate(-1.5deg) skewX(-7deg);
}

.garage-count {
  justify-self: end;
  padding: 0.3em 0.7em 0.2em;
  border-radius: 0.3em;
  color: var(--white);
  background: var(--ink);
  font-size: 1.1em;
  letter-spacing: 0.1em;
  line-height: 1.1;
  white-space: nowrap;
}

.arrow-btn {
  align-self: center;
  display: grid;
  place-items: center;
  width: clamp(48px, 10vmin, 72px);
  height: clamp(48px, 10vmin, 72px);
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: 50%;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 90ms var(--out), box-shadow 90ms var(--out);
}

.arrow-btn svg {
  width: 52%;
  height: 52%;
}

.arrow-prev {
  grid-area: prev;
}

.arrow-next {
  grid-area: next;
}

.garage-card {
  grid-area: card;
  justify-self: center;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "id" "stats" "strip" "foot";
  gap: 0.75em;
  width: min(100%, 30em);
  padding: 0.9em 1.1em;
}

.car-id {
  grid-area: id;
  display: flex;
  align-items: center;
  gap: 0.8em;
  min-width: 0;
}

.car-num {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.9em;
  height: 1.9em;
  padding-top: 0.06em;
  border: 0.14em solid var(--car, var(--yellow));
  border-radius: 50%;
  color: var(--ink);
  background: var(--white);
  box-shadow: 0 0 0 2px var(--ink);
  font-size: 1.8em;
  line-height: 1;
}

.car-text {
  min-width: 0;
  animation: car-in 180ms var(--out) both;
}

.car-text[data-dir="prev"] {
  animation-name: car-in-prev;
}

.car-name {
  margin: 0;
  color: var(--yellow);
  font-size: 2.2em;
  letter-spacing: 0.06em;
  line-height: 1;
}

.car-blurb {
  margin: 0.25em 0 0;
  font-size: 0.98em;
  line-height: 1.3;
  text-wrap: pretty;
}

.stats {
  grid-area: stats;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45em 1.2em;
  margin: 0;
  padding: 0;
  list-style: none;
}

.stats li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5em;
  white-space: nowrap;
}

.pips {
  display: inline-flex;
  gap: 3px;
}

.pips i {
  width: 1em;
  height: 0.78em;
  border-radius: 2px;
  background: rgba(247, 246, 240, 0.17);
  transform: skewX(-14deg);
}

.pips i.on {
  background: var(--yellow);
}

.car-foot {
  grid-area: foot;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
}

.car-best {
  margin: 0;
  color: var(--white);
  font-size: 1.1em;
  letter-spacing: 0.12em;
  line-height: 1.15;
}

.car-foot .btn-big {
  min-width: 5.2em;
}

/* The driving controls in one line, right above GO. */
.drive-strip {
  grid-area: strip;
  min-width: 0;
  padding-top: 0.6em;
  border-top: 2px dashed rgba(247, 246, 240, 0.22);
  font-size: 0.9em;
  line-height: 1.2;
}

.drive-strip p {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4em 1.2em;
  margin: 0;
}

.drive-strip[data-tab="keys"] .strip-touch,
.drive-strip[data-tab="touch"] .strip-keys {
  display: none;
}

.strip-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  white-space: nowrap;
}

.strip-item i {
  font-style: normal;
  opacity: 0.75;
}

.strip-item b {
  color: var(--yellow);
}

.drive-strip .key {
  font-size: 0.78em;
}

/* ---- pause */
.screen-pause {
  background: rgba(22, 22, 26, 0.62);
}

.pause-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1em;
  width: min(100%, 25em);
  text-align: center;
}

.pause-btns {
  display: grid;
  gap: 0.75em;
}

.pause-side {
  display: grid;
  gap: 1em;
  align-content: center;
}

.legend-mini {
  gap: 0.6em;
  padding-top: 0.9em;
  border-top: 2px dashed rgba(247, 246, 240, 0.22);
  font-size: 0.92em;
  text-align: left;
}

.legend-mini .legend-note {
  display: none;
}

.legend-mini .pad {
  width: min(100%, 19em);
}

/* ---- results */
.screen-results {
  background: rgba(22, 22, 26, 0.58);
}

.results-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "verdict" "score" "stats" "btns";
  gap: 0.85em;
  width: min(100%, 31em);
}

.verdict {
  grid-area: verdict;
  position: relative;
  overflow: hidden;
  padding: 1.25em 1em 0.95em;
  border: 3px solid var(--ink);
  border-radius: 0.6em;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 0 5px 0 var(--ink);
  text-align: center;
  transform: rotate(-1.2deg);
}

.verdict::before,
.verdict::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 0.6em;
  background: repeating-linear-gradient(-45deg, var(--ink) 0 0.5em, transparent 0.5em 1em);
}

.verdict::before {
  top: 0;
}

.verdict::after {
  bottom: 0;
}

.verdict-kicker {
  display: block;
  font-size: 0.98em;
  letter-spacing: 0.24em;
  line-height: 1.1;
}

.verdict-title {
  margin: 0.06em 0 0;
  font-size: clamp(2em, 9.5vw, 3.3em);
  letter-spacing: 0.03em;
  line-height: 0.98;
  text-wrap: balance;
}

.verdict-sub {
  margin: 0.25em 0 0;
  font-size: 0.98em;
  font-weight: 600;
  line-height: 1.25;
}

.results-box[data-won="0"] .verdict {
  color: var(--white);
  background: var(--red);
}

.results-score {
  grid-area: score;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6em 1em;
  padding: 0.7em 1.5em 0.6em;
}

.rs-main {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.1em 0.6em;
  min-width: 0;
}

.rs-score {
  color: var(--yellow);
  font-size: 2.9em;
  font-variant-numeric: tabular-nums;
  line-height: 0.95;
}

.newbest {
  align-self: center;
  padding: 0.24em 0.6em 0.14em;
  border-radius: 0.3em;
  color: var(--ink);
  background: var(--teal-hi);
  font-size: 1.05em;
  letter-spacing: 0.12em;
  line-height: 1.1;
  white-space: nowrap;
  transform: rotate(-4deg);
  animation: newbest 0.5s var(--pop) 0.5s 3 both;
}

.rs-side {
  display: grid;
  gap: 0.15em;
  justify-items: end;
  font-size: 0.98em;
  line-height: 1.2;
  text-align: right;
}

.rs-side b {
  font-size: 1.15em;
  font-variant-numeric: tabular-nums;
}

.rs-car {
  white-space: nowrap;
}

.results-stats {
  grid-area: stats;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0 1.6em;
  margin: 0;
  padding: 0.6em 1.2em;
  font-size: 0.98em;
}

.results-stats > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1em;
  padding: 0.26em 0;
  border-bottom: 1px dashed rgba(247, 246, 240, 0.2);
  line-height: 1.25;
}

.results-stats > div:last-child {
  border-bottom: 0;
}

.results-stats dt {
  color: rgba(247, 246, 240, 0.88);
}

.results-stats dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}

.results-btns {
  grid-area: btns;
}

/* ---- error */
.error-box {
  display: grid;
  justify-items: center;
  gap: 0.9em;
  width: min(100%, 27em);
  text-align: center;
}

.error-icon svg {
  display: block;
  width: 4em;
  height: auto;
}

.error-msg {
  margin: 0;
  font-size: 1.08em;
  line-height: 1.45;
  text-wrap: pretty;
}

/* ---- controls sheet */
.screen-controls {
  z-index: 40;
  background: rgba(22, 22, 26, 0.86);
}

.controls-box {
  display: grid;
  justify-items: center;
  gap: 1em;
  width: min(100%, 29em);
  background-color: var(--ink);
}

.controls-box .legend {
  width: 100%;
}

/* ---- roomy desktop and tablet-landscape layouts */
@media (min-width: 900px) and (min-height: 600px) {
  .screen-title {
    --fit-rows: 47;
    --fit-cols: 60;
  }

  .title-grid {
    grid-template-columns: minmax(0, 1.04fr) minmax(0, 1fr);
    grid-template-areas: "head head" "brief legend" "actions actions";
    gap: 1.2em 1.4em;
    width: min(100%, 64em);
  }

  .title-brief,
  .title-legend {
    align-self: stretch;
  }

  .title-brief {
    display: grid;
    align-content: space-between;
    gap: 0.6em;
  }

  .title-brief .premise,
  .title-brief .ways-note {
    margin: 0;
  }

  .title-actions {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-areas: "best start toggles" "link link link";
    align-items: center;
    gap: 0.5em 1.4em;
  }

  .title-actions .best {
    grid-area: best;
    justify-self: end;
  }

  .title-actions .btn-big {
    grid-area: start;
    width: auto;
    min-width: 9em;
  }

  .title-actions .toggles {
    grid-area: toggles;
    justify-self: start;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .title-actions .arcade-link {
    grid-area: link;
  }
}

@media (min-width: 760px) and (min-height: 600px) {
  .garage-card {
    grid-template-columns: minmax(0, 1fr) minmax(21em, auto) auto;
    grid-template-areas: "id stats foot" "strip strip strip";
    align-items: center;
    gap: 0.9em 1.6em;
    width: min(100%, 58em);
    padding: 1.1em 1.5em;
    /* The three columns need about 56 em: on a narrow, tall window the type gives way. */
    font-size: min(1em, calc((100vw - 2 * var(--gut)) / 56));
  }

  .car-foot {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6em;
    text-align: center;
  }

  .pause-box {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
    grid-template-areas: "title title" "btns side";
    align-items: center;
    gap: 1.1em 1.8em;
    width: min(100%, 50em);
  }

  .pause-box .sign-title {
    grid-area: title;
  }

  .pause-btns {
    grid-area: btns;
  }

  .pause-side {
    grid-area: side;
  }

  .results-box {
    width: min(100%, 40em);
  }

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

  .results-stats > div:nth-last-child(2):nth-child(odd) {
    border-bottom: 0;
  }
}

/* ---- the title's legend is only shown where the whole stack fits: beside the brief on wide
   windows (above), or in one tall column. Everywhere else it sits behind a Controls button and
   the garage card carries the driving controls instead. */
@media (max-width: 899px) and (min-height: 960px) {
  .screen-title {
    --fit-rows: 74;
  }
}

@media (max-width: 899px) and (min-height: 600px) and (max-height: 959px) {
  .screen-title {
    --fit-rows: 48;
  }
}

@media (max-width: 899px) and (max-height: 959px) {
  .title-legend {
    display: none;
  }

  .title-actions .btn.only-compact {
    display: inline-flex;
  }
}

/* ---- compact: short windows and small phones. The legend moves behind a Controls button. */
@media (max-height: 599px), (max-width: 499px) and (max-height: 779px) {
  .only-roomy {
    display: none !important;
  }

  .btn.only-compact {
    display: inline-flex;
  }

  .logo {
    --logo: clamp(34px, 11vmin, 70px);
  }

  .logo-tag {
    margin-top: 0.6em;
  }

  .sign {
    padding: 0.85em 1.15em;
  }

  .sign-striped {
    padding-top: 1.7em;
  }

  .sign-striped::before {
    height: 0.8em;
  }

  .sign-title {
    font-size: 2.2em;
  }

  .title-grid {
    gap: 0.7em;
  }

  .title-head {
    padding: 0;
  }

  .premise {
    margin-bottom: 0.6em;
    font-size: 0.98em;
    line-height: 1.32;
  }

  .ways {
    gap: 0.32em;
    margin-top: 0.45em;
  }

  .ways-note {
    display: none;
  }

  .title-actions {
    gap: 0.7em;
  }

  .btn-row {
    gap: 0.45em;
  }

  .btn-small {
    padding-left: 0.6em;
    padding-right: 0.6em;
    font-size: 1em;
    gap: 0.4em;
  }

  .btn-big {
    min-height: 52px;
    font-size: 1.9em;
  }

  .results-btns {
    flex-wrap: nowrap;
  }

  .results-btns .btn-big {
    padding-left: 1.2em;
    padding-right: 1.2em;
    font-size: 1.6em;
  }

  .results-btns .btn {
    min-height: 48px;
  }

  .pause-box {
    gap: 0.75em;
  }

  .pause-btns {
    gap: 0.6em;
  }

  .results-box {
    gap: 0.6em;
  }

  .verdict {
    padding: 0.95em 0.8em 0.7em;
  }

  .verdict::before,
  .verdict::after {
    height: 0.45em;
  }

  .results-score {
    padding: 0.5em 1.4em 0.45em;
  }

  .rs-score {
    font-size: 2.3em;
  }

  .results-stats {
    padding: 0.35em 0.95em;
    font-size: 0.94em;
  }

  .results-stats > div {
    padding: 0.16em 0;
  }

  .garage-card {
    gap: 0.55em;
    padding: 0.7em 0.9em;
  }

  .car-name {
    font-size: 1.9em;
  }

  .car-num {
    font-size: 1.5em;
  }
}

/* ---- compact and wide: two columns instead of one tall stack */
@media (max-height: 599px) and (min-aspect-ratio: 6/5), (max-height: 479px) {
  .screen-title {
    --fit-rows: 1;
  }

  /* The logo shares the window's width with the actions column. */
  .logo {
    --logo: clamp(28px, min(11vmin, 6.6vw), 70px);
  }

  .title-grid {
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    grid-template-areas: "head actions" "brief actions";
    align-items: center;
    gap: 0.7em 1.4em;
    width: min(100%, 62em);
  }

  .title-actions {
    align-self: center;
  }

  .pause-box {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "title title" "btns side";
    align-items: center;
    gap: 0.7em 1.4em;
    width: min(100%, 44em);
  }

  .pause-box .sign-title {
    grid-area: title;
  }

  .pause-btns {
    grid-area: btns;
  }

  .pause-side {
    grid-area: side;
  }

  .pause-side .toggles {
    flex-direction: column;
    align-items: stretch;
  }

  .results-box {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
    grid-template-areas: "verdict stats" "score stats" "btns stats";
    align-items: center;
    gap: 0.9em 1.6em;
    width: min(100%, 58em);
  }

  .results-stats {
    align-self: stretch;
    align-content: center;
  }

  .garage-card {
    grid-template-columns: minmax(0, 1fr) minmax(20em, auto) auto;
    grid-template-areas: "id stats foot" "strip strip strip";
    align-items: center;
    gap: 0.55em 1.1em;
    width: min(100%, 60em);
  }

  .drive-strip {
    padding-top: 0.45em;
  }

  .car-foot {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45em;
    text-align: center;
  }

  .controls-box {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    width: min(100%, 46em);
  }
}

/* ---- compact, wide and narrow at once (a small phone on its side): the right-hand column
   is too slim for a row of buttons, so buttons stack and the garage card uses two rows. */
@media (max-height: 599px) and (min-aspect-ratio: 6/5) and (max-width: 759px), (max-height: 479px) and (max-width: 759px) {
  .title-actions .best {
    letter-spacing: 0.06em;
  }

  .title-actions .btn-big {
    width: 100%;
    padding-left: 0.9em;
    padding-right: 0.9em;
  }

  .title-actions .toggles {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .title-actions .toggles .btn {
    min-width: 0;
    padding-left: 0.3em;
    padding-right: 0.3em;
  }

  .title-actions .toggles .only-compact {
    grid-column: 1 / -1;
  }

  .garage-card {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "id foot" "stats stats" "strip strip";
    gap: 0.5em 1em;
  }

  .stats {
    grid-template-columns: repeat(auto-fit, minmax(9.3em, 1fr));
    gap: 0.3em 0.9em;
    font-size: 0.9em;
  }

  .stats li {
    gap: 0.4em;
  }

  .pips i {
    width: 0.8em;
  }

  .car-foot {
    flex-direction: row;
    align-items: center;
    gap: 0.8em;
  }

  .car-blurb {
    margin-top: 0.1em;
  }

  .verdict-title {
    font-size: clamp(1.5em, 4.3vw, 3.3em);
  }

  .results-score {
    padding-left: 1em;
    padding-right: 1em;
  }

  .rs-score {
    font-size: 1.8em;
  }

  .results-btns {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ------------------------------------------------------------------ 6. HUD */
.hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas:
    "score clock goals"
    "lside clock rside"
    ".     .     ."
    "bl    .     br";
  gap: 0.5em 0.6em;
  padding: calc(var(--safe-t) + var(--hud-pad)) calc(var(--safe-r) + var(--hud-pad)) calc(var(--safe-b) + var(--hud-pad))
    calc(var(--safe-l) + var(--hud-pad));
  font-size: var(--h);
  pointer-events: none;
}

.plate {
  padding: 0.45em 0.6em 0.4em;
  border-top: 3px solid var(--yellow);
  border-radius: 0.45em;
  color: var(--white);
  background: var(--plate);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.28);
}

.bar {
  display: block;
  overflow: hidden;
  border-radius: 2px;
  background: rgba(247, 246, 240, 0.18);
}

.bar > i {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--yellow);
  transform: scaleX(0);
  transform-origin: left center;
}

/* ---- score, lap and gate */
.hud-score {
  grid-area: score;
  justify-self: start;
  align-self: start;
  display: grid;
  gap: 0.2em;
  min-width: 7.4em;
}

.score-row {
  display: grid;
}

.score-val {
  font-size: 2em;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1;
}

.lap-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0 0.8em;
  font-size: 1.05em;
  line-height: 1.25;
}

.lap-item {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3em;
  white-space: nowrap;
}

.lap-item i {
  margin: 0 -0.12em;
  font-style: normal;
  opacity: 0.6;
}

.lap-item span:last-child {
  opacity: 0.85;
}

/* ---- the shift clock */
.hud-clock {
  grid-area: clock;
  justify-self: center;
  align-self: start;
  position: relative;
  display: grid;
  justify-items: center;
}

.clock {
  display: inline-flex;
  align-items: baseline;
  padding: 0.13em 0.3em 0.02em;
  border: 0.065em solid var(--yellow);
  border-radius: 0.2em;
  color: var(--white);
  background: var(--ink);
  box-shadow: 0 0 0 0.05em var(--ink), 0 0.1em 0 rgba(0, 0, 0, 0.3);
  font-size: 3.3em;
  line-height: 1;
}

/* Fixed-width cells: the clock must not twitch as digits change. */
.cd {
  display: inline-block;
  width: 0.57em;
  text-align: center;
}

.cs {
  display: inline-block;
  width: 0.25em;
  color: var(--yellow);
  text-align: center;
}

.cd-t {
  width: 0.6em;
  color: var(--yellow);
  font-size: 0.62em;
}

.clock.is-low {
  border-color: var(--white);
  background: var(--red);
  animation: clock-pulse 0.5s ease-in-out infinite;
}

.clock.is-low .cs,
.clock.is-low .cd-t {
  color: var(--white);
}

.hud-vignette {
  position: absolute;
  inset: 0;
  opacity: 0;
  box-shadow: inset 0 0 14vmin 2vmin rgba(229, 55, 43, 0.6);
}

.hud.is-timelow .hud-vignette {
  opacity: 1;
  animation: vignette 1s ease-in-out infinite;
}

/* Combo banner, wrong-way sign and callouts hang under the clock. They are positioned, not
   placed in the grid, so a long callout can never squeeze the side panels. */
.hud-stack {
  --stack-top: calc(var(--safe-t) + var(--hud-pad) + 4.85em);
  position: absolute;
  left: 50%;
  top: var(--stack-top);
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 0.5em;
  width: max-content;
  max-width: min(42em, calc(100vw - 24em));
  /* However many callouts arrive, the stack stops short of whatever sits at the bottom of the
     screen: it is cut off along its lower edge only (the other edges keep room for shadows). */
  max-height: calc(100% - var(--stack-top) - var(--stack-bottom, var(--hud-pad)));
  padding-bottom: 0.6em; /* room for the last item's shadow inside the cut */
  clip-path: inset(-1em -100vw 0 -100vw);
  transform: translateX(-50%);
}

.combo {
  position: relative;
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  column-gap: 0.45em;
  overflow: hidden;
  padding: 0.26em 0.7em 0.34em;
  border: 2px solid var(--ink);
  border-radius: 0.35em;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 0 3px 0 var(--ink);
  line-height: 1;
  transform: rotate(-2deg);
}

.combo-n {
  font-size: 1.7em;
  animation: combo-pop 240ms var(--pop) both;
}

.combo-name {
  font-size: 1.15em;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.combo-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(29, 29, 33, 0.22);
}

.combo-bar > i {
  display: block;
  height: 100%;
  background: var(--ink);
  transform-origin: left center;
}

.wrongway {
  padding: 0.3em 0.9em 0.16em;
  border: 3px solid var(--white);
  border-radius: 0.3em;
  color: var(--white);
  background: var(--red);
  box-shadow: 0 0 0 3px var(--ink);
  font-size: 1.7em;
  letter-spacing: 0.14em;
  line-height: 1;
  white-space: nowrap;
  animation: wrong-way 0.56s steps(1, end) infinite;
}

/* ---- the three ways to win, and the rival roster */
.hud-goals {
  grid-area: goals;
  justify-self: end;
  align-self: start;
  display: grid;
  gap: 0.34em;
  min-width: 9.6em;
}

.goal {
  --gc: var(--yellow);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  column-gap: 0.5em;
  line-height: 1.1;
}

.goal-wrecks {
  --gc: var(--orange);
}

.goal-dummies {
  --gc: var(--teal-hi);
}

.goal .lbl {
  color: var(--gc);
}

.goal-n {
  font-size: 1.15em;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

.goal .bar {
  grid-column: 1 / -1;
  height: 0.3em;
  margin-top: 0.12em;
}

.goal .bar > i {
  background: var(--gc);
}

.goal.is-done .goal-n {
  color: var(--green);
}

.roster {
  display: flex;
  gap: 3px;
  margin-top: 0.18em;
}

.pip {
  position: relative;
  flex: 1 1 0;
  display: grid;
  place-items: center;
  min-width: 0;
  height: 1.8em;
  overflow: hidden;
  padding-bottom: 3px;
  border-radius: 3px;
  color: var(--rc-ink, var(--ink));
  background: var(--rc, var(--orange));
  font-size: 0.9em;
  line-height: 1;
}

.pip > b {
  padding-top: 0.12em;
}

/* Health: a white bar on a dark track along the bottom of the chip. */
.pip::before,
.pip > i {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
}

.pip::before {
  background: rgba(29, 29, 33, 0.7);
}

.pip > i {
  background: #ffffff;
  transform-origin: left center;
}

.pip.is-wrecked {
  color: #a4a8ae;
  background: #4a4c52;
}

.pip.is-wrecked::after {
  content: "";
  position: absolute;
  left: -15%;
  right: -15%;
  top: calc(50% - 2px);
  height: 2px;
  background: var(--red);
  transform: rotate(-28deg);
}

/* ---- power-up chips */
.hud-power {
  grid-area: rside;
  justify-self: end;
  align-self: start;
  display: grid;
  justify-items: end;
  gap: 0.3em;
}

.chip {
  --pc: var(--yellow);
  position: relative;
  overflow: hidden;
  min-width: 8.2em;
  padding: 0.34em 0.6em 0.46em;
  border-left: 0.36em solid var(--pc);
  border-radius: 0.35em;
  color: var(--white);
  background: var(--plate);
  font-size: 0.92em;
  letter-spacing: 0.1em;
  line-height: 1;
  white-space: nowrap;
  animation: chip-in 200ms var(--pop) both;
}

.chip .bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  border-radius: 0;
}

.chip .bar > i {
  background: var(--pc);
}

/* ---- minimap */
.hud-map {
  grid-area: br;
  justify-self: end;
  align-self: end;
  padding: 3px;
  line-height: 0;
}

.minimap {
  display: block;
  width: var(--map);
  height: var(--map);
  border-radius: 0.3em;
}

/* ---- speed, nitro, damage */
.hud-gauges {
  grid-area: bl;
  justify-self: start;
  align-self: end;
  display: flex;
  align-items: center;
  gap: 0.7em;
}

.speed {
  display: grid;
  justify-items: center;
  min-width: 3em;
}

.speed b {
  font-size: 2.5em;
  font-variant-numeric: tabular-nums;
  line-height: 0.92;
}

.speed .lbl {
  font-size: 0.7em;
}

.meters {
  display: grid;
  gap: 0.3em;
}

.meter {
  --mc: #2ad4ff;
  position: relative;
  width: 9em;
  height: 1.3em;
}

.meter .bar {
  position: absolute;
  inset: 0;
  border-radius: 3px;
}

.meter .bar > i {
  background: var(--mc);
}

.meter-lbl {
  position: absolute;
  left: 0.5em;
  top: 50%;
  color: var(--white);
  font-size: 0.8em;
  letter-spacing: 0.15em;
  line-height: 1;
  text-shadow: 1px 0 0 var(--ink), -1px 0 0 var(--ink), 0 1px 0 var(--ink), 0 -1px 0 var(--ink);
  transform: translateY(-46%);
}

.meter-nitro.is-boosting .bar > i {
  background: var(--white);
}

.meter-nitro.is-boosting .bar {
  box-shadow: 0 0 0 2px #2ad4ff;
}

.meter-damage {
  --mc: var(--yellow);
}

.meter-damage[data-level="1"] {
  --mc: var(--orange);
}

.meter-damage[data-level="2"] {
  --mc: var(--red);
}

.meter-damage[data-level="2"] .bar {
  box-shadow: 0 0 0 2px var(--red);
  animation: blink 0.56s steps(1, end) infinite;
}

/* ---- key reminder (desktop only) */
.hud-hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + var(--hud-pad));
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.35em 0.8em;
  border-radius: 0.5em;
  color: rgba(247, 246, 240, 0.92);
  background: rgba(26, 26, 30, 0.6);
  font-size: 0.86em;
  line-height: 1;
  white-space: nowrap;
  transform: translateX(-50%);
}

.hud-hint span {
  margin-right: 0.7em;
}

.hud-hint span:last-child {
  margin-right: 0;
}

/* ---- narrow windows: the clock shares a row with the two side panels, and everything that
   hangs under it drops below them, kept as wide as the gap between minimap and power-ups. */
@media (max-width: 539px) {
  .combo-name {
    white-space: normal;
  }
}

@media (max-width: 539px) and (orientation: portrait) {
  .hud-stack {
    grid-row: 2 / 4;
    grid-column: 1 / -1;
    top: 0;
    max-width: calc(100vw - 2 * var(--stack-side, 9em));
    max-height: 100%; /* its two grid rows end where the gauges begin */
  }
}

@media (max-width: 429px) {
  .clock {
    font-size: 2.5em;
  }

  .hud-score,
  .hud-goals {
    justify-self: stretch;
    min-width: 0;
  }

  .score-val {
    font-size: 1.85em;
  }

  .goal .lbl {
    letter-spacing: 0.06em;
  }

  .goal-n {
    font-size: 1.08em;
  }

  .chip {
    min-width: 0;
    padding-left: 0.45em;
    padding-right: 0.45em;
    letter-spacing: 0.03em;
  }

  .combo {
    padding-left: 0.55em;
    padding-right: 0.55em;
  }

  .combo-n {
    font-size: 1.5em;
  }

  .combo-name {
    font-size: 1em;
  }

  .wrongway {
    padding-left: 0.7em;
    padding-right: 0.7em;
    font-size: 1.35em;
    letter-spacing: 0.08em;
  }
}

/* ---- short windows: everything under the clock is smaller (callouts too, see section 7),
   so the road ahead stays in view. */
@media (max-height: 499px) {
  .hud-stack {
    gap: 0.3em;
  }

  .combo {
    padding-top: 0.2em;
    padding-bottom: 0.28em;
  }

  .combo-n {
    font-size: 1.5em;
  }

  .combo-name {
    font-size: 1em;
  }

  .wrongway {
    border-width: 2px;
    font-size: 1.35em;
  }
}

@media (max-width: 899px), (max-height: 499px) {
  .hud-hint {
    display: none;
  }
}

/* ---- touch layout: keep clear of the buttons input.js puts on screen */
.is-touch .hud-hint {
  display: none;
}

.is-touch .hud-score,
.is-touch .hud-goals {
  margin-top: var(--util-h);
}

.is-touch .hud-map {
  grid-area: lside;
  justify-self: start;
  align-self: start;
}

.is-touch .minimap {
  width: var(--map-touch, 72px);
  height: var(--map-touch, 72px);
}

/* Portrait: the gauges sit just above the steering pad and are no wider than it. */
.is-touch .hud {
  padding-bottom: calc(var(--safe-b) + var(--tb-edge) + var(--tb) + 10px);
}

.is-touch .hud-gauges {
  gap: 0.5em;
  max-width: calc(var(--tb) * 2 + var(--tb-gap));
}

.is-touch .meter {
  width: 6.4em;
}

/* Below this width the clock cannot fit between the two groups of round buttons at the top. */
@media (max-width: 539px) {
  .is-touch .hud-clock {
    margin-top: var(--util-h);
  }

  .is-touch {
    --stack-side: max(96px, calc(var(--map-touch, 72px) + 22px));
  }
}

@media (max-width: 359px) {
  .is-touch {
    --map-touch: 64px;
  }
}

@media (min-height: 700px) and (orientation: portrait) {
  .is-touch {
    --map-touch: 92px;
  }
}

/* Landscape: there is room between the thumbs, so the gauges go bottom centre. */
@media (orientation: landscape) {
  .is-touch .hud {
    padding-bottom: calc(var(--safe-b) + var(--hud-pad));
  }

  /* Callouts stop above those gauges. */
  .is-touch .hud-stack {
    --stack-bottom: calc(var(--safe-b) + var(--tb-edge) + 4.7em);
  }

  .is-touch .hud-gauges {
    position: absolute;
    grid-area: auto;
    left: 50%;
    bottom: calc(var(--safe-b) + var(--tb-edge));
    max-width: none;
    transform: translateX(-50%);
  }

  .is-touch .meter {
    width: 8em;
  }
}

/* A narrow landscape window has the clock one row down, under the round buttons. */
@media (max-width: 539px) and (orientation: landscape) {
  .is-touch .hud-stack {
    --stack-top: calc(var(--safe-t) + var(--hud-pad) + 4.85em + var(--util-h));
  }
}

/* The shortest landscape phones: the side panels must end above the thumb buttons, so the
   map shrinks, the power-up chips slim down and the rival roster (the Wrecks count stays)
   makes way for them. */
@media (orientation: landscape) and (max-height: 359px) {
  .is-touch {
    --map-touch: 56px;
  }

  .is-touch .roster {
    display: none;
  }

  .is-touch .chip {
    padding-top: 0.24em;
    padding-bottom: 0.36em;
  }
}

/* ------------------------------------------------------------------ 7. callouts */
.toasts {
  display: grid;
  justify-items: center;
}

.toast {
  --life: 1.5s;
  display: grid;
  grid-template-rows: 1fr;
  text-align: center;
  animation: toast-life var(--life) linear both;
}

.toast-in {
  display: grid;
  justify-items: center;
  min-height: 0;
  overflow: hidden;
  padding: 0.3em 0.8em 0.4em;
}

.toast b {
  color: var(--white);
  font-size: 1.9em;
  letter-spacing: 0.04em;
  line-height: 1.08;
  overflow-wrap: anywhere;
  text-shadow: var(--outline);
  text-wrap: balance;
}

.toast span {
  color: var(--white);
  font-size: 1em;
  letter-spacing: 0.1em;
  line-height: 1.3;
  text-shadow: var(--outline);
  white-space: pre-wrap;
}

.toast span:empty {
  display: none;
}

.toast-time b {
  color: var(--green);
}

.toast-score b {
  color: var(--yellow);
}

.toast-warn {
  --life: 1.7s;
}

.toast-warn b {
  color: #ff7466;
}

.toast-info {
  --life: 1.6s;
}

.toast-power {
  --life: 1.9s;
}

.toast-power b {
  color: var(--tc, var(--teal-hi));
}

.toast-combo {
  --life: 1.9s;
}

/* Only a little bigger than the rest: a streak must not hide the road ahead. */
.toast-combo b {
  color: var(--yellow);
  font-size: 2.1em;
  transform: rotate(-2deg);
}

/* A callout that was rewritten in place: no fade-in, just a bump. */
.toast.is-again {
  animation-name: toast-again;
}

.countdown {
  position: absolute;
  left: 50%;
  top: 36%;
  z-index: 25;
  color: var(--white);
  font-size: clamp(96px, 38vmin, 320px);
  line-height: 1;
  pointer-events: none;
  text-shadow: var(--outline);
  transform: translate(-50%, -50%);
  animation: count-pop 0.95s var(--out) both;
}

.countdown[data-go="1"] {
  color: var(--yellow);
}

/* Slim windows: sized so the longest single word of a callout (a rival's name) fits the
   column between the map and the power-up chips. */
@media (max-width: 429px) {
  .toast b {
    font-size: 1.4em;
  }

  .toast-combo b {
    font-size: 1.5em;
  }

  .toast span {
    font-size: 0.95em;
    letter-spacing: 0.06em;
  }

  .toast-in {
    padding-left: 0.3em;
    padding-right: 0.3em;
  }
}

/* Short windows: smaller type, and the second line moves up beside the first when there is room. */
@media (max-height: 499px) {
  .toast-in {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: center;
    gap: 0 0.7em;
    padding-top: 0.1em;
    padding-bottom: 0.2em;
  }

  .toast b {
    font-size: 1.45em;
  }

  .toast-combo b {
    font-size: 1.6em;
  }

  .toast span {
    font-size: 0.92em;
    letter-spacing: 0.06em;
  }
}

/* ------------------------------------------------------------------ 8. touch controls */
.touch {
  position: fixed;
  inset: 0;
  z-index: 20;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms linear, visibility 0s linear 140ms;
}

.touch.is-on {
  visibility: visible;
  opacity: 1;
  transition: opacity 140ms linear;
}

.tbtn {
  display: grid;
  place-items: center;
  border: 2px solid rgba(247, 246, 240, 0.75);
  color: var(--white);
  background: rgba(29, 29, 33, 0.5);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.touch.is-on .tbtn {
  pointer-events: auto;
}

.tbtn svg {
  width: 46%;
  height: 46%;
  pointer-events: none;
}

.tbtn.is-down {
  border-color: var(--white);
  color: var(--ink);
  background: rgba(255, 198, 26, 0.92);
  transform: scale(0.95);
}

.tbtn-word {
  font-size: clamp(13px, 3.7vmin, 19px);
  letter-spacing: 0.08em;
  line-height: 1;
  pointer-events: none;
}

.touch-utils {
  position: absolute;
  top: calc(var(--safe-t) + 6px);
  display: flex;
  gap: 6px;
}

.touch-utils-l {
  left: calc(var(--safe-l) + var(--tb-edge));
}

.touch-utils-r {
  right: calc(var(--safe-r) + var(--tb-edge));
}

.tbtn-util {
  width: var(--tb-util);
  height: var(--tb-util);
  border-radius: 50%;
}

.tbtn-util svg {
  width: 50%;
  height: 50%;
}

.touch-steer {
  position: absolute;
  left: calc(var(--safe-l) + var(--tb-edge));
  bottom: calc(var(--safe-b) + var(--tb-edge));
  display: flex;
  gap: var(--tb-gap);
}

.tbtn-steer {
  width: var(--tb);
  height: var(--tb);
  border-radius: 22%;
}

.touch-pedals {
  position: absolute;
  right: calc(var(--safe-r) + var(--tb-edge));
  bottom: calc(var(--safe-b) + var(--tb-edge));
  display: grid;
  grid-template-columns: var(--tb) var(--tb);
  gap: var(--tb-gap);
}

.tbtn-pedal {
  height: var(--tb);
  border-radius: 22%;
}

.tbtn-mod {
  height: var(--tb-mod);
  border-radius: 16px;
}

.tbtn-gas {
  border-color: var(--yellow);
  color: var(--yellow);
}

.tbtn-brake {
  border-color: #ff8a7d;
  color: #ffb1a8;
}

.tbtn-boost {
  border-color: #6fe3ff;
  color: #a5efff;
}

/* The mute button shows waves or a cross: ui.js keeps data-muted on <html> in step. */
.snd-off,
[data-muted="1"] .snd-on {
  display: none;
}

[data-muted="1"] .snd-off {
  display: inline;
}

/* ------------------------------------------------------------------ 9. motion */
@keyframes load-slide {
  from {
    transform: translateX(-1.7em);
  }

  to {
    transform: translateX(0);
  }
}

@keyframes clock-pulse {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.07);
  }
}

@keyframes vignette {
  0%,
  100% {
    opacity: 0.45;
  }

  50% {
    opacity: 1;
  }
}

@keyframes blink {
  0% {
    opacity: 1;
  }

  50% {
    opacity: 0.35;
  }
}

/* The sign swaps its colours instead of fading, so it reads at full strength all the time. */
@keyframes wrong-way {
  0% {
    color: var(--white);
    background: var(--red);
    border-color: var(--white);
  }

  50% {
    color: var(--red);
    background: var(--white);
    border-color: var(--red);
  }
}

@keyframes combo-pop {
  from {
    transform: scale(1.7);
  }

  to {
    transform: scale(1);
  }
}

@keyframes chip-in {
  from {
    opacity: 0;
    transform: translateX(1.2em);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes car-in {
  from {
    opacity: 0;
    transform: translateX(1.4em);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes car-in-prev {
  from {
    opacity: 0;
    transform: translateX(-1.4em);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes newbest {
  0%,
  100% {
    transform: rotate(-4deg) scale(1);
  }

  50% {
    transform: rotate(-4deg) scale(1.22);
  }
}

/* A callout pops in, drifts up while it is read, then fades and folds away so the ones
   below it close the gap smoothly. */
@keyframes toast-life {
  0% {
    grid-template-rows: 1fr;
    opacity: 0;
    transform: translateY(0.9em) scale(0.6);
  }

  8% {
    opacity: 1;
    transform: translateY(0) scale(1.14);
  }

  15% {
    transform: translateY(-0.05em) scale(1);
  }

  82% {
    grid-template-rows: 1fr;
    opacity: 1;
    transform: translateY(-0.45em) scale(1);
  }

  100% {
    grid-template-rows: 0fr;
    opacity: 0;
    transform: translateY(-1.1em) scale(0.96);
  }
}

@keyframes toast-again {
  0% {
    grid-template-rows: 1fr;
    opacity: 1;
    transform: translateY(0) scale(1.16);
  }

  12% {
    transform: translateY(-0.05em) scale(1);
  }

  82% {
    grid-template-rows: 1fr;
    opacity: 1;
    transform: translateY(-0.45em) scale(1);
  }

  100% {
    grid-template-rows: 0fr;
    opacity: 0;
    transform: translateY(-1.1em) scale(0.96);
  }
}

@keyframes toast-fade {
  0%,
  100% {
    opacity: 0;
  }

  8%,
  84% {
    opacity: 1;
  }
}

@keyframes toast-hold {
  0%,
  84% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

@keyframes count-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(2.2) rotate(-8deg);
  }

  16% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(-3deg);
  }

  68% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(0.96) rotate(-3deg);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.7) rotate(-3deg);
  }
}

@keyframes count-fade {
  0%,
  100% {
    opacity: 0;
  }

  12%,
  70% {
    opacity: 1;
  }
}

@media (hover: hover) {
  .btn:hover {
    background: #ffffff;
  }

  .btn-big:hover {
    background: var(--yellow-hi);
  }

  .arrow-btn:hover {
    background: var(--yellow-hi);
  }

  .tab:hover {
    background: rgba(255, 198, 26, 0.18);
  }

  .tab[aria-pressed="true"]:hover {
    background: var(--yellow-hi);
  }
}

/* ------------------------------------------------------------------ 10. reduced motion */
/* No shaking, pulsing or flashing: states are shown by colour alone and callouts only fade. */
@media (prefers-reduced-motion: reduce) {
  .loadbar > i,
  .clock.is-low,
  .hud.is-timelow .hud-vignette,
  .wrongway,
  .meter-damage[data-level="2"] .bar,
  .combo-n,
  .chip,
  .car-text,
  .newbest {
    animation: none;
  }

  .toast {
    animation-name: toast-fade;
  }

  .toast.is-again {
    animation-name: toast-hold;
  }

  .countdown {
    animation-name: count-fade;
  }

  .btn,
  .arrow-btn,
  .touch,
  .touch.is-on {
    transition: none;
  }

  .btn:active,
  .arrow-btn:active,
  .tbtn.is-down {
    transform: none;
  }
}
