/* Causal Playground: shared styles. Light theme only. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: #f0efec;
  --link: #1c5cab;

  /* Categorical series colors, fixed order (validated palette). */
  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { font-size: 17px; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.55;
}

a { color: var(--link); }
a:hover { text-decoration-thickness: 2px; }

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

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--surface); padding: 8px 12px;
}
.skip-link:focus { left: 8px; }

/* Header and navigation */

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.site-header .inner {
  max-width: 1100px; margin: 0 auto; padding: 10px 20px;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 22px;
}
.site-title {
  font-weight: 700; font-size: 1.1rem; color: var(--ink); text-decoration: none;
}
/* The home page header shows the title large, with the line naming the courses and the author under it. */
.home-head { width: 100%; }
.home-title { font-size: 1.85rem; line-height: 1.25; margin: 14px 0 4px; }
/* One line per part. */
.site-nav { display: flex; flex-direction: column; gap: 4px; width: 100%; font-size: 0.92rem; }
.nav-part { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; }
.nav-part-name { font-size: 0.78rem; font-weight: 600; color: var(--ink-2); }
@media (max-width: 560px) {
  /* On phones a long line scrolls sideways. */
  .nav-part { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; scrollbar-width: none; padding-bottom: 2px; }
}
.site-nav a { color: var(--ink-2); text-decoration: none; padding: 2px 0; }
.site-nav a:hover { color: var(--ink); text-decoration: underline; }
.site-nav a[aria-current="page"] { color: var(--ink); font-weight: 600; border-bottom: 2px solid var(--series-1); }

/* Page body */

main { max-width: 1100px; margin: 0 auto; padding: 8px 20px 40px; }

.prose { max-width: 72ch; }

h1 { font-size: 1.85rem; line-height: 1.25; margin: 28px 0 10px; }
h2 { font-size: 1.35rem; margin: 36px 0 10px; }
h3 { font-size: 1.1rem; margin: 24px 0 8px; }

.lede { font-size: 1.08rem; color: var(--ink-2); max-width: 72ch; }
main > .lede:first-child { margin-top: 22px; }

p, li { max-width: 72ch; }

code, .math { font-family: var(--mono); font-size: 0.92em; }
.math { white-space: nowrap; }

details.symbols {
  max-width: 72ch; margin: 14px 0; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
details.symbols summary { cursor: pointer; font-weight: 600; }
details.symbols p { margin: 10px 0 0; }

/* Simulation block */

.sim {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px 20px;
  margin: 18px 0 8px;
}
.sim > h3:first-child { margin-top: 0; }

.sim-grid {
  display: grid;
  grid-template-columns: minmax(230px, 290px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}
@media (max-width: 820px) {
  .sim-grid { grid-template-columns: minmax(0, 1fr); }
}

.controls { display: flex; flex-direction: column; gap: 14px; }
.control label, .control .label {
  display: flex; justify-content: space-between; gap: 10px;
  font-size: 0.9rem; font-weight: 600; line-height: 1.3;
}
.control output {
  font-family: var(--mono); font-weight: 500; color: var(--ink-2);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.control input[type="range"] { width: 100%; margin: 6px 0 0; accent-color: var(--series-1); }
.control .hint { font-size: 0.8rem; color: var(--ink-2); margin: 2px 0 0; }
.control.check label { justify-content: flex-start; align-items: center; font-weight: 600; }
.control.check input { width: 18px; height: 18px; margin: 0 8px 0 0; accent-color: var(--series-1); }
.control select { font: inherit; font-size: 0.9rem; padding: 4px 6px; margin-top: 6px; width: 100%; }
.control fieldset { border: 0; margin: 0; padding: 0; }
.control legend { font-size: 0.9rem; font-weight: 600; padding: 0; }
.control .radio { display: flex; align-items: center; gap: 6px; font-weight: 400; font-size: 0.9rem; margin-top: 4px; }

.button-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
button {
  font: inherit; font-size: 0.9rem; font-weight: 600;
  padding: 7px 14px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--axis); background: var(--page); color: var(--ink);
}
button:hover { background: var(--wash); }
.sample-label { font-size: 0.85rem; color: var(--ink-2); }

/* Charts */

.chart { margin: 0; min-width: 0; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart figcaption { font-size: 0.85rem; color: var(--ink-2); margin-top: 6px; max-width: none; }
.chart + .chart { margin-top: 18px; }
.chart-title { font-size: 0.95rem; font-weight: 600; margin: 0 0 4px; }

.legend {
  list-style: none; margin: 0 0 6px; padding: 0;
  display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 0.85rem; color: var(--ink-2);
}
.legend li { display: flex; align-items: center; gap: 6px; max-width: none; }
.legend svg { width: 26px; height: 12px; flex: none; }

/* SVG marks. Each series class sets --c. */
.s1 { --c: var(--series-1); }
.s2 { --c: var(--series-2); }
.s3 { --c: var(--series-3); }
.s4 { --c: var(--series-4); }
.s5 { --c: var(--series-5); }
.s6 { --c: var(--series-6); }
.s7 { --c: var(--series-7); }
.s8 { --c: var(--series-8); }
.sg { --c: var(--ink-2); }
.sm { --c: var(--muted); }

svg text { font-family: var(--font); fill: var(--ink-2); font-size: 12px; }
svg .axis-label { fill: var(--ink-2); font-size: 12.5px; }
svg .tick-label { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
svg .note { fill: var(--ink-2); font-size: 12px; }
svg .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
svg .baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
svg .ln { fill: none; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
svg .ln.thin { stroke-width: 1.5; }
svg .dash { stroke-dasharray: 7 5; }
svg .dotted { stroke-dasharray: 1.5 4.5; stroke-width: 2.5; }
svg .dot { fill: var(--c); stroke: var(--surface); stroke-width: 2; }
svg .dot.hollow { fill: var(--surface); stroke: var(--c); stroke-width: 2; }
svg .dot.small { stroke-width: 1; }
svg .bar { fill: var(--c); }
svg .area { fill: var(--c); opacity: 0.12; stroke: none; }
svg .ref { stroke: var(--ink-2); stroke-width: 1.5; }
svg .ref.light { stroke: var(--axis); }
svg .whisker { stroke: var(--c); stroke-width: 2; stroke-linecap: round; }
svg .band { fill: var(--wash); }
svg .hit { fill: transparent; stroke: none; }

/* Results */

.results-wrap { margin-top: 16px; overflow-x: auto; }
table.results {
  border-collapse: collapse; font-size: 0.9rem; min-width: 320px;
  font-variant-numeric: tabular-nums;
}
table.results caption { text-align: left; font-weight: 600; padding-bottom: 6px; }
table.results th, table.results td {
  padding: 5px 12px; border-bottom: 1px solid var(--grid); text-align: right;
}
table.results th:first-child, table.results td:first-child { text-align: left; }
table.results thead th { color: var(--ink-2); font-weight: 600; border-bottom: 1px solid var(--axis); }
table.results tr.key td { font-weight: 700; }
.swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--c); margin-right: 6px; vertical-align: baseline;
}

.readout {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px; margin: 14px 0 0;
}
.readout div {
  background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px;
}
.readout dt { font-size: 0.8rem; color: var(--ink-2); }
.readout dd { margin: 2px 0 0; font-size: 1.25rem; font-weight: 600; }

/* What to notice box */

.notice {
  background: var(--wash);
  border-left: 4px solid var(--series-1);
  border-radius: 0 8px 8px 0;
  padding: 4px 22px 10px;
  margin: 26px 0;
  max-width: 80ch;
}
.notice h2 { font-size: 1.15rem; margin: 14px 0 6px; }
.notice li { margin: 6px 0; }

/* References */

.refs ol { padding-left: 1.4em; }
.refs li { margin: 8px 0; }

/* Module list on the home page */

.part-title { font-size: 1.05rem; margin: 24px 0 8px; }
.module-list { list-style: none; padding: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.module-list li {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px;
  max-width: none;
}
.module-list a { font-weight: 700; font-size: 1.02rem; }
.module-list p { margin: 6px 0 0; color: var(--ink-2); font-size: 0.95rem; }

dl.glossary dt { font-weight: 700; margin-top: 12px; }
dl.glossary dd { margin: 2px 0 0; max-width: 72ch; }
dl.glossary dd + dd { margin-top: 6px; }
dl.glossary .src { color: var(--ink-2); font-size: 0.9rem; }

/* Pager and footer */

.pager {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  border-top: 1px solid var(--border); margin-top: 36px; padding-top: 14px; font-size: 0.95rem;
}
.site-footer { border-top: 1px solid var(--border); background: var(--surface); }
.site-footer .inner { max-width: 1100px; margin: 0 auto; padding: 14px 20px; font-size: 0.85rem; color: var(--ink-2); }
.site-footer p { margin: 0; }
.site-footer p + p { margin-top: 4px; }

.noscript {
  background: var(--wash); padding: 10px 14px; border-radius: 8px; max-width: 72ch;
}

.byline { color: var(--ink-2); font-size: 1rem; margin: 0 0 8px; max-width: 72ch; }
.kicker { font-size: 0.85rem; font-weight: 600; color: var(--ink-2); margin: 26px 0 0; letter-spacing: 0.02em; }
.formula {
  font-size: 0.98rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; overflow-x: auto;
}
@media (max-width: 560px) { .formula { font-size: 0.8rem; padding: 6px 8px; } }

.refs li, .refs a, .glossary a { overflow-wrap: anywhere; }
@media (max-width: 560px) {
  html { font-size: 16px; }
  main { padding: 6px 14px 32px; }
  .sim { padding: 14px 12px 16px; }
  table.results th, table.results td { padding: 4px 6px; }
}

/* Shared helpers added after the module build. */
.chart-stack { min-width: 0; }
svg text.halo { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
svg .ln.thick { stroke-width: 3; }
svg .dot.raw { stroke: none; fill-opacity: 0.35; }
.sim h3 { margin: 22px 0 0; font-size: 1rem; }
.readout-note { font-size: 0.85rem; color: var(--ink-2); margin: 4px 0 0; }
@media (min-width: 561px) { table.results td:first-child { min-width: 10em; } }
.math-nowrap { white-space: nowrap; }
