math {
  font-family: "Cambria Math", "STIX Two Math", "Latin Modern Math", math;
}

mtext[mathvariant="italic"] {
  font-style: italic;
}

.equations {
  overflow-x: auto;
  max-width: 100%;
  margin: 1.6rem 0;
  padding: .4rem 0;
}

.equation-grid {
  display: table;
  width: max-content;
  min-width: 100%;
  border-spacing: 0 .6rem;
}

.equation-row {
  display: table-row;
}

.equation-term,
.equation-number {
  display: table-cell;
  vertical-align: middle;
}

.equation-term math {
  display: inline math;
  math-style: normal;
}

.equation-left,
.equation-number {
  text-align: right;
}

.equation-right {
  padding-left: .22em;
  text-align: left;
}

.equation-full {
  text-align: center;
}

.equation-row .equation-number {
  width: 3.5em;
  padding-left: 1em;
  font-size: .86em;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  color: inherit;
}

figure.algorithm {
  margin: 2rem 0;
  padding: 0;
  border-block: 1px solid currentColor;
}

figure.algorithm > figcaption {
  margin: 0;
  padding: .7em 0;
  border-bottom: 1px solid currentColor;
  color: inherit;
  text-align: left;
  font-size: 1em;
  line-height: 1.4;
}

.algorithm-number {
  display: block;
  margin-bottom: .25em;
  font: 600 .75rem/1.3 var(--sans);
  letter-spacing: .05em;
  text-transform: uppercase;
}

.algorithm-list {
  padding: .75em 0;
  font-size: .91em;
  line-height: 1.5;
}

.algorithm-line {
  display: grid;
  grid-template-columns: 2em minmax(0, 1fr);
  padding: .15em 0;
}

.algorithm-statement {
  padding-inline-start: calc(var(--depth) * .95em);
  overflow-wrap: anywhere;
}

.algorithm-line-number {
  align-self: start;
  justify-self: start;
  padding: .15em .35em;
  font: .76em/1.75 var(--sans);
  font-variant-numeric: tabular-nums;
}

.algorithm-line .algorithm-line-number {
  color: inherit;
  text-decoration: none;
}

.algorithm-number,
.algorithm-variable,
.algorithm-function {
  font-family: var(--sans);
}

.algorithm-comment {
  font-style: italic;
}

.equation-number:hover,
.algorithm-line-number:hover,
.equation-number:focus-visible,
.algorithm-line-number:focus-visible {
  text-decoration: underline;
}

.equation-row:target,
.algorithm-line:target {
  background: color-mix(in srgb, currentColor 9%, transparent);
}

@media print {
  .equations { overflow: visible; font-size: .84em; }
  .algorithm-line, .equation-row { break-inside: avoid; }
}
