/*
 * 讀經：宣紙＋墨。米白紙底、墨黑字、一點朱紅（印章色）；深色＝夜墨（深灰底、淡金字）。
 * 經文原文：明體大字、淡紙色底、左邊一條朱紅線；本站解讀：黑體、白底卡片，標「本站整理」。
 * 版面：頁首 fixed（iOS 26 主畫面 app 頁首要 fixed 才不會糊）、文件本身不捲，只有 #main 捲。
 * 沒有一直跑的動畫（閒置 CPU 0）。
 */
:root {
  --bg: #f4eee2;
  --paper: #fbf8f1;
  --yuan-bg: #efe6d2;
  --ink: #2b2723;
  --ink-2: #4a443d;
  --muted: #7d7469;
  --line: #ddd2bf;
  --accent: #a8352a;
  --accent-soft: #f2ddd5;
  --on-accent: #fff8f0;
  --card-solid: #fbf8f1;
  --link: #8a2c22;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 2px 10px rgba(60, 40, 20, .05);
  --serif: "Noto Serif TC", "Songti TC", "STSong", "PMingLiU", "MingLiU", serif;
  --sans: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --hdr: 52px;
  --tabs: 58px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1b19; --paper: #252421; --yuan-bg: #2c2a25; --ink: #eadcbf; --ink-2: #d6c9ae; --muted: #a49a87; --line: #3b3832;
    --accent: #d88b6c; --accent-soft: #3a2a23; --on-accent: #1c1b19; --card-solid: #262522; --link: #e3a283;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1b19; --paper: #252421; --yuan-bg: #2c2a25; --ink: #eadcbf; --ink-2: #d6c9ae; --muted: #a49a87; --line: #3b3832;
  --accent: #d88b6c; --accent-soft: #3a2a23; --on-accent: #1c1b19; --card-solid: #262522; --link: #e3a283;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
html.standalone, html.standalone body { height: 100vh; }
body { color: var(--ink); font: 17px/1.75 var(--sans); -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
a { color: var(--link); text-decoration: none; }
button { font: inherit; color: inherit; }
h1, h2, h3, h4 { line-height: 1.35; }

/* ── 頁首（fixed） ── */
#hdr {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  height: calc(var(--hdr) + var(--safe-t)); padding: var(--safe-t) 6px 0;
  display: flex; align-items: center; gap: 2px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
#title { flex: 1; margin: 0; font: 700 19px/1 var(--serif); letter-spacing: .08em; padding-left: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#back:not([hidden]) + #title { padding-left: 0; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; color: var(--ink-2); border-radius: 12px; cursor: pointer; padding: 0; }
.icon-btn:active { background: var(--accent-soft); }

/* ── 內容（只有這裡捲） ── */
#main {
  position: fixed; left: 0; right: 0; top: calc(var(--hdr) + var(--safe-t)); bottom: calc(var(--tabs) + var(--safe-b));
  overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; outline: none;
}
.page { max-width: 680px; margin: 0 auto; padding: 16px 16px 40px; }

/* ── 分頁列 ── */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabs) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: var(--bg); border-top: 1px solid var(--line);
}
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--muted); font-size: 12px; line-height: 1.2; }
#tabs svg { width: 25px; height: 25px; }
#tabs a.on { color: var(--accent); font-weight: 600; }

/* ── 共用 ── */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); margin: 0 0 14px; }
.muted { color: var(--muted); }
.small { font-size: 14px; line-height: 1.6; }
.kicker { font-size: 13px; color: var(--accent); letter-spacing: .12em; margin: 0 0 6px; font-weight: 600; }
.h2 { font: 700 21px/1.4 var(--serif); margin: 22px 0 10px; letter-spacing: .04em; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 18px; border-radius: 12px; border: 1px solid var(--accent); background: var(--accent); color: var(--on-accent); font-weight: 600; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn[disabled] { opacity: .5; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.chip { display: inline-flex; align-items: center; min-height: 34px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); color: var(--ink-2); font-size: 15px; margin: 0 6px 8px 0; cursor: pointer; }
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.disclaimer { font-size: 13.5px; color: var(--muted); line-height: 1.6; border-top: 1px dashed var(--line); margin-top: 26px; padding-top: 12px; }
.wip { display: inline-block; font-size: 13px; padding: 1px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; vertical-align: 2px; }
.md p { margin: 0 0 .7em; }
.md ul { margin: 0 0 .7em; padding-left: 1.3em; }
.md li { margin: .2em 0; }
.md > :last-child { margin-bottom: 0; }

/* ── 原文（經文）：明體、紙色底、朱紅線 ── */
.yuan { font-family: var(--serif); font-weight: 500; font-size: 23px; line-height: 1.85; letter-spacing: .06em; color: var(--ink);
  background: var(--yuan-bg); border-left: 3px solid var(--accent); border-radius: 4px 10px 10px 4px; padding: 12px 14px; margin: 0; word-break: break-all; }
.yuan.big { font-size: 26px; }
.lbl { display: inline-block; font-size: 12.5px; letter-spacing: .1em; color: var(--muted); margin: 0 0 4px; }
.lbl.src { color: var(--accent); }

/* ── 解讀（本站整理）：黑體 ── */
.jie { padding: 10px 4px 0; }
.jie .plain { font-size: 17.5px; margin: 0 0 10px; }
.jie h4 { margin: 14px 0 4px; font-size: 14px; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.notes { margin: 0; padding: 0; }
.notes div { margin: 0 0 6px; font-size: 16px; line-height: 1.7; }
.notes dt { display: inline; font-weight: 700; color: var(--ink); }
.notes dt::after { content: "："; }
.notes dd { display: inline; margin: 0; color: var(--ink-2); }
.modern { font-size: 16px; color: var(--ink-2); margin: 0; }
.cons { margin-top: 10px; }
.ask-btn { margin-top: 6px; }

/* ── 閱讀頁 ── */
.sec-head { margin: 4px 0 14px; }
.sec-head h2 { font: 700 23px/1.4 var(--serif); margin: 0 0 6px; letter-spacing: .05em; }
.sec-head p { margin: 0; color: var(--ink-2); font-size: 16px; }
.modes { display: flex; gap: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin: 0 0 14px; }
.modes button { flex: 1; min-height: 40px; border: 0; background: var(--paper); color: var(--muted); font-size: 14.5px; cursor: pointer; }
.modes button.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.sent { margin: 0 0 18px; scroll-margin-top: 12px; }
.sent .jie { border-bottom: 1px solid var(--line); padding-bottom: 14px; }
.sent.focus .yuan { box-shadow: 0 0 0 2px var(--accent); }
.mode-yuan .jie { display: none; }
.mode-yuan .sent { margin-bottom: 8px; }
.mode-plain .jie h4, .mode-plain .notes, .mode-plain .modern, .mode-plain .cons, .mode-plain .ask-btn { display: none; }
.pager { display: flex; gap: 10px; margin-top: 18px; }
.pager a { flex: 1; min-height: 56px; display: flex; flex-direction: column; justify-content: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); font-size: 15px; color: var(--ink); }
.pager a small { color: var(--muted); font-size: 12.5px; }
.pager a.next { text-align: right; }

/* ── 目錄 ── */
.toc { list-style: none; margin: 0; padding: 0; }
.toc li a, .toc li span.off { display: flex; align-items: baseline; gap: 10px; min-height: 52px; padding: 10px 12px; border-bottom: 1px solid var(--line); color: var(--ink); }
.toc .n { color: var(--muted); font-size: 13px; min-width: 2.2em; }
.toc .t { font-family: var(--serif); font-size: 18px; flex: 1; }
.toc li span.off .t { color: var(--muted); }
.sutra-card { display: block; color: var(--ink); }
.sutra-card h3 { font: 700 22px/1.4 var(--serif); margin: 0 0 2px; letter-spacing: .06em; }

/* ── 每日一句 ── */
.daily .date { font-size: 13px; color: var(--muted); }
.daily .yuan { margin: 8px 0 10px; }

/* ── 概念頁 ── */
.c-name { font: 700 30px/1.3 var(--serif); margin: 4px 0 2px; letter-spacing: .08em; }
.rels { list-style: none; padding: 0; margin: 0; }
.rels li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 16px; }
.rels .ty { display: inline-block; min-width: 4.4em; font-size: 13px; color: var(--muted); }
.occ a { display: block; color: var(--ink); padding: 10px 0; border-bottom: 1px solid var(--line); }
.occ .yuan { font-size: 19px; padding: 8px 12px; }
.occ small { display: block; color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ── 概念地圖 ── */
.map-wrap { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.map-wrap svg { display: block; width: 100%; height: auto; }
.map-wrap .node { cursor: pointer; }
.map-wrap .node circle { fill: var(--paper); stroke: var(--ink-2); stroke-width: 1.4; }
.map-wrap .node.center circle { fill: var(--accent); stroke: var(--accent); }
.map-wrap .node.center text { fill: var(--on-accent); font-weight: 700; }
.map-wrap .node text { fill: var(--ink); font-family: var(--serif); font-size: 15px; text-anchor: middle; dominant-baseline: central; }
.map-wrap .edge { stroke: var(--muted); stroke-width: 1.3; fill: none; }
.map-wrap .edge.contains { stroke: var(--ink-2); stroke-width: 2; }
.map-wrap .edge.leads { stroke: var(--accent); }
.map-wrap .edge.opposite { stroke-dasharray: 5 4; }
.map-wrap .elabel { font-size: 13px; fill: var(--muted); text-anchor: middle; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); margin: 8px 2px 0; }
.legend i { display: inline-block; width: 22px; height: 0; border-top: 2px solid var(--muted); vertical-align: middle; margin-right: 4px; }
.legend i.contains { border-color: var(--ink-2); }
.legend i.leads { border-color: var(--accent); }
.legend i.opposite { border-top-style: dashed; }
.figs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 12px; padding: 0 16px; scrollbar-width: none; }
.figs::-webkit-scrollbar { display: none; }
.figs a { flex: none; }
.clist { display: flex; flex-wrap: wrap; }

/* ── 固定圖解 ── */
.fig-yun { display: grid; gap: 8px; }
.fig-yun a { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); }
.fig-yun b { font: 700 26px/1 var(--serif); color: var(--accent); min-width: 1.2em; text-align: center; }
.fig-yun span { font-size: 15.5px; color: var(--ink-2); line-height: 1.55; }
.ring svg { max-width: 420px; margin: 0 auto; }
.ring .lk circle { fill: var(--paper); stroke: var(--accent); stroke-width: 1.4; }
.ring .lk text { font-family: var(--serif); font-size: 15px; fill: var(--ink); text-anchor: middle; dominant-baseline: central; }
.ring .lk .no { font-family: var(--sans); font-size: 13px; fill: var(--muted); }
.ring .arc { stroke: var(--muted); stroke-width: 1.2; fill: none; }
table.gen { width: 100%; border-collapse: collapse; font-size: 16px; background: var(--paper); border-radius: 12px; overflow: hidden; }
table.gen th, table.gen td { border: 1px solid var(--line); padding: 8px 6px; text-align: center; }
table.gen th { font-size: 13.5px; color: var(--muted); font-weight: 600; }
table.gen td b { font-family: var(--serif); font-size: 19px; }

/* ── 底部面板（問 AI） ── */
.sheet-ov { position: fixed; inset: 0; z-index: 50; background: rgba(20, 16, 12, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 680px; max-height: calc(100% - var(--safe-t) - 24px); overflow-y: auto; overscroll-behavior: contain; background: var(--bg); border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + var(--safe-b)); box-shadow: 0 -8px 30px rgba(0, 0, 0, .25); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h3 { margin: 0 0 8px; font-size: 18px; }
.sheet .yuan { font-size: 19px; padding: 8px 12px; }
.thread .q { background: var(--accent-soft); border-radius: 12px 12px 4px 12px; padding: 8px 12px; margin: 12px 0 8px auto; max-width: 88%; width: fit-content; font-size: 16px; }
.thread .a { font-size: 16px; padding: 2px 2px 8px; border-bottom: 1px solid var(--line); }
.thread .a.err { color: var(--accent); }
.ask-row { display: flex; gap: 8px; margin-top: 12px; }
.input { flex: 1; min-width: 0; min-height: 46px; border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font: 16px var(--sans); background: var(--paper); color: var(--ink); }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.sugs { margin-top: 10px; }
.caret { display: inline-block; width: 7px; height: 1em; background: var(--accent); vertical-align: -2px; margin-left: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.thinking { color: var(--muted); font-size: 15px; }
@media (prefers-reduced-motion: reduce) { .caret { animation: none; } }
[hidden] { display: none !important; }
.map-wrap .elabel { paint-order: stroke; stroke: var(--paper); stroke-width: 5px; stroke-linejoin: round; }
.notes dt a { color: inherit; border-bottom: 1px dotted var(--accent); }
