:root { --cell: 30px; --colw: 34px; --note-font: calc(var(--cell) * 0.45); --main-font: calc(var(--cell) * 0.73); --ink: #222; --frame: #a33; --grid: #e6d7c8; }
* { box-sizing: border-box; }
/* 造字（私用區字）：軟體附的 eudc.tte，建置時原樣放到 fonts/ */
@font-face { font-family: "GJTS EUDC"; src: url(fonts/eudc.ttf) format("truetype"); unicode-range: U+E000-F8FF; font-display: swap; }
body { margin: 0; font-family: "GJTS EUDC", "Noto Serif CJK TC", "Source Han Serif TC", "TW-Kai", "PMingLiU", serif; color: var(--ink); background: #faf6f0; }
header { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 8px 16px; background: #fff; border-bottom: 1px solid #ddd; }
header h1 { font-size: 16px; margin: 0; white-space: nowrap; flex: none; }
#tocBtn { display: flex; align-items: center; gap: 4px; padding: 2px 6px 2px 2px; border: 1px solid transparent; border-radius: 6px; background: none; cursor: pointer; font: inherit; color: #666; }
#tocBtn:hover { border-color: #ccc; background: #f3ede4; }
#tocBtn .logo { width: 28px; height: 28px; display: block; }
#tocBtn .caret { width: 0; height: 0; border: 5px solid transparent; border-right: 6px solid #999; border-left: 0; transition: transform .15s; }
body:not(.toc-open) #tocBtn .caret { transform: rotate(180deg); }
#tocBtn .lbl { display: none; font-size: 13px; }
@media (max-width: 800px) { #tocBtn .lbl { display: inline; } }
#searchForm { position: relative; display: flex; align-items: center; gap: 4px; flex: 1 1 140px; min-width: 0; max-width: 360px; }
#searchForm input { flex: 1 1 auto; width: 0; min-width: 80px; padding: 4px 6px; }
#searchStat { font-size: 12px; color: #777; white-space: nowrap; }
/* 部名自動完成：浮在檢索框下方；一行部名，右邊淡字標所在的典與卷 */
#sugg { position: absolute; left: 0; top: 100%; margin: 2px 0 0; padding: 4px 0; width: 360px; max-width: calc(100vw - 32px); max-height: 60vh; overflow: auto; list-style: none; background: #fff; border: 1px solid #ccc; border-radius: 6px; box-shadow: 0 4px 12px rgba(0, 0, 0, .15); z-index: 30; font-size: 14px; }
#sugg li { padding: 5px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
#sugg li .n { color: #999; font-size: 12px; white-space: nowrap; }
#sugg li:hover, #sugg li.active { background: #fff3d6; }
#sugg li mark { background: none; color: #a33; font-weight: bold; }
#pager { display: flex; align-items: center; gap: 4px; flex: none; white-space: nowrap; font-size: 14px; }
#pager button, #searchForm button { padding: 4px 8px; white-space: nowrap; }
#pager #jump { width: 110px; padding: 4px 6px; }
#pager .modes { margin-left: 10px; }
#pager label { display: inline-flex; align-items: center; gap: 2px; }
.modes label { margin-right: 4px; }
@media (max-width: 1080px) { header h1 { display: none; } #pager .modes { margin-left: 4px; } }
@media (max-width: 800px) { #pager { flex-wrap: wrap; flex: 1 1 100%; white-space: normal; row-gap: 6px; } #searchForm { max-width: none; } #pager button { padding: 4px 6px; } #pager #jump { width: 84px; } #pager .modes { margin-left: 0; } }
#main { display: flex; min-height: calc(100vh - 50px); }
/* 目錄抽屜：桌面是左側一欄，可收起；手機上滿版蓋在上面，選了葉就自動收起 */
#side { width: 260px; flex: none; display: flex; flex-direction: column; max-height: calc(100vh - 50px); border-right: 1px solid #ddd; background: #fff; }
body:not(.toc-open) #side { display: none; }
#side .side-bar { display: none; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid #ddd; font-weight: bold; }
#side .side-bar button { padding: 4px 10px; }
#toc { flex: 1; overflow: auto; padding: 8px; font-size: 14px; }
@media (max-width: 800px) {
  #side { position: fixed; inset: 0; width: 100%; max-height: none; z-index: 20; border-right: 0; }
  #side .side-bar { display: flex; }
}
#toc .hd { cursor: pointer; padding: 4px 6px; border-radius: 4px; user-select: none; }
#toc .hd:hover { background: #f3ede4; }
#toc .tri { display: inline-block; width: 0; height: 0; margin-right: 6px; border: 5px solid transparent; border-left: 6px solid #999; border-right: 0; vertical-align: 1px; transition: transform .15s; }
#toc .open > .hd .tri { transform: rotate(90deg); }
#toc .toc-cat > .hd { font-weight: bold; color: #444; }
#toc .toc-cat.open > .hd { color: #a33; }
#toc .hd .n { float: right; color: #999; font-size: 12px; font-weight: normal; }
#toc .toc-roll.open > .hd { background: #fff3d6; }
#toc .toc-sect { margin: 4px 0 2px; color: #666; font-size: 13px; }
#toc .toc-leaves { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; margin: 2px 0 6px; }
#toc .leaf { display: block; text-align: center; padding: 2px 0; border: 1px solid #e3dccf; border-radius: 3px; color: #246; text-decoration: none; font-size: 12px; }
#toc .leaf.cur { background: #ffe9b0; border-color: #e0b84a; font-weight: bold; }
#toc .loading { color: #999; font-size: 12px; padding: 4px 16px; }
body.busy { cursor: progress; }
#view { flex: 1; padding: 12px 16px; overflow: auto; min-width: 0; }
#meta { font-size: 14px; color: #555; margin-bottom: 8px; }
#meta .dim { color: #999; font-size: 12px; }
#leafWrap { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
#scan { max-width: 720px; flex: 1 1 420px; }
#scan .crop { overflow: hidden; border: 1px solid #ccc; position: relative; min-height: 120px; background: #fff; }
#scan .crop.loading::before { content: ''; position: absolute; inset: 0; background: rgba(250, 246, 240, .7); z-index: 1; }
#scan .crop.loading::after { content: ''; position: absolute; left: 50%; top: 50%; width: 36px; height: 36px; margin: -18px 0 0 -18px; border: 4px solid #ddd; border-top-color: #a33; border-radius: 50%; animation: spin .9s linear infinite; z-index: 2; }
@keyframes spin { to { transform: rotate(360deg); } }
#scan img { display: block; width: 100%; }
#scan .crop[hidden] { display: none; }
#scan .cap { font-size: 13px; color: #777; margin-top: 4px; }
#results { width: 340px; flex: none; overflow: auto; max-height: calc(100vh - 50px); padding: 8px; border-left: 1px solid #ddd; background: #fff; font-size: 13px; }
#results .res-bar { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 8px; margin-bottom: 4px; border-bottom: 1px solid #ddd; font-weight: bold; }
#results .res-bar button { padding: 2px 8px; }
#results .none { padding: 16px 4px; color: #777; text-align: center; }
#results .hit { padding: 6px 4px; border-bottom: 1px solid #eee; cursor: pointer; }
#results .hit:hover { background: #fff6dd; }
#results .hit .where { color: #777; font-size: 12px; }
#results mark, .c.hl { background-color: #ffd54a; }
.empty { color: #aaa; font-size: 14px; padding: 20px; }

/* 缺字字圖（24×24 的黑白點陣）與造字 */
/* 字圖取自大圖 glyphs/HH.png（16×16 格），位置由 app.js 算 */
.glyph { display: inline-block; height: 1em; width: 1em; vertical-align: -0.12em; background-repeat: no-repeat; background-size: 1600% 1600%; cursor: help; }
.pua { cursor: help; }

/* ---------- 橫排：重排的閱讀文本，一行是原文的一行（一段），夾注小字 ---------- */
#plain { flex: 1 1 420px; min-width: 0; max-width: 46em; font-size: 19px; line-height: 1.9; background: #fffdf8; border: 1px solid var(--grid); padding: 14px 20px; }
#plain .pl { min-height: 1.9em; white-space: pre-wrap; word-break: break-all; }
#plain .pl.p1 { font-weight: bold; color: #a33; }
/* p2 是一則的起頭（書名或篇名，常連著正文同一行），p3 是其下的篇章：只在行首標一道，不整行加粗 */
#plain .pl.p2 { margin-top: .4em; border-left: 3px solid #e0b84a; padding-left: 8px; margin-left: -11px; }
#plain .pl.p3 { border-left: 3px solid var(--grid); padding-left: 8px; margin-left: -11px; }
#plain .note { font-size: .72em; color: #555; }
#plain .cont::before { content: '…'; color: #bbb; }
.figs { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.figs figure { margin: 0; }
.figs img { display: block; max-width: min(100%, 520px); border: 1px solid var(--grid); background: #fff; }
.figs figcaption { font-size: 12px; color: #777; }
.figs .missing { color: #aaa; font-size: 13px; border: 1px dashed #ccc; padding: 20px; }

/* ---------- 豎排：一葉兩個半葉，每半葉九行、行二十字，中間版心 ---------- */
#leaf { max-width: 100%; overflow-x: auto; }
.folio { display: flex; flex-direction: row-reverse; }
.half { border: 2px solid var(--frame); background: #fffdf8; width: calc(var(--colw) * 9 + 4px); height: calc(var(--cell) * 20 + 4px); flex: none; }
.cols { display: flex; flex-direction: row-reverse; height: 100%; }
.col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; border-left: 1px solid var(--grid); }
.col:last-child { border-left: 0; }
.g { height: var(--cell); flex: none; display: flex; align-items: center; justify-content: center; font-size: var(--main-font); line-height: 1; white-space: nowrap; }
.g.n { flex-direction: row-reverse; font-size: var(--note-font); }
.g.n > span { flex: 1 1 0; display: flex; align-items: center; justify-content: center; }
.col.p1 .g { font-weight: bold; }
.col.fig .g { color: #a33; }
.banxin { width: calc(var(--colw) * 0.9); flex: none; height: calc(var(--cell) * 20 + 4px); border-top: 2px solid var(--frame); border-bottom: 2px solid var(--frame); writing-mode: vertical-rl; text-orientation: upright; font-size: 12px; color: #a33; text-align: center; padding-top: 6px; background: #fffdf8; overflow: hidden; white-space: nowrap; }
.squeezed { color: #999; font-size: 12px; margin-top: 4px; }
