/* IMP 교과서 — 공통 스타일
   색은 모두 토큰으로 정의한다. 다크 모드는 시스템 설정을 따르고, data-theme로 강제할 수 있다. */
@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@500;600;700&family=IBM+Plex+Sans+KR:wght@500;600;700&display=swap");

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eff2f8;
  --surface-3: #e6ebf3;
  --text: #17212c;
  --dim: #546273;
  --faint: #8995a4;
  --border: #dfe5ee;
  --grid: #e7ebf2;
  --axis: #9aa6b4;
  --accent: #2f6fe4;        /* IMP: 파란 이온 */
  --accent-soft: #e5eefe;
  --accent-2: #e04f7d;      /* 세미툰 핑크 */
  --accent-2-soft: #fde8ef;
  --ok: #17905f;
  --ok-soft: #e1f5ec;
  --warn: #c77a06;
  --warn-soft: #fdf1dc;
  --bad: #d23f58;
  --bad-soft: #fde6ea;
  --violet: #7a5af0;
  --violet-soft: #efeafe;
  /* 도펀트 색 (키워드맵과 같은 계열) */
  --sp-B: #1f9d62;
  --sp-BF2: #0f8f8a;
  --sp-P: #2f6fe4;
  --sp-As: #e08a0b;
  --sp-Sb: #8b5cf6;
  --sp-In: #d9467a;
  --sp-Ge: #64748b;
  --sp-Si: #8c98a8;
  --code-bg: #eef1f6;
  --shadow: 0 1px 2px rgba(20, 30, 45, .05), 0 6px 20px rgba(20, 30, 45, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --content: 780px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e131a;
    --surface: #141b24;
    --surface-2: #1a232e;
    --surface-3: #212c39;
    --text: #e5ecf4;
    --dim: #a2afbe;
    --faint: #6e7c8c;
    --border: #253140;
    --grid: #1e2833;
    --axis: #5d6b7b;
    --accent: #6b9dff;
    --accent-soft: #18284a;
    --accent-2: #ff7ca5;
    --accent-2-soft: #3a1a27;
    --ok: #3fcf90;
    --ok-soft: #12302a;
    --warn: #f3b443;
    --warn-soft: #33270f;
    --bad: #ff6f86;
    --bad-soft: #3a1620;
    --violet: #a48bff;
    --violet-soft: #251d45;
    --sp-B: #40cc88;
    --sp-BF2: #2cc4bd;
    --sp-P: #6b9dff;
    --sp-As: #f5a524;
    --sp-Sb: #a98bff;
    --sp-In: #ff74a6;
    --sp-Ge: #93a3b8;
    --sp-Si: #6f7d8f;
    --code-bg: #1b2430;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e131a;
  --surface: #141b24;
  --surface-2: #1a232e;
  --surface-3: #212c39;
  --text: #e5ecf4;
  --dim: #a2afbe;
  --faint: #6e7c8c;
  --border: #253140;
  --grid: #1e2833;
  --axis: #5d6b7b;
  --accent: #6b9dff;
  --accent-soft: #18284a;
  --accent-2: #ff7ca5;
  --accent-2-soft: #3a1a27;
  --ok: #3fcf90;
  --ok-soft: #12302a;
  --warn: #f3b443;
  --warn-soft: #33270f;
  --bad: #ff6f86;
  --bad-soft: #3a1620;
  --violet: #a48bff;
  --violet-soft: #251d45;
  --sp-B: #40cc88;
  --sp-BF2: #2cc4bd;
  --sp-P: #6b9dff;
  --sp-As: #f5a524;
  --sp-Sb: #a98bff;
  --sp-In: #ff74a6;
  --sp-Ge: #93a3b8;
  --sp-Si: #6f7d8f;
  --code-bg: #1b2430;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.78;
  letter-spacing: -0.005em;
  word-break: keep-all;
  overflow-wrap: break-word;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg, canvas { max-width: 100%; }
button { font: inherit; color: inherit; }
code, kbd { font-family: var(--mono); font-size: .88em; background: var(--code-bg); padding: .1em .38em; border-radius: 5px; }
small { font-size: .82em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 40px 0; }
::selection { background: var(--accent-soft); }

/* ---------- 상단바 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 10px;
  height: 60px; padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 800; letter-spacing: -0.02em; min-width: 0; }
.topbar .brand:hover { text-decoration: none; }
.topbar .brand .logo { width: 30px; height: 30px; flex: none; }
.topbar .brand .name { font-size: 17px; white-space: nowrap; }
.topbar .brand .sub { font-size: 12.5px; color: var(--dim); font-weight: 600; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }
.progress { position: absolute; left: 0; bottom: -1px; height: 2px; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .1s linear; }
@media (max-width: 520px) { .topbar .brand .sub { display: none; } }

/* ---------- 챕터 서랍 ---------- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(8, 12, 18, .45); z-index: 60; opacity: 0; pointer-events: none; transition: opacity .2s; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 61;
  width: min(340px, 88vw); overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  transform: translateX(-102%); transition: transform .22s ease;
  padding: 18px 14px 40px;
}
body.drawer-open .drawer { transform: none; }
body.drawer-open .drawer-scrim { opacity: 1; pointer-events: auto; }
.drawer h4 { margin: 4px 8px 12px; font-size: 12px; letter-spacing: .14em; color: var(--faint); font-family: var(--mono); }
.drawer a { display: flex; gap: 12px; align-items: baseline; padding: 9px 10px; border-radius: 10px; color: var(--text); font-size: 15px; line-height: 1.45; }
.drawer a:hover { background: var(--surface-2); text-decoration: none; }
.drawer a.on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.drawer a .n { font-family: var(--mono); font-size: 12px; color: var(--faint); width: 22px; flex: none; }
.drawer a.on .n { color: var(--accent); }
.drawer .part { margin: 16px 10px 6px; font-size: 12px; font-weight: 700; color: var(--dim); }
.drawer a.soon { opacity: .5; pointer-events: none; }
.drawer a small { font-size: 11px; color: var(--faint); font-weight: 600; margin-left: 4px; }
.chapter-nav a.soon { opacity: .5; pointer-events: none; }

/* ---------- 본문 배치 ---------- */
.page { display: block; }
main.chapter, main.home { max-width: var(--content); margin: 0 auto; padding: 0 16px 80px; }
main.home { max-width: 1080px; }
.toc {
  display: none;
}
@media (min-width: 1240px) {
  .toc {
    display: block; position: fixed; top: 92px; right: max(16px, calc((100vw - var(--content)) / 2 - 300px));
    width: 230px; max-height: calc(100vh - 120px); overflow-y: auto;
    font-size: 13.5px; line-height: 1.5;
  }
  .toc h5 { margin: 0 0 10px; font-size: 11.5px; letter-spacing: .14em; color: var(--faint); font-family: var(--mono); }
  .toc a { display: block; padding: 5px 10px; color: var(--dim); border-left: 2px solid var(--border); }
  .toc a:hover { color: var(--text); text-decoration: none; }
  .toc a.on { color: var(--accent); border-left-color: var(--accent); font-weight: 700; }
}

/* ---------- 챕터 머리 ---------- */
.chapter-hero { padding: 56px 0 8px; }
.eyebrow { font-family: var(--mono); font-size: 12.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.chapter-hero h1 { font-size: clamp(34px, 6vw, 48px); line-height: 1.18; margin: 10px 0 18px; letter-spacing: -0.035em; font-weight: 850; }
.lead { font-size: 18.5px; color: var(--dim); line-height: 1.8; margin: 0 0 22px; }
.objectives {
  list-style: none; margin: 0 0 8px; padding: 18px 20px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.objectives::before { content: "이 장을 마치면"; display: block; font-size: 12.5px; font-weight: 700; color: var(--faint); margin-bottom: 8px; }
.objectives li { position: relative; padding-left: 20px; margin: 4px 0; font-size: 15.5px; line-height: 1.6; font-weight: 600; }
.objectives li::before { content: ""; position: absolute; left: 2px; top: .62em; width: 8px; height: 8px; border-radius: 3px; background: var(--accent); }

/* ---------- 절 ---------- */
main.chapter section { margin-top: 64px; }
main.chapter h2 { font-size: clamp(25px, 4vw, 30px); line-height: 1.3; letter-spacing: -0.03em; margin: 0 0 18px; font-weight: 820; }
main.chapter h2 .h-num { font-family: var(--mono); color: var(--accent); font-size: .62em; margin-right: 12px; vertical-align: .18em; font-weight: 700; }
main.chapter h3 { font-size: 20px; line-height: 1.4; margin: 36px 0 12px; letter-spacing: -0.02em; }
main.chapter p { margin: 0 0 18px; }
main.chapter ul, main.chapter ol { padding-left: 1.3em; margin: 0 0 18px; }
main.chapter li { margin: 5px 0; }
.term { font-weight: 750; color: var(--text); background: linear-gradient(transparent 62%, var(--accent-soft) 62%); }
.en { color: var(--dim); font-size: .9em; }
strong { font-weight: 750; }

/* ---------- 인용 ---------- */
cite.ref { font-style: normal; font-size: .72em; vertical-align: .42em; line-height: 0; white-space: nowrap; }
cite.ref a { font-family: var(--mono); font-weight: 700; color: var(--accent); padding: 0 1px; }
cite.ref a:hover { text-decoration: none; background: var(--accent-soft); border-radius: 4px; }
.refs ol { padding-left: 0; list-style: none; counter-reset: none; }
.refs li { display: grid; grid-template-columns: 38px 1fr; gap: 4px; font-size: 14.5px; line-height: 1.6; margin: 0 0 12px; color: var(--dim); }
.refs li .rn { font-family: var(--mono); font-weight: 700; color: var(--accent); }
.refs li .rt { color: var(--text); font-weight: 650; }
.refs li a { word-break: break-all; }
.refs li:target { background: var(--accent-soft); border-radius: 8px; padding: 4px 6px; margin-left: -6px; }
.refs .note { font-size: 13.5px; color: var(--faint); }
.ref-pop {
  position: absolute; z-index: 70; max-width: min(420px, 90vw);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  padding: 10px 12px; font-size: 13.5px; line-height: 1.55; color: var(--dim);
}
.ref-pop b { color: var(--text); }

/* ---------- 도해 ---------- */
figure.diagram { margin: 26px 0 28px; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
figure.diagram svg { display: block; width: 100%; height: auto; }
figure.diagram figcaption, figure figcaption { margin-top: 12px; font-size: 14.5px; color: var(--dim); line-height: 1.6; }
figure figcaption b { color: var(--text); }
/* SVG 안 클래스 (색을 직접 쓰지 않는다) */
.lbl { fill: var(--text); font: 600 13px var(--font); }
.lbl-sm { fill: var(--dim); font: 500 11.5px var(--font); }
.lbl-dim { fill: var(--dim); font: 500 12.5px var(--font); }
.lbl-b { fill: var(--text); font: 800 14px var(--font); }
.lbl-acc { fill: var(--accent); font: 700 13px var(--font); }
.lbl-acc2 { fill: var(--accent-2); font: 700 13px var(--font); }
.lbl-ok { fill: var(--ok); font: 700 13px var(--font); }
.lbl-bad { fill: var(--bad); font: 700 13px var(--font); }
.lbl-warn { fill: var(--warn); font: 700 13px var(--font); }
.t-mono { font-family: var(--mono) !important; }
.s-line { stroke: var(--text); stroke-width: 1.5; fill: none; }
.s-dim { stroke: var(--faint); stroke-width: 1.2; fill: none; }
.s-axis { stroke: var(--axis); stroke-width: 1.2; fill: none; }
.s-dash { stroke: var(--faint); stroke-width: 1.2; stroke-dasharray: 4 4; fill: none; }
.s-acc { stroke: var(--accent); stroke-width: 2.2; fill: none; }
.s-acc2 { stroke: var(--accent-2); stroke-width: 2.2; fill: none; }
.s-ok { stroke: var(--ok); stroke-width: 2.2; fill: none; }
.s-bad { stroke: var(--bad); stroke-width: 2.2; fill: none; }
.s-warn { stroke: var(--warn); stroke-width: 2.2; fill: none; }
.f-bg { fill: var(--bg); }
.f-surface { fill: var(--surface); }
.f-surface2 { fill: var(--surface-2); }
.f-surface3 { fill: var(--surface-3); }
.f-acc { fill: var(--accent); }
.f-acc2 { fill: var(--accent-2); }
.f-ok { fill: var(--ok); }
.f-bad { fill: var(--bad); }
.f-warn { fill: var(--warn); }
.f-violet { fill: var(--violet); }
.f-acc-soft { fill: var(--accent-soft); }
.f-acc2-soft { fill: var(--accent-2-soft); }
.f-ok-soft { fill: var(--ok-soft); }
.f-bad-soft { fill: var(--bad-soft); }
.f-warn-soft { fill: var(--warn-soft); }
.f-violet-soft { fill: var(--violet-soft); }
.f-text { fill: var(--text); }
.f-dim { fill: var(--dim); }
.f-faint { fill: var(--faint); }
.f-si { fill: var(--surface-3); stroke: var(--axis); stroke-width: 1; }
.f-oxide { fill: var(--warn-soft); stroke: var(--warn); stroke-width: 1; }
.f-pr { fill: var(--violet-soft); stroke: var(--violet); stroke-width: 1; }
.f-poly { fill: var(--bad-soft); stroke: var(--bad); stroke-width: 1; }
.f-nreg { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1; }
.f-preg { fill: var(--ok-soft); stroke: var(--ok); stroke-width: 1; }

/* ---------- 시뮬레이터 카드 ---------- */
.sim {
  margin: 30px 0 32px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.sim-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.sim-head h3 { margin: 0 !important; font-size: 16.5px !important; line-height: 1.4; letter-spacing: -0.015em; }
.sim-tag {
  flex: none; font-family: var(--mono); font-size: 11px; font-weight: 800; letter-spacing: .12em;
  padding: 3px 9px; border-radius: 999px; color: var(--accent); border: 1.5px solid currentColor;
}
.sim-tag.anim { color: var(--accent-2); }
.sim-tag.predict { color: var(--warn); }
.sim-tag.challenge { color: var(--ok); }
.sim-tag.lab { color: var(--violet); }
.sim-body { display: block; }
.sim-body.side { display: grid; grid-template-columns: minmax(0, 1fr) 250px; }
.sim-view { position: relative; padding: 14px 14px 8px; min-width: 0; }
.sim-view canvas { display: block; width: 100%; touch-action: none; }
.sim-view .hint { position: absolute; right: 18px; top: 16px; font-size: 12px; color: var(--faint); background: var(--surface); padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); pointer-events: none; }
.sim-controls { padding: 16px 18px; border-left: 1px solid var(--border); display: flex; flex-direction: column; gap: 14px; }
.sim-body:not(.side) .sim-controls { border-left: 0; border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px 22px; }
@media (max-width: 760px) {
  .sim-body.side { display: block; }
  .sim-body.side .sim-controls { border-left: 0; border-top: 1px solid var(--border); }
}
.ctrl { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.ctrl > span { display: flex; justify-content: space-between; gap: 10px; color: var(--dim); font-weight: 600; }
.ctrl output { font-family: var(--mono); color: var(--text); font-weight: 700; font-size: 13.5px; white-space: nowrap; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 26px; background: transparent; cursor: pointer; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 6px; background: linear-gradient(90deg, var(--accent) var(--fill, 50%), var(--surface-3) var(--fill, 50%)); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 6px; background: var(--surface-3); }
input[type=range]::-moz-range-progress { height: 6px; border-radius: 6px; background: var(--accent); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%; background: var(--surface); border: 3px solid var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.2); }
input[type=range]::-moz-range-thumb { width: 15px; height: 15px; border-radius: 50%; background: var(--surface); border: 3px solid var(--accent); }
input[type=range]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.seg button { border: 0; background: transparent; padding: 6px 11px; border-radius: 7px; font-size: 13.5px; font-weight: 650; cursor: pointer; color: var(--dim); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg button[data-sp].on { color: var(--sp); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--dim); font-weight: 600; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 9px; font-size: 14px; font-weight: 650; cursor: pointer; line-height: 1.3;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; }
.sim-readout { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); border-top: 1px solid var(--border); }
.stat { padding: 12px 18px; border-right: 1px solid var(--border); min-width: 0; }
.stat:last-child { border-right: 0; }
.stat .k { display: block; font-size: 12.5px; color: var(--faint); font-weight: 600; margin-bottom: 2px; }
.stat .v { display: block; font-family: var(--mono); font-size: 18px; font-weight: 750; color: var(--text); line-height: 1.3; overflow-wrap: break-word; }   /* 긴 값은 말줄임 대신 줄을 바꿔 다 보인다 */
.stat .v small { font-size: .66em; color: var(--dim); margin-left: 2px; font-weight: 600; }
.stat .v.ok { color: var(--ok); } .stat .v.bad { color: var(--bad); } .stat .v.acc { color: var(--accent); }
.sim-note { padding: 12px 18px 14px; border-top: 1px solid var(--border); background: var(--surface-2); font-size: 14px; line-height: 1.65; color: var(--dim); }
.sim-note b { color: var(--text); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 0 18px 10px; font-size: 13px; color: var(--dim); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 14px; height: 4px; border-radius: 3px; }
.legend i.dot { width: 9px; height: 9px; border-radius: 50%; }

/* PREDICT · CHALLENGE */
.pred-box { padding: 16px 18px 6px; }
.pq { font-weight: 700; font-size: 16px; line-height: 1.6; margin-bottom: 12px; }
.pred-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; }
.pred-opts .btn { text-align: left; padding: 10px 14px; font-weight: 600; }
.pred-opts .btn.right { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.pred-opts .btn.wrong { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.chal-msg { margin: 0 18px 14px; padding: 10px 14px; border-radius: 10px; background: var(--surface-2); font-size: 14.5px; line-height: 1.6; color: var(--dim); }
.chal-msg.ok { background: var(--ok-soft); color: var(--ok); font-weight: 650; }
.chal-msg.bad { background: var(--bad-soft); color: var(--bad); font-weight: 650; }

/* ---------- 강조 상자 ---------- */
.callout {
  margin: 24px 0; padding: 16px 18px; border-radius: var(--radius-sm);
  background: var(--accent-soft); border-left: 4px solid var(--accent);
  font-size: 15.5px; line-height: 1.72;
}
.callout > strong:first-child { display: block; margin-bottom: 4px; font-size: 15px; }
.callout p:last-child { margin-bottom: 0; }
.callout.tip { background: var(--ok-soft); border-left-color: var(--ok); }
.callout.warn { background: var(--warn-soft); border-left-color: var(--warn); }
.callout.deep { background: var(--violet-soft); border-left-color: var(--violet); }
.callout.field { background: var(--accent-2-soft); border-left-color: var(--accent-2); }
.callout.field > strong:first-child::before { content: "FIELD NOTE · "; font-family: var(--mono); font-size: 11.5px; letter-spacing: .1em; color: var(--accent-2); }
.callout.deep > strong:first-child::before { content: "DEEP DIVE · "; font-family: var(--mono); font-size: 11.5px; letter-spacing: .1em; color: var(--violet); }

/* ---------- 수식·표 ---------- */
.formula { margin: 22px 0; padding: 14px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow-x: auto; position: relative; }
.formula .where { margin-top: 6px; font-size: 14px; color: var(--dim); line-height: 1.65; }
.katex-display { margin: .4em 0 !important; overflow-x: auto; overflow-y: hidden; }
.table-wrap { margin: 22px 0; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; line-height: 1.55; }
th, td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-weight: 750; font-size: 13.5px; color: var(--dim); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.table-wrap caption { caption-side: bottom; text-align: left; padding: 10px 14px; font-size: 13.5px; color: var(--dim); }

/* ---------- 정리·퀴즈 ---------- */
.keypoints { margin-top: 72px !important; padding: 24px 24px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.keypoints ol li { margin: 8px 0; font-size: 15.5px; line-height: 1.7; }
.quiz-q { margin: 0 0 22px; padding: 18px 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.quiz-q > p { font-weight: 700; margin: 0 0 12px !important; line-height: 1.6; }
.opts { display: grid; gap: 8px; }
.opt { text-align: left; border: 1px solid var(--border); background: var(--surface-2); padding: 10px 14px; border-radius: 9px; cursor: pointer; font-size: 15px; line-height: 1.5; }
.opt:hover { border-color: var(--accent); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); font-weight: 650; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
.opt:disabled { cursor: default; }
.quiz-exp { display: none; margin-top: 12px; padding: 12px 14px; border-radius: 9px; background: var(--surface-2); font-size: 14.5px; line-height: 1.7; color: var(--dim); }
.quiz-exp.show { display: block; }
.quiz-exp a { font-weight: 650; }

/* ---------- 이전/다음 · 꼬리말 ---------- */
.chapter-nav { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-top: 64px; }
.chapter-nav a { display: block; padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.chapter-nav a:hover { border-color: var(--accent); text-decoration: none; }
.chapter-nav a .d { display: block; font-size: 12.5px; color: var(--faint); font-family: var(--mono); margin-bottom: 4px; }
.chapter-nav a.next { text-align: right; grid-column: 2; }
.chapter-nav a .t { font-weight: 750; overflow-wrap: anywhere; }
footer.site-foot { border-top: 1px solid var(--border); padding: 28px 16px 40px; text-align: center; font-size: 13px; color: var(--faint); line-height: 1.7; }
footer.site-foot a { color: var(--dim); }

/* ---------- 홈 ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 40px; align-items: center; padding: 64px 0 40px; }
@media (max-width: 900px) { .hero { grid-template-columns: 1fr; gap: 24px; padding-top: 40px; } }
.hero h1 { font-size: clamp(36px, 6.4vw, 60px); line-height: 1.12; letter-spacing: -0.045em; margin: 12px 0 20px; font-weight: 880; }
.hero h1 .grad { background: linear-gradient(90deg, var(--accent), var(--grad-b, var(--accent-2))); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p.lead { font-size: 18px; }
.hero .cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 22px 0 18px; }
.hero .cta .btn { padding: 12px 20px; font-size: 15.5px; border-radius: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font-size: 13px; padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--dim); font-weight: 600; }
.hero-sim { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); overflow: hidden; }
.hero-sim .cap { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-size: 12.5px; color: var(--faint); font-family: var(--mono); border-bottom: 1px solid var(--border); }
.home-sec { margin: 72px 0 0; }
.home-sec > h2 { font-size: clamp(26px, 4vw, 34px); letter-spacing: -0.035em; margin: 0 0 8px; }
.home-sec > p.sub { color: var(--dim); margin: 0 0 24px; }
.numbers { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.num-card { padding: 18px 18px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.num-card .big { font-family: var(--mono); font-size: 26px; font-weight: 800; color: var(--accent); letter-spacing: -0.02em; }
.num-card p { margin: 6px 0 0; font-size: 14.5px; line-height: 1.6; color: var(--dim); }
.ch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.ch-card { display: block; padding: 18px 18px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); transition: border-color .15s, transform .15s; }
.ch-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.ch-card .no { font-family: var(--mono); font-size: 12px; color: var(--accent); font-weight: 700; letter-spacing: .1em; }
.ch-card h3 { margin: 4px 0 6px; font-size: 18.5px; letter-spacing: -0.02em; }
.ch-card p { margin: 0; font-size: 14.5px; line-height: 1.62; color: var(--dim); }
.ch-card .tags { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.ch-card .tags span { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--dim); font-weight: 650; }
.ch-card.soon { opacity: .55; pointer-events: none; }
.ch-card.soon .no::after { content: " · 준비 중"; color: var(--faint); }
.how { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.how div { padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); font-size: 14.5px; line-height: 1.6; color: var(--dim); }
.how b { display: block; color: var(--text); font-size: 15.5px; margin-bottom: 4px; }

/* 접근성 */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print {
  .topbar, .drawer, .toc, .sim-controls, .chapter-nav { display: none !important; }
  body { background: #fff; color: #000; }
}

/* =====================================================================
   세미툰 꾸밈 (Skin)
   구조와 기능은 그대로 두고 꾸밈만 바꾼다: 제목·숫자 글꼴, 장 머리의 격자 점무늬 패널,
   한글 배지, 종류별 색 띠, 둥근 강조 상자, 목표·정리·퀴즈의 기호.
   ===================================================================== */
:root {
  --head: "IBM Plex Sans KR", "Pretendard Variable", Pretendard, "Malgun Gothic", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --dot: rgba(47, 111, 228, .13);
  --radius: 18px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --dot: rgba(107, 157, 255, .14); } }
:root[data-theme="dark"] { --dot: rgba(107, 157, 255, .14); }

/* 제목 글꼴 */
h1, h2, h3, .hero h1, .home-sec > h2, .topbar .brand .name, .ch-card h3, .chapter-nav a .t { font-family: var(--head); }
main.chapter h2 { font-weight: 700; letter-spacing: -0.02em; }
.chapter-hero h1 { font-weight: 700; letter-spacing: -0.03em; }
.hero h1 { font-weight: 700; letter-spacing: -0.035em; }

/* 상단바: 아래에 얇은 두 색 선 */
.topbar { border-bottom: 0; box-shadow: 0 1px 0 var(--border); }
.topbar .brand .sub { color: var(--accent-2); }

/* 장 머리: 실리콘 격자를 닮은 점무늬 패널 */
.chapter-hero {
  position: relative; margin-top: 28px; padding: 34px 28px 26px;
  border-radius: 24px; border: 1px solid var(--border);
  background:
    radial-gradient(120% 90% at 100% 0%, var(--glow, var(--accent-2-soft)) 0%, transparent 55%),
    radial-gradient(circle at 1px 1px, var(--dot) 1.2px, transparent 0) 0 0 / 18px 18px,
    var(--surface);
}
@media (max-width: 520px) { .chapter-hero { padding: 26px 18px 20px; border-radius: 18px; } }
.chapter-hero .objectives { background: color-mix(in srgb, var(--surface) 88%, transparent); }

/* 장 표시: 영문 대문자 대신 한글 칩 */
.eyebrow {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--head); font-size: 13px; letter-spacing: 0; text-transform: none; font-weight: 700;
  color: var(--accent); background: var(--accent-soft); padding: 4px 12px; border-radius: 999px;
}
.eyebrow::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); }

/* 절 번호: 색 사각 배지 */
main.chapter h2 .h-num {
  display: inline-grid; place-items: center; min-width: 1.7em; height: 1.7em; padding: 0 .35em;
  margin-right: 12px; vertical-align: .12em; border-radius: 9px;
  background: var(--accent); color: #fff; font-family: var(--mono); font-size: .56em; font-weight: 700;
}

/* 목표: 체크 표시 */
.objectives li::before {
  content: "✓"; top: 0; left: 0; width: auto; height: auto; background: none; border-radius: 0;
  color: var(--ok); font-weight: 800; font-size: 14px;
}

/* 시뮬레이터 카드: 종류별 색 띠와 채워진 한글 배지 */
.sim { --kc: var(--accent); border-top: 4px solid var(--kc); border-radius: var(--radius); }
.sim[data-kind="anim"] { --kc: var(--accent-2); }
.sim[data-kind="predict"] { --kc: var(--warn); }
.sim[data-kind="challenge"] { --kc: var(--ok); }
.sim[data-kind="lab"] { --kc: var(--violet); }
.sim-head { background: linear-gradient(180deg, color-mix(in srgb, var(--kc) 9%, var(--surface-2)), var(--surface-2)); }
.sim-tag {
  border: 0; background: var(--kc, var(--accent)); color: #fff !important;
  font-family: var(--head); font-size: 12px; font-weight: 700; letter-spacing: 0; text-transform: none;
  padding: 4px 10px; border-radius: 7px;
}
.sim-tag.anim { background: var(--accent-2); }
.sim-tag.predict { background: var(--warn); }
.sim-tag.challenge { background: var(--ok); }
.sim-tag.lab { background: var(--violet); }
.sim-head h3 { font-family: var(--head); font-weight: 700 !important; }

/* 강조 상자: 테두리를 두른 둥근 카드와 한글 라벨 */
.callout { border-left: 0; border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent); border-radius: 16px; }
.callout.tip { border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.callout.warn { border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.callout.deep { border-color: color-mix(in srgb, var(--violet) 30%, transparent); }
.callout.field { border-color: color-mix(in srgb, var(--accent-2) 35%, transparent); }
.callout.field > strong:first-child::before, .callout.deep > strong:first-child::before {
  display: inline-block; margin-right: 8px; padding: 2px 9px; border-radius: 999px;
  font-family: var(--head); font-size: 11.5px; letter-spacing: 0; color: #fff; vertical-align: .1em;
}
.callout.field > strong:first-child::before { content: "현업 노트"; background: var(--accent-2); }
.callout.deep > strong:first-child::before { content: "더 깊이"; background: var(--violet); }

/* 핵심 정리: 번호 원 */
.keypoints { border-radius: var(--radius); border-top: 4px solid var(--accent); }
.keypoints ol { list-style: none; padding-left: 0 !important; counter-reset: kp; }
.keypoints ol li { position: relative; padding-left: 38px; counter-increment: kp; }
.keypoints ol li::before {
  content: counter(kp); position: absolute; left: 0; top: .15em;
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-family: var(--mono); font-size: 13px; font-weight: 700;
}

/* 퀴즈: 보기 글자 */
.quiz-q { border-radius: 16px; }
.opts { counter-reset: opt; }
.opt { counter-increment: opt; display: flex; gap: 10px; align-items: baseline; }
.opt::before {
  content: counter(opt, upper-alpha); flex: none; width: 22px; height: 22px; border-radius: 6px;
  display: inline-grid; place-items: center; font-family: var(--mono); font-size: 12px; font-weight: 700;
  background: var(--surface); color: var(--dim); border: 1px solid var(--border); transform: translateY(1px);
}
.opt.right::before { background: var(--ok); color: #fff; border-color: var(--ok); }
.opt.wrong::before { background: var(--bad); color: #fff; border-color: var(--bad); }

/* 그림·표·이전/다음 카드 모서리 */
figure.diagram, .table-wrap, .formula { border-radius: 16px; }
.chapter-nav a { border-radius: 16px; }
.chapter-nav a .d { font-family: var(--head); font-weight: 700; color: var(--accent); }

/* 홈 */
.hero-sim { border-radius: 22px; border-top: 4px solid var(--accent); }
.num-card { border-radius: 16px; background:
  radial-gradient(circle at 1px 1px, var(--dot) 1px, transparent 0) 0 0 / 16px 16px, var(--surface); }
.num-card .big { font-family: var(--mono); }
.ch-card { border-radius: 16px; }
.ch-card .no { font-family: var(--head); letter-spacing: .02em; }
.drawer h4, .toc h5 { font-family: var(--head); letter-spacing: 0; font-size: 12.5px; color: var(--dim); }
.drawer a .n { font-family: var(--mono); }

/* 면접 포인트 상자: 이 장의 개념을 면접에서 설명할 때 이어야 할 인과 사슬 */
.callout.interview { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 38%, transparent); }
.callout.interview > strong:first-child::before {
  content: "면접 포인트"; display: inline-block; margin-right: 8px; padding: 2px 9px; border-radius: 999px;
  font-family: var(--head); font-size: 11.5px; letter-spacing: 0; color: #fff; background: var(--warn); vertical-align: .1em;
}
.callout.interview ol, .callout.interview ul { margin: 6px 0 0 !important; }

/* 책 표지 캐릭터 그림 */
.hero-art { position: relative; border-radius: 22px; overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow); aspect-ratio: 16 / 9; background: var(--surface-2); }
.hero-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-art .cap { position: absolute; left: 12px; bottom: 10px; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; color: #fff; background: rgba(0, 0, 0, .38); backdrop-filter: blur(4px); }

/* ---------- 시리즈 카드 (홈) ---------- */
.series-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.series-card { display: block; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); transition: border-color .15s, transform .15s; }
a.series-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.series-card img { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: cover; background: var(--surface-2); }
.series-card .t { display: flex; align-items: center; gap: 8px; margin: 12px 16px 4px; font-weight: 750; font-size: 16.5px; letter-spacing: -0.01em; }
.series-card .t .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.series-card .t small { font-size: 12px; font-weight: 600; color: var(--faint); }
.series-card p { margin: 0 16px 16px; font-size: 14px; line-height: 1.6; color: var(--dim); }
.series-card.soon { opacity: .62; }
