/* Layout concept: a lab bench — the board is the bench top, the call and tools sit in a narrow rack beside it.
   Light first; dark follows the system or data-theme. The board itself stays paper-white in both themes. */
:root {
  --bg: #E9EDF0;
  --surface: #FFFFFF;
  --surface-2: #F3F5F7;
  --ink: #14202A;
  --muted: #5A6A76;
  --line: #D2D9DF;
  --accent: #0B6E78;
  --accent-ink: #FFFFFF;
  --accent-soft: #D6ECEE;
  --signal: #C77C00;
  --signal-soft: #FBEBCB;
  --good: #2D7F4F;
  --bad: #B8402F;
  --paper: #FBFCFD;
  --shadow: 0 1px 2px rgba(20, 32, 42, .06), 0 6px 20px rgba(20, 32, 42, .06);
  --f-display: "Chakra Petch", "Segoe UI", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1418; --surface: #161F25; --surface-2: #1C262D; --ink: #E2E9ED; --muted: #8D9CA6;
    --line: #29353D; --accent: #3BB1BB; --accent-ink: #06272A; --accent-soft: #143B40;
    --signal: #F0A62C; --signal-soft: #3A2C10; --good: #58B47D; --bad: #E7735F;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1418; --surface: #161F25; --surface-2: #1C262D; --ink: #E2E9ED; --muted: #8D9CA6;
  --line: #29353D; --accent: #3BB1BB; --accent-ink: #06272A; --accent-soft: #143B40;
  --signal: #F0A62C; --signal-soft: #3A2C10; --good: #58B47D; --bad: #E7735F;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--f-body); -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--f-display); line-height: 1.2; text-wrap: balance; margin: 0; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.mt { margin-top: 1.4rem; }
.hint { font: 400 .78rem var(--f-body); color: var(--muted); text-transform: none; letter-spacing: 0; }
.err { color: var(--bad); min-height: 1.2em; margin: .4rem 0 0; font-size: .88rem; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: .55rem .7rem; min-width: 0;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.num, .class-timer { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: .55rem .95rem; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); border-color: var(--line); }
.btn.sm { padding: .32rem .65rem; font-size: .85rem; }
.btn.lg { padding: .8rem 1.4rem; font-size: 1rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.brand { display: flex; align-items: center; gap: .55rem; font: 700 1.05rem var(--f-display); letter-spacing: .01em; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 6px; background: var(--accent);
  -webkit-mask: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M5 18h5l3-8 4 14 3-9 2 3h5' fill='none' stroke='white' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: cover;
}

/* ---------- sign in ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px 24px; display: grid; gap: .55rem; box-shadow: var(--shadow);
}
.login-card .brand { font-size: 1.35rem; }
.login-sub { margin: 0 0 .8rem; color: var(--muted); }
.login-card label { font-size: .85rem; font-weight: 500; margin-top: .3rem; }
.login-card .btn { margin-top: .8rem; }

/* ---------- home ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap;
  padding: .7rem 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: .2rem; overflow-x: auto; flex: 1; min-width: 0; }
.tabs button, .side-tabs button, .stage-switch button {
  background: none; border: 0; padding: .45rem .75rem; border-radius: 7px; cursor: pointer;
  color: var(--muted); font-weight: 500; white-space: nowrap;
}
.tabs button[aria-selected="true"], .side-tabs button[aria-selected="true"], .stage-switch button[aria-selected="true"] {
  background: var(--accent-soft); color: var(--ink);
}
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.who { font-weight: 600; }

.join-strip {
  max-width: 1200px; margin: 18px auto 0; padding: 18px 20px; display: flex; gap: 1rem;
  align-items: center; justify-content: space-between; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  width: calc(100% - 32px);
}
.join-strip.live { border-color: var(--signal); background: linear-gradient(90deg, var(--signal-soft), var(--surface) 60%); }
.join-title { font: 600 1.15rem var(--f-display); }
.join-sub { color: var(--muted); font-size: .92rem; max-width: 60ch; }

.home-body { max-width: 1200px; margin: 0 auto; padding-block: 18px 48px; padding-inline: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px 16px; display: grid; gap: 2px;
}
.stat .k { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.stat .v { font: 600 1.7rem var(--f-display); font-variant-numeric: tabular-nums; }
.stat .s { font-size: .82rem; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1.15fr 1fr; gap: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; min-width: 0; }
.panel > h2 { margin-bottom: .9rem; }

.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; margin-bottom: .75rem; }
.bar-row .name { font-weight: 500; font-size: .92rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { font: 500 .82rem var(--f-mono); color: var(--muted); }
.track { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 5px; overflow: hidden; display: flex; border: 1px solid var(--line); }
.track i { display: block; height: 100%; }
.track .taught { background: var(--accent); }
.track .revised { background: var(--good); }
.legend { display: flex; gap: 1rem; font-size: .8rem; color: var(--muted); margin: -.3rem 0 .8rem; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.subject-bars .bar-row { margin-bottom: .55rem; }
.subject-bars .name { font-size: .86rem; }
.paper-tag { font: 600 .68rem var(--f-mono); padding: 1px 5px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); margin-right: 6px; }

.balance-row { display: grid; grid-template-columns: 7rem 1fr auto; gap: 10px; align-items: center; margin-bottom: .5rem; }
.balance-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.balance-row .track { grid-column: auto; }
.mini-list { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .35rem; }
.mini-list li { display: flex; justify-content: space-between; gap: .8rem; font-size: .9rem; padding: .4rem .6rem; background: var(--surface-2); border-radius: 7px; }
.mini-list li span:last-child { color: var(--muted); white-space: nowrap; font-size: .82rem; }
.mini-list .empty { background: none; color: var(--muted); padding-left: 0; }
.week-chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 110px; margin-top: .6rem; }
.week-chart .col { display: grid; grid-template-rows: 1fr auto; gap: 4px; height: 100%; text-align: center; }
.week-chart .barbox { display: flex; align-items: end; justify-content: center; }
.week-chart .bar { width: 70%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.week-chart .bar.zero { background: var(--line); }
.week-chart .d { font: .72rem var(--f-mono); color: var(--muted); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input { flex: 1 1 180px; }
.subj { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 12px; overflow: hidden; }
.subj-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.subj-head h2 { font-size: 1rem; }
.subj-head .val { font: .82rem var(--f-mono); color: var(--muted); white-space: nowrap; }
.topic-row { display: grid; grid-template-columns: 6px minmax(0, 1fr) 9rem 7.5rem 6.5rem; gap: 10px; align-items: center; padding: 8px 14px 8px 0; border-bottom: 1px solid var(--line); }
.topic-row:last-child { border-bottom: 0; }
.topic-row .stripe { align-self: stretch; }
.topic-row[data-status="taught"] .stripe { background: var(--accent); }
.topic-row[data-status="revised"] .stripe { background: var(--good); }
.topic-row[data-status="planned"] .stripe { background: transparent; }
.topic-row .t { font-size: .93rem; min-width: 0; }
.topic-row .ctrls { display: contents; }
.topic-row .meta { font-size: .78rem; color: var(--muted); }
.topic-row select { padding: .3rem .4rem; font-size: .85rem; }
.topic-row .last { font: .78rem var(--f-mono); color: var(--muted); text-align: right; }
.add-topic { display: grid; grid-template-columns: 10rem 1fr 1.4fr auto; gap: 8px; align-items: center; margin-top: 18px; padding: 14px; border: 1px dashed var(--line); border-radius: var(--r); }
.add-topic h3 { grid-column: 1 / -1; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.inline-form input { flex: 1 1 240px; }
.inline-form select { flex: 0 1 260px; }

.card-list { display: grid; gap: 10px; }
.class-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: grid; gap: .4rem; }
.class-card .top { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.class-card .title { font-weight: 600; }
.class-card .sub { color: var(--muted); font-size: .86rem; }
.class-card .mins { font: 500 .9rem var(--f-mono); }
.thumbs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
.thumbs a { flex: 0 0 auto; }
.thumbs img { width: 150px; aspect-ratio: 16/9; object-fit: cover; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); display: block; }
.chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.chip.teach { background: var(--signal-soft); border-color: transparent; color: var(--ink); }
.chip.ok { color: var(--good); }
.chip.no { color: var(--bad); }

.doubt { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--signal); border-radius: 8px; padding: 10px 12px; display: grid; gap: .3rem; }
.doubt.done { border-left-color: var(--good); opacity: .85; }
.doubt .dt { font-size: .93rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.doubt .dm { font-size: .78rem; color: var(--muted); }
.doubt .dans { font-size: .86rem; padding: .4rem .6rem; background: var(--surface-2); border-radius: 6px; white-space: pre-wrap; }
.doubt form { display: flex; gap: 6px; }
.doubt form input { flex: 1; padding: .35rem .55rem; font-size: .85rem; }

table.qtable { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.qtable th, .qtable td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.qtable th { font: 600 .72rem var(--f-body); text-transform: uppercase; letter-spacing: .07em; color: var(--muted); background: var(--surface-2); }
.qtable td.n { font-family: var(--f-mono); text-align: right; }
.qtable td.q { white-space: normal; min-width: 16rem; }

/* ---------- room ---------- */
.room { height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.classbar {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; position: relative;
  padding: .55rem 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.conn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--signal); }
.conn[data-state="online"]::before { background: var(--good); }
.conn[data-state="offline"] { color: var(--bad); }
.conn[data-state="offline"]::before { background: var(--bad); }
.tile[data-conn="connecting"]::after, .tile[data-conn="disconnected"]::after, .tile[data-conn="failed"]::after {
  content: "Connecting video…"; position: absolute; inset: auto 0 40% 0; text-align: center; color: #fff; font-size: .8rem; font-weight: 600; text-shadow: 0 1px 2px rgba(0,0,0,.8);
}
.class-idle { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; min-width: 0; }
.class-idle select { flex: 1 1 200px; max-width: 420px; }
.class-idle select#csTeacher { flex: 0 1 180px; }
.class-live { display: flex; align-items: center; gap: .8rem; flex: 1; min-width: 0; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); box-shadow: 0 0 0 4px color-mix(in srgb, var(--bad) 25%, transparent); flex: 0 0 auto; animation: pulse 2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--bad) 10%, transparent); } }
.class-meta { min-width: 0; flex: 1; }
.class-topic { font: 600 1rem var(--f-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.class-sub { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.class-sub #clTeacher { color: var(--signal); font-weight: 600; }
.class-timer { font-size: 1.05rem; font-weight: 500; }
.end-wrap { position: relative; }
.end-confirm, .clear-confirm {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; display: flex; gap: 6px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; box-shadow: var(--shadow); white-space: nowrap; font-size: .88rem;
}
.hand-alert { position: absolute; left: 50%; top: calc(100% + 8px); transform: translateX(-50%); z-index: 15; background: var(--signal); color: #1b1200; font-weight: 600; padding: 6px 14px; border-radius: 999px; box-shadow: var(--shadow); }

.room-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; min-height: 0; }
.stage { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 10px; gap: 8px; }
.stage-switch { display: flex; gap: 4px; align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.board-wrap { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
.board-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.tool-group { display: flex; gap: 2px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 3px; }
.tool-group button { min-width: 32px; height: 32px; border: 0; border-radius: 6px; background: none; cursor: pointer; font-size: 1rem; display: grid; place-items: center; padding: 0 6px; }
.tool-group button:hover { background: var(--surface-2); }
.tool-group button.on { background: var(--accent); color: var(--accent-ink); }
.tool-group button i { display: block; border-radius: 50%; background: currentColor; }
.tool-group .swatch { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line); }
#colorBtns button.on { background: var(--surface-2); }
#colorBtns button.on .swatch { box-shadow: 0 0 0 2px var(--accent); }
.pages span { font: .82rem var(--f-mono); padding: 0 6px; color: var(--muted); }
.board-box { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; }
#board, #boardFx { position: absolute; border-radius: 8px; touch-action: none; }
#board { background: var(--paper); box-shadow: var(--shadow); border: 1px solid var(--line); }
#boardFx { pointer-events: none; }
.board-box.tool-laser #board { cursor: none; }
.board-box.tool-text #board { cursor: text; }
.board-box #board { cursor: crosshair; }
.text-input { position: absolute; z-index: 5; font: 500 18px var(--f-body); padding: 2px 6px; background: #fff; color: #14202A; border: 1px dashed #0B6E78; min-width: 140px; }
.clear-confirm { top: 8px; right: 8px; }

.video-stage { flex: 1; min-height: 0; display: grid; gap: 8px; grid-auto-rows: 1fr; }
.video-stage video { width: 100%; height: 100%; object-fit: contain; background: #0A0F12; border-radius: 10px; min-height: 0; }
.video-stage .vs-empty { display: grid; place-items: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: 10px; }

.side { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: var(--surface); }
.tiles { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 8px; position: relative; }
.tile { position: relative; aspect-ratio: 16/9; background: #0A0F12; border-radius: 9px; overflow: hidden; max-width: 100%; }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.me { position: absolute; width: 34%; right: 14px; bottom: 14px; z-index: 2; border: 2px solid var(--surface); box-shadow: var(--shadow); }
.tiles:not(.has-peer) .tile.me { position: relative; width: 100%; right: auto; bottom: auto; border: 0; }
.tile.me video { transform: scaleX(-1); }
.tile.me.screen video { transform: none; }
.tile-label { position: absolute; left: 6px; bottom: 6px; right: 6px; display: flex; justify-content: space-between; gap: 4px; color: #fff; font-size: .78rem; font-weight: 600; text-shadow: 0 1px 2px rgba(0,0,0,.7); pointer-events: none; }
.tile-flags { display: flex; gap: 3px; }
.tile.speaking { box-shadow: 0 0 0 3px var(--accent); }
.tile .no-cam { position: absolute; inset: 0; display: grid; place-items: center; color: #9fb0bb; font: 600 1.6rem var(--f-display); background: #121A20; }
.tile .hand { position: absolute; top: 6px; left: 6px; background: var(--signal); color: #1b1200; border-radius: 999px; padding: 1px 8px; font-size: .8rem; font-weight: 700; }
.tile .teach-tag { position: absolute; top: 6px; right: 6px; background: var(--signal); color: #1b1200; border-radius: 4px; padding: 0 6px; font: 700 .68rem var(--f-mono); letter-spacing: .06em; }

.side-tabs { display: flex; gap: 2px; padding: 0 8px 6px; border-bottom: 1px solid var(--line); }
.side-tabs button { flex: 1; }
.side-tabs b { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font: 600 .7rem var(--f-mono); line-height: 18px; }
.side-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.chat-log { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { display: grid; gap: 1px; max-width: 92%; }
.msg .mh { font-size: .74rem; color: var(--muted); }
.msg .mb { background: var(--surface-2); border-radius: 10px; padding: 6px 10px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .92rem; }
.msg.mine { align-self: flex-end; }
.msg.mine .mh { text-align: right; }
.msg.mine .mb { background: var(--accent-soft); }
.msg.sys { align-self: center; max-width: 100%; }
.msg.sys .mb { background: none; color: var(--muted); font-size: .8rem; padding: 0; text-align: center; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; }
#doubtForm { border-top: 0; border-bottom: 1px solid var(--line); }
.room-doubts { overflow-y: auto; padding: 10px; display: grid; gap: 8px; align-content: start; }

.quiz-form { padding: 10px 12px; display: grid; gap: .45rem; overflow-y: auto; }
.quiz-form label { font-size: .82rem; font-weight: 600; }
.q-opts { display: grid; gap: 6px; }
.q-opt { display: grid; grid-template-columns: auto 1.5rem 1fr; align-items: center; gap: 6px; }
.q-opt .L { font: 600 .85rem var(--f-mono); color: var(--muted); }
.q-opt input[type="text"] { padding: .4rem .55rem; }
.q-row { display: flex; align-items: center; gap: 8px; }
.quiz-wait { padding: 14px; display: grid; gap: .7rem; }
.wait-q { font-weight: 500; }
.quiz-score { padding: 4px 12px 12px; font-size: .86rem; color: var(--muted); }
.quiz-score b { color: var(--ink); font-family: var(--f-mono); }
.countbar { height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.countbar i { display: block; height: 100%; background: var(--signal); width: 100%; transform-origin: left; }

.controls {
  display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; align-items: center;
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: 1px solid var(--line);
}
.ctl { display: grid; justify-items: center; gap: 1px; min-width: 54px; padding: 4px 6px; border: 0; background: none; border-radius: 9px; cursor: pointer; font-size: 1.15rem; }
.ctl .lbl { font-size: .68rem; color: var(--muted); font-weight: 500; }
.ctl:hover { background: var(--surface-2); }
.ctl.off { background: color-mix(in srgb, var(--bad) 16%, transparent); }
.ctl.off .lbl { color: var(--bad); }
.ctl.on { background: var(--signal-soft); }
.ctl-sep { width: 1px; height: 28px; background: var(--line); margin: 0 6px; }

.reactions-fx { position: absolute; right: 24px; bottom: 16px; width: 200px; height: 60%; pointer-events: none; overflow: hidden; }
.float {
  position: absolute; bottom: 0; right: 0; display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px 4px 6px;
  box-shadow: var(--shadow); font-size: .82rem; font-weight: 600; animation: rise 3.2s ease-out forwards;
}
.float .e { font-size: 1.3rem; }
@keyframes rise { 0% { transform: translateY(10px); opacity: 0; } 12% { opacity: 1; } 80% { opacity: 1; } 100% { transform: translateY(-260px); opacity: 0; } }

.modal { position: fixed; inset: 0; z-index: 50; background: rgba(8, 14, 18, .55); display: grid; place-items: center; padding: 16px; }
.modal-card { width: min(560px, 100%); background: var(--surface); border-radius: 14px; padding: 22px; display: grid; gap: .9rem; box-shadow: var(--shadow); max-height: 100%; overflow-y: auto; }
.modal-eyebrow { font: 600 .75rem var(--f-body); text-transform: uppercase; letter-spacing: .08em; color: var(--signal); }
.qm-text { font: 500 1.1rem/1.45 var(--f-body); white-space: pre-wrap; overflow-wrap: anywhere; }
.qm-opts { display: grid; gap: 8px; }
.qm-opts button, .qm-opts div {
  text-align: left; display: grid; grid-template-columns: 1.8rem 1fr; gap: .4rem; align-items: start;
  padding: .7rem .8rem; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); cursor: pointer; overflow-wrap: anywhere;
}
.qm-opts button:hover { border-color: var(--accent); }
.qm-opts .L { font: 600 .9rem var(--f-mono); color: var(--muted); }
.qm-opts .right { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--surface)); }
.qm-opts .wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, var(--surface)); }
.qm-foot { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font: .85rem var(--f-mono); }
.result-head { font: 700 1.4rem var(--f-display); }
.result-head.correct { color: var(--good); }
.result-head.wrong { color: var(--bad); }
.result-head.skipped { color: var(--muted); }
.rs-expl { margin: 0; color: var(--muted); font-size: .92rem; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 9px; font-size: .9rem; max-width: calc(100% - 32px); box-shadow: var(--shadow); }

/* ---------- narrow screens ---------- */
@media (max-width: 960px) {
  .two-col { grid-template-columns: 1fr; }
  .room { height: auto; min-height: 100%; }
  .room-grid { grid-template-columns: 1fr; }
  .side { border-left: 0; border-top: 1px solid var(--line); order: -1; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .tile.me, .tiles:not(.has-peer) .tile.me { position: relative; width: 100%; right: auto; bottom: auto; border: 0; }
  .side-pane { max-height: 46vh; }
  .stage { min-height: 70vw; }
  .board-box { min-height: 56vw; }
  .controls { position: sticky; bottom: 0; z-index: 10; }
  .ctl .lbl { display: none; }
  .ctl { min-width: 42px; }
  .topic-row { grid-template-columns: 6px minmax(0, 1fr); }
  .topic-row .ctrls { grid-column: 2; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
  .topic-row .ctrls select { flex: 1 1 8rem; }
  .add-topic { grid-template-columns: 1fr; }
  .balance-row { grid-template-columns: 5rem 1fr auto; }
}
@media (max-width: 960px) {
  .topic-row .last { text-align: left; }
}

/* ===================== v5: play layer ===================== */
:root { --xp: #6D4AFF; --xp-soft: #ECE7FF; --fire: #F26A1B; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --xp: #A78BFA; --xp-soft: #2A2246; --fire: #FF8A3D; } }
:root[data-theme="dark"] { --xp: #A78BFA; --xp-soft: #2A2246; --fire: #FF8A3D; }

/* players strip */
.players { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-bottom: 14px; }
.player { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.player.me { border-color: color-mix(in srgb, var(--xp) 45%, var(--line)); }
.lv-badge { width: 54px; height: 54px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(135deg, var(--xp), var(--accent)); color: #fff; transform: rotate(-4deg); box-shadow: var(--shadow); }
.lv-n { font: 700 1.5rem var(--f-display); transform: rotate(4deg); }
.pl-main { min-width: 0; display: grid; gap: 5px; }
.pl-name { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.pl-title { font: 600 .8rem var(--f-display); color: var(--xp); text-transform: uppercase; letter-spacing: .06em; }
.xpbar { height: 10px; border-radius: 6px; background: var(--xp-soft); overflow: hidden; }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--xp), var(--accent)); border-radius: 6px; transition: width .6s ease; }
.pl-meta { font-size: .78rem; color: var(--muted); }
.pl-side { display: grid; gap: 4px; justify-items: end; font-weight: 700; }
.flame { color: var(--fire); font-size: 1.05rem; }
.flame.cold { filter: grayscale(1); opacity: .5; }
.pl-badges { font-size: .9rem; color: var(--muted); }
.mt-panel { margin-top: 14px; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.badge { display: grid; gap: 2px; padding: 10px; border: 1px dashed var(--line); border-radius: 10px; font-size: .78rem; color: var(--muted); opacity: .55; }
.badge .bi { font-size: 1.5rem; filter: grayscale(1); }
.badge b { color: var(--ink); font-size: .86rem; }
.badge.got { opacity: 1; border-style: solid; border-color: color-mix(in srgb, var(--xp) 40%, var(--line)); background: var(--xp-soft); }
.badge.got .bi { filter: none; }

/* flashcards */
.stats.three { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.card-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.add-card { display: grid; grid-template-columns: 12rem 1fr 1fr auto; gap: 8px; align-items: start; padding: 14px; border: 1px dashed var(--line); border-radius: var(--r); margin-bottom: 16px; }
.add-card h3 { grid-column: 1 / -1; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.fcard { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; min-width: 0; }
.fc-front { font-weight: 600; overflow-wrap: anywhere; white-space: pre-wrap; }
.fc-back { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; white-space: pre-wrap; border-top: 1px dashed var(--line); padding-top: 6px; }
.fc-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .76rem; color: var(--muted); flex-wrap: wrap; }
.boxes { color: var(--xp); letter-spacing: 2px; }
.fcard.mini { padding: 8px 10px; font-size: .88rem; }

.review-wrap { width: min(520px, 100%); display: grid; gap: 14px; justify-items: center; }
.rv-top { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px; color: #fff; font-weight: 600; }
.rv-top .btn { color: #fff; }
.rv-card { position: relative; width: 100%; aspect-ratio: 3 / 2; max-width: 100%; perspective: 1200px; cursor: grab; touch-action: pan-y; transition: transform .25s ease, opacity .25s ease; user-select: none; }
.rv-card.dragging { transition: none; cursor: grabbing; }
.rv-face { position: absolute; inset: 0; border-radius: 18px; padding: 26px 24px; display: grid; place-items: center; text-align: center; backface-visibility: hidden; transition: transform .45s cubic-bezier(.2,.8,.2,1); box-shadow: 0 18px 50px rgba(0,0,0,.35); font: 500 1.25rem/1.45 var(--f-body); overflow-wrap: anywhere; white-space: pre-wrap; }
.rv-front { background: var(--surface); color: var(--ink); }
.rv-back { background: linear-gradient(140deg, var(--xp), var(--accent)); color: #fff; transform: rotateY(180deg); }
.rv-card.flipped .rv-front { transform: rotateY(-180deg); }
.rv-card.flipped .rv-back { transform: rotateY(0); }
.rv-label { position: absolute; top: 12px; left: 16px; font: 600 .7rem var(--f-body); text-transform: uppercase; letter-spacing: .1em; opacity: .6; }
.rv-tip { position: absolute; bottom: 12px; font-size: .75rem; opacity: .5; }
.rv-card[data-hint="know"] .rv-face { box-shadow: 0 0 0 4px var(--good), 0 18px 50px rgba(0,0,0,.35); }
.rv-card[data-hint="revise"] .rv-face { box-shadow: 0 0 0 4px var(--bad), 0 18px 50px rgba(0,0,0,.35); }
.rv-card.out-right { transform: translateX(140%) rotate(18deg) !important; opacity: 0; }
.rv-card.out-left { transform: translateX(-140%) rotate(-18deg) !important; opacity: 0; }
.rv-btns { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.rv-again { border-color: var(--bad); color: var(--bad); }
.rv-know { background: var(--good); border-color: var(--good); color: #fff; }
.rv-done { color: #fff; font: 600 1.15rem var(--f-display); text-align: center; margin: 0; }
.rv-keys { color: #cfd8de; }

/* question bank */
.bank-form, .gen-form { display: grid; gap: 8px; align-content: start; }
.gen-form .q-row { gap: 8px; }
.bq { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: grid; gap: 6px; }
.bq-q { font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.bq-opts { margin: 0; padding-left: 1.4rem; font-size: .9rem; color: var(--muted); display: grid; gap: 2px; }
.bq-opts .right { color: var(--good); font-weight: 600; }
code { font-family: var(--f-mono); font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* room: xp, stage top, battle bar */
.xp-pill { font-size: .78rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--xp-soft); color: var(--xp); white-space: nowrap; }
.xp-pill:empty { display: none; }
.stage-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.battle-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; flex: 1; min-width: 0; padding: 5px 8px 5px 12px; border-radius: 10px; background: linear-gradient(90deg, var(--xp-soft), var(--signal-soft)); border: 1px solid color-mix(in srgb, var(--xp) 30%, var(--line)); }
.bb-kind { font: 700 .95rem var(--f-display); }
.bb-q { font-size: .8rem; color: var(--muted); }
.bb-scores { display: flex; gap: 6px; flex-wrap: wrap; }
.bb-p { display: inline-flex; gap: 6px; align-items: center; padding: 2px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: .85rem; }
.bb-p.lead { border-color: var(--signal); box-shadow: 0 0 0 2px color-mix(in srgb, var(--signal) 25%, transparent); }
.bb-p.me b { color: var(--xp); }
.bb-fire { color: var(--fire); font-weight: 700; animation: flick 1s infinite alternate; }
@keyframes flick { to { transform: scale(1.15); } }
.bb-turn { font-size: .82rem; font-weight: 600; color: var(--signal); margin-left: auto; }

/* lightboard */
#lightVideo { position: absolute; border-radius: 8px; object-fit: cover; transform: scaleX(-1); background: #0A0F12; box-shadow: var(--shadow); }
.board-box.light #board { background: transparent; border-color: transparent; box-shadow: none; }
.light-hint { position: absolute; z-index: 3; left: 50%; top: 50%; transform: translate(-50%, -50%); margin: 0; color: #fff; background: rgba(10,15,20,.7); padding: 10px 16px; border-radius: 10px; font-weight: 600; text-align: center; }
.hands-btn.on { background: var(--xp) !important; color: #fff !important; }
.gesture-chip { position: absolute; left: 12px; bottom: 12px; z-index: 6; padding: 5px 12px; border-radius: 999px; background: rgba(10,15,20,.75); color: #fff; font-size: .82rem; font-weight: 600; pointer-events: none; }
.hands-help { position: absolute; z-index: 25; right: 12px; top: 12px; width: min(440px, calc(100% - 24px)); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); display: grid; gap: 8px; }
.hh-head { display: flex; justify-content: space-between; align-items: center; }
.hh-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hh-cols ul { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 5px; font-size: .86rem; }
.hh-cols li span { display: inline-block; width: 1.6rem; }

/* battle controls (quiz pane) */
.battle-ctl { padding: 10px 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; background: linear-gradient(180deg, var(--xp-soft), transparent); }
#battleIdle { display: grid; gap: 8px; }
.bc-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn.battle { background: var(--xp); border-color: var(--xp); color: #fff; font-weight: 600; }
.btn.battle:disabled { background: var(--surface-2); border-color: var(--line); color: var(--muted); }
.battle-live { margin: 0; font-weight: 600; color: var(--xp); font-size: .9rem; }
.room-card-form { display: grid; gap: 6px; padding: 8px; border-bottom: 1px solid var(--line); }

/* results, buzzer, battle end */
.rs-combo { margin: 0; font-weight: 700; color: var(--fire); }
.buzz-card { text-align: left; }
.buzz-btn { justify-self: center; width: 150px; height: 150px; border-radius: 50%; border: 0; cursor: pointer; font: 700 1.6rem var(--f-display); letter-spacing: .08em; color: #fff;
  background: radial-gradient(circle at 35% 30%, #ff6b5e, #c0392b 60%, #7d1f16); box-shadow: 0 10px 0 #6d1a12, 0 16px 30px rgba(0,0,0,.3); transition: transform .08s, box-shadow .08s; }
.buzz-btn:active { transform: translateY(8px); box-shadow: 0 2px 0 #6d1a12, 0 6px 14px rgba(0,0,0,.3); }
.buzz-btn:disabled { filter: grayscale(.8) brightness(.9); cursor: default; }
.be-rows { display: grid; gap: 8px; }
.be-row { display: grid; grid-template-columns: 2rem 1fr auto; gap: 2px 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.be-row.win { border-color: var(--signal); background: var(--signal-soft); }
.be-rank { font-size: 1.4rem; grid-row: span 2; }
.be-sub { grid-column: 2 / -1; font-size: .8rem; color: var(--muted); }

/* floating chips */
.fx-float { position: fixed; left: 50%; top: 42%; z-index: 80; transform: translate(-50%, 0); padding: 8px 18px; border-radius: 999px; font: 700 1.1rem var(--f-display); color: #fff; background: var(--xp); box-shadow: var(--shadow); pointer-events: none; animation: xpup 1.8s ease-out forwards; }
.fx-float.combo { background: var(--fire); top: 50%; }
@keyframes xpup { 0% { opacity: 0; transform: translate(-50%, 20px) scale(.8); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.08); } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60px) scale(1); } }

@media (max-width: 960px) {
  .add-card { grid-template-columns: 1fr; }
  .hh-cols { grid-template-columns: 1fr; }
  .bb-turn { margin-left: 0; }
}


/* ===================== v6: Air Board, clean room ===================== */
.board-tools.air .t-adv { display: none; }
.board-tools:not(.air) .air-only { display: none; }
#bgBtns button { font-size: .85rem; padding: 0 10px; }
#bgBtns button.on { background: var(--accent); color: var(--accent-ink); }
.hands-btn { font-size: .85rem !important; font-weight: 600; padding: 0 12px !important; }
#lightVideo { filter: brightness(.86) contrast(1.06) saturate(.9); }
.board-box.light #board { border-radius: 10px; }
.gesture-chip { left: 50%; transform: translateX(-50%); bottom: 14px; letter-spacing: .01em; background: rgba(12,18,24,.72); backdrop-filter: blur(6px); }
.gesture-chip::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #4ADE80; margin-right: 8px; vertical-align: 1px; }
.controls { gap: 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
