/* 교실용 TTS 도우미 — 남색 바탕 + 파란 포인트 */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --line: #d5dcea;
  --text: #0f172a;
  --muted: #475569;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --primary-soft: #dbe6fe;
  --danger: #dc2626;
  --accent: #f59e0b;
  --hl: #fde68a;
  --hl-ink: #1e293b;
  --shadow: 0 6px 24px rgba(15, 23, 42, .08);
  --radius: 18px;
  --dock-h: 76px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a; --surface: #1e293b; --surface-2: #273449; --line: #334155;
    --text: #f1f5f9; --muted: #cbd5e1; --primary: #3b82f6; --primary-soft: #1e3a8a;
    --danger: #ef4444; --hl: #facc15; --hl-ink: #0f172a;
    --shadow: 0 6px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f172a; --surface: #1e293b; --surface-2: #273449; --line: #334155;
  --text: #f1f5f9; --muted: #cbd5e1; --primary: #3b82f6; --primary-soft: #1e3a8a;
  --danger: #ef4444; --hl: #facc15; --hl-ink: #0f172a;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 500 17px/1.5 "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--dock-h) + 24px + env(safe-area-inset-bottom));
}
body.overlay { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

/* 상단 */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 0; min-width: 0; }
.logo {
  display: grid; place-items: center; width: 42px; height: 42px; flex: none; border-radius: 12px; color: #fff;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8); box-shadow: 0 4px 12px rgba(37, 99, 235, .35);
}
.brand-text { font-size: 21px; font-weight: 800; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.icon-btn, .chip-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 42px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 700;
}
.icon-btn { width: 42px; justify-content: center; padding: 0; }
.chip-btn { padding: 0 12px; }
.chip-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); font-variant-numeric: tabular-nums; }
.chip-btn.ended { background: var(--danger); color: #fff; border-color: var(--danger); }

.wrap { max-width: 1040px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-left)); display: grid; gap: 16px; }
.wrap > * { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.sec-head h2 { margin: 0; font-size: 19px; font-weight: 800; }
.sec-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { display: inline-flex; gap: 6px; }
.hint { color: var(--muted); font-size: 14px; margin: 10px 0 0; }
.center { text-align: center; }
.notice { background: #fef3c7; color: #78350f; border-radius: 14px; padding: 12px 14px; font-weight: 600; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 700; background: var(--surface-2); white-space: nowrap;
}
.btn.sm { min-height: 38px; padding: 0 12px; font-size: 15px; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.ghost { background: var(--surface); border-color: var(--line); }
.btn.ghost.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .phrase:focus-visible, .tab:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.link { background: none; border: 0; padding: 0; color: var(--primary); font-weight: 700; text-decoration: underline; }
.file-btn { cursor: pointer; }

/* 문구 묶음 */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: thin; }
.tab {
  flex: none; height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 700; color: var(--muted);
}
.tab[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.phrases { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.phrase {
  text-align: left; min-height: 56px; padding: 12px 16px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface-2); font-weight: 700; line-height: 1.35;
}
.phrase:hover { border-color: var(--primary); }
.phrase:active { background: var(--primary-soft); }
.phrase.editing { border-style: dashed; border-color: var(--primary); }
.phrase.editing::before { content: "✏️ "; }
.add-row { display: flex; gap: 8px; margin-top: 14px; }
.add-row input { flex: 1; min-width: 0; }
input[type="text"], input[type="number"], select, textarea {
  min-height: 44px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); font-size: 16px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }

/* 읽어줄 내용 */
#text {
  width: 100%; min-height: 200px; height: 34vh; resize: vertical; line-height: 1.6; font-weight: 600;
}
.text-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.text-foot .hint { margin: 6px 0 0; }
.count { color: var(--muted); font-size: 14px; margin-top: 6px; }
.count b { color: var(--primary); }
@media (pointer: coarse) { .text-foot .hint { visibility: hidden; } }

.foot { text-align: center; padding: 8px 0 0; }
.foot .link { color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: none; }

/* 하단 읽기 바 */
.dock {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex; gap: 10px; padding: 10px; width: min(560px, calc(100% - 24px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: 0 12px 40px rgba(15, 23, 42, .25);
}
.dock .btn { min-height: 56px; font-size: 19px; border-radius: 16px; }
.btn.play { flex: 2; background: var(--primary); color: #fff; }
.btn.play.is-on { background: #1d4ed8; }
.btn.stop { flex: 1; background: var(--danger); color: #fff; }
.btn.board { flex: 1; background: var(--surface-2); border-color: var(--line); }
body.speaking .btn.play { box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 30%, transparent); }

/* 칠판 모드 */
.board-view, .timer-view {
  position: fixed; inset: 0; z-index: 50; background: #0b1220; color: #f8fafc;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.board-text {
  flex: 1; overflow-y: auto; padding: 5vh 6vw; font-weight: 800; line-height: 1.45; letter-spacing: -.01em;
  word-break: keep-all; overflow-wrap: anywhere;
}
.board-text .sent { border-radius: .15em; transition: color .2s, background-color .2s; cursor: pointer; }
.board-text .sent.done { color: #64748b; }
.board-text .sent.now { background: var(--hl); color: var(--hl-ink); box-decoration-break: clone; -webkit-box-decoration-break: clone; padding: 0 .1em; }
.board-empty { color: #94a3b8; font-size: .5em; }
.board-bar, .timer-bar {
  display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; padding: 14px;
  background: rgba(255, 255, 255, .06); border-top: 1px solid rgba(255, 255, 255, .1);
}
.board-bar .btn, .timer-bar .btn { min-height: 52px; font-size: 18px; flex: 0 1 auto; min-width: 96px; }
.board-bar .btn.ghost, .timer-bar .btn.ghost { background: transparent; color: #f8fafc; border-color: rgba(255, 255, 255, .25); }

/* 큰 타이머 */
.timer-view { align-items: center; justify-content: center; }
.timer-big {
  flex: 1; display: grid; place-items: center; font-weight: 800; font-variant-numeric: tabular-nums;
  font-size: min(34vw, 62vh); line-height: 1; letter-spacing: -.03em;
}
.timer-label { font-size: clamp(22px, 4vw, 44px); font-weight: 800; color: #93c5fd; margin-bottom: 2vh; min-height: 1em; }
.timer-bar { width: 100%; }
.timer-view.urgent .timer-big { color: #fbbf24; }
.timer-view.ended .timer-big { color: #f87171; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }

/* 대화 상자 */
dialog.sheet {
  border: 0; padding: 0; border-radius: 22px; width: min(560px, calc(100% - 24px)); max-height: calc(100dvh - 32px);
  background: var(--surface); color: var(--text); box-shadow: 0 24px 64px rgba(0, 0, 0, .35);
}
dialog.sheet::backdrop { background: rgba(2, 6, 23, .55); }
.sheet-in { padding: 20px; display: grid; gap: 12px; }
.sheet-in h3 { margin: 0; font-size: 20px; font-weight: 800; }
.sheet-in h3.mt { margin-top: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.sheet-in textarea { width: 100%; resize: vertical; }
.sheet-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.sheet-actions.wrap-row { flex-wrap: wrap; justify-content: flex-start; }
.grow { flex: 1; }
.field { display: grid; gap: 6px; }
.field span { font-weight: 700; font-size: 15px; color: var(--muted); }
.range { display: grid; gap: 4px; }
.range span { display: flex; justify-content: space-between; font-weight: 700; }
.range b { color: var(--primary); }
input[type="range"] { width: 100%; accent-color: var(--primary); height: 32px; }
.check-row, .checks label { display: flex; align-items: center; gap: 10px; font-weight: 600; min-height: 36px; }
input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--primary); }
.checks { border: 1px solid var(--line); border-radius: 14px; padding: 8px 14px 10px; margin: 0; }
.checks legend { font-weight: 800; padding: 0 6px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.time-input { display: flex; gap: 12px; align-items: center; justify-content: center; font-size: 22px; font-weight: 800; }
.time-input input { width: 96px; text-align: center; font-size: 28px; font-weight: 800; }
.help { background: var(--surface-2); border-radius: 14px; padding: 10px 14px; }
.help summary { font-weight: 700; cursor: pointer; }
.help ul { padding-left: 18px; margin: 8px 0; }
.help li { margin: 6px 0; }
.help p { margin: 0; color: var(--muted); font-size: 14px; }
.picked {
  display: grid; place-items: center; min-height: 120px; border-radius: 18px; background: var(--primary-soft);
  font-size: clamp(36px, 9vw, 64px); font-weight: 800; text-align: center; padding: 8px;
}
.picked.rolling { color: var(--muted); }

/* 알림 */
.toast {
  position: fixed; left: 50%; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 100;
  bottom: calc(var(--dock-h) + 32px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 700;
  max-width: calc(100% - 32px); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 작은 화면 */
@media (max-width: 560px) {
  .brand-text { font-size: 18px; }
  .hide-sm { display: none; }
  .logo { width: 38px; height: 38px; }
  .icon-btn, .chip-btn { height: 40px; }
  .icon-btn { width: 40px; }
  .card { padding: 14px; }
  .phrases { grid-template-columns: 1fr 1fr; gap: 8px; }
  .phrase { font-size: 15px; padding: 10px 12px; min-height: 52px; }
  .dock .btn { font-size: 17px; min-height: 52px; padding: 0 10px; }
  #text { height: 26vh; }
}
@media (max-width: 480px) { .brand-text { display: none; } }
@media (max-width: 380px) {
  .phrases { grid-template-columns: 1fr; }
}
