:root{
  /* These tokens mirror the main app's dark theme in ../../styles.css. */
  --bg:#0f1117; --bg2:#1e2235; --card:#1a1d2e; --line:#2a3045;
  --txt:#e2e8f0; --muted:#8892a4; --pri:#2c5282; --pri2:#63b3ed;
  --header:#111827; --ok:#2ecc71; --bad:#ff5b6e; --gold:#ffd24a;
}
html[data-theme="light"]{
  /* These tokens mirror the main app's light theme in ../../styles.css. */
  --bg:#f0f4f8; --bg2:#edf2f7; --card:#ffffff; --line:#e2e8f0;
  --txt:#2d3748; --muted:#718096; --pri:#2c5282; --pri2:#3182ce;
  --header:#2c5282;
}
*{box-sizing:border-box}
html,body{margin:0}
body{font-family:'Segoe UI',system-ui,Arial,sans-serif;background:
  radial-gradient(1200px 600px at 80% -10%,rgba(49,130,206,.2) 0%,transparent 60%),var(--bg);
  color:var(--txt);min-height:100vh}
h2,h3{margin:.2rem 0}
.muted{color:var(--muted)}
.warn{color:var(--gold)}
.ok{color:var(--ok)}

/* Topbar */
.topbar{display:flex;justify-content:space-between;align-items:center;gap:.75rem;
  padding:.7rem 1rem;background:var(--header);backdrop-filter:blur(8px);
  border-bottom:1px solid var(--line);position:sticky;top:0;z-index:20}
.brand{font-weight:800;font-size:1.15rem;display:flex;align-items:center;gap:.4rem}
.brand em{font-style:normal;font-size:.62rem;letter-spacing:.08em;background:var(--pri);
  padding:.2rem .5rem;border-radius:999px}
.me{display:flex;align-items:center;gap:.55rem}
.me .av{width:38px;height:38px;border-radius:50%;border:2px solid var(--pri2);background:#222}
.me-info .nm{font-weight:700;font-size:.9rem;line-height:1}
.me-info .col{font-size:.72rem;color:var(--muted)}
.icon{background:var(--card);border:1px solid var(--line);color:var(--txt);
  width:38px;height:38px;border-radius:10px;cursor:pointer;font-size:1rem}
.icon:hover{border-color:var(--pri2)}
.icon.danger:hover{border-color:var(--bad);color:var(--bad)}

/* Layout */
.layout{display:grid;grid-template-columns:1fr 340px;gap:1rem;max-width:1100px;
  margin:1rem auto;padding:0 1rem}
.stage-card,.side{background:var(--card);border:1px solid var(--line);border-radius:16px}
.stage-card{min-height:60vh;padding:1.4rem;display:flex}
#stage{flex:1;display:flex;flex-direction:column;justify-content:center}
.side{padding:1rem;align-self:start}

.center{text-align:center;display:flex;flex-direction:column;align-items:center;gap:.8rem}
.pill{background:var(--bg2);border:1px solid var(--line);color:var(--pri2);
  padding:.25rem .7rem;border-radius:999px;font-size:.72rem;font-weight:700;letter-spacing:.05em}

/* Buttons */
button.primary{background:linear-gradient(135deg,var(--pri),var(--pri2));color:#fff;border:none;
  padding:.75rem 1.2rem;border-radius:12px;font-weight:700;cursor:pointer;font-size:.95rem}
button.primary:hover{filter:brightness(1.08)}
button.primary:disabled{opacity:.6;cursor:default}
button.big{font-size:1.05rem;padding:.9rem 1.6rem}

/* Question / options */
.qtext{font-size:1.35rem;line-height:1.35;margin:.6rem 0 1rem}
.opts{display:grid;grid-template-columns:1fr 1fr;gap:.7rem}
.opt{background:var(--bg2);border:1px solid var(--line);color:var(--txt);
  padding:1rem;border-radius:12px;cursor:pointer;text-align:left;font-size:1rem;transition:.15s}
.opt:hover:not(:disabled){border-color:var(--pri2);transform:translateY(-2px)}
.opt:disabled{opacity:.55;cursor:default}
.vote-footer{display:flex;justify-content:center;min-height:2.7rem;margin-top:.8rem}
.vote-count{align-self:center;color:var(--muted);font-size:.82rem}
.view-vote{border:1px solid var(--pri2);border-radius:999px;background:transparent;color:var(--pri2);
  padding:.55rem 1.25rem;font-weight:800;font-size:.85rem;cursor:pointer;transition:.15s}
.view-vote:hover{background:rgba(99,179,237,.12);transform:translateY(-1px)}
.correct{font-size:1.4rem;font-weight:800;color:var(--ok);background:rgba(46,204,113,.12);
  border:1px solid rgba(46,204,113,.4);padding:.8rem 1.4rem;border-radius:12px}

/* Timer */
.timerbar{height:8px;background:var(--bg2);border-radius:999px;overflow:hidden;margin-bottom:.9rem}
.timerbar .fill{height:100%;background:linear-gradient(90deg,var(--bad),var(--gold),var(--ok));
  transition:width 1s linear}
.thead{display:flex;align-items:center;gap:.8rem;margin-bottom:.5rem}
.clock{font-weight:800;color:var(--gold)}

/* Leaderboard */
.lb-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:.6rem}
.count{font-size:.75rem;color:var(--muted)}
.lb-row{display:flex;align-items:center;gap:.6rem;padding:.5rem;border-radius:10px;margin-bottom:.35rem;
  background:var(--bg2);border:1px solid transparent}
.lb-row.me{border-color:var(--pri2)}
.lb-row .rank{width:26px;height:26px;border-radius:50%;display:grid;place-items:center;
  font-weight:800;font-size:.8rem;background:var(--card);color:var(--muted)}
.lb-row .r1{background:var(--gold);color:#3a2d00}
.lb-row .r2{background:#c9d1e8;color:#20242e}
.lb-row .r3{background:#e0a06a;color:#301c0a}
.lb-row .av{width:34px;height:34px;border-radius:50%;background:#222}
.lb-row .who{flex:1;min-width:0}
.lb-row .nm{font-weight:700;font-size:.86rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.lb-row .col{font-size:.7rem;color:var(--muted)}
.lb-row .pts{font-weight:800;color:var(--pri2)}

/* Spinner */
.spinner{width:34px;height:34px;border:4px solid var(--line);border-top-color:var(--pri2);
  border-radius:50%;animation:spin 1s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* Modal */
.modal-wrap{position:fixed;inset:0;background:rgba(6,7,20,.7);display:grid;place-items:center;
  z-index:50;padding:1rem}
.modal{background:var(--card);border:1px solid var(--line);border-radius:18px;width:min(520px,96vw);
  max-height:90vh;overflow:auto;position:relative;box-shadow:0 20px 60px rgba(0,0,0,.5)}
.modal-back,.modal .x{position:absolute;top:.6rem;background:var(--bg2);border:1px solid var(--line);
  color:var(--txt);width:32px;height:32px;border-radius:8px;cursor:pointer;font-size:1.05rem}
.modal-back{left:.6rem}
.modal .x{position:absolute;top:.6rem;right:.6rem;background:var(--bg2);border:1px solid var(--line);
  color:var(--txt);width:32px;height:32px;border-radius:8px;cursor:pointer}
.modal-back:hover,.modal .x:hover{border-color:var(--pri2)}
.modal-body{padding:1.4rem}
.modal-body label{display:block;font-size:.8rem;color:var(--muted);margin:.7rem 0 .25rem}
.modal-body input,.modal-body select{width:100%;padding:.65rem;border-radius:10px;
  background:var(--bg2);border:1px solid var(--line);color:var(--txt);font-size:.95rem}
.modal-body .primary{margin-top:1rem;width:100%}
.settings-guide-link{display:inline-block;margin-top:.65rem;color:var(--pri2);font-size:.82rem;font-weight:700;text-decoration:none}
.settings-guide-link:hover{text-decoration:underline}

.source-grid{display:grid;grid-template-columns:1fr 1fr;gap:.7rem;margin-top:1rem}
.src{display:flex;flex-direction:column;gap:.4rem;align-items:center;justify-content:center;
  background:var(--bg2);border:1px solid var(--line);color:var(--txt);padding:1.1rem .6rem;
  border-radius:14px;cursor:pointer;font-weight:600;font-size:.85rem}
.src span{font-size:1.6rem}
.src:hover{border-color:var(--pri2);transform:translateY(-2px)}
.src[data-src=folder]{grid-column:1 / -1}
.src[data-src=manual]{border-color:rgba(139,123,255,.55)}
.src[data-src=manual] small{font-size:.7rem;color:var(--muted);font-weight:400}

.list{display:flex;flex-direction:column;gap:.5rem;margin-top:.8rem}
.row{text-align:left;background:var(--bg2);border:1px solid var(--line);color:var(--txt);
  padding:.75rem;border-radius:10px;cursor:pointer}
.row:hover{border-color:var(--pri2)}

.results{display:flex;flex-direction:column;gap:.5rem;margin-top:.8rem}
.vote-results{display:flex;flex-direction:column;gap:.8rem;margin-top:1rem}
.vote-option{background:var(--bg2);border:1px solid var(--line);border-radius:12px;padding:.75rem}
.vote-option-head{display:flex;justify-content:space-between;align-items:flex-start;gap:.7rem;font-size:.88rem}
.vote-option-head b{min-width:0;line-height:1.35}
.vote-option-head>span{color:var(--pri2);font-size:.78rem;white-space:nowrap;font-weight:800}
.vote-bar{height:7px;margin:.55rem 0 .65rem;background:var(--card);border-radius:999px;overflow:hidden}
.vote-bar i{display:block;height:100%;background:linear-gradient(90deg,var(--pri),var(--pri2));border-radius:inherit}
.vote-voters{display:flex;flex-wrap:wrap;gap:.35rem}
.vote-voter{display:inline-flex;align-items:center;gap:.28rem;padding:.2rem .45rem .2rem .25rem;
  border:1px solid var(--line);border-radius:999px;color:var(--muted);font-size:.7rem}
.vote-voter img{width:20px;height:20px;border-radius:50%;object-fit:cover;background:var(--card)}
.res-row{display:flex;align-items:center;gap:.6rem;padding:.55rem;border-radius:10px;background:var(--bg2)}
.res-row .pos{width:34px;font-weight:800;color:var(--muted)}
.res-row .av{width:30px;height:30px;border-radius:50%}
.res-row .nm{flex:1;font-weight:600}
.res-row .tag{font-size:.7rem;padding:.15rem .5rem;border-radius:999px}
.res-row.good .tag{background:rgba(46,204,113,.2);color:var(--ok)}
.res-row.bad .tag{background:rgba(255,91,110,.2);color:var(--bad)}
.res-row .pts{font-weight:800;color:var(--pri2);min-width:54px;text-align:right}

.toast{position:fixed;bottom:1.4rem;left:50%;transform:translateX(-50%);background:#000;
  border:1px solid var(--line);color:#fff;padding:.7rem 1.2rem;border-radius:12px;z-index:80;
  animation:pop .2s ease}
@keyframes pop{from{opacity:0;transform:translate(-50%,10px)}}

/* Quiet, transient presence cues keep the room feeling active without
   covering the question or competing with the leaderboard. */
.live-activity{position:fixed;left:1rem;bottom:1rem;display:flex;flex-direction:column;
  align-items:flex-start;gap:.45rem;z-index:35;pointer-events:none;max-width:min(300px,calc(100vw - 2rem))}
.live-activity-item{display:flex;align-items:center;gap:.55rem;padding:.45rem .7rem .45rem .45rem;
  color:var(--txt);background:color-mix(in srgb,var(--card) 78%,transparent);
  border:1px solid color-mix(in srgb,var(--line) 78%,transparent);border-radius:999px;
  box-shadow:0 8px 22px rgba(0,0,0,.16);backdrop-filter:blur(8px);
  animation:activity-in .25s ease both}
.live-activity-item.leaving{animation:activity-out .45s ease forwards}
.live-activity-item img{width:26px;height:26px;border-radius:50%;object-fit:cover;background:var(--bg2)}
.live-activity-item .activity-name{font-weight:700;font-size:.78rem;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.live-activity-item .activity-copy{font-size:.75rem;color:var(--muted);white-space:nowrap}
@keyframes activity-in{from{opacity:0;transform:translateY(8px)}to{opacity:.9;transform:translateY(0)}}
@keyframes activity-out{to{opacity:0;transform:translateY(8px)}}

/* Responsive: tablet & mobile */
@media (max-width:860px){
  .layout{grid-template-columns:1fr}
  /* Keep the question and its answer options visible before a long player list. */
  .stage-card{order:1}
  .side{order:2}
  .stage-card{min-height:52vh;padding:1rem}
}
@media (max-width:480px){
  .me-info{display:none}
  .opts{grid-template-columns:1fr}
  .qtext{font-size:1.15rem}
  .brand span{display:none}
  .source-grid{grid-template-columns:1fr}
  .src[data-src=folder]{grid-column:auto}
  .vote-option-head{display:block}
  .vote-option-head>span{display:block;margin-top:.25rem}
}


/* ---- rendered question-bank / AI HTML content ---- */
.qtext p,.opt p,.explanation p,.correct p{margin:0}
.qtext p + p,.opt p + p{margin-top:.4rem}
.qtext img,.opt img,.explanation img,.correct img{max-width:100%;height:auto;
  border-radius:8px;display:block;margin:.5rem 0}
.qtext span,.opt span,.correct span,.explanation span{font-size:inherit !important}

/* answered reveal + explanation */
.explanation{background:var(--bg2);border:1px solid var(--line);border-left:3px solid var(--pri2);
  border-radius:10px;padding:.7rem .9rem;margin:.8rem 0;font-size:.95rem;line-height:1.45;text-align:left}
.explanation b{display:block;margin-bottom:.3rem;color:var(--pri2)}
.explanation-collapse{width:100%;margin:.8rem 0;text-align:left}
.explanation-collapse summary{display:inline-block;cursor:pointer;color:var(--pri2);
  font-weight:700;font-size:.9rem;padding:.35rem .65rem;border:1px solid var(--line);
  border-radius:8px;background:var(--bg2)}
.explanation-collapse[open] summary{margin-bottom:.1rem}
.reveal{margin-top:.9rem}
.reveal.bad .correct{color:var(--ok)}
.opt.is-correct{border-color:var(--ok);background:rgba(46,204,113,.14)}

/* manual-entry form controls */
.modal-body textarea{width:100%;padding:.65rem;border-radius:10px;background:var(--bg2);
  border:1px solid var(--line);color:var(--txt);font-size:.95rem;font-family:inherit;resize:vertical}
.modal-body textarea.auto-expand{min-height:3.15rem;max-height:none;overflow-y:hidden;resize:none}
.image-picker{display:flex;align-items:center;gap:.6rem;flex-wrap:wrap;margin:.35rem 0 .75rem}
.image-picker input[type=file]{width:auto;padding:.35rem;background:transparent;border:0}
.image-preview{display:flex;align-items:center;gap:.5rem;width:100%;padding:.45rem;
  background:var(--bg2);border:1px solid var(--line);border-radius:10px}
.image-preview img{width:58px;height:42px;object-fit:cover;border-radius:6px}
.image-preview span{font-size:.75rem;color:var(--muted);flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis}
.remove-image{background:transparent;border:0;color:var(--bad);cursor:pointer;font-size:.8rem}
.opt-lbl{display:flex;align-items:center;gap:.4rem;font-size:.8rem;color:var(--muted);margin:.6rem 0 .25rem}
.opt-lbl input{width:auto !important}
.btn-row{display:flex;gap:.6rem;margin-top:1rem;flex-wrap:wrap}
.btn-row .primary{margin-top:0;width:auto;flex:1;min-width:140px}
.ghost{background:transparent;border:1px solid var(--pri2);color:var(--txt);
  padding:.65rem 1rem;border-radius:10px;cursor:pointer;font-weight:600;flex:1;min-width:140px;transition:.15s}
.ghost:hover:not(:disabled){background:rgba(139,123,255,.14)}
.ghost:disabled{opacity:.6;cursor:default}


/* bookmark / question preview rows */
.bm-row{display:flex;align-items:center;gap:.7rem;text-align:left;width:100%}
.bm-thumb{width:54px;height:54px;object-fit:cover;border-radius:8px;flex:0 0 auto;border:1px solid var(--line)}
.bm-txt{display:block;font-size:.9rem;line-height:1.35}
.bm-tag{display:block;font-size:.72rem;color:var(--pri2);font-weight:600;margin-bottom:.15rem;text-transform:uppercase;letter-spacing:.03em}
.bm-preview-text{display:block}
.question-image{margin:.7rem 0;text-align:center}
.question-image img{max-width:100%;height:auto;border-radius:10px}
.explanation img{max-height:420px;object-fit:contain}
