:root {
  --bg: #f6f6f3;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #6b6f78;
  --line: #dcdcd6;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --good: #1a7f37;
  --bad: #cf222e;
  --o: #1f6feb;
  --x: #cf222e;
  --c0: #1f6feb;
  --c1: #d4760a;
  --c2: #1a7f37;
  --c3: #8250df;
  --c4: #bf3989;
  --c5: #0e7c86;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1d2026;
    --ink: #eceef2;
    --muted: #9aa0ab;
    --line: #30343c;
    --accent: #4c8dff;
    --good: #3fb950;
    --bad: #ff6b6b;
    --o: #4c8dff;
    --x: #ff6b6b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-size: 18px; line-height: 1.35; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

button, input, textarea, select { font: inherit; color: inherit; }
button {
  border: 2px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px 20px;
  font-weight: 650;
  cursor: pointer;
  touch-action: manipulation;
}
button:hover { border-color: var(--muted); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; transform: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.small { padding: 8px 14px; font-size: 16px; border-radius: 10px; }
button.link { border: 0; background: none; color: var(--muted); text-decoration: underline; padding: 8px; font-weight: 500; }

input, textarea, select {
  width: 100%;
  border: 2px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px 16px;
}
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
label { display: block; font-weight: 650; margin: 0 0 6px; }
.muted { color: var(--muted); }
.error { color: var(--bad); font-weight: 650; min-height: 1.4em; }

/* ---------- student ---------- */
.student { max-width: 560px; margin: 0 auto; padding: 16px; min-height: 100%; display: flex; flex-direction: column; }
.student header { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--muted); font-size: 16px; min-height: 44px; }
.student header .brand { font-weight: 800; color: var(--ink); font-size: 20px; }
.student header .back { padding: 8px 14px; font-size: 16px; border-radius: 10px; flex: none; }
.student header .class-title { flex: 1; text-align: center; font-weight: 650; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.student header .timer { flex: none; min-width: 3em; text-align: right; }

.room-list { display: flex; flex-direction: column; gap: 12px; }
.room-card { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left; padding: 18px 20px; width: 100%; }
.room-name { font-size: 24px; font-weight: 800; }
.room-meta { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 500; color: var(--muted); }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.live-dot.on { background: var(--good); }
.student main { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; padding: 16px 0; }
.student main.top { justify-content: flex-start; padding-top: 24px; }
.student .hint { font-size: 15px; }
.student h1 { font-size: 28px; margin: 0; text-align: center; }
.teacher-lobby .error:empty { display: none; }
.student .big-input { font-size: 40px; text-align: center; letter-spacing: .15em; font-weight: 700; }
.student .stack { display: flex; flex-direction: column; gap: 14px; }
.student .center { text-align: center; }
.prompt { font-size: 22px; font-weight: 650; text-align: center; white-space: pre-wrap; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--ink); }
.timer.low { color: var(--bad); }

.choices { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.choices button { font-size: 56px; font-weight: 800; padding: 0; aspect-ratio: 1 / 1; max-height: 34vh; width: 100%; color: #fff; border: 4px solid transparent; }
.choices.mc button { font-size: 44px; aspect-ratio: auto; height: 18vh; min-height: 84px; }
.choices button.picked { border-color: var(--ink); box-shadow: 0 0 0 4px var(--bg) inset; }
.choices.done button:not(.picked) { opacity: .3; }
.choices button.picked:disabled { opacity: 1; }

.status { text-align: center; font-size: 20px; font-weight: 650; min-height: 1.5em; }
.verdict { font-size: 64px; font-weight: 900; text-align: center; }
.verdict.good { color: var(--good); }
.verdict.bad { color: var(--bad); }

.pad { position: relative; background: #fff; border: 2px solid var(--line); border-radius: var(--radius); touch-action: none; overflow: hidden; }
.pad canvas { display: block; width: 100%; height: 100%; }
.pad-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.swatch { width: 36px; height: 36px; padding: 0; border-radius: 50%; border: 3px solid var(--line); }
.swatch.on { border-color: var(--ink); }

/* ---------- teacher ---------- */
.teacher { min-height: 100%; display: flex; flex-direction: column; }
.teacher-lobby { width: 100%; max-width: 640px; margin: 0 auto; padding: 32px 16px; }
.teacher-lobby h1 { margin: 0; font-size: 32px; }
.teacher-lobby .stack { display: flex; flex-direction: column; gap: 16px; }
.new-room { margin-top: 16px; padding-top: 24px; border-top: 2px solid var(--line); }
.room-title { font-size: 34px; font-weight: 900; line-height: 1.1; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 12px 20px; background: var(--panel); border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.code { font-size: 44px; font-weight: 900; letter-spacing: .08em; line-height: 1; font-variant-numeric: tabular-nums; }
.joinhint { font-size: 18px; }
.joinhint b { font-size: 22px; }
.topbar .spacer { flex: 1; }
.topbar .tools { display: flex; gap: 8px; flex-wrap: wrap; }

.workspace { flex: 1; display: grid; grid-template-columns: 1fr 260px; min-height: 0; }
.stage { padding: 20px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.roster { border-left: 2px solid var(--line); background: var(--panel); padding: 16px; overflow: auto; }
.roster h2 { font-size: 16px; margin: 0 0 10px; color: var(--muted); font-weight: 650; }
.roster ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.roster li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; font-size: 16px; }
.roster li:hover { background: var(--bg); }
.roster .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.roster .dot.on { background: var(--muted); }
.roster .dot.ans { background: var(--good); }
.roster .kick { margin-left: auto; visibility: hidden; padding: 2px 8px; font-size: 14px; border-width: 1px; }
.roster li:hover .kick { visibility: visible; }

.ask { display: flex; flex-direction: column; gap: 10px; }
.ask-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: stretch; }
.ask-row input { flex: 1; min-width: 200px; width: auto; }
.ask-row select { width: auto; }
.types { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.types button { font-size: 22px; padding: 18px 10px; }
.types .mc-wrap { display: flex; gap: 0; }
.types .mc-wrap button:first-child { flex: 1; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.types .mc-wrap select { width: 64px; border-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; padding: 0 6px; text-align: center; }

.result { flex: 1; background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 16px; min-height: 320px; }
.result-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.result-head .count { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.result-head .spacer { flex: 1; }
.result .prompt { text-align: left; }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); font-size: 22px; text-align: center; }

.bars { display: flex; gap: 16px; height: clamp(220px, 46vh, 560px); }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; border: 0; background: none; padding: 0; border-radius: 0; }
.bar .n { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar .track { flex: 1; width: 100%; position: relative; }
.bar .fill { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 10px 10px 0 0; min-height: 4px; transition: height .25s ease; }
.bar .label { font-size: 34px; font-weight: 900; width: 100%; text-align: center; border-top: 3px solid var(--line); padding-top: 6px; }
.bar.correct .label { color: var(--good); }
.bar.correct .label::after { content: " ✓"; }
.bars.marked .bar:not(.correct) .fill { opacity: .3; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; align-content: start; overflow: auto; }
.card { border: 2px solid var(--line); border-radius: 12px; padding: 12px; background: var(--bg); font-size: 20px; overflow-wrap: anywhere; white-space: pre-wrap; }
.card .who { font-size: 14px; color: var(--muted); font-weight: 650; margin-bottom: 4px; white-space: normal; }
.card img { width: 100%; display: block; border-radius: 8px; background: #fff; cursor: zoom-in; }
.cards.drawings { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

.qr { display: block; line-height: 0; }
.qr svg { width: 100%; height: auto; display: block; border-radius: 6px; }
.joinhint { display: flex; align-items: center; gap: 14px; }
.qr-mini { width: 76px; padding: 0; border: 0; background: none; flex: none; cursor: zoom-in; }
.join-panel { gap: 20px; }
.join-panel .qr-stage { width: min(42vh, 360px); padding: 0; border: 0; background: none; cursor: zoom-in; }
.join-title { font-size: 28px; font-weight: 800; color: var(--ink); margin-bottom: 6px; }
.qr-big { width: min(80vh, 90vw); cursor: pointer; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.82); display: grid; place-items: center; z-index: 10; padding: 24px; cursor: pointer; }
.overlay .picked-name { color: #fff; font-size: min(14vw, 140px); font-weight: 900; text-align: center; line-height: 1.1; }
.overlay img { max-width: 100%; max-height: 90vh; background: #fff; border-radius: 12px; }
.overlay .cap { color: #fff; text-align: center; font-size: 22px; margin-top: 10px; }

@media (max-width: 820px) {
  .workspace { grid-template-columns: 1fr; }
  .roster { border-left: 0; border-top: 2px solid var(--line); }
  .types { grid-template-columns: 1fr 1fr; }
  .code { font-size: 36px; }
}
