/**
 * The Galleries page and photograph viewer.
 *
 * Lifted out of the theme stylesheet when the gallery became a plugin, so the
 * markup and the styling that describes it now travel together.
 *
 * --ink is the theme's warm near-black. The fallback is that same value, so
 * these styles are correct on their own if the theme is ever changed.
 */

.gallery-page {
  background-color: #fff;
}

/* Body copy is optional on this page and usually absent, so the intro block
   only exists when Jeff has actually written something. */
.gallery-intro {
  padding: 3.5rem 0 2.5rem;
  text-align: center;
}

.gallery-intro-title {
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  font-size: 2rem;
  color: var(--ink, #24211e);
  letter-spacing: 0.02em;
  margin-bottom: 1rem;
}

/* Filter chips ------------------------------------------------------------ */

.gallery-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 2.25rem;
  justify-content: center;
  padding: 3rem 1.5rem 2.25rem;
}

/* Text buttons rather than pills. A pill would be a second rectangle
   competing with the squares underneath it. */
.gallery-filter {
  background: none;
  border: 0;
  padding: 0 0 0.5rem;
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
  font-weight: 400;
  font-size: 0.8125rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(36, 33, 30, 0.55);
  position: relative;
  transition: color 0.25s ease;
}

.gallery-filter::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 0;
  height: 2px;
  background-color: #b39873;
  transition: width 0.25s ease, left 0.25s ease;
}

.gallery-filter:hover,
.gallery-filter:focus-visible {
  color: var(--ink, #24211e);
}

.gallery-filter.is-active {
  color: var(--ink, #24211e);
  font-weight: 700;
}

.gallery-filter.is-active::after {
  left: 0;
  width: 100%;
}

/* The grid ---------------------------------------------------------------- */

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 0 4px 4px;
  /* Tiles slide in from beyond the grid's edges while a filter rearranges it.
     Without this they would be seen travelling over the rest of the page. */
  overflow: hidden;
}

.gallery-tile {
  display: block;
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  padding: 0;
  border: 0;
  background: #efece8;
  cursor: pointer;
}

/* Same trap as the viewer below: display:block above outranks the browser's
   own [hidden] rule, so a filtered-out tile would stay on screen. */
.gallery-tile[hidden] {
  display: none;
}

.gallery-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.5s cubic-bezier(0.2, 0.7, 0.3, 1);
}

/* A slow, small push-in. Anything faster or larger reads as a web widget
   rather than as a photograph being looked at. */
.gallery-tile:hover img,
.gallery-tile:focus-visible img {
  transform: scale(1.05);
}

.gallery-tile::after {
  content: '';
  position: absolute;
  inset: 0;
  background-color: rgba(36, 33, 30, 0);
  transition: background-color 0.4s ease;
  pointer-events: none;
}

.gallery-tile:hover::after,
.gallery-tile:focus-visible::after {
  background-color: rgba(36, 33, 30, 0.12);
}

.gallery-tile:focus-visible {
  outline: 2px solid #b39873;
  outline-offset: -2px;
}

@media (min-width: 1600px) {
  .gallery-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

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

/* Two columns rather than Instagram's three: these are wedding photographs
   with faces in them, and a third of a phone screen is too small to read one. */
@media (max-width: 700px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 3px;
    padding: 0 3px 3px;
  }

  /* Tuned so all four chips hold one line at 390px. Wrapping put "Proposals"
     alone on a second row, which read as a mistake rather than a choice. */
  .gallery-filters {
    gap: 1.05rem;
    padding: 2rem 0.75rem 1.5rem;
  }

  .gallery-filter {
    font-size: 0.7rem;
    letter-spacing: 0.07em;
  }
}

/* The viewer -------------------------------------------------------------- */

body.gallery-lightbox-open {
  overflow: hidden;
}

/* Warm near-black to match --ink. Pure black behind a warm photograph reads
   as a hole in the page. */
.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(22, 20, 18, 0.97);
  animation: gallery-fade 0.25s ease;
}

/* display:flex above would otherwise beat the browser's own [hidden] rule —
   same specificity, and an author stylesheet always wins over the UA one —
   leaving the viewer covering the grid on page load. */
.gallery-lightbox[hidden],
.gallery-lightbox-nav[hidden] {
  display: none;
}

@keyframes gallery-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.gallery-lightbox-stage {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 4.5rem 4.5rem 5.5rem;
}

/* The 0.22s here is the outgoing half of a slide, and gallery.js waits exactly
   that long before swapping the src. Change one and change the other. */
.gallery-lightbox-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  opacity: 1;
  transform: translateX(0);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

/* Parked off to one side and invisible: the state a frame leaves through and
   the state the next one arrives from. --gallery-shift carries the direction. */
.gallery-lightbox-stage img.is-swapping {
  opacity: 0;
  transform: translateX(var(--gallery-shift, 0rem));
}

/* For the one frame in which the incoming photograph is moved across to its
   starting side. Animating that jump would undo the illusion. */
.gallery-lightbox-stage img.is-instant {
  transition: none;
}

.gallery-lightbox-nav,
.gallery-lightbox-close {
  position: absolute;
  background: none;
  border: 0;
  color: rgba(255, 255, 255, 0.65);
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
  line-height: 1;
  transition: color 0.2s ease;
  z-index: 1;
}

.gallery-lightbox-nav:hover,
.gallery-lightbox-nav:focus-visible,
.gallery-lightbox-close:hover,
.gallery-lightbox-close:focus-visible {
  color: #fff;
}

.gallery-lightbox-nav {
  top: 50%;
  transform: translateY(-50%);
  font-size: 3.5rem;
  padding: 1rem 1.25rem;
}

.gallery-lightbox-nav.is-prev { left: 0.5rem; }
.gallery-lightbox-nav.is-next { right: 0.5rem; }

.gallery-lightbox-close {
  top: 1rem;
  right: 1.5rem;
  font-size: 2.5rem;
  padding: 0.5rem;
}

.gallery-lightbox-caption {
  position: absolute;
  bottom: 1.75rem;
  left: 0;
  right: 0;
  text-align: center;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  margin: 0;
  pointer-events: none;
}

.gallery-lightbox-caption span + span::before {
  content: '\00a0\00b7\00a0\00a0';
  color: rgba(255, 255, 255, 0.35);
}

@media (max-width: 700px) {
  .gallery-lightbox-stage {
    padding: 3.5rem 0.5rem 4.5rem;
  }

  /* On a phone the arrows would sit on top of the photograph, and swiping is
     the natural gesture there anyway, so they shrink to the edges. */
  .gallery-lightbox-nav {
    font-size: 2.5rem;
    padding: 0.75rem 0.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-tile img,
  .gallery-filter,
  .gallery-filter::after {
    transition: none;
  }

  .gallery-tile:hover img,
  .gallery-tile:focus-visible img {
    transform: none;
  }

  .gallery-lightbox {
    animation: none;
  }

  /* gallery.js also skips the slide entirely here, so this only guards
     against a frame caught mid-transition when the setting changes. */
  .gallery-lightbox-stage img {
    transition: none;
    opacity: 1;
    transform: none;
  }
}
