/* ==========================================================================
   Project Gallery – gallery.css
   Hero-first grid  ·  Responsive  ·  Accessible  ·  Lightbox
   ========================================================================== */

/* ── Custom properties ─────────────────────────────────────────────────── */
.pg-gallery {
  --pg-cols: 4;          /* overridden inline by PHP */
  --pg-gap: 6px;
  --pg-radius: 4px;
  --pg-hero-span: 2;     /* hero spans this many columns + rows */
  --pg-overlay-bg: rgba(0, 0, 0, 0.42);
  --pg-accent: #e07b39;  /* warm brand accent */
  --pg-lb-bg: #0d0d0d;
  --pg-lb-text: #f0f0f0;
  --pg-duration: 220ms;
  --pg-ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ── Grid container ────────────────────────────────────────────────────── */
.pg-gallery {
  display: grid;
  grid-template-columns: repeat(var(--pg-cols), 1fr);
  grid-auto-rows: 200px;  /* base row height; hero spans 2 */
  gap: var(--pg-gap);
  margin: 2rem 0;
  list-style: none;
  padding: 0;
}

/* ── Grid items ────────────────────────────────────────────────────────── */
.pg-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--pg-radius);
  background: #1a1a1a;
  margin: 0;
}

/* Hero: spans 2 cols × 2 rows, always top-left */
.pg-item--hero {
  grid-column: span var(--pg-hero-span);
  grid-row: span var(--pg-hero-span);
}

/* ── Images ────────────────────────────────────────────────────────────── */
.pg-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--pg-duration) var(--pg-ease);
  will-change: transform;
}

/* ── Trigger / link ────────────────────────────────────────────────────── */
.pg-trigger {
  display: block;
  width: 100%;
  height: 100%;
  position: relative;
  text-decoration: none;
  outline-offset: 3px;
}

.pg-trigger:focus-visible {
  outline: 3px solid var(--pg-accent);
  outline-offset: 3px;
  border-radius: var(--pg-radius);
  z-index: 1;
}

/* ── Hover overlay ─────────────────────────────────────────────────────── */
.pg-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--pg-overlay-bg);
  color: #fff;
  opacity: 0;
  transition: opacity var(--pg-duration) var(--pg-ease);
  border-radius: var(--pg-radius);
}

.pg-trigger:hover .pg-overlay,
.pg-trigger:focus-visible .pg-overlay {
  opacity: 1;
}

.pg-trigger:hover img {
  transform: scale(1.04);
}

/* ── Caption (visually hidden – available to screen readers & schema) ── */
.pg-caption {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* ==========================================================================
   Lightbox
   ========================================================================== */
.pg-lightbox {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pg-lightbox[hidden] {
  display: none;
}

.pg-lightbox.pg-lb--open {
  display: flex;
}

/* Backdrop */
.pg-lb-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 10, 0.94);
  cursor: zoom-out;
}

/* Shell */
.pg-lb-shell {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 1400px;
  padding: 0 16px;
  box-sizing: border-box;
}

/* Stage */
.pg-lb-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 0;
  position: relative;
}

/* Main image */
.pg-lb-img {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 3px;
  opacity: 0;
  transform: scale(0.97);
  transition: opacity var(--pg-duration) var(--pg-ease),
              transform var(--pg-duration) var(--pg-ease);
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.7);
}

.pg-lb-img.pg-lb--loaded {
  opacity: 1;
  transform: scale(1);
}

/* Caption */
.pg-lb-caption {
  color: var(--pg-lb-text);
  font-size: 0.875rem;
  text-align: center;
  opacity: 0.75;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
  min-height: 1.25em;
  max-width: 640px;
  padding: 0 8px;
}

/* Counter */
.pg-lb-counter {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.8rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.05em;
  pointer-events: none;
}

/* Buttons shared */
.pg-lb-close,
.pg-lb-prev,
.pg-lb-next {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  min-width: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--pg-duration) var(--pg-ease),
              transform var(--pg-duration) var(--pg-ease);
  flex-shrink: 0;
  z-index: 2;
}

.pg-lb-close:hover,
.pg-lb-prev:hover,
.pg-lb-next:hover {
  background: rgba(255, 255, 255, 0.22);
}

.pg-lb-close:focus-visible,
.pg-lb-prev:focus-visible,
.pg-lb-next:focus-visible {
  outline: 3px solid var(--pg-accent);
  outline-offset: 3px;
}

.pg-lb-close:active,
.pg-lb-prev:active,
.pg-lb-next:active {
  transform: scale(0.93);
}

/* Close floats to top-right */
.pg-lb-close {
  position: absolute;
  top: -56px;
  right: 0;
  z-index: 3;
}

/* Loader */
.pg-lb-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--pg-accent);
  border-radius: 50%;
  animation: pg-spin 0.7s linear infinite;
  display: none;
}

.pg-lb-stage.pg-lb--loading .pg-lb-loader {
  display: block;
}

@keyframes pg-spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

/* Large desktop: keep as-is */
@media (min-width: 1200px) {
  .pg-gallery {
    grid-auto-rows: 220px;
  }
}

/* Medium screens – 3 cols */
@media (max-width: 1024px) {
  .pg-gallery {
    --pg-cols: 3;
    grid-auto-rows: 185px;
  }

  .pg-item--hero {
    grid-column: span 2;
    grid-row: span 2;
  }
}

/* Tablet – 2 cols */
@media (max-width: 768px) {
  .pg-gallery {
    --pg-cols: 2;
    --pg-gap: 4px;
    grid-auto-rows: 160px;
  }

  .pg-item--hero {
    grid-column: span 1;
    grid-row: span 2;
  }

  .pg-lb-prev,
  .pg-lb-next {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }
}

/* Mobile – 2 cols, taller rows */
@media (max-width: 480px) {
  .pg-gallery {
    --pg-cols: 2;
    --pg-gap: 3px;
    grid-auto-rows: 130px;
  }

  .pg-item--hero {
    grid-column: 1 / -1;   /* full width on mobile */
    grid-row: span 1;
    height: 240px;
  }

  .pg-lb-shell {
    padding: 0 8px;
    gap: 8px;
  }

  .pg-lb-img {
    max-height: 70vh;
  }
}

/* ── Reduced motion ────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .pg-item img,
  .pg-overlay,
  .pg-lb-img {
    transition: none;
  }

  .pg-lb-loader {
    animation: none;
    border-top-color: var(--pg-accent);
  }
}
