:root {
  --bg: #0d1b2a;
  --bg-2: #13263b;
  --panel: #182f48;
  --line: #27425f;
  --text: #f1f5f9;
  --muted: #9fb3c8;
  --accent: #f5b301;        /* safety amber */
  --accent-ink: #1a1300;
  --good: #22c55e;
  --bad: #ef4444;
  --optA: #d64545;
  --optB: #2f6fd6;
  --optC: #c98a06;
  --optD: #1f9d55;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #1d3a5c 0%, transparent 60%), var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  background-attachment: fixed;
  min-height: 100vh;
}
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--line); background: rgba(13, 27, 42, .7);
  backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .3px; }
.brand .mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 900; font-size: 15px;
}
.brand .logo {
  height: 40px; width: auto; display: block; background: #fff;
  padding: 5px 9px; border-radius: 9px;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-size: 14px; white-space: nowrap;
}
.chip b { color: var(--text); }
.btn {
  border: 0; border-radius: 12px; padding: 14px 26px; font-weight: 700; font-size: 18px;
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow);
  transition: transform .06s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); box-shadow: none; }
.btn.small { padding: 8px 14px; font-size: 14px; border-radius: 10px; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- Host: start / setup ---------- */
.small { font-size: 14px; }
.btn.wide { width: 100%; }
.setup { max-width: 1400px; margin: 0 auto; padding: 28px 24px 40px; }
.setup-head { text-align: center; margin-bottom: 26px; }
.setup-head .contract {
  font-size: clamp(13px, 1.4vw, 16px); color: var(--muted); max-width: 820px;
  margin: 0 auto 10px; letter-spacing: .2px; line-height: 1.45;
}
.setup-head h1 { font-size: clamp(36px, 5vw, 64px); margin: 0 0 2px; letter-spacing: -.5px; line-height: 1.1; }
.setup-head h1 span { color: var(--accent); }
.setup-head .byline { font-size: clamp(15px, 1.6vw, 19px); color: var(--text); opacity: .85; margin: 0 0 16px; font-weight: 600; }
.facts { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

.setup-grid { display: grid; grid-template-columns: 1fr 380px; gap: 22px; align-items: start; }
.side { display: flex; flex-direction: column; gap: 22px; position: sticky; top: 90px; }
.panel { padding: 22px; position: relative; }
.panel h2 { margin: 0 0 4px; font-size: 22px; }
.step-no {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 900; font-size: 15px; margin-bottom: 10px;
}
.panel-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.panel-actions { display: flex; gap: 8px; }

.topics { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.topic {
  display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 12px; background: var(--bg-2); border: 2px solid var(--line);
  cursor: pointer; user-select: none; transition: border-color .15s, background .15s;
}
.topic:hover { border-color: #3b5f86; }
.topic input { position: absolute; opacity: 0; pointer-events: none; }
.topic .tick {
  width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--muted);
  display: grid; place-items: center; transition: background .15s, border-color .15s;
}
.topic.on { border-color: var(--accent); background: rgba(245, 179, 1, .08); }
.topic.on .tick { background: var(--accent); border-color: var(--accent); }
.topic.on .tick::after { content: "✓"; color: var(--accent-ink); font-weight: 900; font-size: 14px; line-height: 1; }
.topic input:focus-visible + .tick { outline: 2px solid #fff; outline-offset: 2px; }
.topic .tname { font-weight: 600; font-size: 15px; line-height: 1.25; }
.topic .tname small { display: block; color: var(--muted); font-weight: 700; font-size: 12px; letter-spacing: .4px; margin-bottom: 2px; }
.topic .tcount {
  min-width: 34px; text-align: center; font-size: 13px; font-weight: 800; padding: 3px 8px;
  border-radius: 999px; background: var(--panel); color: var(--muted); font-variant-numeric: tabular-nums;
}
.topic.on .tcount { color: var(--text); }
.topic.none { opacity: .5; }

.levels { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.level {
  display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 12px; background: var(--bg-2); border: 2px solid var(--line); cursor: pointer;
}
.level input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.level b { display: block; font-size: 17px; }
.level small { color: var(--muted); font-size: 13px; }
.level em { font-style: normal; font-size: 13px; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.level:has(input:checked) { border-color: var(--accent); background: rgba(245, 179, 1, .08); }
.level:has(input:checked) em { color: var(--text); }

.pool { font-size: 16px; color: var(--muted); margin: 10px 0 14px; line-height: 1.6; }
.pool b { color: var(--text); }
.pool b.big { color: var(--accent); font-size: 22px; }
.pool-warn { font-size: 14px; color: #fcd57a; background: rgba(245, 179, 1, .1); border: 1px solid rgba(245, 179, 1, .35); padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; }

.cfgline { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 16px; }

/* ---------- Host: lobby ---------- */
.lobby { display: grid; grid-template-columns: minmax(320px, 440px) 1fr; gap: 24px; align-items: start; }
.joinbox { padding: 28px; text-align: center; }
.joinbox h2 { margin: 0 0 6px; font-size: 26px; }
#qr { background: #fff; border-radius: 14px; padding: 14px; display: inline-block; margin: 14px 0; }
#qr img, #qr svg { display: block; width: min(320px, 70vw); height: auto; image-rendering: pixelated; }
.code { font-size: 54px; font-weight: 900; letter-spacing: 8px; color: var(--accent); margin: 4px 0; }
.url { font-size: 15px; color: var(--muted); word-break: break-all; }
.players { padding: 24px; min-height: 420px; }
.players-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.players-head h2 { margin: 0; font-size: 26px; }
.namegrid { display: flex; flex-wrap: wrap; gap: 10px; }
.name-tag {
  background: var(--bg-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px;
  font-weight: 600; font-size: 18px; animation: pop .25s ease;
}
.name-tag.off { opacity: .45; }
.name-tag button { background: none; border: 0; color: var(--muted); margin-left: 8px; padding: 0; font-size: 16px; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.empty { color: var(--muted); font-size: 18px; padding: 40px 0; text-align: center; }

/* ---------- Question (host) ---------- */
.qlayout { display: grid; grid-template-columns: 1fr 360px; gap: 24px; }
.qhead { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.qtext { font-size: clamp(24px, 2.6vw, 38px); font-weight: 700; line-height: 1.25; margin: 6px 0 24px; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.opt {
  position: relative; display: flex; align-items: center; gap: 16px; min-height: 110px;
  padding: 18px 20px; border-radius: 16px; color: #fff; font-size: clamp(18px, 1.6vw, 24px); font-weight: 600;
  border: 3px solid transparent; text-align: left; transition: opacity .25s, transform .25s, border-color .25s;
}
.opt .shape { flex: 0 0 auto; width: 48px; height: 48px; border-radius: 12px; background: rgba(0,0,0,.22); display: grid; place-items: center; font-size: 22px; font-weight: 900; }
.opt .shape small { font-size: 12px; display: block; opacity: .85; }
.opt[data-i="0"] { background: var(--optA); }
.opt[data-i="1"] { background: var(--optB); }
.opt[data-i="2"] { background: var(--optC); }
.opt[data-i="3"] { background: var(--optD); }
.opt .count { margin-left: auto; font-weight: 800; font-size: 22px; background: rgba(0,0,0,.25); padding: 4px 12px; border-radius: 999px; }
.reveal .opt.wrong { opacity: .28; }
.reveal .opt.right { border-color: #fff; transform: scale(1.02); box-shadow: 0 0 0 4px rgba(255,255,255,.15), var(--shadow); }
.opt .tick { position: absolute; top: -12px; right: -12px; width: 38px; height: 38px; border-radius: 50%; background: #fff; color: var(--good); display: grid; place-items: center; font-weight: 900; font-size: 22px; }

.timer { position: relative; width: 104px; height: 104px; flex: 0 0 auto; }
.timer svg { transform: rotate(-90deg); }
.timer .num { position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px; font-weight: 900; }
.timer.low .num { color: var(--bad); }
.timebar { height: 10px; background: var(--bg-2); border-radius: 999px; overflow: hidden; }
.timebar > div { height: 100%; background: var(--accent); width: 100%; transition: width .2s linear; }
.timebar.low > div { background: var(--bad); }

.source { margin-top: 18px; padding: 14px 18px; border-left: 4px solid var(--accent); background: var(--bg-2); border-radius: 10px; font-size: 17px; color: #dbe7f3; }

.board { padding: 20px; }
.board h3 { margin: 0 0 4px; font-size: 20px; }
.board .sub { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.rows { display: flex; flex-direction: column; gap: 8px; }
.row { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: var(--bg-2); transition: transform .3s; }
.row .rk { font-weight: 800; color: var(--muted); text-align: center; }
.row .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sc { font-weight: 800; font-variant-numeric: tabular-nums; }
.row .delta { font-size: 13px; font-weight: 700; margin-left: 6px; color: var(--good); }
.row .delta.zero { color: var(--muted); }
.row.answered .nm::after { content: " ✓"; color: var(--good); }
.row:nth-child(1) .rk { color: #ffd54a; }
.row:nth-child(2) .rk { color: #cfd8e3; }
.row:nth-child(3) .rk { color: #e3a46b; }
.progress-dots { display: flex; gap: 4px; flex-wrap: wrap; }
.progress-dots i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.progress-dots i.done { background: var(--accent); }
.progress-dots i.now { background: #fff; }

.controls { display: flex; gap: 12px; margin-top: 22px; flex-wrap: wrap; }

/* ---------- Final / podium ---------- */
.final { text-align: center; }
.final h1 { font-size: clamp(34px, 4vw, 56px); margin: 10px 0 4px; }
.podium { display: grid; grid-template-columns: repeat(3, minmax(160px, 260px)); justify-content: center; align-items: end; gap: 18px; margin: 34px auto 30px; }
.step { border-radius: 16px 16px 0 0; padding: 18px 14px; display: flex; flex-direction: column; justify-content: flex-start; align-items: center; gap: 6px; box-shadow: var(--shadow); animation: rise .8s ease both; }
.step .medal { font-size: 46px; line-height: 1; }
.step .who { font-weight: 800; font-size: clamp(18px, 1.8vw, 26px); word-break: break-word; }
.step .pts { font-weight: 700; opacity: .9; }
.step .place { font-size: 64px; font-weight: 900; opacity: .25; margin-top: auto; }
.step.p1 { height: 340px; background: linear-gradient(#f5c84c, #b8860b); color: #231a00; animation-delay: .9s; }
.step.p2 { height: 270px; background: linear-gradient(#e2e8f0, #94a3b8); color: #111827; animation-delay: .5s; }
.step.p3 { height: 220px; background: linear-gradient(#e9a86b, #a0522d); color: #1f1206; animation-delay: .1s; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.fulltable { max-width: 760px; margin: 0 auto; padding: 20px; text-align: left; }

/* ---------- Participant (phone) ---------- */
.phone { max-width: 560px; margin: 0 auto; padding: 18px 16px 40px; min-height: 100vh; display: flex; flex-direction: column; }
.phone .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 14px; }
.phone h1 { font-size: 28px; margin: 12px 0 6px; }
.field { display: flex; flex-direction: column; gap: 8px; margin: 18px 0; }
.field label { font-weight: 600; }
.field input {
  font: inherit; font-size: 20px; padding: 14px 16px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--bg-2); color: var(--text); outline: none;
}
.field input:focus { border-color: var(--accent); }
.phone .btn { width: 100%; }
.center { text-align: center; }
.big-emoji { font-size: 64px; margin: 24px 0 8px; }
.pq { font-size: 20px; font-weight: 700; margin: 12px 0 16px; line-height: 1.3; }
.pbtns { display: grid; gap: 12px; }
.pbtn {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 70px; padding: 14px 16px; border: 3px solid transparent;
  border-radius: 14px; color: #fff; font-weight: 600; font-size: 17px; text-align: left;
}
.pbtn .shape { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 10px; background: rgba(0,0,0,.22); display: grid; place-items: center; font-weight: 900; }
.pbtn[data-i="0"] { background: var(--optA); }
.pbtn[data-i="1"] { background: var(--optB); }
.pbtn[data-i="2"] { background: var(--optC); }
.pbtn[data-i="3"] { background: var(--optD); }
.pbtns.locked .pbtn { opacity: .35; }
.pbtns.locked .pbtn.mine { opacity: 1; border-color: #fff; }
.pbtns.revealed .pbtn.right { opacity: 1; border-color: #fff; }
.result { border-radius: 16px; padding: 18px; text-align: center; margin: 16px 0; font-size: 20px; font-weight: 800; }
.result.ok { background: rgba(34,197,94,.18); border: 2px solid var(--good); }
.result.no { background: rgba(239,68,68,.15); border: 2px solid var(--bad); }
.result.none { background: var(--bg-2); border: 2px solid var(--line); }
.pref { margin: 4px 0 14px; padding: 14px 16px; border-radius: 12px; background: var(--bg-2); border-left: 4px solid var(--accent); font-size: 15px; color: #dbe7f3; line-height: 1.45; }
.pref .lbl { font-size: 12px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
.pref b { display: block; color: var(--text); margin-bottom: 4px; }
.stat { display: flex; justify-content: space-around; gap: 10px; margin: 14px 0; }
.stat div { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; flex: 1; text-align: center; }
.stat b { display: block; font-size: 26px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #111c2b; border: 1px solid var(--line); padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); z-index: 20; max-width: 92vw; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--good); display: inline-block; }
.conn.off { background: var(--bad); }

@media (max-width: 1000px) {
  .lobby, .qlayout, .setup-grid { grid-template-columns: 1fr; }
  .side { position: static; }
  .options { grid-template-columns: 1fr; }
  .podium { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .step.p1 { height: 260px; } .step.p2 { height: 210px; } .step.p3 { height: 170px; }
  .step .medal { font-size: 34px; } .step .place { font-size: 40px; }
}
@media (max-width: 600px) {
  .wrap, .setup { padding: 16px; }
  .topics { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; }
  .code { font-size: 40px; letter-spacing: 5px; }
}
