/* =============================================================================
   NEXUS — Base
   Element defaults, focus model, and the accessibility primitives every
   page depends on.
   ========================================================================== */

@layer base {
  html {
    block-size: 100%;
    scroll-behavior: smooth;
    /* Anchored sections must clear the fixed masthead. */
    scroll-padding-block-start: calc(var(--header-height) + var(--space-6));
    background-color: var(--color-canvas);
  }

  body {
    min-block-size: 100%;
    margin: 0;
    background-color: var(--color-canvas);
    color: var(--color-text);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    font-weight: var(--weight-regular);
    font-optical-sizing: auto;
    /* Inter: disambiguated l/1, single-storey a in UI contexts. */
    font-feature-settings: "cv05" 1, "cv11" 1, "calt" 1;
    line-height: var(--leading-normal);
    letter-spacing: var(--tracking-normal);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: clip;
  }

  ::selection {
    background-color: var(--color-selection);
    color: var(--color-text);
  }

  /* ---------------------------------------------------------------------
     Focus — visible, high contrast, never removed.
     ------------------------------------------------------------------ */
  :focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
    border-radius: var(--radius-xs);
  }

  :focus:not(:focus-visible) {
    outline: none;
  }

  /* ---------------------------------------------------------------------
     Text elements
     ------------------------------------------------------------------ */
  a:where(:not([class])) {
    color: var(--color-accent);
    text-decoration: underline;
    transition: color var(--duration-fast) var(--ease-standard);
  }

  a:where(:not([class])):hover {
    color: var(--color-accent-hover);
  }

  strong,
  b {
    font-weight: var(--weight-semibold);
  }

  small {
    font-size: var(--text-sm);
  }

  ::marker {
    color: var(--color-text-subtle);
  }

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

  abbr[title] {
    text-decoration: underline dotted;
    cursor: help;
  }

  /* ---------------------------------------------------------------------
     Accessibility primitives
     ------------------------------------------------------------------ */
  .visually-hidden:not(:focus-visible) {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  .skip-link {
    position: absolute;
    inset-block-start: var(--space-3);
    inset-inline-start: var(--space-3);
    z-index: var(--z-notify);
    padding: var(--space-3) var(--space-5);
    background-color: var(--color-surface-raised);
    box-shadow: var(--shadow-ring), var(--shadow-lg);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    text-decoration: none;
    transform: translateY(calc(-100% - var(--space-6)));
    transition: transform var(--duration-base) var(--ease-out);
  }

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

  /* ---------------------------------------------------------------------
     Scrollbars — tuned to the surface, not the OS.
     ------------------------------------------------------------------ */
  @supports (scrollbar-color: currentcolor transparent) {
    html {
      scrollbar-color: var(--color-border-strong) transparent;
      scrollbar-width: thin;
    }
  }

  /* ---------------------------------------------------------------------
     Reduced motion — one global contract, honoured by every component.
     ------------------------------------------------------------------ */
  @media (prefers-reduced-motion: reduce) {
    html {
      scroll-behavior: auto;
    }

    :root {
      --duration-instant: 1ms;
      --duration-fast: 1ms;
      --duration-base: 1ms;
      --duration-slow: 1ms;
      --duration-slower: 1ms;
      --reveal-distance: 0rem;
      --reveal-stagger: 0ms;
    }

    *,
    *::before,
    *::after {
      animation-iteration-count: 1 !important;
      transition-duration: 1ms !important;
      animation-duration: 1ms !important;
      scroll-behavior: auto !important;
    }
  }

  /* ---------------------------------------------------------------------
     Forced colours — keep structure legible when the palette is replaced.
     ------------------------------------------------------------------ */
  @media (forced-colors: active) {
    :focus-visible {
      outline-color: Highlight;
    }
  }
}
