:root {
  --bg: #0f172a;
  --bg2: #1e1b4b;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --yellow: #facc15;
  --pink: #ec4899;
  --blue: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 18px;
  --font: "Baloo 2", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: radial-gradient(1200px 600px at 10% -10%, #4338ca 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 110%, #be185d 0%, transparent 55%), var(--bg);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.1; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.screen { display: none; min-height: 100%; }
.screen.active { display: flex; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
  padding: 22px;
  width: 100%;
  max-width: 520px;
  margin: auto;
}

.logo { font-size: 38px; font-weight: 800; color: var(--ink); letter-spacing: -0.5px; }
.logo span { color: var(--pink); }
.logo small { font-size: 16px; color: var(--muted); font-weight: 700; margin-left: 6px; }
.sub { margin: 2px 0 14px; color: var(--muted); }

label, .label { display: block; font-weight: 700; font-size: 14px; color: #334155; margin: 10px 0 6px; }
label input, .field {
  display: block; width: 100%; margin-top: 6px; padding: 12px 14px; font-size: 18px; font-weight: 700;
  border: 2px solid #e2e8f0; border-radius: 12px; outline: none; background: #f8fafc; color: var(--ink);
}
label input:focus { border-color: var(--blue); background: #fff; }
#in-code { letter-spacing: 4px; text-transform: uppercase; }
input[readonly] { background: #e2e8f0; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }

.btn {
  border: 0; border-radius: 14px; padding: 12px 18px; font-size: 16px; font-weight: 800;
  background: #e2e8f0; color: var(--ink); transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; }
.btn.big { width: 100%; padding: 16px; font-size: 20px; margin-top: 16px; }
.btn.primary { background: linear-gradient(135deg, #f43f5e, #ec4899 60%, #a855f7); color: #fff; box-shadow: 0 8px 20px rgba(236,72,153,.4); }
.btn.danger { background: var(--red); color: #fff; }
.btn.ghost { background: #f1f5f9; }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn.link { background: none; color: var(--muted); text-decoration: underline; font-weight: 600; margin-top: 12px; }
.error { color: var(--red); font-weight: 700; min-height: 1.2em; margin: 8px 0 0; }

/* ---------- picker ---------- */
.picker-head { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.picker-head .label { margin: 0; }
.char-name { font-size: 22px; font-weight: 800; color: var(--pink); }
.preview { width: 88px; height: 88px; background: #64748b; border-radius: 16px;
  background: repeating-linear-gradient(0deg, #5b5f66 0 14px, #63676e 14px 28px); flex: none; }
.preview.big { width: 120px; height: 120px; margin: 6px auto 0; display: block; border-radius: 20px; }
.char-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; margin-top: 10px; }
.char-btn { font-size: 30px; height: 54px; border-radius: 14px; border: 3px solid transparent; background: #f1f5f9; transition: transform .1s; }
.char-btn.sel { border-color: var(--pink); background: #fdf2f8; transform: scale(1.06); }
.color-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.color-btn { width: 38px; height: 38px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px #cbd5e1; }
.color-btn.sel { box-shadow: 0 0 0 3px var(--ink); transform: scale(1.12); }

/* ---------- player screens ---------- */
body.player .screen { padding: 14px; }
body.player #screen-game { padding: 0; }
.lobby-card, .results-card { text-align: center; }
.room-tag { display: inline-block; background: #eef2ff; color: #4338ca; padding: 4px 12px; border-radius: 999px; font-weight: 700; }
.room-tag b { letter-spacing: 2px; }
#lb-hello { margin-top: 8px; font-size: 26px; }
.status-pill { display: inline-block; background: #fef9c3; color: #854d0e; padding: 8px 14px; border-radius: 12px; font-weight: 700; margin: 10px 0; }
.howto { text-align: left; background: #f8fafc; border-radius: 14px; padding: 12px 14px; margin: 14px 0; font-size: 15px; line-height: 1.7; }
.howto .k { display: inline-block; min-width: 38px; text-align: center; background: #0f172a; color: #fff; border-radius: 8px; padding: 0 6px; margin-right: 6px; font-weight: 800; }
.howto .k.pad { background: #f59e0b; }
.howto .k.mud { background: #7a4a24; }
.howto .items { padding-left: 46px; font-weight: 700; }
.lobby-card h3 { margin-top: 6px; font-size: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 10px; max-height: 220px; overflow: auto; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px 3px 4px; border-radius: 999px; background: #f1f5f9; font-weight: 700; font-size: 14px; border: 2px solid var(--c); }
.chip i { font-style: normal; background: var(--c); border-radius: 50%; width: 24px; height: 24px; display: grid; place-items: center; font-size: 15px; }
.chip.me { background: #fef9c3; }

.res-me { background: #f8fafc; border-radius: 16px; padding: 14px; margin: 12px 0; font-size: 17px; }
.big-rank { font-size: 64px; font-weight: 800; color: var(--pink); line-height: 1; }
.big-rank.dim { color: var(--muted); }
.res-me .total { margin-top: 6px; color: #334155; }
.standings { list-style: none; padding: 0; margin: 10px 0; text-align: left; }
.standings li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 12px; font-size: 17px; }
.standings li:nth-child(odd) { background: #f8fafc; }
.standings li.me { background: #fef9c3; }
.standings li.gap { margin-top: 8px; border-top: 2px dashed #cbd5e1; }
.standings .pos { width: 28px; font-weight: 800; color: var(--muted); }
.standings .av { width: 32px; height: 32px; border-radius: 50%; background: var(--c); display: grid; place-items: center; font-size: 18px; }
.standings .nm { flex: 1; font-weight: 700; }

/* ---------- game ---------- */
#screen-game { position: fixed; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hud { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: flex-start; gap: 10px; padding: calc(env(safe-area-inset-top) + 8px) 10px 0; pointer-events: none; }
.hud-pos { background: rgba(15,23,42,.8); color: #fff; border-radius: 14px; padding: 2px 12px; font-weight: 800; font-size: 34px; line-height: 1.2; }
.hud-pos small { font-size: 16px; color: #cbd5e1; }
.hud-mid { flex: 1; padding-top: 8px; }
.hud-bar { height: 12px; background: rgba(15,23,42,.6); border-radius: 999px; overflow: hidden; border: 2px solid rgba(255,255,255,.6); }
.hud-bar div { height: 100%; width: 0; background: linear-gradient(90deg, var(--yellow), #f97316); }
.hud-dist { color: #fff; font-weight: 800; text-shadow: 0 2px 4px rgba(0,0,0,.6); font-size: 15px; margin-top: 2px; }
.hud-item { pointer-events: auto; width: 60px; height: 60px; border-radius: 16px; background: rgba(15,23,42,.6); border: 3px dashed rgba(255,255,255,.5); display: grid; place-items: center; font-size: 34px; }
.hud-item.has { border: 3px solid var(--yellow); background: rgba(250,204,21,.25); animation: pulse 0.8s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.hud-feed { position: absolute; top: calc(env(safe-area-inset-top) + 76px); left: 10px; margin: 0; padding: 0; list-style: none; pointer-events: none; max-width: 70%; }
.hud-feed li { background: rgba(15,23,42,.7); color: #fff; font-weight: 700; font-size: 13px; padding: 3px 10px; border-radius: 10px; margin-bottom: 4px; transition: opacity 1s; }
.hud-feed li.fade { opacity: 0; }
.hud-msg { position: absolute; left: 0; right: 0; top: 32%; text-align: center; font-size: 56px; font-weight: 800; color: #fff; text-shadow: 0 4px 0 #0f172a, 0 0 24px rgba(0,0,0,.5); pointer-events: none; }
.hud-msg.count { font-size: 110px; color: var(--yellow); animation: pop .9s infinite; }
.hud-msg.go { font-size: 110px; color: var(--green); }
.hud-msg.fin { color: var(--yellow); font-size: 48px; }
.hud-msg.dizzy { font-size: 64px; animation: spin 1s linear infinite; }
@keyframes pop { 0% { transform: scale(1.4); opacity: .4; } 25% { transform: scale(1); opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
.hud-sub { position: absolute; left: 0; right: 0; top: calc(32% + 90px); text-align: center; color: #fff; font-weight: 800; font-size: 18px; text-shadow: 0 2px 4px rgba(0,0,0,.8); pointer-events: none; }
.controls { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; padding: 0 12px calc(env(safe-area-inset-bottom) + 14px); pointer-events: none; }
.ctrl-group { display: flex; gap: 12px; pointer-events: auto; }
.ctrl { width: 78px; height: 78px; border-radius: 50%; border: 3px solid rgba(255,255,255,.7); background: rgba(15,23,42,.55); color: #fff; font-size: 34px; font-weight: 800; display: grid; place-items: center; touch-action: none; backdrop-filter: blur(2px); line-height: 1; }
.ctrl small { display: block; font-size: 10px; letter-spacing: 1px; margin-top: -6px; }
.ctrl.down { background: rgba(250,204,21,.6); transform: scale(.94); }
.ctrl.jump { background: rgba(34,197,94,.6); width: 88px; height: 88px; }
.ctrl.item { background: rgba(236,72,153,.45); }
.ctrl.item.ready { border-color: var(--yellow); background: rgba(250,204,21,.45); animation: pulse .8s infinite; }
.kbd-hint { position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); color: rgba(255,255,255,.75); font-size: 12px; font-weight: 700; pointer-events: none; white-space: nowrap; }
@media (hover: none), (max-width: 700px) { .kbd-hint { display: none; } }

.toast { position: fixed; left: 50%; top: 20%; transform: translate(-50%, -20px); background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 14px; font-weight: 800; opacity: 0; transition: all .25s; pointer-events: none; z-index: 50; text-align: center; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 60; }
#confetti span { position: absolute; top: -40px; animation: fall 3.5s linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

/* =================================================== ADMIN */
body.admin { color: #fff; }
body.admin .screen { padding: 18px; }
.setup-card { color: var(--ink); max-width: 560px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 6px; }
.seg button { border: 2px solid #e2e8f0; background: #f8fafc; border-radius: 12px; padding: 8px 4px; font-weight: 800; font-size: 16px; }
.seg button small { display: block; font-weight: 600; color: var(--muted); font-size: 12px; }
.seg button.sel { border-color: var(--pink); background: #fdf2f8; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

#a-dash { flex-direction: column; gap: 14px; }
.dash-head { display: flex; align-items: center; gap: 18px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); border-radius: var(--radius); padding: 12px 18px; flex-wrap: wrap; }
.code-box .code { font-size: 54px; font-weight: 800; letter-spacing: 6px; color: var(--yellow); line-height: 1; }
.code-box .muted, .head-info .muted { color: #cbd5e1; }
.url { color: #e2e8f0; font-weight: 700; font-size: 15px; word-break: break-all; }
.qr { width: 104px; height: 104px; background: #fff; border-radius: 10px; padding: 4px; cursor: zoom-in; }
.head-info { display: flex; flex-direction: column; gap: 4px; font-size: 18px; }
.badge { display: inline-block; padding: 2px 12px; border-radius: 999px; font-weight: 800; background: #334155; width: fit-content; }
.badge.lobby { background: #2563eb; } .badge.countdown, .badge.racing { background: #16a34a; } .badge.results { background: #a855f7; } .badge.final { background: #ca8a04; }
.round { font-weight: 800; font-size: 20px; }
.head-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.head-actions .btn.big { width: auto; margin: 0; padding: 12px 22px; }

.panel { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); border-radius: var(--radius); padding: 16px 18px; }
.panel h2 { font-size: 26px; margin-bottom: 4px; }
.panel h3 { font-size: 18px; margin: 8px 0; color: #e2e8f0; }
.panel .muted { color: #cbd5e1; }
.player-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.pcard { position: relative; display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.1); border-radius: 14px; padding: 8px 10px; font-weight: 800; font-size: 17px; animation: popin .35s; }
.pcard.off { opacity: .4; }
.pcard .av { width: 40px; height: 40px; border-radius: 50%; background: var(--c); display: grid; place-items: center; font-size: 24px; flex: none; }
.pcard .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .kick { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--red); color: #fff; font-size: 12px; line-height: 22px; padding: 0; display: none; }
.pcard:hover .kick { display: block; }
@keyframes popin { from { transform: scale(.6); opacity: 0; } }
.empty { color: #94a3b8; font-size: 18px; padding: 20px 0; }

.race-wrap { display: grid; grid-template-columns: 1fr 300px; gap: 16px; }
.lanes { display: grid; gap: 3px 18px; align-content: start; }
.lane { display: grid; grid-template-columns: 30px 120px 1fr; align-items: center; gap: 6px; height: var(--lh, 30px); }
.lane .rk { font-weight: 800; color: var(--yellow); text-align: right; font-size: 15px; }
.lane .ln { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.lane .strip { position: relative; height: 100%; background: linear-gradient(90deg, #475569, #52525b); border-radius: 6px; border-right: 6px solid; border-image: repeating-linear-gradient(0deg, #fff 0 4px, #111 4px 8px) 6; }
.lane .runner { position: absolute; top: 50%; left: 0; transform: translate(-50%, -50%); font-size: calc(var(--lh, 30px) * .8); transition: left .14s linear; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0,0,0,.4)); }
.lane .runner::after { content: ""; position: absolute; left: 50%; bottom: -3px; width: 70%; height: 4px; transform: translateX(-50%); background: var(--c); border-radius: 3px; }
.lane.fin .strip { background: linear-gradient(90deg, #15803d, #16a34a); }
.lane.off { opacity: .35; }
.lane .fx { position: absolute; top: 50%; transform: translate(-50%, -50%); font-size: 12px; }
.race-side { background: rgba(15,23,42,.4); border-radius: 14px; padding: 12px; }
.race-timer { font-size: 34px; font-weight: 800; text-align: center; color: var(--yellow); }
.race-timer small { display: block; font-size: 15px; color: #fca5a5; }
.live-top { list-style: none; padding: 0; margin: 0; }
.live-top li { display: flex; align-items: center; gap: 8px; padding: 4px 6px; font-weight: 800; font-size: 17px; border-radius: 8px; }
.live-top li:nth-child(1) { background: rgba(250,204,21,.25); }
.live-top .p { width: 24px; color: var(--yellow); }
.live-top .e { font-size: 20px; }
.live-top .t { margin-left: auto; color: #86efac; font-size: 14px; }
.feed { list-style: none; padding: 0; margin: 0; max-height: 300px; overflow: hidden; }
.feed li { font-size: 14px; font-weight: 600; padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.08); animation: popin .3s; }
.big-countdown { position: fixed; inset: 0; display: none; place-items: center; font-size: 280px; font-weight: 800; color: var(--yellow); text-shadow: 0 10px 0 #0f172a; pointer-events: none; z-index: 40; background: rgba(15,23,42,.35); }
.big-countdown.show { display: grid; }

.podium { display: flex; justify-content: center; align-items: flex-end; gap: 14px; margin: 18px 0 6px; }
.podium .step { text-align: center; width: 170px; }
.podium .av { width: 80px; height: 80px; border-radius: 50%; background: var(--c); display: grid; place-items: center; font-size: 48px; margin: 0 auto 6px; border: 4px solid #fff; }
.podium .nm { font-weight: 800; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium .pt { color: #cbd5e1; font-weight: 700; }
.podium .block { margin-top: 8px; border-radius: 12px 12px 0 0; font-size: 46px; font-weight: 800; display: grid; place-items: center; color: #0f172a; }
.podium .s1 .block { height: 150px; background: linear-gradient(#fde047, #eab308); }
.podium .s2 .block { height: 110px; background: linear-gradient(#e2e8f0, #94a3b8); }
.podium .s3 .block { height: 80px; background: linear-gradient(#fdba74, #c2410c); }
.res-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 16px; }
.tbl th { text-align: left; color: #94a3b8; font-weight: 700; padding: 4px 6px; }
.tbl td { padding: 5px 6px; border-top: 1px solid rgba(255,255,255,.08); font-weight: 700; }
.tbl td.e { font-size: 20px; }
.tbl tr.top td { color: var(--yellow); }
.tbl-wrap { max-height: 52vh; overflow: auto; }

.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.92); display: grid; place-items: center; z-index: 70; cursor: zoom-out; }
.qr-big { text-align: center; }
.qr-big img { width: min(70vh, 80vw); background: #fff; border-radius: 20px; padding: 12px; }
.qr-big .code { font-size: 80px; font-weight: 800; letter-spacing: 10px; color: var(--yellow); }
.qr-big .url { font-size: 26px; }
dialog { border: 0; border-radius: var(--radius); padding: 22px; width: min(480px, 92vw); }
dialog::backdrop { background: rgba(15,23,42,.7); }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

@media (max-width: 900px) {
  .race-wrap, .res-cols { grid-template-columns: 1fr; }
  .lane { grid-template-columns: 26px 80px 1fr; }
}
