/* ==========================================================================
   02. Base
   --------------------------------------------------------------------------
   Reset, element defaults and accessibility essentials.
   Everything here applies site-wide; nothing here adds visual flourish.
   ========================================================================== */

/* -- Reset ------------------------------------------------------------------- */

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

* {
  margin: 0;
}

html {
  scroll-padding-top: calc(var(--header-h) + var(--space-4));
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Smooth scrolling is a motion preference, not a default. */
@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

/* -- Elements ---------------------------------------------------------------- */

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* -- Language-aware typography ---------------------------------------------------
   Arabic (Tajawal) renders better with a taller line height, and its glyphs
   must never carry negative letter-spacing. Latin text gets a hair of
   breathing room. Applied per-document via the <html lang> attribute. */

:lang(ar) {
  --leading-normal: 1.85;
}

html[lang="ar"] h1,
html[lang="ar"] h2,
html[lang="ar"] h3,
html[lang="ar"] h4 {
  letter-spacing: 0;
}

:lang(en) h1,
:lang(en) h2 {
  letter-spacing: -0.01em;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  line-height: var(--leading-tight);
  font-weight: 700;
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

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

img {
  height: auto;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
}

button {
  cursor: pointer;
}

ul,
ol {
  padding-inline-start: 1.25rem;
}

details > summary {
  cursor: pointer;
}

hr {
  border: 0;
  border-top: 1px solid var(--color-border);
}

code,
kbd,
samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

mark {
  background-color: var(--color-accent-soft);
  color: var(--color-text);
  border-radius: 0.125rem;
  padding: 0 0.25em;
}

::selection {
  background-color: var(--color-accent);
  color: var(--color-on-accent);
}

/* -- Accessibility ------------------------------------------------------------ */

/* Visible keyboard focus everywhere, invisible to pointer users. */
:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}

/* Focus ring on <main> is never useful — the skip link is the entry point. */
main:focus {
  outline: none;
}

/* Skip link: visually hidden until focused. */
.skip-link {
  position: absolute;
  inset-inline-start: var(--space-4);
  top: var(--space-4);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background-color: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  transform: translateY(-300%);
  transition: transform var(--dur-base) var(--ease-out);
}

.skip-link:focus-visible {
  transform: translateY(0);
}

/* Motion preferences: reduce everything to a single imperceptible frame. */
@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;
  }
}

/* Respect high-contrast mode by honoring user overrides. */
@media (forced-colors: active) {
  :focus-visible {
    outline-color: CanvasText;
  }
}
