/* Justified rows: each photo keeps its own shape. Width grows in proportion to the
   photo ratio (--r), so every photo of a row ends up with the same height. */
.gallery {
  --row: 30rem;
  padding-bottom: 11rem;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 1.4rem;
}
.g-r75 { --r: 0.75; }
.g-r81 { --r: 0.8145; }
.g-r83 { --r: 0.8289; }
.g-r49 { --r: 0.4906; }
/* Desktop only: absorbs the free space of the incomplete last row, which would otherwise
   stretch its few photos to twice the height of the other rows. Smaller screens end on
   a full row, which this spacer would shrink. */
@media (min-width: 1100px) {
  .gallery::after {
    content: "";
    flex: 10000 1 0;
  }
}

.g-r56 { --r: 0.5625; }
.g-r67 { --r: 0.6667; }
.g-r90 { --r: 0.9019; }
.g-r123 { --r: 1.2277; }
.g-r133 { --r: 1.3333; }

.gallery-item {
  position: relative;
  flex: calc(var(--r) * 100) 1 calc(var(--r) * var(--row));
  aspect-ratio: var(--r);
  margin: 0;
  overflow: hidden;
  border-radius: var(--radius-media);
  background: var(--ie-sand);
}
.js .gallery-item {
  opacity: 0;
  transform: translateY(4.8rem);
  clip-path: inset(18% 0 0 0);
  transition: opacity 0.9s ease, transform 1.1s var(--ease-out), clip-path 1.1s var(--ease-in-out);
}
.js .gallery-item.is-visible {
  opacity: 1;
  transform: none;
  clip-path: inset(0 0 0 0);
}
.gallery-item__link {
  position: absolute;
  inset: 0;
  display: block;
  cursor: zoom-in;
}
.gallery-item__inner {
  position: absolute;
  inset: 0;
  transform: scale(var(--zoom, 1));
  transition: transform 1.2s var(--ease-out);
}
.js .gallery-item {
  --zoom: 1.15;
}
.js .gallery-item.is-visible {
  --zoom: 1;
}
.gallery-item__inner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.gallery-item::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(34, 31, 30, 0) 50%, rgba(34, 31, 30, 0.5) 100%);
  opacity: 0;
  transition: opacity 0.4s ease;
}
.gallery-item__caption {
  position: absolute;
  z-index: 1;
  left: 2rem;
  right: 2rem;
  bottom: 1.8rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  pointer-events: none;
  color: var(--ie-paper);
  opacity: 0;
  transform: translateY(1rem);
  transition: opacity 0.4s ease, transform 0.5s var(--ease-out);
}
.gallery-item__num {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 2.2rem;
}
.gallery-item__more {
  padding-bottom: 0.2rem;
  border-bottom: 1px solid rgba(247, 244, 238, 0.6);
  font-family: var(--font-body);
  font-weight: 300;
  font-size: 1.6rem;
}
@media (hover: hover) {
  .js .gallery-item.is-visible:hover {
    --zoom: 1.05;
  }
  .gallery-item:hover::after,
  .gallery-item:hover .gallery-item__caption {
    opacity: 1;
    transform: none;
  }
}
.gallery-item__link:focus-visible {
  outline-offset: -4px;
}

/* ---------- Lightbox ---------- */

.lightbox {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 24px 32px;
  border: 0;
  background: rgba(34, 31, 30, 0.94);
  color: var(--ie-paper);
  opacity: 0;
  transition: opacity 0.35s ease;
}
.lightbox[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.lightbox.is-shown {
  opacity: 1;
}
.lightbox::backdrop {
  background: transparent;
}
.lightbox__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.lightbox__count {
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 18px;
}
.lightbox__count span {
  opacity: 0.6;
}
.lightbox__stage {
  min-height: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
}
.lightbox__img {
  justify-self: center;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  animation: lightbox-zoom 0.5s var(--ease-out) both;
}
.lightbox__btn {
  width: 52px;
  height: 52px;
  padding: 0;
  border: 1px solid rgba(247, 244, 238, 0.3);
  border-radius: 50%;
  background: transparent;
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1;
  color: var(--ie-paper);
  cursor: pointer;
}
.lightbox__btn[hidden] {
  display: block;
  visibility: hidden;
}
.lightbox__bottom {
  height: 24px;
}
@keyframes lightbox-zoom {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 1099px) {
  .gallery {
    --row: calc((100vw - 8rem) * 0.32);
    padding-bottom: 8rem;
    gap: 1.2rem;
  }
}
@media (max-width: 767px) {
  .gallery {
    --row: calc((100vw - 4rem) * 0.48);
    padding-bottom: 6.4rem;
    gap: 1rem;
  }
  .gallery-item__caption {
    display: none;
  }
  .lightbox {
    padding: 16px;
  }
  .lightbox__stage {
    gap: 8px;
  }
  .lightbox__btn {
    width: 40px;
    height: 40px;
    font-size: 17px;
  }
}
