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

body {
  font-family: "Chakra Petch", "Quicksand", sans-serif;
  background: #1e272e;
  height: 100vh;
  overflow: hidden;
  color: white;
}

button {
  font-family: "Chakra Petch", "Quicksand", sans-serif;
}

/* Full-screen 3D stage */
.game-stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* Heads-up display overlaid on the canvas. The container ignores pointer
   events so taps fall through to the canvas (lane change); only the logo
   captures clicks. */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas: "left lane .";
  align-items: start;
  gap: 12px;
  padding: 14px 18px;
  z-index: 50;
  pointer-events: none;
}

.hud-logo {
  pointer-events: auto;
}

.hud-left {
  grid-area: left;
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 14px;
}

.hud-logo {
  display: flex;
}

.hud-logo img {
  width: 38px;
  display: block;
}

.timer-container {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

#timer {
  font-size: 1.3rem;
  font-weight: 600;
  color: #fff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
}

.best-time {
  font-size: 0.9rem;
  color: #f7b733;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}

.game-info {
  grid-area: lane;
  justify-self: center;
  display: flex;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 600;
}

#current-lane {
  font-weight: 700;
  color: #eaf4ff;
  background: rgba(18, 26, 36, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.35);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  padding: 5px 14px;
  border-radius: 16px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
}

/* Brief pop + glow each time the player changes lane */
@keyframes lane-flash {
  0% {
    transform: scale(1.3);
    background: #3498db;
    border-color: #8fd0ff;
    color: #fff;
    box-shadow: 0 0 20px rgba(52, 152, 219, 0.95);
  }
  25% {
    transform: scale(1.16);
    background: #3498db;
    border-color: #8fd0ff;
    color: #fff;
    box-shadow: 0 0 16px rgba(52, 152, 219, 0.8);
  }
  100% {
    transform: scale(1);
    background: rgba(18, 26, 36, 0.5);
    border-color: rgba(255, 255, 255, 0.35);
    color: #eaf4ff;
    box-shadow: 0 0 0 rgba(52, 152, 219, 0);
  }
}

#current-lane.lane-flash {
  animation: lane-flash 0.6s ease-out;
}

#gameCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
  border: none;
  border-radius: 0;
  background: #1e272e;
  touch-action: none;
}

/* Black wash that peaks while the camera is inside a tunnel, hiding the
   scene swap. Driven from JS via inline opacity. */
.tunnel-fade {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  z-index: 65;
  pointer-events: none;
}

.game-over {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  /* Translucent frosted layer: the crash / victory scene stays visible behind. */
  background: rgba(18, 26, 36, 0.45);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.game-over h2 {
  font-size: 2.5rem;
  margin-bottom: 15px;
  font-weight: 600;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

.game-over p {
  font-size: 1.2rem;
  margin-bottom: 25px;
  color: #aebccb;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.55);
}

.progress-reached {
  font-size: 1rem;
  color: #3498db;
  font-weight: 500;
  margin-bottom: 10px;
}

.new-record {
  font-size: 1.3rem;
  color: #f39c12;
  font-weight: 600;
  margin-top: 5px;
  margin-bottom: 20px;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.8;
  }
}

#restart-btn {
  padding: 14px 35px;
  font-size: 1rem;
  font-weight: 600;
  background: #3498db;
  color: #fff;
  border: none;
  border-radius: 25px;
  cursor: pointer;
  transition: all 0.15s ease;
}

#restart-btn:hover {
  background: #2980b9;
}

.hidden {
  display: none !important;
}

.countdown-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 39, 46, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 60;
}

.start-overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 26, 36, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 40;
  cursor: pointer;
  padding: 24px;
}

.start-card {
  text-align: center;
  max-width: 85%;
}

.start-msg {
  font-size: 1.35rem;
  font-weight: 600;
  color: #fff;
  line-height: 1.5;
  margin-bottom: 18px;
}

.start-msg .arrow-key {
  display: inline-block;
  padding: 0 9px;
  border: 1.5px solid rgba(255, 255, 255, 0.7);
  border-radius: 6px;
  font-weight: 700;
  margin: 0 2px;
}

.start-cta {
  font-size: 1.05rem;
  font-weight: 600;
  color: #f39c12;
  text-transform: uppercase;
  letter-spacing: 1px;
  animation: pulse 1.2s ease-in-out infinite;
}

@media (max-width: 768px) {
  .start-msg {
    font-size: 1.1rem;
  }
  .start-cta {
    font-size: 0.95rem;
  }
}

#countdown-text {
  font-size: 8rem;
  font-weight: 700;
  color: #fff;
  animation: countdown-pulse 0.4s ease-in-out;
}

@keyframes countdown-pulse {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 768px) {
  #countdown-text {
    font-size: 5rem;
  }
}

.lane-change-btn {
  margin-top: 20px;
  padding: 12px 28px;
  font-size: 1.1rem;
  background: linear-gradient(45deg, #667eea, #764ba2);
  color: white;
  border: none;
  border-radius: 25px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transition: background 0.1s, transform 0.1s;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}
.lane-change-btn:hover {
  background: linear-gradient(45deg, #764ba2, #667eea);
  transform: translateY(-2px);
}
.lane-change-btn:active {
  transform: translateY(0px);
  transition: transform 0.05s;
}

/* On narrow screens, keep the timer on the top row and drop the lane
   indicator onto a centred row below. */
@media (max-width: 640px) {
  .hud {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "left ."
      "lane lane";
    row-gap: 8px;
    padding: 10px 12px;
  }

  .hud-left {
    gap: 10px;
  }

  .game-info {
    font-size: 1rem;
  }

  #timer {
    font-size: 1.1rem;
  }

  .hud-logo img {
    width: 32px;
  }
}
