:root {
  --gallery-cream: #f9f3eb;
  --gallery-card: rgba(255,255,255,0.72);
  --gallery-stroke: rgba(31,27,22,0.08);
}

body.gallery-page {
  background: linear-gradient(180deg, #f6efe7 0%, #f9f3eb 36%, #f5efe6 100%);
  color: var(--ink);
}

body.gallery-page::before,
body.gallery-page::after {
  content: "";
  position: fixed;
  inset: -15% -15% auto -15%;
  height: 65vh;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(circle at 20% 20%, rgba(201,89,60,0.12), transparent 28%),
              radial-gradient(circle at 80% 25%, rgba(45,74,62,0.10), transparent 25%),
              radial-gradient(circle at 50% 80%, rgba(201,169,97,0.10), transparent 28%);
  filter: blur(60px);
  animation: galleryGlow 18s ease-in-out infinite alternate;
}

body.gallery-page::after {
  inset: auto -20% -15% -20%;
  height: 48vh;
  background: radial-gradient(circle at 30% 15%, rgba(127,90,240,0.08), transparent 30%),
              radial-gradient(circle at 70% 60%, rgba(45,74,62,0.08), transparent 28%);
  animation-duration: 22s;
}

@keyframes galleryGlow {
  0% { transform: translate3d(0, 0, 0) scale(1); opacity: 0.8; }
  50% { transform: translate3d(1.5%, -2%, 0) scale(1.08); opacity: 1; }
  100% { transform: translate3d(-1.5%, 1%, 0) scale(1.04); opacity: 0.88; }
}

.gallery-shell {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 150px 32px 90px;
}

.gallery-hero {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 56px;
  align-items: center;
  margin-bottom: 42px;
}

.gallery-hero-copy h1 {
  font-size: clamp(44px, 6vw, 88px);
  line-height: 0.94;
  letter-spacing: -0.05em;
  margin: 18px 0 20px;
}

.gallery-hero-copy p {
  max-width: 580px;
  font-size: 1.08rem;
  line-height: 1.75;
  color: var(--ink-soft);
}

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 28px;
}

.gallery-hero-visual {
  position: relative;
  min-height: 540px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.gallery-visual-stack {
  position: relative;
  overflow: hidden;
  border-radius: 28px;
  box-shadow: 0 30px 80px rgba(31,27,22,0.14);
  border: 1px solid rgba(31,27,22,0.06);
  background: rgba(255,255,255,0.4);
}

.gallery-visual-stack img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scale(1.04);
  transition: transform 0.7s var(--ease);
}

.gallery-visual-stack:hover img {
  transform: scale(1.1);
}

.gallery-visual-stack.tall {
  min-height: 520px;
}

.gallery-visual-stack.short {
  min-height: 250px;
  margin-top: 36px;
}

.gallery-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 20px 0 32px;
}

.filter-btn {
  background: rgba(255,255,255,0.52);
  color: var(--ink);
  border: 1px solid rgba(31,27,22,0.08);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease), background 0.25s ease, border-color 0.25s ease;
}

.filter-btn:hover,
.filter-btn.active {
  background: linear-gradient(135deg, rgba(201,89,60,0.1), rgba(201,169,97,0.12));
  border-color: rgba(201,89,60,0.2);
  box-shadow: 0 10px 24px rgba(31,27,22,0.06);
  transform: translateY(-2px);
}

.gallery-grid {
  columns: 3 320px;
  column-gap: 22px;
}

.gallery-card {
  position: relative;
  display: inline-block;
  width: 100%;
  margin: 0 0 22px;
  break-inside: avoid;
  border-radius: 26px;
  overflow: hidden;
  background: rgba(255,255,255,0.4);
  border: 1px solid rgba(31,27,22,0.06);
  box-shadow: 0 18px 45px rgba(31,27,22,0.08);
  transform: translateY(30px);
  opacity: 0;
  transition: transform 0.65s var(--ease), opacity 0.65s var(--ease), box-shadow 0.4s var(--ease);
}

.gallery-card.visible {
  opacity: 1;
  transform: translateY(0);
}

.gallery-card:hover {
  box-shadow: 0 22px 50px rgba(31,27,22,0.12);
}

.gallery-card img {
  width: 100%;
  height: auto;
  display: block;
  transition: transform 0.7s var(--ease), filter 0.5s var(--ease);
}

.gallery-card:hover img {
  transform: scale(1.08);
  filter: saturate(1.08) contrast(1.02);
}

.gallery-card-overlay {
  position: absolute;
  inset: auto 0 0 0;
  padding: 22px 20px 18px;
  background: linear-gradient(180deg, rgba(11,15,17,0.04), rgba(11,15,17,0.78));
  color: #fff;
}

.gallery-card-overlay span {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.9;
}

.gallery-card-overlay h3 {
  font-size: clamp(1.2rem, 2vw, 1.75rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.gallery-card.hidden {
  display: none;
}

.lightbox {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(17, 18, 20, 0.8);
  backdrop-filter: blur(12px);
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  z-index: 2000;
}

.lightbox.open {
  opacity: 1;
  visibility: visible;
}

.lightbox-content {
  position: relative;
  width: min(100%, 980px);
  background: rgba(255,255,255,0.94);
  border-radius: 26px;
  overflow: hidden;
  border: 1px solid rgba(31,27,22,0.08);
  box-shadow: 0 30px 80px rgba(0,0,0,0.28);
  transform: scale(0.96);
  transition: transform 0.25s var(--ease);
}

.lightbox.open .lightbox-content {
  transform: scale(1);
}

.lightbox-content img {
  width: 100%;
  max-height: 78vh;
  display: block;
  object-fit: cover;
}

.lightbox-caption {
  padding: 18px 22px 20px;
}

.lightbox-caption h3 {
  font-size: clamp(1.3rem, 3vw, 2.2rem);
  margin-bottom: 4px;
}

.lightbox-caption p {
  color: var(--ink-soft);
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(31,27,22,0.08);
  background: rgba(255,255,255,0.88);
  color: var(--ink);
  font-size: 22px;
  cursor: pointer;
}

@media (max-width: 980px) {
  .gallery-hero {
    grid-template-columns: 1fr;
    gap: 28px;
  }

  .gallery-hero-visual {
    min-height: 360px;
  }

  .gallery-shell {
    padding-top: 120px;
  }
}

@media (max-width: 640px) {
  .gallery-shell {
    padding-left: 18px;
    padding-right: 18px;
  }

  .gallery-hero-copy h1 {
    font-size: clamp(2.5rem, 12vw, 4.3rem);
  }

  .gallery-grid {
    columns: 1;
    column-gap: 0;
  }

  .gallery-card {
    margin-bottom: 18px;
  }

  .gallery-visual-stack.short {
    margin-top: 0;
  }

  .cta-row {
    flex-direction: column;
    align-items: stretch;
  }

  .cta-row .btn {
    justify-content: center;
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gallery-page::before,
  .gallery-page::after,
  .gallery-card,
  .gallery-card img,
  .filter-btn,
  .lightbox,
  .lightbox-content {
    animation: none !important;
    transition: none !important;
  }
}

/* Additional styles for the new performant masonry grid used by gallery.js */
/* Ensure legacy column-based gallery-grid does not interfere */
.gallery-grid { columns: unset !important; column-gap: 0 !important; }

.masonry { display: grid !important; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; align-items: start; }
/* Make each item participate in layout explicitly */
.masonry-item { display: block; border-radius: 18px; overflow: hidden; background: linear-gradient(180deg, var(--cream-soft), #fff); border: 1px solid var(--line); box-shadow: 0 12px 34px rgba(31,27,22,0.04); transform-origin: center; opacity: 0; transform: translateY(18px) scale(.995); transition: transform 520ms var(--ease), opacity 420ms var(--ease), box-shadow 420ms var(--ease); }
.masonry-item.in-view { opacity: 1; transform: translateY(0) scale(1); }
.masonry-item > .masonry-media, .masonry-item > .masonry-caption { display: block; }

.masonry-media { position: relative; width: 100%; height: 0; padding-bottom: 100%; background: #f7f5f1; }
.masonry-media img, .masonry-media video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
/* hide captions on thumbnails so each image is presented as a clean square */
.masonry-caption { display: none; }
.masonry-caption .tag { display:none; }
.masonry-caption .title { display:none; }
.masonry-item.video .play-icon { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); width: 64px; height: 64px; border-radius: 50%; background: rgba(31,27,22,0.6); display:flex; align-items:center; justify-content:center; opacity: 0; transition: opacity 220ms ease; }
.masonry-item .play-icon svg { width: 26px; height: 26px; fill: #fff; margin-left: 4px; }
.masonry-item:hover .play-icon { opacity: 1; }

/* Prevent overlapping by ensuring margins and flow are explicit */
.masonry-item { margin: 0; }
.masonry { position: relative; }

.gallery-loader { text-align: center; padding: 26px 0; color: var(--ink-soft); }

/* Controls and tabs */
.controls-row { display:flex; justify-content:space-between; align-items:center; gap:16px; margin-bottom:12px; }
.controls-row .filters { display:flex; gap:12px; flex-wrap:wrap; }
.view-tabs { display:flex; gap:8px; }
.tab-btn { padding:8px 14px; border-radius:999px; border:1px solid rgba(31,27,22,0.06); background: rgba(255,255,255,0.6); font-weight:700; cursor:pointer; }
.tab-btn.active { background: linear-gradient(135deg, rgba(201,89,60,0.08), rgba(201,169,97,0.1)); border-color: rgba(201,89,60,0.16); }

/* Pager */
.pager { display:flex; gap:12px; justify-content:center; align-items:center; margin-top:18px; }
.page-info { font-weight:600; color:var(--ink-soft); }

/* Responsive breakpoints: mobile -> large screens */
@media (max-width: 479px) {
  .controls-row { flex-direction:column; align-items:flex-start; }
  .masonry { grid-template-columns: 1fr; gap: 12px; }
  .masonry-media { padding-bottom: 75%; }
  .gallery-shell { padding: 90px 16px 60px; }
  .gallery-hero { grid-template-columns: 1fr; gap: 18px; }
  .gallery-visual-stack.tall { min-height: 260px; }
  .gallery-visual-stack.short { min-height: 140px; margin-top: 18px; }
  .masonry-caption .title { font-size: 15px; }
}

@media (min-width: 480px) and (max-width: 699px) {
  .masonry { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .masonry-media { padding-bottom: 72%; }
  .gallery-shell { padding: 100px 20px 70px; }
}

@media (min-width: 700px) and (max-width: 999px) {
  .masonry { grid-template-columns: repeat(3, 1fr); gap: 18px; }
  .masonry-media { padding-bottom: 66%; }
  .gallery-shell { padding: 120px 28px 80px; }
}

@media (min-width: 1000px) and (max-width: 1199px) {
  .masonry { grid-template-columns: repeat(4, 1fr); gap: 20px; }
  .gallery-shell { padding: 140px 32px 90px; }
}

@media (min-width: 1200px) and (max-width: 1599px) {
  .masonry { grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 24px; }
  .gallery-shell { padding: 150px 36px 100px; }
}

@media (min-width: 1600px) {
  .masonry { grid-template-columns: repeat(6, minmax(240px, 1fr)); gap: 28px; }
  .gallery-shell { padding: 180px 48px 120px; }
  .gallery-hero-visual { min-height: 640px; }
}

/* Reduce hover effects for touch-only devices */
@media (hover: none) and (pointer: coarse) {
  .masonry-item { transition: none; }
  .masonry-item:hover { transform: none; box-shadow: none; }
  .masonry-item.video .play-icon { opacity: 1; }
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .masonry-item { transition: none !important; transform: none !important; }
  .masonry-media img, .masonry-media video { transition: none !important; }
}

