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

body {
  overflow: hidden;
  background: #111;
  font-family: "Inter", system-ui, sans-serif;
  user-select: none;
  color: #d4d4d4;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

#container { width: 100vw; height: 100vh; position: relative; }
#threeCanvas { position: absolute; inset: 0; }

/* ===================== MAIN MENU ===================== */

#mainMenu {
  position: absolute; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 8, 8, 0.88);
  backdrop-filter: blur(20px);
}

#menuContent {
  width: 300px;
  display: flex; flex-direction: column; align-items: center;
}

#menuTitle {
  font-family: "Exo 2", sans-serif;
  font-size: 44px;
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: 6px;
  color: #fff;
  text-align: center;
  margin-bottom: 6px;
  text-transform: uppercase;
}

#menuSub {
  font-size: 11px;
  font-weight: 500;
  color: #555;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 36px;
}

#playerNameInput {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: none;
  border-radius: 10px;
  padding: 13px 18px;
  font-family: "Inter", sans-serif;
  font-size: 15px;
  font-weight: 500;
  color: #fff;
  text-align: center;
  outline: none;
  transition: background 0.2s;
  margin-bottom: 20px;
}

#playerNameInput::placeholder { color: #444; }
#playerNameInput:focus { background: rgba(255, 255, 255, 0.08); }

#menuAiRow {
  width: 100%;
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 28px;
  font-size: 13px; color: #555; font-weight: 500;
}

#menuAiRow span:first-child { flex-shrink: 0; }

#aiCountSlider {
  flex: 1;
  accent-color: #666;
  height: 4px;
}

#aiCountValue {
  min-width: 18px;
  text-align: right;
  font-weight: 600;
  color: #aaa;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

#menuActions {
  width: 100%;
  display: flex; flex-direction: column; gap: 10px;
}

#menuActions button, #joinRow button {
  font-family: "Exo 2", sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #ccc;
  background: rgba(255, 255, 255, 0.06);
  border: none;
  border-radius: 10px;
  padding: 14px 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  width: 100%;
}

#menuActions button:hover, #joinRow button:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

#menuActions button:active, #joinRow button:active {
  background: rgba(255, 255, 255, 0.16);
}

#menuDivider {
  display: flex; align-items: center; gap: 14px;
  margin: 6px 0;
}

#menuDivider::before, #menuDivider::after {
  content: ""; flex: 1; height: 1px;
  background: rgba(255, 255, 255, 0.06);
}

#menuDivider span {
  font-size: 11px; color: #3a3a3a; font-weight: 500;
  letter-spacing: 1px; text-transform: uppercase;
  white-space: nowrap;
}

#joinRow {
  display: flex; gap: 8px;
}

#joinCodeInput {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-family: "Exo 2", sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 4px;
  outline: none;
  transition: background 0.2s;
}

#joinCodeInput::placeholder {
  color: #333;
  letter-spacing: 3px;
  font-weight: 600;
}

#joinCodeInput:focus { background: rgba(255, 255, 255, 0.08); }

#joinRow button { width: auto; padding: 14px 24px; flex-shrink: 0; }

#menuError {
  margin-top: 16px;
  color: #c44;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}

/* ===================== LOBBY ===================== */

#lobby {
  position: absolute; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 8, 8, 0.88);
  backdrop-filter: blur(20px);
}

#lobbyContent {
  width: 320px;
  display: flex; flex-direction: column; align-items: center;
}

#lobbyLabel {
  font-size: 11px; font-weight: 500; color: #444;
  letter-spacing: 3px; text-transform: uppercase;
  margin-bottom: 10px;
}

#lobbyCode {
  font-family: "Exo 2", sans-serif;
  font-size: 36px;
  font-weight: 800;
  letter-spacing: 8px;
  color: #fff;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  padding: 14px 28px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 6px;
}

#lobbyCode:hover { background: rgba(255, 255, 255, 0.08); }

#lobbyCopied {
  font-size: 12px;
  color: #5a5;
  font-weight: 500;
  margin-bottom: 24px;
  height: 18px;
}

#lobbyPlayers {
  width: 100%;
  margin-bottom: 24px;
}

.lobby-player {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px; font-weight: 500;
  background: rgba(255, 255, 255, 0.03);
  margin-bottom: 4px;
}

.lobby-player-color {
  width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0;
}

.lobby-player-name { flex: 1; color: #bbb; }
.lobby-player-you { color: #fff; font-weight: 600; }

.lobby-player-host {
  font-family: "Exo 2", sans-serif;
  font-size: 10px; color: #555;
  text-transform: uppercase; letter-spacing: 1.5px;
  font-weight: 700;
}

#lobbyActions {
  width: 100%;
  margin-bottom: 16px;
}

#btnStartRace {
  font-family: "Exo 2", sans-serif;
  font-size: 14px; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase;
  color: #ccc;
  background: rgba(255, 255, 255, 0.06);
  border: none; border-radius: 10px;
  padding: 14px 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  width: 100%;
}

#btnStartRace:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }

#lobbyHint {
  font-size: 12px; color: #333; font-weight: 500;
  letter-spacing: 0.5px;
}

/* ===================== GAME HUD ===================== */

#gameUI { position: absolute; inset: 0; pointer-events: none; }
#gameUI > * { pointer-events: auto; }
#nameLabels { pointer-events: none; }

#hud {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 100;
  display: flex; gap: 6px; align-items: center;
}

#hud > div {
  background: rgba(10, 10, 10, 0.7);
  backdrop-filter: blur(12px);
  border-radius: 8px;
  padding: 8px 16px;
  font-family: "Exo 2", sans-serif;
  font-weight: 600;
}

#speedDisplay {
  font-size: 18px; color: #e0e0e0;
  font-variant-numeric: tabular-nums;
  min-width: 100px; text-align: center;
  letter-spacing: 0.5px;
}

#lapDisplay {
  font-size: 13px; color: #999;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
}

#cameraMode {
  font-size: 11px; color: #555;
  text-transform: uppercase; letter-spacing: 2px;
}

#positionBadge {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  z-index: 100;
  display: flex; align-items: baseline; gap: 2px;
}

#positionNumber {
  font-family: "Exo 2", sans-serif;
  color: #fff; font-size: 52px; font-weight: 800;
  line-height: 1;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

#positionSuffix {
  font-family: "Exo 2", sans-serif;
  color: #aaa; font-size: 22px; font-weight: 700;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}

#leaderboard {
  position: absolute; top: 12px; left: 12px; z-index: 100;
  background: rgba(10, 10, 10, 0.7);
  backdrop-filter: blur(12px);
  border-radius: 10px;
  padding: 10px 0;
  min-width: 190px;
  font-variant-numeric: tabular-nums;
}

.lb-row {
  display: flex; align-items: center;
  padding: 3px 14px; gap: 8px;
  font-size: 12px; color: #666; height: 24px;
  font-weight: 500;
}

.lb-row.is-player { color: #ddd; font-weight: 600; }
.lb-row.is-finished { opacity: 0.4; }
.lb-pos { width: 18px; text-align: right; font-family: "Exo 2", sans-serif; font-weight: 700; flex-shrink: 0; }
.lb-color { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-lap { width: 28px; text-align: right; flex-shrink: 0; font-size: 10px; color: #444; }
.lb-row.is-player .lb-lap { color: #888; }
.lb-gap { width: 48px; text-align: right; flex-shrink: 0; font-size: 10px; color: #383838; font-family: "Exo 2", sans-serif; }
.lb-row.is-player .lb-gap { color: #777; }

/* ===================== RACE OVERLAY ===================== */

#raceOverlay {
  position: absolute; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
}

#raceOverlayContent {
  background: rgba(18, 18, 18, 0.95);
  border-radius: 16px;
  padding: 36px 44px;
  min-width: 340px;
  text-align: center;
}

#raceOverlayTitle {
  font-family: "Exo 2", sans-serif;
  color: #fff; font-size: 26px; font-weight: 800;
  margin-bottom: 24px; letter-spacing: 1px;
  text-transform: uppercase;
}

#raceOverlayResults { text-align: left; margin-bottom: 24px; }

.result-row {
  display: flex; align-items: center;
  padding: 8px 12px; gap: 12px;
  font-size: 14px; color: #666;
  border-radius: 6px;
  margin-bottom: 2px;
  font-weight: 500;
}

.result-row.is-player { color: #ddd; font-weight: 600; background: rgba(255, 255, 255, 0.04); }
.result-pos { width: 24px; text-align: right; font-family: "Exo 2", sans-serif; font-weight: 700; flex-shrink: 0; }
.result-color { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.result-name { flex: 1; }
.result-time { font-variant-numeric: tabular-nums; font-size: 13px; color: #444; font-family: "Exo 2", sans-serif; }
.result-row.is-player .result-time { color: #888; }

#raceOverlayHint {
  font-size: 12px; color: #333;
  letter-spacing: 0.5px; font-weight: 500;
}

/* ===================== NAME LABELS ===================== */

#nameLabels {
  position: absolute; inset: 0; z-index: 90;
  pointer-events: none; overflow: hidden;
}

.name-label {
  position: absolute;
  font-family: "Exo 2", sans-serif;
  color: #e0e0e0; font-size: 11px; font-weight: 600;
  letter-spacing: 1px;
  white-space: nowrap;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.9), 0 0 2px rgba(0, 0, 0, 0.7);
  transform: translate(-50%, -100%);
  pointer-events: none;
  transition: opacity 0.1s;
}

#instructions {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: #333; z-index: 100;
  white-space: nowrap; letter-spacing: 0.5px;
  font-weight: 500;
}
