:root {
    --background-color: #f8f9fa;
    --modal-background-color: rgba(0, 0, 0, 0.85);
    --modal-content-bg-color: #fff;
    --close-btn-color: #ffffff;
    --caption-color: #333;
    --primary-color: #3EACC4;
    --font-size-large: 4em;
    --font-size-medium: 1.1em;
    --border-radius: 12px;
    --transition-duration: 0.3s;
    --hover-scale: 1.05;
    --hover-shadow: 0 12px 30px rgba(62, 172, 196, 0.3);
}

img {
    image-rendering: auto;
    image-rendering: optimizeQuality;
    -ms-interpolation-mode: bicubic;
    transform: translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    filter: brightness(1) contrast(1) blur(0.1px);
    transition: all var(--transition-duration) ease;
    perspective: 1000px;
    -webkit-perspective: 1000px;
}

section#galleri {
    padding: 40px 20px;
    background-color: var(--background-color);
    min-height: 100vh;
}

.section-tip {
    text-align: center;
    font-family: var(--title-font);
    font-size: 1.1rem;
    font-weight: 400;
    margin: -1rem 0 2.5rem 0;
    padding: 0 15px;
    color: #6c757d;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.6;
    letter-spacing: 0.2px;
    opacity: 0.9;
    position: relative;
    transform: translateY(-5px);
}

/* Maintain the width for Masonry layout */
.grid {
    width: 90%;
    max-width: 1300px;
    margin: 0 auto;
}

.grid-item {
    width: 25%;
    padding: 8px;
    box-sizing: border-box;
}

.grid-item img {
    width: 100%;
    display: block;
    border-radius: var(--border-radius);
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    backface-visibility: hidden;
    cursor: pointer;
}

.grid-item:hover img {
    transform: scale(var(--hover-scale));
    box-shadow: var(--hover-shadow);
}

/* Modern Modal Styling */
.modal {
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    display: none;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    padding: 20px;
    box-sizing: border-box;
    transition: background-color 0.4s ease-out, backdrop-filter 0.4s ease-out, display 0.4s allow-discrete;
}

.modal.show {
    display: flex;
    background-color: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    background: rgba(255, 255, 255, 0.95);
    width: 90%;
    max-width: 1000px;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    opacity: 0;
    transform: translateY(30px);
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.5s ease-out;
    overflow: hidden;
}

.modal.show .modal-content {
    opacity: 1;
    transform: translateY(0);
}

.modal-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(to right, var(--primary-color), #2d8a9d);
}

.modal-content img {
    width: 70%;
    max-height: 65vh;
    object-fit: contain;
    display: block;
    margin: 0 auto;
    transition: transform 0.3s ease;
}

.modal-content img:hover {
    transform: none;
}

#caption {
    margin: 25px auto 15px;
    font-size: 1.2em;
    color: #2c3e50;
    font-weight: 500;
    line-height: 1.5;
    text-align: center;
    max-width: 80%;
}

.close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.05);
    color: #2c3e50;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3em;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    z-index: 2;
}

.close:hover {
    background: rgba(0, 0, 0, 0.1);
    border-color: rgba(0, 0, 0, 0.05);
    transform: rotate(90deg);
}

@keyframes modalContentOpen {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes modalContentClose {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(30px);
    }
}

.modal.show .modal-content {
    animation: modalContentOpen 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal.closing .modal-content {
    animation: modalContentClose 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal.closing {
    background-color: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
}

/* Responsive Design */
@media (max-width: 1400px) {
    .grid {
        width: 95%;
    }
}

@media (max-width: 1200px) {
    .grid-item {
        width: 33.333%;
    }
}

@media (max-width: 900px) {
    .grid-item {
        width: 50%;
    }
}

@media (max-width: 600px) {
    .grid-item {
        width: 100%;
    }
}

/* Scroll to Top Button Enhancement */
#scrollToTop {
    background-color: var(--primary-color) !important;
    transition: transform 0.3s ease, background-color 0.3s ease !important;
    box-shadow: 0 2px 10px rgba(62, 172, 196, 0.3);
}

#scrollToTop:hover {
    transform: translateY(-3px);
    background-color: #2d8a9d !important;
}