/* ==========================================================================
   Base — modern CSS reset + document defaults
   No class selectors here; only element, attribute, and pseudo selectors.
   ========================================================================== */


/* --------------------------------------------------------------------------
   Box model
-------------------------------------------------------------------------- */

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

/* Prevent author display rules from overriding the hidden attribute */
[hidden] {
  display: none !important;
}


/* --------------------------------------------------------------------------
   Document
-------------------------------------------------------------------------- */

html {
  /* Prevent font size inflation on iOS after orientation change */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;

  /* Smooth anchor-link scrolling — collapses to instant via reduced-motion token */
  scroll-behavior: smooth;
  hanging-punctuation: first last;
}

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background-color: var(--color-bg);

  /* Improve text rendering on macOS/iOS */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}


/* --------------------------------------------------------------------------
   Typography
-------------------------------------------------------------------------- */

h1, h2, h3, h4, h5, h6 {
  margin-block: 0;
  font-weight: var(--font-weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}

p, li, figcaption {
  /* Prevent overly long lines on wide viewports */
  max-inline-size: 70ch;
  text-wrap: pretty;
}

p {
  margin-block: 0;
}

/* Ensure elements without explicit size do not overflow their container */
img, video, svg, canvas, audio, iframe, embed, object {
  display: block;
  max-width: 100%;
}

img, video {
  height: auto;
}

/* Inherit fonts for form controls — browsers do not do this by default */
input, button, textarea, select {
  font: inherit;
}

/* Remove default button styling so components start from a clean slate */
button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  margin: 0;
}

/* Remove default list styling — add back in components that need it */
ul, ol {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Consistent anchor base — colour and underline set by component or utility */
a {
  color: var(--color-link);
  text-decoration-skip-ink: auto;
}

a:hover {
  color: var(--color-link-hover);
}

a:visited {
  color: var(--color-link-visited);
}

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


/* --------------------------------------------------------------------------
   Focus management (WCAG 2.4.7 — Focus Visible)
   :focus-visible is used so mouse users don't see the ring while keyboard
   users always get a clear indicator.
-------------------------------------------------------------------------- */

:focus {
  /* Remove default browser outline; we replace it below */
  outline: none;
}

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

/* Slightly larger offset for elements that already have a border */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline-offset: 1px;
}


/* --------------------------------------------------------------------------
   Skip-to-content link (WCAG 2.4.1 — Bypass Blocks)
   Visually hidden until focused; must be the first focusable element on every page.
-------------------------------------------------------------------------- */

.skip-link {
  position: absolute;
  inset-inline-start: var(--space-4);
  inset-block-start: var(--space-4);
  z-index: var(--z-toast);

  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  color: var(--color-link);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
  border: 2px solid var(--color-focus-ring);
  border-radius: var(--radius-md);
  text-decoration: none;
  box-shadow: var(--shadow-lg);

  /* Hidden off-screen until focused */
  translate: 0 calc(-100% - var(--space-8));
  transition: translate var(--duration-fast) var(--ease-out);
}

.skip-link:focus-visible {
  translate: 0 0;
  outline: none; /* Already visually distinct via border + shadow */
}


/* --------------------------------------------------------------------------
   Reduced motion — disable all CSS transitions/animations globally.
   JS modules also read the --duration-* tokens which are zeroed in tokens.css.
-------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important; /* WORKAROUND: overrides third-party animation libraries */
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}


/* --------------------------------------------------------------------------
   Miscellaneous
-------------------------------------------------------------------------- */

/* Remove gap between table cells */
table {
  border-collapse: collapse;
  border-spacing: 0;
}

/* Horizontally scrollable code blocks */
pre {
  overflow-x: auto;
  white-space: pre;
}

/* Consistent horizontal rule */
hr {
  border: none;
  border-block-start: 1px solid var(--color-border);
  margin-block: var(--space-6);
}

/* Prevent text selection on interactive controls where it feels wrong */
button,
[role="button"],
label {
  user-select: none;
}
