/* ==========================================================================
   VERDICT — POLISH LAYER
   Loaded after every other stylesheet. One calm editorial system:
   - warm paper background, near-black ink, ONE accent (deep red)
   - serif for headlines, sans for everything else, mono only for IDs/dates
   - sentence-case labels, hairline borders, generous whitespace
   ========================================================================== */

:root {
  /* Graphite: neutral greys + slate. No hue that a political party owns. */
  --bg: #f6f6f5;
  --bg-subtle: #ececea;
  --surface: #ffffff;
  --surface-alt: #f0f0ee;

  --ink: #151515;
  --ink-secondary: #444444;
  --ink-muted: #6a6a6a;
  --ink-faint: #8c8c8c;

  --border: #dcdcd9;
  --border-subtle: #e8e8e5;
  --border-strong: #151515;

  --accent: #334155;
  --accent-hover: #1e293b;
  --accent-soft: #eef1f5;
  --accent-border: #c9d1db;

  --dark: #1c1d1f;

  --font-serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-sans: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-display: var(--font-serif);

  --max-width: 1200px;
  --radius-xs: 3px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;

  --space-section: clamp(56px, 8vw, 104px);
  --shadow-card: 0 1px 2px rgba(20, 21, 22, 0.04), 0 4px 16px rgba(20, 21, 22, 0.04);
}

/* ---------- Base ---------- */

html { scroll-padding-top: 88px; }

body {
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  color: var(--ink);
  text-wrap: balance;
}

h1 { font-size: clamp(2.4rem, 5.2vw, 3.9rem); line-height: 1.06; letter-spacing: -0.022em; }
h2 { font-size: clamp(1.7rem, 3.2vw, 2.3rem); line-height: 1.15; letter-spacing: -0.015em; }
h3 { font-size: 1.3rem; line-height: 1.28; letter-spacing: -0.005em; }
h4 { font-size: 1.1rem; line-height: 1.3; }

p { text-wrap: pretty; }

a { text-underline-offset: 3px; text-decoration-thickness: 1px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

::selection { background: #dfe3e9; color: var(--ink); }

.main-wrapper {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px 96px;
}

/* Section rhythm: one consistent gap between top-level blocks */
.main-wrapper > section,
.main-wrapper > .dossier-block {
  margin-top: var(--space-section);
}
.main-wrapper > section:first-child { margin-top: 0; }

/* Skip link */
.skip-link {
  position: fixed;
  top: -64px;
  left: 16px;
  z-index: 300;
  padding: 10px 16px;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-md);
  font-weight: 600;
  transition: top 0.15s ease;
}
.skip-link:focus { top: 12px; }

/* ---------- Eyebrow / label system (replaces the mono-caps soup) ---------- */

.kicker,
.section-num,
.layer-num,
.channel-label,
.contact-kicker-row,
.protocol-num,
.trust-center-badge,
.coverage-bar-title {
  font-family: var(--font-sans) !important;
  font-size: 0.75rem !important;
  font-weight: 700 !important;
  letter-spacing: 0.1em !important;
  text-transform: uppercase !important;
  color: var(--accent) !important;
}

.section-meta,
.filter-label,
.stat-label,
.metric-lbl,
.coverage-bar-meta,
.showcase-updated,
.search-try-prompts > span:first-child {
  font-family: var(--font-sans) !important;
  font-size: 0.8125rem !important;
  letter-spacing: 0.01em !important;
  text-transform: none !important;
  font-weight: 500 !important;
  color: var(--ink-muted) !important;
}

/* ---------- Buttons ---------- */

.btn,
.btn-primary,
.btn-secondary,
.btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: none;
  text-decoration: none;
  padding: 11px 20px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.btn-primary,
.btn.btn-primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.btn-primary:hover,
.btn.btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-secondary,
.btn-outline,
.btn.btn-outline {
  background: transparent;
  color: var(--ink);
  border-color: var(--border);
}
.btn-secondary:hover,
.btn-outline:hover,
.btn.btn-outline:hover {
  border-color: var(--ink);
  background: var(--surface);
  color: var(--ink);
}

.btn-sm { padding: 8px 14px; font-size: 0.875rem; }

/* ---------- Top strip (secondary links) ---------- */

.top-strip { background: var(--dark); color: #cfd0d3; font-size: 0.82rem; }
.top-strip-inner { max-width: var(--max-width); margin: 0 auto; padding: 0 24px; height: 34px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.strip-links { display: flex; align-items: center; gap: 22px; }
.top-strip a { color: inherit; text-decoration: none; font-weight: 500; }
.top-strip a:hover { color: #fff; text-decoration: underline; text-underline-offset: 3px; }
.top-strip a[aria-current="page"] { color: #fff; font-weight: 600; }

/* ---------- Site header: large at the top, shrinks as you scroll ----------
   --p runs 0 (top of page) to 1 (scrolled). site-header.js sets it with easing,
   so the wordmark, bar height, blur and border all move together. */

.site-header {
  --hl: 88px;            /* height at the top of the page */
  --hs: 60px;            /* height once scrolled */
  --p: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--hl);     /* constant, so content never jumps while the bar shrinks */
  pointer-events: none;
}
.site-header-inner {
  position: relative;
  pointer-events: auto;
  height: calc(var(--hl) - (var(--hl) - var(--hs)) * var(--p));
  max-width: none;
  padding: 0 max(24px, calc((100% - var(--max-width)) / 2 + 24px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  background-color: rgb(246 246 245 / calc(0.88 * var(--p)));
  -webkit-backdrop-filter: saturate(1.6) blur(calc(22px * var(--p)));
  backdrop-filter: saturate(1.6) blur(calc(22px * var(--p)));
  border-bottom: 1px solid rgb(21 21 21 / calc(0.11 * var(--p)));
  box-shadow: 0 8px 28px rgb(20 21 22 / calc(0.06 * var(--p)));
}

.hdr-left { display: flex; align-items: center; gap: 30px; min-width: 0; }
.hdr-right { display: flex; align-items: center; justify-content: flex-end; gap: 12px; min-width: 0; }

.brand { display: inline-flex; align-items: center; gap: calc(14px - 3px * var(--p)); color: var(--ink); text-decoration: none; flex: 0 0 auto; }
.brand-mark { width: calc(44px - 12px * var(--p)); height: calc(44px - 12px * var(--p)); border-radius: calc(10px - 2px * var(--p)); display: block; }
.brand-wordmark {
  font-family: var(--font-serif);
  font-size: calc(1.85rem - 0.55rem * var(--p));
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  line-height: 1;
}
.brand:hover .brand-wordmark { color: var(--accent); }

.site-nav { display: flex; align-items: center; gap: 4px; }
.site-nav a { position: relative; padding: 8px 12px; font-size: 1rem; font-weight: 600; color: var(--ink-secondary); text-decoration: none; border-radius: var(--radius-sm); white-space: nowrap; }
.site-nav a:hover { color: var(--ink); background: rgba(21, 21, 21, 0.06); }
.site-nav a[aria-current="page"] { color: var(--ink); }
.site-nav a[aria-current="page"]::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 2px; height: 2px; background: var(--accent); border-radius: 2px; }
.nav-extra, .nav-cta-mobile { display: none !important; }

/* The search pill keeps its original design; it now sits in the middle of the bar. */
.header-search {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px 0 12px;
  font-size: 0.9rem; font-weight: 500; color: var(--ink-muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  text-decoration: none; transition: border-color 0.15s ease, color 0.15s ease;
}
.header-search:hover { border-color: var(--ink-muted); color: var(--ink); }
.header-search kbd { font-family: var(--font-mono); font-size: 0.7rem; line-height: 1; padding: 3px 6px; color: var(--ink-muted); background: var(--bg-subtle); border: 1px solid var(--border-subtle); border-radius: 4px; }

.header-cta { height: 38px; padding-top: 0; padding-bottom: 0; }

/* "More" appears once the top strip has scrolled away, so those links stay reachable. */
.more { position: relative; opacity: 0; visibility: hidden; transition: opacity 0.35s ease, visibility 0.35s; }
.site-header.is-compact .more { opacity: 1; visibility: visible; }
.more-btn { display: inline-flex; align-items: center; gap: 4px; height: 38px; padding: 0 10px; background: transparent; border: 0; border-radius: var(--radius-sm); font: 600 0.95rem var(--font-sans); color: var(--ink-secondary); cursor: pointer; }
.more-btn:hover { color: var(--ink); background: rgba(21, 21, 21, 0.06); }
.more-menu { display: none; position: absolute; right: 0; top: calc(100% + 8px); min-width: 200px; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 16px 36px rgba(20, 21, 22, 0.14); flex-direction: column; }
.more.open .more-menu { display: flex; }
.more-menu a { padding: 10px 12px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: 0.95rem; }
.more-menu a:hover { background: var(--bg-subtle); }
.more-menu a[aria-current="page"] { font-weight: 700; }

.nav-toggle { display: none; width: 40px; height: 38px; padding: 0; background: transparent; border: 1px solid var(--border); border-radius: var(--radius-md); cursor: pointer; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.nav-toggle span { display: block; width: 16px; height: 1.5px; background: var(--ink); transition: transform 0.2s ease, opacity 0.2s ease; }
.site-header.is-open .nav-toggle span:nth-child(1) { transform: translateY(5.5px) rotate(45deg); }
.site-header.is-open .nav-toggle span:nth-child(2) { opacity: 0; }
.site-header.is-open .nav-toggle span:nth-child(3) { transform: translateY(-5.5px) rotate(-45deg); }

/* Narrower desktops: the search pill stays roughly central but is no longer pinned to the exact middle, so nothing collides */
@media (max-width: 1099px) {
  .site-header-inner { display: flex; gap: 16px; }
  .header-search { margin-inline: auto; }
  .hdr-left { flex: 1 1 auto; }
  .hdr-right { flex: 0 0 auto; }
}

@media (max-width: 860px) {
  .top-strip { display: none; }
  .site-header { --hl: 66px; --hs: 56px; }
  .site-header-inner { padding: 0 16px; gap: 10px; }
  .brand-mark { width: calc(38px - 8px * var(--p)); height: calc(38px - 8px * var(--p)); }
  .brand-wordmark { font-size: calc(1.5rem - 0.38rem * var(--p)); }
  .header-search span, .header-search kbd { display: none; }
  .header-search { width: 38px; padding: 0; justify-content: center; }
  .more { display: none; }
  .nav-toggle { display: inline-flex; }

  .site-nav { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; align-items: stretch; gap: 0; padding: 8px 16px 16px; background: var(--bg); border-bottom: 1px solid var(--border); box-shadow: 0 16px 32px rgba(20, 21, 22, 0.1); }
  .site-header.is-open .site-nav { display: flex; }
  .site-nav a { padding: 14px 8px; font-size: 1.05rem; border-bottom: 1px solid var(--border-subtle); border-radius: 0; }
  .site-nav a[aria-current="page"]::after { display: none; }
  .site-nav a[aria-current="page"] { color: var(--accent); }
  .site-nav .nav-extra { display: block !important; }
  .site-nav .nav-cta-mobile { display: block !important; margin-top: 12px; padding: 13px 16px; text-align: center; font-weight: 700; color: #fff; background: var(--ink); border: 0; border-radius: var(--radius-md); }
  .site-nav .nav-cta-mobile:hover { background: var(--accent); color: #fff; }
}
@media (max-width: 520px) {
  .header-cta { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .more { transition: none; }
}

/* Old chrome, in case any page still carries it */
.top-utility, .masthead { display: none !important; }

/* ---------- Page tools (case / dossier switchers) ---------- */

.page-tools {
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border-subtle);
}
.page-tools-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.page-tools .crumb {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-secondary);
  text-decoration: none;
}
.page-tools .crumb:hover { color: var(--accent); }
.page-tools-title {
  font-size: 0.875rem;
  color: var(--ink-muted);
  padding-left: 20px;
  border-left: 1px solid var(--border);
}
.page-tools-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.page-tools label { font-size: 0.85rem; color: var(--ink-muted); font-weight: 500; }
.page-tools select {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  padding: 7px 32px 7px 12px;
  max-width: min(420px, 62vw);
  color: var(--ink);
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.page-tools .challenge-pill-btn {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 7px 14px;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent-border);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.page-tools .challenge-pill-btn:hover { background: var(--accent-soft); border-color: var(--accent); }

@media (max-width: 640px) {
  .page-tools-inner { padding: 10px 16px; gap: 10px 14px; }
  .page-tools-title { display: none; }
  .page-tools-right { margin-left: 0; width: 100%; }
  .page-tools select { flex: 1 1 auto; max-width: none; }
}

/* ---------- Footer ---------- */

.site-footer {
  position: relative;
  isolation: isolate;
  margin-top: 0;
  padding: clamp(48px, 6vw, 80px) 0 0;
  color: #b3b3b3;
  background:
    radial-gradient(60% 80% at 100% 0%, rgba(148, 163, 184, 0.14), transparent 62%),
    #17181a;
  border-top: 0;
  border-radius: 28px 28px 0 0;
  overflow: hidden;
}
.site-footer::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.06) 1px, transparent 1.3px) 0 0 / 22px 22px;
  -webkit-mask-image: linear-gradient(160deg, #000, transparent 55%);
  mask-image: linear-gradient(160deg, #000, transparent 55%);
}
.site-footer .brand-mark { width: 38px; height: 38px; border-radius: 10px; display: block; }
.footer-inner { max-width: var(--max-width); margin: 0 auto; padding: 0 24px; }
.footer-top {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  gap: 48px;
  padding-bottom: 56px;
}
.footer-brand .brand-wordmark { color: #efefef; font-size: 1.2rem; letter-spacing: 0.14em; }
.footer-brand .footer-brand-row { display: flex; align-items: center; gap: 11px; margin-bottom: 16px; }
.footer-brand p { font-size: 0.95rem; line-height: 1.6; color: #949494; max-width: 34ch; }
.footer-col h5 {
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #efefef;
  margin-bottom: 16px;
}
.footer-col ul { list-style: none; display: grid; gap: 10px; }
.footer-col a {
  font-size: 0.95rem;
  color: #b3b3b3;
  text-decoration: none;
}
.footer-col a:hover { color: #fff; text-decoration: underline; }
.footer-col .footer-email {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  word-break: break-all;
}
.footer-bottom {
  display: flex;
  justify-content: space-between;
  gap: 16px 32px;
  flex-wrap: wrap;
  padding: 24px 0 32px;
  border-top: 1px solid #2c2e31;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: #8a8d92;
}

@media (max-width: 900px) {
  .footer-top { grid-template-columns: 1fr 1fr; gap: 40px 32px; }
  .footer-brand { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  .footer-top { grid-template-columns: 1fr; }
}

/* ---------- Reading progress ---------- */
.scroll-progress-line { top: 0; z-index: 120; height: 2px; }
.scroll-progress-fill { background: var(--accent); }

/* ---------- Layout safety (all pages) ---------- */
/* Doc / case two-column layouts: the single column must be allowed to shrink */
.doc-layout > *, .case-page-layout > * { min-width: 0; }
@media (max-width: 900px) {
  .doc-layout, .case-page-layout { grid-template-columns: minmax(0, 1fr) !important; }
  .doc-layout { margin-top: 16px; }
  pre, .code-block, .endpoint-code { max-width: 100%; overflow-x: auto; }
}

@media (max-width: 700px) {
  #api-content [style*="grid-template-columns"] { grid-template-columns: minmax(0, 1fr) !important; }
  .code-param-table { display: block; max-width: 100%; overflow-x: auto; }
}

code { overflow-wrap: anywhere; }
@media (max-width: 700px) {
  .dossier-table, .ledger-table { max-width: 100%; }
  .case-content-stream .dossier-table, .dossier-shell .dossier-table { display: block; overflow-x: auto; }
  .identity-badge { white-space: normal; }
}

@media (max-width: 520px) {
  .footer-top { grid-template-columns: 1fr 1fr; gap: 36px 20px; }
  .footer-brand, .footer-col:last-child { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  .coverage-metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Small screens: reclaim width from nested cards ---------- */
@media (max-width: 640px) {
  .main-wrapper { padding-left: 16px; padding-right: 16px; }
  .footer-inner { padding-left: 16px; padding-right: 16px; }
  .case-section { padding: 20px 16px !important; }
  .evidence-packet-card, .consistency-review-card { padding: 16px !important; }
  .packet-top-bar { flex-wrap: wrap; gap: 8px; }
  .consistency-review-card > div { flex-wrap: wrap; gap: 8px; }
  .audit-log-table, .dossier-table { display: block; max-width: 100%; overflow-x: auto; }
}

/* Dossier hero name: editorial, not billboard */
.dossier-title {
  font-size: clamp(2.4rem, 5.2vw, 3.9rem) !important;
  line-height: 1.05 !important;
  letter-spacing: -0.022em !important;
}

/* Fund page: let grid tiles shrink inside the card, scale the hero on phones */
.preset-selector-row, .preset-selector-row > * { min-width: 0; }
@media (max-width: 640px) {
  .preset-selector-row { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
  .fund-hero-title { font-size: clamp(1.9rem, 9vw, 2.6rem) !important; line-height: 1.08 !important; overflow-wrap: anywhere; }
}

/* ==========================================================================
   PREMIUM FINISH (all pages)
   One shape language for every control, a soft lift on primary actions,
   the hero entrance, and the back-to-top button. Uses !important only where
   the legacy rules in style.css do.
   ========================================================================== */

html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }

/* ---------- Buttons: 10px corners everywhere ---------- */
.btn,
.btn-primary,
.btn-secondary,
.btn-outline { border-radius: 10px !important; }

.btn-primary,
.btn.btn-primary {
  box-shadow: 0 1px 2px rgba(20, 21, 22, 0.14), 0 8px 18px -10px rgba(30, 41, 59, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
  transition: background-color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease !important;
}
.btn-primary:hover,
.btn.btn-primary:hover {
  box-shadow: 0 2px 4px rgba(20, 21, 22, 0.14), 0 14px 26px -12px rgba(30, 41, 59, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.1) !important;
}
.btn-primary:active,
.btn.btn-primary:active { transform: translateY(0) !important; }

.btn-secondary,
.btn-outline,
.btn.btn-outline {
  background: var(--surface) !important;
  border-color: var(--border) !important;
  box-shadow: 0 1px 2px rgba(20, 21, 22, 0.04);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}
.btn-secondary:hover,
.btn-outline:hover,
.btn.btn-outline:hover {
  border-color: var(--ink-faint) !important;
  box-shadow: 0 8px 18px -12px rgba(20, 21, 22, 0.35);
  transform: translateY(-1px);
}

/* ---------- Header controls ---------- */
.header-search { border-radius: 10px; box-shadow: 0 1px 2px rgba(20, 21, 22, 0.04); }
.header-search kbd { border-radius: 6px; }
.more-btn, .site-nav a { border-radius: 8px; }

@media (max-width: 860px) {
  /* Search and menu: one matching pair of icon buttons */
  .header-search,
  .nav-toggle {
    width: 40px;
    height: 40px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(20, 21, 22, 0.05);
  }
  .site-nav { border-radius: 0 0 20px 20px; }
  .site-nav .nav-cta-mobile { border-radius: 12px; }
}

/* ---------- Form fields ---------- */
.form-control { border-radius: 10px !important; }

/* ---------- Hero entrance: a short rise as the page opens ---------- */
@keyframes verdict-rise {
  from { opacity: 0; transform: translateY(12px); }
}
@media (prefers-reduced-motion: no-preference) {
  .page-hero > *,
  .hero-copy > *,
  .glance {
    animation: verdict-rise 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  }
  .page-hero > :nth-child(2), .hero-copy > :nth-child(2) { animation-delay: 0.06s; }
  .page-hero > :nth-child(3), .hero-copy > :nth-child(3) { animation-delay: 0.12s; }
  .page-hero > :nth-child(n+4), .hero-copy > :nth-child(n+4) { animation-delay: 0.18s; }
  .glance { animation-delay: 0.16s; }
}

/* ---------- Back to top ---------- */
.to-top {
  position: fixed;
  z-index: 90;               /* below the header (100) and every modal */
  right: max(22px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  padding: 0;
  color: var(--ink);
  background: rgb(255 255 255 / 0.88);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
  border: 0;
  border-radius: 50%;
  box-shadow: 0 14px 32px -12px rgba(20, 21, 22, 0.4), 0 2px 6px rgba(20, 21, 22, 0.08);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(0.9);
  transition: opacity 0.3s ease, visibility 0.3s, transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.to-top.is-visible { opacity: 1; visibility: visible; transform: none; }
.to-top:hover { color: #fff; background: var(--ink); box-shadow: 0 18px 36px -12px rgba(20, 21, 22, 0.55), 0 2px 6px rgba(20, 21, 22, 0.1); }
.to-top:active { transform: scale(0.94); }
.to-top:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 50%; }

.to-top-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); pointer-events: none; }
.to-top-track { fill: none; stroke: var(--border); stroke-width: 1.5; transition: stroke 0.2s ease; }
.to-top-fill { fill: none; stroke: var(--accent); stroke-width: 2.25; stroke-linecap: round; transition: stroke-dashoffset 0.12s linear, stroke 0.2s ease; }
.to-top:hover .to-top-track { stroke: rgba(255, 255, 255, 0.2); }
.to-top:hover .to-top-fill { stroke: #fff; }

.to-top-arrow {
  position: relative;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.to-top:hover .to-top-arrow { transform: translateY(-2px); }

.site-header[tabindex="-1"]:focus { outline: none; }

@media (max-width: 640px) {
  .to-top { width: 46px; height: 46px; right: max(14px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  .to-top, .to-top-arrow, .to-top-fill { transition: none; }
}
@media print {
  .to-top { display: none !important; }
}

/* ==========================================================================
   POP-UPS (every .modal-backdrop: source, evidence, diff, entity, API,
   challenge, comparison). Opens with a lift, closes with a short drop
   (js/dialogs.js keeps the class "is-closing" on for the exit), and turns
   into a bottom sheet on phones. "body" raises specificity over home.css.
   ========================================================================== */

@keyframes vd-fade-in  { from { opacity: 0; } }
@keyframes vd-fade-out { to { opacity: 0; } }
@keyframes vd-pop-in   { from { opacity: 0; transform: translateY(22px) scale(0.965); } }
@keyframes vd-pop-out  { to { opacity: 0; transform: translateY(12px) scale(0.98); } }
@keyframes vd-sheet-in  { from { transform: translateY(100%); } }
@keyframes vd-sheet-out { to { transform: translateY(100%); } }
@keyframes vd-pop-soft { from { opacity: 0; transform: translateY(6px) scale(0.98); } }

body .modal-backdrop {
  z-index: 200;
  padding: 24px;
  background: rgba(16, 17, 19, 0.46) !important;
  -webkit-backdrop-filter: blur(10px) saturate(1.15);
  backdrop-filter: blur(10px) saturate(1.15);
  overscroll-behavior: contain;
}
body .modal-backdrop.open,
body .modal-backdrop.active,
body .modal-backdrop.is-closing { display: flex !important; }
body .modal-backdrop.is-closing { pointer-events: none; }

/* The dialog frames; its content scrolls inside, so the close button never scrolls away */
body .modal-backdrop .modal-dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  max-height: min(88vh, calc(100dvh - 48px));
  padding: 0 !important;
  overflow: hidden !important;
  background: var(--surface) !important;
  border: 0 !important;
  border-radius: 24px !important;
  box-shadow:
    0 0 0 1px rgba(20, 21, 22, 0.06),
    0 12px 28px -12px rgba(10, 11, 12, 0.28),
    0 44px 96px -32px rgba(10, 11, 12, 0.55) !important;
}
body .modal-backdrop .modal-dialog.evidence-modal-dialog { max-width: 780px; }
body .modal-backdrop .modal-dialog > :not(.modal-close-btn) {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(24px, 4vw, 36px);
  scrollbar-width: thin;
}
/* Keep the first heading clear of the close button */
body .modal-backdrop .modal-dialog > :not(.modal-close-btn) > :is(h2, h3, h4, .modal-title, .dialog-title):nth-child(-n+3) { padding-right: 44px; }

body .modal-backdrop .modal-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0 0 2px;
  font-size: 1.45rem;
  line-height: 1;
  color: var(--ink-secondary);
  background: rgb(240 240 238 / 0.92) !important;
  border: 1px solid var(--border-subtle) !important;
  border-radius: 50% !important;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
body .modal-backdrop .modal-close-btn:hover { color: #fff; background: var(--ink) !important; border-color: var(--ink) !important; transform: rotate(90deg); }
body .modal-backdrop .modal-close-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 50% !important; }

@media (prefers-reduced-motion: no-preference) {
  body .modal-backdrop.open,
  body .modal-backdrop.active { animation: vd-fade-in 0.28s ease both; }
  body .modal-backdrop.open .modal-dialog,
  body .modal-backdrop.active .modal-dialog { animation: vd-pop-in 0.5s cubic-bezier(0.16, 1, 0.3, 1) both; }
  body .modal-backdrop.is-closing { animation: vd-fade-out 0.22s ease both; }
  body .modal-backdrop.is-closing .modal-dialog { animation: vd-pop-out 0.22s ease both; }
}

/* Phones: a bottom sheet with a grab handle */
@media (max-width: 640px) {
  body .modal-backdrop { align-items: flex-end; padding: 0; }
  body .modal-backdrop .modal-dialog,
  body .modal-backdrop .modal-dialog.evidence-modal-dialog {
    max-width: none;
    max-height: 90dvh;
    border-radius: 24px 24px 0 0 !important;
  }
  body .modal-backdrop .modal-dialog::before {
    content: "";
    flex: 0 0 auto;
    width: 40px;
    height: 4px;
    margin: 10px auto 0;
    background: var(--border);
    border-radius: 2px;
  }
  body .modal-backdrop .modal-dialog > :not(.modal-close-btn) { padding: 18px 18px calc(24px + env(safe-area-inset-bottom)); }
  body .modal-backdrop .modal-close-btn { top: 14px; right: 14px; width: 36px; height: 36px; }
}
@media (max-width: 640px) and (prefers-reduced-motion: no-preference) {
  body .modal-backdrop.open .modal-dialog,
  body .modal-backdrop.active .modal-dialog { animation: vd-sheet-in 0.45s cubic-bezier(0.16, 1, 0.3, 1) both; }
  body .modal-backdrop.is-closing .modal-dialog { animation: vd-sheet-out 0.22s ease-in both; }
}

.has-modal .to-top { opacity: 0; visibility: hidden; }

/* ---------- Forms inside dialogs ---------- */
.dialog-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}
.dialog-kicker::before { content: ""; width: 6px; height: 6px; background: currentColor; border-radius: 50%; }
.dialog-title { margin: 8px 0 8px; font-size: clamp(1.35rem, 2.6vw, 1.65rem); line-height: 1.2; letter-spacing: -0.015em; }
.dialog-lede { margin: 0 0 20px; font-size: 0.95rem; line-height: 1.55; color: var(--ink-secondary); }
.dialog-form { display: grid; gap: 16px; }
.dialog-field { display: grid; gap: 6px; }
.dialog-label { font-size: 0.86rem; font-weight: 600; color: var(--ink); }
.dialog-req { color: #b3261e; }
.dialog-optional { margin-left: 4px; font-weight: 400; color: var(--ink-muted); }
.dialog-input {
  width: 100%;
  padding: 11px 13px;
  font: 400 0.95rem/1.45 var(--font-sans);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: inset 0 1px 2px rgba(20, 21, 22, 0.04);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}
textarea.dialog-input { resize: vertical; min-height: 72px; }
.dialog-input::placeholder { color: var(--ink-faint); }
.dialog-input:hover { border-color: var(--ink-faint); }
.dialog-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(51, 65, 85, 0.14); }
.dialog-input[readonly] { color: var(--ink-secondary); background: var(--surface-alt); border-style: dashed; }
.dialog-input-mono { font-family: var(--font-mono); font-size: 0.85rem; }
.dialog-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding-top: 4px; }
.dialog-actions .btn { margin-left: auto; }
.dialog-status { font-size: 0.9rem; line-height: 1.5; color: var(--ink-secondary); }
.dialog-status:empty { display: none; }
.dialog-status:not(:empty) {
  padding: 11px 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
}
.dialog-status b { color: var(--ink); }
.dialog-status code { font-family: var(--font-mono); font-size: 0.82rem; overflow-wrap: anywhere; }
.dialog-status a { font-weight: 600; color: var(--accent); }
.dialog-status.is-ok { color: #1e4d33; background: #e9f3ed; border-color: #cfe4d7; }
.dialog-status.is-ok b { color: #1e5e3a; }
.dialog-status.is-error { color: var(--ink); background: #fbf1ef; border-color: #efd3cf; }
.dialog-status.is-error b { color: #9a2a22; }
.dialog-status.is-pending { color: var(--ink-muted); }
.captcha-slot:empty { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .dialog-status:not(:empty) { animation: vd-pop-soft 0.35s cubic-bezier(0.16, 1, 0.3, 1) both; }
}
@media (max-width: 640px) {
  /* Side-by-side boxes inside dialogs stack on phones */
  body .modal-backdrop .modal-dialog [style*="grid-template-columns"] { grid-template-columns: minmax(0, 1fr) !important; }
}
