/**
 * Canon Pure CSS Mathematical Typography Engine
 * Shared across estate static sites and applications.
 *
 * Zero external libraries, zero remote CDN fonts, zero runtime JS.
 * Fully accessible, selectable, Ctrl+F searchable, and responsive.
 *
 * Driven by the --math-* CSS variable contract.
 * Upstream canonical source: ~/projects/siteops/shared/math/math.css
 */

:root {
  --math-font-family: "Latin Modern Math", "Cambria Math", "STIX Two Math", "TeX Gyre Termes Math", "Computer Modern Serif", "Times New Roman", Times, serif;
  --math-font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --math-font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Liberation Mono", Menlo, Consolas, monospace;
  --math-font-size: 1.25rem;
  --math-color: #ffd8a8;
  --math-accent: #ff9838;
  --math-dim: rgba(255, 255, 255, 0.45);
  --math-surface: rgba(14, 16, 22, 0.75);
  --math-border: rgba(255, 255, 255, 0.08);
  --math-border-accent: var(--math-accent);
  --math-radius: 6px;
  --math-legend-color: rgba(255, 255, 255, 0.65);
}

/* Sunken Math Display Box / Container */
.math-box,
.tc-math-box {
  background: var(--math-surface);
  border: 1px solid var(--math-border);
  border-left: 3px solid var(--math-border-accent);
  border-radius: var(--math-radius);
  padding: 1.25rem 1.5rem;
  margin: 1.5rem 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Primary Display Equation */
.math-equation,
.tc-math-equation {
  font-family: var(--math-font-family);
  font-size: var(--math-font-size);
  color: var(--math-color);
  margin-bottom: 0.75rem;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.2em 0;
  padding: 0.45rem 0.5rem;
  letter-spacing: 0.01em;
  user-select: all;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Inline Mathematical Snippet */
.math-inline,
.tc-math-inline {
  font-family: var(--math-font-family);
  font-size: 1.05em;
  color: var(--math-color);
  display: inline-flex;
  align-items: center;
  vertical-align: baseline;
  padding: 0 0.15em;
  white-space: nowrap;
}

/* Mathematical Variables (Italic Serif: x, y, t, θ, β) */
.math-var,
.tc-var {
  font-style: italic;
  padding: 0 0.05em;
}

/* Upright Standard Functions & Roman Labels (ln, exp, lim, sin, KL) */
.math-fn,
.tc-math-fn {
  font-style: normal;
  font-family: var(--math-font-sans);
  font-size: 0.9em;
  font-weight: 600;
  padding: 0 0.15em;
  letter-spacing: 0.02em;
}

/* Spaced Mathematical Operators (=, +, -, ·, ×, ≈, ≥, ≤, ||, |) */
.math-op,
.tc-math-op {
  font-style: normal;
  margin: 0 0.35em;
  color: var(--math-accent);
  display: inline-block;
}

/* Wide Quad Spacing (quad / qquad separation) */
.math-quad,
.tc-math-quad {
  display: inline-block;
  width: 1.65rem;
}

/* Standard Parentheses and Brackets */
.math-delim,
.tc-math-delim {
  font-style: normal;
  font-weight: 300;
  display: inline-block;
  transform: scaleY(1.2);
  margin: 0 0.06em;
  color: var(--math-dim);
}

/* Large / Outer Delimiters (Matrices, outer expectation brackets) */
.math-delim-lg,
.tc-math-delim-lg {
  font-style: normal;
  font-weight: 200;
  display: inline-block;
  transform: scaleY(1.65);
  vertical-align: -0.06em;
  margin: 0 0.08em;
  color: var(--math-dim);
}

/* Vertical True Fractions (\frac{num}{den}) */
.math-frac,
.tc-math-frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: -0.65em;
  margin: 0 0.28em;
  text-align: center;
  line-height: 1;
}

.math-frac > .math-num,
.math-frac > .tc-num,
.tc-math-frac > .tc-num,
.tc-math-frac > .math-num {
  display: block;
  font-size: 0.88em;
  padding-bottom: 0.22em;
  border-bottom: 1.5px solid var(--math-color);
  line-height: 1.1;
}

.math-frac > .math-den,
.math-frac > .tc-den,
.tc-math-frac > .tc-den,
.tc-math-frac > .math-den {
  display: block;
  font-size: 0.88em;
  padding-top: 0.22em;
  line-height: 1.1;
}

/* Limits with Subscript Expression (\lim_{\beta \to 0}) */
.math-lim,
.tc-math-lim {
  display: inline-flex;
  flex-direction: column;
  vertical-align: -0.78em;
  margin: 0 0.35em;
  text-align: center;
  line-height: 1;
}

.math-lim > .math-lim-name,
.math-lim > .tc-lim-name,
.tc-math-lim > .tc-lim-name,
.tc-math-lim > .math-lim-name {
  font-style: normal;
  font-size: 0.95em;
}

.math-lim > .math-lim-to,
.math-lim > .tc-lim-to,
.tc-math-lim > .tc-lim-to,
.tc-math-lim > .math-lim-to {
  font-size: 0.68em;
  margin-top: 0.18em;
  color: var(--math-dim);
  letter-spacing: -0.02em;
}

/* Precision Superscripts */
.math-sup,
.tc-math-sup {
  font-size: 0.7em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
  top: -0.58em;
  margin-left: 0.05em;
}

/* Precision Subscripts */
.math-sub,
.tc-math-sub {
  font-size: 0.7em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
  bottom: -0.25em;
  margin-left: 0.05em;
}

/* Stacked Subscript + Superscript (e.g. s_i^\beta) */
.math-subsup,
.tc-math-subsup {
  display: inline-flex;
  flex-direction: column;
  vertical-align: -0.48em;
  margin-left: 0.08em;
  line-height: 1;
  font-size: 0.7em;
  text-align: left;
}

.math-subsup > .math-sup-stacked,
.math-subsup > .tc-math-sup-stacked,
.tc-math-subsup > .tc-math-sup-stacked,
.tc-math-subsup > .math-sup-stacked {
  margin-bottom: 0.22em;
}

.math-subsup > .math-sub-stacked,
.math-subsup > .tc-math-sub-stacked,
.tc-math-subsup > .tc-math-sub-stacked,
.tc-math-subsup > .math-sub-stacked {
  margin-top: 0.08em;
}

/* Blackboard Bold (\mathbb{E}, \mathbb{R}, \mathbb{C}, \mathbb{Z}) */
.math-bb,
.tc-math-bb {
  font-style: normal;
  font-family: var(--math-font-family);
  font-size: 1.1em;
  font-weight: 700;
  padding: 0 0.08em;
}

/* Calligraphic Script (\mathcal{F}, \mathcal{L}, \mathcal{H}) */
.math-cal,
.tc-math-cal {
  font-style: italic;
  font-family: "Latin Modern Math", "Cambria Math", "STIX Two Math", "Apple Chancery", "Baskerville", serif;
  font-size: 1.2em;
  font-weight: 600;
  padding: 0 0.08em;
}

/* Formula Caption / Explanatory Legend */
.math-legend,
.tc-math-legend {
  font-size: 0.82rem;
  color: var(--math-legend-color);
  line-height: 1.6;
  margin: 0;
  border-top: 1px solid var(--math-border);
  padding-top: 0.65rem;
}

.math-legend code,
.tc-math-legend code {
  color: var(--math-color);
  background: var(--math-surface);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  border: 1px solid var(--math-border);
  font-family: var(--math-font-mono);
  font-size: 0.85em;
}

/* Compact math inside technical cards / grids */
.math-in-card .math-equation,
.tc-math-in-card .tc-math-equation,
.tc-math-in-card .math-equation {
  font-size: 1.05rem;
}

/* Responsive adjustment for small screens */
@media (max-width: 640px) {
  .math-equation,
  .tc-math-equation {
    font-size: 1.1rem;
    gap: 0.35em 0;
  }

  .math-box,
  .tc-math-box {
    padding: 1rem 1.1rem;
  }

  .math-quad,
  .tc-math-quad {
    width: 1rem;
  }
}
