.beforeAndAfter {
    position: relative;
    max-width: 100%;
    width: 100%;
    margin: 0 auto;

    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -o-user-select: none;
    user-select: none;

    border-radius: var(--border-radius);

    > .content {
        position: relative;
        width: 100%;
        display: flow-root; /* contains the floated .image.before */

        > .title {
            position: absolute;
            bottom: 10px;
            right: 10px;
            font-size: 0.7em;
            font-weight: 300;
            padding: 0 .8em;
            border-radius: var(--border-radius-small);
            background: var(--color-background-dark);

            > a {
                text-decoration: none;
            }
        }

        > .image {
            float: left;
            width: 100%;
            border-radius: var(--border-radius);
        }

        > .image.after {
            position: absolute;
            left: 0;
            top: 0;
            clip-path: inset(0px 100% 0px 0px);
        }

        > picture > img {
            float: left;
            width: 100%;
            height: 100%;
            background-position: center;
            background-repeat: no-repeat;
            background-size: 30%;
            border-radius: var(--border-radius);
            overflow: hidden;
        }

        > .divisor {
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0%;
            width: 2px;
            margin-left: -2px;
            content: '';
            z-index: 1;

            > .tooltip {
                position: absolute;
                top: calc(50% + 3px);
                left: 40px;
                transform: translateY(-50%);
                background: #fff;
                color: var(--color-primary);
                padding: 6px 12px;
                border-radius: var(--border-radius-small);
                font-size: var(--font-size-small);
                white-space: nowrap;
                opacity: 1;
                transition: opacity 0.3s ease;
                pointer-events: none;

                &::before {
                    content: '';
                    position: absolute;
                    top: 50%;
                    left: -6px;
                    transform: translateY(-50%);
                    border-width: 6px 6px 6px 0;
                    border-style: solid;
                    border-color: transparent #fff transparent transparent;
                }
            }

            > .tooltip.hidden {
                opacity: 0;
            }
        }

        > input[type=range] {
            z-index: 1;
            position: absolute;
            left: -22px;
            right: -22px;
            top: 50%;
            background: none;
            width: auto;

            -webkit-appearance: none;

            &:focus {
                outline: none;
            }

            &::-webkit-slider-runnable-track {
                background: transparent;
                height: 0px;
            }

            &::-webkit-slider-thumb {
                height: 45px;
                width: 45px;
                margin-top: -22px;

                background-color: var(--color-accent);
                background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="none" stroke="white" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m16 3l4 4l-4 4m4-4H4m4 14l-4-4l4-4m-4 4h16"/></svg>');
                background-size: 20px;
                background-position: center;
                background-repeat: no-repeat;
                border-radius: var(--border-radius);

                cursor: pointer;
                -webkit-appearance: none;
            }

            &::-moz-range-track {
                background: transparent;
                height: 0px;
            }

            &::-moz-range-thumb {
                border: none;
                height: 45px;
                width: 45px;
                margin-top: -22px;

                background-color: var(--color-background-dark);
                background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="none" stroke="white" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m16 3l4 4l-4 4m4-4H4m4 14l-4-4l4-4m-4 4h16"/></svg>');
                background-size: 20px;
                background-position: center;
                background-repeat: no-repeat;
                border-radius: var(--border-radius);

                cursor: pointer;
                -webkit-appearance: none;
            }

            &:-moz-focusring {
                outline: none;
            }

            &:focus::-moz-range-track {
                background: transparent;
            }
        }

        > input[type=range].wobble {
            animation-name: sliderWobble;
            animation-duration: 3s;
            animation-fill-mode: both;
            animation-iteration-count: infinite;
        }
    }

    > .fullscreen-btn {
        position: absolute;
        top: 10px;
        right: 10px;
        z-index: 2;
        width: 34px;
        height: 34px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(0, 0, 0, 0.45);
        border: none;
        border-radius: var(--border-radius-small);
        cursor: pointer;
        color: white;
        padding: 0;
        opacity: 0;
        transition: opacity 0.2s ease;

        svg {
            width: 16px;
            height: 16px;
        }

        .icon-compress {
            display: none;
        }
    }

    &:hover > .fullscreen-btn {
        opacity: 1;
    }

    &.fullscreen {
        position: fixed;
        inset: 0;
        z-index: 9999;
        background: #000;
        border-radius: 0;
        margin: 0;
        max-width: 100vw;
        aspect-ratio: auto !important;
        display: flex;
        align-items: center;
        justify-content: center;

        > .content {
            width: 100%;
            height: 100dvh;

            > img.image.before {
                float: none;
                width: 100%;
                height: 100%;
                object-fit: contain;
                object-position: center;
                border-radius: 0;
            }

            > .image.after {
                width: 100%;
                height: 100%;
                border-radius: 0;

                picture {
                    display: block;
                    width: 100%;
                    height: 100%;
                }

                img, video {
                    display: block;
                    width: 100%;
                    height: 100%;
                    object-fit: contain;
                    object-position: center;
                    border-radius: 0;
                }
            }
        }

        > .fullscreen-btn {
            opacity: 1;

            .icon-expand { display: none; }
            .icon-compress { display: block; }
        }
    }
}

@keyframes sliderWobble {

    35%,
    45% {
        transform: translateX(5px);
    }

    0%,
    30%,
    40%,
    50% {
        transform: translateX(0);
    }
}
