:root {
  color-scheme: dark;
  --ink: #f7fbff;
  --muted: #9aa8ba;
  --panel: rgba(8, 13, 22, 0.72);
  --line: rgba(255, 255, 255, 0.18);
  --hot: #ff315c;
  --cyan: #2ee9ff;
  --gold: #ffd166;
  --black: #05070c;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 16% 12%, rgba(255, 49, 92, 0.25), transparent 30%),
    radial-gradient(circle at 78% 18%, rgba(46, 233, 255, 0.18), transparent 28%),
    linear-gradient(130deg, #090a12 0%, #101525 42%, #09070e 100%);
}

body::before {
  position: fixed;
  inset: 0;
  content: "";
  pointer-events: none;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(46, 233, 255, 0.035) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(circle at 50% 50%, black, transparent 74%);
}

button {
  font: inherit;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: var(--ink);
  background: linear-gradient(135deg, rgba(255, 49, 92, 0.96), rgba(255, 143, 31, 0.95));
  min-height: 38px;
  padding: 0 16px;
  border-radius: 6px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  cursor: pointer;
  box-shadow: 0 12px 32px rgba(255, 49, 92, 0.28);
}

button:hover {
  filter: brightness(1.08);
}

button:active {
  transform: translateY(1px);
}

.shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: clamp(10px, 2vw, 24px);
}

.game-frame {
  position: relative;
  width: min(100%, 1180px);
  aspect-ratio: 16 / 9;
  min-height: 360px;
  max-height: calc(100vh - 20px);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: #070913;
  box-shadow:
    0 28px 80px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(255, 255, 255, 0.05) inset;
}

.game-frame::after {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 4px),
    radial-gradient(circle at 50% 78%, transparent 0 45%, rgba(0, 0, 0, 0.34) 100%);
  mix-blend-mode: screen;
  opacity: 0.42;
}

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

.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  right: 14px;
  display: grid;
  grid-template-columns: auto auto auto auto auto minmax(150px, 1fr) auto auto auto;
  gap: 10px;
  align-items: stretch;
  pointer-events: none;
  z-index: 3;
}

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

.touch-toggle {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 6px;
  background: rgba(8, 13, 22, 0.72);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: none;
  text-transform: none;
}

.touch-toggle[aria-pressed="true"] {
  background: linear-gradient(135deg, rgba(46, 233, 255, 0.4), rgba(46, 233, 255, 0.16));
  border-color: var(--cyan);
  color: var(--cyan);
}

.hud-stack,
.boost-wrap {
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid rgba(46, 233, 255, 0.22);
  border-radius: 5px;
  background:
    linear-gradient(155deg, rgba(46, 233, 255, 0.06), rgba(8, 13, 22, 0.82) 65%),
    rgba(8, 13, 22, 0.78);
  backdrop-filter: blur(14px);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.4) inset,
    0 0 14px rgba(46, 233, 255, 0.08);
}

.hud-stack {
  display: grid;
  align-content: center;
  min-width: 74px;
}

.speed {
  min-width: 132px;
}

.timer {
  min-width: 118px;
}

.label {
  display: block;
  color: rgba(46, 233, 255, 0.78);
  font-size: 10px;
  line-height: 1;
  text-transform: uppercase;
  font-weight: 900;
  letter-spacing: 0.10em;
}

.hud strong {
  display: block;
  margin-top: 3px;
  font-size: 20px;
  line-height: 1;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.hud small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  margin-left: 2px;
}

.boost-wrap {
  display: grid;
  align-content: center;
  min-width: 0;
}

.boost-meter {
  height: 10px;
  margin-top: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.boost-meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--gold), var(--hot));
  box-shadow: 0 0 16px rgba(46, 233, 255, 0.75);
}

.engine-label {
  margin-top: 6px;
}

.engine-meter span {
  background: linear-gradient(90deg, var(--hot), var(--gold), #4cf38f);
  box-shadow: 0 0 12px rgba(255, 49, 92, 0.55);
  transition: width 120ms ease;
}

.engine-meter.is-low {
  box-shadow: 0 0 0 1px rgba(255, 49, 92, 0.8) inset;
  animation: engine-warn 0.5s ease-in-out infinite alternate;
}

.combo-stack {
  border-color: rgba(255, 209, 102, 0.35);
  box-shadow: 0 0 0 1px rgba(255, 209, 102, 0.2) inset, 0 0 14px rgba(255, 209, 102, 0.18);
}

.combo-stack .label {
  color: rgba(255, 209, 102, 0.92);
}

.combo-stack strong {
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.55);
}

.combo-stack.is-hot strong {
  color: var(--hot);
  text-shadow: 0 0 14px rgba(255, 49, 92, 0.7);
}

@keyframes engine-warn {
  from { background: rgba(255, 49, 92, 0.18); }
  to   { background: rgba(255, 49, 92, 0.42); }
}

.title-card {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: clamp(14px, 2.5vw, 26px);
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 49, 92, 0.18), transparent 55%),
    radial-gradient(circle at 84% 88%, rgba(46, 233, 255, 0.16), transparent 55%),
    rgba(5, 8, 15, 0.96);
  border: none;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
  z-index: 6;
}

.finish-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 36px));
  padding: 22px 24px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  background: rgba(5, 8, 15, 0.86);
  backdrop-filter: blur(14px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
  z-index: 5;
  text-align: center;
}

.title-card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.title-card__hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.title-card__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.title-card__pb {
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.prerace-btn {
  min-width: 220px;
  padding: 0 28px;
  height: 48px;
  font-size: 16px;
  letter-spacing: 0.06em;
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--cyan);
  font-size: 12px;
  line-height: 1;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(40px, 7vw, 76px);
  line-height: 0.88;
  text-shadow: 4px 4px 0 rgba(255, 49, 92, 0.85), -2px -2px 0 rgba(46, 233, 255, 0.55);
}

h2 {
  font-size: clamp(32px, 5vw, 54px);
}

.title-card p:not(.eyebrow),
.finish-panel p:not(.eyebrow) {
  margin: 12px 0 0;
  max-width: 48ch;
  color: #dce6f4;
  line-height: 1.45;
}

.title-card .pb-line {
  margin-top: 10px;
  color: var(--gold);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.car-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  overflow-y: auto;
  align-content: start;
  padding-right: 4px;
}

.track-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
}

.track-card {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(155deg, rgba(46, 233, 255, 0.05), rgba(8, 13, 22, 0.84)),
    rgba(8, 13, 22, 0.82);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font: inherit;
  text-transform: none;
  letter-spacing: 0;
  box-shadow: none;
  min-height: auto;
  transition: border-color 100ms ease, transform 80ms ease, background 120ms ease;
}

.track-card:hover {
  border-color: rgba(46, 233, 255, 0.6);
  transform: translateY(-1px);
}

.track-card[aria-checked="true"] {
  border-color: var(--cyan);
  background: linear-gradient(155deg, rgba(46, 233, 255, 0.18), rgba(8, 13, 22, 0.85));
  box-shadow: 0 0 0 1px rgba(46, 233, 255, 0.55) inset, 0 6px 18px rgba(46, 233, 255, 0.18);
}

.track-card__name {
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.track-card__desc {
  margin: 0;
  color: #c4cfdf;
  font-size: 10.5px;
  line-height: 1.3;
}

.track-card__swatch {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.track-card__swatch span {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

@media (max-width: 760px) {
  .car-picker, .track-picker {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.car-card {
  display: grid;
  gap: 4px;
  padding: 8px 10px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(46, 233, 255, 0.04), rgba(8, 13, 22, 0.85)),
    rgba(8, 13, 22, 0.85);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font: inherit;
  text-transform: none;
  letter-spacing: 0;
  box-shadow: none;
  min-height: auto;
  transition: border-color 100ms ease, transform 80ms ease, background 120ms ease;
}

.car-card:hover {
  border-color: rgba(46, 233, 255, 0.6);
  transform: translateY(-1px);
}

.car-card[aria-checked="true"] {
  border-color: var(--cyan);
  background: linear-gradient(155deg, rgba(46, 233, 255, 0.16), rgba(8, 13, 22, 0.8));
  box-shadow: 0 0 0 1px rgba(46, 233, 255, 0.55) inset, 0 8px 24px rgba(46, 233, 255, 0.18);
}

.car-card__preview {
  display: block;
  width: 100%;
  height: clamp(54px, 7.5vw, 72px);
  border-radius: 6px;
  background:
    radial-gradient(circle at 50% 80%, rgba(46, 233, 255, 0.22), transparent 65%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(0, 0, 0, 0.25));
  border: 1px solid rgba(255, 255, 255, 0.10);
}

.car-card__title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.car-card__name {
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.car-card__shape {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.car-card__desc {
  margin: 0;
  color: #c4cfdf;
  font-size: 10px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.car-card__bars {
  display: grid;
  grid-template-columns: 22px 1fr 22px 1fr;
  align-items: center;
  gap: 3px 6px;
  font-size: 9px;
  font-weight: 900;
  text-transform: uppercase;
  color: var(--muted);
}

.car-card .stat-bar {
  position: relative;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.10);
  overflow: hidden;
}

.car-card .stat-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--gold), var(--hot));
  border-radius: inherit;
}


.finish-panel {
  left: 50%;
  top: 50%;
  bottom: auto;
  transform: translate(-50%, -50%);
  text-align: center;
}

.finish-panel button {
  margin-top: 18px;
}

.race-callout {
  position: absolute;
  left: 50%;
  top: 48%;
  z-index: 5;
  width: min(520px, calc(100% - 32px));
  transform: translate(-50%, -50%);
  color: #fff;
  text-align: center;
  text-transform: uppercase;
  font-size: clamp(38px, 9vw, 104px);
  font-weight: 950;
  line-height: 0.9;
  letter-spacing: 0;
  pointer-events: none;
  opacity: 0;
  text-shadow:
    5px 5px 0 rgba(255, 49, 92, 0.85),
    -3px -3px 0 rgba(46, 233, 255, 0.7),
    0 0 36px rgba(255, 255, 255, 0.3);
  transition: opacity 120ms ease;
}

.race-callout.is-visible {
  opacity: 1;
}

.leaderboard {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 3;
  width: 188px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(5, 8, 15, 0.68);
  backdrop-filter: blur(12px);
}

.leaderboard ol {
  display: grid;
  gap: 5px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.leaderboard li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 23px;
  padding: 4px 7px;
  border-radius: 4px;
  color: #dce6f4;
  background: rgba(255, 255, 255, 0.06);
  font-size: 12px;
  font-weight: 800;
}

.leaderboard li.is-player {
  color: #05070c;
  background: linear-gradient(90deg, var(--cyan), var(--gold));
}

[hidden] {
  display: none !important;
}

.game-frame.is-prerace .hud,
.game-frame.is-prerace .leaderboard,
.game-frame.is-prerace .race-callout {
  display: none !important;
}

.touch-controls {
  position: absolute;
  inset: auto 0 0 0;
  z-index: 6;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: clamp(10px, 3vw, 22px);
  pointer-events: none;
  touch-action: none;
  user-select: none;
}

.touch-pad {
  display: grid;
  gap: 10px;
  pointer-events: auto;
}

.touch-pad--left {
  grid-template-columns: auto auto;
}

.touch-pad--right {
  grid-template-columns: auto auto;
  grid-auto-flow: column;
  align-items: end;
}

.touch-btn {
  width: clamp(58px, 13vw, 88px);
  height: clamp(58px, 13vw, 88px);
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  background: rgba(8, 13, 22, 0.62);
  color: var(--ink);
  font-size: clamp(14px, 3.4vw, 20px);
  font-weight: 900;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
  -webkit-tap-highlight-color: transparent;
  transition: transform 60ms ease, background 80ms ease;
}

.touch-btn.is-active {
  transform: scale(0.94);
  background: rgba(46, 233, 255, 0.22);
  border-color: var(--cyan);
}

.touch-btn--gas {
  width: clamp(72px, 16vw, 104px);
  height: clamp(72px, 16vw, 104px);
  background: linear-gradient(135deg, rgba(255, 49, 92, 0.85), rgba(255, 143, 31, 0.85));
  border-color: rgba(255, 209, 102, 0.6);
}

.touch-btn--gas.is-active {
  background: linear-gradient(135deg, #ff315c, #ffd166);
}

.touch-btn--brake {
  background: rgba(255, 49, 92, 0.32);
  border-color: rgba(255, 49, 92, 0.55);
}

.touch-btn--drift {
  background: rgba(46, 233, 255, 0.18);
  border-color: rgba(46, 233, 255, 0.55);
}

.has-touch .leaderboard {
  right: clamp(8px, 2vw, 14px);
  left: auto;
  bottom: clamp(120px, 22vw, 170px);
  width: clamp(150px, 30vw, 196px);
}

.has-touch .title-card,
.has-touch .finish-panel {
  bottom: clamp(120px, 22vw, 170px);
}

.has-touch .finish-panel {
  bottom: auto;
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .shell {
    min-height: 100%;
  }

  .game-frame {
    min-height: 520px;
    aspect-ratio: 9 / 14;
  }

  .hud {
    grid-template-columns: repeat(3, 1fr);
  }

  .boost-wrap {
    grid-column: 1 / -1;
  }

  #start {
    grid-column: 1 / -1;
  }

  .title-card {
    padding: 16px;
  }

  .leaderboard {
    left: 14px;
    right: 14px;
    bottom: 12px;
    width: auto;
  }

  .leaderboard ol {
    grid-template-columns: repeat(3, 1fr);
  }

  .leaderboard li {
    min-width: 0;
  }

}
