/* Event Gallery Styles */
.event-gallery {
    margin: 4em 0 2em 0;
    padding: 2em 0;
    border-top: 2px solid rgba(106, 169, 245, 0.2);
}

.event-gallery h2 {
    font-size: 1.75em;
    margin-bottom: 1.5em;
    color: var(--text-heading);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5em;
    margin-bottom: 2em;
    align-items: start; /* Allow items to have different heights */
    justify-items: start; /* Left-align all items by default */
}

/* When there are exactly 2 items, ensure they stay left-aligned */
.gallery-grid:has(.gallery-item:nth-child(2):last-child) {
    grid-template-columns: repeat(2, minmax(300px, 600px));
    justify-content: start; /* Left-align the grid columns */
}

.gallery-item {
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    height: auto; /* Allow natural height based on content */
    max-width: 600px; /* Prevent items from being too wide */
}

.gallery-image {
    position: relative; /* Enable positioning for caption overlay */
}

.gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.gallery-image img {
    width: 100%;
    height: auto; /* Preserve aspect ratio */
    display: block;
    object-fit: contain; /* Don't crop, show full image */
}

.gallery-caption {
    position: absolute;
    bottom: 4px;
    right: 4px;
    padding: 2px 6px;
    margin: 0; /* Remove default paragraph margin */
    font-size: 0.75em;
    line-height: 1.1;
    color: white;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 4px;
    max-width: calc(100% - 16px); /* Ensure it doesn't overflow */
    text-align: right;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: opacity 0.3s ease, background-color 0.3s ease;
    opacity: 0.85;
}

.gallery-image:hover .gallery-caption {
    opacity: 1;
    background: rgba(0, 0, 0, 0.85);
}

/* Hide captions for video items */
.gallery-video .gallery-caption {
    display: none;
}

/* Video wrapper for responsive YouTube embeds */
.gallery-video {
    width: 100%;
    max-width: 600px; /* Match gallery-item max-width */
}

.video-wrapper {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    height: 0;
    overflow: hidden;
    width: 100%;
}

.video-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* Mobile responsive */
@media screen and (max-width: 736px) {
    .gallery-grid {
        grid-template-columns: 1fr !important; /* Force single column on mobile */
        gap: 1em;
    }
    
    /* Override 2-item rule on mobile */
    .gallery-grid:has(.gallery-item:nth-child(2):last-child) {
        grid-template-columns: 1fr !important;
    }
    
    .gallery-image img {
        height: auto; /* Preserve aspect ratio on mobile too */
    }
    
    .event-gallery {
        margin: 2em 0 1em 0;
        padding: 1em 0;
    }
    
    .event-gallery h2 {
        font-size: 1.5em;
        margin-bottom: 1em;
    }
    
    .gallery-caption {
        bottom: 3px;
        right: 6px;
        padding: 3px 6px;
        margin: 0; /* Remove default paragraph margin */
        font-size: 0.7em;
        max-width: calc(100% - 12px);
    }
    
    .gallery-item {
        max-width: 100%; /* Allow full width on mobile */
    }
}

@media screen and (min-width: 737px) and (max-width: 980px) {
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
