/* وصلها 4 — base layer: reset, typography, focus, motion preferences. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-block: calc(var(--topbar-height) + var(--space-4)) calc(var(--tabbar-height) + var(--space-4)); }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--glow), var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 400 var(--text-body)/var(--leading-body) var(--font-body);
  overflow-wrap: break-word;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p, figure, blockquote, dl, dd { margin: 0; }
h1, h2, h3, h4 { font-weight: 600; line-height: var(--leading-tight); text-wrap: balance; }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
p { text-wrap: pretty; }
small { font-size: var(--text-sm); }
img, svg, video, canvas { display: block; max-width: 100%; }
img { height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 4px; }
a:hover { color: var(--accent-strong); }
[hidden] { display: none !important; }
/* «حجم الخط» in settings: the whole interface is in rem, so the root scales it. */
html[data-text-size="large"] { font-size: 112.5%; }
html[data-text-size="larger"] { font-size: 125%; }
::selection { background: var(--accent-soft); }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--space-5) 0; }

/* Latin, formulas and code keep their own direction inside Arabic text. */
[lang="en"], .ltr { direction: ltr; unicode-bidi: isolate; }
/* English subtitles under Arabic titles line up with the Arabic edge. */
.display-en, .en-sub, .lecture-en, .lecture-head [lang="en"] { text-align: end; }
bdi { unicode-bidi: isolate; }
code, kbd, .mono { font-family: var(--font-mono); font-size: .95em; } /* relative to the surrounding text */

/* Focus: always visible, never hidden behind fixed bars. */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
/* Headings and regions focused by script (page change, next question) are reading
   positions, not controls: no ring, so mouse users do not see a stray box. */
[tabindex="-1"]:focus { outline: none; }
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible { scroll-margin-block: calc(var(--topbar-height) + var(--space-5)) calc(var(--tabbar-height) + var(--space-5)); }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; inset-inline-start: var(--space-4); top: var(--space-3); z-index: 100;
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-control);
  background: var(--accent); color: var(--on-accent); font-weight: 600; text-decoration: none;
  transform: translateY(-160%); opacity: 0; pointer-events: none;
  transition: transform var(--fast) var(--ease-out), opacity var(--fast) var(--ease-out);
}
.skip-link:focus-visible { transform: none; opacity: 1; pointer-events: auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}
@media (forced-colors: active) {
  body { background: Canvas; }
  :focus-visible { outline-color: Highlight; }
}

/* Reduced motion chosen in «المزيد» (progress.lowMotion), on top of the device setting. */
:root[data-motion="reduced"] *, :root[data-motion="reduced"] *::before, :root[data-motion="reduced"] *::after {
  animation-duration: .01ms !important; animation-iteration-count: 1 !important;
  transition-duration: .01ms !important; scroll-behavior: auto !important;
}
