/* ==========================================================================
   MILESTONE BLOCK
   Requires: GSAP + ScrollTrigger (shared with pin-scroller)
   Layout: section title top | left text slides | right image crossfade | far-right timeline dots
   Safari fixes applied:
     - 100dvh for iOS Safari viewport height
     - visibility removed from image toggle (Safari animation bug)
     - aspect-ratio @supports fallback for Safari < 15
     - inset: 0 expanded to top/right/bottom/left for Safari < 14.1
   ========================================================================== */

/* ── CSS custom properties ────────────────────────────────────── */
.milestone-block {
  --mb-title-color: var(--hng-orange, #f58220);
  --mb-year-color: #1a0800;
  --mb-subtitle-color: var(--hng-muted, rgba(255, 255, 255, 0.7));
  --mb-body-color: var(--hng-muted-heavy, rgba(255, 255, 255, 0.62));
  --mb-dot-idle: rgba(255, 255, 255, 0.55);
  --mb-dot-active: var(--hng-orange, #f58220);
  --mb-dot-line: rgba(255, 255, 255, 0.22);
  --mb-img-radius: var(--radius-image, 40px);
  --mb-padding: var(--hng-section-pad, clamp(1.5rem, 5vw, 5rem));
  --mb-gap: var(--hng-row-gap, clamp(1rem, 2.5vw, 2rem));

  /* Pin-scroll layout */
  position: relative;
  width: 100%;

  /* FIX 1: iOS Safari 100vh includes browser chrome — use 100dvh with 100vh fallback */
  height: 100vh;
  height: 100dvh;

  min-height: 560px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0 !important;
  margin-bottom: var(--hng-block-gap);
}

/* ── Inner wrapper ────────────────────────────────────────────── */
.milestone-block__inner {
  width: 100%;
  height: 100%;
  padding: clamp(1.5rem, 4vw, 3rem) 0 clamp(1.5rem, 4vw, 3rem) 0 !important;
  display: flex;
  flex-direction: column;
  gap: clamp(0.75rem, 1.5vw, 1.25rem);
  box-sizing: border-box;
}

/* Section title */
.milestone-block__section-title {
  flex-shrink: 0;
  margin: 0 0 0.5rem;
  font-family: "ITCAvantGarde", sans-serif;
  font-weight: 900;
  font-style: normal;
  font-stretch: normal;
  font-size: var(--hng-h2-size, clamp(2.25rem, 4.5vw, 3.625rem));
  line-height: 1.1;
  color: var(--mb-title-color);
}

/* ── Stage grid: text | image | timeline ──────────────────────── */
.milestone-block__stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 5fr 6fr 2.5rem;
  grid-template-areas: "text image dots";
  gap: var(--mb-gap);
  align-items: center;
}

/* Odd slides: flip text and image sides */
.milestone-block__stage--odd {
  grid-template-areas: "image text dots";
}

/* ── Left: slide text container ───────────────────────────────── */
.milestone-block__slides-wrap {
  grid-area: text;
  position: relative;
  height: 100%;
}

.milestone-block__slide {
  position: absolute;

  /* FIX 2: Expand inset shorthand — not supported in Safari < 14.1 */
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;

  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(0.6rem, 1.5vh, 1rem);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s ease;
}

.milestone-block__slide.is-active {
  opacity: 1;
  pointer-events: auto;
}

/* Year */
.milestone-block__year {
  display: block;
  font-family: "ITCAvantGarde", sans-serif;
  font-weight: 600;
  font-style: normal;
  font-stretch: normal;
  font-size: var(--hng-h2-size, clamp(2.25rem, 4.5vw, 3.625rem));
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--mb-year-color);
}

/* Subtitle */
.milestone-block__subtitle {
  margin: 0;
  font-weight: 900;
  font-style: normal;
  font-stretch: normal;
  font-size: var(--hng-h3-size, clamp(1.5rem, 2.5vw, 1.875rem));
  color: var(--hng-white);
  line-height: 1.4;
  padding-bottom: 5px;
}

/* Body copy */
.milestone-block__body {
  font-weight: 400;
  font-style: normal;
  font-stretch: normal;
  font-size: var(--hng-body-size, clamp(1rem, 1.5vw, 1.25rem));
  color: var(--hng-white);
  line-height: 1.75;
  max-width: 50ch;
}

.milestone-block__body p {
  margin: 0 0 0.6em;
}

.milestone-block__body p:last-child {
  margin-bottom: 0;
}

/* ── Right (or Left on odd): image crossfade panel ───────────── */
.milestone-block__images {
  grid-area: image;
  position: relative;
  width: 100%;
  align-self: center;
  border-radius: var(--mb-img-radius);
  overflow: hidden;
  background: rgba(0, 0, 0, 0.15);
  isolation: isolate;

  /* FIX 3: aspect-ratio not supported in Safari < 15 — use padding-top fallback */
  aspect-ratio: 16 / 9;
}

/* FIX 3 cont: padding-top hack for Safari < 15 that doesn't support aspect-ratio */
@supports not (aspect-ratio: 16 / 9) {
  .milestone-block__images {
    height: 0;
    padding-top: 56.25%; /* 9 ÷ 16 = 56.25% */
  }
}

/* FIX 4: Remove visibility toggle — Safari skips CSS animation when
   visibility and animation start in the same frame.
   Use only opacity + pointer-events instead. */
.milestone-block__image {
  position: absolute;

  /* FIX 2: Expand inset shorthand for Safari < 14.1 */
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;

  margin: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  /* No visibility: hidden — causes Safari to skip animation on .is-active */
  transition: none;
}

.milestone-block__image.is-active {
  opacity: 1;
  pointer-events: auto;
  animation: milestoneImageFadeIn 0.65s ease-out forwards;
}

@keyframes milestoneImageFadeIn {
  from {
    opacity: 0;
    transform: scale(1.03);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.milestone-block__image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ── Far-right: timeline dots ─────────────────────────────────── */
.milestone-block__timeline {
  grid-area: dots;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  height: 50%;
  position: relative;
}

/* Connecting line behind dots */
.milestone-block__timeline::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 1px;
  background: var(--mb-dot-line);
}

.milestone-block__dot {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid var(--mb-dot-idle);
  background: transparent;
  cursor: pointer;
  padding: 0;
  margin: 6px 0;
  transition:
    background 0.25s ease,
    border-color 0.25s ease,
    transform 0.25s ease;
}

.milestone-block__dot:hover {
  border-color: rgba(255, 255, 255, 0.9);
  transform: scale(1.25);
}

.milestone-block__dot.is-active {
  background: var(--mb-dot-active);
  border-color: var(--mb-dot-active);
  transform: scale(1.35);
}

.milestone-block__dot:focus-visible {
  outline: 2px solid var(--mb-dot-active);
  outline-offset: 3px;
}

/* ── Tablet + Mobile (≤ 900px) ───────────────────────────────── */
@media (max-width: 900px) {
  /* Arrow navigation row injected by JS */
  .milestone-block__arrow-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.5rem 0;
  }

  .milestone-block__arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--mb-dot-idle);
    background: transparent;
    cursor: pointer;
    padding: 0;
    color: rgba(255, 255, 255, 0.75);
    transition:
      border-color 0.25s ease,
      color 0.25s ease,
      transform 0.2s ease;
    flex-shrink: 0;
  }

  .milestone-block__arrow:hover:not(:disabled) {
    border-color: rgba(255, 255, 255, 0.9);
    color: #fff;
    transform: scale(1.1);
  }

  .milestone-block__arrow:disabled {
    opacity: 0.3;
    cursor: default;
  }

  .milestone-block__arrow:focus-visible {
    outline: 2px solid var(--mb-dot-active);
    outline-offset: 3px;
  }

  .milestone-block__arrow svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  /* Dot counter shown between arrows */
  .milestone-block__arrow-counter {
    font-size: 0.85rem;
    color: var(--mb-dot-idle);
    min-width: 3em;
    text-align: center;
    -webkit-user-select: none;
    user-select: none;
  }

  .milestone-block__stage {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    grid-template-areas:
      "dots dots"
      "text image";
    align-items: start;
  }

  /* Ensure odd variant doesn't flip on tablet/mobile */
  .milestone-block__stage--odd {
    grid-template-areas:
      "dots dots"
      "text image";
  }

  .milestone-block__slides-wrap {
    height: auto;
    min-height: 0;
  }

  .milestone-block__slide {
    position: static;
    opacity: 0;
    height: 0;
    overflow: hidden;
    pointer-events: none;
    transition: opacity 0.45s ease;
  }

  .milestone-block__slide.is-active {
    height: auto;
    overflow: visible;
  }

  /* Blur-reveal animation on tablet */
  .milestone-block__image.is-active {
    opacity: 1;
    pointer-events: auto;
    animation: milestoneImageBlurReveal 0.9s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

  @keyframes milestoneImageBlurReveal {
    0% {
      opacity: 0;
      filter: blur(18px);
      transform: scale(1.04) translateY(18px);
    }
    60% {
      opacity: 1;
      filter: blur(0);
      transform: scale(1) translateY(0);
    }
    100% {
      opacity: 1;
      filter: blur(0);
      transform: scale(1) translateY(0);
    }
  }

  .milestone-block__timeline {
    flex-direction: row;
    height: auto;
    width: 100%;
    gap: 0;
    justify-content: center;
  }

  .milestone-block__timeline::before {
    top: 50%;
    left: 0;
    right: 0;
    bottom: auto;
    width: 100%;
    height: 1px;
    transform: translateY(-50%);
  }

  .milestone-block__dot {
    margin: 0 6px;
  }
}

/* ── Mobile (≤ 540px) ─────────────────────────────────────────── */
@media (max-width: 900px) {
  .milestone-block {
    height: auto;
    min-height: 0;
  }

  .milestone-block__year {
    font-size: clamp(3rem, 14vw, 5rem);
  }

  .milestone-block__stage {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "dots"
      "text"
      "image";
    align-items: start;
    gap: clamp(0.75rem, 3vw, 1.25rem);
  }

  .milestone-block__stage--odd {
    grid-template-areas:
      "dots"
      "text"
      "image";
  }

  /* Full-width image on mobile */
  .milestone-block__images {
    height: auto;
    aspect-ratio: 16 / 9;
    width: 100%;
  }

  @supports not (aspect-ratio: 16 / 9) {
    .milestone-block__images {
      height: 0;
      padding-top: 56.25%;
    }
  }

  /* Dot timeline on mobile */
  .milestone-block__timeline {
    display: flex;
    flex-direction: row;
    height: auto;
    width: 100%;
    gap: 0;
    justify-content: center;
  }

  .milestone-block__timeline::before {
    top: 50%;
    left: 0;
    right: 0;
    bottom: auto;
    width: 100%;
    height: 1px;
    transform: translateY(-50%);
  }

  .milestone-block__dot {
    margin: 0 6px;
  }

}