/* ================= GRID ================= */

.theme-gallery {
  display: grid;
  gap: var(--gallery-gap, 16px);
}

/* ================= ITEM ================= */

.theme-gallery-item,
.theme-gallery-more {
  position: relative;
  overflow: hidden;
  aspect-ratio: var(--gallery-ratio, 1 / 1);
  cursor: pointer;
  border-radius: var(--gallery-radius, 0px);
}

/* reset link wrapper */
.theme-gallery-item > a,
.theme-gallery-more {
  display: block;
  width: 100%;
  height: 100%;
  text-decoration: none;
  color: inherit;
}

/* ================= IMAGE / VIDEO / EMBED BASE ================= */

.theme-gallery-item img,
.theme-gallery-item video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transition: transform 0.5s ease;
}

/* ================= EMBED (EXTERNAL VIDEO) ================= */

.theme-gallery-item .gallery-embed {
  width: 100%;
  height: 100%;
  display: block;
}

.theme-gallery-item .gallery-embed iframe,
.theme-gallery-item .gallery-embed video {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  object-fit: cover;
}

/* wp oembed sometimes wraps */
.theme-gallery-item .gallery-embed > * {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
}

/* hover zoom */
.theme-gallery-item.has-zoom:hover img,
.theme-gallery-item.has-zoom:hover video,
.theme-gallery-item.has-zoom:hover .gallery-embed iframe,
.theme-gallery-item.has-zoom:hover .gallery-embed video {
  transform: scale(var(--gallery-hover-scale, 1.1));
}

/* ================= OVERLAY ================= */

.gallery-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;

  background: var(--gallery-overlay-color, rgba(15, 23, 42, 0.2));
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

/* overlay only on hover */
.theme-gallery-item.has-overlay:hover .gallery-overlay {
  opacity: 1;
}

/* ================= ICON ================= */

.gallery-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;

  font-size: var(--gallery-icon-size, 36px);
  color: var(--gallery-icon-color, #fff);
}

/* SVG size */
.gallery-icon svg {
  width: var(--gallery-icon-size, 36px);
  height: var(--gallery-icon-size, 36px);
}

/* reset SVG */
.gallery-icon svg * {
  fill: none;
  stroke: none;
}

/* ===== MODE: FILL ===== */
.gallery-icon[data-mode="fill"],
.gallery-icon[data-mode="fill"] svg * {
  fill: currentColor;
}

/* ===== MODE: STROKE ===== */
.gallery-icon[data-mode="stroke"] svg * {
  stroke: currentColor;
}

/* ===== MODE: BOTH ===== */
.gallery-icon[data-mode="both"],
.gallery-icon[data-mode="both"] svg * {
  fill: currentColor;
  stroke: currentColor;
}

/* ================= VIEW ALL ITEM ================= */

.theme-gallery-more {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gallery-overlay-color, rgba(15, 23, 42, 0.35));
  color: #fff;
  font-weight: 600;
}

.theme-gallery-more span {
  font-size: 2rem;
  line-height: 1;
}

/* ================= MODAL (VIEW ALL GRID) ================= */

.theme-gallery-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
}

.theme-gallery-modal.is-open {
  display: block;
}

.theme-gallery-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  cursor: zoom-out;
}

.theme-gallery-modal__content {
  position: relative;
  max-width: 1200px;
  margin: 5vh auto;
  background: #fff;
  padding: 24px;

  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;

  max-height: 90vh;
  overflow-y: auto;
  border-radius: 1rem;
}

/* modal item */
.theme-gallery-modal-item {
  position: relative;
  overflow: hidden;
  aspect-ratio: var(--gallery-ratio, 1 / 1);
  cursor: pointer;
  border-radius: 0.75rem;
}

.theme-gallery-modal-item img,
.theme-gallery-modal-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* close button */
.gallery-modal-close {
  position: fixed;
  top: 16px;
  right: 20px;
  font-size: 32px;
  background: none;
  border: 0;
  cursor: pointer;
  z-index: 10;
  color: #fff;
  line-height: 1;
}

/* ================= IMAGE LIGHTBOX ================= */

.theme-gallery-lightbox {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.theme-gallery-lightbox.is-open {
  display: flex;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  cursor: zoom-out;
}

.lightbox-image {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  z-index: 1;
  display: block;
}

/* ================= VIDEO LIGHTBOX ================= */

.theme-video-lightbox {
  position: fixed;
  inset: 0;
  z-index: 999999;
  display: none;
}

.theme-video-lightbox.is-open {
  display: block;
}

.theme-video-lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  cursor: zoom-out;
}

.theme-video-lightbox__panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(1000px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
  background: #0b1220;
  border-radius: 1rem;
  overflow: hidden;
}

.theme-video-lightbox__body {
  padding: 1rem;
}

/* IMPORTANT: frame for iframe/video */
.theme-video-lightbox__frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  overflow: hidden;
  border-radius: 0.75rem;
}

.theme-video-lightbox__frame iframe,
.theme-video-lightbox__frame video {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* close button */
button.theme-video-lightbox__close {
  position: absolute;
  right: 1.5rem;
  top: 1.5rem;
  z-index: 5;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 999px;
  border: 0;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ================= LOCK SCROLL ================= */

html.theme-video-lightbox-open,
html.theme-gallery-modal-open,
html.theme-gallery-lightbox-open {
  overflow: hidden;
}

.gallery-video-placeholder {
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.35);
}
