:root {
  color-scheme: light dark;
  --surface: #fcfcfb;
  --ink: #14213a;
  --muted: #4d576b;
  --rule: #d9dee8;
  --track: #eef1f6;
  --blue: #2a78d6;
  --orange: #eb6834;
  --link: #1c5cab;
  --head: Bahnschrift, "DIN Alternate", "Roboto Condensed", "Helvetica Neue", Arial, sans-serif;
  --body: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #171a21;
    --ink: #edf0f6;
    --muted: #adb6c7;
    --rule: #353b48;
    --track: #232833;
    --blue: #3987e5;
    --orange: #d95926;
    --link: #8bbcf5;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font: 1.0625rem/1.6 var(--body);
}

a { color: var(--link); }

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

.skip { position: absolute; left: -999rem; }
.skip:focus { left: 1rem; top: 1rem; z-index: 2; background: var(--surface); padding: 0.5rem 1rem; }

.page {
  display: grid;
  grid-template-columns: 14rem minmax(0, 52rem);
  gap: 3.5rem;
  max-width: 76rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.side {
  align-self: start;
  position: sticky;
  top: 0;
  padding-top: 2rem;
  max-height: 100vh;
  overflow-y: auto;
  font-family: var(--head);
}
.site-name { font-size: 1.15rem; font-weight: 700; margin: 0 0 1rem; }
nav ul { list-style: none; margin: 0; padding: 0; }
nav a {
  display: block;
  padding: 0.3rem 0 0.3rem 0.75rem;
  border-left: 3px solid var(--rule);
  color: var(--muted);
  text-decoration: none;
}
nav a:hover { color: var(--ink); text-decoration: underline; }
nav a[aria-current="true"] { border-left-color: var(--blue); color: var(--ink); }

main { padding-top: 2rem; min-width: 0; }

section { padding-bottom: 3rem; margin-bottom: 3rem; border-bottom: 1px solid var(--rule); }

h1, h2, h3 { font-family: var(--head); line-height: 1.15; text-wrap: balance; }
h1 {
  font-size: clamp(2.4rem, 7vw, 4.25rem);
  font-stretch: condensed;
  margin: 0 0 0.75rem;
}
h2 { font-size: 1.9rem; margin: 0 0 1rem; }
section#question h2 { font-size: 1.4rem; margin-top: 2.5rem; }
h3 { font-size: 1.2rem; margin: 2rem 0 0.75rem; }
p, li { max-width: 68ch; }

.answer {
  font: 600 clamp(1.4rem, 3.5vw, 1.9rem)/1.25 var(--head);
  padding-left: 1rem;
  border-left: 6px solid var(--orange);
}
.aside, .source { color: var(--muted); font-size: 0.95rem; }
.source { font-size: 0.85rem; margin-top: 1.5rem; overflow-wrap: anywhere; }
code { font-size: 0.9em; overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.notice { border: 2px solid var(--orange); padding: 0.75rem 1rem; }
ul.plain { columns: 2 18rem; }
footer { color: var(--muted); font-size: 0.9rem; padding-bottom: 3rem; }

/* controls */
select, button {
  font: 1rem var(--head);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--muted);
  border-radius: 4px;
  padding: 0.4rem 0.75rem;
  min-height: 2.5rem;
  max-width: 100%;
}
button { cursor: pointer; }
label { font-family: var(--head); }

.switch {
  border: 0;
  margin: 1.25rem 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-family: var(--head);
}
.switch legend { padding: 0; margin-bottom: 0.35rem; color: var(--muted); }
.switch label { position: relative; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.switch span {
  display: flex;
  align-items: center;
  min-height: 2.5rem;
  padding: 0.3rem 0.85rem;
  border: 1px solid var(--muted);
  border-radius: 4px;
}
.switch input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.switch input:focus-visible + span { outline: 3px solid var(--blue); outline-offset: 2px; }

/* tables that carry the charts */
.chart { overflow-x: auto; margin: 1rem 0; }
table {
  width: 100%;
  border-collapse: collapse;
  font: 0.95rem/1.35 var(--head);
  font-variant-numeric: tabular-nums;
}
caption { text-align: left; color: var(--muted); padding-bottom: 0.5rem; }
th, td { padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--rule); vertical-align: middle; }
th { text-align: left; font-weight: 600; }
tbody th { font-weight: 400; }
thead th { color: var(--muted); font-weight: 400; vertical-align: bottom; }
.num { text-align: right; white-space: nowrap; }
thead th.num { white-space: normal; }
.plot { width: 38%; min-width: 9rem; }
tr.primary th, tr.primary td { font-weight: 700; }

/* The side margin leaves room for a dot at either end of the scale. */
.track { position: relative; height: 1.4rem; margin: 0 6px; background: var(--track); }
.bar { position: absolute; top: 0.25rem; bottom: 0.25rem; border-radius: 0 4px 4px 0; background: var(--blue); }
.bar.leftward { border-radius: 4px 0 0 4px; }
.bar.orange { background: var(--orange); }
.whisker { position: absolute; height: 2px; background: var(--ink); top: calc(50% - 1px); }
.reference { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--muted); }
.dot {
  position: absolute;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  border: 1px solid var(--surface);
}
.dot.validation { background: var(--blue); border-radius: 50%; top: 2px; }
.dot.holdout { background: var(--orange); bottom: 2px; }
.dot.level90 { background: var(--orange); bottom: 2px; }
.dot.level80 { background: var(--blue); border-radius: 50%; top: 2px; }
.span { position: absolute; height: 2px; margin: 0; }
.span.validation { background: var(--blue); top: 6px; }
.span.holdout { background: var(--orange); bottom: 6px; }
.scale { display: flex; justify-content: space-between; margin: 0 6px; font-size: 0.8rem; }

.legend { display: flex; flex-wrap: wrap; max-width: none; gap: 0.25rem 1.25rem; font: 0.9rem var(--head); margin: 0 0 0.5rem; }
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.key { width: 10px; height: 10px; display: inline-block; background: var(--orange); }
.key.blue { background: var(--blue); }
.key.round { border-radius: 50%; }
.key.line { width: 2px; height: 14px; background: var(--muted); }

/* the factor ruler */
.ruler { margin: 1.5rem 0; padding: 1.25rem 0; border-top: 4px solid var(--ink); border-bottom: 1px solid var(--rule); }
.ruler label { display: block; font-size: 1.15rem; }
.ruler output { font-weight: 700; font-size: 1.7rem; }
.ruler input { width: 100%; margin: 0.75rem 0 1.25rem; min-height: 2rem; accent-color: var(--blue); }
#ruler-scale { position: relative; height: 6.5rem; margin: 0 1.25rem; font-family: var(--head); }
#ruler-scale .axis { position: absolute; left: 0; right: 0; top: 4rem; height: 1px; background: var(--muted); }
#ruler-scale .tick { position: absolute; top: 4rem; height: 0.5rem; width: 1px; background: var(--muted); }
#ruler-scale .tick span {
  position: absolute;
  top: 0.6rem;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--muted);
}
#ruler-scale .range90 { position: absolute; top: 2.4rem; height: 4px; background: var(--orange); }
#ruler-scale .range80 { position: absolute; top: 0.75rem; height: 1.25rem; background: var(--blue); }
#ruler-scale .centre { position: absolute; top: 0.25rem; height: 3.75rem; width: 3px; margin-left: -1.5px; background: var(--ink); }
#ruler-text { margin-bottom: 0; }

summary { cursor: pointer; font-family: var(--head); padding: 0.4rem 0; }

@media (max-width: 60rem) {
  .page { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 0 1rem; }
  .side { position: static; max-height: none; padding-top: 1rem; border-bottom: 1px solid var(--rule); }
  nav ul { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; padding-bottom: 0.75rem; }
  nav a { border-left: 0; padding: 0.35rem 0; text-decoration: underline; }
}

/* Narrow screens: each chart row stacks, so nothing scrolls sideways. */
@media (max-width: 40rem) {
  table.stack, table.stack caption, table.stack tbody, table.stack tr,
  table.stack tbody th, table.stack td { display: block; width: auto; }
  table.stack thead { position: absolute; left: -999rem; }
  table.stack tr { padding: 0.6rem 0; border-bottom: 1px solid var(--rule); }
  table.stack th, table.stack td { border: 0; padding: 0.15rem 0; }
  table.stack td.num { display: flex; justify-content: space-between; gap: 1rem; text-align: left; }
  table.stack td[data-label]::before { content: attr(data-label); color: var(--muted); font-weight: 400; white-space: normal; }
  table.stack .plot { width: auto; }
}

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

@media print {
  .side, .switch, .skip { display: none; }
  .page { display: block; }
  * { print-color-adjust: exact; }
}
