/* Reset and element defaults. */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /*
   * The scrollbar's space is reserved whether there is a scrollbar or not.
   *
   * Pages here differ enormously in length — a rulebook is seventeen thousand
   * pixels, an empty My Reference is under a thousand — so on any platform with
   * classic scrollbars the gutter appears and disappears as you move between
   * them, and the whole layout, header included, jumps by its width each time.
   * Reserving it costs about fifteen pixels on the short pages and makes every
   * page the same width as every other. It also holds the line when an overlay
   * locks the body, which would otherwise shift the page underneath the thing
   * that just opened.
   */
  scrollbar-gutter: stable;
  /* Anchored headings clear the sticky header instead of hiding under it. */
  scroll-padding-top: calc(var(--header-height) + var(--section-bar-height) + var(--space-4));
}

@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;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-md);
  font-weight: var(--body-weight);
  line-height: var(--leading-normal);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/*
 * An open overlay must not scroll the page behind it. The lock goes on the
 * body alone: the viewport takes its overflow from the body while the root's
 * own overflow is visible, so this stops the scroll either way — but locking
 * the root as well makes it a scroll container, and a scroll container kills
 * `position: sticky` in everything inside it. That dropped the header and the
 * section bar out of view the moment the jump list opened, which is half of
 * why the list read as a free-floating overlay rather than a menu hanging off
 * the bar that opened it.
 */
html.has-overlay body {
  overflow: hidden;
}

/*
 * Both halves are set, not just the background. A selection that only paints
 * behind the text leaves every colour on the page to fend for itself — a
 * glossary term is purple, a cross-reference is green, a link is accent — and
 * one of them will always be the one that disappears. Naming the ink as well
 * means every selected glyph lands on the same known pair.
 */
::selection {
  background-color: var(--selection);
  color: var(--selection-ink);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--display-weight);
  line-height: var(--leading-tight);
  letter-spacing: var(--display-tracking);
}

p,
ul,
ol,
dl,
figure,
blockquote,
pre,
table {
  margin: 0;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--accent-strong);
}

button {
  font: inherit;
  color: inherit;
}

input,
select,
textarea {
  font: inherit;
  color: inherit;
}

code,
kbd,
pre,
samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

hr {
  height: 1px;
  margin: var(--space-6) 0;
  border: 0;
  background: var(--line);
}

/*
 * One focus treatment for the whole site. Never removed, never made invisible:
 * a keyboard user must always be able to see where they are.
 */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* `main` takes focus from the skip link but should not draw a ring for it. */
main:focus {
  outline: none;
}

/*
 * Several components set an explicit `display`, which would otherwise beat the
 * user-agent rule for `[hidden]` and leave an invisible element in the tab
 * order. `hidden` always wins.
 */
[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--space-3);
  top: var(--space-3);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--surface-raised);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: translateY(0);
}

/*
 * Anchor aliases: zero-size targets that keep a retired anchor working. Placed
 * just before the heading that replaced it, and offset so the browser scrolls
 * to the same place the live anchor would.
 */
.anchor-alias {
  display: block;
  height: 0;
  scroll-margin-top: calc(var(--header-height) + var(--section-bar-height) + var(--space-4));
}
