:root {
  --bg: #f9faf8; --panel: #ffffff; --fg: #1b1c1d; --dim: #5d6460; --line: #e1e4df;
  --accent: #2f7a35; --edge: #d6dbd3; --node-off: #c4cac1; --code-bg: #f1f3ef; --err: #b91c1c;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --tk-k: #0f6e8c; --tk-s: #9a5a06; --tk-c: #7b847b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141514; --panel: #1c1e1c; --fg: #e7e9e5; --dim: #9ba39b; --line: #2c302c;
    --accent: #8cc84b; --edge: #363b36; --node-off: #4a504a; --code-bg: #222522; --err: #f87171;
    --tk-k: #7cc4e0; --tk-s: #e3b25f; --tk-c: #858d85;
  }
}
:root[data-theme="dark"] {
  --bg: #141514; --panel: #1c1e1c; --fg: #e7e9e5; --dim: #9ba39b; --line: #2c302c;
  --accent: #8cc84b; --edge: #363b36; --node-off: #4a504a; --code-bg: #222522; --err: #f87171;
    --tk-k: #7cc4e0; --tk-s: #e3b25f; --tk-c: #858d85;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
code, pre, textarea { font-family: var(--mono); font-size: 14px; }
:not(pre) > code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
pre { background: var(--code-bg); padding: 12px 14px; border-radius: 8px; overflow-x: auto; line-height: 1.45; }
h1, h2, h3 { line-height: 1.25; }
.tk-k { color: var(--tk-k); } .tk-s, .tk-n { color: var(--tk-s); } .tk-c { color: var(--tk-c); font-style: italic; }
.tk-op { color: var(--accent); font-weight: 600; }
h1 { font-size: 2rem; margin: 0 0 .5rem; }
h2 { margin-top: 2.2rem; }

/* Header: brand + sections; a menu button on phones. */
.site-header { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 28px; height: 58px; padding: 0 24px; background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; color: var(--fg); text-decoration: none; }
.brand img { width: 30px; height: 30px; border-radius: 22%; box-shadow: 0 0 0 1px var(--line); }
.site-header nav { display: flex; gap: 4px; flex: 1; }
.site-header nav a { padding: 6px 12px; border-radius: 6px; color: var(--dim); text-decoration: none; font-size: 15px; }
.site-header nav a:hover { color: var(--fg); background: var(--code-bg); }
.site-header nav a[aria-current] { color: var(--fg); font-weight: 600; }
.site-header nav .ext { margin-left: auto; }
.icon-btn { display: none; font: inherit; font-size: 15px; color: var(--fg); background: var(--code-bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 12px; cursor: pointer; }

/* Pages: a reading column; playgrounds take the whole width, with the code beside the network;
   the course adds its chapters. */
main { padding: 36px 48px 64px; min-width: 0; }
main.page { max-width: 1080px; margin: 0 auto; }
main.wide { max-width: 1640px; margin: 0 auto; }
main > p, main > ul, main > ol, main > h1, main > h2, main > h3, main > details, main > .note { max-width: 88ch; }
.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); max-width: 1640px; margin: 0 auto; }
@media (min-width: 1400px) { body { font-size: 17px; } }
#toc { position: sticky; top: 58px; align-self: start; height: calc(100vh - 58px); overflow-y: auto; padding: 28px 16px; border-right: 1px solid var(--line); }
#toc h2 { margin: 0 0 10px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
#toc ol { list-style: none; padding: 0; margin: 0; }
#toc li a { display: block; padding: 6px 8px; border-radius: 6px; color: var(--dim); text-decoration: none; font-size: 15px; }
#toc li a:hover { background: var(--code-bg); color: var(--fg); }
#toc li a[aria-current] { background: var(--code-bg); color: var(--fg); font-weight: 600; }
.toc-btn { margin-bottom: 18px; }
.backdrop { display: none; }

.lead { font-size: 1.15rem; color: var(--dim); }
.note { border-left: 3px solid var(--accent); background: var(--panel); padding: 10px 14px; border-radius: 0 8px 8px 0; }
details { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; margin: 12px 0; }
details summary { cursor: pointer; font-weight: 600; }
.task { font-weight: 600; }
#pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--line); }
#pager a { text-decoration: none; }
.site-footer { border-top: 1px solid var(--line); padding: 24px; text-align: center; color: var(--dim); font-size: 14px; }
.site-footer a { color: var(--dim); }

@media (max-width: 860px) {
  .site-header { padding: 0 16px; gap: 12px; }
  .icon-btn { display: inline-flex; }
  .site-header .menu-btn { margin-left: auto; }
  .site-header nav { display: none; position: absolute; top: 58px; left: 0; right: 0; flex-direction: column; padding: 8px 16px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
  .site-header.open nav { display: flex; }
  .site-header nav .ext { margin-left: 0; }
  main { padding: 24px 16px 48px; }
  .layout { grid-template-columns: 1fr; }
  #toc { position: fixed; top: 58px; left: 0; bottom: 0; height: auto; width: min(300px, 85vw); z-index: 20; background: var(--panel); transform: translateX(-100%); transition: transform .2s; }
  body.toc-open #toc { transform: none; }
  body.toc-open .backdrop { display: block; position: fixed; inset: 58px 0 0; z-index: 10; background: rgb(0 0 0 / .35); }
}

/* Home */
.hero { display: flex; align-items: center; gap: 28px; margin: 24px 0 8px; }
.hero img { width: 112px; height: 112px; flex: none; border-radius: 22%; box-shadow: 0 0 0 1px var(--line); }
.hero h1 { margin: 0; font-size: 2.6rem; }
.hero p { margin: 6px 0 0; font-size: 1.2rem; color: var(--dim); max-width: 46ch; }
.cta { display: flex; flex-wrap: wrap; gap: 10px; margin: 24px 0 8px; }
.cta a { padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); text-decoration: none; font-weight: 600; }
.cta a.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 18px 0; }
.features div { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.features h3 { margin: 0 0 6px; font-size: 1.02rem; }
.features p { margin: 0; color: var(--dim); font-size: 15px; }
@media (max-width: 520px) { .hero { gap: 16px; } .hero img { width: 72px; height: 72px; } .hero h1 { font-size: 2rem; } }

/* Playground */
.pg { container-type: inline-size; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; margin: 18px 0; overflow: hidden; }
.pg-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--dim); }
.pg-bar button, .pg-bar select { font: inherit; color: var(--fg); background: var(--code-bg); border: 1px solid var(--line); border-radius: 6px; padding: 3px 10px; cursor: pointer; }
.pg-bar label { display: inline-flex; align-items: center; gap: 6px; }
.pg-bar input[type=range] { width: 80px; accent-color: var(--accent); }
.pg-round { margin-left: auto; font-family: var(--mono); }
.pg-main { display: grid; grid-template-columns: 1fr; }
@container (min-width: 860px) {
  .pg-main { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); }
  .pg-editors { border-right: 1px solid var(--line); }
  .pg-code { flex: 1; border-bottom: 0; }
  .pg canvas { height: min(calc(var(--pg-h, 340px) * 1.3), 78vh); }
}
.pg-tabs { display: inline-flex; gap: 2px; }
.pg-tabs button[aria-selected="true"] { background: var(--panel); border-color: var(--accent); color: var(--accent); }
.pg-editors { min-width: 0; display: flex; flex-direction: column; }
.pg-code { width: 100%; border: 0; border-bottom: 1px solid var(--line); resize: vertical; padding: 12px 14px; background: var(--code-bg); color: var(--fg); line-height: 1.5; outline: none; tab-size: 2; white-space: pre-wrap; overflow-wrap: anywhere; }
.pg canvas { display: block; width: 100%; height: var(--pg-h, 340px); touch-action: none; cursor: pointer; }
.pg-status { font-family: var(--mono); font-size: 13px; padding: 0 12px; color: var(--err); }
.pg-status:empty { display: none; }
.pg-info { font-family: var(--mono); font-size: 12px; color: var(--dim); padding: 6px 12px 8px; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.pg-embed > script { display: none; }
.pg-export { width: min(760px, calc(100vw - 32px)); background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.pg-export::backdrop { background: rgb(0 0 0 / .4); }
.pg-export textarea { width: 100%; height: 30vh; font-size: 12px; background: var(--code-bg); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; }
.pg-dialog-bar { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.pg-dialog-bar button { font: inherit; font-size: 14px; color: var(--fg); background: var(--code-bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 14px; cursor: pointer; }

/* puck.html: the steps side by side, then the controls and what to do with the current example. */
.steps { list-style: none; counter-reset: step; padding: 0; margin: 20px 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; max-width: none !important; }
.steps li { counter-increment: step; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font-size: 15px; color: var(--dim); }
.steps li b:first-child { display: block; color: var(--fg); margin-bottom: 4px; }
.steps li b:first-child::before { content: counter(step) ". "; color: var(--accent); }
.steps em { color: var(--fg); font-style: normal; font-weight: 600; }
.demo-panel { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px; padding: 10px 14px; margin: 18px 0 -6px; }
.demo-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-size: 14px; color: var(--dim); }
.demo-bar button { font: inherit; color: var(--fg); background: var(--code-bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 12px; cursor: pointer; }
.demo-bar button.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 600; }
.demo-bar button:disabled { opacity: .5; cursor: default; }
.stale { color: var(--accent); }
.howto { margin: 8px 0 0; }
#console { max-height: 14em; overflow: auto; font-size: 12px; }

.pg-export h3 { margin: 0 0 6px; }
.pg-export p { margin: 6px 0 12px; color: var(--dim); }
.pg-form { display: grid; gap: 10px; font-size: 14px; }
.pg-form select, .pg-form input:not([type=checkbox]) { font: inherit; color: var(--fg); background: var(--code-bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
.pg-dev-status { margin-right: auto; align-self: center; font-size: 14px; color: var(--dim); }
.pg-dev-log { font-size: 12px; max-height: 10em; overflow: auto; }
.pg-export details { margin-top: 14px; }
.pg-dialog-bar button:disabled { opacity: .5; cursor: default; }
.readings { margin-left: auto; font-family: var(--mono); font-size: 13px; color: var(--fg); }

/* Reference tables: wide ones scroll on their own on phones. */
.table { overflow-x: auto; margin: 1rem 0; }
.table table { border-collapse: collapse; width: 100%; font-size: 15px; }
.table th, .table td { text-align: left; vertical-align: top; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.table th { color: var(--dim); font-weight: 600; }
.table td:first-child { white-space: nowrap; }
