/* Concurrency in Go: styles. Tokens first, then layout, prose, code, simulations. */
:root {
  --bg: #f4f3ee;
  --surface: #ffffff;
  --surface-2: #ecebe4;
  --ink: #1b2027;
  --muted: #566070;
  --line: #d6d5cd;
  --accent: #165dff;
  --accent-ink: #ffffff;
  --accent-soft: #e3ebff;
  --good: #14804a;
  --good-soft: #def3e8;
  --bad: #b3261e;
  --bad-soft: #fbe5e2;
  --warn: #8a5a00;
  --warn-soft: #fbefd5;
  --code-bg: #14171d;
  --code-ink: #e6e9ef;
  --code-muted: #8b95a5;
  --tk-kw: #c4a7ff;
  --tk-st: #9fe0b4;
  --tk-nu: #ffc477;
  --tk-cm: #8a94a6;
  --tk-ty: #7fc4ff;
  --tk-fn: #8fb4ff;
  --tk-bi: #ffa7a0;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1217; --surface: #171b22; --surface-2: #1e232c; --ink: #e8ebf0; --muted: #98a2b3; --line: #2b323d;
    --accent: #6f9bff; --accent-ink: #0b1020; --accent-soft: #1a2747;
    --good: #5ed39b; --good-soft: #12332a; --bad: #ff8a80; --bad-soft: #3b1b19; --warn: #f0b64a; --warn-soft: #382b10;
    --code-bg: #0b0e13; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1217; --surface: #171b22; --surface-2: #1e232c; --ink: #e8ebf0; --muted: #98a2b3; --line: #2b323d;
  --accent: #6f9bff; --accent-ink: #0b1020; --accent-soft: #1a2747;
  --good: #5ed39b; --good-soft: #12332a; --bad: #ff8a80; --bad-soft: #3b1b19; --warn: #f0b64a; --warn-soft: #382b10;
  --code-bg: #0b0e13; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.65 var(--font);
  padding-left: max(0px, env(safe-area-inset-left, 0px)); padding-right: max(0px, env(safe-area-inset-right, 0px));
}
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.skip-link { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: 6px; z-index: 10; }
.skip-link:focus { left: 8px; }
h1, h2, h3, h4 { line-height: 1.2; letter-spacing: -0.01em; text-wrap: balance; }
h1 { font-size: clamp(2rem, 5vw, 3rem); margin: 0.3em 0 0.4em; }
h2 { font-size: 1.55rem; margin: 2.2em 0 0.6em; }
h3 { font-size: 1.2rem; margin: 1.8em 0 0.5em; }
h4 { font-size: 1.02rem; margin: 1.5em 0 0.4em; }
p, ul, ol { margin: 0 0 1.1em; }
li { margin: 0.25em 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 4px; }
.eyebrow { font: 600 0.78rem/1.4 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 0 0 0.4em; }
.lead { font-size: 1.2rem; color: var(--muted); max-width: 40rem; }
.meta { color: var(--muted); font-size: 0.95rem; }

/* header and footer */
.site-header { border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 5; padding-top: env(safe-area-inset-top, 0px); }
.bar { max-width: 76rem; margin: 0 auto; padding: 0.7rem max(16px, env(safe-area-inset-right, 0px)) 0.7rem max(16px, env(safe-area-inset-left, 0px)); display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.bar-links { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; font-size: 0.95rem; }
.ext-quiet { color: var(--muted); text-decoration: none; }
.ext-quiet:hover { color: var(--ink); text-decoration: underline; }
.site-footer { border-top: 1px solid var(--line); margin-top: 4rem; color: var(--muted); font-size: 0.9rem; }
.site-footer p { margin: 0; }
.wrap { max-width: 76rem; margin: 0 auto; padding: 1.5rem max(16px, env(safe-area-inset-right, 0px)) 2rem max(16px, env(safe-area-inset-left, 0px)); }

/* buttons */
.btn { font: 600 0.9rem/1 var(--font); padding: 0.6rem 0.9rem; min-height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-quiet { background: transparent; }
.btn-lg { font-size: 1rem; padding: 0.85rem 1.2rem; min-height: 48px; }
.cta { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.5rem; }

/* layout */
.layout { display: grid; grid-template-columns: 15rem minmax(0, 1fr); gap: 3rem; align-items: start; }
.toc { position: sticky; top: 4.5rem; font-size: 0.93rem; border-left: 2px solid var(--line); padding-left: 1rem; }
.toc-title { font-weight: 700; margin: 0 0 0.6rem; }
.toc-title a { color: var(--ink); text-decoration: none; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0.1rem 0; }
.toc a { display: block; padding: 0.25rem 0.4rem; color: var(--muted); text-decoration: none; border-radius: 5px; }
.toc a:hover { color: var(--ink); background: var(--surface-2); }
.toc a[aria-current="page"] { color: var(--ink); font-weight: 600; background: var(--accent-soft); }
.toc-home { margin-top: 0.8rem; }
.prose { max-width: 44rem; min-width: 0; }
.prose > h1 { margin-top: 0.1em; }
.prose h2[id]::before, .prose h3[id]::before { content: none; }

/* callouts and tables */
.callout { border: 1px solid var(--line); border-left: 4px solid var(--accent); background: var(--surface); border-radius: 8px; padding: 0.9rem 1.1rem 0.4rem; margin: 1.4em 0; }
.callout-title { font-weight: 700; margin: 0 0 0.4em; }
.callout-warn { border-left-color: var(--warn); background: var(--warn-soft); }
.callout-tip { border-left-color: var(--good); }
.callout-source { border-left-color: var(--muted); font-size: 0.95rem; }
.callout-try { border-left-color: var(--accent); background: var(--accent-soft); }
blockquote { margin: 1.2em 0; padding: 0.2em 1.1em; border-left: 3px solid var(--line); color: var(--muted); }
.table-wrap { overflow-x: auto; margin: 1.3em 0; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 0.93rem; min-width: 32rem; }
th, td { text-align: left; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--surface-2); font-weight: 650; }
tr:last-child td { border-bottom: 0; }

/* code */
figure { margin: 0; }
.code { margin: 1.4em 0; background: var(--code-bg); border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.code figcaption { font: 500 0.78rem/1.4 var(--mono); color: var(--code-muted); padding: 0.55rem 1rem; border-bottom: 1px solid rgba(255, 255, 255, 0.08); overflow-wrap: anywhere; }
.code pre { margin: 0; padding: 0.9rem 1rem; overflow-x: auto; color: var(--code-ink); font: 0.86rem/1.55 var(--mono); tab-size: 4; }
.code code { background: none; padding: 0; font-size: inherit; color: inherit; }
.ln::before { content: attr(data-n); display: inline-block; width: 3.2ch; margin-right: 1.4ch; text-align: right; color: var(--code-muted); user-select: none; }
.code-note { font-size: 0.88rem; color: var(--muted); margin-top: -0.6em; }
.tk-kw { color: var(--tk-kw); } .tk-st { color: var(--tk-st); } .tk-nu { color: var(--tk-nu); }
.tk-cm { color: var(--tk-cm); font-style: italic; } .tk-ty { color: var(--tk-ty); } .tk-fn { color: var(--tk-fn); } .tk-bi { color: var(--tk-bi); }

/* chapter list on the overview page */
.section-list { list-style: none; padding: 0; margin: 1.5em 0; border-top: 1px solid var(--line); counter-reset: s; }
.section-list li { display: flex; gap: 1rem; align-items: baseline; justify-content: space-between; border-bottom: 1px solid var(--line); margin: 0; counter-increment: s; }
.section-list a { display: block; padding: 0.9rem 0; text-decoration: none; color: var(--ink); flex: 1; min-width: 0; }
.section-list a:hover .sl-title { color: var(--accent); text-decoration: underline; }
.sl-title { display: block; font-weight: 650; }
.sl-title::before { content: counter(s) ". "; color: var(--muted); font-weight: 500; }
.sl-sum { display: block; color: var(--muted); font-size: 0.93rem; }
.sl-min { color: var(--muted); font: 0.8rem var(--mono); white-space: nowrap; }

/* pager */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.pager a { display: block; padding: 0.8rem 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); text-decoration: none; color: var(--ink); min-width: 0; }
.pager a:hover { border-color: var(--accent); }
.pager-next { text-align: right; }
.pager-dir { display: block; font: 600 0.75rem var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.pager-title { display: block; font-weight: 650; overflow-wrap: anywhere; }

/* home */
.hero { padding: 2rem 0 1rem; }
.hero h1 { font-size: clamp(2.4rem, 7vw, 4rem); }
.how { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 1.5rem 1.6rem; margin: 2rem 0; max-width: 52rem; }
.how h2 { margin-top: 0; }
.how-list { padding-left: 1.3rem; }
.note { color: var(--muted); font-size: 0.95rem; margin-bottom: 0; }
.part { margin-top: 3rem; }
.part h2 { margin: 0 0 0.3em; }
.part-label { font: 600 0.8rem var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); display: block; margin-bottom: 0.2rem; }
.part-blurb { color: var(--muted); max-width: 44rem; }
.part-count { font: 0.8rem var(--mono); margin-left: 0.4rem; }
.chapter-list { list-style: none; padding: 0; margin: 1rem 0 0; border-top: 1px solid var(--line); }
.cl { border-bottom: 1px solid var(--line); margin: 0; display: flex; align-items: center; gap: 1rem; padding: 0.7rem 0; }
.cl a { display: flex; align-items: center; gap: 1rem; width: 100%; text-decoration: none; color: var(--ink); }
.cl-num { font: 600 0.85rem var(--mono); color: var(--muted); min-width: 2ch; }
.cl-body { flex: 1; min-width: 0; }
.cl-title { display: block; font-weight: 650; }
.cl-topic { display: block; font-size: 0.92rem; color: var(--muted); }
.cl-published a:hover .cl-title { color: var(--accent); text-decoration: underline; }
.cl-planned .cl-title { color: var(--muted); font-weight: 600; }
.chip { font: 600 0.72rem var(--mono); letter-spacing: 0.04em; text-transform: uppercase; padding: 0.2rem 0.5rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.chip-pub { background: var(--good-soft); color: var(--good); border-color: transparent; }

/* simulations */
.sim-figure { margin: 1.8em 0; }
.sim-figure figcaption { font-size: 0.92rem; color: var(--muted); margin-top: 0.5rem; }
.sim { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }
.sim-noscript, .sim-trace-list { font-size: 0.92rem; color: var(--muted); }
.sim-live .sim-noscript { display: none; }
.sim-controls { display: flex; flex-wrap: wrap; gap: 0.7rem 1.4rem; align-items: center; margin-bottom: 0.8rem; }
.ctl { display: flex; align-items: center; gap: 0.5rem; font-size: 0.92rem; }
.ctl input[type="range"] { width: 7.5rem; accent-color: var(--accent); }
.ctl-value { font: 600 0.9rem var(--mono); min-width: 1.5ch; }
.ctl-wide { min-width: 4ch; }
.ctl-seed { width: 5.2rem; font: 0.9rem var(--mono); padding: 0.4rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.ctl-check input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); }
.sim-stage { overflow-x: auto; }
.sim-svg { display: block; width: 100%; height: auto; min-width: 560px; }
.sim-status { margin: 0.7rem 0 0.2rem; min-height: 3.2em; font-weight: 600; }
.sim-result { margin: 0 0 0.8rem; font-size: 0.95rem; color: var(--muted); }
.sim-result.ok { color: var(--good); font-weight: 600; }
.sim-result.bad { color: var(--bad); font-weight: 600; }
.sim-playback { display: grid; gap: 0.6rem; }
.pb-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.pb-speed-label { font-size: 0.9rem; color: var(--muted); margin-left: auto; }
.pb-speed { font: inherit; padding: 0.3rem; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.pb-scrub { display: flex; gap: 0.8rem; align-items: center; }
.pb-range { flex: 1; accent-color: var(--accent); min-width: 0; }
.pb-label { font: 0.8rem var(--mono); color: var(--muted); white-space: nowrap; }
.sim-trace { margin-top: 0.8rem; font-size: 0.92rem; }
.sim-trace summary { cursor: pointer; color: var(--accent); }
.sim-trace-list { max-height: 16rem; overflow: auto; padding-left: 1.4rem; margin-top: 0.5rem; }
.sim-svg text { font-family: var(--font); fill: var(--ink); font-size: 13px; }
.row-bg { fill: var(--surface-2); stroke: none; }
.row-actor .row-bg { fill: var(--accent-soft); }
.row-done { opacity: 0.55; }
.row-name { font-weight: 700; font-size: 15px; }
.row-name.small { font-size: 13px; }
.row-note { font-size: 12px; fill: var(--muted); }
.op { fill: var(--surface); stroke: var(--line); }
.op-text { font-size: 12px; fill: var(--muted); }
.op-past { fill: var(--surface-2); }
.op-now { fill: var(--accent); stroke: var(--accent); }
.op-blocked { fill: var(--warn); stroke: var(--warn); }
.op-now + .op-text { fill: var(--accent-ink); font-weight: 700; }
.box { fill: var(--surface); stroke: var(--ink); stroke-width: 1.5; }
.box-off { stroke: var(--line); stroke-dasharray: 4 4; }
.box-label { font-size: 12px; fill: var(--muted); }
.box-value { font-size: 36px; font-weight: 700; }
.box-small { font-size: 12px; }
.box-pulse { animation: pulse 0.7s ease-out; }
.badge { fill: var(--good-soft); }
.badge-starvation { fill: var(--warn-soft); }
.badge-text { font-size: 13px; font-weight: 700; }
.lane-label { font-size: 12px; fill: var(--muted); }
.lane { fill: var(--surface-2); stroke: none; }
.lane-lock { fill: var(--surface); stroke: var(--line); stroke-width: 1.5; }
.lane-held { stroke: var(--ink); }
.lock-text { font-size: 15px; font-weight: 700; }
.tok circle { stroke: var(--ink); stroke-width: 1.5; fill: var(--surface); }
.tok text { font-size: 12px; font-weight: 700; }
.tok-hold circle { fill: var(--accent); stroke: var(--accent); }
.tok-hold text { fill: var(--accent-ink); }
.tok-woken circle { fill: var(--warn-soft); stroke: var(--warn); stroke-dasharray: 3 3; }
.tok-wait circle { fill: var(--warn-soft); stroke: var(--warn); }
.tok-think circle { fill: var(--surface); stroke: var(--muted); }
.acq-bar { fill: var(--accent); }
.acq-zero { fill: var(--bad); }
@keyframes pulse { from { stroke-width: 5; } to { stroke-width: 1.5; } }
@media (prefers-reduced-motion: reduce) {
  .box-pulse { animation: none; }
  * { scroll-behavior: auto !important; transition: none !important; }
}

/* small screens */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 1.2rem; }
  .toc { position: static; border-left: 0; border-bottom: 1px solid var(--line); padding: 0 0 1rem; }
  .toc ol { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; }
}
@media (max-width: 560px) {
  body { font-size: 16px; }
  .site-header { position: static; }
  .pager { grid-template-columns: 1fr; }
  .pager-empty { display: none; }
  .cl { flex-wrap: wrap; }
  .sl-min { display: none; }
  .pb-speed-label { margin-left: 0; }
}
