/* Experimentelle Galerie — festes Grid + Labyrinth-Sliding */

body.cv-gallery-page-active {
  --cv-menu-page-accent: var(--cv-menu-mode-gallery);
  --cv-galerie-gap: 0.65rem;
}

body.cv-gallery-page-active .cv-menu-chronik-wrap,
body.cv-gallery-page-active .cv-menu-search-wrap {
  display: none !important;
}

body.cv-gallery-page-active .cv-menu-mode-title-wrap {
  display: none !important;
}

/* Left title may use the full start column (1fr), not the narrow search width. */
body.cv-gallery-page-active .cv-menu-start {
  width: auto;
  max-width: 100%;
  min-width: 0;
}

body.cv-gallery-page-active .cv-galerie-hover-title:not([hidden]) {
  display: block;
}

.cv-galerie-hover-title {
  display: none;
  margin: 0;
  min-width: 0;
  max-width: 100%;
  width: max-content;
  font: inherit;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--cv-menu-page-accent, var(--cv-menu-mode-gallery));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.cv-gallery-page-active #cv-content {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  height: 100%;
  min-height: 0;
  columns: unset;
  column-count: unset;
  column-width: auto;
  column-gap: 0;
  /* `.content` hat schon `--cv-page-padding` — bündig mit der Menü-Bar */
  padding-inline: 0;
  padding-block: 0;
  box-sizing: border-box;
}

body.cv-gallery-page-active #cv-kopf,
body.cv-gallery-page-active #cv-loading-hint,
body.cv-gallery-page-active .cv-scroll-bottom-spacer,
body.cv-gallery-page-active #cv-overview {
  display: none !important;
}

body.cv-gallery-page-active .cv-track {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  height: 100%;
}

body.cv-gallery-page-active #content-scroll {
  overflow: hidden;
  height: 100%;
}

#cv-markdown.is-galerie-layout {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  max-width: 100%;
  height: auto;
  min-height: 0;
  box-sizing: border-box;
  padding: 0;
}

.cv-galerie {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  /* oben/unten = links/rechts (`.content` padding-inline) */
  padding-block: var(--cv-page-padding);
  box-sizing: border-box;
}

.cv-galerie-grid {
  display: grid;
  grid-template-columns: repeat(var(--cv-galerie-cols, 5), minmax(0, 1fr));
  grid-template-rows: repeat(var(--cv-galerie-rows, 4), minmax(0, 1fr));
  gap: var(--cv-galerie-gap);
  width: 100%;
  height: 100%;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  box-sizing: border-box;
  overflow: hidden;
  /* Track-Gewichte kommen aus JS (Magnify); immer Viewport-füllend */
}

.cv-galerie-slot {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: color-mix(in srgb, var(--cv-preview-bg, #2a3038) 72%, transparent);
}

.cv-galerie-slot.is-gap {
  background: color-mix(in srgb, var(--cv-preview-bg, #2a3038) 38%, transparent);
}

.cv-galerie-tile {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  overflow: hidden;
  text-align: left;
}

.cv-galerie-tile:focus-visible {
  outline: 1px solid var(--cv-link, #7ec8e3);
  outline-offset: 2px;
}

.cv-galerie-frame {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--cv-preview-bg, #2a3038);
}

.cv-galerie-tile.is-loaded .cv-galerie-frame {
  display: none;
}

/* Fehlender Thumb: ruhiger Flächen-Placeholder statt broken-image-Icon */
.cv-galerie-tile.is-missing .cv-galerie-frame {
  display: block;
  background:
    linear-gradient(
      145deg,
      color-mix(in srgb, var(--cv-preview-bg, #2a3038) 88%, #000) 0%,
      color-mix(in srgb, var(--cv-preview-bg, #2a3038) 62%, #000) 100%
    );
}

.cv-galerie-tile.is-missing .cv-galerie-thumb {
  display: none;
}

.cv-galerie-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  opacity: 0;
  transition: opacity 180ms ease;
}

.cv-galerie-tile.is-loaded .cv-galerie-thumb {
  opacity: 1;
}

.cv-galerie-tile.is-exiting,
.cv-galerie-tile[class*='is-eaten--'],
.cv-galerie-tile[class*='is-spawn--'] {
  pointer-events: none;
}

/*
 * Loch frisst: unregelmäßige Maske wächst von der Lücken-Seite her.
 * Jeweils 6 Punkte, damit clip-path smooth interpoliert.
 */
@keyframes cv-galerie-eaten-from-left {
  0% {
    clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%, 0% 68%, 0% 32%);
  }
  42% {
    clip-path: polygon(36% 0%, 100% 0%, 100% 100%, 40% 100%, 22% 70%, 48% 28%);
  }
  100% {
    clip-path: polygon(100% 0%, 100% 0%, 100% 100%, 100% 100%, 100% 70%, 100% 30%);
  }
}

@keyframes cv-galerie-eaten-from-right {
  0% {
    clip-path: polygon(0% 0%, 100% 0%, 100% 32%, 100% 68%, 100% 100%, 0% 100%);
  }
  42% {
    clip-path: polygon(0% 0%, 64% 0%, 52% 28%, 78% 70%, 60% 100%, 0% 100%);
  }
  100% {
    clip-path: polygon(0% 0%, 0% 0%, 0% 30%, 0% 70%, 0% 100%, 0% 100%);
  }
}

@keyframes cv-galerie-eaten-from-top {
  0% {
    clip-path: polygon(0% 0%, 32% 0%, 68% 0%, 100% 0%, 100% 100%, 0% 100%);
  }
  42% {
    clip-path: polygon(0% 38%, 28% 22%, 70% 48%, 100% 36%, 100% 100%, 0% 100%);
  }
  100% {
    clip-path: polygon(0% 100%, 30% 100%, 70% 100%, 100% 100%, 100% 100%, 0% 100%);
  }
}

@keyframes cv-galerie-eaten-from-bottom {
  0% {
    clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 68% 100%, 32% 100%, 0% 100%);
  }
  42% {
    clip-path: polygon(0% 0%, 100% 0%, 100% 62%, 72% 78%, 30% 52%, 0% 64%);
  }
  100% {
    clip-path: polygon(0% 0%, 100% 0%, 100% 0%, 70% 0%, 30% 0%, 0% 0%);
  }
}

.cv-galerie-tile.is-eaten--from-left {
  animation: cv-galerie-eaten-from-left 920ms cubic-bezier(0.45, 0.05, 0.25, 1) forwards;
}

.cv-galerie-tile.is-eaten--from-right {
  animation: cv-galerie-eaten-from-right 920ms cubic-bezier(0.45, 0.05, 0.25, 1) forwards;
}

.cv-galerie-tile.is-eaten--from-top {
  animation: cv-galerie-eaten-from-top 920ms cubic-bezier(0.45, 0.05, 0.25, 1) forwards;
}

.cv-galerie-tile.is-eaten--from-bottom {
  animation: cv-galerie-eaten-from-bottom 920ms cubic-bezier(0.45, 0.05, 0.25, 1) forwards;
}

/*
 * Loch speit: Blob wächst aus Nachbar-Richtung (oder Zentrum) zur vollen Zelle.
 */
@keyframes cv-galerie-spawn-from-center {
  0% {
    clip-path: polygon(46% 44%, 56% 46%, 54% 56%, 46% 58%, 42% 50%, 44% 42%);
  }
  55% {
    clip-path: polygon(6% 8%, 94% 4%, 100% 48%, 90% 96%, 8% 100%, 0% 52%);
  }
  100% {
    clip-path: polygon(0% 0%, 100% 0%, 100% 50%, 100% 100%, 0% 100%, 0% 50%);
  }
}

@keyframes cv-galerie-spawn-from-left {
  0% {
    clip-path: polygon(0% 38%, 8% 42%, 6% 58%, 0% 62%, 0% 55%, 0% 45%);
  }
  50% {
    clip-path: polygon(0% 6%, 72% 0%, 88% 42%, 70% 100%, 0% 94%, 0% 50%);
  }
  100% {
    clip-path: polygon(0% 0%, 100% 0%, 100% 50%, 100% 100%, 0% 100%, 0% 50%);
  }
}

@keyframes cv-galerie-spawn-from-right {
  0% {
    clip-path: polygon(92% 42%, 100% 38%, 100% 62%, 94% 58%, 100% 50%, 96% 46%);
  }
  50% {
    clip-path: polygon(28% 0%, 100% 6%, 100% 50%, 100% 94%, 30% 100%, 12% 48%);
  }
  100% {
    clip-path: polygon(0% 0%, 100% 0%, 100% 50%, 100% 100%, 0% 100%, 0% 50%);
  }
}

@keyframes cv-galerie-spawn-from-top {
  0% {
    clip-path: polygon(42% 0%, 58% 0%, 56% 8%, 48% 6%, 44% 4%, 40% 2%);
  }
  50% {
    clip-path: polygon(4% 0%, 96% 0%, 100% 68%, 72% 92%, 8% 86%, 0% 40%);
  }
  100% {
    clip-path: polygon(0% 0%, 100% 0%, 100% 50%, 100% 100%, 0% 100%, 0% 50%);
  }
}

@keyframes cv-galerie-spawn-from-bottom {
  0% {
    clip-path: polygon(44% 94%, 56% 92%, 58% 100%, 42% 100%, 40% 98%, 46% 96%);
  }
  50% {
    clip-path: polygon(0% 32%, 88% 12%, 100% 60%, 96% 100%, 4% 100%, 8% 70%);
  }
  100% {
    clip-path: polygon(0% 0%, 100% 0%, 100% 50%, 100% 100%, 0% 100%, 0% 50%);
  }
}

.cv-galerie-tile.is-spawn--from-center {
  animation: cv-galerie-spawn-from-center 1080ms cubic-bezier(0.22, 0.8, 0.28, 1) forwards;
}

.cv-galerie-tile.is-spawn--from-left {
  animation: cv-galerie-spawn-from-left 1080ms cubic-bezier(0.22, 0.8, 0.28, 1) forwards;
}

.cv-galerie-tile.is-spawn--from-right {
  animation: cv-galerie-spawn-from-right 1080ms cubic-bezier(0.22, 0.8, 0.28, 1) forwards;
}

.cv-galerie-tile.is-spawn--from-top {
  animation: cv-galerie-spawn-from-top 1080ms cubic-bezier(0.22, 0.8, 0.28, 1) forwards;
}

.cv-galerie-tile.is-spawn--from-bottom {
  animation: cv-galerie-spawn-from-bottom 1080ms cubic-bezier(0.22, 0.8, 0.28, 1) forwards;
}

@media (hover: hover) and (pointer: fine) {
  .cv-galerie-tile:hover .cv-galerie-thumb,
  .cv-galerie-tile:focus-visible .cv-galerie-thumb {
    filter: brightness(1.06);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cv-galerie-thumb {
    transition: none;
  }

  .cv-galerie-tile[class*='is-eaten--'],
  .cv-galerie-tile[class*='is-spawn--'] {
    animation: none;
  }

  .cv-galerie-tile[class*='is-eaten--'] {
    clip-path: polygon(0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%);
  }

  .cv-galerie-tile[class*='is-spawn--'] {
    clip-path: none;
  }
}

@media (max-width: 720px) {
  body.cv-gallery-page-active {
    --cv-galerie-gap: 0.45rem;
  }
}

/* Mobile layout sets height:auto on track/content — gallery needs a filled viewport */
html.cv-mobile-layout body.cv-gallery-page-active:not(.cv-site) .scrollwrapper {
  height: calc(100vh - var(--cv-menu-height));
  height: calc(100dvh - var(--cv-menu-height));
  overflow: hidden;
}

html.cv-mobile-layout body.cv-gallery-page-active:not(.cv-site) .container,
html.cv-mobile-layout body.cv-gallery-page-active:not(.cv-site) .content,
html.cv-mobile-layout body.cv-gallery-page-active:not(.cv-site) #content-scroll {
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

html.cv-mobile-layout body.cv-gallery-page-active:not(.cv-site) .cv-track {
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
}

html.cv-mobile-layout body.cv-gallery-page-active:not(.cv-site) #cv-content {
  display: flex;
  flex-direction: column;
  height: 100% !important;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
}

html.cv-mobile-layout body.cv-gallery-page-active:not(.cv-site) #cv-markdown.is-galerie-layout,
html.cv-mobile-layout body.cv-gallery-page-active:not(.cv-site) .cv-galerie,
html.cv-mobile-layout body.cv-gallery-page-active:not(.cv-site) .cv-galerie-grid {
  height: 100%;
  min-height: 0;
  max-height: 100%;
}
