:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-soft: #f0f1ee;
  --text: #252b29;
  --muted: #68716d;
  --line: #dfe2de;
  --accent: #e8582c;
  --accent-soft: #fff0e9;
  --navy: #1b2e3a;
  --green: #bddd42;
  --code-bg: #18242a;
  --code-text: #e6eeea;
  --sidebar-width: 318px;
  --header-height: 68px;
  --shadow: 0 18px 55px rgba(33, 42, 38, .13);
  --sans: "Noto Sans KR", system-ui, sans-serif;
  --serif: "Gowun Batang", serif;
  --mono: "JetBrains Mono", Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #101716;
  --surface: #18201f;
  --surface-soft: #212b29;
  --text: #edf3f0;
  --muted: #a2afaa;
  --line: #34413d;
  --accent: #ff7951;
  --accent-soft: #34221d;
  --navy: #dce9e5;
  --code-bg: #080d10;
  --shadow: 0 18px 55px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-height) + 24px); }
body { margin: 0; color: var(--text); background: var(--bg); font-family: var(--sans); line-height: 1.75; transition: color .2s, background .2s; }
button, input { font: inherit; }
a { color: inherit; }
code, kbd { font-family: var(--mono); }
.read-progress { position: fixed; z-index: 120; inset: 0 0 auto; height: 3px; }
.read-progress span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--accent), var(--green)); }

.topbar { position: fixed; z-index: 100; inset: 3px 0 auto; height: var(--header-height); display: flex; align-items: center; padding: 0 24px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(16px); }
.brand { min-width: 0; display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; }
.brand-mark { display: grid; place-items: center; flex: 0 0 auto; width: 38px; height: 38px; border-radius: 11px; color: #fff; background: var(--accent); font: 800 .8rem var(--mono); box-shadow: inset 0 -3px rgba(0,0,0,.12); }
.brand-copy { min-width: 0; display: grid; line-height: 1.25; }
.brand-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }
.brand-copy small { color: var(--muted); font-size: .68rem; }
.topbar-actions { display: flex; align-items: center; gap: 9px; margin-left: auto; }
.search-button, .source-button, .theme-button, .menu-button { border: 1px solid var(--line); color: var(--text); background: var(--surface); cursor: pointer; }
.search-button { display: flex; align-items: center; gap: 9px; min-width: 220px; padding: 8px 10px; border-radius: 9px; color: var(--muted); text-align: left; }
.search-button span:first-child { color: var(--text); font-size: 1.1rem; }
.search-button kbd { margin-left: auto; padding: 2px 6px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface-soft); font-size: .62rem; }
.source-button { padding: 8px 12px; border-radius: 9px; font-size: .76rem; font-weight: 700; text-decoration: none; }
.theme-button, .menu-button { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; }
.menu-button { display: none; margin-right: 10px; }

.app-shell { padding-top: calc(var(--header-height) + 3px); }
.sidebar { position: fixed; z-index: 80; top: calc(var(--header-height) + 3px); bottom: 0; left: 0; width: var(--sidebar-width); overflow-y: auto; border-right: 1px solid var(--line); background: var(--surface); scrollbar-width: thin; }
.sidebar-head { position: sticky; z-index: 2; top: 0; display: flex; justify-content: space-between; align-items: baseline; padding: 22px 22px 16px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(10px); }
.sidebar-head p { margin: 0; color: var(--muted); font: 600 .64rem var(--mono); letter-spacing: .12em; }
.sidebar-head strong { color: var(--accent); font-size: .7rem; }
#book-toc { padding: 12px 11px 90px; }
.toc-home, .toc-page, .toc-group-title { display: flex; align-items: flex-start; gap: 8px; width: 100%; border-radius: 7px; color: var(--muted); text-decoration: none; line-height: 1.45; }
.toc-home { margin-bottom: 12px; padding: 10px 11px; color: var(--text); background: var(--surface-soft); font-size: .84rem; font-weight: 700; }
.toc-group { margin: 4px 0; }
.toc-group-title { padding: 10px 11px 8px; color: var(--text); font-size: .79rem; font-weight: 800; }
.toc-group-title::before { content: "◆"; margin-top: 2px; color: var(--accent); font-size: .55rem; }
.toc-group-pages { display: grid; padding: 0 0 8px 12px; }
.toc-page { position: relative; padding: 6px 11px 6px 18px; font-size: .76rem; }
.toc-page::before { content: ""; position: absolute; top: 13px; left: 5px; width: 4px; height: 4px; border-radius: 50%; background: var(--line); }
.toc-page:hover { color: var(--text); background: var(--surface-soft); }
.toc-home.active, .toc-page.active, .toc-group-title.active { color: var(--accent); background: var(--accent-soft); }
.toc-page.visited::after { content: "✓"; margin-left: auto; color: #77a327; font-size: .65rem; }
.sidebar-footer { position: absolute; right: 0; bottom: 0; left: 0; display: flex; justify-content: space-between; padding: 13px 20px; border-top: 1px solid var(--line); color: var(--muted); background: var(--surface); font-size: .66rem; }
.sidebar-footer a { color: var(--accent); }
.sidebar-scrim { display: none; }

.reader { min-height: calc(100vh - var(--header-height)); margin-left: var(--sidebar-width); }
.reader-toolbar { position: sticky; z-index: 55; top: calc(var(--header-height) + 3px); display: flex; justify-content: space-between; align-items: center; min-height: 52px; padding: 9px clamp(24px, 4vw, 58px); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); }
.breadcrumbs { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted); font-size: .72rem; }
.breadcrumbs span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breadcrumbs span + span::before { content: "/"; margin-right: 8px; color: var(--line); }
.page-tools { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; margin-left: 15px; }
.page-tools a, .page-tools button { padding: 6px 9px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; font-size: .7rem; text-decoration: none; cursor: pointer; }
.page-tools a:hover, .page-tools button:hover { color: var(--text); background: var(--surface-soft); }
#content-toc-toggle { display: none; }
.reader-grid { display: grid; grid-template-columns: minmax(0, 860px) 190px; justify-content: center; gap: 54px; padding: 68px clamp(24px, 4vw, 58px) 30px; }
.book-page { min-width: 0; font-size: .97rem; }
.loading { display: grid; place-items: center; min-height: 50vh; color: var(--muted); }
.loading span { width: 38px; height: 38px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-hero { margin-bottom: 48px; padding-bottom: 30px; border-bottom: 1px solid var(--line); }
.page-kicker { margin: 0 0 13px; color: var(--accent); font: 600 .7rem var(--mono); letter-spacing: .12em; }
.page-hero h1 { margin: 0; font: 700 clamp(2.3rem, 5vw, 4.25rem)/1.18 var(--serif); letter-spacing: -.055em; word-break: keep-all; }
.page-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 20px; color: var(--muted); font-size: .72rem; }
.page-meta a { color: var(--accent); }
.book-page > h1:first-child { display: none; }
.book-page h2 { margin: 62px 0 20px; padding-bottom: 12px; border-bottom: 1px solid var(--line); font: 700 2rem/1.35 var(--serif); letter-spacing: -.035em; }
.book-page h3 { margin: 43px 0 15px; font-size: 1.35rem; line-height: 1.45; letter-spacing: -.025em; }
.book-page h4 { margin: 32px 0 12px; font-size: 1.05rem; }
.book-page p { margin: 13px 0; color: var(--muted); }
.book-page strong { color: var(--text); }
.book-page a { color: #337ab7; text-underline-offset: 3px; }
[data-theme="dark"] .book-page a { color: #7cb8ec; }
.book-page ul, .book-page ol { margin: 14px 0; padding-left: 25px; color: var(--muted); }
.book-page li { margin: 7px 0; }
.book-page li::marker { color: var(--accent); }
.book-page hr { margin: 48px 0; border: 0; border-top: 1px solid var(--line); }
.book-page code { padding: .13em .38em; border: 1px solid var(--line); border-radius: 5px; color: var(--accent); background: var(--surface-soft); font-size: .86em; }
.book-page pre { position: relative; overflow-x: auto; margin: 22px 0; padding: 25px 70px 25px 24px; border-radius: 11px; color: var(--code-text); background: var(--code-bg); box-shadow: var(--shadow); line-height: 1.7; white-space: pre; }
.book-page pre code { padding: 0; border: 0; color: inherit; background: none; font-size: .82rem; }
.codehilite, .code-wrap { position: relative; }
.copy-code { position: absolute; z-index: 3; top: 31px; right: 10px; padding: 5px 8px; border: 1px solid rgba(255,255,255,.16); border-radius: 5px; color: #cbd6d2; background: rgba(255,255,255,.07); font-size: .66rem; cursor: pointer; }
.copy-code:hover { color: #fff; }
.book-page blockquote { margin: 24px 0; padding: 17px 20px; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 0 9px 9px 0; background: var(--surface); }
.book-page blockquote p:first-child { margin-top: 0; }
.book-page blockquote p:last-child { margin-bottom: 0; }
.book-page img { display: block; max-width: 100%; height: auto; margin: 26px auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: zoom-in; box-shadow: 0 8px 26px rgba(34,42,38,.07); }
.table-scroll-wrapper { overflow-x: auto; margin: 24px 0; border: 1px solid var(--line); border-radius: 10px; }
.book-page table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .84rem; line-height: 1.55; }
.book-page th, .book-page td { min-width: 130px; padding: 13px 15px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.book-page th:last-child, .book-page td:last-child { border-right: 0; }
.book-page tr:last-child td { border-bottom: 0; }
.book-page th { color: var(--text); background: var(--surface-soft); font-weight: 700; }
.book-page .admonition { margin: 22px 0; padding: 17px 20px; border-left: 4px solid #4c91d0; border-radius: 8px; background: var(--surface-soft); }
.book-page .admonition-title { margin-top: 0; color: var(--text); font-weight: 700; }
.book-page mjx-container { display: inline-block !important; max-width: 100% !important; overflow-x: auto; overflow-y: hidden; vertical-align: middle; }
.book-page mjx-container[display="true"] { display: block !important; width: 100% !important; }
.book-page mjx-assistive-mml { display: none !important; }

.page-toc { position: sticky; top: calc(var(--header-height) + 82px); align-self: start; max-height: calc(100vh - 120px); overflow-y: auto; color: var(--muted); font-size: .7rem; }
.page-toc > p { margin: 0 0 12px; font: 600 .62rem var(--mono); letter-spacing: .13em; }
.page-toc nav { display: grid; border-left: 1px solid var(--line); }
.page-toc a { padding: 5px 0 5px 12px; text-decoration: none; line-height: 1.45; }
.page-toc a.level-3 { padding-left: 24px; }
.page-toc a:hover { color: var(--text); }
.page-toc a.active { margin-left: -1px; border-left: 2px solid var(--accent); color: var(--accent); font-weight: 700; }
.page-navigation { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: min(1104px, calc(100% - 48px)); margin: 55px auto 0; }
.page-navigation a { display: grid; min-height: 112px; padding: 20px 22px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-decoration: none; }
.page-navigation a:last-child { text-align: right; }
.page-navigation a.disabled { visibility: hidden; }
.page-navigation span { color: var(--muted); font-size: .68rem; }
.page-navigation strong { margin-top: 7px; font-size: .9rem; }
.reader-footer { width: min(1104px, calc(100% - 48px)); margin: 60px auto 0; padding: 38px 0 70px; border-top: 1px solid var(--line); color: var(--muted); font-size: .72rem; text-align: center; }
.reader-footer p { margin: 4px; }
.reader-footer a { color: var(--accent); }

.search-dialog { width: min(680px, calc(100% - 24px)); max-height: min(720px, calc(100vh - 50px)); padding: 0; border: 1px solid var(--line); border-radius: 15px; color: var(--text); background: var(--surface); box-shadow: 0 35px 100px rgba(0,0,0,.3); }
.search-dialog::backdrop, .image-dialog::backdrop { background: rgba(10,17,15,.55); backdrop-filter: blur(5px); }
.search-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.search-head > span { color: var(--accent); font-size: 1.45rem; }
.search-head input { flex: 1; min-width: 0; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 1rem; }
.search-head button { padding: 4px 7px; border: 1px solid var(--line); border-radius: 5px; color: var(--muted); background: var(--surface-soft); font: .62rem var(--mono); cursor: pointer; }
.search-meta { display: flex; justify-content: space-between; gap: 10px; padding: 9px 18px; color: var(--muted); background: var(--surface-soft); font-size: .66rem; }
.search-meta kbd { font-size: .6rem; }
.search-results { max-height: 540px; overflow-y: auto; padding: 7px; }
.search-result { display: grid; gap: 4px; padding: 12px 13px; border-radius: 8px; color: var(--text); text-decoration: none; }
.search-result:hover, .search-result.selected { background: var(--accent-soft); }
.search-result small { color: var(--accent); font: .62rem var(--mono); }
.search-result strong { font-size: .86rem; }
.search-result p { overflow: hidden; margin: 0; color: var(--muted); font-size: .72rem; white-space: nowrap; text-overflow: ellipsis; }
.empty-search { padding: 60px 20px; color: var(--muted); text-align: center; }
.image-dialog { width: min(94vw, 1500px); height: min(92vh, 1000px); padding: 45px 18px 18px; border: 0; border-radius: 12px; background: #101514; }
.image-dialog img { width: 100%; height: 100%; object-fit: contain; }
.image-dialog button { position: absolute; top: 9px; right: 12px; width: 34px; height: 34px; border: 0; border-radius: 50%; color: #fff; background: rgba(255,255,255,.12); font-size: 1.35rem; cursor: pointer; }
.top-button { position: fixed; z-index: 60; right: 24px; bottom: 24px; width: 44px; height: 44px; border: 0; border-radius: 50%; color: #fff; background: var(--accent); box-shadow: var(--shadow); cursor: pointer; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s; }
.top-button.visible { opacity: 1; transform: none; pointer-events: auto; }
.toast { position: fixed; z-index: 130; left: 50%; bottom: 26px; padding: 9px 16px; border-radius: 999px; color: #fff; background: #17201e; font-size: .72rem; box-shadow: var(--shadow); opacity: 0; transform: translate(-50%, 10px); pointer-events: none; transition: .2s; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* 2026 evidence-based edition */
.edition-hero { margin: 0 0 64px; padding: clamp(26px, 5vw, 52px); border: 1px solid color-mix(in srgb, var(--accent) 34%, var(--line)); border-radius: 20px; background: linear-gradient(145deg, var(--accent-soft), var(--surface) 54%, color-mix(in srgb, var(--green) 14%, var(--surface))); box-shadow: var(--shadow); }
.edition-eyebrow { margin: 0 0 10px !important; color: var(--accent); font: 700 .66rem var(--mono); letter-spacing: .16em; }
.edition-hero h2 { margin: 0 0 16px !important; font-size: clamp(1.65rem, 3vw, 2.55rem) !important; line-height: 1.25; }
.edition-promise { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; overflow: hidden; margin: 26px 0; border: 1px solid var(--line); border-radius: 12px; background: var(--line); }
.edition-promise div { display: grid; gap: 5px; padding: 18px; background: var(--surface); }
.edition-promise strong { color: var(--accent); font-size: .78rem; }
.edition-promise span { color: var(--muted); font-size: .76rem; }
.edition-callout, .evidence-note, .boundary { margin: 0 0 32px; padding: 18px 20px; border-left: 4px solid var(--accent); border-radius: 0 10px 10px 0; background: var(--accent-soft); }
.edition-callout strong { display: block; margin-bottom: 5px; color: var(--accent); font: 700 .68rem var(--mono); letter-spacing: .08em; }
.edition-callout p, .evidence-note p { margin: 0; }
.boundary { border-left-color: #8a6f42; background: color-mix(in srgb, #c7a564 15%, var(--surface)); }
.decision-grid, .metric-grid, .research-cards, .task-canvas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 24px 0 36px; }
.decision-grid article, .metric-grid article, .research-cards article, .task-canvas article { padding: 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.decision-grid article > span { color: var(--accent); font: 700 .72rem var(--mono); }
.decision-grid h2, .decision-grid h3, .metric-grid h3, .research-cards h3, .task-canvas h3 { margin: 4px 0 8px !important; font-size: 1rem !important; }
.decision-grid p, .metric-grid p, .research-cards p, .task-canvas p { margin: 0; color: var(--muted); font-size: .84rem; }
.comparison-table { overflow-x: auto; margin: 22px 0 36px; border: 1px solid var(--line); border-radius: 12px; }
.comparison-table table { margin: 0; border: 0; }
.comparison-table th, .comparison-table td { border-right: 0; border-left: 0; }
.steps { display: grid; gap: 10px; padding: 0; list-style: none; counter-reset: steps; }
.steps li { position: relative; padding: 16px 18px 16px 54px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); counter-increment: steps; }
.steps li::before { content: counter(steps, decimal-leading-zero); position: absolute; top: 16px; left: 17px; color: var(--accent); font: 700 .7rem var(--mono); }
.steps p { margin: 3px 0 0; color: var(--muted); }
.layer-stack { display: grid; gap: 0; margin: 24px 0 38px; border: 1px solid var(--line); border-radius: 12px; }
.layer-stack article { display: grid; grid-template-columns: 130px 1fr; gap: 18px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.layer-stack article:last-child { border: 0; }
.layer-stack strong { color: var(--accent); }
.layer-stack p { margin: 0; }
.checklist { display: grid; gap: 9px; padding: 0; list-style: none; }
.checklist li { position: relative; padding: 11px 14px 11px 38px; border-radius: 8px; background: var(--surface-soft); }
.checklist li::before { content: "✓"; position: absolute; left: 14px; color: #6e9528; font-weight: 800; }
.evidence-level { display: inline-flex; margin-bottom: 9px; padding: 3px 8px; border-radius: 999px; color: var(--accent); background: var(--accent-soft); font: 700 .62rem var(--mono); }
.decision-tool { margin: 28px 0; padding: 22px 24px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-soft); }
.decision-tool h3 { margin-top: 0; }
.timeline { display: grid; gap: 18px; margin: 24px 0 42px; }
.timeline article { position: relative; padding: 24px 24px 24px 112px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.timeline article > span { position: absolute; top: 25px; left: 22px; color: var(--accent); font: 700 .75rem var(--mono); }
.timeline h2 { margin: 0 0 10px !important; font-size: 1.2rem !important; }
.timeline ul { margin-bottom: 0; }
.source-notes { margin-top: 56px; padding-top: 22px; border-top: 1px solid var(--line); }
.source-notes h2 { margin-top: 0 !important; font-size: 1rem !important; }
.source-notes li { margin: 5px 0; font-size: .78rem; }

@media (max-width: 1180px) {
  :root { --sidebar-width: 286px; }
  .reader-grid { grid-template-columns: minmax(0, 820px); }
  .page-toc { display: none; position: fixed; z-index: 70; top: calc(var(--header-height) + 62px); right: 18px; width: 240px; max-height: calc(100vh - 100px); padding: 18px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
  .page-toc.open { display: block; }
  #content-toc-toggle { display: inline-block; }
}

@media (max-width: 840px) {
  .menu-button { display: grid; }
  .sidebar { transform: translateX(-102%); transition: transform .25s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .sidebar-scrim { position: fixed; z-index: 75; inset: calc(var(--header-height) + 3px) 0 0; background: rgba(6,12,10,.45); }
  .sidebar-scrim.open { display: block; }
  .reader { margin-left: 0; }
  .search-button { min-width: auto; }
  .search-button span:nth-child(2), .search-button kbd { display: none; }
  .brand-copy small { display: none; }
}

@media (max-width: 600px) {
  :root { --header-height: 60px; }
  .topbar { padding: 0 13px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-copy strong { max-width: 170px; font-size: .76rem; }
  .source-button { display: none; }
  .reader-toolbar { padding: 8px 16px; }
  .breadcrumbs span:first-child { display: none; }
  .page-tools a { display: none; }
  .reader-grid { padding: 46px 18px 20px; }
  .page-hero { margin-bottom: 35px; }
  .page-hero h1 { font-size: 2.35rem; }
  .book-page { font-size: .92rem; }
  .book-page h2 { margin-top: 48px; font-size: 1.6rem; }
  .book-page h3 { font-size: 1.16rem; }
  .book-page pre { margin-right: -6px; margin-left: -6px; padding: 48px 18px 20px; border-radius: 8px; }
  .copy-code { top: 9px; }
  .book-page th, .book-page td { min-width: 160px; padding: 11px 12px; }
  .page-navigation { grid-template-columns: 1fr; width: calc(100% - 36px); }
  .page-navigation a:last-child { text-align: left; }
  .reader-footer { width: calc(100% - 36px); }
  .search-meta kbd { display: none; }
  .top-button { right: 17px; bottom: 17px; }
  .edition-promise, .decision-grid, .metric-grid, .research-cards, .task-canvas { grid-template-columns: 1fr; }
  .layer-stack article { grid-template-columns: 1fr; gap: 4px; }
  .timeline article { padding: 58px 18px 20px; }
  .timeline article > span { top: 20px; left: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
