/* Copyright (c) 2026 geniuskey and BodyBook contributors.
   SPDX-License-Identifier: MIT — see ../LICENSE-MIT. */
/* ==========================================================================
   BodyBook — 몸의 원리 공통 스타일
   ========================================================================== */
@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css");
@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&display=swap");

:root {
  --bg: #f8f7f7;
  --bg-elev: #ffffff;
  --surface: #eef1f7;
  --surface-2: #e3e8f2;
  --border: #d6dce8;
  --text: #141a26;
  --text-dim: #566178;
  --text-faint: #8a93a8;
  --accent: #be123c;
  --accent-soft: rgba(190, 18, 60, 0.09);
  --accent-2: #1971c2;
  --accent-2-soft: rgba(25, 113, 194, 0.10);
  --ok: #1f9d55;
  --warn: #d08700;
  --bad: #e8590c;
  --red: #e0443e;
  --green: #2da44e;
  --blue: #2f6fe0;
  --grid: rgba(20, 26, 38, 0.08);
  --axis: rgba(20, 26, 38, 0.45);
  --canvas-bg: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 20px rgba(16, 24, 40, 0.06);
  --radius: 14px;
  --radius-sm: 8px;
  --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, monospace;
  --maxw: 880px;
  --nav-h: 58px;
  --on-accent: #ffffff;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17;
    --bg-elev: #121826;
    --surface: #171f30;
    --surface-2: #1e283c;
    --border: #273248;
    --text: #e6ebf5;
    --text-dim: #9aa6bf;
    --text-faint: #69748c;
    --accent: #fb7185;
    --accent-soft: rgba(251, 113, 133, 0.15);
    --accent-2: #74c0fc;
    --accent-2-soft: rgba(116, 192, 252, 0.14);
    --ok: #3fcf7f;
    --warn: #f5b93a;
    --bad: #ff8a4c;
    --red: #ff5f57;
    --green: #3fcf6f;
    --blue: #5b8cff;
    --grid: rgba(230, 235, 245, 0.08);
    --axis: rgba(230, 235, 245, 0.45);
    --canvas-bg: #0f1522;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.35);
    --on-accent: #2a0610;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f17;
  --bg-elev: #121826;
  --surface: #171f30;
  --surface-2: #1e283c;
  --border: #273248;
  --text: #e6ebf5;
  --text-dim: #9aa6bf;
  --text-faint: #69748c;
  --accent: #fb7185;
  --accent-soft: rgba(251, 113, 133, 0.15);
  --accent-2: #74c0fc;
  --accent-2-soft: rgba(116, 192, 252, 0.14);
  --ok: #3fcf7f;
  --warn: #f5b93a;
  --bad: #ff8a4c;
  --red: #ff5f57;
  --green: #3fcf6f;
  --blue: #5b8cff;
  --grid: rgba(230, 235, 245, 0.08);
  --axis: rgba(230, 235, 245, 0.45);
  --canvas-bg: #0f1522;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.35);
  --on-accent: #2a0610;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--nav-h) + 16px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.75;
  word-break: keep-all;
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}
img, svg, canvas, video { max-width: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd { font-family: var(--mono); font-size: 0.88em; background: var(--surface); padding: 0.1em 0.4em; border-radius: 5px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 48px 0; }
::selection { background: var(--accent-soft); }

/* ------------------------------------------------------------------ Top bar */
.bb-topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--nav-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.bb-logo { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--text); letter-spacing: -0.02em; font-size: 18px; white-space: nowrap; }
.bb-logo:hover { text-decoration: none; }
.bb-logo .mark { width: 28px; height: 28px; flex: none; }
.bb-logo small { font-weight: 500; color: var(--text-dim); font-size: 13px; }
.bb-topbar .spacer { flex: 1; }
.bb-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
  font: inherit; font-size: 14px; cursor: pointer;
}
.bb-btn:hover { border-color: var(--accent); }
.bb-btn.icon { width: 36px; padding: 0; }
.bb-progress { position: absolute; left: 0; bottom: -1px; height: 2px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); width: 0; }

/* Drawer (chapter list) */
.bb-drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 60; opacity: 0; pointer-events: none; transition: opacity .2s; }
.bb-drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: min(340px, 88vw); z-index: 61;
  background: var(--bg-elev); border-right: 1px solid var(--border);
  transform: translateX(-102%); transition: transform .25s ease;
  overflow-y: auto; padding: 20px 14px 40px;
}
body.drawer-open .bb-drawer { transform: none; }
body.drawer-open .bb-drawer-backdrop { opacity: 1; pointer-events: auto; }
.bb-drawer h4 { margin: 8px 10px 10px; font-size: 12px; letter-spacing: .12em; color: var(--text-faint); text-transform: uppercase; }
.bb-chlist { list-style: none; margin: 0; padding: 0; }
.bb-chlist a { display: flex; gap: 12px; align-items: baseline; padding: 9px 10px; border-radius: 10px; color: var(--text); line-height: 1.4; }
.bb-chlist a:hover { background: var(--surface); text-decoration: none; }
.bb-chlist a.active { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.bb-chlist .num { font-family: var(--mono); font-size: 12px; color: var(--text-faint); width: 22px; flex: none; }
.bb-chlist a.active .num { color: var(--accent); }

/* ------------------------------------------------------------------ Layout */
.bb-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 40px; max-width: 1240px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 1180px) {
  .bb-layout { grid-template-columns: minmax(0, 1fr) 230px; }
}
.bb-toc { display: none; }
@media (min-width: 1180px) {
  .bb-toc { display: block; position: sticky; top: calc(var(--nav-h) + 28px); align-self: start; max-height: calc(100vh - var(--nav-h) - 56px); overflow-y: auto; padding-top: 48px; font-size: 13.5px; }
  .bb-toc h4 { margin: 0 0 10px; font-size: 11px; letter-spacing: .14em; color: var(--text-faint); }
  .bb-toc a { display: block; padding: 5px 0 5px 12px; border-left: 2px solid var(--border); color: var(--text-dim); line-height: 1.45; }
  .bb-toc a:hover { color: var(--text); text-decoration: none; }
  .bb-toc a.active { border-left-color: var(--accent); color: var(--accent); font-weight: 600; }
}

main.chapter { max-width: var(--maxw); width: 100%; margin: 0 auto; padding: 40px 0 80px; min-width: 0; }
main.chapter > section { margin: 64px 0; }
main.chapter h2 { font-size: 28px; line-height: 1.35; letter-spacing: -0.02em; margin: 0 0 18px; padding-top: 8px; }
main.chapter h2 .h-num { font-family: var(--mono); color: var(--accent); font-size: 0.7em; margin-right: 10px; vertical-align: 0.12em; }
main.chapter h3 { font-size: 20px; margin: 36px 0 12px; letter-spacing: -0.01em; }
main.chapter p { margin: 0 0 16px; }
main.chapter ul, main.chapter ol { padding-left: 1.3em; margin: 0 0 16px; }
main.chapter li { margin: 4px 0; }
strong { font-weight: 700; }
.term { font-weight: 700; color: var(--accent); }
.en { color: var(--text-dim); font-size: 0.9em; }

/* Chapter hero */
.chapter-hero { padding: 24px 0 8px; }
.eyebrow { font-family: var(--mono); font-size: 13px; letter-spacing: .16em; color: var(--accent); font-weight: 600; text-transform: uppercase; }
.chapter-hero h1 { font-size: clamp(32px, 5.4vw, 46px); line-height: 1.2; letter-spacing: -0.03em; margin: 10px 0 16px; }
.lead { font-size: 19px; color: var(--text-dim); line-height: 1.7; }
.objectives { list-style: none; padding: 18px 20px !important; margin: 24px 0 0 !important; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); display: grid; gap: 6px; }
.objectives::before { content: "이 장에서 배우는 것"; display: block; font-size: 12px; letter-spacing: .1em; color: var(--text-faint); font-weight: 700; margin-bottom: 4px; }
.objectives li { padding-left: 26px; position: relative; margin: 0 !important; }
.objectives li::before { content: ""; position: absolute; left: 4px; top: 0.62em; width: 10px; height: 10px; border-radius: 3px; background: var(--accent); opacity: .85; }

/* ------------------------------------------------------------------ Figures */
figure { margin: 28px 0; }
figure.diagram { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
figure.diagram svg { display: block; width: 100%; height: auto; }
figcaption { font-size: 14px; color: var(--text-dim); margin-top: 12px; line-height: 1.6; }
figcaption b { color: var(--text); }
.fig-row { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* SVG helpers usable inside inline diagrams */
svg .t { fill: var(--text); font-family: var(--font); font-size: 13px; }
svg .t-dim { fill: var(--text-dim); font-family: var(--font); font-size: 12px; }
svg .t-mono { fill: var(--text-dim); font-family: var(--mono); font-size: 11px; }
svg .t-acc { fill: var(--accent); font-family: var(--font); font-size: 13px; font-weight: 700; }
svg .s-line { stroke: var(--text-dim); fill: none; stroke-width: 1.5; }
svg .s-axis { stroke: var(--axis); fill: none; stroke-width: 1.2; }
svg .s-acc { stroke: var(--accent); fill: none; stroke-width: 2; }
svg .f-surface { fill: var(--surface); stroke: var(--border); }
svg .f-elev { fill: var(--bg-elev); stroke: var(--border); }
svg .f-acc { fill: var(--accent); }
svg .f-acc-soft { fill: var(--accent-soft); stroke: var(--accent); }
svg .f-acc2-soft { fill: var(--accent-2-soft); stroke: var(--accent-2); }

/* ------------------------------------------------------------------ Simulator card */
.sim {
  margin: 32px 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.sim-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--border); background: linear-gradient(90deg, var(--accent-soft), transparent 70%); }
.sim-tag { font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .12em; color: var(--accent); border: 1px solid var(--accent); border-radius: 999px; padding: 2px 9px; line-height: 1.6; }
.sim-tag.three { color: var(--accent-2); border-color: var(--accent-2); }
.sim-head h3 { margin: 0 !important; font-size: 17px !important; flex: 1; min-width: 180px; }
.sim-body { display: grid; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 820px) {
  .sim-body.side { grid-template-columns: minmax(0, 1fr) 280px; }
  .sim-body.side .sim-controls { border-top: 0; border-left: 1px solid var(--border); }
}
.sim-view { position: relative; background: var(--canvas-bg); min-height: 120px; }
.sim-view canvas { display: block; width: 100%; }
.sim-view.three { height: 440px; cursor: grab; touch-action: none; }
.sim-view.three:active { cursor: grabbing; }
.sim-view .hint { position: absolute; right: 10px; bottom: 8px; font-size: 12px; color: var(--text-faint); pointer-events: none; background: color-mix(in srgb, var(--canvas-bg) 70%, transparent); padding: 2px 8px; border-radius: 6px; }
.overlay-label { position: absolute; pointer-events: none; font-size: 12px; font-weight: 600; color: var(--text); background: color-mix(in srgb, var(--bg-elev) 85%, transparent); border: 1px solid var(--border); padding: 2px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -50%); }
.sim-controls { padding: 16px 18px; border-top: 1px solid var(--border); display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); align-content: start; }
.sim-body.side .sim-controls { grid-template-columns: 1fr; }
.ctrl { display: grid; gap: 6px; font-size: 14px; }
.ctrl > span { display: block; color: var(--text-dim); }
.ctrl > span::after { content: ""; display: table; clear: both; }
.ctrl > span > output { float: right; margin-left: 8px; }
.ctrl output { font-family: var(--mono); color: var(--text); font-weight: 600; font-size: 13px; }
.ctrl select { font: inherit; font-size: 14px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.ctrl-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { font: inherit; font-size: 13px; border: 0; background: transparent; color: var(--text-dim); padding: 5px 11px; border-radius: 7px; cursor: pointer; }
.seg button.on, .seg button[aria-pressed="true"] { background: var(--bg-elev); color: var(--accent); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.btn { font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--text-dim); cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 5px; border-radius: 3px; background: linear-gradient(90deg, var(--accent) var(--fill, 50%), var(--surface-2) var(--fill, 50%)); }
input[type="range"]::-moz-range-track { height: 5px; border-radius: 3px; background: var(--surface-2); }
input[type="range"]::-moz-range-progress { height: 5px; border-radius: 3px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--bg-elev); border: 2px solid var(--accent); margin-top: -6.5px; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--bg-elev); border: 2px solid var(--accent); }

.sim-readout { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1px; background: var(--border); border-top: 1px solid var(--border); }
.stat { background: var(--bg-elev); padding: 12px 16px; display: grid; gap: 2px; }
.stat .k { font-size: 12px; color: var(--text-dim); }
.stat .v { font-family: var(--mono); font-size: 18px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 12px; color: var(--text-dim); font-weight: 400; margin-left: 2px; }
.sim-note { padding: 12px 18px; font-size: 14px; color: var(--text-dim); border-top: 1px solid var(--border); background: var(--surface); line-height: 1.6; }

/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text-dim); padding: 10px 18px 0; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

/* ------------------------------------------------------------------ Callouts & formula */
.callout { margin: 24px 0; padding: 16px 18px 16px 20px; border-radius: var(--radius-sm); background: var(--accent-soft); border-left: 4px solid var(--accent); font-size: 16px; }
.callout > strong:first-child { display: block; margin-bottom: 4px; }
.callout p:last-child { margin-bottom: 0; }
.callout.tip { background: color-mix(in srgb, var(--ok) 12%, transparent); border-left-color: var(--ok); }
.callout.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); border-left-color: var(--warn); }
.callout.deep { background: var(--accent-2-soft); border-left-color: var(--accent-2); }
.callout.deep > strong:first-child::before { content: "심화 · "; color: var(--accent-2); }

.formula { margin: 22px 0; padding: 14px 18px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow-x: auto; }
.formula .where { font-size: 14px; color: var(--text-dim); margin-top: 6px; }
.katex { font-size: 1.08em; }
.katex-display { margin: 0.4em 0 !important; overflow-x: auto; overflow-y: hidden; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 22px 0; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface); font-weight: 700; font-size: 14px; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Key points summary */
.keypoints { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 22px; }
.keypoints h2 { font-size: 22px !important; }
.keypoints ol { counter-reset: kp; list-style: none; padding: 0 !important; }
.keypoints li { counter-increment: kp; position: relative; padding-left: 38px; margin: 10px 0 !important; }
.keypoints li::before { content: counter(kp); position: absolute; left: 0; top: 0.1em; width: 26px; height: 26px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 14px; display: grid; place-items: center; font-family: var(--mono); }

/* ------------------------------------------------------------------ Quiz */
.quiz { display: grid; gap: 16px; }
.quiz-q { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.quiz-q > p:first-child { font-weight: 700; margin-bottom: 12px; }
.quiz-q .opts { display: grid; gap: 8px; }
.quiz-q button.opt { text-align: left; font: inherit; font-size: 15px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; line-height: 1.5; }
.quiz-q button.opt:hover:not(:disabled) { border-color: var(--accent); }
.quiz-q button.opt.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); font-weight: 600; }
.quiz-q button.opt.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.quiz-q button.opt:disabled { cursor: default; }
.quiz-exp { display: none; margin-top: 12px; font-size: 15px; color: var(--text-dim); padding: 10px 14px; border-radius: 8px; background: var(--surface); }
.quiz-q.done .quiz-exp { display: block; }

/* ------------------------------------------------------------------ Prev / Next */
.bb-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: var(--maxw); margin: 0 auto; padding: 0 0 20px; }
.bb-pager a { display: block; padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); color: var(--text); }
.bb-pager a:hover { border-color: var(--accent); text-decoration: none; }
.bb-pager small { display: block; color: var(--text-faint); font-size: 12px; }
.bb-pager .next { text-align: right; grid-column: 2; }
.bb-foot { border-top: 1px solid var(--border); color: var(--text-faint); font-size: 13px; padding: 28px 16px 40px; text-align: center; }

/* ------------------------------------------------------------------ Home page */
.home-hero { position: relative; overflow: hidden; border-bottom: 1px solid var(--border); }
.home-hero .inner { max-width: 1180px; margin: 0 auto; padding: 72px 16px 64px; display: grid; gap: 40px; align-items: center; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) { .home-hero .inner { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); } }
.home-hero h1 { font-size: clamp(36px, 6.4vw, 62px); line-height: 1.12; letter-spacing: -0.035em; margin: 14px 0 20px; }
.home-hero h1 .grad { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.home-hero p { font-size: 19px; color: var(--text-dim); max-width: 560px; }
.home-hero .cta { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 28px; }
.home-hero .cta a { padding: 12px 20px; border-radius: 12px; font-weight: 700; }
.home-hero .cta a.primary { background: var(--accent); color: var(--on-accent); }
.home-hero .cta a.ghost { border: 1px solid var(--border); color: var(--text); background: var(--bg-elev); }
.home-hero .cta a:hover { text-decoration: none; filter: brightness(1.05); }
.hero-3d { height: 420px; border-radius: 20px; border: 1px solid var(--border); background: radial-gradient(ellipse at 50% 40%, var(--accent-soft), transparent 70%), var(--bg-elev); position: relative; overflow: hidden; box-shadow: var(--shadow); touch-action: none; }
.hero-3d .hint { position: absolute; left: 14px; bottom: 10px; font-size: 12px; color: var(--text-faint); }
.home-section { max-width: 1180px; margin: 0 auto; padding: 64px 16px; }
.home-section h2 { font-size: 30px; letter-spacing: -0.02em; margin: 0 0 8px; }
.home-section > p.sub { color: var(--text-dim); margin: 0 0 32px; }
.ch-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.ch-card { display: flex; flex-direction: column; gap: 8px; padding: 20px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); transition: transform .15s, border-color .15s; min-height: 190px; }
.ch-card:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-2px); }
.ch-card .num { font-family: var(--mono); font-size: 12px; color: var(--accent); font-weight: 600; letter-spacing: .1em; }
.ch-card h3 { margin: 0; font-size: 19px; letter-spacing: -0.01em; }
.ch-card p { margin: 0; color: var(--text-dim); font-size: 14.5px; line-height: 1.6; flex: 1; }
.ch-card .tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.ch-card .tags span { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface); color: var(--text-dim); }
.ch-card .tags span.sim { background: var(--accent-soft); color: var(--accent); margin: 0; border: 0; box-shadow: none; overflow: visible; }
.ch-card .tags span.d3 { background: var(--accent-2-soft); color: var(--accent-2); }
.flow { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); counter-reset: fl; }
.flow div { counter-increment: fl; padding: 16px; border-radius: 12px; background: var(--bg-elev); border: 1px solid var(--border); font-size: 14.5px; color: var(--text-dim); position: relative; }
.flow div b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }
.flow div::before { content: counter(fl, decimal-leading-zero); font-family: var(--mono); font-size: 12px; color: var(--accent); font-weight: 700; display: block; margin-bottom: 6px; }

/* Glossary */
.gl-search { width: 100%; font: inherit; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); margin-bottom: 20px; }
.gl-list { display: grid; gap: 10px; }
.gl-item { padding: 14px 18px; border-radius: 12px; background: var(--bg-elev); border: 1px solid var(--border); }
.gl-item h4 { margin: 0 0 4px; font-size: 16px; }
.gl-item h4 .en { font-weight: 500; margin-left: 6px; }
.gl-item p { margin: 0 !important; font-size: 15px; color: var(--text-dim); }
.gl-item .ch { font-size: 12px; margin-top: 6px; display: inline-block; }

@media (max-width: 640px) {
  body { font-size: 16px; }
  main.chapter { padding-top: 24px; }
  main.chapter h2 { font-size: 24px; }
  .sim-view.three { height: 340px; }
  .hero-3d { height: 320px; }
  .bb-logo small { display: none; }
  .bb-pager { grid-template-columns: 1fr; }
  .bb-pager .next { grid-column: 1; }
}

/* ------------------------------------------------------------------ BodyBook extras */
svg .s-acc2 { stroke: var(--accent-2); fill: none; stroke-width: 2; }
svg .f-acc2 { fill: var(--accent-2); }
svg .f-ok-soft { fill: color-mix(in srgb, var(--ok) 16%, transparent); stroke: var(--ok); }
svg .f-warn-soft { fill: color-mix(in srgb, var(--warn) 18%, transparent); stroke: var(--warn); }
svg .f-bad-soft { fill: color-mix(in srgb, var(--bad) 14%, transparent); stroke: var(--bad); }
svg .f-bad { fill: var(--bad); }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface); color: var(--text-dim); border: 1px solid var(--border); }
/* 스크롤 컨테이너 안의 KaTeX 숨김 MathML(absolute)이 페이지 가로 스크롤을 만들지 않도록 */
.table-wrap, .formula, .sim, figure, .callout, .quiz-q { position: relative; }
/* keep-all에서 '·'로 이어진 긴 토큰이 좁은 화면을 넘지 않도록 */
main.chapter p, main.chapter li, figcaption, .callout, .quiz-exp { overflow-wrap: anywhere; }

svg .s-dash { stroke: var(--text-faint); fill: none; stroke-width: 1.2; stroke-dasharray: 4 3; }
svg .s-bad { stroke: var(--bad); fill: none; stroke-width: 2; }
svg .beam { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.2; }
svg .lbl { fill: var(--text); font-family: var(--font); font-size: 14px; }
svg .lbl-dim { fill: var(--text-dim); font-family: var(--font); font-size: 13px; }
svg .lbl-b { fill: var(--text); font-family: var(--font); font-size: 15px; font-weight: 700; }
svg .lbl-acc { fill: var(--accent); font-family: var(--font); font-size: 14px; font-weight: 700; }
svg .lbl-acc2 { fill: var(--accent-2); font-family: var(--font); font-size: 14px; font-weight: 700; }
svg .lbl-bad { fill: var(--bad); font-family: var(--font); font-size: 14px; font-weight: 700; }

.sw-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--text-dim); padding: 10px 18px; border-top: 1px solid var(--border); }
.sw-legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,.15); }

.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: default; }
.ok-t { color: var(--ok); } .bad-t { color: var(--bad); } .warn-t { color: var(--warn); }

/* 몸의 계통 띠 (챕터 상단, common.js가 삽입) */
.bb-stages { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; margin: 28px 0 0; }
.bb-stages a { position: relative; display: block; padding: 9px 8px 9px 16px; background: var(--surface); color: var(--text-faint); line-height: 1.3; min-width: 0; clip-path: polygon(0 0, calc(100% - 9px) 0, 100% 50%, calc(100% - 9px) 100%, 0 100%, 9px 50%); }
.bb-stages a:first-child { clip-path: polygon(0 0, calc(100% - 9px) 0, 100% 50%, calc(100% - 9px) 100%, 0 100%); padding-left: 10px; border-radius: 8px 0 0 8px; }
.bb-stages a:hover { text-decoration: none; color: var(--text); }
.bb-stages b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bb-stages small { display: block; font-family: var(--mono); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .8; }
.bb-stages a.done { background: var(--accent-soft); color: var(--accent); }
.bb-stages a.cur { background: var(--accent); color: var(--on-accent); }
@media (max-width: 640px) {
  .bb-stages { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bb-stages small { display: none; }
  .bb-stages b { font-size: 12.5px; }
  .bb-stages a:nth-child(4) { clip-path: polygon(0 0, calc(100% - 9px) 0, 100% 50%, calc(100% - 9px) 100%, 0 100%); padding-left: 10px; }
}

/* 케이스 파일: 장마다 이어지는 가상의 인물 다온 */
.casefile { margin: 28px 0; border: 1px solid var(--border); border-left: 4px solid var(--accent-2); border-radius: var(--radius-sm); background: var(--bg-elev); padding: 16px 18px; font-size: 16px; position: relative; }
.casefile > .tag { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-family: var(--mono); font-size: 11.5px; font-weight: 600; letter-spacing: .1em; color: var(--accent-2); margin-bottom: 8px; }
.casefile > .tag b { background: var(--accent-2-soft); border-radius: 999px; padding: 2px 9px; }
.casefile h4 { margin: 0 0 6px; font-size: 17px; }
.casefile p { margin: 0 0 10px !important; }
.casefile p:last-child, .casefile ul:last-child { margin-bottom: 0 !important; }
.casefile .clue { display: grid; gap: 1px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--border); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-top: 12px; }
.casefile .clue div { background: var(--surface); padding: 9px 12px; font-size: 13px; color: var(--text-dim); line-height: 1.45; }
.casefile .clue b { display: block; color: var(--text); font-size: 14px; }

/* 환자 모니터 화면 (실제 장비처럼 어두운 화면) */
.sim-view.monitor { background: #0b0d12; }
.sim-view.monitor .hint { color: #9aa6bf; background: rgba(11, 13, 18, .7); }
[hidden] { display: none !important; }

.sim-view canvas.drag { cursor: grab; touch-action: none; }
.sim-view canvas.drag:active { cursor: grabbing; }

/* ------------------------------------------------------------------ 몸 공통 색 */
/* 계통(seg-*), 모니터 채널(tr-*), 생리 물질 색. 캔버스에서는 BB.segColor(key), BB.trace(i), BB.color("art") */
:root {
  --seg-base: #5c677d; --seg-circ: #be123c; --seg-resp: #1c7ed6; --seg-musc: #e8590c;
  --seg-meta: #2b8a3e; --seg-reg: #7048e8;
  --tr-1: #2fbf5b; --tr-2: #ff4d5e; --tr-3: #22c3e6; --tr-4: #f5c400;
  --art: #d6293e; --ven: #3b5bdb; --o2: #e03131; --co2: #4263eb; --glu: #e67700; --ins: #7048e8;
  --fat: #f0b429; --carb: #2f9e44; --prot: #c2255c; --water: #1c7ed6; --heat: #f76707; --nerve: #ae3ec9;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --seg-base: #adb5bd; --seg-circ: #fb7185; --seg-resp: #74c0fc; --seg-musc: #ffa94d;
    --seg-meta: #69db7c; --seg-reg: #b197fc;
    --art: #ff6b7a; --ven: #7c9cff; --o2: #ff6b6b; --co2: #748ffc; --glu: #ffc078; --ins: #b197fc;
    --fat: #ffd43b; --carb: #69db7c; --prot: #f783ac; --water: #74c0fc; --heat: #ffa94d; --nerve: #e599f7;
  }
}
:root[data-theme="dark"] {
  --seg-base: #adb5bd; --seg-circ: #fb7185; --seg-resp: #74c0fc; --seg-musc: #ffa94d;
  --seg-meta: #69db7c; --seg-reg: #b197fc;
  --art: #ff6b7a; --ven: #7c9cff; --o2: #ff6b6b; --co2: #748ffc; --glu: #ffc078; --ins: #b197fc;
  --fat: #ffd43b; --carb: #69db7c; --prot: #f783ac; --water: #74c0fc; --heat: #ffa94d; --nerve: #e599f7;
}
svg .seg-base { fill: var(--seg-base); } svg .seg-circ { fill: var(--seg-circ); } svg .seg-resp { fill: var(--seg-resp); }
svg .seg-musc { fill: var(--seg-musc); } svg .seg-meta { fill: var(--seg-meta); } svg .seg-reg { fill: var(--seg-reg); }
svg .f-art { fill: var(--art); } svg .f-ven { fill: var(--ven); } svg .f-glu { fill: var(--glu); } svg .f-ins { fill: var(--ins); }
svg .f-fat { fill: var(--fat); } svg .f-carb { fill: var(--carb); } svg .f-prot { fill: var(--prot); } svg .f-water { fill: var(--water); }
svg .f-nerve { fill: var(--nerve); } svg .f-heat { fill: var(--heat); }
svg .s-art { fill: none; stroke: var(--art); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
svg .s-ven { fill: none; stroke: var(--ven); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
svg .s-nerve { fill: none; stroke: var(--nerve); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .s-glu { fill: none; stroke: var(--glu); stroke-width: 2; } svg .s-ins { fill: none; stroke: var(--ins); stroke-width: 2; }
svg .f-art-soft { fill: color-mix(in srgb, var(--art) 16%, transparent); stroke: var(--art); }
svg .f-ven-soft { fill: color-mix(in srgb, var(--ven) 14%, transparent); stroke: var(--ven); }
svg .f-organ { fill: color-mix(in srgb, var(--accent) 10%, var(--bg-elev)); stroke: var(--accent); stroke-width: 1.4; }
svg .f-tr1 { fill: var(--tr-1); } svg .f-tr2 { fill: var(--tr-2); } svg .f-tr3 { fill: var(--tr-3); } svg .f-tr4 { fill: var(--tr-4); }
svg .s-ok { stroke: var(--ok); fill: none; stroke-width: 2; }
svg .f-ok { fill: var(--ok); } svg .f-warn { fill: var(--warn); }


/* 캔버스 위 떠 있는 정보 상자 (AB.tip) */
.bb-tip { position: absolute; z-index: 5; pointer-events: none; max-width: 260px; padding: 8px 11px; border-radius: 9px; font-size: 13px; line-height: 1.45;
  background: color-mix(in srgb, var(--bg-elev) 94%, transparent); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text); opacity: 0; transition: opacity .12s; }
.bb-tip.on { opacity: 1; }
.bb-tip b { display: block; font-size: 14px; }
.bb-tip small { color: var(--text-dim); }

/* 정보 패널 (클릭한 대상 설명) */
.info-panel { padding: 14px 18px; border-top: 1px solid var(--border); background: var(--bg-elev); font-size: 15px; line-height: 1.6; min-height: 64px; }
.info-panel h4 { margin: 0 0 4px; font-size: 16px; }
.info-panel p { margin: 0 0 6px !important; color: var(--text-dim); }
.info-panel .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.info-panel .chips span { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface); color: var(--text-dim); }

/* 시뮬레이터 바로가기 링크 (sim-head 오른쪽, common.js가 삽입) */
.sim-link { font-size: 12px; color: var(--text-faint); font-family: var(--mono); }
.sim-link:hover { color: var(--accent); text-decoration: none; }
.sim.flash { animation: simflash 1.6s ease; }
@keyframes simflash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: var(--shadow); } }

/* 시뮬레이터만 보기 모드 */
.bb-btn.toggle[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.bb-btn .lbl-wide { display: none; }
@media (min-width: 560px) { .bb-btn .lbl-wide { display: inline; } }
body.sim-only main.chapter > section > :not(h2):not(.sim):not(.sim-group),
body.sim-only main.chapter > section.keypoints,
body.sim-only main.chapter > section.quiz-sec,
body.sim-only .chapter-hero .objectives,
body.sim-only .chapter-hero .lead { display: none !important; }
body.sim-only main.chapter > section:not(:has(.sim)) { display: none; }
body.sim-only main.chapter > section { margin: 28px 0; }
body.sim-only main.chapter h2 { font-size: 18px; color: var(--text-dim); }
body.sim-only .sim { margin: 14px 0 24px; }
.sim-only-banner { display: none; margin: 18px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--text); font-size: 14px; }
body.sim-only .sim-only-banner { display: block; }

/* 시뮬레이터 갤러리 */
.gal-filter { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.gal-filter input { flex: 1 1 240px; font: inherit; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); }
.gal-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.gal-card { display: flex; flex-direction: column; gap: 6px; padding: 16px 18px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); transition: transform .15s, border-color .15s; }
.gal-card:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-2px); }
.gal-card .ch { font-family: var(--mono); font-size: 11.5px; color: var(--accent); letter-spacing: .06em; }
.gal-card h3 { margin: 0; font-size: 16.5px; line-height: 1.4; }
.gal-card p { margin: 0; font-size: 13.5px; color: var(--text-dim); line-height: 1.55; }
.gal-card .ico { width: 100%; height: 6px; border-radius: 3px; }
.gal-sec { margin: 30px 0 10px; font-size: 18px; display: flex; gap: 10px; align-items: baseline; }
.gal-sec small { font-family: var(--mono); color: var(--text-faint); font-size: 12px; }

/* 큰 지도형 뷰 */
.sim-view.tall canvas { min-height: 360px; }
.map-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--text-dim); padding: 10px 18px; border-top: 1px solid var(--border); }
.map-legend span { display: inline-block; white-space: nowrap; }
.map-legend span > i { margin-right: 6px; vertical-align: -1px; }
.map-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* ------------------------------------------------------------------ 상단바 검색 (시리즈 공통) */
.book-nav-left, .book-nav-right { display: flex; align-items: center; gap: 12px; flex: 1 1 0; min-width: 0; }
.book-nav-left { overflow: hidden; }
.book-nav-left > a { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.book-nav-right { justify-content: flex-end; }
.book-search { position: relative; flex: 0 1 340px; min-width: 80px; color: var(--text-dim); }
.book-search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.book-search input { display: block; width: 100%; height: 36px; padding: 0 12px 0 37px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-elev); color: var(--text); font: inherit; font-size: 14px; outline: none; }
.book-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.book-search input::placeholder { color: var(--text-faint); }
.book-search-results { display: none; position: absolute; top: calc(100% + 10px); left: 0; width: max(100%, 300px); max-width: min(420px, calc(100vw - 32px)); max-height: min(60vh, 460px); overflow-y: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elev); box-shadow: var(--shadow); padding: 6px; }
.book-search.open .book-search-results { display: block; }
.book-search-results a { display: block; padding: 9px 11px; border-radius: 8px; color: var(--text); line-height: 1.4; }
.book-search-results a:hover, .book-search-results a:focus { background: var(--accent-soft); text-decoration: none; outline: none; }
.book-search-results strong, .book-search-results small { display: block; }
.book-search-results strong { font-size: 14px; }
.book-search-results small { margin-top: 3px; color: var(--text-dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book-search-results p { margin: 0; padding: 10px 11px; font-size: 14px; }
@media (max-width: 760px) { .book-nav-left > a small { display: none; } .book-nav-right .series-link span { display: none; } .book-nav-right .series-link { width: 36px; padding: 0; } }
@media (max-width: 600px) { .book-nav-left, .book-nav-right { flex: 0 0 auto; } .book-nav-left > a { display: none; } .book-search { flex: 1 1 auto; } .book-search-results { left: 50%; transform: translateX(-50%); } }
@media (max-width: 440px) { .book-nav-right .series-link { display: none; } .book-search input::placeholder { color: transparent; } }
.bb-topbar .series-link { white-space: nowrap; text-decoration: none; }
@media (max-width: 1100px) { .bb-btn .lbl-wide { display: none !important; } .bb-btn.toggle, .bb-btn.gal { width: 36px; padding: 0; } }

/* 건강 안내 */
.health-note { font-size: 13.5px; color: var(--text-dim); border: 1px dashed var(--border); border-radius: 10px; padding: 10px 14px; margin: 24px 0; }
/* 숫자 상자 (홈, 장 도입부) */
.numbers { display: grid; gap: 1px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin: 22px 0; }
.numbers div { background: var(--bg-elev); padding: 16px 18px; }
.numbers b { display: block; font-family: var(--mono); font-size: 24px; letter-spacing: -0.02em; color: var(--text); }
.numbers span { color: var(--text-dim); font-size: 14px; line-height: 1.5; display: block; }
