:root {
  --paper: #faf7f0;
  --card: #fffdf8;
  --ink: #1b1a17;
  --ink-soft: #3d3a34;
  --muted: #6e6960;
  --faint: #938c80;
  --rule: #e0d9ca;
  --rule-soft: #ebe5d8;
  --accent: #1d4f46;
  --series-1: #b04a2a;
  --series-2: #1f5c7a;
  --series-3: #6a7130;
  --prose: 46rem;
  --wide: 62rem;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 5rem; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- masthead ---------- */

.masthead {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid var(--rule);
  background: rgba(250, 247, 240, .92);
  backdrop-filter: blur(8px);
}
.masthead-inner {
  display: flex;
  align-items: center;
  gap: .55rem;
  width: min(100%, var(--wide));
  margin: 0 auto;
  padding: .85rem 2rem;
  font-size: .8rem;
}
.wordmark { font-weight: 650; letter-spacing: -.01em; }
.masthead-sep { color: var(--faint); }
.masthead-section { color: var(--muted); }
.masthead a { text-decoration: none; }
.masthead a:hover { text-decoration: underline; text-underline-offset: 2px; }

/* ---------- page frame ---------- */

.page {
  display: grid;
  grid-template-columns: 11rem minmax(0, 1fr);
  gap: 3rem;
  width: min(100%, var(--wide));
  margin: 0 auto;
  padding: 3.5rem 2rem 6rem;
}

.contents {
  position: sticky;
  align-self: start;
  top: 5.5rem;
  display: flex;
  flex-direction: column;
  gap: .1rem;
  font-size: .8rem;
}
.contents-label {
  margin: 0 0 .7rem;
  color: var(--faint);
  font-size: .625rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.contents a {
  padding: .3rem 0 .3rem .7rem;
  border-left: 2px solid var(--rule-soft);
  color: var(--muted);
  text-decoration: none;
  transition: color .15s ease, border-color .15s ease;
}
.contents a:hover { color: var(--ink); }
.contents a.is-active {
  border-left-color: var(--series-1);
  color: var(--ink);
  font-weight: 600;
}

main { min-width: 0; }

/* ---------- typography ---------- */

.hero { margin-bottom: 3.5rem; }
.hero h1 {
  max-width: 22ch;
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2.3rem, 5.2vw, 3.5rem);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -.02em;
}
.standfirst {
  max-width: var(--prose);
  margin: 1.4rem 0 0;
  color: var(--ink-soft);
  font-size: 1.12rem;
  line-height: 1.6;
}
.byline {
  margin: 1.6rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  color: var(--faint);
  font-size: .75rem;
  letter-spacing: .04em;
  text-transform: uppercase;
}

section { margin-bottom: 4rem; scroll-margin-top: 5rem; }
section h2 {
  margin: 0 0 1.3rem;
  font-family: var(--serif);
  font-size: 1.85rem;
  font-weight: 400;
  letter-spacing: -.015em;
}
section p {
  max-width: var(--prose);
  margin: 0 0 1.05rem;
  color: var(--ink-soft);
}

/* ---------- chart ---------- */

.chart-figure {
  margin: 1.8rem 0 2.2rem;
  padding: 1.5rem 1.4rem 1.1rem;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--card);
}
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
figcaption {
  max-width: var(--prose);
  margin-top: 1.1rem;
  padding-top: .9rem;
  border-top: 1px solid var(--rule-soft);
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.55;
}
.curve-hit { cursor: crosshair; }

/* ---------- results table ---------- */

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.results-table th,
.results-table td {
  padding: .7rem .8rem;
  border-bottom: 1px solid var(--rule-soft);
  text-align: left;
}
.results-table thead th {
  border-bottom: 1px solid var(--rule);
  color: var(--faint);
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.results-table .num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.results-table thead .num { font-family: var(--sans); }
.results-table tbody tr:last-child td { border-bottom: 1px solid var(--rule); }
.results-table .task-name { display: flex; align-items: center; gap: .6rem; font-weight: 600; }
.swatch { width: .7rem; height: .18rem; flex: 0 0 auto; border-radius: 1px; }

/* ---------- tasks ---------- */

.download-all { display: flex; align-items: center; gap: .8rem; margin: 1.6rem 0 2rem; }
.button {
  display: inline-block;
  padding: .5rem .95rem;
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: var(--accent);
  color: #f7f5ef;
  font-size: .82rem;
  font-weight: 600;
  text-decoration: none;
}
.button:hover { background: #17403a; }
.button-secondary {
  border-color: var(--rule);
  background: transparent;
  color: var(--ink);
  font-weight: 500;
}
.button-secondary:hover { border-color: var(--faint); background: #f3efe5; }
.button-note { color: var(--faint); font-size: .78rem; }

.task-list { display: flex; flex-direction: column; gap: 1.1rem; }
.task {
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--card);
}
.task-head { padding: 1.3rem 1.4rem; }
.task-title {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  margin: 0 0 .5rem;
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 400;
}
.task-rule { width: .8rem; height: .2rem; flex: 0 0 auto; border-radius: 1px; align-self: center; }
.task-desc { max-width: var(--prose); margin: 0 0 .9rem; color: var(--ink-soft); font-size: .95rem; }
.task-id { margin: 0 0 .9rem; color: var(--faint); font-family: var(--mono); font-size: .75rem; }

.badges { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.badge {
  padding: .2rem .5rem;
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--muted);
  font-size: .7rem;
  letter-spacing: .02em;
}
.badge strong { color: var(--ink-soft); font-weight: 600; }

.task-actions { display: flex; flex-wrap: wrap; gap: .6rem; }

.task-detail { border-top: 1px solid var(--rule-soft); }
.task-detail[hidden] { display: none; }
.detail-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--rule-soft); }
.detail-tab {
  padding: .65rem 1.1rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
}
.detail-tab:hover { color: var(--ink); }
.detail-tab.is-active { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }
.detail-body { padding: 1.3rem 1.4rem; }

.markdown { max-width: var(--prose); font-size: .92rem; }
.markdown h1, .markdown h2, .markdown h3 {
  margin: 1.5rem 0 .6rem;
  font-family: var(--serif);
  font-weight: 400;
  line-height: 1.25;
}
.markdown h1 { font-size: 1.35rem; }
.markdown h2 { font-size: 1.15rem; }
.markdown h3 { font-size: 1rem; font-family: var(--sans); font-weight: 650; }
.markdown h1:first-child, .markdown h2:first-child { margin-top: 0; }
.markdown p, .markdown li { color: var(--ink-soft); }
.markdown p { margin: 0 0 .85rem; }
.markdown ul, .markdown ol { margin: 0 0 .85rem; padding-left: 1.3rem; }
.markdown li { margin-bottom: .3rem; }
.markdown code {
  padding: .1rem .3rem;
  border-radius: 2px;
  background: #f0ebdf;
  font-family: var(--mono);
  font-size: .85em;
}
.markdown pre {
  margin: 0 0 .95rem;
  padding: .85rem 1rem;
  overflow-x: auto;
  border: 1px solid var(--rule-soft);
  border-radius: 3px;
  background: #f6f2e8;
}
.markdown pre code { padding: 0; background: none; font-size: .8rem; line-height: 1.55; }

.file-tree { margin: 0; font-family: var(--mono); font-size: .78rem; }
.file-group { margin-bottom: 1rem; }
.file-group:last-child { margin-bottom: 0; }
.file-group-name { margin: 0 0 .35rem; color: var(--faint); font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; font-family: var(--sans); font-weight: 700; }
.file-row {
  display: block;
  width: 100%;
  padding: .28rem .4rem;
  border: 0;
  border-radius: 2px;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.file-row:hover { background: #f2eee3; color: var(--ink); }

/* ---------- file viewer ---------- */

.file-viewer {
  position: fixed;
  z-index: 60;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background: rgba(27, 26, 23, .45);
}
.file-viewer[hidden] { display: none; }
.file-viewer-panel {
  display: flex;
  flex-direction: column;
  width: min(100%, 56rem);
  max-height: 100%;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--card);
  box-shadow: 0 18px 48px rgba(27, 26, 23, .22);
}
.file-viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--rule-soft);
}
.file-viewer-head code { font-family: var(--mono); font-size: .78rem; overflow-wrap: anywhere; }
.file-viewer-head button {
  width: 1.9rem; height: 1.9rem;
  flex: 0 0 auto;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.file-viewer-head button:hover { border-color: var(--faint); color: var(--ink); }
#fileViewerBody {
  margin: 0;
  padding: 1rem;
  overflow: auto;
  font-family: var(--mono);
  font-size: .78rem;
  line-height: 1.6;
  white-space: pre;
}

footer {
  margin-top: 5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule);
  color: var(--faint);
  font-size: .78rem;
}
footer p { margin: 0; }

/* ---------- responsive ---------- */

@media (max-width: 62rem) {
  .page { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 2.5rem 1.5rem 4rem; }
  .contents {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    gap: .4rem;
    margin-bottom: 2.5rem;
    padding-bottom: 1.2rem;
    border-bottom: 1px solid var(--rule);
  }
  .contents-label { width: 100%; margin-bottom: .4rem; }
  .contents a { padding: .25rem .6rem; border-left: 0; border: 1px solid var(--rule-soft); border-radius: 2px; }
  .contents a.is-active { border-color: var(--faint); }
  .masthead-inner { padding: .85rem 1.5rem; }
}

@media (max-width: 34rem) {
  body { font-size: 15px; }
  .page { padding: 2rem 1rem 3rem; }
  .masthead-inner { padding: .75rem 1rem; }
  .chart-figure { padding: 1rem .6rem .8rem; }
  .chart { overflow-x: auto; }
  .chart svg { min-width: 34rem; }
  .results-table { display: block; overflow-x: auto; }
  .task-head, .detail-body { padding: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; }
}
