:root {
  --bg: #0b1a33;
  --bg-2: #10244a;
  --panel: #152c57;
  --panel-2: #1c386b;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f4f7fb;
  --muted: #a9b8d3;
  --brand: #4589ff;
  --good: #24a148;
  --bad: #da1e28;
  --warn: #f1c21b;
  --opt-0: #0f62fe;
  --opt-1: #d02670;
  --opt-2: #007d79;
  --opt-3: #8a3ffc;
  --radius: 14px;
  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(1200px 700px at 80% -10%, #1d4390 0%, transparent 60%),
              radial-gradient(900px 600px at -10% 110%, #3b1f6e 0%, transparent 55%),
              var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 12px 18px;
  font-weight: 600;
  background: var(--brand);
  color: #fff;
  transition: transform .08s ease, filter .15s ease, opacity .15s;
}
a.btn { text-decoration: none; display: inline-block; }
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; transform: none; }
.btn.secondary { background: var(--panel-2); }
.btn.danger { background: var(--bad); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

input[type=text], input[type=password], input[type=number] {
  width: 100%;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}
input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(69, 137, 255, .3); }

.card {
  background: rgba(21, 44, 87, 0.75);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(6px);
}

.brand-mark {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 700; letter-spacing: .02em;
}
.brand-mark .dot {
  width: 14px; height: 14px; border-radius: 4px;
  background: linear-gradient(135deg, var(--brand), var(--opt-3));
}

/* answer tiles --------------------------------------------------------- */
.opt { --c: var(--opt-0); }
.opt[data-i="1"] { --c: var(--opt-1); }
.opt[data-i="2"] { --c: var(--opt-2); }
.opt[data-i="3"] { --c: var(--opt-3); }

.shape { display: inline-grid; place-items: center; flex: none; font-size: 1.1em; }
.shape::before { content: '▲'; }
.opt[data-i="1"] .shape::before { content: '◆'; }
.opt[data-i="2"] .shape::before { content: '●'; }
.opt[data-i="3"] .shape::before { content: '■'; }
.tf .opt[data-i="0"] .shape::before { content: '✓'; }
.tf .opt[data-i="1"] .shape::before { content: '✗'; }

/* player ---------------------------------------------------------------- */
.player {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  max-width: 560px; margin: 0 auto; padding: 16px;
}
.player header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0 14px; }
.player header .score { font-weight: 700; background: var(--panel); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px; font-size: 14px; }
.player main { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.player h1 { font-size: 28px; margin: 0; line-height: 1.2; }
.player h2 { font-size: 20px; margin: 0; line-height: 1.35; font-weight: 600; }
.player .qmeta { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; }
.player .timerbar { height: 6px; border-radius: 3px; background: var(--panel); overflow: hidden; }
.player .timerbar > i { display: block; height: 100%; background: var(--brand); transform-origin: left; }
.player .answers { display: grid; gap: 10px; }
.player .answers .opt {
  display: flex; align-items: center; gap: 12px; text-align: left;
  min-height: 64px; padding: 14px 16px; border: 0; border-radius: 12px;
  background: var(--c); color: #fff; font-weight: 600; font-size: 16px; line-height: 1.3;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .25);
  transition: transform .08s, opacity .2s, filter .2s;
}
.player .answers .opt:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0, 0, 0, .25); }
.player .answers.tf { grid-template-columns: 1fr 1fr; }
.player .answers.tf .opt { flex-direction: column; justify-content: center; min-height: 140px; font-size: 22px; }
.player .answers.locked .opt { opacity: .3; pointer-events: none; }
.player .answers.locked .opt.chosen { opacity: 1; outline: 3px solid #fff; outline-offset: 2px; }
.player .answers.revealed .opt.chosen { opacity: .55; outline: 3px dashed #ff8389; }
.player .answers.revealed .opt.correct { opacity: 1; outline: 3px solid #fff; outline-offset: 2px; }
.player .answers.revealed .opt .tag { margin-left: auto; font-size: 12px; font-weight: 700; background: rgba(0, 0, 0, .35); padding: 3px 8px; border-radius: 999px; white-space: nowrap; }

.big-emoji { font-size: 64px; line-height: 1; }
.result { border-radius: var(--radius); padding: 28px 20px; text-align: center; }
.result.good { background: linear-gradient(160deg, #24a148, #0e6027); }
.result.bad { background: linear-gradient(160deg, #da1e28, #750e13); }
.result.none { background: var(--panel); }
.result h1 { font-size: 34px; }
.result .pts { font-size: 22px; font-weight: 700; margin-top: 8px; }
.explain { background: var(--panel); border-left: 4px solid var(--brand); border-radius: 10px; padding: 14px 16px; line-height: 1.45; font-size: 15px; }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.error { color: #ff8389; min-height: 1.3em; font-size: 14px; }

/* big screen ------------------------------------------------------------ */
.screen {
  height: 100vh; overflow: hidden;
  display: flex; flex-direction: column;
  padding: 2.2vh 3vw;
  font-size: 1.6vh;
}
.screen .topbar { display: flex; justify-content: space-between; align-items: center; font-size: 2.2vh; }
.screen .topbar .pill { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: .5em 1.2em; font-weight: 600; }
.screen .stage { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-top: 2vh; }

.lobby { display: grid; grid-template-columns: auto 1fr; gap: 5vw; align-items: center; flex: 1; }
.lobby .qr { background: #fff; border-radius: 2vh; padding: 2vh; width: 48vh; height: 48vh; box-shadow: 0 2vh 6vh rgba(0, 0, 0, .4); }
.lobby .qr img { width: 100%; height: 100%; display: block; }
.lobby .joinurl { margin-top: 2vh; text-align: center; font-size: 3vh; font-weight: 700; word-break: break-all; }
.lobby h1 { font-size: 8vh; margin: 0; line-height: 1.05; }
.lobby h1 small { display: block; font-size: .45em; color: var(--muted); font-weight: 500; margin-top: 1vh; }
.lobby .count { font-size: 3.2vh; margin: 4vh 0 2vh; }
.lobby .count b { font-size: 6vh; color: var(--brand); margin-right: .3em; }
.chips { display: flex; flex-wrap: wrap; gap: 1vh; max-height: 36vh; overflow: hidden; align-content: flex-start; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: .7vh 1.6vh; font-size: 2.3vh; font-weight: 600; animation: pop .35s ease-out; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }

.q-screen { display: flex; flex-direction: column; flex: 1; min-height: 0; gap: 2.5vh; }
.q-head { display: flex; align-items: center; gap: 3vw; }
.q-head h1 { flex: 1; font-size: 4.6vh; line-height: 1.2; margin: 0; font-weight: 600; }
.ring { width: 14vh; height: 14vh; position: relative; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 9; }
.ring .track { stroke: var(--panel); }
.ring .prog { stroke: var(--brand); stroke-linecap: round; transition: stroke .3s; }
.ring.low .prog { stroke: var(--bad); }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 5.5vh; font-weight: 700; }
.answered-count { text-align: center; }
.answered-count b { display: block; font-size: 6vh; line-height: 1; }
.answered-count span { color: var(--muted); font-size: 2vh; }

.s-answers { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 2vh; min-height: 0; }
.s-answers.n3 .opt:last-child { grid-column: 1 / -1; }
.s-answers .opt {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 2vh;
  background: var(--c); border-radius: 1.6vh; padding: 2vh 3vh;
  font-size: 3.1vh; font-weight: 600; line-height: 1.25;
  box-shadow: 0 .6vh 0 rgba(0, 0, 0, .25);
  transition: opacity .4s, filter .4s;
}
.s-answers .opt .shape { font-size: 4vh; width: 5vh; }
.s-answers .opt .txt { flex: 1; position: relative; z-index: 1; }
.s-answers .opt .cnt { position: relative; z-index: 1; font-size: 4.5vh; font-weight: 700; min-width: 2ch; text-align: right; }
.s-answers .opt .bar { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(255, 255, 255, .16); width: 0; transition: width .9s cubic-bezier(.2, .8, .2, 1); }
.s-answers.revealed .opt:not(.correct) { opacity: .35; filter: grayscale(.6); }
.s-answers.revealed .opt.correct { outline: .5vh solid #fff; outline-offset: .3vh; }
.s-answers.revealed .opt.correct .shape::before { content: '✓'; }
.s-answers.tf .opt { justify-content: center; font-size: 5vh; }
.s-answers.tf .opt .txt { flex: none; }
.s-explain { font-size: 2.7vh; line-height: 1.4; background: var(--panel); border-left: .6vh solid var(--good); border-radius: 1.2vh; padding: 2vh 3vh; }
.s-explain b { color: #6fdc8c; }

.lb { flex: 1; display: flex; flex-direction: column; gap: 1.3vh; max-width: 1400px; width: 100%; margin: 0 auto; }
.lb h1 { font-size: 6vh; margin: 0 0 1vh; text-align: center; }
.lb-row { display: grid; grid-template-columns: 7vh 1fr auto; align-items: center; gap: 2vh; background: var(--panel); border: 1px solid var(--line); border-radius: 1.4vh; padding: 1.2vh 2.4vh; font-size: 3vh; animation: slidein .5s both; }
.lb-row .rk { font-weight: 700; color: var(--muted); }
.lb-row .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .sc { font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-row .mv { font-size: .6em; margin-left: .6em; color: #6fdc8c; }
.lb-row.top1 { background: linear-gradient(90deg, #8e6a00, var(--panel)); }
.lb-row.top2 { background: linear-gradient(90deg, #5d6878, var(--panel)); }
.lb-row.top3 { background: linear-gradient(90deg, #7a4a24, var(--panel)); }
@keyframes slidein { from { transform: translateX(-4vw); opacity: 0; } }

.podium { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.podium h1 { font-size: 7vh; margin: 0 0 4vh; }
.podium .steps { display: flex; align-items: flex-end; gap: 2vw; }
.podium .step { width: 22vw; text-align: center; animation: rise .9s cubic-bezier(.2, .8, .2, 1) both; }
.podium .step .who { font-size: 3.6vh; font-weight: 700; margin-bottom: 1vh; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium .step .pts { font-size: 2.4vh; color: var(--muted); margin-bottom: 1.5vh; }
.podium .step .block { border-radius: 1.4vh 1.4vh 0 0; display: grid; place-items: center; font-size: 10vh; font-weight: 700; }
.podium .p1 .block { height: 38vh; background: linear-gradient(#f1c21b, #8e6a00); }
.podium .p2 .block { height: 28vh; background: linear-gradient(#c1c7cd, #5d6878); }
.podium .p3 .block { height: 20vh; background: linear-gradient(#e0a370, #7a4a24); }
.podium .p1 { animation-delay: 1.2s; }
.podium .p2 { animation-delay: .6s; }
@keyframes rise { from { transform: translateY(40vh); opacity: 0; } }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -3vh; width: 1vh; height: 1.8vh; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

.fs-btn { position: fixed; right: 12px; bottom: 12px; opacity: .15; transition: opacity .2s; }
.fs-btn:hover { opacity: 1; }

/* host ------------------------------------------------------------------ */
.host { max-width: 1400px; margin: 0 auto; padding: 16px; }
.host header { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 16px; }
.host header .links { display: flex; gap: 8px; flex-wrap: wrap; }
.host .grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .host .grid { grid-template-columns: 1fr; } }
.host h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
.host .controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.host .phase { display: inline-block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; padding: 4px 10px; border-radius: 999px; background: var(--panel-2); }
.host .phase.question { background: var(--warn); color: #000; }
.host .phase.reveal { background: var(--good); }
.host .kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 16px 0; }
@media (max-width: 600px) { .host .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.kpi b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.host .cur-q { font-size: 18px; font-weight: 600; line-height: 1.35; margin: 4px 0 12px; }
.dist { display: grid; gap: 8px; }
.dist .row { display: grid; grid-template-columns: 28px 1fr 60px; gap: 10px; align-items: center; font-size: 14px; }
.dist .row .lbl { position: relative; background: var(--panel); border-radius: 8px; overflow: hidden; padding: 8px 10px; }
.dist .row .lbl i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--c); opacity: .55; transition: width .4s; }
.dist .row .lbl span { position: relative; }
.dist .row .tag { width: 28px; height: 28px; border-radius: 8px; background: var(--c); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.dist .row.correct .lbl { outline: 2px solid var(--good); }
.dist .row .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.current td { background: rgba(69, 137, 255, .12); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #6f6f6f; margin-right: 6px; }
.status-dot.on { background: var(--good); }
.meter { display: inline-block; width: 70px; height: 6px; border-radius: 3px; background: var(--panel-2); vertical-align: middle; margin-right: 6px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--good); }
.scroll { max-height: 520px; overflow: auto; }
.login { max-width: 380px; margin: 18vh auto; display: grid; gap: 12px; }
.conn { font-size: 12px; color: var(--muted); }
.conn.off { color: #ff8389; }

/* host tabs + question editor ------------------------------------------ */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 16px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--brand); }
.dirty-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); display: inline-block; }

.editor { display: grid; gap: 14px; max-width: 980px; margin: 0 auto; }
.editor-bar { position: sticky; top: 8px; z-index: 5; display: grid; gap: 12px; }
.editor-meta { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
@media (max-width: 640px) { .editor-meta { grid-template-columns: 1fr; } }
.editor label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.editor input[type=text], .editor input[type=number], .editor textarea { padding: 10px 12px; font-size: 15px; color: var(--text); }
.editor textarea { width: 100%; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, .06); resize: vertical; font: inherit; outline: none; }
.editor textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(69, 137, 255, .3); }
.editor-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.editor-actions #edStatus { margin-right: auto; font-size: 13px; }
.editor-lock { background: rgba(241, 194, 27, .12); border: 1px solid rgba(241, 194, 27, .5); color: #f7dd7a; border-radius: 10px; padding: 10px 12px; font-size: 14px; }

.ed-list { display: grid; gap: 12px; }
.ed-q { display: grid; gap: 12px; }
.ed-q.invalid { border-color: var(--bad); box-shadow: 0 0 0 2px rgba(218, 30, 40, .4); }
.ed-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.ed-num { font-weight: 700; font-size: 18px; min-width: 2.2ch; }
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 6px 10px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--panel-2); color: var(--text); }
.ed-time { display: inline-flex !important; grid-template-columns: none; align-items: center; gap: 6px !important; margin-left: auto; }
.ed-time input { width: 76px; padding: 6px 8px !important; }
.ed-tools { display: inline-flex; gap: 4px; }
.icon-btn { border: 1px solid var(--line); background: transparent; border-radius: 8px; width: 34px; height: 34px; display: inline-grid; place-items: center; font-size: 15px; color: var(--text); }
.icon-btn:hover:not(:disabled) { background: var(--panel-2); }
.icon-btn:disabled { opacity: .3; cursor: not-allowed; }
.icon-btn.danger:hover:not(:disabled) { background: var(--bad); border-color: var(--bad); }
.ed-opts { display: grid; gap: 8px; }
.ed-opt { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.ed-correct { width: 38px; height: 38px; border-radius: 10px; border: 2px solid var(--c); background: transparent; color: #fff; font-weight: 700; display: grid; place-items: center; }
.ed-correct.on { background: var(--good); border-color: var(--good); }
.ed-opt.is-correct input { border-color: var(--good); }
.ed-tf { display: flex; gap: 8px; }
.ed-tf button { flex: 1; padding: 12px; border-radius: 10px; border: 2px solid var(--line); background: transparent; font-weight: 700; }
.ed-tf button.on { background: var(--good); border-color: var(--good); }
.ed-hint { font-size: 12px; color: var(--muted); }
.ed-add { justify-self: center; }
.ed-empty { text-align: center; padding: 40px; }
.editor input[type=text], .editor input[type=number], .editor textarea { font-weight: 400; }
.editor .error:empty { display: none; }
