.bidirectional-gallery-wrapper {
    display: flex;
    justify-content: center;
    gap: 4%;
    height: var(--carousel-height, 750px);
    overflow: hidden;
    position: relative;
    padding: 15px 0;
    width: 100%;
}

.gallery-column {
    flex: 1;
    max-width: 32%;
    display: flex;
    flex-direction: column;
}

.gallery-track {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.gallery-item {
    border-radius: var(--item-border-radius, 24px);
    width: 100%;
    aspect-ratio: var(--item-aspect-ratio, 1/1);
    height: var(--item-height, auto);
    background-color: transparent;
    position: relative;
    /* Perspective is what makes the inner flip look 3D instead of a flat squash */
    perspective: 1200px;
}

/* The flipping "card". Front and back are stacked on top of each other inside this. */
.gallery-item-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform var(--flip-duration, 0.8s);
    transform-style: preserve-3d;
}

.gallery-item.has-flip:hover .gallery-item-inner {
    transform: rotateY(180deg);
}

.gallery-item-front,
.gallery-item-back {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: var(--item-border-radius, 24px);
    overflow: hidden;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.gallery-item-front img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: var(--image-fit, cover);
}

.bidirectional-gallery-wrapper .gallery-item-back {
    transform: rotateY(180deg);
    background-color: rgba(9, 34, 67, 0.5) !important;
    background-image: none !important;
    color: #FFFFFF !important;
    font-size: var(--flip-text-size, 18px);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 16px;
    box-sizing: border-box;
}

.gallery-item-back p {
    margin: 0;
    line-height: 1.4;
}

/* --- Perfectly Synchronized Structural Loops --- */
.col-down .gallery-track {
    transform: translateY(-50%);
    animation: scrollDown var(--gallery-speed, 30s) linear infinite;
}

.col-up .gallery-track {
    transform: translateY(0);
    animation: scrollUp var(--gallery-speed, 30s) linear infinite;
}

@keyframes scrollUp {
    100% { transform: translateY(-50%); }
}

@keyframes scrollDown {
    100% { transform: translateY(0); }
}

/* The hover pause rule has been completely removed so it scrolls endlessly */