/* ============================================================================
 * Heliomath BASE — bare-element defaults for the Heliomath design system.
 *
 * The "base" (a.k.a. "elements") layer: raw HTML elements — body, headings,
 * paragraphs, links, lists, rules, media, form controls — wired to the design
 * tokens. This is the styling every page gets for free, without adding a single
 * class.
 *
 * WHAT LIVES HERE:  element selectors only (body, h1, p, a, ul, hr, img …).
 * WHAT DOES NOT:    component classes (buttons, cards, forms → heliomath_
 *                   components*.css) and utilities. Litmus test — if a rule
 *                   needs a class or an id to do its job, it is NOT base.
 *
 * TOKENS: consume tokens (colour, type, structure) from heliomath_tokens.css —
 * the single, self-contained foundation. Load it BEFORE this file. Never
 * hard-code a hex or a raw px type size here.
 *
 * NO SELECTOR SCOPE — BY DESIGN. Like grokkoli_base.css, this file styles bare
 * elements and relies on CONTROLLED LOADING, not a wrapper class, to stay off
 * the wrong pages. Two rules make that safe:
 *   1. Load this file ONLY on Heliomath pages that are ready for it. The link
 *      tag IS the opt-in; a page that doesn't load it is untouched, and
 *      Grokkoli/legacy pages never receive it.
 *   2. Load it AFTER the legacy CSS (Bootstrap, base.css, grokkoli_base.css) so
 *      these bare selectors win on source order. Loading via {% block
 *      extra_head %} guarantees this (extra_head renders last in <head>).
 * Cascade order within the system: tokens -> base -> components -> utilities.
 * ========================================================================== */

/* --- Fonts --------------------------------------------------------------- *
 * Quicksand — the decorative display face (--font-family-decorative: the hero display
 * type AND the testimonial quote mark). Its @font-face lives only in grokkoli_base.css,
 * which Heliomath doesn't load — so without this the decorative font silently falls back
 * to Nunito everywhere. Declared here in the foundation so it renders on EVERY Heliomath
 * page (home, educators, pricing, …) consistently. */
@font-face {
    font-family: 'Quicksand';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: local(''),
         url("../webfonts/quicksand/Quicksand-Regular.a541d4e66100.woff2") format('woff2'),
         url("../webfonts/quicksand/Quicksand-Regular.7194c41ffab5.ttf") format('truetype');
}

/* --- Box model ----------------------------------------------------------- *
 * border-box makes width/padding intuitive. (Bootstrap's Reboot already sets
 * this; asserted here so the base is self-sufficient.) */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* --- No horizontal scroll (global) --------------------------------------- *
 * The page must NEVER scroll horizontally: clip any accidental overflow so a stray
 * too-wide element (a min-width, a long unbroken string, a full-bleed calc) can't
 * open a scrollable dead gutter on the right — most visible at ~320-360px phone
 * widths. base.css/Bootstrap used to mask this; now it's owned here. Genuinely wide
 * content (data tables, code) must still get its OWN overflow-x:auto wrapper — this
 * only forbids the PAGE from scrolling.
 *
 * `hidden` is the floor-safe clamp (Safari 14.1+), on BOTH html AND body because
 * overflow-x on <html> alone doesn't clamp the page in Chromium. Where supported
 * (Chrome 90+ / Safari 16+ / Firefox 81+) we upgrade to `clip`, which clips WITHOUT
 * turning <body> into a scroll container — so position:sticky (e.g. the blog
 * sidebar, which is why heliomath_blog.css forces #main overflow:unset) keeps
 * working. On older Safari the `hidden` fallback still kills h-scroll; a sticky
 * element there just won't stick — an acceptable degradation on a tiny share. */
html,
body {
    overflow-x: hidden;
}
@supports (overflow-x: clip) {
    html,
    body {
        overflow-x: clip;
    }
}

/* --- Page / body defaults ------------------------------------------------ *
 * The inherited baseline every descendant starts from: brand font, comfortable
 * body size, generous line-height, primary ink, and the beige page surface
 * (not white — cuts glare for the audience). */
body {
    margin: 0;                              /* zero the UA's default 8px body margin (was supplied by base.css); full-bleed sections/hero must reach the viewport edge */
    font-family: var(--font-family-base);
    font-size: var(--type-body-size);       /* ~17px — comfortable body default for the audience */
    line-height: var(--type-body-line);     /* 1.6 */
    font-weight: var(--font-weight-regular);
    color: var(--text-primary);
    background-color: var(--surface-default);
    -webkit-text-size-adjust: 100%;         /* stop iOS inflating text on rotate */
}

/* --- Headings ------------------------------------------------------------ *
 * Shared: reset browser margins to a single bottom gap (em-relative, so the
 * rhythm scales with the heading's own size), semibold weight, primary ink.
 * Per-level: size + line-height straight from the type scale. */
h1, h2, h3, h4, h5, h6 {
    margin: 0 0 0.5em;
    font-weight: var(--font-weight-semibold);   /* 600 by default — one consistent heading weight; go heavier only via an explicit override */
    color: var(--text-lively);
}

h1 { font-size: var(--type-h1-size); line-height: var(--type-h1-line); }
h2 { font-size: var(--type-h2-size); line-height: var(--type-h2-line); }
h3 { font-size: var(--type-h3-size); line-height: var(--type-h3-line); }
h4 { font-size: var(--type-h4-size); line-height: var(--type-h4-line); }
/* The type scale is authored for h1-h4; h5/h6 are rare, so they fall back to
 * body / small sizes (still semibold) rather than inventing new scale steps. */
h5 { font-size: var(--type-body-size);       line-height: var(--type-body-line); }
h6 { font-size: var(--type-body-small-size); line-height: var(--type-body-small-line); }

/* --- Body copy & inline text --------------------------------------------- */
p {
    margin: 0 0 1em;
}
/* No trailing bottom margin when a flow element is the LAST thing in its container,
 * so a container's bottom edge matches its top (that dangling margin was stacking on
 * top of the section/container padding, making the bottom look heavier). Covers every
 * block that carries a bottom margin — extends the long-standing p:last-child rule. */
p:last-child,
ul:last-child,
ol:last-child,
li:last-child,
h1:last-child, h2:last-child, h3:last-child,
h4:last-child, h5:last-child, h6:last-child {
    margin-bottom: 0;
}

strong, b {
    font-weight: var(--font-weight-semibold);
}

small {
    font-size: var(--type-caption-size);    /* 14px — fine print, not body copy */
}

/* --- Links --------------------------------------------------------------- *
 * Body links: brand link blue, always underlined (the underline is the
 * non-colour signal, so links are distinguishable without relying on hue). */
a {
    color: var(--link);
    text-decoration: underline;
}
a:hover  { color: var(--link-hover); }
a:active { color: var(--link-active); }

/* Focus ring — shown on ANY focus, INCLUDING mouse/pointer press (deliberately
 * NOT gated to :focus-visible, so the ring shows on click too, per Eric). It's a
 * box-shadow ring with outline:none. Floor-safe. */
a:focus {
    outline: none;
    box-shadow: var(--focus-ring-link);
    /* Pill-shaped ring (follows the same contour as the buttons + the style-guide
     * links), with a little horizontal room so the rounded ends clear the text; the
     * equal negative margin cancels it so surrounding text doesn't shift. */
    border-radius: var(--radius-pill);
    padding-left: 0.4em;
    padding-right: 0.4em;
    margin-left: -0.4em;
    margin-right: -0.4em;
    /* Drop the underline while pressed — the pill IS the affordance here. (Harmless on
     * button links, which carry no underline.) */
    text-decoration: none;
}
/* Fill the pill with the link's colour @ 30% (matches the ring). Kept as a SEPARATE
 * selector so it can skip button links: a bare `a:focus` (0,1,1) would out-specify a
 * .btn variant's own fill (0,1,0) and repaint a focused <a class="btn"> translucent
 * azure. The ring/padding above are already neutralised on buttons by the .btn /
 * .main-cta focus rules; this excludes them from the fill too. .nav-link is excluded
 * as well — the nav pills own their box + a text-colour ring (heliomath_nav.css /
 * marketing.css), no link fill. .logo AND .navbar-brand (the nav wordmark link) are excluded
 * too — the wordmark links are images, not text, so they take no pill (their ring/padding
 * reset lives in heliomath_components.css). --link-fill is surface-overridable (on-dark
 * contexts re-point it; see the tokens). */
a:focus:not(.btn):not(.main-cta):not(.nav-link):not(.logo):not(.navbar-brand):not(.logo-link) {
    background-color: var(--link-fill);
}

/* --- Lists --------------------------------------------------------------- */
ul, ol {
    margin: 0 0 1em;
    padding-left: 1.5em;
}
li {
    margin-bottom: 0.25em;
}

/* --- Media --------------------------------------------------------------- *
 * Never overflow the container; preserve aspect ratio. */
img, svg, video {
    max-width: 100%;
    vertical-align: middle;   /* was supplied by base.css; kills the inline baseline gap under images/svg */
}
img, video {
    height: auto;
}

/* --- Tables -------------------------------------------------------------- *
 * Collapse borders (the comparison + legal pages render <table>s). Was base.css. */
table {
    border-collapse: collapse;
}
th {
    text-align: inherit;
    font-weight: var(--font-weight-semibold);
}

/* --- Rules / dividers ---------------------------------------------------- */
hr {
    border: 0;
    border-top: var(--border-hairline);
    margin: 1.5em 0;
}

/* --- Form controls ------------------------------------------------------- *
 * Only the inheritance fix belongs in base — browsers do NOT inherit font or
 * colour into form controls, so without this they'd render in the UA default.
 * All *visual* form styling (fills, borders, focus) is a component concern. */
button, input, select, textarea {
    margin: 0;              /* browsers don't zero control margins; was supplied by base.css */
    font: inherit;
    color: inherit;
}

/* --- Text selection ------------------------------------------------------ */
::selection {
    background-color: var(--accent-primary);
    color: var(--text-on-dark-fill);
}

/* --- Font-preload hack --------------------------------------------------- *
 * external_base/home_base render a <div class="font-load-forcing"> (three throwaway
 * glyph divs) to force the webfonts to paint early. It MUST be visually hidden and
 * out of flow — its hide rule lived in grokkoli_base.css, which Heliomath does NOT
 * load, so without this the divs render as stray text at the very top of every page
 * (a light band above the content — most visible on the dark auth pages). A class,
 * not a bare element, but it belongs with the global page defaults. */
.font-load-forcing {
    position: absolute;
    visibility: hidden;
}
