/* ── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Press Start 2P', cursive;
  overflow: hidden;
  background: #0a0a14;
  background-image:
    radial-gradient(ellipse 70% 50% at 20% 10%, rgba(80,40,160,0.25) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 90%, rgba(20,80,180,0.2)  0%, transparent 60%);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Game Container ─────────────────────────────────────── */
.game-container {
  position: relative;
  width: min(95vw, 420px);
  height: min(92vh, 700px);
  height: min(92dvh, 700px);
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.05),
    0 30px 80px rgba(0,0,0,0.7),
    0 0 60px rgba(80,40,200,0.2);
}

/* ── Road ───────────────────────────────────────────────── */
.road-lane-markers {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.road-line {
  width: 6px;
  height: 50px;
  background: linear-gradient(180deg, rgba(255,255,255,0.7), rgba(255,255,255,0.2));
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 3px;
  box-shadow: 0 0 6px rgba(255,255,255,0.3);
}

/* side kerbs */
.game-container::before,
.game-container::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  width: 18px;
  background: repeating-linear-gradient(
    180deg,
    #e74c3c 0px, #e74c3c 20px,
    #ecf0f1 20px, #ecf0f1 40px
  );
  opacity: 0.55;
  z-index: 1;
  pointer-events: none;
}
.game-container::before { left: 0; border-radius: 14px 0 0 14px; }
.game-container::after  { right: 0; border-radius: 0 14px 14px 0; }

/* ── Cars ───────────────────────────────────────────────── */
.car, .enemy {
  width: 38px;
  height: 76px;
  position: absolute;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 3;
  will-change: top, left;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.6));
  transition: filter 0.1s;
  border-radius: 6px;
  box-sizing: border-box;
}

/* ── Player car ── */
.car {
  filter: drop-shadow(0 0 10px rgba(100,200,255,0.5)) drop-shadow(0 4px 8px rgba(0,0,0,0.6));
  /* Fallback: visible blue car shape shown while/if image fails */
  background-color: #1a5fa8;
  border: 2px solid #5ab4ff;
  box-shadow:
    inset 0 8px 0 rgba(255,255,255,0.18),   /* windshield */
    inset 0 -8px 0 rgba(0,0,0,0.25),         /* bumper shadow */
    inset 3px 0 0 rgba(255,255,255,0.08),
    inset -3px 0 0 rgba(255,255,255,0.08);
}

/* ── Enemy cars ── */
.enemy {
  /* Fallback: visible red car shape */
  background-color: #a81a28;
  border: 2px solid #ff4455;
  box-shadow:
    inset 0 8px 0 rgba(255,255,255,0.15),
    inset 0 -8px 0 rgba(0,0,0,0.25),
    inset 3px 0 0 rgba(255,255,255,0.06),
    inset -3px 0 0 rgba(255,255,255,0.06);
}

/* Colour variants so not all fallback enemies look identical */
.enemy.img-yellow { background-color: #a87d00; border-color: #ffc233; }
.enemy.img-white  { background-color: #5a6070; border-color: #c0c8d8; }
.enemy.img-green  { background-color: #1a7a40; border-color: #3dbb6e; }

/* Once image has loaded (.img-loaded class added by JS),
   hide the fallback bg/border so only the image shows */
.car.img-loaded,
.enemy.img-loaded {
  background-color: transparent;
  border-color: transparent;
  box-shadow: none;
}

/* ── Top bar: holds pause + mute, sits above HUD ────────── */
.top-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 52px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 12px;
  z-index: 9;
  pointer-events: none;
}

.top-bar > * { pointer-events: auto; }

/* ── HUD / Score Bar ────────────────────────────────────── */
.hud {
  position: absolute;
  top: 52px; left: 0; right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 6px 14px;
  background: linear-gradient(180deg, rgba(0,0,0,0.5) 0%, transparent 100%);
  z-index: 8;
  pointer-events: none;
}

.hud-chip {
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: clamp(0.38rem, 1.5vw, 0.52rem);
  color: #ecf0f1;
  backdrop-filter: blur(6px);
  line-height: 1.6;
  white-space: nowrap;
  min-width: 64px;
  text-align: center;
}

.hud-chip span {
  display: block;
  color: rgba(255,255,255,0.5);
  font-size: 0.75em;
  margin-bottom: 2px;
}

.hud-score   { color: #f9ca24; }
.hud-level   { color: #6ab04c; }
.hud-hiscore { color: #e056fd; }

/* Level-up flash overlay */
.levelup-flash {
  position: absolute;
  inset: 0;
  background: rgba(255,255,100,0.08);
  z-index: 20;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.levelup-flash.active { opacity: 1; }

/* ── Overlay Screens ────────────────────────────────────── */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(5, 5, 15, 0.9);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  z-index: 10;
  padding: 24px 20px;
  gap: 0;
}

.overlay-title {
  font-size: clamp(1rem, 4vw, 1.5rem);
  margin-bottom: 16px;
  color: #f9ca24;
  text-shadow: 0 0 20px rgba(249,202,36,0.5);
  letter-spacing: 0.04em;
}

.overlay-title.danger { color: #e74c3c; text-shadow: 0 0 20px rgba(231,76,60,0.5); }

.overlay-subtitle {
  font-size: clamp(0.42rem, 1.6vw, 0.58rem);
  color: rgba(255,255,255,0.6);
  line-height: 2;
  margin-bottom: 28px;
  max-width: 280px;
}

.overlay-stat {
  font-size: clamp(0.5rem, 1.8vw, 0.65rem);
  color: #ecf0f1;
  margin-bottom: 10px;
  line-height: 1.8;
}

.overlay-stat strong {
  color: #f9ca24;
}

.new-highscore-badge {
  background: linear-gradient(135deg, #f9ca24, #f0932b);
  color: #000;
  font-size: clamp(0.4rem, 1.5vw, 0.55rem);
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 20px;
  animation: badgePulse 0.8s ease-in-out infinite alternate;
}

@keyframes badgePulse {
  from { transform: scale(1);    box-shadow: 0 0 0   rgba(249,202,36,0.4); }
  to   { transform: scale(1.05); box-shadow: 0 0 16px rgba(249,202,36,0.6); }
}

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  font-family: 'Press Start 2P', cursive;
  font-size: clamp(0.55rem, 2vw, 0.75rem);
  padding: 14px 28px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s, background 0.2s;
  letter-spacing: 0.05em;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
  background: linear-gradient(135deg, #e74c3c, #c0392b);
  color: #fff;
  box-shadow: 0 4px 20px rgba(231,76,60,0.4), 0 2px 0 rgba(0,0,0,0.3);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #ff5c4a, #e74c3c);
  box-shadow: 0 6px 28px rgba(231,76,60,0.55), 0 2px 0 rgba(0,0,0,0.3);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.7);
  border: 1px solid rgba(255,255,255,0.15);
  font-size: clamp(0.42rem, 1.5vw, 0.58rem);
  padding: 10px 20px;
  margin-top: 10px;
}
.btn-secondary:hover { background: rgba(255,255,255,0.14); }

/* ── Touch Controls ─────────────────────────────────────── */
.touch-controls {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 28px;
  z-index: 9;
}

.touch-btn {
  width: 64px;
  height: 64px;
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 22px;
  color: rgba(255,255,255,0.85);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
  touch-action: none;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.touch-btn:active,
.touch-btn.pressed {
  background: rgba(255,255,255,0.22);
  border-color: rgba(255,255,255,0.45);
  transform: scale(0.93);
}

/* ── Mute Button ────────────────────────────────────────── */
.mute-btn {
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
  color: #fff;
}
.mute-btn:hover { background: rgba(255,255,255,0.15); }

/* ── Pause Button ───────────────────────────────────────── */
.pause-btn {
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
  color: #fff;
}
.pause-btn:hover { background: rgba(255,255,255,0.15); }

/* ── Pause Overlay ──────────────────────────────────────── */
.pause-overlay {
  position: absolute;
  inset: 0;
  background: rgba(5,5,15,0.82);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 11;
  gap: 16px;
}

.pause-overlay h2 {
  font-size: clamp(1rem, 4vw, 1.4rem);
  color: #ecf0f1;
  letter-spacing: 0.06em;
}

/* ── Particle / Crash Flash ─────────────────────────────── */
.crash-flash {
  position: absolute;
  inset: 0;
  background: rgba(255,80,80,0.18);
  z-index: 12;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.05s;
}
.crash-flash.active { opacity: 1; }

/* ── Speed Lines (decorative) ───────────────────────────── */
.speed-line {
  position: absolute;
  width: 1px;
  background: linear-gradient(180deg, transparent, rgba(255,255,255,0.15), transparent);
  pointer-events: none;
  z-index: 1;
}

/* ── Utility ─────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Small Screen Adjustments ───────────────────────────── */
@media (max-height: 600px) {
  .touch-btn { width: 52px; height: 52px; font-size: 18px; }
  .touch-controls { bottom: 8px; gap: 20px; }
  .hud { padding: 8px 18px; }
}

@media (max-width: 360px) {
  .touch-btn { width: 56px; height: 56px; }
  .touch-controls { gap: 24px; }
}