.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 32px;
    padding: 32px;
    max-width: 1400px;
    margin: 0 auto;
    grid-auto-rows: 1fr; /* This ensures rows have equal height */
}

.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: 4px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.09);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    display: flex;
    flex-direction: column;
    height: 100%; /* Fill the entire grid cell */
}

.gallery-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.gallery-item img, .gallery-item video {
    width: 100%;
    height: 250px;
    object-fit: cover;
    display: block;
    border-radius: 4px 4px 0 0;
}

.gallery-item .caption {
    padding: 16px;
    color: var(--nasa-light);
    font-size: 0.9rem;
    font-weight: 400;
    letter-spacing: 0.02em;
    backdrop-filter: blur(10px);
}

.media-type {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--nasa-light);
    z-index: 2;
}

.media-icon {
    width: 16px;
    height: 16px;
    opacity: 0.8;
}

/* Play button for videos */
.play-button-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background-color: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.gallery-item:hover .play-button-overlay {
    background-color: rgba(16, 91, 216, 0.8);
    transform: translate(-50%, -50%) scale(1.1);
}

.play-icon {
    width: 24px;
    height: 24px;
    fill: white;
    margin-left: 4px; /* Slight adjustment to center the triangle */
}

@media (max-width: 600px) {
    .gallery {
        padding: 16px;
        gap: 16px;
    }

/* Make each row's items equal height */

/* Image takes available space but maintains height */
.gallery-item img, .gallery-item video {
    width: 100%;
    height: 250px;
    object-fit: cover;
    display: block;
    border-radius: 4px 4px 0 0;
    flex-shrink: 0; /* Prevent the image from shrinking */
}

/* Caption expands as needed */
.gallery-item .caption {
    padding: 16px;
    color: var(--nasa-light);
    font-size: 0.9rem;
    font-weight: 400;
    letter-spacing: 0.02em;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    flex-grow: 1; /* Allow caption to grow */
    display: flex;
    align-items: center; /* Vertically center the text */
}}