/* Gallery page. Shared tokens, nav and footer live in styles.css. */

.gallery-main {
  padding-top: 7rem;
}

.gallery-container {
  max-width: 1400px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.gallery-main .section-title {
  margin-bottom: 0.75rem;
}

.gallery-hint {
  text-align: center;
  color: var(--text-light);
  font-size: 0.95rem;
  margin-bottom: 3rem;
}

.gallery-section {
  margin-bottom: 4rem;
}

.gallery-section h2 {
  text-align: center;
  margin-bottom: 2rem;
  font-size: clamp(1.6rem, 4vw, 2rem);
}

.gallery-section h2::after {
  content: '';
  display: block;
  width: 60px;
  height: 3px;
  background: var(--primary);
  margin: 1rem auto 0;
}

/* Two equal columns by default; .split is a 2:1 layout. */
.gallery-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.gallery-grid.split {
  grid-template-columns: 2fr 1fr;
}

/* Two photos stacked in one column, sharing the row height */
.gallery-stack {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 1.25rem;
}

/* ---------- Tiles (buttons that open the lightbox) ---------- */
.gallery-tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  padding: 0;
  border: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: zoom-in;
  border-radius: 0.75rem;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 0.3s var(--ease), box-shadow 0.3s ease;
}

.gallery-tile.wide {
  grid-column: 1 / -1;
  aspect-ratio: 21 / 9;
}

.gallery-tile.tall {
  aspect-ratio: 3 / 4;
}

/* Takes its height from the row instead of its own ratio */
.gallery-tile.fill {
  aspect-ratio: auto;
  height: 100%;
}

.gallery-tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s var(--ease);
}

.gallery-tile:disabled {
  cursor: default;
}

.caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 2rem 1rem 0.9rem;
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--white);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.82));
  transform: translateY(100%);
  transition: transform 0.3s var(--ease);
}

.gallery-tile:focus-visible {
  outline-offset: 4px;
}

.gallery-tile:focus-visible .caption {
  transform: none;
}

/* Hover effects only where hover exists; touch screens always show captions. */
@media (hover: hover) {
  .gallery-tile:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
  }

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

  .gallery-tile:hover .caption {
    transform: none;
  }
}

@media (hover: none) {
  .caption {
    transform: none;
    font-size: 0.88rem;
    padding: 1.5rem 0.85rem 0.7rem;
  }
}

/* ---------- Lightbox (native <dialog>) ---------- */
.lightbox {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 1rem;
  border: 0;
  background: rgba(0, 0, 0, 0.92);
  color: var(--white);
}

.lightbox[open] {
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.lightbox figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  height: 100%;
  justify-content: center;
}

.lightbox img {
  max-width: 100%;
  max-height: calc(100% - 3rem);
  object-fit: contain;
  border-radius: 0.5rem;
}

.lightbox figcaption {
  text-align: center;
  font-size: 0.95rem;
  color: var(--text);
}

.close-lightbox {
  position: absolute;
  top: max(0.75rem, env(safe-area-inset-top));
  right: max(0.75rem, env(safe-area-inset-right));
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  font-size: 2rem;
  line-height: 1;
  color: var(--white);
  background: rgba(13, 20, 36, 0.7);
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  cursor: pointer;
}

.close-lightbox:hover {
  border-color: var(--primary-text);
}

/* Stop the page scrolling behind the open lightbox */
html:has(.lightbox[open]) {
  overflow: hidden;
}

/* ---------- Phones / small tablets ---------- */
@media (max-width: 768px) {
  .gallery-main {
    padding-top: 6rem; /* slim navbar with a menu button on phones */
  }

  .gallery-container {
    margin-top: 1rem;
  }

  .gallery-section {
    margin-bottom: 3rem;
  }

  .gallery-grid,
  .gallery-grid.split {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }

  .gallery-stack {
    grid-template-rows: none;
    gap: 0.85rem;
  }

  .gallery-tile.wide {
    aspect-ratio: 16 / 9;
  }

  .gallery-tile.fill {
    aspect-ratio: 4 / 3;
    height: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-tile:hover,
  .gallery-tile:hover img {
    transform: none;
  }
}
