:root {
  --pad: #051c24;
  --pad-deep: #082a33;
  --ink: #EAF8F4;
  --muted: #8FB2AE;
  --line: rgba(120, 240, 255, 0.16);
  --red: #ff5cbe; /* decorative accent: the world's magenta rumble, not a warning */
  --red-hot: #ff4d6a; /* warnings only: low time, behind, empty charge, penalties */
  --ice: #8FF3FF;
  --ice-soft: rgba(143, 243, 255, 0.2);
  --gold: #F2D38A; /* medals + boost, like the gold boost gates */
  --sand: #F7B6DA;
  --violet: #3FB8B0;
  --glass: rgba(6, 34, 42, 0.58);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--pad-deep);
  color: var(--ink);
  font-family: "Bahnschrift", "DIN Alternate", "Segoe UI Condensed", "Helvetica Neue", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

body {
  min-height: 100dvh;
}

button,
a {
  font: inherit;
  color: inherit;
}

#game {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(255, 92, 190, 0.16), transparent 55%),
    var(--pad-deep);
}

#world {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: auto;
}

.topbar,
.hud,
#dashboard,
#overlay,
#message,
.touch,
footer {
  position: absolute;
  z-index: 4;
}

.topbar {
  /* Above #overlay (same stacking level, later in the page) so MUSIC / SOUND / pause work on the menu and pause screens. */
  z-index: 5;
  top: calc(12px + var(--safe-t));
  left: calc(16px + var(--safe-l));
  right: calc(16px + var(--safe-r));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.topbar > * {
  pointer-events: auto;
}

.brand {
  text-decoration: none;
  letter-spacing: 0.22em;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}

.brand span {
  color: var(--ice);
  margin: 0 2px;
}

.edition {
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.32em;
  font-size: 10px;
  color: var(--muted);
}

.edition i {
  display: block;
  width: 28px;
  height: 1px;
  background: linear-gradient(90deg, var(--red), var(--ice));
}

.actions {
  display: flex;
  gap: 6px;
}

.actions button,
.primary {
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(14px);
  color: var(--ink);
  letter-spacing: 0.16em;
  cursor: pointer;
}

.actions button {
  height: 32px;
  padding: 0 12px;
  font-size: 10px;
  border-radius: 999px;
}

.actions button[aria-pressed="true"] {
  border-color: rgba(143, 243, 255, 0.45);
  color: var(--ice);
  box-shadow: inset 0 0 0 1px rgba(143, 243, 255, 0.12);
}

#pause {
  width: 32px;
  padding: 0;
  letter-spacing: 0;
  font-size: 13px;
}

.hud {
  top: calc(58px + var(--safe-t));
  left: calc(16px + var(--safe-l));
  right: calc(16px + var(--safe-r));
  display: flex;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.hud.hidden,
#dashboard.hidden,
.overlay.hidden {
  display: none;
}

.stage,
.timer,
.menu,
.vehicle-label {
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.stage,
.timer {
  min-width: 180px;
  padding: 12px 14px 14px;
}

.eyebrow,
#distance,
#score,
.energy span,
.energy small,
.tag,
.race-note,
.vehicle-label span,
.vehicle-label p,
.spec-note {
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  font-size: 9px;
}

#stageName,
#time,
.vehicle-label strong,
.menu h1 {
  font-weight: 650;
  letter-spacing: 0.04em;
}

#stageName {
  display: block;
  margin: 4px 0 10px;
  font-size: 18px;
}

.route {
  position: relative;
  height: 3px;
  margin: 0 0 10px;
  background: rgba(232, 238, 248, 0.1);
}

.route b {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: linear-gradient(90deg, var(--red), var(--ice));
}

.route i {
  position: absolute;
  top: -3px;
  width: 2px;
  height: 9px;
  background: var(--ink);
  opacity: 0.45;
}

.route i:first-of-type { left: 33.3%; }
.route i:last-of-type { left: 66.6%; }

.timer {
  text-align: right;
}

#time {
  display: block;
  margin: 2px 0 6px;
  font-size: 36px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

#time.low {
  color: var(--red-hot);
  text-shadow: 0 0 18px rgba(255, 45, 58, 0.45);
}

#message {
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: min(92vw, 560px);
  text-align: center;
  font-size: clamp(22px, 4vw, 42px);
  letter-spacing: 0.18em;
  font-weight: 650;
  text-shadow: 0 8px 40px rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

#message.show {
  opacity: 1;
}

#message.sip {
  color: var(--ice);
  font-size: clamp(32px, 7vw, 64px);
  letter-spacing: 0.22em;
  text-shadow: 0 0 28px rgba(143, 243, 255, 0.55), 0 0 6px rgba(240, 235, 227, 0.35), 0 8px 40px rgba(0, 0, 0, 0.55);
  animation: sipPunch 0.55s ease-out;
}

#message.style {
  color: var(--gold);
  font-size: clamp(26px, 5vw, 52px);
  text-shadow: 0 0 28px rgba(240, 194, 122, 0.85), 0 8px 40px rgba(0, 0, 0, 0.55);
  animation: sipPunch 0.45s ease-out;
}

#juiceFlash {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 62%, rgba(143, 243, 255, 0.32), transparent 58%);
}

#juiceFlash.show.sip {
  animation: juiceFlash 0.58s ease-out;
  background: radial-gradient(circle at 50% 62%, rgba(143, 243, 255, 0.4), transparent 58%);
}

#juiceFlash.show.style {
  animation: juiceFlash 0.5s ease-out;
  background: radial-gradient(circle at 50% 62%, rgba(240, 194, 122, 0.32), transparent 58%);
}

#juiceFlash.show.empty {
  animation: juiceFlash 0.5s ease-out;
  background: radial-gradient(circle at 50% 62%, rgba(255, 45, 58, 0.28), transparent 58%);
}

.attack-target.behind {
  color: var(--red-hot);
}

.attack-target {
  display: block;
  margin-top: 4px;
  letter-spacing: 0.14em;
  font-size: 9px;
  color: var(--gold);
}

.charge-track.sip b {
  box-shadow: 0 0 22px rgba(143, 243, 255, 0.95);
  background: linear-gradient(90deg, #fff, var(--ice));
}

.ghost-delta {
  display: block;
  margin-top: 4px;
  letter-spacing: 0.16em;
  font-size: 10px;
  color: var(--ice);
}

.ghost-delta.behind { color: var(--red-hot); }

.launch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 16px;
}

#modeToggle {
  height: 52px;
  padding: 0 16px;
  border: 1px solid var(--line);
  background: var(--glass);
  letter-spacing: 0.16em;
  font-size: 11px;
  cursor: pointer;
}

#modeToggle[aria-pressed="true"] {
  border-color: rgba(240, 194, 122, 0.5);
  color: var(--gold);
}

#modeToggle:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.charge-track.empty b {
  background: linear-gradient(90deg, #8d1a24, var(--red-hot));
  box-shadow: 0 0 16px rgba(255, 45, 58, 0.5);
}

.livery-on strong {
  color: var(--ice);
}

#message.ice {
  color: var(--ice);
}

#message.gold {
  color: var(--gold);
}

#dashboard {
  left: calc(12px + var(--safe-l));
  right: calc(12px + var(--safe-r));
  bottom: calc(30px + var(--safe-b)); /* clear of the footer line */
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  padding: 0;
  pointer-events: none;
  background: transparent;
  border: 0;
  backdrop-filter: none;
  z-index: 5;
}

.velocity,
.energy {
  background: rgba(4, 20, 26, 0.55);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  padding: 8px 12px 10px;
  max-width: 42%;
}

.velocity {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

#speed {
  font-size: clamp(28px, 5vw, 44px);
  line-height: 0.85;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
}

.velocity div {
  padding-bottom: 6px;
  letter-spacing: 0.2em;
  font-size: 11px;
  color: var(--muted);
}

#driveMode {
  display: block;
  margin-top: 4px;
  color: var(--ice);
  letter-spacing: 0.16em;
  font-size: 11px;
  font-weight: 650;
}

#driveMode.thrust {
  color: var(--red-hot);
}

.energy {
  width: min(260px, 38vw);
}

.energy > div:first-child {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}

.charge-track {
  height: 6px;
  background: rgba(232, 238, 248, 0.08);
  overflow: hidden;
}

.charge-track b {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #1e6f88, var(--ice));
  box-shadow: 0 0 16px rgba(143, 243, 255, 0.45);
  transform-origin: left center;
}

.energy small {
  display: block;
  margin-top: 7px;
}

.energy em {
  margin-left: 12px;
  font-style: normal;
  color: var(--gold);
}

.overlay {
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(240px, 0.7fr);
  align-items: stretch;
  overflow: auto;
  gap: 24px;
  padding:
    calc(92px + var(--safe-t))
    calc(28px + var(--safe-r))
    calc(92px + var(--safe-b))
    calc(28px + var(--safe-l));
  background:
    linear-gradient(90deg, transparent 0 11%, rgba(255, 92, 190, 0.14) 11.5% 12.2%, transparent 12.8%),
    linear-gradient(90deg, transparent 0 26%, rgba(232, 238, 248, 0.1) 26.4% 27%, transparent 27.5%),
    linear-gradient(90deg, transparent 0 72%, rgba(255, 92, 190, 0.16) 72.3% 73.1%, transparent 73.6%),
    linear-gradient(90deg, transparent 0 87%, rgba(143, 243, 255, 0.12) 87.2% 88%, transparent 88.5%),
    linear-gradient(180deg, rgba(3, 16, 21, 0.05) 0%, rgba(3, 16, 21, 0.22) 48%, rgba(3, 16, 21, 0.48) 100%);
}

.menu {
  padding: 22px 22px 18px;
  max-width: 720px;
}

.courses {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 16px;
  max-height: min(36vh, 320px);
  overflow: auto;
}

.course {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(3, 16, 21, 0.45);
  text-align: left;
  cursor: pointer;
  letter-spacing: 0.08em;
}

.course[aria-pressed="true"] {
  border-color: rgba(143, 243, 255, 0.45);
  box-shadow: inset 0 0 0 1px rgba(143, 243, 255, 0.12);
}

.course[disabled] {
  opacity: 0.42;
  cursor: not-allowed;
}

.course .no {
  color: var(--muted);
  font-size: 10px;
}

.course strong {
  display: block;
  font-size: 11px;
  letter-spacing: 0.12em;
}

.course small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.1em;
}

.pips {
  color: var(--gold);
  font-size: 9px;
  letter-spacing: 0.14em;
  white-space: nowrap;
}

.medal-hud {
  display: block;
  margin-top: 4px;
  letter-spacing: 0.18em;
  font-size: 9px;
  color: var(--gold);
}

.coach {
  position: absolute;
  left: 50%;
  bottom: calc(168px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 6;
  padding: 12px 18px;
  border: 1px solid rgba(143, 243, 255, 0.35);
  background: rgba(4, 20, 26, 0.82);
  backdrop-filter: blur(14px);
  letter-spacing: 0.14em;
  font-size: clamp(13px, 2.2vw, 18px);
  font-weight: 700;
  color: var(--ink);
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 0 18px rgba(143, 243, 255, 0.12);
  animation: coachPulse 1.1s ease-in-out infinite;
}

@keyframes coachPulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.03); }
}

.coach[hidden] {
  display: none;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  letter-spacing: 0.12em;
}

.tag b {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red-hot);
  box-shadow: 0 0 12px var(--red-hot);
  animation: pulse 1.4s ease-in-out infinite;
}

.menu h1 {
  margin: 0 0 10px;
  font-size: clamp(34px, 6vw, 68px);
  line-height: 0.88;
  letter-spacing: -0.03em;
}

.menu h1 em {
  font-style: italic;
  color: transparent;
  background: linear-gradient(120deg, #fff 10%, var(--ice) 45%, var(--red) 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

.menu p {
  margin: 0 0 22px;
  color: #b8d4d0;
  font-size: 15px;
  line-height: 1.55;
  letter-spacing: 0.02em;
  max-width: 42ch;
}

.primary {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  height: 52px;
  padding: 0 22px;
  border-color: rgba(255, 179, 221, 0.4);
  background: linear-gradient(180deg, rgba(255, 92, 190, 0.92), rgba(150, 30, 110, 0.88));
  letter-spacing: 0.2em;
  font-size: 12px;
  box-shadow:
    0 0 0 1px rgba(232, 213, 163, 0.12),
    0 0 28px rgba(143, 243, 255, 0.22),
    0 10px 40px rgba(255, 92, 190, 0.26);
}

.primary:hover,
.primary:focus-visible {
  filter: brightness(1.08);
}

.primary span {
  color: var(--ice);
}

.instructions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 18px;
  margin: 22px 0 16px;
}

.instructions div {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  letter-spacing: 0.14em;
  font-size: 10px;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 22px;
  padding: 0 6px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  font-size: 10px;
  letter-spacing: 0.08em;
}

.race-note {
  margin: 0;
}

.vehicle-label {
  justify-self: end;
  width: min(340px, 100%);
  padding: 22px 22px 18px;
  border-left: 3px solid var(--red);
}

.vehicle-label strong {
  display: block;
  margin: 8px 0 8px;
  font-size: 28px;
  letter-spacing: 0.18em;
}

.vehicle-label p {
  margin: 0 0 16px;
}

.specs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 12px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

.specs li {
  padding: 8px 10px;
  border: 1px solid rgba(120, 240, 255, 0.2);
  background: rgba(6, 34, 42, 0.3);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.specs b {
  display: block;
  margin-bottom: 2px;
  color: var(--ink);
  font-size: 16px;
  letter-spacing: 0.04em;
}

.vehicle-label > div {
  letter-spacing: 0.16em;
  font-size: 10px;
  color: var(--ice);
}

.vehicle-label > div b {
  color: var(--muted);
}

.spec-note {
  margin: 12px 0 0;
  line-height: 1.5;
  letter-spacing: 0.08em;
}

.touch {
  display: none;
  right: calc(12px + var(--safe-r));
  bottom: calc(18px + var(--safe-b));
  left: calc(12px + var(--safe-l));
  z-index: 6;
  /* Steer · steer · brake · jump · boost. Boost is widest: it is the one held down at speed. */
  grid-template-columns: 1fr 1fr 0.78fr 1.12fr 1.6fr;
  gap: 8px;
}

.touch button {
  height: 64px;
  border: 1px solid var(--line);
  background: rgba(5, 28, 36, 0.72);
  color: var(--ink);
  letter-spacing: 0.12em;
  font-size: 12px;
  backdrop-filter: blur(10px);
}

.touch button:active,
.touch button.held {
  background: rgba(255, 92, 190, 0.4);
  border-color: rgba(255, 92, 190, 0.55);
}

.touch button[data-control="jump"] {
  color: var(--ice);
}

/* Filled, so the thumb finds it without looking away from the road. */
.touch button[data-control="boost"] {
  border-color: rgba(126, 232, 255, 0.55);
  background: rgba(126, 232, 255, 0.16);
  color: var(--ice);
  font-size: 14px;
  font-weight: 800;
}

.touch button[data-control="boost"]:active,
.touch button[data-control="boost"].held {
  background: rgba(126, 232, 255, 0.42);
  border-color: var(--ice);
  color: #06121a;
}

footer {
  left: calc(16px + var(--safe-l));
  right: calc(16px + var(--safe-r));
  bottom: calc(10px + var(--safe-b));
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.16em;
  pointer-events: none;
}

@keyframes pulse {
  50% { opacity: 0.35; transform: scale(0.82); }
}

@keyframes sipPunch {
  0% { transform: translate(-50%, -50%) scale(0.72); letter-spacing: 0.34em; }
  40% { transform: translate(-50%, -50%) scale(1.12); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

@keyframes juiceFlash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

@media (max-width: 860px) {
  .overlay {
    grid-template-columns: 1fr;
    align-items: stretch;
    padding-bottom: calc(148px + var(--safe-b));
    overflow: auto;
  }

  .vehicle-label {
    justify-self: stretch;
    width: auto;
  }

  .edition,
  #footerHint {
    display: none;
  }

  #dashboard {
    bottom: calc(108px + var(--safe-b));
    padding: 0;
  }

  .velocity,
  .energy {
    padding: 6px 8px 8px;
    max-width: 46%;
  }

  .energy {
    width: min(220px, 48vw);
  }

  .touch {
    display: grid;
  }

  .hud {
    top: calc(50px + var(--safe-t));
  }

  .stage,
  .timer {
    min-width: 0;
    padding: 8px 10px 10px;
  }

  #stageName {
    font-size: 13px;
    margin-bottom: 8px;
  }

  #time {
    font-size: 26px;
  }
}

@media (max-width: 520px) {
  .courses {
    grid-template-columns: 1fr;
    max-height: 28vh;
  }

  .instructions {
    grid-template-columns: 1fr;
  }

  .menu {
    padding: 20px 18px 16px;
  }

  .menu h1 {
    font-size: 40px;
  }

  .actions button:not(#pause) {
    padding: 0 8px;
    letter-spacing: 0.08em;
  }
}

@media (hover: none) and (pointer: coarse) {
  .touch {
    display: grid;
  }
}

/* Routine points: a quiet line under the score counter instead of centre-screen text */
.score-feed {
  display: block;
  min-height: 14px;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.14em;
  white-space: nowrap;
  color: var(--gold);
  opacity: 0;
  transition: opacity 0.35s ease;
}

.score-feed.show {
  opacity: 1;
  animation: feedIn 0.25s ease-out;
}

.score-feed.info { color: var(--ice); }
.score-feed.penalty { color: var(--red-hot); }

@keyframes feedIn {
  0% { transform: translateY(5px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

/* With the touch pad up, the on-screen buttons already say this. */
body.pad .energy small {
  display: none;
}
