:root {
  --bg: #f6f1e6;
  --paper: #fffcf5;
  --ink: #241f19;
  --muted: #6f6355;
  --faint: #9a8d7c;
  --accent: #8c2f2f;
  --accent-2: #b4553f;
  --line: #ded2bd;
  --line-soft: #eae1d1;
  --highlight: rgba(188, 146, 58, 0.24);
  --shadow: 0 18px 50px rgba(70, 50, 20, 0.10);
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", STSong, "SimSun", serif;
  --sans: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --reader-size: 18px;
}

[data-theme="dark"] {
  --bg: #131110;
  --paper: #1b1815;
  --ink: #e8dfd1;
  --muted: #a99b88;
  --faint: #7d7264;
  --accent: #d08a76;
  --accent-2: #e0a48e;
  --line: #342d26;
  --line-soft: #29231e;
  --highlight: rgba(205, 165, 85, 0.18);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(180, 140, 70, 0.07), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(140, 47, 47, 0.05), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }

::selection { background: rgba(140, 47, 47, 0.18); }

/* ---------- top bar ---------- */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 60;
  height: 62px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  font-family: var(--sans);
  font-weight: 700;
  letter-spacing: .14em;
  font-size: 15px;
  white-space: nowrap;
}
.brand span { color: var(--accent); }

.topnav { display: flex; gap: 6px; margin-left: 10px; }
.topnav a {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 999px;
  transition: .18s;
}
.topnav a:hover, .topnav a.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 9%, transparent); }

.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 7px 11px;
  cursor: pointer;
  transition: .18s;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn:active { transform: translateY(1px); }

.progress {
  position: fixed;
  z-index: 70;
  top: 61px; left: 0;
  height: 2px;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .08s linear;
}

/* ---------- cover / index ---------- */
.cover {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 120px 24px 80px;
  position: relative;
  overflow: hidden;
}
.cover::before {
  content: "";
  position: absolute;
  width: 70vmin; height: 70vmin;
  border: 1px solid var(--line);
  border-radius: 50%;
  opacity: .5;
  pointer-events: none;
}
.cover::after {
  content: "舊邦新命";
  position: absolute;
  right: -2vw; bottom: -8vh;
  font-size: 24vw;
  line-height: 1;
  color: var(--ink);
  opacity: .028;
  writing-mode: vertical-rl;
  letter-spacing: .12em;
  pointer-events: none;
}
.cover-kicker {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: .42em;
  color: var(--accent);
  text-transform: uppercase;
  margin-bottom: 28px;
}
.cover h1 {
  margin: 0;
  font-size: clamp(64px, 14vw, 148px);
  line-height: .95;
  letter-spacing: .08em;
  font-weight: 700;
}
.cover .sub {
  margin: 26px 0 0;
  font-family: var(--sans);
  font-size: clamp(14px, 2vw, 18px);
  color: var(--muted);
  letter-spacing: .08em;
}
.cover blockquote {
  margin: 34px 0 0;
  color: var(--faint);
  font-size: 15px;
  line-height: 1.9;
}
.cover .cover-meta {
  margin-top: 28px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--faint);
  letter-spacing: .18em;
}
.cover-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 38px; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 14px;
  letter-spacing: .08em;
  padding: 13px 24px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  color: var(--accent);
  transition: .2s;
}
.btn:hover { background: var(--accent); color: var(--paper); transform: translateY(-1px); }
.btn.primary { background: var(--accent); color: #fff8ee; }
.btn.primary:hover { background: #732424; }

.scroll-hint {
  margin-top: 56px;
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: .25em;
  color: var(--faint);
  animation: floaty 2.4s ease-in-out infinite;
}
@keyframes floaty { 0%,100%{transform:translateY(0)} 50%{transform:translateY(7px)} }

/* ---------- index sections ---------- */
.wrap { width: min(1080px, calc(100% - 48px)); margin: 0 auto; }
.section { padding: 78px 0; border-top: 1px solid var(--line-soft); }
.section-head { display: flex; align-items: baseline; gap: 18px; margin-bottom: 34px; }
.section-head .num {
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: .3em;
  color: var(--accent);
}
.section-head h2 { margin: 0; font-size: clamp(24px, 3.4vw, 34px); letter-spacing: .06em; }
.section-head .line { flex: 1; height: 1px; background: var(--line); }

.lead { font-size: 17px; line-height: 2; color: var(--muted); max-width: 760px; }
.lead em { color: var(--ink); font-style: normal; border-bottom: 1px solid var(--accent); }

.artifacts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 34px; }
.artifact {
  background: var(--paper);
  border: 1px solid var(--line-soft);
  border-radius: 18px;
  padding: 26px 24px;
  box-shadow: var(--shadow);
}
.artifact .sigil {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  color: var(--accent);
  font-size: 20px;
  margin-bottom: 18px;
}
.artifact h3 { margin: 0 0 10px; font-size: 18px; letter-spacing: .04em; }
.artifact p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.9; }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; counter-reset: step; }
.step { padding: 24px 22px; border-top: 2px solid var(--line); position: relative; }
.step::before {
  counter-increment: step; content: "0" counter(step);
  font-family: var(--sans); font-size: 12px; letter-spacing: .2em; color: var(--accent);
}
.step h3 { margin: 12px 0 8px; font-size: 17px; }
.step p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.9; }

.timeline { display: grid; gap: 0; margin-top: 10px; }
.tl-item {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 24px;
  padding: 22px 0;
  border-bottom: 1px solid var(--line-soft);
}
.tl-item .yr { font-family: var(--sans); font-size: 13px; color: var(--accent); letter-spacing: .08em; padding-top: 4px; }
.tl-item h3 { margin: 0 0 6px; font-size: 19px; }
.tl-item p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.85; }

/* ---------- reader layout ---------- */
.reader-hero {
  padding: 130px 24px 54px;
  text-align: center;
  border-bottom: 1px solid var(--line-soft);
}
.reader-hero .kicker { font-family: var(--sans); font-size: 11px; letter-spacing: .35em; color: var(--accent); }
.reader-hero h1 { margin: 18px 0 12px; font-size: clamp(38px, 7vw, 64px); letter-spacing: .08em; }
.reader-hero p { margin: 0 auto; max-width: 640px; color: var(--muted); font-size: 15px; line-height: 1.9; }
.reader-hero .meta { margin-top: 18px; font-family: var(--sans); font-size: 12px; color: var(--faint); letter-spacing: .15em; }

.layout {
  display: grid;
  grid-template-columns: 272px minmax(0, 760px);
  gap: clamp(28px, 5vw, 64px);
  justify-content: center;
  padding: 54px 24px 100px;
  align-items: start;
}

.toc {
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 110px);
  overflow: auto;
  padding-right: 10px;
  font-family: var(--sans);
  scrollbar-width: thin;
}
.toc-title {
  font-size: 11px; letter-spacing: .28em; color: var(--faint);
  padding-bottom: 12px; border-bottom: 1px solid var(--line-soft); margin-bottom: 14px;
}
.toc ul { list-style: none; margin: 0 0 14px; padding: 0; }
.toc li { margin: 0; }
.toc a {
  display: block;
  padding: 6px 10px 6px 12px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
  border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
  transition: .16s;
}
.toc a:hover { color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
.toc .vol > a { color: var(--ink); font-weight: 700; font-size: 13px; letter-spacing: .04em; margin-top: 10px; }
.toc .sub a { padding-left: 24px; font-size: 12px; }
.toc .sub a::before { content: "·"; margin-right: 7px; color: var(--faint); }

.prose {
  font-size: var(--reader-size);
  line-height: 1.98;
  text-align: justify;
  text-justify: inter-ideograph;
  overflow-wrap: break-word;
}
.prose > p:first-child::first-letter {
  float: left;
  font-size: 3.3em;
  line-height: 1;
  padding: 4px 10px 0 0;
  color: var(--accent);
}
.prose p { margin: 0 0 1.15em; }
.prose h1 {
  position: relative;
  margin: 5rem 0 2rem;
  padding-top: 2.4rem;
  font-size: clamp(26px, 4vw, 34px);
  letter-spacing: .08em;
  border-top: 2px solid var(--accent);
  scroll-margin-top: 92px;
}
.prose h1::before {
  content: "卷";
  position: absolute;
  top: 2.4rem; right: 0;
  font-family: var(--sans); font-size: 11px; letter-spacing: .3em; color: var(--faint);
}
.prose h1.prologue { border-top-color: var(--line); }
.prose h1.prologue::before { content: "楔"; }
.prose h2 {
  margin: 3.6rem 0 1.6rem;
  font-size: clamp(22px, 3.2vw, 28px);
  letter-spacing: .06em;
  line-height: 1.4;
  scroll-margin-top: 92px;
}
.prose h2::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--accent);
  margin-right: 12px;
  transform: translateY(-3px) rotate(45deg);
}
.prose h3 {
  margin: 2.4rem 0 1rem;
  font-size: 1.12em;
  scroll-margin-top: 92px;
}
.prose blockquote {
  margin: 1.6em 0;
  padding: 18px 24px;
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 4%, transparent);
  color: var(--muted);
  font-size: .96em;
  line-height: 1.95;
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose strong {
  font-weight: 700;
  background: linear-gradient(transparent 62%, var(--highlight) 62%);
}
.prose em { font-style: normal; border-bottom: 1px dashed var(--accent); }
.prose hr {
  border: 0;
  height: 1px;
  width: 64px;
  background: var(--line);
  margin: 2.6rem auto;
}
.prose ul, .prose ol { margin: 0 0 1.2em; padding-left: 1.6em; }
.prose li { margin: .35em 0; }
.prose a { color: var(--accent); border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .88em;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  padding: .15em .4em;
  border-radius: 4px;
}
.prose .table-wrap { overflow-x: auto; margin: 1.6em 0; border: 1px solid var(--line-soft); border-radius: 10px; }
.prose table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.65;
  min-width: 560px;
}
.prose thead th {
  text-align: left;
  background: color-mix(in srgb, var(--accent) 7%, var(--paper));
  color: var(--ink);
  font-weight: 700;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.prose tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
  color: var(--muted);
}
.prose tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--ink) 2.2%, transparent); }
.prose tbody tr:last-child td { border-bottom: 0; }

.chapter-end {
  margin: 4rem 0 0;
  padding-top: 28px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--faint);
  letter-spacing: .1em;
}
.chapter-end a { color: var(--accent); }

.to-top {
  position: fixed;
  right: 22px; bottom: 26px;
  z-index: 50;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  color: var(--muted);
  cursor: pointer;
  display: grid; place-items: center;
  opacity: 0; pointer-events: none;
  transition: .2s;
  font-family: var(--sans);
  font-size: 15px;
}
.to-top.show { opacity: 1; pointer-events: auto; }
.to-top:hover { color: var(--accent); border-color: var(--accent); }

.toc-toggle { display: none; }

/* ---------- footer ---------- */
.site-footer {
  border-top: 1px solid var(--line-soft);
  padding: 38px 24px 46px;
  text-align: center;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--faint);
  line-height: 2;
}
.site-footer a { color: var(--muted); border-bottom: 1px solid var(--line); }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding-top: 30px; }
  .toc {
    position: fixed;
    z-index: 80;
    top: 0; left: 0; bottom: 0;
    width: min(86vw, 340px);
    max-height: none;
    background: var(--paper);
    border-right: 1px solid var(--line);
    padding: 78px 20px 30px;
    transform: translateX(-102%);
    transition: transform .26s ease;
    box-shadow: var(--shadow);
  }
  body.toc-open .toc { transform: translateX(0); }
  body.toc-open::after {
    content: "";
    position: fixed; inset: 0;
    background: rgba(0,0,0,.32);
    z-index: 75;
  }
  .toc-toggle { display: inline-flex; }
  .reader-hero { padding-top: 100px; }
  .artifacts, .steps { grid-template-columns: 1fr; }
  .tl-item { grid-template-columns: 86px 1fr; gap: 14px; }
}

@media (max-width: 560px) {
  .topbar { height: 56px; padding: 0 14px; gap: 8px; }
  .brand { font-size: 13px; letter-spacing: .08em; }
  .topnav a { padding: 7px 8px; font-size: 12px; }
  .top-actions .label { display: none; }
  .progress { top: 55px; }
  .cover { padding-top: 96px; }
  .prose { font-size: calc(var(--reader-size) - 1px); line-height: 1.9; }
  .prose h1 { margin-top: 3.6rem; }
  .prose h2 { margin-top: 2.8rem; }
  .chapter-end { flex-direction: column; gap: 10px; align-items: flex-start; }
  .to-top { right: 14px; bottom: 18px; }
}

@media print {
  .topbar, .toc, .to-top, .progress, .reader-hero, .site-footer, .chapter-end { display: none !important; }
  .layout { display: block; padding: 0; }
  .prose { max-width: none; font-size: 11pt; }
  body { background: #fff; }
}
