/* ============================================================================
   Design system — hand-written, dependency-free.

   No build step, no framework, no CDN: the CSP stays strict and every byte
   here is readable in one file. Order below is deliberate —
   tokens → base → layout → chrome → components → pages → utilities → print.

   Light and dark are designed as a pair from the same semantic tokens; neither
   is derived from the other. Every foreground/background pair in the token
   block is checked against WCAG AA (see scripts/check_contrast.py).
   ========================================================================= */

/* ── Tokens: non-colour ─────────────────────────────────────────────────── */

:root {
  color-scheme: light dark;

  /* Spacing scale — all vertical rhythm comes from these. */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;
  --space-9: 6rem;

  /* Radii */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 22px;
  --radius-pill: 999px;

  /* Motion — subtle, purposeful, always behind prefers-reduced-motion. */
  --dur-1: 120ms;
  --dur-2: 160ms;
  --dur-3: 220ms;
  --ease: cubic-bezier(0.2, 0.6, 0.3, 1);

  /* Stacking */
  --z-sticky: 50;
  --z-header: 100;
  --z-drawer: 200;
  --z-modal: 300;
  --z-toast: 400;

  /* Type */
  --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", "Cascadia Mono", Menlo,
    Consolas, monospace;

  --fs-hero: clamp(2.05rem, 1.35rem + 3.1vw, 3.4rem);
  --fs-h1: clamp(1.7rem, 1.32rem + 1.6vw, 2.4rem);
  --fs-h2: clamp(1.22rem, 1.12rem + 0.5vw, 1.5rem);
  --fs-h3: 1.0625rem;
  --fs-lede: clamp(1.02rem, 0.98rem + 0.25vw, 1.15rem);
  --fs-body: 1rem;
  --fs-sm: 0.875rem;
  --fs-xs: 0.78rem;

  --lh-heading: 1.25;
  --lh-body: 1.6;

  /* Containers */
  --w-narrow: 26rem;
  --w-prose: 68ch;
  --w-default: 62rem;
  --w-wide: 1100px;
  --gutter: clamp(1rem, 0.55rem + 2vw, 2rem);

  --header-h: 60px;
}

/* ── Tokens: colour — light ─────────────────────────────────────────────── */

:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-inset: #f2f5f9;
  --surface-hover: #f7f9fc;
  --surface-overlay: rgba(15, 23, 41, 0.42);

  --text-primary: #0f1729;
  --text-secondary: #545f75;
  --text-tertiary: #636d85;
  --text-on-accent: #ffffff;

  --border-subtle: #e4e8ef;
  --border-strong: #cbd3e0;
  /* Interactive boundaries need 3:1 (WCAG 1.4.11); the two above
     are decorative hairlines and are exempt. */
  --border-control: #848d9c;

  --accent: #1c50d8;
  --accent-hover: #17419f;
  --accent-solid: #1c50d8;
  --accent-solid-hover: #17419f;
  --accent-bg: #eef3ff;
  --accent-border: #c3d5ff;

  --positive: #10682e;
  --positive-bg: #e7f6ec;
  --positive-border: #aad9ba;

  --negative: #c22630;
  --negative-bg: #fdecec;
  --negative-border: #f2b8b8;

  --warning: #855400;
  --warning-bg: #fdf3e0;
  --warning-border: #e9cd9c;

  --danger-fg: #ffffff;
  --focus: #1c50d8;
  --chart-grid: #e7ebf2;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 2px 4px -1px rgba(16, 24, 40, 0.05), 0 10px 20px -6px rgba(16, 24, 40, 0.1);
  --shadow-lg: 0 10px 24px -8px rgba(16, 24, 40, 0.14), 0 26px 50px -16px rgba(16, 24, 40, 0.18);
  --shadow-focus: 0 0 0 4px rgba(28, 80, 216, 0.16);
}

/* Dark palette. Written out twice rather than derived: a manual choice has to
   beat the system preference in both directions, and CSS gives no way to share
   one custom-property block between a media query and an attribute selector. */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg: #0b0e14;
    --surface: #12161f;
    --surface-raised: #181d28;
    --surface-inset: #0f131b;
    --surface-hover: #1b212d;
    --surface-overlay: rgba(3, 6, 12, 0.66);

    --text-primary: #e9edf5;
    --text-secondary: #a3aec2;
    --text-tertiary: #8a95a9;
    --text-on-accent: #06111f;

    --border-subtle: #232a37;
    --border-strong: #38414f;
    --border-control: #616b80;

    --accent: #7cb0ff;
    --accent-hover: #a3c8ff;
    --accent-solid: #7cb0ff;
    --accent-solid-hover: #a3c8ff;
    --accent-bg: rgba(124, 176, 255, 0.12);
    --accent-border: rgba(124, 176, 255, 0.38);

    --positive: #4ecb71;
    --positive-bg: rgba(78, 203, 113, 0.13);
    --positive-border: rgba(78, 203, 113, 0.38);

    --negative: #ff8a80;
    --negative-bg: rgba(255, 138, 128, 0.13);
    --negative-border: rgba(255, 138, 128, 0.38);

    --warning: #ecb544;
    --warning-bg: rgba(236, 181, 68, 0.13);
    --warning-border: rgba(236, 181, 68, 0.38);

    --danger-fg: #2a0707;
    --focus: #7cb0ff;
    --chart-grid: #232a37;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.58);
    --shadow-focus: 0 0 0 4px rgba(124, 176, 255, 0.24);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0b0e14;
  --surface: #12161f;
  --surface-raised: #181d28;
  --surface-inset: #0f131b;
  --surface-hover: #1b212d;
  --surface-overlay: rgba(3, 6, 12, 0.66);

  --text-primary: #e9edf5;
  --text-secondary: #a3aec2;
  --text-tertiary: #8a95a9;
  --text-on-accent: #06111f;

  --border-subtle: #232a37;
  --border-strong: #38414f;
  --border-control: #616b80;

  --accent: #7cb0ff;
  --accent-hover: #a3c8ff;
  --accent-solid: #7cb0ff;
  --accent-solid-hover: #a3c8ff;
  --accent-bg: rgba(124, 176, 255, 0.12);
  --accent-border: rgba(124, 176, 255, 0.38);

  --positive: #4ecb71;
  --positive-bg: rgba(78, 203, 113, 0.13);
  --positive-border: rgba(78, 203, 113, 0.38);

  --negative: #ff8a80;
  --negative-bg: rgba(255, 138, 128, 0.13);
  --negative-border: rgba(255, 138, 128, 0.38);

  --warning: #ecb544;
  --warning-bg: rgba(236, 181, 68, 0.13);
  --warning-border: rgba(236, 181, 68, 0.38);

  --danger-fg: #2a0707;
  --focus: #7cb0ff;
  --chart-grid: #232a37;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.58);
  --shadow-focus: 0 0 0 4px rgba(124, 176, 255, 0.24);
}

:root[data-theme="light"] { color-scheme: light; }

/* ── Base ───────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

img, svg { max-width: 100%; }

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--dur-1) var(--ease);
}
a:hover { color: var(--accent-hover); text-decoration: underline; }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

h1, h2, h3, h4 {
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: var(--lh-heading);
  text-wrap: balance;
}
h1 { font-size: var(--fs-h1); margin: 0 0 var(--space-3); }
h2 { font-size: var(--fs-h2); margin: var(--space-7) 0 var(--space-3); }
h3 { font-size: var(--fs-h3); margin: var(--space-5) 0 var(--space-2); font-weight: 650; }
p { margin: 0 0 var(--space-4); }

.lede {
  color: var(--text-secondary);
  font-size: var(--fs-lede);
  margin-bottom: var(--space-5);
  max-width: 62ch;
  text-wrap: pretty;
}
.muted { color: var(--text-secondary); }
.small { font-size: var(--fs-sm); }
.tiny { font-size: var(--fs-xs); }
.nums { font-variant-numeric: tabular-nums; }

strong, b { font-weight: 650; }

code, .mono {
  font-family: var(--font-mono);
  font-size: 0.875em;
  font-variant-numeric: tabular-nums;
}
code {
  background: var(--surface-inset);
  border: 1px solid var(--border-subtle);
  padding: 0.1em 0.4em;
  border-radius: var(--radius-xs);
}
pre {
  background: var(--surface-inset);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: 1.55;
  margin: 0 0 var(--space-4);
}
pre code { background: none; border: none; padding: 0; }

hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: var(--space-6) 0;
}

ul.tight, ol.tight { padding-left: 1.25rem; margin: 0 0 var(--space-4); }
ul.tight li, ol.tight li { margin: var(--space-2) 0; }
ul.tight li::marker, ol.tight li::marker { color: var(--text-tertiary); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-3);
  top: var(--space-3);
  z-index: calc(var(--z-header) + 1);
  transform: translateY(-250%);
  background: var(--surface-raised);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: var(--space-2) var(--space-4);
  font-weight: 600;
  transition: transform var(--dur-2) var(--ease);
}
.skip-link:focus { transform: translateY(0); text-decoration: none; }

/* ── Layout ─────────────────────────────────────────────────────────────── */

main {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--w-default);
  margin: 0 auto;
  padding: var(--space-6) var(--gutter) var(--space-8);
}
main.wide { max-width: var(--w-wide); }
main.prose { max-width: calc(var(--w-prose) + 2 * var(--gutter)); }
main.narrow {
  max-width: calc(var(--w-narrow) + 2 * var(--gutter));
  padding-top: var(--space-7);
}

main.prose h2 { margin-top: var(--space-8); }
main.prose p, main.prose li { text-wrap: pretty; }

.prose-body { max-width: var(--w-prose); }
.prose-body h2 { margin-top: var(--space-8); }
.prose-body p, .prose-body li { text-wrap: pretty; }

/* Anchored headings must clear the sticky header. */
:is(h1, h2, h3)[id] { scroll-margin-top: calc(var(--header-h) + var(--space-4)); }

.doc-meta {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  background: var(--surface-inset);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
}
.doc-meta .sep { color: var(--border-strong); }

.stack > * + * { margin-top: var(--space-4); }
.stack-lg > * + * { margin-top: var(--space-6); }
.stack-sm > * + * { margin-top: var(--space-2); }

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}
.cluster-sm { gap: var(--space-2); }

.spread {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.spread-center { align-items: center; }

.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); }

.center { text-align: center; }
.flush { margin: 0; }
.mt-0 { margin-top: 0; }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mb-0 { margin-bottom: 0; }
.mb-5 { margin-bottom: var(--space-5); }
.full { width: 100%; }
.hidden { display: none !important; }

/* ── Header ─────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
  padding-top: env(safe-area-inset-top);
}

/* The frosted background sits on a pseudo-element rather than on .topbar
   itself: backdrop-filter makes its element the containing block for fixed
   descendants, which would collapse the mobile drawer to the height of the
   header instead of the viewport. */
.topbar::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--surface);
}
@supports (backdrop-filter: blur(1px)) {
  .topbar::before {
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    backdrop-filter: saturate(1.6) blur(12px);
  }
}
.topbar.is-scrolled {
  border-bottom-color: var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  max-width: var(--w-wide);
  margin: 0 auto;
  min-height: var(--header-h);
  padding: var(--space-2) var(--gutter);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-primary);
  font-weight: 680;
  font-size: 1.02rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
  margin-right: auto;
}
.brand:hover { color: var(--text-primary); text-decoration: none; }
.brand .mark { flex: none; width: 26px; height: 26px; }
.mark-tile { fill: var(--accent-solid); }
.mark-glyph { fill: none; stroke: var(--text-on-accent); stroke-width: 2.6;
  stroke-linecap: round; stroke-linejoin: round; }
.mark-end { fill: var(--text-on-accent); }

.nav-links { display: flex; align-items: center; gap: var(--space-1); }
.nav-links a,
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 550;
  white-space: nowrap;
  transition: color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.nav-links a:hover,
.nav-link:hover { color: var(--text-primary); background: var(--surface-hover); text-decoration: none; }
.nav-links a[aria-current="page"] {
  color: var(--text-primary);
  background: var(--surface-inset);
}

.nav-actions { display: flex; align-items: center; gap: var(--space-2); }
.nav-divider {
  width: 1px;
  height: 22px;
  background: var(--border-subtle);
  margin: 0 var(--space-1);
}

button.nav-link {
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
}

/* Theme toggle — a segmented System / Light / Dark control. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--surface-inset);
  border: 1px solid var(--border-control);
  border-radius: var(--radius-pill);
}
.theme-toggle button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: var(--radius-pill);
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.theme-toggle button:hover { color: var(--text-primary); }
.theme-toggle button svg { width: 15px; height: 15px; fill: none;
  stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle button[aria-pressed="true"] {
  background: var(--surface-raised);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Hamburger */
.nav-toggle {
  display: none;
  width: 44px;
  height: 44px;
  flex: none;
  place-items: center;
  border: 1px solid var(--border-control);
  border-radius: var(--radius-sm);
  background: var(--surface-inset);
  color: var(--text-primary);
  cursor: pointer;
}
.nav-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor;
  stroke-width: 1.9; stroke-linecap: round; }
.nav-toggle .icon-close { display: none; }
.nav-toggle[aria-expanded="true"] .icon-close { display: block; }
.nav-toggle[aria-expanded="true"] .icon-open { display: none; }

/* visibility flips instantly on open and only after the slide on close, so
   the panel is focusable the moment it is asked for — a visibility:hidden
   element silently refuses focus(). */
.nav-scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  background: var(--surface-overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-3) var(--ease), visibility 0s linear var(--dur-3);
}
body.nav-open .nav-scrim {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--dur-3) var(--ease), visibility 0s;
}
body.nav-open { overflow: hidden; }

@media (max-width: 860px) {
  .nav-toggle { display: grid; }

  .nav-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(20rem, 86vw);
    z-index: calc(var(--z-drawer) + 1);
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    background: var(--surface);
    border-left: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-lg);
    padding: calc(var(--space-6) + env(safe-area-inset-top)) var(--space-5)
             calc(var(--space-5) + env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateX(100%);
    visibility: hidden;
    transition: transform var(--dur-3) var(--ease), visibility 0s linear var(--dur-3);
  }
  body.nav-open .nav-panel {
    transform: translateX(0);
    visibility: visible;
    transition: transform var(--dur-3) var(--ease), visibility 0s;
  }

  .nav-panel .nav-links,
  .nav-panel .nav-actions {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-1);
  }
  .nav-panel .nav-links a,
  .nav-panel .nav-link {
    min-height: 44px;
    font-size: 1rem;
    padding: var(--space-3);
  }
  .nav-panel .nav-actions { gap: var(--space-3); margin-top: auto; }
  .nav-panel .nav-actions .btn,
  .nav-panel .nav-actions .nav-link { width: 100%; justify-content: center; }
  .nav-panel .nav-divider { width: 100%; height: 1px; margin: var(--space-2) 0; }
  .nav-panel .theme-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    min-height: 44px;
    color: var(--text-secondary);
    font-size: 0.9rem;
  }
  /* Touch targets in the drawer are thumb-sized, not pointer-sized. */
  .nav-panel .theme-toggle button { width: 44px; height: 44px; }
  .nav-panel .theme-toggle button svg { width: 17px; height: 17px; }
}

@media (min-width: 861px) {
  /* The drawer's children become direct flex items of the bar, so the nav
     sits next to the brand and everything after it is pushed right. */
  .nav-panel { display: contents; }
  .nav-panel .theme-row .theme-label { display: none; }
  .nav-scrim { display: none; }
  .topbar .brand { margin-right: 0; }
  .topbar .nav-links { margin-right: auto; margin-left: var(--space-2); }
}

/* ── Footer ─────────────────────────────────────────────────────────────── */

.site-footer {
  flex: none;
  border-top: 1px solid var(--border-subtle);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  padding-bottom: env(safe-area-inset-bottom);
}
.footer-inner {
  max-width: var(--w-wide);
  margin: 0 auto;
  padding: var(--space-7) var(--gutter) var(--space-6);
  display: grid;
  gap: var(--space-6);
  grid-template-columns: minmax(0, 1.6fr) repeat(2, minmax(0, 1fr));
}
@media (max-width: 700px) {
  .footer-inner { grid-template-columns: 1fr 1fr; }
  .footer-brand { grid-column: 1 / -1; }
}
.footer-brand .brand { margin-right: 0; }
.footer-brand p { margin: var(--space-3) 0 0; max-width: 34ch; }

.footer-group h2 {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-tertiary);
  margin: 0 0 var(--space-3);
  font-weight: 600;
}
.footer-group ul { list-style: none; margin: 0; padding: 0; }
.footer-group li { margin-bottom: var(--space-2); }
.footer-group a { color: var(--text-secondary); }
.footer-group a:hover { color: var(--text-primary); }

.footer-legal {
  max-width: var(--w-wide);
  margin: 0 auto;
  padding: var(--space-5) var(--gutter) var(--space-7);
  border-top: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
  font-size: var(--fs-xs);
  line-height: 1.65;
}
.footer-legal p { margin: 0 0 var(--space-2); max-width: 84ch; }
.footer-legal p:last-child { margin-bottom: 0; }

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  --btn-bg: var(--accent-solid);
  --btn-bg-hover: var(--accent-solid-hover);
  --btn-fg: var(--text-on-accent);
  --btn-bd: transparent;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-3) var(--space-5);
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: inherit;
  font-size: 0.94rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease),
              color var(--dur-1) var(--ease), transform var(--dur-1) var(--ease),
              box-shadow var(--dur-1) var(--ease);
}
.btn:hover { background: var(--btn-bg-hover); color: var(--btn-fg); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-secondary {
  --btn-bg: var(--surface-raised);
  --btn-bg-hover: var(--surface-hover);
  --btn-fg: var(--text-primary);
  --btn-bd: var(--border-control);
  box-shadow: var(--shadow-sm);
}

.btn-ghost {
  --btn-bg: transparent;
  --btn-bg-hover: var(--surface-inset);
  --btn-fg: var(--text-secondary);
  --btn-bd: transparent;
}
.btn-ghost:hover { color: var(--text-primary); }

.btn-danger {
  --btn-bg: var(--negative);
  --btn-bg-hover: var(--negative);
  --btn-fg: var(--danger-fg);
}
.btn-danger:hover { filter: saturate(1.2) brightness(1.03); }

/* Compact only above the layout breakpoint where the mobile drawer gives way
   to the desktop bar; below it, every target stays thumb-sized. */
.btn-sm { min-height: 44px; padding: var(--space-2) var(--space-4); font-size: var(--fs-sm); }
@media (min-width: 861px) {
  .btn-sm { min-height: 34px; padding: var(--space-2) var(--space-3); }
}
.btn-block { width: 100%; }

/* Loading state: the label swaps for a spinner, so an in-flight request is
   visible rather than only implied by a disabled button. */
.btn[data-loading="true"] { color: transparent; pointer-events: none; }
.btn[data-loading="true"]::after {
  content: "";
  position: absolute;
  width: 1.05em;
  height: 1.05em;
  border: 2px solid var(--btn-fg);
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 0.65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.linkish {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.linkish:hover { color: var(--accent-hover); }

.segmented {
  display: inline-flex;
  border: 1px solid var(--border-control);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-raised);
  box-shadow: var(--shadow-sm);
}
.segmented .btn {
  --btn-bg: transparent;
  --btn-bg-hover: var(--surface-hover);
  --btn-fg: var(--text-primary);
  --btn-bd: transparent;
  border-radius: 0;
  box-shadow: none;
}
.segmented .btn + .btn { border-left: 1px solid var(--border-subtle); }

/* ── Forms ──────────────────────────────────────────────────────────────── */

.field { margin-bottom: var(--space-4); }
.field:last-child { margin-bottom: 0; }

label, .label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}
.field-hint {
  margin: var(--space-2) 0 0;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
.field-error {
  margin: var(--space-2) 0 0;
  font-size: var(--fs-sm);
  color: var(--negative);
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  min-height: 46px;
  padding: var(--space-3);
  background: var(--surface-raised);
  border: 1px solid var(--border-control);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  /* 16px minimum: anything smaller makes iOS Safari zoom the page on focus. */
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.4;
  transition: border-color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
input[type="number"] { font-variant-numeric: tabular-nums; }
input::placeholder, textarea::placeholder { color: var(--text-tertiary); opacity: 1; }
input:hover:not(:disabled), select:hover, textarea:hover { border-color: var(--text-tertiary); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

input[aria-invalid="true"] { border-color: var(--negative); }
input[aria-invalid="true"]:focus { box-shadow: 0 0 0 4px var(--negative-bg); }

.input-wrap { position: relative; display: block; }
.input-wrap input { padding-right: 3rem; }

.pw-toggle {
  position: absolute;
  right: 1px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  /* Full 44px touch target, sized to sit inside the 46px input. */
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-tertiary);
  cursor: pointer;
}
.pw-toggle:hover { color: var(--text-primary); background: var(--surface-inset); }
.pw-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.pw-toggle .icon-hide { display: none; }
.pw-toggle[aria-pressed="true"] .icon-hide { display: block; }
.pw-toggle[aria-pressed="true"] .icon-show { display: none; }

/* Money input: a permanent $ affordance rather than a placeholder that goes
   away exactly when you start typing digits. */
.money-input { position: relative; max-width: 15rem; }
.money-input::before {
  content: "$";
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 1.2rem;
  pointer-events: none;
}
.money-input input {
  padding-left: 1.9rem;
  font-size: 1.35rem;
  font-weight: 600;
  min-height: 56px;
  font-variant-numeric: tabular-nums;
}
.money-input input::-webkit-outer-spin-button,
.money-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Qualified with the element so it outweighs the input[type=...] base rule. */
input.code-input {
  max-width: 12rem;
  font-family: var(--font-mono);
  font-size: 1.45rem;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  text-align: center;
  min-height: 56px;
  font-variant-numeric: tabular-nums;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-inset);
  font-size: var(--fs-sm);
  font-weight: 400;
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.check:hover { border-color: var(--border-strong); }
.check:focus-within { border-color: var(--accent); box-shadow: var(--shadow-focus); }
.check input[type="checkbox"] {
  flex: none;
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin: 1px 0 0;
  border: 1.5px solid var(--border-control);
  border-radius: var(--radius-xs);
  background: var(--surface-raised);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.check input[type="checkbox"]::after {
  content: "";
  width: 11px;
  height: 6px;
  border: 2px solid var(--text-on-accent);
  border-top: none;
  border-right: none;
  transform: translateY(-1px) rotate(-45deg) scale(0.5);
  opacity: 0;
  transition: opacity var(--dur-1) var(--ease), transform var(--dur-1) var(--ease);
}
.check input[type="checkbox"]:checked {
  background: var(--accent-solid);
  border-color: var(--accent-solid);
}
.check input[type="checkbox"]:checked::after {
  opacity: 1;
  transform: translateY(-1px) rotate(-45deg) scale(1);
}

/* Live requirement hint: neutral until met, then explicitly satisfied. */
.req {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  margin-top: var(--space-2);
}
.req::before {
  content: "";
  width: 15px; height: 15px;
  flex: none;
  border: 1.5px solid var(--border-control);
  border-radius: 50%;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.req[data-met="true"] { color: var(--positive); }
.req[data-met="true"]::before {
  border-color: var(--positive);
  background: var(--positive);
  box-shadow: inset 0 0 0 2px var(--surface);
}

/* ── Cards ──────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.card:last-child { margin-bottom: 0; }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.card-head > :is(h1, h2, h3) { margin: 0; }
.card-head .card-meta { color: var(--text-secondary); font-size: var(--fs-sm); }
@media (min-width: 560px) { .card-head .card-meta { text-align: right; } }
.card-meta .value {
  font-size: 1.25rem;
  font-weight: 680;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}
.card-meta .value.pos { color: var(--positive); }
.card-meta .value.neg { color: var(--negative); }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-5);
}
.auth-head { text-align: center; margin-bottom: var(--space-5); }
.auth-head .brand { justify-content: center; margin: 0 0 var(--space-4); }
.auth-head h1 { margin-bottom: var(--space-2); }
.auth-head p { color: var(--text-secondary); font-size: var(--fs-sm); margin: 0; }
.auth-foot {
  text-align: center;
  margin-top: var(--space-5);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
.auth-step { animation: step-in var(--dur-3) var(--ease); }
@keyframes step-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ── Stats ──────────────────────────────────────────────────────────────── */

.stat {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  min-width: 0;
}
.stat .label {
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.stat .value {
  margin-top: var(--space-1);
  font-size: clamp(1.15rem, 0.92rem + 0.95vw, 1.5rem);
  font-weight: 660;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  /* Long values wrap instead of being shrunk by a JS font-size branch. */
  overflow-wrap: anywhere;
  line-height: 1.2;
}
.stat .delta { font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }

.stat-secondary { background: var(--surface-inset); box-shadow: none; }
.stat-secondary .value { font-size: 1.05rem; font-weight: 620; }

.pos { color: var(--positive); }
.neg { color: var(--negative); }

/* ── Tables ─────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
caption { text-align: left; color: var(--text-secondary); padding-bottom: var(--space-3); }
th, td {
  text-align: left;
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}
thead th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  border-bottom-color: var(--border-strong);
}
tbody tr { transition: background var(--dur-1) var(--ease); }
tbody tr:hover { background: var(--surface-hover); }
tbody tr:last-child :is(td, th) { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.sym { font-weight: 680; letter-spacing: 0.01em; }

/* Mobile: each row becomes a small card. Horizontal scroll is the fallback,
   not the plan. */
@media (max-width: 640px) {
  table.table-cards { display: block; }
  table.table-cards thead { display: none; }
  table.table-cards tbody, table.table-cards tr, table.table-cards td { display: block; }
  table.table-cards tr {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--surface-inset);
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);
  }
  table.table-cards tr:last-child { margin-bottom: 0; }
  table.table-cards td {
    display: flex;
    /* Inline content inside a cell becomes its own flex item, so a value with
       a link or emphasis in it is several items, not one. They wrap instead of
       shooting past the right edge; short numeric values never reach it. */
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: 0 var(--space-4);
    border: none;
    padding: var(--space-2) 0;
    text-align: right;
    overflow-wrap: anywhere;
  }
  table.table-cards td + td { border-top: 1px dashed var(--border-subtle); }
  table.table-cards td::before {
    content: attr(data-label);
    flex: none;
    text-align: left;
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
  }
  .table-wrap:has(table.table-cards) { overflow-x: visible; }
}

/* ── Messages, callouts, notices ────────────────────────────────────────── */

.msg {
  display: none;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin: var(--space-4) 0;
  font-size: var(--fs-sm);
  background: var(--surface-inset);
  color: var(--text-primary);
  --msg-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 8h.01M11 12h1v4h1'/%3E%3C/svg%3E");
}
.msg.show { display: flex; }
.msg::before {
  content: "";
  flex: none;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  background: currentColor;
  -webkit-mask: var(--msg-icon) center / contain no-repeat;
  mask: var(--msg-icon) center / contain no-repeat;
}
.msg.error {
  background: var(--negative-bg);
  border-color: var(--negative-border);
  color: var(--negative);
  --msg-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v6M12 16.4v.01'/%3E%3C/svg%3E");
}
.msg.ok {
  background: var(--positive-bg);
  border-color: var(--positive-border);
  color: var(--positive);
  --msg-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='m8 12.5 2.5 2.5L16 9.5'/%3E%3C/svg%3E");
}
.msg.warn {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning);
  --msg-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 3.5 22 20H2z'/%3E%3Cpath d='M12 10v4M12 17.2v.01'/%3E%3C/svg%3E");
}
.msg strong { color: inherit; }
.msg a { color: inherit; text-decoration: underline; }

.callout {
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--accent);
  background: var(--surface-inset);
  padding: var(--space-4) var(--space-5);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin: var(--space-5) 0;
}
.callout > :last-child { margin-bottom: 0; }
.callout.warn { border-left-color: var(--warning); background: var(--warning-bg); border-color: var(--warning-border); }
.callout.good { border-left-color: var(--positive); background: var(--positive-bg); border-color: var(--positive-border); }
.callout.info { border-left-color: var(--accent); background: var(--accent-bg); border-color: var(--accent-border); }
.callout.small { font-size: var(--fs-sm); padding: var(--space-3) var(--space-4); }
.callout h3 { margin-top: 0; }

.notice {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-inset);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  margin: var(--space-4) 0;
}
.notice > div > :last-child { margin-bottom: 0; }
.notice-icon { flex: none; color: var(--text-tertiary); line-height: 0; }
.notice-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.notice.warn { background: var(--warning-bg); border-color: var(--warning-border); color: var(--text-primary); }
.notice.warn .notice-icon { color: var(--warning); }
.notice.good { background: var(--positive-bg); border-color: var(--positive-border); color: var(--text-primary); }
.notice.good .notice-icon { color: var(--positive); }

/* ── Badges ─────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.15rem var(--space-3);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface-inset);
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: "●"; font-size: 0.62em; line-height: 1; }
.badge.good { color: var(--positive); border-color: var(--positive-border); background: var(--positive-bg); }
.badge.bad { color: var(--negative); border-color: var(--negative-border); background: var(--negative-bg); }
.badge.warn { color: var(--warning); border-color: var(--warning-border); background: var(--warning-bg); }
.badge.accent { color: var(--accent); border-color: var(--accent-border); background: var(--accent-bg); }
.badge.plain::before { content: none; }

/* ── Modal ──────────────────────────────────────────────────────────────── */

dialog.modal {
  width: min(30rem, calc(100vw - 2 * var(--space-4)));
  max-height: min(90vh, 44rem);
  padding: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  margin: auto;
}
dialog.modal::backdrop { background: var(--surface-overlay); }
dialog.modal[open] { animation: modal-in var(--dur-3) var(--ease); }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.modal-body {
  padding: var(--space-5);
  padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  overflow-y: auto;
  max-height: min(90vh, 44rem);
}
.modal-body h2 { margin: 0 0 var(--space-3); font-size: 1.2rem; }
.modal-body > p { color: var(--text-secondary); font-size: var(--fs-sm); }
.modal-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
  margin-top: var(--space-5);
  flex-wrap: wrap;
}
.modal-actions .btn { flex: 1 1 auto; }
@media (min-width: 480px) { .modal-actions .btn { flex: 0 0 auto; } }

/* ── Toasts ─────────────────────────────────────────────────────────────── */

.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 2 * var(--space-4));
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-pill);
  background: var(--text-primary);
  color: var(--bg);
  font-size: var(--fs-sm);
  font-weight: 550;
  box-shadow: var(--shadow-lg);
  animation: toast-in var(--dur-3) var(--ease);
}
.toast.leaving { animation: toast-out var(--dur-3) var(--ease) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px); } }

/* ── Skeletons & empty states ───────────────────────────────────────────── */

.skeleton {
  border-radius: var(--radius-sm);
  background: var(--surface-inset);
  background-image: linear-gradient(90deg, transparent 20%,
    color-mix(in srgb, var(--border-subtle) 70%, transparent) 50%, transparent 80%);
  background-size: 220% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  color: transparent;
  user-select: none;
}
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -40% 0; } }
.skeleton-line { height: 0.8em; margin: 0.4em 0; }
.skeleton-title { height: 1.5em; width: 45%; }
.skeleton-block { height: 100%; width: 100%; border-radius: var(--radius-md); }
.skeleton-pick { height: 56px; border-radius: var(--radius-md); }

.empty { text-align: center; padding: var(--space-7) var(--space-5); }
.empty-glyph {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-4);
  display: grid;
  place-items: center;
  border-radius: var(--radius-lg);
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid var(--accent-border);
}
.empty-glyph svg { width: 26px; height: 26px; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.empty h2 { margin: 0 0 var(--space-2); font-size: 1.15rem; }
.empty p { color: var(--text-secondary); max-width: 42ch; margin: 0 auto var(--space-5); }

/* ── Stepper ────────────────────────────────────────────────────────────── */

.stepper {
  display: flex;
  gap: var(--space-2);
  list-style: none;
  margin: 0 0 var(--space-5);
  padding: 0 0 var(--space-1);
  overflow-x: auto;
  scrollbar-width: none;
}
.stepper::-webkit-scrollbar { display: none; }
.stepper li {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-tertiary);
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
  transition: color var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease),
              background var(--dur-2) var(--ease);
}
.stepper .n {
  display: grid;
  place-items: center;
  width: 20px; height: 20px;
  flex: none;
  border-radius: 50%;
  background: var(--surface-inset);
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}
.stepper li[data-state="done"] { color: var(--text-secondary); }
.stepper li[data-state="done"] .n { background: var(--positive-bg); color: var(--positive); }
.stepper li[aria-current="step"] {
  color: var(--text-primary);
  border-color: var(--accent-border);
  background: var(--accent-bg);
}
.stepper li[aria-current="step"] .n { background: var(--accent-solid); color: var(--text-on-accent); }

.step-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
  flex-wrap: wrap;
}
.step-num {
  display: grid;
  place-items: center;
  width: 28px; height: 28px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  font-size: var(--fs-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.step-head h2 { margin: 0; font-size: 1.2rem; }
.step-head .step-meta { margin-left: auto; color: var(--text-secondary); font-size: var(--fs-sm); }

/* ── Pick grid ──────────────────────────────────────────────────────────── */

.pick-grid {
  display: grid;
  gap: var(--space-2);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 13.5rem), 1fr));
}
.pick {
  position: relative;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  column-gap: var(--space-2);
  row-gap: 1px;
  min-height: 56px;
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: var(--text-primary);
  transition: border-color var(--dur-1) var(--ease), background var(--dur-1) var(--ease);
}
.pick:hover { border-color: var(--border-strong); background: var(--surface-hover); }
.pick .box {
  grid-row: 1 / 3;
  width: 20px; height: 20px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--border-control);
  border-radius: var(--radius-xs);
  background: var(--surface-raised);
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.pick .box svg {
  width: 12px; height: 12px;
  fill: none; stroke: var(--text-on-accent);
  stroke-width: 3; stroke-linecap: round; stroke-linejoin: round;
  opacity: 0;
  transition: opacity var(--dur-1) var(--ease);
}
.pick .rank {
  grid-row: 1 / 3;
  color: var(--text-tertiary);
  font-size: var(--fs-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 1.6em;
}
.pick .line {
  grid-column: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-width: 0;
}
.pick .sym { font-weight: 680; letter-spacing: 0.01em; line-height: 1.25; }
.pick .co {
  grid-column: 3;
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pick[aria-checked="true"] { border-color: var(--accent); background: var(--accent-bg); }
.pick[aria-checked="true"] .box { background: var(--accent-solid); border-color: var(--accent-solid); }
.pick[aria-checked="true"] .box svg { opacity: 1; }
.pick.top-tier::before {
  content: "";
  position: absolute;
  left: 0; top: var(--space-3); bottom: var(--space-3);
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--positive);
}
.pick .flag {
  flex: none;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--warning);
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-xs);
  padding: 0 0.3rem;
  white-space: nowrap;
}

.pick-bar {
  position: sticky;
  bottom: var(--space-3);
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  box-shadow: var(--shadow-md);
}
.pick-bar .count { font-weight: 650; font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: 0 0 var(--space-4); }
.chip {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--surface-inset);
  font-size: var(--fs-sm);
}
.chip .k { color: var(--text-secondary); font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.chip .v { font-weight: 680; font-variant-numeric: tabular-nums; }
.chip.accent { background: var(--accent-bg); border-color: var(--accent-border); }

/* ── Chart ──────────────────────────────────────────────────────────────── */

.chart-wrap {
  position: relative;
  width: 100%;
  /* Reserved height: the card must not shift when the data lands. */
  height: 260px;
}
@media (max-width: 640px) { .chart-wrap { height: 205px; } }
.chart { display: block; width: 100%; height: 100%; touch-action: pan-y; }
.chart .grid-line { stroke: var(--chart-grid); stroke-width: 1; }
.chart .axis-label {
  fill: var(--text-tertiary);
  font-size: 11px;
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
}
.chart .line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart .area { fill: url(#equity-fill); }
.chart .grad-top { stop-color: var(--accent); stop-opacity: 0.3; }
.chart .grad-bottom { stop-color: var(--accent); stop-opacity: 0; }
.chart .crosshair { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .empty-label { fill: var(--text-secondary); font-size: 13px; font-family: var(--font-sans); }
.chart .drawin {
  stroke-dasharray: var(--len);
  stroke-dashoffset: var(--len);
  animation: draw 900ms var(--ease) forwards;
}
@keyframes draw { to { stroke-dashoffset: 0; } }

.chart-tip {
  position: absolute;
  top: var(--space-2);
  pointer-events: none;
  transform: translateX(-50%);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-xs);
  line-height: 1.4;
  white-space: nowrap;
  opacity: 0;
  transition: opacity var(--dur-1) var(--ease);
}
.chart-tip.show { opacity: 1; }
.chart-tip .v { display: block; font-weight: 680; font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums; }
.chart-tip .d { color: var(--text-secondary); }

/* ── Home ───────────────────────────────────────────────────────────────── */

.hero {
  display: grid;
  gap: var(--space-7);
  align-items: center;
  padding: var(--space-5) 0 var(--space-7);
}
@media (min-width: 900px) {
  .hero { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: var(--space-8); }
}
.hero h1 { font-size: var(--fs-hero); letter-spacing: -0.035em; margin-bottom: var(--space-4); }
.hero .lede { font-size: clamp(1.05rem, 1rem + 0.4vw, 1.22rem); margin-bottom: var(--space-5); }
.hero-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.hero-actions .btn { padding-inline: var(--space-6); }
.hero-note { margin: var(--space-4) 0 0; color: var(--text-tertiary); font-size: var(--fs-sm); }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  border: 1px solid var(--accent-border);
  background: var(--accent-bg);
  color: var(--accent);
  font-size: var(--fs-xs);
  font-weight: 650;
}

/* Static, hand-built preview of the product. Fake tickers — nothing real. */
.preview {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.preview-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-inset);
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  font-weight: 600;
}
.preview-bar .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.preview-bar .dot:first-child { background: var(--positive); }
.preview-body { padding: var(--space-4); display: grid; gap: var(--space-2); }
.preview-row {
  display: grid;
  grid-template-columns: 1.4rem minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface-inset);
  font-size: var(--fs-sm);
}
.preview-row .r { color: var(--text-tertiary); font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums; }
.preview-row .t { font-weight: 680; min-width: 0; }
.preview-row .t span { display: block; font-weight: 400; font-size: var(--fs-xs);
  color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-row .a { font-weight: 680; font-variant-numeric: tabular-nums; }
.preview-row.is-top { border-color: var(--accent-border); background: var(--accent-bg); }
.preview-foot {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-inset);
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.steps {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
}
.step {
  padding: var(--space-5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.step .n {
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  margin-bottom: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-weight: 700;
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}
.step h3 { margin: 0 0 var(--space-2); font-size: 1rem; }
.step p { margin: 0; color: var(--text-secondary); font-size: var(--fs-sm); }

/* The core differentiator gets a panel, not a footnote. */
.trust {
  display: grid;
  gap: var(--space-5);
  padding: var(--space-6);
  border: 1px solid var(--positive-border);
  border-radius: var(--radius-xl);
  background: var(--positive-bg);
  margin: var(--space-6) 0;
}
@media (min-width: 780px) { .trust { grid-template-columns: auto minmax(0, 1fr); align-items: start; } }
.trust-shield {
  display: grid;
  place-items: center;
  width: 52px; height: 52px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--positive-border);
  color: var(--positive);
}
.trust-shield svg { width: 26px; height: 26px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.trust h2 { margin: 0 0 var(--space-3); font-size: clamp(1.2rem, 1.05rem + 0.6vw, 1.5rem); }
.trust p { margin: 0 0 var(--space-4); color: var(--text-primary); max-width: 64ch; }
.trust ul { list-style: none; margin: 0 0 var(--space-4); padding: 0; display: grid; gap: var(--space-2); }
.trust li {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  font-size: var(--fs-sm);
  --tick: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='m5 12.5 4.5 4.5L19 7'/%3E%3C/svg%3E");
}
.trust li::before {
  content: "";
  flex: none;
  width: 18px; height: 18px;
  margin-top: 1px;
  background: var(--positive);
  -webkit-mask: var(--tick) center / contain no-repeat;
  mask: var(--tick) center / contain no-repeat;
}

.latest {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.latest .week { font-size: 1.3rem; font-weight: 680; letter-spacing: -0.02em; }
.latest .meta { color: var(--text-secondary); font-size: var(--fs-sm); }

.broker-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.broker-list li {
  display: grid;
  grid-template-columns: minmax(7rem, auto) minmax(0, 1fr);
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-inset);
  font-size: var(--fs-sm);
}
@media (max-width: 520px) { .broker-list li { grid-template-columns: 1fr; gap: var(--space-1); } }
.broker-list .who { font-weight: 650; }
.broker-list .where { color: var(--text-secondary); }

/* In-page section nav — desktop only, and only where it earns its place. */
.page-with-toc { display: block; }
.toc { display: none; }
@media (min-width: 1040px) {
  .page-with-toc {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 13rem;
    gap: var(--space-7);
    align-items: start;
  }
  .toc { display: block; position: sticky; top: calc(var(--header-h) + var(--space-5)); }
}
.toc h2 {
  margin: 0 0 var(--space-3);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-tertiary);
}
.toc ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); }
.toc a {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-left: 2px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
}
.toc a:hover { color: var(--text-primary); border-left-color: var(--accent); text-decoration: none; }

/* ── Account ────────────────────────────────────────────────────────────── */

.qr-panel {
  display: inline-block;
  /* Scanners need a light quiet zone, so this stays white in both themes. */
  background: #ffffff;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  line-height: 0;
}
.qr-panel svg { width: 186px; height: 186px; }

.copy-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-inset);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  word-break: break-all;
}
.copy-field .val { flex: 1 1 auto; letter-spacing: 0.04em; }

.codes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface-inset);
  list-style: none;
}
.codes-grid li {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  letter-spacing: 0.06em;
  padding: var(--space-2);
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  text-align: center;
}

/* ── Motion preferences ─────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .skeleton { animation: none; background-image: none; }
  .chart .drawin { stroke-dasharray: none; stroke-dashoffset: 0; animation: none; }
}

/* ── Print: the buy list as a clean one-page order sheet ────────────────── */

.print-only { display: none; }

@media print {
  :root {
    --bg: #fff; --surface: #fff; --surface-inset: #fff; --surface-raised: #fff;
    --text-primary: #000; --text-secondary: #333; --text-tertiary: #444;
    --border-subtle: #bbb; --border-strong: #888;
    --shadow-sm: none; --shadow-md: none; --shadow-lg: none;
  }
  body { background: #fff; color: #000; }
  .topbar, .site-footer, .nav-scrim, .nav-panel, .toast-host, .skip-link,
  .no-print, .stepper, .pick-bar { display: none !important; }
  main { max-width: none; padding: 0; }
  .card { border: 1px solid #bbb; box-shadow: none; break-inside: avoid; page-break-inside: avoid; }
  table.table-cards { display: table; }
  table.table-cards thead { display: table-header-group; }
  table.table-cards tbody { display: table-row-group; }
  table.table-cards tr { display: table-row; border: none; background: none; padding: 0; }
  table.table-cards td { display: table-cell; text-align: left;
    border-bottom: 1px solid #ddd; padding: var(--space-2); }
  table.table-cards td::before { content: none; }
  table.table-cards td.num { text-align: right; }
  .print-only { display: block; }
}
