:root {
  --bg: #f5f3ee;
  --card: #ffffff;
  --ink: #1f2a24;
  --muted: #66736c;
  --line: #dfe5df;
  --accent: #2f6b4f;
  --accent-soft: #e4efe8;
  --danger: #a33a3a;
  --shadow: 0 20px 50px rgba(31, 42, 36, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
button, input { font: inherit; }
button { cursor: pointer; }

.wrap {
  width: min(720px, calc(100% - 28px));
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 0;
}
.card, .host-card, .leaderboard-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.card { width: 100%; padding: 28px; }
.eyebrow { letter-spacing: .16em; font-size: .78rem; font-weight: 800; color: var(--accent); }
h1 { margin: .35rem 0 .6rem; font-size: clamp(2rem, 5vw, 3.5rem); line-height: 1; }
h2 { font-size: clamp(1.7rem, 5vw, 2.7rem); line-height: 1.12; }
.lead { color: var(--muted); font-size: 1.05rem; }
.stack { display: grid; gap: 12px; margin-top: 24px; }
input {
  width: 100%; padding: 16px 18px; border-radius: 14px;
  border: 1px solid var(--line); background: white;
}
button {
  border: 1px solid var(--line); border-radius: 14px;
  padding: 14px 18px; background: white; color: var(--ink);
  font-weight: 750;
}
button:hover { transform: translateY(-1px); }
.primary { background: var(--accent); color: white; border-color: var(--accent); }
.ghost { background: transparent; }
.danger { color: white; background: var(--danger); border-color: var(--danger); }
.error { color: var(--danger); }
.topline { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
#score { font-weight: 800; color: var(--accent); }
.answers { display: grid; gap: 12px; margin-top: 22px; }
.answer-btn { text-align: left; padding: 17px 18px; font-size: 1.02rem; }
.answer-btn.selected { outline: 3px solid var(--accent); }
.answer-btn.correct { background: var(--accent-soft); border-color: var(--accent); }
.feedback { margin-top: 18px; color: var(--muted); font-weight: 650; }

.host-body { min-height: 100vh; background: #eef2ee; }
.host-wrap { width: min(1400px, calc(100% - 48px)); margin: 0 auto; padding: 32px 0; }
.host-topline { display:flex; align-items:center; justify-content:space-between; gap:30px; }
.host-topline h1 { font-size: clamp(2.5rem, 4vw, 5rem); }
.pill { padding: 10px 16px; border-radius: 999px; background: white; border:1px solid var(--line); font-weight:800; }
.host-card { padding: 36px; min-height: 55vh; }
.host-card h2 { max-width: 1100px; font-size: clamp(2.2rem, 4vw, 4.8rem); margin-top: 0; }
.host-answers { display:grid; grid-template-columns:1fr 1fr; gap:16px; }
.host-answer { display:flex; align-items:center; gap:16px; padding:20px; border:1px solid var(--line); border-radius:18px; font-size:1.35rem; }
.host-answer span { width:44px; height:44px; border-radius:12px; display:grid; place-items:center; background:var(--accent-soft); font-weight:900; }
.host-meta { margin-top:24px; color:var(--muted); font-size:1.2rem; }
.leaderboard-card { margin-top:20px; padding:24px 28px; }
.leaderboard { margin:0; padding-left:24px; }
.leaderboard li { padding:8px 0; display:flex; justify-content:space-between; gap:20px; }
.result-row { margin: 16px 0; }
.result-head { display:flex; justify-content:space-between; gap:20px; font-size:1.2rem; }
.bar { height:20px; background:#edf0ed; border-radius:999px; overflow:hidden; margin:7px 0; }
.bar-fill { height:100%; background:#9aa79f; }
.result-row.is-correct .bar-fill { background:var(--accent); }
.result-row.is-correct .result-head { font-weight:850; }

.admin-wrap { width:min(850px, calc(100% - 28px)); }
.admin-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; margin-top:24px; }
.admin-state { padding:14px 16px; border-radius:12px; background:var(--accent-soft); margin-top:18px; font-weight:750; }
.admin-note { margin-top:20px; color:var(--muted); }
code { background:#eef0ee; padding:2px 6px; border-radius:6px; }

@media (max-width: 760px) {
  .host-answers, .admin-grid { grid-template-columns:1fr; }
  .host-wrap { width:min(100% - 20px, 1400px); }
  .host-card { padding:22px; }
}

.avatar-heading { font-weight: 850; margin: 4px 0 10px; }
.avatar-picker { display:grid; grid-template-columns:repeat(4, 1fr); gap:9px; }
.avatar-choice { min-height:82px; padding:8px 5px; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:5px; font-size:.75rem; line-height:1.1; }
.avatar-choice .avatar-emoji { font-size:2rem; line-height:1; }
.avatar-choice.selected { outline:3px solid var(--accent); background:var(--accent-soft); }
.join-hint { color:var(--muted); font-size:.85rem; margin-bottom:0; }
.player-identity { display:flex; align-items:center; gap:10px; padding:10px 12px; margin-bottom:18px; border-radius:14px; background:var(--accent-soft); }
.identity-avatar { font-size:2.2rem; line-height:1; }
.player-identity strong { display:block; }
.role-badge, .mini-role { display:inline-block; margin-left:7px; padding:2px 6px; border-radius:999px; background:var(--accent); color:#fff; font-size:.62rem; letter-spacing:.06em; text-transform:uppercase; vertical-align:middle; }
.leader-name { display:flex; align-items:center; gap:8px; }
.leader-avatar { font-size:1.35rem; }
.mini-role { font-size:.55rem; margin-left:2px; }

@media (max-width: 520px) {
  .avatar-picker { grid-template-columns:repeat(3, 1fr); }
}

/* v3: tydligare avatarval */
.avatar-picker { margin-top: 8px; }
.avatar-choice { cursor:pointer; border:2px solid #d8ddd8; background:#fff; color:inherit; }
.avatar-choice:hover { transform:translateY(-1px); }
.avatar-choice.selected { border-color:var(--accent); outline:3px solid var(--accent); outline-offset:1px; background:var(--accent-soft); }
.avatar-choice[aria-pressed="true"]::after { content:"✓ vald"; font-size:.68rem; font-weight:900; }

/* v4: tidsgränser, hostbilder och bonusfrågor */
.host-status-group { display:flex; align-items:center; gap:12px; flex-wrap:wrap; justify-content:flex-end; }
.bonus-pill { background:#fff0c7; border-color:#e6c45d; color:#684b00; }
.host-timer { width:92px; height:92px; border-radius:50%; display:grid; place-items:center; align-content:center; background:#fff; border:5px solid var(--accent); box-shadow:var(--shadow); font-weight:950; line-height:.8; }
.host-timer span { font-size:2.4rem; }
.host-timer small { font-size:.7rem; margin-top:8px; color:var(--muted); }
.host-timer.urgent { border-color:#b8463c; animation:stressPulse .65s infinite alternate; }
.host-timer.urgent span { color:#b8463c; }
.host-timer-bar,.player-timer { height:12px; border-radius:999px; overflow:hidden; background:#e7ebe7; margin-top:22px; }
.host-timer-fill,.player-timer-fill { height:100%; width:100%; background:var(--accent); transition:width .45s linear; }
.host-timer-bar.urgent .host-timer-fill,.player-timer.urgent .player-timer-fill { background:#b8463c; }
.time-urgent { animation:tinyShake .42s infinite alternate; }
.host-question-layout { display:grid; grid-template-columns:minmax(0,1fr) minmax(280px,38%); gap:30px; align-items:start; }
.host-question-main { min-width:0; }
.question-image-wrap { margin:0; border-radius:20px; overflow:hidden; background:#eef0ee; min-height:240px; max-height:52vh; }
.question-image { width:100%; height:100%; max-height:52vh; object-fit:cover; display:block; }
.rank { display:inline-grid; place-items:center; width:28px; height:28px; border-radius:50%; background:var(--accent-soft); font-weight:900; }
.leaderboard-card h3 { margin:.2rem 0 1rem; font-size:1.5rem; }
.player-timer { height:9px; margin-top:14px; }
@keyframes stressPulse { from { transform:scale(1); box-shadow:0 0 0 0 rgba(184,70,60,.2); } to { transform:scale(1.08); box-shadow:0 0 0 12px rgba(184,70,60,0); } }
@keyframes tinyShake { from { transform:translateX(-1px); } to { transform:translateX(1px); } }
@media (max-width:900px) { .host-question-layout { grid-template-columns:1fr; } .question-image-wrap { max-height:36vh; } .question-image { max-height:36vh; } }


/* v5: QR-kod i vänteläget */
.waiting-qr { text-align:center; margin:28px auto 8px; }
.waiting-qr[hidden] { display:none !important; }
.waiting-qr img { width:min(340px, 55vw); height:auto; border-radius:20px; background:#fff; padding:14px; box-shadow:var(--shadow); }
.waiting-qr p { margin:16px 0 0; font-size:1.35rem; font-weight:800; }


/* v6: statisk QR-panel synlig direkt vid sidladdning */
.join-qr-panel {
  text-align:center;
  margin-bottom:20px;
  padding:30px;
  background:var(--card);
  border:1px solid var(--line);
  border-radius:24px;
  box-shadow:var(--shadow);
}
.join-qr-panel[hidden] { display:none !important; }
.join-qr-panel h2 { margin:.4rem 0 1.2rem; font-size:clamp(2rem,3.2vw,3.8rem); }
.join-qr-panel img {
  display:block;
  width:min(360px,50vw);
  height:auto;
  margin:0 auto;
  padding:14px;
  border-radius:20px;
  background:#fff;
}
.join-qr-panel p { margin:16px 0 0; font-size:1.25rem; font-weight:800; color:var(--muted); }

/* v7: registrerade deltagare på vänteskärmen */
.waiting-player-count {
  display:inline-flex;
  align-items:baseline;
  gap:10px;
  margin-top:18px;
  padding:12px 20px;
  border-radius:999px;
  background:var(--accent-soft);
  color:var(--accent);
}
.waiting-player-count strong { font-size:2rem; line-height:1; }
.waiting-player-count span { font-size:1rem; font-weight:850; text-transform:uppercase; letter-spacing:.05em; }

/* v9: hidden must win over component display rules */
[hidden] { display: none !important; }
.host-timer[hidden],
.host-timer-bar[hidden] { display: none !important; }

/* v10: timer markup is absent until a question is active */
#hostTimerSlot[hidden] { display:none !important; }

/* v11: tvåfasfrågor och uttryckligt avatarval */
.host-timer.preview { border-color:#8b7b45; }
.host-timer.preview span { color:#6d5f31; }
.avatar-choice:not(.selected) { outline:none; }
.answer-btn:disabled { cursor:default; }

/* v12: tydlig svarsåterkoppling på mobilen */
.answer-btn.chosen-correct {
  background:#dff3e4;
  border-color:#27834a;
  color:#153c25;
  outline:3px solid #27834a;
}
.answer-btn.chosen-wrong {
  background:#f8dddd;
  border-color:#b43c3c;
  color:#5d1e1e;
  outline:3px solid #b43c3c;
}
.answer-btn.muted {
  background:#ecefed;
  border-color:#d5dad6;
  color:#8a928c;
  opacity:.78;
}
.answer-btn.answer-pending {
  opacity:.65;
}
.answer-btn:disabled { transform:none; }

/* v13: result + leaderboard layout and admin navigation */
.host-stage { display:block; }
.host-stage .leaderboard-card[hidden] { display:none !important; }
.host-stage.results-mode {
  display:grid;
  grid-template-columns:minmax(0, 1.7fr) minmax(320px, .8fr);
  gap:20px;
  align-items:start;
}
.host-stage.results-mode .host-card { min-height:0; }
.host-stage.results-mode .leaderboard-card { margin-top:0; position:sticky; top:20px; }
.host-stage.results-mode .host-question-layout { grid-template-columns:1fr; }
.host-stage.results-mode .question-image-wrap { display:none !important; }
.host-stage.results-mode .host-card h2 { font-size:clamp(1.9rem, 3vw, 3.5rem); }
.host-stage.results-mode .host-answers { display:block; }
.host-stage.results-mode .result-row { margin:12px 0; }
.leaderboard-card .leaderboard { padding-left:0; list-style:none; }
.leaderboard-card .leaderboard li { border-bottom:1px solid var(--line); }
.admin-grid-main { grid-template-columns:1fr 1.4fr; }
.admin-grid-main .danger { grid-column:1 / -1; }
.admin-grid-main button:disabled { opacity:.45; cursor:not-allowed; }

@media (max-width:1000px) {
  .host-stage.results-mode { grid-template-columns:1fr; }
  .host-stage.results-mode .leaderboard-card { position:static; }
}

/* v15 – XML editor */
.button-link{display:inline-flex;align-items:center;justify-content:center;text-decoration:none;box-sizing:border-box}
.editor-wrap{max-width:1180px}
.editor-header-actions{display:flex;gap:.7rem;align-items:center;flex-wrap:wrap}
.editor-message{min-height:1.5rem;margin-top:.8rem;font-weight:700}
.editor-message.success{color:#176b35}.editor-message.error{color:#a32222}
.muted-text{opacity:.72}.editor-grid-2,.editor-grid-4{display:grid;gap:.8rem;margin:.8rem 0}
.editor-grid-2{grid-template-columns:repeat(2,minmax(0,1fr))}.editor-grid-4{grid-template-columns:repeat(4,minmax(0,1fr))}
.editor-wrap label{display:flex;flex-direction:column;gap:.35rem;font-weight:700}
.editor-wrap input,.editor-wrap textarea,.editor-wrap select{width:100%;box-sizing:border-box;padding:.72rem .8rem;border:1px solid rgba(0,0,0,.18);border-radius:12px;background:#fff;color:#111;font:inherit}
.editor-wrap textarea{resize:vertical}.questions-editor{display:grid;gap:1rem;margin-top:1rem}
.question-editor-card{border:1px solid rgba(0,0,0,.12);border-radius:18px;padding:1rem;background:rgba(255,255,255,.58)}
.question-editor-top,.answers-editor-head{display:flex;justify-content:space-between;gap:1rem;align-items:center;margin-bottom:.8rem}
.question-number{font-size:1.15rem;font-weight:900}.question-editor-actions{display:flex;gap:.4rem}
.answer-editor-list{display:grid;gap:.55rem}.answer-editor-row{display:grid;grid-template-columns:70px 90px minmax(0,1fr) 44px;gap:.55rem;align-items:center}
.correct-choice{flex-direction:row!important;align-items:center!important;gap:.35rem!important}.correct-choice input{width:auto!important}
.answer-id-input{text-align:center;font-weight:800}.danger-soft{background:#fff0f0;color:#8d1515;border:1px solid #e7b4b4}
@media(max-width:760px){.editor-grid-2,.editor-grid-4{grid-template-columns:1fr}.answer-editor-row{grid-template-columns:58px 82px 1fr}.answer-editor-row button{grid-column:3}.topline{align-items:flex-start}.editor-header-actions{width:100%}}
\n\n/* v16: host layout always fits one projector/TV viewport */\n.host-body {\n  height: 100vh;\n  height: 100dvh;\n  min-height: 0;\n  overflow: hidden;\n}\n\n.host-wrap {\n  width: min(1600px, calc(100% - 32px));\n  height: 100vh;\n  height: 100dvh;\n  margin: 0 auto;\n  padding: clamp(10px, 1.5vh, 18px) 0;\n  display: grid;\n  grid-template-rows: auto minmax(0, 1fr);\n  gap: clamp(8px, 1.2vh, 14px);\n  overflow: hidden;\n}\n\n.host-topline {\n  min-height: 0;\n  gap: 18px;\n}\n.host-topline > div:first-child { min-width: 0; }\n.host-topline .eyebrow { font-size: clamp(.58rem, 1.05vh, .76rem); }\n.host-topline h1 {\n  margin: .15rem 0 0;\n  font-size: clamp(1.55rem, 3.2vh, 3rem);\n  line-height: .98;\n  white-space: nowrap;\n  overflow: hidden;\n  text-overflow: ellipsis;\n}\n.host-status-group { flex-wrap: nowrap; gap: 8px; }\n.pill { padding: clamp(6px, .8vh, 10px) 12px; font-size: clamp(.72rem, 1.35vh, .95rem); }\n.host-timer {\n  width: clamp(58px, 8vh, 76px);\n  height: clamp(58px, 8vh, 76px);\n  border-width: 4px;\n}\n.host-timer span { font-size: clamp(1.55rem, 3vh, 2.1rem); }\n.host-timer small { margin-top: 5px; font-size: .58rem; }\n\n/* Waiting screen: QR panel alone fills the available viewport. */\n.join-qr-panel {\n  align-self: stretch;\n  min-height: 0;\n  margin: 0;\n  padding: clamp(14px, 2vh, 24px);\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  overflow: hidden;\n}\n.join-qr-panel h2 {\n  margin: .2rem 0 clamp(6px, 1vh, 12px);\n  font-size: clamp(1.6rem, 3.4vh, 3rem);\n}\n.join-qr-panel img {\n  width: auto;\n  height: min(48vh, 440px);\n  max-width: 48vw;\n  aspect-ratio: 1;\n  object-fit: contain;\n  padding: clamp(7px, 1vh, 12px);\n}\n.join-qr-panel p { margin: clamp(6px, 1vh, 12px) 0 0; font-size: clamp(.9rem, 1.8vh, 1.2rem); }\n.waiting-player-count { margin-top: clamp(7px, 1vh, 12px); padding: 8px 16px; }\n.waiting-player-count strong { font-size: clamp(1.4rem, 2.5vh, 1.9rem); }\n\n.host-stage { min-height: 0; height: 100%; overflow: hidden; }\n.host-stage[hidden] { display: none !important; }\n.host-card {\n  height: 100%;\n  min-height: 0;\n  padding: clamp(14px, 2vh, 26px);\n  display: grid;\n  grid-template-rows: minmax(0, 1fr) auto auto;\n  gap: clamp(6px, .9vh, 12px);\n  overflow: hidden;\n}\n.host-question-layout {\n  min-height: 0;\n  height: 100%;\n  grid-template-columns: minmax(0, 1.35fr) minmax(220px, .65fr);\n  gap: clamp(14px, 2vw, 26px);\n  align-items: stretch;\n  overflow: hidden;\n}\n.host-question-main {\n  min-height: 0;\n  display: flex;\n  flex-direction: column;\n  overflow: hidden;\n}\n.host-card h2 {\n  max-width: none;\n  margin: 0 0 clamp(8px, 1.2vh, 14px);\n  font-size: clamp(1.65rem, 4.2vh, 3.8rem);\n  line-height: 1.04;\n  flex: 0 0 auto;\n}\n.host-answers {\n  min-height: 0;\n  flex: 1 1 auto;\n  grid-template-columns: 1fr 1fr;\n  grid-auto-rows: minmax(0, 1fr);\n  gap: clamp(8px, 1.2vh, 14px);\n  overflow: hidden;\n}\n.host-answer {\n  min-height: 0;\n  gap: clamp(8px, 1vw, 14px);\n  padding: clamp(9px, 1.45vh, 16px);\n  border-radius: 14px;\n  font-size: clamp(.95rem, 2vh, 1.3rem);\n  line-height: 1.12;\n}\n.host-answer span {\n  flex: 0 0 auto;\n  width: clamp(30px, 4.5vh, 42px);\n  height: clamp(30px, 4.5vh, 42px);\n  border-radius: 10px;\n}\n.question-image-wrap {\n  min-height: 0;\n  height: 100%;\n  max-height: none;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  border-radius: 16px;\n}\n.question-image {\n  width: 100%;\n  height: 100%;\n  max-height: 100%;\n  object-fit: contain;\n}\n.host-meta {\n  margin: 0;\n  max-height: 11vh;\n  overflow: hidden;\n  font-size: clamp(.8rem, 1.65vh, 1.05rem);\n  line-height: 1.2;\n}\n.host-timer-bar { height: clamp(7px, 1vh, 10px); margin: 0; }\n\n/* Result mode: answer bars and leaderboard always share the same remaining height. */\n.host-stage.results-mode {\n  height: 100%;\n  min-height: 0;\n  grid-template-columns: minmax(0, 1.6fr) minmax(260px, .7fr);\n  gap: clamp(10px, 1.2vw, 18px);\n  align-items: stretch;\n  overflow: hidden;\n}\n.host-stage.results-mode .host-card,\n.host-stage.results-mode .leaderboard-card { height: 100%; min-height: 0; overflow: hidden; }\n.host-stage.results-mode .host-card { padding: clamp(12px, 1.7vh, 22px); }\n.host-stage.results-mode .host-question-layout { height: auto; min-height: 0; }\n.host-stage.results-mode .host-question-main { overflow: hidden; }\n.host-stage.results-mode .host-card h2 {\n  margin-bottom: clamp(5px, .7vh, 9px);\n  font-size: clamp(1.25rem, 2.7vh, 2.3rem);\n  line-height: 1.06;\n}\n.host-stage.results-mode .host-answers {\n  display: grid;\n  grid-template-columns: 1fr;\n  grid-auto-rows: auto;\n  gap: clamp(3px, .45vh, 6px);\n  overflow: hidden;\n}\n.host-stage.results-mode .result-row { margin: 0; }\n.host-stage.results-mode .result-head {\n  gap: 10px;\n  font-size: clamp(.78rem, 1.55vh, 1.02rem);\n  line-height: 1.08;\n}\n.host-stage.results-mode .bar { height: clamp(7px, .9vh, 11px); margin: 3px 0 1px; }\n.host-stage.results-mode .result-row small { font-size: clamp(.62rem, 1.05vh, .75rem); }\n.host-stage.results-mode .host-meta { max-height: 8vh; font-size: clamp(.72rem, 1.35vh, .92rem); }\n.leaderboard-card {\n  margin: 0;\n  padding: clamp(12px, 1.7vh, 20px);\n}\n.host-stage.results-mode .leaderboard-card { position: static; top: auto; }\n.leaderboard-card h3 { margin: 0 0 clamp(5px, .8vh, 10px); font-size: clamp(1.05rem, 2.2vh, 1.45rem); }\n.leaderboard-card .leaderboard { height: calc(100% - 2rem); overflow: hidden; }\n.leaderboard-card .leaderboard li {\n  min-height: 0;\n  padding: clamp(4px, .75vh, 8px) 0;\n  font-size: clamp(.72rem, 1.45vh, .95rem);\n  line-height: 1.05;\n}\n.rank { width: clamp(20px, 2.9vh, 26px); height: clamp(20px, 2.9vh, 26px); font-size: .78em; }\n.leader-avatar { font-size: clamp(1rem, 2vh, 1.25rem); }\n.leader-name { gap: clamp(4px, .55vw, 8px); min-width: 0; }\n\n/* Short-height laptops/projectors: compress further rather than scroll. */\n@media (max-height: 760px) {\n  .host-wrap { padding: 8px 0; gap: 7px; }\n  .host-topline h1 { font-size: clamp(1.35rem, 2.8vh, 2rem); }\n  .host-card { padding: 12px 16px; }\n  .host-card h2 { font-size: clamp(1.35rem, 3.8vh, 2.7rem); }\n  .host-answer { padding: 8px 11px; font-size: clamp(.82rem, 1.8vh, 1.05rem); }\n  .host-meta { max-height: 8vh; }\n  .join-qr-panel img { height: min(44vh, 330px); }\n}\n\n@media (max-width: 1000px) {\n  .host-stage.results-mode { grid-template-columns: minmax(0, 1.45fr) minmax(230px, .65fr); }\n}\n

/* v17: subtle fireworks on final screen */
.fireworks-layer{
  position:fixed;
  inset:0;
  z-index:50;
  pointer-events:none;
  overflow:hidden;
}
.firework-burst{
  position:absolute;
  width:1px;
  height:1px;
}
.firework-burst .spark{
  position:absolute;
  left:0;
  top:0;
  width:7px;
  height:7px;
  border-radius:50%;
  background:currentColor;
  box-shadow:0 0 10px currentColor;
  opacity:0;
  animation:quizFirework 1.25s cubic-bezier(.15,.7,.25,1) var(--delay,0ms) forwards;
}
.spark-0{color:#d39b2d}
.spark-1{color:#b54a59}
.spark-2{color:#4c7d67}
.spark-3{color:#5c6fa8}
.spark-4{color:#a05d9e}

@keyframes quizFirework{
  0%{transform:translate(0,0) scale(.2);opacity:0}
  12%{opacity:1}
  72%{opacity:1}
  100%{transform:translate(var(--dx),var(--dy)) scale(.55);opacity:0}
}

@media (prefers-reduced-motion: reduce){
  .fireworks-layer{display:none!important}
}


/* v19: fullscreen final leaderboard */
body.final-mode {
  overflow:hidden;
}

body.final-mode .host-wrap{
  width:100%;
  max-width:none;
  height:100dvh;
  padding:clamp(12px,2vh,24px);
  display:grid;
  grid-template-rows:auto 1fr;
  gap:clamp(8px,1.5vh,16px);
}

body.final-mode .host-topline{
  min-height:0;
}

body.final-mode .host-topline > div:first-child .eyebrow{
  display:none;
}

body.final-mode #quizTitle{
  font-size:clamp(2rem,4vw,4.5rem);
  margin:0;
}

body.final-mode #hostStage{
  display:block !important;
  min-height:0;
  height:100%;
}

body.final-mode #hostContent{
  display:none !important;
}

body.final-mode #leaderboardCard{
  display:flex !important;
  flex-direction:column;
  height:100%;
  margin:0;
  padding:clamp(22px,3vh,40px) clamp(28px,4vw,64px);
  border-radius:clamp(20px,2vw,32px);
}

body.final-mode #leaderboardCard h3{
  text-align:center;
  font-size:clamp(2.4rem,5vw,5.8rem);
  margin:0 0 clamp(12px,2vh,24px);
}

body.final-mode .leaderboard{
  flex:1;
  display:grid;
  align-content:center;
  gap:clamp(6px,1.2vh,16px);
  overflow:hidden;
}

body.final-mode .leaderboard li{
  font-size:clamp(1.5rem,3vw,3.2rem);
  padding:clamp(8px,1vh,16px) clamp(10px,1.2vw,20px);
  border-bottom:1px solid var(--line);
}

body.final-mode .leader-avatar{
  font-size:1.35em;
}

body.final-mode .rank{
  width:1.6em;
  height:1.6em;
  font-size:.75em;
}

body.final-mode #hostStatus{
  font-size:clamp(1rem,1.5vw,1.4rem);
}

/* Larger finale fireworks */
body.final-mode .fireworks-layer{
  z-index:999;
}

body.final-mode .firework-burst .spark{
  width:12px;
  height:12px;
  box-shadow:
    0 0 14px currentColor,
    0 0 28px currentColor;
}

@keyframes quizFirework{
  0%{transform:translate(0,0) scale(.15);opacity:0}
  8%{opacity:1}
  58%{opacity:1}
  100%{transform:translate(var(--dx),var(--dy)) scale(.7);opacity:0}
}

@media (max-width:760px){
  body.final-mode #leaderboardCard{
    padding:18px 16px;
  }
  body.final-mode #leaderboardCard h3{
    font-size:clamp(2rem,10vw,3.3rem);
  }
  body.final-mode .leaderboard li{
    font-size:clamp(1.15rem,5.5vw,1.8rem);
  }
}


/* v20: waiting slideshow */
.intro-slideshow{
  position:relative;
  width:min(760px, 100%);
  height:clamp(170px, 28vh, 320px);
  margin:clamp(14px, 2vh, 22px) auto 0;
  border-radius:18px;
  overflow:hidden;
  background:#e7ebe7;
  box-shadow:var(--shadow);
}

.intro-slide{
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  object-fit:cover;
  opacity:0;
  transform:scale(1.02);
  transition:opacity 1s ease, transform 5s ease;
}

.intro-slide.is-active{
  opacity:1;
  transform:scale(1);
}

body.waiting-mode .join-qr-panel{
  display:grid;
  grid-template-columns:minmax(280px,.8fr) minmax(360px,1.2fr);
  grid-template-areas:
    "head slideshow"
    "qr slideshow"
    "count slideshow";
  align-items:center;
  gap:clamp(10px,2vh,22px) clamp(18px,3vw,36px);
  text-align:center;
}

body.waiting-mode .join-qr-panel > .eyebrow,
body.waiting-mode .join-qr-panel > h2,
body.waiting-mode .join-qr-panel > p{
  grid-area:head;
}

body.waiting-mode .join-qr-panel > img{
  grid-area:qr;
  width:min(280px,28vh);
}

body.waiting-mode .waiting-player-count{
  grid-area:count;
  margin-top:0;
}

body.waiting-mode .intro-slideshow{
  grid-area:slideshow;
  width:100%;
  height:min(58vh,520px);
  margin:0;
}

/* v20: final couple photo + leaderboard */
body.final-mode #leaderboardCard{
  display:grid !important;
  grid-template-columns:minmax(300px,.85fr) minmax(460px,1.15fr);
  gap:clamp(18px,3vw,42px);
  align-items:stretch;
}

body.final-mode .final-photo-wrap{
  display:flex;
  min-width:0;
  min-height:0;
  border-radius:clamp(18px,2vw,28px);
  overflow:hidden;
  background:#eef0ee;
}

body.final-mode .final-photo-wrap[hidden]{
  display:none !important;
}

body.final-mode .final-photo{
  width:100%;
  height:100%;
  object-fit:cover;
  display:block;
}

body.final-mode .leaderboard-inner{
  min-width:0;
  min-height:0;
  display:flex;
  flex-direction:column;
}

body.final-mode .leaderboard-inner .leaderboard{
  flex:1;
}

@media (max-width:900px), (max-aspect-ratio:4/3){
  body.waiting-mode .join-qr-panel{
    display:flex;
    flex-direction:column;
  }

  body.waiting-mode .intro-slideshow{
    width:min(680px,100%);
    height:clamp(150px,27vh,260px);
  }

  body.final-mode #leaderboardCard{
    grid-template-columns:1fr;
    grid-template-rows:minmax(150px,32vh) 1fr;
  }

  body.final-mode .final-photo{
    object-position:center 35%;
  }
}

@media (prefers-reduced-motion:reduce){
  .intro-slide{
    transition:none;
    transform:none;
  }
}


/* v21: fixed waiting slideshow + no-scroll viewport */
html,
body.host-body{
  width:100%;
  height:100%;
  min-height:100%;
}

body.host-body{
  overflow:hidden;
}

body.waiting-mode .host-wrap{
  width:min(1500px, calc(100% - 28px));
  height:100dvh;
  min-height:0;
  margin:0 auto;
  padding:clamp(10px,1.6vh,18px) 0;
  display:grid;
  grid-template-rows:auto minmax(0,1fr);
  gap:clamp(8px,1.3vh,14px);
  overflow:hidden;
}

body.waiting-mode .host-topline{
  min-height:0;
}

body.waiting-mode .host-topline h1{
  margin:.15rem 0 0;
  font-size:clamp(1.7rem,3.2vw,3.4rem);
  line-height:.95;
}

body.waiting-mode .join-qr-panel{
  min-height:0;
  height:100%;
  margin:0;
  padding:clamp(14px,2.2vh,24px);
  overflow:hidden;

  display:grid;
  grid-template-columns:minmax(250px,.72fr) minmax(0,1.28fr);
  grid-template-rows:auto minmax(0,1fr) auto;
  grid-template-areas:
    "intro slideshow"
    "qr slideshow"
    "count slideshow";
  column-gap:clamp(18px,3vw,42px);
  row-gap:clamp(8px,1.4vh,16px);
  align-items:center;
}

body.waiting-mode .join-qr-panel > .eyebrow{
  grid-area:intro;
  align-self:end;
}

body.waiting-mode .join-qr-panel > h2{
  grid-area:intro;
  align-self:end;
  margin:1.1rem 0 0;
  font-size:clamp(1.5rem,2.8vw,3rem);
}

body.waiting-mode .join-qr-panel > p{
  display:none;
}

body.waiting-mode .join-qr-panel > img{
  grid-area:qr;
  display:block;
  width:auto;
  height:min(36vh,310px);
  max-width:100%;
  margin:auto;
  padding:10px;
  object-fit:contain;
}

body.waiting-mode .waiting-player-count{
  grid-area:count;
  justify-self:center;
  margin:0;
  padding:clamp(8px,1vh,12px) clamp(14px,1.5vw,20px);
}

body.waiting-mode .waiting-player-count strong{
  font-size:clamp(1.4rem,2.5vw,2rem);
}

body.waiting-mode .intro-slideshow{
  grid-area:slideshow;
  width:100%;
  height:100%;
  min-height:0;
  max-height:none;
  margin:0;
  border-radius:18px;
  overflow:hidden;
}

body.waiting-mode .intro-slide{
  object-fit:contain;
  background:#111;
}

body.waiting-mode #hostStage{
  display:none !important;
}

/* Short screens: compress header further */
@media (max-height:700px){
  body.waiting-mode .host-topline .eyebrow{
    display:none;
  }
  body.waiting-mode .host-topline h1{
    font-size:clamp(1.4rem,2.5vw,2.4rem);
  }
  body.waiting-mode .join-qr-panel{
    padding:10px 14px;
  }
  body.waiting-mode .join-qr-panel > img{
    height:min(32vh,230px);
  }
}

/* Narrow portrait/mobile host */
@media (max-width:850px){
  body.waiting-mode .host-wrap{
    width:min(100% - 16px, 760px);
  }

  body.waiting-mode .host-topline{
    display:none;
  }

  body.waiting-mode .host-wrap{
    grid-template-rows:minmax(0,1fr);
  }

  body.waiting-mode .join-qr-panel{
    grid-template-columns:1fr;
    grid-template-rows:auto minmax(0,1fr) auto auto;
    grid-template-areas:
      "intro"
      "slideshow"
      "qr"
      "count";
    gap:8px;
    padding:10px;
  }

  body.waiting-mode .join-qr-panel > h2{
    font-size:clamp(1.25rem,5vw,1.9rem);
  }

  body.waiting-mode .intro-slideshow{
    height:auto;
    min-height:0;
  }

  body.waiting-mode .join-qr-panel > img{
    height:min(22vh,170px);
  }

  body.waiting-mode .waiting-player-count{
    padding:7px 12px;
  }
}


/* v23: structurally fixed waiting viewport */
html {
  height: 100%;
}

body.host-body {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

body.waiting-mode .host-wrap {
  box-sizing: border-box;
  width: min(1500px, calc(100% - 24px));
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  padding: clamp(8px, 1.2vh, 14px) 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(6px, 1vh, 10px);
}

/* Keep the global title fully visible without stealing much height. */
body.waiting-mode .host-topline {
  min-height: 0;
  height: auto;
  padding: 0 2px;
}

body.waiting-mode .host-topline > div:first-child {
  min-width: 0;
}

body.waiting-mode .host-topline .eyebrow {
  font-size: clamp(.62rem, 1vw, .76rem);
  line-height: 1;
}

body.waiting-mode .host-topline h1 {
  margin: .12rem 0 0;
  font-size: clamp(1.45rem, 2.8vw, 3rem);
  line-height: 1.03;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

body.waiting-mode .host-status-group {
  flex: 0 0 auto;
}

/* The waiting card owns all remaining viewport height. */
body.waiting-mode .join-qr-panel {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  margin: 0;
  padding: clamp(12px, 1.8vh, 20px);
  overflow: hidden;

  display: grid;
  grid-template-columns: minmax(220px, .72fr) minmax(0, 1.28fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "copy slideshow"
    "qr slideshow"
    "count slideshow";
  column-gap: clamp(16px, 2.5vw, 34px);
  row-gap: clamp(6px, 1vh, 12px);
  align-items: center;
}

body.waiting-mode .waiting-copy {
  grid-area: copy;
  min-width: 0;
  align-self: end;
  text-align: center;
}

body.waiting-mode .waiting-copy .eyebrow {
  display: block;
  margin: 0 0 .25rem;
  font-size: clamp(.62rem, 1vw, .78rem);
  line-height: 1;
}

body.waiting-mode .waiting-copy h2 {
  margin: 0;
  font-size: clamp(1.25rem, 2.4vw, 2.55rem);
  line-height: 1.02;
}

body.waiting-mode .waiting-copy p {
  display: none;
}

body.waiting-mode .join-qr-panel > img {
  grid-area: qr;
  display: block;
  justify-self: center;
  align-self: center;
  width: auto;
  height: min(34vh, 285px);
  max-width: 92%;
  max-height: 100%;
  margin: 0;
  padding: 8px;
  object-fit: contain;
}

body.waiting-mode .waiting-player-count {
  grid-area: count;
  justify-self: center;
  align-self: start;
  margin: 0;
}

body.waiting-mode .intro-slideshow {
  grid-area: slideshow;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  margin: 0;
  overflow: hidden;
  border-radius: 18px;
}

body.waiting-mode .intro-slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Must never consume layout space while waiting. */
body.waiting-mode #hostStage,
#hostStage[hidden] {
  display: none !important;
}

/* Short 16:9 projectors / laptop screens */
@media (max-height: 760px) and (min-width: 851px) {
  body.waiting-mode .host-wrap {
    padding: 6px 0;
    gap: 5px;
  }

  body.waiting-mode .host-topline .eyebrow {
    display: none;
  }

  body.waiting-mode .host-topline h1 {
    font-size: clamp(1.3rem, 2.3vw, 2.2rem);
  }

  body.waiting-mode .join-qr-panel {
    padding: 9px 12px;
    row-gap: 4px;
  }

  body.waiting-mode .waiting-copy .eyebrow {
    font-size: .62rem;
  }

  body.waiting-mode .waiting-copy h2 {
    font-size: clamp(1.1rem, 2vw, 1.75rem);
  }

  body.waiting-mode .join-qr-panel > img {
    height: min(31vh, 220px);
    padding: 5px;
  }

  body.waiting-mode .waiting-player-count {
    padding: 7px 12px;
  }
}

/* Portrait/mobile host view: one self-contained viewport, no overflow. */
@media (max-width: 850px) {
  body.waiting-mode .host-wrap {
    width: min(100% - 12px, 720px);
    height: 100dvh;
    padding: 6px 0;
    grid-template-rows: minmax(0, 1fr);
  }

  body.waiting-mode .host-topline {
    display: none;
  }

  body.waiting-mode .join-qr-panel {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "copy"
      "slideshow"
      "qr"
      "count";
    gap: 6px;
    padding: 8px;
  }

  body.waiting-mode .waiting-copy h2 {
    font-size: clamp(1.15rem, 5vw, 1.7rem);
  }

  body.waiting-mode .intro-slideshow {
    min-height: 0;
    height: 100%;
  }

  body.waiting-mode .join-qr-panel > img {
    height: min(19vh, 145px);
  }

  body.waiting-mode .waiting-player-count {
    padding: 6px 11px;
  }
}
