:root {
  --bg: #0f1720;
  --panel: #1c2a38;
  --accent: #ffc107;
  --text: #f4f7fa;
  --muted: #9fb3c8;
  --primary: #1e88e5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

.frame {
  padding: 16px;
  max-width: 480px;
  width: 100%;
  text-align: center;
}

h1 {
  margin: 8px 0 2px;
  font-size: 32px;
  letter-spacing: 2px;
  color: var(--accent);
}

.tagline {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 15px;
}

.game-wrap {
  position: relative;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
}

.hud {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(15, 23, 32, 0.72);
  border-radius: 8px;
  padding: 6px 8px;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 32, 0.86);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
}

.overlay.visible { display: flex; }

.overlay h2 {
  margin: 0;
  font-size: 28px;
  color: var(--accent);
}

.overlay p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

button {
  margin-top: 8px;
  min-width: 120px;
  min-height: 44px;
  padding: 10px 24px;
  font-size: 17px;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

button:active { transform: scale(0.97); }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.new-best {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
}
.new-best.hidden { display: none; }

/* Start Screen */
#start-screen { gap: 12px; padding: 12px; }
.start-title {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 1px;
}
.start-subtitle { margin: 0; font-size: 18px; color: var(--muted); }
.best-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 20px;
  background: var(--panel);
  border-radius: 12px;
}
.best-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.best-value { font-size: 24px; font-weight: 700; color: var(--primary); }
#start-screen .start-prompt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 300px;
  padding: 14px 24px;
  font-size: 18px;
  font-weight: 600;
  border-radius: 12px;
  background: #000;
  color: #00c853;
}
.start-controls { margin: 0; font-size: 15px; color: var(--muted); }
.start-divider {
  width: 80%;
  border: none;
  border-top: 1px solid var(--muted);
  opacity: 0.4;
  margin: 4px 0;
}
.mute-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(28, 42, 56, 0.7);
  border: 1px solid rgba(159, 179, 200, 0.35);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.mute-pill.muted-on { border-color: var(--accent); color: var(--accent); }

/* Entrance polish for the start title */
@keyframes title-in {
  from { opacity: 0; transform: translateY(-8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.start-title { animation: title-in 0.45s ease-out both; }
@media (prefers-reduced-motion: reduce) {
  .start-title { animation: none; }
}

/* HUD bars: health and nitro */
.hud-bars {
  position: absolute;
  top: 44px;
  left: 8px;
  right: 8px;
  display: flex;
  gap: 8px;
  pointer-events: none;
}
.bar { flex: 1; display: flex; align-items: center; gap: 4px; }
.bar-label { font-size: 10px; font-weight: 700; color: var(--muted); }
.bar-track {
  flex: 1;
  height: 8px;
  background: rgba(15, 23, 32, 0.72);
  border-radius: 4px;
  overflow: hidden;
}
.bar-fill { height: 100%; width: 100%; transition: width 0.15s ease-out; }
.bar-fill.health { background: #69f0ae; }
.bar-fill.nitro { background: #ff9100; }

/* Boost zone (touch) */
.boost-zone {
  position: absolute;
  bottom: 10px;
  right: 10px;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  background: rgba(255, 145, 0, 0.5);
  border: 1px solid var(--accent);
  border-radius: 999px;
  user-select: none;
  touch-action: none;
}

/* Car select chips */
.section-label {
  margin: 4px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 1px;
}
.car-chip.locked { opacity: 0.45; cursor: not-allowed; }
.car-select {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.car-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  min-width: 0;
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  background: rgba(28, 42, 56, 0.7);
  border: 1px solid rgba(159, 179, 200, 0.35);
  color: var(--muted);
}
.car-chip.selected {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(255, 193, 7, 0.15);
}
.car-swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; }

/* Leaderboard */
.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 88%;
  max-width: 280px;
  font-size: 13px;
  color: var(--muted);
}
.leaderboard li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 6px;
}
.leaderboard li:nth-child(odd) { background: rgba(28, 42, 56, 0.5); }
.board-rank { font-weight: 700; color: var(--accent); }
.board-score { font-weight: 700; color: var(--text); flex: 1; text-align: left; }
.board-meta { font-size: 11px; }
.board-empty { justify-content: center; color: var(--muted); }

/* Garage */
.garage-open-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 300px;
  margin: 0;
  min-height: 44px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 700;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid rgba(159, 179, 200, 0.35);
  color: var(--text);
}
.garage-open-btn:hover { border-color: var(--accent); }

#garage-screen {
  background: rgba(15, 23, 32, 0.96);
  justify-content: flex-start;
  overflow-y: auto;
  gap: 10px;
  z-index: 5;
}
.garage-balance {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
}
.garage-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}
.garage-card {
  background: var(--panel);
  border: 1px solid rgba(159, 179, 200, 0.25);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
}
.garage-card.selected { border-color: var(--accent); }
.garage-card.locked { opacity: 0.85; }
.garage-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.garage-card-name { font-weight: 700; flex: 1; }
.garage-card-price { font-size: 12px; color: var(--muted); }
.garage-stat {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
  font-size: 12px;
  color: var(--muted);
}
.garage-stat-label { width: 62px; }
.garage-stat-track { display: flex; gap: 4px; }
.garage-stat-seg {
  width: 26px;
  height: 8px;
  border-radius: 3px;
  background: rgba(159, 179, 200, 0.25);
}
.garage-stat-seg.filled { background: var(--accent); }
.garage-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.garage-btn {
  margin: 0;
  min-width: 0;
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  background: var(--primary);
}
.garage-btn.unaffordable { opacity: 0.45; cursor: not-allowed; }
.garage-btn.garage-close { background: var(--panel); border: 1px solid rgba(159, 179, 200, 0.35); color: var(--text); min-height: 44px; }
.final-bank { margin: 0; font-size: 14px; color: var(--accent); }

/* Missions screen */
.missions-list { max-height: 260px; overflow-y: auto; }
.mission-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid rgba(159, 179, 200, 0.25);
  border-radius: 10px;
  text-align: left;
}
.mission-card.done { border-color: var(--accent); background: rgba(255, 193, 7, 0.08); }
.mission-card.claimed { opacity: 0.55; }
.mission-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.mission-text { font-size: 13px; font-weight: 600; color: var(--text); }
.mission-reward { font-size: 12px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.mission-prog { font-size: 11px; color: var(--muted); }
.mission-card .garage-actions { margin: 2px 0 0; display: flex; }
.mission-card .garage-btn { min-width: 100%; min-height: 34px; font-size: 13px; padding: 6px 10px; }

@media (min-width: 600px) {
  h1 { font-size: 40px; }
}
