:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f7f9;
  --ink: #1f2933;
  --muted: #5b6673;
  --line: #e2e6eb;
  --grid: #d9dfe5;
  --edge: #74828f;
  --accent: #d9731f;
  --good: #1b7f52;
  --good-bg: #e4f4ec;
  --warn: #9a4a0b;
  --warn-bg: #fcf1e3;
  --mistake: #c0392b;
  --mistake-bg: #fcecea;

  /* Role colours: the same palette as causalblocks/style.py, so the site and
     the notebooks draw a confounder the same way. */
  --role-treatment: #fa953d;
  --role-outcome: #16a085;
  --role-confounder: #3498db;
  --role-mediator: #9b59b6;
  --role-collider: #e74c3c;
  --role-instrument: #f1c40f;
  --role-precision: #e6ebee;
  --role-unrelated: #b3bfc0;
  --on-role: #1f2933;
  --on-role-strong: #ffffff;

  --font-display: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-ui: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 var(--font-body);
}
.wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding-inline: max(16px, 3vw);
}
a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-block: 18px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font: 700 20px/1 var(--font-display);
  letter-spacing: -0.01em;
  text-decoration: none;
}
.brand-mark { display: grid; grid-template-columns: repeat(2, 11px); gap: 3px; }
.brand-mark span { width: 11px; height: 11px; border-radius: 3px; }
.top nav { display: flex; gap: 20px; font-size: 15px; }

.intro { padding-block: 28px 24px; max-width: 760px; }
.intro h1 {
  margin: 0 0 12px;
  font: 800 clamp(30px, 4.4vw, 50px)/1.04 var(--font-display);
  letter-spacing: -0.025em;
  text-wrap: balance;
}
.intro p { margin: 0; font-size: 18px; color: var(--muted); max-width: 62ch; }
.intro p strong { color: var(--ink); font-weight: 600; }

/* ---------- Workspace ---------- */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  padding-bottom: 48px;
}
@media (max-width: 960px) { .workspace { grid-template-columns: minmax(0, 1fr); } }

.board {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.board-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.label {
  font: 600 12px/1 var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: 600 14px/1 var(--font-body);
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
}
.chip:hover { border-color: var(--edge); }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip.mistake { color: var(--mistake); border-color: var(--mistake); background: transparent; }
.chip.mistake:hover { background: var(--mistake-bg); }
.chip.mistake[aria-pressed="true"] { background: var(--mistake); color: #fff; border-color: var(--mistake); }
.presets { align-items: center; }
.mistakes-label { margin-left: 8px; color: var(--mistake); }

.canvas-scroll { overflow-x: auto; }
#canvas {
  display: block;
  width: 100%;
  min-width: 560px;
  height: auto;
  touch-action: pan-x pan-y;
  user-select: none;
  -webkit-user-select: none;
  background-color: var(--surface);
  background-image: radial-gradient(var(--grid) 1.1px, transparent 1.2px);
  background-size: 22px 22px;
}
.node, .port, .tool { touch-action: none; }
.node { cursor: grab; }
.node.dragging { cursor: grabbing; }
.node rect.body { stroke-width: 2; }
.node .name { font: 700 17px var(--font-ui); letter-spacing: -0.01em; }
.node .role { font: 600 11px var(--font-body); letter-spacing: 0.09em; text-transform: uppercase; }
.port { cursor: crosshair; }
.port circle.dot { fill: var(--surface); stroke: var(--edge); stroke-width: 2; }
.port:hover circle.dot, .port.active circle.dot { stroke: var(--accent); fill: var(--accent); }
.port path { stroke: var(--edge); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.port:hover path, .port.active path { stroke: var(--surface); }
.edge { cursor: pointer; }
.edge .line { stroke: var(--edge); stroke-width: 2.5; fill: none; }
.edge.selected .line { stroke: var(--accent); stroke-width: 3; }
.edge .hit { stroke: transparent; stroke-width: 18; fill: none; }
.pending { stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 6 5; fill: none; pointer-events: none; }
.tool { cursor: pointer; }
.tool circle { fill: var(--ink); }
.tool:hover circle { fill: var(--accent); }
.tool path { stroke: var(--surface); stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }

.board-foot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  padding: 16px;
  border-top: 1px solid var(--line);
}
@media (max-width: 640px) { .board-foot { grid-template-columns: minmax(0, 1fr); } }
.tray { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.tray button {
  font: 600 15px/1 var(--font-ui);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px dashed var(--edge);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.tray button:hover { border-style: solid; border-color: var(--accent); }
.tray .empty { color: var(--muted); font-size: 15px; }
.hint { margin: 10px 0 0; font-size: 15px; color: var(--muted); }
.steps { margin: 10px 0 0; padding-left: 20px; font-size: 15px; }
.steps li + li { margin-top: 6px; }
.steps li::marker { font: 700 14px var(--font-ui); color: var(--accent); }

.caption.mistake { color: var(--mistake); background: var(--mistake-bg); }
.caption {
  margin: 0;
  padding: 10px 16px;
  font-size: 15px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.direct {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 4px;
}
.direct .headline { font-size: 18px; margin: 2px 0 0; }
.direct .headline .mono { font-weight: 600; color: var(--muted); }
.toast {
  margin: 0;
  padding: 10px 16px;
  font-size: 15px;
  background: var(--warn-bg);
  color: var(--warn);
  border-bottom: 1px solid var(--line);
}

/* ---------- Panel ---------- */
.panel { display: flex; flex-direction: column; gap: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}
.question {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font: 600 18px/1.3 var(--font-display);
}
.question select {
  font: 600 16px var(--font-ui);
  padding: 7px 30px 7px 10px;
  border-radius: 9px;
  border: 2px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
}
#treatment { border-color: var(--role-treatment); }
#outcome { border-color: var(--role-outcome); }

.estimate-value {
  font: 600 clamp(44px, 5.5vw, 60px)/1 var(--font-display);
  letter-spacing: -0.02em;
  font-variant-numeric: lining-nums tabular-nums;
  font-variant-numeric: tabular-nums;
  margin: 6px 0 8px;
}
.estimate-value.zero { color: var(--muted); }
.headline {
  margin: 0 0 4px;
  font: 700 21px/1.3 var(--font-display);
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.lede { margin: 0; font-size: 15px; color: var(--muted); }
.interval { display: block; width: 100%; height: auto; margin: 14px 0 4px; }
.interval text { font: 600 11px var(--font-body); fill: var(--muted); }
.meta { margin: 0; font-size: 14px; color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; font-weight: 600; }

.card h2 {
  margin: 0 0 10px;
  font: 700 17px/1.25 var(--font-display);
  letter-spacing: -0.01em;
}
.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.notes li { display: grid; grid-template-columns: 12px minmax(0, 1fr); gap: 10px; font-size: 15px; }
.notes .sw { width: 12px; height: 12px; border-radius: 3px; margin-top: 5px; }

.checks { display: grid; gap: 10px; margin: 0; }
.check { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: start; }
.check dt { font-weight: 600; font-size: 15px; }
.check dd { margin: 0; font-size: 14px; color: var(--muted); grid-column: 1; }
.pill {
  grid-column: 2;
  grid-row: 1 / span 2;
  font: 600 12px/1 var(--font-body);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.pill.pass { background: var(--good-bg); color: var(--good); }
.pill.flag { background: var(--warn-bg); color: var(--warn); }
.caution {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--ink);
  font-size: 15px;
}
.caution strong { color: var(--warn); }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.history li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  font-size: 15px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--line);
}
.history li:last-child { border-bottom: 0; padding-bottom: 0; }
.history .current { font-weight: 600; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 14px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ---------- Footer ---------- */
footer { border-top: 1px solid var(--line); padding-block: 24px 40px; font-size: 14px; color: var(--muted); }
footer p { margin: 0 0 8px; max-width: 80ch; }

@media (prefers-reduced-motion: no-preference) {
  .estimate-value { transition: color 0.2s; }
}

/* ---------- Reading pages ---------- */
.top nav a[aria-current="page"] { text-decoration-thickness: 2px; font-weight: 600; }
.prose {
  max-width: 68ch;
  padding-block: 28px 56px;
  font-size: 18px;
  line-height: 1.65;
}
.prose h1 {
  margin: 0 0 16px;
  font: 700 clamp(32px, 4.6vw, 48px)/1.08 var(--font-display);
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.prose h2 {
  margin: 44px 0 12px;
  font: 700 26px/1.2 var(--font-display);
  letter-spacing: -0.01em;
  text-wrap: balance;
}
.prose p { margin: 0 0 16px; }
.prose ul, .prose ol { margin: 0 0 16px; padding-left: 22px; display: grid; gap: 10px; }
.prose a { text-decoration-color: var(--accent); }
.standfirst { font-size: 21px; line-height: 1.55; color: var(--muted); }
.role-tag {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 6px;
  font: 600 0.88em/1.5 var(--font-ui);
  background: var(--c);
  color: var(--on-role-strong);
}
.table-scroll { overflow-x: auto; margin: 0 0 16px; }
.roles { border-collapse: collapse; width: 100%; font-size: 17px; }
.roles th, .roles td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.roles th { font: 600 13px var(--font-ui); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.reading { list-style: none; padding-left: 0 !important; gap: 18px !important; }
.reading li { display: grid; gap: 2px; }
.reading a { font: 700 19px/1.35 var(--font-display); }
.reading .by { font-size: 15px; color: var(--muted); }
.reading .why { font-size: 16px; }
.free {
  display: inline-block;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 999px;
  font: 600 12px/1.6 var(--font-ui);
  background: var(--good-bg);
  color: var(--good);
}
.byline { margin-top: 36px !important; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 16px; }
