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

:root {
  --bg: #0a0a0f;
  --surface: #15151c;
  --surface-2: #1f1f29;
  --border: #2a2a36;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-light: #818cf8;
  --accent: #f59e0b;
  --green: #10b981;
  --red: #ef4444;
  --road: #2a2a32;
  --road-line: #fbbf24;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.5rem;
  background: #0a0a0f;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.back-link {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}
.back-link:hover { color: var(--text); }

.topbar__trip {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}
.topbar__route { color: var(--primary-light); font-weight: 600; }
.topbar__sep { margin: 0 0.4rem; opacity: 0.5; }

/* ── Game container ── */
.game {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.5rem 2.5rem;
}

/* ── Windshield (main view) ── */
.windshield {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 1.25rem;
  overflow: hidden;
  border: 2px solid var(--border);
  background: #000;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  isolation: isolate;
}

.sky {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, #0f172a, #475569 60%, #94a3b8);
  transition: background 1.5s ease;
}

.sun {
  position: absolute;
  top: 12%;
  right: 18%;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle, #fef3c7 0%, #fbbf24 50%, transparent 70%);
  filter: blur(4px);
  opacity: 0.85;
  transition: opacity 0.6s;
  pointer-events: none;
}
.sun.dim { opacity: 0.25; }

.scenery-layer {
  position: absolute;
  left: -10%;
  right: -10%;
  pointer-events: none;
  will-change: transform;
}
.scenery-far {
  bottom: 32%;
  height: 32%;
  filter: brightness(0.7) saturate(0.85);
  opacity: 0.85;
}
.scenery-mid {
  bottom: 22%;
  height: 24%;
  filter: brightness(0.85);
}
.scenery-near {
  bottom: 8%;
  height: 26%;
  filter: brightness(1);
}

.scenery-item {
  position: absolute;
  bottom: 0;
  transform-origin: bottom center;
  will-change: transform, left;
}

/* ── Road ── */
.road {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 38%;
  background: linear-gradient(to bottom, var(--road) 0%, #15151c 100%);
  perspective: 280px;
  perspective-origin: 50% 0%;
  overflow: hidden;
  transition: transform 0.15s ease-out;
}

.road__lines {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  --road-speed: 1s;
}
.road__lines::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 8px;
  margin-left: -4px;
  background-image: linear-gradient(to bottom, var(--road-line) 0%, var(--road-line) 50%, transparent 50%, transparent 100%);
  background-size: 100% 60px;
  background-repeat: repeat-y;
  background-position: 0 0;
  transform: rotateX(72deg) translateZ(0);
  transform-origin: 50% 0%;
  animation: road-scroll var(--road-speed) linear infinite;
  opacity: 0.9;
}

.road__lines.paused::before { animation-play-state: paused; }

@keyframes road-scroll {
  from { background-position: 0 0; }
  to { background-position: 0 60px; }
}

.road__edge {
  position: absolute;
  bottom: 0;
  width: 4px;
  background: linear-gradient(to bottom, transparent, #94a3b8);
  height: 100%;
}
.road__edge--left { left: 12%; }
.road__edge--right { right: 12%; }

.car-hood {
  position: absolute;
  left: -2%;
  right: -2%;
  bottom: -8%;
  height: 14%;
  background: linear-gradient(to bottom, #1a1a22, #050507);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  border-top: 2px solid #2a2a36;
  z-index: 5;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.6) inset;
}

.rearview {
  position: absolute;
  top: 4%;
  left: 50%;
  transform: translateX(-50%);
  width: 18%;
  aspect-ratio: 16 / 5;
  background: #0a0a0f;
  border: 2px solid #1f1f29;
  border-radius: 0.4rem;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rearview__interior {
  font-size: 0.5rem;
  color: var(--text-muted);
  opacity: 0.4;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* ── HUD ── */
.hud {
  position: absolute;
  z-index: 7;
  background: rgba(10, 10, 15, 0.65);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 0.6rem;
  padding: 0.45rem 0.7rem;
  min-width: 110px;
  pointer-events: none;
}
.hud--tl { top: 0.75rem; left: 0.75rem; }
.hud--tr { top: 0.75rem; right: 0.75rem; text-align: right; }
.hud--bl { bottom: 0.75rem; left: 0.75rem; }
.hud--br { bottom: 0.75rem; right: 0.75rem; text-align: right; }

.hud__label {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.hud__value {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.2;
}
.hud__sub {
  font-size: 0.65rem;
  color: var(--primary-light);
  font-weight: 600;
}

/* ── Highway signpost ── */
.signpost {
  position: absolute;
  top: 14%;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  z-index: 6;
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
}
.signpost.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.signpost__panel {
  background: var(--sign-color, #1e3a8a);
  border: 4px solid #fefefe;
  border-radius: 0.5rem;
  padding: 0.5rem 1.5rem;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  min-width: 180px;
}
.signpost__top {
  font-size: 0.6rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 0.1em;
}
.signpost__city {
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.02em;
}
.signpost__mile {
  font-size: 0.85rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
}
.signpost__mile::after { content: ' mi'; opacity: 0.7; }

/* ── Overlays ── */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  padding: 1.5rem;
}
.overlay.active { display: flex; }

.overlay__card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  padding: 2rem;
  max-width: 520px;
  width: 100%;
  text-align: center;
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.85) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.overlay__emoji {
  font-size: 3.5rem;
  margin-bottom: 0.5rem;
  line-height: 1;
}

.overlay__title {
  font-size: clamp(1.5rem, 4vw, 2.2rem);
  font-weight: 800;
  background: linear-gradient(135deg, #f8fafc 0%, var(--primary-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.75rem;
  line-height: 1.15;
}

.overlay__desc {
  font-size: 0.92rem;
  color: var(--text-muted);
  line-height: 1.65;
  margin-bottom: 1.25rem;
}
.overlay__desc strong { color: var(--text); font-weight: 700; }

.overlay__controls {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0 auto 1.5rem;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.overlay__controls li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: center;
}

kbd {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 0.3rem;
  font-size: 0.72rem;
  font-family: 'SFMono-Regular', Consolas, monospace;
  color: var(--text);
  min-width: 22px;
  text-align: center;
}

/* ── City arrival card ── */
.overlay__card--city {
  padding: 1.25rem;
  text-align: left;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1.25rem;
  max-width: 640px;
}
@media (max-width: 600px) {
  .overlay__card--city {
    grid-template-columns: 1fr;
  }
}

.city-cam {
  position: relative;
  border-radius: 0.875rem;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  background: #000;
  border: 1px solid var(--border);
}
.city-cam__skyline {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, #1e3a8a 0%, #0c4a6e 40%, #1a1a22 100%);
}
.city-cam__live {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  background: rgba(239, 68, 68, 0.9);
  color: white;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 0.3rem;
  letter-spacing: 0.06em;
  z-index: 2;
  animation: blink 2s ease-in-out infinite;
}
@keyframes blink {
  0%, 50%, 100% { opacity: 1; }
  25%, 75% { opacity: 0.35; }
}
.city-cam__time {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.62rem;
  color: rgba(255, 255, 255, 0.85);
  font-family: 'SFMono-Regular', Consolas, monospace;
  background: rgba(0, 0, 0, 0.5);
  padding: 0.15rem 0.45rem;
  border-radius: 0.3rem;
  z-index: 2;
}
.city-cam__label {
  position: absolute;
  bottom: 0.5rem;
  left: 0.5rem;
  right: 0.5rem;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  z-index: 2;
}

.city-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.4rem;
}
.city-info__emoji {
  font-size: 2.5rem;
  line-height: 1;
}
.city-info__name {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
}
.city-info__meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.city-info__fact {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin: 0.4rem 0 0.8rem;
}

/* ── Buttons ── */
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border: none;
  color: white;
  padding: 0.7rem 1.6rem;
  border-radius: 0.6rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(99, 102, 241, 0.4);
}
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.82rem;
  transition: all 0.15s;
  font-family: inherit;
}
.btn-ghost:hover:not(:disabled) {
  border-color: var(--primary-light);
  color: var(--text);
}
.btn-ghost:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Finish stats ── */
.finish-stats {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 0.8rem 1rem;
  margin-bottom: 1.25rem;
}
.finish-stats__row {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.finish-stats__row span:last-child {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ── Radio ── */
.radio {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 10, 15, 0.65);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 0.6rem;
  padding: 0.35rem 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 7;
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}
.radio.visible { opacity: 1; }
.radio__icon { font-size: 1rem; }
.radio__freq {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.radio__name {
  font-size: 0.6rem;
  color: var(--text-muted);
}

/* ── Dashboard ── */
.dashboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  padding: 0.75rem 1.5rem;
  background: linear-gradient(to bottom, #1a1a22, #0a0a0f);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
}
@media (max-width: 700px) {
  .dashboard {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
}

.dash-gauges { display: flex; gap: 1rem; justify-content: flex-start; }

.gauge {
  width: 140px;
  position: relative;
}
.gauge__arc svg {
  width: 100%;
  height: auto;
  display: block;
}
.gauge__track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 6;
  stroke-linecap: round;
}
.gauge__fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 126;
  stroke-dashoffset: 126;
  transition: stroke-dashoffset 0.3s ease;
}
.gauge__num {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.gauge__num small {
  font-size: 0.55rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 0.2rem;
}

/* ── Steering wheel ── */
.steering-area {
  display: flex;
  align-items: center;
  justify-content: center;
}
.steering {
  position: relative;
  width: 130px;
  height: 130px;
  cursor: grab;
  user-select: none;
}
.steering:active { cursor: grabbing; }
.steering__outer {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 14px solid #1a1a22;
  background: transparent;
  box-shadow:
    0 0 0 2px #2a2a36 inset,
    0 8px 24px rgba(0, 0, 0, 0.5);
  transition: transform 0.15s ease-out;
}
.steering__inner {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  transition: transform 0.15s ease-out;
}
.steering__spoke {
  position: absolute;
  background: #1a1a22;
  box-shadow: 0 0 0 1px #2a2a36 inset;
  border-radius: 4px;
}
.steering__spoke--h {
  top: 50%;
  left: 14px;
  right: 14px;
  height: 6px;
  transform: translateY(-50%);
}
.steering__spoke--ld {
  top: 50%;
  left: 28px;
  width: 50px;
  height: 6px;
  transform: translateY(-50%) rotate(60deg);
  transform-origin: left center;
}
.steering__spoke--rd {
  top: 50%;
  right: 28px;
  width: 50px;
  height: 6px;
  transform: translateY(-50%) rotate(-60deg);
  transform-origin: right center;
}
.steering__hub {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #475569, #1f1f29);
  border: 1px solid #2a2a36;
}
.steering__arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  color: var(--text-muted);
  opacity: 0.6;
  pointer-events: none;
}
.steering__arrow--l { left: -20px; }
.steering__arrow--r { right: -20px; }

.dash-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ── Route progress ── */
.route-progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 0.5rem 0.25rem;
}
.route-progress__start,
.route-progress__end {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}
.route-progress__track {
  position: relative;
  flex: 1;
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: visible;
}
.route-progress__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 999px;
  width: 0%;
  transition: width 0.4s ease;
}
.route-progress__cities {
  position: absolute;
  inset: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
  pointer-events: none;
}
.route-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 2px solid var(--bg);
  transition: all 0.3s;
  flex-shrink: 0;
}
.route-dot.visited {
  background: var(--accent);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
}
.route-dot.current {
  background: var(--primary-light);
  box-shadow: 0 0 10px rgba(129, 140, 248, 0.8);
  transform: scale(1.3);
}

/* ── Small screens ── */
@media (max-width: 600px) {
  .game { padding: 0.5rem 0.75rem 2rem; }
  .windshield { aspect-ratio: 4 / 3; }
  .hud { padding: 0.35rem 0.55rem; min-width: 90px; }
  .hud__value { font-size: 0.85rem; }
  .hud__label { font-size: 0.55rem; }
  .hud--bl, .hud--br { display: none; }
  .signpost__panel { padding: 0.4rem 1rem; min-width: 140px; }
  .signpost__city { font-size: 0.9rem; }
  .rearview { width: 22%; }
  .gauge { width: 100px; }
  .steering { width: 100px; height: 100px; }
  .topbar__trip { display: none; }
}
