/* ═══════════════════════════════════════════════════════════════════
   math.css — KaTeX-quality math rendering with zero JavaScript.
   Pairs with engine/math_render.py
   ═══════════════════════════════════════════════════════════════════ */

/* ── Variables (italic single-letter) ── */
.sol-math i,
.sol-ans i,
.sol-final-text i,
.step-block i,
.math i {
  font-family: 'Cambria Math', 'Latin Modern Math', 'STIX Two Math', Georgia, 'Times New Roman', serif;
  font-style: italic;
  letter-spacing: 0.02em;
}

/* Class-based variable (used by math_render.py) */
.mv {
  font-family: 'Cambria Math', 'Latin Modern Math', 'STIX Two Math', Georgia, 'Times New Roman', serif;
  font-style: italic;
  letter-spacing: 0.02em;
}

/* ── Numbers (upright serif in math context) ── */
.mn {
  font-family: 'Cambria Math', 'Latin Modern Math', Georgia, 'Times New Roman', serif;
  font-style: normal;
}

/* ── Operators ── */
.mo {
  font-family: 'Cambria Math', 'Latin Modern Math', Georgia, serif;
  padding: 0 0.15em;
}

/* ── Superscripts & subscripts ── */
.sol-math sup,
.sol-ans sup,
.sol-final-text sup,
.step-block sup,
.math sup {
  font-size: 0.7em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
  top: -0.42em;
}

.sol-math sub,
.sol-ans sub,
.sol-final-text sub,
.step-block sub,
.math sub {
  font-size: 0.7em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
  top: 0.3em;
}

/* ── Stacked fractions ── */
.mfrac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 0.15em;
  line-height: 1;
  text-align: center;
}

.mfrac .mfn {
  padding: 0 0.25em 0.15em;
  border-bottom: 1.2px solid currentColor;
  line-height: 1.15;
  min-width: 0.6em;
}

.mfrac .mfd {
  padding: 0.15em 0.25em 0;
  line-height: 1.15;
  min-width: 0.6em;
}

/* Small inline fractions (inside superscripts, etc.) */
.mfrac-sm {
  font-size: 0.8em;
  margin: 0 0.1em;
}

.mfrac-sm .mfn,
.mfrac-sm .mfd {
  padding: 0 0.15em;
}

/* ── Square root / radicals ── */
.msqrt {
  display: inline-flex;
  align-items: stretch;
  vertical-align: middle;
  margin: 0 0.1em;
  position: relative;
}

.msqrt-sign {
  font-family: 'Cambria Math', 'Latin Modern Math', 'STIX Two Math', serif;
  font-size: 1.15em;
  line-height: 1;
  display: flex;
  align-items: flex-end;
}

.msqrt-body {
  padding: 2px 3px 0 2px;
  line-height: 1.25;
  min-width: 0.5em;
  position: relative;
}

/* Vinculum line: extends from left edge of body across to right */
.msqrt-body::before {
  content: '';
  position: absolute;
  top: 0;
  left: -1px;   /* overlap 1px into the √ sign area */
  right: 0;
  height: 0;
  border-top: 1.3px solid currentColor;
}

/* nth root index (small number above radical) */
.msqrt-idx {
  font-size: 0.6em;
  position: relative;
  top: -0.3em;
  margin-right: -3px;
}

/* ── Absolute value ── */
.mabs {
  display: inline-flex;
  align-items: center;
}

.mabs::before,
.mabs::after {
  content: "|";
  font-family: 'Cambria Math', Georgia, serif;
  font-weight: 200;
  font-size: 1.15em;
  color: currentColor;
  padding: 0 1px;
}

/* ── Scalable parentheses ── */
.mparen {
  display: inline-flex;
  align-items: center;
}

.mparen::before {
  content: "(";
  font-family: 'Cambria Math', Georgia, serif;
  font-weight: 200;
  font-size: 1.2em;
  color: var(--text-3);
  margin-right: 1px;
}

.mparen::after {
  content: ")";
  font-family: 'Cambria Math', Georgia, serif;
  font-weight: 200;
  font-size: 1.2em;
  color: var(--text-3);
  margin-left: 1px;
}

/* Large parens (around tall fractions) */
.mparen-lg::before,
.mparen-lg::after {
  font-size: 1.8em;
  line-height: 0.85;
}

/* ── Integral sign ── */
.mint {
  font-family: 'Cambria Math', 'Latin Modern Math', 'STIX Two Math', serif;
  font-size: 1.4em;
  font-style: normal;
  line-height: 1;
  vertical-align: middle;
  margin: 0 0.1em;
}

/* ── Limit notation ── */
.mlim {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 0.2em;
  font-style: normal;
}

.mlim sub {
  font-size: 0.7em;
  position: static;
  top: auto;
}

/* ── Summation ── */
.msum {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  font-family: 'Cambria Math', 'Latin Modern Math', serif;
  font-size: 1.3em;
  line-height: 1;
  margin: 0 0.15em;
}

.msum-top,
.msum-bot {
  font-size: 0.55em;
  line-height: 1.1;
}

/* ═══════════════════════════════════════════════════════════════════
   SOLUTION CARD — the main output container
   ═══════════════════════════════════════════════════════════════════ */

/* ── Answer bar at top ── */
.sol-ans {
  font-family: 'Cambria Math', 'Latin Modern Math', Georgia, 'Times New Roman', serif;
  font-size: 1.25em;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: var(--text);
}

/* ── Math expression lines ── */
.sol-card .sol-math {
  font-family: 'Cambria Math', 'Latin Modern Math', Georgia, 'Times New Roman', serif;
  font-size: 15px;
  color: var(--text);
  line-height: 2;
  margin: 3px 0 3px 20px;
  padding: 2px 0;
  letter-spacing: 0.01em;
}

/* ── Final answer — green ── */
.sol-card .sol-math.sol-final {
  color: var(--accent);
  font-weight: 500;
}

.sol-final-block {
  margin-top: 10px;
}

.sol-final-text {
  font-family: 'Cambria Math', 'Latin Modern Math', Georgia, 'Times New Roman', serif;
  font-size: 16px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.01em;
}

/* ═══════════════════════════════════════════════════════════════════
   NEW STEP FORMAT — clean flowing text
   (Used by AlgebraBuilder and new-format solvers)
   ═══════════════════════════════════════════════════════════════════ */

.step-block {
  margin-bottom: 18px;
}

/* Step header — "Step 1: Factor the quadratic" */
.step-header {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

/* Substep text */
.step-substep {
  font-size: 14px;
  color: var(--text-2);
  margin-bottom: 3px;
  line-height: 1.7;
}

/* Substep math */
.step-substep .math {
  font-family: 'Cambria Math', 'Latin Modern Math', Georgia, 'Times New Roman', serif;
  font-size: 15px;
  color: var(--text);
  letter-spacing: 0.01em;
  display: block;
  padding: 3px 0 3px 20px;
  line-height: 2;
}

/* Step result — plain flow */
.step-result {
  margin-top: 4px;
}

.step-result .math {
  font-family: 'Cambria Math', 'Latin Modern Math', Georgia, 'Times New Roman', serif;
  font-size: 15px;
  color: var(--text);
  font-weight: 500;
  letter-spacing: 0.01em;
  padding-left: 20px;
}

/* ── Given / equation block — plain, no box ── */
.given-block,
.equation-block {
  margin-bottom: 14px;
}

.given-block .math-line .math,
.equation-block .math-line .math {
  font-family: 'Cambria Math', 'Latin Modern Math', Georgia, 'Times New Roman', serif;
  font-size: 16px;
  color: var(--text);
  letter-spacing: 0.01em;
}

/* ── Substitute block ── */
.substitute-block {
  margin-bottom: 14px;
}

.substitute-block .text-line {
  font-size: 14px;
  color: var(--text-3);
  margin-bottom: 4px;
}

.substitute-block .math-line .math {
  font-family: 'Cambria Math', 'Latin Modern Math', Georgia, 'Times New Roman', serif;
  font-size: 15px;
  padding-left: 16px;
}

/* ── Note block ── */
.note-block {
  margin-bottom: 10px;
}

.note-block .text-line {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
}

/* ── Final answer block — plain, green text only ── */
.final-block {
  margin-top: 10px;
}

.final-block .math-line .math {
  font-family: 'Cambria Math', 'Latin Modern Math', Georgia, 'Times New Roman', serif;
  font-size: 17px;
  font-weight: 500;
  color: var(--accent);
}

.final-block .text-line {
  font-weight: 600;
  color: var(--accent);
  font-size: 15px;
}

/* ── Step gap ── */
.step-gap {
  height: 16px;
}

/* ═══════════════════════════════════════════════════════════════════
   DIAGRAMS — SVG geometry/coordinate/number-line illustrations
   ═══════════════════════════════════════════════════════════════════ */

.sol-diagram {
  margin: 14px 0;
  text-align: center;
  overflow-x: auto;
}

.sol-diagram svg {
  max-width: 100%;
  height: auto;
  display: inline-block;
}

/* Responsive: shrink diagrams on mobile */
@media (max-width: 640px) {
  .sol-diagram svg {
    max-width: 100%;
    height: auto;
  }
  .sol-math, .sol-ans, .math {
    font-size: 14px;
  }
  .sol-final-text {
    font-size: 15px;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   NESTED FRACTIONS — smaller inner fractions to avoid overflow
   ═══════════════════════════════════════════════════════════════════ */

.mfrac .mfrac {
  font-size: 0.85em;
}

.mfrac .mfrac .mfrac {
  font-size: 0.8em;
}

/* Fraction inside radical — tighter spacing */
.msqrt .mfrac,
.msqrt-body .mfrac {
  font-size: 0.9em;
}

/* ═══════════════════════════════════════════════════════════════════
   LARGE PARENTHESES — for wrapping tall content (stacked fractions)
   ═══════════════════════════════════════════════════════════════════ */

.mparen-xl::before,
.mparen-xl::after {
  font-size: 2.2em;
  line-height: 0.75;
}

/* ═══════════════════════════════════════════════════════════════════
   MATRIX — bracket-bordered grid
   ═══════════════════════════════════════════════════════════════════ */

.mmatrix {
  display: inline-block;
  vertical-align: middle;
  border-left: 2px solid currentColor;
  border-right: 2px solid currentColor;
  padding: 4px 6px;
  margin: 0 0.2em;
  border-radius: 2px;
}

.mmatrix table {
  border-collapse: collapse;
}

.mmatrix td {
  padding: 2px 8px;
  text-align: center;
  font-family: 'Cambria Math', 'Latin Modern Math', Georgia, serif;
  font-size: inherit;
}

/* ═══════════════════════════════════════════════════════════════════
   EQUATION ALIGNMENT — align = signs across consecutive lines
   ═══════════════════════════════════════════════════════════════════ */

.sol-math-align {
  display: flex;
  flex-direction: column;
  margin: 3px 0 3px 20px;
}

.sol-math-align .sol-math {
  margin: 0;
  padding: 2px 0;
}
