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

:root {
  --accent: #ffca28;
  --bg: #0d1117;
  --panel: rgba(18, 22, 30, 0.92);
}

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: var(--bg);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #fff; user-select: none;
}

#game { display: block; width: 100vw; height: 100vh; }

.hidden { display: none !important; }

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

#topleft {
  position: absolute; top: 18px; left: 20px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat { display: flex; align-items: baseline; gap: 10px; }
.stat .label { font-size: 12px; letter-spacing: 2px; color: #8b98a9; width: 44px; }
.stat .value { font-variant-numeric: tabular-nums; font-weight: 700; }
.stat .value.big { font-size: 38px; line-height: 1; color: var(--accent); text-shadow: 0 2px 12px rgba(255,202,40,.35); }
.stat .value { font-size: 22px; }
.stat.small .value { font-size: 15px; color: #cdd7e2; }

#speedo {
  position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%);
  font-weight: 800; text-align: center;
}
#speedo #speed { font-size: 54px; font-variant-numeric: tabular-nums; text-shadow: 0 3px 18px rgba(0,0,0,.6); }
#speedo .unit { font-size: 16px; color: #8b98a9; margin-left: 6px; }

#boost {
  position: relative; width: 220px; height: 16px; margin: 8px auto 0;
  background: rgba(0,0,0,.45); border: 1px solid rgba(255,255,255,.18);
  border-radius: 9px; overflow: hidden;
}
#boostFill {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #29b6f6, #4fc3f7);
  transition: width .08s linear, background .15s;
}
#boost.ready #boostFill { background: linear-gradient(90deg, #66bb6a, #b2ff59); }
#boost.firing #boostFill {
  background: linear-gradient(90deg, #ff9800, #ffeb3b);
  animation: boostpulse .25s infinite alternate;
}
@keyframes boostpulse { from { filter: brightness(1); } to { filter: brightness(1.5); } }
#boost .boostlabel {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; letter-spacing: 2px; color: rgba(255,255,255,.85);
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}

#topright {
  position: absolute; top: 16px; right: 18px; width: 240px;
  text-align: right;
}
#online { font-size: 13px; color: #4caf50; margin-bottom: 8px; letter-spacing: .5px; }
#board {
  background: var(--panel); border-radius: 10px; padding: 8px 10px;
  font-size: 12.5px; backdrop-filter: blur(6px);
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
  pointer-events: auto;
}
#board .row { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
#board .row .pos { width: 20px; color: #8b98a9; text-align: right; }
#board .row .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
#board .row .nm { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#board .row .tm { font-variant-numeric: tabular-nums; color: var(--accent); }
#board .row.me { background: rgba(255,202,40,.12); border-radius: 4px; }
.board-tabs { display: flex; gap: 2px; margin-bottom: 6px; }
.board-tab {
  flex: 1; text-align: center; font-size: 10px; font-weight: 700; letter-spacing: 1.5px;
  color: #6b7686; padding: 3px 0; border-radius: 5px; cursor: pointer;
  transition: color .15s, background .15s;
}
.board-tab:hover { color: #cdd7e2; }
.board-tab.active { color: var(--accent); background: rgba(255,202,40,.1); }

#audioControls {
  position: absolute; bottom: 46px; right: 18px; display: flex; gap: 8px;
  pointer-events: auto;
}
.audiobtn {
  background: rgba(0,0,0,.4); border: 1px solid rgba(255,255,255,.15);
  color: #cdd7e2; font-size: 12px; font-weight: 600; padding: 5px 10px;
  border-radius: 8px; cursor: pointer; backdrop-filter: blur(4px); transition: all .12s;
}
.audiobtn:hover { border-color: rgba(255,255,255,.35); color: #fff; }
.audiobtn.muted { color: #6b7686; background: rgba(0,0,0,.25); }

#help {
  position: absolute; bottom: 14px; right: 18px;
  font-size: 12px; color: #6b7686; background: rgba(0,0,0,.3);
  padding: 5px 10px; border-radius: 8px;
}
#help b { color: #aeb9c6; }

#minimap-wrap {
  position: absolute; bottom: 14px; left: 18px;
  background: var(--panel); border-radius: 10px; padding: 6px;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}

#garage {
  position: absolute; top: 50%; left: 20px; transform: translateY(-50%);
  width: 250px; pointer-events: auto;
  background: var(--panel); border: 1px solid rgba(255,210,63,.35);
  border-radius: 14px; padding: 16px 16px 14px; backdrop-filter: blur(6px);
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  animation: garageIn .18s ease-out;
}
@keyframes garageIn { from { opacity: 0; transform: translate(-12px, -50%); } to { opacity: 1; transform: translate(0, -50%); } }
#garage .gtitle { font-size: 15px; font-weight: 800; letter-spacing: 1px; color: var(--accent); margin-bottom: 10px; }
#garage .glabel { font-size: 11px; letter-spacing: 1.5px; color: #8b98a9; margin: 12px 0 6px; }
#garage .ghint { margin-top: 12px; font-size: 11px; color: #6b7686; }
#garageTypes { display: flex; flex-wrap: wrap; gap: 6px; }
#garageColors { display: flex; flex-wrap: wrap; gap: 8px; }
#garageColors .swatch { width: 28px; height: 28px; }
#minimap { display: block; }

#toast {
  position: absolute; top: 90px; left: 50%; transform: translateX(-50%);
  font-size: 30px; font-weight: 800; text-align: center;
  opacity: 0; transition: opacity .25s; text-shadow: 0 3px 20px rgba(0,0,0,.6);
}
#toast.show { opacity: 1; }

/* Shield indicator — glows blue when the player has a shield active */
#shieldHud {
  position: absolute; top: 160px; left: 50%; transform: translateX(-50%);
  font-size: 32px; opacity: 0; transition: opacity .2s, filter .2s;
  pointer-events: none;
}
#shieldHud.active {
  opacity: 1;
  filter: drop-shadow(0 0 10px #29b6f6) drop-shadow(0 0 4px #29b6f6);
  animation: shieldpulse 1.2s infinite alternate;
}
@keyframes shieldpulse { from { filter: drop-shadow(0 0 8px #29b6f6); } to { filter: drop-shadow(0 0 20px #29b6f6) drop-shadow(0 0 8px #fff); } }

#view {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  font-size: 15px; font-weight: 700; letter-spacing: 1px;
  background: rgba(0,0,0,.45); padding: 7px 16px; border-radius: 20px;
  opacity: 0; transition: opacity .2s; backdrop-filter: blur(4px);
}
#view.show { opacity: 1; }

/* ---------- Overlay ---------- */
#overlay {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #1a2233, #070a10);
}
.panel {
  background: var(--panel); border: 1px solid rgba(255,255,255,.07);
  border-radius: 18px; padding: 34px 40px; width: 420px; max-width: 92vw;
  text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.panel-logo { width: 100%; max-width: 320px; height: auto; display: block; margin: 0 auto 4px; }
.tag { color: #9aa7b5; font-size: 14px; line-height: 1.5; margin: 12px 0 24px; }
.panel label {
  display: block; text-align: left; font-size: 12px; letter-spacing: 1.5px;
  color: #8b98a9; margin: 14px 0 6px;
}
#nameInput {
  width: 100%; padding: 12px 14px; border-radius: 10px; font-size: 16px;
  background: #0d1420; border: 1px solid #263043; color: #fff; outline: none;
}
#nameInput:focus { border-color: var(--accent); }
#cartypes { display: flex; flex-wrap: wrap; gap: 8px; }
.cartype {
  flex: 1 1 auto; padding: 9px 6px; border-radius: 9px; cursor: pointer;
  background: #0d1420; border: 1px solid #263043; color: #cdd7e2;
  font-size: 13px; font-weight: 600; transition: all .12s;
}
.cartype:hover { border-color: #3a475e; color: #fff; }
.cartype.sel { background: var(--accent); border-color: var(--accent); color: #201800; }

#swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  border: 3px solid transparent; transition: transform .1s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.sel { border-color: #fff; }
.swatch.locked { opacity: .28; cursor: not-allowed; position: relative; }
.swatch.locked::after { content: '🔒'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.unlock { color: #6b7686; font-size: 11px; letter-spacing: 0; }
#playBtn {
  width: 100%; margin-top: 26px; padding: 14px; border: 0; border-radius: 12px;
  background: var(--accent); color: #201800; font-size: 18px; font-weight: 800;
  letter-spacing: 1px; cursor: pointer; transition: transform .08s, filter .15s;
}
#playBtn:hover { filter: brightness(1.08); transform: translateY(-1px); }
#playBtn:active { transform: translateY(0); }
.hint { margin-top: 16px; font-size: 12px; color: #6b7686; }

/* Race status — next race countdown shown below online count */
#raceStatus {
  font-size: 12px; font-weight: 700; color: var(--accent);
  opacity: 0.9; margin-bottom: 6px; letter-spacing: .5px;
}

/* Race overlay — full-screen dim for countdown and results */
#raceOverlay {
  position: fixed; inset: 0; z-index: 8;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.74); backdrop-filter: blur(4px);
}
#raceOverlayContent { text-align: center; padding: 32px 40px; }
.race-label {
  font-size: 26px; font-weight: 900; letter-spacing: 4px;
  color: var(--accent); text-shadow: 0 0 24px rgba(255,202,40,.4);
  margin-bottom: 6px;
}
.race-sub { font-size: 13px; color: #8b98a9; letter-spacing: 2px; margin-bottom: 18px; }
.race-count {
  font-size: 110px; font-weight: 900; line-height: 1; color: #fff;
  text-shadow: 0 0 60px rgba(255,202,40,.5);
  animation: racePulse .7s ease-in-out infinite alternate;
}
@keyframes racePulse { from { transform: scale(0.95); } to { transform: scale(1.05); } }
.race-go {
  font-size: 90px; font-weight: 900; color: var(--accent); line-height: 1;
  text-shadow: 0 0 80px rgba(255,202,40,.9);
  animation: raceGo .3s ease-out;
}
@keyframes raceGo { from { transform: scale(1.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.race-results { margin: 14px auto 12px; min-width: 280px; }
.race-result-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 14px; border-radius: 8px; margin: 3px 0;
}
.race-result-me { background: rgba(255,202,40,.14); border: 1px solid rgba(255,202,40,.22); }
.race-pos { font-size: 20px; width: 34px; text-align: center; }
.race-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.race-name { flex: 1; text-align: left; font-size: 15px; font-weight: 600; }
.race-laps { font-size: 12px; color: #8b98a9; }
.race-dismiss { margin-top: 20px; font-size: 13px; color: #6b7686; }

/* Race banner — top-center strip during an active sprint */
#raceBanner {
  position: absolute; top: 58px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.65); border: 1px solid rgba(255,202,40,.3);
  border-radius: 20px; padding: 7px 22px;
  font-size: 14px; font-weight: 800; letter-spacing: 2px; color: var(--accent);
  backdrop-filter: blur(6px); white-space: nowrap;
  box-shadow: 0 4px 22px rgba(0,0,0,.4);
}

#conn {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: #b71c1c; padding: 8px 18px; border-radius: 20px; font-size: 13px;
}
