/* 八字课堂 — one stylesheet.
   Type: 12 / 13.5 / 15 / 17.5 (reading) / 20 / 26.  Space: 4 / 8 / 12 / 16 / 24 / 32 / 48. */

:root {
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "Noto Serif CJK SC", serif;
  --kai: "Kaiti SC", "STKaiti", "KaiTi", "BiauKai", "Songti SC", serif;
  --body-font: var(--sans);
  --ink: #2a2421;
  --ink-2: #4a413c;
  --muted: #6e635c;
  --faint: #8f847b;
  --line: #e6dfd5;
  --line-2: #efe9e1;
  --paper: #f7f4ee;
  --panel: #ffffff;
  --panel-2: #fbf9f5;
  --accent: #a63d2a;
  --accent-2: #7f2c1d;
  --accent-soft: #f6e6e0;
  --seal: #b4402c;
  --unc: #c0392b;
  --b1: #fde8df;
  --b1-line: #e7c2b2;
  --b2: #e4eef8;
  --b2-line: #c5d6ea;
  --b3: #e3f3e6;
  --b3-line: #b7dcc0;
  --wood: #2f7d4a;
  --fire: #c23b2b;
  --earth: #96652a;
  --metal: #a77a12;
  --water: #2563a6;
  --h1: rgba(250, 214, 92, 0.55);
  --h2: rgba(139, 205, 128, 0.5);
  --h3: rgba(126, 182, 240, 0.45);
  --h4: rgba(240, 140, 160, 0.42);
  --radius: 10px;
  --top-h: 52px;
  --shadow: 0 12px 32px rgba(43, 35, 32, 0.14);
  --shadow-s: 0 2px 8px rgba(43, 35, 32, 0.07);
  --fs: 1;
  --lh: 1.95;
  --bottom: 0px;
}

:root[data-theme="sepia"] {
  --ink: #3b2f22;
  --ink-2: #554634;
  --muted: #6f604c;
  --faint: #877760;
  --line: #e0d2b8;
  --line-2: #eadfca;
  --paper: #f3ead5;
  --panel: #faf4e6;
  --panel-2: #f6eedb;
  --accent-soft: #eddac5;
  --b1: #f3ddc8;
  --b1-line: #e0c2a4;
  --b2: #e4dcc4;
  --b2-line: #cfc3a4;
  --b3: #e3e6c8;
  --b3-line: #c5cba6;
}

:root[data-theme="dark"] {
  --ink: #e9e2da;
  --ink-2: #cfc5bb;
  --muted: #a99d92;
  --faint: #8c8076;
  --line: #3a332f;
  --line-2: #2e2825;
  --paper: #1b1715;
  --panel: #24201e;
  --panel-2: #211d1b;
  --accent: #e3806a;
  --accent-2: #f09a84;
  --accent-soft: #3b2721;
  --seal: #b4402c;
  --unc: #ef7c6d;
  --b1: #4a2e28;
  --b1-line: #6a463c;
  --b2: #243246;
  --b2-line: #3a5270;
  --b3: #1e3a2c;
  --b3-line: #2f5a42;
  --wood: #6cc08b;
  --fire: #f07a6a;
  --earth: #d2a36a;
  --metal: #e0bb57;
  --water: #79aee8;
  --h1: rgba(214, 170, 30, 0.38);
  --h2: rgba(90, 170, 90, 0.36);
  --h3: rgba(80, 140, 220, 0.38);
  --h4: rgba(220, 90, 120, 0.36);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  --shadow-s: 0 2px 8px rgba(0, 0, 0, 0.3);
}

:root[data-font="serif"] { --body-font: var(--serif); }
:root[data-font="kai"] { --body-font: var(--kai); }

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--top-h) + 64px); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  padding-bottom: var(--bottom);
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
img { max-width: 100%; height: auto; display: block; }
svg { display: block; }
[hidden] { display: none !important; }
button, a, summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
mark { background: #f4d97a; color: inherit; border-radius: 2px; padding: 0 1px; }
:root[data-theme="dark"] mark { background: #7a6420; }
kbd { display: inline-block; min-width: 18px; padding: 0 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; font: 12px/18px var(--sans); color: var(--muted); text-align: center; background: var(--panel); }
::selection { background: rgba(166, 61, 42, 0.2); }

/* ── Top bar ── */

#progress { position: fixed; top: 0; left: 0; right: 0; z-index: 25; height: 2px; pointer-events: none; }
#progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.12s linear; }

#top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  transition: transform 0.22s ease;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 17px; letter-spacing: 0.08em; white-space: nowrap; font-family: var(--serif); }
.brand:hover { color: inherit; }
.seal {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: var(--seal);
  color: #fff7f0;
  font-family: var(--serif);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: 0;
  writing-mode: vertical-rl;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.18);
}
#nav { display: flex; gap: 2px; }
#nav a { position: relative; padding: 6px 12px; border-radius: 8px; color: var(--muted); font-size: 14.5px; }
#nav a:hover { color: var(--ink); background: var(--line-2); }
#nav a[aria-current="page"] { color: var(--ink); font-weight: 600; }
#nav a[aria-current="page"]::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -9px; height: 2px; border-radius: 2px; background: var(--accent); }
#search-form { position: relative; margin-left: auto; display: flex; align-items: center; }
#search-form svg { position: absolute; left: 11px; width: 16px; height: 16px; color: var(--faint); pointer-events: none; }
#search-form kbd { position: absolute; right: 9px; pointer-events: none; }
#q {
  width: 260px;
  height: 36px;
  padding: 0 34px 0 34px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  font-size: 14px;
  transition: width 0.2s, border-color 0.15s;
}
#q::placeholder { color: var(--faint); }
#q:focus { outline: none; border-color: var(--accent); width: 320px; }
#q:focus + kbd { display: none; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; color: var(--ink-2); font-size: 15px; }
.icon-btn:hover { background: var(--line-2); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }
.search-btn { display: none; }
.aa-btn { font-family: var(--serif); font-weight: 600; font-size: 16px; }

/* ── Panels, popovers, toast ── */

.panel {
  position: fixed;
  z-index: 30;
  top: calc(var(--top-h) + env(safe-area-inset-top) + 6px);
  right: 12px;
  width: min(360px, calc(100vw - 24px));
  padding: 12px 16px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.pf-row { display: flex; align-items: center; gap: 10px; min-height: 46px; }
.pf-row > span:first-child { width: 36px; flex: none; color: var(--muted); font-size: 13.5px; }
.pf-val { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.pf-demo { margin: 8px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--paper); font-size: calc(16px * var(--fs)); line-height: var(--lh); }
.step { width: 42px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.step small { font-size: 11px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel); }
.seg button { padding: 6px 12px; font-size: 13.5px; color: var(--ink-2); border-left: 1px solid var(--line); white-space: nowrap; }
.seg button:first-child { border-left: 0; }
.seg button:hover { background: var(--line-2); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }

.pop {
  position: fixed;
  z-index: 40;
  max-width: min(320px, calc(100vw - 24px));
  padding: 8px 12px;
  border-radius: 9px;
  background: #2b2320;
  color: #f5ede6;
  font-size: 13.5px;
  line-height: 1.55;
  box-shadow: var(--shadow);
  pointer-events: none;
  white-space: pre-wrap;
}
.pop b { color: #f3c9a8; font-weight: 500; margin-right: 4px; }

#toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(24px + var(--bottom) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 9px 16px;
  border-radius: 20px;
  background: #2b2320;
  color: #f5ede6;
  font-size: 14px;
  box-shadow: var(--shadow);
  white-space: nowrap;
  animation: pop-in 0.18s ease-out;
}
@keyframes pop-in { from { opacity: 0; transform: translate(-50%, 6px); } }

#resume-pill {
  position: fixed;
  z-index: 18;
  left: 50%;
  bottom: calc(22px + var(--bottom) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 9px 18px;
  border-radius: 22px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: pop-in 0.2s ease-out;
}

/* ── Layout ── */

#main { display: block; outline: none; min-height: 60vh; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 32px 28px 72px; }
.narrow { max-width: 780px; }
.crumb { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); font-size: 13.5px; }
.crumb a:hover { text-decoration: underline; }
.crumb span[aria-hidden] { color: var(--faint); }
h1 { margin: 6px 0 8px; font-size: 27px; line-height: 1.35; font-weight: 650; letter-spacing: 0.01em; }
h2 { margin: 36px 0 12px; font-size: 18px; font-weight: 650; }
.lead { margin: 0; color: var(--ink-2); font-size: 15px; }
.muted { color: var(--muted); }
.tag {
  display: inline-block;
  padding: 0 8px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 20px;
  white-space: nowrap;
  background: var(--line-2);
  color: var(--muted);
  font-weight: 400;
}
.tag.raw { background: #fbe9d3; color: #9a5a12; }
:root[data-theme="dark"] .tag.raw { background: #4a3315; color: #e8b46a; }
.tag.unc { background: var(--accent-soft); color: var(--accent); }
.tag.pat { background: var(--accent-soft); color: var(--accent-2); }
.tag.star { background: none; color: var(--accent); padding: 0 2px; }
.sec-h { display: flex; align-items: baseline; gap: 12px; margin: 40px 0 14px; }
.sec-h h2 { margin: 0; font-size: 19px; font-family: var(--serif); letter-spacing: 0.04em; }
.sec-h a { margin-left: auto; color: var(--muted); font-size: 13.5px; }
.sec-h a:hover { color: var(--accent); }
.empty { padding: 28px 16px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); text-align: center; font-size: 14px; }

.bar { position: relative; height: 4px; border-radius: 2px; background: var(--line-2); overflow: hidden; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 2px; background: var(--accent); }
.btn { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 14px; color: var(--ink-2); white-space: nowrap; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); color: #fff; }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn.danger:hover { border-color: var(--unc); color: var(--unc); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 5px 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip .n { margin-left: 4px; color: var(--faint); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] .n { color: inherit; opacity: 0.7; }

/* status dot: unread / reading / done */
.st-dot { flex: none; display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--panel); }
.st-dot.seen { border-color: var(--faint); }
.st-dot.doing { border-color: var(--accent); background: linear-gradient(90deg, var(--accent) 50%, var(--panel) 50%); }
.st-dot.done { border-color: var(--accent); background: var(--accent); }

/* ── Home ── */

.hero { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin: 4px 0 24px; }
.hero h1 { font-family: var(--serif); font-size: 32px; margin: 0; letter-spacing: 0.08em; }
.hero p { margin: 4px 0 0; color: var(--muted); }
.hero .h-stats { display: flex; gap: 22px; }
.hero .h-stats a { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.3; }
.hero .h-stats b { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.hero .h-stats span { color: var(--muted); font-size: 12.5px; }
.resume {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px 16px;
  padding: 18px 20px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow-s);
}
.resume:hover { border-color: var(--accent); color: inherit; }
.resume .r-k { color: var(--muted); font-size: 13px; }
.resume .r-t { font-size: 18px; font-weight: 650; line-height: 1.45; }
.resume .r-go { grid-row: 1 / 3; grid-column: 2; display: inline-flex; align-items: center; height: 38px; padding: 0 18px; border-radius: 19px; background: var(--accent); color: #fff; font-size: 14px; white-space: nowrap; }
.resume .bar { grid-column: 1 / 3; margin-top: 8px; }
.recent { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.recent::-webkit-scrollbar { display: none; }
.recent a { flex: 0 0 230px; display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.recent a:hover { border-color: var(--accent); color: inherit; }
.recent .k { color: var(--muted); font-size: 12px; }
.recent .t { font-size: 14px; font-weight: 550; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.5; }

.courses { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.ccard {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 18px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.ccard:hover { border-color: var(--accent); color: inherit; transform: translateY(-2px); box-shadow: var(--shadow-s); }
.ccard .c-no { font-family: var(--serif); color: var(--accent); font-size: 13px; letter-spacing: 0.1em; }
.ccard .c-name { font-size: 18px; font-weight: 650; line-height: 1.45; }
.ccard .c-meta { color: var(--muted); font-size: 13px; }
.ccard .bar { margin-top: 10px; }
.ccard .c-last { margin-top: 8px; color: var(--ink-2); font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ccard .c-last::before { content: "上次 · "; color: var(--faint); }

.books { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 20px 18px; }
.bcard { display: flex; flex-direction: column; gap: 8px; }
.bcard:hover { color: inherit; }
.bcard .cover {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 4px 10px 10px 4px;
  overflow: hidden;
  background: linear-gradient(135deg, #8a3324, #5e2016);
  box-shadow: inset 6px 0 0 rgba(0, 0, 0, 0.12), 0 6px 18px rgba(43, 35, 32, 0.18);
  transition: transform 0.18s, box-shadow 0.18s;
}
.bcard:hover .cover { transform: translateY(-3px) rotate(-0.4deg); box-shadow: inset 6px 0 0 rgba(0, 0, 0, 0.12), 0 12px 26px rgba(43, 35, 32, 0.26); }
.bcard .cover img { width: 100%; height: 100%; object-fit: cover; }
.bcard .cover .ct { position: absolute; inset: 18px 14px; display: grid; place-items: center; color: #f6e8d8; font-family: var(--serif); font-size: 17px; text-align: center; line-height: 1.5; writing-mode: vertical-rl; margin: auto; letter-spacing: 0.15em; }
.bcard .b-name { font-size: 15px; font-weight: 600; line-height: 1.45; }
.bcard .b-meta { color: var(--muted); font-size: 12.5px; margin-top: -4px; }
.bcard .bar { height: 3px; }

/* ── Collection (course / book) page ── */

.c-head { display: grid; grid-template-columns: 1fr; gap: 6px; margin-bottom: 18px; }
.c-head.book { grid-template-columns: 132px 1fr; gap: 6px 22px; align-items: start; }
.c-head .cover { grid-row: 1 / 6; aspect-ratio: 3 / 4; border-radius: 3px 8px 8px 3px; overflow: hidden; box-shadow: 0 6px 18px rgba(43, 35, 32, 0.2); background: #7a2c1f; }
.c-head .cover img { width: 100%; height: 100%; object-fit: cover; }
.c-head h1 { margin: 2px 0 0; }
.c-head .c-prog { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin-top: 4px; }
.c-head .c-prog .bar { flex: 1; max-width: 320px; }
.c-head .c-act { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.c-note { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.filter { position: sticky; top: calc(var(--top-h) + env(safe-area-inset-top)); z-index: 9; display: flex; align-items: center; gap: 8px; padding: 10px 0; margin: 8px 0 4px; background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.filter input { flex: 1; min-width: 0; max-width: 240px; height: 32px; margin-left: auto; padding: 0 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); font-size: 13.5px; }
.filter input:focus { outline: none; border-color: var(--accent); }

.lessons { list-style: none; margin: 0; padding: 0; }
.lessons li { border-bottom: 1px solid var(--line); }
.lessons a { display: grid; grid-template-columns: 18px 40px 1fr auto; gap: 2px 10px; align-items: baseline; padding: 13px 8px; border-radius: 8px; }
.lessons a:hover { background: var(--panel); color: inherit; }
.lessons .st-dot { align-self: center; }
.lessons a.nl { grid-template-columns: 18px 1fr auto; }
.lessons a.nl .l-s { grid-column: 2 / 4; }
.lessons .l-no { font-variant-numeric: tabular-nums; color: var(--faint); font-size: 13.5px; }
.lessons .l-t { font-size: 15.5px; font-weight: 550; line-height: 1.5; }
.lessons a:hover .l-t { color: var(--accent); }
.lessons .l-s { grid-column: 3 / 5; color: var(--muted); font-size: 13.5px; line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lessons .l-tags { display: flex; gap: 4px; align-items: center; }
.lessons li.last a { background: var(--accent-soft); }
.lessons li.done .l-t { color: var(--ink-2); }
.group-h { position: relative; margin: 30px 0 6px; padding: 0 8px; font-size: 14.5px; color: var(--ink-2); font-weight: 650; font-family: var(--serif); letter-spacing: 0.04em; display: flex; gap: 10px; align-items: baseline; }
.group-h .n { color: var(--faint); font-weight: 400; font-size: 12.5px; font-family: var(--sans); }
/* 书的目录：章名醒目，节行紧凑（编号一列、标题、右边原书起始页），小标题一行淡字 */
.group-h.bk { margin: 34px 0 4px; padding: 0 8px 8px; font-size: 16.5px; color: var(--ink); border-bottom: 2px solid var(--ink); }
.group-h .gh-k, .gh .gh-k { margin-right: 0.6em; color: var(--accent); }
.c-list > .group-h.bk:first-child { margin-top: 14px; }
.lessons.bk a { padding: 10px 8px; gap: 1px 10px; }
.lessons.bk .l-no { text-align: right; font-size: 13px; }
.lessons.bk .l-t { font-size: 15px; }
.lessons.bk .l-s { -webkit-line-clamp: 1; font-size: 12.5px; color: var(--faint); }
.lessons .l-pg { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Reader ── */

.reader { display: grid; grid-template-columns: minmax(0, 1fr); max-width: 1440px; margin: 0 auto; }
.toc, .outline { display: none; }
@media (min-width: 1180px) {
  .reader { grid-template-columns: 290px minmax(0, 1fr); }
  .toc {
    display: block;
    position: sticky;
    top: calc(var(--top-h) + env(safe-area-inset-top));
    height: calc(100vh - var(--top-h) - env(safe-area-inset-top));
    overflow-y: auto;
    padding: 24px 12px 40px 18px;
    border-right: 1px solid var(--line);
    scrollbar-width: thin;
  }
}
@media (min-width: 1180px) { .lbar .toc-tool { display: none; } }
@media (min-width: 1440px) {
  .reader { grid-template-columns: 290px minmax(0, 1fr) 250px; }
  .outline {
    display: block;
    position: sticky;
    top: calc(var(--top-h) + env(safe-area-inset-top));
    height: calc(100vh - var(--top-h) - env(safe-area-inset-top));
    overflow-y: auto;
    padding: 28px 18px 40px 8px;
    scrollbar-width: thin;
  }
  .lbar [data-action="drawer"][data-tab="outline"] { display: none; }
}
.toc h3, .dr-body h3, .outline h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
.toc h3 a:hover { text-decoration: underline; }
.toc ol, .dr-body ol { list-style: none; margin: 0; padding: 0; }
.toc li a, .dr-body li a { display: flex; gap: 8px; align-items: baseline; padding: 6px 8px; border-radius: 7px; font-size: 13.5px; line-height: 1.45; color: var(--ink-2); }
.toc li a:hover, .dr-body li a:hover { background: var(--line-2); color: var(--ink); }
.toc li a[aria-current], .dr-body li a[aria-current] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.toc li .n, .dr-body li .n { flex: none; width: 26px; color: var(--faint); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.toc li .st-dot, .dr-body li .st-dot { width: 7px; height: 7px; border-width: 1.2px; align-self: center; }
.toc .gh, .dr-body .gh { margin: 16px 8px 4px; font-size: 12.5px; color: var(--faint); }
.ol-list { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--line); }
.ol-list a { display: block; padding: 5px 10px 5px 12px; margin-left: -1px; border-left: 2px solid transparent; font-size: 13px; line-height: 1.5; color: var(--muted); }
.ol-list a.l3 { padding-left: 24px; font-size: 12.5px; }
.ol-list a:hover { color: var(--ink); }
.ol-list a.on { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.ol-empty { color: var(--faint); font-size: 13px; padding: 4px 0; }

.lesson { min-width: 0; max-width: 760px; width: 100%; margin: 0 auto; padding: 28px 28px 96px; }
.lesson > h1 { font-size: 28px; line-height: 1.4; margin: 10px 0 6px; font-family: var(--serif); letter-spacing: 0.02em; }
.l-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 13px; }
.l-meta span + span::before { content: "·"; margin-right: 14px; color: var(--faint); }
.lesson .summary { margin: 12px 0 0; padding: 0 0 0 14px; border-left: 3px solid var(--accent-soft); color: var(--ink-2); font-size: 15px; line-height: 1.75; }

/* case card (案例课的命盘) */
.case { margin: 20px 0 6px; padding: 16px 18px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: var(--shadow-s); }
.case-h { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 12px; font-size: 13.5px; }
.case-h .sex { font-family: var(--serif); font-weight: 650; font-size: 15px; }
.case-h .who { color: var(--muted); }
.pillars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-width: 420px; margin: 0 auto; }
.pl { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px; border-radius: 10px; background: var(--paper); }
.pl.day { background: var(--accent-soft); }
.pl-k { color: var(--muted); font-size: 12px; }
.pl-g, .pl-z { font-family: var(--serif); font-size: 30px; line-height: 1.25; font-weight: 600; }
.dayun { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); font-size: 13px; }
.dayun .dy-k { color: var(--muted); margin-right: 4px; }
.dayun .dy { display: inline-flex; flex-direction: column; align-items: center; min-width: 44px; padding: 3px 6px; border-radius: 8px; background: var(--paper); line-height: 1.3; }
.dayun .dy i { font-style: normal; color: var(--faint); font-size: 11px; }
.dayun .dy b { font-family: var(--serif); font-size: 15px; font-weight: 600; }

.sltext { margin: 10px 0 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.sltext summary { display: flex; align-items: center; gap: 8px; padding: 10px 14px; color: var(--ink-2); font-size: 14px; font-weight: 550; cursor: pointer; list-style: none; }
.sltext summary::-webkit-details-marker { display: none; }
.sltext summary::before { content: "▸"; color: var(--faint); transition: transform 0.15s; }
.sltext[open] summary::before { transform: rotate(90deg); }
.sltext summary .muted { font-weight: 400; font-size: 12.5px; }
.st-item { margin: 0 14px 12px; padding: 10px 14px; border-left: 3px solid var(--accent-soft); background: var(--paper); border-radius: 0 8px 8px 0; }
.st-n { display: block; color: var(--faint); font-size: 12px; margin-bottom: 2px; }
.st-body { font-size: 15px; line-height: 1.8; color: var(--ink-2); }

.book-note { display: flex; gap: 10px; align-items: flex-start; margin: 18px 0 0; padding: 10px 14px; border-radius: 10px; background: var(--line-2); color: var(--ink-2); font-size: 13.5px; line-height: 1.6; }
.book-note button { margin-left: auto; flex: none; color: var(--accent); font-size: 13.5px; }

.lbar {
  position: sticky;
  top: calc(var(--top-h) + env(safe-area-inset-top));
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 18px -10px 10px;
  padding: 4px 10px;
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.lbar .spacer { flex: 1; }
.lbar .tool { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; color: var(--ink-2); }
.lbar .tool:hover { background: var(--line-2); color: var(--ink); }
.lbar .tool svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.lbar .tool[aria-pressed="true"] { color: var(--accent); }
.lbar .tool[aria-pressed="true"] svg { fill: currentColor; }
.legend { color: var(--muted); font-size: 12.5px; }

.text { font-family: var(--body-font); font-size: calc(17.5px * var(--fs)); line-height: var(--lh); letter-spacing: 0.015em; color: var(--ink); font-feature-settings: "palt" 0; hanging-punctuation: allow-end; }
.text p { margin: 0 0 1.1em; text-align: justify; text-justify: inter-ideograph; }
.notice { margin: 16px 0; padding: 12px 14px; border-radius: 10px; background: var(--line-2); color: var(--ink-2); font-size: 14px; }
.notice.warn { background: #fbefdc; color: #7c4a0e; }
:root[data-theme="dark"] .notice.warn { background: #3d2c14; color: #e9c48a; }

.wx-on .w0 { color: var(--wood); }
.wx-on .w1 { color: var(--fire); }
.wx-on .w2 { color: var(--earth); }
.wx-on .w3 { color: var(--metal); }
.wx-on .w4 { color: var(--water); }
.wx-on .gz { font-weight: 600; }

mark.find { background: rgba(244, 217, 122, 0.75); box-shadow: 0 0 0 1px rgba(217, 165, 32, 0.4); }
mark.find.cur { background: #f2a33a; box-shadow: 0 0 0 2px #f2a33a; color: #1d1410; }
:root[data-theme="dark"] mark.find { background: rgba(160, 128, 30, 0.6); }

/* highlights (划线) */
mark.hl { padding: 0; border-radius: 0; cursor: pointer; background: transparent; }
mark.hl.c1 { background: var(--h1); }
mark.hl.c2 { background: var(--h2); }
mark.hl.c3 { background: var(--h3); }
mark.hl.c4 { background: var(--h4); }
mark.hl.note-end::after { content: "✎"; display: inline-block; margin-left: 2px; font-size: 0.7em; vertical-align: super; color: var(--accent); font-family: var(--sans); }
mark.hl.flash { animation: flash 1.6s ease-out 2; }
@keyframes flash { 30% { box-shadow: 0 0 0 4px rgba(166, 61, 42, 0.35); } }

.selbar {
  position: fixed;
  z-index: 42;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  border-radius: 12px;
  background: #2b2320;
  color: #f5ede6;
  box-shadow: var(--shadow);
  font-size: 13.5px;
  user-select: none;
  -webkit-user-select: none;
}
.selbar .sw { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.selbar .sw::before { content: ""; width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.85); }
.selbar .sw.c1::before { background: #f4d65e; }
.selbar .sw.c2::before { background: #8fcf86; }
.selbar .sw.c3::before { background: #82b6ee; }
.selbar .sw.c4::before { background: #ef93a7; }
.selbar .sw[aria-pressed="true"] { background: rgba(255, 255, 255, 0.16); }
.selbar .sep { width: 1px; height: 20px; margin: 0 4px; background: rgba(255, 255, 255, 0.2); }
.selbar .act { height: 30px; padding: 0 9px; border-radius: 8px; color: #f5ede6; white-space: nowrap; }
.selbar .act:hover, .selbar .sw:hover { background: rgba(255, 255, 255, 0.12); }
.selbar .note-prev { max-width: 180px; padding: 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #e8d6c6; font-size: 12.5px; }

#findbar {
  position: fixed;
  z-index: 22;
  top: calc(var(--top-h) + env(safe-area-inset-top) + 8px);
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 6px 5px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
#findbar input { width: 170px; height: 32px; padding: 0 8px; border: 0; background: none; font-size: 14px; }
#findbar input:focus { outline: none; }
#findbar .fb-count { min-width: 52px; color: var(--muted); font-size: 12.5px; text-align: center; font-variant-numeric: tabular-nums; }
#findbar button { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; color: var(--ink-2); }
#findbar button:hover { background: var(--line-2); }
#findbar svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.done-box { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 14px; margin: 40px 0 0; padding: 22px 16px; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); font-size: 14px; text-align: center; }
.done-box.is-done { border-style: solid; background: var(--panel); color: var(--ink-2); }
.done-box .seal-s { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 14px; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 24px; }
.pager a { display: block; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.pager a:hover { border-color: var(--accent); color: inherit; }
.pager .k { display: block; color: var(--muted); font-size: 12.5px; }
.pager .t { display: block; font-size: 14.5px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager .next { text-align: right; grid-column: 2; }

/* ── 讲义 / 书 (Markdown) ── */
.md h2 { position: relative; margin: 2em 0 0.7em; padding-left: 14px; font-size: 1.18em; font-weight: 700; line-height: 1.5; font-family: var(--body-font); }
.md h2::before { content: ""; position: absolute; left: 0; top: 0.28em; bottom: 0.28em; width: 4px; border-radius: 2px; background: var(--accent); }
.md h3 { margin: 1.6em 0 0.5em; font-size: 1.06em; font-weight: 700; color: var(--accent-2); line-height: 1.55; }
.md > :first-child { margin-top: 0.4em; }
.md h4.sum { margin: 0 0 0.4em; font-size: 0.95em; color: var(--accent); letter-spacing: 0.16em; }
.sumbox { margin: 2.2em 0 1em; padding: 1em 1.2em 0.4em; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow-s); }
.sumbox > :last-child { margin-bottom: 0.6em; }
.md strong { font-weight: 700; }
.ann { color: var(--muted); font-size: 0.86em; }
.md ol, .md ul { margin: 0 0 1.1em; padding-left: 1.6em; }
.md li { margin: 0.3em 0; }
.md li::marker { color: var(--faint); }
.md blockquote { margin: 0 0 1.1em; padding: 0.5em 1em; border-left: 3px solid var(--accent-soft); background: var(--panel-2); border-radius: 0 8px 8px 0; color: var(--ink-2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.8em 0; }
.md .tbl { margin: 0.6em 0 1.3em; overflow-x: auto; container-type: inline-size; }
.md table { border-collapse: collapse; margin: 0 auto; font-size: 0.92em; line-height: 1.6; }
.md th, .md td { padding: 6px 14px; border: 1px solid var(--line); text-align: center; }
.md td.nw, .md th.nw, .md td.gzc { white-space: nowrap; }
.md .tbl td.lt, .md .tbl td.la, .md .tbl th.lt { text-align: left; }
.md thead th { background: var(--line-2); font-weight: 600; font-size: 0.9em; color: var(--muted); }
.md tbody th { background: var(--line-2); font-weight: 500; color: var(--muted); font-size: 0.9em; }
.md .tbl.chart table { font-family: var(--serif); border: 0; border-radius: 12px; overflow: hidden; background: var(--panel); box-shadow: 0 0 0 1px var(--line); }
.md .tbl.chart th, .md .tbl.chart td { border: 0; border-top: 1px solid var(--line-2); padding: 6px 18px; }
.md .tbl.chart thead th { border-top: 0; background: var(--panel-2); font-family: var(--sans); }
.md .tbl.chart tbody th { background: var(--panel-2); font-family: var(--sans); }
.md .tbl.chart td { font-weight: 600; }
.md .tbl.chart td.gzc { font-size: 1.32em; }
.md .tbl.chart td.gzc.g3 { font-size: 1.08em; }
@container (max-width: 520px) {
  .md .tbl.chart th, .md .tbl.chart td { padding: 5px 8px; }
  .md .tbl.chart tbody th { white-space: normal; padding: 5px 4px; min-width: 2.4em; }
}
.md figure { margin: 1.2em 0 1.4em; }
.md figure:not(.fg) button { display: block; width: fit-content; max-width: 100%; margin: 0 auto; border-radius: 10px; overflow: hidden; background: #fff; border: 1px solid var(--line); cursor: zoom-in; }
:root[data-theme="dark"] .md figure:not(.fg) button { filter: brightness(0.86); }
.md figure:not(.fg) img { width: auto; max-width: 100%; max-height: 62vh; object-fit: contain; }
.md figcaption { margin-top: 6px; color: var(--muted); font-size: 0.82em; text-align: center; }

/* 重画的课件 / 书插图 */
.md figure.fg {
  position: relative;
  margin: 1.35em 0 1.6em;
  padding: 30px 16px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-s);
}
.fg-tag { position: absolute; top: 8px; left: 14px; color: var(--faint); font-size: 11px; letter-spacing: 0.12em; font-family: var(--sans); }
.fg-src {
  position: absolute; right: 10px; top: 6px;
  padding: 0 4px; border: 0; background: transparent;
  color: var(--faint); font-size: 11px; line-height: 1.6; cursor: pointer; font-family: var(--sans);
}
.fg-src:hover { color: var(--accent); }
.fg-in { container-type: inline-size; font-size: 0.94em; line-height: 1.75; }
.fg-in h4 { margin: 0 0 4px; font-size: 16.5px; font-weight: 650; line-height: 1.45; font-family: var(--sans); text-align: left; }
.fg-in .fg-sub { margin: 0 0 8px; font-size: 14px; color: var(--muted); text-align: left; }
.fg-in p { margin: 0 0 0.4em; text-align: left; }
.fg-in .fg-note { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.fg-in .fg-hand, .fg-in .hand { font-family: var(--kai); color: var(--accent-2); }
.fg-in .mk { border: 1.5px solid var(--accent); border-radius: 4px; padding: 0 0.15em; }
.fg-in .fg-box { margin: 8px 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.fg-in .fg-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
@container (max-width: 520px) { .fg-in .fg-cols { grid-template-columns: 1fr; } }
.fg-in .fg-flow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
/* 「标签 | 内容」两栏（figlayout.js 标 fg-lab）：标签是窄窄一列、右边一道竖线像大括号，内容占满；手机上标签在上 */
.fg-in .fg-cols.fg-lab { grid-template-columns: fit-content(8.5em) minmax(0, 1fr); gap: 0 14px; align-items: stretch; }
.fg-in .fg-cols.fg-lab > :first-child {
  display: flex; flex-direction: column; justify-content: center;
  margin: 0; padding: 2px 12px 2px 0; border: 0; border-right: 2px solid var(--accent); border-radius: 0; background: none;
  color: var(--accent); font-weight: 650; font-family: var(--sans); line-height: 1.5;
}
.fg-in .fg-cols.fg-lab > :first-child p { margin: 0; color: inherit; }
.fg-in .fg-cols.fg-lab > :last-child { margin: 0; }
.fg-in .fg-cols.fg-lab > .fg-box:last-child { border: 0; padding: 0; background: none; }
@container (max-width: 520px) {
  .fg-in .fg-cols.fg-lab { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .fg-in .fg-cols.fg-lab > :first-child { padding: 0 0 4px; border-right: 0; border-bottom: 2px solid var(--accent); }
  .fg-in .fg-cols.fg-lab > :first-child br { display: none; }
}
/* 有一栏放不下半栏（figlayout.js 标 fg-span）时整组改成上下排，免得别的栏孤零零占半边 */
.fg-in .fg-cols:not(.fg-lab):has(> .fg-span) { grid-template-columns: minmax(0, 1fr); }
.fg-in .fg-cols.fg-lab.fg-num { grid-template-columns: auto minmax(0, 1fr); gap: 0 12px; }
.fg-in .fg-cols.fg-lab.fg-num > :first-child {
  align-self: start; justify-content: center; align-items: center; width: 1.7em; height: 1.7em; margin-top: 0.15em; padding: 0;
  border: 0; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 0.9em; font-family: var(--sans);
}
/* 一长串短条目（fg-lc）分栏排 */
.fg-in ul.fg-lc, .fg-in ol.fg-lc { columns: var(--lw, 10em) auto; column-gap: 0.8em; padding-left: 0; }
.fg-in .fg-lc > li { break-inside: avoid; margin-left: 1.8em; }
/* 四柱位置示意（fg-pos）：位置名淡、放了十神的格子突出 */
:is(.fg-in, .tbl) table.fg-pos { width: auto; min-width: min(100%, 15em); margin: 6px auto 8px; table-layout: fixed; }
:is(.fg-in, .tbl) table.fg-pos td, :is(.fg-in, .tbl) table.fg-pos th { width: 25%; padding: 5px 4px; background: none; font-family: var(--sans); white-space: nowrap; }
:is(.fg-in, .tbl) table.fg-pos .pn { color: var(--faint); font-size: 0.8em; font-weight: 400; }
:is(.fg-in, .tbl) table.fg-pos .pk { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.fg-in .fg-flow .ar { color: var(--muted); }
.fg-in .b1 { background: var(--b1); }
.fg-in .b2 { background: var(--b2); }
.fg-in .b3 { background: var(--b3); }
.fg-in span.b1, .fg-in span.b2, .fg-in span.b3 { padding: 0 0.2em; border-radius: 3px; }
.fg-in .c1 { color: var(--fire); }
.fg-in .c2 { color: var(--water); }
.fg-in .c3 { color: var(--wood); }
.fg-scroll { max-width: 100%; overflow-x: auto; }
.fg-in table { width: 100%; border-collapse: collapse; margin: 8px 0; font-family: var(--serif); }
.fg-in th, .fg-in td { white-space: normal; }
.fg-in .fg-pan, .fg-in .fg-yun { text-align: center; width: auto; min-width: min(100%, 280px); margin-left: auto; margin-right: auto; }
.fg-in .fg-pan td, .fg-in .fg-pan th { min-width: 2.8em; }
.fg-in .fg-pan caption, .fg-in .fg-yun caption { caption-side: top; margin-bottom: 4px; font-size: 13px; color: var(--muted); font-family: var(--sans); }
.fg-in .fg-pan th, .fg-in .fg-pan td, .fg-in .fg-yun th, .fg-in .fg-yun td { border: 0; border-top: 1px solid var(--line-2); padding: 4px 12px; text-align: center; }
.fg-in .fg-pan tr.gz td, .fg-in .fg-pan tr.gz th { font-size: 1.35em; font-weight: 700; color: var(--ink); }
.fg-in .fg-pan tr.ss td, .fg-in .fg-pan tr.ss th, .fg-in .fg-pan tr.num td, .fg-in .fg-pan tr.num th { font-size: 0.8em; color: var(--muted); font-weight: 400; }
.fg-in .fg-yun { font-size: 0.92em; }
.fg-in .fg-yun tr.gz td, .fg-in .fg-yun tr.gz th { font-size: 1.2em; font-weight: 700; }
.fg-in .fg-yun tr.ss td, .fg-in .fg-yun tr.num td, .fg-in .fg-yun tr.ss th, .fg-in .fg-yun tr.num th { font-size: 0.8em; color: var(--muted); font-weight: 400; }
.fg-in td.on, .fg-in th.on { background: var(--accent-soft); font-weight: 700; }
.fg-in .fg-tb th, .fg-in .fg-tb td { border: 1px solid var(--line); padding: 6px 8px; text-align: center; }
.fg-in .fg-tb th { background: var(--panel-2); font-weight: 600; font-family: var(--sans); }
.fg-in svg { display: block; width: 100%; max-width: 640px; height: auto; margin: 8px auto; }
.fg-in svg text { fill: var(--ink); stroke: none; font-family: var(--serif); }
.fg-in svg .ln { stroke: var(--ink); fill: none; }
.fg-in svg .ln2 { stroke: var(--line); fill: none; }
.fg-in svg .ah { fill: var(--ink); stroke: none; }
.fg-in svg .bx { fill: var(--panel-2); stroke: var(--line); }
.fg-in svg .tx { fill: var(--ink); stroke: none; }
.fg-in svg .tx2 { fill: var(--muted); stroke: none; }
.fg-in svg .b1 { fill: var(--b1); stroke: var(--b1-line); }
.fg-in svg .b2 { fill: var(--b2); stroke: var(--b2-line); }
.fg-in svg .b3 { fill: var(--b3); stroke: var(--b3-line); }
.fg-in svg text.c1, .fg-in svg tspan.c1 { fill: var(--fire); }
.fg-in svg text.c2, .fg-in svg tspan.c2 { fill: var(--water); }
.fg-in svg text.c3, .fg-in svg tspan.c3 { fill: var(--wood); }
.fg-in svg line.c1, .fg-in svg polyline.c1, .fg-in svg path.c1, .fg-in svg polygon.c1, .fg-in svg circle.c1, .fg-in svg ellipse.c1, .fg-in svg rect.c1 { stroke: var(--fire); fill: none; }
.fg-in svg line.c2, .fg-in svg polyline.c2, .fg-in svg path.c2, .fg-in svg polygon.c2, .fg-in svg circle.c2, .fg-in svg ellipse.c2, .fg-in svg rect.c2 { stroke: var(--water); fill: none; }
.fg-in svg line.c3, .fg-in svg polyline.c3, .fg-in svg path.c3, .fg-in svg polygon.c3, .fg-in svg circle.c3, .fg-in svg ellipse.c3, .fg-in svg rect.c3 { stroke: var(--wood); fill: none; }
.fg-in svg text.w0, .fg-in svg tspan.w0 { fill: var(--wood); }
.fg-in svg text.w1, .fg-in svg tspan.w1 { fill: var(--fire); }
.fg-in svg text.w2, .fg-in svg tspan.w2 { fill: var(--earth); }
.fg-in svg text.w3, .fg-in svg tspan.w3 { fill: var(--metal); }
.fg-in svg text.w4, .fg-in svg tspan.w4 { fill: var(--water); }
.fg-in svg line.w0, .fg-in svg polyline.w0, .fg-in svg path.w0 { stroke: var(--wood); fill: none; }
.fg-in svg line.w1, .fg-in svg polyline.w1, .fg-in svg path.w1 { stroke: var(--fire); fill: none; }
.fg-in svg line.w2, .fg-in svg polyline.w2, .fg-in svg path.w2 { stroke: var(--earth); fill: none; }
.fg-in svg line.w3, .fg-in svg polyline.w3, .fg-in svg path.w3 { stroke: var(--metal); fill: none; }
.fg-in svg line.w4, .fg-in svg polyline.w4, .fg-in svg path.w4 { stroke: var(--water); fill: none; }
.fg-in svg circle.w0, .fg-in svg ellipse.w0, .fg-in svg rect.w0, .fg-in svg polygon.w0 { fill: var(--wood); }
.fg-in svg circle.w1, .fg-in svg ellipse.w1, .fg-in svg rect.w1, .fg-in svg polygon.w1 { fill: var(--fire); }
.fg-in svg circle.w2, .fg-in svg ellipse.w2, .fg-in svg rect.w2, .fg-in svg polygon.w2 { fill: var(--earth); }
.fg-in svg circle.w3, .fg-in svg ellipse.w3, .fg-in svg rect.w3, .fg-in svg polygon.w3 { fill: var(--metal); }
.fg-in svg circle.w4, .fg-in svg ellipse.w4, .fg-in svg rect.w4, .fg-in svg polygon.w4 { fill: var(--water); }

/* 图里表格的版式（2026-10-18 第二版，decorateFigs 按格子字数打类）：
   文字格用无衬线、长句靠左；短格不折行（宁可横滑，也不挤成一字一行）；全是干支的格子用衬线大字；
   「编号 | 名目 | 一段话」这种列表式的表（fg-stack），手机上改成一条一块；很宽的矩阵表（fg-wide）首列固定。 */
.fg-in .fg-tb { font-size: 0.95em; }
.fg-in .fg-tb th, .fg-in .fg-tb td { font-family: var(--sans); line-height: 1.6; }
.fg-in td.lt, .fg-in th.lt, .fg-in td.la { text-align: left; }
.fg-in td.idx, .fg-in th.idx { white-space: nowrap; color: var(--muted); }
.fg-in td.nw, .fg-in th.nw { white-space: nowrap; }
.fg-in table.fg-tb > * > tr > td:not(.nw):not(.lt):not(.gzc), .fg-in table.fg-tb > * > tr > th:not(.nw):not(.lt):not(.gzc) { min-width: 6em; }
.fg-in td.gzc, .fg-in th.gzc { font-family: var(--serif); font-size: 1.12em; font-weight: 600; }
:is(.fg-in, .tbl) table.fg-wide > * > tr > :first-child { position: sticky; left: 0; z-index: 1; background: var(--panel-2); }
.fg-scroll {
  background:
    linear-gradient(to right, var(--panel) 30%, transparent) 0 0 / 28px 100% no-repeat local,
    linear-gradient(to left, var(--panel) 30%, transparent) 100% 0 / 28px 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, 0.14), transparent) 0 0 / 12px 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.14), transparent) 100% 0 / 12px 100% no-repeat scroll;
}
@container (max-width: 520px) {
  :is(.fg-in, .tbl) table.fg-stack, :is(.fg-in, .tbl) table.fg-stack > tbody, :is(.fg-in, .tbl) table.fg-stack > thead { display: block; width: 100%; }
  :is(.fg-in, .tbl) table.fg-stack > caption { display: block; margin-bottom: 6px; text-align: center; }
  :is(.fg-in, .tbl) table.fg-stack > * > tr { display: block; padding: 9px 12px; border: 1px solid var(--line); border-top: 0; }
  :is(.fg-in, .tbl) table.fg-stack > :first-child > tr:first-child { border-top: 1px solid var(--line); }
  :is(.fg-in, .tbl) table.fg-stack > thead > tr, :is(.fg-in, .tbl) table.fg-stack > * > tr.hd { background: var(--panel-2); text-align: center; }
  :is(.fg-in, .tbl) table.fg-stack > * > tr > td, :is(.fg-in, .tbl) table.fg-stack > * > tr > th { display: inline; padding: 0; border: 0; text-align: left; white-space: normal; font-weight: 650; font-size: 1em; }
  :is(.fg-in, .tbl) table.fg-stack > * > tr > :not(.lt) + :not(.lt)::before { content: "  ·  "; white-space: pre; color: var(--faint); font-weight: 400; }
  :is(.fg-in, .tbl) table.fg-stack > * > tr > .lt { display: block; margin-top: 3px; font-weight: 400; }
  :is(.fg-in, .tbl) table.fg-stack > * > tr > .lt + .lt { margin-top: 6px; }
  :is(.fg-in, .tbl) table.fg-stack > * > tr > :has(table) { display: block; margin: 6px 0 2px; }
  :is(.fg-in, .tbl) table.fg-stack > * > tr > :not(.lt) + :not(.lt):has(table)::before { content: none; }
  /* 竖排后每段前标列名（figlayout.js 给 td 加 data-h），表头那行不显示 */
  :is(.fg-in, .tbl) table.fg-stack.lbl > thead { display: none; }
  :is(.fg-in, .tbl) table.fg-stack.lbl > :first-child > tr:first-child { border-top: 1px solid var(--line); }
  :is(.fg-in, .tbl) table.fg-stack > * > tr > .lt[data-h]::before { content: attr(data-h) "　"; color: var(--accent); font-weight: 650; font-size: 0.92em; }
  /* 行首序号和后面的话排在一行 */
  :is(.fg-in, .tbl) table.fg-stack > * > tr > .idx { margin-right: 0.5em; color: var(--accent); }
  :is(.fg-in, .tbl) table.fg-stack > * > tr > .idx + .lt { display: inline; margin: 0; }
  :is(.fg-in, .tbl) table.fg-stack > * > tr > .idx + .lt ~ * { display: block; margin-top: 3px; }
  :is(.fg-in, .tbl) table.fg-stack > * > tr > .idx + .lt ~ *::before { content: none; }
  :is(.fg-in, .tbl) table.fg-stack > * > tr > .b1, :is(.fg-in, .tbl) table.fg-stack > * > tr > .b2, :is(.fg-in, .tbl) table.fg-stack > * > tr > .b3 { padding: 0 4px; border-radius: 3px; }
  .fg-in .fg-pan td, .fg-in .fg-pan th, .fg-in .fg-yun td, .fg-in .fg-yun th { min-width: 2.2em; padding: 4px 7px; }
  /* 十列的大运、流年条：格子收窄，手机上一屏放得下 */
  .fg-in .fg-yun:has(td:nth-child(9)) td, .fg-in .fg-yun:has(td:nth-child(9)) th { min-width: 0; padding: 4px 2px; }
}
/* 原书页码：靠右的小字，不占正文视线；宽屏放到正文右边的空白里 */
/* 原书页码：段与段之间靠右的一行小字（落在上一段的段后空白里，不多占地方） */
.pgm { display: flex; justify-content: flex-end; height: 14px; margin: -16px 0 2px; font-family: var(--sans); }
.pgm button { padding: 0 2px; color: var(--faint); font-size: 11px; line-height: 14px; letter-spacing: 0.02em; opacity: 0.8; }
.pgm button:hover { color: var(--accent); opacity: 1; }
.md > .pgm:first-child { margin-top: 0; }
.md > .pgm + p, .md > .pgm + h2, .md > .pgm + h3, .md > .pgm + figure { margin-top: 0; }

/* ── Search ── */

.s-box { position: relative; margin: 12px 0 12px; }
.s-box svg { position: absolute; left: 14px; top: 13px; width: 20px; height: 20px; color: var(--faint); pointer-events: none; }
.s-box input { width: 100%; height: 48px; padding: 0 16px 0 44px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); font-size: 17px; box-shadow: var(--shadow-s); }
.s-box input:focus { outline: none; border-color: var(--accent); }
.s-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; }
.s-filters select { height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 15px; background: var(--panel); font-size: 13px; color: var(--ink-2); max-width: 220px; }
.s-sum { color: var(--muted); font-size: 13.5px; margin: 14px 0 10px; }
.s-group { margin: 18px 0 8px; }
.s-group > summary { display: flex; align-items: baseline; gap: 10px; padding: 8px 4px; border-bottom: 2px solid var(--line); cursor: pointer; list-style: none; font-weight: 650; font-size: 15px; font-family: var(--serif); }
.s-group > summary::-webkit-details-marker { display: none; }
.s-group > summary .n { color: var(--muted); font-weight: 400; font-size: 12.5px; font-family: var(--sans); }
.s-group > summary::after { content: "▾"; margin-left: auto; color: var(--faint); font-family: var(--sans); transition: transform 0.15s; }
.s-group:not([open]) > summary::after { transform: rotate(-90deg); }
.hit { display: block; padding: 12px 6px; border-bottom: 1px solid var(--line); }
.hit:hover { color: inherit; background: var(--panel); }
.hit .h-t { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; font-weight: 600; font-size: 15px; }
.hit .h-c { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.hit .h-x { display: block; margin-top: 4px; color: var(--ink-2); font-size: 14px; line-height: 1.7; }
.hit .h-n { color: var(--faint); font-size: 12.5px; }
.s-more { display: block; width: 100%; padding: 10px; color: var(--accent); font-size: 13.5px; text-align: center; }
.s-recent { margin: 20px 0; }
.s-recent h3 { margin: 0 0 10px; font-size: 13.5px; color: var(--muted); font-weight: 600; }
.s-recent .chips + h3 { margin-top: 22px; }

/* ── 我的 ── */

.me-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 16px 0 8px; }
.stat { padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); }
.stat b { display: block; font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.3; }
.stat span { color: var(--muted); font-size: 13px; }
.prog-list { display: grid; gap: 10px; }
.prog-row { display: grid; grid-template-columns: minmax(0, 1fr) 140px 70px; gap: 12px; align-items: center; padding: 6px 4px; font-size: 14px; }
.prog-row:hover { color: inherit; }
.prog-row:hover .p-n { color: var(--accent); }
.prog-row .p-n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prog-row .p-v { color: var(--muted); font-size: 12.5px; text-align: right; font-variant-numeric: tabular-nums; }
.mlist { list-style: none; margin: 0; padding: 0; }
.mlist li { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.mlist li > a { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 11px 4px; }
.mlist .k { color: var(--muted); font-size: 12.5px; }
.mlist .t { font-size: 15px; font-weight: 550; }
.mlist .x { flex: none; width: 32px; height: 32px; border-radius: 8px; color: var(--faint); }
.mlist .x:hover { background: var(--line-2); color: var(--unc); }
.hl-group { margin: 16px 0; }
.hl-group > a { display: block; margin-bottom: 6px; font-weight: 600; font-size: 14.5px; }
.hl-group > a .k { color: var(--muted); font-weight: 400; font-size: 12.5px; margin-left: 6px; }
.hl-item { display: block; position: relative; margin: 0 0 8px; padding: 10px 14px 10px 16px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); }
.hl-item:hover { color: inherit; border-color: var(--accent); }
.hl-item::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 0 3px 3px 0; }
.hl-item.c1::before { background: #e8c240; }
.hl-item.c2::before { background: #6fbf64; }
.hl-item.c3::before { background: #5f9ee3; }
.hl-item.c4::before { background: #e57690; }
.hl-item .q { font-family: var(--body-font); font-size: 15px; line-height: 1.75; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.hl-item .nt { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); color: var(--ink-2); font-size: 14px; white-space: pre-wrap; }
.hl-item .nt::before { content: "笔记 · "; color: var(--accent); }
.hl-item .d { margin-top: 4px; color: var(--faint); font-size: 12px; }
.data-act { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

/* ── About ── */

.about p, .about li { color: var(--ink-2); }
.about .demo { padding: 12px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-family: var(--body-font); font-size: 16px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; align-items: center; font-size: 14px; }
.keys dt { text-align: right; white-space: nowrap; }
.keys dd { margin: 0; color: var(--ink-2); }

/* ── Modal ── */

#modal { position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; padding: 16px; }
.modal-back { position: absolute; inset: 0; background: rgba(20, 16, 14, 0.45); }
.modal-card { position: relative; width: min(520px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 20px 22px; border-radius: 16px; background: var(--panel); box-shadow: var(--shadow); animation: pop-in-m 0.16s ease-out; }
@keyframes pop-in-m { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.modal-card h3 { margin: 0 0 12px; font-size: 17px; }
.modal-card blockquote { margin: 0 0 12px; padding: 8px 12px; border-left: 3px solid var(--accent-soft); background: var(--paper); border-radius: 0 8px 8px 0; color: var(--ink-2); font-family: var(--body-font); font-size: 14.5px; max-height: 8em; overflow-y: auto; }
.modal-card textarea { width: 100%; min-height: 120px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); font-size: 15px; line-height: 1.7; resize: vertical; }
.modal-card textarea:focus { outline: none; border-color: var(--accent); }
.m-act { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* ── Lightbox ── */

#lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(12, 10, 9, 0.97); touch-action: none; }
.lb-stage { position: absolute; inset: 0 0 56px; display: grid; place-items: center; overflow: hidden; }
.lb-stage img { max-width: 100vw; max-height: calc(100vh - 56px); object-fit: contain; transform-origin: 50% 50%; user-select: none; -webkit-user-drag: none; background: #fff; }
.lb-bar { position: absolute; left: 0; right: 0; bottom: 0; height: calc(56px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: flex; align-items: center; justify-content: center; gap: 18px; color: #eee; font-size: 14px; font-variant-numeric: tabular-nums; }
.lb-bar button { width: 44px; height: 40px; border-radius: 8px; color: #eee; font-size: 24px; line-height: 1; }
.lb-bar button:hover { background: rgba(255, 255, 255, 0.1); }
.lb-bar .lb-close { position: absolute; right: max(12px, env(safe-area-inset-right)); font-size: 18px; }

/* ── Drawer ── */

#drawer { position: fixed; inset: 0; z-index: 45; }
.drawer-back { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); animation: fade 0.18s; }
@keyframes fade { from { opacity: 0; } }
.drawer-card { position: absolute; top: 0; bottom: 0; right: 0; width: min(380px, 90vw); display: flex; flex-direction: column; background: var(--paper); box-shadow: var(--shadow); animation: slide-in 0.2s ease-out; }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0.6; } }
.dr-tabs { display: flex; align-items: center; gap: 4px; padding: calc(10px + env(safe-area-inset-top)) 10px 8px 14px; border-bottom: 1px solid var(--line); }
.dr-tabs [role="tab"] { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.dr-tabs [role="tab"][aria-selected="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.dr-x { margin-left: auto; width: 36px; height: 36px; border-radius: 8px; color: var(--muted); }
.dr-body { flex: 1; overflow-y: auto; padding: 14px 12px calc(24px + env(safe-area-inset-bottom)); }

/* ── Bottom bars (phones) ── */

#tabbar, #rbar { display: none; }
@media (max-width: 760px) {
  :root { --top-h: 44px; }
  .brand { font-size: 16px; gap: 7px; }
  .icon-btn { width: 36px; height: 36px; }
  body.has-tabbar { --bottom: calc(58px + env(safe-area-inset-bottom)); }
  body.has-rbar { --bottom: calc(56px + env(safe-area-inset-bottom)); }
  #tabbar, #rbar {
    position: fixed;
    z-index: 21;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    height: calc(56px + env(safe-area-inset-bottom));
    padding: 0 max(4px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(4px, env(safe-area-inset-left));
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(12px);
    -webkit-backdrop-filter: saturate(1.4) blur(12px);
    border-top: 1px solid var(--line);
    transition: transform 0.22s ease;
  }
  body:not(.has-tabbar) #tabbar, body:not(.has-rbar) #rbar { display: none; }
  #tabbar a, #rbar > * { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 11px; }
  #tabbar svg, #rbar svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
  #tabbar a[aria-current="page"] { color: var(--accent); }
  #tabbar a[aria-current="page"] svg { stroke-width: 2; }
  body.chrome-away #rbar { transform: translateY(100%); }
  body.chrome-away.has-rbar #top { transform: translateY(-100%); }
  #rbar .rb-mark[aria-pressed="true"] { color: var(--accent); }
  #rbar .rb-mark[aria-pressed="true"] svg { fill: currentColor; }
  #rbar a:not([href]) { opacity: 0.3; pointer-events: none; }
  #top { gap: 8px; }
  #nav, #search-form { display: none; }
  .search-btn { display: inline-grid; margin-left: auto; }
  .wrap { padding: 20px 16px 48px; }
  .lesson { padding: 16px 18px 48px; }
  .lesson > h1 { font-size: 23px; }
  h1 { font-size: 23px; }
  .hero h1 { font-size: 26px; }
  .hero .h-stats { gap: 16px; }
  .courses { grid-template-columns: 1fr; gap: 10px; }
  .ccard { padding: 13px 16px 12px; gap: 2px; border-radius: 12px; }
  .ccard .c-name { font-size: 16.5px; }
  .books { grid-template-columns: repeat(2, 1fr); gap: 18px 14px; }
  .resume { padding: 16px; }
  .resume .r-t { font-size: 16.5px; }
  .resume .r-go { padding: 0 14px; }
  .c-head.book { grid-template-columns: 96px 1fr; gap: 4px 16px; }
  .lbar { position: static; margin: 12px 0 6px; padding: 0; gap: 4px; background: none; border: 0; backdrop-filter: none; -webkit-backdrop-filter: none; }
  .lbar .tool { width: 32px; height: 32px; }
  .lbar [data-action="drawer"] { display: none; }
  .text { font-size: calc(17.5px * var(--fs)); }
  .text p { text-align: left; }
  .lessons a { grid-template-columns: 14px 32px 1fr auto; padding: 12px 4px; gap: 2px 8px; }
  .lessons a.nl { grid-template-columns: 14px 1fr auto; gap: 2px 10px; }
  .step, .seg button { min-height: 36px; }
  .pager .t { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .prog-row { grid-template-columns: minmax(0, 1fr) 80px 56px; }
  .pillars { gap: 6px; }
  .pl-g, .pl-z { font-size: 26px; }
  #findbar { top: auto; bottom: calc(var(--bottom) + 10px + env(safe-area-inset-bottom)); left: 12px; right: 12px; }
  #findbar input { flex: 1; width: auto; }
  .filter input { max-width: 150px; }
}

@media (pointer: coarse) {
  .toc li a, .dr-body li a { padding: 10px 8px; }
  .ol-list a { padding-top: 8px; padding-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── 目录预览（卡片悬停、底部面板、顶栏下拉） ── */

.ccard-wrap, .bcard-wrap { position: relative; min-width: 0; display: flex; flex-direction: column; }
.ccard-wrap > .ccard, .bcard-wrap > .bcard { flex: 1; }
.ccard-wrap > .ccard { padding-bottom: 38px; }
.bcard-wrap > .bcard { padding-bottom: 32px; }
.ccard-wrap:hover > .ccard { border-color: var(--accent); color: inherit; transform: translateY(-2px); box-shadow: var(--shadow-s); }
.bcard-wrap:hover .cover { transform: translateY(-3px) rotate(-0.4deg); box-shadow: inset 6px 0 0 rgba(0, 0, 0, 0.12), 0 12px 26px rgba(43, 35, 32, 0.26); }
.toc-btn {
  position: absolute;
  z-index: 2;
  right: 8px;
  bottom: 8px;
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  box-shadow: var(--shadow-s);
}
.toc-btn:hover, .toc-btn[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }
.ccard-wrap:hover > .toc-btn { transform: translateY(-2px); }
@media (hover: hover) and (pointer: fine) {
  .toc-btn { opacity: 0; pointer-events: none; }
  .ccard-wrap:hover > .toc-btn,
  .bcard-wrap:hover > .toc-btn,
  .ccard-wrap:focus-within > .toc-btn,
  .bcard-wrap:focus-within > .toc-btn,
  .toc-btn:focus,
  .toc-btn:focus-visible,
  .toc-btn[aria-expanded="true"] { opacity: 1; pointer-events: auto; }
}
@media (pointer: coarse) {
  .toc-btn { height: 32px; padding: 0 12px; }
}

.nav-drop { display: flex; align-items: center; }
.nav-panel {
  position: fixed;
  z-index: 32;
  display: flex;
  width: min(760px, calc(100vw - 16px));
  height: min(70vh, 560px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: toc-in 0.12s ease-out;
}
.nav-left { width: 270px; flex: none; overflow: auto; overscroll-behavior: contain; border-right: 1px solid var(--line); padding: 6px; }
.nav-right { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 8px 8px 8px 10px; min-height: 0; overscroll-behavior: contain; }
#nav .nav-panel a { position: static; }
#nav .nav-panel a::after { content: none; }
#nav .nav-ci {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 400;
  background: none;
}
#nav .nav-ci i { flex: none; color: var(--accent); font-family: var(--serif); font-style: normal; font-size: 12px; letter-spacing: 0.06em; }
#nav .nav-ci .nn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#nav .nav-drop[data-drop="books"] .nav-ci .nn { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#nav .nav-ci .np { flex: none; color: var(--faint); font-variant-numeric: tabular-nums; font-size: 12px; }
#nav .nav-ci:hover, #nav .nav-ci.on { background: var(--accent-soft); color: inherit; }
#nav .nav-ci.on .nn { color: var(--accent); font-weight: 650; }
@media (hover: none), (pointer: coarse) {
  .nav-panel { display: none !important; }
}

.toc-pop {
  position: fixed;
  z-index: 35;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 16px));
  max-height: min(72vh, 600px);
  padding: 14px 14px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
  overscroll-behavior: contain;
  animation: toc-in 0.12s ease-out;
}
@keyframes toc-in { from { opacity: 0; } }
.toc-head { display: flex; flex-direction: column; gap: 2px; }
.toc-sheet-body .toc-head { padding-right: 36px; }
.toc-k { font-family: var(--serif); color: var(--accent); font-size: 12.5px; letter-spacing: 0.08em; }
.toc-name { font-size: 16px; font-weight: 650; line-height: 1.4; }
.toc-meta { display: flex; align-items: center; gap: 10px; margin: 8px 0; color: var(--muted); font-size: 12.5px; }
.toc-meta span { flex: none; }
.toc-meta .bar { flex: 1; height: 3px; }
.toc-head, .toc-meta, .toc-go, .toc-filter { flex: none; }
.toc-go { display: flex; align-items: center; width: 100%; height: 34px; margin: 0 0 8px; justify-content: center; font-size: 13.5px; overflow: hidden; }
.toc-go span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc-filter input {
  width: 100%;
  height: 30px;
  margin: 0 0 6px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  font-size: 13px;
}
.toc-filter input:focus { outline: none; border-color: var(--accent); }
.toc-scroll { overflow: auto; min-height: 0; overscroll-behavior: contain; }
.toc-pop .toc-scroll, .toc-sheet-body .toc-scroll { flex: 1 1 auto; }
.nav-right .toc-scroll { flex: 1; min-height: 0; }
.toc-lessons { list-style: none; margin: 0; padding: 0; }
.toc-lessons a {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 6px;
  border-radius: 7px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--ink-2);
  font-weight: 400;
  background: none;
}
#nav .toc-lessons a { display: flex; padding: 6px; color: var(--ink-2); font-weight: 400; background: none; }
.toc-lessons a:hover, #nav .toc-lessons a:hover { background: var(--line-2); color: var(--ink); }
.toc-lessons .n { flex: none; min-width: 1.5em; color: var(--faint); font-variant-numeric: tabular-nums; font-size: 12.5px; text-align: right; }
.toc-lessons .t { flex: 1; min-width: 0; }
.toc-lessons .st-dot { width: 7px; height: 7px; border-width: 1.2px; align-self: center; }
.toc-li.last > a { background: var(--accent-soft); }
.toc-li.last > a:hover { background: var(--accent-soft); }
.toc-gh { margin: 12px 6px 4px; font-size: 12.5px; color: var(--faint); font-weight: 650; font-family: var(--serif); }
.toc-gh.bk { margin-top: 16px; padding-bottom: 4px; color: var(--ink-2); border-bottom: 1px solid var(--line); }
.toc-empty { padding: 16px 8px; color: var(--muted); font-size: 13px; text-align: center; }

#toc-sheet { position: fixed; inset: 0; z-index: 46; }
.toc-sheet-back { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); animation: fade 0.12s; }
.toc-sheet-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  max-height: min(78vh, 640px);
  padding: 14px 14px calc(12px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  background: var(--paper);
  box-shadow: var(--shadow);
  overscroll-behavior: contain;
  animation: toc-in 0.12s ease-out;
}
.toc-sheet-x {
  position: absolute;
  z-index: 1;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--muted);
}
.toc-sheet-x:hover { background: var(--line-2); color: var(--ink); }
.toc-sheet-body { display: flex; flex-direction: column; min-height: 0; max-height: calc(min(78vh, 640px) - 28px); overflow: hidden; }
.toc-sheet-body .toc-scroll { overflow: auto; max-height: calc(min(78vh, 640px) - 210px); }

/* 重画图放得下时才出现的「放大」。不改 .fg / .fg-scroll 的排版。 */
.fg-zoom {
  position: absolute;
  right: 46px;
  top: 6px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: 11px;
  line-height: 1.6;
  cursor: pointer;
  font-family: var(--sans);
}
.fg-zoom:hover { color: var(--accent); }
#fgz { position: fixed; inset: 0; z-index: 48; background: var(--paper); }
.fgz-x {
  position: absolute;
  z-index: 2;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  box-shadow: var(--shadow-s);
}
.fgz-x:hover { color: var(--accent); }
.fgz-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 52px 16px 28px;
  touch-action: pan-x pan-y; /* 单指滑动交给浏览器（有惯性），双指缩放由 app.js 处理 */
  -webkit-overflow-scrolling: touch;
}
.fgz-md { min-height: 100%; }
.fgz-md figure.fg { margin: 0 auto; }

@media print {
  #top, #tabbar, #rbar, .lbar, .toc, .outline, .pager, .done-box, #progress, .book-note,
  #toc-pop, #toc-sheet, #fgz, .nav-panel, .toc-btn, .fg-zoom { display: none !important; }
  figure.fg, figure.fg-orig { break-inside: avoid; }
  body { background: #fff; }
  .lesson { max-width: none; padding: 0; }
}
