/* 閱讀原文（read.html）：紙色 / 夜間兩種底，正文用宋體，一欄居中；頂欄往下讀時收起 */
:root {
  --rd-bg: #f2f1ec; --rd-page: #fbfaf6; --rd-ink: #1e2425; --rd-ink-2: #4f5a5c; --rd-ink-3: #7a8385; --rd-line: #dcdcd5; --rd-hl: rgb(93 133 149 / .26);
  --rd-fs: 18px;
  /* 正文不用網站的標題字體：那套只裁了常用字，古籍裡的生僻字會混進別的字體 */
  --rd-font: 'Songti SC', 'Noto Serif SC', 'Source Han Serif SC', 'Noto Serif CJK SC', 'STSong', 'SimSun', serif;
  color-scheme: light;
}
:root[data-theme="night"] { --rd-bg: #15191a; --rd-page: #1b2021; --rd-ink: #cfd3cd; --rd-ink-2: #a3aaa6; --rd-ink-3: #7c8481; --rd-line: #2d3436; --rd-hl: rgb(130 170 185 / .3); color-scheme: dark; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.rd { margin: 0; min-height: 100dvh; background: var(--rd-bg); color: var(--rd-ink); font-family: var(--f-sans); transition: background-color .3s, color .3s; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 30; padding: 8px 12px; background: var(--rd-page); }
.skip:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--c-shiqing); outline-offset: 2px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* —— 頂欄 —— */
.rd-bar { position: fixed; inset: 0 0 auto; z-index: 10; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 12px;
  height: 56px; padding: 0 max(16px, env(safe-area-inset-left)) 0 max(12px, env(safe-area-inset-left));
  background: color-mix(in oklab, var(--rd-bg) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--rd-line);
  transition: transform .35s var(--ease-out), background-color .3s; }
.bar-off .rd-bar { transform: translateY(-100%); }
.rd-back { display: inline-flex; align-items: center; gap: 6px; min-width: 0; padding: 8px 6px; font: 500 16px/1.3 var(--f-serif); }
.rd-back svg { flex-shrink: 0; width: 16px; height: 16px; }
.rd-back span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rd-where { margin: 0; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--rd-ink-3); }
.rd-tools { display: flex; justify-content: flex-end; gap: 2px; }
.rd-btn { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 10px; border: 0; border-radius: 2px; background: none; font-size: 13px; color: var(--rd-ink-2); transition: background-color .2s, color .2s; }
.rd-btn svg { width: 18px; height: 18px; }
.rd-btn:hover, .rd-btn[aria-expanded="true"] { background: color-mix(in oklab, var(--rd-ink) 7%, transparent); color: var(--rd-ink); }

/* —— 設置 —— */
.rd-set { position: fixed; z-index: 12; top: 62px; right: 12px; width: 300px; padding: 8px 16px; border: 1px solid var(--rd-line); border-radius: 4px; background: var(--rd-page);
  box-shadow: 0 12px 32px rgb(20 26 28 / .16); }
.rd-set[hidden] { display: none; }
.rd-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; font-size: 13px; color: var(--rd-ink-2); }
.rd-row + .rd-row { border-top: 1px solid var(--rd-line); }
.rd-row[hidden] { display: none; }
.rd-seg { display: flex; align-items: center; }
.rd-seg button { min-width: 52px; padding: 6px 10px; border: 1px solid var(--rd-line); margin-left: -1px; background: none; font-size: 13px; color: var(--rd-ink-2); }
.rd-seg button:first-child { border-radius: 2px 0 0 2px; }
.rd-seg button:last-child { border-radius: 0 2px 2px 0; }
.rd-seg button[aria-pressed="true"] { position: relative; border-color: var(--rd-ink-2); color: var(--rd-ink); background: color-mix(in oklab, var(--rd-ink) 6%, transparent); }
.rd-seg output { min-width: 44px; text-align: center; font: 15px var(--f-num); color: var(--rd-ink); }

/* —— 正文 —— */
.rd-main { padding: 96px 20px 120px; }
.rd-loading { padding: 20vh 0; text-align: center; color: var(--rd-ink-3); font-size: 14px; }
.rd-loading small { display: block; margin-top: 8px; font-size: 12px; }
.rd-text { max-width: calc(var(--rd-fs) * 33); margin: 0 auto; font: 400 var(--rd-fs)/2 var(--rd-font); letter-spacing: .02em; }
.rd-ch { margin: 0 0 2em; text-align: center; font: 500 1.45em/1.5 var(--f-serif), var(--rd-font); letter-spacing: .12em; }
.rd-text p { margin: 0 0 .85em; text-indent: 2em; text-align: justify; overflow-wrap: anywhere; scroll-margin-top: 80px; transition: background-color .6s; }
.rd-text p.is-hit { background: var(--rd-hl); }
.rd-text mark { background: var(--rd-hl); color: inherit; border-radius: 1px; }
/* 原書的小字注：縮小、淡一號 */
.zhu { font-size: .78em; line-height: 1.6; color: var(--rd-ink-2); letter-spacing: 0; }
.zhu::before { content: '〔'; color: var(--rd-ink-3); }
.zhu::after { content: '〕'; color: var(--rd-ink-3); }
.hide-zhu .zhu { display: none; }
/* 白話譯文：默認收起；打開後排成正文下面的淺色段 */
.rd-text p.yi { display: none; margin: -.85em 0 0; padding: .3em 0 .3em 1em; border-left: 2px solid var(--rd-line); text-indent: 0; font: .88em/1.9 var(--f-sans); color: var(--rd-ink-2); }
.show-yi .rd-text p.yi { display: block; }
.rd-text p.yi.is-first { margin-top: -.2em; padding-top: .5em; }
.rd-text p.yi:has(+ p:not(.yi)), .rd-text p.yi:last-of-type { margin-bottom: 1.3em; padding-bottom: .5em; }
.yi-k { display: inline-block; margin-right: .6em; letter-spacing: .1em; padding: 0 .35em; border: 1px solid var(--rd-line); border-radius: 2px; font-size: .78em; line-height: 1.5; color: var(--rd-ink-3); vertical-align: .08em; }
.yi .zhu::before, .yi .zhu::after { content: none; }
.yi .zhu { font-size: 1em; color: inherit; }
/* 章末：上一章 / 下一章 */
.rd-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 4em; padding-top: 2em; border-top: 1px solid var(--rd-line); }
.rd-pager > * { display: block; padding: 14px 16px; border: 1px solid var(--rd-line); border-radius: 4px; background: none; text-align: left; font: 500 16px/1.5 var(--f-serif), var(--rd-font); color: var(--rd-ink); transition: border-color .2s; }
.rd-pager > :last-child { text-align: right; }
.rd-pager > span { border: 0; }
.rd-pager small { display: block; margin-bottom: 2px; font: 12px var(--f-sans); color: var(--rd-ink-3); }
.rd-pager > :hover:not(span) { border-color: var(--rd-ink-2); }
.rd-fail { padding: 20vh 0; text-align: center; color: var(--rd-ink-2); }
.rd-go { display: inline-block; margin-top: 16px; padding: 8px 18px; border: 1px solid var(--rd-ink-2); border-radius: 2px; background: none; font-size: 14px; color: var(--rd-ink); }

/* —— 底欄 —— */
.rd-foot { position: fixed; inset: auto 0 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: calc(52px + env(safe-area-inset-bottom)); padding: 0 12px env(safe-area-inset-bottom);
  background: color-mix(in oklab, var(--rd-bg) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--rd-line);
  transition: transform .35s var(--ease-out); }
.bar-off .rd-foot { transform: translateY(100%); }
.rd-foot[hidden] { display: none; }
.rd-step { display: inline-flex; align-items: center; gap: 4px; height: 38px; padding: 0 10px; border: 0; border-radius: 2px; background: none; font-size: 13px; color: var(--rd-ink-2); }
.rd-step svg { width: 14px; height: 14px; }
.rd-step:hover:not(:disabled) { background: color-mix(in oklab, var(--rd-ink) 7%, transparent); color: var(--rd-ink); }
.rd-step:disabled { opacity: .35; cursor: default; }
.rd-pos { display: flex; align-items: center; gap: 12px; font: 13px var(--f-num); color: var(--rd-ink-3); }
.rd-pos input { width: 4.2em; height: 28px; padding: 0 6px; border: 1px solid var(--rd-line); border-radius: 2px; background: var(--rd-page); font: 13px var(--f-num); color: var(--rd-ink); text-align: center; }
.rd-zoom { display: flex; }
.rd-zoom button { width: 30px; height: 28px; border: 1px solid var(--rd-line); margin-left: -1px; background: none; font-size: 14px; color: var(--rd-ink-2); }

/* —— 目錄、搜索：左側滑出的面板 —— */
.rd-panel { position: fixed; inset: 0 auto 0 0; width: min(400px, 92vw); height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; border-right: 1px solid var(--rd-line);
  background: var(--rd-page); color: var(--rd-ink); overflow-y: auto; overscroll-behavior: contain; }
.rd-panel[open] { animation: rd-in .35s var(--ease-out); }
.rd-panel::backdrop { background: rgb(20 26 28 / .36); }
@keyframes rd-in { from { transform: translateX(-24px); opacity: 0; } }
html:has(.rd-panel[open]) { overflow: hidden; }
.rd-panel-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 14px 24px; background: var(--rd-page); border-bottom: 1px solid var(--rd-line); }
.rd-panel-head h2 { margin: 0; font: 500 18px/1.4 var(--f-serif); }
.rd-x { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 2px; background: none; color: var(--rd-ink-2); }
.rd-x svg { width: 18px; height: 18px; }
.rd-x:hover { background: color-mix(in oklab, var(--rd-ink) 7%, transparent); }
.rd-eds { display: flex; flex-wrap: wrap; gap: 6px; padding: 16px 24px 4px; }
.rd-eds[hidden] { display: none; }
.rd-eds button { padding: 5px 10px; border: 1px solid var(--rd-line); border-radius: 2px; background: none; font-size: 13px; color: var(--rd-ink-2); }
.rd-eds button[aria-pressed="true"] { border-color: var(--rd-ink); background: var(--rd-ink); color: var(--rd-page); }
.rd-toc-list { list-style: none; margin: 0; padding: 8px 0 32px; }
.rd-toc-list a { display: flex; justify-content: space-between; gap: 12px; padding: 10px 24px; font: 15px/1.5 var(--f-serif), var(--rd-font); color: var(--rd-ink); }
.rd-toc-list a small { flex-shrink: 0; font: 12px/1.9 var(--f-num); color: var(--rd-ink-3); }
.rd-toc-list a:hover { background: color-mix(in oklab, var(--rd-ink) 5%, transparent); }
.rd-toc-list a[aria-current] { position: relative; background: color-mix(in oklab, var(--rd-ink) 7%, transparent); font-weight: 600; }
.rd-toc-list a[aria-current]::before { content: ''; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; background: var(--rd-ink); }
.rd-find-form { display: flex; gap: 8px; padding: 16px 24px 4px; }
.rd-find-form[hidden] { display: none; }
.rd-find-form input { flex: 1; min-width: 0; height: 40px; padding: 0 12px; border: 1px solid var(--rd-line); border-radius: 2px; background: var(--rd-bg); font: 15px var(--f-sans); color: var(--rd-ink); }
.rd-find-form .rd-go { margin: 0; }
.rd-find-note { margin: 0; padding: 10px 24px; font-size: 13px; line-height: 1.7; color: var(--rd-ink-3); }
.rd-hits { list-style: none; margin: 0; padding: 0 0 32px; }
.rd-hits a { display: block; padding: 10px 24px; font: 14px/1.8 var(--rd-font); color: var(--rd-ink-2); border-bottom: 1px solid color-mix(in oklab, var(--rd-line) 60%, transparent); }
.rd-hits a:hover { background: color-mix(in oklab, var(--rd-ink) 5%, transparent); }
.rd-hits mark { background: var(--rd-hl); color: var(--rd-ink); }
.rd-hit-ch { padding: 16px 24px 4px; font: 500 12px/1.4 var(--f-sans); letter-spacing: .1em; color: var(--rd-ink-3); }

/* —— 影印：一頁一頁豎著排，寬度隨放大倍數 —— */
.rd-pdf { --zoom: 1; --ratio: 1.414; width: min(100%, calc(860px * var(--zoom))); margin: 0 auto; }
body[data-kind="pdf"] .rd-main { padding-inline: 8px; overflow-x: auto; }
.pg { position: relative; aspect-ratio: 1 / var(--ratio); margin: 0 auto 12px; background: #fff; box-shadow: 0 1px 3px rgb(20 26 28 / .12); }
.pg canvas { position: relative; display: block; width: 100%; height: 100%; }
.pg-n { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font: 13px var(--f-num); color: #9aa1a2; }
:root[data-theme="night"] .pg { background: #2a2f30; }
:root[data-theme="night"] .pg canvas { filter: brightness(.82) contrast(1.05); }
.rd-nextvol { display: block; margin: 32px auto 0; padding: 12px 24px; border: 1px solid var(--rd-ink-2); border-radius: 2px; background: none; font: 500 16px var(--f-serif); color: var(--rd-ink); }

@media (max-width: 720px) {
  .rd-bar { grid-template-columns: minmax(0, 1fr) auto; }
  .rd-where { display: none; }
  .rd-btn span { display: none; }
  .rd-btn { width: 40px; padding: 0; justify-content: center; }
  .rd-main { padding: 80px 18px 100px; }
  .rd-set { left: 8px; right: 8px; width: auto; }
  .rd-pager { grid-template-columns: 1fr; }
  .rd-pager > span { display: none; }
  .rd-pager > :last-child { text-align: left; }
  .rd-step span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .rd-bar, .rd-foot, .rd-panel[open] { transition: none; animation: none; }
}
