/* Inter, vendored locally (app/fonts) so typography holds fully offline. */
@font-face {
  font-family: InterVariable;
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("./fonts/InterVariable.woff2") format("woff2");
}
@font-face {
  font-family: InterVariable;
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("./fonts/InterVariable-Italic.woff2") format("woff2");
}

:root {
  color-scheme: light;
  --bg: #eef2f3;
  --surface: #ffffff;
  --surface-2: #eef3f4;
  --surface-3: #f7f9fa;
  --ink: #14202a;
  --muted: #5a6871;
  --line: #d6dee2;
  --line-soft: #e6ecee;
  --teal: #0f766e;
  --teal-soft: #d7efec;
  --rust: #a74425;
  --rust-soft: #f6e1d8;
  --indigo: #3f54a0;
  --indigo-soft: #e0e5fb;
  --green: #2f6a37;
  --green-soft: #dff0db;
  --amber: #8a5d0c;
  --amber-soft: #f4e9cd;
  --danger: #9f2434;
  --danger-soft: #f3d8de;
  --on-accent: #ffffff;
  --shadow: 0 16px 40px rgba(20, 32, 42, 0.10);
  --shadow-sm: 0 4px 14px rgba(20, 32, 42, 0.07);
  --radius: 10px;
  --radius-sm: 7px;
  --font: InterVariable, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1214;
  --surface: #141d21;
  --surface-2: #1b262b;
  --surface-3: #182226;
  --ink: #e7eef1;
  --muted: #93a6ad;
  --line: #2a383e;
  --line-soft: #223035;
  --teal: #45c9bb;
  --teal-soft: #103633;
  --rust: #e0916c;
  --rust-soft: #3a2419;
  --indigo: #93a6ee;
  --indigo-soft: #1e2647;
  --green: #74c378;
  --green-soft: #142c17;
  --amber: #d8b262;
  --amber-soft: #322713;
  --danger: #ec7184;
  --danger-soft: #3a1820;
  --on-accent: #0c1214;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; color: var(--ink); font-family: var(--font); line-height: 1.45; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { color: transparent; }

h1, h2, h3, h4, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.25rem, 1.9vw, 1.9rem); line-height: 1.1; letter-spacing: -0.01em; }
h2 { margin-bottom: 0; font-size: 0.92rem; }
h3 { margin-bottom: 8px; font-size: 1.02rem; line-height: 1.2; }
h4 { margin-bottom: 6px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 0.78rem; }

.app-shell { min-height: 100vh; }

/* ---------------- Topbar ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 14px 22px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.topbar__title { display: flex; align-items: center; gap: 13px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 auto;
  background: radial-gradient(circle at 50% 50%, #fff 0 5px, transparent 6px),
              radial-gradient(circle at 50% 50%, var(--teal) 0 17px, transparent 18px);
  box-shadow: inset 0 0 0 1px var(--line);
}
.eyebrow { margin: 0 0 2px; color: var(--teal); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
.topbar__meta { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; color: var(--muted); font-size: 0.76rem; }
.topbar__meta span { padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); white-space: nowrap; }
#themeToggle { padding: 6px 11px; border-radius: 999px; }

/* ---------------- Workspace ---------------- */
.workspace {
  display: grid;
  grid-template-columns: minmax(248px, 312px) minmax(440px, 1fr);
  gap: 14px; padding: 14px; align-items: start;
  max-width: 1560px; margin: 0 auto;
}
.case-panel, .flow-panel { min-width: 0; }
.case-panel { position: sticky; top: 78px; max-height: calc(100vh - 92px); overflow: auto; }

.control-band, .flow-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.control-band { padding: 13px; margin-bottom: 13px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.section-head h2 { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 800; }

/* ---------------- Buttons ---------------- */
.ghost-button, .chip, .tab, .mini-link {
  min-height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.ghost-button { padding: 5px 10px; color: var(--muted); }
.ghost-button:hover, .mini-link:hover { border-color: var(--teal); color: var(--teal); }
.primary-button {
  border: 0; border-radius: var(--radius-sm); background: var(--teal); color: var(--on-accent); font-weight: 700;
  padding: 8px 13px; min-height: 34px; box-shadow: var(--shadow-sm);
}
.primary-button:hover { filter: brightness(1.06); }

.control-group { display: grid; gap: 7px; margin-bottom: 11px; }
.control-label { color: var(--muted); font-size: 0.71rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; }
.ctrl-help { width: 15px; height: 15px; padding: 0; margin-left: 5px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: 0.62rem; font-weight: 800; line-height: 1; cursor: pointer; vertical-align: middle; text-transform: none; }
.ctrl-help:hover { border-color: var(--teal); color: var(--teal); }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 9px; font-size: 0.8rem; line-height: 1.1; overflow-wrap: anywhere;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.chip:hover { border-color: var(--teal); }
.chip.is-active { border-color: var(--teal); background: var(--teal-soft); color: var(--teal); font-weight: 700; box-shadow: inset 0 0 0 1px var(--teal); }
.chip.is-same { border-style: dotted; color: var(--muted); }
.chip.is-pinned { border-style: dashed; border-color: var(--indigo); color: var(--indigo); }
.verdict__same { margin: 0; padding: 6px 9px; font-size: 0.76rem; color: var(--muted); background: var(--surface-2); border: 1px dashed var(--line); border-radius: var(--radius-sm); }
.chip.is-blocked { opacity: 0.4; cursor: not-allowed; }
.chip.is-blocked:hover { border-color: var(--line); }
/* Morphology = Shape row + (conditional) LST-subtype row, each a labelled
   chip group spaced like the other control rows. */
.chip-group { display: grid; gap: 7px; }
/* Surface-pattern axis: full-width stacked chips, each previewing its gate
   colour, with the NICE/JNET/Kudo crosswalk as a subline. */
.chip-row--stack { flex-direction: column; align-items: stretch; }
.chip-row--stack .chip { display: grid; gap: 2px; text-align: left; }
.chip__main { font-weight: 600; }
.chip__sub { font-size: 0.72rem; color: var(--muted); }
.chip--gate-clear:not(.is-active) { border-color: var(--green); }
.chip--gate-caution:not(.is-active) { border-color: var(--amber); }
.chip--gate-stop:not(.is-active) { border-color: var(--danger); }

/* ---------------- Case visual (live lesion sketch + colon site map) ---------------- */
.case-visual {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 76px; gap: 10px; align-items: center;
  margin: 0 0 12px; padding: 8px 10px; border: 1px solid var(--line); border-left-width: 4px;
  border-radius: var(--radius-sm); background: var(--surface-3);
}
.case-visual.gate-stop { border-left-color: var(--danger); }
.case-visual.gate-caution { border-left-color: var(--amber); }
.case-visual.gate-clear { border-left-color: var(--green); }
.case-visual svg { display: block; width: 100%; height: auto; }
.case-visual__lesion { min-width: 0; }

/* ---------------- Verdict (left) ---------------- */
.verdict { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 9px; }
.verdict__gate { display: flex; align-items: center; gap: 8px; font-weight: 750; font-size: 0.86rem; }
.gate-dot { width: 11px; height: 11px; border-radius: 999px; flex: 0 0 auto; }
.gate-stop .gate-dot { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.gate-caution .gate-dot { background: var(--amber); box-shadow: 0 0 0 4px var(--amber-soft); }
.gate-clear .gate-dot { background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.verdict__primary { display: grid; gap: 1px; }
.verdict__label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 800; }
.verdict__primary strong { font-size: 0.96rem; line-height: 1.2; }
.verdict .primary-button { width: 100%; justify-self: stretch; }
.verdict__pin { width: 100%; }
.verdict__cmp { justify-self: center; border: 0; background: none; color: var(--indigo); font-weight: 700; }
.verdict__cmp:hover { text-decoration: underline; }

/* ---------------- Inputs ---------------- */
.search-input, .select-input {
  width: 100%; min-height: 34px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); padding: 6px 10px;
}
.search-input:focus, .select-input:focus, button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--teal) 35%, transparent); outline-offset: 2px;
}
@supports not (outline-color: color-mix(in srgb, red, blue)) {
  .search-input:focus, .select-input:focus, button:focus-visible { outline: 3px solid rgba(15,118,110,0.3); }
}

/* ---------------- Tabs ---------------- */
/* clip (not hidden): hidden would make this a scroll container and silently
   kill position:sticky for the case strip and evidence nav inside it */
.flow-panel { overflow: hidden; overflow: clip; }
.tabs { display: flex; overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--surface-3); scrollbar-width: thin; }
.tab { flex: 0 0 auto; border: 0; border-right: 1px solid var(--line); border-radius: 0; padding: 12px 15px; color: var(--muted); background: transparent; white-space: nowrap; font-weight: 600; }
.tab:hover { color: var(--ink); background: var(--surface); }
.tab.is-active { color: var(--ink); background: var(--surface); box-shadow: inset 0 -3px 0 var(--teal); font-weight: 800; }
.tab-page { min-width: 0; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
.tab-page[hidden] { display: none; }

/* ---------------- Pills ---------------- */
.pill { display: inline-flex; align-items: center; min-height: 22px; padding: 3px 8px; border-radius: 999px; font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.02em; white-space: nowrap; }
.pill.triage, .pill.referral { background: var(--danger-soft); color: var(--danger); }
.pill.cold { background: var(--teal-soft); color: var(--teal); }
.pill.hot, .pill.pedunculated { background: var(--rust-soft); color: var(--rust); }
.pill.water { background: var(--indigo-soft); color: var(--indigo); }
.pill.advanced, .pill.mixed { background: var(--amber-soft); color: var(--amber); }
.pill.rescue, .pill.safety, .pill.followup { background: var(--green-soft); color: var(--green); }

/* ---------------- Console / decision brief ---------------- */
.console-view { display: grid; gap: 14px; }

.gate-banner { display: grid; grid-template-columns: 1fr; padding: 13px 15px; border-radius: var(--radius); border: 1px solid var(--line); }
.gate-banner p { margin: 4px 0 0; font-size: 0.86rem; }
.gate-banner__icon { width: 30px; height: 30px; border-radius: 999px; display: grid; place-items: center; font-weight: 900; color: var(--on-accent); }
.gate-banner__id { display: flex; align-items: center; gap: 11px; padding-bottom: 10px; margin-bottom: 11px; border-bottom: 1px solid color-mix(in srgb, currentColor 15%, var(--line)); }
.gate-banner__id-glyph { width: 90px; flex: 0 0 auto; }
.gate-banner__id-glyph svg { display: block; width: 100%; height: auto; }
.gate-banner__tokens { display: flex; flex-wrap: wrap; gap: 5px; min-width: 0; }
.gate-banner__main { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: start; }
.type-tok { font-size: 0.68rem; font-weight: 700; color: var(--ink); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.type-tok--amber { color: var(--amber); border-color: var(--amber); background: var(--amber-soft); }
.type-tok--danger { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.gate-banner.gate-stop { background: var(--danger-soft); border-color: var(--danger); }
.gate-banner.gate-stop .gate-banner__icon { background: var(--danger); }
.gate-banner.gate-caution { background: var(--amber-soft); border-color: var(--amber); }
.gate-banner.gate-caution .gate-banner__icon { background: var(--amber); }
.gate-banner.gate-clear { background: var(--green-soft); border-color: var(--green); }
.gate-banner.gate-clear .gate-banner__icon { background: var(--green); }

.primary-card { border: 1px solid var(--teal); border-left-width: 4px; border-radius: var(--radius); padding: 14px 16px; background: linear-gradient(180deg, var(--teal-soft), transparent 120%); }
.primary-card__tag { font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--teal); }
.primary-card h3 { margin: 5px 0 6px; font-size: 1.18rem; }
.primary-card p { margin: 0; font-size: 0.9rem; }
.primary-card__alts { margin-top: 13px; padding-top: 11px; border-top: 1px dashed color-mix(in srgb, var(--teal) 45%, var(--line)); }
.primary-card__alts h4 { margin-bottom: 8px; }
.primary-card__tension { margin: 11px 0 0; }

/* figure + do/avoid layout, reused inside the Teaching points "working the step" card */
.step-dossier__grid { display: grid; grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); gap: 14px; align-items: start; }
.step-dossier__media { margin: 0; min-width: 0; }
.step-dossier__media img { width: 100%; aspect-ratio: 16 / 11; object-fit: cover; display: block; border-radius: var(--radius-sm); background: #0a0f12; }
.step-dossier__media .caption { margin: 7px 0 0; }
.step-dossier__body { min-width: 0; display: grid; gap: 0; align-content: start; }
.step-dossier__body .two-col { margin: 0; }
/* Curative-criteria panel under a cancer stop: constructive, not alarmist. */
.curative-card { margin: 12px 0; padding: 13px 15px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); display: grid; gap: 8px; }
.curative-card__tag { font-size: 0.66rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--teal); }
.curative-card p { margin: 0; }
.curative-list { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.curative-list li { font-size: 0.85rem; }

.brief-block { border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 15px; background: var(--surface); }
.brief-block > h4 { color: var(--ink); font-size: 0.84rem; }
.alt-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }
.alt-list li { display: grid; gap: 2px; padding-left: 12px; border-left: 2px solid var(--line); }
.alt-name { border: 0; background: none; padding: 0; font-weight: 750; color: var(--ink); text-align: left; font-size: 0.9rem; }
.alt-name:hover { color: var(--ink); text-decoration: none; }

.adjunct-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.adjunct { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; background: var(--surface-3); }
.adjunct__tag { display: inline-block; font-size: 0.66rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; color: var(--teal); margin-bottom: 4px; }
.adjunct p { margin: 0 0 6px; font-size: 0.82rem; }

.tension { font-size: 0.85rem; padding: 9px 11px; border-left: 3px solid var(--amber); background: var(--amber-soft); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin: 0 0 8px; }
.tension:last-child { margin-bottom: 0; }
.brief-foot { margin: 0; }

/* ---------------- What-if comparison (pinned vs current case) ---------------- */
.compare-card {
  border: 1px solid var(--indigo); border-radius: var(--radius); padding: 12px 14px;
  background: linear-gradient(180deg, var(--indigo-soft), transparent 150%);
  display: grid; gap: 10px;
}
.compare-card__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.compare-card__head > div { display: grid; gap: 2px; min-width: 0; }
.compare-card__title { font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--indigo); }
.compare-card__pin { overflow-wrap: anywhere; }
.diff-inputs { display: flex; flex-wrap: wrap; gap: 6px; }
.diff-input {
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  padding: 3px 10px; font-size: 0.74rem; color: var(--muted);
}
.diff-input s { opacity: 0.75; }
.diff-input strong { color: var(--ink); }
.diff-arrow { color: var(--indigo); font-weight: 800; }
.diff-rows { display: grid; gap: 9px; }
.diff-row { display: grid; grid-template-columns: 92px 1fr; gap: 8px; align-items: start; }
.diff-row__label { font-size: 0.66rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding-top: 6px; }
.diff-row__cols { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; min-width: 0; }
.diff-was, .diff-now { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); padding: 6px 9px; font-size: 0.78rem; min-width: 0; overflow-wrap: anywhere; }
.diff-now { border-color: var(--indigo); box-shadow: inset 3px 0 0 var(--indigo); }
.diff-tag { display: block; font-size: 0.6rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 2px; }
.diff-detail { display: block; margin-top: 3px; color: var(--muted); font-size: 0.72rem; line-height: 1.35; }
.diff-was .gate-dot, .diff-now .gate-dot { display: inline-block; width: 9px; height: 9px; margin-right: 5px; vertical-align: baseline; }
.diff-route { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; padding-top: 4px; }
.diff-step { border: 1px solid var(--line); border-radius: 999px; background: var(--surface); padding: 3px 10px; font-size: 0.72rem; color: var(--muted); }
.diff-step.add { border-color: var(--green); color: var(--green); background: var(--green-soft); font-weight: 700; }
.diff-step.del { text-decoration: line-through; }
.diff-same { font-size: 0.74rem; color: var(--muted); margin: 0; }

/* evidence chips */
.ev-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.ev-chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 9px; font-size: 0.7rem; color: var(--muted); }
.ev-chip:hover { border-color: var(--teal); color: var(--teal); }
.ev-chip strong { color: var(--ink); font-weight: 800; }

/* ---------------- Evidence ---------------- */
/* "Answers, not a library": clinical questions lead, charts render on tap. */
.evidence-questions { display: grid; gap: 4px; }
/* Evidence hierarchy: top-level section headers (peers to the disclosure
   summaries), then teal subheads inside a section. */
.ev-section-head { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; color: var(--ink); margin: 0 0 12px; padding-top: 16px; border-top: 1px solid var(--line); }
.evidence-questions > .ev-section-head:first-child { padding-top: 0; border-top: 0; }
.case-evidence-lead { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 13px 15px; display: grid; gap: 7px; box-shadow: var(--shadow-sm); }
.case-evidence-lead h3 { margin: 0; font-size: 1rem; color: var(--ink); line-height: 1.25; }
.case-evidence-lead .ev-chips { margin-top: 0; }
.case-evidence-lead .ev-subhead { margin: 0; }
.ev-subhead { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--teal); margin: 18px 0 7px; }
.q-theme { margin-top: 18px; }
.q-theme:first-of-type { margin-top: 4px; }
.ev-subhead--ruled { margin: 0 0 7px; padding-bottom: 5px; border-bottom: 1px solid var(--line-soft); }
.q-row { border-bottom: 1px solid var(--line); }
.q-row > summary { display: flex; align-items: center; gap: 10px; min-height: 54px; padding: 9px 2px; cursor: pointer; list-style: none; }
.q-row > summary::-webkit-details-marker { display: none; }
.q-row > summary::before { content: "▸"; flex: none; color: var(--muted); font-size: 0.8em; transition: transform 0.12s ease; }
.q-row[open] > summary::before { transform: rotate(90deg); }
.q-row__text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.q-row__q { font-weight: 620; font-size: 0.95rem; line-height: 1.25; color: var(--ink); }
.q-row__a { font-size: 0.84rem; color: var(--muted); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-body { padding: 2px 2px 14px; display: grid; gap: 11px; }
.q-row[open] > .q-body { margin-left: 12px; padding-left: 12px; border-left: 2px solid var(--teal-soft); }
[data-theme="dark"] .q-row[open] > .q-body { border-left-color: var(--line); }
.q-verdict { font-weight: 600; font-size: 0.9rem; margin: 0; }
.ev-disclosure { margin-top: 20px; border-top: 1px solid var(--line); }
.ev-disclosure > summary { min-height: 46px; display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.25rem; letter-spacing: -0.01em; color: var(--ink); cursor: pointer; padding: 14px 2px 11px; list-style: none; }
.ev-disclosure > summary::-webkit-details-marker { display: none; }
.ev-disclosure > summary::before { content: "▸"; color: var(--muted); transition: transform 0.12s ease; }
.ev-disclosure[open] > summary::before { transform: rotate(90deg); }
/* Library cards (grouped by area): the header opens the full study summary. */
.lib-card { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); padding: 10px 11px; display: grid; gap: 9px; margin-bottom: 9px; }
.lib-card__head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; width: 100%; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; }
.lib-card__head:hover .lib-card__title { color: var(--teal); }
.lib-card__title { flex: 1; min-width: 0; font-size: 0.88rem; font-weight: 600; overflow-wrap: anywhere; }
.lib-card__meta { flex: none; }
.lib-card .trial-outcomes { margin: 0; }
@media (max-width: 480px) { .q-row > summary { flex-wrap: wrap; } }
@media (prefers-reduced-motion: reduce) { .ev-disclosure > summary::before, .optic-perf > summary::before { transition: none; } }
.count-chip { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; font-size: 0.72rem; color: var(--ink); text-transform: none; letter-spacing: 0; }

.evidence-matrix, .technique-grid { display: grid; gap: 10px; }
.evidence-meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.evidence-meta span, .branch-chip { border: 1px solid var(--line); border-radius: 999px; padding: 3px 8px; color: var(--muted); font-size: 0.68rem; background: var(--surface); }

/* guidelines */
.guideline-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; margin-bottom: 6px; }
.guideline-card { border: 1px solid var(--line); border-left: 3px solid var(--indigo); border-radius: var(--radius); background: var(--surface); padding: 12px; display: grid; gap: 6px; align-content: start; }
.guideline-card__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.guideline-card__title { margin: 0; font-size: 0.86rem; color: var(--ink); text-transform: none; letter-spacing: 0; }
.guideline-card__title-btn { border: 0; background: transparent; padding: 0; text-align: left; font-weight: 700; line-height: 1.25; cursor: pointer; }
.guideline-card__title-btn:hover { color: var(--teal); text-decoration: underline; }
.guideline-card p { margin: 0; font-size: 0.8rem; color: var(--muted); }
.flash { animation: flash 1.3s ease; } /* applied by revealTarget() to any jump target */

/* comparison cards, shared-axis dumbbell rows */
.cmp-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 14px; box-shadow: var(--shadow-sm); }
.cmp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 12px; }
.cmp-head h3 { margin: 2px 0 3px; font-size: 0.9rem; font-weight: 700; text-transform: none; color: var(--ink); }
.cmp-rows { display: grid; gap: 12px; }
.cmp-row { display: grid; grid-template-columns: minmax(150px, 0.7fr) minmax(220px, 1.4fr); gap: 12px 16px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.cmp-row:first-child { border-top: 0; }
.cmp-row--axis { padding: 0 0 2px; align-items: end; }
.cmp-row--axis .db-axis { margin-left: calc(var(--bar-name-w, 120px) + 8px); }
.cmp-row__meta { display: grid; gap: 2px; align-content: center; }
.cmp-trial { border: 0; background: none; padding: 0; text-align: left; font-weight: 750; color: var(--ink); font-size: 0.86rem; }
.cmp-trial:hover { color: var(--teal); text-decoration: underline; }

/* labelled arm bars: name + colour chip on the left, length = the number,
   value at the bar end (inside when the bar is long), winner bolded */
.db { display: grid; gap: 5px; min-width: 0; --bar-name-w: 120px; }
.bar-row { display: grid; grid-template-columns: var(--bar-name-w) minmax(0, 1fr); gap: 8px; align-items: center; min-width: 0; }
.bar-row__name {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0;
  font-size: 0.72rem; font-weight: 600; color: var(--muted);
  white-space: normal; line-height: 1.2; overflow-wrap: break-word;
}
.bar-row__chip { width: 8px; height: 8px; border-radius: 999px; flex: 0 0 auto; }
.bar-row__track {
  position: relative; height: 15px; border-radius: 4px; background: var(--surface-2); min-width: 0;
  background-image: repeating-linear-gradient(to right, transparent 0, transparent calc(25% - 1px), var(--line-soft) calc(25% - 1px), var(--line-soft) 25%);
}
.bar-row__fill { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 4px 3px 3px 4px; opacity: 0.85; }
.bar-row__val {
  position: absolute; top: 50%; transform: translate(6px, -50%);
  font-size: 0.7rem; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.bar-row__val.is-inside { transform: translate(calc(-100% - 6px), -50%); color: var(--on-accent); }
.bar-row.is-best .bar-row__name { color: var(--ink); font-weight: 800; }
.bar-row.is-best .bar-row__val { font-weight: 800; }
.bar-row.is-best .bar-row__fill { opacity: 1; }
.db-axis { position: relative; display: block; height: 12px; margin-left: calc(var(--bar-name-w) + 8px); font-size: 0.66rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.db-axis span { position: absolute; top: 0; transform: translateX(-50%); }
.db-axis span:first-child { left: 0; transform: none; }
.db-axis span:nth-child(2) { left: 50%; }
.db-axis span:last-child { left: 100%; transform: translateX(-100%); }

.cmp-note { grid-column: 1 / -1; margin: 2px 0 0; }
.favours { color: var(--green); font-weight: 700; }
.cmp-foot { margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--line); }
.bottom-line { font-size: 0.86rem; margin: 0 0 6px; }
.cmp-foot .tension { margin: 0; }
.ns { color: var(--muted); font-weight: 700; }
.flag-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.flag-chip { font-size: 0.64rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; }
.cmp-tradeoff { font-size: 0.82rem; margin: 0 0 10px; padding: 8px 11px; border-radius: var(--radius-sm); background: var(--indigo-soft); color: var(--ink); border: 1px solid var(--indigo); }
.tradeoff-mark { font-weight: 900; color: var(--indigo); margin-right: 4px; }

/* ---------------- Optical ---------------- */
.optical-view { display: grid; gap: 12px; min-width: 0; max-width: 100%; }
.crosswalk-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 14px; box-shadow: var(--shadow-sm); }
.crosswalk-scroll { overflow-x: auto; }
.crosswalk-table, .classification-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.crosswalk-table th, .crosswalk-table td, .classification-table th, .classification-table td { border-top: 1px solid var(--line); padding: 9px 8px; text-align: left; vertical-align: top; }
.crosswalk-table th, .classification-table th { color: var(--muted); font-size: 0.67rem; text-transform: uppercase; letter-spacing: 0.03em; }
.crosswalk-table .ct-c { text-align: center; }
.optic-badge { display: inline-grid; place-items: center; min-width: 26px; padding: 3px 7px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); font-weight: 800; font-size: 0.76rem; }
/* The cross-walk is a risk ladder, make risk the dominant visual variable. */
.risk-stop { background: color-mix(in srgb, var(--danger) 9%, var(--surface)); }
.risk-caution { background: color-mix(in srgb, var(--amber) 9%, var(--surface)); }
.risk-low { background: color-mix(in srgb, var(--green) 8%, var(--surface)); }
.risk-stop td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
.risk-caution td:first-child { box-shadow: inset 4px 0 0 var(--amber); }
.risk-low td:first-child { box-shadow: inset 4px 0 0 var(--green); }
.risk-stop .optic-badge { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.risk-caution .optic-badge { background: var(--amber-soft); color: var(--amber); border-color: var(--amber); }
.risk-low .optic-badge { background: var(--teal-soft); color: var(--teal); border-color: var(--teal); }
@supports not (background: color-mix(in srgb, red, blue)) {
  .risk-stop { background: var(--danger-soft); } .risk-caution { background: var(--amber-soft); } .risk-low { background: var(--green-soft); }
}

.classification-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 14px; display: grid; grid-template-columns: minmax(180px, 0.7fr) minmax(320px, 1.3fr); gap: 14px; }
.classification-card > section { min-width: 0; }
.classification-card p { overflow-wrap: anywhere; }
/* Diagnostic-performance block, full-width third row of the card grid. */
.optic-perf { grid-column: 1 / -1; border-top: 1px solid var(--line); padding-top: 2px; margin-top: 8px; }
.optic-perf > summary { display: flex; align-items: center; gap: 8px; font-size: 0.86rem; font-weight: 700; color: var(--ink); cursor: pointer; padding: 9px 2px; list-style: none; }
.optic-perf > summary::-webkit-details-marker { display: none; }
.optic-perf > summary::before { content: "▸"; color: var(--muted); transition: transform 0.12s ease; }
.optic-perf[open] > summary::before { transform: rotate(90deg); }
.optic-perf__facet { margin-top: 11px; }
.optic-perf__facet:first-of-type { margin-top: 7px; }
.optic-perf__ctx { font-weight: 650; font-size: 0.82rem; margin: 0 0 6px; }
.optic-perf__stats { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 5px; }
.optic-stat { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 1px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 9px; }
.optic-stat__v { font-weight: 800; font-size: 0.82rem; }
.optic-stat__k { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.caveat { border-left: 2px solid var(--amber); padding-left: 8px; }

/* Optical Dx, system-first image tables ---------------------------------- */
.optic-systems { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
.optic-sys { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--muted); cursor: pointer; text-align: left; }
.optic-sys strong { font-size: 0.95rem; color: var(--ink); }
.optic-sys span { font-size: 0.66rem; line-height: 1.25; }
.optic-sys.is-on { border-color: var(--teal); background: var(--teal-soft); }
.optic-sys.is-on strong { color: var(--teal); }
.optic-card { min-width: 0; max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 14px; }
.optic-card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.optic-card__head h3 { margin: 0; }
.optic-card__actions { display: flex; gap: 6px; flex-wrap: wrap; }
.optic-table-scroll { width: 100%; min-width: 0; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.optic-table { width: 100%; min-width: 920px; border-collapse: collapse; font-size: 0.8rem; }
.optic-table th, .optic-table td { border-top: 1px solid var(--line); padding: 10px 9px; text-align: left; vertical-align: top; }
.optic-table th { color: var(--muted); font-size: 0.67rem; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
.optic-table .ot-type strong { font-size: 0.95rem; white-space: nowrap; }
.ot-img { width: 194px; min-width: 194px; }
.ot-visuals { display: grid; gap: 8px; }
.ot-visual { width: 176px; margin: 0; }
.ot-img img { display: block; width: 176px; height: 132px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); }
.ot-img .ot-draw { object-fit: contain; }
.ot-visual figcaption { margin-top: 4px; color: var(--muted); font-size: 0.66rem; font-weight: 700; line-height: 1.2; }
.optic-about__h { margin: 16px 0 6px; font-size: 0.86rem; }
.optic-about .optic-perf__facet:first-of-type { margin-top: 7px; }
@media (max-width: 560px) {
  .optic-systems { grid-template-columns: 1fr; }
  .optic-table { min-width: 760px; }
  .ot-img { width: 146px; min-width: 146px; }
  .ot-visual, .ot-img img { width: 132px; }
  .ot-img img { height: 99px; }
}

/* ---------------- Techniques ---------------- */
.technique-row { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 13px; }
.technique-row h3 { margin: 7px 0 5px; }
.technique-evidence { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.technique-basis, .technique-advice { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.technique-advice { margin-top: 4px; }
.technique-basis strong, .technique-advice strong { color: var(--text); }
.technique-references { margin-top: 12px; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.technique-references__label { margin: 0 0 7px; color: var(--ink); font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; }
.technique-reference-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 6px; }
.technique-reference { min-width: 0; padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--ink); text-align: left; cursor: pointer; }
.technique-reference:hover { border-color: var(--teal); background: var(--teal-soft); }
.technique-reference__name, .technique-reference__meta { display: block; overflow-wrap: anywhere; }
.technique-reference__name { font-size: 0.76rem; font-weight: 800; line-height: 1.25; }
.technique-reference__meta { margin-top: 2px; color: var(--muted); font-size: 0.64rem; line-height: 1.3; }
@keyframes flash { 0%, 100% { box-shadow: none; } 25% { box-shadow: 0 0 0 3px var(--teal-soft); border-color: var(--teal); } }
.step-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.step { background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-size: 0.74rem; color: var(--ink); }

/* ---------------- Question / Answer ---------------- */
.trainer-view { display: grid; gap: 12px; }
.quiz-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.quiz-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; box-shadow: var(--shadow-sm); display: grid; grid-template-columns: minmax(220px, 0.8fr) 1.4fr; }
.quiz-figure { margin: 0; position: relative; background: #0a0f12; }
.quiz-figure img { width: 100%; height: 100%; min-height: 200px; object-fit: cover; display: block; }
.quiz-figure figcaption { position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.quiz-credit { border-radius: 4px; background: rgba(10, 15, 18, 0.82); color: #fff; font-size: 10px; line-height: 1.3; padding: 4px 6px; text-decoration: none; }
.quiz-credit:hover { text-decoration: underline; }
.quiz-body { padding: 16px; display: grid; gap: 12px; align-content: start; }
.quiz-stem { font-size: 0.96rem; font-weight: 600; margin: 0; line-height: 1.4; }
.quiz-options { display: grid; gap: 8px; }
.quiz-option { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; text-align: left; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface); font-size: 0.87rem; }
.quiz-option:hover:not(:disabled) { border-color: var(--teal); background: var(--surface-3); }
.quiz-key { width: 22px; height: 22px; border-radius: 6px; background: var(--surface-2); display: grid; place-items: center; font-weight: 800; font-size: 0.76rem; }
.quiz-option.is-correct { border-color: var(--green); background: var(--green-soft); }
.quiz-option.is-correct .quiz-key { background: var(--green); color: var(--on-accent); }
.quiz-option.is-wrong { border-color: var(--danger); background: var(--danger-soft); }
.quiz-option.is-wrong .quiz-key { background: var(--danger); color: var(--on-accent); }
.quiz-option.is-dim { opacity: 0.6; }
.quiz-mark { font-weight: 900; }
.quiz-option.is-correct .quiz-mark { color: var(--green); }
.quiz-option.is-wrong .quiz-mark { color: var(--danger); }
.quiz-explain { border-radius: var(--radius-sm); padding: 12px; border: 1px solid var(--line); }
.quiz-explain.ok { background: var(--green-soft); border-color: var(--green); }
.quiz-explain.no { background: var(--amber-soft); border-color: var(--amber); }
.quiz-explain p { margin: 5px 0 0; font-size: 0.85rem; }
.quiz-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 11px; }

/* ---------------- Detail blocks (popovers) ---------------- */
.hero { margin: 0; position: relative; }
.hero-image { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; background: #0a0f12; display: block; border-radius: var(--radius) var(--radius) 0 0; }
.detail-body { padding: 14px; }
.detail-title { display: flex; gap: 8px; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.detail-title h2 { font-size: 1.12rem; line-height: 1.18; }
.caption { color: var(--muted); font-size: 0.78rem; margin: 9px 0 12px; }
.callout { border-left: 4px solid var(--teal); background: var(--teal-soft); padding: 10px 12px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin: 12px 0; font-size: 0.88rem; }
.compact-list { display: grid; gap: 6px; padding-left: 17px; margin: 0; color: var(--ink); font-size: 0.85rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; margin: 12px 0; }
.do-block, .avoid-block, .lecture-block { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; }
/* Do / Avoid headings stay off the gate palette (green/danger reserved for the gate
   verdict). The word + the block carry the meaning; colour does not. */
.do-block h4 { color: var(--ink); }
.avoid-block h4 { color: var(--ink); }
.lecture-block { margin: 12px 0; background: var(--surface-3); }
.link-row, .next-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; }
.mini-link { display: inline-flex; align-items: center; padding: 5px 10px; color: var(--muted); font-size: 0.78rem; text-decoration: none; }
.mini-link.strong { color: var(--teal); border-color: var(--teal); font-weight: 700; }
.next-row .mini-link { background: var(--surface-2); }

/* "How we know this": static stat tiles at the foot of the Evidence tab */
.ev-howweknow { display: block; }
.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-tile {
  display: grid; gap: 2px; align-content: start;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 12px 13px;
}
.stat-tile__n { font-size: 1.5rem; font-weight: 800; line-height: 1.05; color: var(--teal); font-variant-numeric: tabular-nums; }
.stat-tile__label { font-size: 0.74rem; color: var(--muted); line-height: 1.2; }

/* ---------------- Study-summary popover (takeaway-first) ---------------- */
.study-summary { display: grid; gap: 13px; }
.study-summary__id h3 { margin: 4px 0 3px; font-size: 1.05rem; }
.study-summary__id .pill { margin-bottom: 2px; }
.study-summary__take { margin: 0; font-weight: 650; }
.study-summary h4 { margin: 0 0 5px; }
.study-summary__design, .study-summary__find { display: grid; gap: 3px; }
.study-summary__design p, .study-summary__find p { margin: 0; font-size: 0.86rem; }
.study-summary__branches { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cmp-card--popover { border: 0; box-shadow: none; padding: 0; }
.indexed-source { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-3); padding: 11px 12px; display: grid; gap: 8px; }
.indexed-source h4 { margin: 0; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.indexed-source p { margin: 0; }
.indexed-source__status { font-size: 0.84rem; font-weight: 700; color: var(--ink); }
.indexed-source__details > summary { cursor: pointer; display: inline-flex; align-items: center; gap: 7px; color: var(--ink); font-size: 0.8rem; font-weight: 700; list-style: none; }
.indexed-source__details > summary::-webkit-details-marker { display: none; }
.indexed-source__details > summary::before { content: "▸"; font-size: 0.8em; transition: transform 0.12s ease; }
.indexed-source__details[open] > summary::before { transform: rotate(90deg); }
.indexed-source__outcomes { display: grid; gap: 8px; margin-top: 8px; }
.indexed-outcome { display: grid; gap: 5px; padding-top: 8px; border-top: 1px solid var(--line-soft); }
.indexed-source__outcomes .indexed-outcome:first-child { border-top: 0; padding-top: 0; }
.indexed-outcome__metric { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; font-size: 0.82rem; }
.indexed-outcome__pairs { display: grid; gap: 4px; }
.indexed-outcome__pair { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: baseline; font-size: 0.76rem; }
.indexed-outcome__pair span { color: var(--muted); min-width: 0; }
.indexed-outcome__pair strong { color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }
.indexed-bars { display: grid; gap: 7px; }
.indexed-bar { display: grid; gap: 3px; }
.indexed-bar__head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; font-size: 0.76rem; }
.indexed-bar__head span { color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.indexed-bar__head strong { color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }
.indexed-bar__track { height: 5px; border-radius: 999px; overflow: hidden; background: var(--line-soft); }
.indexed-bar__track span { display: block; height: 100%; border-radius: inherit; background: var(--muted); opacity: 0.45; }
.indexed-bar.is-best .indexed-bar__track span { background: var(--teal); opacity: 0.95; }
.indexed-bar.is-best .indexed-bar__head strong { color: var(--teal); }

.q-trial-inline { display: grid; gap: 8px; }
.q-trial-inline__head {
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; width: 100%;
  text-align: left; background: none; border: 0; padding: 0; color: var(--ink); cursor: pointer;
}
.q-trial-inline__head span:nth-child(2) { font-weight: 700; }
.q-trial-inline__head:hover span:nth-child(2) { color: var(--teal); }

/* ---------------- Popover (everything opens in place, one system) ---------------- */
.popover {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink);
  padding: 0; width: min(760px, 94vw); max-height: 86vh; box-shadow: var(--shadow);
}
.popover[open] { display: flex; flex-direction: column; }
.popover::backdrop { background: rgba(8, 13, 16, 0.5); backdrop-filter: blur(2px); }
.popover__bar {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 9px 8px 16px; border-bottom: 1px solid var(--line); background: var(--surface-3);
  border-radius: var(--radius) var(--radius) 0 0;
}
.popover__kicker {
  font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.popover__close {
  width: 28px; height: 28px; flex: 0 0 auto; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-weight: 800; line-height: 1;
}
.popover__close:hover { border-color: var(--teal); color: var(--teal); }
.popover__body { padding: 16px; overflow: auto; flex: 1 1 auto; min-height: 0; }
.popover__foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--line); }
.popover .guideline-card, .popover .technique-row { border: 0; padding: 0; }
.popover-node .hero-image { border-radius: var(--radius-sm); aspect-ratio: 16 / 9; }
.popover-node .detail-body { padding: 12px 2px 0; }

/* trial outcome charts at the top of an evidence popover */
.trial-outcomes { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-3); padding: 11px 12px; display: grid; gap: 11px; }
.trial-outcomes h4 { margin: 0 0 2px; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.trial-outcome { display: grid; gap: 7px; padding-top: 10px; border-top: 1px solid var(--line-soft); }
.trial-outcomes h4 + .trial-outcome { border-top: 0; padding-top: 0; }
.trial-outcome__metric { margin: 0; font-size: 0.82rem; }
.trial-outcome .cmp-note { margin: 0; }

/* node "evidence at a glance" */
.ev-glance { margin: 12px 0 0; border-top: 1px solid var(--line); padding-top: 11px; display: grid; gap: 9px; }
.ev-glance > h4 { margin: 0; color: var(--ink); font-size: 0.84rem; }
.cmp-mini-row { display: grid; gap: 8px; }
.cmp-mini {
  display: grid; gap: 7px; text-align: left; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-3); padding: 10px 11px; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.cmp-mini:hover { border-color: var(--teal); box-shadow: var(--shadow-sm); }
.cmp-mini__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; font-size: 0.8rem; line-height: 1.25; }
.cmp-mini__why { font-size: 0.7rem; font-weight: 700; color: var(--ink); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cmp-mini__role { font-size: 0.58rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.cmp-mini__role.role-efficacy, .cmp-mini__role.role-efficacy-safety { border-color: var(--teal); background: var(--teal-soft); color: var(--teal); }
/* Safety is a category, not the gate verdict: stays neutral (base chip) so amber
   means "caution" only on the gate. The other role accents (teal/indigo/rust) are
   off the gate palette and may stay. */
.cmp-mini__role.role-safety { /* inherits the neutral base chip */ }
.cmp-mini__role.role-alternative, .cmp-mini__role.role-why-not-the-alternative, .cmp-mini__role.role-trade-off { border-color: var(--indigo); background: var(--indigo-soft); color: var(--indigo); }
.cmp-mini__role.role-case-modifier { border-color: var(--rust); background: var(--rust-soft); color: var(--rust); }
.cmp-mini__metric { font-size: 0.76rem; font-weight: 700; }
.cmp-mini__metric em { font-style: normal; font-weight: 600; color: var(--muted); }
.cmp-mini__caveat { font-size: 0.66rem; line-height: 1.3; color: var(--amber); }
/* Studied-size chip on a chart row, tinted teal when it fits the current case size. */
.size-badge { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: 0.68rem; font-weight: 700; white-space: nowrap; vertical-align: middle; }
.size-badge.is-match { border-color: var(--teal); background: var(--teal-soft); color: var(--teal); }
.size-badge.is-extrap { border-color: var(--amber); border-style: dashed; background: var(--surface-2); color: var(--amber); }
.size-badge.is-unknown { border-style: dashed; }
.cmp-mini .size-badge { margin-left: 0; }
.lib-card__head .size-badge { margin-left: 0; }
.cmp-mini__read { display: block; }
.ev-group { display: grid; gap: 4px; }
.ev-group__label { display: flex; align-items: center; gap: 6px; font-size: 0.66rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.ev-group .ev-chips { margin-top: 0; }
/* "Show all sources", the case-relevant supporting trials, collapsed by default
   (the curated charts above are the signal). Native <details>, no JS. */
.ev-glance__more > summary { cursor: pointer; font-size: 0.8rem; font-weight: 700; color: var(--ink); padding: 8px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); list-style: none; display: inline-flex; align-items: center; gap: 7px; }
.ev-glance__more > summary:hover { border-color: var(--teal); color: var(--teal); }
.ev-glance__more > summary::-webkit-details-marker { display: none; }
.ev-glance__more > summary::before { content: "▸"; font-size: 0.8em; transition: transform 0.12s ease; }
.ev-glance__more[open] > summary::before { transform: rotate(90deg); }
.ev-glance__more-body { display: grid; gap: 9px; padding-top: 8px; }
/* "Show all sources" renders full bar-chart cards (reusing the library card). */
.ev-glance__libs .lib-card:last-child { margin-bottom: 0; }
@media (prefers-reduced-motion: reduce) { .ev-glance__more > summary::before { transition: none; } }

/* ---------------- Dormant Teaching surface: the polypectomy journey ---------------- */
.teaching-view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
.teach-intro { margin-bottom: 10px; min-width: 0; }
.teach-intro p { margin: 0 0 9px; }
.teach-rail { display: flex; flex-wrap: nowrap; gap: 6px; min-width: 0; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.teach-chip { flex: 0 0 auto; padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 0.76rem; font-weight: 700; white-space: nowrap; }
.teach-chip:hover { border-color: var(--teal); color: var(--teal); }
.teach-chip.is-in-plan { border-color: var(--teal); color: var(--teal); background: var(--teal-soft); }
.teach-chapter { border-top: 1px solid var(--line); }
.teach-chapter > summary { display: flex; align-items: baseline; gap: 10px; padding: 13px 2px; cursor: pointer; list-style: none; }
.teach-chapter > summary::-webkit-details-marker { display: none; }
.teach-chapter__n { flex: 0 0 auto; width: 22px; height: 22px; display: inline-grid; place-items: center; border-radius: 999px; background: var(--teal-soft); color: var(--teal); font-size: 0.74rem; font-weight: 800; }
.teach-chapter__t { display: grid; gap: 2px; min-width: 0; }
.teach-chapter__t > strong { font-size: 0.95rem; color: var(--ink); }
.teach-chapter[open] .teach-chapter__n { background: var(--teal); color: var(--on-accent); }
.teach-chapter.is-in-plan > summary .teach-chapter__n { background: var(--teal); color: var(--on-accent); }
.teach-chapter__body { display: grid; gap: 12px; padding: 2px 0 16px; }
.teach-card { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-3); padding: 12px; }
.teach-card.is-in-plan { border-color: var(--teal); box-shadow: inset 3px 0 0 var(--teal); }
.teach-card__head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.teach-inplan { margin-left: auto; font-size: 0.66rem; font-weight: 800; color: var(--teal); background: var(--teal-soft); border-radius: 999px; padding: 2px 7px; }
.teach-card .callout { margin: 0 0 10px; }
.teach-card .two-col { margin: 0; }
.teach-card--jump { background: var(--surface); border-style: dashed; }
.teach-stop { margin: 0; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--danger); border-left: 4px solid var(--danger); background: var(--danger-soft); color: var(--danger); font-size: 0.82rem; font-weight: 600; }
.teach-pointer { margin: 2px 0 0; }
/* Pronounced off-label flag (pedunculated surface read), shared with the selector. */
.surface-caveat { margin: 10px 0 0; padding: 8px 11px 8px 12px; border-left: 3px solid var(--amber); border-radius: var(--radius-sm); background: var(--amber-soft); font-size: 0.75rem; line-height: 1.45; color: var(--ink); }
.surface-caveat__mark { color: var(--amber); font-weight: 700; margin-right: 3px; }
.rarity-note { margin: 10px 0 0; padding: 8px 11px 8px 12px; border-left: 3px solid var(--indigo); border-radius: var(--radius-sm); background: var(--indigo-soft); font-size: 0.75rem; line-height: 1.45; color: var(--ink); }
.rarity-note__mark { color: var(--indigo); font-weight: 700; margin-right: 3px; }
@media (prefers-reduced-motion: reduce) {}

/* ---------------- Feedback ---------------- */
.feedback-dialog { width: min(680px, 94vw); }
.feedback-form { padding: 16px; display: grid; gap: 13px; overflow: auto; }
.feedback-field > span, .feedback-text-wrap > span {
  font-size: 0.66rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
}
.feedback-field, .feedback-text-wrap { display: grid; gap: 5px; }
.feedback-text {
  width: 100%; min-height: 132px; resize: vertical; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--ink);
  padding: 10px 11px; font: inherit; line-height: 1.4;
}
.feedback-text:focus { outline: 3px solid color-mix(in srgb, var(--teal) 35%, transparent); outline-offset: 2px; }
.feedback-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.feedback-notes { display: grid; gap: 8px; }
.feedback-note {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-3); padding: 9px 10px; display: grid; gap: 5px;
}
.feedback-note p { margin: 0; font-size: 0.84rem; overflow-wrap: anywhere; }
.feedback-note__meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 0.7rem; color: var(--muted); }
.feedback-empty { margin: 0; color: var(--muted); font-size: 0.84rem; }
.feedback-actions {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center;
  padding-top: 11px; border-top: 1px solid var(--line);
}
.feedback-status { color: var(--muted); font-size: 0.78rem; min-width: 0; overflow-wrap: anywhere; }


/* ---------------- Responsive ---------------- */
@media (max-width: 1180px) {
  .workspace { grid-template-columns: minmax(232px, 280px) minmax(380px, 1fr); }
}
@media (max-width: 920px) {
  .quiz-card { grid-template-columns: 1fr; }
  .quiz-figure img { min-height: 170px; max-height: 230px; }
}
@media (max-width: 820px) {
  .topbar { position: static; align-items: flex-start; flex-direction: column; gap: 12px; }
  .workspace { grid-template-columns: 1fr; padding: 10px; }
  .case-panel { position: static; max-height: none; }
  .two-col, .classification-card, .adjunct-grid, .gate-banner, .step-dossier__grid { grid-template-columns: 1fr; }
  .cmp-row { grid-template-columns: 1fr; }
  .cmp-head { flex-direction: column; gap: 8px; }
  .diff-row { grid-template-columns: 1fr; gap: 4px; }
  .diff-row__label { padding-top: 0; }
  .diff-row__cols { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .topbar { padding: 13px; }
  .topbar__meta { justify-content: flex-start; }
  .tab { padding: 11px 11px; font-size: 0.82rem; }
  .tab-page { padding: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .hero-image { aspect-ratio: 4 / 3; }
  .stat-tiles { grid-template-columns: repeat(2, 1fr); }
  .feedback-actions { grid-template-columns: 1fr; }
  .feedback-actions .primary-button, .feedback-actions .ghost-button { width: 100%; }
  .feedback-status { min-height: 18px; }
}

/* ---------------- Print: the Console brief as a clean one-pager ---------------- */
@page { margin: 14mm; }
@media print {
  html, html[data-theme="dark"] {
    --bg: #ffffff; --surface: #ffffff; --surface-2: #f1f4f5; --surface-3: #f7f9fa;
    --ink: #14202a; --muted: #5a6871; --line: #c9d3d8; --line-soft: #e6ecee;
    --teal: #0f766e; --teal-soft: #e2f1ef; --rust: #a74425; --rust-soft: #f6e1d8;
    --indigo: #3f54a0; --indigo-soft: #e0e5fb; --green: #2f6a37; --green-soft: #dff0db;
    --amber: #8a5d0c; --amber-soft: #f4e9cd; --danger: #9f2434; --danger-soft: #f3d8de;
    --on-accent: #ffffff; --shadow: none; --shadow-sm: none;
  }
  .topbar, .case-panel, .tabs, #themeToggle, .popover, .compare-card { display: none !important; }
  .workspace { display: block; padding: 0; }
  .flow-panel { border: 0; box-shadow: none; }
  .tab-page { display: none !important; }
  #tab-console { display: block !important; }
  .brief-block, .primary-card, .gate-banner { break-inside: avoid; box-shadow: none; }
  .console-view::before {
    content: "Colorectal Polypectomy Decision Tool, recommendation (evidence to June 2026; teaching aid, not a directive)";
    display: block; font-size: 0.74rem; color: #5a6871; border-bottom: 1px solid #c9d3d8;
    padding-bottom: 6px; margin-bottom: 10px;
  }
  .link-row a[href]::after { content: " (" attr(href) ")"; font-size: 0.68rem; color: #555; }
}

/* Tab switches cross-fade via the View Transitions API (JS skips it under
   prefers-reduced-motion and on unsupporting browsers). */
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 0.16s; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
