/* Layer 2 of 5 — base: reset, document defaults, accessibility utilities, motion policy. */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-ui);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern";
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
}

img, svg, video, canvas { display: block; max-width: 100%; }
svg { flex-shrink: 0; }
input, button, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; text-align: inherit; }
button:disabled, [aria-disabled="true"] { cursor: not-allowed; }
a { color: var(--accent-text); text-decoration-thickness: 0.06em; text-underline-offset: 0.2em; }
a:hover { text-decoration-thickness: 0.1em; }
h1, h2, h3, h4 { font-weight: var(--fw-semibold); line-height: var(--lh-tight); text-wrap: balance; }
p { text-wrap: pretty; }
ul, ol { padding-inline-start: 1.4em; }
table { border-collapse: collapse; }
[hidden] { display: none !important; }
::selection { background: var(--selection); }

/* Mixed-direction safety: Latin runs inside Arabic text keep their own direction. */
bdi, [dir="auto"] { unicode-bidi: plaintext; }
code, kbd, pre, samp { font-family: var(--font-mono); font-size: 0.92em; }
pre, code { direction: ltr; unicode-bidi: isolate; }

kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.6em; height: 1.6em; padding: 0 0.35em;
  font-size: var(--fs-2xs); font-weight: var(--fw-medium);
  color: var(--text-3);
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: var(--r-xs);
  background: var(--surface-hover);
  direction: ltr;
}

/* ---------- Focus: always visible for keyboard users, never for mouse clicks ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
.focus-inset:focus-visible { outline-offset: -2px; }

/* ---------- Scrollbars (thin, theme-aware) ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Accessibility utilities ---------- */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; inset-inline-start: var(--sp-3); top: var(--sp-3); z-index: var(--z-toast);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--r-sm);
  background: var(--accent); color: var(--text-on-accent); font-weight: var(--fw-semibold);
  transform: translateY(-200%); transition: transform var(--dur-fast) var(--ease-out);
  text-decoration: none;
}
.skip-link:focus { transform: none; }

/* ---------- Motion policy ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important; animation-iteration-count: 1 !important;
    transition-duration: 1ms !important; scroll-behavior: auto !important;
  }
}
:root[data-motion="off"] *, :root[data-motion="off"] *::before, :root[data-motion="off"] *::after {
  animation-duration: 1ms !important; animation-iteration-count: 1 !important;
  transition-duration: 1ms !important; scroll-behavior: auto !important;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(4px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
.noscript { padding: 2rem; text-align: center; }
