/**
 * gallery.css — Gallery grid, filters and lightbox
 * -----------------------------------------------------------------------------
 * The gallery grid and filter buttons are populated by main.js from the
 * manifest in site-config.js. The lightbox markup lives in index.html and is
 * shown/hidden by main.js.
 */

/* ---- Filters ----------------------------------------------------------- */
.gallery__filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-xs);
  margin-bottom: clamp(2rem, 4vw, 3rem);
}

.gallery__filter {
  font-family: var(--font-sans);
  font-size: var(--fs-small);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--color-ink-soft);
  background: none;
  border: none;
  padding: 0.5rem 0.25rem;
  cursor: pointer;
  position: relative;
  transition: color var(--dur-fast) var(--ease);
}

/* Invisible tap-target extension (the visible ::after below is the active
   underline). Grows each filter to ~45px tall without moving anything; the
   4px horizontal bleed stays well inside the 12px gap between buttons. */
.gallery__filter::before {
  content: "";
  position: absolute;
  inset: -4px;
}

.gallery__filter::after {
  content: "";
  position: absolute;
  left: 0.25rem;
  right: 0.25rem;
  bottom: 0;
  height: 1px;
  background-color: var(--color-accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--dur-fast) var(--ease);
}

.gallery__filter:hover { color: var(--color-ink); }

.gallery__filter.is-active {
  color: var(--color-ink);
}
.gallery__filter.is-active::after {
  transform: scaleX(1);
}

/* ---- Grid -------------------------------------------------------------- */
.gallery__grid {
  max-width: var(--container-wide);
  margin-inline: auto;
  padding-inline: var(--gutter);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(0.5rem, 1.2vw, 1rem);
}

.gallery__item {
  position: relative;
  margin: 0;
  overflow: hidden;
  aspect-ratio: 3 / 2;
  background-color: var(--color-bg-alt);
  cursor: pointer;
}

.gallery__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--dur) var(--ease),
              opacity var(--dur) var(--ease);
}

.gallery__item:hover img,
.gallery__item:focus-within img {
  transform: scale(1.05);
}

/* Caption revealed on hover — restrained, no permanent card. */
.gallery__caption {
  position: absolute;
  inset: auto 0 0 0;
  padding: var(--space-md) var(--space-sm) var(--space-sm);
  font-size: var(--fs-small);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--color-on-dark);
  background: linear-gradient(to top, rgba(12, 11, 8, 0.7), transparent);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease);
}

.gallery__item:hover .gallery__caption,
.gallery__item:focus-within .gallery__caption {
  opacity: 1;
  transform: none;
}

/* Fade items out/in when filtering. */
.gallery__item.is-hidden { display: none; }

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

/* ===================================================================== */
/* LIGHTBOX                                                             */
/* ===================================================================== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-lightbox);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 4vw, 3rem);
  background-color: rgba(12, 11, 8, 0.94);
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}

/* CRITICAL: an author `display: flex` beats the browser's built-in
   `[hidden] { display: none }`, which previously left this full-screen,
   fully transparent overlay sitting on top of the entire page and swallowing
   every click (nav links, CTAs, gallery tiles). Both rules below keep the
   closed lightbox out of the way:
     - [hidden]      -> removed from layout entirely (JS available)
     - :not(.is-open)-> never intercepts pointer events (belt and braces, and
                        covers the moment between closing and `hidden`) */
.lightbox[hidden] {
  display: none !important;
}

.lightbox:not(.is-open) {
  pointer-events: none;
}

.lightbox.is-open {
  opacity: 1;
  pointer-events: auto;
}

.lightbox__figure {
  margin: 0;
  max-width: min(1400px, 92vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-md);
}

.lightbox__image {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  box-shadow: var(--shadow-soft);
}

.lightbox__caption {
  color: var(--color-on-dark-soft);
  font-size: var(--fs-small);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}

/* Controls */
.lightbox__close,
.lightbox__nav {
  position: absolute;
  background: none;
  border: none;
  color: var(--color-on-dark);
  cursor: pointer;
  line-height: 1;
  opacity: 0.75;
  transition: opacity var(--dur-fast) var(--ease);
  /* Comfortable thumb targets on phones. */
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Controls sit above the figure so they are never covered by a tall image. */
  z-index: 1;
  -webkit-tap-highlight-color: transparent;
}
.lightbox__close:hover,
.lightbox__nav:hover { opacity: 1; }

.lightbox__close {
  top: clamp(1rem, 3vw, 2rem);
  right: clamp(1rem, 3vw, 2.5rem);
  font-size: 2.5rem;
}

.lightbox__nav {
  top: 50%;
  transform: translateY(-50%);
  font-size: clamp(2.5rem, 6vw, 4rem);
  padding: var(--space-sm);
}

.lightbox__nav--prev { left: clamp(0.5rem, 2vw, 2rem); }
.lightbox__nav--next { right: clamp(0.5rem, 2vw, 2rem); }

/* On touch/small screens, move arrows to the bottom for easy thumb reach. */
@media (max-width: 640px) {
  .lightbox__nav {
    top: auto;
    bottom: clamp(1rem, 4vw, 2rem);
    transform: none;
  }
  .lightbox__nav--prev { left: 25%; }
  .lightbox__nav--next { right: 25%; }
}

/* Prevent the page behind the lightbox from scrolling when it's open. */
body.is-lightbox-open {
  overflow: hidden;
}
