/* Shared mathematical typesetting pass.
   Fractions are structural HTML rather than slash-text, and display equations never wrap. */
.math-typeset {
  min-width: 0;
  max-width: 100%;
  font-family: var(--font-math);
  font-variant-numeric: lining-nums;
  overflow-x: auto;
  overflow-y: hidden;
  overflow-wrap: normal !important;
  word-break: normal !important;
  scrollbar-width: thin;
  overscroll-behavior-inline: contain;
}

.math-typeset__content {
  width: max-content;
  min-width: max-content;
  display: inline-flex;
  align-items: baseline;
  flex-wrap: nowrap;
  white-space: pre;
  line-height: 1.25;
}

.math-typeset:not(.math-typeset--display) {
  overflow-x: visible;
  overflow-y: visible;
}

.math-typeset:not(.math-typeset--display) > .math-typeset__content {
  width: auto;
  min-width: 0;
  white-space: normal;
}

.math-typeset--display {
  width: 100%;
  text-align: center;
}

.math-typeset--display > .math-typeset__content {
  margin-inline: auto;
  padding: 0.3em 0.08em 0.28em;
}

.math-fraction {
  display: inline-grid;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: stretch;
  margin-inline: 0.1em;
  vertical-align: -0.42em;
  line-height: 1;
  text-align: center;
}

.math-fraction__numerator,
.math-fraction__denominator {
  min-width: 1.15em;
  padding-inline: 0.12em;
  text-align: center;
}

.math-fraction__numerator {
  padding-bottom: 0.08em;
  border-bottom: 0.065em solid currentColor;
}

.math-fraction__denominator {
  padding-top: 0.08em;
}

.math-script {
  position: relative;
  font-size: 0.68em;
  line-height: 0;
}

.math-delimited-group {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  vertical-align: middle;
}

.math-delimited-group__body {
  display: inline-flex;
  align-items: baseline;
}

.math-delimiter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-inline: 0.02em;
  font-family: "STIX Two Math", "Cambria Math", var(--font-math);
  line-height: 1;
  transform-origin: center;
}

.math-delimited-group--tall > .math-delimiter {
  font-size: 1.62em;
  transform: scaleY(1.12);
}

.math-script--fraction {
  font-size: 0.64em;
  letter-spacing: -0.025em;
  white-space: nowrap;
}

sup.math-script {
  top: -0.48em;
  vertical-align: baseline;
}
sub.math-script {
  top: 0.2em;
  vertical-align: baseline;
}

.math-integral {
  display: inline-flex;
  align-items: center;
  margin-inline: 0.08em 0.16em;
  vertical-align: -0.12em;
  white-space: nowrap;
}

.math-integral__symbol {
  display: inline-block;
  font-family: "STIX Two Math", "Cambria Math", var(--font-math);
  font-size: 1.34em;
  font-weight: var(--weight-regular);
  line-height: 0.9;
}

.math-integral--limited {
  display: inline-grid;
  grid-template-columns: auto max-content;
  grid-template-rows: 0.72em 0.72em;
  column-gap: 0.01em;
  align-items: center;
  margin-inline: 0.08em 0.2em;
  vertical-align: -0.28em;
}

.math-integral--limited .math-integral__symbol {
  grid-column: 1;
  grid-row: 1 / 3;
  align-self: center;
  font-size: 1.48em;
  line-height: 0.86;
}

.math-integral--limited .math-integral__limits {
  display: contents;
}

.math-integral__upper,
.math-integral__lower {
  display: block;
  grid-column: 2;
  min-width: 0.72em;
  padding-left: 0.02em;
  font-family: var(--font-math);
  font-size: 0.48em;
  line-height: 1;
  text-align: left;
  white-space: nowrap;
}

.math-integral__upper {
  grid-row: 1;
  align-self: end;
  transform: translateY(-0.08em);
}

.math-integral__lower {
  grid-row: 2;
  align-self: start;
  transform: translateY(0.08em);
}

.math-typeset--display .math-integral__symbol {
  font-size: 1.42em;
}

.math-typeset--display .math-integral--limited .math-integral__symbol {
  font-size: 1.56em;
}

.math-evaluation {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  white-space: nowrap;
}

.math-evaluation__body {
  display: inline-flex;
  align-items: baseline;
}

.math-evaluation__limits {
  display: inline-grid;
  grid-template-rows: 1fr 1fr;
  align-items: center;
  justify-items: center;
  min-width: 1.05em;
  margin-left: 0.05em;
  font-size: 0.56em;
  line-height: 0.92;
}

.math-evaluation__upper,
.math-evaluation__lower {
  display: block;
  min-width: 100%;
  text-align: center;
  white-space: nowrap;
}

.math-evaluation__upper {
  align-self: end;
  transform: translateY(-0.08em);
}

.math-evaluation__lower {
  align-self: start;
  transform: translateY(0.08em);
}

.question-shell__math.math-typeset,
.equation-step__expression.math-typeset,
.memory-learn-item__notation.math-typeset,
.memory-flashcard__content.math-typeset,
.memory-game-expression.math-typeset,
.word-bank-detail__notation.math-typeset {
  white-space: nowrap;
}

.equation-step__expression.math-typeset {
  overflow-wrap: normal;
  word-break: normal;
}

.memory-flashcard__content.math-typeset {
  width: 100%;
  max-width: 100%;
  text-align: center;
}

.memory-match-option.math-typeset,
.memory-game-token.math-typeset,
.memory-game-choice.math-typeset,
.memory-impostor-option.math-typeset,
.memory-sort-item.math-typeset,
.memory-rapid-option.math-typeset,
.question-option__label.math-typeset {
  max-width: 100%;
}

@media (max-width: 680px) {
  .question-shell__math.math-typeset {
    font-size: clamp(1.35rem, 7vw, 2.1rem);
  }

  .math-typeset--display > .math-typeset__content {
    margin-inline: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .math-typeset { scroll-behavior: auto; }
}

/* AO1 notation pass: typeset mathematical fragments inside prose without turning
   the whole sentence into display maths or forcing it onto one line. */
.math-typeset[data-math-prose] {
  font-family: inherit;
  overflow-x: visible;
  overflow-y: visible;
}

.math-typeset[data-math-prose] > .math-typeset__content {
  width: auto;
  min-width: 0;
  display: inline;
  white-space: inherit;
  line-height: inherit;
}

.math-typeset[data-math-prose] .math-fraction,
.math-typeset[data-math-prose] .math-script {
  font-family: var(--font-math);
}

