/* ============================================================================
   BASE — Reset, typography, element defaults (ERP.AI brutalist)
   ============================================================================ */

@layer base {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  /* Resolve the local product/category accent at the selected element.
     Mixing into the theme canvas keeps normal reading contrast in both modes. */
  ::selection {
    background: color-mix(
      in srgb,
      var(
          --swage-accent,
          var(--selection-accent, var(--catalog-taxonomy-accent, var(--pi, var(--primary))))
        )
        30%,
      var(--background)
    );
    color: var(--foreground);
  }

  html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overscroll-behavior: none;
    /* Native sizing preserves overlay and classic scrollbar behavior. */
    color-scheme: light;
    scrollbar-width: thin;
    scrollbar-color: var(--muted-foreground) var(--background);
  }

  html.dark {
    color-scheme: dark;
  }

  /* Offset anchors for fixed nav + audience bar — see --scroll-stack in tokens.css. */
  [id] {
    scroll-margin-top: var(--scroll-stack);
  }

  body {
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--foreground);
    background-color: var(--background);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    position: relative;
  }

  /* EB Garamond italic reads thin at hero sizes against brutalist uppercase
     headlines. Bump the utility to 600 (Semi-Bold) so every italic
     pull-quote has real presence without losing humanist character. */
  .font-serif {
    font-weight: 600;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    font-family: var(--font-heading);
    font-weight: 500;
    line-height: 1.1;
    color: var(--foreground);
    letter-spacing: 0;
    text-wrap: balance;
  }
  h1 {
    font-size: var(--text-5xl);
  }
  h2 {
    font-size: var(--text-4xl);
  }
  h3 {
    font-size: var(--text-3xl);
  }
  h4 {
    font-size: var(--text-2xl);
  }

  p {
    margin-bottom: var(--space-4);
    text-wrap: pretty;
  }

  a {
    color: var(--foreground);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-standard);
  }
  a:hover {
    color: var(--primary);
  }

  code,
  pre,
  kbd,
  samp {
    font-family: var(--font-mono);
    font-size: 0.9em;
  }
  pre {
    overflow-x: auto;
    padding: var(--space-4);
    background: var(--surface-container);
  }
  img,
  svg,
  video {
    display: block;
    max-width: 100%;
    height: auto;
  }
  button,
  input,
  select,
  textarea {
    font: inherit;
    color: inherit;
  }
  button {
    cursor: pointer;
  }
  :focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }

  .skip-link {
    position: fixed;
    inset-block-start: 0;
    left: 0;
    z-index: var(--z-skip);
    display: flex;
    align-items: center;
    gap: var(--space-4);
    max-inline-size: 100%;
    min-block-size: var(--space-12);
    padding: var(--space-3) var(--space-4);
    border-radius: 0 0 var(--tacet-radius-xl) 0;
    background: var(--ink-nav);
    color: var(--ink-light);
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.5;
    text-decoration: none;
    transform: translateY(-100%);
    transition: none;
  }
  .skip-link:focus {
    outline: 2px solid var(--tacet-orange);
    outline-offset: calc(-1 * var(--space-1));
    transform: none;
  }
  .skip-link kbd {
    flex-shrink: 0;
    padding: var(--space-1) var(--space-2);
    border: 1px solid currentColor;
    border-radius: var(--tacet-radius-sm);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1;
  }

  @media (forced-colors: active) {
    .skip-link {
      background: Canvas;
      color: LinkText;
    }
    .skip-link:focus {
      outline-color: Highlight;
    }
  }

  /* Explicitly style scrollers; mixed-surface panels own their local colors. */
  :where(
    pre,
    :has(> pre),
    .overflow-x-auto,
    .scroll-thin,
    .nx .win-body,
    .nx .circuit-scroll,
    [data-scroll-surface]
  ) {
    scrollbar-width: thin;
    scrollbar-color: var(--scroll-thumb, var(--muted-foreground)) var(--scroll-track, transparent);
  }

  /* System previews retain light panels inside either document theme.
     Low specificity lets an explicit surface attribute override this default. */
  .nx :where(.win-body, .circuit-scroll) {
    color-scheme: light;
    --scroll-thumb: var(--ink-2);
  }

  [data-scroll-surface='light'] {
    color-scheme: light;
    --scroll-thumb: var(--ink-muted);
    --scroll-track: transparent;
  }

  [data-scroll-surface='dark'] {
    color-scheme: dark;
    --scroll-thumb: var(--ink-light-mid);
    --scroll-track: transparent;
  }

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

  /* Content width cap — section backgrounds bleed full, content is capped.
     Pages with .main--full-bleed skip the cap entirely. */
  #main-content:not(.main--full-bleed) > section > *,
  #main-content:not(.main--full-bleed) > header > *,
  #main-content:not(.main--full-bleed) > div > * {
    max-width: 90rem;
    margin-inline: auto;
  }
}

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