/* ==========================================================================
   نَبْض | NABD — Kinetic Interior Design
   ملف: /css/animations.css
   حركات الكشف والانتقالات الحركية (Scroll-driven & Observer fallback)
   ========================================================================== */

/* ==========================================================================
   أ) إطارات الحركة الأساسية (Keyframes)
   ========================================================================== */

@keyframes revealFromRight {
  from {
    clip-path: inset(0 0 0 100%);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}

@keyframes revealFromLeft {
  from {
    clip-path: inset(0 100% 0 0);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}

@keyframes revealFromBottom {
  from {
    clip-path: inset(100% 0 0 0);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}

@keyframes revealCircle {
  from {
    clip-path: circle(0% at 50% 50%);
  }
  to {
    clip-path: circle(70% at 50% 50%);
  }
}

@keyframes revealUp {
  from {
    opacity: 0;
    transform: translateY(40px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes drawLine {
  from {
    stroke-dashoffset: 2000;
  }
  to {
    stroke-dashoffset: 0;
  }
}

/* ==========================================================================
   ب) حركات التمرير الحديثة (Scroll-Driven Animations — Chrome 115+)
   ========================================================================== */

@supports (animation-timeline: view()) {
  .reveal-from-right {
    animation: revealFromRight 800ms var(--ease-out-expo) both;
    animation-timeline: view();
    animation-range: entry 0% cover 40%;
  }

  .reveal-from-left {
    animation: revealFromLeft 800ms var(--ease-out-expo) both;
    animation-timeline: view();
    animation-range: entry 0% cover 40%;
  }

  .reveal-from-bottom {
    animation: revealFromBottom 800ms var(--ease-out-expo) both;
    animation-timeline: view();
    animation-range: entry 0% cover 40%;
  }

  .reveal-circle {
    animation: revealCircle 1000ms var(--ease-out-expo) both;
    animation-timeline: view();
    animation-range: entry 0% cover 45%;
  }

  .reveal-up {
    animation: revealUp 700ms var(--ease-out-expo) both;
    animation-timeline: view();
    animation-range: entry 0% cover 35%;
  }

  .timeline-line-svg path,
  .timeline-line-svg line {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    animation: drawLine 1ms linear both;
    animation-timeline: view();
    animation-range: entry 0% cover 80%;
  }
}

/* ==========================================================================
   ج) البديل للمتصفحات الأخرى (Fallback عبر IntersectionObserver)
   ========================================================================== */

@supports not (animation-timeline: view()) {
  .reveal-from-right {
    clip-path: inset(0 0 0 100%);
    transition: clip-path 800ms var(--ease-out-expo);
  }

  .reveal-from-left {
    clip-path: inset(0 100% 0 0);
    transition: clip-path 800ms var(--ease-out-expo);
  }

  .reveal-from-bottom {
    clip-path: inset(100% 0 0 0);
    transition: clip-path 800ms var(--ease-out-expo);
  }

  .reveal-circle {
    clip-path: circle(0% at 50% 50%);
    transition: clip-path 1000ms var(--ease-out-expo);
  }

  .reveal-up {
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 700ms var(--ease-out-expo),
                transform 700ms var(--ease-out-expo);
  }

  .reveal-from-right.is-visible {
    clip-path: inset(0 0 0 0);
  }

  .reveal-from-left.is-visible {
    clip-path: inset(0 0 0 0);
  }

  .reveal-from-bottom.is-visible {
    clip-path: inset(0 0 0 0);
  }

  .reveal-circle.is-visible {
    clip-path: circle(70% at 50% 50%);
  }

  .reveal-up.is-visible {
    opacity: 1;
    transform: none;
  }
}

/* ==========================================================================
   د) تتابع ظهور الكلمات (Word-Split Stagger)
   ========================================================================== */

.word-split > span {
  display: inline-block;
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 500ms var(--ease-out-expo),
              transform 500ms var(--ease-out-expo);
  transition-delay: calc(var(--i, 0) * 0.05s);
}

.word-split.is-visible > span {
  opacity: 1;
  transform: translateY(0);
}

/* ==========================================================================
   هـ) التنسيق الأساسي لمسار الخط الزمني (Timeline SVG Path)
   ========================================================================== */

.timeline-line-svg path,
.timeline-line-svg line {
  stroke: var(--acid);
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
}

/* ==========================================================================
   و) تحسين أداء الكومبوزيتور (will-change)
   ========================================================================== */

.hero-title-kinetic,
.project-card-img,
.marquee-track {
  will-change: transform;
}

/* ==========================================================================
   ز) احترام تفضيل تقليل الحركة (prefers-reduced-motion)
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .reveal-from-right,
  .reveal-from-left,
  .reveal-from-bottom,
  .reveal-circle,
  .reveal-up {
    animation: none !important;
    clip-path: none !important;
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  .word-split > span {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  .marquee-track {
    animation: none !important;
  }

  html {
    scroll-behavior: auto;
  }
}
