/* =============================================================
   ANDALOUS — 01. Tokens, Reset, Base Typography
   -------------------------------------------------------------
   كل الألوان مستخرجة من الشعار ومن صور المشاريع الفعلية.
   لا تستخدم قيمًا لونية خارج هذه القائمة.
   ============================================================= */

@font-face {
  font-family: 'Reem Kufi Fallback';
  src: local('Segoe UI'), local('Tahoma');
  size-adjust: 96%;
}

:root {
  /* ---------- اللون ---------- */
  --c-ink: #1a1e22;          /* حبر الخليل — من تكسية سما مول الداكنة */
  --c-ink-2: #23282d;        /* حبر أفتح — أسطح داكنة ثانوية */
  --c-stone: #efe9e0;        /* ورق حجري — خلفية الموقع الافتراضية */
  --c-stone-2: #e4dcd0;      /* حجر أعمق — أسطح فاتحة ثانوية */
  --c-sand: #b9a78e;         /* رمل مظلَّل — حدود، ونص ثانوي على الداكن فقط */
  --c-sand-deep: #6b5c47;    /* رمل داكن — نص ثانوي على الفاتح (5.20:1) */
  --c-light: #c8913d;        /* ضوء دافئ — تعبئة وحدود فقط، لا نصّ على الفاتح */
  --c-light-ink: #8a5f13;    /* ضوء دافئ داكن — نصّ التفاعل وحلقة التركيز على الفاتح (4.67:1) */
  --c-light-soft: #e0ab5c;   /* ضوء دافئ فاتح — على الخلفيات الداكنة (8.10:1) */
  --c-gold: #bea23e;         /* ذهب أندلسي — للنجمة والشعار فقط */
  --c-dusk: #3c4a6b;         /* أزرق الغسق — أشرطة الليل */
  --c-dusk-deep: #262f45;

  /* أدوار وظيفية */
  --bg: var(--c-stone);
  --fg: var(--c-ink);
  --fg-muted: #5c5750;
  --rule: rgba(26, 30, 34, 0.16);
  --rule-soft: rgba(26, 30, 34, 0.08);
  --rule-control: #767068;   /* حدود حقول الإدخال — 3.06:1 على الأبيض */

  /* على الأسطح الداكنة */
  --fg-on-dark: #f3eee6;
  --fg-on-dark-muted: #b8b0a4;
  --rule-on-dark: rgba(243, 238, 230, 0.2);

  /* ---------- الطباعة ---------- */
  --ff-display: 'Reem Kufi', 'Reem Kufi Fallback', 'Segoe UI', Tahoma, sans-serif;
  --ff-body: 'IBM Plex Sans Arabic', 'Segoe UI', Tahoma, Arial, sans-serif;
  --ff-mono: 'IBM Plex Mono', ui-monospace, 'Courier New', monospace;

  --fs-mono: clamp(0.688rem, 0.63rem + 0.16vw, 0.75rem);
  --fs-xs: clamp(0.813rem, 0.78rem + 0.16vw, 0.875rem);
  --fs-sm: clamp(0.938rem, 0.9rem + 0.19vw, 1rem);
  --fs-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --fs-lg: clamp(1.125rem, 1.05rem + 0.38vw, 1.375rem);
  --fs-xl: clamp(1.375rem, 1.2rem + 0.75vw, 1.875rem);
  --fs-2xl: clamp(1.75rem, 1.4rem + 1.6vw, 2.75rem);
  --fs-3xl: clamp(2.25rem, 1.6rem + 2.9vw, 4.25rem);
  --fs-4xl: clamp(2.75rem, 1.7rem + 4.6vw, 6rem);

  --lh-tight: 1.12;
  --lh-snug: 1.3;
  --lh-body: 1.85;

  /* ---------- المسافات (نظام موحّد — لا قيم عشوائية) ---------- */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;
  --s8: 4rem;
  --s9: 6rem;
  --s10: 8rem;
  --s11: 10rem;

  /* إيقاع الأقسام */
  --band-y: clamp(3.25rem, 7vw, 6.5rem);
  --band-y-lg: clamp(4rem, 9vw, 8.5rem);

  /* ---------- القياس ---------- */
  --measure: 62ch;
  --wrap: 1320px;
  --wrap-narrow: 900px;
  --gutter: clamp(1.25rem, 5vw, 4rem);
  --rail: 0px; /* عرض حجز مؤشّر النجمة — يُفعَّل على الشاشات الكبيرة */

  /* ---------- الحركة ---------- */
  --e-out: cubic-bezier(0.22, 0.61, 0.36, 1);
  --e-inout: cubic-bezier(0.65, 0, 0.35, 1);
  --t-fast: 180ms;
  --t-base: 340ms;
  --t-slow: 700ms;

  --header-h: 4.5rem;
}

@media (min-width: 1180px) {
  :root {
    --rail: 5.5rem;
    --header-h: 5.25rem;
  }
}

/* =============================================================
   Reset
   ============================================================= */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* يمنع اختفاء العناوين خلف الهيدر الثابت عند القفز بالمرساة */
  scroll-padding-top: calc(var(--header-h) + 1rem);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--ff-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
  /* احترام المناطق الآمنة على الأجهزة ذات الحواف المنحنية */
  padding-inline: env(safe-area-inset-right) env(safe-area-inset-left);
}

body.is-locked {
  overflow: hidden;
}

h1,
h2,
h3,
h4,
p,
figure,
blockquote,
ul,
ol,
dl {
  margin: 0;
}

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

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

img,
video {
  height: auto;
}

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

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

a {
  color: inherit;
  text-decoration: none;
}

address {
  font-style: normal;
}

/* =============================================================
   Focus — واضح ودائمًا مرئي بلوحة المفاتيح
   ============================================================= */

:focus-visible {
  outline: 2px solid var(--c-light-ink);
  outline-offset: 3px;
  border-radius: 2px;
}

.and-on-dark :focus-visible,
.and-dark :focus-visible {
  outline-color: var(--c-light-soft);
}

/* =============================================================
   Typography primitives
   ============================================================= */

.and-display {
  font-family: var(--ff-display);
  font-weight: 600;
  line-height: var(--lh-tight);
  letter-spacing: 0;
}

.and-h1 {
  font-family: var(--ff-display);
  font-weight: 600;
  font-size: var(--fs-3xl);
  line-height: var(--lh-tight);
  margin: 0;
}

.and-h2 {
  font-family: var(--ff-display);
  font-weight: 600;
  font-size: var(--fs-2xl);
  line-height: var(--lh-snug);
  margin: 0;
}

.and-h3 {
  font-family: var(--ff-display);
  font-weight: 500;
  font-size: var(--fs-xl);
  line-height: var(--lh-snug);
  margin: 0;
}

.and-lede {
  font-size: var(--fs-lg);
  line-height: 1.7;
  color: var(--fg);
  max-width: 48ch;
}

.and-prose p {
  max-width: var(--measure);
  margin-block-end: var(--s5);
}

.and-prose p:last-child {
  margin-block-end: 0;
}

/* تسمية أحادية المسافة — تُستخدم لأرقام اللوحات والمراحل فقط،
   وكل رقم فيها له مرجع حقيقي */
.and-label {
  font-family: var(--ff-mono);
  font-size: var(--fs-mono);
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--c-sand-deep);
  display: inline-flex;
  align-items: center;
  gap: var(--s3);
}

.and-on-dark .and-label {
  color: var(--fg-on-dark-muted);
}

/* النجمة الصغيرة التي تسبق التسمية — نفس مفردة الشعار */
.and-label::before {
  content: '';
  inline-size: 0.5rem;
  block-size: 0.5rem;
  flex: none;
  background: currentColor;
  opacity: 0.75;
  clip-path: polygon(
    50% 0%, 61% 28%, 89% 11%, 72% 39%, 100% 50%, 72% 61%,
    89% 89%, 61% 72%, 50% 100%, 39% 72%, 11% 89%, 28% 61%,
    0% 50%, 28% 39%, 11% 11%, 39% 28%
  );
}

.and-label--bare::before {
  display: none;
}

/* =============================================================
   Utilities
   ============================================================= */

.and-wrap {
  inline-size: 100%;
  max-inline-size: var(--wrap);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.and-wrap--narrow {
  max-inline-size: var(--wrap-narrow);
}

/* حجز مساحة مؤشّر النجمة على الشاشات الكبيرة.
   max() ضروري: دون 1180px يكون --rail صفرًا، ولولاها لألغى هذا السطر
   هامش .and-wrap تمامًا فالتصق المحتوى بحافة الشاشة. */
.and-rail-pad {
  padding-inline-start: max(var(--gutter), var(--rail));
}

.and-sr {
  position: absolute !important; /* مطلوب لإخفاء بصري مع إبقاء النص لقارئ الشاشة */
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.and-skip {
  position: absolute;
  inset-block-start: -100%;
  inset-inline-start: var(--s4);
  z-index: 200;
  background: var(--c-ink);
  color: var(--fg-on-dark);
  padding: var(--s3) var(--s5);
  font-size: var(--fs-sm);
  transition: inset-block-start var(--t-fast) var(--e-out);
}

.and-skip:focus {
  inset-block-start: var(--s4);
}

/* =============================================================
   الأزرار — صيغة فعل مباشر دائمًا
   ============================================================= */

.and-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  min-block-size: 3rem;
  padding: var(--s3) var(--s6);
  font-family: var(--ff-body);
  font-size: var(--fs-sm);
  font-weight: 500;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  transition: background-color var(--t-fast) var(--e-out),
    color var(--t-fast) var(--e-out), border-color var(--t-fast) var(--e-out),
    transform var(--t-fast) var(--e-out);
}

.and-btn:active {
  transform: translateY(1px);
}

/* كل أيقونة inline SVG داخل زر أو رابط تأخذ قياسها من حجم النص.
   بدون هذه القاعدة يمنحها المتصفح مقاسه الافتراضي 300×150 فيتشوّه الزر. */
.and-btn > svg,
.and-link > svg,
.and-btn__ico {
  inline-size: 1.05em;
  block-size: 1.05em;
  flex: none;
}

/* نصّ الزر لا ينكسر إلى سطرين داخل شريط أفقي */
.and-btn > span {
  white-space: nowrap;
}

/* على الشاشات الضيّقة تُسمح بالالتفاف حتى لا يتجاوز الزر عرض الشاشة */
@media (max-width: 420px) {
  .and-btn > span {
    white-space: normal;
  }
}

/* أساسي — الضوء الدافئ */
.and-btn--solid {
  background: var(--c-light);
  color: #1a1204;
  border-color: var(--c-light);
}

.and-btn--solid:hover {
  background: #b47f2f;
  border-color: #b47f2f;
}

/* ثانوي على الفاتح */
.and-btn--line {
  border-color: var(--rule);
  color: var(--fg);
}

.and-btn--line:hover {
  border-color: var(--c-ink);
  background: rgba(26, 30, 34, 0.05);
}

/* ثانوي على الداكن */
.and-btn--ghost {
  border-color: var(--rule-on-dark);
  color: var(--fg-on-dark);
}

.and-btn--ghost:hover {
  border-color: var(--fg-on-dark);
  background: rgba(243, 238, 230, 0.09);
}

.and-btn--sm {
  min-block-size: 2.5rem;
  padding: var(--s2) var(--s5);
  font-size: var(--fs-xs);
}

/* رابط نصّي بخط سفلي يتمدّد */
.and-link {
  display: inline-flex;
  align-items: center;
  gap: var(--s3);
  font-size: var(--fs-sm);
  font-weight: 500;
  padding-block: var(--s2);
  position: relative;
}

.and-link::after {
  content: '';
  position: absolute;
  inset-block-end: 0;
  inset-inline-start: 0;
  inline-size: 100%;
  block-size: 1px;
  background: currentColor;
  opacity: 0.32;
  transform-origin: right;
  transform: scaleX(1);
  transition: opacity var(--t-fast) var(--e-out);
}

.and-link:hover {
  color: var(--c-light-ink);
}

.and-link:hover::after {
  opacity: 1;
}

.and-on-dark .and-link:hover {
  color: var(--c-light-soft);
}

/* السهم في RTL يشير إلى اليسار */
.and-link__arrow {
  inline-size: 1.1em;
  block-size: 1.1em;
  flex: none;
  transition: transform var(--t-base) var(--e-out);
}

.and-link:hover .and-link__arrow,
.and-btn:hover .and-btn__ico--arrow {
  transform: translateX(-0.28em);
}

/* =============================================================
   Reduced motion — احترام كامل
   ============================================================= */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important; /* مطلوب لتعطيل حركة الطرف الثالث */
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
