:root {
  --ns-gallery-cols: 3;
  --ns-gallery-gap: 0.85rem;
  --ns-gallery-ratio: 4/3;
  --ns-gallery-fit: cover;
}

body.wp-theme-candy .ns-gallery {
  margin: clamp(1.1rem, 2.2vw, 1.6rem) 0;
}

/* Reset the global "button refinement" inside galleries (prevents double-dot shadows). */
body.wp-theme-candy .page__content .ns-gallery button,
body.wp-theme-candy .page__content .ns-gallery button:hover,
body.wp-theme-candy .page__content .ns-gallery button:focus-visible {
  box-shadow: none;
  transform: none;
  letter-spacing: normal;
  font-weight: 400;
}

/* Tiles grid */
body.wp-theme-candy .ns-gallery__grid {
  display: grid;
  grid-template-columns: repeat(var(--ns-gallery-cols), minmax(0, 1fr));
  gap: var(--ns-gallery-gap);
  align-items: stretch;
}

body.wp-theme-candy .ns-gallery--mosaic .ns-gallery__grid {
  grid-auto-flow: dense;
  grid-auto-rows: clamp(130px, 18vw, 220px);
}

body.wp-theme-candy .ns-gallery--mosaic .ns-gallery__tile:nth-child(1) {
  grid-column: span 2;
  grid-row: span 2;
}

body.wp-theme-candy .ns-gallery--mosaic .ns-gallery__tile:nth-child(2) {
  grid-row: span 2;
}

/* In fit-auto mode, portrait tiles get extra height in mosaic layouts. */
body.wp-theme-candy .ns-gallery--mosaic.ns-gallery--fit-auto .ns-gallery__tile[data-ns-orient="portrait"] {
  grid-row: span 2;
}

body.wp-theme-candy .ns-gallery--mosaic .ns-gallery__tile:nth-child(6n + 4) {
  grid-column: span 2;
}

/* In mosaic mode, tiles fill the grid cell height (prevents "empty bottom" areas). */
body.wp-theme-candy .ns-gallery--mosaic .ns-gallery__tile {
  height: 100%;
  display: flex;
  flex-direction: column;
}

body.wp-theme-candy .ns-gallery--mosaic .ns-gallery__tile-media {
  aspect-ratio: auto;
  flex: 1 1 auto;
  height: 100%;
}

body.wp-theme-candy .ns-gallery--mosaic .ns-gallery__img {
  height: 100%;
}

body.wp-theme-candy .ns-gallery__tile {
  display: block;
  text-decoration: none;
  border-radius: 1rem;
  overflow: hidden;
  border: 1px solid rgba(4, 39, 23, 0.18);
  background: rgba(255, 255, 255, 0.45);
  box-shadow: 0 10px 22px rgba(3, 25, 14, 0.14);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

body.wp-theme-candy .ns-gallery__tile:hover,
body.wp-theme-candy .ns-gallery__tile:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 14px 26px rgba(3, 25, 14, 0.18);
}

body.wp-theme-candy .ns-gallery__tile-media {
  display: block;
  width: 100%;
  aspect-ratio: var(--ns-gallery-ratio);
  background: rgba(4, 39, 23, 0.06);
}

body.wp-theme-candy .ns-gallery__img {
  width: 100%;
  height: 100%;
  object-fit: var(--ns-gallery-fit);
  display: block;
}

/* Fit-Auto: show portrait images fully without affecting landscape framing. */
body.wp-theme-candy .ns-gallery--fit-auto .ns-gallery__slide[data-ns-orient="portrait"] .ns-gallery__img,
body.wp-theme-candy .ns-gallery--fit-auto .ns-gallery__tile[data-ns-orient="portrait"] .ns-gallery__img {
  object-fit: contain;
  background: rgba(255, 255, 255, 0.18);
}

body.wp-theme-candy .ns-gallery__tile-caption {
  display: block;
  padding: 0.65rem 0.85rem 0.75rem;
  font-size: 0.98rem;
  line-height: 1.35;
  color: rgba(4, 39, 23, 0.92);
}

/* Slider */
body.wp-theme-candy .ns-gallery__slider {
  position: relative;
}

body.wp-theme-candy .ns-gallery__viewport {
  border-radius: 1.25rem;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid rgba(4, 39, 23, 0.18);
  background: rgba(255, 255, 255, 0.3);
  box-shadow: 0 12px 28px rgba(3, 25, 14, 0.14);
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

body.wp-theme-candy .ns-gallery__viewport::-webkit-scrollbar {
  display: none;
}

body.wp-theme-candy .ns-gallery__track {
  display: flex;
  gap: 0;
}

body.wp-theme-candy .ns-gallery__slide {
  flex: 0 0 100%;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  padding: 0;
}

body.wp-theme-candy .ns-gallery__media {
  width: 100%;
  aspect-ratio: var(--ns-gallery-ratio);
  background: rgba(4, 39, 23, 0.06);
}

body.wp-theme-candy .ns-gallery__link {
  display: block;
  width: 100%;
  height: 100%;
  color: inherit;
}

body.wp-theme-candy .ns-gallery__caption {
  padding: 0.85rem 1rem 1.05rem;
  font-size: 1.02rem;
  line-height: 1.45;
  color: rgba(4, 39, 23, 0.92);
}

body.wp-theme-candy .ns-gallery__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border: 1px solid rgba(4, 39, 23, 0.18);
  background: rgba(255, 250, 234, 0.88);
  color: rgba(4, 39, 23, 0.92);
  box-shadow: 0 10px 20px rgba(3, 25, 14, 0.18);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

body.wp-theme-candy .ns-gallery__nav span {
  font-size: 30px;
  line-height: 1;
  margin-top: -2px;
}

body.wp-theme-candy .ns-gallery__nav--prev {
  left: 12px;
}

body.wp-theme-candy .ns-gallery__nav--next {
  right: 12px;
}

body.wp-theme-candy .ns-gallery__nav:focus-visible {
  outline: 2px solid var(--green-500);
  outline-offset: 2px;
}

body.wp-theme-candy .ns-gallery__dots {
  display: flex;
  gap: 0.55rem;
  justify-content: center;
  align-items: center;
  margin-top: 0.9rem;
  flex-wrap: nowrap;
  max-width: 100%;
  overflow-x: auto;
  padding: 0 0.25rem;
  scrollbar-width: none;
}

body.wp-theme-candy .ns-gallery__dots::-webkit-scrollbar {
  display: none;
}

body.wp-theme-candy .ns-gallery__dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  border: 0;
  background: rgba(4, 39, 23, 0.24);
  opacity: 0.6;
  cursor: pointer;
  padding: 0;
  box-shadow: none !important;
  transform: none;
  letter-spacing: normal;
  font-weight: 400;
  transition: opacity 0.18s ease, transform 0.18s ease, background 0.18s ease;
}

/* Some parent button styles add decorative pseudo elements; disable them for dots. */
body.wp-theme-candy .ns-gallery__dot::before,
body.wp-theme-candy .ns-gallery__dot::after {
  content: none !important;
}

body.wp-theme-candy .ns-gallery__dot:hover,
body.wp-theme-candy .ns-gallery__dot:focus-visible {
  box-shadow: none;
  transform: none;
  opacity: 0.85;
}

body.wp-theme-candy .ns-gallery__dot[aria-current="true"] {
  background: var(--green-500);
  opacity: 1;
  transform: scale(1.15);
}

body.wp-theme-candy .ns-gallery__dot[aria-current="true"]:hover,
body.wp-theme-candy .ns-gallery__dot[aria-current="true"]:focus-visible {
  transform: scale(1.15);
}

body.wp-theme-candy .ns-gallery__thumbs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.85rem;
}

body.wp-theme-candy .ns-gallery__thumb {
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid rgba(4, 39, 23, 0.18);
  background: rgba(255, 255, 255, 0.35);
  aspect-ratio: 1/1;
  cursor: pointer;
  padding: 0;
  box-shadow: none;
  transform: none;
  letter-spacing: normal;
  font-weight: 400;
}

body.wp-theme-candy .ns-gallery__thumb:hover,
body.wp-theme-candy .ns-gallery__thumb:focus-visible {
  box-shadow: none;
  transform: none;
}

body.wp-theme-candy .ns-gallery__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0.92;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

body.wp-theme-candy .ns-gallery__thumb:hover img,
body.wp-theme-candy .ns-gallery__thumb[aria-current="true"] img {
  opacity: 1;
  transform: scale(1.02);
}

/* Lightbox */
body.wp-theme-candy .ns-lightbox {
  position: fixed;
  inset: 0;
  z-index: 90000;
  background: rgba(3, 22, 13, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 3vw, 2rem);
}

body.wp-theme-candy.ns-lightbox-open .ns-lightbox {
  display: flex;
}

body.wp-theme-candy.ns-lightbox-open {
  overflow: hidden;
}

body.wp-theme-candy .ns-lightbox__panel {
  width: min(1100px, 100%);
  border-radius: 1.35rem;
  background: rgba(255, 250, 234, 0.95);
  border: 1px solid rgba(4, 39, 23, 0.22);
  box-shadow: 0 26px 60px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  position: relative;
}

body.wp-theme-candy .ns-lightbox__media {
  width: 100%;
  aspect-ratio: var(--ns-gallery-ratio);
  background: rgba(4, 39, 23, 0.06);
}

body.wp-theme-candy .ns-lightbox__media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: rgba(4, 39, 23, 0.02);
}

body.wp-theme-candy .ns-lightbox__meta {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem 1rem;
}

body.wp-theme-candy .ns-lightbox__caption {
  font-size: 1rem;
  line-height: 1.4;
  color: rgba(4, 39, 23, 0.92);
}

body.wp-theme-candy .ns-lightbox__counter {
  font-size: 0.95rem;
  color: rgba(4, 39, 23, 0.76);
  white-space: nowrap;
}

body.wp-theme-candy .ns-lightbox__btn {
  position: absolute;
  top: 12px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid rgba(4, 39, 23, 0.18);
  background: rgba(255, 250, 234, 0.9);
  color: rgba(4, 39, 23, 0.92);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

body.wp-theme-candy .ns-lightbox__btn:focus-visible {
  outline: 2px solid var(--green-500);
  outline-offset: 2px;
}

body.wp-theme-candy .ns-lightbox__btn--close {
  right: 12px;
}

body.wp-theme-candy .ns-lightbox__btn--prev,
body.wp-theme-candy .ns-lightbox__btn--next {
  top: 50%;
  transform: translateY(-50%);
}

body.wp-theme-candy .ns-lightbox__btn--prev {
  left: 12px;
}

body.wp-theme-candy .ns-lightbox__btn--next {
  right: 12px;
}

body.wp-theme-candy .ns-lightbox__btn span {
  font-size: 26px;
  line-height: 1;
  margin-top: -1px;
}

/* Responsive */
@media (max-width: 980px) {
  body.wp-theme-candy .ns-gallery__thumbs {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  body.wp-theme-candy .ns-gallery__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Avoid an awkward "empty slot" on the last row when there's an odd number of tiles on 2-col mobile. */
  body.wp-theme-candy .ns-gallery--tiles .ns-gallery__tile:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  /* Home primary mosaic: let the final tile close the layout edge-to-edge on mobile. */
  body.wp-theme-candy.home .ns-gallery--home-primary.ns-gallery--mosaic .ns-gallery__tile:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  /* Mobile mosaic: keep the vibe, but avoid tall spans that can create unfillable gaps. */
  body.wp-theme-candy .ns-gallery--mosaic .ns-gallery__grid {
    grid-auto-rows: clamp(120px, 34vw, 190px);
  }

  body.wp-theme-candy .ns-gallery--mosaic .ns-gallery__tile:nth-child(6n + 4) {
    grid-column: span 1;
  }

  /* Mosaic: prevent unfillable "holes" on 2-col mobile when fit-auto portraits span 2 rows. */
  body.wp-theme-candy .ns-gallery--mosaic.ns-gallery--fit-auto .ns-gallery__tile[data-ns-orient="portrait"] {
    grid-row: span 1;
  }

  /* On mobile, preview tiles may crop differently even in fit-auto mode (lightbox still shows full image). */
  body.wp-theme-candy .ns-gallery--fit-auto .ns-gallery__tile[data-ns-orient="portrait"] .ns-gallery__img {
    object-fit: cover;
    background: transparent;
  }

  body.wp-theme-candy .ns-gallery__nav {
    width: 42px;
    height: 42px;
  }

  body.wp-theme-candy .ns-gallery__nav span {
    font-size: 28px;
  }

  body.wp-theme-candy .ns-gallery__thumbs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  body.wp-theme-candy .ns-gallery__grid {
    grid-template-columns: 1fr;
  }

  /* Keep mosaic layouts as a 2-col pattern even on small phones. */
  body.wp-theme-candy .ns-gallery--mosaic .ns-gallery__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
  }

  body.wp-theme-candy .ns-gallery__thumbs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  body.wp-theme-candy .ns-gallery__tile,
  body.wp-theme-candy .ns-gallery__thumb img {
    transition: none !important;
  }
}
