/* Buffer Builder: the formulation bench. Scenes by art.js, colors from the --bb-* properties below (light and dark).
   Species are told apart by shape (filled disc HA, open ring A⁻, triangle H₃O⁺, square OH⁻) and the A⁻ bars are hatched,
   so colour is never the only cue. */
html {
  --bb-wall1: #e9f1f2; --bb-wall2: #d6e3e6; --bb-tileline: rgba(36, 94, 118, .10); --bb-bench1: #8a6a4c; --bb-bench2: #6c5139;
  --bb-line: #3b5260; --bb-ink: #142833; --bb-text: #142833; --bb-muted: #4a5f6b; --bb-ink-line: #233843;
  --bb-plaque: #ffffff; --bb-chip: #ffffff; --bb-lampbg: #f4f7f8; --bb-lamp-on: #18b26b; --bb-lamp-off: #9aa8b0;
  --bb-glass: #cfe6ee; --bb-glass-line: #5d7f8d; --bb-liq1: #d9eff7; --bb-liq2: #b5dbe9; --bb-liq-top: #7fb6cb; --bb-liq-card: #eef8fb;
  --bb-ha: #c4572a; --bb-ha-hi: #f0a07a; --bb-a: #1f6f8b; --bb-a-hi: #7cc4dc; --bb-h3o: #b8325a; --bb-oh: #5b4bb0;
  --bb-cap1: #7a2f14; --bb-cap2: #134a5e; --bb-label: #fbfaf4; --bb-shelf: #9a7a5a;
  --bb-metal1: #f1f4f6; --bb-metal2: #cfd8de; --bb-metal3: #9fb0ba; --bb-screen1: #fbfdfc; --bb-screen2: #edf4f2;
  --bb-cable: #2f3b42; --bb-bulb: #d6eef5; --bb-card: #ffffff; --bb-track: #edf2f4;
  --bb-chosen: #2a7b4f; --bb-chosen-bg: rgba(42, 123, 79, .10);
  --bb-plotbg: #ffffff; --bb-grid: rgba(36, 94, 118, .18); --bb-axis: #2a3f4b; --bb-curve: #c4572a;
  --bb-model: #1d7a3a; --bb-flag: #ffffff; --bb-flag-on: #ffe7b8; --bb-readout: #fff7e0;
  --bb-panel1: #f7fbfc; --bb-panel2: #e9f2f4; --bb-chipbg: #ffffff; --bb-chip-on: #d7ecf2; --bb-chip-line: #8eaab5; --bb-accent: #245e76;
  --bb-build: #9a4a12; --bb-predict: #245e76;
}
html[data-theme="dark"] {
  --bb-wall1: #1b2930; --bb-wall2: #142128; --bb-tileline: rgba(140, 200, 220, .08); --bb-bench1: #4a3a2c; --bb-bench2: #33281f;
  --bb-line: #8fa9b6; --bb-ink: #e8f0f3; --bb-text: #e8f0f3; --bb-muted: #a9bcc6; --bb-ink-line: #0b1418;
  --bb-plaque: #1c2d36; --bb-chip: #1c2d36; --bb-lampbg: #14232b; --bb-lamp-on: #3ee68e; --bb-lamp-off: #4d5d66;
  --bb-glass: #4b6b78; --bb-glass-line: #9cc0cf; --bb-liq1: #24495a; --bb-liq2: #1a3846; --bb-liq-top: #5fa8c2; --bb-liq-card: #13303c;
  --bb-ha: #f08a5a; --bb-ha-hi: #ffc2a2; --bb-a: #5fc4e6; --bb-a-hi: #b6e8f8; --bb-h3o: #ff7aa0; --bb-oh: #a99cff;
  --bb-cap1: #f08a5a; --bb-cap2: #5fc4e6; --bb-label: #20323b; --bb-shelf: #6a5440;
  --bb-metal1: #3a474f; --bb-metal2: #2a353c; --bb-metal3: #1d262c; --bb-screen1: #0f1d24; --bb-screen2: #0b161c;
  --bb-cable: #a9bcc6; --bb-bulb: #2a4b58; --bb-card: #16242c; --bb-track: #22333c;
  --bb-chosen: #5fd08e; --bb-chosen-bg: rgba(95, 208, 142, .12);
  --bb-plotbg: #12222a; --bb-grid: rgba(150, 210, 230, .16); --bb-axis: #b9cbd4; --bb-curve: #ff9a6a;
  --bb-model: #6fd68f; --bb-flag: #1c2d36; --bb-flag-on: #5a4313; --bb-readout: #3a3012;
  --bb-panel1: #16242c; --bb-panel2: #1d2f3a; --bb-chipbg: #1f333f; --bb-chip-on: #24566a; --bb-chip-line: #4f7383; --bb-accent: #7fc4dc;
  --bb-build: #ffad70; --bb-predict: #7fc4dc;
}

.core { height: 100%; display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(330px, 1fr); gap: 16px; padding: 16px; overflow: auto; color: var(--bb-ink); font-size: 16px; box-sizing: border-box; }
.core * { box-sizing: border-box; }
.core input, .core button, .core select { font-size: 16px; }
.core-bench, .core-panel { min-width: 0; border-radius: 16px; overflow: auto; }
.core-bench { display: flex; flex-direction: column; gap: 10px; }
.core-panel { padding: 14px 16px; background: linear-gradient(180deg, var(--bb-panel1), var(--bb-panel2)); border: 1px solid var(--bb-chip-line); box-shadow: 0 2px 10px rgba(16, 43, 56, .12); }
.core-scene { flex: 0 0 auto; overflow: auto; border-radius: 14px; border: 2px solid var(--bb-line); background: var(--bb-wall2); box-shadow: 0 4px 14px rgba(16, 43, 56, .22); }
.core-scene:focus-visible, .bb-trace:focus-visible { outline: 3px solid #dd9823; outline-offset: 3px; }
.core-scene svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.core-scene.bb-plot svg { touch-action: none; cursor: crosshair; }
.core.locked .core-scene.bb-plot svg { cursor: default; }
.core-scene svg text, .bb-trace svg text { font-family: inherit; fill: var(--bb-text); font-size: 20px; }
.core-scene svg .bb-head { font-size: 22px; font-weight: 800; }
.core-scene svg .bb-chiptext, .core-scene svg .bb-lamptext { font-size: 20px; font-weight: 700; }
.core-scene svg .bb-bottletext { font-size: 21px; font-weight: 800; fill: #1b2a31; }
.core-scene svg .bb-bottlesub { font-size: 20px; font-weight: 600; fill: #34474f; }
html[data-theme="dark"] .core-scene svg .bb-bottletext { fill: #f2f6f8; }
html[data-theme="dark"] .core-scene svg .bb-bottlesub { fill: #c9d6dc; }
.core-scene svg .bb-lab { font-size: 21px; font-weight: 700; fill: #fff; paint-order: stroke; stroke: rgba(0, 0, 0, .45); stroke-width: 3px; }
.core-scene svg .bb-lcd { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; fill: var(--bb-ink); }
.core-scene svg .bb-lcdsmall { font-size: 22px; font-weight: 800; fill: var(--bb-muted); }
.core-scene svg .bb-metercap { font-size: 20px; font-weight: 600; fill: var(--bb-ink); }
.core-scene svg .bb-counter, .core-scene svg .bb-plate { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.core-scene svg .bb-cardhead { font-size: 20px; font-weight: 800; fill: var(--bb-muted); }
.core-scene svg .bb-rowlab, .core-scene svg .bb-val { font-size: 21px; font-weight: 800; font-variant-numeric: tabular-nums; }
.core-scene svg .bb-foot, .core-scene svg .bb-small, .core-scene svg .bb-legend { font-size: 20px; font-weight: 600; }
.core-scene svg .bb-chosentext { font-size: 20px; font-weight: 800; fill: #fff; }
html[data-theme="dark"] .core-scene svg .bb-chosentext { fill: #0b1418; }
.core-scene svg .bb-model, .bb-trace svg .bb-model { fill: var(--bb-model); font-weight: 800; }
.core-scene svg .bb-tick, .bb-trace svg .bb-tick { font-variant-numeric: tabular-nums; }
.core-scene svg .bb-axislab, .bb-trace svg .bb-axislab { font-weight: 700; fill: var(--bb-muted); }
.core-scene svg .bb-axis, .bb-trace svg .bb-axis { fill: none; stroke: var(--bb-axis); stroke-width: 2.4; }
.core-scene svg .bb-grid, .bb-trace svg .bb-grid { fill: none; stroke: var(--bb-grid); stroke-width: 1.4; }
.core-scene svg .bb-grid7 { stroke-dasharray: 6 5; stroke-width: 2; }
.core-scene svg .curve, .bb-trace svg .curve { fill: none; stroke: var(--bb-curve); stroke-width: 4; stroke-linejoin: round; }
.bb-trace svg .curve-1 { stroke: var(--bb-a); stroke-dasharray: 10 7; }
.core-scene svg .marker { fill: none; stroke: var(--bb-ink); stroke-width: 2.6; }
.core-scene svg .bb-mk-half { stroke-dasharray: 9 6; }
.core-scene svg .bb-mk-probe { stroke-dasharray: 2 6; stroke-linecap: round; stroke-width: 3; }
.core-scene svg .bb-mk-active { stroke: #b06a00; stroke-width: 4; }
html[data-theme="dark"] .core-scene svg .bb-mk-active { stroke: #ffc861; }
.core-scene svg .bb-flag { fill: var(--bb-flag); stroke: var(--bb-line); stroke-width: 1.6; }
.core-scene svg .bb-flag-active { fill: var(--bb-flag-on); stroke-width: 2.6; }
.core-scene svg .bb-flagtext, .bb-trace svg .bb-flagtext { font-size: 20px; font-weight: 800; }
.core-scene svg .bb-modelline { fill: none; stroke: var(--bb-model); stroke-width: 3; stroke-dasharray: 12 5; }
.core-scene svg .bb-probe { fill: var(--bb-readout); stroke: var(--bb-ink); stroke-width: 3; }
.core-scene svg .bb-readout { fill: var(--bb-readout); stroke: var(--bb-line); stroke-width: 1.6; }
.core-scene svg .bb-readtext { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.core-observation { margin: 0; min-height: 3em; padding: 10px 14px; line-height: 1.45; font-weight: 600; border-left: 5px solid var(--bb-accent); background: var(--bb-panel1); border-radius: 0 10px 10px 0; }
.bb-trace { border-radius: 14px; border: 2px solid var(--bb-line); background: var(--bb-screen2); overflow: auto; }
.bb-trace[hidden] { display: none; }
.bb-trace svg { display: block; width: 100%; height: auto; }
.bb-trace .bb-note { margin: 4px 14px 10px; }

.bb-case { margin: 0 0 12px; padding: 10px 14px; border-radius: 12px; background: var(--bb-chipbg); border: 1px dashed var(--bb-chip-line); }
.bb-case p { margin: 6px 0; line-height: 1.45; }
.bb-case .bb-case-kicker { margin-top: 0; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; color: var(--bb-predict); }
.bb-table { border-collapse: collapse; margin: 6px 0; width: 100%; font-variant-numeric: tabular-nums; }
.bb-table th, .bb-table td { border: 1px solid var(--bb-chip-line); padding: 5px 8px; text-align: center; }
.bb-table tr:first-child th { background: var(--bb-panel2); }
.bb-table tr > th:first-child { text-align: left; }

.bb-step { margin: 14px 0 8px; padding-top: 10px; border-top: 1px solid var(--bb-chip-line); font-size: 16px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.bb-step-build { color: var(--bb-build); }
.bb-step-predict { color: var(--bb-predict); }
.bb-note { margin: 4px 0 8px; line-height: 1.4; }
.bb-field { display: grid; gap: 6px; margin: 0 0 12px; }
.bb-label { font-weight: 700; line-height: 1.35; }
.bb-num { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bb-num input { flex: 1 1 auto; min-width: 0; width: 100%; font: inherit; font-size: 18px; font-weight: 700; min-height: 44px; padding: 8px 10px; border-radius: 10px; border: 2px solid var(--bb-chip-line); background: var(--bb-chipbg); color: inherit; font-variant-numeric: tabular-nums; }
.bb-unit { flex: 0 0 auto; font-weight: 600; }
.bb-amount-row { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 10px; align-items: center; }
.bb-range { width: 100%; min-height: 44px; accent-color: var(--bb-accent); margin: 0; }
.bb-drops { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.core .bb-dropbtn { font: inherit; font-size: 18px; font-weight: 800; min-width: 60px; min-height: 44px; border-radius: 10px; border: 2px solid var(--bb-chip-line); background: var(--bb-chipbg); color: inherit; cursor: pointer; }
.bb-dropnum { flex: 1 1 140px; }
.bb-markrow { margin: 0 0 8px; padding: 2px 6px; border-radius: 10px; border: 2px solid transparent; }
.bb-markrow.on { border-color: var(--bb-accent); background: var(--bb-chip-on); }
.bb-marklabel { flex: 0 0 11em; font-weight: 700; }
.bb-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.bb-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.core .bb-chip { font: inherit; font-size: 16px; font-weight: 700; min-height: 44px; padding: 8px 14px; border-radius: 22px; border: 2px solid var(--bb-chip-line); background: var(--bb-chipbg); color: inherit; cursor: pointer; text-align: left; line-height: 1.3; }
.core .bb-chip.bb-card { display: grid; gap: 2px; border-radius: 12px; padding: 10px 12px; }
.core .bb-chip.bb-card span { font-weight: 500; }
.core .bb-chip.on { background: var(--bb-chip-on); border-color: var(--bb-accent); box-shadow: inset 0 0 0 1px var(--bb-accent); }
.core .bb-chip.on:not(.bb-card)::before, .core .bb-chip.bb-card.on strong::before { content: "✓ "; }
.core .bb-chip:hover:not(:disabled), .core .bb-dropbtn:hover:not(:disabled) { border-color: var(--bb-accent); }
.bb-actions { display: flex; gap: 10px; margin-top: 8px; }
.core-run, .core-revise { font: inherit; font-size: 16px; font-weight: 800; min-height: 46px; border-radius: 12px; padding: 10px 16px; cursor: pointer; }
.core-run { flex: 1 1 auto; background: #245e76; color: #fff; border: 0; box-shadow: 0 3px 0 #163c4c; }
.core-revise { background: var(--bb-chipbg); color: inherit; border: 2px solid var(--bb-chip-line); }
.core button:disabled, .core input:disabled { opacity: .6; cursor: default; }
.core .bb-chip.on:disabled { opacity: .85; }
.core-run:disabled { box-shadow: none; }
.core :focus-visible { outline: 3px solid #dd9823; outline-offset: 2px; }
.core-status { margin: 8px 0 4px; line-height: 1.4; font-weight: 600; }
.bb-precision { margin: 0 0 6px; line-height: 1.4; }
.core-about summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 700; }
.core-about p { line-height: 1.5; margin: 0 0 8px; }
.bb-example { margin: 8px 0; max-width: 420px; }

body .ps-kicker, body .ps-hint-note, body .ps-badge { font-size: 16px; }

@media (max-width: 900px) {
  .core { height: auto; grid-template-columns: 1fr; padding: 12px; }
  .core-bench, .core-panel { overflow: visible; }
  .core-panel { padding-bottom: 30px; }
  .core-scene svg, .bb-trace svg { min-width: 760px; }
  .bb-example svg { min-width: 0; }
}
@media (max-width: 480px) {
  .bb-amount-row { grid-template-columns: 1fr; }
  .bb-marklabel { flex-basis: 8em; }
}
@media (prefers-reduced-motion: reduce) { .core * { animation: none !important; transition: none !important; } }
.bb-trace svg .bb-key { fill: none; stroke: var(--bb-curve); stroke-width: 4; }
.bb-trace svg .bb-key-1 { stroke: var(--bb-a); stroke-dasharray: 10 7; }
.core-bench > * { flex-shrink: 0; }
