/* Data Visualization & Storytelling — visual companion
   Tokens first. Every colour in the page comes from this block. */

:root {
  color-scheme: light;

  /* ground and ink: cool plotting-paper neutrals, blue-biased */
  --page:        #eef0f3;
  --surface:     #ffffff;
  --surface-2:   #f6f7f9;
  --ink:         #10141a;
  --ink-2:       #4a545f;
  --muted:       #7d8894;
  --hairline:    #dbe0e6;
  --hairline-2:  #c7cfd8;

  /* the one emphasis hue. Week 3's rule, applied to the notes themselves */
  --focus:       #eb6834;
  --focus-text:  #c2451a;
  --focus-wash:  #fdeee7;

  /* chart series: the validated categorical order */
  --s1: #2a78d6;  --s2: #eb6834;  --s3: #1baf7a;  --s4: #eda100;
  --s5: #e87ba4;  --s6: #008300;  --s7: #4a3aa7;  --s8: #e34948;

  /* chart chrome */
  --grid:    #e4e8ed;
  --axis:    #b9c2cc;
  --tick:    #7d8894;
  --dim:     #ccd3da;      /* the greyed-out set */

  /* status */
  --good: #0ca30c;  --warn: #fab219;  --bad: #d03b3b;

  --radius: 3px;
  --rail: 15rem;
  --measure: 39rem;

  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "IBM Plex Serif", ui-serif, Georgia, "Times New Roman", serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:       #0c0f13;
    --surface:    #151a20;
    --surface-2:  #1b2128;
    --ink:        #eef2f6;
    --ink-2:      #a9b4c0;
    --muted:      #7d8894;
    --hairline:   #242c35;
    --hairline-2: #333d48;
    --focus:      #f2814f;
    --focus-text: #f2814f;
    --focus-wash: #2a1a12;
    --s1: #3987e5;  --s2: #d95926;  --s3: #199e70;  --s4: #c98500;
    --s5: #d55181;  --s6: #008300;  --s7: #9085e9;  --s8: #e66767;
    --grid:  #222a33;
    --axis:  #3b4650;
    --tick:  #8b96a2;
    --dim:   #2e3740;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:       #0c0f13;
  --surface:    #151a20;
  --surface-2:  #1b2128;
  --ink:        #eef2f6;
  --ink-2:      #a9b4c0;
  --muted:      #7d8894;
  --hairline:   #242c35;
  --hairline-2: #333d48;
  --focus:      #f2814f;
  --focus-text: #f2814f;
  --focus-wash: #2a1a12;
  --s1: #3987e5;  --s2: #d95926;  --s3: #199e70;  --s4: #c98500;
  --s5: #d55181;  --s6: #008300;  --s7: #9085e9;  --s8: #e66767;
  --grid:  #222a33;
  --axis:  #3b4650;
  --tick:  #8b96a2;
  --dim:   #2e3740;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.62;
  font-feature-settings: "kern";
}

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

.masthead {
  border-bottom: 1px solid var(--hairline);
  background: var(--surface);
}
.masthead-in {
  max-width: 76rem;
  margin: 0 auto;
  padding: 1.6rem 1.6rem 1.9rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0 1.4rem;
  align-items: start;
}
.wknum {
  font-family: var(--mono);
  font-size: 3.4rem;
  line-height: 0.86;
  font-weight: 600;
  letter-spacing: -0.04em;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.wknum span { color: var(--hairline-2); }
.mast-text h1 {
  font-family: var(--serif);
  font-size: 1.72rem;
  font-weight: 600;
  line-height: 1.15;
  margin: 0.1rem 0 0.3rem;
  text-wrap: balance;
  letter-spacing: -0.01em;
}
.eyebrow {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}
.mast-text p.lede {
  margin: 0;
  color: var(--ink-2);
  max-width: 46rem;
}

.mast-tools { display: flex; gap: 0.5rem; align-items: center; }

/* ---------- layout ---------- */

.wrap {
  max-width: 76rem;
  margin: 0 auto;
  padding: 2rem 1.6rem 6rem;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: 0 3rem;
  align-items: start;
}

.rail { position: sticky; top: 1.4rem; }
.rail nav { border-left: 1px solid var(--hairline); }
.rail a {
  display: block;
  padding: 0.28rem 0 0.28rem 0.85rem;
  margin-left: -1px;
  border-left: 2px solid transparent;
  font-size: 0.84rem;
  line-height: 1.35;
  color: var(--ink-2);
  text-decoration: none;
}
.rail a:hover { color: var(--ink); border-left-color: var(--hairline-2); }
.rail a.on { color: var(--focus-text); border-left-color: var(--focus); }
.rail .rail-h {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 0 0.5rem 0.85rem;
}

.col { min-width: 0; }
.col > * { max-width: var(--measure); }
.col > .plate, .col > .wide, .col > .table-wrap, .col > .grid2, .col > .grid3 { max-width: none; }

/* ---------- text ---------- */

h2 {
  font-family: var(--serif);
  font-size: 1.34rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.005em;
  margin: 3.2rem 0 0.9rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--hairline);
  text-wrap: balance;
}
.col > h2:first-child { margin-top: 0.4rem; border-top: 0; padding-top: 0; }
h2 .num {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  margin-right: 0.55rem;
  vertical-align: 0.14em;
}
h3 {
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.005em;
  margin: 2rem 0 0.55rem;
}
p { margin: 0 0 0.95rem; }
ol, ul { margin: 0 0 1.1rem; padding-left: 1.35rem; }
li { margin: 0 0 0.42rem; }
li::marker { color: var(--muted); font-variant-numeric: tabular-nums; }
strong { font-weight: 600; }
a { color: var(--focus-text); text-decoration-thickness: 1px; text-underline-offset: 2px; }

code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 0.05em 0.32em;
}
pre {
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.55;
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  overflow-x: auto;
  margin: 0 0 1.1rem;
}
pre code { background: none; border: 0; padding: 0; font-size: 1em; }
pre .c { color: var(--muted); }
pre .k { color: var(--s1); }
pre .s { color: var(--s3); }

/* ---------- the plate: a numbered figure block ---------- */

.plate {
  margin: 1.9rem 0 2.1rem;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface);
}
.plate-head {
  display: flex;
  gap: 0.8rem;
  align-items: baseline;
  padding: 0.75rem 1.05rem;
  border-bottom: 1px solid var(--hairline);
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
}
.plate-no {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--focus-text);
  white-space: nowrap;
}
.plate-title { font-size: 0.92rem; font-weight: 600; line-height: 1.3; }
.plate-body { padding: 1.05rem; }
.plate-cap {
  padding: 0 1.05rem 1rem;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--ink-2);
  max-width: 46rem;
}
.plate-cap b { color: var(--ink); font-weight: 600; }

/* ---------- controls ---------- */

.ctlbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
  margin: 0 0 0.95rem;
}
.ctlbar:last-child { margin: 0.95rem 0 0; }
.ctl-label {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.seg { display: inline-flex; border: 1px solid var(--hairline-2); border-radius: var(--radius); overflow: hidden; }
.seg button {
  font-family: var(--sans);
  font-size: 0.82rem;
  line-height: 1;
  padding: 0.45rem 0.7rem;
  border: 0;
  border-right: 1px solid var(--hairline-2);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--surface-2); color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--focus); color: #fff; }
:root[data-theme="dark"] .seg button[aria-pressed="true"],
:root:not([data-theme="light"]) .seg button[aria-pressed="true"] { color: #14100d; }

button.btn {
  font-family: var(--sans);
  font-size: 0.82rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--hairline-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
button.btn:hover { background: var(--surface-2); }
button.btn[aria-pressed="true"] { background: var(--focus); border-color: var(--focus); color: #fff; }

.swtch { display: inline-flex; align-items: center; gap: 0.42rem; font-size: 0.84rem; color: var(--ink-2); cursor: pointer; }
.swtch input { accent-color: var(--focus); width: 0.95rem; height: 0.95rem; }

input[type="range"] { accent-color: var(--focus); width: 11rem; vertical-align: middle; }

:where(button, a, input, select, [tabindex]):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.readout {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 0.2rem 0.5rem;
}

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; margin: 0 0 1.4rem; }
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}
th, td {
  text-align: left;
  padding: 0.46rem 0.75rem 0.46rem 0;
  border-bottom: 1px solid var(--hairline);
  vertical-align: top;
}
th {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  border-bottom-color: var(--hairline-2);
  white-space: nowrap;
}
tbody tr:hover { background: var(--surface-2); }
td.num { font-family: var(--mono); }

/* ---------- small pieces ---------- */

.note {
  border-left: 2px solid var(--focus);
  background: var(--focus-wash);
  padding: 0.8rem 1rem;
  margin: 0 0 1.2rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.9rem;
}
.note p:last-child, .note ol:last-child, .note ul:last-child { margin-bottom: 0; }
.note .tag {
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--focus-text);
  display: block;
  margin-bottom: 0.25rem;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 1.1rem; }
.chip {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.2rem 0.5rem;
  border: 1px solid var(--hairline-2);
  border-radius: 100px;
  color: var(--ink-2);
  background: var(--surface);
}

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: 1.1rem; margin: 0 0 1.3rem; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1.1rem; margin: 0 0 1.3rem; }

.card {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.85rem 1rem;
  font-size: 0.88rem;
}
.card h4 {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.card p:last-child { margin-bottom: 0; }
.card .k {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  display: block;
}

.checklist { counter-reset: ck; list-style: none; padding: 0; }
.checklist li {
  counter-increment: ck;
  position: relative;
  padding-left: 2.1rem;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}
.checklist li::before {
  content: counter(ck, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0.1rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

/* ---------- charts ---------- */

.figstage { width: 100%; }
.figstage svg { display: block; width: 100%; height: auto; overflow: visible; }
.figrow { display: flex; flex-wrap: wrap; gap: 1.1rem; }
.figrow > * { flex: 1 1 15rem; min-width: 0; }

svg text { font-family: var(--sans); fill: var(--ink-2); }
svg .tick { font-family: var(--mono); font-size: 10px; fill: var(--tick); }
svg .axline { stroke: var(--axis); stroke-width: 1; }
svg .gridline { stroke: var(--grid); stroke-width: 1; }
svg .lbl { font-size: 11px; fill: var(--ink-2); }
svg .lbl-strong { font-size: 11px; font-weight: 600; fill: var(--ink); }
svg .axtitle { font-size: 10.5px; fill: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; font-family: var(--mono); }
svg .val { font-family: var(--mono); font-size: 10px; fill: var(--ink-2); }

.tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--hairline-2);
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(10,15,20,0.13);
  padding: 0.4rem 0.6rem;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--ink);
  max-width: 15rem;
}
.tip b { font-family: var(--mono); font-weight: 600; }
.tip[hidden] { display: none; }

.legend { display: flex; flex-wrap: wrap; gap: 0.35rem 1rem; margin: 0.7rem 0 0; font-size: 0.8rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend i { width: 0.7rem; height: 0.7rem; border-radius: 2px; display: inline-block; }

/* ---------- index page ---------- */

.hero {
  max-width: 76rem;
  margin: 0 auto;
  padding: 3rem 1.6rem 2rem;
}
.hero h1 {
  font-family: var(--serif);
  font-size: clamp(2rem, 5vw, 3.1rem);
  font-weight: 600;
  line-height: 1.06;
  letter-spacing: -0.02em;
  margin: 0.5rem 0 0.9rem;
  max-width: 22ch;
  text-wrap: balance;
}
.hero p { max-width: 42rem; color: var(--ink-2); font-size: 1.02rem; }

.weeks { display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0.9rem; }
a.wkcard {
  display: block;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.9rem 1rem 1rem;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.12s ease, transform 0.12s ease;
}
a.wkcard:hover { border-color: var(--focus); transform: translateY(-1px); }
a.wkcard .wk {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  display: block;
  margin-bottom: 0.3rem;
}
a.wkcard h3 { margin: 0 0 0.35rem; font-size: 0.98rem; font-weight: 600; line-height: 1.25; }
a.wkcard p { margin: 0; font-size: 0.83rem; color: var(--ink-2); line-height: 1.45; }
a.wkcard .figs {
  margin-top: 0.6rem;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--focus-text);
}

/* ---------- footer nav ---------- */

.pagenav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--hairline);
  font-size: 0.88rem;
}
.pagenav a { text-decoration: none; color: var(--ink-2); }
.pagenav a:hover { color: var(--focus-text); }
.pagenav .k { font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.11em; text-transform: uppercase; color: var(--muted); display: block; }

@media (max-width: 62rem) {
  .wrap { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; margin-bottom: 2rem; }
  .rail nav { display: flex; flex-wrap: wrap; gap: 0 0.4rem; border-left: 0; }
  .rail a { border-left: 0; padding: 0.2rem 0.5rem; border: 1px solid var(--hairline); border-radius: 100px; font-size: 0.78rem; margin: 0 0 0.35rem; }
  .rail a.on { border-color: var(--focus); }
  .masthead-in { grid-template-columns: auto 1fr; }
  .mast-tools { grid-column: 1 / -1; margin-top: 0.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- sticky top bar: always a way back ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}
.topbar-in {
  max-width: 76rem;
  margin: 0 auto;
  padding: 0.5rem 1.6rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}
.topbar a.crumb { color: var(--ink-2); text-decoration: none; white-space: nowrap; }
.topbar a.crumb:hover { color: var(--focus-text); }
.topbar .sep { color: var(--hairline-2); }
.topbar .cur {
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .spacer { flex: 1 1 auto; min-width: 0.5rem; }
.topbar .home { font-weight: 600; color: var(--ink); }
@media (max-width: 34rem) { .topbar .hide-sm { display: none; } }

/* the rail and headings must clear the sticky bar */
.rail { top: 4.2rem; }
h2[id] { scroll-margin-top: 4.5rem; }
