/* Gallery Block Styles */
.gallery-block {
    margin-bottom: 2rem;
}

.gallery-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

.gallery-row {
    /* Base gutter uses the desktop spacing value; mobile overrides are applied
       via a media query below so existing desktop behavior is preserved. */
    --gallery-gutter: calc(var(--gallery-spacing, 3) * 0.25rem);
    row-gap: var(--gallery-gutter);
}

.gallery-col {
    padding-left: calc(var(--gallery-gutter) / 2);
    padding-right: calc(var(--gallery-gutter) / 2);
    margin-bottom: var(--gallery-gutter);
}

.gallery-item {
    position: relative;
    width: 100%;
    aspect-ratio: var(--gallery-aspect-ratio, 4/3);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border-radius: 0.25rem;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* Overlay and Title Styles */
.gallery-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    pointer-events: none;
}

.gallery-overlay::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,0.5), rgba(0,0,0,0.2));
    opacity: calc(var(--gallery-overlay-opacity, 50) / 100);
    transition: opacity 0.3s ease;
}

.gallery-title-container {
    position: absolute;
    left: 0;
    right: 0;
    padding: 1rem;
    color: #ffffff;
    z-index: 1;
}

/* Vertical Positioning */
.gallery-title-container.vertical-top {
    top: 0;
}

.gallery-title-container.vertical-center {
    top: 50%;
    transform: translateY(-50%);
}

.gallery-title-container.vertical-bottom {
    bottom: 0;
}

/* Horizontal Alignment */
.gallery-title-container.text-left {
    text-align: left;
}

.gallery-title-container.text-center {
    text-align: center;
}

.gallery-title-container.text-right {
    text-align: right;
}

.gallery-title {
    margin: 0;
    font-weight: 600;
    line-height: 1.2;
}

/* Caption styles (below image) */
.gallery-caption {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background-color: #ffffff;
    border-radius: 0.25rem;
}

.gallery-text {
    margin: 0;
    color: #6c757d;
    line-height: 1.4;
}

/* Text shadow helpers for titles and captions. When an outline-* class is
   also present on the same element, the outline-* rule (defined after these)
   will take precedence. */
.shadow-none {
    text-shadow: none;
}

.shadow-soft {
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

.shadow-medium {
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.shadow-strong {
    text-shadow: 0 3px 6px rgba(0, 0, 0, 0.8);
}

/* Text outline helpers, implemented via multi-directional text-shadow. These
   override any shadow-* class when both are applied. There is intentionally
   no outline-none rule so that the base shadow-* value remains in effect. */
.outline-soft {
    text-shadow:
        -1px 0 0 rgba(0, 0, 0, 0.7),
         1px 0 0 rgba(0, 0, 0, 0.7),
         0 -1px 0 rgba(0, 0, 0, 0.7),
         0  1px 0 rgba(0, 0, 0, 0.7);
}

.outline-strong {
    text-shadow:
        -1px 0 0 rgba(0, 0, 0, 0.95),
         1px 0 0 rgba(0, 0, 0, 0.95),
         0 -1px 0 rgba(0, 0, 0, 0.95),
         0  1px 0 rgba(0, 0, 0, 0.95);
}

/* GLightbox customizations */
.glightbox-clean .gslide-description {
    background: rgba(0, 0, 0, 0.7);
}

.glightbox-clean .gdesc-inner {
    padding: 1rem;
}

.glightbox-clean .gslide-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #ffffff;
}

.glightbox-clean .gslide-desc {
    font-size: 0.9rem;
    color: #f8f9fa;
}

/*
Responsive behavior using the custom properties emitted by the
gallery block template.

- Desktop (>= 768px): use base columns/spacing and block-level
  wrapping/breaking flags.
- Mobile (< 768px): prefer mobile override values when provided.
*/

@media (min-width: 768px) {
    .gallery-row {
        /* On desktop, use the base columns/spacing to build a CSS grid. */
        --gallery-effective-columns: var(--gallery-columns, 3);
        --gallery-effective-spacing: var(--gallery-spacing, 3);

        display: grid;
        grid-template-columns: repeat(var(--gallery-effective-columns, 3), minmax(0, 1fr));
        gap: calc(var(--gallery-effective-spacing, 3) * 0.25rem);
    }

    /* When force_single_row is enabled, show a single horizontally scrollable row. */
    .gallery-block[style*="--gallery-force-single-row: 1"] .gallery-row {
        display: flex;
        flex-wrap: nowrap;
        /* On desktop, keep everything on one row but avoid horizontal scrollbars
           by letting flexbox distribute the available width across items. */
        gap: calc(var(--gallery-effective-spacing, 3) * 0.25rem);
    }

    .gallery-block[style*="--gallery-force-single-row: 1"] .gallery-col {
        /* Let flexbox size tiles evenly within the row, taking gaps into account,
           so the row fits the container without overflowing. */
        flex: 1 1 0;
        max-width: none;
    }
}

@media (max-width: 767.98px) {
    .gallery-row {
        --gallery-effective-columns: var(--gallery-columns-mobile, var(--gallery-columns, 2));
        --gallery-effective-spacing: var(--gallery-spacing-mobile, var(--gallery-spacing, 2));
    }

    .gallery-block {
        /* Decide between single-row scrollable layout vs wrapped grid on mobile */
        --gallery-force-row-mobile: var(--gallery-force-single-row-mobile, var(--gallery-force-single-row, 0));
    }

    .gallery-row {
        display: grid;
        grid-template-columns: repeat(var(--gallery-effective-columns, 2), minmax(0, 1fr));
        gap: calc(var(--gallery-effective-spacing, 2) * 0.25rem);
    }

    .gallery-block[style*="--gallery-force-single-row-mobile: 1"] .gallery-row {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: calc(var(--gallery-effective-spacing, 2) * 0.25rem);
    }

    .gallery-block[style*="--gallery-force-single-row-mobile: 1"] .gallery-col {
        /* On mobile, also ensure each tile has a concrete width in the horizontal row. */
        flex: 0 0 calc(100% / var(--gallery-effective-columns, 2));
        max-width: calc(100% / var(--gallery-effective-columns, 2));
    }
}

/* Typography defaults: allow wrapping, and on very small screens be
   slightly more aggressive about breaking long words to avoid overflow. */

.gallery-title {
    /* Base/desktop title font size from per-item or block-level desktop variables. */
    font-size: calc(var(--gallery-item-title-size-desktop, var(--gallery-title-size-desktop, 100)) * 1%);
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
}

.gallery-text {
    /* Base/desktop caption font size from per-item or block-level desktop variables. */
    font-size: calc(var(--gallery-item-caption-size-desktop, var(--gallery-caption-size-desktop, 100)) * 1%);
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
}

@media (max-width: 767.98px) {
    .gallery-title {
        /* On small screens, use mobile title size overrides where provided. */
        font-size: calc(var(--gallery-item-title-size-mobile, var(--gallery-title-size-mobile, 100)) * 1%);
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .gallery-text {
        /* On small screens, use mobile caption size overrides where provided. */
        font-size: calc(var(--gallery-item-caption-size-mobile, var(--gallery-caption-size-mobile, 100)) * 1%);
        overflow-wrap: anywhere;
        word-break: break-word;
    }
}

/* Desktop vs mobile text toggles for optional mobile-specific titles/captions.
   By default, show desktop text everywhere; on small screens, hide desktop
   variants and show the mobile overrides when provided. */

.gallery-title-mobile,
.gallery-caption-mobile {
    display: none;
}

@media (max-width: 767.98px) {
    .gallery-title-desktop,
    .gallery-caption-desktop {
        display: none;
    }

    .gallery-title-mobile,
    .gallery-caption-mobile {
        display: inline;
    }
}
