/* ---------------------------------------------------------------------------
   F8 长文阅读器 · 陶土语系
   作用域一律挂在 [data-page="read"] 或 .rd-* 前缀下，不污染其它页面。
   五层色板与主色都带 fallback，脱离 style.css 也能独立打开。
--------------------------------------------------------------------------- */

body[data-page="read"] {
  --rd-accent: var(--accent, #b85d3d);
  --rd-accent-dark: var(--accent-dark, #8f3f2b);
  --rd-accent-light: var(--accent-light, #f8e9e1);
  --rd-bg: var(--bg, #fbf6ef);
  --rd-card: var(--bg-card, #fffdf9);
  --rd-ink: var(--ink, #3a2f24);
  --rd-soft: var(--ink-soft, #6b5b48);
  --rd-light: var(--ink-light, #9b8871);
  --rd-border: var(--border, #e6d9c7);
  --rd-border-strong: var(--border-strong, #d4c4ad);
  --rd-l1: var(--l1, #7d3829);
  --rd-l2: var(--l2, #b85d3d);
  --rd-l3: var(--l3, #d28a62);
  --rd-l4: var(--l4, #927056);
  --rd-l5: var(--l5, #6c7c5b);
  --rd-fs: 18px;
  --rd-lh: 1.9;
  --rd-measure: 38em;      /* ≈ 38 个全角字 / 70 个西文字符 */
  background: var(--rd-bg);
  color: var(--rd-ink);
}
body[data-page="read"][data-rd-size="s"] { --rd-fs: 16px; --rd-lh: 1.85; }
body[data-page="read"][data-rd-size="l"] { --rd-fs: 20px; --rd-lh: 1.95; --rd-measure: 34em; }

/* ---- 进度条 ---- */
.rd-progress {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  height: 3px; background: rgba(184, 93, 61, .12);
}
.rd-progress i { display: block; width: 0; height: 100%; background: var(--rd-accent); transition: width .1s linear; }

/* ---- 骨架 ---- */
body[data-page="read"] .rd-main { max-width: none; padding: 34px 40px 90px; }
.rd-shell {
  display: grid; gap: 34px; align-items: start;
  grid-template-areas: "toc stage aside";
  grid-template-columns: 224px minmax(0, 1fr) 250px;
  justify-content: start;
}
.rd-toc { grid-area: toc; }
.rd-stage { grid-area: stage; min-width: 0; max-width: calc(var(--rd-measure) + 4em); }
.rd-aside { grid-area: aside; }

/* ---- 目录 ---- */
.rd-toc {
  position: sticky; top: 26px; max-height: calc(100vh - 52px);
  display: flex; flex-direction: column;
  padding: 14px 4px 14px 0;
}
.rd-toc-head { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 10px; border-bottom: 1px solid var(--rd-border); }
.rd-toc-label { color: var(--rd-light); font-size: 11px; letter-spacing: .2em; text-transform: uppercase; }
.rd-toc-close { display: none; width: 30px; height: 30px; border: 1px solid var(--rd-border-strong); border-radius: 7px; background: var(--rd-card); color: var(--rd-soft); font-size: 17px; line-height: 1; cursor: pointer; }
.rd-toc-body { overflow-y: auto; padding: 10px 4px 4px; scrollbar-width: thin; }
.rd-toc-group { margin: 14px 0 6px; padding: 0 8px; color: var(--rd-light); font-size: 11px; letter-spacing: .06em; }
.rd-toc-group:first-child { margin-top: 2px; }
.rd-toc-item {
  position: relative; display: flex; gap: 8px; align-items: baseline;
  padding: 6px 9px; border-radius: 6px; border-left: 2px solid transparent;
  color: var(--rd-soft); font-size: 12.5px; line-height: 1.45; text-decoration: none;
}
.rd-toc-item em { flex: 0 0 auto; color: var(--rd-light); font-family: Georgia, "Songti SC", serif; font-size: 11px; font-style: normal; }
.rd-toc-item span { flex: 1 1 auto; }
.rd-toc-item:hover { background: var(--rd-accent-light); color: var(--rd-accent-dark); }
.rd-toc-item.done em { color: var(--rd-accent); }
.rd-toc-item.active { background: var(--rd-card); border-left-color: var(--rd-accent); color: var(--rd-ink); font-weight: 600; }
.rd-toc-item.active em { color: var(--rd-accent); }
.rd-toc-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: rgba(184, 93, 61, .35); width: 0; border-radius: 0 2px 2px 0; }
.rd-toc-item.active .rd-toc-fill { background: var(--rd-accent); }
.rd-toc-foot { padding: 12px 9px 2px; border-top: 1px solid var(--rd-border); color: var(--rd-light); font-size: 11px; }

/* ---- 头部 ---- */
.rd-head { padding-bottom: 20px; border-bottom: 1px solid var(--rd-border); }
body[data-page="read"] .rd-head .kicker { margin-bottom: 12px; }
.rd-docs { display: flex; flex-wrap: wrap; gap: 8px; }
.rd-doc {
  display: inline-flex; align-items: baseline; gap: 7px;
  padding: 8px 15px; border: 1px solid var(--rd-border-strong); border-radius: 8px;
  background: var(--rd-card); color: var(--rd-soft); font-size: 13.5px; text-decoration: none;
  transition: .15s ease;
}
.rd-doc span { color: var(--rd-accent); font-family: Georgia, "Songti SC", serif; font-size: 12px; }
.rd-doc:hover { border-color: var(--rd-accent); color: var(--rd-accent-dark); }
.rd-doc.active { background: var(--rd-accent); border-color: var(--rd-accent); color: #fff; font-weight: 600; }
.rd-doc.active span { color: rgba(255, 255, 255, .78); }
.rd-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.rd-meta { margin: 0; color: var(--rd-light); font-size: 12px; }
.rd-meta b { color: var(--rd-soft); font-weight: 600; }
.rd-tools { display: flex; align-items: center; gap: 10px; }
.rd-size { display: inline-flex; border: 1px solid var(--rd-border-strong); border-radius: 7px; overflow: hidden; background: var(--rd-card); }
.rd-size button { min-width: 34px; min-height: 30px; padding: 0 8px; border: 0; background: none; color: var(--rd-soft); font-size: 12px; cursor: pointer; }
.rd-size button + button { border-left: 1px solid var(--rd-border); }
.rd-size button:hover { background: var(--rd-accent-light); color: var(--rd-accent-dark); }
.rd-size button.active { background: var(--rd-accent); color: #fff; }

/* ---- 正文 ---- */
/* 换章时整块换掉 innerHTML，浏览器的 scroll anchoring 会「好心」把滚动位置
   拉回原来的锚点元素，正好抵消我们的「跳到章首」。这里显式关掉。 */
.rd-article, .rd-article * { overflow-anchor: none; }
.rd-article { padding: 30px 0 10px; font-size: var(--rd-fs); line-height: var(--rd-lh); }
.rd-chapter-group { margin: 0 0 10px; color: var(--rd-accent); font-size: 12px; letter-spacing: .06em; }
.rd-article h1 {
  max-width: var(--rd-measure); margin: 0 0 14px;
  font-family: Georgia, "Songti SC", "Noto Serif SC", serif;
  font-size: clamp(26px, 3.4vw, 37px); font-weight: 700; letter-spacing: -.01em; line-height: 1.28;
}
.rd-summary {
  max-width: var(--rd-measure); margin: 0 0 26px; padding: 12px 16px;
  border-left: 3px solid var(--rd-accent); background: var(--rd-card);
  color: var(--rd-soft); font-size: .84em; line-height: 1.75;
}
.rd-front { max-width: var(--rd-measure); margin: 0 0 30px; border: 1px dashed var(--rd-border-strong); border-radius: 8px; background: var(--rd-card); }
.rd-front > summary { padding: 10px 14px; color: var(--rd-soft); font-size: .76em; cursor: pointer; }
.rd-front > summary::marker { color: var(--rd-accent); }
.rd-front > div { padding: 0 16px 6px; font-size: .8em; }
.rd-front blockquote { margin: 0; border: 0; padding: 0; background: none; font-style: normal; }

.rd-body { max-width: var(--rd-measure); }
.rd-block { position: relative; }
.rd-body p { margin: 0 0 1.15em; }
.rd-body strong { color: var(--rd-ink); font-weight: 700; }
.rd-body em { font-style: normal; color: var(--rd-accent-dark); }
.rd-body h3 { margin: 1.8em 0 .7em; font-family: Georgia, "Songti SC", serif; font-size: 1.06em; }
.rd-body ul, .rd-body ol { margin: 0 0 1.15em; padding-left: 1.35em; }
.rd-body li { margin-bottom: .45em; }
.rd-body li::marker { color: var(--rd-accent); }
.rd-body code { padding: 1px 5px; border-radius: 4px; background: var(--rd-accent-light); font-size: .88em; }
.rd-body hr { margin: 2em 0; border: 0; border-top: 1px solid var(--rd-border); }

.rd-body blockquote {
  margin: 0 0 1.3em; padding: 16px 20px;
  border-left: 3px solid var(--rd-l1); border-radius: 0 6px 6px 0;
  background: var(--rd-card); box-shadow: 0 1px 0 var(--rd-border);
  font-size: .96em;
}
.rd-body blockquote p { margin: 0 0 .7em; }
.rd-body blockquote p:last-of-type { margin-bottom: 0; }
.rd-body blockquote cite { display: block; margin-top: .8em; font-style: normal; }

/* 引文出处徽章：A 亲笔 / B 采访 / C 编者整理（必须显式提示非本人措辞） */
.rd-cite {
  display: inline-flex; flex-wrap: wrap; align-items: center; gap: 5px;
  margin-left: 2px; padding: 1px 7px 1px 3px;
  border: 1px solid var(--rd-border); border-radius: 99px; background: var(--rd-bg);
  color: var(--rd-light); font-size: .68em; line-height: 1.7; vertical-align: baseline;
}
.rd-tier {
  display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%;
  background: var(--rd-l4); color: #fff; font-family: Georgia, serif; font-size: 10px; font-weight: 700;
}
.rd-cite[data-tier="A"] .rd-tier { background: var(--rd-l1); }
.rd-cite[data-tier="B"] .rd-tier { background: var(--rd-l2); }
.rd-cite[data-tier="C"] .rd-tier { background: var(--rd-l5); }
.rd-cite[data-tier="D"] .rd-tier { background: var(--rd-light); }
.rd-cite-label { color: var(--rd-soft); }
.rd-cite-meta { color: var(--rd-light); }
.rd-cite[data-tier="C"] { border-color: var(--rd-l5); border-style: dashed; }
.rd-cite-warn { padding: 0 6px; border-radius: 99px; background: var(--rd-l5); color: #fff; letter-spacing: .04em; }
.rd-cite-ditto { padding: 1px 8px; }
.rd-source { display: block; }
.rd-infer { color: var(--rd-l5); font-size: .82em; }

.rd-table-wrap { margin: 0 0 1.3em; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.rd-body table { width: 100%; border-collapse: collapse; font-size: .8em; line-height: 1.65; }
.rd-body th, .rd-body td { padding: 9px 11px; border: 1px solid var(--rd-border); text-align: left; vertical-align: top; }
.rd-body th { background: var(--rd-card); color: var(--rd-soft); font-weight: 600; white-space: nowrap; }
.rd-body tbody tr:nth-child(even) { background: rgba(255, 253, 249, .6); }

/* 段落级锚点 */
.rd-anchor {
  position: absolute; left: -1.55em; top: .18em;
  width: 1.2em; height: 1.2em; display: grid; place-items: center;
  border-radius: 4px; color: var(--rd-light); font-size: .8em; text-decoration: none;
  opacity: 0; transition: opacity .12s ease;
}
.rd-block:hover > .rd-anchor, .rd-anchor:focus-visible { opacity: 1; }
.rd-anchor:hover { background: var(--rd-accent-light); color: var(--rd-accent); }
.rd-subanchor { display: block; height: 0; overflow: hidden; }
.rd-block:target > :not(.rd-anchor):not(.rd-subanchor),
.rd-block.rd-flash > :not(.rd-anchor):not(.rd-subanchor) { animation: rd-flash 1.6s ease-out; }
@keyframes rd-flash { 0%, 35% { background: rgba(184, 93, 61, .13); } 100% { background: transparent; } }
[id] { scroll-margin-top: 80px; }

/* ---- 上一章 / 下一章 ---- */
.rd-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 40px; padding-top: 26px; border-top: 1px solid var(--rd-border); }
.rd-pager a {
  display: block; min-height: 62px; padding: 13px 16px;
  border: 1px solid var(--rd-border); border-radius: 8px; background: var(--rd-card);
  text-decoration: none; transition: .15s ease;
}
.rd-pager a:hover { border-color: var(--rd-accent); transform: translateY(-2px); box-shadow: 0 6px 18px rgba(58, 47, 36, .07); }
.rd-pager span { display: block; color: var(--rd-light); font-size: 11px; }
.rd-pager strong { display: block; margin-top: 5px; font-size: 14px; font-weight: 600; line-height: 1.45; }
.rd-pager .rd-next { text-align: right; grid-column: 2; }
.rd-pager .rd-end { grid-column: 2; display: flex; align-items: center; justify-content: flex-end; color: var(--rd-light); font-size: 12px; }
.rd-foot-note { max-width: var(--rd-measure); margin: 30px 0 0; color: var(--rd-light); font-size: 12px; line-height: 1.8; }
.rd-foot-note b { color: var(--rd-soft); }
.rd-foot-note code { padding: 1px 5px; border-radius: 4px; background: var(--rd-card); font-size: 11px; }

/* ---- 本章涉及节点 ---- */
.rd-aside { position: sticky; top: 26px; }
.rd-nodes { padding: 16px; border: 1px solid var(--rd-border); border-top: 3px solid var(--rd-l3); background: var(--rd-card); }
.rd-nodes h2 { margin: 0 0 4px; font-size: 13px; letter-spacing: .02em; }
.rd-nodes > p { margin: 0 0 12px; color: var(--rd-light); font-size: 11px; }
.rd-node { display: block; padding: 9px 0; border-top: 1px solid var(--rd-border); text-decoration: none; }
.rd-node:first-of-type { border-top: 0; }
.rd-node b { display: block; font-size: 13px; font-weight: 600; }
.rd-node b:hover { color: var(--rd-accent); }
.rd-node i { font-style: normal; color: var(--rd-light); font-size: 10px; }
.rd-node q { display: block; margin-top: 4px; color: var(--rd-soft); font-size: 11.5px; line-height: 1.6; quotes: "「" "」"; }
.rd-rel { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 99px; font-size: 10px; vertical-align: 1px; }
.rd-rel[data-r="deepens"] { background: var(--rd-accent-light); color: var(--rd-accent-dark); }
.rd-rel[data-r="exemplifies"] { background: #e8eee2; color: var(--rd-l5); }
.rd-rel[data-r="contradicts"] { background: #f1e3de; color: var(--rd-l1); }

/* ---- 悬浮目录按钮 / 抽屉 / 提示 ---- */
.rd-toc-fab {
  display: none; position: fixed; right: 16px; bottom: 18px; z-index: 25;
  min-height: 44px; padding: 0 18px; border: 1px solid var(--rd-accent); border-radius: 99px;
  background: var(--rd-accent); color: #fff; font-size: 13px; cursor: pointer;
  box-shadow: 0 8px 22px rgba(58, 47, 36, .22);
}
.rd-scrim { position: fixed; inset: 0; z-index: 18; background: rgba(58, 47, 36, .32); }
.rd-toast {
  position: fixed; left: 50%; bottom: 26px; z-index: 40; transform: translateX(-50%);
  padding: 9px 16px; border-radius: 99px; background: var(--rd-ink); color: var(--rd-bg); font-size: 13px;
  box-shadow: 0 8px 22px rgba(58, 47, 36, .3);
}
.rd-muted { color: var(--rd-light); }
.rd-error { padding: 18px; border: 1px solid var(--rd-border-strong); border-radius: 8px; background: var(--rd-card); }
.rd-error button { margin-top: 10px; padding: 7px 14px; border: 1px solid var(--rd-accent); border-radius: 7px; background: none; color: var(--rd-accent); cursor: pointer; }

/* ---- 响应式 ---- */
@media (max-width: 1460px) {
  .rd-shell { grid-template-areas: "toc stage" "toc aside"; grid-template-columns: 214px minmax(0, 1fr); gap: 30px; }
  .rd-aside { position: static; max-width: calc(var(--rd-measure) + 4em); margin-top: 34px; }
  .rd-nodes { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 22px; }
  .rd-nodes h2, .rd-nodes > p { grid-column: 1 / -1; }
}
@media (max-width: 1060px) {
  body[data-page="read"] .rd-main { padding: 26px 22px 96px; }
  .rd-shell { grid-template-areas: "stage" "aside"; grid-template-columns: minmax(0, 1fr); }
  .rd-stage, .rd-aside { max-width: none; }
  .rd-toc {
    position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(84vw, 320px);
    max-height: none; padding: 16px 10px; background: var(--rd-card);
    border-right: 1px solid var(--rd-border); box-shadow: 8px 0 25px rgba(58, 47, 36, .16);
    transform: translateX(-105%); transition: transform .2s ease;
  }
  .rd-toc.open { transform: translateX(0); }
  .rd-toc-close { display: block; }
  .rd-toc-fab { display: block; }
  .rd-body, .rd-article h1, .rd-summary, .rd-front, .rd-foot-note { max-width: 34em; }
}
@media (max-width: 760px) {
  body[data-page="read"] { --rd-fs: 17px; }
  body[data-page="read"][data-rd-size="s"] { --rd-fs: 16px; }
  body[data-page="read"][data-rd-size="l"] { --rd-fs: 19px; }
  body[data-page="read"] .rd-main { padding: 64px 16px 96px; }
  .rd-article { padding-top: 24px; }
  .rd-anchor { display: none; }
  .rd-pager { grid-template-columns: 1fr; }
  .rd-pager .rd-next, .rd-pager .rd-end { grid-column: 1; text-align: left; justify-content: flex-start; }
  .rd-doc { flex: 1 1 0; min-width: 0; justify-content: center; gap: 4px; min-height: 44px; padding: 8px 6px; font-size: 12.5px; }
  .rd-body table { font-size: .74em; }
  .rd-body blockquote { padding: 13px 15px; }
  .rd-cite { font-size: .66em; }
}

@media (prefers-reduced-motion: reduce) {
  .rd-progress i, .rd-toc, .rd-pager a, .rd-anchor { transition: none; }
  .rd-block.rd-flash > *, .rd-block:target > * { animation: none; }
}
