:root {
  --bg: #f5f7ff;
  --bg-2: #eef0ff;
  --surface: #ffffff;
  --ink: #1e1b4b;
  --ink-soft: #5b5f86;
  --line: #e2e5f5;
  --blue: #3b6cf6;
  --blue-dark: #2447c9;
  --lavender: #a78bfa;
  --lavender-soft: #ede9fe;
  --yellow: #ffc83d;
  --yellow-dark: #e0a800;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #e11d48;
  --red-soft: #ffe4e6;
  --brand-gradient: linear-gradient(120deg, #2447c9 0%, #7c3aed 55%, #ec4899 100%);
  --radius: 18px;
  --shadow: 0 10px 30px -12px rgba(49, 46, 129, 0.25);
  --shadow-sm: 0 4px 14px -6px rgba(49, 46, 129, 0.2);

  --opt-0: #3b6cf6;
  --opt-1: #8b5cf6;
  --opt-2: #f5b400;
  --opt-3: #10b981;
  --opt-4: #ec4899;
  --opt-5: #0ea5e9;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% -10%, #dfe6ff 0, transparent 45%),
    radial-gradient(circle at 110% 10%, #efe7ff 0, transparent 40%),
    var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }

.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app { max-width: 720px; margin: 0 auto; padding: 16px 16px 40px; }
.app.wide { max-width: 1180px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-logo {
  width: 40px; height: 40px; flex: none; border-radius: 12px; display: block;
  box-shadow: 0 6px 16px -6px rgba(124, 58, 237, 0.55);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-weight: 900; font-size: 1.25rem; letter-spacing: -0.02em; }
.brand-accent { background: var(--brand-gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-sub {
  margin-top: 3px; font-size: 0.68rem; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-soft);
}

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; border: 1px solid var(--line);
}
.card + .card { margin-top: 16px; }
.card h2, .card h3 { margin-top: 0; }

.screen { animation: enter 0.35s ease both; }
@keyframes enter { from { opacity: 0; transform: translateY(12px) scale(0.99); } to { opacity: 1; transform: none; } }

.center { text-align: center; }
.muted { color: var(--ink-soft); }
.small { font-size: 0.875rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grow { flex: 1; }

/* ---------- Form ---------- */
label.field { display: block; font-weight: 700; margin-bottom: 6px; font-size: 0.95rem; }
.input, select.input, textarea.input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line);
  background: #fbfbff; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(59, 108, 246, 0.15); }
textarea.input { resize: vertical; min-height: 80px; }
.input.code {
  text-transform: uppercase; letter-spacing: 0.3em; text-align: center; font-weight: 900; font-size: 1.6rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: 14px; border: 0; cursor: pointer; font-weight: 800;
  background: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--blue-dark);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s; text-decoration: none; user-select: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--blue-dark); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn.big { padding: 16px 24px; font-size: 1.15rem; width: 100%; }
.btn.yellow { background: var(--yellow); color: #3b2a00; box-shadow: 0 4px 0 var(--yellow-dark); }
.btn.light { background: var(--lavender-soft); color: #4c1d95; box-shadow: 0 4px 0 #d8ccfb; }
.btn.ghost { background: transparent; color: var(--ink-soft); box-shadow: none; padding: 8px 12px; }
.btn.ghost:hover { background: var(--bg-2); }
.btn.danger { background: var(--red); box-shadow: 0 4px 0 #9f1239; }
.btn.sm { padding: 8px 12px; font-size: 0.9rem; border-radius: 10px; }

/* ---------- Chips / badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  background: var(--bg-2); font-weight: 800; font-size: 0.8rem; color: var(--ink-soft);
}
.badge.blue { background: #dbe6ff; color: var(--blue-dark); }
.badge.purple { background: var(--lavender-soft); color: #5b21b6; }
.badge.yellow { background: #fff3c4; color: #7a5600; }
.badge.green { background: var(--green-soft); color: #166534; }
.badge.red { background: var(--red-soft); color: #9f1239; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 12px; border-radius: 999px; background: var(--surface); border: 2px solid var(--line);
  font-weight: 700; animation: pop 0.3s ease both; display: inline-flex; align-items: center; gap: 6px;
}
.chip.me { border-color: var(--blue); background: #eef3ff; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: #c7c9dd; }
.chip .dot.on { background: #22c55e; box-shadow: 0 0 0 3px #dcfce7; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Hero ---------- */
.hero { text-align: center; padding: 24px 8px 8px; }
.hero h1 { font-size: clamp(2rem, 7vw, 3rem); margin: 8px 0; letter-spacing: -0.03em; line-height: 1.05; }
.hero h1 .accent { white-space: nowrap; background: var(--brand-gradient); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero .emoji { font-size: 3rem; display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.hero-logo {
  width: 76px; height: 76px; border-radius: 22px; display: inline-block;
  box-shadow: 0 14px 30px -12px rgba(124, 58, 237, 0.6); animation: bob 2.4s ease-in-out infinite;
}
.stage-logo { width: 64px; height: 64px; border-radius: 18px; margin: 0 auto; display: block; box-shadow: 0 10px 24px -10px rgba(124, 58, 237, 0.55); }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-6deg); } }

.room-code {
  font-size: clamp(2.2rem, 9vw, 3.4rem); font-weight: 900; letter-spacing: 0.18em; color: var(--blue-dark);
  background: #eef3ff; border-radius: 16px; padding: 6px 16px; display: inline-block;
}

.waiting-dots span { animation: blink 1.4s infinite both; font-weight: 900; }
.waiting-dots span:nth-child(2) { animation-delay: 0.2s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

/* ---------- Question ---------- */
.q-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.timer {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: 1.6rem;
  background: conic-gradient(var(--blue) var(--p, 100%), var(--bg-2) 0); position: relative; flex: none;
}
.timer::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--surface); }
.timer span { position: relative; }
.timer.warn { background: conic-gradient(var(--red) var(--p, 100%), var(--bg-2) 0); color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }
.progress { height: 8px; border-radius: 99px; background: var(--bg-2); overflow: hidden; margin-bottom: 14px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), var(--lavender)); transition: width 0.25s linear; }

.q-text {
  font-size: clamp(1.25rem, 4.6vw, 1.75rem); font-weight: 900; line-height: 1.3; margin: 4px 0 16px;
  text-align: center; padding: 18px 14px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); overflow-wrap: anywhere;
}

.options { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 560px) { .options { grid-template-columns: 1fr 1fr; } }

.opt {
  --c: var(--opt-0);
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 72px;
  padding: 14px 16px; border-radius: 16px; border: 0; cursor: pointer; text-align: left;
  background: var(--c); color: #fff; font-weight: 800; font-size: 1.1rem;
  box-shadow: 0 5px 0 color-mix(in srgb, var(--c) 70%, #000); transition: transform 0.08s, box-shadow 0.08s, opacity 0.2s, filter 0.2s;
  overflow-wrap: anywhere;
}
.opt:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 color-mix(in srgb, var(--c) 70%, #000); }
.opt .letter {
  flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.25); font-weight: 900;
}
.opt[data-i="2"] { color: #3b2a00; }
.opt[data-i="2"] .letter { background: rgba(0, 0, 0, 0.1); }
.opt .check {
  margin-left: auto; flex: none; width: 28px; height: 28px; border-radius: 8px; border: 3px solid rgba(255, 255, 255, 0.8);
  display: grid; place-items: center; font-size: 1rem;
}
.opt.selected { outline: 4px solid var(--ink); outline-offset: 2px; }
.opt.selected .check::after { content: "✓"; }
.opt:disabled { cursor: default; }
.opt.dim { opacity: 0.35; filter: grayscale(0.4); }
.opt.correct { outline: 4px solid var(--green); outline-offset: 2px; }
.opt .count { margin-left: auto; background: rgba(255, 255, 255, 0.3); padding: 2px 10px; border-radius: 99px; font-size: 0.95rem; }

.submitted {
  text-align: center; padding: 26px 16px; border-radius: var(--radius); background: var(--lavender-soft);
  font-weight: 800; font-size: 1.15rem; margin-top: 14px; animation: enter 0.3s ease both;
}

/* ---------- Result ---------- */
.verdict { text-align: center; border-radius: var(--radius); padding: 22px 16px; color: #fff; box-shadow: var(--shadow); }
.verdict.ok { background: linear-gradient(135deg, #22c55e, #16a34a); }
.verdict.bad { background: linear-gradient(135deg, #fb7185, #e11d48); }
.verdict.none { background: linear-gradient(135deg, #94a3b8, #64748b); }
.verdict .big { font-size: 2rem; font-weight: 900; }
.verdict .gain { font-size: 2.6rem; font-weight: 900; animation: pop 0.4s ease both; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat { background: var(--surface); border-radius: 14px; padding: 12px 8px; text-align: center; border: 1px solid var(--line); }
.stat b { display: block; font-size: 1.5rem; font-weight: 900; }
.stat span { font-size: 0.8rem; color: var(--ink-soft); font-weight: 700; }

.answer-key { display: grid; gap: 8px; }
.answer-key .ak {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--bg-2);
  font-weight: 700; position: relative; overflow: hidden;
}
.answer-key .ak .bar { position: absolute; inset: 0 auto 0 0; background: rgba(59, 108, 246, 0.12); z-index: 0; transition: width 0.6s ease; }
.answer-key .ak > *:not(.bar) { position: relative; z-index: 1; }
.answer-key .ak.ok { background: var(--green-soft); color: #14532d; }
.answer-key .ak.ok .bar { background: rgba(22, 163, 74, 0.18); }
.answer-key .ak .n { margin-left: auto; font-variant-numeric: tabular-nums; }
.answer-key .letter { width: 28px; height: 28px; flex: none; border-radius: 8px; display: grid; place-items: center; color: #fff; font-weight: 900; }

/* ---------- Leaderboard ---------- */
.lb { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.lb li {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 14px; background: var(--bg-2);
  font-weight: 700; animation: enter 0.3s ease both;
}
.lb li.me { background: #dbe6ff; outline: 2px solid var(--blue); }
.lb .rk { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; font-weight: 900; background: var(--surface); flex: none; }
.lb li:nth-child(1) .rk { background: #ffe07a; }
.lb li:nth-child(2) .rk { background: #e2e8f0; }
.lb li:nth-child(3) .rk { background: #fed7aa; }
.lb .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb .sc { font-weight: 900; font-variant-numeric: tabular-nums; }
.lb .sub { font-size: 0.75rem; color: var(--ink-soft); font-weight: 700; }

/* ---------- Podium ---------- */
.final-title { text-align: center; margin: 10px 0 4px; font-size: clamp(1.8rem, 7vw, 2.6rem); font-weight: 900; letter-spacing: -0.02em; }
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 10px; margin: 24px 0 12px; }
.pod { text-align: center; animation: rise 0.8s cubic-bezier(0.2, 0.9, 0.3, 1.3) both; }
.pod.p1 { animation-delay: 0.9s; }
.pod.p2 { animation-delay: 0.45s; }
.pod.p3 { animation-delay: 0.1s; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.pod .avatar {
  width: 58px; height: 58px; margin: 0 auto 6px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 900; font-size: 1.5rem; color: #fff; box-shadow: var(--shadow-sm); border: 3px solid #fff;
}
.pod.p1 .avatar { width: 74px; height: 74px; font-size: 2rem; }
.pod .crown { font-size: 2rem; display: block; animation: bob 2s ease-in-out infinite; }
.pod .name { font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px; }
.pod .pts { font-weight: 800; color: var(--ink-soft); font-size: 0.9rem; margin-bottom: 6px; }
.pod .block {
  border-radius: 16px 16px 6px 6px; display: grid; place-items: center; color: #fff; font-weight: 900; font-size: 2.2rem;
  box-shadow: var(--shadow);
}
.pod.p1 .block { height: 150px; background: linear-gradient(180deg, #ffd54a, #f5a800); color: #5a3b00; }
.pod.p2 .block { height: 110px; background: linear-gradient(180deg, #cbd5e1, #94a3b8); }
.pod.p3 .block { height: 80px; background: linear-gradient(180deg, #fdba74, #ea8a3c); }
.pod.empty { visibility: hidden; }

.me-final { text-align: center; font-weight: 800; margin: 8px 0 16px; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); }
.toast {
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 14px; font-weight: 700; box-shadow: var(--shadow);
  animation: enter 0.25s ease both;
}
.toast.error { background: var(--red); }
.toast.ok { background: var(--green); }

.conn { position: fixed; top: 10px; right: 10px; z-index: 40; }

/* ---------- Admin ---------- */
.tabs { display: flex; gap: 6px; background: var(--surface); padding: 6px; border-radius: 14px; box-shadow: var(--shadow-sm); border: 1px solid var(--line); }
.tab { border: 0; background: transparent; padding: 8px 14px; border-radius: 10px; font-weight: 800; cursor: pointer; color: var(--ink-soft); }
.tab.active { background: var(--blue); color: #fff; }

.set-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.set-card h3 { margin: 0 0 4px; overflow-wrap: anywhere; }

.q-item { display: flex; gap: 12px; padding: 14px; border-radius: 14px; background: var(--bg-2); align-items: flex-start; }
.q-item + .q-item { margin-top: 10px; }
.q-item .num { width: 34px; height: 34px; flex: none; border-radius: 10px; display: grid; place-items: center; background: var(--surface); font-weight: 900; }
.q-item .body { flex: 1; min-width: 0; }
.q-item .body .t { font-weight: 800; overflow-wrap: anywhere; }
.q-item .opts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.q-item .opts span { padding: 3px 10px; border-radius: 8px; background: var(--surface); font-size: 0.85rem; font-weight: 700; }
.q-item .opts span.ok { background: var(--green-soft); color: #166534; }
.q-item .actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

.opt-edit { display: flex; gap: 8px; align-items: center; }
.opt-edit + .opt-edit { margin-top: 8px; }
.opt-edit input[type="radio"], .opt-edit input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--green); flex: none; }

.host-grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 960px) { .host-grid { grid-template-columns: 320px 1fr; } }
.qr { display: grid; place-items: center; }
.qr svg { width: 180px; height: 180px; }
.link-box { display: flex; gap: 6px; }
.link-box input { font-size: 0.85rem; }

.seg { display: inline-flex; background: var(--bg-2); border-radius: 12px; padding: 4px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 9px; font-weight: 800; cursor: pointer; color: var(--ink-soft); }
.seg button.active { background: var(--surface); color: var(--blue-dark); box-shadow: var(--shadow-sm); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.tbl th, table.tbl td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
.tbl-wrap { overflow-x: auto; }

dialog {
  border: 0; border-radius: var(--radius); padding: 0; width: min(640px, calc(100vw - 24px)); box-shadow: 0 30px 80px -20px rgba(30, 27, 75, 0.45);
  max-height: calc(100dvh - 24px);
}
dialog::backdrop { background: rgba(30, 27, 75, 0.45); backdrop-filter: blur(2px); }
dialog .dlg { padding: 20px; }
dialog h3 { margin-top: 0; }

.host-grid aside .room-code { font-size: 2.3rem; letter-spacing: 0.12em; padding: 6px 12px; max-width: 100%; }
