#gallery {
    position: relative;
    padding-top: 120px;
    z-index: 1;
}

.gallery-back {
    position: relative;
    z-index: 2;
    background-image:
      linear-gradient(to bottom, rgba(27, 27, 34, 0.8), rgba(21, 21, 25, 0.8)),
      url('../../img/background.png');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    border-radius: 10px;
    border-top: 1px solid #F2CD5C;
}

/* Grid container for gallery items */
.gallery-back {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    position: relative;
    z-index: 2;
    padding: 0 20px;
}

/* Each gallery item */
.gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: 10px;
    cursor: pointer;
    transition: transform 0.3s ease;
    aspect-ratio: 4 / 3; /* maintain aspect ratio */
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s ease;
}

/* Overlay dark layer */
.gallery-item .overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    transition: background 0.3s ease;
    z-index: 1;
}

/* Text content initially hidden and positioned bottom left */
.gallery-item .text-content {
    position: absolute;
    bottom: -60px;
    left: 20px;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.5s ease;
    z-index: 2;
}

.gallery-item .text-content h4 {
    color: #ffb703;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 18px;
}

.gallery-item .text-content p {
    color: #fff;
    font-size: 14px;
}

/* Hover effects */
.gallery-item:hover img {
    transform: scale(1.1);
}

.gallery-item:hover .overlay {
    background: rgba(0, 0, 0, 0.75);
}

.gallery-item:hover .text-content {
    bottom: 20px;
    opacity: 1;
    transform: translateY(0);
}

/* Popup Preview */
.image-popup {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.3s ease;
    padding: 20px;
}

.image-popup.active {
    display: flex;
}

.popup-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    background: #111;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
    text-align: center;
    color: #fff;
    padding-bottom: 20px;
    animation: scaleIn 0.3s ease;
}

.popup-content img {
    width: auto;
    height: 550px; /* fixed height */
    max-width: 100%;
    object-fit: contain;
    display: block;
    margin: 0 auto;
}

.popup-details {
    padding: 15px 20px 0;
}

.popup-details h4 {
    color: #ffb703;
    margin-bottom: 10px;
    font-size: 20px;
}

.popup-details p {
    font-size: 14px;
    color: #ddd;
}

.popup-close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    color: #fff;
    cursor: pointer;
    transition: color 0.3s ease;
}

.popup-close:hover {
    color: #ffb703;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Responsiveness */

/* Tablet (<= 991px) */
@media (max-width: 991px) {
    .gallery-back {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: 15px;
    }

    .gallery-item .text-content h4 {
        font-size: 16px;
    }

    .gallery-item .text-content p {
        font-size: 13px;
    }

    .popup-details h4 {
        font-size: 18px;
    }
}

/* Smartphone (<= 600px) */
@media (max-width: 600px) {
    #gallery {
        padding-top: 120px;
    }

    .gallery-back {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 10px;
        padding: 0 10px;
    }

    .gallery-item {
        border-radius: 8px;
        aspect-ratio: 1 / 1; /* square on mobile */
    }

    .gallery-item .text-content {
        left: 10px;
        bottom: -50px;
    }

    .gallery-item .text-content h4 {
        font-size: 15px;
    }

    .gallery-item .text-content p {
        font-size: 12px;
    }

    .popup-content {
        max-width: 95%;
        max-height: 90%;
    }

    .popup-details h4 {
        font-size: 16px;
    }

    .popup-details p {
        font-size: 13px;
    }

    .popup-close {
        font-size: 24px;
    }
}
