:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --accent-2: #8a6bff;
  --secondary: #2a2b3d;
  --text: #fff;
  --muted: #aaadbe;
  --gold: #ffcf3a;
  --hud-h: 48px;
  --help-h: 22px;
  font-family:
    "Nunito",
    ui-rounded,
    "SF Pro Rounded",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-weight: 800;
}
* {
  box-sizing: border-box;
}
html,
body {
  width: 100%;
  min-width: 0;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
body {
  padding: 8px;
  background:
    radial-gradient(120% 70% at 50% 0%, #211c4a 0%, rgba(15, 16, 32, 0) 60%),
    var(--bg);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
button {
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
:focus-visible {
  outline: 3px solid #ffd84a;
  outline-offset: 2px;
}

.shell {
  width: min(960px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* HUD */
.hud {
  min-height: var(--hud-h);
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.brand-icon {
  width: 34px;
  height: 34px;
  transform: rotate(-12deg);
  filter: drop-shadow(0 3px 6px rgba(255, 160, 30, 0.4));
}
.brand h1 {
  margin: 0;
  font-size: 23px;
  font-weight: 900;
  letter-spacing: -0.02em;
  font-style: italic;
  white-space: nowrap;
  background: linear-gradient(180deg, #fff3c2, var(--gold) 55%, #ff8a1f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.chips {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}
.chip {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
  padding: 7px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #27283d, var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 #0a0b16;
}
.chip span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.chip strong {
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.chip-score strong {
  color: var(--gold);
}
.chip-speed strong {
  min-width: 3ch;
  text-align: right;
  color: #7fe7ff;
}
.chip.pop strong {
  animation: pop 0.3s cubic-bezier(0.3, 1.8, 0.5, 1);
}
@keyframes pop {
  50% {
    transform: scale(1.35);
  }
}

/* Pills */
.pill {
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  padding: 0 22px;
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
  transition:
    transform 0.12s,
    filter 0.12s;
}
.pill:active {
  transform: translateY(2px) scale(0.98);
}
.pill:disabled {
  opacity: 0.45;
  cursor: default;
}
.pill-primary {
  background: linear-gradient(180deg, #8a6bff, var(--accent));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.28),
    0 4px 0 #3b1fb3,
    0 10px 24px rgba(104, 66, 255, 0.45);
}
.pill-primary:hover {
  filter: brightness(1.08);
}
.pill-secondary {
  background: linear-gradient(180deg, #34364c, var(--secondary));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 3px 0 #0a0b16;
}
.pill-big {
  min-width: 190px;
  min-height: 56px;
  font-size: 22px;
}
.icon-button {
  width: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.icon-button svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Stage */
.stage {
  position: relative;
  width: 100%;
  height: clamp(
    340px,
    calc(100svh - 16px - var(--hud-h) - var(--help-h) - 16px),
    820px
  );
  border-radius: 20px;
  overflow: hidden;
  background: #2f8f4e;
  box-shadow:
    0 0 0 3px #2c2d52,
    0 16px 40px rgba(0, 0, 0, 0.45);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.stage.shake {
  animation: shake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
@keyframes shake {
  10%,
  90% {
    transform: translate(-2px, 1px);
  }
  20%,
  80% {
    transform: translate(5px, -2px);
  }
  30%,
  50%,
  70% {
    transform: translate(-7px, 2px);
  }
  40%,
  60% {
    transform: translate(7px, -1px);
  }
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline-offset: -4px;
}

/* On-screen controls */
.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px;
  pointer-events: none;
}
.control-group {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.ctl {
  pointer-events: auto;
  position: relative;
  width: 62px;
  height: 62px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: none;
  color: #fff;
  background: linear-gradient(
    180deg,
    rgba(60, 62, 92, 0.82),
    rgba(26, 27, 40, 0.82)
  );
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.18),
    0 4px 0 rgba(8, 9, 20, 0.8),
    0 8px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.08s;
}
.ctl svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ctl.held {
  transform: translateY(3px) scale(0.95);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.18),
    0 1px 0 rgba(8, 9, 20, 0.8);
}
.ctl-steer.held {
  background: linear-gradient(180deg, #8a6bff, var(--accent));
}
.ctl-brake {
  width: 72px;
  height: 52px;
  border-radius: 18px;
  font-weight: 900;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: linear-gradient(
    180deg,
    rgba(255, 92, 110, 0.9),
    rgba(200, 34, 62, 0.9)
  );
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.3),
    0 4px 0 rgba(110, 10, 30, 0.9),
    0 8px 18px rgba(0, 0, 0, 0.35);
}
.ctl-nitro {
  width: 74px;
  height: 74px;
  overflow: hidden;
  background: linear-gradient(
    180deg,
    rgba(40, 42, 70, 0.9),
    rgba(20, 21, 36, 0.9)
  );
  box-shadow:
    inset 0 0 0 3px rgba(127, 231, 255, 0.35),
    0 4px 0 rgba(8, 9, 20, 0.8),
    0 8px 18px rgba(0, 0, 0, 0.35);
}
.ctl-nitro svg {
  position: relative;
  width: 30px;
  height: 30px;
  margin-top: -10px;
  fill: #fff;
  stroke: none;
}
.nitro-label {
  position: absolute;
  bottom: 12px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.nitro-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 100%;
  transform-origin: bottom;
  transform: scaleY(var(--nitro, 0));
  background: linear-gradient(180deg, #7fe7ff, #2c8bff 60%, #6842ff);
  transition: transform 0.15s linear;
}
.ctl-nitro.full {
  box-shadow:
    inset 0 0 0 3px #bff4ff,
    0 4px 0 rgba(8, 9, 20, 0.8),
    0 0 26px rgba(127, 231, 255, 0.85);
  animation: glow 0.9s ease-in-out infinite alternate;
}
@keyframes glow {
  to {
    filter: brightness(1.25);
  }
}

/* Overlay */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  background: radial-gradient(
    circle at 50% 40%,
    rgba(15, 16, 32, 0.45),
    rgba(15, 16, 32, 0.82)
  );
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 3;
}
.overlay[hidden] {
  display: none;
}
.card {
  width: min(380px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 20px 20px 22px;
  border-radius: 26px;
  text-align: center;
  background: linear-gradient(180deg, #2a2b44, var(--panel));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.08),
    0 6px 0 #0a0b16,
    0 24px 50px rgba(0, 0, 0, 0.5);
  animation: card-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes card-in {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
}
.card-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.card-title {
  margin: 2px 0 6px;
  font-size: 40px;
  line-height: 1.05;
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #fff6cf, var(--gold) 50%, #ff7a1a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 #7a2c00);
}
.card-copy {
  margin: 0 0 14px;
  color: #d8daea;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}
.final {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-bottom: 14px;
}
.final[hidden] {
  display: none;
}
.final-label {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.final-score {
  font-size: 46px;
  font-weight: 900;
  line-height: 1;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.badge {
  margin-top: 4px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  background: linear-gradient(180deg, #ffe46b, #ffab1f);
  color: #4a2400;
  animation: pop 0.6s cubic-bezier(0.3, 1.8, 0.5, 1) 0.2s both;
}
.badge[hidden] {
  display: none;
}
.final-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  width: 100%;
  margin: 12px 0 0;
}
.final-stats div {
  padding: 7px 8px;
  border-radius: 14px;
  background: var(--panel-2);
}
.final-stats dt {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.final-stats dd {
  margin: 0;
  font-size: 17px;
  font-weight: 900;
}
.modes {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}
.mode {
  min-height: 44px;
  min-width: 104px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 14px;
  padding: 0 14px;
  cursor: pointer;
  background: var(--secondary);
  color: var(--muted);
  box-shadow: 0 3px 0 #0a0b16;
}
.mode svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}
.mode[aria-pressed="true"] {
  color: #fff;
  background: linear-gradient(180deg, #8a6bff, var(--accent));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.25),
    0 3px 0 #3b1fb3;
}
.card-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.help {
  min-height: var(--help-h);
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 5px;
  margin: 0 1px;
  border-radius: 6px;
  background: var(--secondary);
  box-shadow: 0 2px 0 #0a0b16;
  color: #fff;
  font: inherit;
  font-size: 11px;
}

@media (max-width: 620px) {
  .brand h1 {
    display: none;
  }
  .help {
    display: none;
  }
  :root {
    --help-h: 0px;
  }
  .stage {
    height: clamp(340px, calc(100svh - 16px - var(--hud-h) - 8px), 820px);
  }
}
@media (max-width: 400px) {
  .chip {
    padding: 6px 9px;
  }
  .chip span {
    font-size: 10px;
  }
  .chip strong {
    font-size: 16px;
  }
  .chip-best span {
    display: none;
  }
  .chip-best::before {
    content: "★";
    color: var(--gold);
    font-size: 13px;
  }
  .ctl {
    width: 58px;
    height: 58px;
  }
  .ctl-nitro {
    width: 66px;
    height: 66px;
  }
  .ctl-brake {
    width: 62px;
  }
  .controls {
    padding: 10px;
  }
  .control-group {
    gap: 8px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
