/* Open Sans (SIL OFL 1.1), self-hosted variable fonts; license in fonts/OFL.txt */
@font-face {
  font-family: "Open Sans";
  font-style: normal;
  font-weight: 300 800;
  font-stretch: 75% 100%;
  font-display: swap;
  src: local("Open Sans"), url("fonts/OpenSans[wdth,wght].ttf") format("truetype");
}
@font-face {
  font-family: "Open Sans";
  font-style: italic;
  font-weight: 300 800;
  font-stretch: 75% 100%;
  font-display: swap;
  src: local("Open Sans Italic"), url("fonts/OpenSans-Italic[wdth,wght].ttf") format("truetype");
}

/* ==================================================================
   TOKENS
   One source of truth for this page. Three levels:
     1. primitives   (--gray-*, --blue-*, ...)     raw values only
     2. semantic     (--surface-*, --text-*, ...)  what components use
     3. component    (--btn-*, --field-*, ...)     documented aliases
   Components below consume levels 2 and 3 only.
   ================================================================== */
:root {
  color-scheme: dark;

  /* 1. Primitives: neutrals (neutrals) */
  --gray-1000: #0B0C0F;
  --gray-950: #0E0F12;
  --gray-925: #111317;
  --gray-900: #181B21;
  --gray-875: #1D2027;
  --gray-850: #22252C;
  --gray-800: #2A2E36;
  --gray-700: #3A3F49;
  --gray-500: #7D8490;
  --gray-450: #868D99;
  --gray-400: #9BA1AB;
  --gray-200: #C9CDD4;
  --gray-100: #E8E9EC;
  --white: #FFFFFF;

  /* 1. Primitives: hues. blue-400 and the action blues are the header blue
     desaturated 20% (HSL S x 0.8) for long sessions on bright displays.
     Header original: #7C9CFF. Others inferred for AA on gray-900. */
  --blue-300: #A3B9FF;
  --blue-400: #89A3F2;
  --blue-600: #5B6FC9;
  --blue-650: #586CCA;
  --blue-700: #5469C2;
  --cyan-300: #8FDCF0;
  --cyan-400: #5CC8E6;
  --green-300: #9BE3BD;
  --green-400: #6CD3A0;
  --amber-300: #F0CD8C;
  --amber-400: #E7B75F;
  --red-300: #FFB0B0;
  --red-400: #FF8A8A;
  --violet-300: #CFC2FA;
  --violet-400: #B9A6F7;

  /* 2. Surfaces */
  --surface-canvas: var(--gray-950);
  --surface-chrome: var(--gray-925);
  --surface-panel: var(--gray-900);
  --surface-raised: var(--gray-875);
  --surface-inset: var(--gray-1000);
  --surface-hover: var(--gray-875);
  --surface-selected: var(--gray-850);
  --surface-overlay: rgb(5 6 8 / 0.72);

  /* 2. Text */
  --text-strong: var(--white);
  --text-primary: var(--gray-100);
  --text-secondary: var(--gray-200);
  --text-muted: var(--gray-400);
  --text-disabled: var(--gray-500);
  --text-inverse: var(--gray-1000);
  --text-link: var(--blue-300);
  --text-code: var(--gray-200);

  /* 2. Borders and focus */
  --border-subtle: var(--gray-850);
  --border-default: var(--gray-800);
  --border-strong: var(--gray-700);
  --border-error: var(--red-400);
  --border-selection: var(--blue-400);
  --focus-color: var(--blue-400);
  --focus-width: 2px;
  --focus-offset: 2px;

  /* 2. Brand and action */
  --accent: var(--blue-400);
  --accent-soft: rgb(137 163 242 / 0.12);
  --accent-line: rgb(137 163 242 / 0.32);
  --action-primary: var(--blue-650);
  --action-primary-hover: var(--blue-600);
  --action-primary-pressed: var(--blue-700);
  --on-action-primary: var(--white);
  --action-danger-soft: rgb(255 138 138 / 0.10);

  /* 2. Feedback: fg, bg, border */
  --info: var(--blue-400);      --info-bg: rgb(137 163 242 / 0.10);  --info-line: rgb(137 163 242 / 0.30);
  --success: var(--green-400);  --success-bg: rgb(108 211 160 / 0.10); --success-line: rgb(108 211 160 / 0.30);
  --warning: var(--amber-400);  --warning-bg: rgb(231 183 95 / 0.10);  --warning-line: rgb(231 183 95 / 0.30);
  --danger: var(--red-400);     --danger-bg: rgb(255 138 138 / 0.10);  --danger-line: rgb(255 138 138 / 0.30);

  /* 2. Status states (separate from brand accent) */
  --state-queued: var(--gray-400);
  --state-active: var(--cyan-400);
  --state-review: var(--amber-400);
  --state-blocked: var(--red-300);
  --state-paused: var(--violet-400);
  --state-done: var(--green-400);
  --state-failed: var(--red-400);
  --state-cancelled: var(--gray-450);
  --state-unknown: var(--gray-450);

  /* 2. Syntax (on --surface-inset) */
  --syn-plain: var(--gray-200);
  --syn-keyword: var(--violet-300);
  --syn-function: var(--blue-300);
  --syn-string: var(--green-300);
  --syn-number: var(--amber-300);
  --syn-type: var(--cyan-300);
  --syn-comment: var(--gray-500);
  --syn-punct: var(--gray-400);
  --syn-gutter: var(--gray-500);
  --syn-active-line: rgb(255 255 255 / 0.04);
  --syn-selection: rgb(137 163 242 / 0.24);
  --syn-match: rgb(231 183 95 / 0.28);

  /* 2. Chart highlights (evidence in a clinical note) */
  --hl-evidence: rgb(231 183 95 / 0.28);
  --hl-evidence-line: var(--amber-400);
  --hl-selected: rgb(137 163 242 / 0.28);

  /* 2. Typography */
  --font: "Open Sans", system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, Menlo, monospace;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 14px;
  --text-lg: 15px;
  --text-xl: 16px;
  --text-2xl: 20px;
  --text-3xl: 24px;
  --text-display: 30px;
  --leading-tight: 1.25;
  --leading-body: 1.5;
  --leading-code: 1.6;

  /* 2. Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --space-10: 44px;
  --space-12: 64px;

  /* 2. Shape */
  --radius-sm: 5px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 14px;
  --radius-pill: 999px;
  --border-width: 1px;

  /* 2. Elevation */
  --shadow-1: 0 1px 0 rgb(0 0 0 / 0.30);
  --shadow-2: 0 8px 24px rgb(0 0 0 / 0.35);
  --shadow-3: 0 16px 40px rgb(0 0 0 / 0.45);

  /* 2. Layout */
  --header-h: 68px;
  --content-max: 1440px;
  --sidebar-w: 232px;
  --control-h-sm: 30px;
  --control-h: 36px;
  --control-h-lg: 40px;
  --row-h: 44px;

  /* 2. Layering */
  --z-content: 0;
  --z-sticky: 10;
  --z-popover: 30;
  --z-backdrop: 40;
  --z-dialog: 50;
  --z-toast: 60;

  /* 2. Motion */
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur-fast: 120ms;
  --dur-med: 220ms;
  --dur-slow: 360ms;
}

/* Density: compact overrides only spacing, control and row sizes. */
[data-density="compact"] {
  --control-h-sm: 26px;
  --control-h: 30px;
  --control-h-lg: 34px;
  --row-h: 34px;
  --space-3: 10px;
  --space-4: 12px;
  --space-5: 16px;
}

@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0ms; --dur-med: 0ms; --dur-slow: 0ms; }
}

/* ==================================================================
   BASE
   ================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { scrollbar-gutter: stable; scroll-padding-top: calc(var(--header-h) + var(--space-4)); }
body {
  margin: 0;
  background: var(--surface-canvas);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--text-link); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4, p { margin: 0; }
code, kbd, pre { font-family: var(--mono); }
:focus-visible { outline: var(--focus-width) solid var(--focus-color); outline-offset: var(--focus-offset); }
/* The hidden attribute always wins over component display rules (.banner, .notice, .empty, ...). */
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--space-4); top: -100px; z-index: var(--z-toast);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  background: var(--action-primary); color: var(--on-action-primary); font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: var(--space-3); }

/* ==================================================================
   HEADER (tokenized)
   ================================================================== */
.app-header {
  position: sticky; top: 0; z-index: var(--z-sticky);
  isolation: isolate;
  height: var(--header-h); padding: 0 var(--space-7);
  display: flex; align-items: center; gap: var(--space-5);
  background: transparent;
}
.app-header::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  width: 100vw; background: var(--surface-chrome);
  border-bottom: var(--border-width) solid var(--border-subtle);
}
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; color: var(--text-primary); border-radius: var(--radius-md); text-decoration: none; }
.brand svg { display: block; color: var(--accent); }
.brand-name { font-size: var(--text-xl); font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.dot { width: 7px; height: 7px; flex-shrink: 0; border-radius: 50%; background: var(--accent); }
.command {
  flex: 1 1 auto; max-width: 760px; min-width: 44px; margin: 0 auto;
  height: var(--control-h-lg); padding: 0 14px;
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-inset); border: var(--border-width) solid var(--border-default); border-radius: var(--radius-lg);
  color: var(--text-muted); font-size: var(--text-md); cursor: pointer;
}
.command:hover { border-color: var(--border-strong); color: var(--text-secondary); }
.command-label { flex: 1; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
kbd {
  font-size: var(--text-xs); padding: 2px 6px;
  border: var(--border-width) solid var(--border-default); border-radius: var(--radius-sm); color: var(--text-secondary);
}
.top-nav { display: flex; align-items: center; gap: var(--space-1); font-size: var(--text-md); font-weight: 500; }
.top-nav a { padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); color: var(--text-secondary); white-space: nowrap; text-decoration: none; }
.top-nav a:hover { color: var(--text-strong); }
.top-nav a[aria-current="page"] { background: var(--surface-hover); color: var(--text-strong); }
/* Menu button: opens the hamburger menu that lists every page not shown in the bar. */
.nav-toggle {
  display: flex; width: var(--control-h-lg); height: var(--control-h-lg); flex-shrink: 0;
  align-items: center; justify-content: center; padding: 0;
  background: transparent; border: var(--border-width) solid var(--border-default); border-radius: var(--radius-lg); color: var(--text-secondary); cursor: pointer;
}
.nav-toggle:hover { border-color: var(--border-strong); color: var(--text-strong); }
.nav-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

/* ==================================================================
   GUIDE LAYOUT
   ================================================================== */
.sg-layout {
  max-width: var(--content-max); margin: 0 auto;
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); gap: var(--space-8);
  padding: 0 var(--space-7);
}
.sg-toc {
  position: sticky; top: var(--header-h); align-self: start;
  max-height: calc(100vh - var(--header-h)); overflow-y: auto;
  padding: var(--space-8) 0 var(--space-8);
}
.sg-toc h2 {
  margin: var(--space-5) 0 var(--space-2); padding: 0 var(--space-3);
  font-family: var(--mono); font-size: var(--text-xs); font-weight: 500; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.sg-toc h2:first-child { margin-top: 0; }
.sg-toc ul { list-style: none; margin: 0; padding: 0; }
.sg-toc a {
  display: block; padding: 5px var(--space-3); border-radius: var(--radius-md);
  color: var(--text-secondary); font-size: var(--text-sm); text-decoration: none;
}
.sg-toc a:hover { background: var(--surface-hover); color: var(--text-strong); }
.sg-toc a[aria-current="true"] { background: var(--surface-selected); color: var(--text-strong); box-shadow: inset 2px 0 0 var(--accent); }

.sg-main { padding: var(--space-10) 0 var(--space-12); min-width: 0; }
.sg-intro { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-5); margin-bottom: var(--space-10); }
.eyebrow { font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em; }
.page-title { margin-top: var(--space-1); font-size: var(--text-display); font-weight: 600; letter-spacing: -0.02em; line-height: var(--leading-tight); }
.page-subtitle { margin-top: var(--space-2); max-width: 68ch; color: var(--text-muted); font-size: var(--text-lg); }

.sg-section { padding-top: var(--space-10); margin-top: var(--space-10); border-top: var(--border-width) solid var(--border-subtle); }
.sg-section:first-of-type { margin-top: 0; }
.sg-section > h2 { font-size: var(--text-3xl); font-weight: 600; letter-spacing: -0.015em; }
.sg-section > .lead { margin-top: var(--space-2); max-width: 72ch; color: var(--text-muted); }
.sg-block { margin-top: var(--space-8); }
.sg-block > h3 { font-size: var(--text-xl); font-weight: 600; }
.sg-block > h3 code { font-size: var(--text-sm); color: var(--text-muted); font-weight: 400; margin-left: var(--space-2); }
.sg-block > p { margin-top: var(--space-1); max-width: 72ch; color: var(--text-muted); }

/* Specimen frame: where examples render */
.specimen {
  margin-top: var(--space-4); padding: var(--space-6);
  background: var(--surface-panel); border: var(--border-width) solid var(--border-default); border-radius: var(--radius-xl);
}
.specimen.inset { background: var(--surface-inset); }
.specimen-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.specimen-row + .specimen-row { margin-top: var(--space-4); }
.specimen-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.specimen-label { font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); min-width: 96px; }

/* Usage notes */
.rules { margin-top: var(--space-4); display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.rule { padding: var(--space-4); border-radius: var(--radius-lg); border: var(--border-width) solid var(--border-subtle); background: var(--surface-chrome); font-size: var(--text-sm); color: var(--text-secondary); }
.rule strong { display: block; margin-bottom: var(--space-1); font-family: var(--mono); font-size: var(--text-xs); font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; }
.rule.do strong { color: var(--success); }
.rule.dont strong { color: var(--danger); }
.rule ul { margin: 0; padding-left: var(--space-4); }

.demo-flag {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 1px var(--space-2); border-radius: var(--radius-pill);
  border: var(--border-width) dashed var(--border-strong);
  font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted);
}

/* ==================================================================
   FOUNDATION SPECIMENS
   ================================================================== */
.swatch-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); margin-top: var(--space-4); }
.swatch { border: var(--border-width) solid var(--border-default); border-radius: var(--radius-lg); overflow: hidden; background: var(--surface-panel); }
.swatch-chip { height: 64px; border-bottom: var(--border-width) solid var(--border-subtle); display: flex; align-items: flex-end; padding: var(--space-2) var(--space-3); font-weight: 600; }
.swatch-meta { padding: var(--space-2) var(--space-3) var(--space-3); display: grid; gap: 2px; }
.swatch-name { font-family: var(--mono); font-size: var(--text-xs); color: var(--text-primary); }
.swatch-value, .swatch-ratio { font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }
.ratio-pass { color: var(--success); }
.ratio-fail { color: var(--danger); }

.direction-table, .data-table, .token-table {
  width: 100%; border-collapse: collapse; font-size: var(--text-sm);
}
.table-wrap { overflow-x: auto; border: var(--border-width) solid var(--border-default); border-radius: var(--radius-xl); background: var(--surface-panel); }
.direction-table th, .direction-table td, .token-table th, .token-table td, .data-table th, .data-table td {
  padding: var(--space-3) var(--space-4); text-align: left; vertical-align: top;
  border-bottom: var(--border-width) solid var(--border-subtle);
}
.direction-table tr:last-child > *, .token-table tr:last-child > *, .data-table tbody tr:last-child > * { border-bottom: 0; }
.direction-table thead th, .token-table thead th, .data-table thead th {
  font-family: var(--mono); font-size: var(--text-xs); font-weight: 500; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em; background: var(--surface-chrome); white-space: nowrap;
}
.direction-table td:first-child { font-weight: 500; white-space: nowrap; }
.token-table code, .direction-table code { font-size: var(--text-xs); color: var(--text-code); }

.source-tag { font-family: var(--mono); font-size: var(--text-xs); padding: 1px 6px; border-radius: var(--radius-sm); white-space: nowrap; }
.source-observed { color: var(--accent); background: var(--accent-soft); }
.source-inferred { color: var(--text-muted); background: var(--surface-hover); }

.type-row { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: var(--space-5); align-items: baseline; padding: var(--space-4) 0; border-bottom: var(--border-width) solid var(--border-subtle); }
.type-row:last-child { border-bottom: 0; }
.type-row .spec { font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); line-height: 1.6; }
.type-row .sample { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.space-row { display: grid; grid-template-columns: 96px 56px minmax(0, 1fr); gap: var(--space-4); align-items: center; padding: 6px 0; font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }
.space-bar { height: 12px; background: var(--accent-line); border-left: 2px solid var(--accent); border-radius: 2px; }

.radius-demo { width: 96px; height: 64px; background: var(--surface-raised); border: var(--border-width) solid var(--border-strong); display: grid; place-items: center; font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }
.elev-demo { width: 150px; height: 84px; border-radius: var(--radius-lg); display: grid; place-items: center; font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); border: var(--border-width) solid var(--border-default); }

.motion-track { position: relative; height: 36px; flex: 1; min-width: 200px; background: var(--surface-inset); border-radius: var(--radius-pill); border: var(--border-width) solid var(--border-subtle); }
.motion-dot { position: absolute; top: 5px; left: 6px; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); transition: left var(--dur-slow) var(--ease); }
.motion-track.moved .motion-dot { left: calc(100% - 30px); }

.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: var(--space-2); }
.icon-cell { display: grid; justify-items: center; gap: var(--space-2); padding: var(--space-4) var(--space-2); border-radius: var(--radius-lg); color: var(--text-secondary); font-family: var(--mono); font-size: var(--text-xs); }
.icon-cell:hover { background: var(--surface-hover); color: var(--text-strong); }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-sm { width: 16px; height: 16px; }

/* ==================================================================
   COMPONENTS
   ================================================================== */

/* Button. Component aliases: --btn-h, --btn-px */
.btn {
  --btn-h: var(--control-h);
  --btn-px: var(--space-4);
  position: relative;
  height: var(--btn-h); padding: 0 var(--btn-px);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  border: var(--border-width) solid var(--border-default); border-radius: var(--radius-md);
  background: var(--surface-raised); color: var(--text-primary);
  font-size: var(--text-md); font-weight: 500; white-space: nowrap; cursor: pointer; text-decoration: none;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-selected); }
.btn:active { background: var(--surface-hover); }
.btn-sm { --btn-h: var(--control-h-sm); --btn-px: var(--space-3); font-size: var(--text-sm); }
.btn-lg { --btn-h: var(--control-h-lg); --btn-px: var(--space-5); }
.btn-primary { background: var(--action-primary); border-color: var(--action-primary); color: var(--on-action-primary); }
.btn-primary:hover { background: var(--action-primary-hover); border-color: var(--action-primary-hover); }
.btn-primary:active { background: var(--action-primary-pressed); }
.btn-outline { background: transparent; }
.toggle-button { justify-self: start; }
.toggle-button[aria-pressed="true"] { background: var(--surface-selected); border-color: var(--accent); color: var(--text-strong); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-hover); border-color: transparent; color: var(--text-strong); }
.btn-danger { background: var(--action-danger-soft); border-color: var(--danger-line); color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }
.btn-icon { --btn-px: 0; width: var(--btn-h); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.btn[aria-busy="true"] { color: transparent; pointer-events: none; }
.btn[aria-busy="true"]::after {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--text-muted); border-top-color: var(--text-strong);
  animation: spin 700ms linear infinite;
}
.btn-primary[aria-busy="true"]::after { border-color: rgb(255 255 255 / 0.4); border-top-color: var(--on-action-primary); }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn + .btn { margin-left: calc(-1 * var(--border-width)); }
.btn-group .btn:first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.btn-group .btn:last-child { border-radius: 0 var(--radius-md) var(--radius-md) 0; }
.btn-group .btn-primary + .btn-primary { border-left-color: var(--action-primary-pressed); }
.force-hover { border-color: var(--border-strong); background: var(--surface-selected); }
.force-focus { outline: var(--focus-width) solid var(--focus-color); outline-offset: var(--focus-offset); }

@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn[aria-busy="true"]::after, .spinner { animation-duration: 2s; } }

/* Field. Component aliases: --field-h, --field-bg */
.field { display: grid; gap: 6px; min-width: 0; }
.field-label { display: flex; align-items: baseline; gap: var(--space-2); font-size: var(--text-sm); font-weight: 500; color: var(--text-primary); }
.field-label .optional { font-weight: 400; color: var(--text-muted); font-size: var(--text-xs); }
.field-label .required { color: var(--danger); }
.field-help { font-size: var(--text-xs); color: var(--text-muted); }
.field-error { display: flex; align-items: center; gap: 6px; font-size: var(--text-xs); color: var(--danger); }
.input, .select, .textarea {
  --field-h: var(--control-h);
  --field-bg: var(--surface-inset);
  width: 100%; min-height: var(--field-h); padding: 0 var(--space-3);
  background: var(--field-bg); border: var(--border-width) solid var(--border-default); border-radius: var(--radius-md);
  color: var(--text-primary); font-size: var(--text-md);
  transition: border-color var(--dur-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-disabled); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: none; border-color: var(--focus-color); box-shadow: 0 0 0 1px var(--focus-color); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--border-error); }
.input:disabled, .select:disabled, .textarea:disabled { color: var(--text-disabled); background: var(--surface-panel); cursor: not-allowed; }
.input[readonly] { background: var(--surface-panel); color: var(--text-secondary); }
.input.mono { font-family: var(--mono); font-size: var(--text-sm); }
.input.input-units { width: calc(var(--space-10) + var(--space-8)); max-width: 100%; text-align: center; flex: 0 0 auto; }
.textarea { padding: var(--space-2) var(--space-3); line-height: var(--leading-body); resize: vertical; min-height: 84px; }
.select { appearance: none; padding-right: var(--space-8); cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.input-affix { position: relative; display: flex; align-items: center; }
.input-affix .input { padding-left: 36px; }
.input-affix.suffix .input { padding-left: var(--space-3); padding-right: 76px; }
.input-affix > .affix { position: absolute; left: var(--space-3); color: var(--text-muted); pointer-events: none; display: flex; }
.input-affix > .affix-end { position: absolute; right: var(--space-1); display: flex; gap: 2px; }
.input-affix > .affix-text { position: absolute; right: var(--space-3); font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); pointer-events: none; }

.checkbox-field, .radio-field { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-md); cursor: pointer; min-height: 28px; }
.checkbox-field input, .radio-field input { width: 16px; height: 16px; margin: 0; accent-color: var(--action-primary); cursor: pointer; }
.checkbox-field:has(input:disabled), .radio-field:has(input:disabled) { color: var(--text-disabled); cursor: not-allowed; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: var(--space-2); font-size: var(--text-sm); font-weight: 500; }
.stack { display: grid; gap: var(--space-2); }

/* Answer-choice editor row: pick-as-correct radio with its letter, the choice text, and a remove button (pack editor). */
.choice-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--space-2); align-items: center; }
.choice-row .radio-field { min-width: 44px; font-family: var(--mono); font-size: var(--text-sm); }
.choice-list { display: grid; gap: var(--space-2); }
/* Form grid whose fields mix help text and none: keep each control at the top of its cell instead of stretching it. */
.form-grid.is-top { align-items: start; }

.switch { display: inline-flex; align-items: center; gap: var(--space-3); padding: 0; border: 0; background: none; cursor: pointer; font-size: var(--text-md); color: var(--text-primary); }
.switch-track { position: relative; width: 36px; height: 20px; border-radius: var(--radius-pill); background: var(--surface-selected); border: var(--border-width) solid var(--border-strong); transition: background var(--dur-fast) var(--ease); }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--text-muted); transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease); }
.switch[aria-checked="true"] .switch-track { background: var(--action-primary); border-color: var(--action-primary); }
.switch[aria-checked="true"] .switch-track::after { transform: translateX(16px); background: var(--on-action-primary); }
.switch:disabled { color: var(--text-disabled); cursor: not-allowed; }
.switch:disabled .switch-track { opacity: 0.5; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-inset); border: var(--border-width) solid var(--border-default); border-radius: var(--radius-lg); }
.segmented button { height: calc(var(--control-h) - 8px); padding: 0 var(--space-3); border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text-muted); font-size: var(--text-sm); font-weight: 500; cursor: pointer; }
.segmented button:hover { color: var(--text-strong); }
.segmented button[aria-pressed="true"] { background: var(--surface-raised); color: var(--text-strong); box-shadow: var(--shadow-1); }

.form-grid { display: grid; gap: var(--space-5); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.action-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-6); padding-top: var(--space-4); border-top: var(--border-width) solid var(--border-subtle); }
.action-bar .save-state { margin-right: auto; font-size: var(--text-sm); color: var(--text-muted); display: inline-flex; align-items: center; gap: var(--space-2); }

/* Navigation */
.tabs { display: flex; gap: var(--space-1); border-bottom: var(--border-width) solid var(--border-default); overflow-x: auto; }
.tab { position: relative; padding: var(--space-2) var(--space-3) 10px; border: 0; background: none; color: var(--text-muted); font-size: var(--text-md); font-weight: 500; cursor: pointer; white-space: nowrap; display: inline-flex; gap: var(--space-2); align-items: center; }
.tab:hover { color: var(--text-strong); }
.tab[aria-selected="true"] { color: var(--text-strong); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: var(--space-2); right: var(--space-2); bottom: -1px; height: 2px; border-radius: 2px; background: var(--accent); }
.tab .count { font-family: var(--mono); font-size: var(--text-xs); padding: 0 6px; border-radius: var(--radius-pill); background: var(--surface-hover); color: var(--text-secondary); }
/* Wrapping variant: tabs with long titles wrap onto more lines instead of scrolling (narrow screens). */
.tabs-wrap { flex-wrap: wrap; overflow-x: visible; }
.tabs-wrap .tab { white-space: normal; text-align: left; }
.tab-panel { padding-top: var(--space-4); color: var(--text-secondary); font-size: var(--text-sm); }
.breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0; padding: 0; font-size: var(--text-sm); }
.breadcrumbs li { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--text-muted); min-width: 0; }
.breadcrumbs li + li::before { content: "/"; color: var(--border-strong); }
.breadcrumbs a { color: var(--text-secondary); text-decoration: none; }
.breadcrumbs a:hover { color: var(--text-strong); text-decoration: underline; }
.breadcrumbs [aria-current="page"] { color: var(--text-primary); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40ch; }
.pagination { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-muted); }
.pagination .range { margin-right: auto; font-family: var(--mono); font-size: var(--text-xs); }

/* Containers */
.panel { background: var(--surface-panel); border: var(--border-width) solid var(--border-default); border-radius: var(--radius-xl); }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: var(--border-width) solid var(--border-subtle); }
.panel-head :is(h2, h3, h4) { margin: 0; font-size: var(--text-lg); font-weight: 600; display: flex; align-items: center; gap: var(--space-2); }
.panel-title-block { display: grid; gap: var(--space-1); min-width: 0; }
.panel-head .meta { margin-left: auto; font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }
.panel-body { padding: var(--space-5); color: var(--text-secondary); font-size: var(--text-sm); }
.card { padding: var(--space-4); border-radius: var(--radius-lg); background: var(--surface-raised); border: var(--border-width) solid var(--border-subtle); }
.card:hover { border-color: var(--border-default); }
.disclosure { border: var(--border-width) solid var(--border-default); border-radius: var(--radius-lg); background: var(--surface-panel); }
.disclosure + .disclosure { margin-top: var(--space-2); }
.disclosure > summary { list-style: none; display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-4); cursor: pointer; font-weight: 500; border-radius: var(--radius-lg); }
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary .chev { transition: transform var(--dur-fast) var(--ease); color: var(--text-muted); }
.disclosure[open] > summary .chev { transform: rotate(90deg); }
.disclosure > summary:hover { background: var(--surface-hover); }
.disclosure-body { padding: 0 var(--space-4) var(--space-4) 38px; color: var(--text-secondary); font-size: var(--text-sm); }
.section-header { display: flex; align-items: flex-end; gap: var(--space-4); padding-bottom: var(--space-3); border-bottom: var(--border-width) solid var(--border-subtle); }
.section-header h4 { font-size: var(--text-2xl); font-weight: 600; letter-spacing: -0.01em; }
.section-header p { color: var(--text-muted); font-size: var(--text-sm); }
.section-header .btn { margin-left: auto; }
.section-header { flex-wrap: wrap; }
.section-header > div { flex: 1 1 calc(var(--space-12) * 3); min-width: 0; }
.section-header .tag { margin-left: auto; white-space: nowrap; flex: 0 0 auto; }

/* Data */
.data-table td { color: var(--text-secondary); }
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tbody tr[aria-selected="true"] { background: var(--accent-soft); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: var(--text-xs); }
.data-table .truncate { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: var(--text-xs); }
.sort-btn { display: inline-flex; align-items: center; gap: 4px; padding: 0; border: 0; background: none; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; }
.sort-btn[aria-sort-dir] { color: var(--text-primary); }
.row-actions { display: flex; gap: var(--space-1); justify-content: flex-end; }
.bulk-bar { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-4); background: var(--accent-soft); border-bottom: var(--border-width) solid var(--accent-line); font-size: var(--text-sm); }

.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 var(--space-2); border-radius: var(--radius-pill); border: var(--border-width) solid var(--border-default); background: var(--surface-inset); font-family: var(--mono); font-size: var(--text-xs); color: var(--text-secondary); white-space: nowrap; }
/* Wrapping variant: a badge with long text wraps inside its container instead of overflowing. */
.badge-wrap { height: auto; min-height: 22px; padding-block: var(--space-1); max-width: 100%; white-space: normal; }
.badge .dot { width: 6px; height: 6px; background: currentColor; }
.badge-info { color: var(--info); border-color: var(--info-line); background: var(--info-bg); }
.badge-success { color: var(--success); border-color: var(--success-line); background: var(--success-bg); }
.badge-warning { color: var(--warning); border-color: var(--warning-line); background: var(--warning-bg); }
.badge-danger { color: var(--danger); border-color: var(--danger-line); background: var(--danger-bg); }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 4px 0 var(--space-2); border-radius: var(--radius-sm); background: var(--surface-hover); border: var(--border-width) solid var(--border-default); font-family: var(--mono); font-size: var(--text-xs); color: var(--text-secondary); }
.tag button { width: 18px; height: 18px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 3px; background: none; color: var(--text-muted); cursor: pointer; }
.tag button:hover { background: var(--surface-selected); color: var(--text-strong); }

.state { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: var(--text-xs); color: var(--state-c, var(--state-unknown)); white-space: nowrap; }
.state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.state[data-shape="ring"]::before { background: transparent; box-shadow: inset 0 0 0 2px currentColor; }
.state[data-shape="square"]::before { border-radius: 2px; }
.state[data-shape="pulse"]::before { animation: pulse 1.6s var(--ease) infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .state[data-shape="pulse"]::before { animation: none; } }
.s-queued { --state-c: var(--state-queued); }
.s-active { --state-c: var(--state-active); }
.s-review { --state-c: var(--state-review); }
.s-blocked { --state-c: var(--state-blocked); }
.s-paused { --state-c: var(--state-paused); }
.s-done { --state-c: var(--state-done); }
.s-failed { --state-c: var(--state-failed); }
.s-cancelled { --state-c: var(--state-cancelled); }
.s-unknown { --state-c: var(--state-unknown); }

.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); border: var(--border-width) solid var(--border-default); border-radius: var(--radius-xl); background: var(--surface-panel); overflow: hidden; }
.metric { padding: var(--space-4) var(--space-5); border-right: var(--border-width) solid var(--border-subtle); }
.metric:last-child { border-right: 0; }
.metric-label { font-size: var(--text-sm); color: var(--text-muted); }
.metric-value { margin-top: var(--space-1); font-family: var(--mono); font-size: 28px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--text-strong); line-height: 1.1; }
.metric-foot { margin-top: var(--space-1); font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--space-2) var(--space-6); margin: 0; font-size: var(--text-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; color: var(--text-primary); overflow-wrap: anywhere; }
.kv dd.mono { font-family: var(--mono); font-size: var(--text-xs); }
.kv dd .missing { color: var(--text-disabled); font-style: italic; }

.avatar { width: 28px; height: 28px; border-radius: var(--radius-md); display: inline-grid; place-items: center; font-family: var(--mono); font-size: var(--text-xs); font-weight: 500; flex-shrink: 0; border: var(--border-width) solid var(--border-default); }
.avatar-user { background: var(--accent-soft); color: var(--accent); }
time, .timestamp { font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); font-variant-numeric: tabular-nums; }

.tooltip-wrap { position: relative; display: inline-flex; }
.tooltip { position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); z-index: var(--z-popover); padding: 6px var(--space-2); border-radius: var(--radius-md); background: var(--surface-raised); border: var(--border-width) solid var(--border-strong); box-shadow: var(--shadow-2); font-size: var(--text-xs); color: var(--text-primary); white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity var(--dur-fast) var(--ease); }
.tooltip-wrap:hover .tooltip, .tooltip-wrap:focus-within .tooltip { opacity: 1; }

/* Overlays */
.menu { min-width: 220px; padding: var(--space-1); background: var(--surface-panel); border: var(--border-width) solid var(--border-default); border-radius: var(--radius-lg); box-shadow: var(--shadow-3); }
.menu-label { padding: var(--space-2) var(--space-3) var(--space-1); font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.menu-item { width: 100%; display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-3); border: 0; border-radius: var(--radius-md); background: none; font-size: var(--text-md); color: var(--text-secondary); text-align: left; text-decoration: none; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-hover); color: var(--text-strong); outline: none; }
.menu-item .menu-meta { margin-left: auto; font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }
.menu-item.danger { color: var(--danger); }
.menu-item[aria-current="page"] { background: var(--surface-hover); color: var(--text-strong); }
.menu-item:disabled { color: var(--text-disabled); cursor: not-allowed; background: none; }
.menu-divider { height: 1px; margin: var(--space-1) 0; background: var(--border-subtle); }
.menu-anchor { position: relative; display: inline-block; }
.menu-anchor .menu { position: absolute; top: calc(100% + var(--space-2)); left: 0; z-index: var(--z-popover); }
.menu[hidden] { display: none; }

dialog.dialog { width: min(520px, calc(100vw - 32px)); padding: 0; border: var(--border-width) solid var(--border-default); border-radius: var(--radius-xl); background: var(--surface-panel); color: var(--text-primary); box-shadow: var(--shadow-3); }
dialog.dialog::backdrop { background: var(--surface-overlay); }
.dialog-head { padding: var(--space-5) var(--space-6) 0; }
.dialog-head h2 { font-size: var(--text-2xl); font-weight: 600; }
.dialog-head p { margin-top: var(--space-1); color: var(--text-muted); font-size: var(--text-sm); }
.dialog-body { padding: var(--space-5) var(--space-6); display: grid; gap: var(--space-4); }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-6); border-top: var(--border-width) solid var(--border-subtle); }
.dialog-error { padding: var(--space-3); border-radius: var(--radius-md); background: var(--danger-bg); border: var(--border-width) solid var(--danger-line); color: var(--danger); font-size: var(--text-sm); }
.dialog-error[hidden] { display: none; }

/* Feedback */
.notice { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--space-3); align-items: start; padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg); border: var(--border-width) solid var(--n-line); background: var(--n-bg); font-size: var(--text-sm); color: var(--text-secondary); }
.notice .icon { color: var(--n-fg); margin-top: 1px; }
.notice strong { color: var(--text-primary); font-weight: 600; }
.notice + .notice { margin-top: var(--space-2); }
.notice-info { --n-fg: var(--info); --n-bg: var(--info-bg); --n-line: var(--info-line); }
.notice-success { --n-fg: var(--success); --n-bg: var(--success-bg); --n-line: var(--success-line); }
.notice-warning { --n-fg: var(--warning); --n-bg: var(--warning-bg); --n-line: var(--warning-line); }
.notice-danger { --n-fg: var(--danger); --n-bg: var(--danger-bg); --n-line: var(--danger-line); }
.banner { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-4); border-radius: var(--radius-md); background: var(--warning-bg); border: var(--border-width) solid var(--warning-line); font-size: var(--text-sm); color: var(--text-primary); }
.banner .icon { color: var(--warning); }
.banner .btn { margin-left: auto; }

.progress { height: 6px; border-radius: var(--radius-pill); background: var(--surface-inset); border: var(--border-width) solid var(--border-subtle); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--state-active); border-radius: inherit; transition: width var(--dur-med) var(--ease); }
.progress.indeterminate > span { width: 30%; animation: slide 1.4s var(--ease) infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) { .progress.indeterminate > span { animation: none; width: 100%; opacity: 0.4; } }
.progress-label { display: flex; justify-content: space-between; font-size: var(--text-xs); color: var(--text-muted); margin-bottom: 6px; font-family: var(--mono); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin 700ms linear infinite; flex-shrink: 0; }
.skeleton { height: 12px; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-raised), var(--surface-selected), var(--surface-raised)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
.empty { display: grid; justify-items: center; text-align: center; gap: var(--space-2); padding: var(--space-8) var(--space-5); border: var(--border-width) dashed var(--border-default); border-radius: var(--radius-lg); }
.empty .empty-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: var(--radius-lg); background: var(--surface-raised); color: var(--text-muted); margin-bottom: var(--space-1); }
.empty h5 { margin: 0; font-size: var(--text-lg); font-weight: 600; }
.empty p { max-width: 42ch; color: var(--text-muted); font-size: var(--text-sm); }
.empty .btn { margin-top: var(--space-2); }

.toast-region { position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: var(--z-toast); display: grid; gap: var(--space-2); }
.toast { display: flex; align-items: center; gap: var(--space-3); min-width: 280px; max-width: 380px; padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg); background: var(--surface-raised); border: var(--border-width) solid var(--border-strong); box-shadow: var(--shadow-3); font-size: var(--text-sm); animation: toast-in var(--dur-med) var(--ease); }
.toast .icon { color: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ==================================================================
   PRACTICE COMPONENTS
   Specimens for the coding practice screens: citation chip, code search
   result row, chart panel with evidence highlights, scored answer card,
   progress tile with sparkline, streak and level badges. Tokens only.
   Status is never color alone: each state also carries an icon and a word.
   ================================================================== */

/* Citation chip: a reference to a pinned source (file and section). */
.cite-chip {
  display: inline-flex; align-items: center; gap: var(--space-1); min-width: 0; max-width: 100%;
  padding: 2px var(--space-2); border-radius: var(--radius-pill);
  border: var(--border-width) solid var(--accent-line); background: var(--accent-soft); color: var(--text-link);
  font-family: var(--mono); font-size: var(--text-xs); line-height: var(--leading-tight);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none;
}
a.cite-chip:hover, button.cite-chip:hover { border-color: var(--accent); color: var(--text-strong); }
button.cite-chip { cursor: pointer; }
.cite-chip:focus-visible { outline: var(--focus-width) solid var(--focus-color); outline-offset: var(--focus-offset); }

/* Code search result row: code, description, citation chips. */
.code-results { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-2); }
.code-result {
  display: grid; grid-template-columns: minmax(88px, auto) minmax(0, 1fr); gap: var(--space-1) var(--space-4); align-items: baseline;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg);
  background: var(--surface-raised); border: var(--border-width) solid var(--border-subtle);
  transition: border-color var(--dur-fast) var(--ease);
}
.code-result:hover { border-color: var(--border-strong); }
.code-result[aria-current="true"] { border-color: var(--accent-line); background: var(--surface-selected); box-shadow: inset 2px 0 0 var(--accent); }
.code-value { font-family: var(--mono); font-size: var(--text-lg); font-weight: 500; color: var(--text-strong); font-variant-numeric: tabular-nums; }
.code-body { display: grid; gap: var(--space-2); min-width: 0; }
.code-desc { color: var(--text-primary); font-size: var(--text-md); overflow-wrap: anywhere; }
.code-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.code-results-empty { padding: var(--space-6); text-align: center; color: var(--text-muted); font-size: var(--text-sm); }

/* Chart panel: a clinical note with evidence highlights. */
.chart { border-radius: var(--radius-xl); background: var(--surface-panel); border: var(--border-width) solid var(--border-default); overflow: hidden; }
.chart-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); padding: var(--space-3) var(--space-5); background: var(--surface-chrome); border-bottom: var(--border-width) solid var(--border-subtle); }
.chart-head h4 { font-size: var(--text-lg); font-weight: 600; }
.chart-id { margin-left: auto; font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }
.chart-facts { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); padding: var(--space-3) var(--space-5); border-bottom: var(--border-width) solid var(--border-subtle); font-size: var(--text-sm); color: var(--text-secondary); }
.chart-body { display: grid; gap: var(--space-5); padding: var(--space-5); max-height: 420px; overflow-y: auto; }
.chart-section { display: grid; gap: var(--space-2); }
.chart-section h5 { font-family: var(--mono); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.chart-text { white-space: pre-line; line-height: var(--leading-body); color: var(--text-primary); font-size: var(--text-md); overflow-wrap: anywhere; }
mark.hl {
  padding: 0 2px; border-radius: 2px; color: inherit;
  background: var(--hl-evidence); box-shadow: inset 0 -2px 0 var(--hl-evidence-line);
}
mark.hl[data-selected] { background: var(--hl-selected); box-shadow: inset 0 -2px 0 var(--accent); }
/* Highlights can be switched off; the underline and tag go with them. */
.chart[data-highlights="off"] mark.hl { background: none; box-shadow: none; }
.chart[data-highlights="off"] mark.hl .hl-code { display: none; }
mark.hl .hl-code { margin-left: var(--space-1); font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }

/* Scored answer card: correct, missing, and extra codes, each with a citation. */
.score { container-type: inline-size; border-radius: var(--radius-xl); background: var(--surface-panel); border: var(--border-width) solid var(--border-default); overflow: hidden; }
.score-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); padding: var(--space-4) var(--space-5); border-bottom: var(--border-width) solid var(--border-subtle); }
.score-head h4 { font-size: var(--text-lg); font-weight: 600; }
.score-tally { margin-left: auto; display: flex; flex-wrap: wrap; gap: var(--space-3); font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }
.score-list { list-style: none; margin: 0; padding: 0; display: grid; }
.score-row { display: grid; grid-template-columns: auto minmax(88px, auto) minmax(0, 1fr); gap: var(--space-3); align-items: start; padding: var(--space-3) var(--space-5); border-top: var(--border-width) solid var(--border-subtle); }
.score-row:first-child { border-top: 0; }
.score-mark { display: inline-flex; align-items: center; gap: var(--space-1); min-width: 74px; font-family: var(--mono); font-size: var(--text-xs); color: var(--sc-fg); }
.score-code { font-family: var(--mono); font-size: var(--text-md); font-weight: 500; color: var(--text-strong); }
.score-detail { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-1); min-width: 0; font-size: var(--text-sm); color: var(--text-secondary); }
.score-row[data-selected] { box-shadow: inset 3px 0 0 var(--accent); }
.score-row.is-correct { --sc-fg: var(--success); }
.score-row.is-missing { --sc-fg: var(--warning); background: var(--warning-bg); }
.score-row.is-extra { --sc-fg: var(--danger); background: var(--danger-bg); }
.score-foot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: var(--border-width) solid var(--border-subtle); }

/* Progress tile with sparkline. */
.tile-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-4); }
.tile { display: grid; gap: var(--space-2); align-content: start; min-width: 0; padding: var(--space-4) var(--space-5); border-radius: var(--radius-lg); background: var(--surface-raised); border: var(--border-width) solid var(--border-subtle); }
.tile-label { font-family: var(--mono); font-size: var(--text-xs); letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.tile-value { font-family: var(--mono); font-size: 28px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--text-strong); }
.tile-delta { font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }
.tile-delta.up { color: var(--success); }
.tile-delta.down { color: var(--danger); }
.tile-foot { font-size: var(--text-xs); color: var(--text-muted); }
.sparkline { display: block; width: 100%; max-width: 160px; height: 32px; overflow: visible; }
.sparkline-line { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sparkline-area { fill: var(--accent-soft); stroke: none; }
.sparkline-dot { fill: var(--accent); }
.skill-list { display: grid; gap: var(--space-4); }

/* Streak and level badges. */
.streak-badge, .level-badge {
  display: inline-flex; align-items: center; gap: var(--space-2); padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill); font-size: var(--text-sm); font-weight: 500; white-space: nowrap;
}
.streak-badge { color: var(--warning); background: var(--warning-bg); border: var(--border-width) solid var(--warning-line); }
.level-badge { color: var(--text-link); background: var(--accent-soft); border: var(--border-width) solid var(--accent-line); }
.streak-badge .count, .level-badge .count { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--text-strong); }
.level-card { display: grid; gap: var(--space-2); min-width: 0; }

/* Bar list rows (accuracy by tag, setting, chapter): extends .skill-list. */
.skill-row { display: grid; gap: var(--space-1); min-width: 0; }
.skill-row .progress-label { margin-bottom: 0; gap: var(--space-3); }
.skill-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-3); font-size: var(--text-xs); color: var(--text-muted); font-family: var(--mono); }

/* Trend chart: line with axes. Drawn by progress.js at the host width, so text stays 1:1. */
.trend-chart { display: block; width: 100%; height: auto; overflow: visible; }
.trend-grid { stroke: var(--border-subtle); stroke-width: 1; }
.trend-axis { stroke: var(--border-strong, var(--border-default)); stroke-width: 1; }
.trend-tick { fill: var(--text-muted); font-family: var(--mono); font-size: var(--text-xs); }
.trend-area { fill: var(--accent-soft); stroke: none; }
.trend-line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.trend-dot { fill: var(--surface-raised); stroke: var(--accent); stroke-width: 2; }
.chart-wrap { display: grid; gap: var(--space-3); min-width: 0; }

/* Calendar heat strip: one cell per day, Monday to Sunday rows, weeks as columns. Level and count are both text. */
.heat-strip { --heat-size: 24px; display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, var(--heat-size)); grid-auto-columns: var(--heat-size); gap: var(--space-1); overflow-x: auto; padding-bottom: var(--space-1); }
.heat-cell { display: grid; place-items: center; border-radius: var(--radius-sm); border: var(--border-width) solid var(--border-subtle); background: var(--surface-inset); color: var(--text-muted); font-family: var(--mono); font-size: var(--text-xs); }
.heat-cell[data-level="1"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--text-strong); }
.heat-cell[data-level="2"] { background: color-mix(in srgb, var(--accent) 50%, var(--surface-inset)); border-color: var(--accent-line); color: var(--text-strong); }
.heat-cell[data-level="3"] { background: var(--accent); border-color: var(--accent); color: var(--text-inverse); font-weight: 600; }
.heat-cell.is-pad { visibility: hidden; }
.heat-legend { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); }
.heat-legend .heat-cell { min-width: var(--space-5); height: var(--space-5); padding: 0 var(--space-1); }

@media (max-width: 640px) {
  .code-result { grid-template-columns: minmax(0, 1fr); }
  .score-row { grid-template-columns: auto minmax(0, 1fr); }
  .score-detail { grid-column: 1 / -1; }
}
@container (max-width: 520px) {
  .score-row { grid-template-columns: auto minmax(0, 1fr); }
  .score-detail { grid-column: 1 / -1; }
}

pre.code { margin: 0; padding: var(--space-3) 0; overflow-x: auto; background: var(--surface-inset); font-size: var(--text-sm); line-height: var(--leading-code); color: var(--syn-plain); counter-reset: ln; tab-size: 2; }
pre.code .ln { display: block; padding: 0 var(--space-4) 0 0; }
pre.code .ln::before { counter-increment: ln; content: counter(ln); display: inline-block; width: 44px; padding-right: var(--space-4); text-align: right; color: var(--syn-gutter); user-select: none; }
pre.code .ln.active { background: var(--syn-active-line); }
pre.code .ln.active::before { color: var(--text-secondary); }
.k { color: var(--syn-keyword); } .f { color: var(--syn-function); } .s { color: var(--syn-string); }
.n { color: var(--syn-number); } .t { color: var(--syn-type); } .c { color: var(--syn-comment); font-style: italic; } .p { color: var(--syn-punct); }
.sel { background: var(--syn-selection); } .match { background: var(--syn-match); border-radius: 2px; }
.code-frame { border: var(--border-width) solid var(--border-default); border-radius: var(--radius-lg); overflow: hidden; }
.code-bar { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4); background: var(--surface-chrome); border-bottom: var(--border-width) solid var(--border-subtle); font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }
.code-bar .path { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; direction: rtl; text-align: left; }
.code-bar .spacer { flex: 1; }
.inline-code { padding: 1px 5px; border-radius: var(--radius-sm); background: var(--surface-inset); border: var(--border-width) solid var(--border-subtle); font-size: 0.92em; color: var(--text-code); }


.map-table td:first-child code { color: var(--text-primary); }

/* ==================================================================
   RESPONSIVE
   ================================================================== */
@media (max-width: 720px) {
  .command-label, .command kbd { display: none; }
  .command { flex: 0 0 auto; width: var(--control-h-lg); padding: 0; justify-content: center; margin: 0 0 0 auto; }
}
@media (max-width: 960px) {
  .sg-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .sg-toc { position: static; max-height: none; padding: var(--space-5) 0 0; display: flex; gap: var(--space-2); overflow-x: auto; border-bottom: var(--border-width) solid var(--border-subtle); padding-bottom: var(--space-3); }
  .sg-toc h2, .sg-toc .toc-group-extra { display: none; }
  .sg-toc ul { display: flex; gap: var(--space-1); }
  .sg-toc a { white-space: nowrap; }
  .sg-toc a[aria-current="true"] { box-shadow: inset 0 -2px 0 var(--accent); }
  .sg-main { padding-top: var(--space-8); }
}
@media (max-width: 860px) {
  .sg-layout { padding: 0 var(--space-4); }
  .type-row { grid-template-columns: minmax(0, 1fr); gap: var(--space-1); }
}
@media (max-width: 640px) {
  .app-header { height: auto; flex-wrap: wrap; padding: var(--space-3) var(--space-4); row-gap: var(--space-3); }
  .specimen { padding: var(--space-4); }
  .metric { border-right: 0; border-bottom: var(--border-width) solid var(--border-subtle); }
  .toast-region { left: var(--space-4); right: var(--space-4); }
  .toast { min-width: 0; max-width: none; }
}

/* ==================================================================
   SPECIMEN HELPERS (replace inline style attributes; CSP forbids them)
   ================================================================== */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.intro-control { min-width: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.span-all { grid-column: 1 / -1; }
.note { margin-top: var(--space-2); color: var(--text-muted); font-size: var(--text-sm); }
.muted-sm { color: var(--text-muted); font-size: var(--text-sm); }
.grid-wide { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.card-text { margin-top: var(--space-1); color: var(--text-muted); }

.t-display { font-size: var(--text-display); font-weight: 600; letter-spacing: -0.02em; }
.t-h1 { font-size: var(--text-3xl); font-weight: 600; letter-spacing: -0.015em; }
.t-h2 { font-size: var(--text-2xl); font-weight: 600; }
.t-h3 { font-size: var(--text-xl); font-weight: 600; }
.t-h4 { font-size: var(--text-lg); font-weight: 600; }
.t-wrap { white-space: normal; }
.t-small { font-size: var(--text-sm); color: var(--text-secondary); }
.t-caption { font-size: var(--text-xs); color: var(--text-muted); }
.t-mono { font-family: var(--mono); font-size: var(--text-sm); }
.t-metric { font-family: var(--mono); font-size: 28px; font-weight: 500; font-variant-numeric: tabular-nums; }

.radius-demo.r-sm { border-radius: var(--radius-sm); }
.radius-demo.r-md { border-radius: var(--radius-md); }
.radius-demo.r-lg { border-radius: var(--radius-lg); }
.radius-demo.r-xl { border-radius: var(--radius-xl); }
.radius-demo.r-pill { border-radius: var(--radius-pill); }
.elev-demo.e-0 { background: var(--surface-panel); }
.elev-demo.e-1 { background: var(--surface-raised); box-shadow: var(--shadow-1); }
.elev-demo.e-2 { background: var(--surface-panel); box-shadow: var(--shadow-2); }
.elev-demo.e-3 { background: var(--surface-panel); box-shadow: var(--shadow-3); }

.btn-primary.force-hover { background: var(--action-primary-hover); border-color: var(--action-primary-hover); }
.btn.force-pressed { background: var(--surface-hover); }
.btn-primary.force-pressed { background: var(--action-primary-pressed); border-color: var(--action-primary-pressed); }

.skeleton.w-40 { width: 40%; }
.skeleton.w-70 { width: 70%; }
.skeleton.w-90 { width: 90%; }
.empty-icon.is-danger { color: var(--danger); }

/* ==================================================================
   MENU TRIGGERS AND SPLIT BUTTON
   Component alias: --split-divider
   ================================================================== */
.menu-anchor .menu.align-end { left: auto; right: 0; }
.chev { transition: transform var(--dur-fast) var(--ease); }
[aria-expanded="true"] > .chev { transform: rotate(180deg); }
.split { --split-divider: rgb(255 255 255 / 0.22); position: relative; display: inline-flex; }
/* Menu anchors to the whole split group, left edge under the main button. */
.split > .menu-anchor { position: static; }
.split > .btn:first-child { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.split > .menu-anchor > .btn { border-radius: 0 var(--radius-md) var(--radius-md) 0; margin-left: calc(-1 * var(--border-width)); --btn-px: 0; width: 34px; }
.split > .menu-anchor > .btn-primary { border-left-color: var(--split-divider); }
.split > .menu-anchor > .btn:not(.btn-primary) { border-left-color: var(--border-strong); }

/* ==================================================================
   DATA TABLE BUILDER (js/data-table.js)
   ================================================================== */
.dt { background: var(--surface-panel); border: var(--border-width) solid var(--border-default); border-radius: var(--radius-xl); overflow: hidden; }
.dt-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: var(--border-width) solid var(--border-subtle); }
.dt-search { flex: 1 1 240px; max-width: 360px; }
.dt-count { margin-left: auto; font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); white-space: nowrap; }
.dt-scroll { overflow-x: auto; }
.dt .data-table th.dt-col-check, .dt .data-table td.dt-col-check { width: 44px; padding-right: 0; }
.dt .data-table th.dt-col-actions { text-align: right; }
.dt .data-table tbody tr { transition: opacity var(--dur-med) var(--ease), background var(--dur-fast) var(--ease); }
.dt .data-table tbody tr.dt-removing { opacity: 0; }
.dt[aria-busy="true"] .data-table tbody { opacity: 0.55; }
.dt .sort-btn .icon { opacity: 0.35; }
.dt th[aria-sort] .sort-btn { color: var(--text-primary); }
.dt th[aria-sort] .sort-btn .icon { opacity: 1; }
.dt th[aria-sort="ascending"] .sort-btn .icon { transform: rotate(180deg); }
.dt-message td { padding: var(--space-8) var(--space-4); text-align: center; color: var(--text-muted); }
.dt-message .empty { border: 0; padding: var(--space-4); }
.dt-skeleton td { padding-top: var(--space-4); padding-bottom: var(--space-4); }
.dt-footer { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); padding: var(--space-3) var(--space-4); border-top: var(--border-width) solid var(--border-subtle); font-size: var(--text-sm); color: var(--text-muted); }
.dt-footer[hidden] { display: none; }
.dt-range { margin-right: auto; font-family: var(--mono); font-size: var(--text-xs); }
.dt-page-size { display: inline-flex; align-items: center; gap: var(--space-2); }
.dt-footer .select, .dt-page-size .select { width: auto; --field-h: var(--control-h-sm); font-size: var(--text-sm); }
.dt-page-num { font-family: var(--mono); font-size: var(--text-xs); }
.bulk-bar[hidden] { display: none; }
.bulk-bar .bulk-clear { margin-left: auto; }
.dt-demo-controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3) var(--space-6); margin-top: var(--space-4); }
.usage { margin-top: var(--space-4); }
.usage pre { margin: 0; padding: var(--space-4); overflow-x: auto; background: var(--surface-inset); font-size: var(--text-sm); line-height: var(--leading-code); color: var(--syn-plain); border-top: var(--border-width) solid var(--border-subtle); }
.toast-danger .icon { color: var(--danger); }
.toast-info .icon { color: var(--info); }

/* ==================================================================
   SELECT PICKER
   Native pickers take their highlight color from the OS (often a harsh
   system accent). Chromium's customizable select lets the picker use
   tokens: soft accent tint for the chosen option, surface step on hover.
   Other browsers keep the native picker; the field itself is unchanged.
   ================================================================== */
@supports (appearance: base-select) {
  .select, .select::picker(select) { appearance: base-select; }
  .select { display: inline-flex; align-items: center; gap: var(--space-2); padding-right: var(--space-3); background-image: none; }
  .select::picker-icon { color: var(--text-muted); transition: rotate var(--dur-fast) var(--ease); }
  .select:open::picker-icon { rotate: 180deg; }
  .select:open { border-color: var(--border-strong); }
  .select::picker(select) {
    margin-block: var(--space-1); padding: var(--space-1);
    min-width: anchor-size(width);
    background: var(--surface-panel); color: var(--text-primary);
    border: var(--border-width) solid var(--border-default); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
  }
  .select option {
    display: flex; align-items: center; gap: var(--space-2);
    min-height: var(--control-h-sm); padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-md); color: var(--text-secondary); cursor: pointer;
  }
  .select option:hover, .select option:focus-visible { background: var(--surface-hover); color: var(--text-strong); outline: none; }
  .select option:checked { background: var(--accent-soft); color: var(--text-strong); font-weight: 500; }
  .select option::checkmark { order: 1; margin-left: auto; color: var(--accent); }
}

.stack > .segmented { justify-self: start; }

/* ==================================================================
   APP PAGE SHELL
   Layout primitives for real app pages (not gallery scaffolding).
   Spacing follows design-implementation-guide.md section 5.1:
   page gutters --space-7 (--space-4 at 860px and below), page top
   --space-10, bottom --space-12, blocks on a page --space-8.
   ================================================================== */
.page {
  max-width: var(--content-max); margin: 0 auto;
  padding: var(--space-10) var(--space-7) var(--space-12);
  display: grid; gap: var(--space-8); align-content: start;
}
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-5); }
.page-head > div:first-child { display: grid; gap: var(--space-1); min-width: 0; }
.page-head .page-title, .page-head .page-subtitle { margin-top: 0; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.page-stack { display: grid; gap: var(--space-8); align-content: start; min-width: 0; }
.page-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 380px); gap: var(--space-8); align-items: start; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.panel-stack { display: grid; gap: var(--space-4); }
@media (max-width: 1100px) { .page-split { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 860px) { .page { padding: var(--space-8) var(--space-4) var(--space-10); } }

/* Command palette (js/app-header.js) */
.palette { width: min(640px, calc(100vw - 32px)); padding: 0; margin-top: 12vh; border: var(--border-width) solid var(--border-default); border-radius: var(--radius-xl); background: var(--surface-panel); color: var(--text-primary); box-shadow: var(--shadow-3); }
.palette::backdrop { background: var(--surface-overlay); }
.palette-search { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: var(--border-width) solid var(--border-subtle); color: var(--text-muted); }
.palette-search input { flex: 1; min-width: 0; height: var(--control-h); border: 0; background: transparent; color: var(--text-primary); font-size: var(--text-lg); outline: none; }
.palette-list { list-style: none; margin: 0; padding: var(--space-2); max-height: min(420px, 60vh); overflow-y: auto; }
.palette-group { padding: var(--space-2) var(--space-3) var(--space-1); font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.palette-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); color: var(--text-secondary); cursor: pointer; }
.palette-item[aria-selected="true"] { background: var(--surface-selected); color: var(--text-strong); box-shadow: inset 2px 0 0 var(--accent); }
.palette-item .palette-meta { margin-left: auto; font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }
.palette-empty { padding: var(--space-6); text-align: center; color: var(--text-muted); font-size: var(--text-sm); }
.palette-foot { display: flex; gap: var(--space-4); padding: var(--space-2) var(--space-4); border-top: var(--border-width) solid var(--border-subtle); font-size: var(--text-xs); color: var(--text-muted); }
.palette-item-main { display: grid; gap: var(--space-1); min-width: 0; flex: 1; }
.palette-title, .palette-snippet, .palette-context { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-title { color: var(--text-primary); }
.palette-snippet, .palette-context { color: var(--text-muted); font-size: var(--text-xs); }
.palette-item .palette-meta { display: grid; gap: var(--space-1); flex: 0 1 40%; min-width: 0; margin-left: 0; justify-items: end; text-align: right; white-space: nowrap; }
.palette-status { padding: var(--space-2) var(--space-4); color: var(--text-muted); font-size: var(--text-xs); }
.palette-foot { align-items: center; flex-wrap: wrap; }
.palette-scope { margin-left: auto; border: 0; padding: 0; background: transparent; color: var(--accent); font: inherit; cursor: pointer; }
.palette-scope:focus-visible { outline: var(--focus-width) solid var(--focus-color); outline-offset: var(--focus-offset); }
.search-result { display: grid; gap: var(--space-2); padding: var(--space-4); border: var(--border-width) solid var(--border-subtle); border-radius: var(--radius-lg); background: var(--surface-raised); text-decoration: none; }
.search-result:hover, .search-result:focus-visible { border-color: var(--accent-line); background: var(--surface-hover); }
.search-result-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.search-result-title { color: var(--text-primary); font-weight: 600; }
.search-result-context, .search-result-snippet { color: var(--text-muted); font-size: var(--text-sm); overflow-wrap: anywhere; }
.search-results { display: grid; gap: var(--space-4); }
.search-results-status { color: var(--text-muted); font-size: var(--text-sm); }

/* ==================================================================
   SHARED APP-PAGE PIECES
   ================================================================== */
/* Components carry no outer margin; the gallery re-adds its own spacing. */
.sg-section > .table-wrap, .sg-block > .table-wrap, .sg-block > .dt, .sg-section > .dt { margin-top: var(--space-4); }

/* Dialogs: head with an optional close button, scrolling body, size variants. */
dialog.dialog[open] { display: flex; flex-direction: column; max-height: min(88vh, calc(100dvh - 32px)); }
dialog.dialog > form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.dialog-head { display: flex; align-items: flex-start; gap: var(--space-3); }
.dialog-head > :first-child { flex: 1; min-width: 0; }
.dialog-head h2 { margin: 0; }
.dialog-body { flex: 1; min-height: 0; overflow-y: auto; align-content: start; }
.dialog-foot .push-start { margin-right: auto; }
dialog.dialog.dialog-lg { width: min(720px, calc(100vw - 32px)); }
dialog.dialog.dialog-xl { width: min(960px, calc(100vw - 32px)); }
.dialog-error:empty, .field-error:empty { display: none; }

/* Heading with its one-line description (ladder row 3). */
.heading-group { display: grid; gap: var(--space-1); min-width: 0; }
.heading-group > * { margin: 0; }

/* Card grid for app pages (the gallery's .specimen-grid is scaffolding). */
.card-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card-stack { display: grid; gap: var(--space-3); align-content: start; }

/* Monospace inline value: ids, paths, counts. */
.mono { font-family: var(--mono); font-size: var(--text-sm); }

/* Range slider: native control tinted with the action color. */
.range { width: 100%; min-height: var(--control-h); accent-color: var(--action-primary); cursor: pointer; }
.range:disabled { cursor: not-allowed; opacity: 0.5; }

/* pre.code without line-number spans still gets side padding. */
pre.code:not(:has(.ln)) { padding: var(--space-3) var(--space-4); white-space: pre-wrap; overflow-wrap: anywhere; }

/* Selects keep one line; long option text truncates in the closed control. */
.select { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Grid children may shrink below their content width, so wide tables and long
   ids scroll inside .table-wrap / pre instead of widening the page. */
.page > *, .page-stack > *, .page-split > *, .panel-stack > *, .panel, .panel-body, .card { min-width: 0; }
.notice > div, .banner > span, .kv dd, .panel-head .meta { overflow-wrap: anywhere; }

/* Bar fill widths in 1% steps (JS sets class pw-N; no inline style). */
.progress > span.pw-0 { width: 0%; }
.progress > span.pw-1 { width: 1%; }
.progress > span.pw-2 { width: 2%; }
.progress > span.pw-3 { width: 3%; }
.progress > span.pw-4 { width: 4%; }
.progress > span.pw-5 { width: 5%; }
.progress > span.pw-6 { width: 6%; }
.progress > span.pw-7 { width: 7%; }
.progress > span.pw-8 { width: 8%; }
.progress > span.pw-9 { width: 9%; }
.progress > span.pw-10 { width: 10%; }
.progress > span.pw-11 { width: 11%; }
.progress > span.pw-12 { width: 12%; }
.progress > span.pw-13 { width: 13%; }
.progress > span.pw-14 { width: 14%; }
.progress > span.pw-15 { width: 15%; }
.progress > span.pw-16 { width: 16%; }
.progress > span.pw-17 { width: 17%; }
.progress > span.pw-18 { width: 18%; }
.progress > span.pw-19 { width: 19%; }
.progress > span.pw-20 { width: 20%; }
.progress > span.pw-21 { width: 21%; }
.progress > span.pw-22 { width: 22%; }
.progress > span.pw-23 { width: 23%; }
.progress > span.pw-24 { width: 24%; }
.progress > span.pw-25 { width: 25%; }
.progress > span.pw-26 { width: 26%; }
.progress > span.pw-27 { width: 27%; }
.progress > span.pw-28 { width: 28%; }
.progress > span.pw-29 { width: 29%; }
.progress > span.pw-30 { width: 30%; }
.progress > span.pw-31 { width: 31%; }
.progress > span.pw-32 { width: 32%; }
.progress > span.pw-33 { width: 33%; }
.progress > span.pw-34 { width: 34%; }
.progress > span.pw-35 { width: 35%; }
.progress > span.pw-36 { width: 36%; }
.progress > span.pw-37 { width: 37%; }
.progress > span.pw-38 { width: 38%; }
.progress > span.pw-39 { width: 39%; }
.progress > span.pw-40 { width: 40%; }
.progress > span.pw-41 { width: 41%; }
.progress > span.pw-42 { width: 42%; }
.progress > span.pw-43 { width: 43%; }
.progress > span.pw-44 { width: 44%; }
.progress > span.pw-45 { width: 45%; }
.progress > span.pw-46 { width: 46%; }
.progress > span.pw-47 { width: 47%; }
.progress > span.pw-48 { width: 48%; }
.progress > span.pw-49 { width: 49%; }
.progress > span.pw-50 { width: 50%; }
.progress > span.pw-51 { width: 51%; }
.progress > span.pw-52 { width: 52%; }
.progress > span.pw-53 { width: 53%; }
.progress > span.pw-54 { width: 54%; }
.progress > span.pw-55 { width: 55%; }
.progress > span.pw-56 { width: 56%; }
.progress > span.pw-57 { width: 57%; }
.progress > span.pw-58 { width: 58%; }
.progress > span.pw-59 { width: 59%; }
.progress > span.pw-60 { width: 60%; }
.progress > span.pw-61 { width: 61%; }
.progress > span.pw-62 { width: 62%; }
.progress > span.pw-63 { width: 63%; }
.progress > span.pw-64 { width: 64%; }
.progress > span.pw-65 { width: 65%; }
.progress > span.pw-66 { width: 66%; }
.progress > span.pw-67 { width: 67%; }
.progress > span.pw-68 { width: 68%; }
.progress > span.pw-69 { width: 69%; }
.progress > span.pw-70 { width: 70%; }
.progress > span.pw-71 { width: 71%; }
.progress > span.pw-72 { width: 72%; }
.progress > span.pw-73 { width: 73%; }
.progress > span.pw-74 { width: 74%; }
.progress > span.pw-75 { width: 75%; }
.progress > span.pw-76 { width: 76%; }
.progress > span.pw-77 { width: 77%; }
.progress > span.pw-78 { width: 78%; }
.progress > span.pw-79 { width: 79%; }
.progress > span.pw-80 { width: 80%; }
.progress > span.pw-81 { width: 81%; }
.progress > span.pw-82 { width: 82%; }
.progress > span.pw-83 { width: 83%; }
.progress > span.pw-84 { width: 84%; }
.progress > span.pw-85 { width: 85%; }
.progress > span.pw-86 { width: 86%; }
.progress > span.pw-87 { width: 87%; }
.progress > span.pw-88 { width: 88%; }
.progress > span.pw-89 { width: 89%; }
.progress > span.pw-90 { width: 90%; }
.progress > span.pw-91 { width: 91%; }
.progress > span.pw-92 { width: 92%; }
.progress > span.pw-93 { width: 93%; }
.progress > span.pw-94 { width: 94%; }
.progress > span.pw-95 { width: 95%; }
.progress > span.pw-96 { width: 96%; }
.progress > span.pw-97 { width: 97%; }
.progress > span.pw-98 { width: 98%; }
.progress > span.pw-99 { width: 99%; }
.progress > span.pw-100 { width: 100%; }

/* ===== M25 claim form fields (N14: service-line row, diagnosis grid). Tokens only. ===== */
.claim-block { display: grid; gap: var(--space-3); }
.claim-block > h5 { font-family: var(--mono); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.claim-dx { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: var(--space-3); }
.claim-cell { display: grid; gap: var(--space-1); min-width: 0; align-content: start; }
.claim-cell-label { font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }
.claim-cell-pair { display: grid; grid-template-columns: minmax(0, 1fr) var(--space-12); gap: var(--space-1); }
.claim-lines { display: grid; gap: var(--space-3); }
.claim-line { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: var(--space-3); align-items: end; padding: var(--space-4); border: var(--border-width) solid var(--border-default); border-radius: var(--radius-lg); background: var(--surface-panel); }
.claim-line-no { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }
.claim-line .claim-wide { grid-column: span 2; }
.claim-mods { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-1); }
.claim-readonly { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-5); font-size: var(--text-sm); color: var(--text-secondary); }
.claim-missing { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); }

/* ===== M11/M12 lookup browsers (N2 term-tree, N3 tabular-tree, N4 note-callout, N5 pcs-builder). Tokens only. ===== */
.page-split-even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .page-split-even { grid-template-columns: minmax(0, 1fr); } }
.code-link { font-family: var(--mono); font-size: var(--text-sm); color: var(--text-link); text-decoration: none; border-radius: var(--radius-sm); }
.code-link:hover { text-decoration: underline; }
.code-link:focus-visible, .tree-link:focus-visible { outline: var(--focus-width) solid var(--focus-color); outline-offset: var(--focus-offset); }

/* Tree: lazy ARIA tree. Rows are focusable treeitems; the label selects, the chevron opens. */
.tree-host { max-height: 70vh; overflow: auto; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin-left: var(--space-3); padding-left: var(--space-2); border-left: var(--border-width) solid var(--border-subtle); }
.tree-item { display: block; border-radius: var(--radius-md); }
.tree-item:focus { outline: none; }
.tree-item:focus-visible > .tree-row { outline: var(--focus-width) solid var(--focus-color); outline-offset: calc(var(--focus-width) * -1); border-radius: var(--radius-md); }
.tree-row { display: flex; align-items: flex-start; gap: var(--space-1); }
.tree-toggle { flex-shrink: 0; width: var(--control-h-sm); height: var(--control-h-sm); display: inline-grid; place-items: center; border: 0; background: none; color: var(--text-muted); border-radius: var(--radius-md); cursor: pointer; }
button.tree-toggle:hover { color: var(--text-strong); background: var(--surface-hover); }
span.tree-toggle { cursor: default; }
.tree-toggle .icon { transition: transform var(--dur-fast) var(--ease); }
.tree-item[aria-expanded="true"] > .tree-row .tree-toggle .icon { transform: rotate(90deg); }
.tree-label { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-2); padding: var(--space-1) var(--space-2); min-height: var(--control-h-sm); border-radius: var(--radius-md); color: var(--text-secondary); font-size: var(--text-sm); cursor: pointer; overflow-wrap: anywhere; }
.tree-label:hover { background: var(--surface-hover); }
.tree-item[aria-selected="true"] > .tree-row > .tree-label { background: var(--surface-selected); box-shadow: inset 2px 0 0 var(--accent); color: var(--text-strong); }
.tree-code, .tree-term { font-weight: 500; color: var(--text-strong); }
.tree-code { font-family: var(--mono); }
.tree-muted { color: var(--text-muted); }
.tree-codes { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-2); }
.tree-link { padding: 0; border: 0; background: none; color: var(--text-link); font: inherit; cursor: pointer; border-radius: var(--radius-sm); }
.tree-link:hover { text-decoration: underline; }
.tree-status { padding: var(--space-1) var(--space-2); font-size: var(--text-sm); color: var(--text-muted); }
.tree-status.is-error { color: var(--danger); }

/* Note callout: one Tabular note group. Excludes1 is the strong one. */
.note-callout { --c-fg: var(--accent); --c-bg: var(--surface-inset); --c-line: var(--border-default); display: grid; gap: var(--space-2); padding: var(--space-3) var(--space-4); border: var(--border-width) solid var(--c-line); border-left: var(--space-1) solid var(--c-fg); border-radius: var(--radius-lg); background: var(--c-bg); font-size: var(--text-sm); color: var(--text-secondary); }
.note-callout h5 { margin: 0; font-family: var(--mono); font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--c-fg); }
.note-callout p { margin: 0; }
.note-excludes1 { --c-fg: var(--danger); --c-bg: var(--danger-bg); --c-line: var(--danger-line); }
.note-excludes2 { --c-fg: var(--warning); --c-bg: var(--warning-bg); --c-line: var(--warning-line); }
.note-codeFirst, .note-useAdditionalCode, .note-codeAlso { --c-fg: var(--info); --c-bg: var(--info-bg); --c-line: var(--info-line); }

/* PCS builder: seven-character code string and the selectable values of characters 4 to 7. */
.pcs-code { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.pcs-char { display: grid; justify-items: center; gap: var(--space-1); min-width: var(--space-10); padding: var(--space-2) var(--space-3); border: var(--border-width) solid var(--border-default); border-radius: var(--radius-md); background: var(--surface-inset); }
.pcs-char-value { font-family: var(--mono); font-size: var(--text-xl); font-weight: 500; color: var(--text-strong); }
.pcs-char-pos { font-family: var(--mono); font-size: var(--text-xs); color: var(--text-muted); }
.pcs-char.is-empty .pcs-char-value { color: var(--text-disabled); }
.pcs-char.is-set { border-color: var(--accent-line); background: var(--accent-soft); }
.pcs-axes { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-4); }
.pcs-axis { display: grid; gap: var(--space-2); align-content: start; min-width: 0; }
.pcs-axis h5 { margin: 0; font-family: var(--mono); font-size: var(--text-xs); font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.pcs-option { display: grid; grid-template-columns: var(--space-5) minmax(0, 1fr); gap: var(--space-2); align-items: baseline; padding: var(--space-2) var(--space-3); border: var(--border-width) solid var(--border-default); border-radius: var(--radius-md); background: var(--surface-panel); color: var(--text-secondary); font: inherit; font-size: var(--text-sm); text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.pcs-option:hover { border-color: var(--border-strong); }
.pcs-option:focus-visible { outline: var(--focus-width) solid var(--focus-color); outline-offset: var(--focus-offset); }
.pcs-option[aria-pressed="true"] { border-color: var(--accent-line); background: var(--surface-selected); color: var(--text-strong); box-shadow: inset 2px 0 0 var(--accent); }
.pcs-option:disabled { color: var(--text-disabled); cursor: not-allowed; }
.pcs-option-value { font-family: var(--mono); color: var(--text-strong); }
/* ===== end M11/M12 lookup browsers ===== */
