/* Requires tokens.css to be loaded first — every var(--*) reference below
   resolves against the tokens declared in that file. Loading globals.css
   standalone produces silently-broken styles.

   Cascade layer order (lowest → highest priority among named layers):
       reset    — element-level UA reset and page-wide defaults
       layout   — AppShell / page-frame structure (layout.css)
       components — every per-component file under components/
       utilities — single-purpose helpers (.label-caps, .sr-only, .skip-link, …)

   Custom properties from tokens.css live outside any layer — they cascade by
   source order, which is correct for design tokens. Anything UN-LAYERED in
   any css file wins against ALL named layers; avoid that unless a rule must
   override component CSS regardless of import order. */

@layer reset, layout, components, utilities;

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

  * {
    margin: 0;
    padding: 0;
  }

  html {
    scroll-behavior: smooth;
    scrollbar-gutter: stable;
    background-color: var(--md-surface);
    -webkit-text-size-adjust: 100%;
  }

  body {
    background-color: var(--md-surface);
    color: var(--md-on-surface);
    font-family: var(--font-body);
    font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    line-height: var(--leading-normal);
  }

  h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 500;
    color: var(--md-on-surface);
    text-wrap: balance;
    line-height: var(--leading-tight);
  }

  button {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
  }

  button:not(:disabled),
  a[href],
  select:not(:disabled),
  summary,
  [role='button']:not(:disabled) {
    cursor: pointer;
  }

  a {
    color: inherit;
    text-decoration: none;
  }

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

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

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

  ::selection {
    background-color: var(--md-primary-muted);
    color: var(--md-on-surface);
  }
}

@layer utilities {
  /* MD3-style hover/active overlay via ::after.
     Opt-in: add class="state-layer" to an interactive element. */
  .state-layer {
    position: relative;
    overflow: hidden;
    isolation: isolate;

    &::after {
      content: '';
      position: absolute;
      inset: 0;
      background: currentColor;
      opacity: 0;
      pointer-events: none;
      transition: opacity var(--motion-spring-fast-effects-duration) var(--motion-spring-fast-effects);
      z-index: 0;
    }

    &:is(:hover, [data-force~='hover'])::after { opacity: 0.08; }
    &:is(:active, [data-force~='active'])::after { opacity: 0.12; }

    & > * {
      position: relative;
      z-index: 1;
    }
  }

  /* Small-caps metadata label. */
  .label-caps {
    font-family: var(--font-sans);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--md-on-surface-variant);
  }

  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .skip-link {
    position: absolute;
    inset-block-start: var(--space-2);
    inset-inline-start: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--md-on-surface);
    color: var(--md-surface);
    border-radius: var(--radius-sm);
    z-index: 100;
    transform: translateY(-200%);
    transition: transform var(--motion-spring-fast-effects-duration) var(--motion-spring-fast-effects);

    &:focus-visible {
      transform: translateY(0);
    }
  }
}
