/* FlatMatch Base Styles, Reset, Landmarks, View Transitions & Typography */
@layer reset, tokens, base, components, utilities;

@layer reset {
  html {
    box-sizing: border-box;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
  }

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

  body, main, header, nav, footer, section, article, aside, div, form, fieldset, dialog,
  input, select, textarea, button, table, th, td, ul, ol, figure, figcaption, details, summary {
    box-sizing: border-box;
  }

  body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.55;
    color: var(--text-primary);
    background-color: var(--bg-canvas);
    accent-color: var(--accent-color);
    min-block-size: 100dvb;
    display: flex;
    flex-direction: column;
    overflow-x: clip;
  }

  h1, h2, h3, h4, p, ul, ol, figure, blockquote {
    margin-block-start: 0;
  }

  img, svg, picture, video {
    display: block;
    max-inline-size: 100%;
  }

  img {
    block-size: auto;
  }

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

  button {
    cursor: pointer;
  }
}

/* Cross-document MPA View Transitions (progressive enhancement) */
@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }

  ::view-transition-old(root) {
    animation: 0.18s ease-in both fm-page-out;
  }

  ::view-transition-new(root) {
    animation: 0.22s ease-out both fm-page-in;
  }
}

@keyframes fm-page-out {
  to { opacity: 0; }
}

@keyframes fm-page-in {
  from { opacity: 0; }
}

/* Safari WebKit icon pseudo-element repaint workaround (#301609) */
@keyframes webkit-301609 {}

@supports ((-webkit-nbsp-mode: normal) or (-webkit-touch-callout: none) or (font: -apple-system-body)) and (content-visibility: auto) {
  @layer webkit-301609-fix {
    ::before, ::after {
      animation: webkit-301609 0s;
    }
  }
}

@layer base {
  main {
    flex: 1 0 auto;
    padding-block-end: var(--space-8);
  }

  h1, h2, h3, h4 {
    line-height: 1.18;
    letter-spacing: -0.02em;
    font-weight: 700;
    color: var(--text-primary);
  }

  h1 {
    font-size: var(--text-3xl);
    margin-block-end: var(--space-4);
  }

  h2 {
    font-size: var(--text-2xl);
    margin-block-end: var(--space-3);
  }

  h3 {
    font-size: var(--text-xl);
    margin-block-end: var(--space-2);
  }

  p {
    color: var(--text-secondary);
    margin-block-end: var(--space-4);
  }

  a:any-link {
    color: var(--brand-primary-text);
    text-decoration-thickness: 1.5px;
    text-underline-offset: 0.2em;
  }

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

  :where(a:any-link, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
  }

  .num, .tabular {
    font-variant-numeric: tabular-nums;
  }

  /* Visually Hidden Utility (focus-within safe for skip links) */
  .visually-hidden:where(:not(:focus-within, :active)) {
    position: absolute !important;
    clip-path: inset(50%) !important;
    overflow: hidden !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    border: 0 !important;
    white-space: nowrap !important;
  }

  .skip-link:focus-visible {
    position: fixed;
    inset-block-start: 0.75rem;
    inset-inline-start: 0.75rem;
    z-index: 9999;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 2px solid var(--focus-ring);
    border-radius: var(--radius-sm);
    padding: 0.65rem 1rem;
    font-weight: 700;
    text-decoration: none;
    box-shadow: var(--shadow-lg);
  }

  /* Popover polyfill hidden safety before JS loads */
  @supports not selector(:popover-open) {
    [popover]:not(.\:popover-open) {
      display: none;
    }
  }

  [inert], [inert] * {
    opacity: 0.55;
    cursor: default;
    user-select: none;
  }

  [hidden] {
    display: none !important;
  }
}

@layer utilities {
  .container {
    inline-size: min(100% - 2rem, var(--container-max));
    margin-inline: auto;
  }

  .section {
    padding-block: var(--space-7);
  }

  .section-tight {
    padding-block: var(--space-6);
  }

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