/* 類澱粉 PET 定量筆記
   視覺比喻：測量工作台上的紙本筆記——暖白紙、石墨墨、黃銅色的量測標記。
   版面架構：頂欄導覽（全站 5 頁）+ 單欄閱讀區，內文 1rem = 20px、
   行高 1.78、全站最小字 0.9rem（老花眼鐵則）。
   規則依據：docs/AI_AGENT_RULES.md（扁平閱讀、不巢狀卡片）、PRODUCT.md、
   DESIGN.md（卡片不得巢狀、行長、焦點狀態）。本頁無裝飾性 raster 素材。 */

:root {
  --paper: #faf8f4;
  --paper-2: #efeae2;
  --ink: #1e1e1c;
  --ink-2: #4a4842;
  --ink-3: #6a6860;
  --rule: #d5cec4;
  --rule-2: #e2dcd2;
  --accent: #264f4f;
  --accent-ink: #154444;
  --accent-soft: #eaf2f0;
  --data: #2b3a55;
  --warn: #8a4526;
  --warn-soft: #f8efe8;
  --ok: #1f5c3d;
  --no: #9a3a20;
  --nav-hover: #efeae2;
  /* 依據等級色（方法章節用）；實算對比 ≥ 4.5:1（見頁尾驗證） */
  --lvl-std: #1f3a63;
  --lvl-std-bg: #e8eef7;
  --lvl-std-bd: #c3d2e6;
  --lvl-guide: #5d4516;
  --lvl-guide-bg: #f4ecdc;
  --lvl-guide-bd: #e0d2b6;
  --lvl-paper: #23502f;
  --lvl-paper-bg: #e8f1e9;
  --lvl-paper-bd: #c6dcc9;
  --lvl-team: #4a3560;
  --lvl-team-bg: #efeaf5;
  --lvl-team-bd: #d6cbe6;
  --lvl-own: #7a3a12;
  --lvl-own-bg: #f9ece3;
  --lvl-own-bd: #e6cdb9;
  --lvl-none: #7a2418;
  --lvl-none-bg: #f8e6e2;
  --lvl-none-bd: #c99083;
  --maxw: 820px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 104px; font-size: 20px; }
/* 1rem = 20px 是本頁的設計前提（見檔頭說明）：全站最小字 0.9rem = 18px。
   先前的 CSS 沒有設 html 字級，實際以瀏覽器預設 16px 渲染，最小字只有 14.4px。 */
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;        /* 20px */
  line-height: 1.78;
}

/* 可見焦點（PRODUCT.md：保持焦點狀態可見） */
a:focus-visible, button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 60;
  background: var(--ink); color: var(--paper); padding: 12px 18px;
}
.skip-link:focus { left: 8px; top: 8px; }

.progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 0;
  background: var(--accent); z-index: 50;
}
@media (prefers-reduced-motion: no-preference) { .progress { transition: width 120ms linear; } }

/* 舊頂欄（.topbar／.pagenav／.brand-*）已於 2026-09-29 整合進主站外殼，規則移除；
   現行頂欄樣式在檔尾的 .shell-topbar 區塊。 */

/* 本頁內容：扁平清單，不是卡片 */
.toc {
  margin: 0 0 46px; padding: 16px 0 8px;
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.toc p {
  margin: 0 0 8px; color: var(--ink-3);
  font-size: 0.9rem; font-weight: 700; letter-spacing: 0.14em;
}
.toc ol { margin: 0; padding: 0; list-style: none; columns: 2; column-gap: 30px; }
.toc li { margin: 0 0 3px; break-inside: avoid; }
.toc a {
  display: flex; align-items: baseline; gap: 9px; padding: 5px 0;
  color: var(--ink-2); text-decoration: none; font-size: 0.95rem;
}
.toc a span { flex: none; color: var(--ink-3); font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.toc a:hover { color: var(--ink); text-decoration: underline; }
.toc a[aria-current="true"] { color: var(--accent-ink); font-weight: 700; }

/* 各頁開頭（首頁用 .lede） */
.pagehead { margin-bottom: 34px; }
.pagehead h1 {
  margin: 0 0 14px; font-size: clamp(1.9rem, 3.2vw, 2.5rem);
  line-height: 1.32; letter-spacing: -0.01em;
}
.pagehead-body { margin: 0; font-size: 1.05rem; color: var(--ink-2); }

/* 頁尾切換：上一頁／下一頁 */
.pager {
  display: flex; gap: 16px; justify-content: space-between;
  margin: 52px 0 0; padding-top: 18px; border-top: 2px solid var(--rule);
}
.pager a { color: var(--accent-ink); text-decoration: none; font-size: 0.95rem; font-weight: 700; }
.pager a:hover { text-decoration: underline; }
.pager .next { margin-left: auto; text-align: right; }

/* 閱讀區 */
#doc { max-width: var(--maxw); margin: 0 auto; padding: 52px 24px 96px; }

.crumbs { margin-bottom: 26px; font-size: 0.95rem; color: var(--ink-3); }
.crumbs a { color: var(--accent-ink); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.crumbs span { margin: 0 6px; }

.lede { margin-bottom: 52px; }
.lede-with-mascot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px;
  align-items: center;
  gap: 24px;
}
.lede-mascot { width: 160px; height: 160px; object-fit: contain; }
.kicker {
  margin: 0 0 10px;
  color: var(--accent-ink);
  font-size: 0.9rem; font-weight: 700; letter-spacing: 0.14em;
}
.lede h1 {
  margin: 0 0 18px;
  font-size: clamp(2.2rem, 4vw, 3rem);
  line-height: 1.28; letter-spacing: -0.01em;
}
.lede h1::after {
  content: ""; display: block; width: 50px; height: 3px;
  background: var(--accent); margin-top: 20px;
}
.lede-body { margin: 0; font-size: 1.15rem; color: var(--ink-2); }
.lede-body strong { color: var(--ink); }

/* 章節：扁平閱讀欄，不是卡片 */
section { padding: 30px 0; border-top: 1px solid var(--rule-2); scroll-margin-top: 104px; }
section:first-of-type { border-top: 0; }
section h2 {
  display: flex; align-items: baseline; gap: 12px;
  margin: 0 0 14px;
  font-size: 1.65rem; line-height: 1.4;
}
section h2 .n { color: var(--accent); font-size: 0.95rem; font-weight: 700; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; }
section h3 { margin: 26px 0 8px; font-size: 1.25rem; line-height: 1.5; }
section p { margin: 0 0 16px; }
section p:last-child, section ul:last-child, section ol:last-child { margin-bottom: 0; }
section b, section strong { color: var(--ink); }
section ul, section ol { margin: 0 0 18px; padding-left: 1.5em; }
section li { margin-bottom: 9px; }
section li::marker { color: var(--accent); }

.cite {
  color: var(--accent-ink); font-size: 0.9rem; font-weight: 700;
  text-decoration: none; vertical-align: super; padding: 0 1px;
}
.cite:hover { text-decoration: underline; }

/* 流程：一串步驟，不是卡片 */
.flow {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin: 20px 0 4px; padding: 0; list-style: none;
}
.flow li {
  margin: 0; padding: 7px 15px;
  border: 1px solid var(--rule); border-radius: 2px;
  background: var(--paper-2); font-size: 0.95rem; color: var(--ink-2);
}
.flow li + li::before { content: "→"; color: var(--ink-3); margin-right: 8px; }

/* 線性 vs 非線性：上下對照，不畫框 */
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; max-width: 460px; margin: 0 0 14px; }
.grid i { display: block; aspect-ratio: 1; border: 1px solid var(--rule); background: var(--paper-2); }
.grid.warp i { background: var(--accent-soft); }
.grid.warp i:nth-child(3n) { transform: translateY(-3px) scale(1.06); }
.grid.warp i:nth-child(4n) { transform: translateY(3px) scale(.94); }
.grid.warp i:nth-child(5n) { transform: translateX(3px) scale(1.04); }

/* 重點／警告：左側細線，不做卡中卡 */
.key, .warn {
  margin: 20px 0; padding: 16px 20px;
  border-left: 4px solid var(--accent); background: var(--accent-soft);
  font-size: 1.05rem;
}
.warn { border-left-color: var(--warn); background: var(--warn-soft); }

/* 公式 */
.formula {
  margin: 20px 0; padding: 16px 20px;
  background: var(--paper-2); border-left: 4px solid var(--data);
  color: var(--data); font-weight: 700; font-size: 1.1rem;
  overflow-x: auto;
}
.pending { padding: 18px 20px; background: var(--paper-2); color: var(--ink-2); font-size: 1rem; }

/* 表格（寬表格由 ../shared/responsive-tables.js 處理行動版） */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 20px 0; }
table { width: 100%; min-width: 460px; border-collapse: collapse; font-size: 1rem; }
th, td { border: 1px solid var(--rule); padding: 12px 15px; text-align: left; vertical-align: top; }
th { background: var(--paper-2); font-weight: 700; font-size: 0.95rem; }
td.ok { color: var(--ok); font-weight: 700; }
td.no { color: var(--no); font-weight: 700; }

/* 參考文獻 */
.refs { margin: 0; padding: 0; list-style: none; counter-reset: r; }
.refs li {
  counter-increment: r; position: relative;
  padding: 14px 0 14px 46px; border-bottom: 1px solid var(--rule-2);
  font-size: 1rem; line-height: 1.7; scroll-margin-top: 96px;
}
.refs li:last-child { border-bottom: none; }
.refs li::before {
  content: "[" counter(r) "]"; position: absolute; left: 0; top: 14px;
  color: var(--accent); font-weight: 700; font-size: 0.95rem;
}
.refs a { color: var(--accent-ink); word-break: break-word; }
.refs .why { display: block; margin-top: 5px; color: var(--ink-3); font-size: 0.9rem; }
.refs li:target { background: var(--accent-soft); }

footer { margin-top: 56px; padding: 24px 0 0; border-top: 2px solid var(--rule); }
footer p { margin: 0; color: var(--ink-3); font-size: 0.95rem; }
footer .sig { margin-top: 6px; font-size: 0.9rem; }

.totop {
  position: fixed; right: 24px; bottom: 24px; z-index: 45;
  font: inherit; font-size: 0.95rem; font-weight: 700;
  color: var(--paper); background: var(--accent);
  border: none; border-radius: 2px; padding: 12px 20px;
  cursor: pointer; opacity: 0; visibility: hidden;
}
.totop:hover { background: var(--accent-ink); }
.totop.on { opacity: 1; visibility: visible; }
@media (prefers-reduced-motion: no-preference) { .totop { transition: opacity 180ms ease; } }

/* 窄螢幕：頁籤換行，不用抽屜 */
@media (max-width: 1024px) {
  #doc { padding: 34px 20px 88px; }
  .lede h1 { font-size: 2.1rem; }
  .lede-with-mascot { grid-template-columns: minmax(0, 1fr) 128px; gap: 12px; }
  .lede-mascot { width: 128px; height: 128px; }
  section h2 { font-size: 1.4rem; }
  .totop { right: 16px; bottom: 16px; }
}

@media (max-width: 720px) {
  .shell-topbar-inner { gap: 8px; }
  .shell-brand small { display: none; }
  .shell-page-nav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .toc ol { columns: 1; }
  .lede-with-mascot { display: block; }
  .lede-mascot { display: none; }
  .pager { flex-direction: column; gap: 10px; }
  .pager .next { margin-left: 0; text-align: left; }
}

@media (max-width: 560px) {
  .lede-body { font-size: 1.05rem; }
  .key, .warn, .formula { padding: 14px 16px; }
  .refs li { padding-left: 38px; }
}

@media print {
  .shell-topbar, .pager, .toc, .progress, .totop, .crumbs { display: none; }
  body { background: #fff; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ===== 方法（Methods）區塊 =====
   論文式逐步方法：步驟、參數列、依據等級標籤、圖解。
   規則依 docs/AI_AGENT_RULES.md：扁平閱讀、不做巢狀卡片；圖解為本區塊唯一的
   raster 素材（WebP），文字仍在 HTML。 */

.step { padding: 20px 0 6px; border-top: 1px solid var(--rule-2); }
.step + .step { margin-top: 6px; }
.step:first-of-type { border-top: 0; padding-top: 4px; }

/* 輸入 → 運算 → 輸出 一行讀完 */
.io { margin: 0 0 14px; padding: 12px 16px; background: var(--paper-2); font-size: 1rem; }
.io b { color: var(--data); }
.io span.sep { color: var(--ink-3); margin: 0 8px; }

/* 參數列：不是卡片，是一列一列的量測紀錄 */
.params { margin: 0 0 16px; padding: 0; list-style: none; }
.params li {
  padding: 9px 0; border-bottom: 1px dashed var(--rule-2);
  font-size: 1rem; line-height: 1.7;
}
.params li:last-child { border-bottom: 0; }
.params .pn { color: var(--ink); font-weight: 700; }
.params .pv { color: var(--ink-2); }

/* 依據等級 */
.lvl {
  display: inline-block; margin: 0 2px; padding: 1px 9px;
  border: 1px solid; border-radius: 2px;
  font-size: 0.9rem; font-weight: 700; line-height: 1.6; white-space: nowrap;
}
.lvl.std   { color: var(--lvl-std); background: var(--lvl-std-bg); border-color: var(--lvl-std-bd); }
.lvl.guide { color: var(--lvl-guide); background: var(--lvl-guide-bg); border-color: var(--lvl-guide-bd); }
.lvl.paper { color: var(--lvl-paper); background: var(--lvl-paper-bg); border-color: var(--lvl-paper-bd); }
.lvl.team  { color: var(--lvl-team); background: var(--lvl-team-bg); border-color: var(--lvl-team-bd); }
.lvl.ours  { color: var(--lvl-own); background: var(--lvl-own-bg); border-color: var(--lvl-own-bd); }
.lvl.none  { color: var(--lvl-none); background: var(--lvl-none-bg); border-color: var(--lvl-none-bd); border-style: dashed; }

/* 行內程式碼／檔名：最小字 0.95rem（19px），不低於 18px 門檻 */
code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
  font-size: 0.95rem; background: var(--paper-2);
  padding: 1px 4px; border-radius: 2px; word-break: break-all;
}

/* 數學式（MathML，非圖片） */
.math {
  margin: 20px 0; padding: 14px 20px;
  background: var(--paper-2); border-left: 4px solid var(--data);
  overflow-x: auto;
}
/* MathML 在 Chrome 會把子元素字級逐層乘 0.71（實測 mfrac→msub→mtext 只剩基準的 0.50 倍：
   基準 1.35rem 時下標僅 13.4px、1.15rem 時 11.4px，都低於全站最小字 18px）。
   因此直接把 MathML 內所有元素固定成 1.25rem（實測 20px），不讓 UA 逐層縮小。 */
.math math, .math math * { font-size: 1.25rem; color: var(--data); }

/* 下標／上標（既有公式用）：不得低於 18px 門檻 */
sub, sup { font-size: 0.9rem; line-height: 0; }

/* 圖解：寬度一律不超過閱讀欄 */
.fig { margin: 26px 0; }
.fig img {
  display: block; width: 100%; max-width: 100%; height: auto;
  border: 1px solid var(--rule); background: #fff;
}
.fig figcaption { margin-top: 10px; font-size: 0.95rem; color: var(--ink-2); line-height: 1.7; }
.fig figcaption b { color: var(--accent-ink); }
.figsrc { display: block; margin-top: 5px; color: var(--ink-3); font-size: 0.9rem; }

@media (max-width: 560px) {
  .io { padding: 10px 14px; }
  .math { padding: 12px 14px; }
}

/* ═══ 主站外殼（2026-09-29 整合：頂列導覽／麵包屑／配色對齊 nminfo/style.css） ═══
   對比依據（WCAG 2.1，於 #faf8f4 底上實算）：
   --brand-primary #264f4f 8.56:1、--accent-ink #154444 10.19:1、--ink-2 8.62:1、--ink-3 5.26:1 皆過 AA 文字；
   --nav-active-marker #c47a4a 3.18:1 僅用作左側標記線（非文字），與主站用法一致。 */
:root {
  --brand-primary: #264f4f;
  --brand-primary-strong: #1e4e4e;
  --brand-accent: #bd7a4e;
  --nav-active-marker: #c47a4a;
  --maxw-wide: 1180px;
}

.shell-topbar {
  position: sticky; top: 0; z-index: 80;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.shell-topbar-inner {
  max-width: var(--maxw-wide); margin: 0 auto;
  padding: 9px clamp(12px, 1.6vw, 26px);
  display: flex; align-items: center; gap: clamp(10px, 1.3vw, 22px); flex-wrap: wrap;
}
.shell-brand { display: flex; align-items: center; gap: 9px; text-decoration: none; flex: 0 0 auto; }
.shell-brand svg { width: 30px; height: 30px; color: var(--brand-primary); display: block; }
.shell-brand strong { display: block; font-size: 1.05rem; font-weight: 700; color: var(--brand-primary-strong); line-height: 1.2; }
.shell-brand small { display: block; font-size: 0.9rem; letter-spacing: 1.1px; color: var(--ink-3); line-height: 1.35; }
.shell-site-nav, .shell-page-nav { display: flex; align-items: center; gap: 1px; flex-wrap: wrap; }
.shell-site-nav a, .shell-page-nav a {
  padding: 9px 11px; font-size: 0.92rem; color: var(--ink-2); text-decoration: none;
  border-left: 3px solid transparent; min-height: 40px; display: inline-flex; align-items: center;
}
.shell-site-nav a:hover, .shell-page-nav a:hover { background: var(--nav-hover); border-left-color: var(--rule); }
.shell-page-nav { margin-left: auto; }
.shell-page-nav a[aria-current="page"] {
  border-left-color: var(--nav-active-marker); background: var(--paper);
  color: var(--brand-primary-strong); font-weight: 700;
}
.crumbs span { color: var(--ink-3); }
@media (max-width: 860px) {
  .shell-page-nav { margin-left: 0; width: 100%; }
}
