#gallery {
    font-family: 'Poppins', sans-serif;
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
}

#gallery:not(.active) {
    opacity: 0;
    pointer-events: none;
}

#gallery .gallery-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 40px 20px 0 20px; 
}

#gallery .gallery-container .heading {
    width: 30%;
    padding-bottom: 50px;
}

#gallery .gallery-container .heading h3 {
    font-size: 3em;
    font-weight: bolder;
    border-bottom: 3px solid #222;
    margin-bottom: 30px;
    padding-bottom: 10px;
}

#gallery .gallery-container .heading h3 span {
    font-weight: 50;
}

/* Group section container */
#gallery .group-section {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto 40px auto;
    text-align: left;
}

/* Group header with bold black underline */
#gallery .group-header {
    width: 100%;
    margin: 0 0 16px 0;
}

#gallery .group-header h4 {
    display: inline-block;
    font-size: 1.4em;
    font-weight: 700;
    color: #000;
    border-bottom: 3px solid #000;
    padding-bottom: 6px;
    margin: 0 0 4px 0;
}

/* Per-group 3-column masonry box */
#gallery .gallery-container .box {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    gap: 30px;
}

#gallery .gallery-container .box .dream {
    display: flex;
    flex-direction: column;
    flex: 1;
    width: 32.5%;
}

/* Image container with transitions */
#gallery .image-container {
    width: 100%;
    overflow: hidden;
    margin-bottom: 30px;
    position: relative;
    border-radius: 5px;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 1;
    transform: translateY(0) scale(1);
}

#gallery .gallery-container .box .dream img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
    cursor: pointer;
    display: block;
    image-orientation: from-image;
}

#gallery .dream img:hover {
    transform: scale(1.1);
}

/* Animation states */
#gallery .image-hidden {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
}

#gallery .image-loading {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
}

#gallery .image-loaded {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* Loading animation for better UX */
#gallery .image-container.image-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: galleryImageSpin 1s linear infinite;
    z-index: 10;
}

@keyframes galleryImageSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Progressive loading styles */
.progressive-image-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 5px;
}

.image-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, #f0f0f0, #e0e0e0);
    background-size: cover;
    background-position: center;
    transition: opacity 0.3s ease;
    z-index: 1;
}

.progressive-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: all 0.3s ease;
    opacity: 0;
    z-index: 2;
    position: relative;
    cursor: pointer;
    image-orientation: from-image;
}

.progressive-image.loading {
    opacity: 0;
    transform: scale(1.05);
}

.progressive-image.loaded {
    opacity: 1;
    transform: scale(1);
}

.progressive-image.error {
    opacity: 0.5;
    background: #f0f0f0;
}

.progressive-image:hover {
    transform: scale(1.1);
}

/* Loading animation */
.progressive-image-container::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: progressiveImageSpin 1s linear infinite;
    z-index: 3;
    opacity: 0;
}

.progressive-image.loading ~ .progressive-image-container::before,
.image-container.image-loading .progressive-image-container::before {
    opacity: 1;
}

@keyframes progressiveImageSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Modal styles */
#imageModal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.9);
    backdrop-filter: blur(5px);
    transition: opacity 0.3s ease;
}

#imageModal.modal-opening {
    animation: modalFadeIn 0.3s ease;
}

#imageModal.modal-closing {
    animation: modalFadeOut 0.3s ease;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalFadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

#imageModal .modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 90vw;
    max-height: 90vh;
}

#imageModal .modal img,
#imageModal #modalImg {
    max-width: 100%;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    image-orientation: from-image;
}

#imageModal .close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #fff;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 2001;
    transition: color 0.3s ease;
}

#imageModal .close:hover {
    color: #ccc;
}

/* Navigation arrows */
#imageModal .nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    font-size: 24px;
    padding: 15px 20px;
    cursor: pointer;
    border-radius: 5px;
    transition: background-color 0.3s ease;
    z-index: 2001;
}

#imageModal .nav-arrow:hover {
    background: rgba(255, 255, 255, 0.4);
}

#imageModal .prev { left: 20px; }
#imageModal .next { right: 20px; }

#imageModal .image-transitioning {
    opacity: 0.3;
    transform: scale(0.95);
    transition: all 0.15s ease-in-out;
}

/* Back to top button */
#backToTop {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 50px;
    height: 50px;
    background: white;
    color: black;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(100px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

#backToTop::before {
    content: '';
    width: 12px;
    height: 2px;
    background: black;
    margin-bottom: 2px;
    border-radius: 1px;
}

#backToTop.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

#backToTop:hover {
    background: #f5f5f5;
    transform: translateY(-3px) scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

#backToTop:active {
    transform: translateY(-1px) scale(1.05);
    background: #eeeeee;
}

/* Gallery responsive design */
@media only screen and (max-width: 769px) {
    #gallery .gallery-container .box { 
        flex-direction: column; 
        gap: 20px;
    }
    #gallery .gallery-container .box .dream { 
        width: 100%; 
    }
    #gallery .image-container { 
        height: auto;
        min-height: 250px; 
    }
    #imageModal .nav-arrow { 
        padding: 10px 15px; 
        font-size: 18px; 
    }
    #imageModal .close { 
        font-size: 30px; 
        right: 20px; 
        top: 10px; 
    }
    #backToTop { 
        bottom: 20px; 
        right: 20px; 
        width: 45px; 
        height: 45px; 
        font-size: 14px; 
    }
    #backToTop::before { 
        width: 10px; 
        height: 2px; 
    }
    #gallery .gallery-container .heading {
        width: 90%;
    }
}

@media only screen and (max-width: 643px) {
    #gallery .gallery-container .heading { 
        width: 100%; 
    }
    #gallery .gallery-container .heading h3 { 
        font-size: 2em; 
    }
    #gallery .image-container { 
        min-height: 200px; 
    }
    #gallery .group-header h4 {
        font-size: 1.2em;
    }
}

/* Ensure body doesn't scroll when modal is open */
body.modal-open { 
    overflow: hidden; 
}

/* Empty gallery state */
.empty-gallery-message {
    text-align: center;
    padding: 60px 20px;
    color: #666;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    margin: 20px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.empty-gallery-message h3 { 
    font-size: 1.5em; 
    margin-bottom: 15px; 
    color: #333; 
}

.empty-gallery-message p { 
    margin: 10px 0; 
    font-size: 1em; 
    line-height: 1.5; 
}

.empty-gallery-message code {
    background: #f5f5f5;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

/* Ensure proper section transitions */
.section {
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    opacity: 1;
    transform: translateY(0);
}

.section:not(.active) {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.section.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
    position: relative;
}

/* Groups container */
#groupsContainer {
    width: 100%;
    max-width: 1400px;
}