:root {
  --bg: #fbf7ef;
  --surface: #ffffff;
  --soft: #f4efe4;
  --ink: #2b2a33;
  --muted: #6f6a78;
  --line: #e7e0d2;
  --brand: #5b5bd6;
  --brand-ink: #ffffff;
  --brand-soft: #ecebff;
  --accent: #ff9f43;
  --good: #20a26b;
  --good-soft: #e3f6ec;
  --warn-soft: #fff4dc;
  --warn-line: #f2c86b;
  --danger: #e5484d;
  --danger-soft: #ffeceb;
  --gold: #f5b800;
  --gold-soft: #fff7d1;
  /* 질문 종류 색 */
  --k-fact: #3b82f6;
  --k-why: #8b5cf6;
  --k-whatif: #ec4899;
  --k-value: #0d9488;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(40, 30, 10, 0.06), 0 4px 14px rgba(40, 30, 10, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Noto Sans KR', system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  font-size: 16px;
  line-height: 1.55;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
h1, h2, h3, h4 { font-family: 'Jua', 'Noto Sans KR', sans-serif; font-weight: 400; line-height: 1.3; margin: 0.4em 0; }
h1 { font-size: 2.4rem; }
h2 { font-size: 1.7rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.08rem; margin-top: 1.2em; }
a { color: var(--brand); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.hidden, [hidden] { display: none !important; }
.pre { white-space: pre-wrap; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.center { text-align: center; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.grow { flex: 1; min-width: 0; }

/* ---------- 레이아웃 ---------- */
#app { min-height: 100vh; }
.screen { max-width: 980px; margin: 0 auto; padding: 16px 16px 80px; }
.screen.narrow { max-width: 640px; }
.screen.wide { max-width: 1280px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.tight { gap: 2px; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row.wrap { flex-wrap: wrap; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; min-height: 40px; }
.back { text-decoration: none; font-weight: 700; color: var(--muted); padding: 6px 0; }
.back:hover { color: var(--brand); }
section { margin: 20px 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin: 16px 0; }
.panel.soft { background: var(--soft); box-shadow: none; }
.panel > h3:first-child { margin-top: 0; }
details > summary { cursor: pointer; font-weight: 700; padding: 4px 0; }
details[open] > summary { margin-bottom: 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

/* ---------- 버튼 · 입력 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 9px 16px; font-weight: 700; text-decoration: none; color: var(--ink);
  min-height: 42px; transition: transform 0.06s, background 0.15s;
}
.btn:hover:not(:disabled) { background: var(--soft); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover:not(:disabled) { background: #4a4ac4; }
.btn.danger, .btn.primary.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-outline { color: var(--danger); border-color: #f3b7b9; }
.btn.danger-outline:hover:not(:disabled) { background: var(--danger-soft); }
.btn.small { min-height: 34px; padding: 5px 12px; font-size: 0.9rem; border-radius: 10px; }
.link { background: none; border: 0; color: var(--brand); text-decoration: underline; padding: 0; font-weight: 700; }
.icon-btn { background: none; border: 0; border-radius: 8px; padding: 4px 7px; font-size: 1.05rem; line-height: 1; min-width: 34px; min-height: 34px; opacity: 0.75; }
.icon-btn:hover { background: var(--soft); opacity: 1; }
.icon-btn.on { opacity: 1; background: var(--gold-soft); }

.input {
  width: 100%; border: 1.5px solid var(--line); background: #fffdf9; border-radius: 12px;
  padding: 10px 12px; resize: vertical; min-height: 44px;
}
.input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--brand-soft); }
.input:disabled { background: var(--soft); color: var(--muted); }
.input.short { width: auto; max-width: 200px; }
.input.pin { font-size: 1.6rem; letter-spacing: 0.3em; text-align: center; }
.select { width: auto; padding: 7px 10px; min-height: 42px; background: var(--surface); }
.label { display: block; font-weight: 700; margin: 10px 0; }
.label .input { margin-top: 6px; font-weight: 400; }
.label.inline { display: flex; align-items: center; gap: 8px; margin: 0; }
.label.inline .input { margin: 0; width: 90px; }
.narrow-form { max-width: 360px; }
.narrow-form .btn { width: 100%; margin-top: 8px; }

/* ---------- 칩 · 배지 ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 14px; font-weight: 700; display: inline-flex; flex-direction: column; align-items: center; line-height: 1.25;
}
.chip small { font-weight: 400; font-size: 0.75rem; color: var(--muted); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.on small { color: #e3e3ff; }
.chip.k-fact.on { background: var(--k-fact); border-color: var(--k-fact); }
.chip.k-why.on { background: var(--k-why); border-color: var(--k-why); }
.chip.k-whatif.on { background: var(--k-whatif); border-color: var(--k-whatif); }
.chip.k-value.on { background: var(--k-value); border-color: var(--k-value); }
.chips.small .chip { padding: 3px 10px; font-size: 0.85rem; }
.starters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 0.88rem; }
.starter { border: 1px dashed #c9c2b3; background: #fffdf6; border-radius: 8px; padding: 3px 10px; }
.starter:hover:not(:disabled) { border-style: solid; border-color: var(--brand); }

.badge { display: inline-block; border-radius: 999px; padding: 1px 10px; font-size: 0.8rem; font-weight: 700; background: var(--soft); white-space: nowrap; }
.badge.k-fact { background: #e6efff; color: #1d4fb0; }
.badge.k-why { background: #efe8ff; color: #5b2fb8; }
.badge.k-whatif { background: #ffe6f2; color: #a8215f; }
.badge.k-value { background: #dff5f2; color: #0b6b62; }
.badge.k-idea { background: #fff1d6; color: #8a5a00; }
.badge.k-evidence { background: #e6efff; color: #1d4fb0; }
.badge.k-answer { background: var(--good-soft); color: #11714a; }
.badge.k-ask { background: #efe8ff; color: #5b2fb8; }
.tag { display: inline-block; border-radius: 6px; padding: 0 7px; font-size: 0.78rem; font-weight: 700; background: var(--soft); color: var(--muted); white-space: nowrap; }
.tag.mine { background: var(--brand-soft); color: var(--brand); }
.tag.teacher { background: #ffe9d6; color: #a14d00; }
.tag.best { background: var(--gold-soft); color: #8a6400; }
.tag.focus { background: var(--brand); color: #fff; }
.who { font-size: 0.82rem; font-weight: 700; color: #4b4660; background: #f1eef8; border-radius: 6px; padding: 0 7px; white-space: nowrap; }
.who.teacher { background: #ffe9d6; color: #a14d00; }
.me-pill { background: var(--brand); color: #fff; border-radius: 999px; padding: 3px 12px; font-weight: 700; }
.phase-pill { display: inline-block; border-radius: 999px; padding: 1px 10px; font-weight: 700; background: var(--brand-soft); color: var(--brand); font-size: 0.82rem; margin-left: 6px; vertical-align: middle; font-family: 'Noto Sans KR', sans-serif; }
.phase-pill.closed { background: var(--soft); color: var(--muted); }
.live { font-size: 0.8rem; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.live::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #c8c2b6; }
.live.on::before { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.live.off { color: var(--danger); }
.live.off::before { background: var(--danger); }

/* ---------- 처음 화면 ---------- */
.home .hero { text-align: center; padding: 32px 0 12px; }
.hero-emoji { font-size: 3rem; }
.lead { font-size: 1.15rem; color: var(--muted); }
.home-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 640px; margin: 20px auto; }
.big-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 2px solid var(--line); border-radius: 22px; padding: 28px 12px; box-shadow: var(--shadow);
  transition: transform 0.1s, border-color 0.15s;
}
.big-card:hover { transform: translateY(-2px); border-color: var(--brand); }
.big-card strong { font-family: 'Jua', sans-serif; font-weight: 400; font-size: 1.4rem; }
.big-card span:last-child { color: var(--muted); font-size: 0.92rem; }
.big-card.student { background: #f1f0ff; }
.big-card.teacher { background: #fff3e3; }
.big-emoji { font-size: 2.6rem; line-height: 1.2; }
.flow { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; max-width: 900px; margin: 28px auto 0; counter-reset: f; }
.flow li { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 2px; counter-increment: f; }
.flow li b::before { content: counter(f) '. '; color: var(--brand); }
.flow small { color: var(--muted); }
.flow-emoji { font-size: 1.5rem; }
@media (max-width: 720px) { .flow { grid-template-columns: 1fr 1fr; } }
@media (max-width: 420px) { .home-cards { grid-template-columns: 1fr; } h1 { font-size: 2rem; } }

/* ---------- 번호 고르기 ---------- */
.seat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; margin: 16px 0; }
.seat {
  aspect-ratio: 1; border: 2px solid var(--line); background: var(--surface); border-radius: 16px;
  font-family: 'Jua', sans-serif; font-size: 1.7rem; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1;
}
.seat:hover:not(:disabled) { border-color: var(--brand); background: var(--brand-soft); }
.seat small { font-family: 'Noto Sans KR', sans-serif; font-size: 0.68rem; color: var(--muted); }
.seat.taken { opacity: 0.4; background: var(--soft); }
.seat-grid.small { grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; }
.seat-grid.small .seat { font-size: 1.1rem; aspect-ratio: auto; min-height: 52px; border-radius: 10px; }
.seat-grid.small .seat:disabled { opacity: 0.55; }
.seat.taken-t { background: var(--good-soft); border-color: #9fd9bd; }
.seat.taken-t:hover { background: var(--danger-soft); border-color: var(--danger); }

/* ---------- 수업 목록 ---------- */
.lesson-list { display: grid; gap: 10px; }
.lesson-card { display: flex; flex-direction: column; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
a.lesson-card:hover { border-color: var(--brand); }
.lesson-card.closed { opacity: 0.7; box-shadow: none; }
.lesson-title { font-family: 'Jua', sans-serif; font-size: 1.25rem; text-decoration: none; color: var(--ink); }
.lesson-card .phase-pill { margin-left: 0; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; background: var(--surface); border: 2px dashed var(--line); border-radius: var(--radius); }

/* ---------- 수업 머리 · 단계 ---------- */
.lesson-head h2 { margin-bottom: 4px; }
.prompt { background: #fffbe9; border: 1px solid #f1e2a8; border-radius: 12px; padding: 10px 14px; margin: 8px 0 12px; }
.steps { list-style: none; padding: 0; margin: 12px 0 6px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.steps li > * {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: 0; border-radius: 12px; padding: 8px 4px;
  background: var(--soft); border: 2px solid transparent; font-weight: 700; font-size: 0.88rem; color: var(--muted); text-align: center;
}
.steps li > * > span { font-size: 1.3rem; }
.steps li.done > * { background: #ece8f9; color: #6b66a3; }
.steps li.now > * { background: var(--brand); color: #fff; box-shadow: 0 4px 12px rgba(91, 91, 214, 0.3); }
.steps.clickable button { cursor: pointer; }
.steps.clickable li:not(.now) button:hover { border-color: var(--brand); color: var(--brand); }
.phase-tip { margin: 4px 0 8px; font-weight: 700; color: #4b4660; }
.banner { background: var(--danger-soft); border: 1px solid #f3b7b9; color: #9b1c20; border-radius: 12px; padding: 10px 14px; font-weight: 700; margin: 10px 0; }
.banner.warn { background: var(--warn-soft); border-color: var(--warn-line); color: #7a5300; }
.privacy { background: var(--good-soft); border-radius: 10px; padding: 8px 12px; font-size: 0.9rem; }

/* ---------- 카드 ---------- */
.cards { display: grid; gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.card.is-mine { border-color: #c9c8f5; }
.card.is-hidden, .answer.is-hidden { opacity: 0.5; border-style: dashed; }
.card.focus { border: 2px solid var(--brand); }
.card.picked { outline: 3px solid var(--accent); }
.q-text { font-size: 1.08rem; font-weight: 500; }
.q-text.big { font-size: 1.3rem; font-weight: 700; }
.q-actions { margin-top: 2px; }
.votes { font-weight: 900; color: #a77d00; background: var(--gold-soft); border-radius: 8px; padding: 0 8px; }
.composer textarea { margin-bottom: 6px; }
.counter { font-size: 0.8rem; color: var(--muted); }

.vote-info { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; font-weight: 700; position: sticky; top: 6px; z-index: 5; box-shadow: var(--shadow); }
.tokens { display: flex; gap: 2px; font-size: 1.5rem; }
.token { color: #d8d2c6; }
.token.full { color: var(--gold); }
.vote-row { display: flex; align-items: center; gap: 12px; }
.vote-card.voted { border: 2px solid var(--gold); background: #fffdf2; }
.vote-btn { flex-shrink: 0; border: 2px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 14px; font-weight: 900; min-width: 110px; min-height: 48px; }
.vote-btn:hover:not(:disabled) { border-color: var(--gold); }
.vote-btn.on { background: var(--gold); border-color: var(--gold); color: #3d2c00; }
.vote-btn:disabled { opacity: 0.4; }

.explore-cards { display: grid; gap: 16px; margin-top: 12px; }
.explore-card { border-top: 6px solid var(--brand); }
.explore-card h4 { margin: 6px 0 0; }
.answers { list-style: none; padding: 0; margin: 4px 0; display: grid; gap: 8px; }
.answer { background: #fdfbf6; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; display: flex; flex-direction: column; gap: 4px; }
.answer.best { background: var(--gold-soft); border-color: #f1d36a; }
.answer.is-mine { border-color: #c9c8f5; }
.a-text { font-size: 1rem; }
.empty-li { padding: 8px 4px; }
.like-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 2px 12px; font-weight: 700; min-height: 32px; }
.like-btn.on { background: #fff4c7; border-color: #f1d36a; }
.like-btn:disabled { opacity: 0.6; }
.plain-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.summary { border: 2px solid #ffc98a; background: #fffaf2; }

/* ---------- 선생님 수업 화면 ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 4px; }
.lesson-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.side { position: sticky; top: 10px; max-height: calc(100vh - 20px); overflow: auto; margin-top: 20px; }
.part-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.part { border: 1px solid var(--line); background: var(--soft); border-radius: 10px; padding: 5px 8px; text-align: left; display: flex; flex-direction: column; opacity: 0.6; font-size: 0.85rem; }
.part b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.part span { color: var(--muted); font-size: 0.78rem; }
.part.on { opacity: 1; background: var(--surface); border-color: #9fd9bd; }
.part.on.quiet { background: var(--warn-soft); border-color: var(--warn-line); }
.part.picked { outline: 3px solid var(--accent); }
.t-compose { margin-top: 20px; }
.present-exit { display: none; }
@media (max-width: 960px) {
  .lesson-grid { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
  .part-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}

/* 크게 보기 (화면 공유·TV용) — 이름과 관리 버튼을 감춥니다 */
.teacher-lesson.present { max-width: none; padding: 24px 40px; font-size: 20px; }
.present .topbar, .present .toolbar, .present .side, .present .t-compose, .present .select { display: none; }
.present .lesson-grid { grid-template-columns: 1fr; }
.present .lesson-head h2 { font-size: 2.4rem; }
.present .q-text { font-size: 1.35rem; }
.present .q-text.big { font-size: 1.8rem; }
.present .a-text { font-size: 1.2rem; }
.present .cards { grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); }
.present .present-exit { display: inline-flex; position: fixed; right: 16px; bottom: 16px; z-index: 20; }

/* ---------- 모달 · 토스트 ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(30, 25, 40, 0.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: 20px; padding: 20px; width: min(460px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
.modal h3 { margin-top: 0; }
.modal .row.end { margin-top: 14px; }
#toast-root { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: min(92vw, 440px); pointer-events: none; }
.toast { background: #2b2a33; color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 700; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); transition: opacity 0.3s, transform 0.3s; text-align: center; }
.toast.error { background: var(--danger); }
.toast.out { opacity: 0; transform: translateY(8px); }

@media (max-width: 520px) {
  .steps li > * { font-size: 0.74rem; padding: 6px 2px; }
  .steps li > * > span { font-size: 1.1rem; }
  .vote-row { flex-direction: column; align-items: stretch; }
  .vote-btn { width: 100%; }
  h2 { font-size: 1.45rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- 질문 댓글 ---------- */
.thread { border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 6px; }
.cmt-toggle { background: none; border: 0; padding: 4px 6px; margin-left: -6px; border-radius: 8px; font-weight: 700; color: #4b4660; min-height: 34px; }
.cmt-toggle:hover { background: var(--soft); color: var(--brand); }
.cmt-body { display: grid; gap: 8px; margin-top: 4px; }
.comments { list-style: none; padding: 0; margin: 4px 0; display: grid; gap: 6px; }
.comment { background: #f7f5fb; border-radius: 10px; padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; font-size: 0.95rem; }
.comment.is-mine { background: var(--brand-soft); }
.comment.is-hidden { opacity: 0.5; }
.composer.compact textarea { min-height: 44px; }
.composer.compact .starters { margin-bottom: 6px; font-size: 0.82rem; }
.composer.compact .btn { min-height: 38px; padding: 6px 14px; }
.present .comment { font-size: 1.1rem; }

/* ---------- 배경음악 ---------- */
.bgm {
  position: fixed; left: 12px; bottom: 12px; z-index: 40;
  display: flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, 0.94); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 12px 4px 4px; box-shadow: var(--shadow);
}
.bgm-btn { border: 0; background: var(--brand-soft); color: var(--brand); font-weight: 700; border-radius: 999px; padding: 6px 12px; min-height: 36px; white-space: nowrap; }
.bgm-btn:hover { background: var(--brand); color: #fff; }
.bgm.off .bgm-btn { background: var(--soft); color: var(--muted); }
.bgm-vol { width: 90px; accent-color: var(--brand); }
.bgm.off .bgm-vol { opacity: 0.4; }
.screen { padding-bottom: 96px; }
@media (max-width: 520px) { .bgm-vol { width: 64px; } .bgm { left: 8px; bottom: 8px; } }
.present ~ .bgm, body:has(.present) .bgm { opacity: 0.35; }
body:has(.present) .bgm:hover { opacity: 1; }
