/* ==========================================================================
   科研技能知识库 · Design System
   朱砂 × 暖纸 · 学术书卷 (Cinnabar on Warm Paper)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;600;700;900&family=Noto+Sans+SC:wght@300;400;500;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  /* ---- Surfaces: warm paper ---- */
  --bg: #faf9f6;
  --card: #ffffff;
  --surface-2: #f5f1e8;
  --surface-3: #efe9dc;

  /* ---- Ink: warm black progression ---- */
  --ink: #2a2119;
  --ink-2: #66594c;
  --ink-3: #a29685;
  --line: #e8e0d1;
  --line-soft: #efe9db;

  /* ---- Primary: 朱砂 cinnabar ---- */
  --primary: #a63a2e;
  --primary-deep: #872a20;
  --primary-bright: #c14a38;
  --primary-tint: #f7e9e3;
  --primary-tint-2: #fbf3ee;
  --primary-line: #e6cdbf;

  /* ---- Accent: 赭金 ---- */
  --gold: #a97e24;
  --gold-tint: #f6eeda;
  --gold-line: #e6d6ae;

  /* ---- Typography ---- */
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "SimSun", serif;
  --font-sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;

  /* ---- Effects ---- */
  --shadow-1: 0 1px 2px rgba(42, 33, 25, .05), 0 2px 6px rgba(42, 33, 25, .03);
  --shadow-2: 0 6px 20px -8px rgba(42, 33, 25, .14);
  --shadow-3: 0 24px 56px -16px rgba(42, 33, 25, .28);
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --sidebar-w: 276px;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 28px; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.85;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  /* faint paper grain */
  background-image: radial-gradient(rgba(42, 33, 25, .022) 1px, transparent 1px);
  background-size: 26px 26px;
}
::selection { background: rgba(166, 58, 46, .18); }

h1, h2, h3, h4 { font-family: var(--font-serif); font-weight: 600; margin: 0; text-wrap: balance; }
p { margin: 0 0 14px; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-deep); }
img { max-width: 100%; }

.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }

/* ============ Scroll progress ============ */
.scroll-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: linear-gradient(90deg, var(--primary-deep), var(--primary), var(--primary-bright));
  z-index: 1200; transition: width 90ms linear;
}

/* ============ Sidebar (site nav) ============ */
.sidebar-toggle {
  display: none; position: fixed; top: 14px; left: 14px; z-index: 1102;
  width: 42px; height: 42px; border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--card); color: var(--ink); cursor: pointer;
  align-items: center; justify-content: center; box-shadow: var(--shadow-1);
}
.sidebar-toggle svg { width: 20px; height: 20px; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(42, 33, 25, .32); z-index: 1090; backdrop-filter: blur(2px); }

.sidebar {
  position: fixed; top: 0; left: 0; width: var(--sidebar-w); height: 100vh;
  background: var(--bg); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 26px 18px 40px; z-index: 1100;
  transition: transform 260ms cubic-bezier(.4, 0, .2, 1);
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.sidebar-header { padding: 4px 8px 18px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.sidebar-logo { display: flex; align-items: center; gap: 10px; font-family: var(--font-serif); font-size: 18px; font-weight: 700; color: var(--ink); letter-spacing: .02em; }
.sidebar-logo .logo-seal {
  width: 30px; height: 30px; flex: none; border: 2px solid var(--primary); border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: var(--primary); font-size: 15px; font-weight: 900; transform: rotate(-4deg);
}
.sidebar-sub { margin-top: 8px; font-size: 12px; color: var(--ink-3); letter-spacing: .14em; }

.sidebar-search { position: relative; margin: 0 4px 20px; }
.sidebar-search .s-ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--ink-3); pointer-events: none; }
.sidebar-search input {
  width: 100%; padding: 8px 12px 8px 34px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); font-size: 13px; color: var(--ink); outline: none;
  font-family: var(--font-sans); transition: border-color 160ms, box-shadow 160ms;
}
.sidebar-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(166, 58, 46, .1); }
.sidebar-search input::placeholder { color: var(--ink-3); }

.sidebar-nav .mod-group { margin-bottom: 6px; }
.sidebar-nav summary {
  font-family: var(--font-serif); font-size: 13.5px; font-weight: 600; color: var(--ink);
  cursor: pointer; padding: 9px 8px; list-style: none; border-radius: var(--r-sm);
  display: flex; align-items: center; gap: 8px; user-select: none;
  transition: background 140ms;
}
.sidebar-nav summary:hover { background: var(--surface-2); }
.sidebar-nav summary::-webkit-details-marker { display: none; }
.mod-dot { width: 7px; height: 7px; border-radius: 2px; background: var(--primary); flex: none; transform: rotate(45deg); opacity: .85; }
.mod-group[data-mod="2"] .mod-dot { background: var(--gold); }
.mod-group[data-mod="3"] .mod-dot { background: #7a5ea0; }
.mod-group[data-mod="4"] .mod-dot { background: #3e6b8f; }
.mod-marker { margin-left: auto; font-family: var(--font-mono); font-size: 13px; color: var(--ink-3); transition: transform 200ms; }
.sidebar-nav details[open] > summary .mod-marker { transform: rotate(45deg); }
.chapter-links { padding: 2px 0 8px 10px; display: flex; flex-direction: column; gap: 1px; }
.chapter-links a {
  display: flex; align-items: baseline; gap: 8px; padding: 6px 12px 6px 14px;
  font-size: 13px; color: var(--ink-2); border-left: 2px solid transparent;
  border-radius: 0 var(--r-sm) var(--r-sm) 0; line-height: 1.5; transition: all 130ms;
}
.chapter-links a:hover { background: var(--surface-2); color: var(--ink); }
.chapter-links a.active { background: var(--primary-tint); color: var(--primary-deep); border-left-color: var(--primary); font-weight: 500; }
.chapter-links .no { font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); flex: none; }

.sidebar-foot { margin-top: 22px; padding: 14px 10px 0; border-top: 1px dashed var(--line); font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 8px; }
.sidebar-foot .seal { transform: rotate(-3deg); }

/* ============ Content column ============ */
.content { margin-left: var(--sidebar-w); max-width: 880px; padding: 0 48px; min-height: 100vh; }

/* ============ Chapter header ============ */
.chapter-head { position: relative; padding: 72px 0 8px; }
.chapter-head .ghost-no {
  position: absolute; right: -6px; top: 26px; font-family: var(--font-serif); font-weight: 900;
  font-size: clamp(90px, 13vw, 150px); line-height: 1; color: transparent;
  -webkit-text-stroke: 1.5px rgba(166, 58, 46, .14); pointer-events: none; user-select: none;
  letter-spacing: -.02em;
}
.ch-crumb { display: inline-flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 13px; color: var(--ink-3); letter-spacing: .05em; }
.ch-crumb a { color: var(--ink-3); }
.ch-crumb a:hover { color: var(--primary); }
.ch-crumb .crumb-dot { width: 5px; height: 5px; background: var(--primary); transform: rotate(45deg); border-radius: 1px; }
.ch-crumb .crumb-live { color: var(--primary); font-weight: 500; }
.chapter-title { font-size: clamp(26px, 3.6vw, 40px); line-height: 1.28; max-width: 640px; position: relative; }
.ch-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 16px 0 0; font-size: 13px; color: var(--ink-2); }
.ch-meta .stars { color: var(--gold); letter-spacing: .1em; font-size: 12px; }
.ch-meta .m-divider { color: var(--line); }
.ch-meta .m-pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); font-size: 12px; }
.ch-meta .m-pill svg { width: 13px; height: 13px; color: var(--primary); }

/* objective box */
.obj-box {
  position: relative; margin: 30px 0 0; padding: 20px 24px 18px 58px;
  background: var(--primary-tint-2); border: 1px solid var(--primary-line);
  border-radius: var(--r-md); overflow: hidden;
}
.obj-box::before {
  content: "目"; position: absolute; left: 14px; top: 16px; width: 30px; height: 30px;
  border: 2px solid var(--primary); border-radius: 7px; color: var(--primary);
  font-family: var(--font-serif); font-weight: 700; font-size: 15px;
  display: flex; align-items: center; justify-content: center; transform: rotate(-5deg);
  background: var(--card);
}
.obj-box .obj-label { font-family: var(--font-serif); font-size: 13px; font-weight: 700; color: var(--primary-deep); letter-spacing: .18em; margin-bottom: 6px; }
.obj-box p { font-size: 15px; color: var(--ink-2); line-height: 1.8; margin: 0; }

/* TOC chips */
.toc-wrap { margin: 26px 0 6px; padding: 20px 22px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-1); }
.toc-label { display: flex; align-items: center; gap: 8px; font-family: var(--font-serif); font-size: 13px; font-weight: 700; letter-spacing: .16em; color: var(--ink-2); margin-bottom: 14px; }
.toc-label::after { content: ""; flex: 1; height: 1px; background: repeating-linear-gradient(90deg, var(--line) 0 6px, transparent 6px 12px); }
.toc-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.toc-chips a {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 13px;
  font-size: 13px; color: var(--ink-2); background: var(--surface-2);
  border: 1px solid transparent; border-radius: 999px; transition: all 150ms;
}
.toc-chips a:hover { background: var(--primary-tint); color: var(--primary-deep); border-color: var(--primary-line); transform: translateY(-1px); }
.toc-chips a.now { background: var(--primary); color: #fff; }
.toc-chips .tno { font-family: var(--font-mono); font-size: 10.5px; opacity: .65; }

/* ============ Prose (markdown body) ============ */
.doc-body { padding: 34px 0 20px; }
.doc-body h2 {
  position: relative; font-size: clamp(20px, 2.4vw, 26px); margin: 58px 0 20px; padding-left: 18px;
  line-height: 1.4; scroll-margin-top: 24px;
}
.doc-body h2::before {
  content: ""; position: absolute; left: 0; top: .32em; width: 8px; height: 8px;
  background: var(--primary); transform: rotate(45deg); border-radius: 2px;
}
.doc-body h2::after {
  content: ""; position: absolute; left: 0; bottom: -8px; width: 100%;
  background: repeating-linear-gradient(90deg, var(--line) 0 8px, transparent 8px 16px); height: 1px;
}
.doc-body h3 { font-size: 18.5px; margin: 34px 0 14px; color: var(--ink); scroll-margin-top: 24px; }
.doc-body h4 { font-family: var(--font-sans); font-size: 15.5px; font-weight: 700; margin: 26px 0 10px; color: var(--ink); }
.doc-body p { color: #4d443a; }
.doc-body strong { font-weight: 600; color: var(--ink); background: linear-gradient(transparent 64%, rgba(166, 58, 46, .13) 0); }
.doc-body ul, .doc-body ol { padding-left: 6px; margin: 0 0 18px; list-style: none; }
.doc-body li { position: relative; padding-left: 24px; margin-bottom: 7px; color: #4d443a; }
.doc-body ul > li::before {
  content: ""; position: absolute; left: 6px; top: .72em; width: 6px; height: 6px;
  border: 1.5px solid var(--primary); border-radius: 1px; transform: rotate(45deg); opacity: .7;
}
.doc-body ol { counter-reset: oli; }
.doc-body ol > li { counter-increment: oli; padding-left: 34px; }
.doc-body ol > li::before {
  content: counter(oli); position: absolute; left: 0; top: .18em;
  font-family: var(--font-mono); font-size: 12px; color: var(--primary);
  border: 1px solid var(--primary-line); background: var(--primary-tint-2);
  border-radius: 999px; min-width: 21px; height: 21px; display: flex; align-items: center; justify-content: center;
}
.doc-body li > ul, .doc-body li > ol { margin: 7px 0 2px; }
.doc-body code {
  font-family: var(--font-mono); font-size: .86em; padding: 2px 7px;
  background: var(--primary-tint); color: var(--primary-deep);
  border-radius: 5px; border: 1px solid var(--primary-line); word-break: break-all;
}
.doc-body hr { border: none; height: 1px; margin: 44px 0; background: repeating-linear-gradient(90deg, var(--line) 0 8px, transparent 8px 16px); }

/* ============ Callouts (from blockquotes) ============ */
.co { position: relative; margin: 26px 0; padding: 18px 22px 16px 56px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow-1); }
.co .co-ic {
  position: absolute; left: 14px; top: 16px; width: 28px; height: 28px; flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
  border-radius: 7px; font-family: var(--font-serif); font-weight: 700;
}
.co p { margin: 0 0 8px; font-size: 14.5px; line-height: 1.8; }
.co p:last-child { margin-bottom: 0; }
.co .co-tag { display: inline-block; font-family: var(--font-serif); font-size: 11px; font-weight: 700; letter-spacing: .2em; margin-bottom: 4px; }
.co ul, .co ol { margin: 8px 0 0; }

.co-metaphor { background: var(--primary-tint-2); border-color: var(--primary-line); }
.co-metaphor .co-ic { background: var(--card); border: 2px solid var(--primary); color: var(--primary); transform: rotate(-5deg); border-radius: 8px; }
.co-metaphor .co-tag { color: var(--primary-deep); }

.co-core {
  background: linear-gradient(135deg, var(--primary-deep), var(--primary) 55%, #b34534);
  border: none; color: #fdf6f1; padding: 20px 24px 18px 56px;
}
.co-core .co-ic { background: rgba(255, 255, 255, .12); border: 2px solid rgba(255, 255, 255, .65); color: #fff; transform: rotate(-5deg); }
.co-core .co-tag { color: rgba(255, 240, 230, .85); }
.co-core p { color: #fdf6f1; }
.co-core strong { background: none; color: #ffe9dd; }

.co-tip { background: var(--gold-tint); border-color: var(--gold-line); }
.co-tip .co-ic { background: var(--card); border: 2px solid var(--gold); color: var(--gold); border-radius: 8px; }
.co-tip .co-tag { color: var(--gold); }

.co-warn { background: #fdf3e7; border-color: #ecd9bd; }
.co-warn .co-ic { background: var(--card); border: 2px solid #c07a17; color: #c07a17; border-radius: 8px; }
.co-warn .co-tag { color: #a8670f; }

.co-note { background: var(--surface-2); }
.co-note .co-ic { background: var(--card); border: 2px solid var(--ink-3); color: var(--ink-2); border-radius: 8px; }
.co-note .co-tag { color: var(--ink-2); }

/* ============ Figures ============ */
.fig {
  position: relative; margin: 40px auto; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 20px 20px 0; box-shadow: var(--shadow-2);
  rotate: var(--tilt, 0deg); transition: rotate 300ms cubic-bezier(.34, 1.56, .64, 1), transform 300ms, box-shadow 300ms;
  max-width: 720px;
}
.fig::before { /* washi tape */
  content: ""; position: absolute; top: -11px; left: 50%; width: 96px; height: 24px;
  transform: translateX(-50%) rotate(-2.5deg);
  background: var(--tape, rgba(166, 58, 46, .14));
  border-left: 1px dashed rgba(255, 255, 255, .55); border-right: 1px dashed rgba(255, 255, 255, .55);
  box-shadow: 0 1px 2px rgba(42, 33, 25, .08);
}
.fig:nth-of-type(3n+1) { --tilt: -0.9deg; --tape: rgba(166, 58, 46, .15); }
.fig:nth-of-type(3n+2) { --tilt: .7deg; --tape: rgba(169, 126, 36, .18); }
.fig:nth-of-type(3n+3) { --tilt: -0.4deg; --tape: rgba(62, 107, 143, .14); }
.fig:hover { rotate: 0deg; transform: translateY(-4px); box-shadow: var(--shadow-3); }
.fig-body { display: flex; justify-content: center; align-items: center; padding: 8px 4px 12px; overflow: hidden; }
.fig-body img { max-width: 100%; height: auto; display: block; cursor: zoom-in; border-radius: 4px; transition: transform 400ms; }
.fig:hover .fig-body img { transform: scale(1.015); }
.fig-cap {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px; margin: 0 -20px; border-top: 1px dashed var(--line);
  font-size: 13px; color: var(--ink-2);
}
.fig-cap .fno { font-family: var(--font-serif); font-weight: 700; color: var(--primary); font-size: 12.5px; letter-spacing: .04em; }
.badge-media {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 500;
  padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap;
}
.badge-media svg { width: 11px; height: 11px; }
.badge-shot { background: var(--surface-2); color: var(--ink-2); }
.badge-art { background: var(--primary-tint); color: var(--primary-deep); border-color: var(--primary-line); }
.badge-img-overlay { position: absolute; top: 12px; right: 12px; z-index: 2; box-shadow: var(--shadow-1); }
.fig-wide { max-width: none; }

/* ============ Tables ============ */
.tbl-wrap { overflow-x: auto; margin: 30px 0; border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-1); background: var(--card); }
table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 520px; }
thead th {
  background: var(--primary); color: #fdf6f1; padding: 11px 16px; text-align: left;
  font-weight: 600; font-size: 13px; white-space: nowrap; letter-spacing: .03em;
}
thead th:first-child { border-top-left-radius: var(--r-sm); }
tbody td { padding: 11px 16px; border-top: 1px solid var(--line-soft); color: #4d443a; vertical-align: top; }
tbody tr:nth-child(even) { background: var(--surface-2); }
tbody td:first-child { font-weight: 500; color: var(--ink); }

/* ============ Code blocks ============ */
.codeblock { position: relative; margin: 30px 0; border-radius: var(--r-md); overflow: hidden; box-shadow: var(--shadow-2); background: #2b241c; color: #efe6da; }
.codeblock pre { color: #efe6da; }
.codeblock pre:not(:has(code)) { color: #efe6da; }
.codeblock .cb-bar { display: flex; align-items: center; gap: 8px; padding: 9px 14px; background: rgba(255, 255, 255, .04); border-bottom: 1px solid rgba(255, 255, 255, .07); }
.cb-dots { display: flex; gap: 6px; }
.cb-dots i { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, .14); }
.cb-lang { font-family: var(--font-mono); font-size: 11px; color: rgba(255, 240, 225, .5); letter-spacing: .08em; }
.cb-copy {
  margin-left: auto; border: 1px solid rgba(255, 240, 225, .2); background: transparent; color: rgba(255, 240, 225, .65);
  font-size: 11px; font-family: var(--font-sans); padding: 3px 10px; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px; transition: all 160ms;
}
.cb-copy:hover { border-color: rgba(255, 240, 225, .5); color: #fff; }
.cb-copy svg { width: 11px; height: 11px; }
.codeblock pre { margin: 0; padding: 18px 20px; overflow-x: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.codeblock pre code { font-family: var(--font-mono); font-size: 13.5px; line-height: 1.75; color: #efe6da; background: none; padding: 0; border: none; }
/* pygments inline (noclasses) fallbacks */
.codeblock .c { color: #8d8172; font-style: italic; }      /* comment */
.codeblock .k, .codeblock .ow { color: #e88a74; }          /* keyword */
.codeblock .s1, .codeblock .s2, .codeblock .sd, .codeblock .se { color: #d9b96a; } /* string */
.codeblock .nf, .codeblock .fm { color: #9fc3e8; }         /* function */
.codeblock .mi, .codeblock .mf, .codeblock .nb { color: #c9a7e0; } /* number/builtin */
.codeblock .nd { color: #9fc3e8; }
.codeblock .o { color: #efe6da; }

/* ============ Ext links (学习资源) ============ */
.res-section { margin: 56px 0 0; padding: 28px 28px 24px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); position: relative; overflow: hidden; }
.res-section::after { content: "資"; position: absolute; right: 18px; top: 6px; font-family: var(--font-serif); font-size: 76px; font-weight: 900; color: rgba(166, 58, 46, .05); pointer-events: none; }
.res-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 6px; }
.res-head h2 { font-size: 21px; }
.res-head .res-sub { font-size: 12.5px; color: var(--ink-3); }
.res-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 16px; position: relative; z-index: 1; }
.res-card {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md);
  text-decoration: none; color: var(--ink); transition: all 180ms; position: relative;
}
.res-card:hover { border-color: var(--primary-line); background: var(--primary-tint-2); transform: translateY(-2px); box-shadow: var(--shadow-2); color: var(--ink); }
.res-badge {
  flex: none; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 6px; letter-spacing: .06em;
  font-family: var(--font-sans);
}
.res-badge.bili { background: var(--primary); color: #fff; }
.res-badge.web { background: var(--gold-tint); color: var(--gold); border: 1px solid var(--gold-line); }
.res-badge.git { background: #3e6b8f1a; color: #3e6b8f; border: 1px solid #3e6b8f33; }
.res-body { min-width: 0; }
.res-name { font-size: 14px; font-weight: 500; line-height: 1.5; }
.res-meta { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.res-arrow { margin-left: auto; flex: none; color: var(--ink-3); transition: all 180ms; }
.res-card:hover .res-arrow { color: var(--primary); transform: translate(2px, -2px); }
.res-arrow svg { width: 15px; height: 15px; }

/* ============ Chapter nav (prev / next) ============ */
.chapter-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 52px 0 8px; }
.cn-link {
  display: flex; flex-direction: column; gap: 6px; padding: 18px 20px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md);
  text-decoration: none; color: var(--ink); transition: all 200ms; position: relative; overflow: hidden;
}
.cn-link:hover { border-color: var(--primary-line); box-shadow: var(--shadow-2); transform: translateY(-2px); }
.cn-link.next { text-align: right; align-items: flex-end; }
.cn-link .cn-dir { font-size: 12px; color: var(--ink-3); letter-spacing: .1em; display: flex; align-items: center; gap: 6px; }
.cn-link.next .cn-dir { flex-direction: row-reverse; }
.cn-link .cn-dir svg { width: 13px; height: 13px; }
.cn-link .cn-title { font-family: var(--font-serif); font-size: 16px; font-weight: 600; line-height: 1.45; }
.cn-link:hover .cn-title { color: var(--primary-deep); }
.cn-link.back { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: center; text-align: center; padding: 13px; background: var(--surface-2); border-style: dashed; }

/* ============ Footer ============ */
.site-footer { margin-top: 72px; border-top: 1px solid var(--line); padding: 40px 0 46px; }
.footer-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 18px; }
.footer-brand { display: flex; align-items: center; gap: 14px; }
.seal {
  display: inline-flex; align-items: center; justify-content: center;
  border: 2.5px solid var(--primary); border-radius: 8px; color: var(--primary);
  font-family: var(--font-serif); font-weight: 900; transform: rotate(-4deg);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .5);
}
.seal.seal-memo { padding: 5px 9px; font-size: 13px; letter-spacing: .02em; line-height: 1.1; }
.footer-titles { display: flex; flex-direction: column; gap: 3px; }
.footer-name { font-family: var(--font-serif); font-size: 16px; font-weight: 700; }
.footer-meta { font-size: 12.5px; color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.footer-meta .fd { color: var(--line); }
.footer-credit { font-size: 13px; color: var(--ink-2); text-align: right; line-height: 1.7; }
.footer-credit .by { font-family: var(--font-serif); font-weight: 700; color: var(--primary-deep); }

/* ============ Reveal on scroll ============ */
.rv { opacity: 0; transform: translateY(20px); transition: opacity .7s cubic-bezier(.2, .6, .2, 1), transform .7s cubic-bezier(.2, .6, .2, 1); }
.rv.in { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) {
  .rv { opacity: 1; transform: none; transition: none; }
  .fig { transition: none; }
  html { scroll-behavior: auto; }
}

/* ============ Lightbox ============ */
.lightbox { display: none; position: fixed; inset: 0; background: rgba(30, 24, 18, .93); z-index: 2000; align-items: center; justify-content: center; padding: 48px; }
.lightbox.active { display: flex; }
.lightbox img { max-width: 92vw; max-height: 90vh; border-radius: var(--r-md); box-shadow: var(--shadow-3); background: #fff; }
.lightbox-close { position: absolute; top: 22px; right: 24px; width: 44px; height: 44px; border: none; border-radius: 50%; background: rgba(255, 255, 255, .12); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 160ms; }
.lightbox-close:hover { background: rgba(255, 255, 255, .25); }
.lightbox-close svg { width: 20px; height: 20px; }
.lightbox-cap { position: absolute; bottom: 26px; left: 0; right: 0; text-align: center; color: rgba(255, 245, 235, .75); font-size: 13.5px; }

/* ============ Decorative ============ */
.deco-ring { position: absolute; border: 1.5px solid rgba(166, 58, 46, .18); border-radius: 50%; pointer-events: none; }
.float-a { animation: floaty 7s ease-in-out infinite; }
.float-b { animation: floaty 9s ease-in-out 1.2s infinite; }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }

/* ============ Responsive ============ */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-105%); box-shadow: none; }
  .sidebar.active { transform: translateX(0); box-shadow: var(--shadow-3); }
  .sidebar-toggle { display: flex; }
  .sidebar-backdrop.active { display: block; }
  .content { margin-left: 0; padding: 64px 32px 0; }
  .chapter-head .ghost-no { font-size: 90px; opacity: .8; }
}
@media (max-width: 768px) {
  .content { padding: 60px 18px 0; }
  .res-grid { grid-template-columns: 1fr; }
  .chapter-nav { grid-template-columns: 1fr; }
  .cn-link.next { text-align: left; align-items: flex-start; }
  .cn-link.next .cn-dir { flex-direction: row; }
  .fig { max-width: none; }
  .chapter-head { padding-top: 52px; }
  .footer-inner { flex-direction: column; align-items: flex-start; }
  .footer-credit { text-align: left; }
  .obj-box { padding-left: 24px; padding-top: 52px; }
  .obj-box::before { top: 14px; left: 20px; }
  .co { padding-left: 24px; padding-top: 48px; }
  .co .co-ic { top: 12px; left: 18px; }
  .doc-body h2 { font-size: 20px; }
}

@media print {
  .sidebar, .sidebar-toggle, .scroll-progress, .chapter-nav, .res-section, .site-footer, .lightbox { display: none !important; }
  .content { margin: 0; padding: 0; max-width: none; }
  .fig { box-shadow: none; rotate: none; }
}
