/* 大藏經閱讀器（正式版）— 三色系與主站一致：光明／溫暖／夜間
   色值對齊 prototype-astro BaseLayout（--paper/--wash/--gold 系統） */
:root {
  --bg: #f4f1e8;          /* 主站 wash 光明 */
  --paper: #ffffff;
  --ink: #24211d;
  --accent: #9a7433;      /* 主站連結金褐 */
  --accent-deep: #7c5c16;
  --gold: #b99b50;
  --muted: #6d675f;
  --border: #e5dfd2;
  --verse: #993300;       /* 主站 --cc-verse */
  --dharani: #75561f;
  --note: #a0522d;
  --head2: #A33B2A;       /* 主站 --cc-h2 */
  --fs: 20px;   /* 底線＝主站「內容文字大小」設定值 20px，A− 不低於此 */
}
html.zs-warm {
  --bg: #e7d5af; --paper: #f9f1de; --ink: #3a2c1b;
  --accent: #8a5f28; --accent-deep: #6d4a1c; --muted: #77644a; --border: #cdb488;
}
html.zs-dark {
  --bg: #0e1524; --paper: #16203a; --ink: #d3cbba;
  --accent: #cfa564; --accent-deep: #e3c584; --gold: #c9a45a;
  --muted: #a8a495; --border: #2b3a5e;
  --verse: #d08a5a; --dharani: #c9a95e; --note: #c98a63; --head2: #d98873;
}
/* 罕字字型子集（Jigmo 字雲，SIL OFL 類自由授權；只含全藏實際用到的 6,670 個 Ext-B+ 字）。
   unicode-range 讓瀏覽器只在頁面真的渲染到罕字時才下載（一般卷頁零成本）。 */
@font-face {
  font-family: 'TripitakaExt';
  src: url('fonts/Jigmo2-sub.woff2') format('woff2');
  unicode-range: U+20000-2EBEF;
  font-display: swap;
}
@font-face {
  font-family: 'TripitakaExt';
  src: url('fonts/Jigmo3-sub.woff2') format('woff2');
  unicode-range: U+2EBF0-3134A;
  font-display: swap;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--site-font, "LXGW WenKai TC", "KaiTi", "DFKai-SB", serif), 'TripitakaExt';
  line-height: 1.9; font-size: var(--fs);
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-deep); text-decoration: underline; }
header.site, footer.site {
  display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center;
  padding: 10px 18px; background: var(--paper); border-bottom: 1px solid var(--border);
}
/* 回主站文字連結（最左） */
.home-link {
  padding: 5px 12px; border: 1px solid var(--border); border-radius: 8px;
  color: var(--accent-deep); font-size: 17px; white-space: nowrap;
}
.home-link:hover { background: color-mix(in srgb, var(--gold) 15%, var(--paper)); text-decoration: none; }
/* 工具列常駐：捲動時固定在頂端不收合（2026-08-07 使用者指定） */
header.site { position: sticky; top: 0; z-index: 60; box-shadow: 0 2px 10px rgba(60,44,20,.06); }
html.zs-dark header.site { box-shadow: 0 2px 10px rgba(0,0,0,.4); }
footer.site { border-top: 1px solid var(--border); border-bottom: 0; font-size: .85rem; color: var(--muted); justify-content: center; }
.brand a { font-weight: 800; color: var(--accent-deep); font-size: 1.05rem; }
.crumb { flex: 1; min-width: 200px; font-size: 18px; color: var(--muted); }
.crumb a { color: var(--accent); }
.tools { display: flex; gap: 6px; align-items: center; }
.tool-label { color: var(--muted); font-size: 16px; margin-left: 6px; }
.tools button {
  min-width: 40px; height: 34px; padding: 0 10px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; background: var(--paper); color: var(--accent-deep);
  font-size: .95rem;
}
.tools button.active { background: var(--gold); color: #fff; border-color: var(--gold); }
/* ===== 版面：左側選單＋內容——比照主站 content-cols（置中容器＋選單卡片＋寬閱讀欄） ===== */
.layout {
  width: min(1600px, 97%); margin: 0 auto;
  padding: 22px clamp(14px, 3vw, 24px) 60px;
  display: grid; grid-template-columns: 480px minmax(0, 1fr); gap: 28px; align-items: start;
}
main { max-width: none; margin: 0; padding: 0; width: 100%; min-width: 0; }
#zs-side {
  position: sticky; top: 70px; max-height: calc(100vh - 82px); overflow-y: auto;  /* 讓出常駐工具列高度 */
  background: var(--paper); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 10px 18px; scrollbar-width: thin;
  box-shadow: 0 1px 2px rgba(84,62,28,.06), 0 12px 28px -18px rgba(84,62,28,.5);
}
html.zs-dark #zs-side { box-shadow: 0 1px 2px rgba(0,0,0,.5), 0 14px 30px -18px rgba(0,0,0,.9); }
#sideToggle { display: none; }
#sideFilter {
  width: 100%; padding: 8px 12px; margin-bottom: 8px; font-size: 20px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--ink);
  font-family: inherit;
}
#sideFilter:focus { outline: none; border-color: var(--gold); }
/* 部類收合狀態＝雙欄格（26 部變 13 行，填滿寬度）；展開的部橫跨兩欄 */
#side-tree { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#side-tree > .side-bulei { border: 1px solid color-mix(in srgb, var(--gold) 25%, var(--border)); border-radius: 8px; overflow: hidden; }
#side-tree > .side-bulei[open] { grid-column: 1 / -1; }
#side-tree > .side-hits, #side-tree > .side-loading { grid-column: 1 / -1; }
.side-loading { color: var(--muted); font-size: 20px; padding: 4px; }
.side-links { font-size: 18px; color: var(--muted); padding: 10px 4px 0; border-top: 1px dashed var(--border); margin-top: 12px; }
.side-bulei summary {
  cursor: pointer; padding: 9px 12px; font-weight: 700; color: var(--accent-deep); font-size: 20px;
  border-bottom: 0; list-style: none;
  display: flex; justify-content: flex-start; gap: 6px; align-items: baseline;
  background: color-mix(in srgb, var(--gold) 18%, var(--paper));  /* 部名層：淡金底（層次一） */
}
.side-bulei summary:hover { background: color-mix(in srgb, var(--gold) 26%, var(--paper)); }
.side-bulei summary .cnt { margin-left: auto; }
.side-bulei summary::before { content: '›'; color: var(--gold); margin-right: 6px; transition: transform .15s; display: inline-block; }
.side-bulei[open] summary::before { transform: rotate(90deg); }
.side-bulei summary .cnt, .side-hits .cnt { color: var(--muted); font-weight: 400; font-size: .78rem; margin-left: 6px; }
.side-bulei ul, .side-hits { list-style: none; margin: 0; padding: 2px 0 6px 12px; }
.side-text .t-link {
  display: flex; gap: 8px; align-items: baseline;
  padding: 6px 8px 6px 26px; font-size: 20px; line-height: 1.55;
  border-left: 3px solid color-mix(in srgb, var(--gold) 45%, transparent);
  border-bottom: 1px dashed color-mix(in srgb, var(--border) 60%, transparent);
  background: color-mix(in srgb, var(--gold) 6%, var(--paper));   /* 經名層：更淡金底（層次二） */
}
.side-text .tid { flex: 0 0 auto; color: var(--muted); }
.side-text .cur-t .tid { color: #fff; }
.side-text .tnm { flex: 1; min-width: 0; }  /* 經名過長折行時對齊經名起點，不侵入編號欄 */
.side-text .t-link:hover { background: color-mix(in srgb, var(--gold) 12%, transparent); text-decoration: none; }
.side-text .t-link.cur-t { background: var(--gold); color: #fff; border-radius: 6px; }
/* 卷清單：主站子選單式淡黃層次色塊；點當前經名即可收合/展開 */
ul.side-juans {   /* ul 前綴：權重須壓過 .side-bulei ul 的 padding */
  list-style: none; margin: 0 0 8px 12px; padding: 8px 10px 8px 81px;
  border-left: 3px solid color-mix(in srgb, var(--gold) 30%, transparent);
  display: flex; flex-wrap: wrap; gap: 5px 6px; justify-content: flex-start;  /* 卷格靠左、左緣對齊經名起點（不超過編號欄） */
  background: color-mix(in srgb, var(--gold) 7%, var(--paper));
}
.side-juans a {
  font-size: 20px; padding: 2px 10px; border-radius: 6px;
  background: color-mix(in srgb, var(--gold) 15%, var(--paper));
  border: 1px solid color-mix(in srgb, var(--gold) 30%, transparent);
  color: var(--accent-deep);
}
.side-juans a:hover { background: color-mix(in srgb, var(--gold) 28%, var(--paper)); text-decoration: none; }
.side-juans a.cur { background: var(--gold); color: #fff; border-color: var(--gold); }
@media (max-width: 900px) {
  .layout { display: block; }
  #sideToggle {
    display: inline-block; min-width: 40px; height: 34px; cursor: pointer;
    border: 1px solid var(--border); border-radius: 8px; background: var(--paper); color: var(--accent-deep); font-size: 1rem;
  }
  #zs-side {
    position: fixed; left: 0; top: 0; bottom: 0; width: min(88vw, 490px); z-index: 70;  /* 蓋過常駐工具列；點選單外即關閉 */
    max-height: none; border-radius: 0; border-width: 0 1px 0 0;
    transform: translateX(-105%); transition: transform .25s ease; box-shadow: 6px 0 24px rgba(0,0,0,.25);
  }
  body.side-open #zs-side { transform: none; }
}
h1 { color: var(--head2); font-size: 1.5em; }
.meta { color: var(--muted); font-size: 20px; }
/* 面板層次比照主站：面板亮於底、雙層陰影 */
article.sutra, .toc, .footnotes {
  background: var(--paper); border: 1px solid var(--border); border-radius: 10px;
  padding: clamp(16px, 3vw, 34px); margin: 14px 0;
  box-shadow: 0 1px 2px rgba(84,62,28,.06), 0 12px 28px -18px rgba(84,62,28,.5);
}
html.zs-dark article.sutra, html.zs-dark .toc, html.zs-dark .footnotes {
  box-shadow: 0 1px 2px rgba(0,0,0,.5), 0 14px 30px -18px rgba(0,0,0,.9);
}
.juan-open { text-align: center; margin-bottom: 1.2em; }
.juan-head { color: var(--head2); font-size: 1.35em; margin: .2em 0; }
h3.head { color: var(--accent-deep); font-size: 1.12em; }
.byline, .docnum { text-align: center; color: var(--muted); font-size: .95em; margin: .3em 0; }
.juan-close { text-align: center; color: var(--muted); margin-top: 1.6em; }
.trailer { color: var(--muted); }
/* 偈頌：置中塊、詩行 */
.lg { margin: 1em auto; text-align: center; color: var(--verse); }
.lg .l { display: inline-block; padding: 0 .4em; }
.dharani { color: var(--dharani); }
.inote { color: var(--note); font-size: 1em; }  /* 標註同字級（主站內容樣式偏好） */
body.hide-notes .inote, body.hide-notes sup.fn { display: none; }
sup.fn a { color: var(--note); font-size: .72em; }
.footnotes h4 { margin-top: 0; color: var(--accent-deep); }
.footnotes li { font-size: 20px; color: var(--muted); margin-bottom: .4em; }
.fn-cb, .fn-orig { display: inline-block; margin-right: .8em; }
/* 行號：預設隱藏，開啟時顯示大正頁欄行 */
a.lb, a.pb { display: inline; }
body.show-lines a.lb::after {
  content: attr(data-n); font-size: .6em; color: var(--gold); vertical-align: super; margin: 0 2px;
}
/* 缺字 */
.gaiji, .gaiji-miss { color: var(--note); }
.gaiji-norm { border-bottom: 1px dotted var(--gold); }
.gaiji-rom { color: var(--accent); font-style: italic; }
.ext { }
.tt-x { color: var(--accent); }
.sg { color: var(--accent); }
.fig-ph { color: var(--muted); border: 1px dashed var(--border); padding: 0 6px; border-radius: 4px; }
/* 目次側欄／清單 */
/* 本卷目次：水平排列不佔高度（2026-08-07 使用者指定）；層級以縮排符號區隔 */
.toc { display: flex; flex-wrap: wrap; gap: 4px 18px; align-items: baseline; padding-top: 14px; padding-bottom: 14px; }
.toc strong { flex: 0 0 auto; color: var(--accent-deep); }
.toc a { display: inline-block; padding: 0; }
.toc .lv2::before { content: '· '; color: var(--muted); }
.toc .lv3::before { content: '· · '; color: var(--muted); }
ul.juan-list { list-style: none; padding: 0; }
ul.juan-list li { border-bottom: 1px dashed var(--border); padding: 8px 2px; display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
ul.juan-list .pin { color: var(--muted); font-size: 20px; }
ul.list.nomark { list-style: none; padding-left: 1em; }
/* 表格 */
table.tbl { border-collapse: collapse; margin: 1em auto; }
table.tbl td { border: 1px solid var(--border); padding: 4px 10px; }
/* 目錄卡 */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.card {
  display: flex; flex-direction: column; gap: 6px; padding: 14px 16px;
  background: var(--paper); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 1px 2px rgba(84,62,28,.06), 0 10px 24px -14px rgba(84,62,28,.5);
}
.card:hover { border-color: var(--gold); text-decoration: none; transform: translateY(-2px); transition: .2s; }
.card strong { color: var(--accent-deep); }
.card-meta { color: var(--muted); font-size: 20px; }
.nb { white-space: nowrap; }  /* 「155 部、390 卷」整組不折行 */
/* 卷導覽 */
.juan-nav { display: flex; justify-content: space-between; gap: 10px; margin: 14px 0; }
.navbtn {
  padding: 7px 16px; border: 1px solid var(--border); border-radius: 999px; background: var(--paper);
}
.navbtn.dim { color: var(--muted); opacity: .5; }
.attribution { color: var(--muted); font-size: 20px; text-align: center; margin-top: 26px; }
@media (max-width: 640px) { main { padding: 14px 10px 50px; } header.site { padding: 8px 10px; } }
