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

body {
  font-family: 'Inter', sans-serif;
  background: #050810;
  color: white;
  overflow: hidden;
  min-height: 100vh;
}

.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: block;
}

.hidden {
  display: none !important;
}

/* ════════ WAITING SCREEN ════════ */
#waiting-screen {
  background: 
    radial-gradient(ellipse at top, rgba(0, 224, 255, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at bottom, rgba(170, 255, 0, 0.1) 0%, transparent 50%),
    #050810;
  padding: 30px;
  display: none;
}

#waiting-screen.active {
  display: block;
}

.back-btn {
  position: absolute;
  top: 30px;
  left: 30px;
  color: #94a3b8;
  text-decoration: none;
  font-weight: 600;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: all 0.3s;
  z-index: 10;
}

.back-btn:hover {
  color: #00e0ff;
  border-color: #00e0ff;
}

.waiting-content {
  max-width: 900px;
  margin: 50px auto;
  text-align: center;
}

.title-wrap {
  position: relative;
  display: inline-block;
  margin-bottom: 12px;
}

.game-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 3.5rem;
  letter-spacing: -2px;
  color: white;
  text-shadow: 
    0 0 20px rgba(0, 224, 255, 0.6),
    0 0 40px rgba(0, 224, 255, 0.4);
  position: relative;
  z-index: 2;
}

.game-title span {
  background: linear-gradient(135deg, #aaff00, #00e0ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.speed-lines {
  position: absolute;
  left: -60px;
  top: 50%;
  transform: translateY(-50%);
}

.speed-lines span {
  display: block;
  width: 50px;
  height: 3px;
  background: linear-gradient(90deg, transparent, #00e0ff);
  margin-bottom: 8px;
  animation: speed 1.2s linear infinite;
}

.speed-lines span:nth-child(2) {
  width: 30px;
  animation-delay: 0.2s;
}

.speed-lines span:nth-child(3) {
  width: 40px;
  animation-delay: 0.4s;
}

@keyframes speed {
  0% { transform: translateX(-30px); opacity: 0; }
  50% { opacity: 1; }
  100% { transform: translateX(80px); opacity: 0; }
}

.game-subtitle {
  color: #94a3b8;
  font-size: 1rem;
  margin-bottom: 40px;
}

.room-display {
  background: rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(0, 224, 255, 0.3);
  border-radius: 20px;
  padding: 28px;
  margin-bottom: 35px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
  box-shadow: 0 0 40px rgba(0, 224, 255, 0.1);
}

.room-label {
  font-size: 0.75rem;
  color: #94a3b8;
  letter-spacing: 3px;
  margin-bottom: 10px;
}

.room-code-big {
  font-family: 'Press Start 2P', monospace;
  font-size: 3.5rem;
  letter-spacing: 12px;
  background: linear-gradient(135deg, #00e0ff, #aaff00);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 12px;
}

.room-hint {
  color: #94a3b8;
  font-size: 0.85rem;
}

.room-hint span {
  color: #00e0ff;
  font-family: monospace;
  font-weight: 600;
}

.racers-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  max-width: 700px;
  margin: 0 auto 35px;
}

.racer-slot {
  background: rgba(255, 255, 255, 0.03);
  border: 2px dashed rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 20px 15px;
  transition: all 0.3s;
}

.racer-slot.filled {
  background: rgba(0, 224, 255, 0.05);
  border-style: solid;
  border-color: rgba(0, 224, 255, 0.5);
  box-shadow: 0 0 20px rgba(0, 224, 255, 0.15);
}

.car-preview {
  width: 60px;
  height: 90px;
  margin: 0 auto 12px;
  position: relative;
  filter: drop-shadow(0 0 12px currentColor);
}

.car-body {
  width: 100%;
  height: 100%;
  background: currentColor;
  clip-path: polygon(
    20% 0%, 80% 0%, 
    90% 15%, 100% 35%, 100% 75%,
    85% 90%, 85% 100%, 65% 100%, 65% 90%,
    35% 90%, 35% 100%, 15% 100%, 15% 90%,
    0% 75%, 0% 35%, 10% 15%
  );
}

.color-1 { color: #00e0ff; }
.color-2 { color: #ff7b00; }
.color-3 { color: #aaff00; }
.color-4 { color: #ff3860; }

.racer-slot p {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.racer-slot .status {
  font-size: 0.75rem;
  color: #94a3b8;
}

.racer-slot.filled .status {
  color: #aaff00;
}

.action-buttons {
  display: flex;
  gap: 15px;
  justify-content: center;
  flex-wrap: wrap;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 16px 36px;
  border-radius: 12px;
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.3s;
}

.action-btn.primary {
  background: linear-gradient(135deg, #00e0ff, #0099ff);
  color: #050810;
  box-shadow: 0 8px 25px rgba(0, 224, 255, 0.3);
}

.action-btn.primary:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 35px rgba(0, 224, 255, 0.5);
}

.action-btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.action-btn.secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
}

.action-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ════════ RACE SCREEN ════════ */
#race-screen {
  background: #000;
  display: none;
  flex-direction: column;
  height: 100vh;
}

#race-screen.active {
  display: flex;
}

.race-hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 30px;
  padding: 20px 35px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.9), transparent);
  z-index: 10;
}

.hud-left {
  display: flex;
  gap: 25px;
}

.hud-item {
  background: rgba(0, 0, 0, 0.5);
  padding: 10px 20px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  min-width: 100px;
}

.hud-label {
  font-size: 0.65rem;
  color: #94a3b8;
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.hud-value {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.2rem;
  color: #00e0ff;
}

.hud-center {
  text-align: center;
}

.position-display {
  background: linear-gradient(135deg, rgba(0, 224, 255, 0.15), rgba(170, 255, 0, 0.1));
  border: 2px solid rgba(0, 224, 255, 0.4);
  padding: 12px 32px;
  border-radius: 14px;
  box-shadow: 0 0 30px rgba(0, 224, 255, 0.2);
}

.position-label {
  font-size: 0.7rem;
  color: #94a3b8;
  letter-spacing: 2px;
}

.position-value {
  font-family: 'Press Start 2P', monospace;
  font-size: 2rem;
  background: linear-gradient(135deg, #aaff00, #00e0ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hud-right {
  display: flex;
  justify-content: flex-end;
}

.leaderboard {
  background: rgba(0, 0, 0, 0.5);
  padding: 10px 15px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  min-width: 180px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.8rem;
}

.lb-pos {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.7rem;
  color: #94a3b8;
  width: 16px;
}

.lb-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  filter: drop-shadow(0 0 4px currentColor);
}

.lb-name {
  flex: 1;
  font-weight: 600;
}

.lb-lap {
  font-size: 0.7rem;
  color: #94a3b8;
}

/* Arena */
.arena {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #0a0f1c;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Countdown */
.countdown {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 100;
  pointer-events: none;
}

.countdown h1 {
  font-family: 'Press Start 2P', monospace;
  font-size: 8rem;
  background: linear-gradient(135deg, #ffaa00, #ff3860);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 80px rgba(255, 170, 0, 0.6);
  animation: countdownPop 1s ease-out;
}

@keyframes countdownPop {
  0% { transform: scale(0); opacity: 0; }
  30% { transform: scale(1.3); opacity: 1; }
  60% { transform: scale(1); }
  100% { transform: scale(0.8); opacity: 0; }
}

/* ════════ FINISH SCREEN ════════ */
#finish-screen {
  background: 
    radial-gradient(ellipse at center, rgba(170, 255, 0, 0.1) 0%, transparent 60%),
    #050810;
  padding: 40px;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#finish-screen.active {
  display: flex;
}

.finish-content {
  max-width: 800px;
  width: 100%;
  text-align: center;
}

.finish-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 2.5rem;
  background: linear-gradient(135deg, #aaff00, #00e0ff);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 50px;
  text-shadow: 0 0 40px rgba(170, 255, 0, 0.4);
}

.podium {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: end;
  gap: 15px;
  max-width: 500px;
  margin: 0 auto 50px;
}

.podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.podium-medal {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Press Start 2P', monospace;
  font-size: 1.5rem;
  color: #050810;
  margin-bottom: 12px;
}

.podium-name {
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 12px;
  color: white;
}

.podium-bar {
  width: 100%;
  border-radius: 12px 12px 0 0;
}

.first .podium-medal {
  background: linear-gradient(135deg, #ffaa00, #ff7b00);
  box-shadow: 0 0 30px rgba(255, 170, 0, 0.6);
}

.first .podium-bar {
  height: 200px;
  background: linear-gradient(180deg, #ffaa00, #ff7b00);
}

.second .podium-medal {
  background: linear-gradient(135deg, #c0c0c0, #94a3b8);
}

.second .podium-bar {
  height: 140px;
  background: linear-gradient(180deg, #c0c0c0, #64748b);
}

.third .podium-medal {
  background: linear-gradient(135deg, #cd7f32, #8b4513);
}

.third .podium-bar {
  height: 100px;
  background: linear-gradient(180deg, #cd7f32, #6b3410);
}

.finish-stats {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 25px;
  margin-bottom: 30px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-row:last-child {
  border-bottom: none;
}

.stat-row .label {
  color: #94a3b8;
}

.stat-row .value {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.9rem;
  color: #00e0ff;
}

.finish-buttons {
  display: flex;
  gap: 15px;
  justify-content: center;
  flex-wrap: wrap;
}

/* Responsive */
@media (max-width: 768px) {
  .racers-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .game-title {
    font-size: 2rem;
  }

  .room-code-big {
    font-size: 2.5rem;
  }

  .race-hud {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px 20px;
  }

  .hud-left, .hud-right {
    justify-content: center;
  }
}