:root {
  --bg: #0f1115; --panel: #181b22; --panel2: #20242e; --text: #e8e8ea; --muted: #9aa0ab;
  --red: #e10600; --red2: #ff2a22; --line: #2c313c;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
body { display: flex; flex-direction: column; min-height: 100vh; overflow: hidden; }
main { flex: 1; position: relative; min-height: 0; }
.hidden { display: none !important; }

#top { display: flex; align-items: center; gap: 24px; padding: 8px 16px; background: var(--panel); border-bottom: 2px solid var(--red); flex-wrap: wrap; }
.logo { font-weight: 900; font-size: 22px; letter-spacing: 2px; font-style: normal; }
.logo span { color: var(--red); }
.room b { font-family: ui-monospace, Menlo, monospace; letter-spacing: 2px; }
.share code { font-family: ui-monospace, Menlo, monospace; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #d33; margin-left: 6px; }
.dot.on { background: #3ad13a; }

.panel { display: grid; grid-template-columns: 1fr 1.2fr; gap: 24px; padding: 20px; max-width: 1200px; margin: 0 auto; height: 100%; overflow: auto; }
.col { background: var(--panel); border-radius: 12px; padding: 16px 20px; }
h2 { margin: 6px 0 12px; font-size: 18px; text-transform: uppercase; letter-spacing: 1px; border-left: 4px solid var(--red); padding-left: 10px; }
h3 { margin: 18px 0 8px; font-size: 15px; color: var(--muted); }
small { color: var(--muted); font-weight: normal; }
.label { color: var(--muted); margin: 10px 0 6px; }
.row { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
label.row { justify-content: space-between; }
input, select { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; font-size: 15px; }
input[type=number] { width: 70px; }
button { background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 16px; font-size: 15px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 700; }
button.primary:hover { background: var(--red2); }
button.primary:disabled { opacity: .4; cursor: default; }
button.big { width: 100%; font-size: 20px; padding: 14px; margin: 12px 0; letter-spacing: 2px; }
button.small { padding: 5px 10px; font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }
.help { color: var(--muted); font-size: 13px; margin-top: 10px; line-height: 1.6; }

.teams { display: flex; flex-wrap: wrap; gap: 6px; }
.team { padding: 5px 10px; border-radius: 20px; border: 2px solid transparent; cursor: pointer; font-size: 13px; font-weight: 700; opacity: .75; }
.team.sel { border-color: #fff; opacity: 1; }

.players { list-style: none; padding: 0; margin: 0; }
.players li { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.swatch { width: 14px; height: 14px; border-radius: 3px; flex: none; }
.players .nm { flex: 1; font-weight: 600; }
.badge { font-size: 12px; color: var(--muted); background: var(--panel2); padding: 2px 8px; border-radius: 10px; }
.badge.me { color: #fff; background: #2d4f8a; }

.tracks { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.track { background: var(--panel2); border: 2px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; text-align: center; }
.track.sel { border-color: var(--red); }
.track canvas { width: 100%; aspect-ratio: 16 / 9; display: block; border-radius: 6px; background: #1e4d22; }
.track .tn { margin-top: 6px; font-size: 13px; font-weight: 600; }

.results { margin: 12px 0; background: var(--panel2); border-radius: 10px; padding: 10px 14px; }
.results table { width: 100%; border-collapse: collapse; font-size: 14px; }
.results th { text-align: left; color: var(--muted); font-weight: 600; padding: 4px 6px; }
.results td { padding: 5px 6px; border-top: 1px solid var(--line); }
.results td.num, .results th.num { text-align: right; font-family: ui-monospace, Menlo, monospace; }

.tune label { display: grid; grid-template-columns: 130px 1fr 50px; align-items: center; gap: 10px; margin: 6px 0; }
.tune input[type=range] { width: 100%; accent-color: var(--red); }
.tune b { font-family: ui-monospace, Menlo, monospace; text-align: right; }

/* wyścig */
#race { position: absolute; inset: 0; background: #1e4d22; }
#race-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#hud { position: absolute; inset: 0; pointer-events: none; }
.standings { position: absolute; left: 10px; top: 10px; width: 230px; background: rgba(10,12,16,.82); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.standings .r { display: flex; align-items: center; gap: 6px; padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.standings .pos { width: 18px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }
.standings .nm { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.standings .r.me .nm { color: #ffd84a; font-weight: 700; }
.standings .lap { font-family: ui-monospace, Menlo, monospace; color: var(--muted); }
.standings .lap.fin { color: #3ad13a; font-weight: 700; }
.standings .title { font-weight: 800; letter-spacing: 1px; margin-bottom: 4px; }
.lights { position: absolute; top: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; background: #111; padding: 12px 16px; border-radius: 12px; align-items: center; }
.lights span { width: 34px; height: 34px; border-radius: 50%; background: #3a1010; box-shadow: inset 0 0 6px #000; }
.lights span.on { background: #ff1a1a; box-shadow: 0 0 18px #ff2a2a; }
.lights #lights-text { font-weight: 900; font-size: 28px; color: #3ad13a; margin-left: 8px; letter-spacing: 3px; }
.toasts { position: absolute; bottom: 90px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; }
.toast { background: rgba(10,12,16,.85); padding: 6px 14px; border-radius: 8px; font-weight: 600; animation: fade 3.2s forwards; border-left: 4px solid var(--red); }
@keyframes fade { 0% { opacity: 0; transform: translateY(8px);} 10% { opacity: 1; transform: none;} 80% { opacity: 1;} 100% { opacity: 0;} }
.own-hud { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 10px; }
.own { background: rgba(10,12,16,.82); border-radius: 10px; padding: 8px 12px; min-width: 150px; border-top: 4px solid #fff; }
.own .nm { font-weight: 700; }
.own .spd { font-family: ui-monospace, Menlo, monospace; font-size: 24px; font-weight: 700; }
.own .sm { color: var(--muted); font-size: 12px; }
.race-buttons { position: absolute; right: 10px; top: 10px; pointer-events: auto; display: flex; gap: 6px; }
.race-buttons button { background: rgba(10,12,16,.82); }
.race-buttons #vol { width: 70px; align-self: center; accent-color: #e8b923; }

/* edytor */
#editor { position: absolute; inset: 0; background: #1e4d22; }
#editor-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
#editor-ui { position: absolute; left: 10px; top: 10px; right: 10px; background: rgba(10,12,16,.88); border-radius: 10px; padding: 10px 14px; font-size: 14px; }
#editor-ui .status { color: #ffd84a; min-height: 18px; }
#editor-ui input[type=range] { width: 160px; vertical-align: middle; }

@media (max-width: 900px) { .panel { grid-template-columns: 1fr; } }

/* pad dotykowy */
.touchpad { position: absolute; inset: 0; display: flex; gap: 6px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.tp-side { flex: 1; display: flex; }
/* kierownica-suwak: wysoki panel (cała wysokość kolumny GAZ/HAMULEC, łatwo trafić kciukiem) z paskiem i gałką w środku;
   liczy się tylko pozycja palca w poziomie, po puszczeniu gałka wraca na środek */
.tp-wheel { position: absolute; left: 6px; top: 6px; bottom: 6px; width: 23%; padding: 0 10px; border-radius: 18px; background: rgba(255,255,255,.08); border: 2px solid rgba(255,255,255,.35); display: flex; align-items: center; }
.tp-wheel::before { content: ''; position: absolute; left: 50%; top: 10px; bottom: 10px; width: 2px; margin-left: -1px; background: rgba(255,255,255,.18); }
.tp-wheel.on { border-color: rgba(255,255,255,.75); }
.tp-wheel-bar { position: relative; width: 100%; height: 46px; border-radius: 23px; background: rgba(0,0,0,.35); border: 2px solid rgba(255,255,255,.45); }
.tp-wheel-bar::before { content: ''; position: absolute; left: 50%; top: 8px; bottom: 8px; width: 2px; margin-left: -1px; background: rgba(255,255,255,.5); }
.tp-wheel-bar::after { content: '◀                    ▶'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; color: rgba(255,255,255,.5); font-size: 16px; white-space: pre; }
.tp-knob { position: absolute; top: 50%; left: 50%; width: 66px; height: 66px; margin: -33px 0 0 -33px; border-radius: 50%; background: rgba(255,255,255,.88); color: #111;
  font-weight: 800; font-size: 24px; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.5); transition: left .06s linear; z-index: 1; }
.tp-wheel.on .tp-knob { background: #ffd84a; }
.tp-btn { flex: 1; margin: 6px; border-radius: 18px; background: rgba(255,255,255,.10); border: 2px solid rgba(255,255,255,.35);
  display: flex; align-items: center; justify-content: center; font-size: 44px; font-weight: 900; color: #fff; letter-spacing: 2px; }
.tp-btn.on { background: rgba(255,255,255,.4); transform: scale(.97); }
.tp-gas { background: rgba(58,209,58,.25); border-color: #3ad13a; flex: 1.4; }
.tp-brake { background: rgba(225,6,0,.25); border-color: #e10600; font-size: 28px; }
.tp-gas.on { background: rgba(58,209,58,.6); }
.tp-brake.on { background: rgba(225,6,0,.6); }
#race-touch { pointer-events: auto; opacity: .8; top: 46px; }
#race-touch .tp-right { flex: 0 0 22%; }
#race-touch .tp-mid { flex: 1; pointer-events: none; }
#race-touch .tp-btn { font-size: 30px; background: rgba(0,0,0,.22); }
#race-touch .tp-wheel { background: rgba(0,0,0,.22); }
#race-touch .tp-gas { background: rgba(58,209,58,.28); }
#race-touch .tp-brake { background: rgba(225,6,0,.28); }
#race-touch .tp-btn.on { background: rgba(255,255,255,.45); }
.tp-mid { flex: 0; }
.tp-right { flex-direction: column-reverse; }

/* QR w lobby */
.padbox { margin-top: 16px; background: var(--panel2); border-radius: 10px; padding: 10px 14px; display: flex; gap: 14px; align-items: center; }
.padbox svg { width: 132px; height: 132px; background: #fff; border-radius: 6px; padding: 4px; flex: none; }
.padbox .pu { font-family: ui-monospace, Menlo, monospace; font-size: 14px; word-break: break-all; }

@media (max-width: 900px) {
  .standings { width: 128px; font-size: 10px; padding: 4px 6px; top: 6px; left: 6px; }
  .standings .title { display: none; }
  .standings .r { padding: 2px 0; gap: 4px; }
  .own-hud { left: auto; right: 6px; top: 40px; bottom: auto; }
  .own { min-width: 0; padding: 3px 8px; border-top-width: 3px; }
  .own .nm { font-size: 11px; }
  .own .spd { font-size: 15px; }
  .own .sm { display: none; }
  .race-buttons { top: 6px; right: 6px; }
  .race-buttons button { padding: 4px 8px; font-size: 12px; }
  .race-buttons #vol { width: 54px; }
  .lights { top: 6px; padding: 6px 10px; gap: 6px; }
  .lights span { width: 18px; height: 18px; }
  .lights #lights-text { font-size: 16px; }
  .toasts { bottom: 16px; }
  .toast { font-size: 12px; padding: 4px 10px; }
  #top { gap: 10px; padding: 6px 10px; }
  body.racing #top { display: none; }
  #race-touch { top: 96px; }
  .share { display: none; }
  .panel { padding: 10px; gap: 12px; }
}

/* na dotyku (body.touch) ten sam układ HUD niezależnie od szerokości ekranu – na szerokich telefonach (>900 px)
   lista pozycji i własny HUD nie mogą leżeć pod panelem kierownicy ani pod GAZ/HAMULEC */
body.touch .standings { width: 128px; font-size: 10px; padding: 4px 6px; top: 6px; left: 6px; }
body.touch .standings .title { display: none; }
body.touch .standings .r { padding: 2px 0; gap: 4px; }
body.touch .own-hud { left: auto; right: 6px; top: 40px; bottom: auto; }
body.touch .own { min-width: 0; padding: 3px 8px; border-top-width: 3px; }
body.touch .own .nm { font-size: 11px; }
body.touch .own .spd { font-size: 15px; }
body.touch .own .sm { display: none; }
body.touch .race-buttons { top: 6px; right: 6px; }
body.touch .race-buttons button { padding: 4px 8px; font-size: 12px; }
body.touch .race-buttons #vol { width: 54px; }
body.touch #race-touch { top: 96px; }
body.touch.racing #top { display: none; }

/* chipy: sektory, DRS, flagi okrążeń */
.chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 8px; margin-left: 4px; vertical-align: middle; font-family: ui-monospace, Menlo, monospace; }
.chip.purple { background: #8b3dff; color: #fff; }
.chip.green { background: #22a84a; color: #fff; }
.chip.yellow { background: #e0b400; color: #000; }
.chip.drs { background: #7fe3ff; color: #063a4a; }
.toast.purple { border-left-color: #8b3dff; }
.toast.green { border-left-color: #22a84a; }

.track .del { position: absolute; top: 4px; right: 4px; padding: 1px 6px; font-size: 11px; opacity: .7; }
.track { position: relative; }
.track .ta { font-size: 11px; color: var(--muted); }

.badge.host { color: #000; background: #ffd84a; }
.locked { opacity: .45; pointer-events: none; }

/* ekran startowy */
.rooms { display: flex; flex-direction: column; gap: 8px; }
.room-card { display: flex; align-items: center; gap: 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.room-card .rn { font-weight: 700; }
.room-card .rc { font-family: ui-monospace, Menlo, monospace; color: var(--muted); letter-spacing: 1px; }
.room-card .rd { color: var(--muted); font-size: 13px; }
.room-card .grow { flex: 1; min-width: 0; }
.room-card.racing { border-color: #e10600; }
.rooms .empty { color: var(--muted); padding: 10px 0; }
#room-name { color: var(--muted); font-weight: normal; }
.players .ready { color: #3ad13a; font-weight: 700; }

/* dziennik zdarzeń (prawa krawędź, poza torem) */
.feed { position: absolute; right: 10px; top: 52px; width: 230px; max-height: 60vh; overflow: hidden; background: rgba(10,12,16,.82); border-radius: 10px; padding: 6px 10px; font-size: 12px; }
.feed-title { font-weight: 800; letter-spacing: 1px; color: var(--muted); margin-bottom: 4px; font-size: 11px; text-transform: uppercase; }
.feed .ev { padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,.06); display: flex; gap: 6px; align-items: baseline; }
.feed .ev .t { color: var(--muted); font-family: ui-monospace, Menlo, monospace; font-size: 11px; flex: none; }
.feed .ev.purple { color: #c9a0ff; }
.feed .ev.green { color: #7ee08a; }
.feed .ev.crash { color: #ff9a8a; }
.feed .ev.finish { color: #ffd84a; font-weight: 700; }
.feed .ev.new { animation: evin .4s; }
@keyframes evin { from { background: rgba(255,255,255,.18); } to { background: transparent; } }
@media (max-width: 900px) {
  .feed { right: 6px; top: auto; bottom: 6px; width: 200px; max-height: 64px; font-size: 11px; padding: 4px 8px; }
  .feed-title { display: none; }
}
