:root {
  --bg: #f3f6f7;
  --ink: #14283c;
  --muted: #5f6b7a;
  --line: #e0e6ea;
  --card: #ffffff;
  --z: #3f8268;        /* teal — primary accent (ASPEN-like) */
  --a: #0ea5e9;
  --y: #16a34a;
  --u: #ef4444;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --info: #2563eb;
  --shadow: 0 1px 3px rgba(20, 40, 60, .07), 0 6px 20px rgba(20, 40, 60, .05);
}
* { box-sizing: border-box; }
/* ---- Accessibility ---- */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 1000;
  background: var(--z); color: #fff; padding: .55rem 1rem; border-radius: 0 0 8px 0;
  font-weight: 700; text-decoration: none;
}
.skip-link:focus { left: 0; }
:focus-visible { outline: 2px solid var(--z); outline-offset: 2px; }
.tab:focus-visible, .home-card:focus-visible, .gloss-item:focus-visible, .toc-link:focus-visible,
.btn:focus-visible, select:focus-visible, input:focus-visible, .lang-toggle:focus-visible {
  outline: 2px solid var(--z); outline-offset: 2px; border-radius: 6px;
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.65;
}
h1 { font-size: 1.7rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.25rem; margin: 2rem 0 .8rem; }
h3 { margin: 0 0 .4rem; font-size: 1.05rem; }
p { margin: .5rem 0; }
b { color: #0b1020; }

/* topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: .7rem 1.5rem; box-shadow: var(--shadow);
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
}
.topbar .brand { order: 0; }
.lang-toggle {
  order: 2; margin-left: auto;
  border: 1.5px solid var(--z); background: var(--z); color: #fff;
  padding: .45rem 1rem; border-radius: 999px; cursor: pointer;
  font-size: .95rem; font-weight: 700; white-space: nowrap; transition: .15s;
  box-shadow: var(--shadow);
}
.lang-toggle::before { content: "🌐 "; }
.lang-toggle:hover { filter: brightness(1.08); }
.topbar .tabs { order: 3; flex-basis: 100%; }
.brand { font-weight: 800; font-size: 1.15rem; letter-spacing: .5px; display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.brand span { color: var(--z); }
.brand-logo { height: 40px; width: auto; display: block; flex: 0 0 auto; }
@media (max-width: 520px) { .brand-logo { height: 32px; } }
.tabs { display: flex; gap: .4rem; margin-top: .6rem; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  padding: .45rem .9rem; border-radius: 999px; cursor: pointer;
  font-size: .92rem; transition: .15s;
}
.tab:hover { border-color: var(--z); color: var(--z); }
.tab.active { background: var(--z); color: #fff; border-color: var(--z); }
.tabs .tab-group {
  align-self: center; font-weight: 800; font-size: .82rem; letter-spacing: .5px;
  color: var(--z); padding: 0 .15rem 0 .5rem; user-select: none;
}
.tabs .tab-group:first-child { padding-left: 0; }
.tab.tab-sep { margin-left: .5rem; border-style: dashed; }

/* method dropdown + sub-tabs (replaces the long 31-button row) */
.method-pick { display: flex; align-items: center; gap: .45rem; font-weight: 800;
  font-size: .82rem; letter-spacing: .5px; color: var(--z); }
.method-pick select {
  padding: .42rem .8rem; border: 1.5px solid var(--z); border-radius: 999px;
  font-size: .95rem; font-weight: 700; color: var(--z); background: var(--card); cursor: pointer;
  box-shadow: var(--shadow);
}
.subtabs { display: flex; gap: .4rem; flex-wrap: wrap; }
.tab.subtab { font-weight: 600; }

/* decision flowchart (choose tab) */
.flow { max-width: 760px; margin: 1rem auto 1.5rem; }
.flow-q {
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--z);
  border-radius: 12px; padding: .8rem 1rem; box-shadow: var(--shadow);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem;
  font-size: .95rem;
}
.flow-q .flow-yes {
  background: var(--z); color: #fff; border-radius: 999px; padding: .3rem .8rem;
  font-weight: 700; white-space: nowrap; font-size: .9rem;
}
.flow-no { text-align: center; color: var(--muted); font-size: .85rem; font-weight: 700; margin: .35rem 0; }
.flow-end {
  background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412;
  border-radius: 12px; padding: .7rem 1rem; font-size: .92rem; margin-top: .35rem;
}
/* richer anchor-based design tree */
.flow-head { font-weight: 800; color: var(--z); margin: 1rem 0 .4rem; font-size: 1rem;
  border-bottom: 2px solid var(--z); padding-bottom: .25rem; }
.flow-branch { margin-left: .2rem; border-left: 3px dashed var(--line); padding-left: .8rem; }
.flow-yes.ext { background: var(--card); color: var(--muted); border: 1px solid var(--line); }
.flow-yes.tte { box-shadow: 0 0 0 2px #bfdbfe; }
.flow-legend { display: flex; flex-wrap: wrap; gap: .6rem 1.2rem; font-size: .85rem;
  color: var(--muted); margin: .4rem 0 1rem; }
.flow-legend b { color: var(--ink); }

/* interactive, clickable decision tree */
/* adjacent-approaches gateway cards on the choose page */
.adj-grid { margin-top: .4rem; }
.adj-card { border-left: 4px solid #8b5cf6; }
.adj-card h3 { margin: .1rem 0 .3rem; font-size: 1rem; }
.adj-card p { font-size: .9rem; line-height: 1.65; margin: 0 0 .6rem; }
.adj-goto { display: inline-block; font-weight: 600; font-size: .88rem; text-decoration: none;
  color: #6d28d9; cursor: pointer; }
.adj-goto:hover { text-decoration: underline; }
/* causal-inference workflow flowchart (#flow) */
.flowchart { max-width: 820px; margin: 1.2rem auto; }
.flow-stage { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--teal, #1d6f57);
  border-radius: 10px; padding: .85rem 1.1rem; box-shadow: 0 1px 3px rgba(15,40,60,.05); }
.flow-stage.flow-end { border-left-color: #b45309; background: #fffdf6; }
.flow-head { display: flex; align-items: baseline; gap: .6rem; flex-wrap: wrap; }
.flow-head h3 { margin: .1rem 0; font-size: 1.05rem; }
.flow-no { flex: none; min-width: 2.2rem; text-align: center; font-weight: 800; font-size: .9rem;
  color: #fff; background: var(--teal, #1d6f57); border-radius: 999px; padding: .1rem .5rem; }
.flow-end .flow-no { background: #b45309; }
.flow-stage > p { margin: .4rem 0 .6rem; font-size: .92rem; line-height: 1.7; }
.flow-arrow { text-align: center; color: #94a3b8; font-size: 1.4rem; line-height: 1; margin: .25rem 0; }
.flow-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { display: inline-block; padding: .28rem .7rem; font-size: .85rem; font-weight: 600; text-decoration: none;
  color: #334155; background: #eef4fb; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; }
.chip:hover { background: var(--teal, #1d6f57); color: #fff; border-color: var(--teal, #1d6f57); }
.chip:focus-visible { outline: 2px solid var(--ink, #0f172a); outline-offset: 2px; }
.chip.chip-adj { background: #f5f3ff; border-style: dashed; }   /* demoted → choose page */
.chip.chip-go { background: var(--teal, #1d6f57); color: #fff; border-color: var(--teal, #1d6f57); }
.dtree { max-width: 760px; margin: 1rem auto 1.5rem; }
.dtree-path { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .8rem; min-height: 1.6rem; }
.dtree-crumb { background: #f1f5f9; color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: .2rem .7rem; font-size: .8rem; }
.dtree-crumb.start { background: var(--z); color: #fff; border-color: var(--z); }
.dtree-stage { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--z);
  border-radius: 14px; padding: 1.1rem 1.2rem; box-shadow: var(--shadow); }
.dtree-step { font-size: .78rem; font-weight: 800; letter-spacing: .04em; color: var(--z);
  text-transform: uppercase; margin-bottom: .35rem; }
.dtree-q { font-size: 1.08rem; font-weight: 700; line-height: 1.55; margin-bottom: 1rem; }
.dtree-opts { display: flex; flex-direction: column; gap: .55rem; }
.dtree-opt { text-align: left; background: #f8fafc; border: 1.5px solid var(--line);
  border-radius: 10px; padding: .7rem .9rem; cursor: pointer; font-size: .95rem; line-height: 1.5;
  color: var(--ink); transition: .15s; }
.dtree-opt:hover { border-color: var(--z); background: #ecfeff; transform: translateX(2px); }
.dtree-opt .arrow { float: right; color: var(--z); font-weight: 800; margin-left: .6rem; }
/* recommendation leaf */
.dtree-rec { border-radius: 14px; padding: 1.2rem 1.3rem; border: 2px solid; }
.dtree-rec.toolbox { background: #ecfdf5; border-color: #34d399; }
.dtree-rec.external { background: #fff7ed; border-color: #fdba74; }
.dtree-rec.fallback { background: #eff6ff; border-color: #93c5fd; }
.dtree-rec .rec-tag { display: inline-block; font-size: .78rem; font-weight: 800; letter-spacing: .04em;
  text-transform: uppercase; margin-bottom: .4rem; color: var(--muted); }
.dtree-rec h3 { margin: 0 0 .6rem; font-size: 1.35rem; }
.dtree-rec.toolbox h3 { color: #047857; }
.dtree-rec.external h3 { color: #9a3412; }
.dtree-rec.fallback h3 { color: #1d4ed8; }
.dtree-rec p { margin: .45rem 0; line-height: 1.7; }
.dtree-rec .rec-scenario { background: rgba(255,255,255,.55); border-left: 3px solid currentColor;
  border-radius: 8px; padding: .55rem .8rem; font-size: .92rem; line-height: 1.65; margin-top: .6rem; }
.dtree-rec.toolbox .rec-scenario { color: #047857; }
.dtree-rec.external .rec-scenario { color: #9a3412; }
.dtree-rec.fallback .rec-scenario { color: #1d4ed8; }
.dtree-rec .rec-scenario { color: var(--ink); }
.dtree-rec .rec-watch { background: rgba(255,255,255,.65); border-radius: 10px; padding: .6rem .8rem;
  font-size: .9rem; margin-top: .7rem; }
.dtree-rec .rec-watch b { color: var(--ink); }
.rec-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: .9rem; }
.dtree-goto { background: var(--z); color: #fff; border: none; border-radius: 999px;
  padding: .55rem 1.2rem; font-weight: 700; font-size: .95rem; cursor: pointer; box-shadow: var(--shadow); }
.dtree-goto:hover { filter: brightness(1.06); }
.dtree-showmap { background: var(--card); color: var(--ink); border: 1.5px solid var(--line); border-radius: 999px;
  padding: .55rem 1.1rem; font-weight: 700; font-size: .95rem; cursor: pointer; }
.dtree-showmap:hover { border-color: var(--z); color: var(--z); }
.dtree-controls { display: flex; gap: .6rem; margin-top: .9rem; }
.dtree-controls .btn:disabled { opacity: .4; cursor: not-allowed; }

/* --- database chooser: reuses .dtree/.dtree-map; these are the extra bits --- */
.db-designs { margin-top: .7rem; font-size: .92rem; }
.db-chips { display: inline-flex; flex-wrap: wrap; gap: .4rem; margin-left: .3rem; vertical-align: middle; }
.db-chip { background: var(--z); color: #fff; border: none; border-radius: 999px;
  padding: .2rem .7rem; font-size: .82rem; font-weight: 700; cursor: pointer; }
.db-chip:hover { filter: brightness(1.08); }
table.db-summary td, table.db-summary th { font-size: .84rem; vertical-align: top; }
table.db-summary tr.db-row-hit td { background: #ecfdf5; box-shadow: inset 3px 0 0 #16a34a; }
/* --- align time zero (tab 3, interactive timeline) --- */
.align-lead { background: #f0f7f4; border: 1px solid #cfe3da; border-radius: 12px; padding: .8rem 1rem;
  font-size: .92rem; line-height: 1.75; margin: 0 0 1rem; }
.align-picks { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0 0 1rem; }
.align-pick { border: 1.5px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px;
  padding: .45rem 1rem; font-size: .9rem; font-weight: 700; cursor: pointer; }
.align-pick:hover { border-color: var(--z); color: var(--z); }
.align-pick.active { background: var(--z); color: #fff; border-color: var(--z); }
.align-viz { border: 1px solid var(--line); border-radius: 12px; padding: .7rem 1rem; background: var(--card); }
.align-title { margin: 0 0 .4rem; font-size: .95rem; color: var(--ink); }
.align-svg { width: 100%; height: auto; display: block; }
.align-legend { display: flex; flex-wrap: wrap; gap: .5rem 1rem; margin: .7rem 0; font-size: .82rem; color: var(--muted); }
.align-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.align-legend .sw { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.align-legend .sw-cen { background: repeating-linear-gradient(45deg, #fff7ed, #fff7ed 2px, #f59e0b 2px, #f59e0b 4px); }
.align-legend .sw-ex0 { background: repeating-linear-gradient(45deg, #f1f5f9, #f1f5f9 2px, #cbd5e1 2px, #cbd5e1 4px); }
.align-note { border-radius: 12px; padding: .7rem 1rem; font-size: .9rem; line-height: 1.75; margin: .8rem 0; }
.align-note.bad { background: #f4f6f8; border: 1px solid #cbd5e1; }
.align-note.good { background: #ecfdf5; border: 1px solid #86efac; }
.align-zero { background: rgba(47,111,87,.06); border-radius: 8px; padding: .5rem .7rem; font-size: .9rem; line-height: 1.7; }
.align-pc { display: flex; flex-direction: column; gap: .25rem; margin: .5rem 0; font-size: .86rem; }
.align-pro { color: #047857; } .align-con { color: #5f6b7a; }
/* appraisal narrative (tab Appraisal) */
.apr-intro { background: #f0f7f4; border: 1px solid #cfe3da; border-radius: 12px; padding: .8rem 1rem; margin: 0 0 1rem; }
.apr-intro p { margin: .4rem 0; font-size: .92rem; line-height: 1.8; }
/* speech line: a name badge instead of italics (Chinese italics look bad and
   emoji glyphs are not reliably available on every OS) */
.apr-say { background: #fff; border-left: 3px solid #3f8268; border-radius: 8px;
  padding: .55rem .8rem; color: #312e81; }
.apr-who { display: inline-block; background: #3f8268; color: #fff; border-radius: 999px;
  padding: .08rem .6rem; font-size: .76rem; font-weight: 700; margin-right: .5rem;
  vertical-align: .08em; white-space: nowrap; }
.apr-who.rev { background: #1f4f3f; }
.apr-stepno { display: inline-block; background: #dff0e8; color: #255c47; border-radius: 999px;
  padding: .1rem .6rem; font-size: .74rem; font-weight: 800; margin: 0 .5rem .4rem 0; }
.apr-result { display: flex; flex-wrap: wrap; align-items: baseline; gap: .6rem; border-radius: 12px; padding: .7rem 1rem; margin: 0 0 .9rem; }
.apr-result.bad { background: #f4f6f8; border: 1px solid #cbd5e1; }
.apr-result.good { background: #ecfdf5; border: 1px solid #86efac; }
.apr-hr { font-size: 1.15rem; font-weight: 800; }
.apr-result.bad .apr-hr { color: #475569; } .apr-result.good .apr-hr { color: #047857; }
.apr-hr-say { font-size: .88rem; line-height: 1.6; color: #334155; }
.apr-check { margin-top: 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.apr-check summary { cursor: pointer; padding: .6rem .9rem; font-weight: 700; font-size: .92rem; }
.apr-check ul { margin: 0; padding: 0 1.2rem 1rem 2rem; }
.apr-check li { font-size: .88rem; line-height: 1.7; margin: .35rem 0; }
.apr-ask { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; margin: 0 0 1rem; }
.apr-ask p { margin: 0 0 .6rem; font-size: .95rem; }
.apr-choices { display: flex; flex-wrap: wrap; gap: .6rem; }
.apr-choice { border: 1.5px solid var(--z); background: var(--card); color: var(--z); border-radius: 999px;
  padding: .5rem 1.2rem; font-size: .92rem; font-weight: 700; cursor: pointer; }
.apr-choice:hover { background: var(--z); color: #fff; }
/* the global `b { color }` otherwise splits each option into two colours */
.apr-choice b { color: inherit; }
.apr-react { border-radius: 12px; padding: .7rem 1rem; margin: 0 0 .9rem; font-size: .92rem; line-height: 1.75; }
.apr-react.good { background: #ecfdf5; border: 1px solid #86efac; }
.apr-react.warn { background: #f4f6f8; border: 1px solid #cbd5e1; }
.apr-prompt { font-size: .95rem; margin: 0 0 .7rem; }
.apr-reset { margin-top: 1rem; border: 1px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 999px; padding: .4rem 1rem; font-size: .86rem; font-weight: 700; cursor: pointer; }
.apr-reset:hover { border-color: var(--z); color: var(--z); }
.fc-nohit { margin: -.3rem 0 .8rem; font-size: .86rem; color: var(--muted); text-align: center; }
.db-notes-title { margin: 1.6rem 0 .3rem; font-size: 1rem; }
.db-notes-lead { margin: 0 0 .7rem; font-size: .88rem; color: var(--muted); line-height: 1.7; }
.db-note { border: 1px solid var(--line); border-radius: 10px; background: var(--card); margin-bottom: .6rem; }
.db-note > summary { cursor: pointer; padding: .55rem .9rem; font-weight: 700; font-size: .92rem; }
.db-note > p { margin: 0 .9rem .6rem; font-size: .88rem; line-height: 1.8; }
.db-note-hit { border-color: var(--z); box-shadow: 0 0 0 2px rgba(99, 102, 241, .18); }
.db-refs { margin-top: .8rem !important; }
.db-refs-list { margin: 0 .9rem .8rem; padding-left: 1.3rem; }
.db-refs-list li { font-size: .84rem; line-height: 1.7; margin: .3rem 0; }
.db-refs-list a { color: var(--z); }
.apr-next { display: block; margin: 1rem 0 0; border: 0; background: var(--z); color: #fff;
  border-radius: 999px; padding: .5rem 1.2rem; font-size: .9rem; font-weight: 800; cursor: pointer; }
.apr-next:hover { filter: brightness(1.12); }
.apr-hintline { margin: .9rem 0 0; font-size: .84rem; color: var(--muted); }
.apr-done { margin-top: 1rem; border: 1px solid #a7f3d0; background: #ecfdf5; border-radius: 10px;
  padding: .7rem .9rem; font-size: .9rem; line-height: 1.75; color: #064e3b; }

/* --- spot the bias game (tab 4) --- */
.bias-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: .9rem; }
.bias-card { border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem; background: var(--card); }
.bias-q { font-size: .95rem; line-height: 1.7; }
.bias-n { display: inline-flex; align-items: center; justify-content: center; width: 1.5rem; height: 1.5rem;
  border-radius: 999px; background: var(--z); color: #fff; font-weight: 800; font-size: .82rem; margin-right: .5rem; }
.bias-opts { display: flex; flex-direction: column; gap: .35rem; margin: .7rem 0; }
.bias-opt { display: flex; align-items: center; gap: .45rem; font-size: .9rem; padding: .3rem .5rem;
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.bias-opt.bias-good { background: #ecfdf5; border-color: #34d399; color: #047857; font-weight: 700; }
.bias-opt.bias-bad { background: #fef2f2; border-color: #fca5a5; color: #b91c1c; }
.bias-opt.bias-miss { background: #fffbeb; border-color: #fcd34d; color: #92400e; }
.bias-check { background: var(--z); color: #fff; border: none; border-radius: 999px; padding: .45rem 1.1rem;
  font-weight: 700; font-size: .9rem; cursor: pointer; }
.bias-check:hover { filter: brightness(1.08); }
.bias-feedback { margin-top: .7rem; border-top: 1px dashed var(--line); padding-top: .6rem; font-size: .88rem; line-height: 1.7; }
.bias-feedback p { margin: .35rem 0; }
.bias-verdict { font-weight: 800; margin-bottom: .3rem; }
.bias-verdict.ok { color: #047857; } .bias-verdict.no { color: #b45309; }
.bias-fix { background: rgba(47,111,87,.06); border-radius: 8px; padding: .45rem .65rem; }

/* the full decision-tree map that pops out at a leaf */
.dtree-map { max-width: 100%; margin: 1rem auto 0; background: #f8fafc; border: 1px solid var(--line);
  border-radius: 14px; padding: 1rem 1.1rem; }
.dtree-map .map-title { margin: 0 0 .7rem; font-size: 1.05rem; }
.dtree-map .flow-head { margin: .9rem 0 .4rem; font-size: .98rem; }
.dtree-map .map-sub { font-weight: 700; color: var(--muted); font-size: .85rem; margin: .5rem 0 .3rem; }
.dtree-map .flow-branch { border-left: 3px dashed var(--line); padding-left: .8rem; margin-left: .2rem; }
.map-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .7rem; margin: .35rem 0;
  font-size: .9rem; }
.map-row .map-cond { flex: 1 1 60%; }
.flow-leaf { white-space: nowrap; border-radius: 999px; padding: .25rem .7rem; font-weight: 700; font-size: .85rem; }
.flow-leaf.tb { background: var(--z); color: #fff; }
.flow-leaf.ex { background: var(--card); color: var(--muted); border: 1px solid var(--line); }
.map-row.flow-hit { border-color: #34d399; background: #ecfdf5; box-shadow: 0 0 0 2px #6ee7b7; }
.map-row.flow-hit .flow-leaf.ex { border-color: #34d399; color: #047857; }
.dtree-map .flow-end.flow-hit { box-shadow: 0 0 0 2px #93c5fd; }

/* ---- the full tree drawn as a top-down flowchart ---- */
.fc-toolbar { display: flex; justify-content: flex-end; margin: 0 0 .5rem; }
.fc-toolbar .fc-dl { font-size: .85rem; }
@media print { .fc-toolbar { display: none; } }
.fc-title { text-align: center; margin: 0 0 1rem; font-size: 1.05rem; }
.fc { display: flex; flex-direction: column; align-items: center; }
.fc-start { background: #0f172a; color: #fff; font-weight: 800; border-radius: 999px;
  padding: .5rem 1.3rem; font-size: 1rem; letter-spacing: .5px; }
/* A/B/C/D are PARALLEL anchor families, so lay them out as four columns in one
   horizontal row (scroll sideways on narrow screens) rather than a 2x2 wrap. */
/* The whole chart is scaled to fit by _fitFlowchart(), so the lanes must NOT
   scroll on their own - the point is to see the entire tree at once. */
.fc-lanes { display: flex; gap: 1rem; align-items: flex-start; justify-content: center;
  width: 100%; flex-wrap: nowrap; overflow: visible; padding-bottom: 6px; }
/* Keep lanes compact: the map is auto-scaled to fit, so a generous max-width
   just forces a harsher scale-down and unreadable text when projected. */
.fc-lane { flex: 1 1 0; min-width: 208px; max-width: 310px; display: flex; flex-direction: column; align-items: stretch; }
/* plain vertical connector (a branch line, no arrowhead), optional branch label */
.fc-link { width: 2px; min-height: 22px; background: #94a3b8; margin: 3px auto; position: relative; }
.fc-elabel { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); white-space: nowrap;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px;
  font-size: .72rem; color: var(--muted); line-height: 1.6; }
.fc-head { border-radius: 12px; padding: .55rem .8rem; font-weight: 800; color: #fff; text-align: center; }
.fc-head small { display: block; font-weight: 500; font-size: .76rem; opacity: .92; margin-top: 2px; }
.fc-head.a { background: var(--z); }
.fc-head.b { background: #7c3aed; }
.fc-head.c { background: #b45309; }
.fc-head.d { background: #0e7490; }
a.xref { color: var(--z); cursor: pointer; text-decoration: none; font-weight: 600;
  border-bottom: 1px dotted rgba(63, 125, 98, .55); }
a.xref:hover { color: #2c5b47; border-bottom-style: solid; }
.fc-q { background: var(--card); border: 2px solid #94a3b8; border-radius: 12px; padding: .55rem .8rem;
  font-weight: 700; text-align: center; box-shadow: var(--shadow); }
.fc-q::before { content: "◇ "; color: #94a3b8; }
/* leaves under a question fan out as tree branches: a vertical spine on the left
   with a horizontal elbow into each leaf (org-chart / file-tree look) */
.fc-leaves { display: flex; flex-direction: column; gap: .5rem; position: relative; padding-left: 22px; }
.fc-leaves::before { content: ""; position: absolute; left: 8px; top: -10px; bottom: 18px; width: 2px; background: #94a3b8; }
.fc-leaves .fc-leaf { position: relative; }
.fc-leaves .fc-leaf::before { content: ""; position: absolute; left: -14px; top: 50%; width: 14px; height: 2px; background: #94a3b8; }
.fc-leaf { display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  background: var(--card); border: 1px solid var(--line); border-left-width: 5px; border-radius: 10px;
  padding: .5rem .7rem; font-size: .88rem; }
.fc-leaf.tb { border-left-color: var(--z); }
.fc-leaf.ex { border-left-color: #c3cedb; }
.fc-cond { color: var(--ink); flex: 1 1 auto; min-width: 0; }   /* min-width:0 lets the text wrap beside the badge instead of under it */
.fc-badge { white-space: nowrap; flex: 0 0 auto; border-radius: 999px; padding: .22rem .65rem; font-weight: 700; font-size: .82rem; }
.fc-badge.tb { background: var(--z); color: #fff; }
.fc-badge.ex { background: #eef2f6; color: var(--muted); border: 1px solid var(--line); }
/* Only the endpoint you actually reached should stand out: everything else is
   dimmed, and the hit gets a pulsing green glow (all the ✓ badges are green, so
   a static ring alone was invisible). */
.fc.has-hit .fc-leaf:not(.fc-hit) { opacity: .38; filter: grayscale(.7); }
.fc.has-hit .fc-q, .fc.has-hit .fc-head, .fc.has-hit .fc-elabel { opacity: .72; }
.fc-leaf.fc-hit { background: #ecfdf5; border-color: #16a34a; border-left-color: #16a34a;
  position: relative; z-index: 1; transform: scale(1.03); animation: fcPulse 1.5s ease-in-out infinite; }
.fc-leaf.fc-hit .fc-badge.tb { background: #16a34a; }
@keyframes fcPulse {
  0%, 100% { box-shadow: 0 0 0 3px #6ee7b7, 0 0 10px 2px rgba(22,163,74,.45); }
  50%      { box-shadow: 0 0 0 6px #a7f3d0, 0 0 20px 6px rgba(22,163,74,.65); }
}
@media (prefers-reduced-motion: reduce) {
  .fc-leaf.fc-hit { animation: none; box-shadow: 0 0 0 4px #6ee7b7; }
}
.fc-end { background: #eff6ff; border: 2px solid #93c5fd; border-radius: 12px; padding: .7rem 1rem;
  text-align: center; color: #1e3a8a; font-size: .9rem; max-width: 680px; line-height: 1.6; }
.fc-end.fc-hit { box-shadow: 0 0 0 3px #93c5fd; }
/* the "already have an RCT" branch at the bottom of the flowchart */
.fc-rct { width: 100%; max-width: 560px; display: flex; flex-direction: column; align-items: stretch; }
.fc-note { background: #eff6ff; border: 1px dashed #93c5fd; border-radius: 10px; padding: .5rem .8rem;
  font-size: .82rem; color: #1e3a8a; text-align: center; line-height: 1.6; }

main { max-width: 1280px; margin: 0 auto; padding: 1.5rem 2rem; }
.panel { display: none; animation: fade .25s; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

.banner {
  background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412;
  border-radius: 10px; padding: .6rem .9rem; font-size: .92rem; margin-bottom: 1rem;
}
.lead { font-size: 1.08rem; color: #2b3247; }
.caption { color: var(--muted); font-size: .9rem; }
.muted { color: var(--muted); }

/* cards */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 1rem 1.2rem; box-shadow: var(--shadow); margin: 1rem 0;
}
.card.warn { border-left: 4px solid var(--amber); }
.card.info { border-left: 4px solid var(--info); }
.card.scene { border-left: 4px solid var(--teal, #3f8268); background: linear-gradient(180deg, rgba(63,130,104,0.045), transparent 60%); }
.card.scene h3 { color: var(--teal, #3f8268); }
/* scene mini-charts sit flush on the tinted card (no inner white box, shorter,
   so the data fills the frame instead of floating in a big empty grid) */
.card.scene .chart { height: 280px; background: transparent; border: none; box-shadow: none; margin: .5rem 0 0; }
/* ⑥ DAG ↔ SWIG side by side, each filling its half; the long note sits below each
   diagram as readable text (.diagnote) instead of being squeezed inside the chart */
.whatif-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.whatif-col { min-width: 0; }
.diagnote { margin: .4rem 0 .2rem; line-height: 1.6; }
@media (max-width: 760px) { .whatif-pair { grid-template-columns: 1fr; } }
/* ③ data preview — a real data-row table at the top of the analyse panel */
.data-preview { margin: .4rem 0 1.2rem; }
.data-preview .dp-title { font-size: 1rem; margin: .2rem 0 .5rem; }
.dp-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.dp-table { border-collapse: collapse; width: 100%; font-size: .85rem; white-space: nowrap; }
.dp-table th, .dp-table td { padding: .35rem .6rem; text-align: right; border-bottom: 1px solid var(--line); }
.dp-table th { background: #f3f6fb; color: #334155; font-weight: 600; position: sticky; top: 0; }
.dp-table tbody tr:nth-child(even) { background: #fafcff; }
.dp-table td:first-child, .dp-table th:first-child { text-align: left; color: var(--muted); }
/* ③ download the built-in sample dataset as CSV */
.dl-csv { margin-top: .6rem; padding: .45rem .9rem; font-size: .88rem; font-weight: 600;
  color: #fff; background: var(--teal, #1d6f57); border: none; border-radius: 8px; cursor: pointer; }
.dl-csv:hover { filter: brightness(1.08); }
.dl-csv:focus-visible { outline: 2px solid var(--ink, #0f172a); outline-offset: 2px; }
/* provenance line under each ③ code header — cite the package/method so the code is trustworthy */
.code-src { font-size: .82rem; line-height: 1.6; color: var(--muted); background: #f7f9fd;
  border-left: 3px solid var(--teal, #1d6f57); border-radius: 0 6px 6px 0; padding: .5rem .75rem; margin: .2rem 0 .9rem; }
.code-src code { font-size: .8em; }
/* code-language switcher (SAS / R / Stata) above each ③ code section */
.clang-switch { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem;
  margin: .8rem 0 .9rem; }
.clang-label { font-size: .9rem; color: var(--muted); margin-right: .2rem; }
.clang-btn { padding: .32rem .9rem; font-size: .9rem; font-weight: 600; font-family: inherit;
  color: #334155; background: #f3f6fb; border: 1px solid var(--line); border-radius: 999px; cursor: pointer; }
.clang-btn:hover { background: #e7eef9; }
.clang-btn[aria-pressed="true"] { color: #fff; background: var(--teal, #1d6f57); border-color: var(--teal, #1d6f57); }
.clang-btn:focus-visible { outline: 2px solid var(--ink, #0f172a); outline-offset: 2px; }
/* ④ E-value sensitivity card */
.evalue-card { margin-top: 1.2rem; }
.evalue-card h4 { margin: .8rem 0 .3rem; }
.ev-inputs, .ev-sliders { display: flex; flex-wrap: wrap; gap: 1rem 1.6rem; margin: .5rem 0; }
.ev-inputs label, .ev-sliders label { display: flex; align-items: center; gap: .5rem; font-size: .92rem; }
.ev-inputs input[type="number"] { width: 5rem; padding: .25rem .4rem; border: 1px solid var(--line); border-radius: 6px; }
.ev-sliders input[type="range"] { width: 11rem; vertical-align: middle; }
.ev-sliders b { min-width: 2.2rem; }
.ev-out, .ev-verdict { background: #f7f9fd; border: 1px solid var(--line); border-radius: 8px; padding: .55rem .75rem; line-height: 1.7; margin: .5rem 0; }
/* divider between the analysis and the merged SAS/R code section */
.merge-sep { border: none; border-top: 2px dashed var(--line); margin: 2rem 0 1rem; }
.merge-sas { margin-top: .3rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.cards .card { margin: 0; }
/* fixed 3-up grid for card sets that otherwise leave an ugly orphan row (e.g. 6 cards → 3+3) */
.cards-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .cards-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .cards-3 { grid-template-columns: 1fr; } }

/* DAG diagram */
.dag {
  margin: 1.5rem 0 .5rem; padding: 1.2rem 1rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.dag-svg { width: 100%; max-width: 640px; height: auto; display: block; margin: 0 auto; }
.dag-svg .dn { fill: #fff; font-weight: 700; font-size: 15px; text-anchor: middle; }
.dag-svg .ds { fill: #fff; opacity: .92; font-weight: 500; font-size: 11px; text-anchor: middle; }

/* interactive */
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin: 1rem 0 1.5rem; }
.controls label { display: block; font-weight: 600; }
.controls input[type=range] { width: 100%; margin: .5rem 0 0; accent-color: var(--z); }
.controls small { display: block; color: var(--muted); font-weight: 400; }
.ccw-scen { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.scen-select { font: inherit; font-weight: 600; padding: .4rem .6rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink, #14283c); cursor: pointer; }
.scen-select:focus { outline: 2px solid var(--z); }
.play-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }
.rdd-twocol { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1rem 0; }
.table-wrap { overflow-x: auto; margin: 1rem 0 1.5rem; }
table.cmp { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
table.cmp th, table.cmp td { padding: .7rem .9rem; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--line); font-size: .92rem; }
table.cmp thead th { background: var(--ink, #14283c); color: #fff; font-weight: 600; }
table.cmp tbody td:first-child { font-weight: 600; color: var(--muted); white-space: nowrap; }
table.cmp tbody tr:last-child td { border-bottom: none; }
table.cmp tbody tr:nth-child(even) { background: #f8fafc; }
/* design-family sub-header row inside comparison tables */
table.cmp td.famhdr, table.cmp tbody tr td.famhdr {
  background: #e7efeb; color: var(--z, #3f7d62); font-weight: 700; white-space: normal;
  border-top: 2px solid var(--z, #3f7d62); font-size: .9em; letter-spacing: .01em;
}
/* design-family sub-heading above grouped decision cards */
h4.fam-sub { margin: 1.2rem 0 .5rem; color: var(--z, #3f7d62); font-size: 1rem;
  border-left: 4px solid var(--z, #3f7d62); padding-left: .55rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1rem; text-align: center; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-num { font-size: 2rem; font-weight: 800; margin: .2rem 0; }
.stat-num.small { font-size: 1.2rem; }
.stat-foot { color: var(--muted); font-size: .8rem; }
.bv-readout { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin: .9rem 0 .3rem; }
.bv-item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .7rem 1rem; box-shadow: var(--shadow); display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; }
.bv-k { color: var(--muted); font-size: .85rem; }
.bv-v { font-size: 1.4rem; font-weight: 800; color: var(--z); white-space: nowrap; }
@media (max-width: 720px) { .bv-readout { grid-template-columns: 1fr; } }
.chart { width: 100%; height: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }

/* analysis */
.datasource { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin: 1rem 0; }
.or { color: var(--muted); }
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: .55rem 1.1rem; border-radius: 10px; cursor: pointer; font-size: .95rem; font-weight: 600;
}
.btn:hover { border-color: var(--z); }
.btn.primary { background: var(--z); color: #fff; border-color: var(--z); }
.btn.primary:hover { filter: brightness(1.07); }
.colmap {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; align-items: end;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1.2rem; box-shadow: var(--shadow); margin: 1rem 0;
}
.field { display: flex; flex-direction: column; gap: .3rem; }
.field.wide { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: .9rem; }
select { padding: .45rem; border: 1px solid var(--line); border-radius: 8px; font-size: .92rem; background: var(--card); }
#runAnalyze { grid-column: 1 / -1; }

.result-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin-top: 1rem; }
.rc { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1rem 1.2rem; box-shadow: var(--shadow); }
.rc .big { font-size: 1.6rem; font-weight: 800; }
.rc.highlight { border: 2px solid var(--z); }
.rc p { font-size: .88rem; color: #404a60; margin: .4rem 0 0; }

/* assumptions */
.overall { padding: 1rem 1.2rem; border-radius: 14px; font-weight: 700; margin: 1rem 0; box-shadow: var(--shadow); }
.assume-cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); align-items: start; }
.acard { background: var(--card); border: 1px solid var(--line); border-left-width: 6px; border-radius: 14px; padding: 1rem 1.2rem; box-shadow: var(--shadow); }
.acard h3 { display: flex; align-items: center; gap: .5rem; }
.badge { font-size: .72rem; padding: .15rem .5rem; border-radius: 999px; color: #fff; font-weight: 700; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.st-green { border-left-color: var(--green); } .bg-green { background: var(--green); }
.st-amber { border-left-color: var(--amber); } .bg-amber { background: var(--amber); }
.st-red   { border-left-color: var(--red); }   .bg-red   { background: var(--red); }
.st-info  { border-left-color: var(--info); }  .bg-info  { background: var(--info); }
/* status badges: soft tinted pills (calmer than solid saturated chips); the
   dots keep the solid .bg-* colour, so only the .badge.bg-* pairing is restyled */
.badge.bg-green { background: #e7f6ee; color: #0f7a45; border: 1px solid #bce8d0; }
.badge.bg-amber { background: #fdf1de; color: #97610e; border: 1px solid #f2d6a3; }
.badge.bg-red   { background: #fdeaea; color: #c0322b; border: 1px solid #f2c0bc; }
.badge.bg-info  { background: #eef2f7; color: #44607f; border: 1px solid #cfdbe9; }
.metrics { list-style: none; padding: 0; margin: .6rem 0 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: .4rem; }
.metrics li { background: #f7f9fd; border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; font-size: .85rem; }
.metrics b { display: block; font-size: 1.05rem; }
.metrics span { color: var(--muted); font-size: .76rem; }
.acard .headline { font-size: 1.05rem; margin: .2rem 0 .5rem; }
.acard .plain { font-size: .96rem; color: #2b3849; line-height: 1.75; margin: .3rem 0 .2rem; }
.term { margin-top: .8rem; border-top: 1px dashed var(--line); padding-top: .5rem; }
.term summary {
  cursor: pointer; color: var(--z); font-size: .85rem; font-weight: 600;
  list-style: none; user-select: none;
}
.term summary::before { content: "▸ "; }
.term[open] summary::before { content: "▾ "; }
.term p { font-size: .85rem; color: var(--muted); margin: .5rem 0 0; line-height: 1.7; }
.tdef { margin: .7rem 0 0; padding: .7rem .85rem; background: #f8fafb; border: 1px solid var(--line); border-left: 3px solid var(--z); border-radius: 10px; }
.tdef + .tdef { margin-top: .6rem; }
.tdef h4 { margin: 0 0 .35rem; font-size: .92rem; color: var(--ink, #14283c); font-weight: 700; }
.tdef h4 .en { color: var(--muted); font-weight: 500; font-size: .82rem; }
.tdef p { font-size: .85rem; color: #334155; margin: 0; line-height: 1.75; }
.tdef p b { color: var(--z); font-weight: 700; }
.tdef code { background: #eef4f2; border: 1px solid var(--line); border-radius: 5px; padding: .05rem .35rem; font-size: .82rem; color: #14283c; white-space: nowrap; }
.tdef .tform { margin-top: .3rem; }
.tdef-list { margin: 0; padding-left: 1.15rem; }
.tdef-list li { font-size: .85rem; color: #334155; line-height: 1.7; margin: 0 0 .5rem; }
.tdef-list li:last-child { margin-bottom: 0; }
.tdef-list li b { color: var(--z); font-weight: 700; }
.tdef-list code { background: #eef4f2; border: 1px solid var(--line); border-radius: 5px; padding: .05rem .35rem; font-size: .82rem; color: #14283c; }
/* ⑦ SAS code walkthrough */
pre.sas { background: #0f1f2e; color: #e6edf3; padding: .8rem 1rem; border-radius: 10px;
  overflow-x: auto; margin: .5rem 0 .2rem; box-shadow: var(--shadow); }
pre.sas code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .82rem; line-height: 1.55; white-space: pre; color: inherit; background: none;
  border: none; padding: 0; }
pre.sas .cm { color: #8aa6bf; font-style: italic; }   /* SAS comment */
pre.sas .kw { color: #6fd0c0; font-weight: 600; }      /* PROC / keyword */
.sas-note { background: #fff8e6; border: 1px solid #f0d68c; border-radius: 10px;
  padding: .7rem .9rem; font-size: .85rem; color: #6b5618; margin: .2rem 0 1rem; }

.hidden { display: none !important; }

/* SCCS extensions — expandable cards (extension + worked example + data + SAS) */
.ext-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); margin: .7rem 0; overflow: hidden; }
.ext-card > summary { cursor: pointer; padding: .85rem 1.1rem; font-weight: 700;
  font-size: 1.02rem; list-style: none; line-height: 1.5; }
.ext-card > summary::-webkit-details-marker { display: none; }
.ext-card > summary::before { content: "▸"; color: var(--z); margin-right: .5rem; }
.ext-card[open] > summary::before { content: "▾"; }
.ext-card > summary .ext-tag { color: var(--muted); font-weight: 500; font-size: .9rem; }
.ext-body { padding: 0 1.1rem 1.1rem; }
.ext-body h5 { margin: 1rem 0 .4rem; color: var(--z); font-size: .92rem;
  text-transform: none; letter-spacing: 0; }
.ext-body h5:first-child { margin-top: .4rem; }
.ext-body .mini { width: 100%; border-collapse: collapse; font-size: .82rem; margin: .2rem 0 .4rem; }
.ext-body .mini th, .ext-body .mini td { border: 1px solid var(--line); padding: .28rem .5rem; text-align: center; }
.ext-body .mini th { background: #f1f7f6; font-weight: 700; }
.ext-body .mini td.lo { background: #f8fafc; }
.ext-body .mini caption { caption-side: bottom; font-size: .76rem; color: var(--muted); padding-top: .3rem; text-align: left; }
.ext-body pre.sas { margin: .2rem 0 .3rem; }

/* references / citation footer */
.refs {
  max-width: 1280px; margin: 2rem auto 3rem; padding: 1.4rem 1.5rem;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.refs h2 { margin-top: 0; }
.refs h3 { margin: 1.2rem 0 .5rem; }
.refs .cite {
  background: #f7f9fd; border-left: 4px solid var(--z); border-radius: 8px;
  padding: .7rem .9rem; font-size: .95rem; color: #2b3849; line-height: 1.7;
}
.refs .cite a { color: var(--z); word-break: break-all; }
.cite-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin: .8rem 0 1.4rem; }
.cite-actions .btn { font-size: .88rem; padding: .45rem .9rem; }
.refs .reflist { margin: .8rem 0 0; padding-left: 1.2rem; }
.refs .reflist li { font-size: .88rem; color: #404a60; margin: .4rem 0; line-height: 1.6; }

@media (max-width: 720px) {
  .controls, .colmap, .play-grid, .rdd-twocol { grid-template-columns: 1fr; }
  table.cmp th, table.cmp td { font-size: .82rem; padding: .5rem .55rem; }
}

/* Phone polish: full-width method picker, horizontally-scrollable sub-tabs,
   tighter topbar so the ①–⑥ row never becomes a cramped multi-line wrap. */
@media (max-width: 600px) {
  .topbar { padding: .55rem .8rem; }
  .method-pick { display: flex; align-items: center; gap: .4rem; width: 100%; }
  .method-pick select { flex: 1 1 auto; min-width: 0; width: 100%; }
  .tabs { gap: .3rem; }
  .subtabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 3px; }
  .subtabs .subtab { flex: 0 0 auto; white-space: nowrap; }
  .tab { padding: .4rem .7rem; font-size: .85rem; }
  h1 { font-size: 1.4rem; }
  main { padding-left: .9rem; padding-right: .9rem; }
}

/* Home / overview landing page: search box + clickable method grid. */
.home-search {
  width: 100%; max-width: 520px; margin: .4rem 0 1.2rem; padding: .6rem .9rem;
  font: inherit; font-size: 1rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink);
}
.home-search:focus { outline: none; border-color: var(--z); box-shadow: 0 0 0 2px rgba(63,130,104,.18); }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .7rem; }
.home-card {
  text-align: left; display: flex; flex-direction: column; gap: .2rem;
  padding: .7rem .85rem; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--ink); cursor: pointer; font: inherit;
  transition: border-color .15s, box-shadow .15s, transform .05s;
}
.home-card:hover { border-color: var(--z); box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.home-card:active { transform: translateY(1px); }
.home-card .hc-abbr { font-weight: 800; color: var(--z); }
.home-card .hc-name { font-size: .86rem; color: var(--muted); }
/* Self-check quiz (collapsible card at the end of a method's ① learn panel). */
.quiz { margin-top: 1.6rem; }
.quiz h3::before { content: "📝 "; }
.quiz-q { margin: .7rem 0 1.1rem; }
.quiz-prompt { font-weight: 600; margin: 0 0 .55rem; }
.quiz-opts { display: flex; flex-direction: column; gap: .4rem; }
.quiz-opt { text-align: left; padding: .5rem .8rem; border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink); cursor: pointer; font: inherit; transition: .12s; }
.quiz-opt:hover { border-color: var(--z); }
.quiz-opt.correct { border-color: #16a34a; background: #ecfdf5; font-weight: 600; }
.quiz-opt.wrong { border-color: #dc2626; background: #fef2f2; }
.quiz-explain { margin: .55rem 0 0; font-size: .9rem; line-height: 1.6;
  background: #f1f5f9; border-left: 3px solid var(--z); border-radius: 8px; padding: .5rem .75rem; }

/* Glossary: auto-collected term definitions. */
.gloss-item { border: 1px solid var(--line); border-radius: 10px; padding: .6rem .85rem; margin: .5rem 0; background: var(--card); box-shadow: var(--shadow); }
.gloss-item h4 { margin: 0 0 .25rem; color: var(--z); font-size: 1rem; }
.gloss-item .en { color: var(--muted); font-weight: 500; font-size: .85rem; }
.gloss-item p { margin: 0; font-size: .9rem; line-height: 1.6; }

/* In-page section nav (chips) for the long single-page topics (SR-MA, NMA). */
.page-toc { display: flex; flex-wrap: wrap; gap: .5rem; margin: .2rem 0 1.2rem; }
.page-toc .toc-link {
  display: inline-block; padding: .32rem .8rem; border-radius: 999px;
  background: #eef2f6; border: 1px solid var(--line); color: var(--ink);
  font-weight: 600; font-size: .86rem; text-decoration: none; cursor: pointer;
}
.page-toc .toc-link:hover { background: var(--z); color: #fff; border-color: var(--z); }
/* offset so the sticky header doesn't cover the jumped-to heading */
.panel h2[id] { scroll-margin-top: 72px; }

/* ---- What If book notes: password gate + chapter accordions ---- */
/* --- concept links in the chapter notes + the slide-out explainer --- */
.cb-termlink { font: inherit; color: var(--z); background: rgba(47,111,87,.07);
  border: 0; border-bottom: 1px dashed var(--z); border-radius: 3px;
  padding: 0 .12em; margin: 0; cursor: pointer; }
.cb-termlink:hover { background: rgba(47,111,87,.16); }
.cb-termlink::after { content: "ⓘ"; font-size: .78em; margin-left: .15em; opacity: .75; }
.cb-drawer-scrim { position: fixed; inset: 0; background: rgba(15,23,42,.28); z-index: 60; }
/* Slides in from the right edge. `right` rather than a transform so the closed
   state is a plain offset (nothing to reset) and the drawer can never be left
   half-transformed if a class toggle is missed. */
.cb-drawer { --cb-dw: min(460px, 92vw);
  position: fixed; top: 0; right: calc(-1 * var(--cb-dw)); z-index: 61;
  width: var(--cb-dw); height: 100vh;
  background: var(--card); border-left: 1px solid var(--line); box-shadow: -8px 0 26px rgba(15,23,42,.18);
  display: flex; flex-direction: column; transition: right .2s ease; }
.cb-drawer.open { right: 0; }
.cb-drawer-head { display: flex; align-items: flex-start; gap: .6rem; padding: .9rem 1rem .6rem;
  border-bottom: 1px solid var(--line); }
.cb-drawer-head h3 { margin: 0; font-size: 1rem; flex: 1 1 auto; color: var(--ink); }
.cb-drawer-x { flex: 0 0 auto; border: 1px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-size: .9rem; }
.cb-drawer-x:hover { background: #f1f5f9; color: var(--ink); }
.cb-drawer-body { flex: 1 1 auto; overflow-y: auto; padding: .9rem 1rem; font-size: .9rem; line-height: 1.8; }
.cb-drawer-foot { flex: 0 0 auto; padding: .6rem 1rem .9rem; border-top: 1px solid var(--line); }
.cb-drawer-foot a { font-size: .84rem; color: var(--z); cursor: pointer; }
@media (prefers-reduced-motion: reduce) { .cb-drawer { transition: none; } }

.cb-gate { max-width: 460px; margin: 1.2rem 0; padding: 1.1rem 1.2rem; border: 1px solid var(--line);
  border-radius: 14px; background: var(--card); box-shadow: var(--shadow); }
.cb-gate h3 { margin: 0 0 .3rem; }
.cb-gate-row { display: flex; gap: .5rem; margin-top: .6rem; }
.cb-gate-row input { flex: 1 1 auto; min-width: 0; padding: .5rem .7rem; border: 1px solid var(--line);
  border-radius: 8px; font-size: .95rem; }
.cb-msg { min-height: 1.2em; margin: .5rem 0 0; font-size: .88rem; }
.cb-msg.err { color: #b91c1c; }
.cb-msg.ok { color: #15803d; }
.cb-part { margin: 1.6rem 0 .6rem; padding-bottom: .3rem; border-bottom: 2px solid var(--z); color: var(--z); }
.cb-ch { border: 1px solid var(--line); border-radius: 10px; margin: .5rem 0; background: var(--card); overflow: hidden; }
.cb-ch > summary { cursor: pointer; padding: .6rem .8rem; font-weight: 700; list-style: none; }
.cb-ch > summary::-webkit-details-marker { display: none; }
.cb-ch > summary::before { content: "▸ "; color: var(--z); }
.cb-ch[open] > summary::before { content: "▾ "; }
.cb-ch .cb-chbody { padding: 0 .9rem .8rem; }
.cb-ch .cb-chbody li { margin: .3rem 0; }
.cb-num { color: var(--muted); font-weight: 700; margin-right: .4rem; }
.cb-ch .cb-eg { background: #f0f7f4; border-left: 4px solid var(--z); border-radius: 8px;
  padding: .5rem .8rem; margin: .6rem 0 0; font-size: .92rem; }
.cb-ch .cb-formula { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px;
  padding: .5rem .8rem; margin: .6rem 0 0; }
.cb-ch .cb-formula > b { color: var(--z); }
.cb-ch .cb-formula code, .cb-ch .cb-chbody code { background: #eef2f6; padding: .05rem .3rem;
  border-radius: 4px; font-size: .9em; }
.cb-ch .cb-warn { background: #fff7ed; border-left: 4px solid #d97706; border-radius: 8px;
  padding: .5rem .8rem; margin: .6rem 0 0; font-size: .92rem; }
.cb-ch .cb-warn > b { color: #b45309; }
.cb-ch .cb-warn li { margin: .3rem 0; }
.cb-ch .cb-link { margin: .6rem 0 0; font-size: .9rem; }
.cb-ch .cb-link a.xref { margin-right: .6rem; }
.cb-ch .cb-howto { background: #eef6ff; border-left: 4px solid #2563eb; border-radius: 8px;
  padding: .5rem .8rem .5rem 1.6rem; margin: .6rem 0 0; font-size: .92rem; }
.cb-ch .cb-howto > b { color: #1d4ed8; margin-left: -0.8rem; }
.cb-ch .cb-howto ol { margin: .3rem 0 0; padding-left: 1.1rem; }
.cb-ch .cb-howto li { margin: .3rem 0; }
.cb-ch .cb-deep { background: #faf5ff; border-left: 4px solid #7c3aed; border-radius: 8px;
  padding: .5rem .8rem; margin: .6rem 0 0; font-size: .92rem; }
.cb-ch .cb-deep > b { color: #6d28d9; }
.cb-ch .cb-deep li { margin: .3rem 0; }
.cb-ch .cb-narr { margin: .5rem 0 0; padding: .5rem .8rem; background: #fbfbfd; border: 1px dashed var(--line);
  border-radius: 8px; font-size: .93rem; line-height: 1.75; }
.cb-ch .cb-narr > b { color: var(--z); }
.cb-ch .cb-narr p { margin: .45rem 0; }
.cb-ch .cb-secmap { background: #f0fdf4; border-left: 4px solid #16a34a; border-radius: 8px;
  padding: .55rem .85rem; margin: .6rem 0 0; font-size: .92rem; line-height: 1.7; }
.cb-ch .cb-secmap > b { color: #15803d; }
.cb-ch .cb-secmap p { margin: .5rem 0; }
.cb-ch .cb-secmap .cb-sec { font-weight: 600; color: #166534; display: block; margin-top: .6rem; }
/* SCCS ④ assumption-violation demo */
.sccsvio-tabs { display: flex; flex-wrap: wrap; gap: .5rem; margin: .3rem 0 .9rem; }
.sccsvio-tab { border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: .45rem 1rem; font-size: .9rem; font-weight: 700; cursor: pointer; }
.sccsvio-tab:hover { border-color: var(--z); color: var(--z); }
.sccsvio-tab.active { background: var(--z); color: #fff; border-color: var(--z); }
#sccsVioText p { margin: .5rem 0; font-size: .92rem; line-height: 1.8; }
/* the violation diagram is an inline SVG, not a Plotly div: let it size itself */
#sccsVioChart { height: auto; padding: .6rem .9rem; }
#sccsVioChart svg { display: block; width: 100%; max-width: 920px; height: auto; margin: 0 auto; }
/* SCCS violation scoreboard */
.svb-cards { display: flex; gap: .8rem; flex-wrap: wrap; margin: .8rem 0 .4rem; }
.svb-card { flex: 1 1 240px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  padding: .6rem .9rem; }
.svb-card h4 { margin: 0 0 .4rem; font-size: .92rem; }
.svb-cell { display: flex; align-items: baseline; gap: .45rem; padding: .12rem 0; }
.svb-lab { width: 3.6em; font-size: .82rem; color: var(--muted); }
.svb-god { font-size: .78rem; color: var(--muted); text-decoration: line-through; text-decoration-color: #cbd5e1; }
.svb-val { font-size: 1rem; font-variant-numeric: tabular-nums; }
.svb-val.svb-big { font-size: 1.35rem; font-weight: 800; }
.svb-unit { font-size: .76rem; color: var(--muted); }
.svb-irr { margin: .6rem 0 .8rem; }
.svb-irrlab { font-size: .84rem; color: var(--muted); }
.svb-rail { position: relative; height: 42px; margin: .5rem 0 1.3rem; border-bottom: 2px solid var(--line); }
.svb-truth { position: absolute; top: 0; bottom: 0; transform: translateX(-50%); }
.svb-truth i { display: block; width: 0; height: 100%; border-left: 2px dashed #94a3b8; margin: 0 auto; }
.svb-truth em { position: absolute; top: calc(100% + 3px); left: 50%; transform: translateX(-50%);
  font-size: .72rem; color: var(--muted); font-style: normal; white-space: nowrap; }
.svb-pin { position: absolute; bottom: 5px; transform: translateX(-50%); text-align: center; transition: left .3s ease;
  background: var(--card); border: 1px solid var(--z); border-radius: 8px; padding: .1rem .45rem; }
.svb-pin b { display: block; font-size: .95rem; color: var(--z); line-height: 1.2; }
.svb-pin span { font-size: .7rem; color: #b45309; white-space: nowrap; }
.svb-ticks { display: flex; justify-content: space-between; font-size: .74rem; color: var(--muted); margin-top: .1rem; }
/* SCCS fix rows: mini timeline + label + result chip */
.svfix-title { font-size: 1rem; margin: 1.3rem 0 .5rem; }
.svfix-row { display: flex; align-items: center; gap: .9rem; border: 1px solid var(--line);
  border-radius: 12px; background: var(--card); padding: .55rem .8rem; margin-bottom: .55rem; flex-wrap: wrap; }
.svfix-pic { flex: 0 0 260px; }
.svfix-mini { width: 100%; height: auto; display: block; }
.svfix-txt { flex: 1 1 260px; font-size: .88rem; line-height: 1.7; }
.svfix-res { flex: 0 0 auto; background: #dff0e8; color: #255c47; border-radius: 999px;
  padding: .25rem .7rem; font-size: .82rem; font-weight: 800; white-space: nowrap; }
.svfix-two { display: flex; gap: .5rem; flex-wrap: wrap; }
.svfix-chip { border-radius: 999px; padding: .3rem .8rem; font-size: .84rem; font-weight: 700; }
.svfix-chip.bad { background: #f4f6f8; color: #475569; border: 1px solid #cbd5e1; }
.svfix-chip.good { background: #dff0e8; color: #255c47; border: 1px solid #a7d7c5; }
/* figures extracted from the source books (inside the encrypted notes) */
.cb-figs { margin-top: 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.cb-figs > summary { cursor: pointer; padding: .55rem .9rem; font-weight: 700; font-size: .9rem; }
.cb-figs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .8rem; padding: .8rem; }
.cb-fig { margin: 0; border: 1px solid var(--line); border-radius: 8px; padding: .5rem; background: #fff; }
.cb-fig img { width: 100%; height: auto; display: block; }
.cb-fig figcaption { font-size: .78rem; color: var(--muted); margin-top: .3rem; }
/* ---- inline book figures + click-to-enlarge lightbox ---- */
.cb-figure { margin: 1rem 0; border: 1px solid var(--line); border-radius: 12px;
  background: #fff; padding: .7rem .8rem; }
.cb-figure img { width: 100%; height: auto; display: block; cursor: zoom-in;
  border-radius: 6px; background: #fff; }
.cb-figure figcaption { margin-top: .5rem; font-size: .86rem; line-height: 1.75; color: var(--ink); }
.cb-figure .cb-fig-h { display: block; font-weight: 700; color: var(--z); margin-bottom: .2rem; }
.cb-figure .cb-fig-zoom { float: right; font-size: .76rem; color: var(--muted); font-weight: 400; }
.fig-lb { position: fixed; inset: 0; z-index: 120; background: rgba(15, 23, 42, .88);
  display: flex; align-items: center; justify-content: center; padding: 2.5rem 3.5rem; }
.fig-lb[hidden] { display: none; }
.fig-lb-inner { margin: 0; max-width: 1100px; max-height: 100%; overflow: auto;
  background: #fff; border-radius: 12px; padding: 1rem 1.1rem; }
.fig-lb-inner img { width: 100%; height: auto; display: block; }
.fig-lb-inner figcaption { margin-top: .7rem; font-size: .92rem; line-height: 1.8; color: var(--ink); }
.fig-lb-x, .fig-lb-nav { position: absolute; background: rgba(255,255,255,.9); border: none;
  border-radius: 999px; cursor: pointer; color: var(--ink); }
.fig-lb-x { top: 1rem; right: 1.2rem; width: 38px; height: 38px; font-size: 1.05rem; }
.fig-lb-nav { top: 50%; transform: translateY(-50%); width: 42px; height: 62px; font-size: 1.8rem; line-height: 1; }
.fig-lb-nav.prev { left: .8rem; } .fig-lb-nav.next { right: .8rem; }
.fig-lb-x:hover, .fig-lb-nav:hover { background: #fff; }
@media (max-width: 640px) { .fig-lb { padding: 1rem .6rem; } .fig-lb-nav { width: 34px; height: 48px; } }
/* click-through reading steps inside the figure viewer */
.fig-steps { margin-top: .8rem; border-top: 1px solid var(--line); padding-top: .7rem; }
.fig-steps-lab { font-size: .8rem; font-weight: 800; color: var(--z); margin-bottom: .4rem; }
.fig-steps-chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.fig-step { border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: .3rem .8rem; font-size: .85rem; cursor: pointer; }
.fig-step b { display: inline-block; margin-right: .35rem; color: var(--z); }
.fig-step.on { background: var(--z); color: #fff; border-color: var(--z); }
.fig-step.on b { color: #fff; }
.fig-step-text { margin-top: .55rem; font-size: .9rem; line-height: 1.8;
  background: #f0f7f4; border-radius: 8px; padding: .55rem .8rem; }
.fig-lb-count { margin-top: .5rem; font-size: .8rem; color: var(--muted); }
.cb-figure .cb-fig-steps { margin-top: .4rem; font-size: .8rem; color: var(--z); }
/* layered reference list: 方法原典 / 應用範例 / 延伸與批評 */
.reflist li.ref-head { list-style: none; margin: 1rem 0 .35rem -1.2rem; font-weight: 800;
  font-size: .9rem; color: var(--z); }
.reflist li.ref-head:first-child { margin-top: 0; }
.reflist .ref-why { display: block; font-size: .84rem; color: var(--muted); line-height: 1.7; margin-top: .15rem; }
.reflist .ref-oa { display: inline-block; margin-left: .4rem; padding: 0 .4rem; border-radius: 999px;
  background: #dff0e8; color: #255c47; font-size: .72rem; font-weight: 700; vertical-align: .08em; }
/* ---- 研究設計: the fused workflow spine + the two coupled choosers ---- */
.dz-rail { display: flex; gap: .4rem; flex-wrap: wrap; margin: 1rem 0 .4rem; }
.dz-stage { flex: 1 1 130px; text-align: left; border: 1.5px solid var(--line); background: var(--card);
  border-radius: 10px; padding: .45rem .6rem; cursor: pointer; color: var(--ink); }
.dz-stage b { display: inline-block; width: 1.4em; height: 1.4em; line-height: 1.4em; text-align: center;
  border-radius: 999px; background: #eef2f1; color: var(--muted); font-size: .78rem; margin-right: .35rem; }
.dz-stage.key { border-color: var(--z); }
.dz-stage.key b { background: var(--z); color: #fff; }
.dz-stage.on { background: #f0f7f4; border-color: var(--z); }
.dz-stage:hover { border-color: var(--z); }
.dz-stage-sub { display: block; font-size: .74rem; color: var(--muted); margin-top: .15rem; line-height: 1.5; }
.dz-couple { display: flex; align-items: stretch; gap: .6rem; margin: 1rem 0 .6rem; flex-wrap: wrap; }
.dz-slot { flex: 1 1 240px; border: 1.5px dashed var(--line); border-radius: 12px; padding: .6rem .9rem; background: var(--card); }
.dz-slot.on { border-style: solid; border-color: var(--z); background: #f0f7f4; }
.dz-slot-lab { display: block; font-size: .76rem; font-weight: 800; color: var(--muted); margin-bottom: .15rem; }
.dz-slot b { font-size: 1rem; }
.dz-slot i { font-size: .86rem; color: var(--muted); font-style: normal; }
.dz-link { display: flex; align-items: center; font-size: 1.3rem; color: var(--z); }
.dz-card { border: 1px solid var(--line); border-radius: 12px; background: var(--card); padding: .7rem 1rem;
  font-size: .92rem; line-height: 1.8; }
.dz-card p { margin: .3rem 0; }
.dz-chip { border: 1.5px solid var(--z); background: var(--card); color: var(--z); border-radius: 999px;
  padding: .2rem .7rem; font-size: .84rem; margin: .15rem .25rem .15rem 0; cursor: pointer; }
.dz-chip:hover { background: var(--z); color: #fff; }
.dz-tag { display: inline-block; background: #dff0e8; color: #255c47; border-radius: 999px;
  padding: .2rem .7rem; font-size: .84rem; margin: .15rem .25rem .15rem 0; }
.dz-verdict { border-radius: 8px; padding: .5rem .7rem; margin-top: .5rem !important; }
.dz-verdict.ok { background: #f0f7f4; }
.dz-verdict.warn { background: #f4f6f8; }
.fc-leaf.dz-can { outline: 2px solid var(--z); outline-offset: 2px; }
.fc-leaf.dz-cannot { opacity: .38; }
tr.dz-row-can { background: #f0f7f4; }
/* ITS power lookup (Zhang 2011 tables made clickable) */
.itspower-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .8rem 1.2rem; }
.itspow-es-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .6rem 1rem; }
.itspow-es-controls input { width: 100%; padding: .3rem .5rem; border: 1px solid var(--line); border-radius: 8px; }
.itspow-esline { font-size: 1rem; }
.itspow-esout { margin-top: .5rem; font-size: .9rem; line-height: 1.8; }
.itspower-out { margin: 1rem 0 .4rem; }
.itspow-answer { display: flex; align-items: baseline; gap: .5rem; }
.itspow-answer b { font-size: 2.4rem; line-height: 1; }
.itspow-answer.ok b { color: var(--z); }
.itspow-answer.warn b { color: #b45309; }
.itspow-answer span { font-size: .95rem; color: var(--muted); }
.itspow-say { font-size: .92rem; line-height: 1.8; margin: .5rem 0 .7rem; }
.itspow-table td.hit { background: #dff0e8; font-weight: 700; color: #255c47; }
#itsPowChart svg { width: 100%; height: auto; display: block; }
/* long option text was being clipped by the grid column */
.itspower-controls select, .itspow-es-controls select { width: 100%; max-width: 100%; }
.itspower-controls label { min-width: 0; }
.itspower-controls small { display: block; margin-top: .25rem; }
/* .card.scene .chart pins 280px; the surface needs room to be readable */
.card.scene .chart.itspow-surface { height: 420px; margin: .6rem 0 .2rem; }
