/* 공부방 — 모눈 공책 위에 파란 펜으로 판서, 지금 말하는 곳은 노란 형광펜 */

:root {
  color-scheme: light dark;
  &:has(> head > meta[name="color-scheme"][content="dark"]) { color-scheme: dark; }
  &:has(> head > meta[name="color-scheme"][content="light"]) { color-scheme: light; }

  --paper: light-dark(#eef2ef, #152027);
  --paper-2: light-dark(#e2e9e4, #1b2932);
  --paper-3: light-dark(#f7f9f7, #1f2f39);
  --grid: light-dark(#d6e0da, #1f2e37);
  --rule: light-dark(#c2d0c8, #2c3f4a);
  --ink: light-dark(#1b2a33, #dbe5e1);
  --ink-2: light-dark(#4a5c66, #9db0b8);
  --ink-3: light-dark(#73858e, #74878f);
  --pen: light-dark(#235d83, #86bde2);
  --pen-soft: light-dark(#d6e5ee, #203a4b);
  --red: light-dark(#b2412e, #e88a73);
  --green: light-dark(#2b7656, #79c9a0);
  --green-soft: light-dark(#dcebe2, #1d3a30);
  --hl: light-dark(#f4d943, #e3c53c);
  --hl-soft: light-dark(rgb(244 217 67 / .5), rgb(227 197 60 / .26));
  --margin: light-dark(#e2a9a0, #6b3b35);
  --on-pen: light-dark(#ffffff, #0f1b22);

  --f-display: "Hahmlet", "Noto Serif KR", serif;
  --f-body: "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  --cell: 24px;
  --dock-h: 156px;
  --r: 6px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* 큰 모니터·TV: 화면 전체를 키워서 멀리서도 읽히게 (폭과 높이가 둘 다 넉넉할 때만) */
/* zoom 은 vh 도 함께 키우므로 화면 높이는 calc(100dvh / var(--z, 1)) 로 쓴다 */
@media (min-width: 1900px) and (min-height: 880px) { html { zoom: 1.2; --z: 1.2; } }
@media (min-width: 2300px) and (min-height: 1080px) { html { zoom: 1.4; --z: 1.4; } }
@media (min-width: 2800px) and (min-height: 1350px) { html { zoom: 1.7; --z: 1.7; } }
@media (min-width: 3400px) and (min-height: 1650px) { html { zoom: 2; --z: 2; } }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.7 var(--f-body);
  word-break: keep-all;
  overflow-wrap: anywhere;
}
a { color: var(--pen); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--pen); outline-offset: 2px; border-radius: 3px; }
::selection { background: var(--hl-soft); }
code, kbd { font-family: var(--f-mono); font-size: .9em; }
kbd { border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 4px; padding: 0 .35em; background: var(--paper-3); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.small { font-size: .85rem; color: var(--ink-2); }
.hint { color: var(--ink-2); font-size: .9rem; margin: .4rem 0; }
.mono { font-family: var(--f-mono); font-size: .8rem; }
.err { color: var(--red); }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .75rem; }

/* ---- 버튼 ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 40px; padding: .45em 1.05em; border-radius: 999px;
  border: 1.5px solid var(--pen); background: var(--pen); color: var(--on-pen);
  font-weight: 600; font-size: .95rem; text-decoration: none; cursor: pointer;
  transition: background-color .15s, transform .1s;
}
.btn:hover { background: color-mix(in oklab, var(--pen) 85%, var(--ink)); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--pen); }
.btn.ghost:hover { background: var(--pen-soft); }
.btn.small { min-height: 32px; font-size: .85rem; padding: .25em .8em; }
.btn.big { min-height: 48px; padding: .6em 1.5em; font-size: 1.05rem; }
.btn:disabled { opacity: .4; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--paper-2); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg, .play svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }
.chip { border: 1px solid var(--rule); background: var(--paper-3); border-radius: 999px; padding: .2em .8em; font-size: .85rem; cursor: pointer; }
.chip:hover { border-color: var(--pen); color: var(--pen); }
.chip.ghost { background: transparent; }

/* ---- 윗줄 ---- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: .25rem;
  height: 56px; padding: 0 max(8px, env(safe-area-inset-left));
  background: color-mix(in oklab, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.tb-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-ch { color: var(--pen); font-family: var(--f-display); margin-right: .2em; }
.tb-actions { display: flex; align-items: center; }
.wordmark { font-family: var(--f-display); font-weight: 700; font-size: 1.35rem; margin-left: 8px; padding: 0 3px; letter-spacing: -.01em; background: linear-gradient(transparent 58%, var(--hl-soft) 58%, var(--hl-soft) 90%, transparent 90%); }

/* ---- 홈 ---- */
.home, .course-page, .notes-page { max-width: 760px; margin: 0 auto; padding: 24px 16px 80px; }
.resume { padding: 28px 0 8px; }
.resume-label { margin: 0; color: var(--ink-2); font-size: .95rem; }
.resume blockquote {
  margin: .5rem 0 .75rem; font-family: var(--f-display); font-weight: 600;
  font-size: clamp(1.45rem, 4.6vw, 2.1rem); line-height: 1.45; letter-spacing: -.01em; text-wrap: pretty;
}
.resume blockquote mark { background: linear-gradient(transparent 55%, var(--hl-soft) 55%); color: inherit; padding: 0 .08em; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.resume-where { margin: 0; color: var(--ink-2); }
.stats { color: var(--ink-2); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: .7rem 0; margin: 28px 0; }
.stats b { color: var(--ink); }
.h-section { font-family: var(--f-display); font-size: 1.15rem; font-weight: 600; margin: 32px 0 12px; }
.course-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.course a {
  display: block; padding: 18px 20px; border-radius: 10px; text-decoration: none; color: inherit;
  background: var(--paper-3); border: 1px solid var(--rule); border-left: 5px solid var(--course, var(--pen));
}
.course a:hover { border-color: var(--pen); border-left-color: var(--course, var(--pen)); }
.course h3 { margin: 0; font-family: var(--f-display); font-size: 1.3rem; }
.course p { margin: .3rem 0; }
.course-meter { display: flex; gap: 3px; margin: .8rem 0 .3rem; }
.course-meter span { flex: 1; height: 6px; border-radius: 2px; background: linear-gradient(to right, var(--course, var(--pen)) calc(var(--p) * 100%), var(--rule) 0); }
.add-hint { margin-top: 24px; font-size: .85rem; color: var(--ink-3); }

/* ---- 목차 (정류장 노선) ---- */
.course-head h1 { font-family: var(--f-display); font-size: clamp(1.7rem, 5vw, 2.4rem); line-height: 1.3; margin: 12px 0 8px; }
.goal { color: var(--ink-2); margin: 0; max-width: 62ch; }
.route { list-style: none; padding: 0; margin: 0; }
.stop { position: relative; display: grid; grid-template-columns: 40px 1fr; gap: 14px; padding-bottom: 18px; }
.stop::before { content: ""; position: absolute; left: 19px; top: 38px; bottom: -2px; width: 2px; background: var(--rule); }
.stop:last-child::before { display: none; }
.stop.done::before { background: var(--pen); }
.dot {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; z-index: 1;
  font-family: var(--f-display); font-weight: 700; border: 2px solid var(--rule); background: var(--paper);
  background-image: conic-gradient(var(--pen-soft) calc(var(--p) * 360deg), transparent 0);
}
.stop.doing .dot { border-color: var(--pen); color: var(--pen); }
.stop.done .dot { background: var(--pen); border-color: var(--pen); color: var(--on-pen); }
.stop-body h3 { margin: 6px 0 2px; font-size: 1.08rem; font-weight: 600; }
.stop-body a { color: inherit; text-decoration: none; }
.stop-body a:hover h3 { color: var(--pen); text-decoration: underline; text-underline-offset: 3px; }
.stop-body p { margin: 0 0 2px; color: var(--ink-2); font-size: .95rem; max-width: 62ch; }
.link { color: var(--pen); }

/* ---- 강의 화면 ---- */
.lecture { min-height: calc(100dvh / var(--z, 1)); }
.lec-main { display: grid; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) {
  .lec-main { grid-template-columns: minmax(0, 1fr) 300px; }
  .toc-btn { display: none; }
}
.notebook {
  min-width: 0;
  padding: 24px 16px calc(var(--dock-h) + 40vh / var(--z, 1));
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  background-position: -1px -1px;
}
.notebook > * { max-width: 780px; margin-inline: auto; }
@media (min-width: 720px) {
  .notebook { padding-inline: 32px; }
  .notebook > * { padding-left: 56px; position: relative; }
  .notebook > *::before { content: ""; position: absolute; left: 34px; top: 0; bottom: 0; width: 1.5px; background: var(--margin); opacity: .8; }
}
.nb-head { padding-bottom: 8px; }
.nb-course { margin: 0; color: var(--ink-2); font-size: .9rem; }
.nb-head h1 { font-family: var(--f-display); font-size: clamp(1.7rem, 5vw, 2.4rem); line-height: 1.3; margin: 4px 0 12px; }
.goals { margin: 0 0 16px; padding: 12px 16px 12px 2.2em; background: var(--paper-3); border: 1px solid var(--rule); border-radius: var(--r); color: var(--ink-2); }
.goals li::marker { content: "☐  "; color: var(--pen); }

/* 판서 */
.board { padding-bottom: 8px; }
.beat { position: relative; }
.beat.now::after {
  content: ""; position: absolute; left: -26px; top: 6px; bottom: 6px; width: 6px; border-radius: 3px; background: var(--hl);
}
@media (max-width: 719px) { .beat.now::after { left: -10px; width: 4px; } }
.b-item { margin: 12px 0; scroll-margin: 80px 0 calc(var(--dock-h) + 24px); }
/* 지나간 판서: 누르면 "여기부터 듣기" */
.lecture:not(.asking-open) .beat:not(.now) > .b-item { cursor: pointer; }
@media (hover: hover) {
  .lecture:not(.asking-open) .beat:not(.now):hover::before {
    content: ""; position: absolute; left: -26px; top: 6px; bottom: 6px; width: 6px; border-radius: 3px; background: var(--rule);
  }
}
.beat.picked::before {
  content: ""; position: absolute; left: -26px; top: 6px; bottom: 6px; width: 6px; border-radius: 3px; background: var(--pen);
}
@media (max-width: 719px) { .beat:hover::before, .beat.picked::before { left: -10px; width: 4px; } }
.jump-here {
  position: absolute; z-index: 2; top: 0; right: 0; margin: 0;
  font-size: .85rem; padding: .35em .9em; box-shadow: 0 4px 14px color-mix(in oklab, var(--ink) 16%, transparent);
}
.beat.fresh > .b-item { animation: ink .45s ease-out both; }
.beat.fresh > .b-item:nth-child(2) { animation-delay: .08s; }
.beat.fresh > .b-item:nth-child(3) { animation-delay: .16s; }
.beat.fresh > .b-item:nth-child(n+4) { animation-delay: .24s; }
@keyframes ink { from { opacity: 0; clip-path: inset(0 100% 0 0); } to { opacity: 1; clip-path: inset(0 0 0 0); } }
@media (prefers-reduced-motion: reduce) { .beat.fresh > .b-item { animation: none; } }

.b-sec { display: flex; gap: .6rem; align-items: baseline; font-family: var(--f-display); font-weight: 700; font-size: 1.45rem; line-height: 1.35; margin: 40px 0 12px; color: var(--pen); }
.b-sec .n { flex: none; min-width: 1.6em; height: 1.6em; display: inline-grid; place-items: center; border: 2px solid currentColor; border-radius: 50%; font-size: .8em; }
.b-h { font-size: 1.12rem; font-weight: 600; margin: 24px 0 8px; color: var(--pen); }
.b-t { margin: 10px 0; font-size: 1.04rem; max-width: 66ch; }
.b-t.small { font-size: .9rem; color: var(--ink-2); }
.b-m { overflow-x: auto; overflow-y: hidden; padding: 6px 0; font-size: 1.1rem; position: relative; }
.m-label { display: block; text-align: center; font-size: .85rem; color: var(--ink-2); }
.b-list { margin: 10px 0; padding-left: 1.5em; max-width: 66ch; }
.b-list li { margin: 4px 0; }
.b-list li::marker { color: var(--pen); }
mark.hl { background: var(--hl-soft); color: inherit; padding: 0 .1em; border-radius: 2px; }
.b-item code, .qa-say code, .card code { background: var(--paper-2); padding: .05em .3em; border-radius: 3px; }

.b-code { margin: 14px 0; position: relative; border: 1px solid var(--rule); border-radius: var(--r); background: var(--paper-3); }
.b-code figcaption { font-family: var(--f-mono); font-size: .78rem; color: var(--ink-2); padding: 6px 12px; border-bottom: 1px solid var(--rule); }
.b-code pre { margin: 0; padding: 12px 14px; overflow-x: auto; font: 400 .86rem/1.6 var(--f-mono); tab-size: 4; }
.b-code code { background: none; padding: 0; }
.copy { position: absolute; top: 6px; right: 6px; border: 1px solid var(--rule); background: var(--paper); border-radius: 4px; font-size: .75rem; padding: 2px 8px; cursor: pointer; color: var(--ink-2); }
.b-code figcaption + pre + .copy { top: 3px; }
.c-kw { color: var(--pen); font-weight: 500; }
.c-str { color: var(--green); }
.c-com { color: var(--ink-3); font-style: italic; }
.c-num { color: var(--red); }
.c-fn { color: light-dark(#7a4f9a, #c7a2e6); }

.b-table { overflow-x: auto; margin: 14px 0; }
.b-table table { border-collapse: collapse; min-width: 60%; background: var(--paper-3); font-size: .95rem; }
.b-table th, .b-table td { border: 1px solid var(--rule); padding: 6px 12px; text-align: left; vertical-align: top; }
.b-table th { background: var(--paper-2); font-weight: 600; }

.b-flow { display: flex; flex-wrap: wrap; align-items: stretch; gap: 6px; margin: 16px 0; }
.b-flow .node { display: flex; flex-direction: column; justify-content: center; padding: 8px 12px; border: 1.5px solid var(--pen); border-radius: var(--r); background: var(--paper-3); min-width: 72px; text-align: center; }
.b-flow .node b { font-weight: 600; font-size: .95rem; }
.b-flow .node small { color: var(--ink-2); font-size: .78rem; line-height: 1.35; }
.b-flow .node.on { background: var(--hl-soft); }
.b-flow .arrow { align-self: center; width: 22px; height: 2px; background: var(--pen); position: relative; }
.b-flow .arrow::after { content: ""; position: absolute; right: -1px; top: -4px; border: 5px solid transparent; border-left: 7px solid var(--pen); border-right: 0; }
.b-flow .loop { flex-basis: 100%; color: var(--pen); font-size: .9rem; }
.b-flow.vertical { flex-direction: column; align-items: flex-start; }
.b-flow.vertical .arrow { width: 2px; height: 16px; margin-left: 30px; }
.b-flow.vertical .arrow::after { top: auto; bottom: -2px; right: -4px; border: 5px solid transparent; border-top: 7px solid var(--pen); border-bottom: 0; }

.b-tokens { display: flex; flex-wrap: wrap; gap: 3px; margin: 10px 0; align-items: flex-end; }
.tok { font-family: var(--f-mono); font-size: .9rem; padding: 2px 6px; border-radius: 3px; white-space: pre; display: inline-flex; flex-direction: column; align-items: center; line-height: 1.4; }
.tok sub { font-size: .65rem; color: var(--ink-2); line-height: 1.1; }
.tok.t0 { background: light-dark(#cfe3ef, #20384a); }
.tok.t1 { background: light-dark(#f1e1a8, #4a4120); }
.tok.t2 { background: light-dark(#cfe8d8, #1f3d30); }
.tok.t3 { background: light-dark(#f0d0c8, #4a2a24); }
.tok.t4 { background: light-dark(#ddd5ee, #33294a); }
.tok.t5 { background: light-dark(#e6e1d3, #3b3830); }
.tok.multi { outline: 2px double var(--ink-2); outline-offset: -2px; }
.b-tokens .gap { width: 10px; }
.cap { flex-basis: 100%; font-size: .85rem; color: var(--ink-2); margin-top: 4px; }

.b-bars { margin: 12px 0; display: grid; gap: 4px; max-width: 560px; }
.bar { display: grid; grid-template-columns: minmax(64px, max-content) 1fr 64px; gap: 10px; align-items: center; font-size: .92rem; }
.bar .l { white-space: pre; }
.bar .v { text-align: right; font-family: var(--f-mono); font-size: .82rem; color: var(--ink-2); }
.track { position: relative; height: 14px; background: var(--paper-2); border-radius: 3px; overflow: hidden; }
.fill { position: absolute; inset: 0 auto 0 0; width: var(--w); background: var(--pen); border-radius: 3px; transition: width .25s; }
.fill.ghost { background: var(--ink-3); opacity: .45; }
.fill.alt { background: var(--green); }
.bar.pick .fill { background: var(--hl); }
.bar.pick .l { font-weight: 600; }
.bar.clickable { cursor: pointer; border-radius: 4px; }
.bar.clickable:hover { background: var(--pen-soft); }

.b-matrix { margin: 14px 24px 14px 0; overflow-x: auto; display: inline-block; vertical-align: top; max-width: 100%; }
.b-matrix .title, .lbl { font-size: .85rem; color: var(--ink-2); margin: 4px 0; }
.b-matrix table, .mat { border-collapse: collapse; font-family: var(--f-mono); font-size: .82rem; }
.b-matrix td, .b-matrix th, .mat td, .mat th { padding: 4px 8px; text-align: right; border: 1px solid var(--rule); }
.b-matrix th, .mat th { font-family: var(--f-body); font-weight: 500; color: var(--ink-2); background: var(--paper-2); }
.heat td { background: color-mix(in oklab, var(--pen) calc(var(--a, 0) * 70%), var(--paper-3)); color: color-mix(in oklab, var(--ink), var(--on-pen) calc(var(--a, 0) * 80%)); }
.mat td.masked { color: var(--ink-3); background: repeating-linear-gradient(45deg, var(--paper-2) 0 4px, var(--paper-3) 4px 8px); }

.b-note { display: grid; grid-template-columns: auto 1fr; gap: 10px; margin: 16px 0; padding: 10px 14px; border-radius: var(--r); background: var(--paper-3); border: 1px solid var(--rule); border-left: 4px solid var(--pen); max-width: 70ch; }
.b-note .kind { font-weight: 700; font-size: .8rem; color: var(--pen); padding-top: .2em; }
.b-note.key { border-left-color: var(--hl); background: color-mix(in oklab, var(--hl-soft) 45%, var(--paper-3)); }
.b-note.key .kind { color: var(--ink); }
.b-note.warn { border-left-color: var(--red); }
.b-note.warn .kind { color: var(--red); }

.b-svg { margin: 16px 0; color: var(--ink); }
.b-svg svg { max-width: 100%; height: auto; display: block; }
.b-svg figcaption { font-size: .85rem; color: var(--ink-2); margin-top: 4px; }

.b-lab { margin: 16px 0; padding: 12px 16px; border: 1.5px dashed var(--green); border-radius: var(--r); background: var(--green-soft); }
.b-lab header { display: flex; gap: 8px; align-items: baseline; }
.b-lab .kind, .card .kind, .qa .kind { font-size: .78rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--green); color: var(--on-pen); flex: none; }
.b-lab p { margin: 6px 0; }
.b-lab .cmd { position: relative; display: flex; gap: 8px; align-items: center; background: var(--paper-3); border-radius: 4px; padding: 6px 70px 6px 10px; overflow-x: auto; }
.b-lab .cmd code { background: none; white-space: nowrap; font-size: .8rem; }

/* 형광펜: 지금 말하는 항목 / 남겨 둔 표시 / 질문에 고른 항목 */
.b-item.focus, .b-item.marked { background: linear-gradient(transparent 0, var(--hl-soft) 0); border-radius: 4px; box-shadow: 0 0 0 6px var(--hl-soft); transition: background .3s, box-shadow .3s; }
.b-item.marked:not(.focus) { background: none; box-shadow: inset 4px 0 0 var(--hl); padding-left: 10px; }
.asking-open .b-item { cursor: pointer; }
.asking-open .b-item:hover { outline: 1.5px dashed var(--green); outline-offset: 4px; }
.b-item.ref { outline: 2px solid var(--green) !important; outline-offset: 4px; position: relative; }
.b-item.ref::after { content: attr(data-ref); position: absolute; right: -6px; top: -10px; background: var(--green); color: var(--on-pen); font-size: .75rem; font-weight: 700; padding: 0 6px; border-radius: 999px; }

/* 데모 */
.b-demo { margin: 18px 0; border: 1.5px solid var(--pen); border-radius: 10px; background: var(--paper-3); overflow: hidden; }
.b-demo > header { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; padding: 8px 14px; background: var(--pen-soft); }
.b-demo > header span { font-size: .8rem; color: var(--ink-2); }
.demo-body { padding: 12px 14px 14px; }
.demo-body textarea { width: 100%; border: 1px solid var(--rule); border-radius: 4px; background: var(--paper); padding: 8px; resize: vertical; }
.demo-body select { border: 1px solid var(--rule); border-radius: 4px; background: var(--paper); padding: 4px 6px; max-width: 100%; }
.stats.demo, .demo-body .stats { border: 0; margin: 8px 0; padding: 0; font-size: .9rem; }
.multi-key { outline: 2px double var(--ink-2); padding: 0 4px; }
.chk { display: inline-flex; gap: 6px; align-items: center; font-size: .9rem; cursor: pointer; }
.ctls { display: grid; gap: 4px; margin-bottom: 8px; }
.ctl { display: grid; grid-template-columns: minmax(84px, max-content) 1fr 76px; gap: 10px; align-items: center; font-size: .9rem; }
.ctl output { font-family: var(--f-mono); font-size: .82rem; text-align: right; }
.gen { font-size: 1.15rem; margin: 6px 0; min-height: 1.7em; }
.gen.small { font-size: .9rem; color: var(--ink-2); }
.gen .prompt { color: var(--ink-2); }
.gen .added { background: var(--hl-soft); border-radius: 2px; }
.caret { color: var(--pen); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.seg { display: inline-flex; border: 1.5px solid var(--pen); border-radius: 999px; overflow: hidden; }
.seg button, .seg label { border: 0; background: transparent; padding: .3em .9em; cursor: pointer; font-size: .9rem; display: inline-flex; gap: 4px; align-items: center; }
.seg button[aria-pressed="true"], .seg label:has(input:checked) { background: var(--pen); color: var(--on-pen); }
.seg label input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--pen); outline-offset: -4px; }

input[type="range"] {
  --slider-track-size: 6px; --slider-thumb-size: 18px;
  --slider-track-color: var(--grid); --slider-fill-color: var(--pen);
  --slider-progress: calc((var(--control-value, 50) - var(--attr-min, 0)) / (var(--attr-max, 100) - var(--attr-min, 0)) * 100%);
  appearance: none; inline-size: 100%; block-size: 32px; margin: 0; background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { block-size: var(--slider-track-size); border-radius: 999px; background: linear-gradient(to right, var(--slider-fill-color) var(--slider-progress), var(--slider-track-color) var(--slider-progress)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; inline-size: var(--slider-thumb-size); block-size: var(--slider-thumb-size); margin-block-start: calc((var(--slider-track-size) - var(--slider-thumb-size)) / 2); border-radius: 50%; background: var(--paper); border: 3px solid var(--pen); }
input[type="range"]::-moz-range-track { block-size: var(--slider-track-size); border-radius: 999px; background: var(--slider-track-color); }
input[type="range"]::-moz-range-progress { block-size: var(--slider-track-size); border-radius: 999px; background: var(--slider-fill-color); }
input[type="range"]::-moz-range-thumb { inline-size: var(--slider-thumb-size); block-size: var(--slider-thumb-size); border-radius: 50%; background: var(--paper); border: 3px solid var(--pen); }
input[type="range"]:focus-visible { outline: 2px solid var(--pen); outline-offset: 4px; }

/* 위젯별 */
.bpe .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.bpe ol { margin: 4px 0; padding-left: 1.6em; font-family: var(--f-mono); font-size: .85rem; }
.bpe .pairs .top { background: var(--hl-soft); }
.emb { width: 100%; max-width: 420px; display: block; color: var(--ink); }
.emb .axis { stroke: var(--rule); }
.emb .vec { stroke: var(--pen); stroke-width: 2; color: var(--pen); }
.emb .vec.alt { stroke: var(--green); color: var(--green); stroke-dasharray: 5 4; }
.emb .pt { cursor: pointer; }
.emb .pt circle { fill: var(--paper); stroke: var(--ink-2); stroke-width: 2; }
.emb .pt text { fill: var(--ink); font-size: 13px; }
.emb .g0 circle { stroke: var(--pen); } .emb .g1 circle { stroke: var(--green); } .emb .g2 circle { stroke: var(--red); } .emb .g3 circle { stroke: light-dark(#7a4f9a, #c7a2e6); }
.emb .pt.on circle { fill: var(--hl); }
.emb .pt.result circle { fill: var(--green); stroke: var(--green); }
.emb .pt:focus-visible { outline: none; } .emb .pt:focus-visible circle { stroke-width: 4; }
.att-toks { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.tok-btn { border: 1.5px solid var(--rule); background: var(--paper); border-radius: 4px; padding: 3px 9px; cursor: pointer; }
.tok-btn.on { border-color: var(--pen); background: var(--hl-soft); font-weight: 600; }
.att-lines { display: grid; gap: 3px; margin: 8px 0; max-width: 520px; }
.att-w { display: grid; grid-template-columns: 90px 1fr 44px; gap: 8px; align-items: center; font-size: .9rem; }
.att-w .v { font-family: var(--f-mono); font-size: .8rem; text-align: right; }
.att-w.cut { opacity: .35; }
.att-mat, .att-stage { overflow-x: auto; }
.mats { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; }
.mat.out td { background: var(--green-soft); }
.kv-grid { display: grid; gap: 4px; margin: 8px 0; overflow-x: auto; }
.kv-row { display: flex; gap: 3px; align-items: center; }
.kv-row .lbl { width: 64px; flex: none; margin: 0; }
.kv { font-size: .8rem; padding: 2px 6px; border-radius: 3px; white-space: nowrap; }
.kv.calc { background: var(--red); color: var(--on-pen); }
.kv.reuse { background: var(--pen-soft); color: var(--ink-2); }
.kv.out { color: var(--green); font-weight: 600; }
.agent-log { display: grid; gap: 6px; max-height: 420px; overflow-y: auto; padding: 2px; }
.msg { border: 1px solid var(--rule); border-radius: var(--r); background: var(--paper); }
.msg .who { display: flex; gap: 6px; align-items: center; font-size: .78rem; font-weight: 600; padding: 4px 10px; border-bottom: 1px solid var(--rule); color: var(--ink-2); }
.msg .who code { font-weight: 500; background: var(--paper-2); padding: 0 6px; border-radius: 3px; }
.msg pre { margin: 0; padding: 8px 10px; font: .8rem/1.55 var(--f-mono); white-space: pre-wrap; }
.msg.system { border-style: dashed; }
.msg.user { border-left: 4px solid var(--ink-2); }
.msg.assistant { border-left: 4px solid var(--pen); }
.msg.tool { border-left: 4px solid var(--green); }
.msg.tool_use pre { background: var(--pen-soft); }
.msg.thinking pre { color: var(--ink-2); font-style: italic; }
.msg.now { box-shadow: 0 0 0 3px var(--hl-soft); }
.ctx-meter { display: grid; gap: 4px; font-size: .85rem; color: var(--ink-2); margin-bottom: 8px; }
.ctx-meter .fill { background: var(--hl); }
.lora-pic { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin: 10px 0; }
.lp { display: grid; justify-items: center; gap: 6px; }
.lp small { color: var(--ink-2); font-size: .8rem; }
.sq { width: var(--s); height: var(--s); background: var(--paper-2); border: 1.5px solid var(--ink-3); display: grid; place-items: center; font-family: var(--f-display); font-size: 1.4rem; color: var(--ink-2); }
.lr { display: flex; gap: 8px; align-items: flex-start; }
.lr .b, .lr .a { background: var(--hl); border: 1.5px solid var(--ink); display: grid; place-items: center; font-weight: 700; font-size: .8rem; overflow: hidden; }
.lr .b { width: var(--w); height: var(--h); }
.lr .a { width: var(--w); height: var(--h); }
.op { font-size: 1.6rem; color: var(--ink-2); }
.quant, .gd { width: 100%; max-width: 560px; display: block; }
.quant .axis { stroke: var(--ink-3); } .quant .lvl { stroke: var(--grid); }
.quant .orig { fill: var(--pen); } .quant .qv { fill: var(--red); } .quant .errl { stroke: var(--red); stroke-width: 1.5; opacity: .6; }
.gd .curve { fill: none; stroke: var(--pen); stroke-width: 2.5; }
.gd .trail { fill: none; stroke: var(--red); stroke-width: 1.5; stroke-dasharray: 3 3; }
.gd .ball { fill: var(--hl); stroke: var(--ink); stroke-width: 2; }
.ct-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-top: 8px; }
.ct-msgs { display: grid; gap: 6px; }
.ct-raw { margin: 0; padding: 10px; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r); font: .8rem/1.7 var(--f-mono); white-space: pre-wrap; }
.ct-sp { background: var(--red); color: var(--on-pen); border-radius: 3px; padding: 0 3px; }
.ct-role { color: var(--pen); font-weight: 600; }
.samp { display: grid; gap: 3px; font-size: .88rem; }
.samp-head, .samp-row { display: grid; grid-template-columns: 70px 1fr 1.4fr 1fr; gap: 8px; align-items: center; }
.samp-head { font-size: .78rem; color: var(--ink-2); }
.samp-row .l { font-family: var(--f-mono); }
.samp-row .track em { position: absolute; right: 4px; top: -2px; font-style: normal; font-size: .72rem; font-family: var(--f-mono); color: var(--ink); }
.samp-row.cut { opacity: .4; }
.track.thin { height: 6px; }

/* 카드: 퀴즈 · 생각해 보기 · 멈춤 · 장 끝 */
.card { margin: 18px 0; padding: 14px 16px; border-radius: 10px; background: var(--paper-3); border: 1.5px solid var(--pen); max-width: 680px; }
.card header { margin-bottom: 4px; }
.card .kind { background: var(--pen); }
.think-card .kind { background: var(--green); }
.card .q { font-weight: 600; font-size: 1.05rem; margin: 6px 0 10px; }
.choices { display: grid; gap: 6px; }
.choice { display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 8px 12px; border: 1.5px solid var(--rule); border-radius: 8px; background: var(--paper); cursor: pointer; }
.choice .n { flex: none; width: 1.6em; height: 1.6em; border-radius: 50%; border: 1.5px solid var(--ink-3); display: grid; place-items: center; font-size: .85em; }
.choice:hover { border-color: var(--pen); }
.answered .choice { cursor: default; }
.choice.right { border-color: var(--green); background: var(--green-soft); }
.choice.right .n { background: var(--green); border-color: var(--green); color: var(--on-pen); }
.choice.wrong { border-color: var(--red); }
.choice.wrong .n { background: var(--red); border-color: var(--red); color: var(--on-pen); }
.feedback p { margin: 10px 0 0; }
.card textarea { width: 100%; border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); padding: 8px 10px; resize: vertical; }
.hint-box summary { cursor: pointer; color: var(--pen); font-size: .9rem; }
.verdict { font-weight: 700; }
.verdict.good { color: var(--green); } .verdict.partial { color: var(--pen); } .verdict.miss { color: var(--red); }
.end-card h3 { font-family: var(--f-display); margin: 0 0 6px; }
.pause-card p { margin: 0; }
.beat:not(.now) .go-on { display: none; }

/* 질문 답 (초록 펜 여백 메모) */
.qa { margin: 18px 0; padding: 10px 14px; border-left: 3px solid var(--green); background: color-mix(in oklab, var(--green-soft) 70%, transparent); border-radius: 0 8px 8px 0; max-width: 720px; }
.qa header { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.qa header p { margin: 0; font-weight: 600; flex: 1; min-width: 200px; }
.qa-refs { flex-basis: 100%; margin: 4px 0 0; padding-left: 1em; font-size: .85rem; color: var(--ink-2); }
.qa-say { margin: 8px 0; }
.qa .b-item { margin: 8px 0; }
.typing { color: var(--ink-3); font-size: .9rem; margin: 6px 0; }
/* 지나간 질문: 펼친 채로 남김, 제목을 누르면 접힘 */
.qa.past summary { cursor: pointer; display: flex; gap: 8px; align-items: baseline; list-style: none; }
.qa.past summary::-webkit-details-marker { display: none; }
.qa.past summary p { margin: 0; font-weight: 600; flex: 1; min-width: 200px; }
.qa.past summary::after { content: "접기"; flex: none; font-size: .8rem; color: var(--ink-3); }
.qa.past:not([open]) { background: transparent; }
.qa.past:not([open]) summary::after { content: "답 보기"; }

/* ---- 아래 재생 막대 ---- */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 8px 16px max(8px, env(safe-area-inset-bottom));
  background: color-mix(in oklab, var(--paper-3) 94%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--rule);
}
@media (min-width: 1100px) { .dock { right: 300px; } }
.dock > * { max-width: 900px; margin-inline: auto; }
.sub { font-size: 1.05rem; line-height: 1.55; min-height: 3.1em; max-height: 4.7em; overflow-y: auto; padding: 2px 0 6px; text-wrap: pretty; }
.segs { display: flex; gap: 3px; height: 14px; align-items: center; }
.segs .seg { flex: 1 1 0; height: 14px; border: 0; padding: 0; background: transparent; cursor: pointer; position: relative; border-radius: 0; }
.segs .seg::before { content: ""; position: absolute; left: 0; right: 0; top: 5px; height: 4px; border-radius: 2px; background: var(--rule); }
.segs .seg .fill { top: 5px; height: 4px; bottom: auto; width: calc(var(--p, 0) * 100%); background: var(--pen); }
.segs .seg:hover::before { background: var(--rule); }
.segs { touch-action: manipulation; }
.seek-tip {
  position: absolute; bottom: calc(100% + 6px); margin: 0; transform: translateX(-50%); pointer-events: none;
  max-width: min(420px, calc(100vw - 32px)); padding: 6px 10px; border-radius: 8px;
  background: var(--ink); color: var(--paper); font-size: .82rem; line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.seek-tip b { font-family: var(--f-mono); font-weight: 600; margin-right: 4px; }
.seek-tip[hidden] { display: none; }
.controls { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-top: 2px; }
.where { min-width: 0; display: grid; font-size: .8rem; color: var(--ink-2); line-height: 1.35; }
.where-sec { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.transport { display: flex; align-items: center; gap: 2px; }
.play { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--pen); color: var(--on-pen); display: grid; place-items: center; cursor: pointer; margin: 0 4px; }
.play svg { width: 24px; height: 24px; }
.play .i-pause, .play.is-playing .i-play { display: none; }
.play.is-playing .i-pause { display: block; }
.right { display: flex; justify-content: flex-end; align-items: center; gap: 6px; }
.rate-btn {
  min-width: 52px; min-height: 36px; padding: 0 10px; border: 1px solid var(--rule); border-radius: 999px;
  background: var(--paper); color: var(--ink); font: 600 .9rem/1 var(--f-mono); font-variant-numeric: tabular-nums; cursor: pointer;
}
.rate-btn:hover { border-color: var(--ink-3); }
.rate-btn.off-one { border-color: var(--pen); color: var(--pen); }
.rate-btn[aria-expanded="true"] { background: var(--pen); border-color: var(--pen); color: var(--on-pen); }
.rate-menu {
  position: fixed; inset: auto; margin: 0; padding: 6px; min-width: 104px;
  border: 1px solid var(--rule); border-radius: 12px; background: var(--paper);
  color: var(--ink); box-shadow: 0 8px 24px color-mix(in oklab, var(--ink) 18%, transparent);
}
.rate-menu:popover-open { display: grid; gap: 2px; }
.rate-menu button {
  border: 0; border-radius: 8px; background: transparent; color: inherit; padding: 8px 12px; text-align: left; cursor: pointer;
  font: 500 .95rem/1.2 var(--f-mono); font-variant-numeric: tabular-nums; display: flex; justify-content: space-between; gap: 12px;
}
.rate-menu button:hover, .rate-menu button:focus-visible { background: var(--paper-3); outline: none; }
.rate-menu button[aria-checked="true"] { color: var(--pen); font-weight: 700; }
.rate-menu button[aria-checked="true"]::after { content: "✓"; }
.ask-btn { background: var(--green); border-color: var(--green); }
.ask-btn:hover { background: color-mix(in oklab, var(--green) 85%, var(--ink)); }
.stop-answer { display: none; }
.answering .stop-answer { display: inline-flex; }
.answering .ask-btn { display: none; }
.status { margin: 2px auto 0; font-size: .8rem; color: var(--ink-2); min-height: 1.2em; }
.status:empty { display: none; }

.ask { border: 1.5px solid var(--green); border-radius: 12px; padding: 8px; margin-bottom: 8px; background: var(--paper); }
.ask[hidden] { display: none; }
.ask-row { display: flex; gap: 4px; align-items: flex-end; }
.ask textarea { flex: 1; border: 0; background: transparent; resize: none; padding: 6px 8px; min-height: 3em; }
.ask textarea:focus-visible { outline: none; }
.ask .send { background: var(--green); color: var(--on-pen); }
.mic.rec { background: var(--red); color: var(--on-pen); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in oklab, var(--red) 30%, transparent); } }
.quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 4px 2px; }
.refs { display: flex; flex-wrap: wrap; gap: 4px; }
.refs:empty { display: none; }
.ref-chip { border: 0; background: var(--green-soft); color: var(--green); border-radius: 999px; padding: 2px 10px; font-size: .8rem; cursor: pointer; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 719px) {
  :root { --dock-h: 170px; }
  .controls { grid-template-columns: 1fr auto; grid-template-areas: "t t" "w r"; row-gap: 2px; }
  .transport { grid-area: t; justify-content: center; }
  .where { grid-area: w; }
  .right { grid-area: r; }
  .play { width: 48px; height: 48px; }
  .sub { font-size: 1rem; min-height: 3.1em; }
  .rate-btn { min-height: 34px; min-width: 46px; padding: 0 8px; }
  .ask-btn, .stop-answer { min-height: 36px; padding: .3em .9em; }
}

/* ---- 옆 목차 (넓은 화면: 늘 보임 / 좁은 화면: 시트) ---- */
.lec-side { position: relative; }
.side-sheet { border: 0; padding: 0; background: var(--paper-3); color: var(--ink); }
@media (min-width: 1100px) {
  .lec-side { border-left: 1px solid var(--rule); background: var(--paper-3); }
  .side-sheet[open] { position: sticky; inset: auto; top: 56px; display: block; width: 100%; max-height: calc(100dvh / var(--z, 1) - 56px); overflow-y: auto; margin: 0; }
  .side-sheet .close-side { display: none; }
}
@media (max-width: 1099.98px) {
  .side-sheet { position: fixed; inset: 0 0 0 auto; margin: 0; width: min(340px, 86vw); height: 100dvh; max-height: none; box-shadow: -8px 0 24px rgb(0 0 0 / .18); }
  .side-sheet::backdrop { background: rgb(0 0 0 / .4); }
  @media (prefers-reduced-motion: no-preference) {
    .side-sheet[open] { animation: slide-in .22s ease-out; }
    @keyframes slide-in { from { transform: translateX(100%); } }
  }
}
.side-inner { padding: 8px 16px 24px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-family: var(--f-display); font-size: 1.1rem; margin: 8px 0; }
.toc { list-style: none; margin: 0 0 16px; padding: 0; }
.toc button { display: flex; gap: 10px; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: .92rem; line-height: 1.45; }
.toc button:hover { background: var(--paper-2); }
.toc .n { flex: none; width: 1.7em; height: 1.7em; border-radius: 50%; display: grid; place-items: center; border: 1.5px solid var(--rule); font-size: .8em; }
.toc .done .n { background: var(--pen-soft); border-color: var(--pen-soft); }
.toc .now button { background: var(--hl-soft); font-weight: 600; }
.toc .now .n { border-color: var(--ink); }
.side-tools { border-top: 1px solid var(--rule); padding-top: 12px; }

/* ---- 설정 ---- */
.sheet { border: 1px solid var(--rule); border-radius: 14px; padding: 0; width: min(440px, calc(100vw - 32px)); background: var(--paper-3); color: var(--ink); }
.sheet::backdrop { background: rgb(0 0 0 / .4); }
.sheet-body { padding: 8px 20px 20px; }
.sheet fieldset { border: 0; border-top: 1px solid var(--rule); margin: 8px 0 0; padding: 12px 0 4px; display: grid; gap: 8px; }
.sheet legend { font-weight: 600; padding: 0 6px 0 0; }
.opt { display: flex; gap: 8px; align-items: baseline; cursor: pointer; flex-wrap: wrap; }
.opt small { color: var(--ink-2); }
.field { display: grid; gap: 4px; font-size: .9rem; color: var(--ink-2); }
.sheet select { border: 1px solid var(--rule); border-radius: 6px; background: var(--paper); padding: 6px 8px; color: var(--ink); }
.range-row { display: grid; grid-template-columns: 1fr 56px; gap: 8px; align-items: center; color: var(--ink); }
.keys { font-size: .82rem; color: var(--ink-2); border-top: 1px solid var(--rule); padding-top: 12px; line-height: 2; }

/* ---- 질문 노트 ---- */
.notes-page h1 { font-family: var(--f-display); }
.note-item { border-bottom: 1px solid var(--rule); padding: 10px 0; }
.note-item summary { cursor: pointer; display: grid; gap: 2px; }
.note-item .q { font-weight: 600; }
.note-item .qa-body { padding: 6px 0 0 12px; border-left: 3px solid var(--green); margin-top: 8px; }
.empty { color: var(--ink-2); }

.katex { font-size: 1.08em; }
.b-m .katex-display { margin: .4em 0; }
