/* ==========================================================================
   Component: Instagram Gallery Embed + Photo Grid + Lightbox
   ========================================================================== */

/* ---- Shared grid tile (Home Instagram strip + Gallery page grid) ---- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-1);
}

/* Both grids start empty in the HTML and are filled by js/gallery.js on
   DOMContentLoaded — on a slow connection that gap between first paint and
   the tiles landing is a large layout shift (grid height jumping from 0 to
   several rows of 1:1 tiles). Reserving each grid's height up front via
   aspect-ratio keeps that first paint the right size already. The values
   below are measured (not the plain columns/rows fraction) because the
   fixed pixel gap between tiles makes the true ratio drift very slightly
   from the clean fraction; they match this template's demo photo count
   (12 in data/gallery.js, 8 shown on the Home Instagram strip). If you add
   or remove enough photos to change the row count at a given column count,
   re-measure and adjust. */
#gallery-grid {
  aspect-ratio: 1.3364; /* 12 photos / 4 columns = 3 rows */
}

#instagram-strip {
  aspect-ratio: 2.014; /* 8 photos / 4 columns = 2 rows */
}

.gallery-filters {
  min-height: calc(var(--fs-nav) * var(--lh-nav) + var(--space-1) * 2 + 2px);
}

.gallery-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--color-surface);
}

.gallery-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1);
  transform-origin: center;
  transition: transform 300ms var(--ease-standard);
}

.gallery-tile::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(7, 16, 30, 0.35);
  opacity: 0;
  transition: opacity var(--duration-base) var(--ease-standard);
}

.gallery-tile__icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
  opacity: 0;
  transition: opacity var(--duration-base) var(--ease-standard);
}

/* Focus (keyboard, any device) always gets the full v1.2 hover treatment —
   overlay, glyph and image zoom — so keyboard users get the same feedback
   pointer/hover users do. Plain :hover (pointer devices only, see below)
   is where the "stuck hover on touch" risk actually lives. */
.gallery-tile:focus-visible::after,
.gallery-tile:focus-visible .gallery-tile__icon {
  opacity: 1;
}

.gallery-tile:focus-visible img {
  transform: scale(1.06);
}

@media (hover: hover) and (pointer: fine) {
  .gallery-tile:hover::after,
  .gallery-tile:hover .gallery-tile__icon {
    opacity: 1;
  }

  .gallery-tile:hover img {
    transform: scale(1.06);
  }
}

/* ---- Gallery page filters ---- */
.gallery-filters {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.gallery-filter {
  font-family: var(--font-heading);
  font-size: var(--fs-nav);
  letter-spacing: var(--ls-nav);
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  transition: color var(--duration-base) var(--ease-standard),
    border-color var(--duration-base) var(--ease-standard);
}

.gallery-filter:hover,
.gallery-filter:focus-visible {
  border-color: var(--color-border-strong);
}

.gallery-filter.is-active {
  color: var(--color-on-primary);
  background: var(--color-primary);
  border-color: var(--color-primary);
}

/* ---- Lightbox ---- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: rgba(7, 16, 30, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--duration-base) var(--ease-standard);
}

.lightbox.is-open {
  opacity: 1;
}

.lightbox__stage {
  max-width: min(1000px, 84vw);
  max-height: 82vh;
  margin-inline: var(--space-8);
  text-align: center;
}

.lightbox__image {
  max-width: 100%;
  max-height: 74vh;
  width: auto;
  height: auto;
  margin-inline: auto;
}

.lightbox__caption {
  margin-top: var(--space-2);
}

.lightbox__close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
}

.lightbox__arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
}

.lightbox__arrow--prev {
  left: var(--space-3);
}

.lightbox__arrow--next {
  right: var(--space-3);
}

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

  #gallery-grid {
    aspect-ratio: 0.7482; /* 12 photos / 3 columns = 4 rows */
  }

  #instagram-strip {
    aspect-ratio: 1; /* 8 photos / 3 columns = 3 rows */
  }
}

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

  #gallery-grid {
    aspect-ratio: 0.3284; /* 12 photos / 2 columns = 6 rows */
  }

  #instagram-strip {
    aspect-ratio: 0.4945; /* 8 photos / 2 columns = 4 rows */
  }

  .gallery-filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: var(--space-1);
  }

  .gallery-filter {
    scroll-snap-align: start;
    flex-shrink: 0;
  }

  .lightbox__arrow {
    width: 36px;
    height: 36px;
  }

  .lightbox__stage {
    margin-inline: var(--space-6);
  }
}
