/* Miller 讀書 — 設計規格書：三種風格（a 極簡／b 和紙／c 和風）× 三種明暗（自動／淺色／深色） */
:root {
  --bg: #FBFAF5; --surface: #FFFFFF; --surface2: #F3F3F2; --line: #E3E1DA;
  --text: #3B3A39; --muted: #6F7068; --primary: #165E83; --accent: #00A3AF;
  --tip-bg: #FDF3D6; --tip-line: #F8B500; --warn: #B7282E;
  --tagA-bg: #DDF2F4; --tagA-fg: #00656D; --tagB-bg: #EAF3D3; --tagB-fg: #476312;
  --on-primary: #FFFFFF; --hl-y: #FFF1A8; --hl-g: #CDEFC4; --hl-p: #FAD3E0; --hl-b: #CDE4F8;
  --navy: #143F5A; --gold: #B8923A; --redink: #B7282E;
  --hdr: 52px; --tabh: 44px; --fs: 15px;
  --sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --serif: "Noto Serif TC", "Source Han Serif TC", "Songti TC", "PMingLiU", serif;
  --font: var(--sans); --ls: 0;
  --shadow: none;
}
html[data-style="a"] { --bg: #F8F4EA; --surface: #FCFAF4; --surface2: #EFEADC; --line: #E2DBC9; --muted: #6B6A5E; --ls: .02em; }
html[data-style="b"], html[data-style="c"] { --font: var(--serif); }
html[data-fs="s"] { --fs: 14px; }
html[data-fs="l"] { --fs: 17px; }

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #1E1D1B; --surface: #292725; --surface2: #322F2C; --line: #3F3B37; --text: #EDEAE0; --muted: #A6A79B;
    --primary: #2B6F93; --tip-bg: #3A3118; --tip-line: #C99200; --warn: #E26A68;
    --tagA-bg: #12363A; --tagA-fg: #7FDCE3; --tagB-bg: #2B3A14; --tagB-fg: #C5E58A;
    --hl-y: #5E5420; --hl-g: #2F5A2C; --hl-p: #66324A; --hl-b: #274C6E;
    --navy: #1B4A68; --gold: #C9A24E; --redink: #E26A68; --accent: #43C4CE;
  }
}
html[data-theme="dark"] {
  --bg: #1E1D1B; --surface: #292725; --surface2: #322F2C; --line: #3F3B37; --text: #EDEAE0; --muted: #A6A79B;
  --primary: #2B6F93; --tip-bg: #3A3118; --tip-line: #C99200; --warn: #E26A68;
  --tagA-bg: #12363A; --tagA-fg: #7FDCE3; --tagB-bg: #2B3A14; --tagB-fg: #C5E58A;
  --hl-y: #5E5420; --hl-g: #2F5A2C; --hl-p: #66324A; --hl-b: #274C6E;
  --navy: #1B4A68; --gold: #C9A24E; --redink: #E26A68; --accent: #43C4CE;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); color-scheme: light dark; }
html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--fs); line-height: 1.8; letter-spacing: var(--ls); -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; letter-spacing: inherit; }
a { color: var(--accent); }
html[data-theme="dark"] a, html:not([data-theme="light"]) a { }
#app { max-width: 760px; margin: 0 auto; min-height: 100vh; position: relative; }
[hidden] { display: none !important; }

/* ---------- 標題列 ---------- */
#bar { position: sticky; top: 0; z-index: 30; height: var(--hdr); display: flex; align-items: center; gap: 4px; padding: 0 8px 0 4px; background: var(--bg); border-bottom: 1px solid var(--line); }
.b-title { flex: 1; min-width: 0; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
.b-title small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); line-height: 1.2; letter-spacing: .06em; }
#bar.home .b-title { padding-left: 14px; }
.b-btn { min-width: 44px; height: 44px; padding: 0 10px; border: 0; background: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 4px; font-size: 14px; color: var(--primary); border-radius: 6px; white-space: nowrap; }
.b-btn:active { background: var(--surface2); }
html[data-theme="dark"] .b-btn { color: var(--accent); }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) .b-btn { color: var(--accent); } }
.b-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 固定分頁列 ---------- */
#tabs { position: sticky; top: var(--hdr); z-index: 25; display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
#tabs button { flex: 1 1 0; min-height: 34px; border: 1px solid var(--line); background: var(--surface2); border-radius: 8px; font-size: 12.5px; cursor: pointer; color: var(--text); }
#tabs button[aria-selected="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }
#tabs .cnt { opacity: .7; font-size: 11px; margin-left: 3px; }

#view { padding: 16px 16px 70px; }
#view.flush { padding-top: 0; }

/* ---------- 區塊小標、列表列、分類格 ---------- */
.sec { display: flex; align-items: center; gap: 10px; margin: 22px 0 10px; font-size: 12.5px; letter-spacing: .12em; color: var(--muted); font-weight: 600; }
.sec::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.sec:first-child { margin-top: 4px; }
.row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; cursor: pointer; background: none; width: 100%; text-align: left; border-left: 0; border-right: 0; border-top: 0; }
.row:active { background: var(--surface2); }
.row .no { flex: none; width: 34px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .tx { flex: 1; min-width: 0; }
.row .t1 { font-size: 15px; line-height: 1.5; }
.row .t2 { font-size: 12px; color: var(--muted); line-height: 1.4; margin-top: 1px; }
.row .go { color: var(--muted); font-size: 20px; line-height: 1; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.chip { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 96px; padding: 12px 8px 10px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; text-decoration: none; color: inherit; text-align: center; cursor: pointer; }
.chip:active { background: var(--surface2); }
.chip svg { width: 26px; height: 26px; fill: none; stroke: var(--primary); stroke-width: 1.2; stroke-linecap: round; stroke-linejoin: round; }
html[data-theme="dark"] .chip svg { stroke: var(--accent); }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) .chip svg { stroke: var(--accent); } }
.chip .c1 { font-size: 14px; line-height: 1.35; }
.chip .c2 { font-size: 11px; color: var(--muted); letter-spacing: .04em; line-height: 1.2; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 3px; background: var(--tagA-bg); color: var(--tagA-fg); }
.tip { background: var(--tip-bg); border-left: 4px solid var(--tip-line); padding: 8px 12px; margin: 12px 0; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* ---------- 內文（Markdown） ---------- */
.md { word-wrap: break-word; overflow-wrap: anywhere; }
.md > section > :first-child, .md > :first-child { margin-top: 0; }
.md p { margin: .75em 0; }
.md h2, .md h3, .md h4 { line-height: 1.45; margin: 1.6em 0 .6em; font-weight: 700; }
.md h2.d1, .md h3.d1, .md h4.d1 { font-size: calc(var(--fs) + 4px); color: var(--primary); padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.md .d2 { font-size: calc(var(--fs) + 1.5px); }
.md .d3 { font-size: var(--fs); color: var(--muted); }
html[data-theme="dark"] .md h2.d1 { color: var(--accent); }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) .md h2.d1, html:not([data-theme="light"]) .md h3.d1, html:not([data-theme="light"]) .md h4.d1 { color: var(--accent); } }
html[data-theme="dark"] .md h3.d1, html[data-theme="dark"] .md h4.d1 { color: var(--accent); }
.md ul, .md ol { margin: .6em 0; padding-left: 1.5em; line-height: 1.75; }
.md li { margin: .15em 0; }
.md li > ul, .md li > ol { margin: .2em 0; }
.md blockquote { margin: .9em 0; padding: .1em 14px; border-left: 3px solid var(--accent); background: var(--surface2); border-radius: 0 6px 6px 0; }
.md blockquote blockquote { background: none; }
.md p.cap { font-size: calc(var(--fs) - 2px); color: var(--muted); line-height: 1.65; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.6em 0; }
.md code { background: var(--surface2); padding: 0 4px; border-radius: 3px; font-size: .92em; }
.md pre { background: var(--surface2); padding: 10px 12px; border-radius: 6px; overflow-x: auto; font-size: calc(var(--fs) - 2px); line-height: 1.5; }
.md pre code { background: none; padding: 0; }
.md .math { margin: .9em 0; overflow-x: auto; text-align: center; padding: 2px 0; }
.md .math code { white-space: pre-wrap; font-size: 13px; }
.tbl { overflow-x: auto; margin: .8em 0; -webkit-overflow-scrolling: touch; }
.tbl table { border-collapse: collapse; font-size: calc(var(--fs) - 1.5px); line-height: 1.55; min-width: 100%; }
.tbl th, .tbl td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; min-width: 3.2em; overflow-wrap: normal; }
.tbl th { background: var(--surface2); font-weight: 600; white-space: nowrap; }
.tbl td { background: var(--surface); }
figure.fig { margin: 1em 0; display: flex; flex-direction: column; gap: 8px; }
img.zimg { display: block; max-width: 100%; height: auto; background: #fff; border-radius: 3px; cursor: zoom-in; border: 1px solid var(--line); }
.missing { display: flex; align-items: center; justify-content: center; aspect-ratio: 16/9; border: 1px dashed var(--line); color: var(--muted); font-size: 13px; border-radius: 3px; background: var(--surface2); }
.loadmore { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 0; }
[data-ln] { scroll-margin-top: calc(var(--hdr) + var(--tabh) + 14px); }
.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 40% { background: var(--tip-bg); } 100% { background: transparent; } }

/* ---------- 圖表分頁 ---------- */
.fcard { padding: 12px 0; border-bottom: 1px solid var(--line); }
.fcard .thumbs { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 8px; }
.fcard .thumbs button { flex: none; padding: 0; border: 1px solid var(--line); background: #fff; border-radius: 3px; cursor: zoom-in; display: block; }
.fcard .thumbs button { max-width: 100%; }
.fcard .thumbs img { display: block; width: auto !important; height: auto !important; max-width: 100%; max-height: 200px; object-fit: contain; }
.fcard .thumbs .missing { width: 220px; aspect-ratio: 16/10; }
.fcard .lab { font-weight: 700; font-size: 13.5px; color: var(--primary); }
html[data-theme="dark"] .fcard .lab { color: var(--accent); }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) .fcard .lab { color: var(--accent); } }
.fcard .cap { font-size: 13px; color: var(--text); line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.fcard .ctx { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.fcard .jump { margin-top: 4px; padding: 0 2px; min-height: 36px; border: 0; background: none; color: var(--primary); font-size: 12.5px; cursor: pointer; }
html[data-theme="dark"] .fcard .jump { color: var(--accent); }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) .fcard .jump { color: var(--accent); } }

/* ---------- 底部面板（目錄）、提示、檢視器 ---------- */
#sheet { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
#sheet .panel { width: 100%; max-width: 760px; max-height: 76vh; overflow-y: auto; background: var(--bg); border-radius: 14px 14px 0 0; padding: 6px 14px 24px; box-shadow: 0 -4px 20px rgba(0,0,0,.2); }
#sheet .ph { position: sticky; top: 0; background: var(--bg); display: flex; align-items: center; justify-content: space-between; padding: 10px 2px 6px; font-weight: 600; border-bottom: 1px solid var(--line); }
#sheet .toc-i { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 4px; min-height: 44px; line-height: 1.45; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 14px; }
#sheet .toc-i.d2 { padding-left: 20px; color: var(--text); font-size: 13.5px; }
#sheet .toc-i.d3 { padding-left: 36px; color: var(--muted); font-size: 13px; }
#sheet .toc-i:active { background: var(--surface2); }
#toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 90; background: rgba(40,38,36,.92); color: #fff; font-size: 13px; padding: 8px 16px; border-radius: 20px; opacity: 0; pointer-events: none; transition: opacity .25s; max-width: 86vw; }
#toast.show { opacity: 1; }
#viewer { position: fixed; inset: 0; z-index: 100; background: #0c0c0c; touch-action: none; overflow: hidden; user-select: none; -webkit-user-select: none; }
#viewer .stage { position: absolute; inset: 0; touch-action: none; }
#viewer img { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none; background: #fff; will-change: transform; -webkit-user-drag: none; }
#viewer .v-x, #viewer .v-nav { position: absolute; z-index: 2; width: 46px; height: 46px; border-radius: 23px; border: 0; background: rgba(255,255,255,.16); color: #fff; font-size: 24px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
#viewer .v-x { top: 10px; right: 10px; }
#viewer .v-prev { left: 10px; top: 50%; } #viewer .v-next { right: 10px; top: 50%; }
#viewer .v-cap { position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; padding: 10px 16px 16px; background: rgba(12,12,12,.9); border-top: 1px solid rgba(255,255,255,.14); color: #eee; font-size: 12.5px; line-height: 1.55; max-height: 26vh; overflow-y: auto; pointer-events: none; }

/* ---------- 設定頁 ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 14px 12px; margin: 0 0 14px; }
.card h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); letter-spacing: .08em; font-weight: 600; }
.card .lbl { font-size: 13px; color: var(--muted); margin: 10px 0 6px; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; min-height: 44px; border: 1px solid var(--line); background: var(--surface2); border-radius: 8px; cursor: pointer; font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { text-align: right; word-break: break-all; }
.btn { min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--primary); background: var(--primary); color: var(--on-primary); cursor: pointer; }
.btn.danger { background: none; color: var(--warn); border-color: var(--warn); }

/* ---------- 開場（靜態版；水墨動畫在 3c） ---------- */
#splash { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; flex-direction: column; background: #F9F1DE; color: #3B3A39; transition: opacity .27s ease; }
#splash .name { font-size: 22px; letter-spacing: .28em; padding-left: .28em; font-family: var(--serif); }
#splash .sub { margin-top: 8px; font-size: 12px; letter-spacing: .18em; color: #8a8576; }
#splash.out { opacity: 0; pointer-events: none; }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) #splash { background: #1E1D1B; color: #EDEAE0; } }
html[data-theme="dark"] #splash { background: #1E1D1B; color: #EDEAE0; }

/* =====================================================================
   風格 B：和紙・紙本質感
   ===================================================================== */
html[data-style="b"] body { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 .45  0 0 0 0 .38  0 0 0 0 .25  0 0 0 .07 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"); }
html[data-style="b"][data-theme="dark"] body { background-image: none; }
@media (prefers-color-scheme: dark) { html[data-style="b"]:not([data-theme="light"]) body { background-image: none; } }
html[data-style="b"] #bar { box-shadow: 0 2px 5px rgba(60,45,20,.13); border-bottom-color: transparent; }
html[data-style="b"] #tabs { background: var(--bg); border-bottom: 1px solid var(--line); padding: 8px 12px 0; gap: 2px 3px; row-gap: 7px; }
html[data-style="b"] #tabs button { background: var(--surface2); border: 1px solid var(--line); border-bottom: 0; border-radius: 6px 6px 0 0; min-height: 36px; position: relative; top: 1px; }
html[data-style="b"] #tabs button[aria-selected="true"] { background: var(--bg); color: var(--text); border-top: 2px solid var(--primary); font-weight: 600; }
html[data-style="b"] .chip, html[data-style="b"] .card { border-radius: 3px; box-shadow: 0 1px 3px rgba(60,45,20,.18); border-color: transparent; }
html[data-style="b"] .row { position: relative; border-bottom-style: solid; }
html[data-style="b"] .row::after { content: ""; position: absolute; right: 0; top: 0; width: 12px; height: 12px; background: linear-gradient(225deg, var(--bg) 50%, var(--surface2) 50%); box-shadow: -1px 1px 1px rgba(60,45,20,.12); }
html[data-style="b"] .sec { color: var(--text); }
html[data-style="b"] .sec::before { content: ""; width: 3px; height: 14px; background: var(--gold); border-radius: 1px; }
html[data-style="b"] .tip { transform: rotate(-.3deg); box-shadow: 1px 2px 4px rgba(60,45,20,.2); border-left: 0; }
html[data-style="b"] img.zimg { border: 6px solid #fff; box-shadow: 0 2px 6px rgba(60,45,20,.28); border-radius: 0; }
html[data-style="b"] .md blockquote { border-left-color: var(--gold); }

/* =====================================================================
   風格 C：傳統和風裝飾
   ===================================================================== */
html[data-style="c"] #bar { background-color: var(--navy); color: #F6EFD9; border-bottom: 2px solid var(--gold); background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='20' viewBox='0 0 40 20'><g fill='none' stroke='%23ffffff' stroke-opacity='.09' stroke-width='1'><circle cx='0' cy='20' r='10'/><circle cx='0' cy='20' r='6'/><circle cx='20' cy='20' r='10'/><circle cx='20' cy='20' r='6'/><circle cx='40' cy='20' r='10'/><circle cx='40' cy='20' r='6'/><circle cx='10' cy='10' r='10'/><circle cx='10' cy='10' r='6'/><circle cx='30' cy='10' r='10'/><circle cx='30' cy='10' r='6'/></g></svg>"); }
html[data-style="c"] .b-btn, html[data-style="c"] #bar .b-title small { color: #F6EFD9; }
html[data-style="c"] #bar .b-title small { opacity: .75; }
html[data-style="c"] #tabs { background: var(--bg); border-bottom: 1px solid var(--gold); }
html[data-style="c"] #tabs button { border-radius: 0; border: 1px solid var(--gold); background: transparent; letter-spacing: .1em; }
html[data-style="c"] #tabs button[aria-selected="true"] { background: var(--navy); color: #F6EFD9; border-color: var(--gold); box-shadow: inset 0 0 0 2px var(--navy), inset 0 0 0 3px var(--gold); }
html[data-style="c"] .chip { border-radius: 0; border: 1px solid var(--gold); outline: 1px solid var(--gold); outline-offset: -5px; background: var(--surface); }
html[data-style="c"] .chip svg { stroke: var(--navy); }
html[data-style="c"][data-theme="dark"] .chip svg { stroke: var(--gold); }
@media (prefers-color-scheme: dark) { html[data-style="c"]:not([data-theme="light"]) .chip svg { stroke: var(--gold); } }
html[data-style="c"] .card { border-radius: 0; border: 1px solid var(--gold); outline: 1px solid var(--gold); outline-offset: -5px; }
html[data-style="c"] .sec { justify-content: center; color: var(--navy); letter-spacing: .3em; }
html[data-style="c"][data-theme="dark"] .sec { color: var(--gold); }
@media (prefers-color-scheme: dark) { html[data-style="c"]:not([data-theme="light"]) .sec { color: var(--gold); } }
html[data-style="c"] .sec::before { content: "◆"; font-size: 8px; color: var(--gold); }
html[data-style="c"] .sec::after { content: "◆"; flex: none; height: auto; background: none; font-size: 8px; color: var(--gold); order: 2; }
html[data-style="c"] .sec { gap: 12px; }
html[data-style="c"] .sec > span { order: 1; }
html[data-style="c"] .row { border-bottom-color: var(--gold); border-bottom-style: dotted; }
html[data-style="c"] .md h2.d1 { text-align: center; border-bottom: 0; color: var(--navy); }
html[data-style="c"] .md h2.d1::after { content: "◆ ◆ ◆"; display: block; font-size: 8px; letter-spacing: .6em; color: var(--gold); margin-top: 2px; }
html[data-style="c"][data-theme="dark"] .md h2.d1, html[data-style="c"][data-theme="dark"] .md h3.d1, html[data-style="c"][data-theme="dark"] .md h4.d1 { color: var(--gold); }
@media (prefers-color-scheme: dark) { html[data-style="c"]:not([data-theme="light"]) .md h2.d1 { color: var(--gold); } }
html[data-style="c"] .md blockquote { border-left: 3px double var(--gold); position: relative; }
html[data-style="c"] .md blockquote::after { content: ""; position: absolute; right: 8px; top: 0; width: 8px; height: 18px; background: var(--redink); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%); }
html[data-style="c"] img.zimg { border: 1px solid var(--gold); outline: 1px solid var(--gold); outline-offset: 3px; border-radius: 0; }
html[data-style="c"] .tag { border: 1px solid var(--redink); color: var(--redink); background: none; border-radius: 0; letter-spacing: .1em; }
html[data-style="c"] .fcard .lab, html[data-style="c"] .md h2.d1 { color: var(--navy); }
html[data-style="c"][data-theme="dark"] .fcard .lab { color: var(--gold); }

/* ---------- 風格 A：極簡（預設）微調 ---------- */
html[data-style="a"] .chip { border-radius: 0; border-width: 0 0 1px 0; background: none; }
html[data-style="a"] .card { border-radius: 0; border-width: 0 0 1px 0; background: none; padding-left: 0; padding-right: 0; }
html[data-style="a"] #tabs { padding-top: 4px; gap: 0; }
html[data-style="a"] #tabs button { background: none; border: 0; border-radius: 0; border-bottom: 2px solid transparent; color: var(--muted); min-height: 38px; }
html[data-style="a"] #tabs button[aria-selected="true"] { background: none; color: var(--primary); border-bottom-color: var(--primary); }
html[data-theme="dark"][data-style="a"] #tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
@media (prefers-color-scheme: dark) { html[data-style="a"]:not([data-theme="light"]) #tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); } }
html[data-style="a"] .md blockquote { background: none; border-left-width: 2px; }
html[data-style="a"] img.zimg { border-color: transparent; }
html[data-style="a"] .tip { background: none; border: 1px solid var(--tip-line); }
html[data-style="a"] .seg button { border-radius: 0; background: none; }
html[data-style="a"] .seg button[aria-pressed="true"] { background: none; color: var(--primary); border-color: var(--primary); box-shadow: inset 0 -2px 0 var(--primary); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

html[data-theme="dark"][data-style="a"] .seg button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }
@media (prefers-color-scheme: dark) { html[data-style="a"]:not([data-theme="light"]) .seg button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); } }

/* ---------- 3b：搜尋、常用、收藏、圖表總覽 ---------- */
.rw { position: relative; }
.rw .row { padding-right: 48px; }
.pin { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--primary); font-size: 16px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.pin::after { content: ""; position: absolute; inset: -6px; }
.pin[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
html[data-theme="dark"] .pin:not([aria-pressed="true"]) { color: var(--accent); }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) .pin:not([aria-pressed="true"]) { color: var(--accent); } }
html[data-style="c"] .pin { border-color: var(--gold); border-radius: 0; }
.searchbox { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px; border: 1px solid var(--line); background: var(--surface); border-radius: 24px; color: var(--muted); text-decoration: none; font-size: 14.5px; }
.searchbox svg { flex: none; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.searchbox input { flex: 1; min-width: 0; height: 46px; border: 0; background: none; font: inherit; font-size: 16px; color: var(--text); outline: none; letter-spacing: inherit; -webkit-appearance: none; appearance: none; }
.searchbox input::-webkit-search-cancel-button { display: none; }
.searchbox .sx { flex: none; width: 36px; height: 36px; border: 0; background: none; font-size: 22px; color: var(--muted); cursor: pointer; }
.searchbox:has(input:placeholder-shown) .sx { visibility: hidden; }
html[data-style="a"] .searchbox { border-radius: 0; border-width: 0 0 1px 0; background: none; padding-left: 2px; }
html[data-style="b"] .searchbox { border-radius: 3px; border-color: transparent; box-shadow: 0 1px 3px rgba(60,45,20,.18); }
html[data-style="c"] .searchbox { border-radius: 0; border: 1px solid var(--gold); outline: 1px solid var(--gold); outline-offset: -4px; }
.sfilter { margin: 10px 0 0; }
.sfilter select { width: 100%; min-height: 40px; padding: 0 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 14px; border-radius: 8px; }
html[data-style="a"] .sfilter select { border-radius: 0; background: none; border-width: 0 0 1px 0; }
html[data-style="c"] .sfilter select { border-radius: 0; border-color: var(--gold); }
.sum { font-size: 12.5px; color: var(--muted); margin: 12px 2px 0; line-height: 1.6; }
.rgrp { margin: 0 0 10px; }
.rg { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 12px 2px 4px; font-weight: 600; font-size: 14.5px; text-decoration: none; color: inherit; }
.rg .cnt { color: var(--muted); font-size: 12px; font-weight: 400; flex: none; }
.hit { display: block; width: 100%; min-height: 44px; padding: 9px 4px; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); font-size: 14px; line-height: 1.7; color: var(--text); cursor: pointer; }
.hit:active { background: var(--surface2); }
.hit .fm { display: block; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.hit .tag { margin-right: 2px; }
.more { display: block; width: 100%; min-height: 40px; background: none; border: 0; text-align: left; padding: 0 4px; color: var(--primary); font-size: 13px; cursor: pointer; }
html[data-theme="dark"] .more { color: var(--accent); }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) .more { color: var(--accent); } }
mark.q { background: color-mix(in srgb, var(--tip-line) 40%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; border-bottom: 2px solid var(--tip-line); }
.qchips { display: flex; flex-wrap: wrap; gap: 8px; }
.qchips button { min-height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 19px; background: var(--surface); color: var(--text); cursor: pointer; }
.qchips .qclr { border-style: dashed; color: var(--muted); }
.favp .hit { padding-right: 48px; }
.fcard .chn { display: block; font-size: 11.5px; font-weight: 400; color: var(--muted); }
#selbar { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; display: flex; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 4px 18px rgba(0,0,0,.28); }
#selbar button { min-height: 44px; padding: 0 16px; border: 0; background: none; color: var(--primary); font-size: 14.5px; cursor: pointer; border-radius: 10px; white-space: nowrap; }
html[data-theme="dark"] #selbar button { color: var(--accent); }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) #selbar button { color: var(--accent); } }
#hlclr { position: fixed; right: 14px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 55; min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); color: var(--text); font-size: 13px; box-shadow: 0 3px 12px rgba(0,0,0,.22); cursor: pointer; }
.b-btn svg.on path { fill: currentColor; }
#sres > .sec:first-child, #fres > .sec:first-child { margin-top: 18px; }
#fres > .sum:first-child { margin-top: 14px; }

/* ---------- 3c：螢光筆、便利貼、備份 ---------- */
mark.hl { color: inherit; border-radius: 2px; padding: 0; }
mark.hl-y { background: var(--hl-y); } mark.hl-g { background: var(--hl-g); } mark.hl-p { background: var(--hl-p); } mark.hl-b { background: var(--hl-b); }
html.hlmode mark.hl { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
html.hlmode #pane .md { -webkit-touch-callout: none; }
.mynote { margin: .8em 0; padding: 8px 12px 9px; background: var(--tip-bg); border: 1px dashed var(--tip-line); border-radius: 4px; font-size: calc(var(--fs) - 1px); line-height: 1.7; cursor: pointer; }
.mynote .mn-h { font-family: var(--sans); font-size: 11px; letter-spacing: .1em; color: var(--muted); }
.mynote .mn-h span { color: var(--warn); margin-left: 6px; letter-spacing: 0; }
.mn-t { font-family: var(--sans); white-space: pre-wrap; overflow-wrap: anywhere; }
html[data-style="a"] .mynote { background: none; }
html[data-style="c"] .mynote { border-radius: 0; border-style: solid; border-color: var(--gold); }
.hit .mn-t { display: block; }
.np .nq { font-size: 12.5px; color: var(--muted); line-height: 1.6; margin: 10px 0 8px; border-left: 3px solid var(--line); padding-left: 8px; }
.np textarea { width: 100%; min-height: 130px; padding: 10px; font: inherit; font-family: var(--sans); font-size: 16px; line-height: 1.6; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.nb { display: flex; justify-content: space-between; gap: 10px; margin-top: 10px; }
.hc { display: inline-flex; gap: 8px; align-items: center; }
.hd { position: relative; width: 32px; height: 32px; padding: 0; border-radius: 50%; border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0,0,0,.28); cursor: pointer; }
.hd::after { content: ""; position: absolute; inset: -6px; }
.hd-y { background: var(--hl-y); } .hd-g { background: var(--hl-g); } .hd-p { background: var(--hl-p); } .hd-b { background: var(--hl-b); }
.hd[aria-pressed="true"] { border-color: var(--text); }
#selbar { align-items: center; padding: 4px 6px; }
#selbar .hc { padding: 0 8px 0 6px; }
#hlbar { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; display: flex; align-items: center; gap: 12px; padding: 6px 8px 6px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 26px; box-shadow: 0 4px 18px rgba(0,0,0,.28); white-space: nowrap; }
#hlbar .hl-t { font-size: 13px; color: var(--muted); }
#hlbar .hl-done { min-height: 40px; padding: 0 16px; border: 0; border-radius: 20px; background: var(--primary); color: var(--on-primary); font-size: 14px; cursor: pointer; }
#hlpen { position: fixed; left: 14px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 55; width: 50px; height: 50px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--primary); box-shadow: 0 3px 12px rgba(0,0,0,.25); cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
#hlpen svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
html[data-theme="dark"] #hlpen { color: var(--accent); }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) #hlpen { color: var(--accent); } }
.two { display: flex; gap: 10px; margin-top: 10px; }
.two .btn { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
.btn.alt { background: none; color: var(--primary); }
html[data-theme="dark"] .btn.alt { color: var(--accent); border-color: var(--accent); }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) .btn.alt { color: var(--accent); border-color: var(--accent); } }
#selbar .hd { min-height: 0; width: 32px; height: 32px; padding: 0; border-radius: 50%; }
#selbar .hd-y { background: var(--hl-y); } #selbar .hd-g { background: var(--hl-g); } #selbar .hd-p { background: var(--hl-p); } #selbar .hd-b { background: var(--hl-b); }
#hlbar .hd { min-height: 0; padding: 0; }

/* 3c-2：開場圖示與換頁動畫 */
#splash .ic { width: 112px; height: 112px; margin-bottom: 18px; border-radius: 24px; display: block; }
#view.in-fwd { animation: inFwd .26s ease-out; }
#view.in-back { animation: inBack .24s ease-out; }
@keyframes inFwd { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: none; } }
@keyframes inBack { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #view.in-fwd, #view.in-back { animation: none; } }

/* 4：解鎖畫面、更新橫幅、下載進度 */
#lock { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center; background: #F9F1DE; color: #3B3A39; padding: 24px; }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) #lock { background: #1E1D1B; color: #EDEAE0; } }
html[data-theme="dark"] #lock { background: #1E1D1B; color: #EDEAE0; }
#lock form { width: 100%; max-width: 320px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
#lock .ic { width: 72px; height: 72px; border-radius: 16px; margin-bottom: 4px; }
#lock .name { font-size: 20px; letter-spacing: .26em; padding-left: .26em; font-family: var(--serif); margin-bottom: 10px; }
#lock input[type=password] { width: 100%; min-height: 46px; padding: 0 14px; border-radius: 10px; border: 1px solid #c9c1ad; background: rgba(255,255,255,.75); color: #3B3A39; font-size: 16px; text-align: center; letter-spacing: .08em; outline: none; }
html[data-theme="dark"] #lock input[type=password] { background: #292725; color: #EDEAE0; border-color: #4a4640; }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) #lock input[type=password] { background: #292725; color: #EDEAE0; border-color: #4a4640; } }
#lock input[type=password]:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(22,94,131,.25); }
#lock .uname { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
#lock .btn { width: 100%; }
#lock .err { min-height: 20px; color: #B3402F; font-size: 13.5px; text-align: center; }
html[data-theme="dark"] #lock .err { color: #E88B7C; }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) #lock .err { color: #E88B7C; } }
#lock .hint { font-size: 12px; color: #8a8576; text-align: center; line-height: 1.6; }
#lock form.shake { animation: shake .32s; }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }
.updbar { margin: 12px 0 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; align-items: center; }
.updbar[hidden] { display: none; }
.updbar .ut { font-size: 13.5px; line-height: 1.6; }
.updbar .ua { display: flex; gap: 6px; align-items: center; }
.updbar .btn.sm { min-height: 36px; padding: 0 14px; font-size: 14px; }
.updbar .x { width: 32px; height: 32px; border: 0; background: none; color: var(--muted); font-size: 16px; cursor: pointer; border-radius: 16px; }
.dlprog { height: 6px; border-radius: 3px; background: var(--surface2); overflow: hidden; margin-top: 10px; }
.updbar .dlprog { grid-column: 1 / -1; margin-top: 0; }
.dlprog[hidden] { display: none; }
.dlprog i { display: block; height: 100%; width: 0; background: var(--primary); transition: width .2s; }
html[data-theme="dark"] .dlprog i { background: var(--accent); }
@media (prefers-color-scheme: dark) { html:not([data-theme="light"]) .dlprog i { background: var(--accent); } }
.dlptx { font-size: 12.5px; color: var(--muted); margin-top: 6px; line-height: 1.6; }
.updbar .dlptx { grid-column: 1 / -1; margin-top: 0; }
.dlptx:empty { display: none; }

/* 5：自己處理手指，不使用原生選字；工具列移到上方避開 Google 面板 */
html.hlmode #pane .md { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
::highlight(livehl-y) { background-color: var(--hl-y); }
::highlight(livehl-g) { background-color: var(--hl-g); }
::highlight(livehl-p) { background-color: var(--hl-p); }
::highlight(livehl-b) { background-color: var(--hl-b); }
#selbar { bottom: auto; top: calc(var(--hdr) + var(--tabh) + 12px + env(safe-area-inset-top)); }
#pane .pick { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 3px; }
