/* ===== PREMIUM BENTO GALLERY — Kahramana Baghdad ===== */

/* 1. Gallery Filters — Magnetic Capsule Style */
.gallery-tabs {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin: 4rem auto 6rem;
  padding: 1.5rem;
  background: rgba(17, 11, 5, 0.4);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-btn);
  width: fit-content;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.gallery-tab {
  padding: 0.8rem 2.2rem;
  border: 1px solid transparent;
  border-radius: var(--radius-btn);
  background: transparent;
  color: var(--col-gold-dim);
  font-family: var(--font-primary);
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all 0.5s var(--ease-magnetic);
}

.gallery-tab:hover {
  color: var(--col-cream);
  background: rgba(255, 255, 255, 0.05);
}

.gallery-tab.active {
  background: var(--col-gold);
  color: var(--col-dark);
  border-color: var(--col-gold);
  box-shadow: 0 10px 30px rgba(209, 159, 81, 0.3);
}

/* 2. Bento Grid 2.0 — Asymmetric Architecture */
.gallery-masonry {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 250px;
  gap: 2rem;
  padding-bottom: 8rem;
  contain: layout;
}

/* Logic for asymmetric bento scaling */
.gallery-item {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.03);
  /* Display immediately to fix mobile rendering bug */
  opacity: 1;
  transform: translateY(0);
  transition: transform 0.65s var(--ease-magnetic),
    box-shadow 0.7s var(--ease-magnetic);
  /* will-change only on hover — not on all 19 items at once (GPU memory) */
  contain: layout style;
}

.gallery-skeleton {
  position: absolute;
  inset: 0;
  background: rgba(45, 24, 11, 0.4);
  background: linear-gradient(
    90deg,
    rgba(45, 24, 11, 0.4) 25%,
    rgba(209, 159, 81, 0.05) 50%,
    rgba(45, 24, 11, 0.4) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 2s infinite linear;
  z-index: 1;
  transition: opacity 0.5s ease;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

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

.gallery-item img {
  opacity: 0;
  transition: opacity 0.6s var(--ease-magnetic), transform 1.2s var(--ease-magnetic);
}

.gallery-item.loaded img,
.gallery-item.visible img {
  opacity: 1;
}

.gallery-item:focus-visible {
  outline: 2px solid var(--col-gold);
  outline-offset: 2px;
}

/* Hover lift — will-change activated only on hover, not at rest */
@media (hover: hover) {
  .gallery-item:hover {
    will-change: transform;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
    transform: translateY(-4px) scale(1.01);
  }
}

/* Asymmetric sizing patterns */
.gallery-item:nth-child(7n + 1) {
  grid-column: span 2;
  grid-row: span 2;
}

.gallery-item:nth-child(7n + 4) {
  grid-column: span 2;
  grid-row: span 1;
}

.gallery-item:nth-child(7n + 6) {
  grid-column: span 1;
  grid-row: span 2;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 1.2s var(--ease-magnetic);
  /* No base filter — CSS filters create compositing layers per image on mobile */
}

/* 3. Liquid Glass Overlays */
.gallery-overlay {
  position: absolute;
  inset: 0.8rem;
  /* Inset for bento aesthetic */
  padding: 2.5rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: rgba(17, 11, 5, 0.2);
  /* backdrop-filter: none at rest — blur(0) still creates a compositing layer */
  backdrop-filter: none;
  border-radius: var(--radius);
  border: 1px solid transparent;
  opacity: 0;
  transition: opacity 0.4s ease, background 0.4s ease, backdrop-filter 0.4s ease, border-color 0.4s ease;
  z-index: 2;
}

/* Refraction effect — only on true hover (not touch) */
@media (hover: hover) {
  .gallery-item:hover .gallery-overlay {
    opacity: 1;
    background: rgba(17, 11, 5, 0.5);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.1);
  }
}

.gallery-overlay span {
  color: var(--col-cream);
  font-family: var(--font-drama);
  font-style: italic;
  font-size: var(--text-sec-title);
  font-weight: 700;
  transform: translateY(20px);
  transition: all 0.5s var(--ease-magnetic);
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

@media (hover: hover) {
  .gallery-item:hover .gallery-overlay span {
    transform: translateY(0);
  }

  .gallery-item:hover img {
    transform: scale(1.1);
    filter: brightness(0.6) blur(2px);
  }

  /* 4. Sibling Fade — desktop only, never on touch (GPU-intensive) */
  .gallery-masonry:has(.gallery-item:hover) .gallery-item:not(:hover) {
    opacity: 0.4;
    filter: grayscale(0.4);
    /* No blur — blur on N items at once is too costly even on desktop */
  }
}

/* 5. Lightbox Redesign */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 5, 2, 0.95);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: all 0.6s var(--ease-magnetic);
  backdrop-filter: blur(25px);
  padding: 4rem;
}

.lightbox.active {
  opacity: 1;
  pointer-events: auto;
}

.lightbox img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: var(--radius);
  box-shadow: 0 50px 100px rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transform: scale(0.9);
  transition: transform 0.8s var(--ease-magnetic);
}

.lightbox.active img {
  transform: scale(1);
}

.lightbox-close {
  position: absolute;
  top: 3rem;
  inset-inline-end: 3rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--col-cream);
  width: 65px;
  height: 65px;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.4s var(--ease-magnetic);
}

.lightbox-close:hover {
  background: var(--col-gold);
  color: var(--col-dark);
  transform: rotate(90deg) scale(1.1);
}

/* Responsive Overrides */
@media (max-width: 1200px) {
  .gallery-masonry {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 900px) {
  .gallery-masonry {
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 200px;
    gap: 1.2rem;
  }

  .gallery-item {
    border-radius: var(--radius);
  }
}

@media (max-width: 600px) {
  .gallery-masonry {
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 160px;
    gap: 0.75rem;
  }

  .gallery-item,
  .gallery-item:nth-child(n) {
    grid-column: span 1;
    grid-row: span 1;
  }

  /* First item spans 2 cols on mobile for visual interest */
  .gallery-item:first-child {
    grid-column: span 2;
    grid-row: span 1;
  }

  .gallery-tabs {
    width: 90vw;
    gap: 0.5rem;
    padding: 0.8rem;
    /* Remove backdrop-filter on mobile — GPU expensive */
    backdrop-filter: none;
    background: rgba(17, 11, 5, 0.85);
    margin-bottom: 2rem;
  }

  .gallery-tab {
    padding: 0.6rem 1.2rem;
    font-size: 0.75rem;
  }
}