:root {
  --bg: #FBF6EE;
  --bg-alt: #F4ECDF;
  --surface: #FFFFFF;
  --ink: #1F2540;
  --muted: #5A607A;
  --line: #E4D9C8;
  --coral: #DE5B3C;
  --teal: #1B827C;
  --amber: #C98A12;
  --violet: #6352CC;
  --rose: #C94A83;
  --brain: #EFE3D2;
  --radius: 18px;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141726;
    --bg-alt: #191D30;
    --surface: #1F2439;
    --ink: #F1EDE4;
    --muted: #A9AEC6;
    --line: #2F3553;
    --coral: #F0805F;
    --teal: #4FBDB5;
    --amber: #E8B24A;
    --violet: #9C8FF2;
    --rose: #EC7FB0;
    --brain: #2A2F4A;
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 64px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.6;
}

.wrap { max-width: 720px; margin: 0 auto; padding: 0 18px; }

h1, h2, h3 { font-family: var(--serif); line-height: 1.15; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(2.2rem, 9vw, 3.4rem); font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: clamp(1.55rem, 6vw, 2.1rem); font-weight: 650; margin-bottom: 12px; }
h3 { font-size: 1.2rem; font-weight: 650; }
h4 {
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 0 4px;
}
p { margin: 0 0 14px; }

a { color: inherit; }

:focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; border-radius: 6px; }

.skip {
  position: absolute; left: -999px; top: 8px;
  background: var(--ink); color: var(--bg);
  padding: 8px 14px; border-radius: 8px; z-index: 20;
}
.skip:focus { left: 8px; }

/* Hero */
.hero { padding: 44px 0 30px; }
.eyebrow, .step {
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--coral);
  font-weight: 700;
  margin-bottom: 10px;
}
.lede { font-size: 1.14rem; color: var(--muted); margin-top: 16px; max-width: 34em; }

.facts { list-style: none; margin: 26px 0 0; padding: 0; display: grid; gap: 10px; }
.facts li {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 5px solid var(--violet);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.98rem;
}
.facts li:nth-child(2) { border-left-color: var(--teal); }
.facts li:nth-child(3) { border-left-color: var(--coral); }

/* Section nav */
.toc {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.toc-row {
  display: flex; gap: 8px;
  overflow-x: auto;
  padding-top: 10px; padding-bottom: 10px;
  scrollbar-width: none;
}
.toc-row::-webkit-scrollbar { display: none; }
.toc a {
  flex: none;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  white-space: nowrap;
}

/* Sections */
.section { padding: 44px 0; }
.section.alt { background: var(--bg-alt); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 20px;
}

.aside {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 14px 2px 0;
  padding-left: 12px;
  border-left: 3px solid var(--line);
}

/* Brain map */
.brain { display: block; width: 100%; height: auto; max-width: 460px; margin: 0 auto; }
.brain-base { fill: var(--brain); stroke: var(--ink); stroke-opacity: 0.35; stroke-width: 2; }
.stem { fill: var(--brain); stroke: var(--ink); stroke-opacity: 0.35; stroke-width: 2; }
.folds path { fill: none; stroke: var(--ink); stroke-opacity: 0.14; stroke-width: 2.5; stroke-linecap: round; pointer-events: none; }

.region {
  cursor: pointer;
  opacity: 0.45;
  stroke: var(--ink);
  stroke-opacity: 0;
  stroke-width: 2;
  transition: opacity 0.2s;
}
.region:hover { opacity: 0.7; }
.region.is-on { opacity: 0.95; stroke-opacity: 0.6; }
.region[data-region="pfc"] { fill: var(--violet); }
.region[data-region="striatum"] { fill: var(--coral); }
.region[data-region="amygdala"] { fill: var(--rose); }
.region[data-region="cerebellum"] { fill: var(--amber); }
.region-line { fill: none !important; stroke: var(--teal); stroke-opacity: 1; stroke-width: 16; stroke-linecap: round; }
.region-line.is-on { stroke: var(--teal); stroke-opacity: 1; stroke-width: 19; }

.pins { pointer-events: none; }
.pins circle { fill: var(--surface); stroke: var(--ink); stroke-opacity: 0.5; stroke-width: 1.5; }
.pins text { font: 700 13px var(--sans); fill: var(--ink); text-anchor: middle; }
.orient { font: 600 11px var(--sans); fill: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  font: inherit; font-size: 0.9rem; font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 8px 13px;
  min-height: 42px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
  text-align: left;
}
.chip .num {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--c, var(--ink)); color: #fff;
  font-size: 0.78rem; flex: none;
}
.chip[aria-pressed="true"] { border-color: var(--c, var(--ink)); background: color-mix(in srgb, var(--c, var(--ink)) 13%, transparent); }

.panel {
  margin-top: 16px;
  padding: 16px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--c, var(--violet)) 9%, transparent);
  border-left: 5px solid var(--c, var(--violet));
}
.panel .nick { font-family: var(--serif); font-size: 1.45rem; font-weight: 650; line-height: 1.15; }
.panel .name { color: var(--muted); font-size: 0.92rem; margin: 2px 0 4px; }
.panel p { margin: 0; }

/* Segmented control */
.seg {
  display: flex;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px; gap: 4px;
}
.seg button {
  flex: 1;
  font: inherit; font-size: 0.9rem; font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 0; border-radius: 9px;
  padding: 9px 6px; min-height: 42px;
  cursor: pointer;
  line-height: 1.2;
}
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.seg-pair { display: grid; gap: 8px; }

/* Synapse */
.canvas-wrap { margin-top: 14px; border-radius: 14px; overflow: hidden; background: var(--bg); border: 1px solid var(--line); }
#synapse { display: block; width: 100%; height: 230px; }
.canvas-labels {
  display: flex; justify-content: space-between;
  font-size: 0.74rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--muted); margin-top: 6px;
}

.meter-row { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; margin-top: 14px; }
.meter-label { font-size: 0.9rem; font-weight: 700; }
.meter { height: 14px; border-radius: 999px; background: var(--bg-alt); border: 1px solid var(--line); overflow: hidden; }
.meter-fill { height: 100%; width: 0; border-radius: 999px; background: var(--teal); }
.meter-word { grid-column: 1 / -1; font-size: 0.9rem; color: var(--muted); }

.caption { margin: 14px 0 0; font-size: 0.98rem; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 14px; font-size: 0.82rem; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 3px; }
.dot-coral { background: var(--coral); }
.dot-amber { background: var(--amber); }
.dot-teal { background: var(--teal); }
.ghost {
  margin-left: auto;
  font: inherit; font-size: 0.85rem; font-weight: 600;
  color: var(--ink); background: transparent;
  border: 1.5px solid var(--line); border-radius: 999px;
  padding: 6px 14px; min-height: 38px; cursor: pointer;
}

/* Bars */
.bars { display: grid; gap: 14px; margin-top: 18px; }
.bar-name { display: block; font-size: 0.9rem; font-weight: 700; margin-bottom: 5px; }
.bar { height: 22px; border-radius: 999px; background: var(--bg-alt); border: 1px solid var(--line); overflow: hidden; }
.bar-fill { height: 100%; width: 10%; border-radius: 999px; transition: width 0.6s cubic-bezier(.3,.8,.3,1); }
.fill-teal { background: var(--teal); }
.fill-violet { background: var(--violet); }
.fill-coral { background: var(--coral); }
.bar-key { font-size: 0.8rem; color: var(--muted); margin: 8px 0 0; }

.bar-fill.flicker { animation: flicker 2.6s ease-in-out infinite; }
@keyframes flicker {
  0%, 100% { width: 38%; }
  22% { width: 62%; }
  41% { width: 44%; }
  63% { width: 70%; }
  80% { width: 50%; }
}

/* Igniters */
.igniters { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 16px; }
.igniters span {
  text-align: center;
  font-size: 0.86rem; font-weight: 700;
  padding: 9px 6px;
  border-radius: 10px;
  border: 1.5px dashed var(--line);
  color: var(--muted);
  transition: background 0.3s, color 0.3s, border-color 0.3s;
}
.igniters span.lit { background: var(--coral); border: 1.5px solid var(--coral); color: #fff; }
.igniters span.lit::before { content: "\2713\00a0"; }

/* Accordion */
.stack { display: grid; gap: 10px; margin-top: 18px; }
details { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
summary {
  cursor: pointer; list-style: none;
  padding: 15px 44px 15px 16px;
  font-family: var(--serif); font-size: 1.1rem; font-weight: 650; line-height: 1.3;
  position: relative;
}
summary::-webkit-details-marker { display: none; }
summary::after {
  content: "+"; position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
  font-family: var(--sans); font-size: 1.4rem; font-weight: 400; color: var(--coral);
}
details[open] summary::after { content: "\2212"; }
.d-body { padding: 0 16px 16px; }
.d-body h4:first-child { margin-top: 0; }
.d-body p { margin: 0; }

/* Tiles */
.grid { display: grid; gap: 10px; margin-top: 18px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.tile h3 { margin-bottom: 6px; }
.tile p { margin: 0; font-size: 0.97rem; color: var(--muted); }

.partner { border-left: 5px solid var(--rose); }
.partner ul { margin: 10px 0 0; padding-left: 20px; }
.partner li { margin-bottom: 6px; }

.foot { padding: 28px 0 44px; font-size: 0.86rem; color: var(--muted); }
.foot p { margin: 0; }

@media (min-width: 620px) {
  .facts { grid-template-columns: repeat(3, 1fr); }
  .seg-pair { grid-template-columns: 1fr 1fr; }
  .grid { grid-template-columns: 1fr 1fr; }
  .igniters { grid-template-columns: repeat(4, 1fr); }
  .card { padding: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .bar-fill, .region, .igniters span { transition: none; }
  .bar-fill.flicker { animation: none; width: 52%; }
}
