/* Recursive self-improvement — shared stylesheet, all editions */

:root {
  --paper: #f6f4ef;
  --paper-raised: #ffffff;
  --ink: #17181c;
  --ink-secondary: #43454e;
  --ink-muted: #4d4f59;
  --rule: #d8d4c8;
  --rule-strong: #b8b3a4;
  --accent: #3c3a8c;
  --accent-ink: #2a2866;
  --accent-soft: #e8e6f7;
  --amber: #8a5a12;
  --amber-soft: #f5e7cf;
  --danger: #8a2b1f;
  --danger-soft: #f6e2dd;
  --focus: #1b58c9;
  --code-bg: #ece9df;
  --shadow: 0 1px 2px rgba(23, 24, 28, 0.06), 0 8px 24px rgba(23, 24, 28, 0.06);
  --rung-1: #565419;
  --rung-2: #2f5546;
  --rung-3: #7a4118;
  --rung-4: #8a2b1f;
  color-scheme: light;
}

:root:not([data-theme="light"]) {
  @media (prefers-color-scheme: dark) {
    --paper: #14151a;
    --paper-raised: #1b1d24;
    --ink: #eceaf0;
    --ink-secondary: #c3c2cc;
    --ink-muted: #a8a7b1;
    --rule: #33343d;
    --rule-strong: #45464f;
    --accent: #a7a3f0;
    --accent-ink: #d6d3ff;
    --accent-soft: #262a4a;
    --amber: #e0b262;
    --amber-soft: #3a3020;
    --danger: #e39383;
    --danger-soft: #3d2420;
    --focus: #7fb0ff;
    --code-bg: #20222b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.45);
    --rung-1: #c9c37e;
    --rung-2: #7fbfa4;
    --rung-3: #e0a06a;
    --rung-4: #e39383;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #14151a;
  --paper-raised: #1b1d24;
  --ink: #eceaf0;
  --ink-secondary: #c3c2cc;
  --ink-muted: #a8a7b1;
  --rule: #33343d;
  --rule-strong: #45464f;
  --accent: #a7a3f0;
  --accent-ink: #d6d3ff;
  --accent-soft: #262a4a;
  --amber: #e0b262;
  --amber-soft: #3a3020;
  --danger: #e39383;
  --danger-soft: #3d2420;
  --focus: #7fb0ff;
  --code-bg: #20222b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.45);
  --rung-1: #c9c37e;
  --rung-2: #7fbfa4;
  --rung-3: #e0a06a;
  --rung-4: #e39383;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

html, body { overflow-x: hidden; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Iowan Old Style", "Source Serif 4", Georgia, "Times New Roman", serif;
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.sans { font-family: -apple-system, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }

a { color: var(--accent-ink); text-decoration-thickness: 1px; text-underline-offset: 0.15em; }
a:hover { color: var(--accent); }
a:focus-visible, button:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px;
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 0.9rem;
  height: 48px; padding: 0 0.9rem;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--rule);
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
.topbar .home {
  font-weight: 700; font-size: 0.8rem; letter-spacing: 0.01em;
  color: var(--ink); white-space: nowrap; text-decoration: none;
}
.topnav {
  display: flex; gap: 1rem; overflow-x: auto; scrollbar-width: none;
  -ms-overflow-style: none; white-space: nowrap;
  flex: 1 1 auto; min-width: 0;
}
.topnav::-webkit-scrollbar { display: none; }
.topnav a {
  font-size: 0.84rem; color: var(--ink-secondary); text-decoration: none; padding: 0.3rem 0;
  border-bottom: 2px solid transparent;
}
.topnav a[aria-current="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.topbar .spacer { flex: 0 1 0.9rem; }
.topbar .langs {
  display: flex; gap: 0.35rem; align-items: center;
  flex: 0 1 auto; min-width: 0; max-width: 52vw;
  overflow-x: auto; scrollbar-width: none; -ms-overflow-style: none; white-space: nowrap;
}
.topbar .langs::-webkit-scrollbar { display: none; }
.topbar .chip {
  font-size: 0.76rem; padding: 0.22rem 0.5rem; border-radius: 999px;
  border: 1px solid var(--rule-strong); color: var(--ink-secondary); text-decoration: none;
  white-space: nowrap;
}
.topbar .chip[aria-current="true"] { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 999px; border: 1px solid var(--rule-strong);
  background: transparent; color: var(--ink); cursor: pointer; flex: 0 0 auto;
}
.icon-btn svg[hidden] { display: none; }
section { scroll-margin-top: 60px; }

/* ---------- Layout ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 0 1.1rem; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
@media (min-width: 1040px) {
  .layout { grid-template-columns: minmax(0, 720px) 220px; column-gap: 2.4rem; align-items: start; }
}
.content { min-width: 0; padding-block: 2.4rem 4rem; }
.rail {
  display: none;
}
@media (min-width: 1040px) {
  .rail {
    display: block; position: sticky; top: 64px; padding-top: 2.4rem;
    font-family: -apple-system, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  }
  .rail ol { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--rule); }
  .rail li { margin: 0; }
  .rail a {
    display: block; padding: 0.4rem 0 0.4rem 0.9rem; margin-left: -1px;
    border-left: 2px solid transparent; font-size: 0.82rem; color: var(--ink-muted);
    text-decoration: none; line-height: 1.3;
  }
  .rail a[aria-current="true"] { color: var(--ink); border-left-color: var(--accent); font-weight: 600; }
}

/* ---------- Hero ---------- */
.hero { padding-top: 0.6rem; }
.kicker {
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent-ink); margin: 0 0 0.7rem;
}
h1 {
  font-size: clamp(2rem, 1.55rem + 2vw, 3rem); line-height: 1.12; margin: 0 0 0.9rem; font-weight: 600;
  letter-spacing: -0.01em;
}
.deck {
  font-size: 1.2rem; line-height: 1.55; color: var(--ink-secondary); margin: 0 0 1.4rem; max-width: 42em;
}
.byline {
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.8rem; color: var(--ink-muted); margin: 0 0 2rem;
  display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center;
}
.byline .dot::before { content: "·"; margin-right: 0.6rem; color: var(--rule-strong); }

h2 {
  font-size: 1.55rem; line-height: 1.25; margin: 2.6rem 0 1rem; font-weight: 600; letter-spacing: -0.005em;
  scroll-margin-top: 64px;
}
h3 { font-size: 1.15rem; margin: 1.8rem 0 0.7rem; font-weight: 600; }
p { margin: 0 0 1.1rem; }
strong { font-weight: 650; }
ul, ol { margin: 0 0 1.2rem; padding-left: 1.3rem; }
li { margin-bottom: 0.4rem; }
figure { margin: 1.6rem 0; }
figcaption {
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.82rem; color: var(--ink-muted); margin-top: 0.5rem; line-height: 1.45;
}
blockquote {
  margin: 1.4rem 0; padding: 0.2rem 0 0.2rem 1.1rem; border-left: 3px solid var(--accent);
  font-size: 1.08rem; color: var(--ink-secondary); font-style: italic;
}
blockquote cite { display: block; font-style: normal; font-size: 0.82rem; margin-top: 0.5rem; color: var(--ink-muted); }
code, .mono { font-family: "SF Mono", "IBM Plex Mono", Menlo, Consolas, monospace; font-size: 0.92em; background: var(--code-bg); border-radius: 4px; padding: 0.05em 0.35em; }

.callout {
  border: 1px solid var(--rule-strong); border-radius: 10px; padding: 1.1rem 1.2rem;
  background: var(--paper-raised); box-shadow: var(--shadow); margin: 1.6rem 0;
}
.callout.amber { border-color: color-mix(in srgb, var(--amber) 55%, var(--rule-strong)); background: var(--amber-soft); }
.callout.danger { border-color: color-mix(in srgb, var(--danger) 45%, var(--rule-strong)); background: var(--danger-soft); }
.callout h4 {
  margin: 0 0 0.5rem; font-family: -apple-system, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.78rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-secondary);
}
.callout p:last-child { margin-bottom: 0; }

/* ---------- Evidence ladder ---------- */
.ladder { list-style: none; margin: 1.6rem 0 2rem; padding: 0; counter-reset: rung; }
.rung {
  counter-increment: rung; position: relative; padding: 1.1rem 1.2rem 1.1rem 3.6rem;
  border: 1px solid var(--rule); border-radius: 10px; background: var(--paper-raised);
  margin-bottom: 0.9rem; box-shadow: var(--shadow);
}
.rung::before {
  content: counter(rung); position: absolute; left: 1.1rem; top: 1.1rem;
  width: 1.9rem; height: 1.9rem; border-radius: 999px; display: flex; align-items: center; justify-content: center;
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-weight: 700; font-size: 0.95rem;
  color: var(--paper); background: var(--rung-color, var(--accent));
}
.rung:nth-child(1) { --rung-color: var(--rung-1); }
.rung:nth-child(2) { --rung-color: var(--rung-2); }
.rung:nth-child(3) { --rung-color: var(--rung-3); }
.rung:nth-child(4) { --rung-color: var(--rung-4); }
.rung .tag {
  display: inline-block; font-family: -apple-system, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--rung-color, var(--accent)); margin-bottom: 0.3rem;
}
.rung h3 { margin: 0 0 0.4rem; font-size: 1.05rem; }
.rung p { margin: 0 0 0.5rem; font-size: 0.98rem; }
.rung p:last-child { margin-bottom: 0; }
.rung .evidence { font-size: 0.88rem; color: var(--ink-muted); }

/* ---------- Chronology ---------- */
.chrono { position: relative; margin: 1.6rem 0 2rem; padding-left: 1.6rem; border-left: 2px solid var(--rule); }
.chrono-item { position: relative; padding-bottom: 1.6rem; }
.chrono-item:last-child { padding-bottom: 0; }
.chrono-item::before {
  content: ""; position: absolute; left: -1.71rem; top: 0.35rem; width: 10px; height: 10px; border-radius: 999px;
  background: var(--accent); border: 2px solid var(--paper);
}
.chrono-date {
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.78rem; font-weight: 700; color: var(--ink-muted); letter-spacing: 0.02em; text-transform: uppercase;
}
.chrono-item h3 { margin: 0.2rem 0 0.4rem; font-size: 1.05rem; }
.chrono-item p { margin: 0 0 0.4rem; font-size: 0.98rem; }
.chrono-item p:last-child { margin-bottom: 0; }
.chrono-item .src { font-size: 0.82rem; color: var(--ink-muted); }

/* ---------- Sources table ---------- */
.src-table-wrap { overflow-x: auto; margin: 1.4rem 0 2rem; border: 1px solid var(--rule); border-radius: 10px; }
table.src-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; min-width: 640px; }
table.src-table th, table.src-table td {
  text-align: left; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--rule); vertical-align: top;
}
table.src-table th {
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted);
  background: var(--paper-raised);
}
table.src-table tr:last-child td { border-bottom: none; }
.status-pill {
  display: inline-block; font-family: -apple-system, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.7rem; font-weight: 700; padding: 0.12rem 0.5rem; border-radius: 999px; white-space: nowrap;
}
.status-pill.verified { background: var(--accent-soft); color: var(--accent-ink); }
.status-pill.extract { background: var(--amber-soft); color: var(--amber); }
.status-pill.unverified { background: var(--rule); color: var(--ink-secondary); }

/* ---------- Footer ---------- */
footer.site {
  border-top: 1px solid var(--rule); margin-top: 2rem; padding: 1.6rem 0 3rem;
  font-family: -apple-system, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 0.82rem; color: var(--ink-muted);
}
footer.site a { color: var(--ink-secondary); }
footer.site .foot-nav { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; margin-bottom: 0.9rem; }
footer.site p { margin: 0.3rem 0; }

.skip-link {
  position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff;
  padding: 0.6rem 1rem; border-radius: 0 0 8px 0; z-index: 100;
}
.skip-link:focus { left: 0; }
