/* ==========================================================================
   base.css — Reset, base elements, typography, a11y primitives
   ========================================================================== */

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

  * { margin: 0; }

  html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--header-h) + 1.5rem);
  }

  body {
    font-family: var(--font-body);
    font-size: var(--fs-base);
    line-height: var(--lh-base);
    color: var(--text);
    background-color: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    min-height: 100svh;
    overflow-x: clip;
    transition: background-color var(--dur) var(--ease-out),
                color var(--dur) var(--ease-out);
  }

  /* Arabic typography binds to the lang attribute */
  :lang(ar), [lang="ar"] { font-family: var(--font-arabic); }
  [dir="rtl"] body { letter-spacing: 0; }

  h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: var(--lh-tight);
    letter-spacing: var(--tracking-tight);
    color: var(--text);
    text-wrap: balance;
  }
  [lang="ar"] h1, [lang="ar"] h2, [lang="ar"] h3, [lang="ar"] h4 {
    font-family: var(--font-arabic);
    letter-spacing: 0;
  }

  p { text-wrap: pretty; }

  a {
    color: inherit;
    text-decoration: none;
    transition: color var(--dur-fast) var(--ease-out);
  }

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

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

  ul, ol { list-style: none; padding: 0; }

  :focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
    border-radius: var(--radius-sm);
  }
  :focus:not(:focus-visible) { outline: none; }

  ::selection {
    background: color-mix(in srgb, var(--primary) 28%, transparent);
    color: var(--text);
  }

  /* Custom scrollbar (progressive enhancement) */
  @supports (scrollbar-color: auto) {
    html { scrollbar-color: var(--border-strong) transparent; scrollbar-width: thin; }
  }

  /* Skip link */
  .skip-link {
    position: fixed;
    inset-inline-start: 1rem;
    inset-block-start: -100%;
    z-index: var(--z-toast);
    padding: 0.75rem 1.25rem;
    background: var(--primary);
    color: var(--text-on-primary);
    border-radius: var(--radius-md);
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    transition: inset-block-start var(--dur) var(--ease-out);
  }
  .skip-link:focus { inset-block-start: 1rem; }

  /* Screen-reader only */
  .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;
  }

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

  /* Smooth, brief cross-fade when the user toggles theme */
  html.theme-anim,
  html.theme-anim *,
  html.theme-anim *::before,
  html.theme-anim *::after {
    transition: background-color var(--dur) var(--ease-out),
                border-color var(--dur) var(--ease-out),
                color var(--dur) var(--ease-out),
                fill var(--dur) var(--ease-out) !important;
  }
}
