.gallery-item-hidden,
.gallery-item-unloaded {
  display: none;
}

.gallery-item {
  animation: galleryFadeIn 0.4s ease both;
}

@keyframes galleryFadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.gallery-tags-container {
  margin-bottom: 2rem;
}

.gallery-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.gallery-tag {
  padding: 0.35rem 1rem;
  border: 1.5px solid var(--second-bg-color, #e0e0e0);
  border-radius: 2rem;
  background: var(--third-bg-color, #f5f5f5);
  color: var(--second-text-color);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.25s ease;
  user-select: none;
  white-space: nowrap;
}
.gallery-tag:hover {
  border-color: var(--active-color, #ff9800);
  color: var(--active-color, #ff9800);
}
.gallery-tag.active {
  border-color: var(--active-color, #ff9800);
  color: #fff;
  background: var(--active-color, #ff9800);
  font-weight: 600;
}

.gallery-grid {
  min-height: 200px;
  column-count: 4;
  column-gap: 16px;
}

.gallery-item {
  break-inside: avoid;
  margin-bottom: 16px;
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  background: var(--third-bg-color, #f5f5f5);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
}
.gallery-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.gallery-item-wrapper {
  position: relative;
  width: 100%;
  display: block;
  min-height: 120px;
  background: var(--third-bg-color, #f5f5f5);
}

.gallery-item-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--third-bg-color, #f5f5f5);
  z-index: 1;
  transition: opacity 0.4s ease;
}
.gallery-item-loader::after {
  content: "";
  width: 32px;
  height: 32px;
  border: 3px solid var(--second-bg-color, #e0e0e0);
  border-top-color: var(--active-color, #ff9800);
  border-radius: 50%;
  animation: gallerySpin 0.8s linear infinite;
}

@keyframes gallerySpin {
  to {
    transform: rotate(360deg);
  }
}
.gallery-item-image {
  width: 100%;
  display: block;
  position: relative;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.4s ease;
}
.gallery-item-image.loaded {
  opacity: 1;
}
.gallery-item-image.loaded + .gallery-item-overlay, .gallery-item-image.loaded ~ .gallery-item-overlay {
  opacity: 1;
}

.gallery-item-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 3;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0.1) 60%, rgba(0, 0, 0, 0) 100%);
  padding: 2.5rem 1rem 0.75rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.gallery-item-loaded .gallery-item-loader {
  opacity: 0;
  pointer-events: none;
}

.gallery-item-loaded .gallery-item-overlay {
  opacity: 1;
}

.gallery-item-title {
  font-size: 1rem;
  font-weight: bold;
  color: #fff;
  margin-bottom: 0.2rem;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.gallery-item-description {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.4;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
.lightbox.active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  cursor: zoom-out;
}

.lightbox-content {
  position: relative;
  z-index: 1;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: 90vw;
  max-height: 90vh;
  padding: 1rem;
}

.lightbox-image {
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.lightbox-image.loaded {
  opacity: 1;
  transform: scale(1);
}

.lightbox-caption {
  text-align: center;
  margin-top: 1rem;
  color: rgba(255, 255, 255, 0.9);
  font-size: 1rem;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.lightbox-title {
  font-weight: bold;
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}

.lightbox-description {
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.75);
}

.lightbox-counter {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 0.5rem;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  font-size: 1.5rem;
  transition: background 0.2s ease, transform 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
}
.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-50%) scale(1.1);
}
.lightbox-nav:active {
  transform: translateY(-50%) scale(0.95);
}

.lightbox-prev {
  left: 20px;
}

.lightbox-next {
  right: 20px;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 2;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  font-size: 1.5rem;
  transition: background 0.2s ease, transform 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
}
.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}
.lightbox-close:active {
  transform: scale(0.95);
}

.gallery-comments {
  margin: 3rem auto 0;
  max-width: 800px;
  padding: 0 1rem;
}

@media screen and (max-width: 1408px) {
  .gallery-grid {
    column-count: 3;
  }
}
@media screen and (max-width: 1024px) {
  .gallery-grid {
    column-count: 2;
  }
  .lightbox-prev {
    left: 10px;
    width: 40px;
    height: 40px;
  }
  .lightbox-next {
    right: 10px;
    width: 40px;
    height: 40px;
  }
}
@media screen and (max-width: 768px) {
  .gallery-grid {
    column-count: 2;
    column-gap: 12px;
  }
  .gallery-item {
    margin-bottom: 12px;
  }
  .gallery-tag {
    padding: 0.3rem 0.8rem;
    font-size: 0.8rem;
  }
  .lightbox-nav {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
  }
  .lightbox-prev {
    left: 8px;
  }
  .lightbox-next {
    right: 8px;
  }
  .lightbox-close {
    top: 12px;
    right: 12px;
    width: 38px;
    height: 38px;
  }
  .lightbox-image {
    max-width: 95vw;
    max-height: 75vh;
  }
}
@media screen and (max-width: 480px) {
  .gallery-grid {
    column-count: 1;
  }
  .lightbox-close {
    display: none;
  }
}