/* ==========================================================================
   My Easy Science — assets/ui.css
   ONE shared stylesheet for the whole revamped site. Every page links
   this file and nothing else for shared styles. Per-tool CSS may remain
   only for tool-specific plot or canvas details; there is no
   assets/tool-base.css and no .tool-body scoping anywhere.

   Tokens: colour, type scale, 4/8 px spacing, radius, shadow, focus
   ring, motion. Neutral surfaces; one calm accent per discipline:
   Pharmacology blue, Chemistry green, Figures violet. Light and dark
   themes, both contrast-checked (WCAG 2.2 AA):
     light: ink #16283d on surface #ffffff = 14.9:1; muted #44546a = 7.0:1;
            primary #1f4e79 on #ffffff = 8.1:1; chem green #1e6b3a = 5.9:1;
            figures violet #5b3a9e = 7.4:1; ok #276a2e = 5.9:1;
            warn #8a5200 = 6.0:1; err #b3261e = 5.9:1.
     dark:  ink #e8eff9 on surface #13233a = 13.4:1; muted #a7b8d0 = 7.1:1;
            primary #7fb3e8 on #13233a = 6.9:1; accents lightened to
            >= 4.5:1 against the dark surface.
   Type: system font stack only, 16 px base, 1.5 line height.
   Spacing uses only var(--s1)..var(--s7) (4/8 px steps).
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  /* Colour — light theme (default) */
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --surface-3: #e3eaf2;
  --ink: #16283d;
  --ink-2: #2c3e55;
  --muted: #44546a;
  --line: #d8e0ea;
  --line-strong: #b9c6d6;
  --primary: #1f4e79;
  --primary-hover: #173d60;
  --primary-soft: #e4edf5;
  --on-primary: #ffffff;
  --accent-pharm: #1f4e79;   /* Pharmacology blue */
  --accent-chem: #1e6b3a;    /* Chemistry green */
  --accent-fig: #5b3a9e;     /* Figures violet */
  --accent-pharm-soft: #e4edf5;
  --accent-chem-soft: #e3f0e8;
  --accent-fig-soft: #ece6f6;
  --ok: #276a2e;
  --ok-soft: #e4f1e5;
  --warn: #8a5200;
  --warn-soft: #fdf1dc;
  --err: #b3261e;
  --err-soft: #fbe9e7;
  --info-soft: #e4edf5;
  --plot-grid: #d8e0ea;
  --plot-ink: #44546a;

  /* Type scale */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 16px;
  --fs-lg: 18px;
  --fs-xl: 20px;
  --fs-2xl: 24px;
  --fs-3xl: 32px;
  --lh: 1.5;
  --lh-tight: 1.25;

  /* Spacing (4/8 px steps only) */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  /* Radius, shadow, focus, motion */
  --radius-control: 6px;
  --radius-card: 10px;
  --radius-chip: 999px;
  --shadow-card: 0 1px 2px rgba(22, 40, 61, .07);
  --shadow-popover: 0 8px 24px rgba(22, 40, 61, .18);
  --shadow-sheet: 0 -8px 32px rgba(22, 40, 61, .22);
  --focus-ring: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary);
  --dur-fast: 120ms;
  --dur-med: 180ms;
  --dur-slow: 240ms;
  --ease-out: ease-out;
  --header-h: 56px;
  --content-max: 1200px;
  --workbench-max: 1440px;
  --controls-w: 340px;
}

[data-theme="dark"] {
  --bg: #0b1523;
  --surface: #13233a;
  --surface-2: #182c46;
  --surface-3: #1f3857;
  --ink: #e8eff9;
  --ink-2: #c3d2e6;
  --muted: #a7b8d0;
  --line: #26405f;
  --line-strong: #3a5a80;
  --primary: #7fb3e8;
  --primary-hover: #9cc4ee;
  --primary-soft: #1b3049;
  --on-primary: #0b1523;
  --accent-pharm: #7fb3e8;
  --accent-chem: #6fc48d;
  --accent-fig: #b89ae8;
  --accent-pharm-soft: #1b3049;
  --accent-chem-soft: #16382a;
  --accent-fig-soft: #2b2144;
  --ok: #7cc584;
  --ok-soft: #173a20;
  --warn: #f0b45c;
  --warn-soft: #3d2c10;
  --err: #f28b82;
  --err-soft: #431b18;
  --info-soft: #1b3049;
  --plot-grid: #26405f;
  --plot-ink: #a7b8d0;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow-popover: 0 8px 24px rgba(0, 0, 0, .5);
  --shadow-sheet: 0 -8px 32px rgba(0, 0, 0, .5);
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: var(--fs-base); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh);
  color: var(--ink);
  background: var(--bg);
}
h1, h2, h3, h4 { line-height: var(--lh-tight); margin: 0 0 var(--s2); font-weight: 650; }
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
p { margin: 0 0 var(--s4); }
a { color: var(--primary); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--primary-hover); }
img, svg, canvas, video { max-width: 100%; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: inherit; }
code, kbd, .mono, math { font-family: var(--font-mono); }
math { font-size: .95em; }
/* Tabular numerals for all numeric output */
.num, td, .result-value, .stat-value, output, [data-num] { font-variant-numeric: tabular-nums; }
::selection { background: var(--primary-soft); }

/* Visible focus everywhere (WCAG 2.2 AA) */
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-control); }
:focus:not(:focus-visible) { outline: none; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}
.skip-link {
  position: absolute; left: var(--s4); top: -64px; z-index: 200;
  background: var(--primary); color: var(--on-primary);
  padding: var(--s2) var(--s4); border-radius: var(--radius-control);
  text-decoration: none; transition: top var(--dur-fast) var(--ease-out);
}
.skip-link:focus { top: var(--s2); color: var(--on-primary); }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; vertical-align: -4px; }
.icon.is-on { display: inline-block; }
/* Theme button shows only the icon for the current choice. */
#themeBtn .icon { display: none; }
#themeBtn .icon.is-on { display: inline-block; }
.theme-menu { top: 52px; right: 12px; }

/* ---------- 3. Page frame ---------- */
.page { max-width: var(--content-max); margin: 0 auto; padding: var(--s5) var(--s4) var(--s7); }
.page--wide { max-width: var(--workbench-max); }
.lede { font-size: var(--fs-lg); color: var(--ink-2); margin-bottom: var(--s4); }
.meta-line { color: var(--muted); font-size: var(--fs-sm); margin-bottom: var(--s5); }
.meta-line strong { color: var(--ink-2); font-weight: 650; }
.prose { max-width: 72ch; }
.prose h2 { margin-top: var(--s6); }

/* ---------- 4. Header (one slim row, 56 px) ---------- */
.site-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--s2);
  padding: 0 var(--s4);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: var(--s2);
  font-weight: 700; font-size: var(--fs-lg); color: var(--ink);
  text-decoration: none; white-space: nowrap; min-height: 44px;
}
.brand-mark { width: 32px; height: 32px; border-radius: var(--radius-control); object-fit: cover; }
.site-nav { display: flex; align-items: center; gap: var(--s1); margin-left: var(--s2); }
.site-nav a {
  display: flex; align-items: center; min-height: 44px; padding: 0 var(--s3);
  color: var(--ink-2); text-decoration: none; border-radius: var(--radius-control);
  font-weight: 550;
}
.site-nav a:hover { background: var(--surface-2); color: var(--ink); }
.site-nav a[aria-current="page"] { color: var(--primary); background: var(--primary-soft); }
.header-spacer { flex: 1; }
.header-search {
  min-width: 0; max-width: 260px; flex: 0 1 260px;
  justify-content: flex-start; gap: var(--s2); color: var(--muted);
}
.header-search .search-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-toggle { display: none; }

/* Mobile sheet menu (full height) */
.nav-sheet {
  position: fixed; inset: 0 0 0 auto; width: min(320px, 88vw); height: 100dvh;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--shadow-popover); z-index: 150;
  transform: translateX(102%); transition: transform var(--dur-med) var(--ease-out);
  display: flex; flex-direction: column; padding: var(--s4);
}
.nav-sheet.open { transform: translateX(0); }
.nav-sheet h2 { font-size: var(--fs-lg); }
.nav-sheet a {
  display: flex; align-items: center; min-height: 48px; padding: 0 var(--s2);
  color: var(--ink); text-decoration: none; border-radius: var(--radius-control);
  font-weight: 550; border-bottom: 1px solid var(--line);
}
.nav-sheet a:hover { background: var(--surface-2); }
.nav-sheet .nav-sheet-close { align-self: flex-end; }
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 140;
  background: rgba(11, 21, 35, .5);
}
.sheet-backdrop[hidden] { display: none; }

/* ---------- 5. Footer (one slim line) ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  padding: var(--s4);
  color: var(--muted); font-size: var(--fs-sm);
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5);
  align-items: center; justify-content: center;
  background: var(--surface);
}
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--primary); }

/* ---------- 6. Breadcrumb ---------- */
.breadcrumb { font-size: var(--fs-sm); color: var(--muted); margin-bottom: var(--s4); }
.breadcrumb a { color: var(--muted); }
.breadcrumb [aria-current="page"] { color: var(--ink-2); font-weight: 550; }

/* ---------- 7. Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: var(--s2) var(--s4);
  border-radius: var(--radius-control); border: 1px solid transparent;
  font-weight: 600; cursor: pointer; text-decoration: none;
  background: none; transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); color: var(--on-primary); }
.btn-secondary { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-tertiary { color: var(--primary); padding-left: var(--s2); padding-right: var(--s2); }
.btn-tertiary:hover { background: var(--primary-soft); }
.btn-danger { background: var(--err); color: #fff; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: var(--s1) var(--s3); font-size: var(--fs-sm); }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; flex: none;
  border: 1px solid transparent; border-radius: var(--radius-control);
  background: none; cursor: pointer; color: var(--ink-2);
}
.btn-icon:hover { background: var(--surface-2); color: var(--ink); }
.btn-icon[aria-pressed="true"], .btn-icon.is-active { background: var(--primary-soft); color: var(--primary); }

kbd, .kbd-hint {
  font-family: var(--font-mono); font-size: var(--fs-xs);
  border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: var(--radius-control);
  padding: 1px 6px; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}

/* ---------- 8. Forms: field, input, select, slider ---------- */
.field { margin-bottom: var(--s4); }
.field > label, .field-label {
  display: block; font-weight: 600; margin-bottom: var(--s1);
}
.field .field-symbol { color: var(--muted); font-weight: 400; }
.field .helper { display: block; font-size: var(--fs-sm); color: var(--muted); margin-top: var(--s1); }
.field-error { display: block; font-size: var(--fs-sm); color: var(--err); margin-top: var(--s1); min-height: 1.2em; }
.field-error:empty { display: none; }
.field.has-error .input { border-color: var(--err); }
.field.has-error .input:focus-visible { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--err); }

.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: var(--s2) var(--s3);
  border: 1px solid var(--line-strong); border-radius: var(--radius-control);
  background: var(--surface); color: var(--ink);
}
.input:hover { border-color: var(--muted); }
.input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 2px var(--primary-soft); }
.input[aria-invalid="true"] { border-color: var(--err); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .input { padding-right: 56px; }
.input-unit {
  position: absolute; right: var(--s3); color: var(--muted);
  font-size: var(--fs-sm); pointer-events: none; max-width: 48px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
textarea.input { min-height: 96px; resize: vertical; }

/* Slider with numeric field (paired) */
.slider-pair { display: grid; grid-template-columns: 1fr 96px; gap: var(--s3); align-items: center; }
.slider-pair input[type="range"] { width: 100%; min-height: 44px; accent-color: var(--primary); }
.slider-pair .input { text-align: right; padding-right: var(--s2); }
.slider-pair .slider-num-wrap { position: relative; display: flex; align-items: center; }
.slider-pair .slider-num-wrap .input-unit { right: var(--s2); }

/* ---------- 9. Segmented control ---------- */
.segmented {
  display: inline-flex; flex-wrap: wrap; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-control); padding: 2px;
}
.segmented button {
  min-height: 40px; padding: var(--s2) var(--s4);
  border: 0; border-radius: var(--radius-control); background: none;
  cursor: pointer; font-weight: 550; color: var(--ink-2); white-space: nowrap;
}
.segmented button:hover { color: var(--ink); }
.segmented button[aria-checked="true"], .segmented button[aria-selected="true"] {
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-card);
}
.segmented--block { display: flex; width: 100%; }
.segmented--block button { flex: 1; }

/* ---------- 10. Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: thin; }
.tabs [role="tab"] {
  min-height: 44px; padding: var(--s2) var(--s4);
  border: 0; border-bottom: 2px solid transparent; background: none;
  cursor: pointer; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.tabs [role="tab"]:hover { color: var(--ink); }
.tabs [role="tab"][aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.tabpanel { padding: var(--s4) 0; }
.tabpanel[hidden] { display: none; }

/* ---------- 11. Cards, badges, tables, notices ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
  padding: var(--s4);
}
.card h2, .card h3 { margin-bottom: var(--s2); }
.card-header { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s3); }

.badge {
  display: inline-flex; align-items: center; gap: var(--s1);
  font-size: var(--fs-xs); font-weight: 650; line-height: 1;
  padding: 5px var(--s2); border-radius: var(--radius-chip);
  border: 1px solid var(--line-strong); color: var(--ink-2); background: var(--surface-2);
  white-space: nowrap;
}
.badge--foundation { background: var(--accent-chem-soft); color: var(--accent-chem); border-color: transparent; }
.badge--intermediate { background: var(--accent-pharm-soft); color: var(--accent-pharm); border-color: transparent; }
.badge--advanced { background: var(--accent-fig-soft); color: var(--accent-fig); border-color: transparent; }
.badge--pharmacology { background: var(--accent-pharm-soft); color: var(--accent-pharm); border-color: transparent; }
.badge--chemistry { background: var(--accent-chem-soft); color: var(--accent-chem); border-color: transparent; }
.badge--figures { background: var(--accent-fig-soft); color: var(--accent-fig); border-color: transparent; }

.chip {
  display: inline-block; font-size: var(--fs-xs); color: var(--muted);
  border: 1px solid var(--line); border-radius: var(--radius-chip);
  padding: 3px var(--s2); background: var(--surface);
}

.table-wrap { overflow-x: auto; max-width: 100%; }
table.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.data-table caption { text-align: left; font-weight: 650; padding-bottom: var(--s2); }
.data-table th, .data-table td { text-align: left; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table thead th { background: var(--surface-2); font-weight: 650; }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table td.num, .data-table th.num { text-align: right; }

.notice {
  border: 1px solid var(--line-strong); border-left: 4px solid var(--primary);
  background: var(--info-soft); border-radius: var(--radius-control);
  padding: var(--s3) var(--s4); margin-bottom: var(--s4); font-size: var(--fs-sm);
}
.notice--warn { border-left-color: var(--warn); background: var(--warn-soft); }
.notice--error { border-left-color: var(--err); background: var(--err-soft); }
.notice--ok { border-left-color: var(--ok); background: var(--ok-soft); }
.notice strong { font-weight: 650; }

/* ---------- 12. Bottom sheet ---------- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 150;
  background: var(--surface); border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0; box-shadow: var(--shadow-sheet);
  max-height: 88dvh; display: flex; flex-direction: column;
  transform: translateY(102%); transition: transform var(--dur-med) var(--ease-out);
}
.sheet.open { transform: translateY(0); }
.sheet--peek { transform: translateY(calc(100% - 148px)); }
.sheet--peek.open { transform: translateY(calc(100% - 148px)); }
.sheet--peek.open.sheet--full { transform: translateY(0); }
.sheet-handle { display: flex; justify-content: center; padding: var(--s2) 0 0; cursor: grab; min-height: 32px; background: none; border: 0; width: 100%; }
.sheet-handle::before { content: ""; width: 40px; height: 4px; border-radius: 999px; background: var(--line-strong); }
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: 0 var(--s4) var(--s2); }
.sheet-header h2 { margin: 0; font-size: var(--fs-lg); }
.sheet-body { overflow-y: auto; padding: 0 var(--s4) var(--s5); overscroll-behavior: contain; }

/* ---------- 13. Tooltip, toast, modal, menu ---------- */
[data-tooltip] { position: relative; }
.tooltip-bubble {
  position: absolute; z-index: 180; max-width: 280px;
  background: var(--ink); color: var(--surface);
  font-size: var(--fs-sm); line-height: var(--lh);
  padding: var(--s2) var(--s3); border-radius: var(--radius-control);
  box-shadow: var(--shadow-popover); pointer-events: none;
}
[data-theme="dark"] .tooltip-bubble { background: var(--surface-3); color: var(--ink); border: 1px solid var(--line-strong); }

.toast-region { position: fixed; bottom: var(--s4); left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: var(--s2); align-items: center; width: min(480px, calc(100vw - 32px)); pointer-events: none; }
.toast {
  pointer-events: auto; width: 100%;
  background: var(--ink); color: var(--surface);
  padding: var(--s3) var(--s4); border-radius: var(--radius-control);
  box-shadow: var(--shadow-popover); font-size: var(--fs-sm);
  display: flex; gap: var(--s2); align-items: flex-start;
}
[data-theme="dark"] .toast { background: var(--surface-3); color: var(--ink); border: 1px solid var(--line-strong); }
.toast--error { background: var(--err); color: #fff; }

.modal-backdrop { position: fixed; inset: 0; z-index: 200; background: rgba(11, 21, 35, .55); display: flex; align-items: center; justify-content: center; padding: var(--s4); }
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius-card);
  box-shadow: var(--shadow-popover); max-width: 560px; width: 100%;
  max-height: 88dvh; overflow-y: auto; padding: var(--s5);
}
.modal h2 { margin-bottom: var(--s2); }
.modal-actions { display: flex; gap: var(--s2); justify-content: flex-end; margin-top: var(--s5); flex-wrap: wrap; }

.menu {
  position: absolute; z-index: 160; min-width: 200px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-card); box-shadow: var(--shadow-popover);
  padding: var(--s1);
}
.menu[hidden] { display: none; }
.menu-item {
  display: flex; align-items: center; gap: var(--s2); width: 100%;
  min-height: 44px; padding: var(--s2) var(--s3);
  border: 0; background: none; cursor: pointer; text-align: left;
  border-radius: var(--radius-control); color: var(--ink);
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); }
.menu-item .menu-check { margin-left: auto; visibility: hidden; }
.menu-item .menu-check.is-on { visibility: visible; }

/* ---------- 14. Command palette (Ctrl+K) ---------- */
.cmdk {
  position: fixed; inset: 0; z-index: 250; display: none;
  background: rgba(11, 21, 35, .55); padding: var(--s5) var(--s4);
  align-items: flex-start; justify-content: center;
}
.cmdk.open { display: flex; }
.cmdk-box {
  width: min(640px, 100%); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-card);
  box-shadow: var(--shadow-popover); overflow: hidden;
  margin-top: 8vh;
}
.cmdk-input-row { display: flex; align-items: center; gap: var(--s2); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.cmdk-input-row input { flex: 1; border: 0; background: none; min-height: 32px; font-size: var(--fs-base); }
.cmdk-input-row input:focus { outline: none; box-shadow: none; }
.cmdk-list { list-style: none; margin: 0; padding: var(--s2); max-height: 50vh; overflow-y: auto; }
.cmdk-item {
  display: flex; align-items: center; gap: var(--s3);
  min-height: 48px; padding: var(--s2) var(--s3);
  border-radius: var(--radius-control); cursor: pointer;
}
.cmdk-item[aria-selected="true"] { background: var(--primary-soft); }
.cmdk-name { font-weight: 600; }
.cmdk-sub { color: var(--muted); font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.cmdk-key { margin-left: auto; }
.cmdk-empty { padding: var(--s4); color: var(--muted); }
.cmdk-foot { display: flex; gap: var(--s4); padding: var(--s2) var(--s4); border-top: 1px solid var(--line); color: var(--muted); font-size: var(--fs-xs); flex-wrap: wrap; }
.cmdk-group { font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: var(--s3) var(--s3) var(--s1); }

/* ---------- 15. Home page ---------- */
.home-intro { padding-top: var(--s5); padding-bottom: var(--s4); }
.home-intro h1 { font-size: var(--fs-3xl); margin-bottom: var(--s2); }
.home-search { display: flex; gap: var(--s2); align-items: center; margin-top: var(--s4); max-width: 640px; }
.home-search .input-wrap { flex: 1; }
.home-search .input { padding-left: 40px; }
.home-search .input-wrap > .icon { position: absolute; left: var(--s3); color: var(--muted); pointer-events: none; }
.home-filters { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; margin: var(--s4) 0 var(--s2); }
.home-filters .filter-label { font-size: var(--fs-sm); font-weight: 600; color: var(--muted); }
.home-count { font-size: var(--fs-sm); color: var(--muted); margin: var(--s2) 0 var(--s4); }
.home-section-label { font-size: var(--fs-sm); font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: var(--s5) 0 var(--s3); }
.tool-grid {
  display: grid; gap: var(--s3);
  grid-template-columns: repeat(4, 1fr);
}
.tool-card {
  display: flex; flex-direction: column; gap: var(--s2);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
  padding: var(--s4); color: var(--ink); text-decoration: none; min-height: 44px;
}
.tool-card:hover { border-color: var(--primary); }
.tool-card:focus-visible { box-shadow: var(--focus-ring); }
.tool-card h3 { font-size: var(--fs-base); margin: 0; }
.tool-card p { font-size: var(--fs-sm); color: var(--muted); margin: 0; flex: 1; }
.tool-card-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.tool-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: var(--radius-control);
  background: var(--surface-2); color: var(--primary);
}
.tool-card[data-area="pharmacology"] .tool-icon { background: var(--accent-pharm-soft); color: var(--accent-pharm); }
.tool-card[data-area="chemistry"] .tool-icon { background: var(--accent-chem-soft); color: var(--accent-chem); }
.tool-card[data-area="figures"] .tool-icon { background: var(--accent-fig-soft); color: var(--accent-fig); }
.tool-tags { display: flex; flex-wrap: wrap; gap: var(--s1); }
.tool-card[hidden] { display: none; }
.home-empty { padding: var(--s5); text-align: center; color: var(--muted); }

/* ---------- 16. Workbench (tool pages) ---------- */
.title-strip {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3);
  margin-bottom: var(--s2);
}
.title-strip h1 { font-size: var(--fs-2xl); margin: 0; }
.title-strip .title-actions { margin-left: auto; display: flex; gap: var(--s1); flex-wrap: wrap; }
.related-line { font-size: var(--fs-sm); color: var(--muted); margin-bottom: var(--s4); }
.related-line a { color: var(--muted); }
.workbench { display: grid; grid-template-columns: var(--controls-w) minmax(0, 1fr); gap: var(--s4); align-items: start; }
.wb-controls {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card);
  padding: var(--s4);
  position: sticky; top: calc(var(--header-h) + var(--s4));
  max-height: calc(100dvh - var(--header-h) - var(--s5));
  overflow-y: auto; overscroll-behavior: contain;
}
.wb-results { min-width: 0; display: flex; flex-direction: column; gap: var(--s4); }
.wb-plot-card { padding: var(--s4); }
.control-group { border: 1px solid var(--line); border-radius: var(--radius-control); padding: var(--s3) var(--s4); margin-bottom: var(--s4); }
.control-group > summary, .control-group h3 {
  font-size: var(--fs-base); font-weight: 650; margin: 0 0 var(--s3);
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: var(--s2);
}
.control-group > summary::-webkit-details-marker { display: none; }
.control-group > summary::after { content: ""; margin-left: auto; width: 10px; height: 10px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); transition: transform var(--dur-fast) var(--ease-out); }
.control-group[open] > summary::after { transform: rotate(225deg); }
.control-group .group-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.control-group[data-accent="pharmacology"] .group-dot { background: var(--accent-pharm); }
.control-group[data-accent="chemistry"] .group-dot { background: var(--accent-chem); }
.control-group[data-accent="figures"] .group-dot { background: var(--accent-fig); }
.wb-actions { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s4); }
.wb-actions--row { flex-direction: row; flex-wrap: wrap; }
.result-hero { text-align: left; }
.result-label { font-size: var(--fs-sm); color: var(--muted); margin: 0; }
.result-value { font-size: var(--fs-3xl); font-weight: 700; line-height: var(--lh-tight); margin: var(--s1) 0; }
.result-unit { font-size: var(--fs-lg); color: var(--muted); font-weight: 550; }
.result-meaning { color: var(--ink-2); font-size: var(--fs-sm); margin: 0; }
.formula { font-family: var(--font-mono); font-size: var(--fs-sm); background: var(--surface-2); border-radius: var(--radius-control); padding: var(--s2) var(--s3); overflow-x: auto; margin-bottom: var(--s2); }
.symbol-table td:first-child { font-family: var(--font-mono); white-space: nowrap; }

/* Plot container + MESPlot */
.plot-wrap { width: 100%; max-width: 100%; overflow: hidden; }
.plot-wrap svg { display: block; width: 100%; height: auto; max-width: 100%; }
.plot-legend { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); font-size: var(--fs-sm); color: var(--ink-2); margin-top: var(--s2); }
.plot-legend-item { display: inline-flex; align-items: center; gap: var(--s2); }
.plot-legend-swatch { width: 16px; height: 4px; border-radius: 2px; flex: none; }
.plot-readout { font-size: var(--fs-sm); color: var(--muted); min-height: 1.5em; margin-top: var(--s2); }
.plot-readout strong { color: var(--ink); }
.plot-toolbar { display: flex; gap: var(--s1); flex-wrap: wrap; align-items: center; }
.plot-toolbar .spacer { flex: 1; }

/* Accordion (single-level only; never nested) */
.accordion-item { border: 1px solid var(--line); border-radius: var(--radius-control); margin-bottom: var(--s2); }
.accordion-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  width: 100%; min-height: 44px; padding: var(--s2) var(--s3);
  background: none; border: 0; cursor: pointer; font-weight: 600; text-align: left;
}
.accordion-header .icon { transition: transform var(--dur-fast) var(--ease-out); }
.accordion-item[data-open="true"] .accordion-header .icon { transform: rotate(180deg); }
.accordion-panel { padding: 0 var(--s3) var(--s3); }
.accordion-item[data-open="false"] .accordion-panel { display: none; }

/* Check-yourself reveal answers */
.qa { border: 1px solid var(--line); border-radius: var(--radius-control); padding: var(--s3) var(--s4); margin-bottom: var(--s3); }
.qa p { margin-bottom: var(--s2); }
.qa-answer[hidden] { display: none; }
.qa-answer { background: var(--surface-2); border-radius: var(--radius-control); padding: var(--s3); margin-top: var(--s2); }

/* Status / live region */
.status { font-size: var(--fs-sm); color: var(--muted); }
.status--error { color: var(--err); }
.status--ok { color: var(--ok); }

/* ---------- 17. Responsive ---------- */
@media (max-width: 1023px) {
  .tool-grid { grid-template-columns: repeat(2, 1fr); }
  .workbench { grid-template-columns: 1fr; }
  .wb-controls { position: static; max-height: none; }
  /* Phones/tablets: plot pinned at top, controls in a bottom sheet.
     Tool pages add class="wb-mobile" handling in ui.js: the controls
     panel is moved into #controlsSheet (see SHELL-SPEC.md). */
  .wb-plot-pinned { position: sticky; top: var(--header-h); z-index: 40; }
}
@media (max-width: 767px) {
  .site-nav, .header-search .search-label, .header-search .search-kbd { display: none; }
  .header-search { flex: 0 0 auto; min-width: 44px; padding: var(--s2); justify-content: center; }
  .nav-toggle { display: inline-flex; }
  .tool-grid { grid-template-columns: 1fr; }
  .page { padding: var(--s4) var(--s3) var(--s6); }
  h1 { font-size: 26px; }
  .home-intro h1 { font-size: 26px; }
  .slider-pair { grid-template-columns: 1fr 88px; }
  .title-strip .title-actions { margin-left: 0; }
}
@media (min-width: 768px) {
  .nav-sheet, .sheet-backdrop { display: none; }
}

/* ---------- 18. Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}

/* ---------- 19. Print (A4: title, inputs, plot, results table only) ---------- */
@media print {
  .site-header, .site-footer, .title-strip .title-actions, .cmdk,
  .toast-region, .nav-sheet, .sheet-backdrop, .breadcrumb,
  .wb-actions, .plot-toolbar, .tabs, .home-filters, .home-search { display: none !important; }
  body { background: #fff; color: #000; }
  .page, .page--wide { max-width: none; padding: 0; }
  .card, .wb-controls, .tool-card { box-shadow: none; border-color: #999; break-inside: avoid; }
  .workbench { grid-template-columns: 1fr; }
  .tabpanel[hidden] { display: block !important; }
  .tabpanel { padding: 0; }
  a { color: #000; text-decoration: none; }
  .plot-wrap svg text { fill: #000 !important; }
  .plot-wrap svg .mes-grid line { stroke: #ccc !important; }
}
