:root {
  color-scheme: light;
  --bg: #f5f1e8;
  --surface: #fffdf8;
  --surface-soft: #eee8dc;
  --ink: #24211d;
  --muted: #6e685f;
  --line: #d9d1c3;
  --accent: #b43b2f;
  --accent-soft: #f3ddd7;
  --code-bg: #201e1b;
  --code-ink: #f5efe5;
  --shadow: 0 18px 50px rgba(58, 45, 27, .10);
  --serif: "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", Georgia, serif;
  --sans: "Noto Sans CJK SC", "Source Han Sans SC", system-ui, sans-serif;
  --mono: "Noto Sans Mono CJK SC", "SFMono-Regular", Consolas, monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171614;
  --surface: #211f1c;
  --surface-soft: #2c2925;
  --ink: #eee9df;
  --muted: #afa89d;
  --line: #403b35;
  --accent: #ed8375;
  --accent-soft: #482a26;
  --code-bg: #11100f;
  --code-ink: #eee9df;
  --shadow: 0 18px 50px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.78;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-underline-offset: .18em; }
img { max-width: 100%; height: auto; }
button, input { font: inherit; }

.skip-link {
  position: fixed;
  top: .75rem;
  left: .75rem;
  z-index: 100;
  transform: translateY(-150%);
  padding: .55rem .8rem;
  background: var(--ink);
  color: var(--bg);
  border-radius: .35rem;
}
.skip-link:focus { transform: none; }

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  height: 4rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.25rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.brand {
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.08rem;
  font-weight: 800;
  text-decoration: none;
}
.brand small { color: var(--muted); font-family: var(--sans); font-weight: 500; }
.topbar-actions { display: flex; gap: .5rem; margin-left: auto; }
.icon-button {
  min-height: 2.35rem;
  padding: .4rem .7rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: .5rem;
  cursor: pointer;
}
.icon-button:hover { color: var(--ink); background: var(--surface-soft); }
.menu-button { display: none; }

.layout { display: grid; grid-template-columns: 19rem minmax(0, 1fr); min-height: 100vh; padding-top: 4rem; }
.sidebar {
  position: fixed;
  top: 4rem;
  bottom: 0;
  width: 19rem;
  padding: 1.25rem 1rem 2rem;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.search {
  width: 100%;
  padding: .72rem .85rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: .55rem;
  outline: none;
}
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-hint { margin: .35rem .1rem 1rem; color: var(--muted); font-size: .75rem; }
.book-nav { display: grid; gap: .14rem; }
.book-nav a {
  display: block;
  padding: .45rem .6rem;
  border-radius: .42rem;
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.35;
  text-decoration: none;
}
.book-nav a:hover { color: var(--ink); background: var(--surface-soft); }
.book-nav a.current { color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.search-results { display: grid; gap: .4rem; }
.search-results a { padding: .65rem; background: var(--surface-soft); border-radius: .5rem; text-decoration: none; }
.search-results strong, .search-results span { display: block; }
.search-results strong { color: var(--ink); font-size: .86rem; }
.search-results span { margin-top: .2rem; color: var(--muted); font-size: .75rem; line-height: 1.45; }
.empty-search { color: var(--muted); font-size: .85rem; }

.main { grid-column: 2; min-width: 0; }
.reading-column { width: min(100% - 3rem, 54rem); margin: 0 auto; padding: 4rem 0 6rem; }
.article-card {
  padding: clamp(2rem, 5vw, 4.5rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: .8rem;
  box-shadow: var(--shadow);
}
.article-card h1, .article-card h2, .article-card h3, .article-card h4 {
  scroll-margin-top: 5.5rem;
  font-family: var(--serif);
  line-height: 1.28;
}
.article-card h1 { margin: 0 0 2.5rem; font-size: clamp(2rem, 5vw, 3.35rem); letter-spacing: -.035em; }
.article-card h2 { margin: 3rem 0 1rem; padding-top: .6rem; border-top: 1px solid var(--line); font-size: 1.75rem; }
.article-card h3 { margin: 2.25rem 0 .75rem; font-size: 1.35rem; }
.article-card h4 { margin-top: 1.75rem; font-size: 1.08rem; }
.article-card p { margin: 1.05rem 0; }
.article-card blockquote {
  margin: 1.5rem 0;
  padding: .7rem 1.25rem;
  color: var(--muted);
  background: var(--surface-soft);
  border-left: .25rem solid var(--accent);
}
.article-card table { width: 100%; margin: 1.5rem 0; border-collapse: collapse; font-size: .92rem; }
.article-card th, .article-card td { padding: .6rem .7rem; border: 1px solid var(--line); text-align: left; }
.article-card th { background: var(--surface-soft); }
.article-card :not(pre) > code {
  padding: .12em .35em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: .25rem;
  font-family: var(--mono);
  font-size: .88em;
}
pre {
  position: relative;
  max-width: 100%;
  margin: 1.5rem 0;
  padding: 1.15rem 1.25rem;
  overflow-x: auto;
  color: var(--code-ink);
  background: var(--code-bg);
  border-radius: .55rem;
  font-family: var(--mono);
  font-size: .84rem;
  line-height: 1.6;
}
pre code { font-family: inherit; }
.copy-code {
  position: absolute;
  top: .45rem;
  right: .45rem;
  padding: .25rem .45rem;
  color: #cbc3b5;
  background: #34312d;
  border: 1px solid #4a4640;
  border-radius: .3rem;
  cursor: pointer;
  font-size: .72rem;
  opacity: 0;
}
pre:hover .copy-code, .copy-code:focus { opacity: 1; }
.article-card figure, .article-card > p:has(> img:only-child) { margin: 2rem auto; text-align: center; }
.article-card img { border-radius: .35rem; }
.chapter-toc { margin: 0 0 2rem; padding: 1rem 1.25rem; background: var(--surface-soft); border-radius: .55rem; }
.chapter-toc summary { cursor: pointer; font-weight: 700; }
.chapter-toc ul { columns: 2; padding-left: 1.2rem; }
.chapter-toc li { break-inside: avoid; }
.chapter-toc a { color: var(--muted); font-size: .86rem; text-decoration: none; }

.chapter-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.5rem; }
.chapter-pager a {
  display: flex;
  flex-direction: column;
  padding: 1rem 1.15rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: .65rem;
  text-decoration: none;
}
.chapter-pager a:last-child { text-align: right; }
.chapter-pager span { color: var(--muted); font-size: .75rem; }
.chapter-pager strong { margin-top: .2rem; color: var(--accent); }

.hero { min-height: calc(100vh - 4rem); display: grid; place-items: center; padding: 5rem 1.5rem; }
.hero-inner { width: min(100%, 62rem); }
.eyebrow { color: var(--accent); font-size: .78rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.hero h1 { max-width: 12ch; margin: .5rem 0 1rem; font-family: var(--serif); font-size: clamp(3rem, 9vw, 6.8rem); line-height: .98; letter-spacing: -.06em; }
.hero .subtitle { max-width: 40rem; color: var(--muted); font-family: var(--serif); font-size: clamp(1.1rem, 2.5vw, 1.55rem); }
.hero-actions { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 2rem; }
.primary-link, .secondary-link { padding: .75rem 1rem; border-radius: .5rem; font-weight: 700; text-decoration: none; }
.primary-link { color: #fff; background: var(--accent); }
.secondary-link { color: var(--ink); border: 1px solid var(--line); }
.meta-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 4rem; }
.meta-card { padding: 1.25rem; background: var(--surface); border: 1px solid var(--line); border-radius: .65rem; }
.meta-card strong, .meta-card span { display: block; }
.meta-card strong { font-family: var(--serif); font-size: 1.5rem; }
.meta-card span { color: var(--muted); font-size: .82rem; }
.site-footer { margin-top: 4rem; color: var(--muted); font-size: .8rem; }

.codehilite .hll { background-color: #49483e; }
.codehilite .c, .codehilite .ch, .codehilite .cm, .codehilite .c1, .codehilite .cs { color: #8f897d; font-style: italic; }
.codehilite .k, .codehilite .kc, .codehilite .kd, .codehilite .kn, .codehilite .kp, .codehilite .kr, .codehilite .kt { color: #f08b7e; font-weight: 700; }
.codehilite .s, .codehilite .sa, .codehilite .sb, .codehilite .sc, .codehilite .dl, .codehilite .sd, .codehilite .s1, .codehilite .s2 { color: #d8d68f; }
.codehilite .m, .codehilite .mb, .codehilite .mf, .codehilite .mh, .codehilite .mi, .codehilite .mo { color: #b9a6e8; }
.codehilite .na, .codehilite .nb, .codehilite .nc, .codehilite .nd, .codehilite .ne, .codehilite .nf, .codehilite .ni, .codehilite .nn, .codehilite .nt { color: #8ccbd2; }
.codehilite .o, .codehilite .ow { color: #f2eee7; }

@media (max-width: 860px) {
  .menu-button { display: inline-block; }
  .brand small { display: none; }
  .layout { display: block; }
  .sidebar { z-index: 25; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .menu-open .sidebar { transform: none; }
  .main { display: block; }
  .reading-column { width: min(100% - 1.25rem, 54rem); padding: 1rem 0 4rem; }
  .article-card { padding: 1.5rem; }
  .chapter-toc ul { columns: 1; }
  .meta-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .topbar { padding: 0 .7rem; }
  .icon-button { padding: .35rem .5rem; font-size: .78rem; }
  .article-card { padding: 1.2rem; border-radius: .5rem; }
  .chapter-pager { grid-template-columns: 1fr; }
  .chapter-pager a:last-child { text-align: left; }
}

@media print {
  :root { color-scheme: light; --bg: #fff; --surface: #fff; --ink: #111; --muted: #555; --line: #ccc; --code-bg: #f3f3f3; --code-ink: #111; }
  .topbar, .sidebar, .chapter-pager, .chapter-toc, .copy-code { display: none !important; }
  .layout, .main { display: block; padding: 0; }
  .reading-column { width: auto; padding: 0; }
  .article-card { padding: 0; border: 0; box-shadow: none; }
  a { color: inherit; text-decoration: none; }
  pre { white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid #ddd; }
}

