.media-masonry-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

@media (min-width: 640px) {
  .media-masonry-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .media-masonry-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.media-tile {
  display: block;
  width: 100%;
  margin: 0;
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
}

.media-tile {
  display: inline-block;
  width: 100%;
  margin: 0 0 16px;
  break-inside: avoid;
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
}

.media-tile img {
  display: block;
  width: 100%;
  height: auto;
  transition: opacity .25s ease;
}

.media-tile:focus img,
.media-tile:hover img { opacity: .85; }


.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.9);
  display: flex;
  align-items: center;
  justify-content: center;

  padding: 32px;
  z-index: 9999;

  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}

.lightbox__stage {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  max-height: calc(100vh - 64px);
  border-radius: 12px;
}

.lightbox.is-hidden { display: none; }

.lightbox__image {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 64px - 80px);
  object-fit: contain;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  border-radius: 12px;
}

.lightbox__close,
.lightbox__nav {
  position: absolute;
  border: none;
  background: rgba(255,255,255,.12);
  color: #fff;
  font-size: 28px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.lightbox__close { top: 16px; right: 16px; }
.lightbox__prev { left: 16px; }
.lightbox__next { right: 16px; }

.lightbox__nav:focus,
.lightbox__nav:hover,
.lightbox__close:focus,
.lightbox__close:hover {
  background: rgba(255,255,255,.24);
}

.lightbox__caption {
  position: static;
  margin-top: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));

  color: #fff;
  font-size: 18px;
  line-height: 1.35;

  background: rgba(0,0,0,.45);
  border-radius: 10px;
  align-self: center;

  overflow: hidden;
  max-height: 200px;
  opacity: 1;
  transform: translateY(0);

  transition:
    max-height 0.30s ease,
    opacity    0.20s ease,
    transform  0.30s ease,
    margin-top 0.30s ease,
    padding-top 0.30s ease,
    padding-bottom 0.30s ease;
}

@media (max-width: 640px) {
  .lightbox__caption {
    font-size: 14px;
  }
}

.lightbox.is-active {
  opacity: 1;
  pointer-events: auto;
}

.lightbox__caption.is-hidden {
  max-height: 0;
  opacity: 0;
  transform: translateY(-6px);

  margin-top: 0;
  padding-top: 0;
  padding-bottom: 0;

}

