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

body {
  font-family: 'Inter', sans-serif;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #87ceeb;
}

/* ── Header ─────────────────────────────────────── */
header {
  position: relative;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.25rem;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255,255,255,0.12);
  flex-shrink: 0;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: white;
}
.header-icon {
  width: 20px; height: 20px;
  color: #fb923c;
  flex-shrink: 0;
}
.header-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: white;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.hdr-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.8rem;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: rgba(255,255,255,0.85);
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.hdr-btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.hdr-btn:hover { background: rgba(255,255,255,0.2); color: white; }
.hdr-btn.active { background: rgba(99,102,241,0.4); border-color: rgba(99,102,241,0.6); color: white; }

.accent-btn { background: rgba(249,115,22,0.25); border-color: rgba(249,115,22,0.5); color: #fed7aa; }
.accent-btn:hover { background: rgba(249,115,22,0.45); }
.accent-btn:active { transform: scale(0.95); background: #f97316; color: white; }

/* ── HUD ─────────────────────────────────────────── */
.hud {
  position: absolute;
  top: 62px;
  left: 18px;
  z-index: 150;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  padding: 1rem 1.1rem 0.8rem;
  color: white;
  backdrop-filter: blur(12px);
  min-width: 155px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.hud-speed {
  text-align: center;
  line-height: 1;
}
.speed-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2.6rem;
  font-weight: 700;
  color: #fb923c;
  transition: color 0.3s, text-shadow 0.3s;
  display: block;
}
.speed-num.turbo-active { color: #facc15; text-shadow: 0 0 20px rgba(250,204,21,0.8); }
.speed-unit {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.4);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.hud-bar-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}
.spd-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  border-radius: 6px;
  width: 26px; height: 26px;
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
  font-family: 'Inter', sans-serif;
}
.spd-btn:hover { background: rgba(255,255,255,0.25); }

.hud-bar {
  flex: 1; height: 6px;
  background: rgba(255,255,255,0.12);
  border-radius: 10px;
  overflow: hidden;
}
.hud-fill {
  height: 100%;
  border-radius: 10px;
  background: linear-gradient(90deg, #22c55e, #f59e0b, #ef4444);
  transition: width 0.35s cubic-bezier(0.4,0,0.2,1);
  width: 50%;
}

.hud-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.62rem;
  color: rgba(255,255,255,0.3);
}

.hud-gear {
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.4);
  letter-spacing: 0.05em;
}

.turbo-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.45rem;
  background: linear-gradient(135deg, rgba(234,179,8,0.2), rgba(249,115,22,0.2));
  border: 1px solid rgba(234,179,8,0.4);
  border-radius: 10px;
  color: #fbbf24;
  font-family: 'Inter', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 0.15rem;
}
.turbo-btn svg { width: 14px; height: 14px; }
.turbo-btn:hover { background: linear-gradient(135deg, rgba(234,179,8,0.35), rgba(249,115,22,0.35)); }
.turbo-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.turbo-btn.firing { background: linear-gradient(135deg, #d97706, #ea580c); color: white; box-shadow: 0 0 20px rgba(251,191,36,0.5); }

.shortcuts {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding-top: 0.35rem;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.shortcuts span {
  font-size: 0.6rem;
  color: rgba(255,255,255,0.25);
  font-family: 'JetBrains Mono', monospace;
}

/* ── Scene ───────────────────────────────────────── */
.scene {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* Background layer — the new bg image scrolls */
.bg-layer {
  position: absolute;
  inset: 0;
  width: 300%;
  height: 100%;
  background: url('bg_new.jpg') repeat-x center / auto 100%;
  animation: bgScroll var(--bg-speed, 14s) linear infinite;
  will-change: transform;
}
@keyframes bgScroll { from { transform: translateX(0); } to { transform: translateX(-33.333%); } }

/* Night overlay */
.night-overlay {
  position: absolute;
  inset: 0;
  background: rgba(5,10,35,0.72);
  opacity: 0;
  transition: opacity 1.4s;
  z-index: 10;
  pointer-events: none;
}
body.night .night-overlay { opacity: 1; }

/* Moon */
.moon {
  position: absolute;
  top: 8%; right: 12%;
  width: 58px; height: 58px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 38%, #fffff0, #c8c8a0);
  box-shadow: 0 0 25px rgba(255,255,210,0.5);
  opacity: 0;
  transform: translateY(-20px);
  transition: opacity 1.2s, transform 1.2s;
  z-index: 11;
  pointer-events: none;
}
body.night .moon { opacity: 1; transform: translateY(0); }

/* Stars */
.stars {
  position: absolute;
  inset: 0;
  z-index: 11;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.5s;
}
body.night .stars { opacity: 1; }
.star {
  position: absolute;
  background: white;
  border-radius: 50%;
  animation: twinkle var(--tw, 2s) ease-in-out infinite;
}
@keyframes twinkle { 0%,100%{opacity:0.9} 50%{opacity:0.2} }

/* Road markings */
.road-markings {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 600%;
  height: 12%;
  z-index: 5;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    90deg,
    transparent 0px, transparent 80px,
    rgba(255,255,255,0.6) 80px, rgba(255,255,255,0.6) 140px
  );
  background-size: 220px 8px;
  background-position: 0 50%;
  background-repeat: repeat-x;
  animation: markingScroll var(--bg-speed, 14s) linear infinite;
}
@keyframes markingScroll { from { transform: translateX(0); } to { transform: translateX(-16.666%); } }

/* ── Car ─────────────────────────────────────────── */
.car-wrap {
  position: absolute;
  bottom: 7%;
  left: calc(50% - 200px);
  width: 400px;
  height: auto;
  animation: carBounce var(--bounce-speed, 0.42s) ease-in-out infinite;
  z-index: 20;
  transition: filter 1s;
  will-change: transform;
}
body.night .car-wrap { filter: brightness(0.75); }
body.night.turbo .car-wrap { filter: brightness(0.85); }

.car-img {
  width: 100%;
  height: auto;
  display: block;
  position: relative;
  z-index: 2;
  filter: drop-shadow(0 10px 20px rgba(0,0,0,0.4));
}

/* Headlight beam (night) */
.headlight-beam {
  position: absolute;
  right: -60px;
  top: 28%;
  width: 130px;
  height: 60px;
  background: radial-gradient(ellipse at right, rgba(255,245,180,0.85) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 1.2s;
  z-index: 1;
  pointer-events: none;
}
body.night .headlight-beam { opacity: 1; }

.wheel-overlay { display: none; }

@keyframes wheelSpin { to { transform: rotate(360deg); } }
@keyframes carBounce {
  0%, 100% { transform: translateY(-3px) rotate(-0.25deg); }
  50%       { transform: translateY(3px) rotate(0.25deg); }
}
body.turbo .car-wrap { animation: carBounceFast var(--bounce-speed, 0.2s) ease-in-out infinite; }
@keyframes carBounceFast {
  0%, 100% { transform: translateY(-5px) rotate(-0.5deg); }
  50%       { transform: translateY(4px) rotate(0.5deg); }
}

/* ── Rain ────────────────────────────────────────── */
.rain-container {
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s;
}
body.raining .rain-container { opacity: 1; }

.raindrop {
  position: absolute;
  top: -20px;
  width: 2px;
  border-radius: 2px;
  background: linear-gradient(to bottom, transparent, rgba(174,214,241,0.7));
  animation: fall var(--fall-dur, 0.8s) linear var(--fall-delay, 0s) infinite;
}
@keyframes fall {
  to { transform: translateY(110vh) translateX(-20px); }
}

/* ── Exhaust smoke ───────────────────────────────── */
.exhaust {
  position: absolute;
  z-index: 19;
  pointer-events: none;
}
.smoke-puff {
  position: absolute;
  border-radius: 50%;
  background: rgba(200,200,200,0.35);
  pointer-events: none;
  animation: smokeDrift 1.2s ease-out forwards;
}
@keyframes smokeDrift {
  0%   { opacity: 0.7; transform: scale(0.4) translateX(0) translateY(0); }
  100% { opacity: 0;   transform: scale(2.2) translateX(-60px) translateY(-30px); }
}

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 600px) {
  .car-wrap { width: 280px; left: calc(50% - 140px); }
  .back-wheel  { width: 58px; height: 58px; left: 30px; }
  .front-wheel { width: 58px; height: 58px; left: 182px; }
  .hud { min-width: 130px; padding: 0.75rem 0.9rem; }
  .speed-num { font-size: 2rem; }
  .shortcuts { display: none; }
}
