/* ═══════════════════════════════════════════════════════════════════════
   BASE — Reset + Typography + Core Element Styles
   Wrapped in @layer base so Tailwind @layer utilities takes priority.
   ═══════════════════════════════════════════════════════════════════════ */
@layer base {
  /* ── Modern Reset ─────────────────────────────────────────────────────── */
  *,
  *::before,
  *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  ::selection {
    background: var(--selection-bg);
    color: inherit;
  }

  ::-moz-selection {
    background: var(--selection-bg);
    color: inherit;
  }

  html {
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
    /* Touch and pen users keep native bounce and pull-to-refresh. */
    overscroll-behavior: auto;
    scrollbar-color: var(--scroll-thumb, var(--scroll-thumb-default)) var(--scroll-track, var(--background));
  }

  /* The primary input decides this, because viewport width says nothing about it. */
  @media (hover: hover) and (pointer: fine) {
    html,
    body {
      overscroll-behavior: none;
    }
  }

  /* Theme native scrollbars while leaving their behavior to the browser. */
  html,
  :where(pre, .overflow-auto, .overflow-x-auto, .overflow-y-auto, .scroll-thin, [data-scroll-surface]) {
    --scroll-thumb-default: var(--muted-foreground);

    scrollbar-width: thin;
  }

  :where(pre, .overflow-auto, .overflow-x-auto, .overflow-y-auto, .scroll-thin, [data-scroll-surface]) {
    scrollbar-color: var(--scroll-thumb, var(--scroll-thumb-default)) var(--scroll-track, transparent);
  }

  @media (prefers-contrast: more) {
    html,
    :where(pre, .overflow-auto, .overflow-x-auto, .overflow-y-auto, .scroll-thin, [data-scroll-surface]) {
      --scroll-thumb-default: var(--foreground);

      scrollbar-width: auto;
    }
  }

  @media (forced-colors: active) {
    html,
    :where(pre, .overflow-auto, .overflow-x-auto, .overflow-y-auto, .scroll-thin, [data-scroll-surface]) {
      scrollbar-width: auto;
      scrollbar-color: auto;
    }
  }

  [data-scroll-surface='light'] {
    color-scheme: light;
  }

  [data-scroll-surface='dark'] {
    color-scheme: dark;
  }

  @media (prefers-reduced-motion: no-preference) {
    html {
      scroll-behavior: smooth;
    }
  }

  body {
    font-family: var(--font-body);
    font-weight: 550;
    font-variation-settings: 'wdth' 110;
    background: var(--background);
    color: var(--foreground);
    margin: 0;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: var(--tap-highlight);
    position: relative;
    font-feature-settings: 'ss01' 1;
  }

  img,
  picture,
  video,
  canvas,
  svg {
    display: block;
    max-width: 100%;
    height: auto;
  }

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

  /* ── Link + Button font normalization (matches pre-version) ──────────── */
  a,
  button {
    font-family: var(--font-body);
    font-feature-settings: 'ss01' 1;
  }

  a:focus-visible,
  button:focus-visible {
    outline: var(--outline-width) solid var(--outline-color);
    outline-offset: var(--outline-offset);
  }

  /* ── Font-variation-settings reset (heading/nav/component contexts) ──── */
  .font-heading,
  [class*='font-heading'],
  .font-mono,
  .nav-link-text,
  .btn,
  .neo-chip,
  .governance-card-header,
  .governance-card-body {
    font-variation-settings: normal;
  }

  /* ── Tabular figures for mono contexts ────────────────────────────────── */
  .font-mono,
  [class*='font-mono'] {
    font-variant-numeric: tabular-nums;
  }

  /* ── Typography — heading specs via overridable custom properties ─────── */
  /* NOTE: pre-version does NOT set font-size on headings globally.          */
  /*       Sizes come from utility classes / inline styles in templates.      */
  /*       L4 font classification can override --heading-weight-N and        */
  /*       --heading-tracking-N per-theme via computeDerivativeTokens().     */
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    font-family: var(--font-heading);
    font-variation-settings: normal;
    text-wrap: balance;
  }

  h1 {
    font-weight: var(--heading-weight-1, 900);
    letter-spacing: var(--heading-tracking-1, -0.04em);
    line-height: 0.92;
  }
  h2 {
    font-weight: var(--heading-weight-2, 800);
    letter-spacing: var(--heading-tracking-2, -0.035em);
    line-height: 1.1;
  }
  /* ── Heading weight / tracking / line-height + script min-size guard ──
   --heading-min-size is set by L4 font role mapping when a script/
   handwriting font is assigned to headings.  Prevents illegibly small
   headings (script fonts are unreadable below ~20 px).
   Fallback values match UA-stylesheet defaults exactly so non-script
   themes see zero visual change.  Utility classes (@layer utilities)
   override these freely since @layer base has lower priority.     ─── */
  h3 {
    font-weight: var(--heading-weight-3, 900);
    letter-spacing: var(--heading-tracking-3, -0.02em);
    line-height: 1.2;
    font-size: max(var(--heading-min-size, 0px), 1.17em);
  }
  h4 {
    font-weight: var(--heading-weight-4, 700);
    letter-spacing: var(--heading-tracking-4, -0.015em);
    line-height: 1.3;
    font-size: max(var(--heading-min-size, 0px), 1em);
  }
  h5 {
    font-weight: var(--heading-weight-5, 700);
    letter-spacing: var(--heading-tracking-5, -0.01em);
    line-height: 1.2;
    font-size: max(var(--heading-min-size, 0px), 0.83em);
  }
  h6 {
    font-weight: var(--heading-weight-5, 700);
    letter-spacing: var(--heading-tracking-5, -0.01em);
    line-height: 1.2;
    font-size: max(var(--heading-min-size, 0px), 0.67em);
  }

  code,
  pre,
  .font-mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-variation-settings: normal;
  }

  /* ── Skip Link — defined in components.css (@layer components) ────────── */

  /* ── Container — full-width below lg, max-width at lg+ ────────────────
   Usage: class="container mx-auto px-6"
   xs/sm/md = 100% viewport width (no max-width constraint).
   lg+ = obeys Tailwind default breakpoint max-widths.
   ──────────────────────────────────────────────────────────────────── */
  @media (max-width: 63.99rem) {
    .container {
      max-width: 100% !important;
    }
  }

  /* ── Section contexts — custom selection colors ───────────────────────── */
  .section-dark::selection,
  .section-dark *::selection {
    background: var(--selection-dark-bg);
  }
  .section-warm::selection,
  .section-warm *::selection {
    background: var(--selection-warm-bg);
  }
  .neo-card::selection,
  .neo-card *::selection {
    background: var(--selection-card-bg);
  }
  .stats-card::selection,
  .stats-card *::selection {
    background: var(--selection-stats-bg);
  }

  /* ── Icon alignment (cross-library normalization) ─────────────────────── */
  svg.lucide,
  svg[data-fa-i2svg],
  .heroicon-svg {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
  }
} /* end @layer base */
