:root {
  --ink: #0d1014;
  --ink-2: #13171d;
  --ink-3: #1a1f27;
  --line: rgba(214, 196, 158, 0.16);
  --line-strong: rgba(214, 196, 158, 0.34);
  --paper: #e9e1cf;
  --paper-dim: #b9b09c;
  --muted: #847d6e;
  --gold: #c9a865;
  --gold-soft: rgba(201, 168, 101, 0.22);
  --cinnabar: #b23a2e;
  --jade: #7fa59a;
  --azure: #8fa8c8;
  --serif: "Noto Serif SC", "Source Han Serif SC", "Source Han Serif CN", "Songti SC", "STSong", "SimSun", serif;
  --kai: "LXGW WenKai", "Kaiti SC", "STKaiti", "KaiTi", "楷体", var(--serif);
  --mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --measure: 40rem;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.95;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  /* fine paper grain */
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.05;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.6 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

a { color: var(--gold); text-decoration: none; border-bottom: 1px solid var(--gold-soft); }
a:hover { border-bottom-color: var(--gold); }

em { font-style: normal; color: var(--gold); }
strong { font-weight: 600; color: #f3ead6; }

/* ---------- navigation ---------- */
.nav {
  position: fixed;
  right: 22px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.nav a {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}
.nav a span { opacity: 0; transform: translateX(6px); transition: all .35s ease; }
.nav a::after {
  content: "";
  width: 6px; height: 6px;
  border: 1px solid var(--muted);
  transform: rotate(45deg);
  transition: all .35s ease;
}
.nav:hover a span { opacity: 1; transform: none; }
.nav a.on { color: var(--gold); }
.nav a.on::after { background: var(--gold); border-color: var(--gold); }

.progress {
  position: fixed; left: 0; top: 0; height: 2px; z-index: 60;
  background: linear-gradient(90deg, var(--cinnabar), var(--gold));
  width: 0;
}

/* ---------- hero ---------- */
.hero {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.hero-inner {
  position: relative;
  text-align: center;
  padding: 0 24px;
  animation: rise 2.4s cubic-bezier(.2,.7,.2,1) both .3s;
}
.hero .kicker {
  color: var(--paper-dim);
  letter-spacing: .5em;
  font-size: 14px;
  margin-bottom: 28px;
}
.hero h1 {
  font-weight: 500;
  font-size: clamp(30px, 5vw, 58px);
  letter-spacing: .14em;
  line-height: 1.5;
  margin: 0;
}
.hero h1 small {
  display: block;
  font-size: .5em;
  letter-spacing: .3em;
  color: var(--paper-dim);
  margin-top: 10px;
}
.hero .byline { margin-top: 34px; color: var(--paper-dim); font-size: 15px; letter-spacing: .2em; }
.hero .byline b { color: var(--paper); font-weight: 500; }
.seal {
  display: inline-grid;
  place-items: center;
  width: 54px; height: 54px;
  margin-top: 38px;
  border: 2px solid var(--cinnabar);
  color: var(--cinnabar);
  font-family: var(--kai);
  font-size: 20px;
  line-height: 1.05;
  letter-spacing: 0;
  border-radius: 4px;
  transform: rotate(-4deg);
  box-shadow: inset 0 0 0 3px rgba(178, 58, 46, .14);
}
.scroll-hint {
  position: absolute; bottom: 34px; left: 50%;
  transform: translateX(-50%);
  color: var(--muted); font-size: 12px; letter-spacing: .4em;
  writing-mode: vertical-rl;
  animation: breathe 3s ease-in-out infinite;
}
.hero-epic {
  position: absolute; bottom: 104px; left: 50%; z-index: 2;
  transform: translateX(-50%); white-space: nowrap;
  font-size: 14px; letter-spacing: .2em;
}
.to-epic {
  position: fixed; left: 28px; bottom: 24px; z-index: 60;
  font-size: 13px; letter-spacing: .25em;
  color: var(--muted); background: rgba(13, 16, 20, .55);
  border: 1px solid rgba(236, 227, 207, .22);
  padding: 7px 14px;
  transition: color .3s ease, border-color .3s ease;
}
.to-epic:hover { color: var(--gold); border-color: var(--gold); }
@media (max-width: 820px) { .hero-epic { white-space: normal; width: 86vw; text-align: center; } }

@keyframes rise { from { opacity: 0; transform: translateY(18px); filter: blur(4px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes breathe { 0%,100% { opacity: .35; } 50% { opacity: 1; } }

/* ---------- sections ---------- */
section.chapter {
  position: relative;
  padding: 120px 24px 90px;
  border-top: 1px solid var(--line);
}
section.chapter.alt { background: var(--ink-2); }

.ch-head {
  max-width: 64rem;
  margin: 0 auto 56px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 28px;
  align-items: end;
}
.ch-num {
  font-family: var(--kai);
  font-size: 64px;
  line-height: 1;
  color: var(--gold);
  opacity: .9;
}
.ch-title h2 {
  margin: 0;
  font-weight: 500;
  font-size: 30px;
  letter-spacing: .16em;
}
.ch-title p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: .12em;
}

.prose {
  max-width: var(--measure);
  margin: 0 auto;
}
.prose p { margin: 0 0 1.15em; text-align: justify; }
.prose h3 {
  font-weight: 500;
  font-size: 21px;
  letter-spacing: .12em;
  margin: 2.6em 0 .9em;
  display: flex; align-items: center; gap: 14px;
}
.prose h3::before {
  content: ""; width: 18px; height: 1px; background: var(--gold);
}

blockquote.classic {
  margin: 1.6em 0;
  padding: 18px 26px;
  border-left: 2px solid var(--cinnabar);
  background: linear-gradient(90deg, rgba(178,58,46,.08), transparent 70%);
  font-family: var(--kai);
  font-size: 19px;
  line-height: 2;
  color: #efe5cf;
}
blockquote.classic cite {
  display: block;
  margin-top: 6px;
  font-family: var(--serif);
  font-style: normal;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: .1em;
}

.note {
  font-size: 14px;
  line-height: 1.85;
  color: var(--paper-dim);
  border-top: 1px dashed var(--line-strong);
  padding-top: 12px;
  margin-top: 18px;
}
.note b { color: var(--paper); font-weight: 500; }

.wide {
  max-width: 68rem;
  margin: 48px auto;
}

figure.panel.wide { margin: 48px auto; }
figure.panel {
  margin: 0;
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}
figure.panel figcaption {
  padding: 14px 20px 16px;
  font-size: 14px;
  color: var(--paper-dim);
  border-top: 1px solid var(--line);
  display: flex; gap: 14px; align-items: baseline; flex-wrap: wrap;
}
figure.panel figcaption .fig-no {
  color: var(--gold);
  letter-spacing: .15em;
  white-space: nowrap;
}
.panel-stage { position: relative; }
.panel-stage canvas, .panel-stage svg { display: block; width: 100%; }

.controls {
  display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--paper-dim);
}
.controls .grow { flex: 1; min-width: 160px; }

button.btn {
  font: inherit;
  font-size: 13px;
  letter-spacing: .12em;
  color: var(--paper);
  background: transparent;
  border: 1px solid var(--line-strong);
  padding: 5px 14px;
  border-radius: 2px;
  cursor: pointer;
  transition: all .25s ease;
}
button.btn:hover { border-color: var(--gold); color: var(--gold); }
button.btn.on { background: var(--gold); color: var(--ink); border-color: var(--gold); }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; background: transparent; height: 18px;
}
input[type=range]::-webkit-slider-runnable-track { height: 1px; background: var(--line-strong); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 11px; height: 11px; margin-top: -5px;
  background: var(--gold); transform: rotate(45deg); border: 0; cursor: pointer;
}
input[type=range]::-moz-range-track { height: 1px; background: var(--line-strong); }
input[type=range]::-moz-range-thumb { width: 10px; height: 10px; background: var(--gold); border: 0; border-radius: 0; transform: rotate(45deg); }

.readout { font-family: var(--mono); font-size: 12.5px; color: var(--paper); letter-spacing: 0; }
.readout .gz { font-family: var(--serif); color: var(--gold); margin-left: 6px; }

/* ---------- the passage ---------- */
.passage-wrap {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 360px);
  gap: 56px;
  max-width: 64rem;
  margin: 0 auto;
  align-items: start;
}
.passage {
  writing-mode: vertical-rl;
  font-family: var(--kai);
  font-size: 30px;
  line-height: 2.1;
  letter-spacing: .14em;
  height: auto;
  margin: 0 auto;
  padding: 26px 30px;
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  position: relative;
}
.passage .ph {
  display: block;
  cursor: pointer;
  transition: color .4s ease, text-shadow .4s ease;
  color: rgba(233,225,207,.12);
  margin-left: .35em;
}
.passage.lit .ph { color: var(--paper); }
.passage .ph:hover, .passage .ph.on { color: var(--gold) !important; text-shadow: 0 0 18px rgba(201,168,101,.35); }
.passage .src {
  font-family: var(--serif);
  font-size: 13px;
  color: var(--muted);
  letter-spacing: .3em;
  margin-top: 1.5em;
}
.gloss {
  border: 1px solid var(--line);
  padding: 24px 26px;
  background: var(--ink-3);
  min-height: 300px;
  position: sticky; top: 90px;
}
.gloss .term { font-family: var(--kai); font-size: 26px; color: var(--gold); letter-spacing: .14em; }
.gloss .wei { font-size: 13px; color: var(--muted); margin: 8px 0 14px; }
.gloss p { font-size: 15px; line-height: 1.9; margin: 0 0 .8em; color: var(--paper); }
.gloss .tag {
  display: inline-block; font-size: 12px; letter-spacing: .1em;
  padding: 1px 8px; border: 1px solid var(--line-strong); color: var(--paper-dim); margin-top: 6px;
}
.gloss .tag.use { border-color: var(--jade); color: var(--jade); }
.gloss .tag.aux { border-color: var(--gold); color: var(--gold); }
.gloss .tag.none { border-color: var(--muted); color: var(--muted); }

/* ---------- facts strip ---------- */
.facts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  max-width: 64rem; margin: 64px auto 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.facts div { padding: 22px 18px; border-right: 1px solid var(--line); text-align: center; }
.facts div:last-child { border-right: 0; }
.facts b { display: block; font-size: 36px; font-weight: 400; color: var(--gold); font-family: var(--mono); letter-spacing: 0; line-height: 1.3; }
.facts span { font-size: 13px; color: var(--paper-dim); letter-spacing: .1em; }

/* ---------- chen eight meanings ---------- */
.chen {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  margin: 1.4em 0;
}
.chen div {
  background: var(--ink-2);
  padding: 12px 14px;
  font-size: 14px; line-height: 1.6;
  position: relative;
  transition: opacity .6s ease, background .6s ease;
}
.chen div i { font-style: normal; color: var(--muted); font-family: var(--mono); font-size: 12px; margin-right: 6px; }
.chen div.out { opacity: .28; }
.chen div.out::after {
  content: ""; position: absolute; left: 12px; right: 12px; top: 50%; height: 1px; background: var(--cinnabar);
  transform-origin: left; animation: strike .6s ease both;
}
.chen div.keep { background: rgba(127,165,154,.14); }
.chen div.keep i { color: var(--jade); }
@keyframes strike { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ---------- tables ---------- */
table.ledger {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
  line-height: 1.6;
}
table.ledger th {
  font-weight: 500; color: var(--paper-dim); letter-spacing: .12em; font-size: 13px;
  border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong);
  padding: 10px 12px; text-align: left;
}
table.ledger td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.ledger td.num { font-family: var(--mono); font-size: 13px; letter-spacing: 0; white-space: nowrap; }
table.ledger tr { transition: background .25s ease, opacity .5s ease; }
table.ledger tbody tr.pick { cursor: pointer; }
table.ledger tbody tr.pick:hover { background: rgba(201,168,101,.06); }
table.ledger tbody tr.sel { background: rgba(201,168,101,.13); }
table.ledger tbody tr.dim { opacity: .35; }
table.ledger tbody tr.win td:first-child { box-shadow: inset 2px 0 0 var(--gold); }
table.ledger .src { color: var(--muted); font-size: 13px; }
table.ledger tr.hot td { color: #fff4dc; }

.split {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 28px; align-items: start;
}

/* ---------- step indicator for sieve ---------- */
.steps { display: flex; gap: 0; border-top: 1px solid var(--line); }
.steps button {
  flex: 1; font: inherit; font-size: 13px; color: var(--paper-dim); background: transparent;
  border: 0; border-right: 1px solid var(--line); padding: 12px 10px; cursor: pointer; text-align: left;
  line-height: 1.5; transition: all .3s ease;
}
.steps button:last-child { border-right: 0; }
.steps button b { display: block; font-family: var(--mono); font-weight: 400; color: var(--paper); font-size: 20px; letter-spacing: 0; }
.steps button.on { background: rgba(201,168,101,.1); color: var(--gold); }
.steps button.on b { color: var(--gold); }

/* ---------- calendar ---------- */
.cal {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 0;
}
.cal .d {
  background: var(--ink-2);
  box-shadow: inset 0 0 0 .5px var(--line);
  padding: 6px 4px 26px;
  text-align: center;
  font-size: 12px;
  line-height: 1.35;
  position: relative;
  min-height: 92px;
  transition: background .5s ease;
}
.cal .d.pad { background: transparent; box-shadow: none; }
.cal .d .g { font-family: var(--kai); font-size: 16px; color: var(--paper); }
.cal .d .dt { font-family: var(--mono); font-size: 10.5px; color: var(--muted); letter-spacing: 0; }
.cal .d svg { width: 18px; height: 18px; display: block; margin: 3px auto 2px; }
.cal .d .ev {
  position: absolute; left: 3px; right: 3px; bottom: 3px;
  font-size: 11px; color: var(--ink); background: var(--gold);
  border-radius: 1px; line-height: 1.35; padding: 1px 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transform: translateY(4px); transition: all .5s ease;
}
.cal .d .ev.sky { background: var(--azure); }
.cal .d.has .ev { opacity: 1; transform: none; }
.cal .d.has { background: #1e232c; }
.cal .d.now { outline: 1px solid var(--gold); z-index: 2; }
.cal .d.jiazi .g { color: var(--cinnabar); font-weight: 700; }

/* ---------- timeline (table 2) ---------- */
.tl { position: relative; max-width: 54rem; margin: 0 auto; padding-left: 0; }
.tl::before { content: ""; position: absolute; left: 132px; top: 8px; bottom: 8px; width: 1px; background: var(--line-strong); }
.tl .row {
  display: grid; grid-template-columns: 116px 32px 1fr; gap: 0 16px;
  padding: 10px 0; position: relative;
  opacity: 0; transform: translateY(14px);
  transition: opacity .8s ease, transform .8s ease;
}
.tl .row.in { opacity: 1; transform: none; }
.tl .row .date { text-align: right; font-family: var(--mono); font-size: 13px; color: var(--paper-dim); letter-spacing: 0; padding-top: 3px; }
.tl .row .date b { display: block; font-family: var(--kai); font-size: 18px; color: var(--paper); font-weight: 400; }
.tl .row .dot { position: relative; }
.tl .row .dot::before {
  content: ""; position: absolute; left: 11px; top: 11px; width: 9px; height: 9px;
  border: 1px solid var(--gold); background: var(--ink); transform: rotate(45deg);
}
.tl .row.key .dot::before { background: var(--cinnabar); border-color: var(--cinnabar); width: 11px; height: 11px; left: 10px; }
.tl .row .body { font-size: 15px; line-height: 1.75; }
.tl .row .body .sky { color: var(--azure); }
.tl .row .body .ev { color: var(--gold); }
.tl .row .body small { color: var(--muted); font-size: 12.5px; margin-left: 6px; }

/* ---------- reveal ---------- */
.reveal { opacity: 0; transform: translateY(22px); transition: opacity 1.1s ease, transform 1.1s cubic-bezier(.2,.7,.2,1); }
.reveal.in { opacity: 1; transform: none; }

/* ---------- conclusion ---------- */
.verdict {
  text-align: center; margin: 70px auto 20px;
}
.verdict .big {
  font-family: var(--kai);
  font-size: clamp(30px, 5vw, 52px);
  letter-spacing: .16em;
  color: #f4ead3;
}
.verdict .big span { color: var(--cinnabar); }
.verdict .sub { color: var(--paper-dim); letter-spacing: .3em; font-size: 14px; margin-top: 8px; }

.refs { font-size: 14px; line-height: 1.85; color: var(--paper-dim); padding-left: 1.4em; }
.refs li { margin-bottom: .5em; }

footer {
  border-top: 1px solid var(--line);
  padding: 50px 24px 70px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: .1em;
}

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12.5px; color: var(--paper-dim); }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px; }

@media (max-width: 900px) {
  .passage-wrap, .split { grid-template-columns: 1fr; }
  .gloss { position: static; }
  .facts { grid-template-columns: repeat(2, 1fr); }
  .facts div:nth-child(2) { border-right: 0; }
  .chen { grid-template-columns: repeat(2, 1fr); }
  .nav { display: none; }
  .cal { grid-template-columns: repeat(5, 1fr); }
  .passage { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  html { scroll-behavior: auto; }
}
