/* =============================================================
   styles.css  -  appearance only
   Lavender + Willow (design-system.css, linked first, owns the tokens,
   light/dark and prefers-color-scheme). This file only maps Stoichiomathics
   components onto those tokens and adds the few app-specific tokens that
   the system has no role for: periodic-table cells, limiting / excess,
   and reaction-category accents.

   Roles: lavender = interactive, willow = the answer / positive.
   One saturated element per view: the primary button (or selected cell).
   ============================================================= */

:root {
  color-scheme: light;

  /* inner panels: the "thing inside the thing" (works in both themes) */
  --inset: color-mix(in srgb, var(--card-2) 55%, var(--card));


  /* deep zones (strategy / verdict / worksheet header): same in both themes */
  --deep:          var(--lav-900);
  --on-deep:       var(--lav-50);      /* 13+:1 on --deep */
  --on-deep-muted: var(--lav-100);     /* 11+:1 on --deep */
  --on-deep-line:  rgba(235, 224, 255, .22);
  --on-deep-wash:  rgba(235, 224, 255, .08);
  --deep-ring:     0 0 0 3px rgba(199, 173, 255, .45);
  --deep-btn:       var(--lav-200);    /* primary button on a deep zone */
  --deep-btn-ink:   var(--ink-fixed);
  --deep-btn-hover: var(--lav-100);
  --ink-fixed:      #1c1725;

  /* periodic table: lavender-soft = available, primary = selected */
  --pt-on-bg:     var(--primary-soft);
  --pt-on-ink:    var(--primary-soft-ink);
  --pt-on-border: var(--line-strong);
  --pt-on-hover:  var(--lav-100);
  --pt-on-hover-ink: var(--lav-700);
  --pt-off-bg:    var(--bg);
  --pt-off-ink:   var(--faint);
  --pt-off-border:var(--line);
  --pt-sel-bg:    var(--primary);
  --pt-sel-ink:   var(--primary-ink);

  /* limiting = willow (the answer), excess = lavender; both sit on a deep
     zone and differ by border style too (solid vs dashed), never colour alone */
  --lim-bg: var(--grn-200);  --lim-ink: var(--grn-900);
  --exc-bg: var(--lav-100);  --exc-ink: var(--lav-900);

  /* reaction-category accents (data colours): tag tint + mixed-with-ink text */
  --c-neut:#0e7490; --c-ametal:#be185d; --c-carb:#b45309; --c-oxide:#c2410c;
  --c-comb:#b91c1c; --c-precip:#6d28d9; --c-decomp:#047857; --c-disp:#0369a1;
  --c-synth:#1d4ed8; --c-titr:#7c3aed; --c-elec:#a16207; --c-complex:#a21caf;
  --c-pblock:#4338ca; --c-gasform:#4d7c0f; --c-custom:#475569;
}
[data-theme="dark"] {
  color-scheme: dark;
  --pt-on-hover:  var(--line-strong);
  --pt-on-hover-ink: var(--lav-50);
  --c-neut:#67e8f9; --c-ametal:#f472b6; --c-carb:#fbbf24; --c-oxide:#fb923c;
  --c-comb:#f87171; --c-precip:#a78bfa; --c-decomp:#34d399; --c-disp:#38bdf8;
  --c-synth:#60a5fa; --c-titr:#c084fc; --c-elec:#facc15; --c-complex:#e879f9;
  --c-pblock:#818cf8; --c-gasform:#a3e635; --c-custom:#94a3b8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --pt-on-hover:  var(--line-strong);
    --pt-on-hover-ink: var(--lav-50);
    --c-neut:#67e8f9; --c-ametal:#f472b6; --c-carb:#fbbf24; --c-oxide:#fb923c;
    --c-comb:#f87171; --c-precip:#a78bfa; --c-decomp:#34d399; --c-disp:#38bdf8;
    --c-synth:#60a5fa; --c-titr:#c084fc; --c-elec:#facc15; --c-complex:#e879f9;
    --c-pblock:#818cf8; --c-gasform:#a3e635; --c-custom:#94a3b8;
  }
}


/* ---------- header ---------- */
.site-header {
  max-width: 900px;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-5) var(--sp-2);
}
.site-title { margin: 6px 0 var(--sp-4); }
main { max-width: 900px; margin: 0 auto; padding: var(--sp-2) var(--sp-5) var(--sp-7); }


/* ---------- landing ---------- */
.hero-lead {
  font: var(--t-display);
  letter-spacing: var(--tr-display);
  color: var(--ink-2);
  margin: var(--sp-5) 0;
}

.choice-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .choice-grid { grid-template-columns: 1fr; } }


/* ---------- prompt cards (picker + measurements) ---------- */
.card, .prompt-card { margin-bottom: var(--sp-4); }
.prompt-step {
  display: inline-block;
  font: var(--t-label);
  letter-spacing: var(--tr-label); text-transform: uppercase;
  color: var(--link); margin-bottom: 10px;
}
.prompt-question {
  display: block;
  font: var(--t-h2);
  color: var(--ink-2);
  margin: 0 0 var(--sp-3);
}
.wizard-back-row { margin-top: var(--sp-3); display: flex; gap: 10px; flex-wrap: wrap; }

#measure-continue { margin-top: var(--sp-4); }


/* ---------- species / formula search ---------- */
.searchbar { position: relative; margin-bottom: 10px; }
.text-input { width: 100%; }
.search-preview {
  display: block;
  min-height: 1.1em;
  margin: 6px 2px 0;
  font: var(--t-quantity);
  font-variant-numeric: tabular-nums;
  color: var(--link);
}
.search-preview:empty { display: none; }
.searchbar-divider {
  display: flex; align-items: center; gap: 10px;
  font: var(--t-label); color: var(--muted); text-transform: uppercase; letter-spacing: var(--tr-label);
  margin: 4px 0 var(--sp-3);
}
.searchbar-divider::before, .searchbar-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}

/* ---------- periodic-table picker ---------- */
.tablewrap { margin-bottom: var(--sp-3); }
.legend { display: flex; gap: 14px; font: var(--t-small); color: var(--muted); align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend .l-active { background: var(--pt-on-bg); border: 1px solid var(--pt-on-border); }
.legend .l-sel { background: var(--pt-sel-bg); }
.legend .l-off { background: var(--pt-off-bg); border: 1px solid var(--pt-off-border); }

.ptscroll { overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.ptable { display: grid; grid-template-columns: repeat(18, minmax(35px, 1fr)); grid-auto-rows: 40px; gap: 4px; min-width: 680px; }
.cell {
  appearance: none; padding: 0; margin: 0;
  border-radius: var(--r-sm); position: relative; display: flex; flex-direction: column; justify-content: center; align-items: center;
  font: var(--w-semi) 1rem/1 var(--font-body); user-select: none; border: 1px solid transparent;
}
.cell .z { position: absolute; top: 2px; left: 4px; font-size: .5rem; font-weight: var(--w-medium); opacity: .85; }
.cell.off { background: var(--pt-off-bg); color: var(--pt-off-ink); border-color: var(--pt-off-border); cursor: default; }
.cell.on { background: var(--pt-on-bg); color: var(--pt-on-ink); border-color: var(--pt-on-border); cursor: pointer; transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
.cell.on:hover { background: var(--pt-on-hover); color: var(--pt-on-hover-ink); transform: translateY(-1px); box-shadow: var(--shadow-1); }
.cell.sel { background: var(--pt-sel-bg); color: var(--pt-sel-ink); border-color: var(--pt-sel-bg); box-shadow: var(--focus-ring); }
.cell.sel .z { opacity: 1; }
.ftag {
  grid-column: 3 / span 1; display: flex; align-items: center; justify-content: center;
  font: var(--w-medium) .5625rem/1 var(--font-body); color: var(--muted); border: 1px dashed var(--line-strong); border-radius: var(--r-sm);
}

.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin: var(--sp-3) 0 4px; }

.statusbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 2px 2px; }
.count { color: var(--muted); font: var(--t-small); }
.count b { color: var(--ink); font-weight: var(--w-semi); }
.selchips { display: flex; gap: 6px; flex-wrap: wrap; }
.selchip {
  background: var(--primary-soft); color: var(--primary-soft-ink); border: 1px solid var(--line-strong); border-radius: var(--r-pill); padding: 4px 10px 4px 12px;
  font: var(--t-label); font-size: var(--fs-small); cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.selchip:hover { background: var(--lav-100); }
[data-theme="dark"] .selchip:hover { background: var(--line-strong); }
.selchip span { opacity: .8; }

/* reaction list */
.list { display: flex; flex-direction: column; gap: 9px; margin-top: var(--sp-3); }
.rx {
  appearance: none; width: 100%; margin: 0; text-align: left; font: inherit; color: inherit;
  display: grid; grid-template-columns: 42px 1fr auto; gap: 13px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: 13px 15px; align-items: center; cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.rx:hover { border-color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow-1); }
.idx {
  font: var(--w-semi) var(--fs-small)/1 var(--font-mono); font-variant-numeric: tabular-nums; color: var(--primary-soft-ink);
  background: var(--primary-soft); border-radius: var(--r-sm); height: 34px;
  display: flex; align-items: center; justify-content: center;
}
.rxbody { min-width: 0; }
.rxbody, .rx .eq { display: block; }   /* spans, because the row is a button */
.eq {
  font: var(--t-quantity); font-size: 1rem; line-height: 1.5; color: var(--ink); overflow-wrap: anywhere;
}
.eq .coef { color: var(--primary-soft-ink); }
.eq .op { color: var(--muted); padding: 0 2px; }
.eq .arrow { color: var(--primary-soft-ink); padding: 0 6px; font-weight: var(--w-semi); }
.eq sub { font-size: .66em; } .eq sup { font-size: .66em; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 7px; }
.tag {
  --tag: var(--c-custom);
  background: color-mix(in srgb, var(--tag) 14%, var(--card));
  color: color-mix(in srgb, var(--tag) 62%, var(--ink));
  border: 1px solid color-mix(in srgb, var(--tag) 40%, transparent);
  font: var(--t-label); letter-spacing: var(--tr-label); padding: 3px 10px; border-radius: var(--r-pill); text-transform: uppercase; }
.cond { font: var(--t-small); color: var(--muted); font-style: italic; }
.cond--warn { color: var(--warn-ink); }
.pick { font: var(--t-label); font-size: var(--fs-small); color: var(--muted); white-space: nowrap; }
.rx:hover .pick { color: var(--link); }
.empty { text-align: center; font: var(--t-body); color: var(--muted); padding: 42px 20px; border: 1px dashed var(--line-strong); border-radius: var(--r-md); }
.empty b { color: var(--ink); font-weight: var(--w-semi); }

/* "my reaction is not listed" - same grid as .rx, dashed to read as an escape hatch */
.rx--custom { border-style: dashed; border-color: var(--line-strong); background: var(--bg-tint); }
.rx--custom:hover { border-color: var(--primary); }
.rx--custom .idx { color: var(--primary-soft-ink); font-size: 1.25rem; }
.rx--custom .rxbody .eq { font-family: var(--font-body); color: var(--muted); font-style: italic; }
.rx--custom:hover .pick { color: var(--link); }

/* ---------- custom-reaction builder ---------- */
.custom-side-label {
  font: var(--t-label); letter-spacing: var(--tr-label); text-transform: uppercase;
  color: var(--muted); margin: var(--sp-4) 0 8px;
}
.custom-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
@media (max-width: 620px) { .custom-grid { grid-template-columns: 1fr; } }
.custom-arrow-row { text-align: center; margin: 6px 0; }
.custom-arrow { color: var(--primary-soft-ink); font-size: 1.25rem; font-weight: var(--w-semi); }
.customfield { background: var(--inset); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-3); }
.customfield .cf-label {
  font: var(--t-label); color: var(--muted);
  letter-spacing: var(--tr-label); text-transform: uppercase; margin-bottom: 8px;
}
.coefrow { display: flex; gap: 8px; }
.coef-input { width: 64px; flex: 0 0 auto; text-align: center; font-variant-numeric: tabular-nums; }
.name-input { flex: 1; min-width: 0; font-family: var(--font-mono); }
.formula-preview {
  margin-top: 8px; font: var(--t-quantity); color: var(--ink); min-height: 20px;
}
.formula-preview sub { font-size: .66em; } .formula-preview sup { font-size: .66em; }
.formula-preview:empty::before { content: '\2014'; color: var(--muted); }
.formula-conflict { margin-top: 10px; }
.formula-conflict-label { font: var(--t-small); color: var(--muted); margin-bottom: 6px; }
.formula-conflict-options { display: flex; gap: 8px; flex-wrap: wrap; }
.formula-option {
  font: var(--t-quantity); padding: 4px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--card); color: var(--primary-soft-ink); cursor: pointer;
}
.formula-option sub, .formula-option sup { font-size: .7em; }
.formula-option:hover { background: var(--primary-soft); }

/* ---------- measurements card ---------- */
.calc-eq {
  font: var(--t-quantity); font-size: 1.0625rem; line-height: 1.5; color: var(--ink);
  background: var(--inset); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-3) 14px;
  overflow-x: auto;
}
.calc-eq .arrow { color: var(--primary-soft-ink); padding: 0 8px; font-weight: var(--w-semi); }
.calc-eq .op { color: var(--muted); padding: 0 3px; }
.calc-eq .coef { color: var(--primary-soft-ink); }
.calc-eq sub { font-size: .66em; } .calc-eq sup { font-size: .66em; }
.calc-eq + .choice-grid { margin-top: var(--sp-4); }

.inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: var(--sp-4); }
@media (max-width: 620px) { .inputs { grid-template-columns: minmax(0, 1fr); } }
.massfield { background: var(--inset); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; }
.massfield .who { font: var(--w-semi) 1.0625rem/1.4 var(--font-mono); color: var(--ink); }
.massfield .who sub { font-size: .66em; } .massfield .who sup { font-size: .66em; }
.massfield .cf {
  font: var(--t-label); color: var(--muted);
  letter-spacing: var(--tr-label); text-transform: uppercase; margin-left: 6px;
}
.methodrow { margin: 9px 0 8px; }
.methodrow .msel { width: 100%; font-weight: var(--w-semi); }
.massrow { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.massrow input { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.massrow .unit { color: var(--muted); font: var(--t-body-strong); }
.massrow .uSel { font-weight: var(--w-semi); }
.massrow .uSel.wide { flex: 1; }

/* ---------- step-combo: strategy (deep) + calculation ---------- */
.step-combo {
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-3);
  margin-bottom: var(--sp-4);
  background: var(--bg-tint);
  border: 1px solid var(--line);
}
.step-strategy-zone {
  background: var(--deep);
  color: var(--on-deep);
  padding: var(--sp-6) 28px var(--sp-5);
}
.strategy-eyebrow {
  font: var(--t-label);
  letter-spacing: var(--tr-label); text-transform: uppercase;
  color: var(--on-deep-muted); display: block; margin-bottom: 10px;
}
.verdict-card .strategy-eyebrow, .worksheet-header .strategy-eyebrow { color: var(--on-deep-muted); }
.strategy-instruction {
  font: var(--t-h2);
  color: var(--on-deep);
  margin: 0 0 8px;
}
.step-calc-zone {
  background: var(--bg-tint);
  color: var(--ink);
  padding: var(--sp-5) 28px;
  min-height: 56px;
}
.math-eyebrow {
  font: var(--t-label);
  letter-spacing: var(--tr-label); text-transform: uppercase;
  color: var(--link); display: block; margin-bottom: 10px;
}
.math-typed {
  margin: 0;
  font: var(--t-quantity); font-size: 1.0625rem;
  line-height: 2.05;
  overflow-x: auto;
}
.step-combo-actions { background: var(--bg-tint); padding: 0 28px var(--sp-5); display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.step-combo-actions .btn { padding: 12px 22px; }

/* strategy-only card: no calc zone, actions sit on the deep zone */
#card-strategy { background: var(--deep); border-color: var(--deep); }
#card-strategy .step-combo-actions { background: transparent; padding-top: var(--sp-5); }
.pivot-select { margin: var(--sp-4) 0 4px; }
.pivot-label {
  display: block; margin-bottom: 8px;
  font: var(--t-body-strong);
  color: var(--on-deep);
}

/* buttons that sit on a deep zone */
#card-strategy .btn--primary, .verdict-card .btn--primary { background: var(--deep-btn); color: var(--deep-btn-ink); }
#card-strategy .btn--primary:hover, .verdict-card .btn--primary:hover { background: var(--deep-btn-hover); }
#card-strategy .btn--ghost, .verdict-card .btn--ghost { color: var(--on-deep); border-color: var(--on-deep-line); }
#card-strategy .btn--ghost:hover, .verdict-card .btn--ghost:hover { background: var(--on-deep-wash); }
#card-strategy :focus-visible, .verdict-card :focus-visible { outline-color: var(--lav-200); box-shadow: var(--deep-ring); }

/* ---------- direct mol comparison: growing ratio table ---------- */
.ratio-table-scroll { overflow-x: auto; margin-top: 6px; }
.ratio-table { width: 100%; border-collapse: collapse; font: var(--t-quantity); font-size: .95rem; }
.ratio-table th, .ratio-table td { padding: 12px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ratio-table thead th { font: var(--t-body-strong); color: var(--ink); border-bottom: 2px solid var(--primary); }
.ratio-table thead th:first-child { min-width: 0; }
.ratio-table tbody th { font: var(--t-body-strong); color: var(--ink); white-space: normal; }
.ratio-table tbody tr:last-child th, .ratio-table tbody tr:last-child td { border-bottom: 0; }
.ratio-table .eqgrid { font-size: .95em; }
.ratio-row-in { animation: fade var(--dur-slow) var(--ease); }
/* limiting row: willow wash + solid willow frame (frame, not colour, marks it) */
.ratio-limiting { background: var(--accent-soft); border-radius: var(--r-sm); box-shadow: inset 0 0 0 2px var(--accent); }

/* ---------- stacked fractions + equation grid ---------- */
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  text-align: center;
  vertical-align: middle;
  margin: 0 6px;
  line-height: 1.3;
  font-size: .92em;
  position: relative;
  top: -.05em;
}
.frac-num { padding: 0 5px 2px; border-bottom: 1.4px solid currentColor; }
.frac-den { padding: 2px 5px 0; }

.eqgrid {
  display: inline-grid;
  grid-template-columns: max-content max-content minmax(0, max-content);
  align-items: center;
  row-gap: 6px;
  column-gap: 0;
  max-width: 100%;
}
/* Each equation line is ONE element spanning all three outer columns, laid
   out internally with `subgrid` so its lhs / '=' / rhs still align with
   every other line's columns. A single clip-path wipe per line sweeps
   continuously left-to-right across the whole line. */
.eqgrid .eq-row {
  display: grid;
  grid-template-columns: subgrid;
  grid-column: 1 / -1;
  column-gap: 0;
  align-items: center;
}
.eqgrid .eq-seg { white-space: nowrap; }
.eqgrid .eq-rhs { white-space: normal; }             /* a long sum wraps instead of running off a phone */
.ratio-table .eqgrid .eq-rhs { white-space: nowrap; }
.eqgrid .eq-op { padding: 0 .6em; }
.eqgrid .eq-lhs { justify-self: end; }
.eqgrid .eq-rhs,
.eqgrid .eq-solo { justify-self: start; }
/* a lone line (a conclusion) never widens the columns of the rows around it */
.eqgrid .eq-solo { width: 0; overflow: visible; }
.eqgrid sub { font-size: .7em; } .eqgrid sup { font-size: .7em; }

@supports not (grid-template-columns: subgrid) {
  .eqgrid .eq-row { grid-template-columns: max-content max-content minmax(0, max-content); }
}

.ans-lines { font: var(--t-quantity); font-size: 1.0625rem; line-height: 2.05; overflow-x: auto; animation: fade var(--dur-slow) var(--ease); }

/* ---------- verify worksheet ---------- */
.worksheet {
  border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-3);
  background: var(--card); border: 1px solid var(--line); margin-bottom: var(--sp-4);
}
.worksheet-header { background: var(--deep); padding: 26px 28px var(--sp-5); }
.worksheet-title { font: var(--t-h2); color: var(--on-deep); margin: 0; }
.worksheet-body { padding: var(--sp-2) 28px var(--sp-3); }
.vrow { display: grid; grid-template-columns: 170px 1fr; gap: 14px; padding: 14px 0; border-top: 1px dashed var(--line-strong); align-items: baseline; }
.vrow:first-child { border-top: 0; }
@media (max-width: 560px) { .vrow { grid-template-columns: 1fr; gap: 4px; } }
.vlabel { font: var(--t-label); letter-spacing: var(--tr-label); text-transform: uppercase; color: var(--link); }
.vlabel .nocase { text-transform: none; }          /* a formula keeps its capitals: Mg is not MG */
.vval { font: var(--t-quantity); line-height: 1.8; color: var(--ink); overflow-wrap: anywhere; }
.vval b { color: var(--accent-soft-ink); font-weight: var(--w-semi); background: var(--accent-soft); border-radius: 4px; padding: 0 4px; }
.vval sub { font-size: .7em; } .vval sup { font-size: .7em; }
.dotsep { color: var(--muted); padding: 0 .6em; }
.worksheet-actions { background: var(--card); padding: var(--sp-2) 28px var(--sp-5); }

/* ---------- verdict card ---------- */
.verdict-card {
  background: var(--deep);
  color: var(--on-deep);
  border-radius: var(--r-lg);
  padding: var(--sp-6) 28px;
  box-shadow: var(--shadow-3);
  margin-bottom: var(--sp-4);
  animation: fade var(--dur-slow) var(--ease);
}
.verdict-headline {
  font: var(--t-h1);
  color: var(--on-deep);
  margin: 0 0 10px;
}
.verdict-body { font: var(--t-body); color: var(--on-deep); margin: 0; }
.verdict-body b { color: var(--on-deep); font-weight: var(--w-semi); }
.chip {
  display: inline-block; font: var(--w-semi) .92em/1.4 var(--font-mono); padding: 2px 10px; border-radius: var(--r-sm);
}
.chip sub { font-size: .7em; } .chip sup { font-size: .7em; }
.chip--lim { background: var(--lim-bg); color: var(--lim-ink); border: 2px solid var(--lim-ink); }
.verdict-actions { display: flex; gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-5); }

.whatif { margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px dashed var(--on-deep-line); }
.whatif-toggle { width: 100%; justify-content: flex-start; text-align: left; border-radius: var(--r-md); }
.whatif-body {
  margin-top: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md);
  background: var(--on-deep-wash); border: 1px solid var(--on-deep-line);
  font: var(--t-body); animation: fade var(--dur) var(--ease);
}
.whatif-body b { color: var(--on-deep); font-weight: var(--w-semi); }
.whatif-body .ans-lines { margin-top: 8px; color: var(--on-deep); font-size: 1rem; }

/* ---------- ratio balls: a growing worksheet ----------
   One card, one block per step. The action bar stays at the foot of the
   screen while the blocks pile up above it. */
.eq-note { margin-left: .75em; color: var(--muted); font-weight: var(--w-semi); }

.balls-card { overflow: clip; }              /* clip, not hidden: the action bar must stay sticky */
.balls-head { padding-bottom: var(--sp-4); }
.balls-eq { font: var(--t-quantity); font-size: 1.0625rem; line-height: 1.5; color: var(--on-deep); overflow-x: auto; }
.balls-eq .coef { color: var(--lav-200); }
.balls-eq .op, .balls-eq .arrow { color: var(--on-deep-muted); padding: 0 6px; }
.balls-eq sub, .balls-eq sup { font-size: .66em; }

.balls-stack { background: var(--bg-tint); padding: 0 28px; }
.ball-step { padding: var(--sp-5) 0; border-top: 1px dashed var(--line-strong); scroll-margin-bottom: 128px; }
.ball-step:first-child { border-top: 0; }
.ball-step__head { display: flex; align-items: center; gap: var(--sp-3); }
.ball-no {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary-soft-ink); border: 1px solid var(--line-strong);
  font: var(--w-semi) .875rem/26px var(--font-mono); text-align: center;
}
.ball-ins { margin: 0; font: var(--t-h3); letter-spacing: 0; color: var(--ink); }
.ball-math { margin-top: var(--sp-3); font: var(--t-quantity); font-size: 1.0625rem; line-height: 1.75; overflow-x: auto; padding-bottom: 2px; }
.ball-math .eqgrid { row-gap: 2px; }
.ball-math:empty { display: none; }
.ball-vis { margin-top: var(--sp-3); min-width: 0; }

.balls-actions {
  position: sticky; bottom: 0; z-index: 3;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3) var(--sp-4);
  padding: var(--sp-3) 28px;
  background: var(--bg-tint); border-top: 1px solid var(--line);
  box-shadow: 0 -10px 18px -14px rgba(46, 27, 82, .35);
}
.balls-btns { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.steps-dots { display: flex; gap: 6px; align-items: center; }
.dot {
  width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--primary); background: transparent;
  transition: background-color var(--dur) var(--ease);
}
.dot.is-on { background: var(--primary); }

/* ratiovis.css: the "Fit to" buttons are flex boxes, which turns the <sub> in a formula such as
   Ca(OH)2 into a mid-height flex item. Plain inline text lets it sit below the line again. */
.rv .rv-seg__btn { display: inline-block; padding-top: 4px; padding-bottom: 4px; line-height: calc(var(--rv-ctl) - 8px); text-align: center; }
.rv .rv-seg__btn sub, .rv .rv-seg__btn sup { line-height: 0; }

/* picture hosts on the other cards */
.verify-vis { padding: var(--sp-2) 28px var(--sp-3); background: var(--card); }
.verdict-vis { margin-top: var(--sp-4); min-width: 0; }
.verdict-vis:empty { display: none; }

/* ---------- practice ---------- */
.practice-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-5); }
.score-chip {
  margin-left: auto; padding: 6px 14px; border-radius: var(--r-pill);
  background: var(--accent-soft); color: var(--accent-soft-ink); border: 1px solid var(--accent);
  font: var(--t-quantity); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.pq-eq { margin: 0; }
.pq-cond {
  display: inline-block; margin-top: var(--sp-2); padding: 2px 10px; border-radius: var(--r-pill);
  background: var(--bg-tint); border: 1px solid var(--line-strong); color: var(--muted);
  font: var(--t-small); font-style: italic;
}
.pq-givens { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin: var(--sp-4) 0 0; }
.given {
  display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; min-width: 0;
  padding: 10px 14px; background: var(--inset); border: 1px solid var(--line); border-radius: var(--r-md);
}
.given-f { font: var(--w-semi) 1.0625rem/1.4 var(--font-mono); color: var(--ink); }
.given-f sub, .given-f sup { font-size: .66em; }
.given-amt { font: var(--t-quantity); color: var(--ink-2); font-variant-numeric: tabular-nums; }

.pq { margin-top: var(--sp-5); }
.pq-ask { display: block; margin: 0 0 var(--sp-3); font: var(--t-h2); color: var(--ink-2); max-width: none; }
.pq-ask b { font-family: var(--font-mono); font-weight: var(--w-semi); }
.pq-btns { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); }
.pq-pick { font-family: var(--font-mono); background: var(--primary-soft); border-color: var(--line-strong); color: var(--primary-soft-ink); }
.pq-pick:hover { background: var(--card-2); border-color: var(--primary); }
.pq-pick sub, .pq-pick sup { font-size: .7em; }
.pq-pick[aria-disabled="true"] { cursor: default; opacity: .6; transform: none; }
.pq-pick[aria-disabled="true"]:hover { background: var(--primary-soft); border-color: var(--line-strong); }
.pq-pick[aria-pressed="true"] { opacity: 1; background: var(--primary); border-color: transparent; color: var(--primary-ink); }
.pq-pick[aria-pressed="true"]:hover { background: var(--primary); }
.pq-hintline { margin: var(--sp-3) 0 0; font: var(--t-quantity); color: var(--ink-2); max-width: none; }

.pq-feedback { margin-top: var(--sp-4); border-radius: var(--r-md); }
.pq-feedback:empty { display: none; }
.pq-feedback:focus { outline: none; }
.pq-feedback:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; box-shadow: var(--focus-ring); }
.fb {
  display: flex; align-items: center; gap: 10px; margin: 0; max-width: none;
  padding: var(--sp-3) var(--sp-4); border-left: 3px solid var(--line-strong);
  border-radius: 0 var(--r-md) var(--r-md) 0; font: var(--t-body-strong); color: var(--ink);
}
.fb--ok { background: var(--success-soft); border-left-color: var(--success); }
.fb--no { background: var(--danger-soft); border-left-color: var(--danger); }
.fb-mark { flex: none; font-weight: var(--w-semi); }
.fb sub, .fb sup { font-size: .7em; }
.fb--ok .fb-mark { color: var(--success); }
.fb--no .fb-mark { color: var(--danger); }
.fb-slip { margin: 6px 0 0 3px; color: var(--muted); font: var(--t-body); max-width: none; }

.pq-proof, .pq-leftvis { margin-top: var(--sp-4); min-width: 0; }
.pq-proof:empty, .pq-leftvis:empty { display: none; }
.pq-maths-wrap { margin-top: var(--sp-4); }
.pq-maths {
  margin-top: var(--sp-3); padding: 0 var(--sp-4); background: var(--bg-tint);
  border: 1px solid var(--line); border-radius: var(--r-md); min-width: 0;
}
.pq-form { margin: 0; }
.pq-answer { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); }
.pq-answer .num-input { width: 11rem; max-width: 100%; }
.pq-answer .unit { color: var(--muted); font: var(--t-body-strong); }
.pq-answer .btn[aria-disabled="true"] { opacity: .5; cursor: default; }
.pq-end { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-5); }

@media (max-width: 480px) {
  main, .site-header { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .step-strategy-zone, .step-calc-zone, .verdict-card, .worksheet-header, .worksheet-body { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .step-combo-actions, .worksheet-actions, .verify-vis, .balls-stack { padding-left: var(--sp-4); padding-right: var(--sp-4); }
  .pq-maths { padding: 0 var(--sp-3); }
  .balls-actions { flex-direction: column; align-items: stretch; gap: var(--sp-2); padding: var(--sp-2) var(--sp-4) var(--sp-3); }
  .steps-dots { justify-content: center; }
  .balls-btns { flex-wrap: nowrap; }
  .balls-btns .btn { flex: 0 0 auto; min-height: 40px; padding: 6px 12px; font-size: .9375rem; }
  .balls-btns #balls-next { flex: 1 1 auto; }
  .ball-math { font-size: .875rem; }
}

