/* Base element defaults so bare server-rendered HTML looks right before any
   component classes are applied. Selectors use :where() (zero specificity) so
   components and consumers override without a fight; layer order (see
   index.css) keeps these below the components layer regardless. */

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

:where(body) {
  margin: 0;
  font-family: var(--govbb-font-sans);
  font-size: var(--govbb-font-size-body);
  line-height: var(--govbb-line-height-base);
  color: var(--govbb-color-ink);
  background: var(--govbb-color-surface);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Text elements own typography, not layout. Reset browser margins so spacing
   comes from surrounding layout or component styles. Sizes come from the ramp
   so bare server-rendered HTML is right with no classes at all; h5 matches
   body and leans on weight, as the NHS scale does at its smallest heading. */
:where(h1, h2, h3, h4, h5, h6) {
  margin-block: 0;
  font-weight: 600;
  line-height: 1.2;
  text-wrap: balance;
}

:where(h1) {
  font-size: var(--govbb-font-size-h1);
  line-height: var(--govbb-line-height-h1);
}

:where(h2) {
  font-size: var(--govbb-font-size-h2);
  line-height: var(--govbb-line-height-h2);
}

:where(h3) {
  font-size: var(--govbb-font-size-h3);
  line-height: var(--govbb-line-height-h3);
}

:where(h4) {
  font-size: var(--govbb-font-size-h4);
}

:where(h5) {
  font-size: var(--govbb-font-size-body);
}

:where(h6) {
  font-size: var(--govbb-font-size-body-sm);
}

:where(p) {
  margin-block: 0;
  text-wrap: pretty;
}

:where(a) {
  color: var(--govbb-link-color);

  /* 0.1em is 2px at body size, and holds at any other size. */
  text-underline-offset: 0.1em;
  text-decoration-thickness: max(1px, 0.0625em);
}

:where(a:hover) {
  color: var(--govbb-link-hover-color);
  background-color: var(--govbb-link-hover-bg);
}

:where(::placeholder) {
  color: var(--govbb-color-muted);
  opacity: 1; /* Firefox dims placeholders by default */
}

/* Default keyboard focus ring for anything without its own. Components with
   bespoke rings override via the components layer. */
:where(:focus-visible) {
  outline: 4px solid var(--govbb-color-focus);
  outline-offset: 2px;
}

/* Links focus with the gold highlight, not the ring — matches .govbb-link,
   error-summary and show/hide. After the ring rule so the outline reset wins
   at equal (zero) specificity. */
:where(a:focus-visible) {
  color: var(--govbb-link-active-color);
  background-color: var(--govbb-link-active-bg);

  /* invisible normally; forced-colors mode strips the gold background and
     recolours this outline, so keyboard focus stays visible (WCAG 2.4.7) */
  outline: 2px solid transparent;
  text-decoration: none;
}

/* Collapse every transition (state fades, the show/hide triangle rotation)
   for users who ask for reduced motion. Animations are guarded too, so the
   first component to ship @keyframes is covered automatically. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0s;
    animation-duration: 0.01ms;
    animation-iteration-count: 1;
    scroll-behavior: auto;
  }
}
