
.math-brand {
  display: flex;
  align-items: center;
  gap: .9rem;
  min-width: 0;
}

.math-brand__sep {
  width: 1px;
  height: 22px;
  background: var(--line-strong);
}

.math-brand__name {
  font-size: 1.55rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -.02em;
  color: var(--ink);
}

.site-header .theme-toggle {
  margin-left: auto;
}

.math-brand .brand {
  flex: none;
}

@media (width <= 480px) {
  .math-brand {
    gap: .5rem;
  }

  .math-brand .brand__logo {
    height: 12px;
  }

  .math-brand__sep {
    height: 18px;
  }

  .math-brand__name {
    font-size: 1.1rem;
  }
}

@media (width <= 400px) {
  .math-brand {
    gap: .4rem;
  }

  .math-brand .brand__logo {
    height: 10px;
  }

  .math-brand__name {
    font-size: 1rem;
  }
}

.math-page {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;
  padding-top: calc(var(--header-h) + clamp(2rem, 6vw, 4rem));
  overflow: clip;
}

.math-page > .ruler {
  margin-top: auto;
}

.math-page .hero__grid {
  bottom: auto;
  height: 32rem;
}

.math__layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2rem;
  padding-bottom: clamp(2rem, 4vw, 3rem);
}

.math__nav-title {
  margin-bottom: .75rem;
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.math__tabs {
  display: none;
}

.math__tab {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: .75rem;
  width: 100%;
  padding: .6rem 0 .6rem .9rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  font-size: .95rem;
  line-height: 1.6;
  text-align: left;
  color: var(--ink-2);
  cursor: pointer;
  transition: color .25s var(--ease);
}

.math__tab::before {
  content: '';
  position: absolute;
  left: 0;
  top: .55rem;
  bottom: .55rem;
  width: 2px;
  background: var(--accent);
  transform: scaleY(0);
  transition: transform .3s var(--ease-out);
}

.math__tab-num {
  font-family: var(--font-mono);
  font-size: .75rem;
  color: var(--muted);
  transition: color .25s var(--ease);
}

.math__tab[aria-selected='true'] {
  color: var(--ink);
}

.math__tab[aria-selected='true']::before {
  transform: scaleY(1);
}

.math__tab[aria-selected='true'] .math__tab-num {
  color: var(--accent);
}

@media (hover: hover) and (pointer: fine) {
  .math__tab:hover {
    color: var(--accent);
  }

  .math__tab:hover .math__tab-num {
    color: var(--accent);
  }
}

@media (min-width: 900px) {
  .math__layout {
    grid-template-columns: 15rem minmax(0, 1fr);
    gap: clamp(3rem, 5vw, 5rem);
  }

  .math__nav {
    position: sticky;
    top: calc(var(--header-h) + 1.5rem);
    align-self: start;
  }

  .math__picker {
    display: none;
  }

  .math__tabs {
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--line);
  }
}

.math-panel {
  display: grid;
  gap: 1.5rem;
  min-width: 0;
}

.math-panel:focus {
  outline: none;
}

.math-card {
  min-width: 0;
  padding: clamp(1.25rem, 3vw, 2rem);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.math-card__title {
  display: flex;
  align-items: baseline;
  gap: .9rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
  font-size: clamp(1.25rem, 2.2vw, 1.5rem);
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -.025em;
}

.math-card__num {
  font-family: var(--font-mono);
  font-size: .8rem;
  font-weight: 500;
  letter-spacing: .04em;
  color: var(--accent);
}

.math-card__grid {
  display: grid;
  gap: 1.75rem;
}

@media (min-width: 640px) {
  .math-card__grid {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  }

  .math-output {
    grid-column: 1 / -1;
  }
}

@media (min-width: 1240px) {
  .math-card__grid {
    grid-template-columns: minmax(0, 15rem) minmax(0, 10rem) minmax(0, 1fr);
    gap: 2rem;
  }

  .math-output {
    grid-column: auto;
  }
}

.math-label {
  display: block;
  margin-bottom: .5rem;
  font-family: var(--font-mono);
  font-size: .72rem;
  font-weight: 500;
  letter-spacing: .06em;
  line-height: 1.6;
  text-transform: uppercase;
  color: var(--muted);
}

.math-label output {
  color: var(--ink);
}

.math-note {
  padding: .9rem 1.1rem;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: .95rem;
  color: var(--ink-2);
}

.math-note strong {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--accent);
}

.math-hint {
  font-family: var(--font-mono);
  font-size: .7rem;
  letter-spacing: .04em;
  color: var(--muted);
}

.math-select,
.math-page input[type='number'],
#matrixTable input {
  min-height: 46px;
  padding: .6rem .9rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background-color: var(--bg);
  font-size: 1rem;
  transition: border-color .25s var(--ease), background-color .25s var(--ease), box-shadow .25s var(--ease);
}

.math-select {
  width: 100%;
  padding-right: 2.5rem;
  -webkit-appearance: none;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 1.15rem) 50%, calc(100% - .8rem) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.math-select option {
  background: var(--surface);
  color: var(--ink);
}

.math-page input[type='number'] {
  width: 100%;
  min-width: 0;
  font-family: var(--font-mono);
}

.math-select:hover,
.math-page input[type='number']:hover,
#matrixTable input:hover {
  border-color: var(--muted);
}

.math-select:focus,
.math-page input[type='number']:focus,
#matrixTable input:focus {
  outline: none;
  border-color: var(--accent);
  background-color: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.math-controls {
  display: grid;
  gap: 0;
  max-width: 18rem;
  margin-top: 1.25rem;
}

.math-controls--slider {
  max-width: 32rem;
  gap: .35rem;
}

#calcMatrix .math-controls--slider {
  max-width: 18rem;
}

.math-controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem 1.5rem;
  margin-top: 1.25rem;
}

.math-controls-row .math-controls {
  flex: 1 1 12rem;
  margin-top: 0;
}

.slider {
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: var(--line-strong);
}

.slider::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--line-strong);
}

.slider::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  -webkit-appearance: none;
  appearance: none;
}

.slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 3px solid var(--surface);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.slider:focus {
  outline: none;
}

.slider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 5px var(--accent-soft);
}

.slider:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 5px var(--accent-soft);
}

.math-figure__plate {
  display: grid;
  place-items: center;
  min-height: 14rem;
  margin-top: 1rem;
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background-color: var(--bg);
  background-image: radial-gradient(circle, var(--dot) 1px, transparent 1.2px);
  background-size: 16px 16px;
}

#equations .math-figure__plate {
  background-image: none;
}

.math-figure__plate img {
  height: auto;
}

:root:not([data-theme='light']) .math-figure__plate img {
  filter: invert(1) hue-rotate(180deg);
}

.math-params label {
  display: grid;
  grid-template-columns: 1.75rem minmax(0, 1fr);
  align-items: center;
  gap: .6rem;
  margin-bottom: .5rem;
}

.math-params label span {
  font-family: var(--font-mono);
  font-size: .9rem;
  color: var(--accent);
}

#shapes .math-output > .math-label {
  color: var(--accent);
}

.math-output .formula,
.math-output .calculation {
  margin-bottom: 1.5rem;
}

.math-output .calculation {
  margin-bottom: 0;
}

.formula > br,
.calculation > br {
  display: none;
}

.formula .title,
.calculation .title {
  display: block;
  font-size: .85rem;
  color: var(--muted);
}

.formula .rule,
.calculation .rule {
  display: block;
  margin-bottom: .75rem;
  font-family: var(--font-mono);
  font-size: .95rem;
  line-height: 1.7;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.calculation .rule span {
  font-weight: 500;
  color: var(--accent);
}

.calculation .rule span {
  text-decoration: underline 1px;
  text-underline-offset: .25em;
}

.math-card > .rule {
  padding: .9rem 1.1rem;
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--tint);
  font-family: var(--font-mono);
  font-size: .9rem;
  line-height: 1.7;
  color: var(--ink);
  overflow-wrap: anywhere;
}

sup,
sub {
  font-size: .7em;
  line-height: 0;
}

.math-result {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 1.05rem;
  color: var(--ink-2);
  overflow-wrap: anywhere;
}

.math-result:empty {
  display: none;
}

#pi .math-result span {
  color: var(--accent);
}

#pi .math-result span:not(.blink) {
  text-decoration: underline 1px;
  text-underline-offset: .25em;
}

#pi .math-result .title {
  display: inline;
  margin-right: .4rem;
  color: var(--muted);
}

#pi .math-result i {
  font-family: var(--font-sans);
  font-size: .95rem;
  font-style: normal;
  color: var(--muted);
}

#pi .math-result .blink {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: .6rem;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: .1em;
  animation: blinker 1.2s var(--ease) infinite;
}

@keyframes blinker {
  50% {
    opacity: .15;
  }
}

.math-result--sequence {
  max-height: 26rem;
  overflow-y: auto;
  font-size: .85rem;
  line-height: 1.8;
}

.primes {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  max-height: 28rem;
  overflow-y: auto;
}

.primes .subtitle {
  flex-basis: 100%;
  margin-bottom: .5rem;
  font-family: var(--font-sans);
  font-size: .95rem;
  color: var(--muted);
}

.primes > div:not(.subtitle) {
  min-width: 3rem;
  padding: .15rem .45rem;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--bg);
  font-size: .8rem;
  text-align: center;
  color: var(--ink-2);
  transition: border-color .25s var(--ease), background-color .25s var(--ease), color .25s var(--ease);
}

.primes > div.twin-prime {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.math-matrix-wrap {
  margin: 1.25rem -.35rem 0;
  overflow-x: auto;
}

#matrixTable {
  border-collapse: separate;
  border-spacing: .35rem;
}

#matrixTable td {
  padding: 0;
}

#matrixTable input {
  width: 4.25rem;
  min-height: 2.75rem;
  padding: .3rem;
  font-family: var(--font-mono);
  font-size: .9rem;
  text-align: center;
  -moz-appearance: textfield;
}

#matrixTable input::-webkit-inner-spin-button,
#matrixTable input::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.math-results {
  margin-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.math-results > div {
  display: grid;
  gap: .25rem 1.5rem;
  padding: .85rem 0;
  border-bottom: 1px solid var(--line);
}

.math-results dt {
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .06em;
  line-height: 1.9;
  text-transform: uppercase;
  color: var(--muted);
}

.math-results code {
  display: block;
  line-height: 2;
  font-family: var(--font-mono);
  font-size: .95rem;
  color: var(--ink);
}

.math-results small {
  font-family: var(--font-sans);
  font-size: .9rem;
  color: var(--muted);
}

table.matrix {
  display: inline-table;
  margin: .25rem 0;
  vertical-align: middle;
  border-collapse: collapse;
  border-left: 1px solid var(--ink-2);
  border-right: 1px solid var(--ink-2);
  border-radius: 3px;
}

table.matrix td {
  min-width: 2.4rem;
  padding: .15rem .45rem;
  font-size: .85rem;
  text-align: center;
}

@media (min-width: 640px) {
  .math-results > div {
    grid-template-columns: 9rem minmax(0, 1fr);
    align-items: center;
  }
}
