/* Brain - mobile reading surface.
   One column, thumb-reachable navigation, legible at arm's length.
   Light and dark are both first-class: the OS decides, the toggle overrides. */

:root {
  --bg: #fbfbfa;
  --bg-soft: #f2f1ee;
  --card: #ffffff;
  --line: #e2e0da;
  --ink: #1b1c1e;
  --ink-2: #55575c;
  --ink-3: #86888e;
  --accent: #2f5fd0;
  --accent-soft: #e8eefc;
  --gold: #9a6b12;
  --gold-soft: #fbf1dc;
  --green: #1d6b45;
  --green-soft: #e2f2e9;
  --amber: #8a5a10;
  --radius: 14px;
  --tabh: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --bg-soft: #171a20;
    --card: #171a20;
    --line: #262a33;
    --ink: #e7e8ea;
    --ink-2: #a4a8b2;
    --ink-3: #767b87;
    --accent: #7ea2f0;
    --accent-soft: #1a2438;
    --gold: #e8c37a;
    --gold-soft: #2a2416;
    --green: #6fc99a;
    --green-soft: #12251c;
    --amber: #d7a95e;
    color-scheme: dark;
  }
}

/* The in-page toggle must beat the media query in both directions. */
:root[data-theme="light"] {
  --bg: #fbfbfa; --bg-soft: #f2f1ee; --card: #fff; --line: #e2e0da;
  --ink: #1b1c1e; --ink-2: #55575c; --ink-3: #86888e;
  --accent: #2f5fd0; --accent-soft: #e8eefc;
  --gold: #9a6b12; --gold-soft: #fbf1dc;
  --green: #1d6b45; --green-soft: #e2f2e9; --amber: #8a5a10;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1115; --bg-soft: #171a20; --card: #171a20; --line: #262a33;
  --ink: #e7e8ea; --ink-2: #a4a8b2; --ink-3: #767b87;
  --accent: #7ea2f0; --accent-soft: #1a2438;
  --gold: #e8c37a; --gold-soft: #2a2416;
  --green: #6fc99a; --green-soft: #12251c; --amber: #d7a95e;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  overflow-wrap: break-word;
  padding-bottom: calc(var(--tabh) + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}

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

/* ------------------------------------------------------------- chrome --- */

.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.bar-title {
  flex: 1; min-width: 0;
  font-size: 15px; font-weight: 600; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar .up { display: flex; color: var(--ink-2); }
.bar .up svg, .icon svg { width: 22px; height: 22px; }
.bar span.up { visibility: hidden; }
.icon {
  background: none; border: 0; padding: 0; color: var(--ink-2);
  display: flex; cursor: pointer;
}
svg { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.progress { position: sticky; top: 0; z-index: 21; height: 2px; }
.progress i { display: block; height: 2px; width: 0; background: var(--accent); transition: width .1s linear; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; height: var(--tabh); font-size: 11px; color: var(--ink-3);
  text-decoration: none;
}
.tab:hover { text-decoration: none; }
.tab svg { width: 21px; height: 21px; }
.tab.on { color: var(--accent); }

/* --------------------------------------------------------------- layout --- */

main { max-width: 760px; margin: 0 auto; padding: 4px 18px 40px; }
.doc { font-size: 17px; }
.kicker {
  margin: 18px 0 2px; font-size: 12px; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase; color: var(--ink-3);
}
h1 { font-size: 29px; line-height: 1.2; letter-spacing: -.02em; margin: 4px 0 8px; }
h2 { font-size: 22px; line-height: 1.25; letter-spacing: -.01em; margin: 2.1em 0 .5em; }
h3 { font-size: 18.5px; line-height: 1.3; margin: 1.7em 0 .4em; }
h4 { font-size: 16.5px; margin: 1.5em 0 .35em; color: var(--ink-2); }
h2 .hint { display: block; font-size: 13px; font-weight: 400; color: var(--ink-3); letter-spacing: 0; }
.sub { color: var(--ink-2); margin: 0 0 14px; }
p, ul, ol { margin: 0 0 1em; }
li { margin-bottom: .35em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }

.anchor { margin-left: .4em; color: var(--ink-3); opacity: 0; font-weight: 400; }
h2:hover .anchor, h3:hover .anchor { opacity: 1; }

blockquote {
  margin: 1.2em 0; padding: 12px 16px;
  border-left: 3px solid var(--line);
  background: var(--bg-soft); border-radius: 0 10px 10px 0;
  color: var(--ink-2);
}
blockquote p:last-child { margin-bottom: 0; }

code {
  font: 500 .855em/1.5 ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  background: var(--bg-soft); padding: .12em .38em; border-radius: 5px;
  border: 1px solid var(--line);
}
pre {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; overflow-x: auto;
  font-size: 13.5px; line-height: 1.55;
}
pre code { background: none; border: 0; padding: 0; font-size: inherit; }

a.ts code { background: var(--accent-soft); border-color: transparent; color: var(--accent); }

/* Wide content scrolls in its own box - the page body never does. */
.scroll { overflow-x: auto; margin: 1.2em 0; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--bg-soft); font-weight: 650; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

figure { margin: 1.4em 0; }
img { max-width: 100%; height: auto; border-radius: 10px; display: block; border: 1px solid var(--line); }
figcaption { font-size: 13.5px; color: var(--ink-3); margin-top: 7px; line-height: 1.45; }

pre.mermaid { background: transparent; border: 0; padding: 0; text-align: center; }
pre.mermaid svg { max-width: 100%; height: auto; }

details { margin: 1em 0; }
summary {
  cursor: pointer; font-weight: 600; font-size: 15px; color: var(--ink-2);
  padding: 8px 0; list-style: none;
}
summary::-webkit-details-marker { display: none; }
summary::before { content: "▸ "; color: var(--ink-3); }
details[open] > summary::before { content: "▾ "; }

.toc {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2px 14px; background: var(--bg-soft);
}
.toc a { display: block; padding: 5px 0; font-size: 14.5px; color: var(--ink-2); border-top: 1px solid var(--line); }
.toc a.l3 { padding-left: 16px; font-size: 14px; color: var(--ink-3); }
.toc summary { border: 0; }

/* ---------------------------------------------------------------- pills --- */

.pill {
  display: inline-block; font-size: 11.5px; font-weight: 650;
  letter-spacing: .02em; padding: 3px 9px; border-radius: 999px;
  background: var(--bg-soft); color: var(--ink-2); border: 1px solid var(--line);
  white-space: nowrap;
}
.pill.established, .pill.corroborated { background: var(--green-soft); color: var(--green); border-color: transparent; }
.pill.emerging { background: var(--gold-soft); color: var(--gold); border-color: transparent; }
.pill.needs-check { background: var(--gold-soft); color: var(--amber); border-color: transparent; }
.pill.topic-tag { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ----------------------------------------------------------- home cards --- */

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 18px 0 6px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 8px; text-align: center;
}
.stat b { display: block; font-size: 21px; letter-spacing: -.02em; }
.stat span { font-size: 10.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }

.grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 620px) { .grid { grid-template-columns: 1fr 1fr; } }

.card {
  display: block; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; color: inherit;
}
.card:hover { text-decoration: none; border-color: var(--accent); }
.card h3 { margin: 0; font-size: 17px; }
.card p { margin: 6px 0 8px; font-size: 14.5px; color: var(--ink-2); line-height: 1.5; }
.card-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.card .meta, .row .meta { font-size: 12.5px; color: var(--ink-3); }

.lesson {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; margin: 12px 0;
}
.lesson h3 { margin: 0; font-size: 18px; line-height: 1.3; }
.lesson h3 a { color: inherit; }
.byline { margin: 4px 0 10px; font-size: 13.5px; color: var(--ink-3); }
.tldr { font-size: 15.5px; color: var(--ink); }
.tldr p:last-child { margin-bottom: 0; }
.lesson .claims { border-top: 1px solid var(--line); margin: 12px 0 0; }
.lesson .claims ul { font-size: 15px; padding-left: 20px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.when { font-size: 13.5px; color: var(--ink-2); margin: 8px 0; }
.go { display: inline-block; font-size: 14.5px; font-weight: 600; margin-top: 2px; }

/* ------------------------------------------------------------ list rows --- */

.rows { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; gap: 12px; align-items: flex-start; justify-content: space-between;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 15px; color: inherit;
}
.row:hover { text-decoration: none; border-color: var(--accent); }
.row h3 { margin: 0 0 3px; font-size: 16.5px; line-height: 1.3; }
.row p { margin: 0 0 3px; font-size: 14px; color: var(--ink-2); line-height: 1.45; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }
.row-main { min-width: 0; }

/* --------------------------------------------------------------- claims --- */

.chips { display: flex; gap: 7px; overflow-x: auto; padding: 4px 0 12px; margin: 0 -18px; padding-left: 18px; padding-right: 18px; }
.chip {
  flex-shrink: 0; font: inherit; font-size: 13px; font-weight: 600;
  padding: 6px 13px; border-radius: 999px; cursor: pointer;
  background: var(--card); color: var(--ink-2); border: 1px solid var(--line);
}
.chip.on { background: var(--accent); color: #fff; border-color: transparent; }

.claim {
  background: var(--card); border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: var(--radius); padding: 13px 15px; margin: 9px 0;
}
.claim.corroborated { border-left-color: var(--green); }
.claim.emerging { border-left-color: var(--gold); }
.claim.needs-check { border-left-color: var(--amber); }
.claim-head { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-bottom: 7px; }
.claim-head .n { font-size: 12.5px; font-weight: 700; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.claim-body { font-size: 15.5px; }
.claim-body p { margin: 0; }
.claim details { margin: 8px 0 0; }
.claim summary { font-size: 13px; padding: 4px 0; }
.claim details p { font-size: 13.5px; margin: 0; color: var(--ink-2); }

/* --------------------------------------------------------------- search --- */

#q {
  width: 100%; font: inherit; font-size: 17px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--ink); margin: 6px 0 10px;
}
#q:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.hit mark { background: var(--gold-soft); color: var(--gold); padding: 0 2px; border-radius: 3px; }

/* --------------------------------------------------------------- facts --- */

.facts {
  display: grid; grid-template-columns: auto 1fr; gap: 5px 14px;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 15px; margin: 14px 0;
  font-size: 14px;
}
.facts > div { display: contents; }
.facts dt { color: var(--ink-3); white-space: nowrap; }
.facts dd { margin: 0; color: var(--ink-2); }

@media print { .bar, .tabs, .progress { display: none; } body { padding: 0; } }

.frontmatter {
  border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 2px 14px; margin: 12px 0;
}
.frontmatter > summary { color: var(--ink-3); font-size: 13.5px; font-weight: 500; }
.frontmatter blockquote { background: none; border-left-color: var(--line); padding: 4px 12px; margin: .6em 0; }
.frontmatter p, .frontmatter li { font-size: 14px; color: var(--ink-2); }
