/* ==========================================================
   Gallery page — save as css/pages/gallery.css
   Uses the design tokens from css/main.css
   ========================================================== */

/* Jump links */
.gallery-jump {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 66px;
  z-index: 50;
}
.gallery-jump ul {
  list-style: none;
  margin: 0;
  padding: 0.8rem 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
}

.gallery-jump ul::-webkit-scrollbar {
  display: none;
}
.gallery-jump a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0.65rem 1.15rem;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: var(--green);
  background: var(--ivory);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition:
    color 0.25s,
    background 0.25s,
    border-color 0.25s,
    transform 0.25s;
}

.gallery-jump a:hover,
.gallery-jump a:focus-visible {
  color: var(--ivory);
  background: var(--green);
  border-color: var(--green);
  transform: translateY(-2px);
  outline: none;
}

/* Section heads */
.gallery-section {
  scroll-margin-top: 130px;
}
.gallery-head {
  margin-bottom: clamp(1.8rem, 4vw, 3rem);
  max-width: 62ch;
}
.gallery-head h2 {
  margin-bottom: 0.3em;
}
.gallery-head .lead {
  margin: 0;
}

/* Photo grid: 4 columns on desktop, "wide" spans 2, "tall" spans 2 rows */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: clamp(150px, 17vw, 240px);
  grid-auto-flow: dense;
  gap: var(--gap);
}
.shot {
  margin: 0;
  position: relative;
  border-radius: 18px;
  overflow: hidden;
  background: linear-gradient(
    160deg,
    var(--sky),
    var(--teal) 55%,
    var(--forest)
  );
  box-shadow: 0 18px 40px -26px rgba(17, 42, 27, 0.55);
  grid-column: span 1;
  grid-row: span 1;
}
.shot.wide {
  grid-column: span 2;
}
.shot.tall {
  grid-row: span 2;
}
/* "half": two photos share one row, each taking half the width (and two rows of height).
   Add class="shot half" by hand, or just put exactly two photos in a section and it happens automatically. */
.shot.half,
.gallery-grid:has(> .shot:first-child:nth-last-child(2)):not(
    :has(> .shot.wide, > .shot.tall)
  )
  > .shot {
  grid-column: span 2;
  grid-row: span 2;
}

/* Exactly 3 photos: fit evenly in one row */
.gallery-grid:has(> .shot:first-child:nth-last-child(3)) {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.gallery-grid:has(> .shot:first-child:nth-last-child(3)) > .shot {
  grid-column: span 1;
  grid-row: span 1;
}
.shot-btn {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
}
.shot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.9s var(--ease);
}
.shot figcaption {
  position: absolute;
  inset: auto 0 0 0;
  padding: 2.4rem 1rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ivory);
  background: linear-gradient(180deg, transparent, rgba(17, 42, 27, 0.82));
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 0.4s,
    transform 0.4s var(--ease);
  pointer-events: none;
}
@media (hover: hover) {
  .shot:hover img {
    transform: scale(1.06);
  }
  .shot:hover figcaption,
  .shot:focus-within figcaption {
    opacity: 1;
    transform: none;
  }
}
/* Touch screens have no hover, so captions stay visible */
@media (hover: none) {
  .shot figcaption {
    opacity: 1;
    transform: none;
  }
}

/* Lightbox — z-index stays below the custom cursor (10000) */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: grid;
  place-items: center;
  padding: 4.5rem 3vw 2rem;
  background: rgba(17, 42, 27, 0.92);
}
.lightbox[hidden] {
  display: none;
}
.lightbox figure {
  margin: 0;
  display: grid;
  gap: 0.8rem;
  justify-items: center;
}
.lightbox img {
  max-width: 94vw;
  max-height: 80svh;
  width: auto;
  height: auto;
  border-radius: 12px;
  object-fit: contain;
}
.lightbox figcaption {
  color: var(--ivory);
  font-family: var(--font-head);
  font-style: italic;
  font-size: 1.2rem;
  text-align: center;
}
.lb-close {
  position: absolute;
  top: max(1rem, env(safe-area-inset-top));
  right: max(1rem, env(safe-area-inset-right));
  width: 48px;
  height: 48px;
  border: 1.5px solid rgba(247, 242, 230, 0.5);
  border-radius: 50%;
  background: transparent;
  color: var(--ivory);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  transition:
    background 0.25s,
    color 0.25s;
}
.lb-close:hover {
  background: var(--gold);
  color: var(--forest);
  border-color: var(--gold);
}

/* Responsive */
@media (max-width: 900px) {
  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: clamp(150px, 34vw, 260px);
  }
  /* on tablets the two "half" photos still sit side by side */
  .shot.half,
  .gallery-grid:has(> .shot:first-child:nth-last-child(2)):not(
      :has(> .shot.wide, > .shot.tall)
    )
    > .shot {
    grid-column: span 1;
    grid-row: span 2;
  }

  /* 3 photos: two columns on tablets */
  .gallery-grid:has(> .shot:first-child:nth-last-child(3)) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 520px) {
  .gallery-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: 240px;
  }
  .shot.wide,
  .shot.tall {
    grid-column: span 1;
  }
  .shot.half,
  .gallery-grid:has(> .shot:first-child:nth-last-child(2)):not(
      :has(> .shot.wide, > .shot.tall)
    )
    > .shot {
    grid-column: span 1;
    grid-row: span 1;
  }
  /* 3 photos: one column on mobile */
  .gallery-grid:has(> .shot:first-child:nth-last-child(3)) {
    grid-template-columns: minmax(0, 1fr);
  }
  .shot.tall {
    grid-row: span 2;
  }
  .gallery-jump {
    top: 66px;
  }
  .gallery-jump ul {
    justify-content: flex-start;
    gap: 0.5rem;
  }

  .gallery-jump a {
    min-height: 40px;
    padding: 0.55rem 0.9rem;
    font-size: 0.82rem;
  }
}
@media (prefers-reduced-motion: reduce) {
  .shot img,
  .shot figcaption {
    transition: none;
  }
}
