/*  Stewart / Figge — Acid-Base Calculator
 *  ─────────────────────────────────────────
 *  All visual styling for the single-page app.
 *  Uses CSS custom properties for dark/light theme switching.
 */

/* ═══════════════════════════════════════════════════════════
   §1  Design tokens (dark mode — default)
   ═══════════════════════════════════════════════════════════ */
/* -- Design tokens (dark) -- */
:root {
  --fg: #e6eef8; --muted: #9aa4b2; --gg-label: #9aa4b2;
  --accent: #60a5fa; --card: #0b1220;
  --border: rgba(255,255,255,0.06); --glass: rgba(255,255,255,0.03);
  --input-border: rgba(255,255,255,0.08); --tooltip-bg: rgba(2,6,23,0.92);
  --gg-guide: rgba(230,238,248,0.96);
  --gg-guide-underlay: rgba(2,6,23,0.92);
  --gg-legend-font-size: 15px;
  --scroll-hint-bg: rgba(7,16,41,0.82);
  --scroll-hint-fg: rgba(230,238,248,0.9);
  --scroll-hint-shadow: rgba(2,6,23,0.34);
  --scrollbox-border: rgba(148,163,184,0.24);
  --scrollbox-shadow: rgba(2,6,23,0.2);
  --scrollbox-bg: rgba(255,255,255,0.02);

  /* Gamblegram palette — dark mode (default) */
  /* Cations (color‑blind friendly set) */
  --gg-Na:    #0052CC; /* Na⁺ */
  --gg-K:     #009E73; /* K⁺ */
  --gg-iCa:   #CC79A7; /* iCa²⁺ */
  --gg-Mg:    #56B4E9; /* Mg²⁺ */
  /* Anions (warm / high-contrast) */
  --gg-Cl:     #D55E00; /* Cl⁻ */
  --gg-Lactate:#E69F00; /* Lactate⁻ */
  --gg-HCO3:   #F0E442; /* HCO₃⁻ */
  --gg-Aminus: #F4B183; /* Albumin anionic contribution */
  --gg-Pi:     #F7E0A0; /* Phosphate */
  /* Unknown (distinct) */
  --gg-Unknown: #B347FF; /* Unknown / SIG (neon purple) */
}

/* ═══════════════════════════════════════════════════════════
   §2  Reset & body
   ═══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  min-height: 100vh; line-height: 1.4; margin: 0;
  background: linear-gradient(180deg, #071029 0%, #071b2a 100%);
  color: var(--fg);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px 48px; overflow-y: auto;
  position: relative;
}

/* ═══════════════════════════════════════════════════════════
   §3  Container card
   ═══════════════════════════════════════════════════════════ */
/* -- Container -- */
.container {
  position: relative; width: 100%; max-width: 1100px;
  background: var(--card); border-radius: 12px; padding: 22px;
  margin: 0 auto; box-shadow: 0 8px 30px rgba(2,6,23,0.6);
  border: 1px solid var(--border);
}
h1 { margin: 0 0 6px; font-size: 20px; }
h2 { margin: 0 0 8px; }
h3 { margin: 0; }
p.muted { color: var(--muted); margin: 6px 0 18px; }
.note { color: var(--muted); margin-top: 10px; font-size: 13px; }
footer { margin-top: 14px; color: var(--muted); font-size: 13px; }
footer small { display: block; }
footer small + small { margin-top: 6px; }

/* ═══════════════════════════════════════════════════════════
   §4  Workspace layout
   ═══════════════════════════════════════════════════════════ */
/* -- Default stacked workspace -- */
.workspace {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
section.grid,
.analysis-column {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.ion-column,
.analysis-column {
  min-width: 0;
  min-height: 0;
  position: relative;
}
@media (min-width: 1400px) {
  .container { max-width: 1460px; }
  .workspace {
    display: grid;
    grid-template-columns: minmax(440px, 0.98fr) minmax(560px, 1.18fr);
    gap: 22px;
    align-items: start;
  }
  .ion-column,
  .analysis-column {
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    padding: 20px 12px 16px;
    border: 1px solid var(--scrollbox-border);
    border-radius: 14px;
    background: linear-gradient(180deg, var(--scrollbox-bg), rgba(255,255,255,0.01));
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02), 0 10px 24px var(--scrollbox-shadow);
  }
  .analysis-column {
    gap: 18px;
  }
}

/* ═══════════════════════════════════════════════════════════
   §5  Fieldsets & inputs
   ═══════════════════════════════════════════════════════════ */
/* -- Fieldsets / inputs -- */
fieldset {
  width: 100%;
  min-width: 0;
  min-inline-size: 0;
  margin: 0;
  background: var(--glass); border-radius: 8px; padding: 12px;
  border: 1px solid var(--border);
}
legend { font-weight: 600; color: var(--accent); }
label {
  display: flex; justify-content: flex-start; align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 6px 0; font-size: 16px; color: var(--fg);
}
input[type="number"], input[type="text"] {
  width: 96px; height: 40px; background: transparent;
  border: 1px solid var(--input-border);
  padding: 8px 10px; border-radius: 6px; color: inherit; text-align: right;
  font-size: 16px;
}
input[disabled] { background: rgba(255,255,255,0.01); color: var(--muted); cursor: not-allowed; }
/* native select pickers (replace sliders) */
.picker { display: inline-block; min-width: 140px; margin-left: 0; min-height: 40px; font-size: 16px; }

/* Reference-range muted styling inside labels */
.ion-label .muted { color: var(--muted); font-weight: normal; margin-left: 0.35ch; font-size: 0.95em; }
.field-note { color: var(--muted); font-size: 13px; margin: -2px 0 6px; }
.field-note sup { font-size: .72em; line-height: 1; vertical-align: super; }

/* Picker / select styling (dark/light via CSS vars) */
.picker, .unit-select {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--input-border);
  color: var(--fg);
  padding: 8px 12px;
  border-radius: 8px;
  min-height: 40px;
  font-size: 16px;
  cursor: pointer;
  -webkit-appearance: menulist-button;
  appearance: menulist-button;
}
.picker:focus, .unit-select:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.picker option { color: var(--fg); background: var(--card); }


.ion-label { white-space: normal; display: inline-block; font-weight: 600; flex: 1 1 auto; min-width: 0; }
.ion-label sup,
.gg-legend .item sup {
  font-size: .72em;
  line-height: 1;
  vertical-align: super;
  margin-left: 0.05ch;
}
.ion-label sub,
.gg-legend .item sub {
  font-size: .72em;
  line-height: 1;
  vertical-align: sub;
}
.unit-select {
  margin-left: 0; background: transparent;
  border: 1px solid var(--input-border); color: inherit;
  padding: 8px 10px; border-radius: 6px; font-size: 14px; min-height: 40px;
}
fieldset > label > span:first-child {
  flex: 1 1 auto;
  min-width: 0;
}
fieldset > label > .picker,
fieldset > label > .unit-select,
fieldset > label > input[type="number"],
fieldset > label > input[type="text"] {
  flex: 0 0 auto;
}
select.unit-select option { color: inherit; }
.checkbox-row { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 16px; padding-top: 6px; }
.checkbox-row input { width: 20px; height: 20px; margin: 0; cursor: pointer; }
.checkbox-row label {
  display: block;
  padding: 0;
  color: inherit;
  font-size: inherit;
}
.checkbox-row label sup,
.checkbox-row label sub {
  line-height: 1;
  margin-left: 0;
}
.small-note { font-size: 12px; color: var(--muted); margin-top: 6px; display: block; }
.aux-input { padding-top: 6px; }

.additional-ion-presets {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 8px; margin: 8px 0 10px;
}
.additional-ion-presets-label {
  color: var(--muted); font-size: 13px; font-weight: 600;
}
.ion-preset-btn {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}
.additional-ions-list { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.additional-ion-row {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
  padding: 12px; border-radius: 8px;
  border: 1px solid var(--border); background: rgba(255,255,255,0.02);
}
.additional-ion-grid {
  flex: 1 1 640px;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(150px, 1.7fr) repeat(2, minmax(96px, 0.95fr)) minmax(128px, 1.1fr);
  gap: 10px;
}
.additional-ion-field {
  display: flex; flex-direction: column; align-items: flex-start;
  gap: 6px; padding: 0;
}
.additional-ion-field span {
  color: var(--muted); font-size: 13px; font-weight: 600;
}
.additional-ion-field input,
.additional-ion-field select {
  width: 100%; margin: 0;
}
.additional-ion-field input[type="text"],
.additional-ion-field input[type="number"],
.additional-ion-field select {
  min-height: 40px; text-align: left;
}
.additional-ion-field select {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--input-border);
  color: var(--fg);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 16px;
}
.additional-ion-field select option { color: var(--fg); background: var(--card); }
.additional-ions-actions { margin-top: 12px; display: flex; justify-content: flex-start; }
.additional-ion-remove { flex: 0 0 auto; align-self: flex-end; }

/* ═══════════════════════════════════════════════════════════
   §6  Toolbar (global toggles)
   ═══════════════════════════════════════════════════════════ */
/* -- Toolbar -- */
.toolbar { display: flex; gap: 14px; margin-bottom: 12px; align-items: center; flex-wrap: wrap; }
.toolbar label { color: var(--muted); font-size: 16px; display: flex; gap: 8px; align-items: center; }

/* ═══════════════════════════════════════════════════════════
   §7  Mobile header (hidden on desktop)
   ═══════════════════════════════════════════════════════════ */
/* -- Mobile header (hidden on desktop) -- */
.mobile-header {
  display: none; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 0;
  border-bottom: 1px solid var(--border); margin-bottom: 12px;
}
.mobile-header .mobile-title { font-weight: 800; color: var(--accent); font-size: 15px; white-space: nowrap; }
.mobile-header .mobile-summary { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mobile-header .mh-item { color: var(--muted); font-weight: 700; font-size: 13px; }
.mobile-header .mobile-actions .compact {
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); padding: 6px 8px; border-radius: 6px;
  cursor: pointer; font-size: 12px;
}

/* ═══════════════════════════════════════════════════════════
   §8  Results panel
   ═══════════════════════════════════════════════════════════ */
/* -- Results -- */
.results.compact {
  padding: 14px 16px 11px;
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.015));
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.04);
}
.results-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.results-head h2 { margin: 0; }
.results-head-copy {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 12px;
  min-width: 0;
}
.results-head-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: left;
}
.results-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}
.result-card {
  min-width: 0;
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
}
.results.compact dt {
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.3;
}
.results.compact dd {
  font-size: clamp(16px, 1.2vw, 22px);
  margin: 4px 0 0;
  font-weight: 800;
  text-align: left;
  line-height: 1.1;
}
.img-estimate-summary {
  margin-top: -1px;
  line-height: 1.45;
}
.img-estimate-note {
  font-weight: 600;
}
.img-estimate-note span {
  font-weight: 700;
}
.img-estimate-sep {
  color: var(--muted);
}
.result-meta {
  font-size: 12px;
}
.result-meta.confidence-high { color: #34d399; }
.result-meta.confidence-medium { color: #fbbf24; }
.result-meta.confidence-low { color: #f87171; }
.results.compact dt sup { font-size: .72em; line-height: 1; vertical-align: super; }
.results.compact .ref-range {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.3;
}
.results-head .btn {
  flex-shrink: 0;
  margin-left: auto;
}
.analysis-notes {
  display: grid;
  gap: 2px;
  margin-top: -4px;
}
.analysis-notes .note {
  margin-top: 0;
}
.results.compact dt.out-of-range,
.results.compact dd.out-of-range,
.mobile-header .mh-item span.out-of-range {
  color: #f87171;
}
body.light .results.compact dt.out-of-range,
body.light .results.compact dd.out-of-range,
body.light .mobile-header .mh-item span.out-of-range {
  color: #b91c1c;
}
body.light .result-meta.confidence-high { color: #047857; }
body.light .result-meta.confidence-medium { color: #b45309; }
body.light .result-meta.confidence-low { color: #b91c1c; }
.results-actions { margin-top: 10px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.results-actions button {
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); padding: 12px 16px; border-radius: 6px;
  cursor: pointer; font-size: 14px; min-height: 44px;
}

/* Generic button style used across the UI */
.btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); padding: 10px 14px; border-radius: 6px;
  cursor: pointer; font-size: 14px; min-height: 40px; display: inline-block;
}
.btn:hover { background: rgba(255,255,255,0.01); }

/* Icon inside .btn */
.btn-icon { width: 16px; height: 16px; vertical-align: middle; margin-right: 8px; display: inline-block; }
.btn svg path { stroke: currentColor; }

/* ═══════════════════════════════════════════════════════════
   §9  Gamblegram (SVG stacked bars)
   ═══════════════════════════════════════════════════════════ */
/* -- Gamblegram -- */
.gamblegram {
  padding: 18px 18px 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border-radius: 8px; border: 1px solid rgba(255,255,255,0.03);
}
.gamblegram h2 { margin: 0 0 8px; color: var(--accent); }
.gg-canvas {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  max-height: min(1500px, 95vh);
}
svg#gg-svg { width: 100%; height: auto; display: block; transition: opacity 240ms ease; touch-action: none; }
svg text.gg-val { fill: var(--gg-label); font-weight: 400; pointer-events: none; }
svg text.gg-name { fill: var(--gg-label); font-weight: 400; pointer-events: none; }
.gg-info {
  display: grid;
  grid-template-columns: minmax(0, 180px) minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
  margin-top: 12px;
}
.gg-legend { display: flex; gap: 10px 14px; margin-top: 0; flex-wrap: wrap; }
.gg-legend .item {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: var(--gg-legend-font-size);
  line-height: 1.4;
}
.gg-legend .swatch {
  width: 12px; height: 12px; border-radius: 3px; display: inline-block;
  border: 1px solid rgba(255,255,255,0.06); box-shadow: 0 6px 18px rgba(2,6,23,0.45);
}
.gg-unknown {
  margin-top: 2px;
  font-weight: 700;
  color: #ffd166;
  font-size: var(--gg-legend-font-size);
  line-height: 1.35;
}

@media (min-width: 1400px) {
  .results.compact {
    padding: 12px 14px 10px;
  }
  .results-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }
  .result-card {
    padding: 8px 10px;
  }
  .results.compact dt {
    font-size: 13px;
    line-height: 1.2;
  }
  .results.compact dd {
    font-size: clamp(14px, 0.95vw, 18px);
    margin-top: 3px;
  }
  .results.compact .ref-range {
    margin-top: 2px;
    font-size: 10px;
    line-height: 1.2;
  }
  .gg-info {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "unknown export"
      "legend legend";
    gap: 10px 16px;
  }
  .gg-unknown {
    grid-area: unknown;
    margin-top: 0;
  }
  .gg-legend {
    grid-area: legend;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px 16px;
  }
  .gg-legend .item {
    min-width: 0;
  }
  #export-gg {
    grid-area: export;
    justify-self: end;
    align-self: start;
    margin-top: 0 !important;
  }
}

@keyframes scrollHintFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(4px); }
}

body.page-scroll-hint::before,
body.page-scroll-hint::after {
  content: "\2193";
  position: fixed;
  bottom: 16px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--scroll-hint-bg);
  color: var(--scroll-hint-fg);
  box-shadow: 0 10px 24px var(--scroll-hint-shadow);
  font-size: 17px;
  font-weight: 700;
  pointer-events: none;
  z-index: 50;
  animation: scrollHintFloat 1.2s ease-in-out infinite;
}
body.page-scroll-hint::before { left: 14px; }
body.page-scroll-hint::after {
  right: 14px;
  animation-delay: 0.18s;
}

@media (min-width: 1400px) {
  .ion-column.scroll-hint-visible::before,
  .ion-column.scroll-hint-visible::after,
  .analysis-column.scroll-hint-visible::before,
  .analysis-column.scroll-hint-visible::after {
    content: "\2193";
    position: absolute;
    bottom: 14px;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: var(--scroll-hint-bg);
    color: var(--scroll-hint-fg);
    box-shadow: 0 8px 18px var(--scroll-hint-shadow);
    font-size: 16px;
    font-weight: 700;
    pointer-events: none;
    z-index: 4;
    animation: scrollHintFloat 1.2s ease-in-out infinite;
  }
  .ion-column.scroll-hint-visible::before,
  .analysis-column.scroll-hint-visible::before { left: 10px; }
  .ion-column.scroll-hint-visible::after,
  .analysis-column.scroll-hint-visible::after {
    right: 18px;
    animation-delay: 0.18s;
  }
}

/* ═══════════════════════════════════════════════════════════
   §10  Tooltip
   ═══════════════════════════════════════════════════════════ */
/* -- Tooltip -- */
.gg-tooltip {
  position: absolute; pointer-events: none; padding: 10px 12px;
  border-radius: 8px; background: var(--tooltip-bg); color: var(--fg);
  font-size: 14px; border: 1px solid var(--border);
  transform: translate(-50%, -110%); white-space: nowrap; z-index: 40;
  box-shadow: 0 6px 30px rgba(2,6,23,0.6);
  opacity: 0; transition: opacity 120ms ease, transform 120ms ease;
}
.gg-tooltip.visible { opacity: 1; transform: translate(-50%, -120%) scale(1); }

/* ═══════════════════════════════════════════════════════════
   §11  Formulas panel (collapsible)
   ═══════════════════════════════════════════════════════════ */
/* -- Formulas / collapsible -- */
.formulas { margin-top: 4px; }
.formulas-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 10px; }
.collapse-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); padding: 10px 14px; border-radius: 6px;
  cursor: pointer; font-size: 14px; flex-shrink: 0; min-height: 40px;
}
.formulas.collapsed .formulas-body { display: none; }

/* Formulas body: let MathJax lay out naturally; scrollable if wide */
.formulas-body { overflow-x: auto; padding-bottom: 4px; }
.formulas-body pre { white-space: normal; overflow-wrap: anywhere; }

/* ═══════════════════════════════════════════════════════════
   §12  SVG interactivity (hover / focus effects)
   ═══════════════════════════════════════════════════════════ */
/* -- Gamblegram interactivity -- */
svg rect.gg-rect { transition: transform 160ms ease, filter 160ms ease, stroke 160ms ease, fill-opacity 160ms ease; }
svg rect.gg-rect:hover, svg rect.gg-rect:focus {
  transform: translateY(-3px); filter: brightness(1.03);
  stroke: rgba(0,0,0,0.12); stroke-width: 1.2; cursor: pointer; outline: none;
}

/* Focused mode: dim / hollow out all regions except the active one */
svg.focused rect.gg-rect { /* when any segment selected, switch to focused mode */ fill-opacity: 1; opacity: 1; filter: none; }
svg.focused rect.gg-rect:not(.active) {
  /* non-active segments: keep a faint tint + thicker outline so the original colors remain readable */
  fill-opacity: 0.12; /* faint colour hint */
  stroke: rgba(255,255,255,0.24); /* stronger outline on dark theme */
  stroke-width: 2; /* thicker outline for visibility */
  opacity: 0.98;
  transform: none; filter: none; transition: stroke 160ms ease, fill-opacity 160ms ease, opacity 160ms ease;
}
svg rect.gg-rect.active {
  /* active segment is visually emphasized and remains filled */
  transform: translateY(-4px); filter: brightness(1.04); stroke: rgba(0,0,0,0.12); stroke-width: 1.6; opacity: 1; fill-opacity: 0.95;
}

/* Unknown segment: make visually distinct (neon‑purple accent + glow) */
svg rect.gg-rect[data-key="Unknown"] {
  stroke: var(--gg-Unknown);
  stroke-width: 2.8;
  /* soft glow matching the neon accent */
  filter: drop-shadow(0 8px 18px rgba(179,71,255,0.20)) drop-shadow(0 0 8px rgba(179,71,255,0.12));
}

/* Slightly different outline on light theme for better contrast */
body.light svg.focused rect.gg-rect:not(.active) {
  stroke: rgba(0,0,0,0.18);
  stroke-width: 1.6;
}


/* ═══════════════════════════════════════════════════════════
   §13  Mobile breakpoint (≤ 520 px)
   ═══════════════════════════════════════════════════════════ */
/* -- Mobile (<=520px) -- */
@media (max-width: 520px) {
  body { padding: 10px 8px 32px; font-size: 16px; }
  .container { padding: 14px; border-radius: 8px; }
  .mobile-header { display: flex; }
  h1 { font-size: 20px; }
  label { font-size: 16px; }
  label .ion-label { font-weight: 700; }
  .gg-canvas { height: 66vh; max-height: 66vh; }
  input[type="number"] { width: 100%; font-size: 16px; }
  .unit-select { margin-left: 0; align-self: flex-start; font-size: 14px; }
  /* visible mobile pickers */
  .picker { display: block; width: 100%; margin-top: 8px; font-size: 16px; }
  .picker { -webkit-appearance: menulist-button; appearance: menulist-button; }
  .picker:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

  /* Stack label contents vertically so pickers sit below the ion label */
  label { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
  label .ion-label { display: block; }
  .unit-select { width: auto; }
  .additional-ion-presets { align-items: flex-start; }
  .additional-ion-presets-label { width: 100%; }
  .additional-ion-row { flex-direction: column; align-items: stretch; }
  .additional-ion-grid { grid-template-columns: 1fr; width: 100%; }
  .additional-ion-remove { width: 100%; }

  .results-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .results-head-copy {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }
  .results-head .btn { margin-left: 0; }
  .results-head-note { text-align: left; }
  .results-grid { gap: 10px; }
  .result-card { padding: 12px; }
  .results.compact dt { font-size: 14px; }
  .results.compact dd { font-size: 19px; }
  .analysis-notes { margin-top: 0; }
  .results-actions { justify-content: stretch; }
  .results-actions button { flex: 1; text-align: center; font-size: 14px; }
  .gg-info { grid-template-columns: 1fr; }
  .gg-legend .item { font-size: 14px; }
  .small-note { font-size: 14px; }
}

/* ═══════════════════════════════════════════════════════════
   §14  Light-mode overrides
   ═══════════════════════════════════════════════════════════ */
/* -- Light mode -- */
body.light {
  background: linear-gradient(180deg, #f6f8fb 0%, #eef3f7 100%);
  color: #0b1220;
  --fg: #111827; --muted: #6b7280; --gg-label: #374151;
  --accent: #1d4ed8; --card: #ffffff;
  --border: rgba(2,6,23,0.08); --glass: rgba(0,0,0,0.02);
  --input-border: rgba(0,0,0,0.12); --tooltip-bg: rgba(255,255,255,0.98);
  --gg-guide: rgba(17,24,39,0.92);
  --gg-guide-underlay: rgba(255,255,255,0.98);
  --scroll-hint-bg: rgba(255,255,255,0.9);
  --scroll-hint-fg: rgba(17,24,39,0.78);
  --scroll-hint-shadow: rgba(15,23,42,0.14);
  --scrollbox-border: rgba(100,116,139,0.24);
  --scrollbox-shadow: rgba(15,23,42,0.08);
  --scrollbox-bg: rgba(148,163,184,0.06);

  /* Gamblegram palette — light mode overrides */
  /* Cations (color‑blind friendly set) */
  --gg-Na:    #0052CC; /* Na⁺ */
  --gg-K:     #009E73; /* K⁺ */
  --gg-iCa:   #CC79A7; /* iCa²⁺ */
  --gg-Mg:    #56B4E9; /* Mg²⁺ */
  /* Anions (warm / high-contrast) */
  --gg-Cl:     #D55E00; /* Cl⁻ */
  --gg-Lactate:#E69F00; /* Lactate⁻ */
  --gg-HCO3:   #F0E442; /* HCO₃⁻ */
  --gg-Aminus: #F4B183; /* Albumin anionic contribution */
  --gg-Pi:     #F7E0A0; /* Phosphate */
  /* Unknown (distinct) */
  --gg-Unknown: #B347FF; /* Unknown / SIG (neon purple) */
}
body.light .container {
  background: var(--card); color: var(--fg);
  border: 1px solid var(--border); box-shadow: 0 6px 26px rgba(2,6,23,0.04);
}
body.light input[type="number"] { color: var(--fg); }
body.light input::placeholder { color: #9ca3af; }
body.light .gg-legend .swatch { border: 1px solid rgba(0,0,0,0.08); box-shadow: 0 4px 10px rgba(0,0,0,0.08); }
body.light .gg-tooltip { color: #111; }

/* ── References section ── */
.references { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.references h3 { font-size: 0.95rem; margin: 0 0 0.6rem; color: var(--accent); }
.references ol { padding-left: 1.4rem; margin: 0; font-size: 0.82rem; line-height: 1.55; color: var(--muted); }
.references li + li { margin-top: 0.35rem; }
.references cite { font-style: italic; }
.references a { color: var(--accent); text-decoration: none; }
.references a:hover { text-decoration: underline; }
