/* 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: the four bands are one ladder, and every
   signal a level carries — the fill, the accent bar and the text tone — is one
   notch softer than the level above, so the hierarchy is read without counting.
   The chapter is the exception, and the reason the ladder starts at all: it is
   inverted, a solid accent fill with white text, so the step from a chapter to
   the category band under it is a change of kind and not one more notch. The
   earlier pair of tints, 22% and 16%, moved every signal by a single notch and
   collapsed at reading distance: two pale blue-grey bands, told apart only by
   measuring them.
     h2               chapter        ## Biquaternions      solid accent, white text, bar 8px
     h3 (no link)     category band  ### Theory            fill 16%, bar 4px
     h4               topic band     #### The Forms        fill grey #e8e8e8
     h5               sub-topic tag  ##### Form            fill grey #f0f0f0, leading square
     h6               field tag      ###### Common Theory  no fill, bar 1px, leading dash
     p > a (only)     article entry  <a …>Title</a>        blue link
   The category band takes a tint of the accent #2a4a7f mixed with white (16%)
   and the chapter takes the accent itself; the topic and sub-topic bands take a
   neutral grey instead, so the two label families are told apart by hue as well
   as by depth — a grey fill is visible at a lightness where a blue tint of the
   same lightness reads as almost nothing.
   Against the page background #f7f6f2 the fill contrast falls 8.14, 1.20, 1.13,
   1.05 down the ladder, and the fifth step has nowhere left to go: one notch
   softer than #f0f0f0 is the page itself. The deepest level, the field tag that
   subdivides a structure into *Common Theory*, *Specific Theory*, *Form*,
   *Operators*, *Realification* and *Representations*, therefore drops the fill
   and keeps the bar and the tone. Its size does not drop with it: it stays at
   the article-title size, so a label is never smaller than the entries it
   holds, and it is told from an entry by tone — grey against accent blue — and
   by weight, 700 against 600.
   White on the accent measures 8.8 to 1, so the inverted chapter keeps its
   contrast without a heavier weight.
   A chapter also gets the widest margin (5rem above,
   against 2.2rem for a category), so its band never sits as close to the text
   above it as the next level down.
   A heading is a label and nothing else: every `##`, `###`, `####`, `#####` and
   `######` of a menu is a title. An article entry is not a heading, it is a
   paragraph whose only element child is the link, so the level is carried by the
   markup itself and the menu needs no `-`, `--` or `---` in the source either.
   Every band rule is scoped to `.menu`, the class the build puts on the body of
   the two menu pages, `maths.html` and `physics.html`. The scope must not be
   inferred from the body content: the earlier rule keyed on the entry
   signature `:has(> p > a:only-child)`, which also matched any article carrying
   a prose paragraph with a single link, and banded that article's headings. An
   `h4` would not do as the test either, because a shallow menu can stop at `h3`
   and carry no `h4` at all — `physics.md` is such a menu. The class is set from
   the page list in `build.py`, so a menu is banded by construction and an
   article page keeps its plain headings.
   The deepest a menu reaches is `######`
   (the Biquaternions → Algebra block of `maths.md`, where a section, the twelve
   structures and their field tags take the last three levels), and no page
   carries a `#######`, which markdown would not render as a heading anyway.
   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 2 — the chapter band, the top of the ladder and its one inverted step:
   a solid accent fill with white text, where every level below is a tint or a
   grey carrying dark text. The inversion is what tells a chapter from the
   category band under it; the earlier tints, 22% and 16%, did not. The band is
   also the tallest (79px against 54px at the default font size), on a size step
   of its own (1.95rem against 1.5rem),
   so the level is read before the words are read. The size is written here and
   not on `--size-h2`, because the token belongs to the article headings and the
   menus take their own step. When collapsed by the browser's outline an h2 and
   the h3 under it can otherwise read alike, so the chapter also takes the
   largest gap of the four. The menu-only fill replaces the bottom rule the
   generic h2 carries, which would add a second edge below it. */
.menu .article-body > h2 {
  font-family: var(--font-ui);
  font-size: 1.95rem;
  font-weight: 700;
  color: #ffffff;
  background: #2a4a7f;
  border-bottom: none;
  border-left: 8px solid #14243c;
  padding: 0.9rem 1.1rem;
  margin-top: 5rem;
  margin-bottom: 1.6rem;
}
/* Level 3 — the category band, one notch softer than the chapter: a pale tint
   where the chapter is solid, half the bar and a text tone below full black. */
.menu .article-body > h3:not(:has(a)) {
  font-family: var(--font-ui);
  font-size: 1.5rem;
  font-weight: 700;
  color: #373737;
  background: #dde2eb;
  border-left: 4px solid #5f779f;
  padding: 0.5rem 0.9rem;
  margin-top: 2.2rem;
  margin-bottom: 0.8rem;
}
/* Level 4 — the topic band. Same size as the article titles (--size-h3), so it
   is never smaller than the entries it holds. Its fill is a neutral grey, kept
   one notch above the sub-topic tag and below the category band. */
.menu .article-body > h4 {
  font-family: var(--font-ui);
  font-size: var(--size-h3);
  font-weight: 700;
  color: #464646;
  background: #e8e8e8;
  border-left: 3px solid #94a4bf;
  padding: 0.35rem 0.7rem;
  margin-top: 1.8rem;
  margin-bottom: 0.4rem;
}
/* Level 5 — the sub-topic tag, the softest band: a grey one shade lighter than
   the topic band, the thinnest bar and the greyest tone. It also carries a
   leading square, the marker of the titles that name a structure or a block
   (`##### Biquaternions as a Symmetric Plain Sesqualgebra (SPS) over …`), so
   that a level-5 label is told from a level-4 one before the fill is read.
   The square is drawn, not typed: a glyph would be one font away from an emoji
   square, while an empty box of 0.5em takes the exact hue of the topic band's
   bar and needs no fallback. The source keeps the bare title. */
.menu .article-body > h5 {
  font-family: var(--font-ui);
  font-size: var(--size-h3);
  font-weight: 700;
  color: #535353;
  background: #f0f0f0;
  border-left: 2px solid #cad2df;
  padding: 0.25rem 0.7rem;
  margin-top: 1.2rem;
  margin-bottom: 0.3rem;
}
.menu .article-body > h5::before {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  background: #94a4bf;
  vertical-align: middle;
  margin-right: 0.5em;
}
/* Level 6 — the field tag, the deepest label of a menu (`###### Common Theory`,
   `###### Specific Theory`, …). The grey fill has run out: one notch softer than
   #f0f0f0 is the page background itself, so this level carries no fill and no
   rounded band, only the thinnest bar, the greyest tone and a leading dash.
   The dash is the marker of a sub-item: the source keeps the bare title
   (`###### Common Theory`) and the hyphen comes from `content`, so the heading
   text stays clean for the outline, the anchors and any other consumer, and the
   tag reads as `- Common Theory` on the page.
   The size does not follow the fill down: it stays at the article-title size
   (--size-h3), the same invariant the two levels above obey, so a label is
   never smaller than the entries it holds. It is a title, not an entry: the
   tone is grey where an entry is accent blue. */
.menu .article-body > h6 {
  font-family: var(--font-ui);
  font-size: var(--size-h3);
  font-weight: 700;
  color: #666;
  background: none;
  border-left: 1px solid #dfe4ec;
  padding: 0.2rem 0.7rem;
  margin-top: 0.9rem;
  margin-bottom: 0.2rem;
}
.menu .article-body > h6::before {
  content: "- ";
}
/* The article entry. A paragraph whose only element child is the link, so a
   prose paragraph that happens to contain a link is not caught. Size and weight
   are the old entry level (`--size-h3`, weight 600): the entry reads as before,
   it is only no longer a heading. */
.menu .article-body > p:has(> a:only-child) {
  font-family: var(--font-ui);
  font-size: var(--size-h3);
  font-weight: 600;
  margin-top: 0.15rem;
  margin-bottom: 0.35rem;
}
/* A `__Title__` heading renders as `<h1><strong>Title</strong></h1>`. Without
   the weight reset below the base rule `strong { font-weight: 600 }` wins and
   the title is lighter than a plain heading at 700 — the same heading class
   rendering two weights. `inherit` makes the bold wrapper invisible inside a
   heading, so every heading renders at its own level's weight. */
.article-body h1 strong,
.article-body h2 strong,
.article-body h3 strong,
.article-body h4 strong,
.article-body h5 strong,
.article-body h6 strong {
  font-weight: inherit;
  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 =====
   A display formula cannot be broken across lines: KaTeX emits one nowrap
   line box, and no CSS property can insert a break inside it. So a formula
   wider than the column must scroll in its own box, exactly like a wide
   table. `overflow-x: auto` does that; `max-width: 100%` keeps the box inside
   the column whatever the formula's width; `overscroll-behavior-x: contain`
   stops a horizontal flick inside a formula from chaining to the page.
   Measured in Chromium: the box scrolls (scrollWidth 1354 against a 939
   clientWidth for the longest coordinate rule) and the page itself stays at
   exactly the viewport width. The left end is not clipped — scrollLeft 0
   shows the start of the formula — so no `width: max-content` wrapper is
   needed. */
.article-body .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  padding: 0.5rem 0;
  margin: 1.25rem 0;
  scrollbar-width: thin;
}
.article-body .katex-display > .katex {
  font-size: 1.05em;
}
.article-body .katex {
  font-size: 1.05em;
}
.article-body {
  overflow-wrap: break-word;
}
