:root {
  --paper: #f4f0e6;
  --ink: #1d2230;
  --vermilion: #d2462a;
  --slate: #3e5c86;
  --olive: #6e7a3a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "Liberation Serif", "Times New Roman", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: color-mix(in srgb, var(--vermilion) 16%, transparent);
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: 0.028;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.86' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.6'/%3E%3C/svg%3E");
}

.sheet {
  width: min(calc(100% - 32px), 800px);
  margin: 0 auto;
  padding: 24px 0 28px;
}

.masthead {
  text-align: center;
}

.kicker {
  margin: 0;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--ink);
}

.rule {
  height: 1px;
  background: color-mix(in srgb, var(--ink) 52%, transparent);
}

.masthead-rule {
  margin-top: 14px;
}

.equation {
  padding: clamp(34px, 6vh, 52px) 0 clamp(26px, 4.5vh, 38px);
  text-align: center;
}

.formula {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  column-gap: 0.2em;
  row-gap: 0.06em;
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(30px, 7.4vw, 62px);
  font-weight: 600;
  line-height: 1.04;
  letter-spacing: -0.012em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.formula-group {
  display: inline-flex;
  align-items: baseline;
  gap: 0.15em;
  white-space: nowrap;
}

.formula .var {
  font-style: italic;
}

.formula .var sub,
.var-name sub {
  font-family: var(--serif);
  font-style: normal;
  font-size: 0.46em;
  line-height: 0;
  letter-spacing: 0;
  vertical-align: -0.28em;
}

.formula .op {
  font-weight: 500;
  color: var(--ink);
}

.formula .op.dot {
  font-size: 0.72em;
  color: color-mix(in srgb, var(--ink) 82%, transparent);
}

.formula .coef {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.formula .x1 {
  color: var(--vermilion);
}

.formula .x0 {
  color: var(--slate);
}

.formula .z1 {
  color: var(--olive);
}

.substitution {
  margin: 0.75em auto 0;
  max-width: 100%;
  font-family: var(--serif);
  font-size: clamp(15px, 2.35vw, 21px);
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0.002em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-wrap: balance;
}

.substitution .sub-var {
  font-style: italic;
  font-weight: 400;
}

.substitution .sub-var.x1 {
  color: var(--vermilion);
}

.substitution .sub-val.x0 {
  color: var(--slate);
}

.substitution .sub-val.z1 {
  color: var(--olive);
}

.substitution .sub-result {
  color: var(--vermilion);
  font-weight: 700;
  font-size: 1.28em;
  line-height: 1;
  letter-spacing: -0.01em;
  margin-left: 0.02em;
}

.substitution sub {
  font-family: var(--serif);
  font-style: normal;
  font-size: 0.52em;
  line-height: 0;
  letter-spacing: 0;
  vertical-align: -0.26em;
}

.substitution .sub-op,
.substitution .sub-coef {
  color: var(--ink);
}

.section-rule {
  background: color-mix(in srgb, var(--ink) 40%, transparent);
}

.hair {
  background: color-mix(in srgb, var(--ink) 24%, transparent);
}

.slider-row {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr) 104px 124px;
  column-gap: 16px;
  align-items: center;
  padding: 22px 0;
}

.slider-row.x0 {
  --tint: var(--slate);
}

.slider-row.z1 {
  --tint: var(--olive);
}

.output-row {
  --tint: var(--vermilion);
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  column-gap: 16px;
  align-items: center;
  padding: 24px 0 22px;
}

.row-name {
  min-width: 0;
}

.var-name {
  display: inline-block;
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(42px, 4.6vw, 56px);
  font-weight: 600;
  line-height: 0.92;
  letter-spacing: -0.015em;
  color: var(--tint);
  border-bottom: 1px solid transparent;
  padding-bottom: 4px;
}

.role {
  display: block;
  margin-top: 8px;
  max-width: 84px;
  font-family: var(--sans);
  font-size: 9.5px;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--ink) 62%, transparent);
}

.ruler {
  --line: 22px;
  --minor: 5%;
  --major: 25%;
  position: relative;
  min-width: 0;
  height: 48px;
  cursor: ew-resize;
  touch-action: none;
}

.ruler.output {
  --line: 72px;
  --minor: 2.5%;
  --major: 12.5%;
  height: 108px;
  cursor: default;
  touch-action: auto;
}

.ruler-line {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--line);
  height: 1px;
  background: var(--ink);
  opacity: 0.9;
}

.ticks {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
}

.ticks.minor {
  top: calc(var(--line) - 8px);
  height: 8px;
  background-image: repeating-linear-gradient(90deg, var(--ink) 0 1px, transparent 1px var(--minor));
}

.ticks.major {
  top: calc(var(--line) - 16px);
  height: 16px;
  background-image: repeating-linear-gradient(90deg, var(--ink) 0 1.5px, transparent 1.5px var(--major));
}

.cap {
  position: absolute;
  top: calc(var(--line) - 20px);
  width: 1px;
  height: 28px;
  background: var(--ink);
}

.cap.start {
  left: 0;
}

.cap.end {
  right: 0;
}

.zero-tick {
  position: absolute;
  left: 50%;
  top: calc(var(--line) - 16px);
  width: 2px;
  height: 16px;
  margin-left: -1px;
  background: var(--ink);
}

.thumb {
  position: absolute;
  top: calc(var(--line) - 6.5px);
  left: 50%;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--tint);
  transform: translateX(-50%);
  transition: left 120ms cubic-bezier(0.2, 0.6, 0.25, 1);
  pointer-events: none;
  z-index: 3;
}

.tick-labels {
  pointer-events: none;
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--line) + 10px);
  height: 16px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  color: color-mix(in srgb, var(--ink) 68%, transparent);
  font-variant-numeric: tabular-nums;
}

.tick-labels span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
}

.tick-labels span:nth-child(1) { left: 0; }
.tick-labels span:nth-child(2) { left: 25%; }
.tick-labels span:nth-child(3) { left: 50%; }
.tick-labels span:nth-child(4) { left: 75%; }
.tick-labels span:nth-child(5) { left: 100%; }

.range {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  pointer-events: none;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  outline: none;
  z-index: 5;
}

.range::-webkit-slider-runnable-track {
  height: 1px;
  background: transparent;
}

.range::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 1px;
  height: 1px;
  background: transparent;
  border: none;
}

.range::-moz-range-track {
  height: 1px;
  background: transparent;
}

.range::-moz-range-thumb {
  width: 1px;
  height: 1px;
  background: transparent;
  border: none;
}

.slider-row:has(.range:focus-visible) .var-name {
  border-bottom-color: var(--tint);
}

.row-value {
  font-family: var(--sans);
  font-size: 38px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.018em;
  color: var(--tint);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.note {
  align-self: center;
  border-left: 1px solid color-mix(in srgb, var(--ink) 30%, transparent);
  padding-left: 14px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  color: color-mix(in srgb, var(--ink) 72%, transparent);
}

.note-coef {
  font-style: italic;
}

.output-value {
  position: absolute;
  left: clamp(46px, var(--pos, 50%), calc(100% - 46px));
  bottom: 64px;
  transform: translateX(-50%);
  font-family: var(--sans);
  font-size: 32px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.015em;
  color: var(--vermilion);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: left 120ms cubic-bezier(0.2, 0.6, 0.25, 1);
  z-index: 4;
}

.bottom-rule {
  margin-top: 0;
}

@media (max-width: 760px) {
  .sheet {
    width: min(calc(100% - 32px), 560px);
    padding: 18px 0 22px;
  }

  .kicker {
    font-size: 9px;
    letter-spacing: 0.2em;
  }

  .masthead-rule {
    margin-top: 11px;
  }

  .equation {
    padding: 28px 0 22px;
  }

  .formula {
    font-size: clamp(30px, 8.2vw, 44px);
  }

  .substitution {
    margin-top: 0.6em;
    font-size: clamp(15px, 4vw, 18px);
    line-height: 1.5;
  }

  .substitution .sub-result {
    font-size: 1.22em;
  }

  .slider-row {
    grid-template-columns: 60px minmax(0, 1fr) 72px;
    column-gap: 12px;
    padding: 15px 0;
  }

  .note {
    display: none;
  }

  .var-name {
    font-size: clamp(34px, 9vw, 44px);
  }

  .role {
    margin-top: 7px;
    max-width: 62px;
    font-size: 8px;
    letter-spacing: 0.12em;
    line-height: 1.5;
  }

  .row-value {
    font-size: clamp(22px, 6.4vw, 28px);
  }

  .tick-labels {
    font-size: 9.5px;
  }

  .output-row {
    grid-template-columns: 60px minmax(0, 1fr);
    column-gap: 12px;
    padding: 16px 0 16px;
  }

  .ruler.output {
    --line: 64px;
    height: 100px;
  }

  .output-value {
    left: clamp(36px, var(--pos, 50%), calc(100% - 36px));
    bottom: 60px;
    font-size: clamp(22px, 6.6vw, 28px);
  }

  .tick-labels span:nth-child(1) {
    left: 0;
    transform: none;
  }

  .tick-labels span:nth-child(5) {
    left: 100%;
    transform: translateX(-100%);
  }
}

@media (min-width: 761px) and (min-height: 640px) {
  .sheet {
    margin-block: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .thumb,
  .output-value {
    transition: none;
  }
}
