.gallery-block {
  margin-top: 2.5rem;
}

.gallery-block.is-hidden {
  display: none;
}

.gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.gallery-head h2 {
  margin: 0;
}

.gallery-open {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.gallery-open:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.12);
}

.gallery-open:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.gallery-open:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 10, 0.9);
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
  gap: 16px;
  z-index: 1000;
  color: var(--text);
}

.lightbox[hidden] {
  display: none;
}

.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: absolute;
  z-index: 2;
  background: rgba(20, 20, 22, 0.75);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 28px;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.lightbox-close {
  top: calc(20px + env(safe-area-inset-top));
  right: calc(20px + env(safe-area-inset-right));
  font-size: 30px;
}

.lightbox-prev {
  left: calc(20px + env(safe-area-inset-left));
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-next {
  right: calc(20px + env(safe-area-inset-right));
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
  background: rgba(40, 40, 45, 0.9);
  transform: translateY(-50%) scale(1.03);
}

.lightbox-close:hover {
  transform: scale(1.03);
}

.lightbox-nav-hidden {
  display: none;
}

.lightbox-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  position: relative;
  z-index: 1;
  width: 100%;
}

.lightbox-slide {
  width: min(1100px, 92vw);
  max-height: 70vh;
  min-height: min(70vh, calc(92vw * 2 / 3));
  aspect-ratio: 3 / 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 18, 20, 0.7);
  border-radius: calc(var(--radius) + 6px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 12px;
}

.lightbox-slide picture,
.lightbox-slide img {
  width: 100%;
  height: 100%;
  max-height: 68vh;
  object-fit: contain;
  border-radius: calc(var(--radius) - 2px);
}

.lightbox-counter {
  align-self: flex-end;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.8);
}

.lightbox-caption {
  width: min(1100px, 92vw);
  margin: 0 auto;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.95rem;
}

.lightbox-thumbs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: thin;
}

.lightbox-thumb {
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  overflow: hidden;
  padding: 0;
  width: 110px;
  height: 78px;
  background: transparent;
  cursor: pointer;
  flex: 0 0 auto;
  transition: border 0.2s ease, transform 0.2s ease;
}

.lightbox-thumb img,
.lightbox-thumb picture {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.lightbox-thumb.is-active {
  border-color: var(--accent);
  transform: translateY(-2px);
}

@media (max-width: 900px) {
  .lightbox-prev,
  .lightbox-next {
    width: 40px;
    height: 40px;
    font-size: 24px;
  }

  .lightbox-slide {
    width: 95vw;
  }
}

@media (max-width: 640px) {
  .gallery-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .lightbox {
    padding: 18px 12px;
  }

  .lightbox-thumbs {
    padding-bottom: 4px;
  }

  .lightbox-thumb {
    width: 88px;
    height: 64px;
  }
}
