.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
}

.gallery__item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.gallery__image {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  cursor: pointer;
  border-radius: 0.5rem;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.gallery__image:hover,
.gallery__image:focus {
  transform: scale(1.02);
  opacity: 0.95;
}

.gallery__image:focus {
  outline: 3px solid #222;
  outline-offset: 3px;
}

.gallery__label {
  margin: 0;
}

/* Lightbox */
.gallery-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  background: rgba(0, 0, 0, 0.94);
}

.gallery-lightbox.is-open {
  display: block;
}

.gallery-lightbox__overlay {
  position: absolute;
  inset: 0;
}

.gallery-lightbox__dialog {
  position: relative;
  z-index: 2;
  width: 100vw;
  height: 100vh;
  color: #fff;
}

.gallery-lightbox__figure {
  margin: 0;
  width: 100%;
  height: 100%;
}

.gallery-lightbox__image-wrap {
  position: absolute;
  top: 1.5rem;
  right: 5.5rem;
  bottom: 8.25rem;
  left: 5.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: zoom-in;
}

.gallery-lightbox__image-wrap.is-zoomed {
  cursor: grab;
}

.gallery-lightbox__image-wrap.is-dragging {
  cursor: grabbing;
}

.gallery-lightbox__image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 0.5rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  background: #111;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center center;
  transition: transform 0.2s ease;
  will-change: transform;
}

.gallery-lightbox__image-wrap.is-zoomed .gallery-lightbox__image {
  transition: transform 0.08s linear;
}

.gallery-lightbox__caption {
  position: absolute;
  left: 5.5rem;
  right: 5.5rem;
  bottom: 1.5rem;
  text-align: center;
  padding: 0.85rem 1rem 0.95rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.62), rgba(0, 0, 0, 0.12));
  border-radius: 0.5rem;
}

.gallery-lightbox__counter {
  margin: 0 0 0.55rem;
  font-size: 0.95rem;
  opacity: 0.85;
}

.gallery-lightbox__title {
  margin: 0 0 0.3rem;
  font-size: 1.125rem;
}

.gallery-lightbox__text {
  margin: 0;
  opacity: 0.92;
  line-height: 1.5;
}

.gallery-lightbox__close,
.gallery-lightbox__prev,
.gallery-lightbox__next {
  position: fixed;
  z-index: 4;
  border: 0;
  cursor: pointer;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(4px);
  transition: background 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}

.gallery-lightbox__close:hover,
.gallery-lightbox__prev:hover,
.gallery-lightbox__next:hover,
.gallery-lightbox__close:focus-visible,
.gallery-lightbox__prev:focus-visible,
.gallery-lightbox__next:focus-visible {
  background: rgba(255, 255, 255, 0.24);
  outline: none;
}

.gallery-lightbox__close {
  top: 1.5rem;
  right: 1.5rem;
  width: 48px;
  height: 48px;
  border-radius: 999px;
  font-size: 1.6rem;
  line-height: 1;
}

.gallery-lightbox__prev,
.gallery-lightbox__next {
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  border-radius: 999px;
  font-size: 2rem;
  line-height: 1;
}

.gallery-lightbox__prev {
  left: 1.5rem;
}

.gallery-lightbox__next {
  right: 1.5rem;
}

.gallery-lightbox__image-wrap.is-zoomed ~ .gallery-lightbox__prev,
.gallery-lightbox__image-wrap.is-zoomed ~ .gallery-lightbox__next {
  opacity: 0.45;
}

@media (max-width: 768px) {
  .gallery {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
  }

  .gallery-lightbox__image-wrap {
    top: 1rem;
    right: 4rem;
    bottom: 9rem;
    left: 4rem;
  }

  .gallery-lightbox__caption {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    padding: 0.75rem 0.85rem 0.9rem;
  }

  .gallery-lightbox__counter {
    font-size: 0.9rem;
    margin-bottom: 0.45rem;
  }

  .gallery-lightbox__title {
    font-size: 1rem;
  }

  .gallery-lightbox__text {
    font-size: 0.95rem;
  }

  .gallery-lightbox__close {
    top: 1rem;
    right: 1rem;
    width: 44px;
    height: 44px;
    font-size: 1.4rem;
  }

  .gallery-lightbox__prev,
  .gallery-lightbox__next {
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
  }

  .gallery-lightbox__prev {
    left: 0.75rem;
  }

  .gallery-lightbox__next {
    right: 0.75rem;
  }
}