/* Base: the reset, the page background and text colour, links, and the helpers every page uses (visually hidden,
   JS-only controls, `[hidden]`, icons). Mobile first throughout; see tokens.css for the values. */

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

html {
  background: var(--color-bg);
  /* iOS Safari enlarges text in landscape unless told not to. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh; /* phones: the window without the browser bars sliding in and out */
  margin: 0;
  background: var(--gradient-page);
  background-attachment: fixed;
  color: var(--color-text);
  font-family: var(--font-text);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  /* Lets `.full` (layout.css) measure the window's width without the scrollbar (`cqi`), which 100vw includes. */
  container-type: inline-size;
}

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

/* Browsers give form controls their own font (Arial on macOS) instead of the page's; use the site font. Only the
   family: each control's size stays as its own rule sets it. */
button,
input,
select,
textarea {
  font-family: inherit;
}

/* Keyboard focus, everywhere: a ring outside the element (the tokens). Only for the keyboard (`:focus-visible`), so a
   mouse click doesn't draw it. A component may move it (inset, its own colour) but never just remove it. */
:focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

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

/* The skip link: off the top of the page until the keyboard reaches it, then the first thing on it. Styled from the
   tokens like the other links, with the page background behind it so the content never shows through. */
.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(calc(-100% - var(--space-4)));
}

.skip-link:focus-visible {
  transform: none;
}

/* `<main>` is only focusable so the skip link can land on it; it should never draw a ring of its own. */
main:focus {
  outline: none;
}

/* Controls that only work with JS; `layout.tsx` adds the `js` class before the first paint. */
html:not(.js) .js-only {
  display: none !important;
}

/* Reveal on scroll: the children of a `[data-reveal]` container fade in one after another as they come into view
   (`reveal.js` adds `.revealed` and their place in the batch, --reveal-index): they rise a little, grow to full size
   and come into focus. Hidden only with JS; and should reveal.js never run (it marks the container
   `.reveal-active`), a fallback shows them after a few seconds, so they can't stay hidden. */
html.js [data-reveal] > :not(.revealed) {
  opacity: 0;
  animation: reveal-fallback 0s 3s forwards;
}

[data-reveal].reveal-active > :not(.revealed) {
  animation: none;
}

[data-reveal] > .revealed {
  animation: reveal-in var(--duration-reveal) var(--ease-out) backwards;
  animation-delay: calc(var(--reveal-index, 0) * var(--duration-reveal-step));
}

@keyframes reveal-in {
  from {
    opacity: 0;
    translate: 0 var(--space-2);
    scale: 0.96;
    filter: blur(4px);
  }
}

/* A menu panel dropping into place: the header's account menu (account.css) and, on phones, its nav menu
   (layout.css). */
@keyframes menu-in {
  from {
    opacity: 0;
    translate: 0 calc(-1 * var(--space-1));
    scale: 0.97;
  }
}

@keyframes reveal-fallback {
  to {
    opacity: 1;
  }
}

/* `hidden` wins over the display set by classes such as `.button`. */
[hidden] {
  display: none !important;
}

.icon {
  display: block;
  flex: none;
}

/* Readers who ask for less motion (a system setting) get none: transitions and animations end at once. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0s !important;
    animation-duration: 0s !important;
    animation-delay: 0s !important;
    transition-delay: 0s !important;
    animation-iteration-count: 1 !important;
  }
}
