/* 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; } }
.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; }
#hud-top { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; box-shadow: var(--shadow); }
.hud-cell { display: flex; flex-direction: column; align-items: center; min-width: 66px; }
.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 { background: rgba(10,14,8,.6); border: 1px solid var(--line); border-radius: 10px; width: 160px; height: 160px; }
@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; }

#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; }
#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; }

/* ── 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%; } }
