/* FIX: Force the very first element in the article body to have NO top margin */
.article-body > h1:first-child,
.article-body > h2:first-child,
.article-body > h3:first-child,
.article-body > p:first-child {
  margin-top: 0 !important;
}

.article-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--color-border);
}
.article-header h1 {
  font-family: var(--font-ui);
  font-size: var(--size-h1);
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.3;
}
.coordinate {
  display: inline-block;
  font-family: var(--font-ui);
  font-size: var(--size-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

.article-body > p:first-child {
  font-family: var(--font-ui);
  font-size: var(--size-sm);
  color: var(--color-text-muted);
  background: var(--color-accent-soft);
  border-left: 3px solid var(--color-accent);
  padding: 0.75rem 1rem;
  margin-bottom: 2rem;
  line-height: 1.6;
}
.article-body h1 {
  font-family: var(--font-ui);
  font-size: var(--size-h1);
  font-weight: 700;
  color: var(--color-text);
  margin-top: 3.5rem;
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--color-border);
  line-height: 1.3;
}
.article-body h2 {
  font-family: var(--font-ui);
  font-size: var(--size-h2);
  font-weight: 700;
  color: var(--color-text);
  text-transform: none;
  letter-spacing: 0.01em;
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--color-border);
}
.article-body h2[id^="p0"],
.article-body h2[id^="p1"] {
  font-size: var(--size-base);
  font-weight: 700;
  color: var(--color-accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 1.8rem;
  margin-bottom: 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--color-border);
}
.article-body h3 {
  font-family: var(--font-ui);
  font-size: var(--size-h3);
  font-weight: 600;
  color: var(--color-text);
  margin-top: 1.5rem;
  margin-bottom: 0.4rem;
}

/* ── Menu subdivision levels ───────────────────────────────────────────────
   The menus use more levels than an article does, and each level has one job.
   Prominence decreases with depth, so the top band is always the most visible:
     h2               chapter        ## Biquaternions      dark, 2px rule
     h3 + a link      article entry  ### <a …>Title</a>     blue link
     h3 (no link)     category band  ### Theory            filled band
     h4               topic band     #### The Forms        bar, 3px
     h5               sub-topic tag  ##### Form            bar, 2px
   A label and an entry are both `###`, and they are told apart structurally:
   an entry wraps its title in a link, a label has no link — 1643/1643 against
   221/221, no exception. So the category band is selected by `:not(:has(a))`,
   and the menu needs no `-`, `--` or `---` in the source: the hashes alone
   carry the level.
   Every band rule is scoped to a menu page by `:has(> h3 > a)`. That test is
   exact: no article in the corpus has a link inside an `h3`, so an article
   page never matches and its own headings keep their plain style.
   The bands carry no `text-transform`: the level is told by size, by the
   accent bar and by the fill, so case in the source is shown as written. */
/* Level 3 — the category band. The strongest label signal in the menu: a
   filled band with a thick accent bar, larger and darker than anything under
   it, so it always outranks the topic and sub-topic bands it contains. */
.article-body:has(> h3 > a) > h3:not(:has(a)) {
  font-family: var(--font-ui);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
  background: var(--color-accent-soft);
  border-left: 5px solid var(--color-accent);
  padding: 0.5rem 0.9rem;
  margin-top: 2.6rem;
  margin-bottom: 0.9rem;
}
/* Level 4 — the topic band. Same size as the article titles (--size-h3), so it
   is never smaller than the entries it holds; it sits one notch down by the
   thinner bar and the missing fill. */
.article-body:has(> h3 > a) > h4 {
  font-family: var(--font-ui);
  font-size: var(--size-h3);
  font-weight: 700;
  color: var(--color-text);
  padding-left: 0.7rem;
  border-left: 3px solid var(--color-accent);
  margin-top: 1.8rem;
  margin-bottom: 0.4rem;
}
/* Level 5 — the sub-topic tag. Same size as the article titles, told apart by
   the thinnest bar and the grey tone. Bar thickness separates the three bands. */
.article-body:has(> h3 > a) > h5 {
  font-family: var(--font-ui);
  font-size: var(--size-h3);
  font-weight: 700;
  color: #444;
  padding-left: 0.7rem;
  border-left: 2px solid var(--color-accent);
  margin-top: 1.2rem;
  margin-bottom: 0.3rem;
}
.article-body h1 strong,
.article-body h2 strong,
.article-body h3 strong {
  font-size: inherit;
  color: inherit;
  font-family: inherit;
}
.article-body p { font-size: var(--size-base); margin-bottom: 0.4rem; }
.article-body strong { color: #444; font-family: var(--font-ui); font-size: var(--size-sm); }
.article-body ul { padding-left: 1.5rem; margin-bottom: 1rem; }
.article-body li { margin-bottom: 0.4rem; font-size: var(--size-base); }
.index-list { list-style: none; padding: 0; }
.index-list li { margin-bottom: 1rem; }
.index-list a { font-family: var(--font-ui); font-size: var(--size-base); font-weight: 600; }
.index-summary {
  font-family: var(--font-ui);
  font-size: var(--size-sm);
  color: var(--color-text-muted);
  margin: 0.2rem 0 0 0;
  line-height: 1.5;
}

/* ===== Tables =====
   Ruled-grid style: every cell gets a rule, so a Markdown table reads like the
   grid tables this series used to write as LaTeX arrays. */
.article-body table {
  border-collapse: collapse;
  margin: 1.4rem 0;
  font-size: var(--size-base);
}
.article-body th,
.article-body td {
  border: 1px solid var(--color-border);
  padding: 0.4rem 0.75rem;
  text-align: left;
  vertical-align: top;
}
.article-body thead th {
  background: var(--color-surface);
  font-family: var(--font-ui);
  font-size: var(--size-sm);
  font-weight: 600;
}
.article-body table .katex { font-size: 1em; }

/* Wide tables scroll inside their own box instead of widening the page.
   The wrapper is added by build.py: a <table> cannot clip its own overflow.
   `contain: paint` is needed because without it Chrome still counts the
   table's overflow in the document's scrollable area, giving the page a
   horizontal scrollbar even though the wrapper clips. */
.article-body .table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  contain: paint;
  margin: 1.4rem 0;
}
.article-body .table-scroll > table {
  margin: 0;
}

@media (max-width: 768px) {
  .article-body th,
  .article-body td { padding: 0.3rem 0.45rem; }
}

/* ===== KaTeX math rendering ===== */
.article-body .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.5rem 0;
  margin: 1.25rem 0;
}
.article-body .katex-display > .katex {
  font-size: 1.05em;
}
.article-body .katex {
  font-size: 1.05em;
}
.article-body {
  overflow-wrap: break-word;
}
.article-body .katex-display {
  /* background: var(--color-accent-soft); */
  /* border-radius: 4px; */
}
