/* base.css — shared foundation, tuned for reading pages */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--text);
  font-size: var(--body);
  line-height: 1.62;
  letter-spacing: -0.003em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
}
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p, ul, ol, figure, blockquote, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button { font: inherit; color: inherit; }
p { max-width: 62ch; }
::selection { background: var(--accent); color: var(--accent-ink); }

:root {
  --gutter: clamp(1.125rem, 2.2vw, 2rem);
  --section: clamp(7rem, 10.5vw, 9rem);
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
  --track: 0.055em;
  --rule-weight: 1px;
}

.wrap { padding-inline: var(--gutter); }
.measure { max-width: 34em; }

/* ---------- top bar ---------- */
.top {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 1.5rem; padding-block: 1.4rem 1.2rem; position: relative; z-index: 20;
  flex-wrap: wrap;
}
.mark { font-size: var(--small); font-weight: 600; letter-spacing: 0.04em; }
.nav { display: flex; gap: clamp(0.85rem, 1.9vw, 1.65rem); font-size: 0.8125rem; flex-wrap: wrap; }
.nav a {
  color: var(--muted); padding-block: 0.3rem; letter-spacing: 0.01em;
  transition: color 0.18s;
}
.nav a:hover, .nav a:focus-visible {
  color: var(--ink);
  text-decoration: underline; text-decoration-thickness: 2px;
  text-underline-offset: 0.42em; text-decoration-color: var(--accent);
}
.nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

/* ---------- headings ---------- */
.h1 {
  font-size: var(--h1);
  line-height: 1.02;
  letter-spacing: -0.045em;
  font-weight: 600;
  text-wrap: balance;
}
.h2 {
  font-size: var(--h2);
  line-height: 1.08;
  letter-spacing: -0.035em;
  font-weight: 600;
  text-wrap: balance;
}
.h3 { font-size: var(--body); line-height: 1.35; letter-spacing: -0.012em; font-weight: 600; text-wrap: balance; }
.lead { font-size: var(--lead); line-height: 1.45; letter-spacing: -0.018em; }
.small { font-size: var(--small); line-height: 1.58; color: var(--muted); }
.body { font-size: var(--body); }

/* ---------- action ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 0.55em;
  min-height: 44px; padding: 0.72em 1.3em;
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 0;
  font-size: var(--small); font-weight: 600; letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.16s var(--ease), filter 0.16s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

/* ---------- section rhythm ---------- */
section { padding-block-start: var(--section); }
.chapter { padding-block-start: calc(var(--section) + 1.5rem); }
.chapter-h { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gutter); align-items: end; }
.chapter-h > .ch-t { grid-column: 1 / span 5; position: relative; }
.chapter-h > .ch-s { grid-column: 6 / span 7; }
.chapter-h .ch-s p { font-size: var(--body); max-width: 44ch; color: var(--ink); }
@media (max-width: 820px) {
  .chapter-h { grid-template-columns: minmax(0, 1fr); }
  .chapter-h > .ch-t, .chapter-h > .ch-s { grid-column: 1 / -1; }
  .chapter-h > .ch-s { margin-top: 0.7rem; }
}

/* ---------- layered reading unit ---------- */
.units { display: grid; gap: 4px; margin-top: clamp(1.4rem, 3vw, 2rem); margin-bottom: 0.4rem; }
.unit { background: var(--surface); position: relative; }
.unit > summary, .deeper > summary { list-style: none; cursor: pointer; }
.unit > summary::-webkit-details-marker, .deeper > summary::-webkit-details-marker { display: none; }
.unit > summary {
  display: grid; grid-template-columns: minmax(0, 1fr) 4.5rem 1.4rem;
  gap: 1rem; align-items: baseline;
  padding: 1.15rem 1.25rem 1.15rem 1.5rem;
  transition: background 0.18s var(--ease);
}
.unit > summary::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: transparent; transition: background 0.18s;
}
.unit:hover > summary { background: var(--sunken); }
.unit[open] > summary { background: var(--bg); }
.unit[open] > summary::before { background: var(--accent); }
.unit > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.u-say { font-size: var(--lead); letter-spacing: -0.02em; line-height: 1.42; }
.u-time { font-size: 0.8125rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.unit > summary::after {
  content: "+"; justify-self: end; color: var(--muted);
  font-size: 1rem; line-height: 1; text-align: center;
  transition: color 0.18s;
}
.unit[open] > summary::after { content: "−"; color: var(--accent); }
.unit.done > summary { background: var(--bg); }
.unit.done .u-say { color: var(--muted); }
.unit.done .u-say::after {
  content: ""; display: inline-block; width: 0.4em; height: 0.2em; margin-left: 0.4em;
  border-left: 2px solid var(--accent); border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg) translateY(-0.12em);
}
.u-body { padding: 0.1rem 1.25rem 1.4rem 1.5rem; max-width: 62ch; }
.unit[open] > .u-body { display: grid; gap: 0.85rem; }
.u-body p { font-size: var(--body); line-height: 1.68; }
.deeper { background: var(--sunken); padding: 0.75rem 0.95rem; margin-top: 0.35rem; }
.deeper > summary {
  display: flex; justify-content: space-between; gap: 1rem;
  font-size: 1.2rem; color: var(--ink); letter-spacing: -0.005em;
}
.deeper > summary::after { content: "↓"; color: var(--muted); }
.deeper[open] > summary::after { content: "↑"; }
.deeper p { font-size: var(--body); line-height: 1.66; margin-top: 0.55rem; max-width: 58ch; }
.src { font-size: 1.2rem; color: var(--muted); line-height: 1.6; max-width: 52ch; }
.chk {
  justify-self: start; background: none; border: 0; padding: 0.35rem 0;
  font-size: 0.8125rem; color: var(--ink); cursor: pointer; letter-spacing: 0.01em;
  text-decoration: underline; text-underline-offset: 0.3em; text-decoration-thickness: 2px;
  text-decoration-color: var(--accent);
}
.chk[aria-pressed="true"] { color: var(--accent); text-decoration: none; }
.chk[aria-pressed="true"]::before {
  content: ""; display: inline-block; width: 0.4em; height: 0.2em; margin-right: 0.45em;
  border-left: 2px solid var(--accent); border-bottom: 2px solid var(--accent);
  transform: rotate(-45deg) translateY(-0.12em);
}
@media (max-width: 560px) {
  .unit > summary { grid-template-columns: minmax(0, 1fr) 1.4rem; padding: 1rem 1rem 1rem 1.15rem; }
  .u-time { grid-row: 2; grid-column: 1 / -1; text-align: left; margin-top: 0.35rem; }
  .u-body { padding: 0 1rem 1.2rem 1.15rem; }
}

/* ---------- progress ---------- */
.prog { position: sticky; top: 0; z-index: 30; background: var(--bg); padding-block: 0.6rem 0.7rem; }
.prog-in { display: flex; align-items: center; gap: 1rem; }
.p-track { flex: 1; height: 3px; background: var(--rule-soft); }
.p-track i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.35s var(--ease); }
.p-text { font-size: 0.8125rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.p-text b { color: var(--ink); font-weight: 600; }
.p-next {
  background: none; border: 0; padding: 0.2rem 0; font-size: 0.8125rem; color: var(--ink);
  cursor: pointer; text-decoration: underline; text-underline-offset: 0.28em;
  text-decoration-thickness: 2px; text-decoration-color: var(--accent); white-space: nowrap;
}
.p-next:hover { color: var(--accent); }
.p-next:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- index ---------- */
.idx { display: grid; }
.idx a { display: grid; gap: 0.12rem; padding-block: 0.62rem; color: var(--ink); border-bottom: 2px solid transparent; }
.idx a:hover .idx-t { text-decoration: underline; text-underline-offset: 0.24em; text-decoration-thickness: 2px; text-decoration-color: var(--accent); }
.idx a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.idx-t { font-size: var(--body); font-weight: 600; letter-spacing: -0.012em; }
.idx-d { font-size: 0.8125rem; color: var(--muted); line-height: 1.5; }

/* ---------- tables ---------- */
.tbl { width: 100%; border-collapse: collapse; font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
.tbl caption { text-align: left; padding-bottom: 0.8rem; color: var(--muted); font-size: 0.8125rem; }
.tbl th {
  text-align: left; font-weight: 600; font-size: 0.8125rem; letter-spacing: 0.02em;
  padding: 0 1rem 0.6rem 0; color: var(--muted); vertical-align: bottom;
}
.tbl td { padding: 0.8rem 1rem 0.8rem 0; vertical-align: top; line-height: 1.55; }
.tbl tr:hover td { background: var(--surface); }
.tbl td:first-child { white-space: nowrap; }
.tbl td + td, .tbl th + th { padding-left: 0.25rem; }

/* ---------- code ---------- */
pre {
  margin: 0; padding: 1.15rem 1.25rem; background: var(--code-bg); color: var(--code-ink);
  font-family: "Menlo", "Consolas", "Courier New", monospace; font-size: 0.84rem; line-height: 1.7;
  white-space: pre-wrap; word-break: break-word; overflow-x: auto;
}

/* ---------- questions ---------- */
.q { border: 0; background: var(--surface); padding: 1.1rem 1.25rem; }
.q + .q { margin-top: 2px; }
.q summary {
  cursor: pointer; list-style: none; font-size: var(--lead); letter-spacing: -0.015em;
  display: flex; gap: 1rem; align-items: baseline; padding-right: 0.5rem;
}
.q summary::-webkit-details-marker { display: none; }
.q summary::after { content: "+"; margin-left: auto; color: var(--muted); font-size: 1rem; }
.q[open] summary::after { content: "−"; color: var(--accent); }
.q p { margin-block-start: 0.7rem; max-width: 44em; font-size: var(--body); line-height: 1.68; }
.q summary:hover { color: var(--accent); }
.q summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

/* ---------- footer ---------- */
.foot { padding-block: clamp(3.5rem, 8vw, 6rem) 2.2rem; margin-top: var(--section); background: var(--foot-bg); color: var(--foot-ink); }
.foot .big { font-size: var(--h1); line-height: 1; letter-spacing: -0.045em; font-weight: 600; }
.foot .credits { margin-top: 2.4rem; font-size: 0.8125rem; line-height: 1.65; color: var(--foot-muted); max-width: 60em; }
.foot a { text-decoration: underline; text-underline-offset: 0.25em; }

/* ---------- motion ---------- */
@media (prefers-reduced-motion: no-preference) { .js .rise { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .js .rise { opacity: 1 !important; transform: none !important; }
}

/* 表头一条实线，只为把表头与数据分开 */
.tbl thead th { border-bottom: 2px solid var(--ink); }

/* ---------- 原文逐句 + 白话注 ---------- */
.ex { display: grid; gap: 0.3rem; margin-top: 0.6rem; padding-left: clamp(0.85rem, 2vw, 1.15rem); border-left: 3px solid var(--accent); }
.ex-h { font-size: 0.8125rem; line-height: 1.55; color: var(--muted); margin-bottom: 0.25rem; }
.ex-q { font-size: 0.9688rem; line-height: 1.85; letter-spacing: 0.005em; color: var(--ink); max-width: 60ch; }
.ex-q em { font-style: normal; color: var(--muted); }
.ex-g {
  font-size: 0.875rem; line-height: 1.7; color: var(--ink); opacity: 0.82;
  padding-left: 1.05rem; position: relative; margin-bottom: 0.5rem; max-width: 58ch;
}
.ex-g::before { content: "→"; position: absolute; left: 0; color: var(--accent); opacity: 1; }
.ex-g b { font-weight: 600; }


/* ---------- 顶栏常驻：滚动时钉在最上方 ---------- */
.top {
  position: sticky; top: 0; z-index: 40;
  background: var(--bg);
}
.prog { top: var(--top-h, 76px); }
section[id] { scroll-margin-top: calc(var(--top-h, 76px) + var(--prog-h, 34px) + 20px); }
@media (max-width: 1099px) {
  .prog { top: var(--top-h, 124px); }
  section[id] { scroll-margin-top: calc(var(--top-h, 124px) + var(--prog-h, 34px) + 12px); }
}


/* 顶栏与进度条：两层都常驻，一上一下；进度条用一档浅色分开 */
.prog { background: var(--surface); }
@media (max-width: 1099px) {
  .top { padding-block: 0.85rem 0.7rem; }
}

