/*
 * iFusion Volt — Market Segments 3D Scroll Transition
 * Framer Motion-style scroll-driven animations using CSS + vanilla JS.
 * Sticky fullscreen viewport with crossfading backgrounds, 3D product transform, and text transitions.
 */

/* ─────────────────────────── Section Container ─────────────────────────── */
.markets-section {
  position: relative;
  width: 100%;
  /* 6 panels of scroll + 1 viewport height for the sticky to remain visible.
     Shorter = less scrolling needed to move between segments. */
  height: 360vh;
}

/* ─────────────────────────── Sticky Viewport ─────────────────────────── */
.markets-sticky {
  position: sticky;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Hidden scroll track panels (just for scroll distance) */
.markets-scroll-track {
  display: none;
}

/* ─────────────────────────── Background Layers ─────────────────────────── */
.markets-bg-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 1.4s ease-in-out;
  will-change: opacity;
}

.markets-bg-layer.active {
  opacity: 1;
}

.markets-bg-layer img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transform: scale(1.05);
  transition: transform 6s cubic-bezier(0.16, 1, 0.3, 1);
}

.markets-bg-layer.active img {
  transform: scale(1);
}

/* ─────────────────────────── Dark Overlay ─────────────────────────── */
.markets-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    rgba(8, 8, 8, 0.82) 0%,
    rgba(8, 8, 8, 0.55) 40%,
    rgba(8, 8, 8, 0.25) 70%,
    rgba(8, 8, 8, 0.5) 100%
  );
  z-index: 1;
  pointer-events: none;
}

/* ─────────────────────────── Product Image (3D) ─────────────────────────── */
.markets-product {
  position: absolute;
  left: 42%;
  right: auto;
  bottom: 3%;
  transform: translateX(-50%);
  width: clamp(340px, 46vw, 660px);
  z-index: 3;
  perspective: 1200px;
  transform-style: preserve-3d;
}

.markets-product img {
  width: 100%;
  height: auto;
  transform: rotateY(-8deg) rotateX(2deg) translateZ(0);
  transition: transform 1s cubic-bezier(0.16, 1, 0.3, 1);
  filter: drop-shadow(0 30px 60px rgba(0, 0, 0, 0.8));
  will-change: transform;
}

/* Tubes colour layer — auto-animated light that shifts colour per segment */
.markets-tubes {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 2;
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: 0.6;
  transition: opacity 1.2s ease;
}
@media (prefers-reduced-motion: reduce) {
  .markets-tubes { display: none; }
}

/* ─────────────────────────── Text Content ─────────────────────────── */
.markets-content {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 55%;
  z-index: 4;
  display: flex;
  align-items: center;
  padding-left: clamp(1.5rem, 5vw, 4rem);
}

.markets-text {
  position: absolute;
  top: clamp(3.5rem, 12vh, 7.5rem);
  max-width: 560px;
  opacity: 0;
  transform: translateY(40px);
  transition: opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  will-change: opacity, transform;
}

.markets-text.active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.markets-text.exiting {
  opacity: 0;
  transform: translateY(-30px);
}

/* ─────────────────────────── Text Styling ─────────────────────────── */
.markets-index {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--blue);
  margin-bottom: 1rem;
  padding: 0.3rem 0.8rem;
  background: rgba(10, 132, 255, 0.1);
  border: 1px solid rgba(10, 132, 255, 0.25);
  border-radius: 980px;
}

.markets-title {
  font-size: clamp(2rem, 4.5vw, 3.5rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--white);
  margin: 0 0 1rem;
  text-wrap: balance;
}

.markets-tagline {
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 400;
  font-style: italic;
  color: var(--blue-soft);
  margin: 0 0 1.25rem;
  line-height: 1.4;
}

.markets-desc {
  font-size: clamp(0.9375rem, 1.5vw, 1.0625rem);
  color: var(--muted);
  line-height: 1.7;
  margin: 0;
  text-wrap: pretty;
}

/* ─────────────────────────── Progress Dots ─────────────────────────── */
.markets-progress {
  position: absolute;
  right: 2rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.markets-progress-dot {
  width: 8px;
  height: 8px;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
}

.markets-progress-dot.active {
  background: var(--blue);
  border-color: var(--blue);
  box-shadow: 0 0 12px rgba(10, 132, 255, 0.5);
  transform: scale(1.4);
}

.markets-progress-dot:hover:not(.active) {
  background: rgba(255, 255, 255, 0.4);
  transform: scale(1.2);
}

/* ─────────────────────────── Responsive ─────────────────────────── */
@media (max-width: 900px) {
  .markets-content {
    width: 100%;
    padding: 0 1.5rem;
    align-items: flex-start;
    padding-top: clamp(4.5rem, 12vh, 8rem);
  }

  .markets-product {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    top: auto;
    bottom: 4%;
    width: clamp(240px, 64vw, 380px);
    opacity: 1;
  }

  .markets-overlay {
    background: linear-gradient(
      to bottom,
      rgba(8, 8, 8, 0.92) 0%,
      rgba(8, 8, 8, 0.66) 38%,
      rgba(8, 8, 8, 0.34) 64%,
      rgba(8, 8, 8, 0.62) 100%
    );
  }

  .markets-text {
    top: auto;
    max-width: 100%;
  }

  .markets-title {
    font-size: clamp(1.75rem, 6vw, 2.5rem);
  }

  .markets-progress {
    right: 1rem;
    gap: 0.6rem;
  }

  .markets-progress-dot {
    width: 6px;
    height: 6px;
  }
}

@media (max-width: 480px) {
  .markets-product {
    width: clamp(220px, 66vw, 300px);
    top: auto;
    bottom: 3%;
    opacity: 1;
  }

  .markets-content {
    padding-top: clamp(3.5rem, 9vh, 6rem);
  }

  .markets-title {
    font-size: 1.5rem;
  }

  .markets-tagline {
    font-size: 0.9375rem;
  }

  .markets-desc {
    font-size: 0.875rem;
  }
}

/* ─────────────────────────── Reduced Motion ─────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .markets-bg-layer,
  .markets-bg-layer img,
  .markets-product img,
  .markets-text,
  .markets-progress-dot {
    transition: none !important;
  }

  .markets-bg-layer img {
    transform: none !important;
  }
}
