:root {
  --bg: #ffffff;
  --surface: #f5f6f8;
  --card: #ffffff;
  --ink: #1b1e24;
  --ink-2: #3a3f4a;
  --muted: #5b616e;
  --line: #e4e6eb;
  --line-soft: #eceef1;
  --accent: #2b50c8;
  --accent-ink: #1c3a99;
  --accent-tint: #eef2fd;
  --harm: #1b1e24;
  --res: #2b50c8;
  --ev-measure-bg: #e9eefc; --ev-measure: #1c3a99;
  --ev-infer-bg: #f0f1f4;   --ev-infer: #3a3f4a;
  --ev-coach-bg: #fff3e6;   --ev-coach: #8a4300;
  --ev-analogy-bg: #f3eefc; --ev-analogy: #5b2a9e;
  --serif: 'Noto Serif KR', 'Apple SD Gothic Neo', serif;
  --sans: 'Noto Sans KR', 'Apple SD Gothic Neo', system-ui, sans-serif;
  --topbar: 52px;
  --lab-w: 400px;
  --col: 600px;
  --margin-col: 220px;
  --gap: 32px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b; --surface: #1d2026; --card: #22262d;
    --ink: #e8eaee; --ink-2: #c9cdd5; --muted: #9aa1ad;
    --line: #333842; --line-soft: #2a2e36;
    --accent: #7d9bff; --accent-ink: #a9bcff; --accent-tint: #26304d;
    --harm: #e8eaee; --res: #7d9bff;
    --ev-measure-bg: #26304d; --ev-measure: #a9bcff;
    --ev-infer-bg: #2a2e36;   --ev-infer: #c9cdd5;
    --ev-coach-bg: #3a2a18;   --ev-coach: #ffc58a;
    --ev-analogy-bg: #2f2640; --ev-analogy: #cdb4ff;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; height: var(--topbar);
  display: flex; align-items: center; gap: 16px; padding: 0 24px;
  background: var(--bg); border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.brand { font-weight: 700; letter-spacing: .04em; color: var(--ink); }
.topbar-sub { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lab-toggle {
  margin-left: auto; height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--accent); background: var(--accent-tint); color: var(--accent-ink); cursor: pointer;
}

/* home */
.home-main { max-width: 720px; margin: 0 auto; padding: 56px 24px; }
.home-main h1 { font-family: var(--serif); font-size: 36px; line-height: 1.3; margin: 0 0 12px; }
.home-lead { color: var(--ink-2); line-height: 1.8; margin: 0 0 32px; }
.lesson-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.lesson-list a {
  display: grid; gap: 4px; padding: 18px 20px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink);
}
.lesson-list a:hover { border-color: var(--accent); text-decoration: none; }
.ll-path { font-size: 12px; color: var(--muted); }
.ll-title { font-family: var(--serif); font-size: 20px; font-weight: 600; }
.ll-sum { font-size: 14px; color: var(--ink-2); line-height: 1.6; }

/* table of contents */
.toc-progress { font-size: 13px; color: var(--muted); margin: 0 0 24px; }
.toc { display: grid; gap: 40px; }
.toc-part h2 { font-family: var(--serif); font-size: 24px; margin: 0 0 4px; display: flex; gap: 12px; align-items: baseline; }
.toc-part h2 .toc-num { font-family: var(--sans); font-size: 12px; font-weight: 700; color: var(--accent-ink); letter-spacing: .04em; white-space: nowrap; }
.toc-summary { margin: 0 0 16px; color: var(--ink-2); font-size: 14px; line-height: 1.7; }
.toc-chapter { padding: 12px 0; border-top: 1px solid var(--line-soft); }
.toc-chapter h3 { font-size: 15px; margin: 0 0 6px; display: flex; gap: 8px; }
.toc-num { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 44px; display: inline-block; }
.toc-lessons { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.toc-lessons li { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); padding: 4px 0; }
.toc-lessons li a { color: var(--ink); font-weight: 500; }
.toc-badge { margin-left: auto; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--accent-tint); color: var(--accent-ink); white-space: nowrap; }
.toc-badge.muted { background: var(--surface); color: var(--muted); }

/* previous / next lesson */
.lesson-nav { margin-top: 32px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.nav-item { display: grid; gap: 2px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); font-family: var(--sans); }
.nav-item:last-child { text-align: right; }
a.nav-item:hover { border-color: var(--accent); text-decoration: none; }
.nav-item.is-pending { color: var(--muted); }
.nav-item .toc-badge { margin: 4px 0 0 auto; justify-self: end; }
.nav-dir { font-size: 12px; color: var(--muted); }
.nav-title { font-size: 14px; font-weight: 500; }

/* lesson layout: reading column + margin notes + lab panel */
.page { display: grid; grid-template-columns: minmax(0, 1fr) var(--lab-w); }
body.lab-closed .page { grid-template-columns: minmax(0, 1fr); }
body.lab-closed .lab { display: none; }
.reading { min-width: 0; padding: 48px 32px 96px; }
.article {
  max-width: calc(var(--col) + var(--gap) + var(--margin-col));
  margin: 0 auto; padding-right: calc(var(--gap) + var(--margin-col));
}
.loading { color: var(--muted); }

.meta { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.article h1 { font-family: var(--serif); font-size: 38px; line-height: 1.25; margin: 0 0 16px; }
.objectives {
  margin: 0 0 32px; padding: 16px 20px; border-radius: 10px;
  background: var(--accent-tint); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}
.article .objectives h2 { font-family: var(--sans); font-size: 12px; font-weight: 700; color: var(--accent-ink); margin: 0 0 6px; padding: 0; border: 0; letter-spacing: .02em; }
.objectives ul { margin: 0; padding-left: 18px; line-height: 1.7; font-size: 15px; }

.article h2 {
  font-family: var(--serif); font-size: 23px; font-weight: 600; line-height: 1.4;
  margin: 40px 0 12px; padding-top: 24px; border-top: 1px solid var(--line-soft);
}
.article p, .article li { font-family: var(--serif); font-size: 17px; line-height: 1.9; }
.article p { margin: 0 0 16px; }
.article b, .article strong { font-family: var(--sans); font-weight: 700; font-size: .94em; }
.c-harm { color: var(--harm); }
.c-res { color: var(--res); }

.lab-link {
  display: inline-flex; align-items: center; gap: 8px; margin: 4px 0 16px; padding: 9px 14px;
  border: 0; border-radius: 8px; background: var(--accent-tint); color: var(--accent-ink);
  font-family: var(--sans); font-size: 14px; font-weight: 500; cursor: pointer;
}
.lab-link::before { content: ''; width: 14px; height: 14px; background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4'%3E%3Cpath d='M3 12h3l3-7 4 14 3-7h5'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4'%3E%3Cpath d='M3 12h3l3-7 4 14 3-7h5'/%3E%3C/svg%3E") center/contain no-repeat; }

/* sidenotes (Tufte-style): float into the right margin on wide screens */
.sn-ref { font-family: var(--sans); font-size: 11px; line-height: 0; vertical-align: super; }
.sn-ref button {
  border: 0; background: none; padding: 0 1px; color: var(--accent); font-weight: 700; cursor: pointer; font-size: 11px;
}
.sidenote {
  float: right; clear: right; width: var(--margin-col);
  margin-right: calc(-1 * (var(--margin-col) + var(--gap)));
  margin-top: .3em; margin-bottom: 16px;
  font-family: var(--sans); font-size: 12.5px; line-height: 1.6; color: var(--ink-2);
}
.sidenote .sn-num { color: var(--accent); font-weight: 700; margin-right: 4px; }
@media (min-width: 1181px) { .sidenote.sn-repeat { display: none; } }
.sidenote a { word-break: break-all; }
.ev {
  display: inline-block; margin: 0 4px 4px 0; padding: 1px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
}
.ev-measure { background: var(--ev-measure-bg); color: var(--ev-measure); }
.ev-infer   { background: var(--ev-infer-bg);   color: var(--ev-infer); }
.ev-coach   { background: var(--ev-coach-bg);   color: var(--ev-coach); }
.ev-analogy { background: var(--ev-analogy-bg); color: var(--ev-analogy); }
/* consensus level badges: outlined, so they read as a different axis from evidence-type badges */
.cons {
  display: inline-block; margin: 0 4px 4px 0; padding: 0 8px; border-radius: 4px; border: 1px solid currentColor;
  font-family: var(--sans); font-size: 11.5px; font-weight: 500; white-space: nowrap; background: transparent;
}
.cons-main { color: var(--accent-ink); }
.cons-cond { color: var(--ink-2); }
.cons-debate { color: var(--ev-coach); }
.cons-emerge { color: var(--ev-analogy); }
.cons-hist { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }

/* check questions */
.article details {
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; margin: 0 0 10px;
}
.article details summary { font-family: var(--sans); font-weight: 500; font-size: 15px; cursor: pointer; line-height: 1.6; }
.article details[open] summary { margin-bottom: 8px; }
.article details p { font-size: 16px; margin: 0; }

/* tables in lesson text: sans, ruled rows, scroll sideways on narrow screens */
.article table {
  display: block; max-width: 100%; overflow-x: auto; margin: 8px 0 20px;
  border-collapse: collapse; font-family: var(--sans); font-size: 14px; line-height: 1.55;
}
.article th, .article td { padding: 8px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.article th { font-weight: 700; font-size: 13px; color: var(--ink-2); background: var(--surface); border-bottom: 1px solid var(--muted); white-space: nowrap; }
.article tr:last-child td { border-bottom: 0; }
.article td:first-child { white-space: nowrap; }

/* opening question, terms up front */
.question {
  margin: 0 0 20px; padding: 14px 18px; border-radius: 10px; background: var(--surface);
  font-family: var(--serif); font-size: 19px; line-height: 1.6; font-weight: 600;
}
.question span { display: block; font-family: var(--sans); font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.preterms { margin: -16px 0 32px; padding: 16px 20px; border: 1px solid var(--line); border-radius: 10px; }
.article .preterms h2 { font-family: var(--sans); font-size: 12px; font-weight: 700; color: var(--muted); margin: 0 0 8px; padding: 0; border: 0; }
.preterms dl { margin: 0; display: grid; gap: 8px; }
.preterms dt { font-family: var(--sans); font-size: 14px; font-weight: 700; }
.preterms dd { margin: 0; font-family: var(--sans); font-size: 13.5px; line-height: 1.6; color: var(--ink-2); }

/* one-line summary: any blockquote */
.article blockquote {
  margin: 8px 0 16px; padding: 12px 16px; border-radius: 8px; background: var(--accent-tint);
}
.article blockquote p { margin: 0; font-family: var(--sans); font-size: 15px; line-height: 1.7; }
.article blockquote strong { color: var(--accent-ink); margin-right: 6px; font-size: 12px; }

/* O× quick check */
.ox { margin: 0 0 20px; padding: 12px 16px; border: 1px dashed var(--line); border-radius: 10px; font-family: var(--sans); }
.article .ox p { font-family: var(--sans); margin: 0; }
.article .ox .ox-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.article .ox .ox-q { font-size: 15px; line-height: 1.6; margin: 4px 0 10px; }
.ox-btns { display: flex; gap: 8px; }
.ox-btns button {
  width: 48px; height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); font-size: 17px; font-weight: 700; cursor: pointer;
}
.ox-btns button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-tint); color: var(--accent-ink); }
.article .ox .ox-feedback { font-size: 13.5px; line-height: 1.6; margin-top: 8px; color: var(--ink-2); }
.ox.is-right .ox-feedback::first-line { color: var(--accent-ink); }
.ox.is-wrong .ox-feedback::first-line { color: var(--ev-coach); }

/* myth → refutation → explanation */
.myth { margin: 8px 0 24px; padding: 16px 20px; border-radius: 10px; background: var(--ev-coach-bg); }
.myth p { margin: 0 0 10px; }
.myth p:last-child { margin-bottom: 0; }
.myth strong { color: var(--ev-coach); }

/* worked case and practice */
.case, .practice { margin: 0 0 20px; padding: 16px 20px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.case ol { padding-left: 20px; margin: 8px 0 0; }
.case li { margin-bottom: 8px; }
.practice p { margin: 0; }
.article details.deeper { margin-top: 32px; background: var(--surface); border-color: transparent; }

.refs { margin-top: 48px; padding-top: 24px; border-top: 1px solid var(--line-soft); }
.article .refs h2 { border: 0; padding: 0; margin: 0 0 10px; font-size: 16px; font-family: var(--sans); font-weight: 700; }
.refs ol { padding-left: 20px; margin: 0; }
.article .refs li { font-family: var(--sans); font-size: 13.5px; line-height: 1.7; color: var(--ink-2); }

/* lab panel */
.lab {
  position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--line); padding: 20px;
  display: flex; flex-direction: column; gap: 14px; font-family: var(--sans);
}
.article .lab p { font-family: var(--sans); font-size: 12.5px; line-height: 1.6; margin: 0; }
.lab.inline { margin: 0 0 20px; border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.lab-head { display: flex; gap: 8px; align-items: center; }
.tabs { flex: 1; display: flex; gap: 4px; padding: 4px; border-radius: 10px; background: color-mix(in srgb, var(--ink) 8%, transparent); }
.tabs button {
  flex: 1; height: 34px; border: 0; border-radius: 7px; background: transparent; font-size: 13px; color: var(--ink-2); cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); font-weight: 500; }
.icon-btn {
  width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 8px; background: var(--card);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink-2);
}
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 10px; }
.card h3 { margin: 0; font-size: 13px; font-weight: 700; }
.card .hint { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 0; }
.spectrum { width: 100%; height: auto; display: block; }
.spectrum .axis { stroke: var(--muted); stroke-width: 1; }
.spectrum .grid { stroke: var(--line); stroke-width: 1; }
.spectrum .res { fill: none; stroke: var(--res); stroke-width: 2; stroke-dasharray: 5 4; }
.spectrum .harm { stroke: var(--harm); stroke-width: 3; }
.spectrum .harm.top { stroke: var(--accent); }
.spectrum text { font-family: var(--sans); font-size: 10.5px; fill: var(--muted); }
.spectrum .peak-label { fill: var(--accent-ink); }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; }
.controls .label { color: var(--muted); min-width: 22px; }
.seg {
  height: 32px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: 13px;
}
.seg[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-tint); color: var(--accent-ink); }
.range-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.range-row input { width: 100%; accent-color: var(--accent); }
.check-row { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.readout { font-size: 12.5px; color: var(--ink-2); line-height: 1.6; margin: 0; }
.play {
  display: inline-flex; align-items: center; gap: 10px; border: 0; background: none; padding: 0; cursor: pointer; font-size: 13px; text-align: left;
}
.play .dot {
  width: 38px; height: 38px; border-radius: 19px; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.phrase-list { display: flex; flex-wrap: wrap; gap: 6px; }
.phrase-list .seg { height: auto; min-height: 32px; padding: 6px 10px; text-align: left; line-height: 1.4; }
.layers { margin: 0; display: grid; gap: 10px; }
.layers dt { font-size: 12px; font-weight: 700; color: var(--muted); }
.layers dd { margin: 2px 0 0; font-size: 13.5px; line-height: 1.6; }
.layers .instead { padding: 10px 12px; border-radius: 8px; background: var(--accent-tint); }
.layers .instead dt { color: var(--accent-ink); }
.card.flash { outline: 2px solid var(--accent); outline-offset: 2px; transition: outline-color .6s; }
.terms dl { margin: 0; display: grid; gap: 12px; }
.terms dt { font-size: 13.5px; font-weight: 700; }
.terms dd { margin: 2px 0 0; font-size: 13px; line-height: 1.6; color: var(--ink-2); }
.notes-label { font-size: 12.5px; color: var(--muted); display: block; margin-bottom: 6px; }
#notes {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 14px;
  background: var(--card); color: var(--ink); resize: vertical;
}

/* medium screens: sidenotes become tap-to-open notes inside the text */
@media (max-width: 1180px) {
  .article { padding-right: 0; max-width: var(--col); }
  .sidenote {
    display: none; float: none; width: auto; margin: 8px 0 12px; padding: 10px 12px;
    border-radius: 8px; background: var(--surface);
  }
  .sidenote.open { display: block; }
}
/* small screens: lab panel moves below the article */
@media (max-width: 900px) {
  .page, body.lab-closed .page { grid-template-columns: minmax(0, 1fr); }
  .lab { position: static; height: auto; border-left: 0; border-top: 1px solid var(--line); }
  body.lab-closed .lab { display: flex; }
  #lab-close, .lab-toggle { display: none; }
  .reading { padding: 28px 16px 48px; }
  .article h1 { font-size: 30px; }
  .topbar { padding: 0 16px; }
}
