/* ==========================================================================
   Motion layer for drwaelsalah.com
   Every effect here is gated by prefers-reduced-motion: no-preference.
   Scroll-linked effects use CSS scroll-driven animations where supported,
   and simply stay static where they are not.
   ========================================================================== */

/* ---- 1. Page transitions between pages (same-origin, Chrome/Edge) ---- */
@view-transition { navigation: auto; }
.site-header { view-transition-name: site-header; }
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root) { animation: vt-out 220ms var(--ease-out) both; }
  ::view-transition-new(root) { animation: vt-in 420ms var(--ease-out) both; }
  @keyframes vt-out { to { opacity: 0; transform: translateY(-10px); } }
  @keyframes vt-in { from { opacity: 0; transform: translateY(14px); } }
}
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* ---- 2. Reading progress bar ---- */
.scroll-progress { display: none; }
@supports (animation-timeline: scroll()) {
  @media (prefers-reduced-motion: no-preference) {
    .scroll-progress {
      display: block; position: fixed; inset-inline: 0; top: 0; height: 3px; z-index: 70; pointer-events: none;
      background: linear-gradient(90deg, #2fc9a8, var(--accent));
      transform-origin: left center; transform: scaleX(0);
      animation: progress-grow linear both; animation-timeline: scroll(root);
    }
    html[dir="rtl"] .scroll-progress { transform-origin: right center; background: linear-gradient(270deg, #2fc9a8, var(--accent)); }
    @keyframes progress-grow { to { transform: scaleX(1); } }
  }
}

/* ---- 3. Masked word reveal for headlines (words split by motion.js) ---- */
.mw { display: inline-block; overflow: hidden; vertical-align: top; padding: 0.08em 0.06em 0.18em; margin: -0.08em -0.06em -0.18em; }
.mw > .mwi { display: inline-block; will-change: transform; }
@media (prefers-reduced-motion: no-preference) {
  .js-motion .mw-split .mwi { transform: translateY(112%); }

  .js-motion .mw-split.mw-play .mwi {
    transform: none;
    transition: transform 900ms cubic-bezier(0.19, 1, 0.22, 1);
    transition-delay: calc(var(--w, 0) * 55ms + var(--d, 0ms));
  }
}

/* ---- 4. Hero photo: curtain reveal, then depth on scroll ---- */
@media (prefers-reduced-motion: no-preference) {
  .js-motion .hero-photo.hero-photo-in { animation: curtain 1200ms cubic-bezier(0.77, 0, 0.175, 1) both 150ms; }
  @keyframes curtain {
    from { clip-path: inset(0 0 100% 0 round 28px); transform: scale(1.12); }
    60% { transform: scale(1.04); }
    to { clip-path: inset(0 0 0 0 round 28px); transform: none; }
  }
  .js-motion .hero-media::before { animation: plate-in 1400ms var(--ease-out) both 350ms; }
  @keyframes plate-in { from { opacity: 0; transform: translate(-18px, 18px); } }
  .js-motion .hero-chip { animation: chip-in 800ms cubic-bezier(0.34, 1.4, 0.64, 1) both 1100ms; }
  @keyframes chip-in { from { opacity: 0; transform: translateY(18px) scale(0.92); } }
}
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .hero-media { animation: hero-drift linear both; animation-timeline: view(); animation-range: exit 0% exit 100%; }
    @keyframes hero-drift { to { transform: translateY(-60px) scale(0.97); opacity: 0.6; } }
  }
}

/* ---- 5. Heartbeat line drawn across the stats strip ---- */
.stats { position: relative; }
.pulse-line { position: absolute; inset-inline: 0; top: -1px; height: 44px; width: 100%; transform: translateY(-50%); pointer-events: none; overflow: visible; }
.pulse-line path { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
html[dir="rtl"] .pulse-line { transform: translateY(-50%) scaleX(-1); }
@media (prefers-reduced-motion: no-preference) {
  .js-motion .pulse-line path { stroke-dasharray: 1; stroke-dashoffset: 1; }
  .js-motion .stats.in .pulse-line path { stroke-dashoffset: 0; transition: stroke-dashoffset 1800ms cubic-bezier(0.65, 0, 0.35, 1) 150ms; }
}

/* ---- 6. Tiles: pointer spotlight and gentle tilt (mouse only) ---- */
.tile, .svc, .step, .info-card { --mx: 50%; --my: 50%; }
.tile::after, .svc::after, .step::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; opacity: 0;
  background: radial-gradient(420px circle at var(--mx) var(--my), rgba(47, 201, 168, .16), transparent 60%);
  transition: opacity 300ms ease;
}
.tile.feature::after, .svc.wide::after { background: radial-gradient(460px circle at var(--mx) var(--my), rgba(255, 255, 255, .16), transparent 60%); }
.svc, .step { position: relative; overflow: hidden; }
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .tile:hover::after, .svc:hover::after, .step:hover::after { opacity: 1; }
  .js .tilt.reveal.in, .tilt:not(.reveal) { transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)); transition: transform 600ms cubic-bezier(0.23, 1, 0.32, 1), opacity 600ms ease; transition-delay: 0ms; }
  .js .tilt.tilting.reveal.in, .tilt.tilting:not(.reveal) { transition: transform 120ms linear; }
}

/* ---- 7. Reels rail: cards settle in as they enter the rail (motion.js toggles .on) ---- */
@media (prefers-reduced-motion: no-preference) {
  .js-motion .rail > .reel { transition: opacity 500ms ease, transform 700ms cubic-bezier(0.23, 1, 0.32, 1); }
  .js-motion .rail > .reel.reveal { transition-delay: 0ms; }
  .js-motion .rail > .reel.reveal.in:not(.on) { opacity: .45; transform: scale(.9); }
  .js-motion .rail > .reel.on { opacity: 1; transform: none; }
}
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .reel-frame { transition: transform 400ms cubic-bezier(0.23, 1, 0.32, 1), box-shadow 400ms ease; }
  .reel:hover .reel-frame { transform: translateY(-6px); box-shadow: var(--shadow-md); }
}

/* ---- 8. Split photo: parallax inside its frame ---- */
.split-media { position: relative; overflow: hidden; border-radius: 28px; box-shadow: var(--shadow-md); aspect-ratio: 4 / 5; width: 100%; }
.split-media .split-photo { width: 100%; height: 100%; aspect-ratio: auto; border-radius: 0; box-shadow: none; object-fit: cover; }
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .split-media .split-photo { scale: 1.16; animation: parallax linear both; animation-timeline: view(); }
    @keyframes parallax { from { translate: 0 -7%; } to { translate: 0 7%; } }
  }
}
@media (max-width: 960px) { .split-media { max-width: 460px; } }

/* ---- 9. Quotes: the rule draws, then the words arrive ---- */
.quote { border-top: 0; position: relative; }
.quote::before { content: ""; position: absolute; inset-inline: 0; top: 0; height: 2px; background: var(--accent); transform-origin: left center; }
html[dir="rtl"] .quote::before { transform-origin: right center; }
.quote .qmark { position: absolute; inset-inline-end: 0; top: 14px; font-size: 5rem; line-height: 1; color: var(--accent); opacity: .12; font-weight: 700; pointer-events: none; }
@media (prefers-reduced-motion: no-preference) {
  .js-motion .quote::before { transform: scaleX(0); transition: transform 1000ms cubic-bezier(0.65, 0, 0.35, 1); }
  .js-motion .quote.in::before { transform: scaleX(1); }
  .js-motion .quote .stars i { display: inline-block; opacity: 0; transform: scale(.4) rotate(-30deg); transition: opacity 300ms ease, transform 500ms cubic-bezier(0.34, 1.56, 0.64, 1); }
  .js-motion .quote.in .stars i { opacity: 1; transform: none; }
  .js-motion .quote.in .stars i:nth-child(1) { transition-delay: 500ms; }
  .js-motion .quote.in .stars i:nth-child(2) { transition-delay: 570ms; }
  .js-motion .quote.in .stars i:nth-child(3) { transition-delay: 640ms; }
  .js-motion .quote.in .stars i:nth-child(4) { transition-delay: 710ms; }
  .js-motion .quote.in .stars i:nth-child(5) { transition-delay: 780ms; }
}

/* ---- 10. Brand band: slow living gradient + magnetic buttons ---- */
.band, .action-card { background-size: 180% 180%; }
.band::before {
  content: ""; position: absolute; width: 55%; aspect-ratio: 1; top: -35%; inset-inline-start: -15%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(closest-side, rgba(47, 201, 168, .38), transparent);
}
.band > * { position: relative; }
@media (prefers-reduced-motion: no-preference) {
  .band, .action-card { animation: band-flow 14s ease-in-out infinite alternate; }
  @keyframes band-flow { from { background-position: 0% 30%; } to { background-position: 100% 70%; } }
  .band::before { animation: orb 18s ease-in-out infinite alternate; }
  @keyframes orb { from { transform: translate(0, 0); } to { transform: translate(140%, 40%); } }
}
.magnetic { transition: transform 500ms cubic-bezier(0.23, 1, 0.32, 1), background-color 160ms ease, color 160ms ease, border-color 160ms ease; }
.magnetic.pulling { transition: transform 120ms linear, background-color 160ms ease; }

/* ---- 11. Floating WhatsApp: arrives late, rings once ---- */
@media (prefers-reduced-motion: no-preference) {
  .wa-float { animation: wa-in 700ms cubic-bezier(0.34, 1.56, 0.64, 1) 1400ms both; }
  @keyframes wa-in { from { opacity: 0; transform: translateY(24px) scale(.6); } }
  .wa-float::after {
    content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid #1f9d55; opacity: 0;
    animation: wa-ring 1600ms var(--ease-out) 5s 2;
  }
  @keyframes wa-ring { 0% { opacity: .7; transform: scale(1); } 100% { opacity: 0; transform: scale(1.8); } }
}

/* ---- 12. Section icons pop in with the reveal ---- */
@media (prefers-reduced-motion: no-preference) {
  .js .reveal .ico, .js .reveal .ci { transform: scale(.6) rotate(-12deg); opacity: 0; transition: transform 700ms cubic-bezier(0.34, 1.56, 0.64, 1) 200ms, opacity 300ms ease 200ms; }
  .js .reveal.in .ico, .js .reveal.in .ci { transform: none; opacity: 1; }
  .js .checks .reveal .ci, .js .cv .reveal .ci { transition-delay: 250ms; }
}
