.code-kachelgallerie-stage {
    position: relative;
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    overflow: hidden;
    background: var(--code-gallery-bg-color, #000);
}

.code-kachelgallerie {
    width: 100%;
    height: 100%;
    min-height: 100vh;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-auto-rows: minmax(120px, 1fr);
    grid-auto-flow: dense;
    gap: var(--code-kachel-gap, 0px);
    overflow: hidden;
    background: var(--code-gallery-bg-color, #000);
}

.code-kachelgallerie-intro {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: clamp(24px, 6vw, 96px);
    background: var(--code-intro-bg-color, #000);
    color: var(--code-intro-text-color, #fff);
    opacity: 0;
    transition: opacity var(--code-intro-duration, 900ms) ease;
    pointer-events: none;
}

.code-kachelgallerie-stage.intro-visible .code-kachelgallerie-intro {
    opacity: 1;
}

.code-kachelgallerie-stage.intro-hidden .code-kachelgallerie-intro {
    opacity: 0;
}

.code-kachelgallerie-intro-text {
    max-width: min(1100px, 90vw);
    font-size: var(--code-intro-font-size, 72px) !important;
    line-height: 1.08;
    font-weight: 700;
    text-align: center;
    white-space: normal;
}

.code-kachelgallerie-intro-text * {
    font-size: inherit !important;
    color: inherit !important;
}

/* Kachelcontainer ist immer gleich: .code-kachel ist direktes Grid-/Masonry-Element.
   Link oder Nicht-Link liegen nur innen und beeinflussen Groesse/Animation nicht. */
.code-kachelgallerie .code-kachel {
    display: block;
    position: relative;
    box-sizing: border-box;
    padding: 0;
    overflow: hidden;
    opacity: 0;
    transform: scale(var(--code-kachel-image-scale, 1));
    transition-property: opacity, transform, filter;
    transition-duration: var(--code-kachel-duration, 650ms), var(--code-kachel-duration, 650ms), 220ms;
    transition-timing-function: ease, ease, ease;
    transition-delay: var(--code-kachel-delay, 0ms), var(--code-kachel-delay, 0ms), 0ms;
    will-change: opacity, transform;
}

.code-kachelgallerie .code-kachel.is-visible {
    opacity: 1;
}

.code-kachelgallerie-animation-zoom > .code-kachel {
    transform: scale(calc(var(--code-kachel-image-scale, 1) * .94));
}

.code-kachelgallerie-animation-slide > .code-kachel {
    transform: translateY(28px) scale(var(--code-kachel-image-scale, 1));
}

.code-kachelgallerie-animation-zoom > .code-kachel.is-visible,
.code-kachelgallerie-animation-slide > .code-kachel.is-visible {
    transform: scale(var(--code-kachel-image-scale, 1));
}

.code-kachelgallerie .code-kachel-link,
.code-kachelgallerie .code-kachel-inner {
    display: block;
    width: 100%;
    height: 100%;
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
}

.code-kachelgallerie .code-kachel-link {
    color: inherit;
    text-decoration: none;
}

.code-kachelgallerie img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: brightness(1) contrast(1);
    transition: filter 220ms ease, transform 220ms ease;
}

.code-kachelgallerie .code-kachel:hover img {
    filter: brightness(1.18) contrast(1.18);
    transform: scale(var(--code-kachel-image-hover-scale, 1.025));
}

.code-kachelgallerie > .code-kachel {
    min-width: 0;
    min-height: 0;
}

.code-kachelgallerie > .code-kachel-size-1x1 { grid-column: span 1 !important; grid-row: span 1 !important; }
.code-kachelgallerie > .code-kachel-size-2x1 { grid-column: span 2 !important; grid-row: span 1 !important; }
.code-kachelgallerie > .code-kachel-size-1x2 { grid-column: span 1 !important; grid-row: span 2 !important; }
.code-kachelgallerie > .code-kachel-size-2x2 { grid-column: span 2 !important; grid-row: span 2 !important; }
.code-kachelgallerie > .code-kachel-size-3x1 { grid-column: span 3 !important; grid-row: span 1 !important; }

@media (prefers-reduced-motion: reduce) {
    .code-kachelgallerie-intro,
    .code-kachelgallerie .code-kachel {
        transition: none;
    }
}

@media (max-width: 980px) {
    .code-kachelgallerie {
        grid-template-columns: repeat(4, 1fr);
        grid-auto-rows: minmax(100px, 1fr);
    }
}

@media (max-width: 640px) {
    .code-kachelgallerie {
        grid-template-columns: repeat(2, 1fr);
        grid-auto-rows: minmax(120px, 1fr);
    }

    .code-kachel-size-3x1,
    .code-kachel-size-2x1,
    .code-kachel-size-2x2 {
        grid-column: span 2;
    }
}

/* Grid-Varianten */
.code-kachelgallerie-grid-row {
    grid-auto-flow: row;
}

.code-kachelgallerie-grid-free {
    grid-auto-flow: dense;
    align-content: start;
    grid-auto-rows: minmax(56px, calc(100vh / 6));
}

@media (max-width: 980px) {
    .code-kachelgallerie-grid-free {
        grid-auto-rows: minmax(64px, calc(100vh / 7));
    }
}

@media (max-width: 640px) {
    .code-kachelgallerie-grid-free {
        grid-auto-rows: minmax(80px, calc(100vh / 8));
    }
}


/* Mobile Grid-Varianten */
@media (max-width: 640px) {
    .code-kachelgallerie-mobile-row {
        grid-auto-flow: row !important;
    }

    .code-kachelgallerie-mobile-free {
        grid-auto-flow: dense !important;
        align-content: start;
        grid-auto-rows: minmax(80px, calc(100vh / 8)) !important;
    }

    .code-kachelgallerie-mobile-one {
        grid-template-columns: 1fr !important;
        grid-auto-flow: row !important;
        grid-auto-rows: minmax(140px, auto) !important;
        overflow-y: auto;
    }

    .code-kachelgallerie-mobile-two {
        grid-template-columns: repeat(2, 1fr) !important;
        grid-auto-flow: dense !important;
        grid-auto-rows: minmax(96px, calc(100vh / 8)) !important;
    }

    .code-kachelgallerie-mobile-one > .code-kachel {
        grid-column: span 1 !important;
    }
}

/* Echtes freies Masonry-Grid */
.code-kachelgallerie.code-kachelgallerie-is-masonry {
    display: block !important;
    position: relative !important;
    min-height: 100vh;
}

.code-kachelgallerie.code-kachelgallerie-is-masonry > .code-kachel {
    position: absolute;
    box-sizing: border-box;
}

/* v2.2: Freies Grid nutzt eine eigene JS-Masonry-Engine statt CSS-Grid-Zeilen. */
.code-kachelgallerie.code-kachelgallerie-is-masonry {
    display: block !important;
    position: relative !important;
    width: 100% !important;
    min-height: 100vh;
    grid-template-columns: none !important;
    grid-auto-rows: auto !important;
    grid-auto-flow: initial !important;
    align-content: initial !important;
}

.code-kachelgallerie.code-kachelgallerie-is-masonry > .code-kachel {
    position: absolute !important;
    box-sizing: border-box;
    min-width: 0;
    min-height: 0;
}

/* v2.5: Im freien Masonry-Grid endet der schwarze Hintergrund exakt mit der letzten Kachel. */
.code-kachelgallerie-stage.code-kachelgallerie-stage-is-masonry {
    min-height: 0 !important;
    height: auto;
}

.code-kachelgallerie.code-kachelgallerie-is-masonry {
    min-height: 0 !important;
    overflow: hidden;
}

/* Tooltip innerhalb der Kachel */
.code-kachelgallerie .code-kachel-tooltip {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: clamp(14px, 2.2vw, 34px);
    color: var(--code-tooltip-text-color, #fff);
    background: var(--code-tooltip-bg-color, rgba(0,0,0,.78));
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 220ms ease, transform 220ms ease;
    pointer-events: none;
    text-align: center;
}

.code-kachelgallerie .code-kachel-tooltip-inner {
    max-width: 100%;
    font-size: var(--code-tooltip-font-size, clamp(14px, 1.45vw, 26px)) !important;
    line-height: 1.25;
    box-sizing: border-box;
}

.code-kachelgallerie .code-kachel-tooltip-inner * {
    color: inherit;
}

.code-kachelgallerie .code-kachel:hover .code-kachel-tooltip,
.code-kachelgallerie .code-kachel:focus-within .code-kachel-tooltip {
    opacity: 1;
    transform: translateY(0);
}

/* v2.6.4: Kacheln ohne Tooltip zoomen die komplette Kachel, nicht nur das Bild.
   Dadurch wird bei kleiner Bildgroesse, z. B. 40%, nichts innerhalb der Kachel abgeschnitten. */
.code-kachelgallerie .code-kachel.code-kachel-no-tooltip {
    overflow: visible;
    transform-origin: center center;
}

.code-kachelgallerie .code-kachel.code-kachel-no-tooltip .code-kachel-link,
.code-kachelgallerie .code-kachel.code-kachel-no-tooltip .code-kachel-inner {
    overflow: visible;
}

.code-kachelgallerie .code-kachel.code-kachel-no-tooltip:hover,
.code-kachelgallerie .code-kachel.code-kachel-no-tooltip:focus-within {
    z-index: 20;
    transform: scale(calc(var(--code-kachel-image-scale, 1) * 1.2)) !important;
}

.code-kachelgallerie .code-kachel.code-kachel-no-tooltip:hover img,
.code-kachelgallerie .code-kachel.code-kachel-no-tooltip:focus-within img {
    filter: brightness(1.08) contrast(1.08);
    transform: none;
}


/* v2.6.5: Mobile Viewport-Fix
   - Intro-Schrift skaliert mit der Bildschirmbreite und kann lange Woerter umbrechen.
   - Die Galerie ist mobil nicht mehr auf exakt 100vh begrenzt. Dadurch werden
     weitere/letzte Grid-Zeilen nicht vom Stage-Container abgeschnitten.
   - Das Intro selbst bleibt trotzdem genau im ersten sichtbaren Viewport. */
@media (max-width: 640px) {
    .code-kachelgallerie-stage {
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        overflow: hidden;
    }

    .code-kachelgallerie {
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .code-kachelgallerie-intro {
        inset: 0 0 auto 0;
        height: 100vh;
        height: 100dvh;
        min-height: 0;
        padding: clamp(18px, 5vw, 32px);
    }

    .code-kachelgallerie-intro-text {
        width: 100%;
        max-width: 100%;
        font-size: max(28px, min(var(--code-intro-font-size, 72px), 13vw)) !important;
        line-height: 1.05;
        overflow-wrap: anywhere;
        word-break: normal;
        hyphens: auto;
    }

    /* Bei zeilenorientierten Mobile-Grids darf der Inhalt die Viewporthoehe
       natuerlich erweitern. Die letzte Reihe bleibt dadurch voll sichtbar. */
    .code-kachelgallerie-mobile-row,
    .code-kachelgallerie-mobile-two,
    .code-kachelgallerie-mobile-auto:not(.code-kachelgallerie-is-masonry) {
        align-content: start;
    }
}
