:root {
  --lego-red: #d01012;
  --lego-yellow: #f6b40e;
  --lego-blue: #0057a8;
  --lego-green: #00963e;
  --lego-orange: #f57d20;
  --dark: #1a1a2e;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Fredoka", "Comic Sans MS", sans-serif;
  background: #87ceeb;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 20, 45, 0.35);
  backdrop-filter: blur(3px);
  z-index: 10;
}

.menu-panel {
  background: #fdf6e3;
  border: 6px solid var(--dark);
  border-radius: 24px;
  padding: 32px 44px 28px;
  text-align: center;
  box-shadow: 0 14px 0 rgba(0, 0, 0, 0.35);
  max-width: 720px;
  width: min(92vw, 720px);
  position: relative;
}

/* stud strip along the top of panels */
.menu-panel::before {
  content: "";
  position: absolute;
  top: -16px;
  left: 40px;
  right: 40px;
  height: 20px;
  background: radial-gradient(circle at 10px 10px, var(--lego-red) 9px, transparent 10px);
  background-size: 34px 20px;
  background-repeat: repeat-x;
}

.game-title {
  font-family: "Titan One", "Fredoka", sans-serif;
  font-size: clamp(2.4rem, 7vw, 4.2rem);
  letter-spacing: 2px;
  -webkit-text-stroke: 2.5px var(--dark);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 rgba(0, 0, 0, 0.25);
}

.t-red { color: var(--lego-red); }
.t-yellow { color: var(--lego-yellow); }

.tagline {
  font-size: 1.15rem;
  font-weight: 600;
  color: #444;
  margin: 4px 0 22px;
}

/* ---------- Mode cards ---------- */
.mode-cards {
  display: flex;
  gap: 26px;
  justify-content: center;
  margin-bottom: 20px;
}

.mode-card {
  flex: 1;
  max-width: 270px;
  border: 5px solid var(--dark);
  border-radius: 18px;
  padding: 14px 18px 18px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.3);
  color: #fff;
}

.card-car { background: linear-gradient(180deg, #e6342f, var(--lego-red)); }
.card-bike { background: linear-gradient(180deg, #1272cf, var(--lego-blue)); }

.mode-card:hover {
  transform: translateY(-6px) scale(1.03);
  box-shadow: 0 14px 0 rgba(0, 0, 0, 0.3);
}
.mode-card:active { transform: translateY(0) scale(0.98); box-shadow: 0 4px 0 rgba(0,0,0,.3); }

.studs-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 8px;
}
.studs-row i {
  width: 22px;
  height: 10px;
  border-radius: 6px 6px 3px 3px;
  background: rgba(255, 255, 255, 0.35);
  border: 2px solid rgba(0, 0, 0, 0.25);
}

.mode-emoji { font-size: 3.2rem; line-height: 1.2; filter: drop-shadow(0 4px 0 rgba(0,0,0,.25)); }

.mode-name {
  font-family: "Titan One", sans-serif;
  font-size: 1.9rem;
  letter-spacing: 3px;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.mode-desc { font-weight: 600; opacity: 0.92; margin-bottom: 12px; }

.stat-bars { display: flex; flex-direction: column; gap: 6px; }
.stat { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; font-weight: 700; }
.stat span { width: 68px; text-align: left; }
.stat .bar {
  flex: 1;
  height: 10px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 6px;
  overflow: hidden;
}
.stat .bar div { height: 100%; background: var(--lego-yellow); border-radius: 6px; }

.controls-hint { font-size: 0.95rem; font-weight: 600; color: #666; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }

#hud-topleft { position: absolute; top: 18px; left: 20px; }

#hud-position {
  font-family: "Titan One", sans-serif;
  font-size: 3.4rem;
  color: var(--lego-yellow);
  -webkit-text-stroke: 2.5px var(--dark);
  paint-order: stroke fill;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
  line-height: 1;
}
#hud-position span { font-size: 1.6rem; color: #fff; }

#hud-lap {
  font-family: "Titan One", sans-serif;
  font-size: 1.5rem;
  color: #fff;
  -webkit-text-stroke: 1.5px var(--dark);
  paint-order: stroke fill;
  margin-top: 6px;
}
#hud-lap span { color: var(--lego-yellow); }

#minimap {
  position: absolute;
  top: 18px;
  right: 20px;
  background: rgba(15, 25, 50, 0.55);
  border: 4px solid var(--dark);
  border-radius: 14px;
}

#hud-speed {
  position: absolute;
  bottom: 24px;
  right: 26px;
  font-family: "Titan One", sans-serif;
  font-size: 3rem;
  color: #fff;
  -webkit-text-stroke: 2px var(--dark);
  paint-order: stroke fill;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}
#hud-speed .speed-unit { font-size: 1rem; color: var(--lego-yellow); margin-left: 6px; }

#hud-hint {
  position: absolute;
  bottom: 16px;
  left: 20px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.5);
  font-size: 0.9rem;
}

/* ---------- Countdown & flash ---------- */
#countdown {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 8;
  pointer-events: none;
  font-family: "Titan One", sans-serif;
  font-size: clamp(6rem, 20vw, 12rem);
  color: var(--lego-yellow);
  -webkit-text-stroke: 5px var(--dark);
  paint-order: stroke fill;
  text-shadow: 0 10px 0 rgba(0, 0, 0, 0.3);
  animation: pop 0.5s ease;
}

#flash-msg {
  position: fixed;
  top: 22%;
  left: 0;
  right: 0;
  text-align: center;
  z-index: 8;
  pointer-events: none;
  font-family: "Titan One", sans-serif;
  font-size: clamp(2rem, 6vw, 3.6rem);
  color: #fff;
  -webkit-text-stroke: 2.5px var(--dark);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.3);
  animation: pop 0.4s ease;
}

@keyframes pop {
  0% { transform: scale(0.3); opacity: 0; }
  60% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- Results ---------- */
.results-panel { max-width: 520px; }

#results-podium {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 14px;
  color: #333;
}

#results-list {
  list-style: none;
  margin: 0 auto 22px;
  max-width: 380px;
  text-align: left;
}

#results-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 1.1rem;
  padding: 7px 14px;
  border-radius: 10px;
  margin-bottom: 5px;
  background: rgba(0, 0, 0, 0.06);
  color: #222;
}

#results-list li.player-row {
  background: var(--lego-yellow);
  border: 3px solid var(--dark);
  font-weight: 700;
}

#results-list .place { font-family: "Titan One", sans-serif; width: 34px; }
#results-list .swatch {
  width: 20px;
  height: 14px;
  border-radius: 4px;
  border: 2px solid var(--dark);
  display: inline-block;
}
#results-list .rtime { margin-left: auto; color: #555; font-size: 0.95rem; }

.big-btn {
  font-family: "Titan One", sans-serif;
  font-size: 1.5rem;
  letter-spacing: 2px;
  color: #fff;
  background: linear-gradient(180deg, #24b45c, var(--lego-green));
  border: 5px solid var(--dark);
  border-radius: 16px;
  padding: 12px 40px;
  cursor: pointer;
  box-shadow: 0 7px 0 rgba(0, 0, 0, 0.3);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.big-btn:hover { transform: translateY(-3px); box-shadow: 0 10px 0 rgba(0, 0, 0, 0.3); }
.big-btn:active { transform: translateY(2px); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3); }

@media (max-width: 640px) {
  .mode-cards { flex-direction: column; align-items: center; }
  .menu-panel { padding: 24px 20px; }
}
