:root {
  --bg: #0e1a2b;
  --bg2: #16263d;
  --panel: #1c3050;
  --line: #2c4468;
  --text: #f3f6fb;
  --muted: #9fb2cc;
  --gold: #f6bd41;
  --low: #1fb5a8;
  --high: #ee6a52;
  --under: #8573e6;
  --good: #4ed38a;
  --bad: #ff7b7b;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(1200px 700px at 50% -10%, #1d3557 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--gold); }
[hidden] { display: none !important; }

.brand { font-weight: 900; letter-spacing: -0.02em; line-height: 1; white-space: nowrap; }
.brand .amp { color: var(--gold); padding: 0 0.12em; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.btn {
  border: 0; border-radius: 12px; padding: 14px 20px; font-weight: 800; font-size: 1.05rem;
  background: var(--gold); color: #1b1300; width: 100%;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.ghost { background: transparent; color: var(--text); border: 2px solid var(--line); }
.btn.small { width: auto; padding: 8px 14px; font-size: 0.92rem; border-radius: 10px; }
.btn.danger { background: transparent; color: var(--bad); border: 2px solid #6b3340; }
.field {
  width: 100%; border-radius: 12px; border: 2px solid var(--line); background: #0b1524; color: var(--text);
  padding: 14px 16px; font-size: 1.15rem;
}
.field:focus { outline: none; border-color: var(--gold); }
label.lbl { display: block; font-size: 0.85rem; color: var(--muted); font-weight: 700; margin: 0 0 6px 2px; text-transform: uppercase; letter-spacing: 0.06em; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.muted { color: var(--muted); }
.good { color: var(--good); }
.bad { color: var(--bad); }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: #40121a; color: #ffd9de; border: 1px solid #a5404f; padding: 12px 18px; border-radius: 12px;
  font-weight: 700; max-width: 92vw; text-align: center; transition: 0.2s; z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.offline { position: fixed; top: 0; left: 0; right: 0; background: #7a2732; color: #fff; text-align: center; font-weight: 700; padding: 6px; z-index: 40; font-size: 0.9rem; }

[data-countdown] { font-variant-numeric: tabular-nums; font-weight: 900; }
[data-countdown].low { color: var(--bad); }
[data-countdown].up { color: var(--bad); }

/* ------------------------------------------------------------ board of guesses */
.board { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 0.7em; }
.board.sides { margin-top: 0.7em; }
.slot {
  position: relative; background: var(--bg2); border: 2px solid var(--line); border-top: 0.5em solid var(--muted);
  border-radius: 0.8em; padding: 0.6em 0.5em 0.7em; text-align: center; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 0.25em; transition: opacity 0.4s, transform 0.4s;
}
.slot.side-low { border-top-color: var(--low); }
.slot.side-high { border-top-color: var(--high); }
.slot.side-mid { border-top-color: var(--gold); }
.slot.under { border-top-color: var(--under); }
.slot .odds { font-weight: 900; font-size: 0.8em; color: var(--muted); letter-spacing: 0.04em; }
.slot .val { font-weight: 900; font-size: 1.7em; line-height: 1.05; overflow-wrap: anywhere; }
.slot .val.small { font-size: 1.05em; }
.slot .who { font-size: 0.72em; color: var(--muted); font-weight: 600; overflow-wrap: anywhere; }
.slot .chips { display: flex; flex-wrap: wrap; gap: 0.25em; justify-content: center; margin-top: 0.2em; }
.chip { background: #0b1524; border: 1px solid var(--line); border-radius: 99px; padding: 0.1em 0.6em; font-size: 0.62em; white-space: nowrap; }
.chip b { color: var(--gold); }
.slot.win { border-color: var(--gold); background: #3a3210; box-shadow: 0 0 0 0.2em rgba(246, 189, 65, 0.35), 0 0 2.2em rgba(246, 189, 65, 0.45); }
.slot.win .odds { color: var(--gold); }
.slot.lose { opacity: 0.55; }

/* ---------------------------------------------------------------- phone page */
.phone { max-width: 520px; margin: 0 auto; padding: 16px 16px 40px; }
.phone header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.phone header .brand { font-size: 1.15rem; }
.me-pill { background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 6px 14px; font-weight: 700; font-size: 0.95rem; max-width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-pill b { color: var(--gold); margin-left: 6px; }
.hero { text-align: center; padding: 26px 0 8px; }
.hero .brand { font-size: 2.5rem; }
.hero p { color: var(--muted); margin-top: 10px; }
.round-tag { display: flex; justify-content: space-between; align-items: baseline; color: var(--muted); font-weight: 800; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; }
.round-tag [data-countdown] { font-size: 1.5rem; color: var(--gold); }
.question { font-size: 1.3rem; font-weight: 700; }
.big-num { font-size: 2.6rem; font-weight: 900; color: var(--gold); line-height: 1.1; overflow-wrap: anywhere; }
.center { text-align: center; }
.result-net { font-size: 3rem; font-weight: 900; line-height: 1; }
.lines { font-size: 0.98rem; }
.lines div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); }
.lines div:first-child { border-top: 0; }
.rank-list { list-style: none; padding: 0; margin: 0; }
.rank-list li { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.rank-list li:first-child { border-top: 0; }
.rank-list .pl { width: 1.8em; color: var(--muted); font-weight: 800; }
.rank-list .nm { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list .sc { font-weight: 900; font-variant-numeric: tabular-nums; }
.rank-list li.me .nm { color: var(--gold); }

.chips-left { display: flex; align-items: baseline; gap: 8px; justify-content: center; color: var(--muted); font-weight: 700; }
.chips-left b { font-size: 2rem; color: var(--gold); }
.steps { display: flex; gap: 8px; align-items: center; justify-content: center; color: var(--muted); font-size: 0.9rem; margin-top: 8px; }
.steps button { border: 2px solid var(--line); background: transparent; border-radius: 10px; padding: 6px 14px; font-weight: 800; }
.steps button.on { border-color: var(--gold); color: var(--gold); }
.spots { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-top: 12px; }
.spot { display: flex; align-items: center; gap: 10px; background: var(--bg2); border: 2px solid var(--line); border-left: 8px solid var(--muted); border-radius: 12px; padding: 8px 8px 8px 10px; }
.spot.side-low { border-left-color: var(--low); }
.spot.side-high { border-left-color: var(--high); }
.spot.side-mid { border-left-color: var(--gold); }
.spot.under { border-left-color: var(--under); }
.spot.has { border-color: var(--gold); border-left-width: 8px; }
.spot-odds { font-weight: 900; color: var(--muted); width: 2.4em; font-size: 0.95rem; }
.spot-main { flex: 1; min-width: 0; }
.spot-title { font-weight: 900; font-size: 1.25rem; line-height: 1.1; overflow-wrap: anywhere; }
.spot.side .spot-title, .spot.under .spot-title { font-size: 1.05rem; }
.spot-sub { color: var(--muted); font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spot-amt { width: 2.2em; text-align: center; font-weight: 900; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.pm { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--line); background: #0b1524; font-size: 1.5rem; font-weight: 800; line-height: 1; flex: none; }
.pm:disabled { opacity: 0.3; }
.sticky-bar { position: sticky; bottom: 0; padding: 12px 0 4px; background: linear-gradient(transparent, var(--bg) 35%); }

/* ---------------------------------------------------------------- big screen */
.screen { height: 100vh; overflow: hidden; display: flex; flex-direction: column; padding: 2.2vh 2.4vw; font-size: clamp(11px, min(1.55vw, 2.75vh), 40px); }
.screen .top { display: flex; justify-content: space-between; align-items: center; gap: 2vw; }
.screen .top .brand { font-size: 1.5em; }
.screen .top .join { color: var(--muted); font-weight: 700; font-size: 0.9em; }
.screen .top .join b { color: var(--gold); letter-spacing: 0.12em; font-size: 1.25em; margin-left: 0.3em; }
.screen #stage { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; margin: 1.5vh 0; overflow: hidden; }
#fitbox { display: flex; flex-direction: column; }
.screen .teams-strip { display: flex; flex-wrap: wrap; gap: 0.5em; justify-content: center; min-height: 2.2em; }
.tchip { background: var(--panel); border: 2px solid var(--line); border-radius: 99px; padding: 0.22em 0.9em; font-weight: 700; font-size: 0.8em; display: flex; gap: 0.5em; align-items: center; }
.tchip.done { border-color: var(--good); }
.tchip.done::before { content: "\2713"; color: var(--good); font-weight: 900; }
.tchip.off { opacity: 0.5; }
.tchip b { color: var(--gold); }

.lobby { display: grid; grid-template-columns: 1.15fr 1fr; gap: 4vw; align-items: center; }
.lobby .brand { font-size: 4.2em; white-space: normal; }
.lobby .how { font-size: 1.25em; color: var(--muted); margin-top: 0.8em; }
.lobby .how b { color: var(--text); }
.lobby .code { font-size: 5.5em; font-weight: 900; letter-spacing: 0.14em; color: var(--gold); line-height: 1; margin-top: 0.15em; }
.lobby .qr { background: #fff; border-radius: 1em; padding: 0.8em; width: min(38vh, 26vw); margin: 0 auto; }
.lobby .qr svg { display: block; width: 100%; height: auto; }
.lobby .joined { text-align: center; color: var(--muted); font-weight: 700; margin-top: 1em; }

.stage-head { display: flex; justify-content: space-between; align-items: center; gap: 2vw; margin-bottom: 1.2vh; }
.stage-head .tag { color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.85em; }
.stage-head [data-countdown] { font-size: 2.6em; color: var(--gold); line-height: 1; min-width: 2.2em; text-align: right; }
.q-big { font-size: 2.5em; font-weight: 800; line-height: 1.18; text-align: center; margin: auto 4vw; text-wrap: balance; }
.q-small { font-size: 1.15em; font-weight: 700; text-align: center; margin: 0 2vw 1.6vh; text-wrap: balance; }
.prompt { text-align: center; color: var(--gold); font-weight: 800; margin-top: 1.6vh; font-size: 1.05em; }
.screen .board { font-size: 1em; }

.reveal { display: grid; grid-template-columns: minmax(0, 2.5fr) minmax(0, 1fr); gap: 2vw; align-items: start; min-height: 0; }
.answer-banner { text-align: center; margin-bottom: 1.6vh; }
.answer-banner .lab { color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.8em; }
.answer-banner .num { font-size: 3.6em; font-weight: 900; color: var(--gold); line-height: 1.05; }
.answer-banner .note { color: var(--muted); font-size: 0.85em; }
.leader { background: var(--panel); border: 1px solid var(--line); border-radius: 0.9em; padding: 0.7em 0.9em; font-size: 0.85em; max-height: 100%; overflow: hidden; }
.leader h3 { font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin-bottom: 0.3em; }
.leader .rank-list li { padding: 0.28em 0; }
.leader .delta { width: 3.2em; text-align: right; font-weight: 800; font-size: 0.9em; }
@keyframes pop { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.reveal .answer-banner .num { animation: pop 0.5s 0.9s both cubic-bezier(0.2, 1.6, 0.4, 1); }
.reveal .answer-banner .note { animation: fade 0.5s 1.5s both; }
.reveal .slot.win { animation: winglow 0.6s 2s both; }
.reveal .slot.lose { animation: dim 0.6s 2s both; }
.reveal .slot .chips { animation: fade 0.5s 2.8s both; }
.reveal .leader { animation: fade 0.6s 3.6s both; }
@keyframes winglow { from { border-color: var(--line); background: var(--bg2); box-shadow: none; } }
@keyframes dim { from { opacity: 1; } to { opacity: 0.55; } }

.final { text-align: center; }
.final .lab { color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: 0.14em; }
.final .winner { font-size: 4.2em; font-weight: 900; color: var(--gold); line-height: 1.1; margin: 0.1em 0 0.3em; overflow-wrap: anywhere; }
.final .rank-list { max-width: 26em; margin: 0 auto; text-align: left; font-size: 1.05em; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.ctl { position: fixed; right: 12px; bottom: 12px; opacity: 0.25; z-index: 20; }
.ctl:hover { opacity: 1; }

/* ----------------------------------------------------------------- host page */
.hostpage { max-width: 1060px; margin: 0 auto; padding: 16px 16px 60px; }
.hostpage header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.hostpage header .brand { font-size: 1.4rem; }
.codebox { font-weight: 800; color: var(--muted); }
.codebox b { color: var(--gold); letter-spacing: 0.12em; font-size: 1.3rem; margin-left: 6px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }
.card h2 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-bottom: 12px; }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; }
.opt input[type="number"], .opt select { width: 120px; border-radius: 10px; border: 2px solid var(--line); background: #0b1524; padding: 8px 10px; }
.opt input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--gold); }
.seg { display: inline-flex; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 8px 16px; font-weight: 800; }
.seg button.on { background: var(--gold); color: #1b1300; }
.host-q { font-size: 1.35rem; font-weight: 700; }
.host-a { font-size: 1.1rem; margin-top: 8px; }
.host-a b { color: var(--gold); font-size: 1.4rem; }
.host-timer { font-size: 2rem; color: var(--gold); min-width: 3em; }
table.tt { width: 100%; border-collapse: collapse; }
table.tt th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 6px 8px; }
table.tt td { padding: 9px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
table.tt td.num, table.tt th.num { text-align: right; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #55657e; margin-right: 8px; }
.dot.on { background: var(--good); }
.linkbtn { background: none; border: 0; color: var(--gold); padding: 2px 4px; font-weight: 700; text-decoration: underline; font-size: 0.9rem; }
.qlist { max-height: 320px; overflow: auto; font-size: 0.92rem; }
.qlist div { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; border-top: 1px solid var(--line); }
.qlist b { color: var(--gold); white-space: nowrap; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(640px, 94vw); max-height: 92vh; }
dialog::backdrop { background: rgba(4, 9, 18, 0.75); }
dialog h3 { margin-bottom: 12px; }
textarea.field { min-height: 220px; font-size: 0.95rem; font-family: ui-monospace, Consolas, monospace; }
.hostpage .board { font-size: 0.8rem; }
