/* Layout: a lab-notebook column — one wide "specimen stage" for each simulation, a 66ch reading column for the text. */
:root {
  --bg: #eceff3;
  --surface: #ffffff;
  --stage: #f7f9fb;
  --ink: #15171d;
  --muted: #586172;
  --line: #cfd5de;
  --accent: #2f43c9;
  --accent-soft: #e3e7fb;
  --na: #e0662f;
  --k: #7a4bd8;
  --cl: #198f62;
  --ca: #c99606;
  --nt: #0b9db0;
  --exc: #d4471a;
  --inh: #2468d1;
  --memb: #d6b585;
  --myelin: #e6dcc4;
  --cell: #f6e1e8;
  --cell-edge: #a8466c;
  --glia: #e3efe2;
  --glia-edge: #3f7d4a;
  --vessel: #c8323a;
  --tip-bg: #15171d;
  --tip-fg: #f4f6f9;
  --f-display: "Familjen Grotesk", "Helvetica Neue", Arial, sans-serif;
  --f-body: "Source Serif 4", Georgia, "Times New Roman", serif;
  --f-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --surface: #161a21; --stage: #11151b; --ink: #e7ebf1; --muted: #98a1b2; --line: #2a313c;
    --accent: #93a1ff; --accent-soft: #232a4a;
    --na: #ff8a50; --k: #b190ff; --cl: #46c98f; --ca: #f2c33a; --nt: #39cfe0; --exc: #ff7a4a; --inh: #6aa2ff;
    --memb: #8d7350; --myelin: #4b4535; --cell: #3a2431; --cell-edge: #ec8db3; --glia: #1f3324; --glia-edge: #7fc58a; --vessel: #ef5a62;
    --tip-bg: #e7ebf1; --tip-fg: #11141a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --surface: #161a21; --stage: #11151b; --ink: #e7ebf1; --muted: #98a1b2; --line: #2a313c;
  --accent: #93a1ff; --accent-soft: #232a4a;
  --na: #ff8a50; --k: #b190ff; --cl: #46c98f; --ca: #f2c33a; --nt: #39cfe0; --exc: #ff7a4a; --inh: #6aa2ff;
  --memb: #8d7350; --myelin: #4b4535; --cell: #3a2431; --cell-edge: #ec8db3; --glia: #1f3324; --glia-edge: #7fc58a; --vessel: #ef5a62;
  --tip-bg: #e7ebf1; --tip-fg: #11141a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 17px; line-height: 1.6; margin: 0; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

.wrap { max-width: 920px; margin: 0 auto; padding-inline: 20px; padding-block: 24px 64px; }
@media (max-width: 480px) { .wrap { padding-inline: 16px; } body { font-size: 16px; } }

/* ---------- type ---------- */
h1, h2, h3, .display { font-family: var(--f-display); font-weight: 700; letter-spacing: -0.01em; text-wrap: balance; line-height: 1.12; }
h1 { font-size: clamp(2rem, 6vw, 3.1rem); margin: 0.1em 0 0.25em; }
h2 { font-size: 1.45rem; margin: 2.2em 0 0.5em; }
h3 { font-size: 1.1rem; margin: 1.6em 0 0.4em; }
.eyebrow { font-family: var(--f-mono); font-size: 0.72rem; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); margin: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.tagline { font-size: 1.15rem; color: var(--muted); margin: 0; max-width: 60ch; }
.mono { font-family: var(--f-mono); }

/* ---------- menu ---------- */
.hero { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; padding-block: 10px 8px; }
.hero h1 { font-size: clamp(2.6rem, 9vw, 4.6rem); margin: 0; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero .lede { max-width: 62ch; margin: 0; font-size: 1.08rem; }
.hero-trace { width: 100%; height: 86px; display: block; }
.howto { font-size: 0.95rem; color: var(--muted); max-width: 62ch; margin: 0; }
.group-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px; margin: 2.4em 0 0.9em; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.group-head h2 { margin: 0; font-size: 1.3rem; white-space: nowrap; }
.group-head span { font-family: var(--f-mono); font-size: 0.75rem; color: var(--muted); }
.tiles { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } .tiles .tile:last-child:nth-child(odd) { grid-column: 1 / -1; } }
@media (min-width: 820px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } .tiles .tile:last-child:nth-child(odd) { grid-column: auto; } .tiles .tile:last-child:nth-child(3n+1) { grid-column: 1 / -1; } }
.tile { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 4px 14px; align-items: start; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); text-decoration: none; color: var(--ink); transition: border-color .15s, transform .15s; }
.tile:hover { border-color: var(--accent); transform: translateY(-1px); }
.tile svg { width: 52px; height: 52px; grid-row: span 2; color: var(--accent); }
.tile .t-title { font-family: var(--f-display); font-weight: 700; font-size: 1.05rem; line-height: 1.2; }
.tile .t-title small { font-family: var(--f-mono); font-weight: 500; color: var(--muted); font-size: 0.7rem; margin-right: 6px; }
.tile .t-tag { font-size: 0.86rem; color: var(--muted); line-height: 1.35; }

/* ---------- concept page ---------- */
.crumbs { display: flex; justify-content: space-between; gap: 12px; font-family: var(--f-mono); font-size: 0.8rem; margin-bottom: 18px; }
.crumbs a { text-decoration: none; }
.chip { font-family: var(--f-mono); font-size: 0.72rem; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); letter-spacing: 0.03em; text-transform: none; }
figure.viz { margin: 22px 0 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.stage { position: relative; background: var(--stage); }
.stage canvas { display: block; width: 100%; touch-action: manipulation; }
.controls { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; padding: 12px 14px; border-top: 1px solid var(--line); font-family: var(--f-display); font-size: 0.9rem; }
.controls button { font: inherit; font-weight: 600; padding: 7px 13px; border-radius: 7px; border: 1px solid var(--line); background: var(--stage); color: var(--ink); cursor: pointer; }
.controls button:hover { border-color: var(--accent); }
.controls button.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.controls button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.controls label { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.controls input[type=range] { width: 120px; accent-color: var(--accent); }
.controls .sp { flex: 1 1 0; min-width: 0; }
.controls .ro { font-family: var(--f-mono); font-size: 0.8rem; color: var(--ink); background: var(--stage); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-variant-numeric: tabular-nums; }
.controls .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.controls .seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line); }
.controls .seg button:last-child { border-right: 0; }
.keylist { margin: 0; padding: 10px 14px 12px 14px; border-top: 1px solid var(--line); font-family: var(--f-display); font-size: 0.85rem; columns: 2; column-gap: 18px; list-style: none; }
.keylist li { break-inside: avoid; display: flex; gap: 6px; line-height: 1.35; padding: 2px 0; }
.keylist b { font-family: var(--f-mono); font-size: 0.72rem; min-width: 1.6em; height: 1.6em; border-radius: 50%; background: var(--accent); color: var(--surface); display: inline-grid; place-items: center; flex: none; }
@media (max-width: 380px) { .keylist { columns: 1; } }
figcaption { font-size: 0.92rem; color: var(--muted); padding: 10px 14px 14px; border-top: 1px solid var(--line); }
figcaption b { color: var(--ink); font-family: var(--f-display); }

.prose { max-width: 66ch; }
.prose p { margin: 0 0 1em; }
.plain { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 4px 20px 6px; margin-top: 28px; }
.plain h2 { margin-top: 0.9em; font-size: 1.15rem; }
.plain h2::before { content: "In plain words"; display: block; font-family: var(--f-mono); font-weight: 500; font-size: 0.7rem; letter-spacing: .09em; text-transform: uppercase; color: var(--accent); margin-bottom: 4px; }
.timeline { list-style: none; padding: 0; margin: 0 0 1.2em; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 12px 18px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 0.55em; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline .yr { font-family: var(--f-mono); font-size: 0.8rem; font-weight: 600; color: var(--accent); display: block; font-variant-numeric: tabular-nums; }
.compare { margin-top: 2.4em; border-top: 2px solid var(--ink); padding-top: 4px; }
.compare h2 { margin-top: 0.6em; }
.cmp-row { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 0.95rem; }
.cmp-row div:first-child::before, .cmp-row div:last-child::before { display: block; font-family: var(--f-mono); font-size: 0.68rem; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 2px; }
.cmp-row div:first-child::before { content: "Sapolsky, Behave (2017)"; color: var(--muted); }
.cmp-row div:last-child::before { content: "Current understanding"; color: var(--accent); }
@media (max-width: 560px) { .cmp-row { grid-template-columns: minmax(0,1fr); gap: 6px; } }
.sources { font-size: 0.85rem; color: var(--muted); margin-top: 2.2em; }
.sources h3 { font-size: 0.95rem; color: var(--ink); }
.sources ol { padding-left: 1.2em; }
.pager { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; margin-top: 3em; }
.pager a { display: block; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); text-decoration: none; color: var(--ink); font-family: var(--f-display); font-weight: 700; min-width: 0; }
.pager a small { display: block; font-family: var(--f-mono); font-weight: 500; font-size: 0.7rem; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.pager a.next { text-align: right; grid-column: 2; }
.pager a:hover { border-color: var(--accent); }

/* ---------- glossary terms ---------- */
.term { border-bottom: 1.5px dotted var(--accent); cursor: help; color: inherit; }
.term:hover, .term.on { background: var(--accent-soft); }
.tip { position: fixed; z-index: 50; max-width: min(320px, calc(100vw - 24px)); background: var(--tip-bg); color: var(--tip-fg); font-family: var(--f-display); font-size: 0.88rem; line-height: 1.4; padding: 10px 12px; border-radius: 8px; box-shadow: 0 8px 28px rgba(0,0,0,.25); pointer-events: none; }
.tip b { display: block; font-size: 0.78rem; font-family: var(--f-mono); letter-spacing: .04em; opacity: .75; margin-bottom: 2px; }
.tip::after { content: ""; position: absolute; left: var(--ax, 50%); width: 10px; height: 10px; background: var(--tip-bg); transform: translateX(-50%) rotate(45deg); }
.tip.above::after { bottom: -5px; }
.tip.below::after { top: -5px; }

footer.site { margin-top: 4em; font-size: 0.8rem; color: var(--muted); font-family: var(--f-mono); border-top: 1px solid var(--line); padding-top: 12px; }

@media (prefers-reduced-motion: reduce) { .tile { transition: none; } }

/* ---------- phone & full-screen ---------- */
.rotate-hint { display: none; margin: 0; padding: 8px 14px; font-family: var(--f-display); font-size: 0.8rem; color: var(--muted); border-top: 1px solid var(--line); }
.stage canvas.zoomed { cursor: grab; outline: 2px solid var(--accent); outline-offset: -2px; }
html.noscroll, html.noscroll body { overflow: hidden; }
figure.viz.full { position: fixed; inset: 0; z-index: 100; margin: 0; border: 0; border-radius: 0; overflow-y: auto; background: var(--surface); padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
figure.viz.full .stage { background: var(--stage); }
figure.viz.full figcaption, figure.viz.full .rotate-hint { display: none; }
@media (hover: none), (max-width: 560px) {
  .controls button { min-height: 42px; padding: 8px 14px; }
  .controls .seg button { min-height: 42px; }
  .controls input[type=range] { height: 28px; }
}
@media (max-width: 560px) {
  figure.viz:not(.full) { margin-inline: -16px; border-inline: 0; border-radius: 0; }
  .rotate-hint { display: block; }
  .controls { padding: 10px 12px; gap: 8px; }
  .controls label { flex: 1 1 100%; justify-content: space-between; }
  .controls label input[type=range] { flex: 1 1 auto; width: auto; max-width: 70%; }
  .controls .seg { flex: 1 1 100%; }
  .controls .seg button { flex: 1 1 0; padding-inline: 6px; }
  .controls .ro { flex: 1 1 100%; }
  .tile { padding: 12px; grid-template-columns: 44px minmax(0, 1fr); }
  .tile svg { width: 44px; height: 44px; }
  .crumbs { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); margin-inline: -16px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
  h1 { font-size: 2rem; }
  .plain { padding: 2px 16px 4px; }
  .pager { grid-template-columns: minmax(0, 1fr); }
  .pager a.next { grid-column: 1; }
}
.controls.tools { padding-block: 8px; background: var(--stage); font-size: 0.82rem; }
.controls.tools button { font-weight: 500; padding: 5px 10px; }
@media (max-width: 560px) {
  .controls.tools { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 6px; }
  .controls.tools > * { flex: 0 0 auto; }
  .controls.tools .seg { flex: 0 0 auto; }
  .controls.tools button, .controls.tools .seg button { min-height: 36px; padding: 5px 10px; white-space: nowrap; }
}
.fs-close { display: none; position: absolute; top: 8px; right: 8px; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 18px; cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,.18); }
figure.viz.full .fs-close { display: block; }
