/* ==========================================================================
   Kami web reader · 紙
   Light: parchment #f5f4ed + ink #1B365D — Dark: #141413 + warm silver
   ========================================================================== */

/* Self-hosted LXGW WenKai (霞鹜文楷) subsets — book-only glyph set, ~450KB each.
   No external font CDN: fonts.googleapis.com is unreachable in mainland China.
   Subset from the OFL-1.1 upstream; see assets/fonts/OFL.txt. The two faces are
   Regular (400) and Medium (500) — LXGW WenKai has no Bold, so the Medium face
   declares the 500–700 range to keep 600/700 requests free of synthetic bold. */
@font-face {
  font-family: "Kami Serif";
  src: url("./fonts/kami-serif-w04.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Kami Serif";
  src: url("./fonts/kami-serif-w05.woff2") format("woff2");
  font-weight: 500 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f5f4ed;
  --bg-soft: #f0eee6;
  --surface: #faf9f5;
  --ink: #141413;
  --text: #33322f;
  --text-2: #504e49;
  --text-3: #6b6a64;
  --brand: #1B365D;
  --brand-hover: #14294a;
  --chip-bg: #E4ECF5;
  --line: #e8e6dc;
  --line-2: #e5e3d8;
  --code-bg: #faf9f5;
  --mark: #f1e5bd;
  --mark-ink: #141413;
  --shadow-lg: 0 24px 64px rgba(20, 20, 19, .18), 0 4px 16px rgba(20, 20, 19, .10);
  --serif: "Kami Serif", "LXGW WenKai", "Noto Serif SC", "Source Han Serif SC",
           "Songti SC", "STSong", Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Consolas,
          "Kami Serif", monospace;
  --side-w: 300px;
  --measure: 46rem;
}
[data-theme="dark"] {
  --bg: #141413;
  --bg-soft: #191917;
  --surface: #232321;
  --ink: #faf9f5;
  --text: #c9c7bd;
  --text-2: #b0aea5;
  --text-3: #8a897f;
  --brand: #93b4dc;
  --brand-hover: #b7cde8;
  --chip-bg: #1f2a3a;
  --line: #2c2b28;
  --line-2: #262523;
  --code-bg: #1d1d1b;
  --mark: #3f3d24;
  --mark-ink: #e8e4c8;
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, .5), 0 4px 16px rgba(0, 0, 0, .35);
}

/* ---------- base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.85;
  letter-spacing: .01em;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); }
::selection { background: var(--chip-bg); color: var(--ink); }
.skip {
  position: absolute; left: -999px; top: 8px; z-index: 99;
  background: var(--brand); color: #f5f4ed; padding: 6px 14px; border-radius: 6px;
}
.skip:focus { left: 8px; }

[data-fs="1"] .content { font-size: 18.5px; }
[data-fs="2"] .content { font-size: 20px; }

/* ---------- progress ---------- */
.progress {
  position: fixed; top: 0; left: 0; right: 0; height: 2px;
  background: transparent; z-index: 60; pointer-events: none;
}
#progress-bar { width: 0; height: 100%; background: var(--brand); transition: width .1s linear; }

/* ---------- sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 50;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  transition: transform .22s ease;
}
.side-head { padding: 18px 18px 10px; }
.brand { display: flex; gap: 11px; align-items: center; color: var(--ink); }
.brand:hover { color: var(--ink); }
.brand-mark {
  flex: none; width: 40px; height: 40px; border-radius: 9px;
  background: var(--brand); color: #f5f4ed;
  display: grid; place-items: center;
  font-size: 21px; font-weight: 500;
}
[data-theme="dark"] .brand-mark { color: #141413; }
.brand-text { display: flex; flex-direction: column; line-height: 1.35; }
.brand-text b { font-size: 15.5px; font-weight: 600; }
.brand-text i { font-style: normal; font-size: 11.5px; color: var(--text-3); letter-spacing: .04em; }

.search-btn {
  margin: 6px 16px 14px; display: flex; align-items: center; gap: 9px;
  width: calc(100% - 32px);
  background: var(--surface); color: var(--text-3);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; font: inherit; font-size: 13.5px; cursor: pointer;
  transition: border-color .16s ease, color .16s ease;
}
.search-btn:hover { border-color: var(--brand); color: var(--brand); }
.search-btn span { flex: 1; text-align: left; }
.search-btn kbd {
  font-family: var(--mono); font-size: 10.5px; color: var(--text-3);
  border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
}

.toc-tree { flex: 1; overflow-y: auto; padding: 2px 10px 28px; scrollbar-width: thin; }
.vol-group { margin-bottom: 6px; }
.vol-head {
  display: flex; align-items: baseline; gap: 8px;
  padding: 14px 10px 6px; color: var(--text-3);
}
.vol-name {
  font-size: 12px; font-weight: 600; letter-spacing: .14em;
  color: var(--brand);
}
.vol-desc { font-size: 11px; letter-spacing: .03em; }
.nav-ch, .nav-sec {
  align-items: baseline; gap: 8px;
  padding: 5.5px 10px; border-radius: 7px;
  color: var(--text-2); font-size: 14px; line-height: 1.5;
}
.nav-ch {
  display: flex; font-weight: 600; color: var(--ink); margin-top: 2px;
  cursor: pointer;
}
.nav-sec { display: flex; font-size: 13.5px; }
.nav-ch:hover, .nav-sec:hover { background: var(--surface); color: var(--brand); }
.nav-ch .chev {
  flex: none; margin: 4px 2px 0 0; color: var(--text-3); opacity: .7;
  transition: transform .22s ease, color .16s ease;
}
.vol-group.expanded .nav-ch .chev { transform: rotate(90deg); color: var(--brand); }
.nav-ch:hover .chev { color: var(--brand); opacity: 1; }
.nav-ch.current .nav-ch-t { color: var(--brand); }
.nav-no {
  flex: none; min-width: 34px;
  font-family: var(--mono); font-size: 11px; color: var(--text-3);
}
.nav-ch.active, .nav-sec.active {
  background: var(--chip-bg); color: var(--brand);
}
.nav-sec.active .nav-no { color: var(--brand); }
.nav-sub {
  display: grid; grid-template-rows: 0fr;
  transition: grid-template-rows .24s ease;
}
.nav-sub-in { overflow: hidden; min-height: 0; }
.vol-group.expanded .nav-sub { grid-template-rows: 1fr; }

/* ---------- main / topbar ---------- */
.main {
  margin-left: var(--side-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
}
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 28px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid var(--line-2);
  min-height: 54px;
}
.menu-btn { display: none; }
.crumbs {
  flex: 1; font-size: 12.5px; color: var(--text-3); letter-spacing: .05em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top-actions { display: flex; gap: 6px; }
.search-trigger { display: none; }
@media (max-width: 1100px) { .search-trigger { display: grid; } }
.icon-btn {
  display: grid; place-items: center;
  width: 36px; height: 36px; border-radius: 8px;
  background: transparent; border: none; color: var(--text-2);
  font-family: var(--serif); font-size: 14px; cursor: pointer;
  transition: background .12s ease, color .12s ease, scale .12s ease;
}
.icon-btn:active { scale: 0.96; }
.icon-btn:hover { background: var(--bg-soft); color: var(--brand); }
.icon-btn.fs-lifted { color: var(--brand); }
.ic-moon { display: none; }
[data-theme="dark"] .ic-sun { display: none; }
[data-theme="dark"] .ic-moon { display: block; }

/* ---------- layout ---------- */
.layout {
  display: flex; justify-content: center; gap: 56px;
  padding: 40px 40px 24px;
  flex: 1;
}
.content {
  width: 100%; max-width: var(--measure);
  font-size: 17px;
}
.content p { text-wrap: pretty; }
.content.swap-in { animation: fadeUp .16s ease; }
@keyframes fadeUp {
  from { opacity: .35; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- page head ---------- */
.crumb-line { display: none; }
.page-head { margin-bottom: 34px; }
.eyebrow {
  font-size: 11.5px; font-weight: 600; letter-spacing: .18em;
  color: var(--brand); text-transform: uppercase; margin-bottom: 10px;
}
.page-head h1 {
  font-size: 31px; font-weight: 600; line-height: 1.3; color: var(--ink);
  letter-spacing: .01em;
}
.sec-no { color: var(--brand); margin-right: 10px; }
.meta-line { margin-top: 10px; font-size: 12.5px; color: var(--text-3); }

/* ---------- content typography ---------- */
.content h2 {
  font-size: 21.5px; font-weight: 600; color: var(--ink);
  margin: 36px 0 12px; line-height: 1.4; letter-spacing: .01em;
}
.content h3 {
  font-size: 18px; font-weight: 600; color: var(--ink);
  margin: 32px 0 10px; line-height: 1.45;
}
.content h4, .content h5, .content h6 {
  font-size: 16.5px; font-weight: 600; color: var(--text-2);
  margin: 26px 0 8px;
}
.content p { margin: 0 0 15px; }
.content strong { font-weight: 600; color: var(--ink); }
.content ul, .content ol { margin: 0 0 16px; padding-left: 22px; }
.content li { margin-bottom: 6px; }
.content li::marker { color: var(--brand); }
.content li > ul, .content li > ol { margin: 6px 0 2px; }
.cbx { color: var(--brand); }

.content blockquote {
  margin: 18px 6px 18px 14px; padding: 2px 0 2px 16px;
  color: var(--text-2);
}
.content hr {
  border: none; border-top: 1px solid var(--line);
  margin: 34px 0;
}

.content code {
  font-family: var(--mono); font-size: .82em;
  background: var(--bg-soft); color: var(--text);
  padding: .12em .38em; border-radius: 5px;
  letter-spacing: 0;
}

/* ---------- code blocks ---------- */
.codeblock {
  position: relative; margin: 20px 0;
  background: var(--code-bg);
  border: 1px solid var(--line-2); border-radius: 10px;
}
.code-head {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--line-2);
}
.code-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--brand); opacity: .55;
}
.code-lang {
  flex: 1;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em;
  color: var(--text-3); text-transform: uppercase;
}
.code-copy {
  font-family: var(--serif); font-size: 11.5px; color: var(--text-3);
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  padding: 2px 9px; cursor: pointer;
  transition: color .16s ease, border-color .16s ease;
}
.code-copy:hover { color: var(--brand); border-color: var(--line); }
.code-copy.done { color: var(--brand); border-color: var(--brand); }
.codeblock .highlight { overflow-x: auto; }
.codeblock pre { margin: 0; padding: 14px 18px; background: transparent; }
.codeblock code, .codeblock pre {
  font-family: var(--mono); font-size: 13.2px; line-height: 1.65;
  letter-spacing: 0;
}

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; margin: 20px 0; }
.content table {
  width: 100%; border-collapse: collapse; font-size: 14.5px;
  line-height: 1.65; margin: 0;
}
.content th {
  text-align: left; font-weight: 600; color: var(--text-2);
  padding: 9px 12px; border-bottom: 1.5px solid var(--line);
  white-space: nowrap;
}
.content td {
  padding: 9px 12px; border-bottom: 1px solid var(--line-2);
  vertical-align: top;
}
.content table code { font-size: .82em; }
.content tbody tr { transition: background .12s ease; }
.content tbody tr:hover { background: var(--surface); }

/* content links: quiet underline on hover */
.content p a, .content li a, .content td a {
  text-underline-offset: 3px;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 1px;
  transition: text-decoration-color .16s ease;
}
.content p a:hover, .content li a:hover, .content td a:hover {
  text-decoration-color: var(--brand);
}

/* dark mode: print-designed images are parchment-white. Dim photographs, and
   invert mermaid plates so diagrams sit inside the dark page instead of
   glaring out of it (hue-rotate puts the brand hue back after inversion). */
[data-theme="dark"] .content figure img { filter: brightness(.86); }
[data-theme="dark"] .content figure.diagram img {
  filter: invert(.9) hue-rotate(180deg) brightness(1.02);
}

/* focus visibility */
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px;
}

/* ---------- figures / mermaid / math ---------- */
.content figure { margin: 26px 0; }
.content figure img {
  max-width: 100%; height: auto; display: block; margin: 0 auto;
  border: none;
  outline: 1px solid rgba(0, 0, 0, .1);
  border-radius: 10px;
  background: var(--bg);
}
[data-theme="dark"] .content figure img { outline: 1px solid rgba(255, 255, 255, .1); }
.content figure.diagram img { max-width: min(100%, 860px); }
.content figcaption {
  font-size: 13px; color: var(--text-3); text-align: center; margin-top: 10px;
}
div.math { margin: 22px 0; overflow-x: auto; }
div.math svg { max-width: 100%; }

/* ---------- pager ---------- */
.pager-wrap {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  margin: 60px 0 30px; padding-top: 26px;
  border-top: 1px solid var(--line);
}
.pager-card {
  display: flex; flex-direction: column; gap: 3px;
  padding: 14px 16px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line-2);
  color: var(--text-2);
  transition: border-color .16s ease, transform .16s ease;
}
.pager-card:hover { border-color: var(--brand); color: var(--brand); transform: translateY(-1px); }
.pager-card span { font-size: 11px; letter-spacing: .12em; color: var(--text-3); }
.pager-card b { font-size: 14.5px; font-weight: 600; color: var(--ink); }
.pager-card:hover b { color: var(--brand); }
.pager-card.next { text-align: right; }

/* ---------- license / attribution note (every page) ---------- */
/* last child of .content — the bottom space must be padding, not margin:
   a margin here collapses out of the flex item and disappears, which would
   let the floating to-top button sit on top of the last line. */
.lic-note {
  margin: 0; padding: 14px 0 56px;
  border-top: 1px solid var(--line);
  font-size: 11.5px; line-height: 1.8; color: var(--text-3);
}
.lic-note a { color: var(--text-2); text-decoration: underline; text-underline-offset: 2px; }
.lic-note a:hover { color: var(--brand); }
@media print { .lic-note { font-size: 9pt; break-inside: avoid; } }

/* ---------- 404 ---------- */
.notfound { padding: 8vh 0 0; text-align: center; }
.notfound .nf-code {
  margin: 0; font-size: 76px; line-height: 1; font-weight: 600;
  color: var(--line-2); letter-spacing: .04em;
}
.notfound h1 { margin: 10px 0 14px; font-size: 26px; color: var(--ink); }
.notfound .nf-hint { margin: 0 0 26px; font-size: 14px; color: var(--text-3); }
.notfound .nf-links { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 0 0 26px; }
.notfound kbd {
  padding: 1px 5px; border-radius: 5px; font-size: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text-2);
}
@media (max-width: 640px) { .notfound .nf-code { font-size: 56px; } .notfound h1 { font-size: 21px; } }

/* ---------- outline (right rail) ---------- */
.outline { display: none; }
@media (min-width: 1380px) {
  .outline {
    display: block; width: 230px; flex: none;
    position: sticky; top: 92px; align-self: flex-start;
    max-height: calc(100vh - 140px); overflow-y: auto;
    font-size: 12.5px;
  }
  .outline-title {
    font-size: 11px; font-weight: 600; letter-spacing: .16em;
    color: var(--text-3); margin-bottom: 10px;
  }
  .outline a {
    display: block; padding: 4.5px 0 4.5px 12px;
    color: var(--text-3); line-height: 1.5;
    border-left: 1.5px solid var(--line);
  }
  .outline a.lv1 { padding-left: 12px; font-weight: 600; color: var(--text-2); }
  .outline a.lv3 { padding-left: 26px; font-size: 12px; }
  /* h3 entries only show inside the section you are currently reading */
  .outline a.lv3.collapsed { display: none; }
  .outline a:hover { color: var(--brand); }
  .outline a.active {
    color: var(--brand); border-left-color: var(--brand); font-weight: 600;
  }
}

/* ---------- search overlay ---------- */
.mask {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(20, 20, 19, .45);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.mask.show { opacity: 1; pointer-events: auto; }
.search-layer {
  position: fixed; inset: 0; z-index: 80;
  display: flex; justify-content: center; align-items: flex-start;
  padding: 12vh 20px 40px;
  background: rgba(20, 20, 19, .35);
  backdrop-filter: blur(3px);
}
.search-layer[hidden] { display: none; }
.search-panel {
  width: 100%; max-width: 660px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.search-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--line-2);
  color: var(--text-3);
}
#search-input {
  flex: 1; border: none; outline: none; background: transparent;
  font: inherit; font-size: 16.5px; color: var(--ink);
}
.search-results { max-height: 56vh; overflow-y: auto; padding: 8px; }
.search-hint { padding: 18px 14px; font-size: 13px; color: var(--text-3); }
.search-hit {
  display: block; padding: 10px 14px; border-radius: 9px; color: var(--text);
}
.search-hit:hover, .search-hit.sel { background: var(--bg-soft); }
.search-hit .hit-title { font-size: 14.5px; font-weight: 600; color: var(--ink); }
.search-hit .hit-crumb { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.search-hit mark, .content mark {
  background: var(--mark); color: var(--mark-ink);
  padding: 0 .1em; border-radius: 3px;
}
.search-empty { padding: 22px 14px; font-size: 13.5px; color: var(--text-3); }
.search-status {
  padding: 7px 14px 8px; margin-bottom: 4px;
  font-size: 11.5px; color: var(--text-3);
  border-bottom: 1px solid var(--line-2);
  font-variant-numeric: tabular-nums;
}
.search-foot {
  padding: 9px 16px; border-top: 1px solid var(--line-2);
  font-size: 11.5px; color: var(--text-3); text-align: center;
}
.search-foot kbd {
  font-family: var(--mono); font-size: 10.5px; color: var(--text-2);
  border: 1px solid var(--line); border-radius: 4px;
  padding: 0 4px; margin: 0 1px;
}

/* ---------- home ---------- */
.home .layout { display: block; max-width: 1080px; margin: 0 auto; width: 100%; }
.home-hero { position: relative; padding: 64px 0 40px; max-width: 720px; overflow: hidden; }
.home-hero::before {
  content: "紙";
  position: absolute; right: -140px; top: -50px;
  font-size: 340px; font-weight: 500; line-height: 1;
  color: var(--brand); opacity: .045;
  pointer-events: none; user-select: none;
}
.hero-stats {
  display: flex; align-items: center; gap: 14px;
  margin: 0 0 26px; font-size: 13px; color: var(--text-3);
}
.hero-stats b {
  font-size: 17px; font-weight: 600; color: var(--brand);
  margin-right: 3px; font-variant-numeric: tabular-nums;
}
.hero-stats i {
  width: 1px; height: 12px; background: var(--line);
  display: inline-block;
}
.hero-eyebrow {
  font-size: 11.5px; font-weight: 600; letter-spacing: .22em;
  color: var(--brand); margin-bottom: 18px;
}
.home-hero h1 {
  font-size: clamp(40px, 6vw, 62px); font-weight: 600;
  color: var(--ink); line-height: 1.15; letter-spacing: .01em;
  margin-bottom: 14px;
}
.hero-sub { font-size: 20px; color: var(--text-2); margin-bottom: 18px; }
.hero-meta { font-size: 13.5px; color: var(--text-3); margin-bottom: 30px; }
.hero-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 22px; border-radius: 999px;
  font-size: 15px; font-weight: 600;
  transition: scale .12s ease, transform .16s ease, background .16s ease,
              color .16s ease, border-color .16s ease;
}
.btn:active { scale: 0.96; }
.btn[hidden], [hidden].btn { display: none !important; }
/* one-shot staggered hero entrance (infrequent; killed under reduced motion) */
.hero-eyebrow, .home-hero h1, .hero-sub, .hero-stats, .hero-meta, .hero-actions, .hero-src {
  animation: fadeUp .3s ease both;
}
.hero-sub     { animation-delay: .06s; }
.hero-stats   { animation-delay: .12s; }
.hero-meta    { animation-delay: .16s; }
.hero-actions { animation-delay: .22s; }
.hero-src     { animation-delay: .28s; }
.btn-primary { background: var(--brand); color: #f5f4ed; }
.btn-primary:hover { background: var(--brand-hover); color: #f5f4ed; transform: translateY(-1px); }
[data-theme="dark"] .btn-primary { color: #141413; }
[data-theme="dark"] .btn-primary:hover { color: #141413; }
.btn-ghost { color: var(--brand); border: 1px solid var(--line); background: transparent; }
.btn-ghost:hover { border-color: var(--brand); }
.hero-src { margin-top: 26px; font-size: 12px; color: var(--text-3); }
.home-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(420px, 100%), 1fr));
  gap: 22px; padding: 30px 0 70px;
}
.home-vol {
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 12px; padding: 22px 24px;
}
.home-vol-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.home-vol-label {
  flex: none; font-size: 12px; font-weight: 600; letter-spacing: .1em;
  color: var(--brand); background: var(--chip-bg);
  border-radius: 6px; padding: 3px 9px;
}
.home-vol-head h2 { font-size: 16.5px; font-weight: 600; color: var(--ink); }
.home-chs { list-style: none; columns: 2; column-gap: 24px; }
.home-chs li {
  break-inside: avoid; margin-bottom: 8px;
  font-size: 13.5px; line-height: 1.55;
}
.home-chs a { color: var(--text-2); display: block; }
.home-chs a:hover { color: var(--brand); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; }
  .menu-btn { display: grid; }
  .layout { padding: 28px 22px 20px; }
}
@media (max-width: 640px) {
  body { font-size: 16.5px; }
  .topbar { padding: 10px 14px; gap: 8px; }
  .crumbs { font-size: 11.5px; letter-spacing: .02em; }
  .layout { padding: 20px 16px 16px; }
  .page-head h1 { font-size: 25px; }
  .content h2 { font-size: 19.5px; }
  .pager-wrap { grid-template-columns: 1fr; }
  .home-chs { columns: 1; }
  .home-hero::before { font-size: 220px; top: -34px; right: -70px; }
}

/* ---------- lightbox / to-top / progress loading ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(20, 20, 19, .82);
  display: none; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px; cursor: zoom-out;
}
.lightbox.show { display: flex; }
.lightbox img {
  max-width: 94vw; max-height: 86vh; height: auto;
  background: var(--bg); border-radius: 10px;
}
.lightbox-cap { margin-top: 14px; font-size: 13px; color: #b0aea5; }

.to-top {
  position: fixed; right: 26px; bottom: 26px; z-index: 45;
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--surface); color: var(--text-2);
  border: 1px solid var(--line);
  display: grid; place-items: center; cursor: pointer;
  opacity: 0; pointer-events: none; transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease, scale .12s ease,
              color .16s ease, border-color .16s ease;
}
.to-top:active { scale: 0.96; }
.to-top.show { opacity: 1; pointer-events: auto; transform: none; }
.to-top:hover { color: var(--brand); border-color: var(--brand); }

.progress.loading #progress-bar {
  width: 30% !important;
  animation: bar-slide 1s ease-in-out infinite;
}
@keyframes bar-slide {
  0% { margin-left: -30%; }
  100% { margin-left: 100%; }
}

/* ---------- search hit snippet ---------- */
.hit-line { display: flex; align-items: baseline; gap: 8px; }
.hit-line .hit-title { flex: 1; }
.hit-count {
  flex: none; font-family: var(--mono); font-size: 10.5px;
  color: var(--brand); background: var(--chip-bg);
  border-radius: 5px; padding: 1px 6px;
}
.hit-snippet {
  margin-top: 3px; font-size: 12.5px; color: var(--text-3); line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* search overlay exit fade */
.search-layer { opacity: 1; transition: opacity .15s ease; }
.search-layer.closing { opacity: 0; }
@media print {
  /* force the light palette so dark mode never prints white-on-white */
  :root, [data-theme="dark"] {
    --bg: #fff; --bg-soft: #f7f7f6; --surface: #fff;
    --ink: #111; --text: #111; --text-2: #333; --text-3: #555;
    --brand: #1B365D; --brand-hover: #14294a;
    --line: #ddd; --line-2: #eee; --code-bg: #fafafa;
    --mark: #f1e5bd; --mark-ink: #111;
  }
  .sidebar, .topbar, .pager, .outline, .progress, .search-layer, .mask,
  .code-copy, .crumb-line, .to-top { display: none !important; }
  .main { margin: 0; }
  body { background: #fff; color: #111; }
  .content a { text-decoration: none; }
  .content figure img { filter: none !important; }
  .content h1, .content h2, .content h3 { break-after: avoid; }
  .content figure, .content table, .codeblock { break-inside: avoid; }
}
