/* Animation keyframes */
@keyframes backdrop-in {
    from { background-color: rgba(0, 0, 0, 0); }
    to   { background-color: rgba(0, 0, 0, 0.75); }
}

@keyframes backdrop-out {
    from { background-color: rgba(0, 0, 0, 0.75); }
    to   { background-color: rgba(0, 0, 0, 0); }
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: translateY(32px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes modal-out {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(16px) scale(0.97);
    }
}

@keyframes modal-in-origin {
    from {
        opacity: 0;
        transform: scale(0.1);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes modal-out-origin {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.1);
    }
}

/* Modal overlay */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
    animation: backdrop-in 0.35s ease forwards;
}

.modal.closing {
    animation: backdrop-out 0.25s ease forwards;
}

/* Modal window */
.modal-window {
    background-color: var(--background-color);
    width: 90%;
    height: 90%;
    border-radius: 10px;
    position: relative;
    max-width: 1200px;
    overflow: hidden;
    opacity: 0;
    transform: translateY(32px) scale(0.96);
}

.modal.show .modal-window {
    animation: modal-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal.closing .modal-window {
    animation: modal-out 0.25s ease-in forwards;
}

.modal.show.from-element .modal-window {
    animation: modal-in-origin 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal.closing.from-element .modal-window {
    animation: modal-out-origin 0.25s ease-in forwards;
}

/* Close button */
.modal-close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 30px;
    height: 30px;
    border: var(--btn-color) 0.1rem solid;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--btn-color);
    background-color: var(--background-color);
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1000;
    transition: background-color 0.2s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.modal-close-btn:hover {
    color: var(--background-color);
    background-color: var(--btn-color);
    border: var(--background-color) 0.1rem solid;
}

/* Modal content styles */
.modal-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 5%;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
    z-index: 1;
}

.modal-container, .modal-dynamic-content {
    touch-action: pan-y;
    -ms-touch-action: pan-y;
    overscroll-behavior: contain;
    -ms-scroll-chaining: none;
}

.modal-title {
    text-align: center;
    color: var(--title-color);
    font-weight: 600;
    font-size: 2rem;
    margin: 1rem 0;
}

.modal-subtitle {
    text-align: left;
    color: var(--title-color);
    font-weight: 600;
    font-size: 1.5rem;
    margin-top: 2rem;
    margin-bottom: 0.5rem;
}

.modal-text {
    padding-top: 0.5rem;
    text-align: justify;
    font-size: 1.1rem;
}

.modal-image {
    width: 100%;
    max-width: 800px;
    object-fit: contain;
    display: block;
    margin: auto;
    padding-top: 2rem;
}

.modal-images-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: stretch;
    gap: 0.5rem;
    width: 100%;
    margin: 0 auto;
}

.modal-images-container > .modal-image {
    flex: 0 1 calc(50% - 0.25rem);
    object-fit: contain;
    margin: 0;
    box-sizing: border-box;
}

.modal-caption {
    text-align: center;
    font-size: 1.25rem;
    margin-top: 1rem;
    margin-bottom: 2rem;
}

.modal-list {
    padding-top: 0.5rem;
    padding-left: 1rem;
    text-align: justify;
    font-size: 1.1rem;
    list-style-type: disc;
    color: var(--paragraph-color);
}

.modal-list li {
    margin-bottom: 0.5rem;
}

@media (pointer: coarse) {
    .modal-container {
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch;
    }
}

.modal-dynamic-content {
    touch-action: pan-y;
}
