.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;

    /* One radius for the frame and the photo in it. Pages change --photo-radius, not border-radius: a page's
       border-radius rule would outrank the fullscreen one below and round the fullscreen view's corners */
    --photo-radius: var(--border-radius);
    border-radius: var(--photo-radius);

    /* A frame, so photos of night or deep space don't melt into a dark page. An outline: it takes no room, the
       slider's geometry stays the photo's */
    outline: solid var(--color-border-strong) 1px;

    /* Not clipped: the slider's handle goes over the image's edges, centered on the divisor line */
    --thumb-size: 48px;

    /* Its overhang, half a thumb, stays within the page's 20px phone gutter */
    @media all and (max-width: 600px) {
        --thumb-size: 40px;
    }

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

        > .title {
            position: absolute;
            bottom: 10px;
            left: 10px;
            font-family: var(--font-family-mono);
            font-size: 12px;
            line-height: 1.5;
            padding: 5px 10px;
            border-radius: 6px;
            background: var(--color-overlay);
            color: var(--color-on-overlay);

            > a {
                color: inherit;
                text-decoration: none;
            }
        }

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

        > .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(--photo-radius);
            overflow: hidden;
        }

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

            /* The line itself, faded in from the photo's edges by beforeAndAfter.js: at an edge it would run past the
               rounded corners. A layer of its own, so the tooltip it carries doesn't fade with it */
            &::before {
                content: '';
                position: absolute;
                inset: 0;
                background: #FFFFFF;
                opacity: var(--line-opacity, 0);
            }

            > .tooltip {
                position: absolute;
                top: calc(50% + 3px);
                left: 40px;
                transform: translateY(-50%);
                background: var(--color-overlay);
                color: var(--color-on-overlay);
                padding: 6px 12px;
                /* Rounded corners, not a pill: the arrow needs a straight edge to sit on */
                border-radius: var(--border-radius-small);
                font-size: 13px;
                font-weight: 500;
                white-space: nowrap;
                pointer-events: none;

                /* It fades out, sliding toward the handle, once any slider is first used. visibility switches
                   after the fade, so the hidden tooltip leaves the accessibility tree too */
                transition:
                    opacity 300ms ease,
                    transform 300ms ease,
                    visibility 0s linear 300ms;

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

            > .tooltip.hidden {
                opacity: 0;
                transform: translate(-12px, -50%);
                visibility: hidden;
            }

            @media (prefers-reduced-motion: reduce) {
                > .tooltip.hidden {
                    transform: translateY(-50%);
                }
            }
        }

        > input[type=range] {
            z-index: 1;
            position: absolute;
            /* The thumb's center travels from the input's start + half the thumb to its end - half the thumb:
               overhanging the image by half a thumb on each side puts it exactly on the divisor at every value */
            left: calc(var(--thumb-size) / -2);
            right: calc(var(--thumb-size) / -2);
            margin: 0;
            top: 50%;
            background: none;
            width: auto;

            -webkit-appearance: none;

            &:focus {
                outline: none;
            }

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

            &::-webkit-slider-thumb {
                height: var(--thumb-size);
                width: var(--thumb-size);
                margin-top: calc(var(--thumb-size) / -2);

                background-color: #FFFFFF;
                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="%2309090B" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m9 18l-6-6l6-6m6 0l6 6l-6 6"/></svg>');
                background-size: 22px;
                background-position: center;
                background-repeat: no-repeat;
                border-radius: 50%;
                box-shadow: 0 4px 20px rgba(0, 0, 0, .35);

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

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

            &::-moz-range-thumb {
                border: none;
                height: var(--thumb-size);
                width: var(--thumb-size);
                margin-top: calc(var(--thumb-size) / -2);

                background-color: #FFFFFF;
                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="%2309090B" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m9 18l-6-6l6-6m6 0l6 6l-6 6"/></svg>');
                background-size: 22px;
                background-position: center;
                background-repeat: no-repeat;
                border-radius: 50%;
                box-shadow: 0 4px 20px rgba(0, 0, 0, .35);

                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: 1;
        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;
        outline: none;
        margin: 0;
        max-width: 100vw;
        aspect-ratio: auto !important;
        display: flex;
        align-items: center;
        justify-content: center;

        /* The photo's own box, as large as the window allows less half a thumb on each side: the slider spans the
           photo, not the black bars, and its handle stays on screen. --aspect-ratio is the photo's, set by
           beforeAndAfter.js once the photo's size is known */
        > .content {
            width: min(calc(100vw - var(--thumb-size)), calc(100dvh * var(--aspect-ratio)));
            height: min(100dvh, calc((100vw - var(--thumb-size)) / var(--aspect-ratio)));

            > 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);
    }
}
