:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #dfe2e6;
  --text: #1c1f24;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #e8f0fe;
  --warn: #d97706;
  --bad: #dc2626;
  --good: #16a34a;
  --radius: 10px;
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  color: var(--text);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
[hidden] {
  display: none !important;
}
button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* ---------- 입장 ---------- */
.join {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 16px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.join-card {
  width: min(360px, 100%);
  padding: 24px;
  display: grid;
  gap: 14px;
}
.join-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
}
.join-card label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}
.join-card input {
  font: inherit;
  font-size: 18px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
}
.primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 12px;
  font-size: 17px;
  font-weight: 600;
}
.error {
  color: var(--bad);
  min-height: 1em;
  margin: 0;
  font-size: 14px;
}

/* ---------- 공통 막대 ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.status {
  font-size: 13px;
  color: var(--muted);
  margin-left: auto;
}
.status::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--warn);
  vertical-align: 1px;
}
.status[data-state='open']::before {
  background: var(--good);
}
.status[data-state='closed']::before {
  background: var(--bad);
}
.badge {
  font-size: 13px;
  padding: 3px 10px;
  border-radius: 999px;
}
.watching {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.tool {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 14px;
  min-height: 38px;
}
.tool.on {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ---------- 학생 ---------- */
body.student {
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.class {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.who {
  font-weight: 600;
}
.tools {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.swatch {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid var(--panel);
  background: var(--c);
  box-shadow: 0 0 0 1px var(--line);
  flex: none;
}
.swatch.on {
  box-shadow: 0 0 0 3px var(--accent);
}
.sep {
  width: 1px;
  height: 26px;
  background: var(--line);
  flex: none;
}
.board-area {
  flex: 1;
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  padding: 8px;
}
.board {
  display: block;
  background: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.12);
  touch-action: none;
}
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(244 245 247 / 0.85);
  font-size: 18px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

/* ---------- 선생님 ---------- */
.teacher-bar .room {
  font-size: 17px;
}
.count {
  font-size: 14px;
  color: var(--muted);
}
.join-hint {
  font-size: 13px;
  color: var(--muted);
}
.join-hint code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 6px;
  color: var(--text);
  user-select: all;
}
.spacer {
  flex: 1;
}
.label {
  font-size: 13px;
  color: var(--muted);
}
.segmented {
  display: inline-flex;
  gap: 4px;
}
.teacher-bar .status {
  margin-left: 0;
}
.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  margin: 0;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  padding: 14px;
}
.student-card {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 6px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.2s;
}
.student-card:hover {
  border-color: #b8c0cc;
}
.student-card.writing {
  border-color: var(--accent);
}
.student-card.offline {
  opacity: 0.55;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  min-width: 0;
}
.card-head .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.diag {
  font-size: 11.5px;
  color: var(--muted);
  min-height: 1.3em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.diag.slow {
  color: var(--bad);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--good);
  flex: none;
}
.offline .dot {
  background: var(--muted);
}
.thumb {
  aspect-ratio: 1 / 1.4142;
  width: 100%;
  display: grid;
  place-items: center;
  background: var(--bg);
  border-radius: 6px;
  overflow: hidden;
}
.thumb canvas {
  display: block;
}
.zoom {
  position: fixed;
  inset: 0;
  background: rgb(15 18 24 / 0.55);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 10;
}
.zoom-panel {
  background: var(--panel);
  border-radius: var(--radius);
  width: min(900px, 100%);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.zoom-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.zoom-note {
  font-size: 13px;
  color: var(--muted);
  flex: 1;
}
.zoom-area {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  background: var(--bg);
}

/* ================= 2단계 ================= */
.tool.small {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 13px;
}
.tool.warn {
  border-color: #f59e0b;
  background: #fff7e6;
  color: #92400e;
  font-weight: 600;
}
.tool:disabled {
  opacity: 0.45;
  cursor: default;
}
.primary.small {
  padding: 7px 14px;
  font-size: 15px;
}
.primary:disabled {
  opacity: 0.5;
}
.swatch.small {
  width: 28px;
  height: 28px;
  border-width: 2px;
}
.shared {
  background: #fef3c7;
  color: #92400e;
  font-weight: 600;
}
.badge.note {
  background: #dcfce7;
  color: #166534;
  font-weight: 600;
}

/* ---------- 학생: 질문 핀 ---------- */
.pin-tool.on {
  border-color: #f59e0b;
  background: #fff7e6;
  color: #92400e;
}
.board.pin-mode {
  cursor: crosshair;
  outline: 3px dashed #f59e0b;
  outline-offset: 2px;
}

/* ---------- 학생: 답안 ---------- */
.quizbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: #f0f6ff;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.choices {
  display: inline-flex;
  gap: 8px;
}
.choice {
  min-width: 48px;
  min-height: 44px;
  font-size: 20px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.choice.on {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}
.choice.correct {
  border-color: var(--good);
  background: #dcfce7;
  color: #166534;
}
.choice.wrong {
  border-color: var(--bad);
  background: #fee2e2;
  color: #991b1b;
}
.choice:disabled {
  cursor: default;
}
.quiz-msg {
  font-size: 14px;
  color: var(--muted);
}

/* ---------- 학생: 공유 칠판 ---------- */
.spot {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: min(46%, 520px);
  height: min(60%, 560px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 5;
}
.spot.collapsed {
  height: auto;
  width: auto;
}
.spot.collapsed .spot-boards {
  display: none;
}
.spot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.spot-boards {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 8px;
  padding: 8px;
  background: var(--bg);
}
.spot-item {
  flex: 1;
  min-width: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.spot-item figcaption {
  font-size: 13px;
  font-weight: 600;
  height: 20px;
}
.spot-item canvas {
  display: block;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.12);
}

/* ---------- 선생님: 배치 ---------- */
body.teacher {
  overflow: hidden;
}
.teacher-main {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.content {
  flex: 1;
  min-height: 0;
  display: flex;
}
.grid-wrap {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}
.spot-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  background: #fef3c7;
  color: #92400e;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 1px solid #fcd34d;
}

/* ---------- 선생님: 학생 카드 ---------- */
.student-card.attention {
  border-color: #f59e0b;
}
.student-card.question {
  box-shadow: 0 0 0 3px #fde68a;
}
.student-card.writing {
  border-color: var(--accent);
}
.student-card.is-spot .card-head .name::after {
  content: ' · 공유 중';
  color: #b45309;
  font-weight: 600;
}
.flags {
  font-size: 12px;
  font-weight: 700;
  color: #b45309;
  min-height: 0;
}
.flags:empty {
  display: none;
}
.answer-chip {
  margin-left: auto;
  font-size: 11.5px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  white-space: nowrap;
  background: var(--bg);
  color: var(--muted);
  flex: none;
}
.answer-chip[data-kind='picking'] {
  background: var(--accent-soft);
  color: var(--accent);
}
.answer-chip[data-kind='done'] {
  background: #e5e7eb;
  color: var(--text);
}
.answer-chip[data-kind='right'] {
  background: #dcfce7;
  color: #166534;
}
.answer-chip[data-kind='wrong'] {
  background: #fee2e2;
  color: #991b1b;
}

/* ---------- 선생님: 답안 현황판 ---------- */
.quiz-panel {
  width: 300px;
  flex: none;
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 12px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.quiz-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.bars {
  display: grid;
  gap: 8px;
}
.bar-row {
  display: grid;
  grid-template-columns: 44px 1fr 56px;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}
.bar-row.correct .bar-label {
  color: #166534;
  font-weight: 700;
}
.bar {
  height: 18px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
}
.bar-sub {
  background: var(--accent);
}
.bar-pick {
  background: #93b4f5;
}
.bar-row.correct .bar-sub {
  background: var(--good);
}
.bar-num {
  font-size: 13px;
  color: var(--muted);
  text-align: right;
}
.legend {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.legend .sw {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}
.legend .sw.sub {
  background: var(--accent);
}
.legend .sw.pick {
  background: #93b4f5;
  margin-left: 8px;
}
.quiz-summary {
  margin: 0;
  font-weight: 600;
}
.quiz-missing {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}
.quiz-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ---------- 선생님: 크게 보기 도구 ---------- */
.zoom-head {
  flex-wrap: wrap;
}
.zoom-tools {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
p.zoom-note {
  flex: none;
  margin: 0;
  padding: 6px 14px;
  font-size: 12.5px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

/* ---------- 선생님: 문제 내기 ---------- */
.quiz-dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  width: min(360px, 92vw);
}
.quiz-dialog::backdrop {
  background: rgb(15 18 24 / 0.45);
}
.quiz-form {
  padding: 20px;
  display: grid;
  gap: 12px;
}
.quiz-form h2 {
  margin: 0;
  font-size: 19px;
}
.quiz-form .hint {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}
.quiz-form label {
  display: grid;
  gap: 4px;
  font-size: 14px;
  color: var(--muted);
}
.quiz-form select {
  font: inherit;
  font-size: 16px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

/* ================= 3단계: 학습 기록 ================= */
body.records {
  overflow: hidden;
}
.records-main {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.records-body {
  flex: 1;
  min-height: 0;
  display: flex;
}
.sessions-col {
  width: 240px;
  flex: none;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  padding: 10px;
}
.sessions-col h3 {
  margin: 4px 4px 8px;
  font-size: 14px;
  color: var(--muted);
}
.sessions {
  display: grid;
  gap: 6px;
}
.session,
.student-chip {
  display: grid;
  gap: 2px;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 10px;
}
.session.on,
.student-chip.on {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.muted {
  color: var(--muted);
  font-size: 12.5px;
}
.small-text {
  font-size: 12px;
}
.pane {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 14px;
}
.student-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.viewer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: calc(100% - 70px);
  min-height: 420px;
}
.viewer-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.timeline {
  position: relative;
  height: 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}
.marks {
  position: absolute;
  inset: 0;
}
.mark {
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 3px;
  min-width: 3px;
  border-radius: 2px;
}
.mark.pause {
  background: rgb(245 158 11 / 0.35);
}
.mark.erase {
  background: var(--bad);
}
.mark.pin {
  background: #f59e0b;
  top: 0;
  bottom: 0;
}
.mark.note {
  background: var(--good);
}
.mark.answer {
  background: var(--accent);
}
.playhead {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--text);
  pointer-events: none;
}
.legend .sw.pause {
  background: rgb(245 158 11 / 0.45);
}
.legend .sw.erase {
  background: var(--bad);
  margin-left: 8px;
}
.legend .sw.pin {
  background: #f59e0b;
  margin-left: 8px;
}
.legend .sw.note {
  background: var(--good);
  margin-left: 8px;
}
.legend .sw.answer {
  background: var(--accent);
  margin-left: 8px;
}
.viewer-body {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 14px;
}
.rv-area {
  flex: 1;
  min-width: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  border-radius: 8px;
}
.rv-side {
  width: 360px;
  flex: none;
  overflow-y: auto;
}
.rv-side h3 {
  margin: 0 0 6px;
  font-size: 14px;
}
table.matrix {
  border-collapse: collapse;
  width: 100%;
  background: var(--panel);
  font-size: 13.5px;
}
table.matrix th,
table.matrix td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}
table.matrix th {
  background: var(--bg);
  font-weight: 600;
}
table.matrix.small {
  font-size: 12.5px;
}
table.matrix td.cell {
  background: rgb(37 99 235 / calc(var(--heat, 0) * 0.22));
}
table.matrix td.cell strong,
table.matrix td.cell span {
  display: block;
}
table.matrix td.name {
  font-weight: 600;
  white-space: nowrap;
}
table.matrix tr.foot td {
  background: #f8fafc;
  font-weight: 600;
}
#stats-body h2 {
  font-size: 17px;
  margin: 6px 0 10px;
}
#stats-body .note {
  font-weight: 600;
  color: #b45309;
}

/* 오답 모음 */
.wrong-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.wrong-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.wrong-card.checked {
  border-color: var(--good);
}
.wrong-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.wrong-head h2 {
  margin: 0;
  font-size: 18px;
}
.wrong-actions {
  margin-left: auto;
  display: inline-flex;
  gap: 8px;
  align-items: center;
}
.summary:empty {
  display: none;
}
.summary {
  background: #f0fdf4;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0 0 10px;
  font-size: 14px;
}
.wrong-item {
  display: flex;
  gap: 14px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.wrong-pic {
  width: 260px;
  flex: none;
  min-height: 80px;
  display: grid;
  place-items: center;
  background: var(--bg);
  border-radius: 6px;
}
.wrong-pic img {
  max-width: 100%;
  display: block;
  border: 1px solid var(--line);
}
.wrong-meta {
  display: grid;
  gap: 4px;
  align-content: start;
  flex: 1;
  min-width: 0;
}
.bad {
  color: #991b1b;
  font-weight: 600;
}
.ai-line:empty {
  display: none;
}
.ai-line {
  font-size: 13.5px;
  background: #f5f3ff;
  color: #4c1d95;
  border-radius: 6px;
  padding: 4px 8px;
}
.memo {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  resize: vertical;
}
.foot-note {
  margin: 8px 0 0;
}

@media print {
  body.records {
    overflow: visible;
    background: #fff;
  }
  .no-print,
  .sessions-col {
    display: none !important;
  }
  .records-main,
  .records-body,
  .pane {
    display: block;
    height: auto;
    overflow: visible;
    padding: 0;
  }
  .wrong-card {
    break-after: page;
    border: 0;
    padding: 0;
  }
  body.print-some .wrong-card:not(.print-target) {
    display: none;
  }
  .memo {
    border: 0;
    padding: 0;
    resize: none;
  }
  .memo:placeholder-shown {
    display: none;
  }
}
a.tool {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
/* 기록 화면 보정 */
.viewer {
  height: auto;
  min-height: 0;
}
.viewer-body {
  flex: none;
  height: max(420px, calc(100vh - 290px));
}
.rv-side {
  width: 390px;
}
table.matrix th,
table.matrix td:first-child {
  white-space: nowrap;
}
a.tool,
a.tool:visited {
  color: inherit;
}

/* ================= 음성 수업 ================= */
.badge.voice {
  background: #eef2ff;
  color: #3730a3;
  font-weight: 600;
}
.badge.voice.live {
  background: #fee2e2;
  color: #b91c1c;
}
#hand-btn.on {
  border-color: #f59e0b;
  background: #fff7e6;
  color: #92400e;
}
.tool.on#voice-btn {
  border-color: var(--bad);
  background: #fee2e2;
  color: #991b1b;
}
.mic-meter {
  width: 60px;
  height: 8px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  overflow: hidden;
  display: inline-block;
}
.mic-meter span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--good);
  transition: width 0.1s;
}
.voice-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  background: #eef2ff;
  border-bottom: 1px solid #c7d2fe;
  font-size: 14px;
  flex-wrap: wrap;
}
.voice-items {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}
.voice-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 4px 2px 10px;
  font-weight: 600;
}
.voice-chip.live {
  border-color: var(--bad);
  color: #991b1b;
}
.voice-dot {
  width: 14px;
  height: 14px;
  flex: none;
  font-size: 11px;
  line-height: 14px;
  text-align: center;
}
.voice-dot::before {
  content: '🔈';
  opacity: 0.4;
}
.voice-dot[data-state='connected']::before {
  opacity: 1;
}
.student-card.speaking {
  border-color: var(--bad);
  box-shadow: 0 0 0 3px #fecaca;
}
#zoom-talk.on {
  border-color: var(--bad);
  background: #fee2e2;
  color: #991b1b;
}
