/* formal-learning — 三層側欄 + 長文閱讀版面
   淺色為預設，深色只覆寫 token（見 :root 與 prefers-color-scheme） */

:root {
  --bg: #faf9f7;
  --bg-elev: #fff;
  --bg-side: #f3f1ed;
  --fg: #1c1a17;
  --fg-dim: #5f5a52;
  --fg-faint: #918a80;
  --line: #e0dcd4;
  --accent: #0f766e;
  --accent-soft: #d7ede9;
  --code-bg: #f1efea;
  --sans: "PingFang TC", "Noto Sans TC", "Hiragino Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Cascadia Code", ui-monospace, Menlo, Consolas, monospace;
  --side-w: 264px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --bg-elev: #1a1d22;
    --bg-side: #101216;
    --fg: #e6e4e0;
    --fg-dim: #a8a49d;
    --fg-faint: #6f6b65;
    --line: #2a2e35;
    --accent: #5eead4;
    --accent-soft: #16332e;
    --code-bg: #1d2026;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 1.5rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

/* ---------------------------------------------------------------- 側欄 */

#side {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--side-w);
  padding: 1.5rem 0 1.5rem 1.25rem;
  background: var(--bg-side);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 15px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--fg);
  text-decoration: none;
  margin-bottom: 1.25rem;
  padding-right: 1.25rem;
}
.brand span { color: var(--fg-faint); font-weight: 400; }

#side > a,
.unit-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 1.25rem 0.4rem 0.6rem;
  margin-left: -0.6rem;
  border-radius: 6px;
  color: var(--fg-dim);
  text-decoration: none;
}
#side > a:hover,
.unit-head:hover { background: var(--bg-elev); color: var(--fg); }

#side > a.active,
.unit-head.active {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-soft);
}

.unit { margin-top: 2px; }

/* 第二層：節內錨點 */
.toc {
  list-style: none;
  margin: 0.25rem 0 0.6rem;
  padding: 0 0 0 0.6rem;
  border-left: 2px solid var(--line);
}
.toc a {
  display: block;
  padding: 0.22rem 0.5rem;
  color: var(--fg-dim);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.5;
  border-radius: 4px;
}
.toc a:hover { color: var(--fg); background: var(--bg-elev); }
.toc a.current {
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
  background: var(--accent-soft);
}

/* 掌握度圓點：5 顆，每顆 2 張卡 */
.dots { display: inline-flex; gap: 3px; flex: none; }
.dots i {
  width: 6px; height: 6px;
  border-radius: 50%;
  border: 1.5px solid var(--fg-faint);
}
.dots i.on { background: var(--accent); border-color: var(--accent); }

.progress-total {
  margin-top: auto;
  padding: 0.9rem 1.25rem 0 0;
  border-top: 1px solid var(--line);
  color: var(--fg-faint);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- 內容 */

main {
  margin-left: var(--side-w);
  padding: 3.5rem 3rem 6rem;
  max-width: calc(var(--side-w) + 78ch);
}

article { max-width: 68ch; }

h1 {
  font-size: 2rem;
  line-height: 1.3;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
}
h2 {
  font-size: 1.35rem;
  line-height: 1.4;
  margin: 3rem 0 0.75rem;
  padding-top: 0.5rem;
  letter-spacing: -0.01em;
}
h3 { font-size: 1.08rem; margin: 2rem 0 0.5rem; }
h4 { font-size: 1rem; margin: 1.5rem 0 0.4rem; color: var(--fg-dim); }

p { margin: 0 0 1.1rem; }

.source {
  color: var(--fg-faint);
  font-size: 14px;
  margin-bottom: 2.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}
.source .pdf {
  font-weight: 600;
  white-space: nowrap;
}

/* 內文的 p.NNN：全站有五十幾個，做成一般連結會太吵。
   平時只用虛線底線暗示可點，hover 才亮起來。 */
.pref {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted var(--fg-faint);
  white-space: nowrap;
}
.pref:hover,
.pref:focus-visible {
  color: var(--accent);
  border-bottom-color: var(--accent);
  border-bottom-style: solid;
}
/* 表格裡的頁碼欄是導覽用的，可點性給得明顯一點 */
td .pref { border-bottom-color: var(--line); }

ul, ol { margin: 0 0 1.1rem; padding-left: 1.4rem; }
li { margin: 0.3rem 0; }
li > ul, li > ol { margin: 0.3rem 0 0.5rem; }

blockquote {
  margin: 1.5rem 0;
  padding: 0.1rem 1.25rem;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
  color: var(--fg-dim);
}

hr { border: 0; border-top: 1px solid var(--line); margin: 3rem 0; }

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.12em 0.38em;
  border-radius: 4px;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.15rem;
  overflow-x: auto;
  margin: 0 0 1.4rem;
  line-height: 1.65;
}
pre code { background: none; padding: 0; font-size: 14px; }

/* 寬內容自己捲，body 永不橫捲 */
.table-wrap { overflow-x: auto; margin: 0 0 1.5rem; }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td {
  text-align: left;
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th { font-weight: 600; color: var(--fg-dim); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }

.katex-display { overflow-x: auto; overflow-y: hidden; padding: 0.4rem 0; }

/* ------------------------------------------------------------- 上下頁 */

.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  max-width: 68ch;
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  font-size: 15px;
}
.pager a { text-decoration: none; color: var(--fg-dim); }
.pager a:hover { color: var(--accent); }
.pager .next { margin-left: auto; text-align: right; }

/* ------------------------------------------------------------ 手機版 */

#menu, #scrim { display: none; }

@media (max-width: 900px) {
  body { font-size: 16px; }

  #menu {
    display: block;
    position: fixed;
    top: 0.75rem; left: 0.75rem;
    z-index: 30;
    width: 40px; height: 40px;
    font-size: 18px;
    line-height: 1;
    background: var(--bg-elev);
    color: var(--fg);
    border: 1px solid var(--line);
    border-radius: 8px;
    cursor: pointer;
  }

  #side {
    z-index: 25;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 40px rgb(0 0 0 / 0.18);
  }
  body.nav-open #side { transform: none; }

  body.nav-open #scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgb(0 0 0 / 0.4);
  }

  main {
    margin-left: 0;
    padding: 4.5rem 1.25rem 5rem;
    max-width: 100%;
  }
  article, .pager { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  #side { transition: none; }
}

/* ============================================================ 互動元件
   引導式手算題（#5）與閃卡（#6）。狀態顏色另立 token，深淺色各一組。 */

:root {
  --ok: #0f766e;
  --ok-bg: #e3f2ef;
  --no: #b3411b;
  --no-bg: #fbeae4;
  --lock: #f3f1ed;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ok: #5eead4;
    --ok-bg: #15332e;
    --no: #f0a08a;
    --no-bg: #3a201a;
    --lock: #16191e;
  }
}

.walkthrough, .cards { margin: 2.5rem 0; }

.wt-head h3, .cards-head h4 { margin: 0 0 0.35rem; }
.wt-head p, .cards-head p { color: var(--fg-dim); font-size: 15px; margin: 0 0 1.25rem; }

/* ---- 分段 */

.wt-part {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.25rem;
  background: var(--bg-elev);
}
.wt-part.part-locked { opacity: 0.5; }
.wt-part.part-done { border-color: var(--ok); }

.wt-part-head h4 { margin: 0 0 0.3rem; font-size: 1.05rem; color: var(--fg); }
.wt-part-head p { margin: 0 0 1.1rem; color: var(--fg-dim); font-size: 15px; line-height: 1.7; }

/* ---- 單一步驟 */

.wt-step {
  border-top: 1px solid var(--line);
  padding: 1.1rem 0 0.9rem;
  position: relative;
}
.wt-step:first-of-type { border-top: 0; padding-top: 0.25rem; }

.wt-step.locked { opacity: 0.35; pointer-events: none; filter: grayscale(0.6); }
.wt-step.locked .wt-body::after {
  content: "先完成上一步";
  font-size: 13px;
  color: var(--fg-faint);
}
.wt-step.locked .wt-body > * { display: none; }

.wt-num {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.3rem;
}
.wt-num span { font-weight: 400; }
.wt-step.done .wt-num::after { content: " ✓"; color: var(--ok); }

.wt-prompt { margin-bottom: 0.8rem; line-height: 1.75; }

/* ---- 填空 */

.wt-fill {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--mono);
  font-size: 15px;
  background: var(--code-bg);
  border-radius: 6px;
  padding: 0.7rem 0.85rem;
  margin-bottom: 0.7rem;
}
.wt-input {
  font: inherit;
  padding: 0.3rem 0.55rem;
  min-width: 8ch;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--bg-elev);
  color: var(--fg);
}
.wt-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.wt-input:disabled { border-color: var(--ok); color: var(--ok); font-weight: 600; }

/* ---- 按鈕 */

.wt-btns { display: flex; gap: 0.5rem; }
.wt-btn {
  font: inherit;
  font-size: 14px;
  padding: 0.42rem 0.95rem;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--fg);
  cursor: pointer;
}
.wt-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.wt-btn:disabled { opacity: 0.45; cursor: default; }
.wt-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 600; }
.wt-btn.primary:hover:not(:disabled) { filter: brightness(1.08); color: var(--bg); }
.wt-btn.ghost { color: var(--fg-dim); }

/* ---- 選擇題 */

.wt-options { display: flex; flex-direction: column; gap: 0.45rem; }
.wt-opt {
  font: inherit;
  font-size: 15px;
  text-align: left;
  line-height: 1.6;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
.wt-opt:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.wt-opt:disabled { cursor: default; }
.wt-opt.picked-ok { border-color: var(--ok); background: var(--ok-bg); font-weight: 600; }
.wt-opt.picked-no { border-color: var(--no); background: var(--no-bg); opacity: 0.75; text-decoration: line-through; }

/* ---- 回饋 */

.wt-feedback {
  margin-top: 0.75rem;
  padding: 0 0.9rem;
  border-radius: 7px;
  font-size: 15px;
  line-height: 1.7;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.15s ease, padding 0.15s ease;
}
.wt-feedback.ok, .wt-feedback.no, .wt-feedback.hint {
  max-height: 60rem;
  padding: 0.7rem 0.9rem;
}
.wt-feedback.ok { background: var(--ok-bg); border-left: 3px solid var(--ok); }
.wt-feedback.no { background: var(--no-bg); border-left: 3px solid var(--no); }
.wt-feedback.hint { background: var(--code-bg); border-left: 3px solid var(--fg-faint); }

.wt-error { color: var(--no); }

/* ---- 閃卡 */

.card {
  border: 1px solid var(--line);
  border-left: 3px solid var(--fg-faint);
  border-radius: 8px;
  padding: 1rem 1.15rem;
  margin-bottom: 0.9rem;
  background: var(--bg-elev);
}
.card[data-box="2"] { border-left-color: var(--accent); }
.card[data-box="3"] { border-left-color: var(--ok); }

.card-meta {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 12px;
  color: var(--fg-faint);
  margin-bottom: 0.5rem;
}
.card-meta .kind {
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 0.05rem 0.55rem;
}
.card-front { line-height: 1.75; margin-bottom: 0.85rem; }

.card-back {
  display: none;
  border-top: 1px solid var(--line);
  padding-top: 0.85rem;
  margin-bottom: 0.85rem;
  line-height: 1.75;
  color: var(--fg-dim);
}
.card.revealed .card-back { display: block; }

.card-grade { display: none; gap: 0.5rem; }
.card.revealed .card-grade { display: flex; }
.card.graded .card-grade button { display: none; }

.grade-no:hover:not(:disabled)  { border-color: var(--no); color: var(--no); }
.grade-mid:hover:not(:disabled) { border-color: var(--fg-dim); color: var(--fg); }
.grade-ok:hover:not(:disabled)  { border-color: var(--ok); color: var(--ok); }

.card-grade .mastered { color: var(--ok); font-size: 14px; font-weight: 600; }
.card-grade .again { color: var(--fg-dim); font-size: 14px; }

@media (max-width: 600px) {
  .wt-part { padding: 1rem 0.9rem; }
  .wt-fill { font-size: 14px; }
}

/* ======================================================= 首頁依賴鏈圖 (#12)
   顏色全走 CSS 變數，深淺色自動跟著換。手機上圖不縮小，改成可橫捲——
   把字縮到看不清比要求捲動更糟。 */

.dep-wrap { overflow-x: auto; margin: 1.5rem 0 2rem; }
.dep {
  display: block;
  width: 100%;
  min-width: 660px;
  height: auto;
  font-family: var(--sans);
}

.dep-node {
  fill: var(--bg-elev);
  stroke: var(--line);
  stroke-width: 1;
  transition: stroke 0.12s ease, fill 0.12s ease;
}
.dep-link { cursor: pointer; }
.dep-link:hover .dep-node { stroke: var(--accent); fill: var(--accent-soft); }
.dep-link:focus-visible .dep-node { stroke: var(--accent); stroke-width: 2; }

.dep-title { fill: var(--fg); font-size: 17px; font-weight: 700; }
.dep-venue { fill: var(--fg-faint); font-size: 12px; }
.dep-q     { fill: var(--fg); font-size: 14.5px; }
.dep-tech  { fill: var(--fg-dim); font-size: 11.5px; font-family: var(--mono); }

.dep .dot { fill: none; stroke: var(--fg-faint); stroke-width: 1.5; }
.dep .dot.on { fill: var(--accent); stroke: var(--accent); }

.dep-arrow, .dep-arc { stroke: var(--fg-faint); stroke-width: 1.5; fill: none; }
.dep-arc { stroke-dasharray: 5 4; }
.dep-head { fill: var(--fg-faint); }
.dep-arc-label { fill: var(--fg-dim); font-size: 13px; }

/* ========================================================= 複習頁 (#10) */

.rv-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.25rem; }
.rv-tab { min-width: 5.5rem; }
.rv-tab.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 600;
}
.rv-tab.on:hover { color: var(--bg); }

.rv-progress {
  font-size: 13px;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.6rem;
}

.rv-empty, .rv-result {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.5rem 1.35rem;
  background: var(--bg-elev);
}
.rv-empty h4, .rv-result h4 { margin: 0 0 0.5rem; font-size: 1.1rem; color: var(--fg); }
.rv-empty p, .rv-result p { margin: 0 0 1rem; color: var(--fg-dim); font-size: 15px; }
.rv-result ul { margin: 0 0 1rem; padding-left: 1.2rem; color: var(--fg-dim); font-size: 14px; }
.rv-result li { margin: 0.35rem 0; }
.rv-empty .wt-btn, .rv-result .wt-btn { margin-top: 0.25rem; }

/* 複習頁的卡片一次只出現一張，給它多一點呼吸空間 */
.rv-slot .card { margin-bottom: 0; padding: 1.35rem 1.5rem; }
.rv-slot .card-front { font-size: 1.02rem; }

/* ============================================================ 問答 (#13) */

.ask { margin: 3rem 0 1rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
/* 加值服務未開放時的樣子：說明文字保持正常可讀，只把「操作得了」的部分反灰 */
.ask-lock {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  margin-bottom: 1.25rem;
}
.ask-lock p { margin: 0; font-size: 14px; line-height: 1.75; color: var(--fg-dim); }
.ask-badge {
  flex: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  margin-top: 0.15rem;
  white-space: nowrap;
}
.ask-locked .ask-form { opacity: 0.45; filter: saturate(0.4); }
.ask-locked .ask-form * { cursor: not-allowed; }

.ask-head h4 { margin: 0 0 0.35rem; }
.ask-head p { color: var(--fg-dim); font-size: 14px; margin: 0 0 1rem; }

.ask-form { display: flex; flex-direction: column; gap: 0.6rem; }

.ask-code-row { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; }
.ask-code-row.saved .ask-code { border-color: var(--ok); }
.ask-code {
  font: inherit; font-size: 14px;
  padding: 0.4rem 0.6rem;
  width: 11rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-elev);
  color: var(--fg);
}
.ask-hint { font-size: 12.5px; color: var(--fg-faint); }

.ask-input {
  font: inherit; font-size: 15px;
  line-height: 1.7;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-elev);
  color: var(--fg);
  resize: vertical;
  min-height: 3.6rem;
}
.ask-input:focus, .ask-code:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

.ask-row { display: flex; align-items: center; gap: 0.8rem; }

.ask-out { margin-top: 1rem; font-size: 15px; line-height: 1.8; }
.ask-out:empty { display: none; }
.ask-out.thinking { color: var(--fg-faint); }
.ask-out.error {
  color: var(--no);
  background: var(--no-bg);
  border-left: 3px solid var(--no);
  border-radius: 0 6px 6px 0;
  padding: 0.7rem 0.9rem;
}
.ask-out.answer {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 0.9rem 1.1rem;
}
.ask-out.answer p { margin: 0 0 0.7rem; }
.ask-out.answer p:last-child { margin-bottom: 0; }

/* ------------------------------------------------------------ 學習紀錄 */

.cert { margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--line); }
.cert-head h4 { margin: 0 0 0.35rem; }
.cert-head p { color: var(--fg-dim); font-size: 14px; margin: 0 0 1rem; }
.cert-form { display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; }
.cert-name {
  flex: 1 1 14rem;
  max-width: 20rem;
  font: inherit;
  font-size: 15px;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}
.cert-name:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.cert-out:empty { display: none; }

.cert-card {
  margin-top: 1.5rem;
  padding: 1.75rem 1.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}
.cert-brand { font-size: 13px; letter-spacing: 0.02em; color: var(--fg-faint); font-weight: 700; }
.cert-brand span { color: var(--accent); }
.cert-card h3 { margin: 0.5rem 0 1.4rem; font-size: 21px; }
.cert-who { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1.2rem; margin: 0 0 1.4rem; }
.cert-who dt { color: var(--fg-faint); font-size: 13.5px; }
.cert-who dd { margin: 0; font-weight: 600; }
/* 分數給得夠大，因為它就是這張紙的目的：看到不滿意的數字，回去把它做滿 */
.cert-score {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  margin: 0 0 1.4rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid var(--line);
}
.cert-pct { font-size: 40px; font-weight: 700; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.cert-unit { font-size: 16px; font-weight: 600; color: var(--accent); }
.cert-frac { margin-left: 0.6rem; font-size: 13.5px; color: var(--fg-faint); }
.cert-full {
  margin-left: auto;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  border: 1.5px solid currentColor;
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  align-self: center;
}
.cert-card.full { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.cert-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.cert-table th, .cert-table td { padding: 0.5rem 0.6rem; text-align: left; border-bottom: 1px solid var(--line); }
.cert-table th { color: var(--fg-faint); font-weight: 600; font-size: 13px; }
.cert-table td + td, .cert-table th + th { text-align: right; white-space: nowrap; }
.cert-table tfoot td { font-weight: 700; border-bottom: none; border-top: 2px solid var(--line); }
.cert-note { margin: 1.3rem 0 0; font-size: 12.5px; line-height: 1.75; color: var(--fg-faint); }
.cert-actions { display: flex; gap: 0.8rem; align-items: center; flex-wrap: wrap; margin-top: 1.1rem; }

/* 列印時只留紀錄卡本身。用 visibility 而不是 display，才不會因為祖先被隱藏
   就整個消失——這是這種「只印頁面一小塊」需求的標準寫法。 */
@media print {
  body * { visibility: hidden; }
  .cert-card, .cert-card * { visibility: visible; }
  .cert-card {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    margin: 0;
    border: none;
    padding: 0;
  }
  .cert-card h3 { margin-top: 0; }
  @page { margin: 18mm; }
}

/* ------------------------------------------------------------- 教材檢索 */

.sr-form { display: flex; gap: 0.7rem; margin: 0 0 0.6rem; }
.sr-input {
  flex: 1;
  font: inherit;
  font-size: 16px;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-elev);
  color: var(--fg);
}
.sr-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.sr-meta, .sr-count { font-size: 13px; color: var(--fg-faint); margin: 0 0 1.2rem; }
.sr-empty { font-size: 15px; color: var(--fg-dim); margin: 1rem 0; }

.sr-hit {
  display: block;
  text-decoration: none;
  color: inherit;
  padding: 0.95rem 1.1rem;
  margin-bottom: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-elev);
}
.sr-hit:hover { border-color: var(--accent); }
.sr-where { font-size: 12.5px; color: var(--accent); font-weight: 600; margin-bottom: 0.3rem; }
.sr-text {
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--fg-dim);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.sr-text mark {
  background: var(--accent-soft);
  color: var(--fg);
  font-weight: 600;
  border-radius: 2px;
  padding: 0 1px;
}
.sr-foot {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-top: 0.55rem;
  font-size: 12.5px;
  color: var(--fg-faint);
}
.sr-jump { color: var(--accent); }
.sr-src { margin-left: auto; }
.sr-cite { color: var(--fg-faint); text-decoration: underline; text-decoration-style: dotted; }
.sr-cite:hover { color: var(--accent); }

/* 從檢索結果跳回教材時，短暫標出是哪一段 */
.jump-hit {
  background: var(--accent-soft);
  box-shadow: 0 0 0 6px var(--accent-soft);
  border-radius: 3px;
  transition: background 1.2s ease, box-shadow 1.2s ease;
}
.jump-hit.fade { background: transparent; box-shadow: 0 0 0 6px transparent; }

/* --------------------------------------------------------- 側欄即時檢索 */

#sidesearch { position: relative; margin: 0 1.25rem 1rem 0; }
#ss-input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 0.42rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}
#ss-input::placeholder { color: var(--fg-faint); }
#ss-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

/* 結果浮在導覽之上而不是把它推下去：搜尋是暫時的動作，
   導覽的位置不該因此跳動。 */
#ss-out {
  position: absolute;
  z-index: 40;
  top: calc(100% + 5px);
  left: 0;
  /* 寬度必須貼齊 #sidesearch：#side 有 overflow-y:auto，依 CSS 規範這會把
     overflow-x 一併算成 auto，超出去的部分會被裁掉並長出橫向捲軸。 */
  width: 100%;
  max-height: min(62vh, 520px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.16);
  padding: 0.3rem;
}
.ss-note { margin: 0; padding: 0.6rem 0.55rem; font-size: 13px; color: var(--fg-faint); }
.ss-hit {
  display: block;
  padding: 0.5rem 0.55rem;
  border-radius: 5px;
  text-decoration: none;
  color: inherit;
}
.ss-hit:hover { background: var(--accent-soft); }
.ss-where {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ss-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--fg-dim);
}
.ss-text mark { background: var(--accent-soft); color: var(--fg); font-weight: 600; padding: 0 1px; }
.ss-all {
  display: block;
  padding: 0.5rem 0.55rem;
  margin-top: 0.2rem;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--accent);
  text-decoration: none;
}
.ss-all:hover { background: var(--accent-soft); }

