/* ------------------------------------------------------------
   AI core write-up. Plain cream page; the type does the work.
   ------------------------------------------------------------ */

:root {
  --ink:   #2b2622;
  --muted: #8a7f72;
  --red:   #b23b2e;   /* links only */
  --bg:    #efe8da;
  --panel: #f4efe6;   /* figure panels sit on this */
  --rule:  #d9cfba;
  --code:  #e6decd;   /* code background, a shade darker than the page */

  --sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bar-h: 3rem;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* ---------- top bar ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--bar-h);
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}
.bar-inner {
  box-sizing: content-box;
  max-width: 700px;
  height: 100%;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.back {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
}
.back::before { content: "\2190\00a0"; }
.back:hover { color: var(--ink); }

.toc-toggle {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 0.3rem 0;
  cursor: pointer;
}
.toc-toggle:hover, .toc-toggle[aria-expanded="true"] { color: var(--ink); }

/* ---------- column ---------- */
.col {
  box-sizing: content-box;
  max-width: 700px;
  margin: 0 auto;
  padding: 3rem 16px 6rem;
}

/* ---------- contents ---------- */
.toc {
  display: none;
  position: fixed;
  top: var(--bar-h);
  left: 0;
  right: 0;
  z-index: 25;
  max-height: calc(100vh - var(--bar-h));
  overflow-y: auto;
  padding: 0.9rem 16px 1.2rem;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}
.toc.open { display: block; }

.toc-part {
  margin: 1rem 0 0.2rem;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted);
}
.toc-part:first-child { margin-top: 0; }

.toc-link {
  display: block;
  padding: 0.22rem 0;
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--muted);
  text-decoration: none;
}
.toc-link:hover, .toc-link.active { color: var(--ink); }

@media (min-width: 1280px) {
  .toc-toggle { display: none; }
  .toc {
    display: block;
    top: calc(var(--bar-h) + 2.6rem);
    left: calc(50% + 430px + 24px);
    right: auto;
    width: min(190px, calc(50vw - 430px - 36px));
    max-height: calc(100vh - var(--bar-h) - 5rem);
    padding: 0;
    background: none;
    border: 0;
  }
}

/* ---------- headings and prose ---------- */
.sec { margin-top: 3rem; scroll-margin-top: calc(var(--bar-h) + 1rem); }
article > .sec:first-child { margin-top: 0; }

.sec-title { font-weight: 600; letter-spacing: -0.015em; line-height: 1.2; text-wrap: balance; }
h1.sec-title { font-size: 2.2rem; }
h2.sec-title { font-size: 1.6rem; }

h3 {
  margin-top: 2.1rem;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.3;
}

.meta {
  margin-top: 0.6rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}
.meta a { color: var(--muted); }
.meta + p { margin-top: 1.5rem; }

p { margin-top: 1.1rem; }
.sec-title + p, h3 + p { margin-top: 0.8rem; }

strong { font-weight: 600; }

ul, ol { margin-top: 1.1rem; padding-left: 1.4rem; }
li { margin-top: 0.4rem; }
li::marker { color: var(--muted); }

a {
  color: var(--red);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
a:hover { text-decoration-thickness: 2px; }

code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--code);
  border-radius: 2px;
  padding: 0.08em 0.32em;
}
pre {
  margin: 1.4rem 0;
  padding: 1rem 1.15rem;
  background: var(--code);
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.6;
}
pre code { background: none; padding: 0; font-size: inherit; }

table { width: 100%; margin: 1.4rem 0; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--rule); text-align: left; }
th { font-weight: 600; }

/* ---------- part dividers ---------- */
.part {
  margin-top: 4.5rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--rule);
  font-size: 0.86rem;
  color: var(--muted);
  scroll-margin-top: calc(var(--bar-h) + 1rem);
}
.part + .sec { margin-top: 1.8rem; }

/* ---------- figures ---------- */
.fig { margin: 1.3rem 0; }

.fig-img img { display: block; width: 100%; height: auto; margin: 0 auto; }

.fig-frame { overflow: hidden; }
.fig-frame iframe { display: block; width: 100%; margin: 0 auto; border: 0; background: transparent; }

/* diagrams that may be wider than the text column (up to 860px) */
.fig-wide {
  position: relative;
  left: 50%;
  width: min(860px, calc(100vw - 32px));
  transform: translateX(-50%);
}

.fig-video video { display: block; width: 100%; height: auto; background: var(--ink); }

.fig-missing {
  padding: 2rem 1rem;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--muted);
  border: 1px dashed var(--muted);
}

/* ---------- colophon ---------- */
.colophon {
  margin-top: 4rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule);
  font-size: 0.9rem;
  color: var(--muted);
}
.colophon p { margin-top: 0.4rem; }
.colophon p:first-child { margin-top: 0; }

@media (max-width: 560px) {
  body { font-size: 16px; }
  h1.sec-title { font-size: 1.8rem; }
  h2.sec-title { font-size: 1.45rem; }
  .col { padding-top: 2.2rem; }
  .part { margin-top: 3.5rem; }
}
