/* Before/after image comparison (_includes/image-compare.liquid). */

.compare-figure {
    display: block;
    margin: 1.5rem 0;
}

.compare {
    --pos: 50%;
    position: relative;
    display: grid;
    overflow: hidden;
    border: 1px solid #c8ccd2;
    border-radius: 6px;
    background: #e9edf2;
    user-select: none;
    -webkit-user-select: none;
}

/* Both images share one grid cell, so the frame is as large as the larger of the two. */
.compare-img {
    grid-area: 1 / 1;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* The left image is cut at the slider: only what is left of it shows. */
.compare-before {
    clip-path: inset(0 calc(100% - var(--pos)) 0 0);
}

.compare-tag {
    position: absolute;
    top: 0.6rem;
    padding: 0.15rem 0.55rem;
    border-radius: 4px;
    background: rgba(20, 24, 32, 0.7);
    color: #fff;
    font-size: 0.8rem;
    line-height: 1.4;
    pointer-events: none;
}

.compare-tag-before { left: 0.6rem; }
.compare-tag-after { right: 0.6rem; }

/* Divider line, with a round grip centered on it. */
.compare-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--pos);
    width: 2px;
    margin-left: -1px;
    background: #fff;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.45);
    pointer-events: none;
}

.compare-handle::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2.4rem;
    height: 2.4rem;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.4);
}

/* Left and right chevrons. */
.compare-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1.4rem;
    height: 1.4rem;
    transform: translate(-50%, -50%);
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23445' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 6l-6 6 6 6M15 6l6 6-6 6'/%3E%3C/svg%3E") center / contain no-repeat;
}

/*
 * A transparent range input covers the whole image: dragging anywhere moves the slider, and keyboard,
 * screen reader and touch support come with the native control. Vertical swipes still scroll the page.
 */
.compare-slider {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: ew-resize;
    touch-action: pan-y;
    -webkit-appearance: none;
    appearance: none;
}

.compare-slider:focus-visible ~ .compare-handle::before {
    outline: 3px solid #3b82f6;
    outline-offset: 2px;
}
