/* Cascade layer order is declared once, before any layer content.
   Later layers win regardless of selector specificity, so a plain .class in
   "components" beats an #id in "base". This is what makes @layer powerful. */
@layer tokens, base, layout, components, effects;

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

  * {
    margin: 0;
  }

  html {
    color-scheme: light;
    scroll-behavior: smooth;
    /* Anchored sections stop below the sticky header instead of under it */
    scroll-padding-top: calc(var(--header-h) + var(--space-s));
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
  }

  body {
    min-height: 100svh;
    font-family: var(--font-body);
    font-size: var(--step-0);
    line-height: 1.65;
    color: var(--color-ink);
    background: var(--color-surface);
    -webkit-font-smoothing: antialiased;
  }

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

  /* The width/height attributes on <img> act as CSS sizes. They're good:
     the browser reserves space before the image loads. But a fixed height
     would override CSS aspect-ratio, so let height follow the width. */
  img {
    height: auto;
  }

  h1,
  h2,
  h3 {
    line-height: 1.15;
    font-weight: 700;
    /* Balances line lengths in headings so there are no lonely last words */
    text-wrap: balance;
  }

  h1 { font-size: var(--step-4); }
  h2 { font-size: var(--step-3); }
  h3 { font-size: var(--step-1); }

  p {
    text-wrap: pretty;
    max-width: 65ch;
  }

  a {
    color: var(--color-primary);
    text-underline-offset: 0.2em;
  }

  :focus-visible {
    outline: 3px solid var(--color-accent);
    outline-offset: 3px;
    border-radius: 4px;
  }

  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
  }
}

/* Cross-page fade when moving between pages (Chrome/Edge over http(s);
   ignored elsewhere, e.g. when opened as a file://, with no harm) */
@view-transition {
  navigation: auto;
}
