.gallery-section {
  background: linear-gradient(180deg, #f8fafc 0%, #ffffff 40%, #f1f5f9 100%);
}

.gallery-filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.gallery-filter-btn {
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #475569;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.45rem 1rem;
  border-radius: 9999px;
  cursor: pointer;
  transition:
    background 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.15s ease;
}

.gallery-filter-btn:hover {
  border-color: #cbd5e1;
  color: #1e293b;
}

.gallery-filter-btn.is-active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.28);
}

/* شبکه یکنواخت — بدون شکاف‌های masonry */
.gallery-masonry {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: stretch;
}

@media (min-width: 640px) {
  .gallery-masonry {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.25rem;
  }
}

@media (min-width: 1024px) {
  .gallery-masonry {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.5rem;
  }
}

.gallery-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-radius: 1rem;
  overflow: hidden;
  background: #fff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
  cursor: zoom-in;
  transition:
    transform 0.3s cubic-bezier(0.32, 0.72, 0, 1),
    box-shadow 0.3s ease,
    opacity 0.35s ease;
}

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

.gallery-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}

.gallery-card__img-wrap {
  position: relative;
  overflow: hidden;
  background: #e2e8f0;
  aspect-ratio: 4 / 3;
  flex-shrink: 0;
}

.gallery-card--video .gallery-card__img-wrap,
.gallery-card--embed .gallery-card__img-wrap {
  overflow: hidden;
}

.gallery-card__img-wrap img,
.gallery-card__img-wrap img.gallery-video-poster,
.gallery-card__img-wrap video.gallery-video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 0.45s ease;
}

.gallery-card:hover .gallery-card__img-wrap img,
.gallery-card:hover .gallery-card__img-wrap img.gallery-video-poster {
  transform: scale(1.04);
}

/* آلبوم — لایه‌های پشت کاور */
.gallery-card--album .gallery-card__img-wrap {
  isolation: isolate;
}

.gallery-card__album-stack {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.gallery-card__album-stack span {
  position: absolute;
  inset: 0.35rem 0.45rem 0.55rem 0.55rem;
  border-radius: 0.65rem;
  background: linear-gradient(145deg, #cbd5e1 0%, #94a3b8 100%);
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
}

.gallery-card__album-stack span:first-child {
  transform: rotate(-5deg) translate(6px, -5px);
  z-index: 0;
}

.gallery-card__album-stack span:last-child {
  inset: 0.5rem 0.55rem 0.7rem 0.65rem;
  transform: rotate(4deg) translate(-5px, 6px);
  z-index: -1;
  opacity: 0.92;
}

.gallery-card--album .gallery-card__img-wrap img,
.gallery-card--album .gallery-card__img-wrap video {
  position: relative;
  z-index: 1;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.15);
}

.gallery-card__album-badge {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: none;
  border: none;
  line-height: 1;
  pointer-events: none;
}

.gallery-card__album-badge-icon {
  font-size: 1.35rem;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.55));
}

.gallery-card--album .gallery-card__badge {
  z-index: 4;
  max-width: calc(100% - 2.75rem);
}

.gallery-card__album-count {
  position: absolute;
  bottom: 0.55rem;
  left: 0.55rem;
  z-index: 2;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  background: rgba(15, 23, 42, 0.78);
  color: #f8fafc;
  backdrop-filter: blur(4px);
}

.gallery-card__badge {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  z-index: 4;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  background: rgba(15, 23, 42, 0.72);
  color: #f8fafc;
  backdrop-filter: blur(4px);
  max-width: calc(100% - 1.3rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-card__body {
  padding: 0.65rem 0.75rem 0.75rem;
  text-align: right;
  flex-shrink: 0;
  min-height: 2.75rem;
  display: flex;
  align-items: center;
}

.gallery-card__title {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 700;
  color: #1e293b;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.gallery-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: #64748b;
}

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

.gallery-card--video,
.gallery-card--embed {
  cursor: pointer;
}

.gallery-card__embed-thumb {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: linear-gradient(145deg, #1e293b 0%, #334155 100%);
}

.gallery-card__embed-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #e2e8f0;
}

/* امبد آپارات — عرض کامل مودال (flex والد قبلاً بچه را کوچک می‌کرد) */
#gallery-video-overlay.is-embed-open .gallery-video-overlay__content {
  width: min(96vw, 900px);
  align-items: stretch;
}

#gallery-video-overlay.is-embed-open .gallery-video-overlay__embed {
  display: block !important;
  width: 100% !important;
  max-width: 100%;
  max-height: calc(92vh - 12rem);
  min-height: min(56vw, 320px);
}

#gallery-video-overlay.is-embed-open .gallery-video-overlay__embed > div,
#gallery-video-overlay.is-embed-open .gallery-video-overlay__embed iframe {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box;
}

#gallery-video-overlay.is-embed-open .gallery-video-overlay__embed iframe {
  height: auto !important;
  min-height: 200px;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: 8px;
  background: #000;
}

.gallery-card__play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}

.gallery-card__play::before {
  content: '';
  display: block;
  width: 0;
  height: 0;
  margin-right: 0.15rem;
  border-style: solid;
  border-width: 1.1rem 0 1.1rem 1.75rem;
  border-color: transparent transparent transparent #fff;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.45));
}

#gallery-video-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(15, 23, 42, 0.92);
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  box-sizing: border-box;
}

#gallery-video-overlay.is-open {
  display: flex;
}

#gallery-video-overlay .gallery-video-overlay__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: min(96vw, 1200px);
  max-height: min(92vh, 100%);
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 0.5rem;
}

#gallery-video-overlay .gallery-video-overlay__player {
  max-width: min(96vw, 1200px);
  max-height: calc(92vh - 12rem);
  width: 100%;
  border-radius: 8px;
  background: #000;
}

#gallery-video-overlay .gallery-video-overlay__meta {
  margin-top: 1rem;
  text-align: center;
  max-width: min(96vw, 720px);
}

#gallery-video-overlay .gallery-video-overlay__meta.is-empty {
  display: none;
}

#gallery-video-overlay .gallery-video-overlay__title {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: #f8fafc;
}

#gallery-video-overlay .gallery-video-overlay__title:empty {
  display: none;
  margin: 0;
}

#gallery-video-overlay .gallery-video-overlay__caption {
  margin: 0;
  font-size: 0.95rem;
  color: #cbd5e1;
  line-height: 1.6;
  white-space: pre-line;
}

#gallery-video-overlay .gallery-video-overlay__caption:empty {
  display: none;
}

#gallery-video-overlay .gallery-viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  cursor: pointer;
  font-size: 2rem;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 8px;
  color: #fff;
  background: rgba(30, 41, 59, 0.85);
  z-index: 2;
  font-family: inherit;
  line-height: 1;
}

#gallery-video-overlay .gallery-viewer-nav:hover:not(:disabled) {
  background: rgba(51, 65, 85, 0.95);
}

#gallery-video-overlay .gallery-viewer-nav--prev {
  left: 1rem;
}

#gallery-video-overlay .gallery-viewer-nav--next {
  right: 1rem;
}

#gallery-video-overlay .gallery-viewer-nav:disabled {
  opacity: 0.35;
  cursor: default;
}

#gallery-video-overlay .gallery-viewer-image {
  max-width: min(96vw, 1400px);
  max-height: calc(92vh - 12rem);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

#gallery-video-overlay .gallery-viewer-strip {
  display: flex;
  flex-wrap: nowrap;
  flex-shrink: 0;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding: 0.35rem 0.5rem 0.65rem;
  width: 100%;
  max-width: min(96vw, 720px);
  min-height: 4.25rem;
  box-sizing: border-box;
  overflow-x: auto;
  overflow-y: visible;
  justify-content: center;
  align-items: center;
  scrollbar-width: thin;
}

#gallery-video-overlay .gallery-viewer-strip[hidden] {
  display: none !important;
}

#gallery-video-overlay .gallery-viewer-strip__item {
  flex: 0 0 auto;
  width: 5rem;
  height: 3.5rem;
  padding: 0;
  border: 2px solid rgba(148, 163, 184, 0.45);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: rgba(30, 41, 59, 0.9);
  opacity: 0.75;
  transition:
    opacity 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.15s ease;
}

#gallery-video-overlay .gallery-viewer-strip__item:hover {
  opacity: 1;
  border-color: rgba(148, 163, 184, 0.85);
}

#gallery-video-overlay .gallery-viewer-strip__item.is-active {
  opacity: 1;
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px #38bdf8;
}

#gallery-video-overlay .gallery-viewer-strip__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#gallery-video-overlay .gallery-viewer-strip__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 1.1rem;
  color: #e2e8f0;
}

#gallery-video-overlay .gallery-video-overlay__close {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 2;
  border: none;
  cursor: pointer;
  font-size: 1.75rem;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 8px;
  color: #fff;
  background: rgba(30, 41, 59, 0.85);
}

.gallery-pagination {
  margin-top: 2rem;
}

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

.gallery-pagination__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1rem;
}

.gallery-page-numbers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: center;
}

.gallery-page-btn,
.gallery-page-nav {
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #475569;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  cursor: pointer;
  transition:
    background 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease;
  font-family: inherit;
}

.gallery-page-btn:hover,
.gallery-page-nav:hover:not(:disabled) {
  border-color: #cbd5e1;
  color: #1e293b;
}

.gallery-page-btn.is-active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.gallery-page-nav:disabled {
  opacity: 0.4;
  cursor: default;
}

.gallery-pagination__info {
  font-size: 0.85rem;
  color: #64748b;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .gallery-pagination__info {
    width: 100%;
    text-align: center;
    order: 3;
  }
}
