.modal[aria-hidden="true"] {
    display: none;
}

.modal {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    
    isolation: isolate;
    z-index: 9998;

    --animation-duration: 200ms;
    --dialog-from-transform: translateY(-10vh);
    --dialog-to-transform: translateY(-10vh);
}

.modal .backdrop {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: -1;
}

:where(.modal .backdrop) {
    animation-name: open-backdrop;
    animation-duration: var(--animation-duration);
    animation-timing-function: ease;
}

:where(.modal.closing .backdrop) {
    animation-name: close-backdrop;
    animation-duration: var(--animation-duration);
    animation-timing-function: ease;
}

:where(.modal .dialog) {
    animation-name: open-dialog;
    animation-duration: var(--animation-duration);
    animation-timing-function: ease-out;
}

:where(.modal.closing .dialog) {
    pointer-events: none;
    animation-name: close-dialog;
    animation-duration: var(--animation-duration);
    animation-timing-function: ease-out;
}


@keyframes open-dialog {
    from {
        transform: var(--dialog-from-transform);
        opacity: .5;
    }

    to {
        opacity: 1;
    }
}

@keyframes close-dialog {
    to {
        transform: var(--dialog-to-transform);
        opacity: 0;
    }
}

@keyframes open-backdrop {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes close-backdrop {
    to {
        opacity: 0;
    }
}

@media (prefers-reduced-motion) {

    @keyframes open-dialog {
        from {
            transform: none;
            opacity: 0;
        }

        to {
            opacity: 1;
        }
    }

    @keyframes close-dialog {
        to {
            transform: none;
            opacity: 0;
        }
    }
}