/* =========================================================
   NCMI - Project gallery (3D carousel + full-size viewer)
   Uses variables from styles.css (--primary, --text-muted, --text-faint)
   ========================================================= */

.gallery-section {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 70px 20px 60px;
  overflow: hidden;
}

.gallery-container {
  max-width: 1300px;
  margin: 0 auto;
}

.gallery-container h2 {
  margin: 0 0 12px;
  text-align: center;
  color: var(--primary);
  font-family: "Montserrat", sans-serif;
  font-size: 2rem;
  font-weight: 800;
}

.gallery-intro {
  max-width: 800px;
  margin: 0 auto 35px;
  color: var(--text-muted);
  line-height: 1.6;
  text-align: center;
}

.gallery-hint {
  margin-top: 20px;
  color: var(--text-faint);
  font-size: 0.9rem;
  text-align: center;
}

.gallery-error {
  width: 100%;
  padding: 40px 20px;
  color: var(--text-faint);
  text-align: center;
}

/* =========================================================
   CAROUSEL
   Each item's position is set by a class:
   --center, --left, --right or --hidden.
   Item size and side offset are variables so the
   mobile breakpoints only change numbers.
   ========================================================= */

.gallery-carousel {
  --item-w: 420px;
  --item-h: 290px;
  --side-x: 390px;
  --side-z: -120px;
  --side-rotate: 18deg;
  --side-scale: 0.78;

  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 430px;
  perspective: 1400px;
  touch-action: pan-y;
  user-select: none;
}

.gallery-track {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}

.gallery-item {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--item-w);
  height: var(--item-h);
  padding: 0;
  border: 0;
  border-radius: 16px;
  overflow: hidden;
  background: #111;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  opacity: 0;
  filter: brightness(0.45);
  transform: translate(-50%, -50%) scale(0.65);
  backface-visibility: hidden;
  will-change: transform;
  transition:
    transform 0.65s cubic-bezier(0.22, 0.61, 0.36, 1),
    opacity 0.65s ease,
    filter 0.65s ease,
    box-shadow 0.65s ease;
}

.gallery-item img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  transition: transform 0.65s ease;
}

.gallery-item::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.02) 35%, rgba(0, 0, 0, 0.4) 100%);
}

.gallery-item--center {
  z-index: 30;
  opacity: 1;
  filter: brightness(1);
  cursor: zoom-in;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%) translateZ(180px) scale(1);
}

.gallery-item--center:hover img {
  transform: scale(1.04);
}

.gallery-item--center:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 4px;
}

.gallery-item--left,
.gallery-item--right {
  z-index: 20;
  opacity: 0.82;
  filter: brightness(0.68);
}

.gallery-item--left {
  transform: translate(-50%, -50%) translateX(calc(var(--side-x) * -1))
    translateZ(var(--side-z)) rotateY(var(--side-rotate)) scale(var(--side-scale));
}

.gallery-item--right {
  transform: translate(-50%, -50%) translateX(var(--side-x))
    translateZ(var(--side-z)) rotateY(calc(var(--side-rotate) * -1)) scale(var(--side-scale));
}

.gallery-item--hidden {
  z-index: 1;
  opacity: 0;
  filter: brightness(0.3);
  pointer-events: none;
  transform: translate(-50%, -50%) translateZ(-300px) scale(0.5);
}

/* =========================================================
   ROUND ARROW BUTTONS (carousel + viewer)
   ========================================================= */

.gallery-nav,
.viewer-btn {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-family: Arial, sans-serif;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.gallery-nav,
.viewer-prev,
.viewer-next {
  top: 50%;
  transform: translateY(-50%);
}

.gallery-nav {
  z-index: 100;
}

.gallery-nav:hover,
.viewer-prev:hover,
.viewer-next:hover {
  background: rgba(0, 0, 0, 0.9);
  transform: translateY(-50%) scale(1.08);
}

.gallery-nav:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
}

.viewer-btn:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.gallery-prev {
  left: 20px;
}

.gallery-next {
  right: 20px;
}

/* =========================================================
   FULL-SIZE VIEWER
   ========================================================= */

.gallery-viewer {
  position: fixed;
  inset: 50px;
  z-index: 99999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 30px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.94);
  overflow: hidden;
}

.gallery-viewer.is-open {
  display: flex;
}

/* Dims the page around the viewer; clicking it closes the viewer */
.gallery-viewer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 99998;
  display: none;
  background: rgba(0, 0, 0, 0.6);
}

.gallery-viewer-backdrop.is-open {
  display: block;
}

.gallery-viewer img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.65);
  user-select: none;
}

.viewer-btn {
  z-index: 2;
  width: 52px;
  height: 52px;
}

.viewer-btn:hover {
  background: rgba(0, 0, 0, 0.95);
}

.viewer-close {
  top: 12px;
  right: 16px;
  width: 44px;
  height: 44px;
  font-size: 32px;
}

.viewer-close:hover {
  transform: scale(1.08);
}

.viewer-prev {
  left: 15px;
}

.viewer-next {
  right: 15px;
}

.viewer-title {
  position: absolute;
  bottom: 12px;
  left: 50%;
  z-index: 2;
  max-width: calc(100% - 160px);
  padding: 8px 18px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-family: "Montserrat", sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  pointer-events: none;
  transform: translateX(-50%);
}

.viewer-title:empty {
  display: none;
}

body.gallery-open {
  overflow: hidden;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 900px) {
  .gallery-carousel {
    --item-w: 360px;
    --item-h: 250px;
    --side-x: 270px;
    --side-z: -100px;
    --side-rotate: 15deg;
    --side-scale: 0.72;
    height: 360px;
  }

  .gallery-viewer {
    inset: 30px;
    padding: 20px;
  }
}

@media (max-width: 600px) {
  .gallery-section {
    padding-left: 10px;
    padding-right: 10px;
  }

  .gallery-carousel {
    --item-w: 280px;
    --item-h: 195px;
    --side-x: 190px;
    --side-z: -80px;
    --side-rotate: 12deg;
    --side-scale: 0.65;
    height: 300px;
  }

  .gallery-nav {
    width: 46px;
    height: 46px;
    font-size: 24px;
  }

  .gallery-prev {
    left: 5px;
  }

  .gallery-next {
    right: 5px;
  }

  .gallery-viewer {
    inset: 10px;
    padding: 15px;
  }

  .viewer-btn {
    width: 44px;
    height: 44px;
    font-size: 24px;
  }

  .viewer-close {
    top: 8px;
    right: 8px;
    width: 40px;
    height: 40px;
    font-size: 28px;
  }

  .viewer-prev {
    left: 8px;
  }

  .viewer-next {
    right: 8px;
  }

  .viewer-title {
    bottom: 8px;
    max-width: calc(100% - 120px);
    font-size: 0.85rem;
  }
}
