/* =========================================================
   gallery.css
   The rotating photograph grid.

   THE TILE IS A SLOT, NOT A FRAME. Each one reserves a 4:3 box and is
   otherwise invisible: no ground, no border, no radius. The photograph sits
   inside it at its own aspect ratio and is never cropped, so a portrait shot
   simply takes less width than its slot and the card shows through. That is
   the point. Their group shots and decoy spreads are wide, and object-fit:
   cover would cut people out of the frame to fill a box.

   Because the box is reserved by the slot rather than by the image, nothing
   moves as photographs load or swap.
   ========================================================= */

:root {
  /* The crossfade. gallery.js reads this same number as a constant, so if it
     changes here it changes there: a fade longer than the script's timeout
     leaves the outgoing image removed mid-transition. */
  --gallery-fade: 500ms;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(12px, 2vw, 24px);
}

/* The 4:3 slot. Invisible by design; the card behind it is the surface. */
.gallery-tile {
  position: relative;
  display: block;
  aspect-ratio: 4 / 3;
  border-radius: 0;
  text-decoration: none;
}

/* Absolutely placed and centred so the photograph fits inside the slot
   whatever its shape, and so a second image can be laid over the first for
   the crossfade without either one moving. */
.gallery-tile img {
  position: absolute;
  inset: 0;
  margin: auto;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 2px rgba(36, 30, 22, .10), 0 6px 18px rgba(36, 30, 22, .16);
}

/* The outgoing image of a swap. gallery.js fades the incoming one up over it
   and removes it at the end, so the slot is never empty. */
.gallery-tile img.is-out {
  opacity: 0;
  transition: opacity var(--gallery-fade) ease;
}
.gallery-tile img.is-in {
  opacity: 0;
}
.gallery-tile img.is-in.is-lit {
  opacity: 1;
  transition: opacity var(--gallery-fade) ease;
}

/* ---------- the phone ----------
   Two tiles stacked, and the other four are not rendered at all rather than
   being squeezed. A 4:3 frame at full phone width is already most of the
   screen; three across would put a group photograph in a 120px column.
   gallery.js reads back what is displayed, so hiding these is enough to take
   them out of the rotation. */
@media (max-width: 820px) {
  .gallery-grid { grid-template-columns: 1fr; }
  .gallery-tile:nth-child(n + 3) { display: none; }
}

/* ---------- the viewer ----------
   One photograph, no paging. Opened from a tile, closed on Escape, the
   backdrop, or the button. The rotation is paused for as long as it is open. */
.gallery-viewer {
  padding: 0;
  border: 0;
  background: transparent;
  /* Sized so the photograph sits inside the page rather than filling it: the
     backdrop stays visible all the way round and the close button has room
     above the frame without riding up into the nav. A portrait shot is the
     tall case, so the height cap is what actually governs. */
  max-width: min(86vw, 900px);
  max-height: 78vh;
  overflow: visible;
}
.gallery-viewer::backdrop {
  background: rgba(36, 30, 22, .88);
}
.gallery-viewer img {
  display: block;
  max-width: 100%;
  max-height: 78vh;
  width: auto;
  height: auto;
  border-radius: var(--radius-md);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
.gallery-viewer-close {
  position: absolute;
  top: -46px;
  right: 0;
  width: 38px;
  height: 38px;
  padding: 0;
  background: none;
  border: 1px solid var(--border-frame);
  border-radius: var(--radius-pill);
  color: var(--pasture);
  font-family: var(--display);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}
.gallery-viewer-close:hover {
  border-color: var(--wheat);
  color: var(--wheat);
}

/* On a short screen the close button has nowhere to sit above the photograph,
   so it comes inside the top corner instead of hanging over the backdrop. */
@media (max-height: 620px) {
  .gallery-viewer-close {
    top: 8px;
    right: 8px;
    background: rgba(36, 30, 22, .7);
  }
}
