/* ─────────────────────────────────────────────────────────────────────────
   SWING — Scroll motion layer
   Loaded after styles.css. All declarations are additive; nothing here
   overrides existing visual styles outside of [data-motion] subtrees.
   ───────────────────────────────────────────────────────────────────────── */

[data-motion] {
  --motion-progress: 0;
  --motion-i: 0;
  --motion-n: 1;
}

.motion-ready[data-motion] {
  will-change: transform, opacity, filter;
}

/* Reduced-motion: snap to entered state, no transitions. */
.motion-reduced [data-motion] {
  --motion-progress: 1 !important;
  transition: none !important;
  animation: none !important;
}

/* ── 1. Reveal — fade + lift in ── */
.motion-ready[data-motion="reveal"] {
  opacity: calc(0.05 + var(--motion-progress) * 0.95);
  transform: translate3d(0, calc((1 - var(--motion-progress)) * 32px), 0);
  transition: opacity .6s ease, transform .6s cubic-bezier(.2,.7,.2,1);
}
.motion-ready[data-motion="reveal"].motion-entered {
  opacity: 1;
  transform: none;
}

/* ── 2. Stagger cascade ── */
.motion-ready[data-motion="stagger"] > * {
  opacity: 0;
  transform: translate3d(0, 36px, 0) scale(.97);
  transition:
    opacity .55s ease calc(var(--motion-i) * 90ms),
    transform .7s cubic-bezier(.2,.7,.2,1) calc(var(--motion-i) * 90ms);
}
.motion-ready[data-motion="stagger"].motion-entered > * {
  opacity: 1;
  transform: none;
}

/* ── 3. Parallax ── */
.motion-ready[data-motion="parallax"] {
  --motion-speed: 0.4;
  transform: translate3d(0, calc((var(--motion-progress) - .5) * var(--motion-speed) * 240px), 0);
  will-change: transform;
}

/* ── 4. Hero rings scrub ── */
.motion-ready[data-motion="hero-rings"] .h3r-ring-1 {
  transform: rotateX(calc(58deg - var(--motion-progress) * 25deg)) scale(calc(1 + var(--motion-progress) * .35)) !important;
  animation: none !important;
}
.motion-ready[data-motion="hero-rings"] .h3r-ring-2 {
  transform: rotateX(calc(58deg - var(--motion-progress) * 25deg)) scale(calc(1 + var(--motion-progress) * .25)) rotate(calc(var(--motion-progress) * 30deg)) !important;
  animation: none !important;
}
.motion-ready[data-motion="hero-rings"] .h3r-ring-3 {
  transform: rotateX(calc(58deg - var(--motion-progress) * 25deg)) scale(calc(1 + var(--motion-progress) * .18)) rotate(calc(var(--motion-progress) * -45deg)) !important;
  animation: none !important;
}

/* ── 5. Sticky pin sequence ── */
.motion-pin-stage {
  position: relative;
  min-height: 230vh;
}
.motion-pin-stage > .motion-pin-track {
  position: sticky;
  top: 12vh;
  height: 76vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* ── 6. Horizontal scroll track ── */
.motion-ready[data-motion="horizontal"] {
  position: relative;
  min-height: 200vh;
}
.motion-ready[data-motion="horizontal"] .motion-htrack-pin {
  position: sticky;
  top: 14vh;
  height: 72vh;
  overflow: hidden;
  display: flex;
  align-items: center;
}
.motion-ready[data-motion="horizontal"] .motion-htrack {
  display: flex;
  gap: clamp(1rem, 2.4vw, 2.4rem);
  padding: 0 6vw;
  transform: translate3d(calc(var(--motion-progress) * -60%), 0, 0);
  will-change: transform;
}
.motion-ready[data-motion="horizontal"] .motion-htrack > * {
  flex: 0 0 clamp(240px, 32vw, 380px);
  opacity: calc(0.55 + var(--motion-progress) * 0.5);
}

/* ── 7. Mockup frame ── */
.mockup-frame {
  position: relative;
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(11,124,255,0.12), rgba(0,167,255,0.04));
  border: 1px solid rgba(59,130,246,0.18);
  box-shadow: 0 30px 70px -30px rgba(11,40,90,0.4),
              inset 0 1px 0 rgba(255,255,255,0.6);
}
.mockup-frame::before {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(120% 90% at 50% 0%, rgba(255,255,255,0.45), transparent 60%);
  pointer-events: none; z-index: 2;
}
.mockup-frame img {
  display: block;
  width: 100%;
  height: auto;
}
.mockup-frame .mockup-glow {
  position: absolute;
  inset: -30%;
  background: radial-gradient(50% 50% at 50% 50%, rgba(11,124,255,0.35), transparent 70%);
  filter: blur(40px);
  pointer-events: none;
  z-index: 0;
  opacity: calc(.4 + var(--motion-progress) * 0.5);
}
.mockup-frame .mockup-bezel {
  position: absolute; inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 3;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.45), transparent 25%, transparent 70%, rgba(11,40,90,0.18));
  mix-blend-mode: overlay;
}

/* ── 8. Mask wipe reveal ── */
.motion-ready[data-motion="mask-wipe"] {
  clip-path: inset(
    calc((1 - var(--motion-progress)) * 22%)
    calc((1 - var(--motion-progress)) * 14%)
    calc((1 - var(--motion-progress)) * 22%)
    calc((1 - var(--motion-progress)) * 14%)
    round 22px
  );
  transform: scale(calc(0.9 + var(--motion-progress) * 0.1));
  transition: clip-path .6s cubic-bezier(.2,.7,.2,1), transform .6s ease;
}

/* Circle expand mask */
.motion-ready[data-motion="circle-reveal"] {
  -webkit-mask-image: radial-gradient(circle at 50% 55%, #000 calc(var(--motion-progress) * 95%), transparent calc(var(--motion-progress) * 100%));
          mask-image: radial-gradient(circle at 50% 55%, #000 calc(var(--motion-progress) * 95%), transparent calc(var(--motion-progress) * 100%));
}

/* ── 9. Pricing cascade ── */
.motion-ready[data-motion="pricing-cascade"] > .pricing-card {
  opacity: 0;
  transform: translate3d(0, 90px, 0) rotateX(8deg);
  transform-origin: 50% 100%;
  transition:
    opacity .55s ease calc(var(--motion-i) * 110ms),
    transform .8s cubic-bezier(.2,.7,.2,1) calc(var(--motion-i) * 110ms);
}
.motion-ready[data-motion="pricing-cascade"].motion-entered > .pricing-card {
  opacity: 1;
  transform: none;
}
.motion-ready[data-motion="pricing-cascade"].motion-entered > .pricing-card.is-popular {
  transform: translateY(-6px) scale(1.03);
  z-index: 2;
}

/* ── 10. Workflow draw ── */
.motion-ready[data-motion="workflow"] .workflow-connector {
  position: relative;
  overflow: hidden;
}
.motion-ready[data-motion="workflow"] .workflow-connector::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: 2px;
  background: linear-gradient(90deg, rgba(11,124,255,0.6), rgba(0,167,255,0.95));
  transform-origin: left center;
  transform: scaleX(var(--motion-progress, 0));
  transition: transform .4s ease;
  border-radius: 999px;
  box-shadow: 0 0 14px rgba(11,124,255,0.45);
}
.motion-ready[data-motion="workflow"] .workflow-card {
  opacity: 0;
  transform: translateY(40px) scale(.96);
  transition:
    opacity .55s ease calc(var(--motion-i) * 220ms),
    transform .7s cubic-bezier(.2,.7,.2,1) calc(var(--motion-i) * 220ms);
}
.motion-ready[data-motion="workflow"].motion-entered .workflow-card {
  opacity: 1;
  transform: none;
}

/* ── 11. Hero scene parallax ── */
.motion-ready[data-motion="hero-parallax"] [data-parallax] {
  --speed: 0.4;
  transform: translate3d(0, calc(var(--motion-progress) * var(--speed) * -160px), 0);
  will-change: transform;
}
.motion-ready[data-motion="hero-parallax"] [data-parallax="0.2"] { --speed: 0.2; }
.motion-ready[data-motion="hero-parallax"] [data-parallax="0.4"] { --speed: 0.4; }
.motion-ready[data-motion="hero-parallax"] [data-parallax="0.6"] { --speed: 0.6; }
.motion-ready[data-motion="hero-parallax"] [data-parallax="0.8"] { --speed: 0.8; }
.motion-ready[data-motion="hero-parallax"] [data-parallax="-0.3"] { --speed: -0.3; }

/* ── 12. Gradient text shimmer ── */
.motion-gradient-text {
  background-image: linear-gradient(
    100deg,
    #0b7cff 0%, #00a7ff 30%, #2868ff 50%, #00a7ff 70%, #0b7cff 100%
  );
  background-size: 220% 100%;
  background-position: calc(var(--motion-progress, 0) * 100%) 50%;
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
  transition: background-position .4s linear;
}

/* ── 13. Grand finale ── */
.motion-finale {
  position: relative;
  padding: clamp(4rem, 10vh, 8rem) 0;
  text-align: center;
}
.motion-finale .finale-eyebrow {
  font-family: "JetBrains Mono", monospace;
  font-size: .82rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #355578;
  margin-bottom: 1rem;
}
.motion-finale .finale-title {
  font-size: clamp(1.8rem, 4vw, 3rem);
  margin-bottom: 2.5rem;
  font-weight: 600;
  color: #071a3d;
}
.motion-finale .finale-shot {
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 4vw;
}
.motion-finale .finale-shot .mockup-frame {
  border-radius: 26px;
}

/* ── 14. Profile gauge ── */
.motion-ready[data-motion="gauge"] .gauge-needle {
  transform-origin: 100px 100px;
  transform: rotate(calc(-90deg + var(--motion-progress) * 180deg));
  transition: transform .25s ease-out;
}

/* ── 15. Account: dashboard cascade ── */
.motion-ready[data-motion="dashboard-cascade"] > * {
  opacity: 0;
  transform: translateY(28px);
  transition:
    opacity .5s ease calc(var(--motion-i) * 70ms),
    transform .6s cubic-bezier(.2,.7,.2,1) calc(var(--motion-i) * 70ms);
}
.motion-ready[data-motion="dashboard-cascade"].motion-entered > * {
  opacity: 1;
  transform: none;
}

/* ── 16. Section divider wave ── */
.motion-divider {
  position: relative;
  height: 80px;
  margin: -1px 0;
  overflow: hidden;
  pointer-events: none;
}
.motion-divider svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.motion-divider .divider-back {
  transform: translate3d(calc(var(--motion-progress, 0) * -40px), 0, 0);
  opacity: .35;
}
.motion-divider .divider-front {
  transform: translate3d(calc(var(--motion-progress, 0) * 60px), 0, 0);
  opacity: .65;
}

/* ── 17. Hero card scrub-in ── */
.motion-ready[data-motion="hero-card"] {
  transform: perspective(1100px)
             translateZ(calc(var(--motion-progress) * 60px))
             rotateY(calc((1 - var(--motion-progress)) * -10deg))
             rotateX(calc((1 - var(--motion-progress)) * 6deg));
  transition: transform .25s ease-out;
}

/* ── 18. Profiles section background image layer ── */
.profiles-section.has-bg-mockup {
  position: relative;
}
.profiles-section.has-bg-mockup .profiles-bg {
  position: absolute;
  inset: -10% 5%;
  z-index: 0;
  border-radius: 26px;
  overflow: hidden;
  opacity: calc(.35 + var(--motion-progress, 0) * .35);
  pointer-events: none;
  filter: blur(0.5px) saturate(1.05);
  transform: translate3d(0, calc(var(--motion-progress, 0) * -40px), 0);
}
.profiles-section.has-bg-mockup .profiles-bg img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.profiles-section.has-bg-mockup .profiles-inner {
  position: relative;
  z-index: 1;
}

/* ── 19. Mobile: drop heavy effects ── */
@media (max-width: 768px) {
  .motion-pin-stage,
  .motion-ready[data-motion="horizontal"] {
    min-height: auto !important;
  }
  .motion-pin-stage > .motion-pin-track,
  .motion-ready[data-motion="horizontal"] .motion-htrack-pin {
    position: relative !important;
    top: auto !important;
    height: auto !important;
  }
  .motion-ready[data-motion="horizontal"] .motion-htrack {
    flex-wrap: wrap;
    transform: none !important;
    padding: 0 1rem;
  }
  .motion-ready[data-motion="horizontal"] .motion-htrack > * {
    flex: 1 1 100%;
    opacity: 1;
  }
  .motion-ready[data-motion="hero-card"],
  .motion-ready[data-motion="hero-rings"] .h3r-ring-1,
  .motion-ready[data-motion="hero-rings"] .h3r-ring-2,
  .motion-ready[data-motion="hero-rings"] .h3r-ring-3,
  .motion-ready[data-motion="hero-parallax"] [data-parallax] {
    transform: none !important;
  }
  .mockup-frame { box-shadow: 0 14px 30px -18px rgba(11,40,90,0.35); }
  .motion-finale { padding: 3rem 0; }
}

/* Keep keyboard focus visible above motion layers. */
.motion-ready[data-motion] :focus-visible {
  outline: 2px solid #0b7cff;
  outline-offset: 3px;
  border-radius: 6px;
}
