/* === Gamut Reader — book-feel, low-frame, iPad-first === */
/* Design intent: feel like a quietly typeset book page, not a dashboard.
   Almost no boxes. Information differentiated by colour, weight, and
   generous whitespace rather than card chrome. */

* { box-sizing: border-box; }

html {
  font-size: 17px;
  scroll-behavior: smooth;
  scroll-padding-top: 88px;
  -webkit-text-size-adjust: 100%;
}

html[data-density="loose"]  { font-size: 19px; }
html[data-density="regular"] { font-size: 17px; }
html[data-density="tight"]  { font-size: 16px; }

/* iPad-friendly base */
@media (max-width: 1024px) {
  html { font-size: 17px; }
  html[data-density="loose"] { font-size: 19px; }
  html[data-density="tight"] { font-size: 16px; }
}
@media (max-width: 480px) {
  html { font-size: 16px; }
  html[data-density="loose"] { font-size: 18px; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-serif-latin), var(--font-serif-tc);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  font-feature-settings: "kern", "liga", "calt", "tnum";
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 200ms ease, color 200ms ease;
  /* iPad safe area */
  padding-bottom: env(safe-area-inset-bottom);
}

:lang(zh), :lang(zh-Hant) {
  font-family: var(--font-serif-tc);
}

/* ─── Topbar — slimmer, breathable ────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--rule-soft);
  font-family: var(--font-sans-latin), var(--font-sans-tc);
  /* iOS notch */
  padding-top: max(12px, env(safe-area-inset-top));
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 0.92rem;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-decoration: none;
  flex-shrink: 0;
}
.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent);
  display: grid;
  place-items: center;
  color: var(--bg);
  font-weight: 700;
  font-size: 11px;
}
.brand-name { color: var(--ink); }
.brand-sub { color: var(--ink-3); font-weight: 400; font-size: 0.8rem; }
@media (max-width: 640px) { .brand-sub { display: none; } }

.crumb {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--ink-3);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.crumb a { color: var(--ink-3); text-decoration: none; }
.crumb a:hover { color: var(--ink); }
.crumb-sep { color: var(--ink-faint); }
@media (max-width: 640px) {
  .crumb { font-size: 0.72rem; }
  .crumb a:not(:nth-last-child(2)):not(.crumb-current) { display: none; }
  .crumb-sep:not(:nth-last-child(2)) { display: none; }
}

.controls { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.ctrl-group {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 3px;
  gap: 1px;
}
.ctrl {
  background: transparent;
  border: 0;
  padding: 8px 11px;
  border-radius: 7px;
  font: inherit;
  font-size: 0.8rem;
  color: var(--ink-2);
  cursor: pointer;
  font-family: var(--font-sans-latin), var(--font-sans-tc);
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  line-height: 1;
  /* touch target */
  min-height: 36px;
  min-width: 36px;
  justify-content: center;
}
.ctrl:hover { color: var(--ink); background: var(--bg-elev); }
.ctrl[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}
.ctrl svg { width: 14px; height: 14px; }

/* Hamburger / TOC trigger — only shown on narrow screens */
.menu-btn {
  display: none;
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  padding: 0;
  cursor: pointer;
  color: var(--ink-2);
  align-items: center;
  justify-content: center;
}
.menu-btn:hover { color: var(--ink); }
.menu-btn svg { width: 18px; height: 18px; }
@media (max-width: 1100px) {
  .menu-btn { display: inline-flex; }
}

/* On narrow screens, simplify controls — keep theme + density, hide focus button */
@media (max-width: 720px) {
  .controls .ctrl-group:nth-child(2),
  .controls > .ctrl-group:last-child { display: none; }
}
@media (max-width: 480px) {
  .ctrl { padding: 8px 9px; font-size: 0.74rem; }
}

/* Read-state button */
.read-btn {
  background: var(--bg-card);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 8px 14px;
  font: inherit;
  font-family: var(--font-sans-latin), var(--font-sans-tc);
  font-size: 0.8rem;
  color: var(--ink-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  letter-spacing: 0.02em;
}
.read-btn:hover { color: var(--ink); background: var(--bg-elev); }
.read-btn[aria-pressed="true"] {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
.read-btn .check {
  display: inline-flex;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  align-items: center; justify-content: center;
  font-size: 10px;
  line-height: 1;
}
.read-btn[aria-pressed="true"] .check { background: var(--bg); color: var(--accent); border-color: var(--bg); }

@media (max-width: 480px) {
  .read-btn { padding: 8px 10px; font-size: 0.74rem; }
  .read-btn .label-long { display: none; }
}

/* Reading progress bar */
.progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  z-index: 60;
  width: 0%;
  transition: width 60ms linear;
}

/* ─── Page layout — generous, single-column-first ─────────── */
.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 200px;
  gap: 56px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 40px 40px 160px;
  align-items: start;
}

@media (max-width: 1280px) {
  .layout { grid-template-columns: 230px minmax(0, 1fr); gap: 48px; padding-right: 40px; }
  .meta-rail { display: none; }
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 32px 28px 160px;
  }
  .sidebar { display: none; }
}

@media (max-width: 720px) {
  .layout { padding: 24px 20px 140px; }
}

/* ─── Sidebar TOC (desktop) ───────────────────────────────── */
.sidebar {
  position: sticky;
  top: 88px;
  align-self: start;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  padding-right: 8px;
  font-family: var(--font-sans-latin), var(--font-sans-tc);
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 2px; }

.toc-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.20em;
  color: var(--ink-3);
  text-transform: uppercase;
  margin: 0 0 14px;
  font-weight: 500;
}

.toc { list-style: none; padding: 0; margin: 0; }
.toc li { margin: 0; padding: 0; }
.toc a {
  display: block;
  padding: 7px 10px 7px 14px;
  font-size: 0.85rem;
  color: var(--ink-2);
  text-decoration: none;
  border-left: 2px solid transparent;
  margin-left: -2px;
  line-height: 1.45;
  border-radius: 0 6px 6px 0;
  transition: color 120ms, border-color 120ms;
}
.toc a:hover { color: var(--ink); }
.toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}
.toc .num {
  display: inline-block;
  min-width: 18px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-faint);
  margin-right: 8px;
}
.toc a.active .num { color: var(--accent); }

/* ─── TOC drawer (mobile / iPad portrait) ─────────────────── */
.drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  visibility: hidden;
}
.drawer[data-open="true"] { pointer-events: auto; visibility: visible; }
.drawer-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.32);
  opacity: 0;
  transition: opacity 220ms ease;
}
.drawer[data-open="true"] .drawer-scrim { opacity: 1; }
.drawer-panel {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: min(82vw, 320px);
  background: var(--bg);
  border-right: 1px solid var(--rule);
  padding: 24px 20px 28px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(28px, env(safe-area-inset-bottom));
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.drawer[data-open="true"] .drawer-panel { transform: translateX(0); }
.drawer-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.drawer-close:hover { color: var(--ink); background: var(--bg-card); }
.drawer .toc-label { margin-top: 0; }
.drawer .toc a { font-size: 0.95rem; padding: 10px 12px; }

/* ─── Article (main reading column) ───────────────────────── */
.article {
  max-width: var(--measure);
  margin: 0 auto;
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--ink);
  text-spacing: auto;
  text-spacing-trim: trim-start;
}

.article p {
  margin: 0 0 1.15em;
  text-wrap: pretty;
  hyphens: auto;
}

/* ─── Article header (hero) ──────────────────────────────── */
.hero {
  margin-bottom: var(--sp-7);
  padding-bottom: var(--sp-5);
}

.kicker {
  font-family: var(--font-mono);
  font-size: var(--fs-kicker);
  letter-spacing: var(--tracking-kicker);
  text-transform: uppercase;
  color: var(--ink-3);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
}
.kicker .dot { color: var(--ink-faint); }

.h1 {
  font-family: var(--font-serif-tc);
  font-weight: 600;
  font-size: var(--fs-display);
  line-height: 1.25;
  letter-spacing: -0.005em;
  margin: 0 0 16px;
  color: var(--ink);
  text-wrap: balance;
}
.h1 .en { font-family: var(--font-serif-latin); font-weight: 600; }

.subtitle {
  font-family: var(--font-sans-tc);
  color: var(--ink-2);
  font-size: 1rem;
  line-height: 1.7;
  margin: 0;
  max-width: var(--measure);
}

.tag-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.tag {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  color: var(--ink-3);
  background: transparent;
  border: 1px solid var(--rule);
  text-transform: lowercase;
}
.tag.cannot-miss { color: var(--crit); border-color: color-mix(in oklab, var(--crit) 28%, var(--rule)); }
.tag.priority-high { color: var(--warn); border-color: color-mix(in oklab, var(--warn) 28%, var(--rule)); }
.tag.bread-and-butter { color: var(--info); border-color: color-mix(in oklab, var(--info) 28%, var(--rule)); }

/* ─── Pre-read schema — flat strip, NO boxes ─────────────── */
/* Three short summaries divided by thin rules; reads as one
   continuous "advance organizer" rather than three competing cards */
.schema {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0;
  margin: 0 0 var(--sp-7);
  padding: 22px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
@media (max-width: 720px) {
  .schema { grid-template-columns: 1fr; gap: 18px; padding: 20px 0; }
}
.schema-col {
  padding: 0 22px;
  border-left: 1px solid var(--rule-soft);
}
.schema-col:first-child { border-left: 0; padding-left: 0; }
@media (max-width: 720px) {
  .schema-col { border-left: 0; padding: 0; }
  .schema-col + .schema-col { border-top: 1px solid var(--rule-soft); padding-top: 18px; }
}
.schema-col .label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.schema-col .label::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink-3);
}
.schema-col.task .label::before  { background: var(--accent); }
.schema-col.frame .label::before { background: var(--info); }
.schema-col.trap .label::before  { background: var(--warn); }
.schema-col .body {
  font-family: var(--font-serif-tc);
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--ink);
}
.schema-col .body .trap-item {
  display: block;
  padding: 3px 0;
  position: relative;
  padding-left: 14px;
}
.schema-col .body .trap-item::before {
  content: "·";
  position: absolute;
  left: 0;
  color: var(--warn);
  font-weight: 700;
}
.schema-col .body .trap-item + .trap-item {
  border-top: 1px solid var(--rule-soft);
  margin-top: 4px;
  padding-top: 6px;
}

/* Meta rail entities chip list */
.meta-list.entities {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  font-family: var(--font-sans-latin);
  font-size: 0.74rem;
}
.meta-list.entities li {
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--bg-sunken);
  color: var(--ink-2);
  border: 1px solid var(--rule-soft);
  line-height: 1.5;
}

/* ─── Section headings — flat, just type ─────────────────── */
.h2 {
  font-family: var(--font-sans-tc);
  font-weight: 600;
  font-size: var(--fs-h2);
  line-height: 1.3;
  margin: var(--sp-8) 0 var(--sp-5);
  letter-spacing: -0.005em;
  color: var(--ink);
  scroll-margin-top: 100px;
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.h2 .h2-num {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--accent);
  flex-shrink: 0;
}
.h2 .en { font-family: var(--font-serif-latin); font-weight: 600; }

.h3 {
  font-family: var(--font-sans-tc);
  font-weight: 600;
  font-size: var(--fs-h3);
  line-height: 1.4;
  margin: var(--sp-6) 0 var(--sp-3);
  color: var(--ink);
  scroll-margin-top: 100px;
}
.h3 .en { font-family: var(--font-sans-latin); }

.h4 {
  font-family: var(--font-sans-tc);
  font-weight: 600;
  font-size: var(--fs-h4);
  line-height: 1.4;
  margin: var(--sp-5) 0 var(--sp-2);
  color: var(--ink);
}

/* ─── Lists — quiet bullets ──────────────────────────────── */
.article ul {
  margin: 0 0 1.2em;
  padding: 0;
  list-style: none;
}
.article ul > li {
  position: relative;
  padding-left: 22px;
  margin-bottom: 0.7em;
  line-height: var(--lh-body);
}
.article ul > li::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 0.85em;
  width: 6px;
  height: 1px;
  background: var(--ink-3);
}

/* Nested lists */
.article ul ul { margin: 0.5em 0 0.5em; }
.article ul ul > li { margin-bottom: 0.4em; }

.article ol {
  margin: 0 0 1.2em;
  padding-left: 0;
  counter-reset: ol;
  list-style: none;
}
.article ol > li {
  position: relative;
  padding-left: 30px;
  margin-bottom: 0.6em;
  counter-increment: ol;
}
.article ol > li::before {
  content: counter(ol);
  position: absolute;
  left: 0;
  top: 0;
  font-family: var(--font-mono);
  font-size: 0.82em;
  color: var(--accent);
  font-weight: 500;
}

/* ─── Inline elements ─────────────────────────────────────── */
strong { font-weight: 600; color: var(--ink); }
strong.en, .term {
  font-family: var(--font-sans-latin);
  font-weight: 600;
  font-size: 0.97em;
  color: var(--accent-deep);
  letter-spacing: -0.005em;
}
em { font-style: italic; color: var(--ink-2); }

mark, .hl {
  background: var(--highlight-bg);
  color: var(--highlight-ink);
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 500;
  /* extend slightly for breathing */
  box-shadow: 2px 0 0 var(--highlight-bg), -2px 0 0 var(--highlight-bg);
}

code {
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--ink);
  border: 1px solid var(--rule-soft);
}

.ent {
  font-family: var(--font-sans-latin);
  letter-spacing: 0;
  color: var(--ink);
}

/* ─── Pattern blocks — flat with thin left rule ──────────── */
/* NO border, NO shadow, NO background. Just a heading and a definition list. */
.pattern {
  margin: var(--sp-5) 0 var(--sp-6);
  scroll-margin-top: 100px;
}
.pattern-title {
  font-family: var(--font-sans-tc);
  font-weight: 600;
  font-size: 1.1rem;
  margin: 0 0 14px;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-left: 14px;
  border-left: 3px solid var(--accent);
}
.pattern-title .en { font-family: var(--font-sans-latin); font-weight: 600; }

.pattern-grid {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 6px 18px;
  font-size: 0.98em;
  line-height: 1.75;
  margin: 0;
  padding-left: 17px; /* aligned with title text under the bar */
}
.pattern-grid dt {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding-top: 5px;
  font-weight: 500;
}
.pattern-grid dt.trap-key {
  color: var(--warn);
}
.pattern-grid dd {
  margin: 0 0 4px;
  color: var(--ink);
}
@media (max-width: 720px) {
  .pattern-grid {
    grid-template-columns: 1fr;
    gap: 2px 0;
    padding-left: 17px;
  }
  .pattern-grid dt { padding-top: 12px; padding-bottom: 1px; }
  .pattern-grid dt:first-child { padding-top: 0; }
}

/* ─── Mimic block — flat horizontal rules ────────────────── */
.mimic {
  margin: var(--sp-5) 0 var(--sp-6);
}
.mimic-title {
  font-family: var(--font-sans-tc);
  font-weight: 600;
  font-size: 1.05rem;
  margin: 0 0 14px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding-left: 14px;
  border-left: 3px solid var(--warn);
}
.mimic-title .vs {
  font-family: var(--font-mono);
  color: var(--warn);
  font-size: 0.72em;
  letter-spacing: 0.16em;
  font-weight: 500;
  text-transform: uppercase;
}
.mimic-title .en { font-family: var(--font-sans-latin); font-weight: 600; }
.mimic-body {
  padding-left: 17px;
}
.mimic-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 6px 18px;
  font-size: 0.97em;
  line-height: 1.75;
  padding: 9px 0;
  margin: 0;
  border-top: 1px solid var(--rule-soft);
}
.mimic-row:first-of-type { border-top: 0; padding-top: 2px; }
.mimic-row dt {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding-top: 5px;
  font-weight: 500;
}
.mimic-row dt.trap-key { color: var(--warn); }
.mimic-row dd { margin: 0; }
@media (max-width: 720px) {
  .mimic-row {
    grid-template-columns: 1fr;
    gap: 2px;
    padding: 12px 0;
  }
  .mimic-row dt { padding-top: 0; padding-bottom: 1px; }
}

/* ─── Cannot-miss / Trap callouts — minimal ──────────────── */
/* Just a coloured left rule + label. No box. */
.callout {
  margin: var(--sp-4) 0 var(--sp-5);
  padding: 4px 0 4px 17px;
  border-left: 3px solid var(--ink-3);
  position: relative;
}
.callout-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 500;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-3);
}
.callout-body { line-height: 1.75; }
.callout-body :last-child { margin-bottom: 0; }
.callout-body > p:first-child { margin-top: 0; }

.callout.crit { border-left-color: var(--crit); }
.callout.crit .callout-label { color: var(--crit); }
.callout.trap { border-left-color: var(--warn); }
.callout.trap .callout-label { color: var(--warn); }
.callout.concept { border-left-color: var(--accent); }
.callout.concept .callout-label { color: var(--accent); }
.callout.protocol { border-left-color: var(--ink-2); }
.callout.protocol .callout-label { color: var(--ink-2); }

/* ─── Recall prompts — quiet block ────────────────────────── */
.recall {
  margin: var(--sp-7) 0 var(--sp-5);
  padding: 24px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}
.recall-title {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 4px;
}
.recall-sub {
  font-family: var(--font-sans-tc);
  color: var(--ink-3);
  font-size: 0.9rem;
  margin: 0 0 18px;
}
.recall ol {
  margin: 0;
  counter-reset: rec;
  list-style: none;
  padding: 0;
}
/* Specificity bump: .article ol > li sets counter-increment: ol,
   which silently steals from recall's `rec`. Re-target with higher
   specificity so the LI increments `rec` and the ::before reads it. */
.article .recall ol > li {
  margin-bottom: 14px;
  padding-left: 40px;
  position: relative;
  font-family: var(--font-sans-tc);
  font-size: 1rem;
  line-height: 1.75;
  counter-increment: rec;
}
.article .recall ol > li::before {
  content: "Q" counter(rec);
  position: absolute;
  left: 0;
  top: 0.05em;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
}

/* ─── References (collapsible) ───────────────────────────── */
.refs {
  margin-top: var(--sp-7);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--rule);
}
.refs-summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.refs-summary::-webkit-details-marker { display: none; }
.refs-title {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
}
.refs-count {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}
.refs-chev {
  margin-left: auto;
  color: var(--ink-faint);
  font-size: 1.1rem;
  font-family: var(--font-mono);
  transition: transform 200ms ease;
  display: inline-block;
}
details[open] > .refs-summary .refs-chev { transform: rotate(90deg); color: var(--ink-2); }
details[open] > .refs-summary { margin-bottom: 16px; }
details:hover > .refs-summary .refs-title { color: var(--ink-2); }

/* ─── Reporting anchors (collapsible, embedded mid-article) ─── */
.reporting-anchors {
  margin: var(--sp-5) 0;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--rule-soft);
  border-radius: var(--r-md);
}
.reporting-anchors > .refs-summary {
  padding: 0;
}
.reporting-anchors > .refs-summary .refs-title {
  font-size: 0.75rem;
}
.reporting-anchors .ra-body {
  padding-top: 4px;
}
.reporting-anchors .ra-body > p:first-child { margin-top: 0; }
.reporting-anchors .ra-body code {
  display: inline;
  white-space: normal;
  word-break: break-word;
}
.reporting-anchors .ra-body ul { margin-bottom: 0; }

.refs ol {
  font-family: var(--font-sans-tc);
  font-size: 0.9rem;
  color: var(--ink-2);
  line-height: 1.7;
  margin: 0;
  padding: 0;
  counter-reset: ref;
  list-style: none;
}
.refs ol > li {
  margin-bottom: 10px;
  padding-left: 30px;
  position: relative;
  counter-increment: ref;
}
.refs ol > li::before {
  content: counter(ref) ".";
  position: absolute;
  left: 0;
  top: 0;
  font-family: var(--font-mono);
  font-size: 0.78em;
  color: var(--ink-faint);
}

/* ─── Done banner (read-state) ───────────────────────────── */
.done-banner {
  margin: var(--sp-7) 0 0;
  padding: 18px 22px;
  background: var(--accent-soft);
  border-radius: var(--r-md);
  font-family: var(--font-sans-tc);
  font-size: 0.92rem;
  color: var(--accent-deep);
  display: none;
  align-items: center;
  gap: 12px;
  line-height: 1.5;
}
body[data-read="true"] .done-banner { display: flex; }
.done-banner .check {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: var(--bg);
  display: grid; place-items: center;
  font-size: 12px; flex-shrink: 0;
}

/* ─── Meta rail ──────────────────────────────────────────── */
.meta-rail {
  position: sticky;
  top: 88px;
  align-self: start;
  font-family: var(--font-sans-latin), var(--font-sans-tc);
}
.meta-rail h4 {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 10px;
  font-weight: 500;
}
.meta-rail h4 + h4 { margin-top: 28px; }
.meta-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 0.77rem;
  color: var(--ink-2);
  line-height: 1.5;
}
.meta-list b { color: var(--ink); font-weight: 600; }

/* Print */
@media print {
  .topbar, .sidebar, .meta-rail, .progress, .drawer, .menu-btn, .read-btn { display: none; }
  .layout { display: block; padding: 0; }
  .article { max-width: none; }
  .pattern-title, .mimic-title, .callout { border-left: 0; padding-left: 0; }
}

/* iPad portrait specific tweaks (768-1024 width, portrait) */
@media (min-width: 768px) and (max-width: 1100px) {
  .h1 { font-size: 2rem; }
  .h2 { font-size: 1.5rem; margin-top: var(--sp-7); }
  .article { max-width: 38em; }
}

/* iPhone landscape avoid sticky topbar eating too much */
@media (max-width: 932px) and (orientation: landscape) and (max-height: 500px) {
  .topbar { padding: 8px 16px; }
}
