/* ==========================================================================
   Gallery — photo grid and the full-screen lightbox.
   ========================================================================== */

/* Grid: the first photo spans two rows on wider screens ------------------- */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 200px;
  gap: 16px;
}

.gallery-grid li:first-child {
  grid-column: span 2;
  grid-row: span 2;
}

.gallery-item {
  display: block;
  height: 100%;
  overflow: hidden;
  border-radius: 12px;
  background: var(--blush);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 300ms ease;
}

.gallery-item:hover img {
  transform: scale(1.045);
}

.gallery-count {
  margin-top: 24px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

@media (max-width: 1023px) {
  .gallery-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .gallery-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: 150px;
    gap: 12px;
  }
}

/* Lightbox ---------------------------------------------------------------- */
/* A native <dialog> opened by gallery-lightbox.js. It traps focus, closes on
   Escape, and returns focus to the photo that opened it. */

.lightbox {
  width: min(1100px, 94vw);
  max-width: 94vw;
  max-height: 94dvh;
  padding: 56px 64px 24px;
  border: 0;
  background: transparent;
  color: var(--paper);
  overflow: visible;
}

.lightbox::backdrop {
  background: rgba(0, 0, 0, 0.85);
}

.lightbox img {
  width: 100%;
  max-height: 74dvh;
  border-radius: 8px;
  object-fit: contain;
}

.lightbox figcaption {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-top: 14px;
}

.lightbox :focus-visible {
  outline-color: var(--focus-on-dark);
}

.lightbox-button {
  position: absolute;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  font-size: 1.4rem;
  line-height: 1;
}

.lightbox-button:hover {
  background: rgba(255, 255, 255, 0.32);
}

.lightbox-close {
  top: 0;
  right: 0;
}

.lightbox-prev,
.lightbox-next {
  top: 45%;
}

.lightbox-prev {
  left: 0;
}

.lightbox-next {
  right: 0;
}

/* On phones the arrows move below the photo so they don't cover it. */
@media (max-width: 640px) {
  .lightbox {
    padding: 56px 0 72px;
  }

  .lightbox-prev,
  .lightbox-next {
    top: auto;
    bottom: 8px;
  }

  .lightbox-prev {
    left: 16px;
  }

  .lightbox-next {
    right: 16px;
  }
}

/* Reduced motion ---------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .gallery-item img {
    transition: none;
  }

  .gallery-item:hover img {
    transform: none;
  }
}
