@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

:root {
  color: #fff6d3;
  background: #090b18;
  font-family: 'VT323', monospace;
  font-synthesis: none;
  --ink: #090b18;
  --navy: #111936;
  --cream: #fff6d3;
  --orange: #ff5a3d;
  --yellow: #ffe45c;
  --acid: #bafc4f;
  --cyan: #43e7ff;
  --pink: #ff4fa7;
  --purple: #7137c8;
  --line: rgba(67, 231, 255, 0.55);
  --pixel-font: 'Press Start 2P', monospace;
  --shadow: 4px 4px 0 var(--ink), 7px 7px 0 var(--purple);
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

body {
  min-height: 100svh;
  background: var(--ink);
}

body::after {
  position: fixed;
  z-index: 40;
  inset: 0;
  background: var(--ink);
  content: '';
  pointer-events: none;
  animation: attract-reveal 1.15s steps(8, end) forwards;
}

.screen-filters {
  position: fixed;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

.screen {
  position: fixed;
  inset: 0;
  filter: url('#screen-chromatic');
}

body.is-drifting .screen {
  filter: url('#drift-chromatic');
}

body::before {
  position: fixed;
  z-index: 3;
  inset: 8px;
  border: 4px solid var(--cream);
  box-shadow:
    inset 0 0 0 4px var(--ink),
    inset 0 0 0 7px var(--cyan),
    0 0 20px rgba(67, 231, 255, 0.35);
  content: '';
  pointer-events: none;
}

button,
a { font: inherit; }

button { color: inherit; }

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 4px solid var(--yellow);
  outline-offset: 5px;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.pixel-grid {
  position: fixed;
  z-index: 35;
  inset: 0;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(0deg, rgba(4, 5, 14, 0.18) 0, rgba(4, 5, 14, 0.18) 1px, transparent 1px, transparent 4px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0, rgba(255, 255, 255, 0.025) 1px, transparent 1px, transparent 4px),
    radial-gradient(circle at center, transparent 38%, rgba(4, 5, 14, 0.58) 115%);
  mix-blend-mode: multiply;
  opacity: 0.68;
  transition: opacity 120ms steps(2, end);
}

body.is-drifting .pixel-grid { opacity: 0.88; }

.topbar {
  position: fixed;
  z-index: 10;
  top: 22px;
  left: 50%;
  display: flex;
  width: calc(100% - 44px);
  min-height: 3.15rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem clamp(0.8rem, 2vw, 1.4rem);
  border: 3px solid var(--ink);
  color: var(--cream);
  background: var(--navy);
  box-shadow: 0 4px 0 var(--cyan), 0 7px 0 var(--ink);
  transform: translateX(-50%);
  transition: opacity 240ms steps(4, end), transform 320ms steps(5, end), visibility 240ms;
}

body:not(.is-playing) .topbar {
  visibility: hidden;
  opacity: 0;
  transform: translate(-50%, -1rem);
}

.wordmark {
  padding: 0;
  border: 0;
  color: var(--yellow);
  background: transparent;
  font-family: var(--pixel-font);
  font-size: clamp(0.54rem, 1.2vw, 0.78rem);
  line-height: 1.5;
  letter-spacing: 0.02em;
  text-shadow: 2px 2px 0 var(--pink);
  cursor: pointer;
}

.wordmark span { color: var(--cyan); }

.topbar nav { display: flex; gap: 1rem; }

.topbar a,
.topbar button {
  padding: 0;
  border: 0;
  color: var(--acid);
  background: transparent;
  font-family: var(--pixel-font);
  font-size: clamp(0.42rem, 0.8vw, 0.56rem);
  line-height: 1.5;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
}

.topbar a:hover,
.topbar button:hover {
  color: var(--yellow);
  animation: text-blink 360ms steps(2, end) infinite;
}

.topbar button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  animation: none;
}

.hero {
  position: fixed;
  z-index: 5;
  inset: 0;
  width: 100%;
  height: 100svh;
  color: var(--cream);
  background:
    radial-gradient(circle at 50% 52%, rgba(9, 11, 24, 0.3) 0, rgba(9, 11, 24, 0.58) 72%),
    linear-gradient(180deg, rgba(9, 11, 24, 0.68) 0, rgba(9, 11, 24, 0.38) 55%, rgba(9, 11, 24, 0.68) 100%);
  text-align: center;
  transition: opacity 280ms steps(4, end), transform 400ms steps(5, end), visibility 280ms;
}

.hero.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: scale(1.06);
}

.hero__title {
  position: absolute;
  top: clamp(3.25rem, 9vh, 5.75rem);
  left: 50%;
  width: min(72rem, calc(100vw - 4rem));
  transform: translateX(-50%);
}

.hero__start {
  position: absolute;
  bottom: clamp(2rem, 5vh, 4rem);
  left: 50%;
  width: min(30rem, calc(100vw - 3rem));
  transform: translateX(-50%);
}

.hero__controls,
.hero__coin,
.speed-hud,
.route-hud,
.timer-hud,
.drift-hud,
.surface-hud,
.control-hint {
  font-family: var(--pixel-font);
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--cream);
  font-family: var(--pixel-font);
  font-size: clamp(3.8rem, 10.5vw, 9.2rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.065em;
  text-transform: uppercase;
  filter: url('#title-chromatic') drop-shadow(0 7px 0 rgba(9, 11, 24, 0.92));
}

h1 span {
  display: block;
}

h1 span + span {
  margin-top: 0.14em;
}

.hero__intro {
  margin: 1.35rem 0 0;
  color: var(--cyan);
  font-family: var(--pixel-font);
  font-size: clamp(0.48rem, 1vw, 0.72rem);
  line-height: 1.7;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 var(--ink);
}

.start-button {
  display: inline-flex;
  min-height: 2.6rem;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  margin-top: 0;
  padding: 0.5rem 0.8rem;
  border: 0;
  border-radius: 0;
  color: var(--yellow);
  background: rgba(9, 11, 24, 0.72);
  box-shadow: none;
  font-family: var(--pixel-font);
  font-size: clamp(0.58rem, 1vw, 0.76rem);
  line-height: 1.45;
  text-transform: uppercase;
  text-shadow: 3px 3px 0 var(--orange);
  cursor: pointer;
  animation: text-blink 1s steps(2, end) infinite;
}

.start-button:hover {
  color: var(--cream);
  background: rgba(9, 11, 24, 0.9);
  text-shadow: 3px 3px 0 var(--pink);
  animation: none;
}

.start-button:active {
  transform: translateY(2px);
}

.hero__controls {
  margin: 0.8rem 0 0;
  color: rgba(255, 246, 211, 0.7);
  font-size: clamp(0.34rem, 0.58vw, 0.46rem);
  line-height: 1.7;
  text-shadow: 2px 2px 0 var(--ink);
}

.hero__coin {
  margin: 2rem 0 0;
  color: rgba(255, 246, 211, 0.58);
  font-size: clamp(0.3rem, 0.5vw, 0.4rem);
  letter-spacing: 0.08em;
  text-shadow: 2px 2px 0 var(--ink);
}

.game-ui {
  visibility: hidden;
  opacity: 0;
  transition: opacity 180ms steps(3, end), visibility 180ms;
}

.game-ui.is-active {
  visibility: visible;
  opacity: 1;
}

.speed-hud {
  position: fixed;
  z-index: 6;
  right: clamp(1.8rem, 3vw, 3rem);
  bottom: 2rem;
  display: grid;
  min-width: 13.5rem;
  padding: 0.85rem 0.9rem 0.7rem;
  border: 4px solid var(--cream);
  grid-template-columns: 1fr auto;
  align-items: end;
  color: var(--cream);
  background: rgba(9, 11, 24, 0.88);
  box-shadow: var(--shadow);
  text-align: right;
}

.speed-hud::before {
  position: absolute;
  top: -0.58rem;
  left: 0.8rem;
  padding: 0 0.4rem;
  color: var(--cyan);
  background: var(--ink);
  content: 'SPEED';
  font-size: 0.42rem;
}

.speed-hud > span {
  color: var(--yellow);
  font-family: 'VT323', monospace;
  font-size: clamp(4.2rem, 7vw, 6.8rem);
  font-weight: 400;
  line-height: 0.65;
  letter-spacing: 0.02em;
  text-shadow: 4px 4px 0 var(--orange);
}

.speed-hud small {
  margin-left: 0.5rem;
  color: var(--cyan);
  font-size: 0.5rem;
  line-height: 1.5;
}

.speed-hud b {
  grid-column: 1 / -1;
  margin-top: 0.8rem;
  color: var(--acid);
  font-size: 0.5rem;
  font-weight: 400;
}

.route-hud {
  position: fixed;
  z-index: 6;
  top: 6.4rem;
  left: 50%;
  display: grid;
  width: min(35rem, 48vw);
  padding: 0.65rem 0.75rem;
  border: 3px solid var(--cream);
  grid-template-columns: auto 1fr auto;
  gap: 0.8rem;
  align-items: center;
  color: var(--cream);
  background: var(--navy);
  box-shadow: 4px 4px 0 var(--purple);
  font-size: 0.45rem;
  line-height: 1.45;
  transform: translateX(-50%);
}

.route-hud p { margin: 0; }
.route-hud p:last-child { color: var(--yellow); }

.route-track {
  height: 12px;
  padding: 2px;
  overflow: hidden;
  border: 2px solid var(--cyan);
  background: var(--ink);
}

.route-track span {
  display: block;
  width: 0;
  height: 100%;
  background: repeating-linear-gradient(90deg, var(--acid) 0 6px, var(--yellow) 6px 10px);
}

.timer-hud {
  position: fixed;
  z-index: 6;
  top: 6.4rem;
  left: clamp(1.8rem, 3vw, 3rem);
  display: flex;
  padding: 0.7rem 0.75rem;
  border: 3px solid var(--cream);
  align-items: baseline;
  gap: 0.65rem;
  color: var(--cream);
  background: var(--navy);
  box-shadow: 4px 4px 0 var(--pink);
}

.timer-hud span {
  color: var(--cyan);
  font-size: 0.42rem;
}

.timer-hud strong {
  min-width: 7rem;
  color: var(--yellow);
  font-family: 'VT323', monospace;
  font-size: 1.35rem;
  font-weight: 400;
  letter-spacing: 0.04em;
}

.drift-hud {
  position: fixed;
  z-index: 7;
  top: 31%;
  left: 50%;
  --drift-scale: 1;
  color: var(--yellow);
  opacity: 0;
  filter: drop-shadow(5px 5px 0 var(--orange)) drop-shadow(5px 5px 0 var(--purple));
  pointer-events: none;
  transform: translate(-50%, 1rem) scale(calc(var(--drift-scale) * 0.7)) rotate(-4deg);
  transform-origin: center;
  transition: opacity 90ms steps(2, end), transform 120ms steps(3, end);
}

.drift-hud.is-active {
  opacity: 1;
  transform: translate(-50%, 0) scale(var(--drift-scale)) rotate(-4deg);
}

.drift-hud strong {
  display: block;
  min-width: 4ch;
  font-family: var(--pixel-font);
  font-size: clamp(1.8rem, 4vw, 3.6rem);
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.08em;
  text-align: center;
  -webkit-text-stroke: 2px var(--ink);
}

.drift-hud strong small {
  margin-left: 0.12em;
  font-size: 0.42em;
  letter-spacing: 0;
  -webkit-text-stroke-width: 1px;
}

.drift-hud.is-boosting {
  color: var(--acid);
  filter: drop-shadow(5px 5px 0 var(--cyan)) drop-shadow(5px 5px 0 var(--purple));
}

.surface-hud {
  position: fixed;
  z-index: 6;
  top: 6.4rem;
  right: clamp(1.8rem, 3vw, 3rem);
  padding: 0.72rem 0.65rem;
  border: 3px solid var(--cream);
  color: var(--ink);
  background: var(--acid);
  box-shadow: 4px 4px 0 var(--ink);
  font-size: 0.43rem;
  line-height: 1.3;
}

.surface-hud.is-offroad {
  color: var(--cream);
  background: var(--orange);
  animation: text-blink 320ms steps(2, end) infinite;
}

.control-hint {
  position: fixed;
  z-index: 6;
  bottom: 2rem;
  left: clamp(1.8rem, 3vw, 3rem);
  display: flex;
  padding: 0.55rem 0.6rem;
  border: 3px solid var(--cream);
  gap: 0.85rem;
  align-items: center;
  color: var(--cream);
  background: rgba(9, 11, 24, 0.86);
  box-shadow: 4px 4px 0 var(--cyan);
  font-size: 0.38rem;
  line-height: 1.4;
}

.control-hint p {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  margin: 0;
}

kbd {
  min-width: 1.5rem;
  padding: 0.3rem;
  border: 2px solid var(--cream);
  color: var(--yellow);
  background: var(--navy);
  box-shadow: 2px 2px 0 var(--purple);
  font-family: inherit;
  text-align: center;
}

.mobile-controls { display: none; }

.countdown {
  position: fixed;
  z-index: 20;
  top: 50%;
  left: 50%;
  color: var(--yellow);
  font-family: var(--pixel-font);
  font-size: clamp(6rem, 18vw, 13rem);
  font-weight: 400;
  line-height: 1;
  pointer-events: none;
  text-shadow: 8px 8px 0 var(--orange), 14px 14px 0 var(--purple);
  opacity: 0;
  transform: translate(-50%, -50%) scale(1.35);
}

.countdown.is-visible { animation: countdown-pop 650ms steps(5, end); }

.milestone-screen {
  position: fixed;
  z-index: 23;
  inset: 0;
  display: grid;
  padding: clamp(1.2rem, 4vw, 3rem);
  background: linear-gradient(180deg, transparent 10%, rgba(9, 11, 24, 0.48) 48%, rgba(9, 11, 24, 0.92) 100%);
  place-items: end center;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms steps(3, end), visibility 120ms;
}

.milestone-screen.is-active {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.milestone-tooltip {
  position: relative;
  width: min(54rem, calc(100vw - 3rem));
  border: 5px solid var(--cream);
  color: var(--cream);
  background: var(--navy);
  box-shadow:
    0 0 0 4px var(--ink),
    0 0 0 7px var(--cyan),
    10px 10px 0 7px var(--purple);
  transform: translateY(1.2rem);
  transition: transform 160ms steps(4, end);
}

.milestone-screen.is-active .milestone-tooltip { transform: translateY(0); }

.milestone-tooltip::before {
  position: absolute;
  top: -1.6rem;
  left: clamp(2rem, 12vw, 7rem);
  width: 1.5rem;
  height: 1.5rem;
  border-top: 5px solid var(--cream);
  border-left: 5px solid var(--cream);
  background: var(--navy);
  content: '';
  transform: rotate(45deg);
}

.milestone-tooltip__header {
  display: flex;
  min-height: 2.35rem;
  padding: 0.55rem 0.75rem;
  align-items: center;
  justify-content: space-between;
  color: var(--ink);
  background: var(--cyan);
  font-family: var(--pixel-font);
  font-size: clamp(0.38rem, 0.75vw, 0.5rem);
  line-height: 1.5;
  text-transform: uppercase;
}

.milestone-tooltip__header p { margin: 0; }

.milestone-tooltip__header span {
  color: var(--navy);
  animation: text-blink 900ms steps(2, end) infinite;
}

.milestone-tooltip__body { padding: clamp(1rem, 3vw, 1.7rem); }

.milestone-tooltip h2 {
  margin: 0;
  color: var(--yellow);
  font-family: var(--pixel-font);
  font-size: clamp(1.25rem, 4vw, 2.5rem);
  font-weight: 400;
  line-height: 1.25;
  text-shadow: 4px 4px 0 var(--orange);
  text-transform: uppercase;
}

.milestone-tooltip__body > p:last-of-type {
  max-width: 48rem;
  margin: 1rem 0 0;
  color: var(--cream);
  font-size: clamp(1.2rem, 2.4vw, 1.55rem);
  line-height: 1.25;
}

.milestone-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin: 1.1rem 0 0;
  padding: 0;
  list-style: none;
}

.milestone-stats li {
  padding: 0.65rem 0.8rem;
  border: 3px solid var(--acid);
  color: var(--acid);
  background: var(--ink);
  font-family: var(--pixel-font);
  font-size: clamp(0.44rem, 0.9vw, 0.58rem);
  line-height: 1.5;
  text-transform: uppercase;
}

.milestone-stats[hidden] { display: none; }

.milestone-tooltip__actions {
  display: grid;
  border-top: 4px solid var(--cream);
  grid-template-columns: 1fr 1fr;
}

.milestone-tooltip__actions.is-single-action { grid-template-columns: 1fr; }

.milestone-tooltip__actions.is-single-action button { border-left: 0; }

.milestone-tooltip__actions a,
.milestone-tooltip__actions button {
  display: flex;
  min-height: 3.5rem;
  padding: 0.75rem 1rem;
  border: 0;
  border-radius: 0;
  align-items: center;
  justify-content: space-between;
  color: var(--ink);
  background: var(--acid);
  font-family: var(--pixel-font);
  font-size: clamp(0.38rem, 0.75vw, 0.52rem);
  line-height: 1.5;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
}

.milestone-tooltip__actions a[hidden] { display: none; }

.milestone-tooltip__actions button {
  border-left: 4px solid var(--cream);
  color: var(--cream);
  background: var(--purple);
}

.milestone-tooltip__actions a:hover,
.milestone-tooltip__actions button:hover {
  color: var(--ink);
  background: var(--yellow);
}

body.is-reading .game-ui { opacity: 0.28; }
body.is-reading .mobile-controls { pointer-events: none; }

.finish-screen {
  position: fixed;
  z-index: 25;
  inset: 0;
  display: grid;
  padding: 1.25rem;
  background:
    repeating-linear-gradient(0deg, rgba(113, 55, 200, 0.2) 0 4px, transparent 4px 8px),
    rgba(9, 11, 24, 0.88);
  place-items: center;
  visibility: hidden;
  opacity: 0;
  transition: opacity 140ms steps(3, end), visibility 140ms;
}

.finish-screen.is-active {
  visibility: visible;
  opacity: 1;
}

.finish-panel {
  position: relative;
  width: min(38rem, 100%);
  max-height: calc(100svh - 3rem);
  overflow-y: auto;
  padding: clamp(1.6rem, 5vw, 3rem);
  border: 6px double var(--cream);
  color: var(--cream);
  background: var(--navy);
  box-shadow: 10px 10px 0 var(--pink), 16px 16px 0 var(--ink);
  text-align: center;
  transform: translateY(1rem) scale(0.96);
  transition: transform 180ms steps(4, end);
}

.finish-panel::before,
.finish-panel::after {
  position: absolute;
  top: 1.2rem;
  color: var(--yellow);
  content: '★';
  font-family: var(--pixel-font);
  font-size: 1rem;
}

.finish-panel::before { left: 1.2rem; }
.finish-panel::after { right: 1.2rem; }
.finish-screen.is-active .finish-panel { transform: translateY(0) scale(1); }

.finish-panel__kicker {
  display: inline-block;
  margin: 0;
  padding: 0.45rem 0.55rem;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 4px 4px 0 var(--orange);
  font-family: var(--pixel-font);
  font-size: 0.62rem;
  line-height: 1.5;
  text-transform: uppercase;
  animation: text-blink 720ms steps(2, end) infinite;
}

.finish-panel h2 {
  margin: 1.5rem 0 0;
  color: var(--cyan);
  font-family: 'VT323', monospace;
  font-size: clamp(4rem, 11vw, 7rem);
  font-weight: 400;
  line-height: 0.8;
  text-shadow: 5px 5px 0 var(--purple);
}

.finish-panel > p:not(.finish-panel__kicker) {
  margin: 1.3rem 0 0;
  color: var(--cream);
  font-size: 1.5rem;
}

.finish-leaderboard {
  margin-top: 1.25rem;
  border: 3px solid var(--cream);
  background: var(--ink);
  text-align: left;
}

.finish-leaderboard__header {
  display: flex;
  padding: 0.6rem 0.75rem;
  align-items: center;
  justify-content: flex-start;
  border-bottom: 3px solid var(--cream);
  color: var(--ink);
  background: var(--yellow);
  font-family: var(--pixel-font);
  line-height: 1.5;
  text-transform: uppercase;
}

.finish-leaderboard__header h3 {
  margin: 0;
  font-size: 0.52rem;
  font-weight: 400;
}

.score-entry {
  margin-top: 0;
  padding: 1rem;
  border: 3px solid var(--cyan);
  border-top: 0;
  background: var(--ink);
  text-align: left;
}

.score-entry[hidden] { display: none; }

.score-entry label {
  display: block;
  margin-bottom: 0.7rem;
  color: var(--yellow);
  font-family: var(--pixel-font);
  font-size: 0.46rem;
  line-height: 1.5;
  text-transform: uppercase;
}

.score-entry__controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.7rem;
}

.score-entry input {
  width: 100%;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  border: 4px solid var(--cream);
  border-radius: 0;
  color: var(--yellow);
  background: var(--navy);
  font-family: var(--pixel-font);
  font-size: 1.15rem;
  letter-spacing: 0.3em;
  text-align: center;
  text-transform: uppercase;
}

.score-entry button {
  padding: 0.6rem 0.9rem;
  border: 4px solid var(--cream);
  border-radius: 0;
  color: var(--ink);
  background: var(--acid);
  font-family: var(--pixel-font);
  font-size: 0.42rem;
  line-height: 1.5;
  text-transform: uppercase;
  cursor: pointer;
}

.score-entry button:disabled,
.score-entry input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.score-entry > p {
  min-height: 1.2em;
  margin: 0.7rem 0 0;
  color: var(--cream);
  font-size: 1rem;
  line-height: 1.2;
}

.finish-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  margin-top: 1.8rem;
}

.finish-actions.is-single-action { grid-template-columns: 1fr; }

.finish-actions a,
.finish-actions button {
  display: flex;
  min-height: 4rem;
  padding: 0.9rem;
  border: 4px solid var(--cream);
  border-radius: 0;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: var(--acid);
  box-shadow: 4px 4px 0 var(--orange);
  font-family: var(--pixel-font);
  font-size: 0.5rem;
  line-height: 1.6;
  text-decoration: none;
  text-transform: uppercase;
  cursor: pointer;
}

.finish-actions a[hidden] { display: none; }

#start-again {
  flex-direction: column;
  gap: 0.25rem;
}

.finish-actions.is-single-action #start-again {
  min-height: 5.25rem;
  font-size: clamp(0.62rem, 1.2vw, 0.78rem);
}

.finish-actions button {
  color: var(--cream);
  background: var(--purple);
  box-shadow: 4px 4px 0 var(--cyan);
}

.finish-actions a:hover,
.finish-actions button:hover {
  color: var(--ink);
  background: var(--yellow);
  transform: translate(2px, 2px);
}

.scoreboard-screen {
  position: fixed;
  z-index: 28;
  inset: 0;
  display: grid;
  padding: 1.25rem;
  background: rgba(9, 11, 24, 0.9);
  place-items: center;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms steps(3, end), visibility 140ms;
}

.scoreboard-screen.is-active {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.scoreboard-panel {
  width: min(36rem, 100%);
  max-height: calc(100svh - 2.5rem);
  overflow-y: auto;
  border: 5px solid var(--cream);
  color: var(--cream);
  background: var(--navy);
  box-shadow: 8px 8px 0 var(--cyan), 14px 14px 0 var(--purple);
}

.scoreboard-panel__header {
  display: flex;
  padding: 1.2rem;
  align-items: flex-start;
  justify-content: space-between;
  border-bottom: 4px solid var(--cream);
  background: var(--ink);
}

.scoreboard-panel h2 {
  margin: 0;
  color: var(--yellow);
  font-family: var(--pixel-font);
  font-size: clamp(1rem, 4vw, 1.75rem);
  font-weight: 400;
  line-height: 1.3;
  text-shadow: 3px 3px 0 var(--orange);
  text-transform: uppercase;
}

#scoreboard-close {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 3px solid var(--cream);
  border-radius: 0;
  color: var(--cream);
  background: var(--purple);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
}

.scoreboard-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.scoreboard-list li {
  display: grid;
  padding: 0.8rem 1.1rem;
  border-bottom: 2px solid rgba(255, 246, 211, 0.25);
  grid-template-columns: 3rem 1fr auto;
  gap: 0.7rem;
  align-items: center;
  font-family: var(--pixel-font);
  font-size: clamp(0.46rem, 1.4vw, 0.65rem);
  line-height: 1.5;
}

.scoreboard-list li:nth-child(1) { color: var(--yellow); background: rgba(255, 228, 92, 0.08); }
.scoreboard-list li:nth-child(2) { color: var(--cyan); }
.scoreboard-list li:nth-child(3) { color: var(--pink); }
.scoreboard-list li span { opacity: 0.6; }
.scoreboard-list li time { font-family: 'VT323', monospace; font-size: 1.55rem; }

.scoreboard-list--compact li {
  padding: 0.42rem 0.75rem;
  grid-template-columns: 2.4rem 1fr auto;
  font-size: clamp(0.38rem, 1vw, 0.5rem);
}

.scoreboard-list--compact li time { font-size: 1.2rem; }

.finish-leaderboard .scoreboard-message {
  padding: 1rem 0.75rem;
  font-size: 1.05rem;
}

.scoreboard-message {
  margin: 0;
  padding: 2rem 1.2rem;
  color: var(--cream);
  font-size: 1.3rem;
  text-align: center;
}

.scoreboard-message[hidden] { display: none; }

.noscript {
  position: fixed;
  z-index: 30;
  inset: 2rem;
  padding: 1rem;
  border: 4px solid var(--cream);
  color: var(--yellow);
  background: var(--navy);
  box-shadow: var(--shadow);
  font-family: var(--pixel-font);
  font-size: 0.7rem;
  line-height: 1.8;
}

@keyframes start-pulse {
  50% { color: var(--cream); background: var(--orange); }
}

@keyframes attract-reveal {
  0%, 18% { visibility: visible; opacity: 1; }
  100% { visibility: hidden; opacity: 0; }
}

@keyframes text-blink {
  50% { opacity: 0.35; }
}

@keyframes countdown-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
  18% { opacity: 1; }
  72% { opacity: 1; transform: translate(-50%, -50%) scale(0.95); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(0.72); }
}

@media (max-width: 900px) {
  .control-hint p:nth-child(2) { display: none; }
  .route-hud { width: 42vw; }
}

@media (max-width: 760px) {
  body::before { inset: 5px; border-width: 3px; }

  .topbar {
    top: 14px;
    width: calc(100% - 28px);
    min-height: 2.8rem;
    padding: 0.65rem 0.75rem;
  }

  .wordmark { font-size: 0.48rem; }
  .topbar a,
  .topbar button { font-size: 0.36rem; }

  .hero {
    width: 100%;
  }

  .hero.is-hidden { transform: scale(1.04); }
  .hero__title { top: 7vh; width: calc(100vw - 2.8rem); }
  .hero__start { bottom: 4vh; }
  h1 { font-size: clamp(3.2rem, 17vw, 5.2rem); }
  .hero__intro { margin-top: 1rem; font-size: 0.42rem; }
  .start-button { min-width: 0; min-height: 2.8rem; font-size: 0.52rem; }
  .hero__controls { font-size: 0.32rem; }
  .hero__coin { margin-top: 1.4rem; font-size: 0.28rem; }

  .route-hud {
    top: 4.8rem;
    width: calc(100vw - 2.8rem);
  }

  .route-hud p:first-child { display: none; }
  .route-hud { grid-template-columns: 1fr auto; }

  .surface-hud {
    top: 8.1rem;
    right: 1.4rem;
  }

  .timer-hud {
    top: 8.1rem;
    left: 1.4rem;
  }

  .timer-hud span { display: none; }
  .timer-hud strong { min-width: auto; font-size: 1.1rem; }
  .drift-hud { top: 29%; }

  .drift-hud strong {
    font-size: clamp(1.6rem, 8vw, 3rem);
    -webkit-text-stroke-width: 1px;
  }

  .speed-hud {
    right: 1.4rem;
    bottom: 6.6rem;
    min-width: 10.5rem;
    padding: 0.75rem;
  }

  .speed-hud > span { font-size: 4.3rem; }
  .control-hint { display: none; }

  .mobile-controls {
    position: fixed;
    z-index: 8;
    right: 1.1rem;
    bottom: 1.1rem;
    left: 1.1rem;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 0.55rem;
    align-items: end;
  }

  .mobile-controls__steer,
  .mobile-controls__pedals {
    display: grid;
    grid-template-columns: repeat(2, minmax(2.8rem, 4rem));
    gap: 0.35rem;
  }

  .mobile-controls__pedals { justify-content: end; }

  .mobile-controls button {
    height: 3.15rem;
    padding: 0;
    border: 3px solid var(--cream);
    border-radius: 0;
    color: var(--yellow);
    background: rgba(9, 11, 24, 0.88);
    box-shadow: 3px 3px 0 var(--purple);
    font-family: var(--pixel-font);
    font-size: 0.8rem;
    touch-action: none;
  }

  .mobile-controls .drift-button {
    width: 4.3rem;
    color: var(--ink);
    background: var(--acid);
    box-shadow: 3px 3px 0 var(--orange);
    font-size: 0.48rem;
    text-transform: uppercase;
  }

  .mobile-controls button.is-pressed {
    color: var(--ink);
    background: var(--yellow);
    box-shadow: 1px 1px 0 var(--purple);
    transform: translate(2px, 2px);
  }

  .mobile-controls .drift-button.is-pressed {
    color: var(--cream);
    background: var(--orange);
  }

  .finish-actions { grid-template-columns: 1fr; }
  .finish-panel { padding: 1.25rem; }
  .score-entry__controls { grid-template-columns: 1fr; }

  .milestone-screen {
    padding: 1rem;
    place-items: center;
  }

  .milestone-tooltip {
    width: calc(100vw - 2rem);
    max-height: calc(100svh - 2rem);
    overflow-y: auto;
    box-shadow: 6px 6px 0 5px var(--purple);
  }

  .milestone-tooltip::before { display: none; }
  .milestone-tooltip__header span { display: none; }
  .milestone-tooltip__body { padding: 1rem; }
  .milestone-tooltip__actions { grid-template-columns: 1fr; }

  .milestone-tooltip__actions button {
    border-top: 4px solid var(--cream);
    border-left: 0;
  }
}

@media (max-width: 430px) and (max-height: 720px) {
  .hero__title { top: 5vh; }
  .hero__start { bottom: 2.5vh; }
  .hero__coin { display: none; }
  .speed-hud { bottom: 5.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
