/* ==========================================================================
   Gallery scroll — likova-style pinned chapters, scrub-driven by --p / --c
   custom properties written by gallery-scroll.js.
   Pin + wipe effects are desktop-only; mobile falls back to stacked reveals.
   ========================================================================== */

/* ---------- Dark pinned chapter (School Program) ---------- */

.gallery-chapter {
  --p: 0;
  position: relative;
  background: #ffffff;
  color: var(--text, #111111);
}

.gallery-stage {
  position: relative;
  overflow: hidden;
}

.gallery-stage__inner {
  position: relative;
  height: 100%;
}

.gallery-ghost {
  position: absolute;
  right: -2rem;
  bottom: -6rem;
  font-size: clamp(12rem, 34vw, 30rem);
  font-weight: 700;
  line-height: 1;
  color: transparent;
  -webkit-text-stroke: 1px rgba(17, 17, 17, 0.08);
  pointer-events: none;
  user-select: none;
  z-index: 0;
}

.gallery-eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted, #4a4a4a);
  margin: 0 0 1.1rem;
}

.gallery-title-plate {
  display: inline-block;
  background: #181818;
  padding: 1.1rem 1.8rem 1.2rem 0;
  position: relative;
}

/* extend the plate to the viewport's left edge, likova wordmark style */
.gallery-title-plate::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  right: 100%;
  width: 50vw;
  background: inherit;
}

.gallery-title {
  margin: 0;
  color: #f5f5f1;
  font-size: clamp(2.4rem, 6vw, 4.6rem);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.02em;
  padding-left: 1.4rem;
}

.gallery-lede {
  margin: 1.4rem 0 0;
  max-width: 30rem;
  color: var(--muted, #4a4a4a);
  line-height: 1.7;
  font-size: 0.95rem;
}

/* frameless: the infographic must always be shown complete, uncropped */
.gallery-frame {
  position: relative;
  margin: 0;
}

/* The width/height attributes on the <img> give it an intrinsic aspect ratio,
   so it still occupies layout space before it loads. Without that, a lazy image
   sized with `width: auto` collapses to 0x0 and never enters the viewport, so
   the browser never loads it — it stays blank forever. */
.gallery-frame img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
}

.gallery-detail {
  position: relative;
  z-index: 2;
}

.gallery-kicker {
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted, #4a4a4a);
  margin: 0 0 0.7rem;
}

.gallery-subtitle {
  margin: 0;
  color: #111111;
  font-size: clamp(1.5rem, 2.6vw, 2.2rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.gallery-copy {
  margin: 0.9rem 0 0;
  max-width: 28rem;
  color: var(--muted, #4a4a4a);
  line-height: 1.72;
  font-size: 0.93rem;
}

.gallery-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 1.6rem;
  padding: 0.85rem 1.6rem;
  border: 1px solid #181818;
  color: #181818;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-decoration: none;
  transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}

.gallery-cta:hover {
  background: #181818;
  border-color: #181818;
  color: #f5f5f1;
}

/* ---------- Cover section that wipes up over the pinned chapter ---------- */

.gallery-cover {
  --c: 0;
  position: relative;
  z-index: 2;
  background: var(--bg, #f5f5f1);
  border-top: 2px solid #181818;
}

/* ---------- Desktop: pin + scrub phases + wipe ---------- */

@media (min-width: 901px) {
  .gallery-chapter {
    /* 100vh stage + 220vh of scrub distance */
    height: 320vh;
  }

  .gallery-chapter .gallery-stage {
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1;
  }

  .gallery-stage__inner {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    grid-template-rows: auto 1fr;
    column-gap: 2rem;
    height: 100%;
    padding-top: 7.5rem;
    padding-bottom: 5.5rem;
    box-sizing: border-box;
  }

  /* phase helpers derived from scrub progress */
  .gallery-chapter {
    --ph-title: clamp(0, calc(var(--p) / 0.18), 1);
    --ph-lede: clamp(0, calc((var(--p) - 0.08) / 0.16), 1);
    --ph-img: clamp(0, calc((var(--p) - 0.05) / 0.3), 1);
    --ph-text: clamp(0, calc((var(--p) - 0.3) / 0.2), 1);
  }

  .gallery-head {
    grid-column: 1 / 6;
    grid-row: 1;
    z-index: 2;
  }

  /* negative left inset keeps the ::before viewport-edge extension visible */
  .gallery-title-plate {
    clip-path: inset(0 calc((1 - var(--ph-title)) * 100%) 0 -50vw);
  }

  .gallery-lede {
    opacity: var(--ph-lede);
    transform: translateY(calc((1 - var(--ph-lede)) * 1.8rem));
  }

  .gallery-frame {
    grid-column: 6 / 13;
    grid-row: 1 / 3;
    z-index: 1;
    align-self: center;
    clip-path: inset(calc((1 - var(--ph-img)) * 100%) 0 0 0);
    /* parallax moves the whole figure so the image is never cropped */
    transform: translateY(calc((1 - var(--p)) * 2.5rem));
  }

  .gallery-frame img {
    width: min(100%, calc((100vh - 15rem) * 1.5));
    max-height: calc(100vh - 15rem);
    margin-left: auto;
  }

  .gallery-detail {
    grid-column: 1 / 6;
    grid-row: 2;
    align-self: end;
    opacity: var(--ph-text);
    transform: translateY(calc((1 - var(--ph-text)) * 2.4rem));
  }

  .gallery-ghost {
    transform: translateY(calc(var(--p) * -4rem));
  }

  /* cover wipes up over the last 100vh of the pinned chapter.
     The edge enters the viewport flat, the step gradually opens as the
     user scrolls, reaches full offset at ~60% of the wipe, then holds. */
  .gallery-cover {
    --notch: calc(14vh * clamp(0, calc(var(--c) / 0.6), 1));
    margin-top: -100vh;
    padding-top: 16vh;
    clip-path: polygon(
      0 var(--notch),
      42% var(--notch),
      42% 0,
      100% 0,
      100% 100%,
      0 100%
    );
  }

  /* black rule tracing the stepped notch edge (light-on-light needs it) */
  .gallery-cover::before,
  .gallery-cover::after {
    content: "";
    position: absolute;
    background: #181818;
    z-index: 3;
    pointer-events: none;
  }

  .gallery-cover::before {
    left: 0;
    width: 42%;
    top: var(--notch);
    height: 2px;
  }

  .gallery-cover::after {
    left: 42%;
    top: 0;
    width: 2px;
    height: calc(var(--notch) + 2px);
  }
}

/* ---------- Mobile / tablet: static stacked layout with reveals ---------- */

@media (max-width: 900px) {
  .gallery-chapter {
    height: auto;
  }

  .gallery-stage__inner {
    padding-top: 3.5rem;
    padding-bottom: 3.5rem;
  }

  .gallery-head {
    position: relative;
    z-index: 2;
  }

  .gallery-title-plate {
    padding: 0.8rem 1.2rem 0.9rem 0;
  }

  .gallery-frame {
    margin-top: 2rem;
  }

  .gallery-detail {
    margin-top: 2.2rem;
  }

  .gallery-ghost {
    font-size: 11rem;
    bottom: -3rem;
    right: -1rem;
  }

  [data-gallery-reveal] {
    opacity: 0;
    transform: translateY(1.6rem);
    transition: opacity 0.6s ease, transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
  }

  [data-gallery-reveal].is-inview {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Reduced motion: everything static ---------- */

@media (prefers-reduced-motion: reduce) {
  .gallery-chapter {
    height: auto !important;
  }

  .gallery-chapter .gallery-stage {
    position: static !important;
    height: auto !important;
  }

  .gallery-title-plate,
  .gallery-frame {
    clip-path: none !important;
    transform: none !important;
  }

  .gallery-lede,
  .gallery-detail,
  [data-gallery-reveal] {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  .gallery-frame img {
    transform: none !important;
  }

  .gallery-cover {
    margin-top: 0 !important;
    padding-top: 0 !important;
    clip-path: none !important;
  }
}

/* ==========================================================================
   Course journey re-skin — gallery framing for the existing interaction
   ========================================================================== */

.journey-flow {
  counter-reset: gallery-chapter 1;
}

.journey-chapter {
  counter-increment: gallery-chapter;
}

.journey-title-stage {
  position: relative;
}

.journey-title-stage::before {
  content: "0" counter(gallery-chapter);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: "Space Grotesk", "Noto Sans TC", sans-serif;
  font-size: clamp(10rem, 26vw, 24rem);
  font-weight: 700;
  line-height: 1;
  color: transparent;
  -webkit-text-stroke: 1px rgba(17, 17, 17, 0.09);
  pointer-events: none;
  user-select: none;
  z-index: 0;
}

.journey-title-stage > * {
  position: relative;
  z-index: 1;
}

@media (min-width: 901px) {
  .journey-title-stage {
    min-height: 78vh;
  }

  .journey-intro-title {
    font-size: clamp(2.8rem, 6.5vw, 5.4rem);
    text-transform: uppercase;
    letter-spacing: -0.015em;
  }

  .journey-chapter + .journey-chapter {
    margin-top: 12rem;
  }

  /* room for the sticky panel to stay pinned when the LAST course of a
     chapter is selected — without this the shell runs out of track and
     gets pushed up underneath the sticky header */
  .journey-scroll-markers {
    padding-bottom: 34vh;
  }
}

/* sidebar toc: thin mono index, likova style */
.journey-global-link {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  border-radius: 0;
}

.journey-global-link.is-track {
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  color: #111111;
  margin-top: 1.1rem;
  padding-left: 0;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.45rem;
}

.journey-global-link.is-course {
  font-size: 0.7rem;
  padding-left: 1.15rem;
  position: relative;
  line-height: 1.5;
}

.journey-global-link.is-course::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 0.4rem;
  height: 1px;
  background: rgba(17, 17, 17, 0.25);
  transition: width 0.3s cubic-bezier(0.22, 1, 0.36, 1), background 0.3s ease;
}

.journey-global-link:hover {
  background: transparent;
  color: #111111;
}

.journey-global-link.is-active {
  background: transparent;
  transform: none;
  color: #111111;
  font-weight: 600;
}

.journey-global-link.is-course.is-active {
  font-size: 0.7rem;
}

.journey-global-link.is-course.is-active::before {
  width: 0.85rem;
  background: #111111;
}

.journey-global-link.is-track.is-active {
  font-size: 0.72rem;
  letter-spacing: 0.18em;
}

/* course panel: gallery plate with mask-slide transitions */
.journey-course-panel {
  border-radius: 0.3rem;
  padding: 2rem 2.2rem 2.2rem;
  box-shadow: 0 30px 60px rgba(17, 17, 17, 0.07);
  clip-path: inset(0 0 0 0);
  transition: opacity 0.4s ease, transform 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    clip-path 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.journey-course-panel.is-leaving {
  opacity: 0;
  transform: translateY(-16px);
  clip-path: inset(0 0 14% 0);
}

.journey-course-panel.is-entering {
  opacity: 0;
  transform: translateY(22px);
  clip-path: inset(14% 0 0 0);
}

.journey-course-panel.is-visible {
  clip-path: inset(0 0 0 0);
}

.journey-meta span strong {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
}

.journey-apply-btn,
.journey-detail-btn {
  border-radius: 0.2rem;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

@media (prefers-reduced-motion: reduce) {
  .journey-course-panel,
  .journey-global-link.is-course::before {
    transition: none !important;
  }

  .journey-title-stage::before {
    display: none;
  }
}
