.talg-gallery {
  --talg-columns: 3;
  --talg-accent: var(--accent, var(--wp--preset--color--accent, #b67a46));
  --talg-text: var(--text, var(--wp--preset--color--foreground, #d6deeb));
  --talg-heading: var(--heading, var(--wp--preset--color--contrast, #f2f6ff));
  --talg-surface: var(--bg-elevated, var(--bg, var(--wp--preset--color--base, #171c24)));
  display: block;
  margin: 1.5rem 0;
}

.wp-block-brotwerkstatt-theme-gallery-lightbox.talg-gallery.talg-gallery--layout-grid,
.talg-gallery-grid {
  display: grid;
  grid-template-columns: repeat(var(--talg-columns), minmax(0, 1fr));
  gap: 12px;
}

.talg-gallery--editor-shell {
  display: block;
}

.talg-gallery--editor-shell > .components-button {
  margin-bottom: 12px;
}

.talg-gallery-item {
  margin: 0;
}

.talg-gallery-trigger {
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--talg-accent) 38%, transparent);
  border-radius: 10px;
  padding: 0;
  display: block;
  background: var(--talg-surface);
  cursor: zoom-in;
  overflow: hidden;
}

.talg-gallery-trigger img,
.talg-gallery-item > img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  transition: transform 0.2s ease;
}

.talg-gallery-trigger:hover img,
.talg-gallery-trigger:focus-visible img {
  transform: scale(1.03);
}

.talg-gallery-item figcaption {
  color: var(--talg-text);
  opacity: 0.86;
  font-size: 0.88rem;
  margin-top: 6px;
}

.wp-block-brotwerkstatt-theme-gallery-lightbox.talg-gallery.talg-gallery--layout-carousel {
  display: block;
}

.talg-gallery--layout-carousel .talg-carousel-viewport {
  overflow: hidden;
  border-radius: 12px;
}

.talg-gallery--layout-carousel .talg-carousel-track {
  display: flex;
  transition: transform 0.3s ease;
  will-change: transform;
}

.talg-gallery--layout-carousel .talg-gallery-item {
  flex: 0 0 100%;
}

.talg-gallery--layout-carousel .talg-gallery-item figcaption {
  text-align: center;
}

.talg-carousel-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}

.talg-carousel-button {
  border: 1px solid color-mix(in srgb, var(--talg-accent) 45%, transparent);
  border-radius: 999px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--talg-surface) 92%, black 8%);
  color: var(--talg-heading);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.talg-carousel-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
}

.talg-carousel-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 0;
  padding: 0;
  background: color-mix(in srgb, var(--talg-text) 40%, transparent);
  cursor: pointer;
}

.talg-carousel-dot.is-active {
  background: var(--talg-accent);
}

.wp-block-brotwerkstatt-theme-gallery-lightbox.talg-gallery.talg-gallery--layout-carousel-peek {
  display: block;
}

.talg-gallery--layout-carousel-peek .talg-peek-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.talg-gallery--layout-carousel-peek .talg-peek-thumb {
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--talg-accent) 28%, transparent);
  border-radius: 10px;
  padding: 0;
  background: var(--talg-surface);
  overflow: hidden;
  cursor: pointer;
  opacity: 0.85;
}

.talg-gallery--layout-carousel-peek .talg-peek-thumb:disabled {
  opacity: 0.45;
  cursor: default;
}

.talg-gallery--layout-carousel-peek .talg-peek-thumb-image {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  filter: saturate(0.78);
}

.talg-gallery--layout-carousel-peek .talg-peek-main {
  margin: 0;
}

.talg-gallery--layout-carousel-peek .talg-peek-main-caption {
  text-align: center;
}

.talg-gallery-grid--editor.is-carousel {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  gap: 12px;
}

.talg-gallery-grid--editor.is-carousel .talg-gallery-item {
  min-width: min(100%, 360px);
  scroll-snap-align: start;
}

.talg-gallery-grid--editor.is-carousel-peek {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
}

.talg-lightbox-open {
  overflow: hidden;
}

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

.talg-lightbox {
  position: fixed;
  inset: 0;
  z-index: 99999;
}

.talg-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 14, 0.78);
}

.talg-lightbox-dialog {
  position: relative;
  z-index: 1;
  width: min(92vw, 1180px);
  max-height: 92vh;
  margin: 4vh auto;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 10px;
}

.talg-lightbox-image {
  grid-column: 2;
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--talg-accent) 30%, white 10%);
  background: color-mix(in srgb, var(--talg-surface) 90%, black 10%);
}

.talg-lightbox-caption {
  grid-column: 1 / -1;
  color: var(--talg-heading);
  text-align: center;
  margin: 0;
}

.talg-lightbox-close,
.talg-lightbox-nav {
  border: 1px solid color-mix(in srgb, var(--talg-accent) 45%, transparent);
  border-radius: 999px;
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--talg-surface) 88%, black 12%);
  color: var(--talg-heading);
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
}

.talg-lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
}

.talg-lightbox-prev {
  grid-column: 1;
}

.talg-lightbox-next {
  grid-column: 3;
}

@media (max-width: 900px) {
  .wp-block-brotwerkstatt-theme-gallery-lightbox.talg-gallery.talg-gallery--layout-grid,
  .talg-gallery-grid {
    grid-template-columns: repeat(min(2, var(--talg-columns)), minmax(0, 1fr));
  }

  .talg-lightbox-dialog {
    width: 96vw;
    grid-template-columns: 40px minmax(0, 1fr) 40px;
  }

  .talg-gallery--layout-carousel-peek .talg-peek-shell {
    grid-template-columns: 1fr;
  }

  .talg-gallery--layout-carousel-peek .talg-peek-thumb {
    order: 2;
    max-width: 240px;
    justify-self: center;
  }

  .talg-gallery--layout-carousel-peek .talg-peek-main {
    order: 1;
  }
}

@media (max-width: 580px) {
  .wp-block-brotwerkstatt-theme-gallery-lightbox.talg-gallery.talg-gallery--layout-grid,
  .talg-gallery-grid {
    grid-template-columns: 1fr;
  }

  .talg-lightbox-dialog {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  .talg-lightbox-image,
  .talg-lightbox-caption {
    grid-column: 1;
  }

  .talg-lightbox-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
  }

  .talg-lightbox-prev {
    left: 8px;
  }

  .talg-lightbox-next {
    right: 8px;
  }
}
