/* ==========================================================================
   数字游乐场 · 全书视觉系统
   所有页面（目录、正文、交互游乐场）共用这一份 token 与排版基础
   ========================================================================== */

:root {
  /* 纸张与墨色 */
  --paper: #FFFBF2;
  --paper-2: #FFF4E1;
  --paper-3: #FFEBCF;
  --ink: #241F2E;
  --ink-2: #575060;
  --ink-3: #8B8294;
  --line: #EADFCB;
  --line-2: #D9C9AC;
  --white: #FFFFFF;

  /* 五支彩笔 */
  --coral: #FF6A5A;
  --coral-deep: #D8432F;
  --coral-soft: #FFE7E2;
  --sun: #FFC53D;
  --sun-deep: #C98A00;
  --sun-soft: #FFF2C9;
  --sky: #3FA9F5;
  --sky-deep: #1675B8;
  --sky-soft: #DFF1FF;
  --mint: #2FBF8F;
  --mint-deep: #0F8A61;
  --mint-soft: #D9F7EC;
  --grape: #8B5CF6;
  --grape-deep: #6635D6;
  --grape-soft: #EEE7FF;

  /* 版式 */
  --radius-s: 10px;
  --radius: 18px;
  --radius-l: 28px;
  --shadow-s: 0 1px 0 rgba(36, 31, 46, .05), 0 3px 10px -4px rgba(36, 31, 46, .14);
  --shadow: 0 2px 0 rgba(36, 31, 46, .04), 0 22px 48px -30px rgba(36, 31, 46, .5);
  --font-ui: "Hiragino Sans GB", "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-display: "Avenir Next", "Hiragino Sans GB", "PingFang SC", system-ui, sans-serif;
  --font-serif: Georgia, "Times New Roman", "STIXGeneral", "Hiragino Sans GB", serif;
  --font-mono: "SF Mono", Menlo, Consolas, "Courier New", monospace;

  --accent: var(--coral);
  --accent-deep: var(--coral-deep);
  --accent-soft: var(--coral-soft);
}

[data-accent="coral"] { --accent: var(--coral); --accent-deep: var(--coral-deep); --accent-soft: var(--coral-soft); }
[data-accent="sky"]   { --accent: var(--sky);   --accent-deep: var(--sky-deep);   --accent-soft: var(--sky-soft); }
[data-accent="mint"]  { --accent: var(--mint);  --accent-deep: var(--mint-deep);  --accent-soft: var(--mint-soft); }
[data-accent="grape"] { --accent: var(--grape); --accent-deep: var(--grape-deep); --accent-soft: var(--grape-soft); }
[data-accent="sun"]   { --accent: var(--sun);   --accent-deep: var(--sun-deep);   --accent-soft: var(--sun-soft); }

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(circle at 1px 1px, rgba(36, 31, 46, .05) 1px, transparent 0);
  background-size: 24px 24px;
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.9;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg, canvas { max-width: 100%; }
a { color: var(--accent-deep); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
a:hover { color: var(--accent); }
::selection { background: var(--sun-soft); color: var(--ink); }
:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; border-radius: 6px; }

/* ---------- 通用元件 ---------- */
.wrap { width: min(1180px, 100% - 48px); margin-inline: auto; }
.eyebrow {
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: .22em;
  color: var(--accent-deep);
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: .6em;
}
.eyebrow::before {
  content: "";
  width: 26px; height: 3px;
  border-radius: 99px;
  background: var(--accent);
}
.lead { font-size: 19px; line-height: 1.95; color: var(--ink-2); }
.accent-text { color: var(--accent-deep); }
.muted { color: var(--ink-3); }
.center { text-align: center; }
.hidden { display: none !important; }

.btn {
  --btn-bg: var(--accent);
  --btn-ink: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5em;
  padding: 12px 22px;
  border: 0;
  border-radius: 14px;
  background: var(--btn-bg);
  color: var(--btn-ink);
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.3;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(36, 31, 46, .16);
  transition: transform .12s ease, box-shadow .12s ease, background .2s ease;
}
.btn:hover { color: var(--btn-ink); transform: translateY(-1px); box-shadow: 0 5px 0 rgba(36, 31, 46, .16); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(36, 31, 46, .16); }
.btn-ghost {
  background: var(--white);
  color: var(--ink);
  box-shadow: 0 3px 0 var(--line-2);
  border: 1.5px solid var(--line-2);
}
.btn-ghost:hover { color: var(--ink); background: var(--paper-2); }
.btn-lg { padding: 15px 30px; font-size: 18px; border-radius: 16px; }
.btn-sm { padding: 8px 14px; font-size: 14px; border-radius: 11px; box-shadow: 0 2px 0 rgba(36, 31, 46, .16); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: .45em;
  padding: 5px 13px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  border: 1.5px solid color-mix(in srgb, var(--accent) 26%, transparent);
  font-size: 13.5px;
  font-weight: 800;
  line-height: 1.5;
  white-space: nowrap;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* ==========================================================================
   数学公式（由 minimath.js 生成）
   ========================================================================== */
.math {
  font-family: var(--font-serif);
  font-style: normal;
  line-height: 1.5;
  white-space: nowrap;
}
.math i { font-style: italic; font-family: var(--font-serif); }
.m-frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: -.32em;
  text-align: center;
  margin: 0 .14em;
  line-height: 1.1;
  font-size: .74em;
}
.m-frac .m-num { padding: 0 .22em; border-bottom: 1.6px solid currentColor; }
.m-frac .m-den { padding: 0 .22em; }
.m-sum { display: inline-flex; align-items: center; gap: .05em; vertical-align: -.28em; margin: 0 .12em; }
.m-sum .m-sum-op { font-size: 1.65em; line-height: 1; font-family: var(--font-serif); }
.m-sum .m-lim { display: inline-flex; flex-direction: column; font-size: .56em; line-height: 1.16; text-align: left; }
.m-sqrt { display: inline-flex; align-items: flex-start; }
.m-sqrt .m-sqrt-sym { font-size: 1.12em; line-height: 1.2; }
.m-sqrt .m-rad { border-top: 1.5px solid currentColor; padding: 0 .12em 0 .04em; margin-top: .1em; }
.m-op { font-style: normal; }
.m-text { font-family: var(--font-ui); font-style: normal; font-size: .92em; }
.m-space { display: inline-block; width: .28em; }

.formula {
  position: relative;
  margin: 1.7em 0;
  padding: 18px 22px;
  border-radius: var(--radius);
  background: var(--white);
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow-s);
  text-align: center;
  overflow: hidden;
}
.formula::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle at 1px 1px, rgba(36, 31, 46, .07) 1px, transparent 0);
  background-size: 16px 16px;
  opacity: .6;
  pointer-events: none;
}
.formula .math { position: relative; font-size: clamp(19px, 2.4vw, 25px); line-height: 1.9; }
.formula .label {
  position: relative;
  display: block;
  margin-bottom: 8px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .18em;
  color: var(--ink-3);
}
.formula.plain { background: var(--paper-2); }
.formula.math-big .math { font-size: clamp(23px, 3vw, 32px); }

/* ==========================================================================
   正文排版
   ========================================================================== */
.prose { font-size: 17.5px; line-height: 2.0; color: var(--ink); }
.prose > * { max-width: 100%; }
.prose p { margin: 1.05em 0; }
.prose > p:first-of-type { margin-top: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { font-family: var(--font-display); line-height: 1.35; letter-spacing: -.015em; }
.prose h1 { font-size: clamp(30px, 4.2vw, 44px); font-weight: 800; margin: .4em 0 .5em; }
.prose h2 {
  font-size: clamp(22px, 2.7vw, 29px);
  font-weight: 800;
  margin: 2.5em 0 .8em;
  display: flex;
  align-items: center;
  gap: .55em;
}
.prose h2::before {
  content: "";
  flex: none;
  width: .3em;
  height: 1.02em;
  border-radius: 99px;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.prose h3 {
  font-size: 19.5px;
  font-weight: 800;
  margin: 2em 0 .5em;
  color: var(--ink);
}
.prose h3::before {
  content: "✦ ";
  color: var(--accent);
  font-size: .9em;
}
.prose strong { font-weight: 800; color: var(--ink); }
.prose em { font-style: normal; background: linear-gradient(transparent 62%, var(--sun-soft) 62%, var(--sun-soft) 94%, transparent 94%); padding: 0 .08em; }
.prose .kw {
  background: linear-gradient(transparent 60%, var(--sun-soft) 60%, var(--sun-soft) 92%, transparent 92%);
  font-weight: 700;
  padding: 0 .1em;
}
.prose ul, .prose ol { margin: 1em 0; padding-left: 1.5em; }
.prose li { margin: .45em 0; padding-left: .2em; }
.prose ul > li::marker { color: var(--accent); }
.prose ol > li::marker { color: var(--accent-deep); font-weight: 800; font-family: var(--font-serif); }
.prose blockquote {
  margin: 1.6em 0;
  padding: 4px 0 4px 20px;
  border-left: 4px solid var(--line-2);
  color: var(--ink-2);
  font-size: 16.5px;
}
.prose hr {
  border: 0;
  height: 26px;
  margin: 2.4em auto;
  width: 120px;
  background:
    radial-gradient(circle, var(--line-2) 2.2px, transparent 2.6px) 0 50% / 26px 26px repeat-x;
  opacity: .9;
}
.prose code {
  font-family: var(--font-mono);
  font-size: .88em;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
}
.prose pre {
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  padding: 18px 20px;
  overflow: auto;
  font-size: 14px;
  line-height: 1.7;
}
.prose pre code { background: none; border: 0; padding: 0; color: inherit; }
.prose small { font-size: .82em; color: var(--ink-3); }
.prose .num { font-family: var(--font-serif); font-weight: 700; color: var(--accent-deep); font-size: 1.06em; }

/* 表格 */
.table-wrap { overflow-x: auto; margin: 1.6em 0; }
.prose table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 15px;
  line-height: 1.7;
  background: var(--white);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.prose th, .prose td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.prose th { background: var(--paper-2); font-weight: 800; font-size: 13.5px; letter-spacing: .04em; color: var(--ink-2); }
.prose tr:last-child td { border-bottom: 0; }
.prose tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--paper) 60%, transparent); }

/* 提示框 */
.callout {
  position: relative;
  margin: 1.9em 0;
  padding: 18px 22px 18px 24px;
  border-radius: var(--radius);
  background: var(--paper-2);
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow-s);
  font-size: 16.5px;
  line-height: 1.9;
}
.callout::before {
  content: "";
  position: absolute;
  left: 0; top: 16px; bottom: 16px;
  width: 6px;
  border-radius: 0 99px 99px 0;
  background: var(--callout-accent, var(--sun));
}
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout-title {
  display: flex;
  align-items: center;
  gap: .5em;
  margin: 0 0 .35em;
  font-weight: 800;
  font-size: 15.5px;
  letter-spacing: .03em;
  color: var(--callout-ink, var(--ink));
}
.callout-title .ic { font-size: 1.15em; }
.callout-story { background: var(--sun-soft); border-color: #F0D98F; --callout-accent: var(--sun); --callout-ink: #8a6200; }
.callout-idea { background: var(--mint-soft); border-color: #AEE8D3; --callout-accent: var(--mint); --callout-ink: #0b6b4b; }
.callout-warn { background: var(--coral-soft); border-color: #FFC2B8; --callout-accent: var(--coral); --callout-ink: #a02f1f; }
.callout-play { background: var(--sky-soft); border-color: #B4DDFB; --callout-accent: var(--sky); --callout-ink: #11618f; }
.callout-challenge { background: var(--grape-soft); border-color: #D2C1FF; --callout-accent: var(--grape); --callout-ink: #4f22b8; }
.callout-note { background: var(--white); border-color: var(--line); --callout-accent: var(--ink-3); }

/* 折叠答案 */
details.answer {
  margin: 1.1em 0;
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--white);
  border: 1.5px dashed var(--line-2);
}
details.answer summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--accent-deep);
  list-style: none;
}
details.answer summary::-webkit-details-marker { display: none; }
details.answer summary::before { content: "▸ "; }
details.answer[open] summary::before { content: "▾ "; }
details.answer[open] summary { margin-bottom: .5em; }
details.answer > :last-child { margin-bottom: 0; }

/* 图 */
figure { margin: 2em 0; }
figure svg, figure img { display: block; width: 100%; height: auto; border-radius: var(--radius); }
figcaption {
  margin-top: .7em;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--ink-3);
  text-align: center;
}

/* 玩一玩卡片 */
.play-card {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 1.8em 0;
  padding: 18px 22px;
  border-radius: var(--radius);
  background: linear-gradient(115deg, var(--white) 30%, var(--accent-soft));
  border: 1.5px solid color-mix(in srgb, var(--accent) 30%, var(--line));
  box-shadow: var(--shadow-s);
  text-decoration: none;
  color: inherit;
  transition: transform .18s ease, box-shadow .18s ease;
}
.play-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); color: inherit; }
.play-card .play-ic {
  flex: none;
  width: 54px; height: 54px;
  display: grid; place-items: center;
  border-radius: 15px;
  background: var(--accent);
  color: #fff;
  font-size: 25px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .12);
}
.play-card .play-body { flex: 1; min-width: 0; }
.play-card .play-kicker {
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: .18em;
  color: var(--accent-deep);
}
.play-card .play-title { font-size: 18px; font-weight: 800; margin: 2px 0; }
.play-card .play-desc { font-size: 14px; color: var(--ink-2); line-height: 1.65; }
.play-card .play-go {
  flex: none;
  font-weight: 800;
  color: var(--accent-deep);
  font-size: 14px;
  white-space: nowrap;
}

/* ==========================================================================
   目录页（index.html）
   ========================================================================== */
.cover {
  position: relative;
  overflow: hidden;
  padding: clamp(48px, 8vw, 100px) 0 clamp(40px, 6vw, 80px);
}
.cover-inner {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr);
  gap: clamp(24px, 5vw, 64px);
  align-items: center;
}
.cover-kicker {
  display: inline-flex;
  align-items: center;
  gap: .6em;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--sun-soft);
  border: 1.5px solid #EFD68B;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .08em;
  color: #7a5600;
}
.cover-title {
  margin: .5em 0 .2em;
  font-family: var(--font-display);
  font-size: clamp(52px, 9vw, 104px);
  line-height: .98;
  font-weight: 800;
  letter-spacing: -.03em;
}
.cover-title .t2 {
  display: inline-block;
  color: var(--coral);
  position: relative;
  transform: rotate(-1.5deg);
}
.cover-title .t2::after {
  content: "";
  position: absolute;
  left: 2%; right: 2%; bottom: .04em;
  height: .16em;
  background: var(--sun);
  border-radius: 99px;
  opacity: .55;
  z-index: -1;
}
.cover-sub {
  margin: 1.1em 0 .5em;
  font-size: clamp(19px, 2.2vw, 24px);
  font-weight: 700;
  color: var(--ink-2);
  line-height: 1.6;
}
.cover-desc { font-size: 16px; color: var(--ink-2); max-width: 30em; line-height: 1.95; }
.cover-actions { display: flex; flex-wrap: wrap; gap: 14px; margin: 1.8em 0 1.4em; }
.cover-meta {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--ink-3);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}
.cover-art { position: relative; }
.cover-art img { width: 100%; height: auto; filter: drop-shadow(0 24px 40px rgba(36, 31, 46, .16)); }
.cover-doodle {
  position: absolute;
  font-size: 34px;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .12));
  animation: bob 5s ease-in-out infinite;
}
.cover-doodle.d1 { top: 4%; left: -2%; animation-delay: -1s; }
.cover-doodle.d2 { bottom: 8%; left: 4%; font-size: 28px; animation-delay: -3s; }
.cover-doodle.d3 { top: 12%; right: 2%; font-size: 30px; animation-delay: -2s; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-10px) rotate(4deg); } }

.home-section { padding: clamp(30px, 5vw, 56px) 0; }
.home-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.home-head h2 { margin: 0; font-size: clamp(24px, 3vw, 32px); font-weight: 800; letter-spacing: -.02em; }
.home-head .eyebrow { margin-bottom: 6px; }
.how-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.how-card {
  padding: 22px;
  border-radius: var(--radius);
  background: var(--white);
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow-s);
}
.how-card .n {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-family: var(--font-serif);
  font-weight: 800;
  font-size: 17px;
  margin-bottom: 12px;
}
.how-card h3 { margin: 0 0 6px; font-size: 17px; font-weight: 800; }
.how-card p { margin: 0; font-size: 14.5px; line-height: 1.8; color: var(--ink-2); }

.shelf-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
.shelf-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 24px;
  border-radius: var(--radius-l);
  background: var(--white);
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow-s);
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease;
}
.shelf-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); color: inherit; }
.shelf-card::after {
  content: "";
  position: absolute;
  right: -40px; top: -40px;
  width: 140px; height: 140px;
  border-radius: 50%;
  background: var(--accent-soft);
  opacity: .75;
}
.shelf-card .shelf-num {
  position: relative;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 800;
  color: var(--accent-deep);
  letter-spacing: .1em;
}
.shelf-card h3 { position: relative; margin: 8px 0 6px; font-size: 24px; font-weight: 800; }
.shelf-card p { position: relative; margin: 0; font-size: 15px; color: var(--ink-2); line-height: 1.8; }
.shelf-card .shelf-foot {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}
.shelf-card.is-soon { opacity: .62; filter: saturate(.5); pointer-events: none; }

.toc-list { display: grid; gap: 10px; }
.toc-item {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 15px 18px;
  border-radius: 14px;
  background: var(--white);
  border: 1.5px solid var(--line);
  text-decoration: none;
  color: inherit;
  transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease;
}
.toc-item:hover { border-color: var(--accent); transform: translateX(3px); box-shadow: var(--shadow-s); color: inherit; }
.toc-item .toc-n {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 800;
  color: var(--accent-deep);
}
.toc-item .toc-main { display: block; min-width: 0; text-decoration: none; color: inherit; }
.toc-item .toc-t { display: block; font-weight: 800; font-size: 16.5px; }
.toc-item .toc-d { display: block; font-size: 13.5px; color: var(--ink-3); line-height: 1.6; }
.toc-item .toc-go { font-size: 13px; font-weight: 800; color: var(--accent-deep); white-space: nowrap; text-decoration: none; }
.toc-item:hover .toc-main { color: inherit; }

.site-footer {
  margin-top: 60px;
  padding: 34px 0 44px;
  border-top: 1.5px solid var(--line);
  color: var(--ink-3);
  font-size: 13.5px;
  line-height: 1.9;
}
.site-footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; }

/* ==========================================================================
   书页（book.html）
   ========================================================================== */
.bookbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1.5px solid var(--line);
}
.bookbar-inner {
  width: min(1280px, 100% - 40px);
  margin-inline: auto;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.bookbar .brand {
  font-weight: 800;
  font-size: 16px;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.bookbar .brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--coral); box-shadow: 0 0 0 4px var(--coral-soft); }
.bookbar .bar-nav { display: flex; gap: 6px; margin-left: auto; align-items: center; }
.bookbar .bar-nav a, .bookbar .bar-btn {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink-2);
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1.5px solid transparent;
  background: none;
  font-family: inherit;
  cursor: pointer;
}
.bookbar .bar-nav a:hover, .bookbar .bar-btn:hover { background: var(--paper-2); border-color: var(--line); color: var(--ink); }
.book-progress { position: absolute; left: 0; bottom: -1.5px; height: 3px; width: 0; background: var(--coral); border-radius: 99px; transition: width .1s linear; }

.book-layout {
  width: min(1280px, 100% - 40px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  gap: 48px;
  padding: 40px 0 80px;
}
.toc {
  position: sticky;
  top: 84px;
  align-self: start;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  padding-right: 6px;
  font-size: 13.5px;
  line-height: 1.7;
}
.toc::-webkit-scrollbar { width: 6px; }
.toc::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 99px; }
.toc-title {
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: .2em;
  color: var(--ink-3);
  margin: 0 0 12px;
}
.toc-group { margin-bottom: 18px; }
.toc-group > a {
  display: block;
  font-weight: 800;
  color: var(--ink);
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 8px;
}
.toc-group > a:hover { background: var(--paper-2); }
.toc-sub { margin: 2px 0 0; padding: 0; list-style: none; border-left: 2px solid var(--line); margin-left: 10px; }
.toc-sub a {
  display: block;
  padding: 5px 10px;
  color: var(--ink-2);
  text-decoration: none;
  border-radius: 0 8px 8px 0;
  line-height: 1.55;
}
.toc-sub a:hover { color: var(--accent-deep); background: var(--paper-2); }
.toc-sub a.is-active { color: var(--accent-deep); background: var(--accent-soft); font-weight: 800; }
.toc-extra { border-top: 1.5px dashed var(--line-2); padding-top: 14px; }
.toc-extra a { display: block; padding: 5px 10px; color: var(--ink-2); text-decoration: none; border-radius: 8px; }
.toc-extra a:hover { background: var(--paper-2); }

.reading { min-width: 0; max-width: 760px; }
.book-section { padding: 10px 0 30px; }
.book-section + .book-section { border-top: 1.5px dashed var(--line); margin-top: 20px; padding-top: 30px; }
.section-head { margin-bottom: 26px; }
.section-head .eyebrow { margin-bottom: 8px; }
.section-title {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: clamp(30px, 4.4vw, 46px);
  line-height: 1.18;
  font-weight: 800;
  letter-spacing: -.025em;
}
.section-sub { margin: 0; font-size: 18px; color: var(--ink-2); line-height: 1.7; }
.section-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

.chapter-head {
  position: relative;
  padding: 34px 30px;
  border-radius: var(--radius-l);
  background: linear-gradient(125deg, var(--white), var(--accent-soft));
  border: 1.5px solid color-mix(in srgb, var(--accent) 26%, var(--line));
  overflow: hidden;
  margin-bottom: 32px;
}
.chapter-head::after {
  content: attr(data-ghost);
  position: absolute;
  right: -10px; bottom: -46px;
  font-family: var(--font-serif);
  font-size: 190px;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
  opacity: .1;
  pointer-events: none;
}
.chapter-head .chapter-title {
  position: relative;
  margin: 10px 0 8px;
  font-size: clamp(34px, 5vw, 54px);
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.12;
}
.chapter-head .chapter-sub { position: relative; margin: 0; font-size: 18px; color: var(--ink-2); }
.chapter-head .chip-row { position: relative; margin-top: 16px; }

.page-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 40px 0 0;
}
.page-nav a {
  display: block;
  padding: 16px 20px;
  border-radius: 14px;
  background: var(--white);
  border: 1.5px solid var(--line);
  text-decoration: none;
  color: inherit;
  transition: border-color .15s, transform .15s;
}
.page-nav a:hover { border-color: var(--accent); transform: translateY(-2px); color: inherit; }
.page-nav .pn-k { font-size: 11.5px; font-weight: 800; letter-spacing: .16em; color: var(--ink-3); }
.page-nav .pn-t { font-weight: 800; font-size: 15.5px; margin-top: 3px; }
.page-nav .pn-next { text-align: right; }

.book-end {
  margin-top: 50px;
  padding: 30px;
  border-radius: var(--radius-l);
  background: var(--ink);
  color: var(--paper);
  text-align: center;
}
.book-end h3 { margin: 0 0 8px; font-size: 22px; }
.book-end p { margin: 0 auto; max-width: 34em; color: #D9D2C6; font-size: 14.5px; line-height: 1.9; }
.book-end .btn { margin-top: 18px; background: var(--sun); color: var(--ink); }

/* 打印封面（屏幕不显示） */
.print-cover { display: none; }

/* 打印 */
@media print {
  .print-cover {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 238mm;
    text-align: center;
    break-after: page;
  }
  .print-cover .pc-kicker {
    font-size: 11pt;
    font-weight: 800;
    letter-spacing: .35em;
    color: #8B8294;
  }
  .print-cover .pc-title {
    margin: 14mm 0 4mm;
    font-size: 46pt;
    font-weight: 800;
    letter-spacing: -.04em;
    line-height: 1.05;
    color: #241F2E;
  }
  .print-cover .pc-rule {
    width: 34mm;
    height: 2.2mm;
    border-radius: 99px;
    background: #FF6A5A;
    margin: 2mm 0 6mm;
  }
  .print-cover .pc-sub {
    font-size: 17pt;
    font-weight: 700;
    color: #575060;
    margin: 0;
  }
  .print-cover .pc-chapter {
    margin: 16mm 0 0;
    font-size: 15pt;
    font-weight: 800;
    color: #241F2E;
  }
  .print-cover .pc-author {
    margin: 3mm 0 0;
    font-size: 11pt;
    color: #8B8294;
  }
  .print-cover .pc-note {
    margin-top: 26mm;
    font-size: 9pt;
    color: #8B8294;
    line-height: 1.9;
  }

  @page { size: A4; margin: 18mm 17mm 20mm; }
  html { scroll-padding-top: 0; }
  body { background: #fff; font-size: 11.4pt; line-height: 1.82; }
  .no-print, .bookbar, .toc, .site-footer, .play-card .play-go, .page-nav, .book-end { display: none !important; }
  .book-layout { display: block; width: auto; margin: 0; padding: 0; }
  .reading { max-width: none; }
  .book-section { padding: 0; break-before: page; scroll-margin-top: 0; }
  .book-section:first-of-type { break-before: auto; }
  .book-section + .book-section { border: 0; margin: 0; padding: 0; }
  .chapter-head { padding: 18px 20px; }
  .chapter-head::after { font-size: 120px; opacity: .08; }
  .callout, .play-card, figure, table, details.answer, .formula { break-inside: avoid; }
  .formula { padding: 10px 14px; margin: 1.2em 0; overflow: visible; }
  .formula { font-size: 13.5pt; }
  .formula .katex { font-size: 1em; }
  .play-card { border: 1.5px dashed #bbb; background: #fff; padding: 10px 14px; margin: 1.2em 0; }
  .play-card::after { content: "（在网页版打开可动手玩）"; font-size: 8pt; color: #777; }
  a { color: inherit; text-decoration: none; }
  .site-footer { border: 0; }
  h1, h2, h3 { break-after: avoid; }
  .prose h2 { margin-top: 1.7em; }
  .section-head { margin-bottom: 18px; }
  .section-title { font-size: 26pt; }
  .chapter-head .chapter-title { font-size: 30pt; }
  .chapter-head .chapter-sub { font-size: 13pt; }
  .play-card .play-ic { width: 38px; height: 38px; font-size: 18px; }
}

/* 响应式 */
@media (max-width: 1020px) {
  .cover-inner { grid-template-columns: 1fr; }
  .cover-art { max-width: 520px; margin: 0 auto; order: -1; }
  .how-grid { grid-template-columns: 1fr; }
  .shelf-grid { grid-template-columns: 1fr; }
  .book-layout { grid-template-columns: 1fr; gap: 0; width: min(760px, 100% - 36px); }
  .toc { position: static; max-height: none; margin-bottom: 26px; padding: 18px; background: var(--white); border: 1.5px solid var(--line); border-radius: var(--radius); }
  .toc-group { margin-bottom: 10px; }
}
@media (max-width: 640px) {
  body { font-size: 16.5px; }
  .wrap { width: calc(100% - 32px); }
  .cover { padding-top: 30px; }
  .cover-title { font-size: clamp(46px, 16vw, 72px); }
  .home-head { flex-direction: column; align-items: flex-start; }
  .toc-item { grid-template-columns: 44px minmax(0, 1fr); }
  .toc-item .toc-go { grid-column: 2; }
  .page-nav { grid-template-columns: 1fr; }
  .page-nav .pn-next { text-align: left; }
  .section-title { font-size: 30px; }
}

/* 公式补充 */
/* 展示公式里的分数：居中、略放大，和等号对齐 */
.formula .m-frac,
.formula-card .m-frac { vertical-align: middle; font-size: .9em; }

.math sup, .math sub { font-size: .72em; line-height: 0; }
.math .m-overline { border-top: 1.4px solid currentColor; padding-top: .02em; }
.formula, .formula-card { overflow-x: auto; }

/* 交互卡片内部排版 */
.play-card .play-kicker,
.play-card .play-title,
.play-card .play-desc { display: block; }
.book-section, [id] { scroll-margin-top: 74px; }

/* 行内分数收紧，展示公式仍用居中大分数 */
.prose .m-frac, .math-inline .m-frac { font-size: .68em; vertical-align: -.26em; }
.prose .formula .m-frac, .formula-card .m-frac { font-size: .9em; vertical-align: middle; }

/* 打印目录（屏幕隐藏） */
.print-toc { display: none; }
@media print {
  .print-toc { display: block; break-after: page; padding-top: 4mm; }
  .print-toc .pt-kicker {
    font-size: 9.5pt; font-weight: 800; letter-spacing: .3em; color: #8B8294;
    border-bottom: 2.5px solid #FF6A5A; padding-bottom: 2mm; margin: 0 0 3mm;
  }
  .print-toc h2 { margin: 0 0 3mm; font-size: 20pt; font-weight: 800; letter-spacing: -.02em; }
  .print-toc .pt-list { list-style: none; padding: 0; margin: 0; }
  .print-toc .pt-list li {
    display: flex; align-items: baseline; gap: 4mm;
    padding: 0.82mm 0; border-bottom: 1px dotted #D9C9AC; font-size: 9.3pt;
  }
  .print-toc .pt-num { width: 13mm; flex: none; color: #8B8294; font-family: Georgia, serif; font-weight: 700; }
  .print-toc .pt-title { font-weight: 700; color: #241F2E; }
  .print-toc .pt-dots { flex: 1; border-bottom: 1px dotted #EADFCB; }
  .print-toc .pt-note { margin-top: 2mm; font-size: 7.5pt; line-height: 1.8; color: #8B8294; }
}

/* KaTeX 排版：让 .math 的字体大小接管公式大小 */
.math { display: inline-block; line-height: 1.2; white-space: nowrap; font-family: inherit; }
.math .katex { font-size: 1em; }
.formula { font-size: clamp(19px, 2.4vw, 25px); }
.formula .katex { font-size: 1em; }
.formula .katex-display { margin: 0; }
.formula-card .katex-display,
.res-formula .katex-display { margin: 0; }
.prose .math { vertical-align: baseline; }

/* 章节路线图 */
.chapter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.chapter-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 22px 24px 20px;
  border-radius: var(--radius-l);
  background: var(--white);
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow-s);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.chapter-card::after {
  content: "";
  position: absolute;
  right: -46px; top: -46px;
  width: 150px; height: 150px;
  border-radius: 50%;
  background: var(--accent-soft);
  opacity: .8;
  pointer-events: none;
}
.chapter-card.is-ready:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--accent); color: inherit; }
.chapter-card.is-writing { background: linear-gradient(150deg, var(--white), color-mix(in srgb, var(--accent-soft) 55%, var(--white))); }
.chapter-card .cc-top { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chapter-card .cc-num {
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .12em;
  color: var(--accent-deep);
}
.chapter-card .cc-status {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  color: var(--ink-3);
  border: 1.5px solid var(--line-2);
  border-radius: 999px;
  padding: 3px 10px;
  background: var(--white);
}
.chapter-card .cc-status.is-ready { color: var(--mint-deep); border-color: color-mix(in srgb, var(--mint) 40%, transparent); background: var(--mint-soft); }
.chapter-card h3 { position: relative; margin: 10px 0 4px; font-size: 21px; font-weight: 800; line-height: 1.35; letter-spacing: -.01em; }
.chapter-card .cc-theme { position: relative; margin: 0; font-size: 13.5px; line-height: 1.7; color: var(--ink-2); }
.chapter-card .cc-sections { position: relative; list-style: none; padding: 0; margin: 14px 0 0; display: flex; flex-direction: column; gap: 0; }
.chapter-card .cc-sections li {
  display: flex; gap: 10px; align-items: baseline;
  padding: 6px 0; border-bottom: 1px dashed var(--line);
  font-size: 13.5px; color: var(--ink-2);
}
.chapter-card .cc-sections li:last-child { border-bottom: 0; }
.chapter-card .cc-sections .n { flex: none; width: 2.6em; font-family: var(--font-serif); font-weight: 700; color: var(--accent-deep); }
.chapter-card .cc-go { position: relative; margin-top: 14px; font-size: 13px; font-weight: 800; color: var(--accent-deep); }
.chapter-card .cc-go.muted-go { color: var(--ink-3); }
@media (max-width: 760px) {
  .chapter-grid { grid-template-columns: 1fr; }
  .chapter-card { padding: 18px 18px 16px; }
}

/* 侧边目录：后续章节占位 */
.toc-soon-title {
  margin: 0 0 6px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
  color: var(--ink-3);
}
.toc-soon-item {
  display: block;
  padding: 4px 10px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-3);
  border-left: 2px dashed var(--line);
  margin-left: 10px;
}

/* 打印目录：章标题行 */
@media print {
  .print-toc .pt-list li.pt-chapter {
    border-bottom: 2px solid #FF6A5A;
    margin-top: 1.5mm;
    padding-top: 1.1mm;
    font-size: 9.6pt;
  }
  .print-toc .pt-list li.pt-chapter .pt-title { font-weight: 800; }
  .print-toc .pt-list li.pt-chapter .pt-num { color: #FF6A5A; width: 16mm; }
}

