/* =========================================================
   Gallery — editorial triptych / responsive scroll-snap reel
   Loaded only by /gallery/ so this layer can evolve independently.
   ========================================================= */

.gl-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

body[data-page="gallery"] main > .container > .courses-page-header {
  margin-bottom: clamp(1rem, 2vw, 1.75rem);
}

.gl-gallery {
  position: relative;
  padding: clamp(0.75rem, 1.5vw, 1.25rem) 0 clamp(5rem, 9vw, 7.5rem);
  overflow: hidden;
  overflow: clip;
  isolation: isolate;
}

.gl-gallery::before,
.gl-gallery::after {
  content: "";
  position: absolute;
  z-index: -1;
  border-radius: 50%;
  pointer-events: none;
  filter: blur(1px);
}

.gl-gallery::before {
  width: min(46rem, 62vw);
  aspect-ratio: 1;
  left: -24rem;
  top: 7%;
  background: radial-gradient(circle, rgba(161, 98, 7, 0.09), rgba(161, 98, 7, 0) 68%);
}

.gl-gallery::after {
  width: min(42rem, 58vw);
  aspect-ratio: 1;
  right: -20rem;
  bottom: -12rem;
  background: radial-gradient(circle, rgba(63, 113, 89, 0.1), rgba(63, 113, 89, 0) 68%);
}

.gl-gallery .gl-slider {
  position: relative;
  max-width: 1120px;
  margin-inline: auto;
}

.gl-gallery .gl-track {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
  gap: clamp(1rem, 2.2vw, 1.8rem);
  overflow: visible;
  scroll-snap-type: none;
  scroll-padding: 0;
  padding: clamp(1.5rem, 2.2vw, 2rem) 0 1.5rem;
  outline-offset: 8px;
}

.gl-gallery .gl-slide {
  --gl-accent: var(--accent);
  --gl-tint: var(--accent-soft);
  --gl-rest-y: 1.4rem;
  --gl-hover-y: 0.75rem;
  position: relative;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: clamp(3.75rem, 6vw, 5.5rem) clamp(3.75rem, 6vw, 5.5rem) 1.45rem 1.45rem;
  background: linear-gradient(180deg, var(--surface) 0%, rgba(252, 251, 245, 0.96) 100%);
  box-shadow: 0 18px 45px rgba(51, 61, 33, 0.08);
  transform: translateY(var(--gl-rest-y));
  transition:
    transform 0.55s var(--ease-out),
    border-color 0.45s ease,
    box-shadow 0.55s var(--ease-out),
    opacity 0.4s ease;
}

.gl-gallery .gl-slide:nth-child(2) {
  --gl-rest-y: 0;
  --gl-hover-y: -0.65rem;
}

.gl-gallery .gl-slide--soul {
  --gl-accent: var(--pillar-soul);
  --gl-tint: rgba(161, 98, 7, 0.11);
}

.gl-gallery .gl-slide--mind {
  --gl-accent: var(--pillar-mind);
  --gl-tint: rgba(63, 113, 89, 0.11);
}

.gl-gallery .gl-slide--body {
  --gl-accent: var(--pillar-body);
  --gl-tint: rgba(92, 110, 51, 0.12);
}

.gl-gallery .gl-slide::before {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 0 18% auto;
  height: 2px;
  border-radius: 999px;
  background: var(--gl-accent);
  opacity: 0.46;
  transform: scaleX(0.48);
  transform-origin: center;
  transition: transform 0.55s var(--ease-out), opacity 0.4s ease;
}

.gl-gallery .gl-media {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  background:
    radial-gradient(circle at 50% 42%, var(--gl-tint), transparent 67%),
    var(--surface);
}

.gl-gallery .gl-media::after {
  content: "";
  position: absolute;
  inset: 7%;
  border: 1px solid var(--gl-accent);
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.88);
  transition: opacity 0.5s ease, transform 0.7s var(--ease-out);
  pointer-events: none;
}

.gl-gallery .gl-slide img {
  width: 100%;
  height: 100%;
  display: block;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  transform: scale(1.005);
  transition: transform 0.8s var(--ease-out), filter 0.55s ease;
  user-select: none;
  -webkit-user-drag: none;
}

.gl-gallery .gl-slide figcaption {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 0.85rem;
  row-gap: 0.24rem;
  min-height: 7.4rem;
  padding: 1.25rem 1.35rem 1.4rem;
  border-top: 1px solid var(--line);
  background: linear-gradient(135deg, var(--gl-tint), transparent 62%);
}

.gl-gallery .gl-number {
  grid-row: 1 / span 2;
  padding-top: 0.13rem;
  font-family: var(--font-base);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--gl-accent);
}

.gl-gallery .gl-slide figcaption strong {
  font-family: var(--font-heading);
  font-size: clamp(1.1rem, 1.7vw, 1.3rem);
  font-weight: 500;
  line-height: 1.2;
  color: var(--text-primary);
}

.gl-gallery .gl-slide figcaption > span:last-child {
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--text-muted);
}

@media (min-width: 900px) and (hover: hover) and (pointer: fine) {
  .gl-gallery .gl-slide:hover,
  .gl-gallery .gl-track:focus-visible .gl-slide.is-active {
    border-color: var(--gl-accent);
    box-shadow: 0 28px 62px rgba(51, 61, 33, 0.15);
    transform: translateY(var(--gl-hover-y));
  }

  .gl-gallery .gl-slide:hover::before,
  .gl-gallery .gl-track:focus-visible .gl-slide.is-active::before {
    opacity: 0.86;
    transform: scaleX(1);
  }

  .gl-gallery .gl-slide:hover .gl-media::after,
  .gl-gallery .gl-track:focus-visible .gl-slide.is-active .gl-media::after {
    opacity: 0.2;
    transform: scale(1);
  }

  .gl-gallery .gl-slide:hover img,
  .gl-gallery .gl-track:focus-visible .gl-slide.is-active img {
    transform: scale(1.035);
    filter: saturate(1.04) contrast(1.015);
  }
}

/* Gentle stagger after the existing global reveal observer exposes the stage. */
@media (min-width: 900px) and (prefers-reduced-motion: no-preference) {
  .gl-slider.reveal-on-scroll.is-visible .gl-slide {
    animation: gl-card-in 0.78s var(--ease-out) backwards;
  }

  .gl-slider.reveal-on-scroll.is-visible .gl-slide:nth-child(2) { animation-delay: 0.09s; }
  .gl-slider.reveal-on-scroll.is-visible .gl-slide:nth-child(3) { animation-delay: 0.18s; }
}

@keyframes gl-card-in {
  from {
    opacity: 0;
    transform: translateY(calc(var(--gl-rest-y) + 2rem)) scale(0.965);
  }
  to {
    opacity: 1;
    transform: translateY(var(--gl-rest-y)) scale(1);
  }
}

.gl-gallery .gl-controls {
  display: none;
}

/* Tablet and mobile become a centered, native swipe reel. */
@media (max-width: 899px) {
  .gl-gallery {
    padding-top: 0.8rem;
  }

  .gl-gallery > .container {
    width: 100%;
    max-width: none;
    padding-inline: 0;
  }

  .gl-gallery .gl-slider {
    max-width: none;
  }

  .gl-gallery .gl-track {
    --gl-card-width: min(82vw, 430px);
    display: flex;
    align-items: stretch;
    gap: clamp(0.9rem, 3.8vw, 1.35rem);
    overflow-x: auto;
    overflow-y: visible;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: max(1rem, calc((100% - var(--gl-card-width)) / 2));
    overscroll-behavior-inline: contain;
    padding: 1.2rem max(1rem, calc((100% - var(--gl-card-width)) / 2)) 2rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .gl-gallery .gl-track::-webkit-scrollbar {
    display: none;
  }

  .gl-gallery .gl-slide,
  .gl-gallery .gl-slide:nth-child(2) {
    --gl-rest-y: 0;
    --gl-hover-y: 0;
    flex: 0 0 var(--gl-card-width);
    max-width: var(--gl-card-width);
    scroll-snap-align: center;
    scroll-snap-stop: always;
    opacity: 0.58;
    transform: scale(0.95);
    transform-origin: center;
    border-radius: clamp(3.2rem, 13vw, 5rem) clamp(3.2rem, 13vw, 5rem) 1.35rem 1.35rem;
  }

  .gl-gallery .gl-slide.is-active {
    opacity: 1;
    transform: scale(1);
    border-color: color-mix(in srgb, var(--gl-accent) 48%, var(--line));
    box-shadow: 0 24px 54px rgba(51, 61, 33, 0.14);
  }

  .gl-gallery .gl-slide.is-active::before {
    opacity: 0.78;
    transform: scaleX(1);
  }

  .gl-gallery .gl-slide figcaption {
    min-height: 7rem;
  }

  .gl-gallery .gl-slider.is-enhanced .gl-controls {
    display: grid;
    grid-template-columns: 3rem minmax(11rem, 20rem) 3rem;
    align-items: center;
    justify-content: center;
    gap: clamp(0.75rem, 3vw, 1.2rem);
    width: min(100% - 2rem, 31rem);
    margin: 0 auto;
  }

  .gl-gallery .gl-btn {
    position: static;
    inset: auto;
    width: 3rem;
    height: 3rem;
    transform: none;
    flex: none;
    border: 1px solid var(--accent-line);
    border-radius: 50%;
    background: rgba(252, 251, 245, 0.92);
    color: var(--accent);
    box-shadow: var(--shadow-xs);
    transition:
      color var(--dur) var(--ease-out),
      background var(--dur) var(--ease-out),
      border-color var(--dur) var(--ease-out),
      transform var(--dur-fast) var(--ease-out),
      opacity var(--dur) ease;
  }

  .gl-gallery .gl-btn:hover:not(:disabled) {
    color: var(--surface);
    background: var(--accent);
    border-color: var(--accent);
    transform: translateY(-2px);
  }

  .gl-gallery .gl-btn:active:not(:disabled) {
    transform: translateY(0) scale(0.96);
  }

  .gl-gallery .gl-btn:disabled {
    opacity: 0.3;
    cursor: default;
  }

  .gl-gallery .gl-pagination {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.35rem 0.8rem;
    min-width: 0;
  }

  .gl-gallery .gl-dots {
    display: flex;
    grid-column: 1;
    justify-content: center;
    gap: 0;
    margin: 0;
  }

  .gl-gallery .gl-dot {
    position: relative;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
  }

  .gl-gallery .gl-dot::before {
    content: "";
    position: absolute;
    width: 0.48rem;
    height: 0.48rem;
    left: 50%;
    top: 50%;
    border: 1px solid var(--accent);
    border-radius: 50%;
    background: transparent;
    transform: translate(-50%, -50%);
    transition: transform var(--dur) var(--ease-spring), background var(--dur) ease, border-color var(--dur) ease;
  }

  .gl-gallery .gl-dot.is-active::before {
    border-color: var(--terra);
    background: var(--terra);
    transform: translate(-50%, -50%) scale(1.45);
  }

  .gl-gallery .gl-dot.is-active {
    border-color: transparent;
    background: transparent;
    transform: none;
  }

  .gl-gallery .gl-status {
    grid-column: 2;
    grid-row: 1;
    min-width: 2.7rem;
    font-family: var(--font-base);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    text-align: right;
  }

  .gl-gallery .gl-progress {
    grid-column: 1 / -1;
    position: relative;
    height: 1px;
    overflow: hidden;
    background: var(--line);
  }

  .gl-gallery .gl-progress span {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, var(--accent), var(--terra));
    transform: scaleX(var(--gl-progress, 0.3333));
    transform-origin: left center;
    transition: transform 0.45s var(--ease-out);
  }
}

@media (max-width: 560px) {
  .gl-gallery .gl-track {
    --gl-card-width: min(78vw, 390px);
  }

  .gl-gallery .gl-slider.is-enhanced .gl-controls {
    grid-template-columns: minmax(12rem, 20rem);
  }

  .gl-gallery .gl-btn {
    display: none;
  }

  .gl-gallery .gl-slide figcaption {
    padding-inline: 1.15rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gl-gallery .gl-slide,
  .gl-gallery .gl-slide::before,
  .gl-gallery .gl-slide img,
  .gl-gallery .gl-media::after,
  .gl-gallery .gl-dot::before,
  .gl-gallery .gl-progress span,
  .gl-gallery .gl-btn {
    animation: none !important;
    transition: none !important;
  }

  .gl-gallery .gl-track {
    scroll-behavior: auto;
  }
}

