/* =====================================================================
   Image Gallery + Lightbox Plugin — imagegallery.css
   Responsive 3×3 (desktop) / 3-col (mobile) or 6×6 / 3-col layout
   ===================================================================== */

/* ── Custom Properties ─────────────────────────────────────────────── */
:root {
  --iglb-radius:        6px;
  --iglb-thumb-aspect:  1 / 1;       /* square thumbnails */
  --iglb-transition:    0.22s ease;
  --iglb-overlay-bg:    rgba(10, 10, 15, 0.96);
  --iglb-caption-bg:    rgba(0, 0, 0, 0.55);
  --iglb-caption-color: #f0f0f0;
  --iglb-btn-color:     #ffffff;
  --iglb-btn-hover:     rgba(255,255,255,0.15);
  --iglb-focus-ring:    0 0 0 3px rgba(80, 160, 255, 0.7);
}

/* ── Gallery Wrapper ───────────────────────────────────────────────── */
.iglb-gallery-wrap {
  width: 100%;
  margin-block: 1.5rem;
}

.iglb-gallery-title {
  margin-bottom: 0.75rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: inherit;
}

/* ── Grid ──────────────────────────────────────────────────────────── */
.iglb-grid {
  display: grid;
  /* Default: 3 columns — overridden inline by JS */
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;                         /* overridden by JS from data-gap */
}

/* 6-column layout variant applied by JS */
.iglb-grid[data-cols="6"] {
  grid-template-columns: repeat(6, 1fr);
}
.iglb-grid[data-cols="3"] {
  grid-template-columns: repeat(3, 1fr);
}

/* ── Grid Item ─────────────────────────────────────────────────────── */
.iglb-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--iglb-radius);
  background: #1a1a1a;
  aspect-ratio: var(--iglb-thumb-aspect);
  cursor: pointer;
}

.iglb-item:focus-within {
  box-shadow: var(--iglb-focus-ring);
  outline: none;
}

/* ── Thumbnail Link ────────────────────────────────────────────────── */
.iglb-link {
  display: block;
  width: 100%;
  height: 100%;
  text-decoration: none;
  color: inherit;
  position: relative;
}

.iglb-link:focus {
  outline: none;
}

/* ── Thumbnail Image ───────────────────────────────────────────────── */
.iglb-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  transition: transform var(--iglb-transition), filter var(--iglb-transition);
  will-change: transform;
}

/* lazy-load blur-up */
/* Only show blur-up effect while the real image is loading.
   Once JS removes data-src (or adds .loaded), the effect is gone. */
.iglb-thumb[data-src]:not(.loaded) {
    filter: blur(6px);
    transform: scale(1.04);
    transition: filter 0.4s ease, transform 0.4s ease;
}
.iglb-thumb.loaded {
  filter: none;
  transform: scale(1);
}

.iglb-item:hover .iglb-thumb,
.iglb-item:focus-within .iglb-thumb {
  transform: scale(1.06);
}

/* ── Caption Overlay ───────────────────────────────────────────────── */
.iglb-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.35rem 0.6rem;
  background: var(--iglb-caption-bg);
  color: var(--iglb-caption-color);
  font-size: 0.75rem;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transform: translateY(100%);
  transition: transform var(--iglb-transition);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-bottom-left-radius: var(--iglb-radius);
  border-bottom-right-radius: var(--iglb-radius);
}

.iglb-item:hover .iglb-caption,
.iglb-item:focus-within .iglb-caption {
  transform: translateY(0);
}

/* Zoom-in icon overlay */
.iglb-item::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3Cline x1='11' y1='8' x2='11' y2='14'/%3E%3Cline x1='8' y1='11' x2='14' y2='11'/%3E%3C/svg%3E")
    no-repeat center center / 28px;
  opacity: 0;
  transition: opacity var(--iglb-transition);
  background-color: rgba(0,0,0,0.25);
  border-radius: var(--iglb-radius);
  pointer-events: none;
}

.iglb-item:hover::after {
  opacity: 1;
}

/* ═══════════════════════════════════════════════════════════════════
   LIGHTBOX
   ══════════════════════════════════════════════════════════════════ */

/* Overlay */
#iglb-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: var(--iglb-overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#iglb-overlay.iglb-open {
  opacity: 1;
  pointer-events: auto;
}

/* ── Inner Container ─────────────────────────────────────────────── */
#iglb-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: min(92vw, 1200px);
  max-height: 90vh;
  width: auto;
}

/* ── Main Image Wrapper ──────────────────────────────────────────── */
#iglb-img-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  min-width: 60px;
}

#iglb-img {
  display: block;
  max-width: min(88vw, 1100px);
  max-height: calc(90vh - 80px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--iglb-radius);
  box-shadow: 0 8px 60px rgba(0,0,0,0.7);
  user-select: none;
  -webkit-user-drag: none;
  /* animation states */
  transition: opacity 0.2s ease, transform 0.2s ease;
}

/* -- Fade animation */
#iglb-overlay[data-animation="fade"] #iglb-img.iglb-animating {
  opacity: 0;
}

/* -- Slide animation */
#iglb-overlay[data-animation="slide"] #iglb-img.iglb-slide-out-left {
  opacity: 0; transform: translateX(-60px);
}
#iglb-overlay[data-animation="slide"] #iglb-img.iglb-slide-out-right {
  opacity: 0; transform: translateX(60px);
}
#iglb-overlay[data-animation="slide"] #iglb-img.iglb-slide-in-left {
  opacity: 0; transform: translateX(60px);
}
#iglb-overlay[data-animation="slide"] #iglb-img.iglb-slide-in-right {
  opacity: 0; transform: translateX(-60px);
}

/* -- Zoom animation */
#iglb-overlay[data-animation="zoom"] #iglb-img.iglb-animating {
  opacity: 0; transform: scale(0.88);
}

/* ── Spinner ─────────────────────────────────────────────────────── */
#iglb-spinner {
  position: absolute;
  width: 42px;
  height: 42px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: #fff;
  border-radius: 50%;
  animation: iglb-spin 0.7s linear infinite;
  display: none;
}

#iglb-spinner.iglb-loading {
  display: block;
}

@keyframes iglb-spin {
  to { transform: rotate(360deg); }
}

/* ── Caption bar ─────────────────────────────────────────────────── */
#iglb-caption-bar {
  width: 100%;
  padding: 0.5rem 3.5rem;
  text-align: center;
  color: var(--iglb-caption-color);
  font-size: 0.875rem;
  min-height: 2rem;
  line-height: 1.4;
}

/* ── Counter ─────────────────────────────────────────────────────── */
#iglb-counter {
  position: absolute;
  top: -2.4rem;
  left: 0;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.55);
  letter-spacing: 0.05em;
  white-space: nowrap;
}

/* ── Nav Buttons ─────────────────────────────────────────────────── */
.iglb-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: var(--iglb-btn-hover);
  border: 1px solid rgba(255,255,255,0.18);
  color: var(--iglb-btn-color);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s ease, transform 0.18s ease;
  font-size: 0;         /* hide text */
  z-index: 10;
}

.iglb-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.iglb-btn:hover,
.iglb-btn:focus-visible {
  background: rgba(255,255,255,0.22);
  outline: none;
  box-shadow: var(--iglb-focus-ring);
}

.iglb-btn:active {
  transform: translateY(-50%) scale(0.93);
}

#iglb-prev { left:  -70px; }
#iglb-next { right: -70px; }

/* ── Close Button ────────────────────────────────────────────────── */
#iglb-close {
  position: absolute;
  top: -3.2rem;
  right: 0;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.75);
  cursor: pointer;
  padding: 6px;
  line-height: 1;
  font-size: 0;
  border-radius: 4px;
  transition: color 0.18s, background 0.18s;
}

#iglb-close svg {
  width: 26px;
  height: 26px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

#iglb-close:hover,
#iglb-close:focus-visible {
  color: #fff;
  background: var(--iglb-btn-hover);
  outline: none;
  box-shadow: var(--iglb-focus-ring);
}

/* ── Touch Swipe Hint ────────────────────────────────────────────── */
#iglb-swipe-hint {
  display: none;
  position: absolute;
  bottom: 0.8rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.72rem;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.04em;
  pointer-events: none;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════════ */

/* Tablet / mobile breakpoint ≤ 768px */
@media (max-width: 768px) {
  /* JS overrides grid columns; CSS fallback for mobile */
  .iglb-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
  }

  /* Nav buttons: place inside the overlay on mobile */
  #iglb-prev { left:  8px; }
  #iglb-next { right: 8px; }

  .iglb-btn {
    width: 40px;
    height: 40px;
    top: auto;
    bottom: 3.8rem;
    transform: none;
    position: fixed;
  }

  #iglb-prev { left: 12px; }
  #iglb-next { right: 12px; }

  #iglb-img {
    max-width: 96vw;
    max-height: calc(80vh - 80px);
  }

  #iglb-swipe-hint { display: block; }

  #iglb-counter {
    top: auto;
    bottom: 2.2rem;
    left: 50%;
    transform: translateX(-50%);
  }

  #iglb-close {
    top: 1rem;
    right: 1rem;
    position: fixed;
  }
}

/* Very small screens */
@media (max-width: 420px) {
  .iglb-grid {
    gap: 4px;
  }
}

/* ── Reduced motion ──────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .iglb-thumb,
  #iglb-overlay,
  #iglb-img,
  .iglb-caption,
  .iglb-btn,
  #iglb-overlay::after {
    transition: none !important;
    animation: none !important;
  }
}
