/* ===========================================================
   Urealm — الأساس: التصفير، والطباعة، والتركيز، والمنافع.

   ▸ **التركيز يُرى دائمًا.** حلقةٌ من لون النظام بإزاحة، لا خطٌّ
     رفيع يبتلعه الحدّ. من يتنقّل بلوحة المفاتيح يجب أن يعرف أين هو
     من نظرةٍ واحدة، لا من تخمين.

   ▸ ولا `outline: none` في هذا الملفّ ولا في غيره. حذفُ حلقة التركيز
     أشهر عطبٍ في الوصول، ويقع لأنّها «تشوّه الشكل» — والصواب أن
     تُصمَّم لا أن تُحذف.
   =========================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-block-size: 100dvh;
  background: var(--bg-base);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: var(--t-base);
  line-height: var(--lh-body);
  font-weight: var(--w-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

/* لحظة تبديل الوضع وحدها. الانتقال الدائم على كل عنصر يجعل الواجهة
   تبدو بطيئة في كل تفاعل، لا ناعمة. */
html.theme-switching,
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
  transition: background-color var(--dur-3) var(--ease),
              border-color var(--dur-3) var(--ease),
              color var(--dur-3) var(--ease),
              fill var(--dur-3) var(--ease) !important;
}

/* ----------------------- الطباعة ----------------------- */

h1, h2, h3, h4 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--w-medium);
  line-height: var(--lh-tight);
  letter-spacing: var(--track-display);
  text-wrap: balance;
  color: var(--fg);
}

h1 { font-size: var(--t-2xl); }
h2 { font-size: var(--t-xl); }
h3 { font-size: var(--t-lg); }
h4 { font-size: var(--t-md); }

p { margin: 0; text-wrap: pretty; }
ul, ol { margin: 0; padding: 0; list-style: none; }

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 0.2em;
  border-radius: var(--r-xs);
}

a:hover { text-decoration: underline; }
:root[data-links="underline"] a { text-decoration: underline; }

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

code {
  padding: 0.1em 0.36em;
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  background: var(--bg-inset);
  /* الشيفرة تُقرأ من اليسار في كل لغة، وعزلُها يمنع تسرّب الاتجاه. */
  direction: ltr;
  unicode-bidi: isolate;
}

kbd {
  display: inline-flex;
  align-items: center;
  min-inline-size: 1.6em;
  justify-content: center;
  padding: 0.15em 0.4em;
  border: 1px solid var(--line-strong);
  border-block-end-width: 2px;
  border-radius: var(--r-xs);
  background: var(--bg-surface-2);
  color: var(--fg-soft);
  font-size: var(--t-2xs);
  line-height: 1.4;
}

hr {
  block-size: 0;
  margin: var(--sp-5) 0;
  border: 0;
  border-block-start: 1px solid var(--line);
}

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

/* ----------------------- النماذج ----------------------- */

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

button {
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  color: inherit;
}

button:disabled,
[disabled],
[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.45;
}

textarea { resize: vertical; }

/* ----------------------- التركيز ----------------------- */

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* من طلب التركيز دائمًا رآه بالفأرة أيضًا، لا بلوحة المفاتيح وحدها. */
:root[data-focus="always"] :focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ----------------------- الجذر والطبقات ----------------------- */

.viewport {
  position: relative;
  min-block-size: 100dvh;
  isolation: isolate;
}

/* لا حبيبة ولا وهج. النقاء هو الأثر. */
.viewport::before,
.viewport::after { content: none; }

#layer-menu { position: relative; z-index: var(--z-menu); }
#layer-modal { position: relative; z-index: var(--z-modal); }
#layer-toast { position: relative; z-index: var(--z-toast); }

/* ----------------------- الإقلاع ----------------------- */

.boot {
  display: grid;
  place-items: center;
  gap: var(--sp-4);
  min-block-size: 100dvh;
  color: var(--fg-mute);
}

.boot__mark {
  inline-size: 40px;
  block-size: 40px;
  background: currentcolor;
  color: var(--fg);
  opacity: 0.5;
  mask: var(--logo-mask) center / contain no-repeat;
  -webkit-mask: var(--logo-mask) center / contain no-repeat;
}

.boot-error {
  display: grid;
  place-items: center;
  gap: var(--sp-3);
  min-block-size: 100dvh;
  padding: var(--sp-6);
  text-align: center;
  color: var(--danger);
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------- منافع ----------------------- */

.stack { display: flex; flex-direction: column; gap: var(--sp-4); min-inline-size: 0; }
.row { display: flex; align-items: center; gap: var(--sp-2); min-inline-size: 0; }
.row--wrap { flex-wrap: wrap; }
.grow { flex: 1; min-inline-size: 0; }

.truncate {
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted { color: var(--fg-mute); }

.label {
  font-size: var(--t-2xs);
  font-weight: var(--w-medium);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--fg-mute);
}

.scroll-y {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.scroll-x { overflow-x: auto; overscroll-behavior-x: contain; }

.scroll-y,
.scroll-x {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

/* Global invisible scrollbars — scrolling stays fully functional. */
* {
  scrollbar-width: none !important;
}
*::-webkit-scrollbar {
  inline-size: 0 !important;
  block-size: 0 !important;
  width: 0 !important;
  height: 0 !important;
  display: none !important;
}

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

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

/* ----------------------- الحركة ----------------------- */

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

:root[data-motion="reduced"] *,
:root[data-motion="reduced"] *::before,
:root[data-motion="reduced"] *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}
