html, body { margin: 0; height: 100%; overflow: hidden; }

body {
  --level: 0;   /* smoothed loudness */
  --bass: 0;    /* smoothed bass */
  --flash: 0;   /* beat hit, decays */
  --hue: 0deg;  /* shifts each beat */
  background: radial-gradient(120% 90% at 50% 25%, #1b0e3d 0%, #0a0618 55%, #04030c 100%);
  font-family: "Space Grotesk", system-ui, -apple-system, sans-serif;
  color: #fff;
}

/* scene wraps every visual layer so it can shake as one unit */
.scene { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
body.hit .scene { animation: shake 0.2s ease; }
@keyframes shake {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(0.7vw, -0.5vh); }
  40%  { transform: translate(-0.6vw, 0.4vh); }
  60%  { transform: translate(0.5vw, 0.5vh); }
  80%  { transform: translate(-0.4vw, -0.3vh); }
  100% { transform: translate(0, 0); }
}

/* ============ starfield sky ============ */
.stars {
  position: fixed; inset: 0; z-index: 0;
  opacity: 0;
  transition: opacity 0.8s ease;
  background-image:
    radial-gradient(1.6px 1.6px at 12% 18%, #fff, transparent),
    radial-gradient(1.2px 1.2px at 28% 32%, #cfe8ff, transparent),
    radial-gradient(1.4px 1.4px at 45% 12%, #fff, transparent),
    radial-gradient(1px 1px   at 62% 26%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 78% 14%, #ffd6f5, transparent),
    radial-gradient(1.1px 1.1px at 88% 30%, #fff, transparent),
    radial-gradient(1.3px 1.3px at 8% 40%,  #fff, transparent),
    radial-gradient(1px 1px   at 52% 38%, #cfe8ff, transparent);
  animation: twinkle 4s ease-in-out infinite;
}
.playing .stars { opacity: 0.75; }
@keyframes twinkle { 0%,100% { opacity: 0.75; } 50% { opacity: 0.4; } }

/* ============ retro synthwave sun (behind the car) ============ */
.sun {
  position: fixed; top: 37%; left: 50%; z-index: 0;
  width: 46vmin; height: 46vmin;
  border-radius: 50%;
  background: linear-gradient(to bottom, #ffe14d 0%, #ff6ac1 48%, #ff2d95 100%);
  filter: blur(1px) drop-shadow(0 0 50px rgba(255,45,149,0.55));
  opacity: 0;
  transform: translate(-50%, -50%) scale(calc(0.7 + var(--bass) * 0.55 + var(--flash) * 0.3));
  transition: opacity 0.8s ease, transform 0.06s ease-out;
}
.playing .sun { opacity: 0.92; }
.sun::after {  /* horizontal cut-lines on the lower half */
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 55%;
  border-bottom-left-radius: 50%; border-bottom-right-radius: 50%;
  background: repeating-linear-gradient(to bottom, transparent 0 2.4vmin, #0a0618 2.4vmin 3.3vmin);
}

/* ============ neon synthwave floor ============ */
.floor {
  position: fixed;
  left: -50%; right: -50%; bottom: 0;
  height: 55vh;
  z-index: 1;
  perspective: 22vh;
  opacity: 0;
  transition: opacity 0.6s ease;
  -webkit-mask-image: linear-gradient(to top, #000 55%, transparent);
          mask-image: linear-gradient(to top, #000 55%, transparent);
}
.playing .floor { opacity: calc(0.5 + var(--level) * 1.2); }
.floor::before {
  content: "";
  position: absolute;
  bottom: 0; left: 0;
  width: 100%; height: 200%;
  background-image:
    repeating-linear-gradient(to right,  transparent 0 calc(4vw - 1.5px), rgba(255,0,170,0.85) calc(4vw - 1.5px) 4vw),
    repeating-linear-gradient(to bottom, transparent 0 calc(4vw - 1.5px), rgba(0,229,255,0.85) calc(4vw - 1.5px) 4vw);
  transform: rotateX(80deg);
  transform-origin: bottom center;
  animation: floorScroll 1.1s linear infinite;
  filter: drop-shadow(0 0 6px rgba(255,0,170,0.7)) drop-shadow(0 0 6px rgba(0,229,255,0.5)) hue-rotate(var(--hue));
}
@keyframes floorScroll { from { background-position: 0 0; } to { background-position: 0 4vw; } }

/* ============ fog / haze over the grid ============ */
.fog {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 40vh;
  z-index: 2;
  opacity: 0;
  background: linear-gradient(to top, rgba(150,60,220,0.30), rgba(120,40,200,0.08) 50%, transparent);
  filter: blur(8px);
  mix-blend-mode: screen;
  transition: opacity 0.8s ease;
}
.playing .fog { opacity: calc(0.45 + var(--level) * 0.6); }

/* ============ sweeping ceiling beams ============ */
.beams {
  position: fixed; inset: 0; z-index: 2;
  opacity: 0;
  filter: hue-rotate(var(--hue));
  transition: opacity 0.6s ease;
}
.playing .beams { opacity: 1; }
.beam {
  position: absolute;
  top: -25%; left: 50%;
  width: 16vw; height: 150vh;
  transform-origin: top center;
  mix-blend-mode: screen;
  filter: blur(14px);
  opacity: calc(0.06 + var(--level) * 0.9 + var(--flash) * 0.35);
}
.b1 { margin-left: -58vw; background: linear-gradient(to bottom, rgba(255,0,128,0.95), transparent 65%); animation: swingA 2.4s ease-in-out infinite; }
.b2 { margin-left: -35vw; background: linear-gradient(to bottom, rgba(0,229,255,0.95), transparent 65%); animation: swingB 1.9s ease-in-out infinite; }
.b3 { margin-left: -12vw; background: linear-gradient(to bottom, rgba(170,0,255,0.95), transparent 65%); animation: swingA 2.1s ease-in-out infinite reverse; }
.b4 { margin-left:  12vw; background: linear-gradient(to bottom, rgba(6,255,165,0.95), transparent 65%); animation: swingB 2.3s ease-in-out infinite reverse; }
.b5 { margin-left:  35vw; background: linear-gradient(to bottom, rgba(255,190,11,0.95), transparent 65%); animation: swingA 1.7s ease-in-out infinite; }
.b6 { margin-left:  58vw; background: linear-gradient(to bottom, rgba(58,134,255,0.95), transparent 65%); animation: swingB 2.0s ease-in-out infinite reverse; }
@keyframes swingA { 0%,100% { transform: rotate(-26deg); } 50% { transform: rotate(26deg); } }
@keyframes swingB { 0%,100% { transform: rotate(22deg);  } 50% { transform: rotate(-22deg); } }

/* ============ roving club lights ============ */
.rovers {
  position: fixed; inset: 0; z-index: 2;
  opacity: 0;
  mix-blend-mode: screen;
  filter: hue-rotate(var(--hue));
  transition: opacity 0.6s ease;
}
.playing .rovers { opacity: calc(0.45 + var(--level) * 0.9); }
.rover { position: absolute; width: 34vmin; height: 34vmin; border-radius: 50%; filter: blur(16px); }
.r1 { background: radial-gradient(circle, rgba(255,0,170,0.75), transparent 65%); animation: rove1 7.5s ease-in-out infinite; }
.r2 { background: radial-gradient(circle, rgba(0,229,255,0.75), transparent 65%); animation: rove2 9.5s ease-in-out infinite; }
.r3 { background: radial-gradient(circle, rgba(170,0,255,0.75), transparent 65%); animation: rove3 8.5s ease-in-out infinite; }
.r4 { background: radial-gradient(circle, rgba(6,255,165,0.70), transparent 65%);  animation: rove1 11s  ease-in-out infinite reverse; }
@keyframes rove1 { 0%{transform:translate(3vw,8vh);}  50%{transform:translate(72vw,38vh);} 100%{transform:translate(3vw,8vh);} }
@keyframes rove2 { 0%{transform:translate(80vw,5vh);} 50%{transform:translate(10vw,30vh);} 100%{transform:translate(80vw,5vh);} }
@keyframes rove3 { 0%{transform:translate(40vw,2vh);} 50%{transform:translate(55vw,45vh);} 100%{transform:translate(40vw,2vh);} }

/* ============ traffic ============ */
.road {
  position: fixed;
  left: 0; right: 0; bottom: 22vh;
  height: 24vh;
  z-index: 3;
  overflow: hidden;
}
.traffic {
  position: absolute; left: 0; height: auto;
  filter: blur(0.6px) drop-shadow(0 0 10px rgba(0,229,255,0.4));
  -webkit-mask-image: radial-gradient(ellipse 80% 72% at 50% 52%, #000 58%, transparent 90%);
          mask-image: radial-gradient(ellipse 80% 72% at 50% 52%, #000 58%, transparent 90%);
  animation: drive linear forwards;
}
@keyframes drive {
  from { transform: translateX(calc(var(--dir) * -130vw)) scaleX(var(--dir)); }
  to   { transform: translateX(calc(var(--dir) *  130vw)) scaleX(var(--dir)); }
}

/* ============ car on its stage (centered) ============ */
.stage { position: fixed; inset: 0; z-index: 3; display: grid; place-items: center; }
.spot {
  position: absolute; top: 50%; left: 50%;
  width: 82vmin; height: 82vmin; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,245,225,0.95) 0%, rgba(255,190,120,0.3) 34%, transparent 64%);
  filter: blur(8px) hue-rotate(var(--hue));
  transform: translate(-50%, -50%) scale(calc(0.55 + var(--bass) * 1.3 + var(--flash) * 0.45));
  transition: transform 0.06s ease-out;
  mix-blend-mode: screen;
}
.car-wrap { position: relative; }
.car {
  display: block;
  width: min(58vw, 480px);
  -webkit-mask-image: radial-gradient(ellipse 88% 82% at 50% 50%, #000 70%, transparent 97%);
          mask-image: radial-gradient(ellipse 88% 82% at 50% 50%, #000 70%, transparent 97%);
  filter: drop-shadow(0 8px 30px rgba(0,0,0,0.6));
  transform: scale(calc(1 + var(--flash) * 0.16 + var(--bass) * 0.05));
  transition: transform 0.06s ease-out;
}
.reflection {
  position: absolute; top: 100%; left: 0;
  width: 100%; margin-top: -2%;
  transform: scaleY(-1);
  opacity: 0.18;
  filter: blur(2px);
  -webkit-mask-image: linear-gradient(to top, #000, transparent 60%);
          mask-image: linear-gradient(to top, #000, transparent 60%);
}

/* ============ vignette + strobe ============ */
.vignette {
  position: fixed; inset: 0; z-index: 4;
  background: radial-gradient(120% 100% at 50% 45%, transparent 52%, rgba(0,0,0,0.62));
}
.strobe {
  position: fixed; inset: 0; z-index: 5;
  background: #fff;
  mix-blend-mode: overlay;
  opacity: calc(var(--flash) * 0.8);
}

/* ============ text ============ */
main {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center; align-content: end;
  padding-bottom: 7vh;
  pointer-events: none;
}
#prompt {
  margin: 0;
  font-size: clamp(1.3rem, 4.5vw, 2.4rem);
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-shadow: 0 0 12px #ff00aa, 0 0 28px #ff00aa, 0 0 48px rgba(0,229,255,0.6);
  cursor: pointer;
  pointer-events: auto;
  animation: breathe 1.6s ease-in-out infinite;
}
#prompt.hidden { display: none; }
@keyframes breathe { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }
.now {
  margin: 0;
  font-size: clamp(0.75rem, 2.5vw, 1rem);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  opacity: 0;
  color: rgba(255,255,255,0.75);
  text-shadow: 0 0 10px rgba(0,229,255,0.7);
  transition: opacity 0.6s ease;
}
.playing .now { opacity: calc(0.4 + var(--level) * 0.8); }

@media (prefers-reduced-motion: reduce) {
  .floor::before, .beam, .rover, .stars, #prompt, body.hit .scene { animation: none; }
}
