:root {
  color-scheme: light dark;
  --bg: #f7f7f4;
  --text: #202124;
  --muted: #5f6368;
  --border: #d6d7d2;
  --panel: #ffffff;
  --accent: #235c7a;
  /* --code is the background of a code block and --code-text its foreground.
     Naming only the first of those is how dark mode ended up with near-white
     text on a near-white block: the variable was set to a light colour on the
     assumption it was the ink. */
  --code: #1f2933;
  --code-text: #f8fafc;
  /* A background for things drawn on top of the page: example chips, inline
     controls. Named so components do not have to invent one each. */
  --surface: rgba(0, 0, 0, 0.04);
  /* Something is defined in a way that cannot produce an answer. */
  --warn-bg: #ffd9e4;
  --warn-text: #3d0d1c;
}

/* The site declared color-scheme: light and had no dark rules, so a reader in
   dark mode got the light page - and any component that added its own dark
   overrides painted dark colours onto it. Only the variables change here; every
   rule below is written against them already. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171a;
    --text: #e8e8e6;
    --muted: #a1a4a8;
    --border: #3a3c40;
    --panel: #1e2023;
    --accent: #7fb4cd;
    --code: #0e1116;
    --code-text: #e6edf3;
    --surface: rgba(255, 255, 255, 0.07);
    --warn-bg: #5c2438;
    --warn-text: #ffdde6;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

main {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto;
  padding: 48px 0 72px;
}

header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 24px;
  margin-bottom: 28px;
}

.eyebrow {
  color: var(--accent);
  font-weight: 700;
  margin: 0 0 8px;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.25rem);
  line-height: 1.05;
  margin: 0 0 16px;
}

h2 {
  font-size: 1.2rem;
  margin: 0 0 12px;
}

p {
  max-width: 760px;
  margin: 0 0 12px;
}

section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 22px;
  margin: 18px 0;
}

ul {
  margin: 0;
  padding-left: 22px;
}

li + li {
  margin-top: 6px;
}

pre {
  overflow-x: auto;
  background: var(--code);
  color: var(--code-text);
  border-radius: 6px;
  padding: 14px 16px;
  margin: 12px 0;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92rem;
}

a {
  color: var(--accent);
  font-weight: 650;
}

.demo-action {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: inline-block;
  font: inherit;
  font-weight: 700;
  margin: 4px 0 12px;
  padding: 10px 12px;
}

details {
  margin: 12px 0;
}

summary {
  color: var(--accent);
  cursor: pointer;
  font-weight: 700;
}

.demo-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 0.95rem;
}

.demo-table th,
.demo-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.demo-table th {
  background: #eef3f5;
  color: #1f2933;
}

.demo-status {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f2f6f2;
  color: var(--muted);
  padding: 8px 10px;
  margin: 12px 0;
  font-size: 0.92rem;
}

.call-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0;
}

.call-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-weight: 650;
}

.call-form select,
.call-form input,
.call-form textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  padding: 9px 10px;
}

.call-form textarea {
  min-height: 180px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.45;
}

.wide-field {
  grid-column: 1 / -1;
}

.call-form button {
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 10px 12px;
}

@media (max-width: 720px) {
  .call-form {
    grid-template-columns: 1fr;
  }
}

.tree-picker {
  display: grid;
  gap: 6px;
  max-width: 520px;
  margin: 14px 0;
  color: var(--muted);
  font-weight: 650;
}

.tree-picker select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  padding: 9px 10px;
}

.layout-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin: 0 0 12px;
}

.layout-toggle button {
  border: 0;
  border-right: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  padding: 8px 12px;
  cursor: pointer;
}

.layout-toggle button:last-child {
  border-right: 0;
}

.layout-toggle button.active {
  background: var(--accent);
  color: #fff;
}

.tree-view {
  width: 100%;
  min-height: 260px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
  background: #fbfcfb;
}

.tree-view svg {
  display: block;
  min-width: 820px;
}

.tree-view text {
  fill: var(--text);
  font-size: 13px;
}

.tree-node.function,
.tree-node.function_open,
.tree-node.composition_function {
  fill: #235c7a;
}

.tree-node.assumed_primitive {
  fill: #8a5a14;
}

.tree-node.argument {
  fill: #4b6f44;
}

.tree-node.constant {
  fill: #6f6277;
}

.tree-node.foreign_code {
  fill: #9a3412;
}

.tree-node.open_frontier {
  fill: #9a3412;
}

.tree-node.recursive {
  fill: #6d28d9;
}

.tree-meta,
.tree-note {
  color: var(--muted);
  margin-top: 10px;
}
