/* Day/night palette. System preference (prefers-color-scheme) drives the
 * mode; everything else reads from CSS variables. Canvas interiors stay slate
 * in both modes since the plots are designed against a dark backdrop.
 */
:root {
  --body-bg: #ffffff;
  --text: #2a2a2a;
  --text-strong: #111;
  --text-muted: #6a6a6a;
  --text-subtle: #888;
  --link: #1a5cff;
  --card-bg: #f7f7f7;
  --card-border: #e2e2e2;
  --code-bg: #eef0f6;
  --code-fg: #444;
  --rule: #d8d8d8;
  --canvas-bg: #1a1d24;
}

@media (prefers-color-scheme: dark) {
  :root {
    --body-bg: #0e1116;
    --text: #d7d9df;
    --text-strong: #f0f1f4;
    --text-muted: #9aa0ad;
    --text-subtle: #7a7f8a;
    --link: #8fb1ff;
    --card-bg: #181b22;
    --card-border: #262a32;
    --code-bg: #1a1f2a;
    --code-fg: #b6bac5;
    --rule: #2a2f3a;
    --canvas-bg: #1a1d24;
  }
}

html, body {
  background: var(--body-bg);
  color: var(--text);
  transition: background-color 120ms, color 120ms;
}

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

/* Override Tachyons colour utilities so they follow the theme. */
.article-shell .black-80,
.article-shell .black-70,
.article-shell .black-60,
.article-shell .black,
.article-shell article { color: var(--text); }
.article-shell .gray { color: var(--text-muted) !important; }
.article-shell strong, .article-shell b { color: var(--text-strong); }
.article-shell em, .article-shell i { color: inherit; }

/* Article layout: text in a centred reading column, simulations break out
 * wider so the canvas left edge aligns with the text and the controls drift
 * into the right margin.
 */
.article-shell { max-width: none; }

.article-shell article {
  padding: 1rem 0 4rem;
}

.article-shell article > header {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 1rem;
}

.article-shell article > section {
  max-width: none;
  display: grid;
  grid-template-columns:
    [full-start] minmax(1rem, 1fr)
    [content-start] minmax(0, 720px) [content-end]
    minmax(1rem, 1fr) [full-end];
  row-gap: 0;
}

.article-shell article > section > * { grid-column: content; }

.article-shell article > section > .sim {
  grid-column: content-start / full-end;
  padding-right: 1rem;
  max-width: none;
}

.article-shell .ref {
  font-size: 0.9em;
  color: var(--text-muted);
}

/* Inline code in the article body. */
.article-shell code,
.article-shell p code {
  background: var(--code-bg);
  color: var(--code-fg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.92em;
}

/* Simulation chrome. The canvas keeps its dark interior; everything around
 * it picks up the page theme.
 */
.sim {
  color: var(--text);
  font-family: -apple-system, Inter, system-ui, sans-serif;
  margin: 2rem 0;
  font-size: 13px;
  line-height: 1.45;
}

.sim .sim-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 24px;
  padding: 0;
}

.sim .sim-grid > .panel:nth-child(2) {
  position: sticky;
  top: 16px;
  align-self: start;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

@media (max-width: 820px) {
  .sim .sim-grid { grid-template-columns: 1fr; gap: 16px; }
  .sim .sim-grid > .panel:nth-child(2) {
    position: static;
    max-height: none;
  }
}

.sim .panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sim canvas {
  background: var(--canvas-bg);
  border-radius: 6px;
  display: block;
  width: 100%;
}

.sim .controls {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sim .controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--text);
  font-size: 12px;
}

.sim .controls label .label-value {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.sim .controls input[type=range] {
  width: 100%;
  accent-color: var(--link);
}

.sim .row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.sim .chip {
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--body-bg);
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  border: 1px solid var(--card-border);
  transition: 120ms;
  color: var(--text);
}

.sim .chip:hover { background: var(--card-border); }
.sim .chip.on {
  background: var(--link);
  border-color: var(--link);
  color: #fff;
}

.sim .legend {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 4px 4px 0;
}

.sim .legend .sw {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 4px;
}

.sim .meta {
  color: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  margin: 0;
  padding-top: 4px;
  border-top: 1px solid var(--card-border);
}

.sim code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  color: var(--code-fg);
}

/* KaTeX inherits color in dark mode automatically since it uses currentColor
 * for most strokes, but force the math runs to the theme text color so they
 * don't stay pure black on a dark background.
 */
.katex { color: var(--text); }
