* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow: hidden;
  background: #1a1a2e;
  font-family: 'Fredoka One', 'Comic Sans MS', cursive;
  color: #4A3050;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#scene-container {
  touch-action: none;
}

#scene-container {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 0;
}

#scene-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.screen {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  touch-action: manipulation;
}

#start-screen {
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(6px);
}

.title-container {
  text-align: center;
  margin-bottom: 20px;
}

.title {
  font-size: clamp(2.2rem, 8vw, 4.5rem);
  color: #fff;
  text-shadow: 0 4px 20px rgba(255,181,194,0.7), 0 2px 4px rgba(0,0,0,0.2);
  animation: titlePulse 2s ease-in-out infinite;
  letter-spacing: 2px;
}

@keyframes titlePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.subtitle {
  font-size: clamp(0.9rem, 3vw, 1.3rem);
  color: rgba(255,255,255,0.85);
  margin-top: 8px;
}

.color-picker {
  display: flex;
  gap: 12px;
  margin: 20px 0;
}

.color-swatch {
  width: clamp(36px, 8vw, 50px);
  height: clamp(36px, 8vw, 50px);
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.5);
  cursor: pointer;
  transition: all 0.2s;
}

.color-swatch:hover, .color-swatch.active {
  border-color: #fff;
  transform: scale(1.2);
  box-shadow: 0 0 15px rgba(255,255,255,0.5);
}

.btn-play {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1.2rem, 4vw, 1.8rem);
  color: #fff;
  background: linear-gradient(135deg, #FFB5C2, #FF8FA3);
  border: none;
  border-radius: 50px;
  padding: 16px 48px;
  cursor: pointer;
  margin-top: 10px;
  box-shadow: 0 6px 20px rgba(255,143,163,0.4);
  animation: btnPulse 1.5s ease-in-out infinite;
  transition: transform 0.15s;
}

.btn-play:active {
  transform: scale(0.95);
}

.btn-play, .btn-race-again, .btn-menu, .color-swatch {
  touch-action: manipulation;
  cursor: pointer;
  position: relative;
  z-index: 20;
}

@keyframes btnPulse {
  0%, 100% { box-shadow: 0 6px 20px rgba(255,143,163,0.4); }
  50% { box-shadow: 0 6px 30px rgba(255,143,163,0.7); }
}

.controls-hint {
  margin-top: 14px;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.6);
}

.remix-link {
  position: absolute;
  bottom: 12px;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.5);
  text-decoration: none;
}
.remix-link:hover { color: rgba(255,255,255,0.8); }

/* Countdown */
#countdown-screen {
  background: rgba(0,0,0,0.25);
  pointer-events: none;
}

.countdown-num {
  font-size: clamp(5rem, 20vw, 10rem);
  color: #FFB5C2;
  text-shadow: 0 4px 30px rgba(255,181,194,0.6);
  animation: countPop 0.8s ease-out;
}

@keyframes countPop {
  0% { transform: scale(2.5); opacity: 0; }
  40% { transform: scale(0.9); opacity: 1; }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

/* HUD */
#hud {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 5;
  pointer-events: none;
}

.hud-panel {
  position: absolute;
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(4px);
  border-radius: 14px;
  padding: 8px 16px;
  font-size: clamp(0.85rem, 2.5vw, 1.1rem);
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.hud-position { top: 12px; left: 12px; }
.hud-lap { top: 12px; right: 12px; }

.touch-indicator {
  position: absolute;
  bottom: 50%;
  font-size: 3rem;
  color: rgba(255,255,255,0.0);
  transition: color 0.1s;
  pointer-events: none;
}
.touch-indicator.visible { color: rgba(255,255,255,0.3); }
.touch-left { left: 30px; }
.touch-right { right: 30px; }

.lap-popup {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(2rem, 8vw, 4rem);
  color: #FFB5C2;
  text-shadow: 0 3px 15px rgba(255,181,194,0.6);
  animation: lapPop 1.2s ease-out forwards;
  pointer-events: none;
}

@keyframes lapPop {
  0% { transform: translate(-50%,-50%) scale(0); opacity: 0; }
  20% { transform: translate(-50%,-50%) scale(1.3); opacity: 1; }
  50% { transform: translate(-50%,-50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%,-50%) scale(0.8); opacity: 0; }
}

.minimap-container {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(255,255,255,0.7);
  border-radius: 12px;
  padding: 4px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

#minimap {
  display: block;
  border-radius: 8px;
}

/* Results */
#results-screen {
  background: rgba(255,255,255,0.2);
  backdrop-filter: blur(8px);
}

#confetti-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: -1;
}

.results-title {
  font-size: clamp(1.8rem, 6vw, 3rem);
  color: #fff;
  text-shadow: 0 3px 15px rgba(255,181,194,0.6);
  margin-bottom: 20px;
}

.results-table {
  background: rgba(255,255,255,0.85);
  border-radius: 16px;
  padding: 16px 24px;
  min-width: 260px;
  max-width: 90vw;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  margin-bottom: 20px;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: clamp(0.85rem, 2.5vw, 1.05rem);
  border-bottom: 1px solid rgba(74,48,80,0.1);
}
.result-row:last-child { border-bottom: none; }

.result-row.highlight {
  background: rgba(255,181,194,0.2);
  border-radius: 8px;
  padding: 6px 8px;
  margin: 0 -8px;
}

.result-color {
  width: 18px; height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
}

.result-pos { font-weight: bold; min-width: 32px; }
.result-name { flex: 1; }

.btn-race-again {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(1rem, 3.5vw, 1.4rem);
  color: #fff;
  background: linear-gradient(135deg, #B5F0D0, #7ED6A8);
  border: none;
  border-radius: 50px;
  padding: 14px 40px;
  cursor: pointer;
  margin-bottom: 10px;
  box-shadow: 0 4px 15px rgba(126,214,168,0.4);
}

.btn-menu {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(0.85rem, 2.5vw, 1rem);
  color: #4A3050;
  background: rgba(255,255,255,0.7);
  border: none;
  border-radius: 50px;
  padding: 10px 30px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.btn-race-again:active, .btn-menu:active { transform: scale(0.95); }