/* fruitfly-brain — book stylesheet.
   System (see DESIGN_LOG.md): serif body 18px/1.75 at 70ch, layered dark grays,
   ONE amber accent, CSS-only sticky TOC sidebar ≥1160px, no JS anywhere. */

:root {
  --bg: #101418;        /* page */
  --surface: #171d24;   /* boxes, code, tables */
  --raised: #1e2630;    /* hover / emphasis surfaces */
  --border: #2c3540;
  --fg: #e3e9f0;
  --muted: #8b98a5;
  --accent: #e8a849;    /* the one accent: warm amber */
  --accent-dim: #b98637;
  --finding-tint: rgba(108, 182, 255, .07);  /* semantic, cool */
  --finding-edge: rgba(108, 182, 255, .45);
  --dead-tint: rgba(244, 135, 113, .06);     /* semantic, warm-red */
  --dead-edge: rgba(244, 135, 113, .45);
  --serif: "Charter", "Iowan Old Style", "Palatino", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --measure: 70ch;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--fg);
  font: 18px/1.75 var(--serif);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 1rem 1.4rem 6rem;
}

/* ── hero ─────────────────────────────────────────────── */
header.hero { text-align: center; padding: 5rem 1.2rem 2.2rem; }
header.hero h1 {
  font: 700 2.7rem/1.15 var(--sans);
  letter-spacing: -.025em;
  margin: 0 0 .9rem;
}
header.hero .sub {
  color: var(--muted);
  font-size: 1.12rem;
  line-height: 1.65;
  max-width: 44rem;
  margin: 0 auto;
}
header.hero .sub a { color: var(--fg); }
header.hero .stats {
  margin-top: 2rem;
  display: flex; gap: .7rem; justify-content: center; flex-wrap: wrap;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .55rem 1.05rem;
  font-family: var(--sans);
}
.stat b {
  display: block;
  font-size: 1.25rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.stat span {
  color: var(--muted);
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}

/* ── headings ─────────────────────────────────────────── */
h1, h2, h3 { font-family: var(--sans); }

h2 {
  font-size: 1.75rem;
  line-height: 1.25;
  letter-spacing: -.015em;
  margin: 4.5rem 0 .4rem;
  padding-top: 4.5rem;
  border-top: 1px solid var(--border);
  scroll-margin-top: 1.5rem;
}
h2 .ch {
  display: block;
  color: var(--accent);
  font-size: .78rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .14em;
  margin-bottom: .55rem;
}
h3 { font-size: 1.15rem; margin: 2.2rem 0 .4rem; scroll-margin-top: 1.5rem; }

h1.volume {
  margin: 6rem 0 .5rem;
  padding-top: 3rem;
  font-size: 2.2rem;
  letter-spacing: -.02em;
  border-top: 3px double var(--accent-dim);
  scroll-margin-top: 1.5rem;
}

/* ── prose ────────────────────────────────────────────── */
p { margin: 1rem 0; }

p.meta {
  color: var(--muted);
  font: .82rem/1.5 var(--sans);
  margin: .2rem 0 1.4rem;
}

/* standfirst: the 2–3 sentence “what we asked / what we found” opener */
p.stand {
  font-size: 1.16rem;
  line-height: 1.65;
  color: #c3ccd6;
  margin: 0 0 1.6rem;
}
p.stand::after {
  content: "";
  display: block;
  width: 3.5rem;
  border-bottom: 2px solid var(--accent-dim);
  margin-top: 1.4rem;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

b, strong { color: #f0f4f9; }
::selection { background: rgba(232, 168, 73, .28); }

/* ── TOC ──────────────────────────────────────────────── */
details.toc, div.toc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .9rem 1.3rem;
  margin: 1.5rem 0 2.5rem;
  font-family: var(--sans);
}
details.toc summary {
  cursor: pointer;
  font-weight: 650;
  font-size: .95rem;
  list-style: none;
}
details.toc summary::before { content: "☰  "; color: var(--accent); }
details.toc summary::-webkit-details-marker { display: none; }
.toc ol {
  margin: .7rem 0 .2rem;
  padding-left: 1.5rem;
  font-size: .86rem;
  line-height: 1.9;
  color: var(--muted);
}
.toc a { color: #b9c3ce; }
.toc a:hover { color: var(--accent); text-decoration: none; }

/* desktop: pin the same TOC element as a fixed sidebar, no duplication */
@media (min-width: 1160px) {
  details.toc, div.toc {
    position: fixed;
    top: 1.2rem;
    left: max(1.2rem, calc(50% - 35ch - 19.5rem));
    width: 17rem;
    max-height: calc(100vh - 2.4rem);
    overflow-y: auto;
    margin: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
  }
  .toc ol { font-size: .8rem; line-height: 1.75; }
}

/* ── figures ──────────────────────────────────────────── */
figure { margin: 2rem 0; }
figure a { display: block; }
figure img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
  background: #fff;
}
figcaption {
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.6;
  margin-top: .7rem;
  padding-left: .9rem;
  border-left: 2px solid var(--border);
}

/* slightly wider than the text column when room allows */
@media (min-width: 860px) {
  figure { margin-left: -2.5rem; margin-right: -2.5rem; }
  figcaption { margin-left: 2.5rem; margin-right: 2.5rem; }
}

/* ── tables ───────────────────────────────────────────── */
table {
  border-collapse: collapse;
  width: 100%;
  font: .84rem/1.55 var(--sans);
  font-variant-numeric: tabular-nums;
  margin: 1.6rem 0;
}
th, td {
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: .5rem .75rem;
  text-align: left;
}
th {
  background: none;
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  border-bottom: 2px solid var(--border);
}
tr:hover td { background: rgba(255,255,255,.02); }

/* ── code ─────────────────────────────────────────────── */
code, .mono {
  font-family: var(--mono);
  font-size: .82em;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: .08em .4em;
  border-radius: 5px;
}
pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  font-size: .82rem;
  line-height: 1.6;
}
pre code { background: none; border: 0; padding: 0; font-size: 1em; }

/* ── callouts ─────────────────────────────────────────── */
.finding, .deadend {
  border-radius: 8px;
  padding: 1.05rem 1.3rem;
  margin: 1.8rem 0;
  font-size: .98em;
}
.finding {
  background: var(--finding-tint);
  border: 1px solid transparent;
  border-left: 3px solid var(--finding-edge);
}
.finding b { color: #9ecbf5; }
.deadend {
  background: var(--dead-tint);
  border: 1px solid transparent;
  border-left: 3px solid var(--dead-edge);
}
.deadend b { color: #f0a08b; }

/* ── footer ───────────────────────────────────────────── */
footer {
  text-align: center;
  color: var(--muted);
  font: .85rem/1.7 var(--sans);
  padding: 3.5rem 1rem;
  border-top: 1px solid var(--border);
  margin-top: 4rem;
}

/* ── small screens ────────────────────────────────────── */
@media (max-width: 640px) {
  body { font-size: 17px; }
  header.hero { padding-top: 3rem; }
  header.hero h1 { font-size: 2rem; }
  h2 { font-size: 1.45rem; padding-top: 3rem; margin-top: 3rem; }
  figure { margin-left: -.4rem; margin-right: -.4rem; }
  table { display: block; overflow-x: auto; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* volume label inside the TOC */
.toc > b {
  display: block;
  margin-top: .9rem;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
}
