:root {
  --bg: #f6f2ea;
  --paper: #fffdf8;
  --text: #2b2a26;
  --muted: #8a857a;
  --accent: #b4552d;
  --accent-soft: rgba(180, 85, 45, .12);
  --line: #e4dccd;
  --fs: 18px;
}
html.dark {
  --bg: #14161a;
  --paper: #1b1e24;
  --text: #c6c4bc;
  --muted: #7b786f;
  --accent: #d98d5f;
  --accent-soft: rgba(217, 141, 95, .16);
  --line: #2b2f37;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
  font-size: var(--fs);
  line-height: 2;
}
button { font-family: "Noto Sans SC", "Microsoft YaHei", sans-serif; }

/* ---------- top bar ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 52px; z-index: 50;
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
#topbar .title { font-size: 16px; font-weight: 700; font-family: "Noto Sans SC", sans-serif; }
#topbar .title span { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 8px; }
#topbar .tools { margin-left: auto; display: flex; gap: 6px; }
#topbar button {
  border: 1px solid var(--line); background: var(--paper); color: var(--text);
  border-radius: 8px; width: 34px; height: 32px; font-size: 14px; cursor: pointer;
}
#topbar button:hover { border-color: var(--accent); color: var(--accent); }
#progress {
  position: absolute; left: 0; bottom: -1px; height: 2px; width: 0;
  background: var(--accent); transition: width .15s;
}
#searchbar {
  position: fixed; top: 52px; left: 0; right: 0; z-index: 49;
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid var(--line);
}
#searchbar input {
  flex: 0 1 420px; padding: 7px 12px; border-radius: 8px; font-size: 14px;
  border: 1px solid var(--line); background: var(--paper); color: var(--text);
  font-family: "Noto Sans SC", sans-serif;
}
#searchbar input:focus { outline: none; border-color: var(--accent); }
#qinfo { font-size: 12px; color: var(--muted); font-family: "Noto Sans SC", sans-serif; }

/* ---------- sidebar ---------- */
#sidebar {
  position: fixed; top: 52px; bottom: 0; left: 0; width: 288px; z-index: 45;
  overflow-y: auto; padding: 14px 10px 40px;
  background: var(--bg); border-right: 1px solid var(--line);
  transform: translateX(-100%); transition: transform .25s;
}
#sidebar.open { transform: none; }
.side-head {
  font-family: "Noto Sans SC", sans-serif; font-weight: 700; letter-spacing: .4em;
  color: var(--muted); font-size: 14px; padding: 6px 10px 10px;
}
#toc { list-style: none; margin: 0; padding: 0; font-family: "Noto Sans SC", sans-serif; }
#toc a {
  display: block; padding: 6px 10px; border-radius: 8px; text-decoration: none;
  color: var(--text); font-size: 14px; line-height: 1.5;
}
#toc a:hover { background: var(--accent-soft); color: var(--accent); }
#toc a.toc-ch { font-weight: 600; }
#toc ul { list-style: none; margin: 0; padding: 0 0 4px 14px; }
#toc ul a { font-weight: 400; font-size: 13px; color: var(--muted); padding: 3px 10px; }
#toc a.active { background: var(--accent-soft); color: var(--accent); }
#mask { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.35); opacity: 0; pointer-events: none; transition: opacity .25s; }
#mask.show { opacity: 1; pointer-events: auto; }

/* ---------- content ---------- */
#wrap { margin: 0 auto; padding: 92px 20px 60px; max-width: 820px; }
@media (min-width: 1280px) { #wrap { margin-left: calc(50% - 310px); } }
#content {
  background: var(--paper); border: 1px solid var(--line); border-radius: 14px;
  padding: 46px clamp(20px, 6vw, 64px) 60px;
}
h1 {
  font-family: "Noto Sans SC", sans-serif; font-size: 1.7em; line-height: 1.5;
  margin: .6em 0 1em; color: var(--text);
}
.chapter h1 { border-bottom: 3px solid var(--accent); padding-bottom: .4em; }
h2 {
  font-family: "Noto Sans SC", sans-serif; font-size: 1.28em; line-height: 1.6;
  margin: 2em 0 .8em; color: var(--accent);
}
h3 { font-family: "Noto Sans SC", sans-serif; font-size: 1.1em; margin: 1.6em 0 .6em; }
h4 { font-family: "Noto Sans SC", sans-serif; font-size: 1.02em; margin: 1.6em 0 .5em; }
p { margin: 0 0 1.15em; text-align: justify; text-indent: 2em; }
h2 + p, h3 + p, h4 + p { text-indent: 2em; }
.fn {
  font-size: .78em; color: var(--muted); line-height: 1.8;
  border-top: 1px solid var(--line); padding: 8px 4px 2px; margin: 14px 0 18px;
  text-align: justify;
}

/* ---------- figures ---------- */
figure {
  margin: 1.6em auto; padding: 10px; text-align: center;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  max-width: 100%;
}
html.dark figure { background: #23262d; }
figure img { max-width: 100%; height: auto; border-radius: 4px; cursor: pointer; }
figcaption { font-size: .8em; color: var(--muted); margin-top: 6px; font-family: "Noto Sans SC", sans-serif; }
figure.pulse {
  animation: figpulse 2.2s ease;
  border-color: var(--accent);
}
@keyframes figpulse {
  0% { box-shadow: 0 0 0 0 rgba(180,85,45,.0); }
  12% { box-shadow: 0 0 0 6px rgba(180,85,45,.45); background: var(--accent-soft); }
  45% { box-shadow: 0 0 0 3px rgba(180,85,45,.28); }
  100% { box-shadow: 0 0 0 0 rgba(180,85,45,0); }
}

/* clickable figure references */
.figref {
  color: var(--accent); cursor: pointer; font-weight: 600;
  border-bottom: 1px dashed var(--accent); padding: 0 1px;
}
.figref:hover { background: var(--accent-soft); }
p.pulse, h2.pulse { animation: figpulse 2.2s ease; border-radius: 6px; }

/* ---------- cover ---------- */
#cover { text-align: center; padding: 72px 20px 64px; background: #191a1c; color: #efe9dc; border: none; }
.cover-badge {
  display: inline-block; font-family: "Noto Sans SC", sans-serif; font-size: 13px;
  letter-spacing: .3em; border: 1px solid #6b6455; color: #cdc4ae;
  padding: 4px 14px 4px 17px; border-radius: 999px; margin-bottom: 40px;
}
.cover-title { font-size: 3.2em; letter-spacing: .12em; margin: 0 0 8px; color: #f5efe2; border: none; }
.cover-sub { font-size: 1.25em; letter-spacing: .28em; color: #cdc4ae; text-indent: 0; margin: 0 0 44px; }
.cover-meta { font-size: .85em; line-height: 2.1; color: #97917f; text-indent: 0; }

#colophon { text-align: center; color: var(--muted); font-size: 12.5px; padding: 30px 10px 46px; font-family: "Noto Sans SC", sans-serif; }

#backtop {
  position: fixed; right: 22px; bottom: 26px; z-index: 46; width: 42px; height: 42px;
  border-radius: 50%; border: 1px solid var(--line); background: var(--paper); color: var(--text);
  font-size: 17px; cursor: pointer; opacity: 0; pointer-events: none; transition: opacity .25s;
}
#backtop.show { opacity: 1; pointer-events: auto; }

mark { background: rgba(217, 141, 95, .45); color: inherit; border-radius: 2px; padding: 0 1px; }
#hit.pulse { animation: figpulse 2s ease; }

@media (max-width: 900px) {
  #topbar .title span { display: none; }
  #wrap { padding: 80px 10px 40px; }
  #content { padding: 30px 18px 44px; border-radius: 10px; }
}
