/* dr — styl klienta. Ciemny motyw, czytelny na telefonie. */
:root {
  --bg: #12160f;
  --bg2: #1b2115;
  --panel: rgba(24, 30, 18, 0.92);
  --panel2: rgba(34, 42, 26, 0.9);
  --line: rgba(255, 255, 255, 0.10);
  --txt: #e8efe0;
  --muted: #9fb08f;
  --accent: #ffd43b;
  --accent2: #7bd83b;
  --danger: #ff5a4d;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--txt);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
.hidden { display: none !important; }
button, input, select { font-family: inherit; }
a { color: var(--accent2); }

/* ── ekrany menu/lobby/wyniki: overlay przewijalny ── */
.screen { position: fixed; inset: 0; overflow-y: auto; display: flex; justify-content: center;
  align-items: flex-start; padding: 24px 16px; background: radial-gradient(120% 90% at 50% -10%, #263019 0%, var(--bg) 60%); }
.menu-wrap, .lobby-wrap, .results-wrap { width: 100%; max-width: 880px; }

.brand { text-align: center; margin: 8px 0 20px; }
.brand h1 { font-size: clamp(30px, 7vw, 52px); margin: 0; letter-spacing: 1px;
  background: linear-gradient(90deg, #ffd43b, #ff8c1a); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand .tag { color: var(--muted); margin: 4px 0 0; }

.nick-row { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 18px; }
.nick-row label { color: var(--muted); font-size: 14px; }
.nick-row input, .field input[type=text], .field input:not([type]), .chat-row input, #chat-input, select {
  background: #0e120a; border: 1px solid var(--line); color: var(--txt); border-radius: 8px;
  padding: 9px 12px; font-size: 15px; outline: none; }
.nick-row input:focus, select:focus, .chat-row input:focus { border-color: var(--accent); }

.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .cols { grid-template-columns: 1fr; } }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head h3 { margin: 0; font-size: 15px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }

.list { display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow-y: auto; margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 8px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 9px; padding: 9px 11px; }
.row-main { font-weight: 600; flex: 0 0 auto; }
.row-sub { color: var(--muted); font-size: 13px; margin-left: auto; margin-right: 8px; }
.row-sub.ok { color: var(--accent2); }
.row.player .row-sub { margin-right: 0; }
.empty { color: var(--muted); font-size: 14px; padding: 14px; text-align: center; }
.car-dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.5); vertical-align: middle; margin-right: 6px; }

.btn { background: #2a3420; color: var(--txt); border: 1px solid var(--line); border-radius: 9px;
  padding: 11px 16px; font-size: 15px; font-weight: 600; cursor: pointer; transition: filter .12s, transform .05s; width: 100%; }
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(180deg, #ffd43b, #f0a800); color: #201800; border: none; }
.btn-ghost { background: transparent; }
.btn-sm { width: auto; padding: 7px 13px; font-size: 14px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.actions .btn { width: auto; flex: 1; min-width: 120px; }
.mini-btn { background: #222a18; color: var(--txt); border: 1px solid var(--line); border-radius: 7px;
  width: 34px; height: 34px; font-size: 16px; cursor: pointer; }
.mini-btn:hover { filter: brightness(1.2); }

.field { margin: 10px 0; }
.field > label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.field.inline { display: flex; align-items: center; gap: 12px; }
.field.inline label { margin: 0; }
.field input[type=range] { flex: 1; accent-color: var(--accent); }

.track-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; max-height: 300px; overflow-y: auto; }
.track-cell { border: 2px solid transparent; border-radius: 9px; overflow: hidden; cursor: pointer; background: #0e120a; }
.track-cell canvas { width: 100%; height: auto; display: block; }
.track-cell .track-name { display: block; font-size: 12px; padding: 5px 6px; color: var(--muted); }
.track-cell.sel { border-color: var(--accent); }
.track-cell.sel .track-name { color: var(--accent); }

.menu-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 14px; color: var(--muted); font-size: 12px; }
.more-games { font-weight: 600; }

/* ── lobby ── */
.lobby-head { text-align: center; margin-bottom: 14px; }
.lobby-head h2 { margin: 0; }
.lobby-sub { color: var(--muted); font-size: 14px; }
.lobby-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 640px) { .lobby-cols { grid-template-columns: 1fr; } }

/* wybór koloru auta — siatka 12 swatchy z miniaturami sprite'ów */
.color-card { margin-bottom: 16px; }
.color-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 8px; }
.swatch { display: flex; align-items: center; justify-content: center; background: #0e120a; border: 2px solid var(--line);
  border-radius: 9px; padding: 5px; cursor: pointer; transition: border-color .12s, transform .05s; }
.swatch canvas { display: block; width: 48px; height: 28px; }
.swatch:hover:not(.taken):not(.mine) { border-color: rgba(255,255,255,.35); }
.swatch:active:not(.taken) { transform: translateY(1px); }
.swatch.mine { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,212,59,.35) inset; }
.swatch.taken { opacity: .32; cursor: not-allowed; filter: grayscale(.6); }
.chatbox { background: #0e120a; border: 1px solid var(--line); border-radius: 8px; height: 160px;
  overflow-y: auto; padding: 8px; font-size: 14px; margin-bottom: 8px; }
.chat-row input { width: 100%; }
.chat-line { margin: 2px 0; word-break: break-word; }

/* ── HUD ── */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
/* yorg: HUD jak w oryginale — pionowa kolumna wartości po PRAWEJ (speed/lap/time/
   best/ranking/damages/weapon), minimapa w PRAWYM-DOLNYM rogu (patrz .selfcheck/ref). */
#hud-top { position: absolute; top: 128px; right: 12px; left: auto; transform: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; box-shadow: var(--shadow); }
.hud-cell { display: flex; flex-direction: row; align-items: baseline; gap: 8px; min-width: 0; }
.hud-cell .hud-lbl { order: -1; }
.hud-lbl { font-size: 10px; letter-spacing: 1px; color: var(--muted); }
.hud-cell span:last-child { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
#hud-right { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
#minimap { position: fixed; right: 12px; bottom: 12px; background: rgba(10,14,8,.45); border: 1px solid var(--line); border-radius: 10px; width: 170px; height: 170px; }
@media (max-width: 640px) { #minimap { width: 110px; height: 110px; } }
#h-speed { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 12px; }
#h-speed #h-kmh { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
#h-speed .unit { font-size: 12px; color: var(--muted); margin-left: 4px; }
.bar-wrap { display: flex; align-items: center; gap: 6px; width: 160px; }
.bar-lbl { font-size: 11px; color: var(--muted); width: 40px; text-align: right; }
.bar { flex: 1; height: 9px; background: #0e120a; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; transition: width .2s; }
.bar-fill.dmg { background: linear-gradient(90deg, #7bd83b, #ffd43b 55%, #ff5a4d); }
.bar-fill.wear { background: linear-gradient(90deg, #4db3ff, #ffd43b 60%, #ff8c1a); }
#btn-mute { align-self: flex-end; }

/* Czat głosowy (voicehud.js): panel przenośny domyślnie w prawym-górnym rogu, ale
   tam dr trzyma minimapę/prędkość/mute (#hud-right). Przenosimy go w LEWY-górny
   róg, poniżej dotykowego przycisku pełnego ekranu (top:12/46px), by nie zasłaniać
   toru ani sterowania (strefy dotyku zajmują dolne 62% ekranu). */
.vc-panel { left: 10px; right: auto; top: 64px; align-items: flex-start; z-index: 14; }

#msg-center { position: absolute; top: 22%; left: 50%; transform: translateX(-50%); font-size: clamp(20px, 4vw, 34px);
  font-weight: 800; color: var(--accent); text-shadow: 0 2px 12px rgba(0,0,0,.8); white-space: nowrap; }
#countdown { position: absolute; top: 38%; left: 50%; transform: translate(-50%,-50%); font-size: clamp(70px, 20vw, 180px);
  font-weight: 900; color: #fff; text-shadow: 0 4px 30px rgba(0,0,0,.9), 0 0 30px var(--accent); }
.pop { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: translate(-50%,-50%) scale(.4); opacity: 0; } 60% { transform: translate(-50%,-50%) scale(1.15); opacity: 1; } 100% { transform: translate(-50%,-50%) scale(1); } }
#msg-center.pop { animation: popx .35s ease-out; }
@keyframes popx { 0% { transform: translateX(-50%) scale(.4); opacity: 0; } 60% { transform: translateX(-50%) scale(1.12); } 100% { transform: translateX(-50%) scale(1); } }

#chat-log { position: absolute; left: 12px; bottom: 60px; max-width: 46%; display: flex; flex-direction: column; gap: 2px;
  font-size: 14px; text-shadow: 0 1px 3px rgba(0,0,0,.9); }
#chat-log .chat-line { background: rgba(10,14,8,.45); border-radius: 6px; padding: 2px 7px; transition: opacity .5s; }
#chat-log .chat-line.fade { opacity: 0; }
#chat-input-wrap { position: absolute; left: 12px; bottom: 18px; width: min(420px, 70%); }
#chat-input { width: 100%; }

/* ── wyniki ── */
.results-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.results-wrap h2 { text-align: center; margin: 0 0 14px; }
table.results { width: 100%; border-collapse: collapse; }
table.results th, table.results td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
table.results th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
table.results td.pos { font-weight: 800; color: var(--accent); width: 40px; }

/* ── pauza / toast ── */
.overlay { position: fixed; inset: 0; background: rgba(6,8,5,.7); display: flex; align-items: center; justify-content: center; z-index: 20; }
.overlay .panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; width: min(320px, 90%); box-shadow: var(--shadow); }
.overlay .panel h2 { margin: 0 0 16px; text-align: center; }
.overlay .panel .btn { margin-bottom: 10px; }
/* legenda sterowania (panel pauzy) */
.controls-help { margin: 0 0 18px; display: flex; flex-direction: column; gap: 7px; }
.controls-help .ch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.controls-help .lbl { color: var(--muted); }
.controls-help kbd { display: inline-block; min-width: 16px; padding: 2px 5px; margin: 0 1px; text-align: center;
  background: #2a3420; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
  font: 600 12px/1.2 system-ui, sans-serif; color: var(--txt); }
#toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line);
  color: var(--txt); padding: 11px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 30; max-width: 90%; font-size: 14px; }

/* baner offline — widoczny w menu i w grze gdy WS nie jest OPEN */
#offline-banner { position: fixed; top: 0; left: 0; right: 0; z-index: 90; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--danger); color: #2a0a06; font-size: 13px; font-weight: 700; letter-spacing: .3px; padding: 6px 12px; box-shadow: 0 2px 10px rgba(0,0,0,.4); }
#offline-banner .off-dot { width: 8px; height: 8px; border-radius: 50%; background: #2a0a06; animation: livepulse 1.2s ease-in-out infinite; }

/* pełny ekran — przycisk ⛶ (HUD obok 🔊 + róg menu) */
.btn-fullscreen.active { background: var(--accent); color: #201800; border-color: var(--accent); }
#btn-fs-menu.fs-corner { position: fixed; top: 12px; right: 12px; z-index: 50; }
/* na telefonie nakładka dotykowa ma własny ⛶ — ukryj ten w HUD, by się nie dublowały */
body.dr-touch-race #btn-fullscreen { display: none; }

/* ── pasek repleja ── */
#replaybar { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 7px 10px; box-shadow: var(--shadow); width: min(560px, 94%); }
#replaybar .speeds { display: flex; gap: 3px; }
#replaybar .spd { background: #222a18; border: 1px solid var(--line); color: var(--muted); border-radius: 6px; padding: 4px 7px; font-size: 12px; cursor: pointer; }
#replaybar .spd.on { background: var(--accent); color: #201800; border-color: var(--accent); font-weight: 700; }
#replaybar .seek { flex: 1; accent-color: var(--accent); cursor: pointer; }
#replaybar .rp-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 78px; text-align: center; }

/* podgląd na żywo (id trwającego wyścigu) — zamiast paska kontrolek */
#live-indicator { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 8px 6px 14px; box-shadow: var(--shadow);
  font-size: 13px; font-weight: 700; letter-spacing: .5px; color: var(--txt); }
#live-indicator .live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); animation: livepulse 1.6s ease-in-out infinite; }

/* obserwowane auto (replay/widz) */
#watching { position: absolute; top: 62px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 600;
  color: var(--txt); box-shadow: var(--shadow); white-space: nowrap; }
#watching .eye { opacity: .8; }
#watching .car-dot { margin: 0; width: 12px; height: 12px; }
#hud.replay-mode .race-only { display: none; }   /* CZAS/NAJLEPSZE tylko w wyścigu */
/* plakietka NA ŻYWO na liście replayów */
.live-badge { display: inline-block; margin-left: 8px; font-size: 10px; font-weight: 700; letter-spacing: .5px;
  color: #201800; background: var(--danger); border-radius: 5px; padding: 1px 6px; vertical-align: middle;
  animation: livepulse 1.6s ease-in-out infinite; }
@keyframes livepulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

/* ── fps / loading ── */
#fps { position: fixed; left: 8px; top: 8px; background: rgba(0,0,0,.5); color: #7bd83b; font: 12px monospace; padding: 2px 6px; border-radius: 5px; z-index: 40; }
#loading { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 100; transition: opacity .4s; }
#loading.gone { opacity: 0; pointer-events: none; }
#loading-title { font-size: 34px; font-weight: 800; color: var(--accent); }
#loading-label { color: var(--muted); }
#loading-bar { width: 200px; height: 6px; background: #0e120a; border-radius: 4px; overflow: hidden; }
#loading-fill { height: 100%; width: 40%; background: var(--accent); animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

/* ── tryby v2: przełączniki, chipy, rekordy, głosowanie, mistrzostwa ── */
.mods-panel { display: flex; flex-direction: column; gap: 6px; }
.mod-row { display: flex; align-items: center; gap: 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; }
.mod-row.on { border-color: rgba(255,212,59,.4); }
.mod-txt { flex: 1; display: flex; flex-direction: column; }
.mod-txt b { font-size: 14px; }
.mod-txt small { color: var(--muted); font-size: 12px; }
.toggle { width: 42px; height: 24px; border-radius: 999px; background: #0e120a; border: 1px solid var(--line); position: relative; cursor: pointer; flex: 0 0 auto; transition: background .15s; }
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: left .15s, background .15s; }
.toggle.on { background: var(--accent); }
.toggle.on::after { left: 20px; background: #201800; }
.toggle:disabled { opacity: .6; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: 0 0 auto; }
.seg-btn { background: #0e120a; color: var(--muted); border: none; padding: 5px 11px; font-size: 13px; font-weight: 600; cursor: pointer; border-left: 1px solid var(--line); }
.seg-btn:first-child { border-left: none; }
.seg-btn.on { background: var(--accent); color: #201800; }
.seg-btn:disabled { cursor: default; }
.mods-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; justify-content: center; }
.chip { background: var(--panel2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 12px; color: var(--txt); }

.record-row .rec-time { font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; margin-left: auto; margin-right: 10px; }
.record-row .row-sub { margin-left: 0; }
.rec-acts { display: flex; gap: 4px; }

.champ-tbl { width: 100%; border-collapse: collapse; }
.champ-tbl th, .champ-tbl td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
.champ-tbl th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.champ-tbl td.pos { width: 34px; color: var(--muted); font-weight: 700; }
.champ-tbl td.pts { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.champ-tbl tr.human { background: rgba(255,212,59,.08); }
.champ-tbl tr.human td { color: var(--txt); font-weight: 600; }

/* głosowanie na tor */
.vote-panel { width: min(640px, 94%); text-align: center; }
.vote-panel h2 { margin: 0 0 4px; }
.vote-timer { color: var(--accent); font-weight: 800; font-size: 20px; margin-bottom: 12px; font-variant-numeric: tabular-nums; }
.vote-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 560px) { .vote-tiles { grid-template-columns: 1fr; } }
.vote-tile { background: #0e120a; border: 2px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; transition: border-color .12s, transform .05s; }
.vote-tile:hover { border-color: rgba(255,255,255,.3); }
.vote-tile:active { transform: translateY(1px); }
.vote-tile.voted { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(255,212,59,.3) inset; }
.vote-tile canvas { width: 100%; height: auto; display: block; border-radius: 6px; }
.vote-tile .vote-name { display: block; font-weight: 700; margin: 6px 0 2px; }
.vote-tile .vote-tally { display: block; color: var(--muted); font-size: 13px; }

/* podium mistrzostw + konfetti */
.podium-panel { width: min(560px, 94%); text-align: center; position: relative; overflow: hidden; }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin: 18px 0; }
.pod-block { display: flex; flex-direction: column; align-items: center; gap: 3px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px 10px 0 0; padding: 12px 14px 8px; width: 110px; position: relative; }
.pod-block .car-dot { width: 20px; height: 20px; }
.pod-block b { font-size: 14px; }
.pod-block .pod-pts { color: var(--muted); font-size: 12px; }
.pod-block .pod-rank { position: absolute; top: -14px; font-size: 22px; font-weight: 900; color: var(--accent); }
.pod-1 { height: 130px; background: linear-gradient(180deg, rgba(255,212,59,.25), var(--panel2)); }
.pod-2 { height: 104px; }
.pod-3 { height: 88px; }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 12px; border-radius: 2px; animation: confetti-fall linear infinite; }
@keyframes confetti-fall { 0% { transform: translateY(-20px) rotate(0); opacity: 1; } 100% { transform: translateY(560px) rotate(540deg); opacity: .3; } }

.opt-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin: 4px 0 12px; cursor: pointer; }
.opt-row input { accent-color: var(--accent); }
