/* ========================================
   SECTION 7: HORIZONTAL STICKY SCROLL (PERSONAL WORKS)
   ======================================== */

/* Hero text font size - matching Tectonics section (scaled down ~10% for laptop screens) */
#personal-works {
  --studio-font-size: clamp(64px, min(2.16vw, calc(var(--locked-vh, 1vh) * 7.2)), 165px);
  /* Hero text dimensions - matching Tectonics */
  --hero-text-margin: 7.5vw;
  --hero-text-width: calc(100% - (2 * var(--hero-text-margin)));
}

/* 1. The Main Section Wrapper */
#personal-works #horizontal-scroll-section {
  position: relative;

  /* FIX: Use --locked-vh instead of svh for consistent calculations
       with Tectonics section which also uses --locked-vh */
  height: calc(var(--locked-vh) * 500);

  min-height: auto;
  background-color: var(--color-bg);
}

/* 2. The Spacer - Matches parent */
#personal-works #scroll-spacer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* 3. The Sticky Wrapper */
/* NOTE: Do NOT add position: sticky here - ScrollTrigger handles pinning
   with pinType: 'fixed'. CSS sticky conflicts with ScrollTrigger's fixed positioning. */
#personal-works #sticky-layers-wrapper {
  position: relative;
  top: 0;
  left: 0;
  width: 100%;

  /* FIX: Use --locked-vh for consistent calculations */
  height: calc(var(--locked-vh) * 100);

  overflow: hidden;
}

/* 4. The Text Layer */
#personal-works #sticky-text-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 0 var(--layout-margin);
  box-sizing: border-box;
}

#personal-works .sticky-text-content {
  width: var(--hero-text-width);
  max-width: none;
}

/* Text Styles - Matching Tectonics Hero Section */
#personal-works .hero-text-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

#personal-works .hero-title {
  font-family: 'Hanken Grotesk', sans-serif;
  font-weight: var(--font-weight-regular, 400);
  font-size: calc(var(--studio-font-size) / 2);
  margin: 0;
  color: var(--color-text);
}

#personal-works .sup-script {
  font-family: 'Cormorant Infant', serif;
  font-weight: 300;
  font-style: italic;
  font-size: 1em;
  vertical-align: super;
}

#personal-works .hero-text {
  font-family: 'Hanken Grotesk', sans-serif;
  font-weight: var(--font-weight-black, 900);
  font-size: var(--studio-font-size);
  line-height: 1.4;
  color: var(--color-text);
  text-align: center;
  margin: 0;
  padding: 0 1rem;
}

#personal-works .hero-text .accent {
  font-family: 'Cormorant Infant', serif;
  font-style: italic;
  font-weight: 400;
}

/* 5. The Image Scroller Layer */
#personal-works #sticky-image-scroller {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  background-color: transparent;
}

/* 6. The Image Track */
#personal-works #image-track {
  display: flex;
  align-items: center;
  height: 100%;
  /* FIX: max-content ensures it doesn't shrink to viewport width on mobile */
  width: max-content;
  /* transform: translateX(100vw); removed - controlled by GSAP */
  padding-left: 10vw;
}

/* 7. The Images */
#personal-works .scroll-image-wrapper {
  position: relative;
  flex-shrink: 0;
  margin-right: 0;
  contain: layout style;
  overflow: hidden;
}

/* Allow overflow on last image so scale: 1.05 doesn't clip the right edge during hover */
#personal-works .scroll-image-wrapper:last-child {
  overflow: visible;
}

/* But clip overflow in focus mode so all images appear same size when scaled */
#personal-works.focus-mode-active .scroll-image-wrapper:last-child {
  overflow: hidden;
}

#personal-works .scroll-image-wrapper.small {
  width: 21vw;
  height: 31vw;
}

#personal-works .scroll-image-wrapper.large {
  width: 25vw;
  height: 37vw;
}

#personal-works .scroll-image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ========================================
   FOCUS MODE STYLES
   ======================================== */

/* Focus mode overlay - positioned BELOW scroller (z:2) so images are above */
/* Only dims the hero text background, images get blur/dim applied directly */
#personal-works .focus-blur-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  /* Dims hero text area */
  opacity: 0;
  pointer-events: none;
  z-index: 1;
  /* BELOW scroller - doesn't affect any images */
}

/* Lighten effect for non-focused images in focus mode */
/* Uses pseudo-element on each wrapper so focused image is unaffected */
#personal-works.focus-mode-active .scroll-image-wrapper:not(.is-focused)::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.15);
  pointer-events: none;
  z-index: 1;
}

/* Hide the global overlay - keeping element for potential future use */
#personal-works .focus-lighten-overlay {
  display: none;
}

/* Focus text container */
#personal-works .focus-text-container {
  position: fixed;
  opacity: 0;
  pointer-events: none;
  /* FIX H6: Prevent clicks when hidden */
  z-index: 15;
  color: var(--color-text);
}

#personal-works .focus-subheading {
  font-family: 'Hanken Grotesk', sans-serif;
  font-weight: 500;
  text-align: left;
  margin: 0 0 1rem 0;
  line-height: 1.1;
  /* Match tectonics overlay subheading ratio */
  font-size: calc(var(--font-size-body) * 3);
  color: var(--color-text);
}

#personal-works .focus-body-text {
  font-family: 'Hanken Grotesk', sans-serif;
  /* Match tectonics detail body text */
  font-size: calc(var(--font-size-body) * 1.4);
  line-height: 1.4;
  color: var(--color-text);
  overflow: hidden;
}

#personal-works .focus-body-text .line {
  overflow: hidden;
}

/* Focus mode navigation arrows */
#personal-works .focus-nav-arrow {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 25;
  background: transparent;
  border: none;
  padding: 2rem;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.2s ease;
}

#personal-works .focus-nav-arrow img {
  width: 2.5rem;
  height: 2.5rem;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

#personal-works .focus-nav-arrow:hover img {
  opacity: 1;
}

#personal-works .focus-nav-arrow-left {
  left: 2vw;
}

#personal-works .focus-nav-arrow-left img {
  transform: rotate(180deg);
}

#personal-works .focus-nav-arrow-right {
  right: 2vw;
}

/* Show arrows when focus mode is active */
#personal-works.focus-mode-active .focus-nav-arrow {
  opacity: 1;
  pointer-events: auto;
}

/* Hide arrows when at boundaries (controlled by JS classes) */
#personal-works .focus-nav-arrow.is-hidden {
  opacity: 0.2;
  pointer-events: none;
}

/* Hover states */
#personal-works .scroll-image-wrapper.is-hovered {
  z-index: 5;
}

#personal-works #image-track.is-interactive .scroll-image-wrapper {
  cursor: none;
}

/* Mobile adjustments */
@media (max-width: 767px) {
  #personal-works {
    --studio-font-size: max(1.1rem, 0.55rem);
    --hero-text-margin: 3.75vw;
    /* Half of desktop margin for wider text box on mobile */
  }

  #personal-works #horizontal-scroll-section {
    /* FIX: Use --locked-vh for mobile as well */
    height: calc(var(--locked-vh) * 300);
  }

  #personal-works .hero-text {
    line-height: 1.5;
    padding: 0 1.5rem;
  }

  #personal-works .scroll-image-wrapper {
    margin-right: 0;
  }

  #personal-works .scroll-image-wrapper.small {
    width: 42vw;
    height: 62vw;
  }

  #personal-works .scroll-image-wrapper.large {
    width: 50vw;
    height: 74vw;
  }

  /* Mobile focus mode - text below image */
  #personal-works .focus-text-container {
    /* Positioned by JS below image */
    padding: 1rem;
    -webkit-overflow-scrolling: touch;
    /* Smooth scrolling on iOS */
  }

  #personal-works .focus-subheading {
    font-size: calc(var(--font-size-body) * 2);
    margin-bottom: 0.5rem;
  }

  #personal-works .focus-body-text {
    font-size: calc(var(--font-size-body) * 1.1);
    line-height: 1.5;
  }
}