/* 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;
  --rail-tab-w: 40px;   /* 右側垂直頁籤條 */
  --rail-w: 320px;      /* 頁籤條 + 展開的面板 */
}

/* 兩側都能收起來。收合狀態只改變數，版面靠 margin 跟著走，
   不需要為每種組合各寫一套規則。 */
body.side-off { --side-w: 0px; }
body.rail-off { --rail-w: var(--rail-tab-w); }

@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: 264px;
  transition: transform 0.18s ease;
  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);
  margin-right: var(--rail-w);
  padding: 3.5rem 2.5rem 6rem;
  transition: margin 0.18s ease;
}

article {
  max-width: 68ch;
  margin: 0 auto;
}

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: 4rem auto 0;
  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;
    margin-right: 0;
    padding: 4.5rem 1.25rem 5rem;
  }
  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); }


/* ==================================================== 版面：兩側可收合 */

body.side-off #side { transform: translateX(-100%); }

/* 收合後用一顆浮動按鈕叫回來。跟手機版的漢堡是同一顆，
   只是桌面版平常藏著。 */
body.side-off #menu { display: block; }

#side-toggle {
  position: absolute;
  top: 1.5rem;
  right: 0.5rem;
  width: 26px;
  height: 26px;
  padding: 0;
  line-height: 1;
  font-size: 13px;
  color: var(--fg-faint);
  background: none;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
}
#side-toggle:hover { color: var(--fg); border-color: var(--line); background: var(--bg-elev); }

/* ------------------------------------------------------- 右側頁籤面板 */

#rail {
  position: fixed;
  inset: 0 0 0 auto;
  width: var(--rail-w);
  display: flex;
  background: var(--bg-side);
  border-left: 1px solid var(--line);
  transition: width 0.18s ease;
  z-index: 15;
}

/* 頁籤條靠最外緣，文字直排——橫排在 40px 裡塞不下，
   而直排正好是這種側邊頁籤的慣例。 */
#rail-tabs {
  flex: none;
  order: 2;
  width: var(--rail-tab-w);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding-top: 1.25rem;
  gap: 2px;
  background: var(--bg-side);
}
.rail-tab {
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 0.18em;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 0.9rem 0;
  color: var(--fg-faint);
  background: none;
  border: 0;
  border-left: 2px solid transparent;
  cursor: pointer;
}
.rail-tab:hover { color: var(--fg); background: var(--bg-elev); }
.rail-tab.on {
  color: var(--accent);
  background: var(--bg);
  border-left-color: var(--accent);
}

#rail-body {
  order: 1;
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.35rem 1.15rem 3rem;
  background: var(--bg);
}
body.rail-off #rail-body { display: none; }

.rail-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--fg-faint);
  margin: 0 0 0.9rem;
}
.rail-empty { font-size: 13px; color: var(--fg-faint); line-height: 1.8; margin: 0; }

/* -------------------------------------------------------------- 名詞 */

.gl-item {
  padding: 0.7rem 0.75rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--line);
  border-left: 2px solid var(--line);
  border-radius: 6px;
  background: var(--bg-elev);
  scroll-margin-top: 1rem;
}
.gl-item.on { border-left-color: var(--accent); background: var(--accent-soft); }
.gl-term {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--fg);
  margin-bottom: 0.25rem;
  overflow-wrap: anywhere;
}
.gl-what { font-size: 12.5px; line-height: 1.75; color: var(--fg-dim); margin: 0; }
.gl-why {
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--fg-dim);
  margin: 0.45rem 0 0;
  padding-top: 0.45rem;
  border-top: 1px dashed var(--line);
}
.gl-why b { color: var(--fg); }
.gl-at {
  display: inline-block;
  margin-top: 0.45rem;
  font-size: 11.5px;
  color: var(--accent);
  text-decoration: none;
}
.gl-at:hover { text-decoration: underline; }

/* 正文裡被標記的術語 */
dfn.term {
  font-style: inherit;
  border-bottom: 1px dashed var(--fg-faint);
  cursor: help;
}
dfn.term:hover { border-bottom-color: var(--accent); color: var(--accent); }

/* -------------------------------------------------------------- 原文 */

.rail-src { display: block; padding: 0.55rem 0.6rem; border-radius: 5px; text-decoration: none; color: inherit; }
.rail-src:hover { background: var(--accent-soft); }
.rail-src b { display: block; font-size: 13px; color: var(--accent); }
.rail-src span { font-size: 12px; color: var(--fg-faint); }

/* 手機沒有空間放第三欄。這段必須排在 #rail / #side-toggle 的定義之後，
   否則同特異性下會被後面的規則蓋掉——先前就是這樣漏掉的。 */
@media (max-width: 900px) {
  #rail { display: none; }
  #side-toggle { display: none; }
  main { margin-left: 0; margin-right: 0; }
}

/* ---------------------------------------------------------- 草案切換條 */

.draftbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0 0 1.5rem;
  padding: 0.5rem 0.7rem;
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-size: 13px;
}
.draftbar > span { color: var(--fg-faint); margin-right: 0.2rem; }
.draftbar a {
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--fg-dim);
  border: 1px solid var(--line);
}
.draftbar a:hover { color: var(--fg); border-color: var(--fg-faint); }
.draftbar a.on {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

/* ========================================================== 投影片模式 */

#slide-btn {
  position: fixed;
  right: calc(var(--rail-w) + 0.85rem);
  bottom: 1rem;
  z-index: 45;
  width: 34px;
  height: 34px;
  font-size: 15px;
  line-height: 1;
  color: var(--fg-faint);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: right 0.18s ease;
}
#slide-btn:hover { color: var(--accent); border-color: var(--accent); }

body.slides #side,
body.slides #rail,
body.slides .pager,
body.slides #menu,
body.slides .draftbar,
body.slides .source { display: none; }

/* 投影片模式下改用進度列裡的離開鈕，這顆浮動的收起來 */
body.slides #slide-btn { display: none; }

.sb-exit {
  flex: none;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 0.28rem 0.75rem;
  color: var(--fg-dim);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.sb-exit:hover { color: var(--accent); border-color: var(--accent); }

body.slides main {
  margin: 0;
  padding: 3.5rem 3rem 5rem;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 一次只顯示一組兄弟節點。用 revert 而不是 block，
   表格與清單才會回到自己該有的 display。 */
body.slides article > * { display: none; }
body.slides article > .s-on { display: revert; }

body.slides article {
  max-width: 74ch;
  width: 100%;
  font-size: 19px;
}
body.slides article h1 { display: none; }
body.slides article > h2.s-on {
  margin-top: 0;
  font-size: 1.9rem;
  padding-bottom: 0.6rem;
  border-bottom: 2px solid var(--accent);
}
body.slides article > h3.s-on { margin-top: 0; font-size: 1.5rem; }
body.slides article > p.s-on { font-size: 1.02em; }
body.slides article table { font-size: 15.5px; }
body.slides article pre { font-size: 14.5px; }

/* 進度／標題列 */
#slide-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 46;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.5rem 1rem;
  background: var(--bg-side);
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--fg-faint);
}
body:not(.slides) #slide-bar { display: none; }
.sb-pos {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--accent);
  min-width: 3.5em;
}
.sb-title {
  color: var(--fg);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sb-keys { margin-left: auto; white-space: nowrap; }
.sb-exit { margin-left: 0.6rem; }

/* 名詞頁：岔出主線的那一張 */
#slide-term { display: none; }
#slide-term.s-on { display: block; }
.st-kicker {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--accent);
  margin: 0 0 0.6rem;
}
.st-term { margin: 0 0 1.2rem !important; font-size: 2rem !important; border: 0 !important; }
.st-what { font-size: 1.15em; line-height: 1.85; }
.st-why {
  font-size: 1.02em;
  line-height: 1.85;
  color: var(--fg-dim);
  padding: 0.9rem 1.1rem;
  background: var(--accent-soft);
  border-radius: 8px;
}
.st-at { font-size: 0.9em; }
.st-hint { font-size: 0.82em; color: var(--fg-faint); margin-top: 2rem; }

body.slides dfn.term {
  border-bottom-width: 2px;
  border-bottom-color: var(--accent);
  cursor: pointer;
}

@media (max-width: 900px) {
  #slide-btn { right: 0.85rem; }
  body.slides main { padding: 2rem 1.1rem 4rem; }
  body.slides article { font-size: 17px; }
  .sb-keys { display: none; }
}

/* 講者備註：投影時不顯示，按 n 叫出來。
   要寫得比 `body.slides article > .s-on { display: revert }` 更明確，
   否則備註一旦落在當前頁就會被那條規則叫出來。 */
.note { display: none; }
body.slides article > .note.s-on { display: none; }
body.slides.notes-on article > .note.s-on {
  display: block;
  margin-top: 1.6rem;
  padding: 0.9rem 1.1rem;
  border-left: 3px solid var(--fg-faint);
  background: var(--bg-side);
  border-radius: 0 8px 8px 0;
  font-size: 0.82em;
  line-height: 1.8;
  color: var(--fg-dim);
}
.note p:last-child { margin-bottom: 0; }
body:not(.slides) .note { display: none; }
.slide-break { display: none; }

/* 講課版：字再大一級，內容置中偏上 */
body.slide-start.slides article { font-size: 21px; max-width: 66ch; }
body.slide-start.slides article > h2.s-on { font-size: 2.2rem; }
body.slide-start.slides article > h3.s-on { font-size: 1.7rem; }
body.slide-start.slides article pre { font-size: 16px; line-height: 1.75; }

/* ------------------------------------------------------- claim 版面 */

/* claim 是一頁的容器；不能用 display:contents，
   那種元素沒有 box，起始頁的位置判斷會全部歸零 */
.claim { display: block; }
.claim-assert {
  font-size: 1.15em;
  line-height: 1.65;
  font-weight: 500;
  margin: 0 0 1.4rem;
}
.claim-fig { margin: 0; text-align: center; }
.claim-fig img {
  max-width: 100%;
  max-height: 52vh;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;   /* 論文截圖是黑字白底，深色模式也要維持可讀 */
  padding: 0.5rem;
}
.claim-fig figcaption {
  margin-top: 0.7rem;
  font-size: 0.68em;
  color: var(--fg-faint);
}
.dia { width: 100%; max-height: 48vh; }
.dia-box { fill: var(--bg-elev); stroke: var(--line); stroke-width: 1.5; }
.dia-box.hot { stroke: var(--accent); stroke-width: 2.5; fill: var(--accent-soft); }
.dia-num { font: 700 15px var(--sans); fill: var(--fg-faint); }
.dia-num.hot { fill: var(--accent); }
.dia-t { font: 13px var(--sans); fill: var(--fg); }
.dia-t.hot { fill: var(--fg); font-weight: 600; }
.dia-t.dim { fill: var(--fg-faint); font-size: 12px; }
.dia-t.strong { font-weight: 700; fill: var(--accent); font-size: 15px; }
.dia-note { font: 12px var(--sans); fill: var(--fg-faint); }
.dia-arrow { stroke: var(--fg-faint); stroke-width: 1.5; fill: none; }
.dia-arrow.back { stroke: var(--accent); stroke-dasharray: 5 4; }
.dia-arrow-h { fill: var(--fg-faint); }
.dia-band { fill: var(--bg-elev); stroke: var(--line); stroke-width: 1.5; }
.dia-band.mid { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.dia-cut { stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 6 4; }
.dia-cut-label { font: 700 12px var(--sans); fill: var(--accent); text-anchor: middle; }
.claim-body { font-size: 1.02em; }
.claim-body p:last-child { margin-bottom: 0; }
.claim-body pre { margin-bottom: 0; }
.claim-body .katex-display { margin: 0.6rem 0; font-size: 1.15em; }
.claim-body table { font-size: 0.86em; }

/* --------------------------------------------- 側欄群組（單元 → 材料 → 節） */

.toc.group { border-left: 0; padding-left: 0.2rem; margin-bottom: 0.5rem; }
.toc.group > li { margin: 0; }
.toc.group > li > a {
  font-size: 14.5px;
  font-weight: 500;
  color: var(--fg-dim);
  padding: 0.32rem 0.5rem;
  border-radius: 5px;
}
.toc.group > li > a:hover { color: var(--fg); background: var(--bg-elev); }
.toc.group > li > a.current {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-soft);
  box-shadow: none;
}
/* 第三層：節內錨點，明顯縮一階並縮小 */
.toc.group .toc {
  margin: 0.1rem 0 0.45rem 0.55rem;
  padding-left: 0.55rem;
  border-left: 1px solid var(--line);
}
.toc.group .toc a { font-size: 13px; padding: 0.18rem 0.45rem; }

/* 群組標題是按鈕，不是連結——外觀維持一致，但行為是展開／收合 */
button.unit-head {
  width: calc(100% + 0.6rem);
  font: inherit;
  font-size: 15px;
  text-align: left;
  background: none;
  cursor: pointer;
  border: 0;
}
.caret {
  flex: none;
  width: 0;
  height: 0;
  margin-right: 0.15rem;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  opacity: 0.55;
  transition: transform 0.15s ease;
}
.unit.group.open .caret { transform: rotate(90deg); }
.unit.group:not(.open) .toc.group { display: none; }

/* 投影片頁的講義檢視：提示可以播放，但不自動搶走畫面 */
.slide-cue {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 0 0 2rem;
  padding: 0.7rem 0.95rem;
  border: 1px dashed var(--accent);
  border-radius: 8px;
  background: var(--accent-soft);
  font-size: 14px;
  color: var(--fg-dim);
}
.slide-cue button {
  margin-left: auto;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 0.35rem 0.9rem;
  color: var(--accent);
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.slide-cue button:hover { background: var(--accent); color: var(--bg); }
body.slides .slide-cue { display: none; }

/* 講義檢視下，每個 claim 之間要有分隔，否則會黏成一團 */
body:not(.slides) .claim {
  padding: 1.4rem 0;
  border-top: 1px solid var(--line);
}
body:not(.slides) .claim:first-of-type { border-top: 0; }
body:not(.slides) .claim-assert { font-size: 1.05em; }
body:not(.slides) .claim-fig img { max-height: 380px; }

/* 第二層：材料標題也是可展開的按鈕 */
.mat-head {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  width: 100%;
  font: inherit;
  font-size: 14.5px;
  font-weight: 500;
  text-align: left;
  padding: 0.32rem 0.5rem;
  color: var(--fg-dim);
  background: none;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
}
.mat-head:hover { color: var(--fg); background: var(--bg-elev); }
.mat.here > .mat-head { color: var(--accent); font-weight: 600; background: var(--accent-soft); }
.mat:not(.open) > .toc { display: none; }
.mat.open > .mat-head .caret { transform: rotate(90deg); }
.mat-head .caret { border-left-width: 4px; border-top-width: 3.5px; border-bottom-width: 3.5px; }
