/* Reset & font */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Orbitron", sans-serif;
}

html,
body {
  height: 100%;
  overflow: hidden; /* prevent any scroll */
  touch-action: none; /* disables browser scrolling & pinch zoom */
  background: #000;
}

/* Main game container */
.game {
  width: 100%;
  height: 100vh;
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
}

/* Speed Lines Effect */
.speed-lines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
      to bottom,
      rgba(255, 255, 255, 0) 50%,
      rgba(255, 255, 255, 0.03) 50%
    ),
    linear-gradient(90deg, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 100% 20px, 100px 100%;
  pointer-events: none;
  z-index: 1;
  animation: speedLoop 0.5s linear infinite;
}

@keyframes speedLoop {
  0% {
    transform: translateY(0);
  }
  100% {
    transform: translateY(20px);
  }
}

/* Overlay Start Screen */
.startScreen {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 85%;
  max-width: 400px;
  transform: translate(-50%, -50%);
  background: rgba(10, 20, 30, 0.95);
  padding: 2.5rem 2rem;
  text-align: center;
  border-radius: 16px;
  z-index: 50;
  border: 1px solid rgba(0, 255, 255, 0.3);
  box-shadow: 0 0 30px rgba(0, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  color: #fff;
}

.startScreen p {
  margin-bottom: 1.2rem;
  font-size: 0.9rem;
  color: #ccc;
  line-height: 1.6;
}

.ClickToStart {
  cursor: pointer;
  font-weight: 700;
  font-size: 1.6rem !important; /* Force override */
  color: #00ffcc !important;
  text-shadow: 0 0 10px rgba(0, 255, 204, 0.8);
  animation: pulseText 1.5s infinite alternate;
  margin-bottom: 1rem !important;
  display: block;
}

@keyframes pulseText {
  from {
    transform: scale(1);
    text-shadow: 0 0 10px rgba(0, 255, 204, 0.5);
  }
  to {
    transform: scale(1.05);
    text-shadow: 0 0 20px rgba(0, 255, 204, 1);
  }
}

.topbar {
  width: 100%;
  position: absolute;
  top: 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0 20px;
  pointer-events: none;
  z-index: 10;
}

/* Premium HUD for Score */
.score,
.highScore {
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: 8px; /* Classic racing HUD box functionality */
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 1px;
  border-left: 3px solid #00ffcc;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(5px);
  text-transform: uppercase;
  /* Slant the HUD for speed look */
  transform: skewX(-10deg);
}

/* Un-skew text inside */
.score::before,
.highScore::before {
  /* Optional icon implementation removed for simplicity */
}

.highScore {
  border-left-color: #ff00ff; /* Different color for high score */
}

/* Game Area - Asphalt Road Look */
.gameArea {
  width: 100%;
  max-width: 600px; /* Limit width on desktop for better playability */
  margin: 0 auto; /* Center it */
  height: 100%;
  position: relative;
  background-color: #333; /* Fallback */
  background-image: 
      /* Center line guide (faint) */ linear-gradient(
      90deg,
      transparent 49.5%,
      rgba(255, 255, 255, 0.05) 50%,
      transparent 50.5%
    ),
    /* Asphalt noise */ radial-gradient(rgb(60, 60, 60) 15%, transparent 16%),
    radial-gradient(rgb(40, 40, 40) 15%, transparent 16%);
  background-size: 100% 100%, 8px 8px, 8px 8px;
  border-left: 6px solid #fff;
  border-right: 6px solid #fff;
  box-shadow: inset 20px 0 50px rgba(0, 0, 0, 0.8),
    inset -20px 0 50px rgba(0, 0, 0, 0.8); /* Vignette */
  overflow: hidden;
}

/* Dynamic Road Borders (Guard Rails) */
.gameArea::before,
.gameArea::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 6px;
  background: repeating-linear-gradient(
    180deg,
    #ff0000 0,
    #ff0000 40px,
    #fff 40px,
    #fff 80px
  );
  z-index: 5;
  animation: railScroll 0.3s linear infinite; /* Will be synced via JS speed later if desired, standard for now */
}
.gameArea::before {
  left: 0;
}
.gameArea::after {
  right: 0;
}

@keyframes railScroll {
  from {
    background-position: 0 0;
  }
  to {
    background-position: 0 80px;
  }
}

/* Player Car */
.car {
  width: 18vw;
  max-width: 70px;
  height: 30vw;
  max-height: 120px;
  position: absolute;
  bottom: 8%;
  left: 40%;
  background: url(./main-car.png) no-repeat center;
  background-size: contain;
  /* Shadow for depth */
  filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.8));
  z-index: 10;
  transition: transform 0.1s ease-out; /* Smooth tilting */
}

/* Opponent Cars */
.Opponents {
  width: 18vw;
  max-width: 70px;
  height: 30vw;
  max-height: 120px;
  position: absolute;
  background: url(./opponent.png) no-repeat center;
  background-size: contain;
  rotate: 180deg;
  filter: drop-shadow(
    0 -5px 10px rgba(0, 0, 0, 0.6)
  ); /* Shadow above since inverted */
  z-index: 9;
}

/* Road Lines - Center Dashes */
.roadLines {
  position: absolute;
  width: 10px;
  height: 100px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.8) 0%,
    rgba(255, 255, 255, 0.4) 100%
  );
  left: calc(50% - 5px);
  border-radius: 4px;
}

/* Day/Night Overlay - Deep Contrast Night */
.day-night-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0); /* Default Day */
  pointer-events: none;
  z-index: 20; 
  transition: background 3s ease;
  mix-blend-mode: multiply; /* Back to multiply for true darkening */
}

.game.night .day-night-overlay {
  /* User requested "dont make game dark", so we remove the heavy overlay.
     We keep a tiny tint just for atmosphere, or 0.0 effectively disable it.
     Let's use 0.15 for specialized "Dusk" feel instead of pitch black. */
  background: rgba(0, 10, 30, 0.0); 
}

/* Street Lights Container */
.street-lights-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 15;
  overflow: hidden;
}

/* Individual Street Light - The Pole */
.street-light {
  position: absolute;
  width: 12px;
  height: 60px;
  background: linear-gradient(90deg, #555, #888, #555);
  border-radius: 4px;
  box-shadow: 0 5px 10px rgba(0,0,0,0.5);
  z-index: 25; /* Above overlay so poles stand out? No, keep under overlay */
}

.street-light.left { left: -5px; }
.street-light.right { right: -5px; }

/* The Lantern Head */
.street-light::before {
  content: '';
  position: absolute;
  top: 5px;
  width: 30px;
  height: 8px;
  background: #444;
  border-radius: 4px;
  z-index: 26;
}

.street-light.left::before { left: 8px; transform: skewY(-10deg); }
.street-light.right::before { right: 8px; transform: skewY(10deg); }

/* The Light Beam (Cone) - Realistic Soft Spotlight */
.street-light::after {
  content: '';
  position: absolute;
  top: 8px; 
  width: 220px; /* Wider for soft fade */
  height: 500px; 
  
  /* Soft, realistic light gradient (Bright top center -> Transparent edges) */
  background: radial-gradient(ellipse at top, rgba(255, 255, 200, 0.3) 0%, rgba(255, 255, 255, 0.05) 40%, transparent 70%);
  

  opacity: 0;
  pointer-events: none;
  transform-origin: 50% 0%;
  mix-blend-mode: overlay;
  transition: opacity 1.5s ease;
  /* REMOVED filter: blur(4px) - Use gradient for softness instead. Improves FPS significantly. */
  transform: translateZ(0); /* Force GPU */
}

/* Align Center (110px) to Bulb (35px) => Offset -75px */
.street-light.left::after { left: -75px; transform: rotate(-20deg); }
.street-light.right::after { right: -75px; transform: rotate(20deg); }


/* Night Mode: Lights ON */

/* 1. Pole gets slightly darker but stays visible */
.game.night .street-light {
  background: linear-gradient(90deg, #222, #444, #222);
}

/* 2. Light Beam turns ON - SOFT GLOW */
.game.night .street-light::after {
  opacity: 1.0;
  /* Brighter core when ON */
  background: radial-gradient(ellipse at top, rgba(255, 255, 220, 0.5) 0%, rgba(255, 255, 220, 0.1) 50%, transparent 80%);
  mix-blend-mode: screen;
  animation: flickerLight 5s infinite alternate;
}

/* 3. The Bulb Glows */
.game.night .street-light::before {
  box-shadow: 0 0 20px 8px rgba(255, 255, 200, 0.8), inset 0 0 5px white;
  background: #fff;
}

@keyframes flickerLight {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 0.75; }
  98% { opacity: 0.8; }
  99% { opacity: 0.6; } 
}

/* Mobile controls */
.mc {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 80px;
  justify-content: space-around;
  z-index: 20;
  display: none; /* Logic controls visibility */
  width: 100%;
  max-width: 400px;
  pointer-events: none; /* Let clicks pass through except buttons */
}

.mc-btn {
  pointer-events: auto;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 1.5rem;
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
}

.mc-btn:active {
  background: rgba(0, 255, 204, 0.3);
  border-color: #00ffcc;
  transform: scale(0.95);
}

.hide {
  display: none !important;
}

/* ===== Loader Styles ===== */
.loader-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, #1b2735 0%, #090a0f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  flex-direction: column;
  color: white;
}

.loader-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
}

.loader-container p {
  color: #00ffcc;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-size: 1.2rem;
  text-shadow: 0 0 10px rgba(0, 255, 204, 0.5);
}

.progress-bar {
  width: 240px;
  height: 6px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.progress {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #00ffcc, #0099ff);
  box-shadow: 0 0 10px #00ffcc;
  border-radius: 4px;
}

/* Fade-out animation for loader */
.fade-out {
  animation: fadeOut 0.6s forwards;
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
    visibility: hidden;
  }
}
