/*
 * RA Builder — Global typography binding  (RA-M0-GLOBAL-02 consumer)
 * ---------------------------------------------------------------------------
 * SINGLE shared source, loaded on BOTH surfaces so editor == frontend:
 *   • frontend  — enqueued by RA_Builder_Canvas_Template alongside ra-page.css
 *   • editor    — enqueued by RA_Builder_Assets; the IframeCanvas clones every
 *                 parent <link rel=stylesheet> into the frame, so it lands there too.
 * The SAME bytes render on both — no per-surface duplication.
 *
 * WHY THIS FILE EXISTS
 * --------------------
 * `buildGlobalStylesRule()` / `build_global_styles_rule()` emit the design tokens
 * (`--ra-font-{h1..h6,body,label}-{family,size,weight,line-height,letter-spacing,
 * text-transform}`) onto `.ra-builder-document`, but NOTHING consumed them, so every
 * text tag fell back to the wrapping theme's font — headings rendered the theme serif.
 * This stylesheet is the token→tag BINDING. It is 100% static: it does NOT change the
 * CSS-engine node emission, so the FE==BE==EDITOR parity fixtures stay byte-identical.
 *
 * THE CASCADE (why it is built the way it is)
 * -------------------------------------------
 * A text/heading WIDGET renders as `<div class="ra-widget … ra-node-{id}"><h1>…</h1></div>`:
 * the CSS engine sets per-node font on the WRAPPER `.ra-node-{id}`; the bare inner tag
 * INHERITS it. Two forces fight that inherited value on the tag:
 *   1. the active theme's DIRECT `h1{font-family:…}` (specificity 0,0,1) beats inheritance,
 *   2. a DIRECT token value placed on the tag would ALSO block the wrapper's per-node value.
 * So the binding is split so BOTH "per-node wins" AND "beat the theme" hold:
 *
 *   (B) WRAPPER DEFAULT — seed the widget wrapper with its level's global token as the
 *       DEFAULT font. Wrapped in `:where()` → specificity (0,0,0), so the engine's
 *       per-node `.ra-node-{id}` rule (0,1,0) ALWAYS wins. When the node sets nothing,
 *       the token is the default; when it sets font-size, the node value wins. The bare
 *       inner tag inherits whichever applies.
 *
 *   (A) TAG INHERIT — force the bare content tag to INHERIT its wrapper's font, at
 *       specificity (0,2,1) so it out-ranks the theme's direct (0,0,1) tag rule. This is
 *       the CJ-012 `color:inherit` principle extended to the font properties. `:not([class])`
 *       restricts it to the bare tags the text/heading widgets emit — composite widgets
 *       (`.ra-widget-hero__title`, `.ra-widget-card__title`, …) are classed and keep their
 *       own scale untouched.
 *
 * Net: unset heading → global token scale (sans, never theme serif); per-node override →
 * wins (0,1,0 > 0,0,0); theme direct tag rule → loses (0,2,1 > 0,0,1). Identical on both
 * surfaces because it is the same file. Every value degrades gracefully via `var(…, inherit)`.
 */

/* ── Base / body ─────────────────────────────────────────────────────────────
 * The document root is the base font for all inherited body text. A direct value on
 * `.ra-builder-document` beats the theme's inherited `body{font-family}`. The family
 * default is the design system's primary sans stack (Inter → system-ui), so absent an
 * explicit `--ra-font-body-family` token the page is sans-serif, NOT the theme serif. */
.ra-builder-document {
  font-family: var(--ra-font-body-family, 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif);
  font-size: var(--ra-font-body-size, inherit);
  font-weight: var(--ra-font-body-weight, inherit);
  line-height: var(--ra-font-body-line-height, inherit);
  letter-spacing: var(--ra-font-body-letter-spacing, inherit);
}

/* ── (B) Per-level wrapper defaults ──────────────────────────────────────────
 * Zero specificity (:where) so ANY `.ra-node-{id}` engine style overrides the default.
 * `:has(> h1)` / `:has(> a > h1)` matches the heading WIDGET (its heading is a direct
 * child, optionally under a link) but NOT composite widgets whose headings are nested
 * deeper, so a hero/card title keeps its own styling. `--ra-font-h{n}-family` defaults
 * to `inherit` → the body sans above, so a distinct display font is opt-in per token. */
:where(.ra-builder-document .ra-widget:has(> h1), .ra-builder-document .ra-widget:has(> a > h1)) {
  font-family: var(--ra-font-h1-family, inherit);
  font-size: var(--ra-font-h1-size, inherit);
  font-weight: var(--ra-font-h1-weight, inherit);
  line-height: var(--ra-font-h1-line-height, inherit);
  letter-spacing: var(--ra-font-h1-letter-spacing, inherit);
  text-transform: var(--ra-font-h1-text-transform, inherit);
}
:where(.ra-builder-document .ra-widget:has(> h2), .ra-builder-document .ra-widget:has(> a > h2)) {
  font-family: var(--ra-font-h2-family, inherit);
  font-size: var(--ra-font-h2-size, inherit);
  font-weight: var(--ra-font-h2-weight, inherit);
  line-height: var(--ra-font-h2-line-height, inherit);
  letter-spacing: var(--ra-font-h2-letter-spacing, inherit);
  text-transform: var(--ra-font-h2-text-transform, inherit);
}
:where(.ra-builder-document .ra-widget:has(> h3), .ra-builder-document .ra-widget:has(> a > h3)) {
  font-family: var(--ra-font-h3-family, inherit);
  font-size: var(--ra-font-h3-size, inherit);
  font-weight: var(--ra-font-h3-weight, inherit);
  line-height: var(--ra-font-h3-line-height, inherit);
  letter-spacing: var(--ra-font-h3-letter-spacing, inherit);
  text-transform: var(--ra-font-h3-text-transform, inherit);
}
:where(.ra-builder-document .ra-widget:has(> h4), .ra-builder-document .ra-widget:has(> a > h4)) {
  font-family: var(--ra-font-h4-family, inherit);
  font-size: var(--ra-font-h4-size, inherit);
  font-weight: var(--ra-font-h4-weight, inherit);
  line-height: var(--ra-font-h4-line-height, inherit);
  letter-spacing: var(--ra-font-h4-letter-spacing, inherit);
  text-transform: var(--ra-font-h4-text-transform, inherit);
}
:where(.ra-builder-document .ra-widget:has(> h5), .ra-builder-document .ra-widget:has(> a > h5)) {
  font-family: var(--ra-font-h5-family, inherit);
  font-size: var(--ra-font-h5-size, inherit);
  font-weight: var(--ra-font-h5-weight, inherit);
  line-height: var(--ra-font-h5-line-height, inherit);
  letter-spacing: var(--ra-font-h5-letter-spacing, inherit);
  text-transform: var(--ra-font-h5-text-transform, inherit);
}
:where(.ra-builder-document .ra-widget:has(> h6), .ra-builder-document .ra-widget:has(> a > h6)) {
  font-family: var(--ra-font-h6-family, inherit);
  font-size: var(--ra-font-h6-size, inherit);
  font-weight: var(--ra-font-h6-weight, inherit);
  line-height: var(--ra-font-h6-line-height, inherit);
  letter-spacing: var(--ra-font-h6-letter-spacing, inherit);
  text-transform: var(--ra-font-h6-text-transform, inherit);
}

/* ── (B) Label / eyebrow hook ────────────────────────────────────────────────
 * Zero specificity so a per-node style still wins. Binds the `--ra-font-label-*`
 * preset (uppercase, tracked) to bare `<label>` and the hero eyebrow class. */
:where(.ra-builder-document label:not([class]), .ra-builder-document .ra-widget-hero__eyebrow) {
  font-family: var(--ra-font-label-family, inherit);
  font-size: var(--ra-font-label-size, inherit);
  font-weight: var(--ra-font-label-weight, inherit);
  line-height: var(--ra-font-label-line-height, inherit);
  letter-spacing: var(--ra-font-label-letter-spacing, inherit);
  text-transform: var(--ra-font-label-text-transform, inherit);
}

/* ── (A) Tag inherit — beat the theme, keep per-node ──────────────────────────
 * `.ra-builder-document :is(tag):not([class])` = specificity (0,2,1), out-ranking the
 * theme's direct `h1{font-family:…}` (0,0,1). It forces the bare content tag to take its
 * wrapper's computed font — which is the per-node value when set, else the (B) token
 * default. `:not([class])` scopes it to the bare tags text/heading widgets emit, leaving
 * every classed widget-internal tag (with its own design) alone. */
.ra-builder-document :is(h1, h2, h3, h4, h5, h6, p, li):not([class]) {
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
}
