:root {
  --paper: #f7f5f0;
  --card: #ffffff;
  --ink: #16130f;
  --muted: #6b645c;
  --hairline: #ddd8cf;
  --primary: #b8471f;
  --primary-soft: #f3e5df;
  --secondary: #3a5a7a;
  --secondary-soft: #e5ebf1;
  --reference: #6b645c;
  --focus: #f0b69f;
  --shadow: #e9e5dd;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --max-width: 1180px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
  color: var(--ink);
}

body {
  margin: 0;
  min-width: 0;
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: var(--primary-soft);
  touch-action: manipulation;
}

a {
  color: var(--secondary);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--primary);
}

button,
input,
select {
  font: inherit;
}

button,
select,
input[type="number"] {
  min-height: 44px;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  z-index: 10;
  top: 8px;
  left: 8px;
  padding: 8px 12px;
  background: var(--ink);
  color: var(--card);
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.wrap {
  width: min(100%, var(--max-width));
  margin: 0 auto;
  padding-inline: 28px;
}

.reading-width {
  max-width: 900px;
}

.masthead {
  padding: 28px 0 38px;
  border-bottom: 1px solid var(--hairline);
}

.masthead-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--hairline);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.masthead-line nav {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.masthead-line a {
  color: var(--muted);
}

.kicker,
.section-number,
.figure-number {
  margin: 0;
  color: var(--primary);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.kicker {
  margin-top: 42px;
}

h1,
h2,
h3 {
  margin-top: 0;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(3.2rem, 9vw, 6.8rem);
  line-height: 0.96;
  letter-spacing: -0.055em;
}

h2 {
  margin-bottom: 8px;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  line-height: 1.12;
}

h3 {
  margin-bottom: 6px;
  font-size: 1.05rem;
  line-height: 1.3;
}

.lede {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  font-size: 1.08rem;
}

.study-meta {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0;
  margin: 34px 0 0;
  border-block: 1px solid var(--hairline);
}

.study-meta div {
  min-width: 0;
  padding: 14px 18px;
  border-right: 1px solid var(--hairline);
}

.study-meta div:first-child {
  padding-left: 0;
}

.study-meta div:last-child {
  border-right: 0;
}

.study-meta dt,
.study-meta dd {
  margin: 0;
}

.study-meta dt {
  color: var(--muted);
  font-size: 0.75rem;
}

.study-meta dd,
.fit-strip strong,
.threshold-readout strong,
.data-table td:not(:first-child) {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.paper-section {
  padding: 64px 0;
  scroll-margin-top: 12px;
}

.paper-section.ruled {
  border-block: 1px solid var(--hairline);
  background: var(--card);
}

.section-heading {
  max-width: 780px;
  margin-bottom: 30px;
}

.section-heading h2 {
  margin-top: 4px;
}

.section-heading > p:last-child {
  margin: 0;
  color: var(--muted);
}

.controls {
  display: grid;
  grid-template-columns: 1.05fr 1.35fr 1fr;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--hairline);
  background: var(--card);
  box-shadow: 3px 3px 0 var(--shadow);
}

.control {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.control > label,
.control > legend {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
}

.control output {
  float: right;
  color: var(--ink);
  font-family: var(--font-mono);
}

select,
input[type="number"] {
  width: 100%;
  border: 1px solid var(--hairline);
  border-radius: 2px;
  background: var(--card);
  color: var(--ink);
  padding: 8px 10px;
}

select {
  cursor: pointer;
}

input[type="range"] {
  width: 100%;
  min-height: 44px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.segmented label {
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  display: grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid var(--hairline);
  background: var(--paper);
  color: var(--muted);
  font-size: 0.82rem;
}

.segmented label + label span {
  border-left: 0;
}

.segmented input:checked + span {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.segmented input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.status {
  min-height: 26px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.status.error {
  color: var(--primary);
}

.fit-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 18px;
  border-block: 1px solid var(--hairline);
}

.fit-strip div {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 12px 16px;
  border-right: 1px solid var(--hairline);
}

.fit-strip div:first-child {
  padding-left: 0;
}

.fit-strip div:last-child {
  border-right: 0;
}

.fit-strip span {
  color: var(--muted);
  font-size: 0.74rem;
}

.fit-strip strong {
  overflow: hidden;
  font-size: 0.92rem;
  font-weight: 400;
  text-overflow: ellipsis;
}

.analysis-block {
  margin-top: 52px;
  padding-top: 22px;
  border-top: 2px solid var(--ink);
}

.analysis-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.analysis-head h3 {
  margin-top: 2px;
}

.annotation {
  max-width: 800px;
  margin: 4px 0 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px 16px;
  margin: 0 0 6px;
  padding: 0;
  color: var(--muted);
  font-size: 0.75rem;
  list-style: none;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  display: inline-block;
  width: 18px;
  height: 3px;
  background: var(--ink);
}

.swatch.temperature {
  background: var(--primary);
}

.swatch.isotonic {
  background: var(--secondary);
}

.swatch.reference {
  height: 0;
  border-top: 1px dashed var(--reference);
  background: transparent;
}

.chart {
  display: block;
  width: 100%;
  height: auto;
  min-height: 360px;
  border: 1px solid var(--hairline);
  background: var(--card);
}

.chart text {
  font-family: var(--font-ui);
  font-size: 12px;
}

.chart .svg-number {
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart .svg-label {
  font-size: 12px;
}

details {
  margin-top: 14px;
  border-bottom: 1px solid var(--hairline);
}

summary {
  min-height: 44px;
  padding: 10px 0;
  color: var(--secondary);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 400;
}

summary:hover {
  color: var(--primary);
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.data-table {
  width: 100%;
  min-width: 700px;
  border-collapse: collapse;
  background: var(--card);
  font-size: 0.82rem;
}

.data-table caption {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--hairline);
  text-align: right;
  white-space: nowrap;
}

.data-table th {
  color: var(--muted);
  font-weight: 400;
  vertical-align: bottom;
}

.data-table th:first-child,
.data-table td:first-child {
  text-align: left;
}

.data-table tbody tr:hover {
  background: var(--paper);
}

.metrics-table {
  min-width: 820px;
}

.delta-better {
  color: var(--secondary);
}

.delta-worse {
  color: var(--primary);
}

.cost-controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 18px;
  align-items: end;
  max-width: 720px;
  margin: 22px 0;
}

.threshold-readout {
  display: flex;
  min-height: 70px;
  flex-direction: column;
  justify-content: center;
  padding: 8px 14px;
  border-left: 3px solid var(--primary);
  background: var(--primary-soft);
}

.threshold-readout span {
  color: var(--muted);
  font-size: 0.75rem;
}

.threshold-readout strong {
  font-size: 1.2rem;
  font-weight: 400;
}

.method-list article {
  display: grid;
  grid-template-columns: minmax(190px, 0.34fr) 1fr;
  gap: 30px;
  padding: 24px 0;
  border-top: 1px solid var(--hairline);
}

.method-list article:last-child {
  border-bottom: 1px solid var(--hairline);
}

.method-list p,
#data .reading-width > p,
.limitations-list {
  margin: 0;
  color: var(--muted);
}

code,
var {
  font-family: var(--font-mono);
  font-style: normal;
}

code {
  color: var(--ink);
  font-size: 0.88em;
}

.limitations-list {
  padding-left: 20px;
}

.limitations-list li {
  margin-bottom: 12px;
  padding-left: 6px;
}

#data .reading-width > p + p {
  margin-top: 16px;
}

footer {
  padding: 28px 0;
  border-top: 1px solid var(--hairline);
  color: var(--muted);
  font-size: 0.78rem;
}

footer p {
  margin: 0;
}

@media (max-width: 760px) {
  .wrap {
    padding-inline: 18px;
  }

  .masthead-line {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .kicker {
    margin-top: 32px;
  }

  .study-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .study-meta div,
  .study-meta div:first-child {
    padding: 10px 12px;
    border-bottom: 1px solid var(--hairline);
  }

  .study-meta div:nth-child(even) {
    border-right: 0;
  }

  .study-meta div:last-child {
    border-bottom: 0;
  }

  .paper-section {
    padding: 48px 0;
  }

  .controls,
  .cost-controls {
    grid-template-columns: 1fr;
  }

  .fit-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .fit-strip div,
  .fit-strip div:first-child {
    padding: 10px 12px;
    border-bottom: 1px solid var(--hairline);
  }

  .fit-strip div:nth-child(even) {
    border-right: 0;
  }

  .analysis-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .legend {
    justify-content: flex-start;
  }

  .chart {
    min-height: 280px;
  }

  .method-list article {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }

  a,
  .segmented span {
    transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease;
  }
}
