/* Element defaults, with accessible behavior built in. Target: WCAG 2.2 AA. */
@layer base {
  html { font-size: 100%; }   /* respect the user's font-size setting */

  body {
    background: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--text-base);
    accent-color: var(--color-accent);   /* checkboxes, radios, ranges */
  }

  /* Readable line length for text and forms, wherever they appear. Lists
     with role="list" are layout, not text, so their items stay uncapped,
     and so are button_to's forms, which only wrap a single button.
     Set --measure on an element to narrow it and the text inside it. */
  :is(p, h1, h2, h3, h4, h5, h6, blockquote, figcaption, dd, form:not(.button_to)),
  :is(ul, ol):not([role="list"]) > li { max-inline-size: var(--measure); }

  /* Every level is sized, so none falls back to a browser default that's
     relative to its parent or, for h5 and h6, smaller than body text.
     h4 to h6 are body-sized and set apart by their bold weight. */
  h1 { font-size: var(--text-2xl); }
  h2 { font-size: var(--text-xl); }
  h3 { font-size: var(--text-lg); }
  :is(h4, h5, h6) { font-size: var(--text-base); }

  :is(h1, h2, h3, h4, h5, h6) { font-family: var(--font-heading); }

  /* A quoted passage from a book */
  blockquote {
    padding-inline-start: var(--space-3);
    border-inline-start: 3px solid var(--color-accent);
    font-family: var(--font-heading);
    font-style: italic;
  }

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

  :focus-visible {
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
  }

  /* Text-entry controls look the same wherever they appear, inside a .field
     or not. Button-like inputs are left to .btn. */
  :is(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="submit"], [type="button"], [type="reset"], [type="image"]), select, textarea) {
    padding: var(--control-padding-block) var(--control-padding-inline);
    background: var(--color-surface);
    color: var(--color-text);
    border: var(--control-border-width) solid var(--color-border-strong);
    border-radius: var(--radius-control);
  }

  /* aria-invalid marks a control the server rejected; :user-invalid one the
     browser rejected after the user touched it. */
  :is(input, select, textarea):is([aria-invalid="true"], :user-invalid) { border-color: var(--color-danger); }

  /* Comfortable targets (~44px) for controls */
  :is(button, select, input:not([type="checkbox"], [type="radio"])) { min-block-size: 2.75rem; }

  @media (prefers-reduced-motion: reduce) {
    :root { --duration-fast: 0ms; --duration-base: 0ms; }
  }

  @media (forced-colors: active) {
    :focus-visible { outline-color: Highlight; }
  }
}
