:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --text: #1c2033;
  --muted: #5d6478;
  --border: #dfe2ec;
  --brand: #2f5bea;
  --brand-ink: #ffffff;
  --good: #177a42;
  --bad: #c0392b;
  --opt-a: #2f5bea;
  --opt-b: #b5541a;
  --opt-c: #127a6b;
  --opt-d: #8a4fd6;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(20, 30, 60, 0.07);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --surface: #1c1f2b;
    --text: #eef0f6;
    --muted: #a3a9bb;
    --border: #2e3344;
    --brand: #5b7ff5;
    --good: #3ccf7a;
    --bad: #ff7b7b;
    --mid: #ffb84d;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
}

a { color: var(--brand); }

.wrap { max-width: 980px; margin: 0 auto; padding: 20px 16px 48px; }
.narrow { max-width: 460px; }

header.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.logo { font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; }
.logo span { color: var(--brand); }
#meTag { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 65%; }
@media (max-width: 520px) { #envTag { display: none; } }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 12px; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.3rem; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1 1 auto; }

label { display: block; font-weight: 600; margin: 12px 0 6px; }
input[type=text], input[type=number], select, textarea {
  width: 100%; padding: 12px 14px; font-size: 1rem; font-family: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.code-input { font-size: 1.8rem !important; letter-spacing: 0.3em; text-align: center; font-weight: 700; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px; font-size: 1rem; font-weight: 600; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none;
}
button:hover, .btn:hover { filter: brightness(0.97); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.danger { color: var(--bad); }
.block { width: 100%; }
.big { padding: 16px 22px; font-size: 1.15rem; }

.error { color: var(--bad); font-weight: 600; margin-top: 10px; }
.notice { padding: 10px 14px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }

/* ---------- Answer options ---------- */
.opt-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .opt-grid.two { grid-template-columns: 1fr 1fr; } }
.opt {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 16px 18px; font-size: 1.1rem; color: #fff; border: none; border-radius: var(--radius);
  min-height: 64px;
}
.opt .letter {
  flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255,255,255,0.25); font-weight: 800;
}
.opt-0 { background: var(--opt-a); } .opt-1 { background: var(--opt-b); }
.opt-2 { background: var(--opt-c); } .opt-3 { background: var(--opt-d); }
.opt-4 { background: #b0466e; } .opt-5 { background: #4c7a2f; }
.opt.chosen { outline: 4px solid var(--text); outline-offset: 2px; }
.opt.dim { opacity: 0.35; }

/* ---------- Presenter ---------- */
.present { min-height: calc(100vh - 60px); display: flex; flex-direction: column; }
.present .stage { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.q-text { font-size: clamp(1.5rem, 3.4vw, 2.6rem); font-weight: 750; line-height: 1.2; margin-bottom: 24px; }
.join-banner {
  display: flex; gap: 24px; align-items: center; justify-content: center; flex-wrap: wrap;
  padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.join-code { font-size: clamp(2.4rem, 7vw, 4.5rem); font-weight: 800; letter-spacing: 0.12em; color: var(--brand); }
.qr { background: #fff; padding: 10px; border-radius: 10px; line-height: 0; }
.qr img, .qr svg { width: 180px; height: 180px; }
.pill { display: inline-block; padding: 4px 12px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-size: 0.9rem; }
.names { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.timer { font-size: 2.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--bad); }
.controls { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; padding: 14px 0 4px; }

/* bar chart */
.bars { display: grid; gap: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 34%) 1fr 64px; gap: 12px; align-items: center; font-size: 1.1rem; }
.bar-track { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; height: 38px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 8px 0 0 8px; transition: width 0.5s ease; }
.bar-row.correct .bar-label::after { content: "  ✓"; color: var(--good); font-weight: 800; }
.bar-count { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }

/* word cloud */
.cloud { display: flex; flex-wrap: wrap; gap: 10px 22px; justify-content: center; align-items: center; padding: 20px; min-height: 200px; }
.cloud span { font-weight: 750; line-height: 1; }

.open-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.open-list div { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }

/* leaderboard */
.board { display: grid; gap: 8px; max-width: 640px; margin: 0 auto; width: 100%; }
.board-row { display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; font-size: 1.15rem; }
.board-row .rank { font-weight: 800; color: var(--muted); }
.board-row .pts { font-weight: 800; font-variant-numeric: tabular-nums; }
.podium { display: flex; gap: 14px; justify-content: center; align-items: flex-end; margin: 10px 0 24px; }
.podium div { text-align: center; padding: 14px 10px; border-radius: 12px 12px 0 0; color: #fff; width: 150px; font-weight: 700; }
.podium .p1 { background: #d4a017; color: #1c2033; min-height: 250px; }
.podium .p2 { background: #8e99ab; color: #1c2033; min-height: 205px; }
.podium .p3 { background: #94582c; min-height: 175px; }
.podium .medal { font-size: 2rem; }

/* editor */
.q-edit { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 12px; background: var(--bg); }
.q-edit .opt-line { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.q-edit .opt-line input[type=text] { flex: 1; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.list-item:last-child { border-bottom: none; }

/* avatars */
.avatar-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.avatar-grid button {
  font-size: 1.6rem; padding: 6px 0; border-radius: 10px; background: var(--bg);
  border: 2px solid transparent; line-height: 1.2;
}
.avatar-grid button[aria-checked="true"] { border-color: var(--brand); background: var(--surface); transform: scale(1.08); }
.av { font-size: 1.3em; line-height: 1; margin-right: 4px; }
.my-avatar { font-size: 3.5rem; line-height: 1; margin-bottom: 6px; }
.podium .av { display: block; font-size: 2.4rem; margin: 4px 0; }

/* analysis */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; text-align: center; }
.stat b { display: block; font-size: 1.7rem; }
.qa { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 10px; background: var(--surface); }
.qa-head { display: flex; gap: 12px; align-items: baseline; justify-content: space-between; flex-wrap: wrap; }
.qa-pct { font-size: 1.4rem; font-weight: 800; white-space: nowrap; }
.lvl-hard { color: var(--bad); } .lvl-mid { color: var(--mid, #8a6100); } .lvl-easy { color: var(--good); }
.qa-meter { height: 10px; border-radius: 6px; background: var(--bg); overflow: hidden; margin: 8px 0; }
.qa-meter div { height: 100%; }
.qa-meter .lvl-hard { background: var(--bad); } .qa-meter .lvl-mid { background: #e0a800; } .qa-meter .lvl-easy { background: var(--good); }

/* student */
.status-big { font-size: 1.5rem; font-weight: 750; margin: 8px 0; }
.result-good { color: var(--good); }
.result-bad { color: var(--bad); }

/* ---------- Editor: slide list | preview | settings ---------- */
.ed-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.ed-title { max-width: 380px; font-weight: 700; font-size: 1.05rem !important; padding: 8px 12px !important; }
.ed-grid { display: grid; grid-template-columns: 230px 1fr 340px; gap: 16px; padding: 16px; min-height: calc(100vh - 120px); }
.ed-slides { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.new-slide { position: relative; }
.menu { position: absolute; z-index: 20; top: 48px; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.15); padding: 6px; display: grid; gap: 4px; }
.menu button { justify-content: flex-start; border: none; background: transparent; text-align: left; }
.menu button:hover { background: var(--bg); }
.slide-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; overflow-y: auto; max-height: calc(100vh - 210px); }
.slide-thumb { display: grid; grid-template-columns: 22px 1fr; gap: 6px; align-items: start; cursor: pointer; }
.slide-num { color: var(--muted); font-weight: 700; padding-top: 6px; text-align: right; }
.thumb-card { background: var(--surface); border: 2px solid var(--border); border-radius: 10px; padding: 8px 10px; min-height: 84px; overflow: hidden; }
.slide-thumb.active .thumb-card { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent); }
.thumb-type { font-size: .72rem; color: var(--muted); margin-bottom: 3px; }
.thumb-text { font-size: .82rem; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.thumb-bars { display: flex; gap: 4px; align-items: flex-end; height: 22px; margin-top: 6px; }
.thumb-bars i { flex: 1; border-radius: 2px 2px 0 0; display: block; }
.ed-preview { min-width: 0; }
.slide-canvas { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; min-height: 420px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow); }
.slide-canvas .q-text { font-size: clamp(1.2rem, 2.4vw, 2rem); margin: 14px 0 18px; }
.opt.is-correct { outline: 3px solid var(--good); outline-offset: 2px; }
.preview-hint { padding: 30px; border: 2px dashed var(--border); border-radius: 14px; text-align: center; color: var(--muted); }
.ed-settings { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px; align-self: start; position: sticky; top: 12px; }
.ed-settings .opt-line { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.ed-settings .opt-line input[type=text] { flex: 1; padding: 9px 12px; }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; margin-top: 14px; cursor: pointer; }
label.check input { width: 18px; height: 18px; }
@media (max-width: 1000px) {
  .ed-grid { grid-template-columns: 1fr; }
  .slide-list { grid-auto-flow: column; grid-auto-columns: 180px; overflow-x: auto; max-height: none; }
  .ed-settings { position: static; }
}

/* ---------- Presenter ---------- */
.pr-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tog { padding: 7px 12px; font-size: .88rem; }
.tog.on { border-color: var(--brand); color: var(--brand); }
.tog.alert { background: #fff4d6; border-color: #e0a800; color: #7a5600; }
.pr-grid { display: grid; grid-template-columns: 1fr; gap: 20px; padding: 20px 20px 8px; min-height: calc(100vh - 200px); }
.pr-grid.with-join { grid-template-columns: 1fr 260px; }
.pr-stage { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px 32px; display: flex; flex-direction: column; min-width: 0; box-shadow: var(--shadow); }
.pr-join { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 18px; align-self: start; display: flex; flex-direction: column; align-items: center; }
.qr.big svg, .qr.big img { width: 200px; height: 200px; }
.join-host { font-size: 1.3rem; font-weight: 700; margin-bottom: 10px; }
.join-code-sm { font-size: 2rem; font-weight: 800; letter-spacing: .08em; color: var(--brand); }
.counter { margin-top: 12px; padding: 8px 16px; background: var(--bg); border-radius: 10px; font-weight: 700; }
.lobby { display: flex; flex-direction: column; gap: 18px; justify-content: center; flex: 1; }
.lobby h1 { font-size: clamp(1.6rem, 3vw, 2.4rem); }
.tally { display: flex; gap: 22px; font-size: 1.3rem; font-weight: 750; margin-bottom: 14px; flex-wrap: wrap; }
.cols { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 18px; align-items: end; flex: 1; min-height: 280px; }
.col { display: flex; flex-direction: column; height: 100%; min-width: 0; }
.col-count { font-size: 1.5rem; font-weight: 800; display: flex; align-items: center; gap: 6px; }
.mark { font-size: .85rem; width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; }
.mark.good { background: #dff3e6; color: var(--good); } .mark.bad { background: #fde3e3; color: var(--bad); }
.col-track { flex: 1; display: flex; align-items: flex-end; border-bottom: 3px solid var(--border); min-height: 160px; }
.col-fill { width: 100%; border-radius: 8px 8px 0 0; transition: height .5s ease; }
.col.wrong .col-fill { opacity: .3; }
.col-label { margin-top: 10px; font-size: 1rem; }
.spotlight { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 18px; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100%); background: var(--surface); border-left: 1px solid var(--border); box-shadow: -10px 0 30px rgba(0,0,0,.12); padding: 18px; overflow-y: auto; z-index: 50; }
.ask { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-top: 10px; display: grid; gap: 8px; }
.ask.done { opacity: .6; }
.ask .row button { padding: 6px 10px; font-size: .85rem; }
.reason-group { margin-top: 14px; }
.reason { background: var(--bg); border-radius: 8px; padding: 8px 10px; margin-top: 6px; }
@media (max-width: 800px) { .pr-grid.with-join { grid-template-columns: 1fr; } }

/* ---------- Student extras ---------- */
.fab { position: fixed; right: 16px; bottom: 16px; border-radius: 999px; box-shadow: 0 6px 20px rgba(0,0,0,.18); z-index: 30; }
.modal { position: fixed; inset: 0; background: rgba(10,14,30,.45); display: grid; place-items: end center; z-index: 40; padding: 16px; }
.modal .card { width: 100%; max-width: 460px; margin: 0; }
.reason-box { margin-top: 14px; text-align: left; }

/* Presenter buttons stay pinned to the bottom of the screen so they're never scrolled out of view. */
#present .controls {
  position: sticky; bottom: 0; z-index: 10; padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px);
  border-top: 1px solid var(--border);
}
.avatar-hint { margin-top: 6px; }

/* Reasons shown after the answer is revealed */
.ed-settings .why-input { width: 100%; margin: 4px 0 4px 30px; width: calc(100% - 30px); padding: 7px 10px; font-size: .88rem; }
.why-box { margin-top: 16px; padding: 14px 18px; border-radius: 12px; background: var(--bg); border: 1px solid var(--border); display: grid; gap: 8px; font-size: 1.15rem; }
.why-title { font-weight: 800; }
.why-row { display: flex; gap: 10px; align-items: flex-start; text-align: left; line-height: 1.4; }
.why-row .why-mark { flex: none; width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; font-size: .85rem; font-weight: 800; margin-top: 2px; }
.why-row.good .why-mark { background: #dff3e6; color: var(--good); }
.why-row.bad .why-mark { background: #fde3e3; color: var(--bad); }
#statusCard .why-row { margin: 10px 0; padding: 10px 12px; border-radius: 10px; background: var(--bg); font-size: 1rem; }
/* With reasons on screen, keep the bar chart short so the reasons fit above the buttons. */
.pr-stage:has(.why-box) .q-text { margin-bottom: 12px; }
.pr-stage:has(.why-box) .tally { margin-bottom: 8px; }
.pr-stage:has(.why-box) .cols { flex: none; height: 22vh; min-height: 130px; }
.pr-stage:has(.why-box) .col-track { min-height: 60px; }
.pr-stage .why-box { font-size: clamp(.95rem, 1.5vw, 1.2rem); }

.timer-controls { flex-basis: 100%; display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap; }

/* Student score badge and celebration */
.me-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; color: var(--muted); min-width: 0; }
.score-pill { flex: none; padding: 5px 11px; border-radius: 999px; background: #fff4d6; color: #7a5200; font-weight: 800; font-size: .95rem; font-variant-numeric: tabular-nums; }
.score-pill.bump { animation: bump .7s ease; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
.cheer { padding: 18px 12px; border-radius: 16px; background: linear-gradient(135deg, #e6f7ec, #fff4d6); margin-bottom: 8px; animation: pop .5s ease; }
.cheer-big { font-size: 2.2rem; font-weight: 900; color: var(--good); line-height: 1.15; }
.cheer-sub { font-weight: 700; margin-top: 4px; }
.cheer-points { font-size: 1.6rem; font-weight: 900; color: #b07800; margin-top: 6px; }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.06); opacity: 1; } 100% { transform: scale(1); } }
.total-score { margin-top: 12px; font-size: 1.05rem; }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti span { position: absolute; top: -40px; animation-name: fall; animation-timing-function: ease-in; animation-fill-mode: forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); opacity: .8; } }
@media (prefers-color-scheme: dark) {
  .score-pill { background: #4a3a10; color: #ffd76a; }
  .cheer { background: linear-gradient(135deg, #12361f, #3a2f10); }
  .cheer-points { color: #ffd76a; }
}

/* End-of-session summary */
.summary { margin-top: 24px; }
.summary h2 { margin-bottom: 8px; }
.summary-table { width: 100%; border-collapse: collapse; font-size: 1rem; }
.summary-table th, .summary-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: center; }
.summary-table th { font-size: .85rem; color: var(--muted); font-weight: 700; }
.summary-table .summary-q, .summary-table th:nth-child(2) { text-align: left; }
.summary-table td:nth-child(3), .summary-table td:nth-child(4) { font-weight: 800; font-size: 1.15rem; }

.sample-item { background: linear-gradient(135deg, #eef2ff, #fff4d6); border-radius: 12px; padding-left: 12px; padding-right: 12px; }
@media (prefers-color-scheme: dark) { .sample-item { background: linear-gradient(135deg, #1e2547, #3a2f10); } }

/* Presenter moderation: click a word or answer to delete it */
.cloud .cloud-word { background: none; border: 0; padding: 2px 4px; font-weight: 750; line-height: 1; font-family: inherit; cursor: pointer; border-radius: 8px; }
.cloud .cloud-word:hover, .cloud .cloud-word:focus-visible { text-decoration: line-through; background: rgba(192, 57, 43, .08); }
.open-list .open-item { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.open-item .del-x { background: none; border: 0; color: var(--muted); padding: 0 2px; font-size: .9rem; cursor: pointer; opacity: .35; }
.open-item:hover .del-x, .open-item .del-x:focus-visible { opacity: 1; color: var(--bad); }

/* Answers closed, answer not revealed yet */
.closed-banner { margin: 6px 0 10px; padding: 10px 14px; border-radius: 10px; background: #fff4d6; color: #6b4e00; font-weight: 700; text-align: center; }
@media (prefers-color-scheme: dark) { .closed-banner { background: #3a2f10; color: #ffd76a; } }
