/* ==========================================================================
   內文排版（article.doc）：對應 docs/converter.md 第 3 節的 class
   原則：經大注小、零裝箱、朱筆只做讀者行為、版心頁碼在右緣
   ========================================================================== */

.doc {
  font-family: var(--font-body);
  font-size: 1em;                 /* = --fs，由 .page-inner 設定 */
  line-height: var(--lh);
  text-align: justify;
  text-justify: inter-character;
  line-break: strict;
  overflow-wrap: anywhere;
  hanging-punctuation: last allow-end;
  text-spacing-trim: space-first;
  font-kerning: normal;
  color: var(--text);
}

/* 章節區塊（.sec）：目前不需要任何樣式。
   2026-09-17 之前這裡有 content-visibility: auto（只排版可見章節，改字級快很多）
   與 padding-right/margin-right 互抵（避免 paint containment 裁掉右緣頁碼）。
   content-visibility 會讓畫面外章節在佔位高度與實際高度之間切換，跳轉位置屢屢跳錯，已整個移除；
   互抵的留白隨之失去作用（實測有無皆不影響頁碼位置與版寬），一併拿掉。 */

/* 段落：書卷式（首行縮排、段距小） */
.doc p { margin: 0 0 .35em; text-indent: 2em; }
.doc p.empty { margin: 0; text-indent: 0; }
.doc p.opener, .doc p.byline, .doc p.sub-head, .doc p.label-head,
.doc p.h1, .doc p.juan, .doc p.closer, .doc p.dateline { text-indent: 0; }

.doc p.opener { color: var(--muted); font-size: .85em; text-align: left; margin: 0 0 .9em; }
.doc p.byline, .doc p.closer { text-align: right; color: var(--muted); margin: .5em 0 1.4em; }
/* 底本用過大的 margin-left 把落款推到版面右側，轉檔器換成這個 class（見 docs/converter.md）。
   絕對縮排在窄版心會把整段推出版外，靠右則任何版心都對。 */
.doc .align-right { text-align: right; text-indent: 0; }
.doc p.h1 {
  font-family: var(--font-kai); font-size: 1.35em; line-height: 1.4; letter-spacing: .06em;
  text-align: center; color: var(--head); margin: .4em 0 1.2em;
}
/* 書名行內的版本說明註：另起一行、回到內文字體與大小 */
.doc p.h1 .note-inline {
  display: block; margin-top: .6em;
  font-family: var(--font-body); font-size: .6em; letter-spacing: 0; line-height: var(--lh);
  text-align: justify; color: var(--muted);
}
.doc p.juan { text-align: center; color: var(--muted); letter-spacing: .12em; font-size: .9em; margin: 1.6em 0; }
.doc p.sub-head { color: var(--muted); font-size: 1.02em; margin: -.2em 0 .9em; }
.doc p.label-head { font-weight: 600; margin: .8em 0 .3em; }

/* 標題：明體 600、行高收緊，層級只以字級區分 */
.doc .head {
  font-family: var(--font-serif); font-weight: 600;
  color: var(--head); line-height: 1.4; letter-spacing: .04em;
  text-align: left; text-indent: 0;
  margin: 1.7em 0 .6em;
  scroll-margin-top: calc(var(--topbar-h) + var(--crumbbar-h) + 12px);
}
.doc h2.head { font-size: 1.5em; margin-top: 2.2em; }
.doc h3.head { font-size: 1.3em; }
.doc h4.head { font-size: 1.15em; }
.doc h5.head, .doc h6.head { font-size: 1.05em; }
.doc .sec > .head:first-child { margin-top: 1.4em; }
.doc > .sec:first-child > .head, .doc > .head:first-child { margin-top: 0; }

/* 科判行：預設隱藏；開啟時為縮小疏排淡墨的結構行 */
.doc p.kp { display: none; }
:root[data-kp="on"] .doc p.kp {
  display: block; text-indent: 0;
  font-family: var(--font-sans); font-size: .78em; letter-spacing: .28em; color: var(--muted);
  margin: .9em 0 .15em;
}

/* 經大注小：經文原文以楷體放大一級 */
.doc p.jing, .doc .orig > p {
  font-family: var(--font-kai); font-size: 1.08em; color: var(--head);
  text-indent: 0; margin: .9em 0;
}
.doc p.jing + p.jing, .doc .orig > p + p { margin-top: -.3em; }

/* 偈頌 */
.doc .lg { text-align: center; text-indent: 0; margin: 1.2em 0; line-height: calc(var(--lh) * 1.1); }
.doc .lg .l { text-indent: 0; }

/* 清單 */
.doc ul.list, .doc ol.list { margin: .8em 0 .8em 1.6em; padding: 0; }
.doc .list.no-marker { list-style: none; margin-left: 0; }
.doc .list li { text-indent: 0; margin: .3em 0; }
.doc .list li p { text-indent: 0; margin: 0; }

/* 圖 */
.doc figure { margin: 1.6em auto; text-align: center; text-indent: 0; }
.doc figure img { margin: 0 auto; max-width: 100%; height: auto; cursor: zoom-in; }
.doc figcaption { margin-top: .5em; font-size: .85em; color: var(--muted); font-family: var(--font-ui); }

/* 表格 */
.doc table.table { border-collapse: collapse; margin: 1em 0; width: 100%; font-size: .9em; }
.doc table.table td, .doc table.table th { border: 1px solid var(--rule); padding: .3em .6em; text-indent: 0; vertical-align: top; }

/* 行內註記 */
.doc .note-inline { font-size: .8em; color: var(--muted); }
.doc .note-inline::before { content: "（"; }
.doc .note-inline::after { content: "）"; }
.doc .seg-note { font-size: .8em; color: var(--muted); }
.doc .app {
  text-decoration: underline dotted var(--accent);
  text-decoration-thickness: 1px; text-underline-offset: .22em;
  cursor: help;
}
.doc .caesura { display: inline-block; width: 1em; }
.doc .space::before { content: "\3000"; }
.doc .space[data-quantity="2"]::before { content: "\3000\3000"; }
.doc .space[data-quantity="3"]::before { content: "\3000\3000\3000"; }
.doc .gaiji, .doc .unclear, .doc .supplied { color: var(--muted); }
.doc .milestone { display: none; }

/* 行號：預設不顯示；「原書換行」開啟時在此斷行 */
.doc .lb { display: none; }
:root[data-lb="on"] .doc .lb { display: inline; }
:root[data-lb="on"] .doc .lb::after { content: "\A"; white-space: pre; }

/* 頁碼：預設行內小標；桌機改為右緣版心頁碼（見下方 media） */
.doc .pb { display: inline; }
.doc .pb::before {
  content: "頁" attr(data-page);
  font-family: var(--font-ui); font-size: .68em; line-height: 1;
  color: var(--muted);
  border: 1px solid var(--rule); border-radius: 3px;
  padding: .1em .35em; margin: 0 .3em;
  vertical-align: .18em; white-space: nowrap;
  letter-spacing: 0; text-indent: 0;
}
:root[data-pages="off"] .doc .pb { display: none; }

@media (min-width: 1024px) {
  /* 版心頁碼：零寬浮動元素靠右、clear 讓相鄰頁碼自動往下堆疊不重疊。
     實測（金剛經講義 12,136 節點、501 個頁碼）：改字級重排約 1.0 秒；
     改用 position:absolute 反而 2.4 秒，故保留 float 寫法。 */
  /* 呈現（業主 2026-09-17 定案）：橫排阿拉伯數字「頁 12」，前面一小段短線指向換頁那一行；
     CBETA 式頁碼（0239a）只顯示原值。高度 1.5em 讓相鄰換頁的標記往下堆疊不重疊。 */
  /* 浮動盒高度 = 一行（--lh），標籤以 top:50% 對齊該行文字中心。
     樣式與手機版行內小標相同（細框），不畫指示線——業主指出短線像中文「一」會誤讀。 */
  .doc .pb { float: right; clear: right; width: 0; height: calc(var(--lh) * 1em); position: relative; }
  .doc .pb::before {
    content: "頁 " attr(data-page);
    position: absolute; left: .7em; top: 50%; transform: translateY(-50%);
    font-family: var(--font-ui); font-size: .66em; line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    border: 1px solid var(--rule); border-radius: 3px;
    margin: 0; padding: .18em .4em;
    letter-spacing: 0; white-space: nowrap;
    vertical-align: baseline;
  }
  .doc .pb.is-latin::before { content: attr(data-page); }
}

/* 全文檢索 highlight（任務 4 使用） */
/* 檢索上色（lib/highlight.js）：同時含所有詞的段落塗底色、只含部分詞的段落畫底線、目前筆用深一階。
   優先用 CSS Custom Highlight API（不改 DOM、不重排）；不支援時退回 mark.hl */
::highlight(jwn-hit) { background-color: var(--hl); }
::highlight(jwn-hit-partial) { text-decoration: underline var(--hl-cur) 2px; text-underline-offset: .14em; }
::highlight(jwn-hit-current) { background-color: var(--hl-cur); }
.doc mark.hl { background: var(--hl); color: inherit; padding: 0 .04em; border-radius: 2px; }
.doc mark.hl.is-partial { background: transparent; box-shadow: inset 0 -2px 0 var(--hl-cur); }
.doc mark.hl.is-current { background: var(--hl-cur); box-shadow: none; }

/* 目前章節標題的朱筆記號（由 scrollspy 給 .head 加上） */
.doc .head.is-current { position: relative; }
