/*
  Base — reset, box model, and default typography.
  Consumes tokens.css exclusively; no hardcoded colors/fonts here.
*/

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-ink);
  background: var(--color-surface);
  transition: background-color var(--transition-base), color var(--transition-base);
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  line-height: var(--leading-tight);
  margin: 0 0 var(--space-4);
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }

p {
  margin: 0 0 var(--space-4);
  /* NO `color` here, deliberately. `body` already sets --color-ink, so a
     paragraph in ordinary page flow inherits it — this rule only ever
     RE-asserted it, and in doing so outranked every container that owns
     its own colour pair. The footer's intro paragraph rendered
     #1A1F2B on #003287 in light mode: 1.6:1, effectively unreadable.

     Third time this project has shipped the same shape of bug (Day 2's
     --color-surface-as-text, Day 21's blanket `a { color }` over
     .btn--primary), so it is worth naming the general rule: a bare
     element selector must not set a theme text colour. Containers that
     sit on an always-dark surface (.site-footer, .hero, .topbar) set
     --color-on-dark on themselves and rely on inheritance to carry it
     down; any global element rule silently breaks that.

     Guarded by tests/test_stylesheets.py. */
}

p.lead {
  font-size: var(--text-lg);
  color: var(--color-muted);
}

/* The `:not(.btn)` on each of these is load-bearing, not tidiness.

   An <a class="btn btn--primary"> carries its own colour pair
   (--color-accent background, --color-accent-contrast text). A blanket
   `a { color: ... }` rule outranks `.btn--primary` the moment it picks
   up any extra specificity — and `:root[data-theme="dark"] a` (0,1,1)
   does exactly that against `.btn--primary` (0,1,0).

   The result, from Day 2 until the Day 21 audit caught it: in dark mode
   every anchor styled as a primary button rendered orange text on an
   orange background — an invisible label. It hit Log out, Apply Now, the
   homepage hero CTA, "+ Create Admin", "+ Add Hero Slide", the CMS
   sub-nav's active tab, and Day 20's "Download admission letter".
   `.btn--primary:hover` (0,2,0) *did* win, so the label appeared as soon
   as the pointer touched it — which is why it survived two previous
   audits and a lot of manual clicking.

   Anything that styles itself as a component belongs outside this rule,
   rather than being fought with specificity further down the cascade.

   TWO ESCAPE HATCHES, and they are the only ones:

     .btn         — an anchor that is a button. Excluded in the selector.
     .block-link  — an anchor that WRAPS a card, so the whole row is one
                    click target. Everything inside it (a name, a muted
                    preview, a timestamp) should keep the card's colours,
                    not become link-blue — which is exactly what the Day
                    27 messaging inbox did. Carried risk #6 since Day 21,
                    found by looking at the page rather than by a test.

   NOTE THE SHAPE OF THE SECOND HATCH. The obvious version —
   `a:not(.btn):not(.block-link)` — was written first and immediately
   broke the footer: adding a second `:not()` raises this rule from
   (0,1,1) to (0,2,1), which then outranks `.site-footer a` at (0,2,0),
   and every footer link turned navy-on-navy. Caught in a 420px
   screenshot, one fix after the fix.

   So the hatch is a LATER rule at EQUAL specificity, not a narrower
   selector. `a.block-link` is (0,1,1), the same as `a:not(.btn)`, and
   wins on order alone — leaving every container-scoped rule exactly
   where it was.

   Adding a third hatch means adding it here, the same way, not
   overriding this rule from a component stylesheet.
   `test_global_anchor_rule_lists_its_exclusions` fails if the two
   lists drift. */
a:not(.btn) {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}
.btn {
  text-decoration: none;
}
:root[data-theme="dark"] a:not(.btn) {
  color: var(--color-accent);
}
a:not(.btn):hover {
  color: var(--color-accent);
}

/* The card-link hatch. Equal specificity to the rule above, declared
   after it — see the note on why this is not another `:not()`. */
a.block-link,
a.block-link:hover,
:root[data-theme="dark"] a.block-link {
  color: inherit;
  text-decoration: none;
}

/* Visible keyboard focus everywhere — never suppressed. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

ul, ol {
  margin: 0 0 var(--space-4);
  padding-left: var(--space-5);
}

button {
  font-family: inherit;
}

/* Numeric/data type treatment — the platform's signature typographic
   device (see tokens.css comment). Applied via this utility class to
   stat counters, program duration/module badges, matricule numbers,
   reference numbers, etc. */
.font-mono {
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}
