:root {
  --bg: #fbf7f0;
  --surface: #ffffff;
  --ink: #2b2723;
  --muted: #7a7168;
  --line: #e8dfd2;
  --brand: #d9572b;
  --brand-ink: #ffffff;
  --me: #fde7d9;
  --ai: #ffffff;
  --warn: #fff3c9;
  --ok: #e3f1e6;
  --now: #fff0d6;
  --radius: 14px;
  --gutter: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1917;
    --surface: #26221f;
    --ink: #f2ece4;
    --muted: #a39a90;
    --line: #3a342f;
    --brand: #f07a50;
    --brand-ink: #1c1917;
    --me: #4a3025;
    --ai: #26221f;
    --warn: #4a4020;
    --ok: #243628;
    --now: #4a3a1f;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', 'PingFang SC', system-ui, sans-serif;
  line-height: 1.55;
  padding: 0 var(--gutter) 96px;
  max-width: 1320px;
  margin: 0 auto;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---- 머리글 ---- */
.top { display: flex; align-items: center; gap: 14px; padding: 16px 0 8px; flex-wrap: wrap; }
.brand { margin-right: auto; }
h1 { font-size: 1.3rem; margin: 0; letter-spacing: -0.02em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 0.88rem; }
.prep { font-size: 0.78rem; color: var(--muted); }
.opt { font-size: 0.88rem; color: var(--muted); cursor: pointer; user-select: none; display: inline-flex; align-items: center; gap: 4px; }
.opt select { font: inherit; font-size: 0.85rem; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 2px 6px; }
.pill { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 14px; cursor: pointer; font-size: 0.88rem; }
.pill:hover { border-color: var(--brand); }
.pill.on { background: var(--ok); }
.pill b { background: var(--brand); color: var(--brand-ink); border-radius: 999px; padding: 0 7px; font-size: 0.78rem; margin-left: 2px; }

/* ---- 시리즈 토글 ---- */
.series-tabs { display: flex; gap: 4px; padding: 4px; background: var(--line); border-radius: 16px; width: fit-content; max-width: 100%; margin: 4px 0 10px; }
.tab { border: 0; background: transparent; border-radius: 12px; padding: 8px 20px; cursor: pointer; text-align: left; display: flex; flex-direction: column; line-height: 1.25; }
.tab strong { font-size: 1rem; }
.tab small { color: var(--muted); font-size: 0.72rem; }
.tab[aria-selected='true'] { background: var(--surface); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
.tab[aria-selected='true'] strong { color: var(--brand); }

/* ---- 클립 목록 ---- */
.clips { display: flex; flex-wrap: wrap; gap: 6px 22px; padding-bottom: 12px; }
.group { min-width: 0; max-width: 100%; }
.group-label { display: block; font-size: 0.78rem; color: var(--muted); margin: 0 2px 4px; }
.row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; max-width: 100%; }
.clip-btn {
  flex: 0 0 auto; text-align: left; border: 1px solid var(--line); background: var(--surface);
  border-radius: 12px; padding: 7px 11px; cursor: pointer; width: 190px;
}
.clip-btn .ttl { display: block; font-size: 0.85rem; line-height: 1.3; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.badges { display: flex; flex-wrap: wrap; gap: 3px; }
.badge { font-size: 0.68rem; padding: 0 6px; border-radius: 999px; background: var(--line); color: var(--muted); }
.badge.star { background: var(--brand); color: var(--brand-ink); }
.badge.ok { background: var(--ok); color: var(--ink); }
.clip-btn[aria-current='true'] { border-color: var(--brand); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 25%, transparent); }

/* ---- 본문: 대본이 메인 ---- */
.layout { display: grid; grid-template-columns: minmax(0, 4fr) minmax(0, 6fr); gap: 22px; align-items: start; }
.stage { position: sticky; top: 12px; }
.player { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); overflow: hidden; }
.player iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.source { color: var(--muted); font-size: 0.8rem; margin: 6px 2px 4px; }
.source a { color: inherit; }
.clip-info h2 { font-size: 1rem; margin: 6px 0 2px; line-height: 1.35; }
.meta { margin: 2px 0; color: var(--muted); font-size: 0.82rem; }

.script { min-width: 0; }
.view-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.vtab { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 16px; cursor: pointer; font-size: 0.92rem; }
.vtab[aria-selected='true'] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 700; }
.study-sec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 16px 12px; margin-bottom: 12px; }
.study-sec h3 { font-size: 0.95rem; margin: 10px 0 6px; }
.krow { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; padding: 8px 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); align-items: start; }
.krow:last-child { border-bottom: 0; }
.krow .t { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 1px 8px; font-size: 0.74rem; color: var(--muted); cursor: pointer; margin-top: 3px; white-space: nowrap; }
.krow .t:hover { border-color: var(--brand); color: var(--brand); }
.erow { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.erow:last-child { border-bottom: 0; }
.ex { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 0.85rem; text-align: left; padding: 0; }
.ex:hover { color: var(--brand); text-decoration: underline; }
.script-bar { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; align-items: center; padding: 0 2px 10px; }
.bar-left, .bar-right { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.status { color: var(--muted); }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 24px; text-align: center; }
.empty h3 { margin: 0 0 6px; }

.scene { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.scene > summary { list-style: none; cursor: pointer; padding: 12px 16px; display: flex; gap: 10px; align-items: baseline; justify-content: space-between; }
.scene > summary::-webkit-details-marker { display: none; }
.scene > summary::before { content: '▸'; color: var(--brand); transition: transform 0.15s; margin-right: -2px; }
.scene[open] > summary::before { transform: rotate(90deg); }
.scene[open] > summary { border-bottom: 1px solid var(--line); }
.sum-main { flex: 1; display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; min-width: 0; }
.sum-main .num { color: var(--brand); font-size: 0.82rem; }
.sum-main .ttl { font-weight: 700; }
.sum-meta { color: var(--muted); font-size: 0.78rem; white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.scene-inner { padding: 4px 16px 14px; }
.scene-sum { background: var(--bg); border-radius: 10px; padding: 8px 12px; margin: 8px 0 6px; font-size: 0.92rem; }
.scene-sum p { margin: 2px 0; }

.zh { color: var(--muted); font-size: 0.88em; }
body.no-zh .zh { display: none; }

.line { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; padding: 9px 6px; border-radius: 10px; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); align-items: start; scroll-margin: 80px; }
.line:last-child { border-bottom: 0; }
.line.now { background: var(--now); }
.line.asked { outline: 2px solid var(--brand); }
.line .t { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 1px 8px; font-size: 0.74rem; color: var(--muted); cursor: pointer; margin-top: 3px; white-space: nowrap; }
.line .t:hover { border-color: var(--brand); color: var(--brand); }
.ko-row { display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; }
.spk { font-size: 0.78rem; color: var(--brand); font-weight: 700; flex: 0 0 auto; }
.ko { font-size: 1.06rem; word-break: keep-all; overflow-wrap: anywhere; }
.orig { color: var(--muted); font-style: italic; font-size: 0.88rem; }
body.hide-orig .orig { display: none; }
body.hide-ko .line .ko { filter: blur(7px); transition: filter 0.15s; }
body.hide-ko .line .ko:hover, body.hide-ko .line .ko:focus-visible { filter: none; }
.notes { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
.acts { display: flex; gap: 4px; }
.act { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; width: 32px; height: 28px; cursor: pointer; padding: 0; }
.act:hover { border-color: var(--brand); }
.act.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.shadow-result { grid-column: auto; margin-top: 6px; padding: 6px 10px; border-radius: 10px; background: var(--warn); font-size: 0.85rem; }
.shadow-result.live { background: var(--bg); color: var(--muted); }
.shadow-result.good { background: var(--ok); }
.shadow-result .heard { display: block; color: var(--muted); font-size: 0.82rem; }

.done-btn { margin-top: 10px; }

/* 눌러서 듣는 글자 */
.tts { cursor: pointer; border-radius: 6px; transition: background 0.12s; }
.tts:hover, .tts:focus-visible { background: color-mix(in srgb, var(--brand) 14%, transparent); outline: none; }
.loading { opacity: 0.55; animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }

.chip { display: inline-flex; align-items: center; background: var(--ok); border-radius: 999px; font-size: 0.82rem; white-space: normal; }
.chip-t { padding: 2px 4px 2px 10px; }
.chip-add { border: 0; background: transparent; cursor: pointer; padding: 2px 9px 2px 3px; color: var(--brand); font-weight: 700; }
.chip .tts:hover, .chip .tts:focus-visible { background: color-mix(in srgb, var(--brand) 30%, var(--ok)); }

/* ---- 오른쪽 아래 채팅 ---- */
.fab { position: fixed; right: 20px; bottom: 20px; z-index: 30; border: 0; background: var(--brand); color: var(--brand-ink); border-radius: 999px; padding: 13px 20px; font-weight: 700; cursor: pointer; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); }
.fab:hover { filter: brightness(1.05); }
.chat-panel { position: fixed; right: 20px; bottom: 20px; z-index: 40; width: min(400px, calc(100vw - 24px)); height: min(640px, calc(100vh - 40px)); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3); overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 10px 16px; background: var(--brand); color: var(--brand-ink); }
.chat-clip { flex: 1; font-size: 0.75rem; opacity: 0.85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.x { border: 0; background: transparent; cursor: pointer; font-size: 1rem; padding: 2px 6px; border-radius: 6px; opacity: 0.8; }
.x:hover { opacity: 1; background: rgba(0, 0, 0, 0.1); }
.ctx { display: flex; gap: 6px; align-items: flex-start; padding: 6px 12px; background: var(--now); font-size: 0.82rem; border-bottom: 1px solid var(--line); }
.ctx span { flex: 1; }

.log { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 90%; padding: 9px 12px; border-radius: 14px; border: 1px solid var(--line); white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--me); border-color: transparent; }
.msg.ai { align-self: flex-start; background: var(--ai); }
.msg.thinking { color: var(--muted); }
.msg .say { margin-left: 6px; border: 0; background: none; cursor: pointer; font-size: 0.95rem; padding: 0 2px; }
.fix { margin-top: 8px; padding: 8px 10px; background: var(--warn); border-radius: 10px; font-size: 0.88rem; white-space: normal; }
.fix s { opacity: 0.7; }
.fix .zh { display: block; }
.vocab { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.err { align-self: stretch; background: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: 0.88rem; }

.starters { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 12px 8px; }
.starters button { border: 1px dashed var(--line); background: none; border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 0.83rem; }
.starters button:hover { border-color: var(--brand); }

.composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; font: inherit; background: var(--bg); color: var(--ink); max-height: 120px; }
.icon, .send { border: 0; border-radius: 12px; cursor: pointer; padding: 9px 14px; }
.icon { background: var(--bg); border: 1px solid var(--line); }
.icon.on { background: var(--brand); color: var(--brand-ink); }
.send { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.send:disabled { opacity: 0.5; cursor: default; }
.note { margin: 0; padding: 0 14px 10px; color: var(--muted); font-size: 0.78rem; min-height: 1.2em; }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 60; max-width: min(520px, calc(100vw - 32px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 0.86rem; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); }

/* ---- 대화상자 ---- */
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
dialog form { display: flex; flex-direction: column; gap: 10px; min-width: 240px; }
dialog input { padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; background: var(--bg); color: var(--ink); }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
#vocabDialog { width: min(480px, calc(100vw - 24px)); max-height: 80vh; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.vrow { display: flex; gap: 10px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--line); }
.vko { font-weight: 600; }
.vzh { flex: 1; }

/* ---- 좁은 화면 ---- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 12px; }
  .stage { top: 0; z-index: 20; background: var(--bg); padding: 6px 0; margin: 0 calc(var(--gutter) * -1); padding-inline: var(--gutter); border-bottom: 1px solid var(--line); }
  .clip-info h2 { font-size: 0.92rem; }
  .meta { display: none; }
  .chat-panel { right: 0; left: 0; bottom: 0; width: 100%; height: min(78vh, 100vh); border-radius: 18px 18px 0 0; }
  .line { grid-template-columns: minmax(0, 1fr) auto; }
  .line .t { grid-column: 1 / -1; justify-self: start; }
  .tab { padding: 8px 12px; }
  .msg { max-width: 94%; }
}

/* 따라 말하기 비교, 퀴즈, 글씨 크기 */
.cmp { display: block; margin: 4px 0 2px; font-size: 0.95rem; }
.cmp .w.ok { color: #2e8b57; }
.cmp .w.bad { color: #d64545; text-decoration: underline wavy; }
.reply-zh { display: block; margin-top: 6px; font-size: 0.85rem; }
.fs { display: inline-flex; gap: 4px; }
.fs .pill { padding: 5px 10px; }
.dlg-head strong { margin-right: auto; }
.dlg-head { gap: 8px; }
.quiz { display: flex; flex-direction: column; gap: 10px; }
.qno { margin: 0; color: var(--muted); font-size: 0.8rem; }
.qhead { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.qko { font-size: 1.3rem; }
.qopts { display: grid; gap: 8px; }
.qopt { border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; text-align: left; cursor: pointer; }
.qopt:hover:not(:disabled) { border-color: var(--brand); }
.qopt.right { background: var(--ok); border-color: #2e8b57; }
.qopt.wrong { background: var(--warn); border-color: #d64545; }
.quiz .send { align-self: flex-end; }

.search { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 5px 14px; font: inherit; font-size: 0.88rem; width: 15em; max-width: 100%; }
.best { font-size: 0.76rem; color: #2e8b57; margin-top: 2px; }
.best.low { color: #d6821f; }
.line.reading { background: var(--ok); }
.listen-btn { margin: 4px 0 2px; }
.dlg-head .pill { padding: 3px 10px; font-size: 0.8rem; }
