:root {
  --bg: #0d1017;
  --panel: rgba(16, 20, 30, 0.86);
  --panel-solid: #141926;
  --line: rgba(255, 255, 255, 0.1);
  --text: #eef2f8;
  --muted: #95a0b4;
  --accent: #ff3b5c;
  --accent2: #ffb020;
  --good: #3ddc84;
  --radius: 14px;
  --display: 'Russo One', 'Arial Black', system-ui, sans-serif;
  --ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--ui); }
body { overflow: hidden; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }

button {
  font: 600 14px var(--ui);
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
button:hover { background: rgba(255, 255, 255, 0.16); }
button:active { transform: translateY(1px); }
button.primary { background: linear-gradient(180deg, #ff5470, #e52648); border-color: #ff7088; color: #fff; }
button.primary:hover { background: linear-gradient(180deg, #ff6a83, #f0335a); }
button.primary:disabled { opacity: 0.5; cursor: default; }
button.big { width: 100%; padding: 12px; font-size: 16px; margin-top: 8px; }
button.danger { background: rgba(229, 38, 72, 0.25); border-color: rgba(229, 38, 72, 0.5); }
button.ghost { background: transparent; border: none; font-size: 20px; padding: 0 8px; }

input, select {
  width: 100%;
  font: 500 14px var(--ui);
  color: var(--text);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 11px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
select option { background: var(--panel-solid); }
input:disabled, select:disabled { opacity: 0.6; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.04em; }
.field { margin-bottom: 12px; flex: 1; }
.row { display: flex; gap: 10px; }
.pill { font: 600 11px var(--ui); background: rgba(255, 255, 255, 0.1); padding: 3px 8px; border-radius: 99px; color: var(--muted); vertical-align: middle; }
kbd { font: 600 11px var(--ui); background: rgba(255, 255, 255, 0.12); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; margin-right: 3px; }
h2 { font: 400 20px var(--display); margin: 0 0 12px; letter-spacing: 0.02em; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 16px 0 8px; }

/* ------------------------------------------------------------- home */
.screen { position: fixed; inset: 0; }
#home { overflow-y: auto; }
.home-bg {
  position: fixed; inset: 0;
  background: linear-gradient(180deg, rgba(10, 12, 20, 0.55), rgba(10, 12, 20, 0.92)), url('assets/images/menu-bg.jpg') center / cover;
  filter: saturate(1.1);
}
.home-wrap { position: relative; max-width: 1040px; margin: 0 auto; padding: 32px 16px 48px; }
.brand { text-align: center; margin-bottom: 24px; }
.brand h1 { font: 400 clamp(48px, 9vw, 92px) var(--display); margin: 0; letter-spacing: 0.04em; font-style: italic; text-shadow: 0 6px 30px rgba(255, 59, 92, 0.45); }
.brand h1 span { color: var(--accent); }
.brand p { margin: 4px 0 0; color: #cdd5e3; font-size: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; backdrop-filter: blur(10px); margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.profile { display: flex; gap: 20px; align-items: flex-end; flex-wrap: wrap; }
.profile .field { min-width: 200px; margin-bottom: 0; }
#carPreview { width: 132px; height: 78px; }
.swatches { display: flex; gap: 7px; flex-wrap: wrap; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.sel { border-color: #fff; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25); }
.home-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.home-cols .card { margin-bottom: 0; }
@media (max-width: 760px) { .home-cols { grid-template-columns: 1fr; } }
.room-list { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.room { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 11px; }
.room .info { flex: 1; min-width: 0; }
.room .name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room .meta { font-size: 12px; color: var(--muted); }
.room .theme-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.invite { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; margin-bottom: 10px; border-radius: 11px; background: rgba(255, 176, 32, 0.15); border: 1px solid rgba(255, 176, 32, 0.4); }
.track-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-bottom: 12px; }
.track-card { padding: 6px; border-radius: 10px; border: 2px solid var(--line); background: rgba(0, 0, 0, 0.3); cursor: pointer; text-align: center; }
.track-card.sel { border-color: var(--accent); background: rgba(255, 59, 92, 0.12); }
.track-card canvas { width: 100%; height: auto; display: block; }
.track-card span { font-size: 12px; font-weight: 600; }
.controls-help { display: flex; flex-wrap: wrap; gap: 8px 22px; justify-content: center; font-size: 13px; color: #cdd5e3; margin-top: 16px; }

/* ------------------------------------------------------------- game */
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; pointer-events: none; }
#topbar > * { pointer-events: auto; }
.room-title { font: 400 16px var(--display); text-shadow: 0 2px 6px #000; }
.top-actions { display: flex; gap: 6px; }
.top-actions button { background: rgba(10, 12, 20, 0.7); padding: 7px 11px; }
.top-actions button.off { opacity: 0.45; }

.hud { position: absolute; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(6px); }
#hudLeft { top: 56px; left: 14px; padding: 10px 14px; min-width: 170px; }
.hud-pos { font: 400 44px/1 var(--display); margin-bottom: 6px; }
.hud-pos small { font-size: 18px; color: var(--muted); margin-left: 4px; }
.hud-row { display: flex; justify-content: space-between; gap: 14px; font-size: 14px; }
.hud-row label { margin: 0; font-size: 11px; line-height: 20px; }
.hud-row b { font-variant-numeric: tabular-nums; }
#leaderboard { top: 56px; right: 14px; margin: 0; padding: 8px 10px; list-style: none; min-width: 190px; max-width: 240px; font-size: 13px; }
#leaderboard li { display: flex; align-items: center; gap: 7px; padding: 2px 0; white-space: nowrap; }
#leaderboard li .p { width: 22px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
#leaderboard li .d { width: 9px; height: 9px; border-radius: 50%; flex: none; }
#leaderboard li .n { overflow: hidden; text-overflow: ellipsis; flex: 1; }
#leaderboard li .l { color: var(--muted); font-size: 11px; }
#leaderboard li.me { color: var(--accent2); font-weight: 800; }
#leaderboard li.gap { color: var(--muted); justify-content: center; }
#speedo { right: 228px; bottom: 16px; padding: 8px 14px; text-align: right; }
#speedo b { font: 400 34px var(--display); font-variant-numeric: tabular-nums; }
#speedo small { display: block; color: var(--muted); font-size: 11px; margin-top: -4px; }
#minimap { position: absolute; right: 14px; bottom: 14px; width: 200px; height: 200px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }

#banner { position: absolute; top: 30%; left: 0; right: 0; text-align: center; font: 400 clamp(36px, 8vw, 96px) var(--display); text-shadow: 0 6px 24px rgba(0, 0, 0, 0.8); pointer-events: none; opacity: 0; transition: opacity 0.2s, transform 0.2s; }
#banner.show { opacity: 1; }
#banner.go { color: var(--good); }
#banner small { display: block; font: 600 clamp(14px, 2.4vw, 22px) var(--ui); margin-top: 8px; color: #fff; }
#toast { position: absolute; top: 64px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 16px; font-weight: 600; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
#toast.show { opacity: 1; }

.panel { position: absolute; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); backdrop-filter: blur(10px); }
#lobbyPanel { top: 56px; right: 14px; width: 310px; max-height: calc(100% - 290px); display: flex; flex-direction: column; }
#lobbyPanel.collapsed .panel-body { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px 0; }
.panel-head h2 { margin: 0; }
.panel-body { padding: 4px 16px 16px; overflow-y: auto; }
.player-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; max-height: 160px; overflow-y: auto; }
.player-list li { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.player-list .d { width: 10px; height: 10px; border-radius: 50%; }
.player-list .tag { font-size: 11px; color: var(--accent2); }

#results { top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100% - 32px)); max-height: 80%; padding: 20px; display: flex; flex-direction: column; }
#results h2 { font-size: 30px; margin-bottom: 2px; }
.results-scroll { overflow-y: auto; margin: 10px 0; }
#results table { width: 100%; border-collapse: collapse; font-size: 14px; }
#results th { text-align: left; font-size: 11px; color: var(--muted); text-transform: uppercase; padding: 4px 6px; }
#results td { padding: 6px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
#results tr.me td { color: var(--accent2); font-weight: 800; }
#results tr:nth-child(1) td:first-child { color: #ffd54a; }
#results tr:nth-child(2) td:first-child { color: #cfd8e3; }
#results tr:nth-child(3) td:first-child { color: #e09a5a; }
#results .d { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }

#chat { position: absolute; left: 14px; bottom: 14px; width: min(380px, calc(100% - 260px)); pointer-events: none; }
#chatLog { display: flex; flex-direction: column; gap: 2px; max-height: 180px; overflow: hidden; justify-content: flex-end; font-size: 13px; text-shadow: 0 1px 3px #000; }
#chatLog div { background: rgba(0, 0, 0, 0.35); padding: 2px 8px; border-radius: 6px; align-self: flex-start; transition: opacity 1s; }
#chatLog div.old { opacity: 0; }
#chatLog .sys { color: var(--accent2); }
#chatInput { margin-top: 6px; pointer-events: auto; }

#touch { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; padding: 12px; pointer-events: none; }
#touch button { pointer-events: auto; width: 74px; height: 74px; border-radius: 50%; font-size: 20px; background: rgba(255, 255, 255, 0.14); user-select: none; -webkit-user-select: none; touch-action: none; }
#touch button.gas { background: rgba(61, 220, 132, 0.3); width: 88px; height: 88px; }
#touch button.small-btn { font-size: 12px; width: 60px; height: 60px; align-self: flex-end; }
.touch-left, .touch-right { display: flex; gap: 12px; align-items: flex-end; }
body.touch #minimap { width: 130px; height: 130px; top: 56px; bottom: auto; }
body.touch #speedo { right: auto; left: 50%; transform: translateX(-50%); bottom: 20px; }
body.touch #chat { display: none; }
body.touch #leaderboard { top: 196px; }

@media (max-width: 760px) {
  #lobbyPanel { left: 14px; right: 14px; width: auto; top: 52px; max-height: calc(100% - 180px); }
  #leaderboard { display: none; }
  #hudLeft { min-width: 0; padding: 8px 10px; }
  .hud-pos { font-size: 32px; }
  #speedo { right: 150px; }
  #minimap { width: 130px; height: 130px; }
  .room-title { font-size: 13px; }
}
