.mg-bas {
    --mg-bas-position: 50%;
    width: 100%;
    position: relative;
    display: block;
}

.mg-bas,
.mg-bas * {
    box-sizing: border-box;
}

.mg-bas__viewport {
    position: relative;
    width: 100%;
    min-height: 150px;
    height: 520px;
    overflow: hidden;
    background: #e9edf2;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    isolation: isolate;
    outline: none;
    cursor: ew-resize;
}

.mg-bas__viewport:focus-visible {
    outline: 2px solid #2479F5;
    outline-offset: 3px;
}

/*
 * Both image layers occupy the ENTIRE viewport.
 * The before layer alone is clipped by its width.
 * This is the key fix: the before image must never become narrower
 * when the slider moves, otherwise it gets stretched/squeezed.
 */
.mg-bas__layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.mg-bas__layer--after {
    z-index: 1;
}

.mg-bas__layer--before {
    z-index: 2;
    width: var(--mg-bas-position);
}

.mg-bas__image {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: none !important;
    max-height: none;
    object-fit: cover;
    object-position: center center;
    pointer-events: none;
    -webkit-user-drag: none;
    user-select: none;
}

/* Keep the before image at the viewport size even though its parent is clipped. */
.mg-bas__layer--before .mg-bas__image {
    /* JS sets this to the full viewport width in px, matching the reference implementation. */
    width: 100%;
    min-width: 100%;
    max-width: none !important;
    height: 100%;
}

.mg-bas__divider {
    position: absolute;
    z-index: 5;
    top: 0;
    bottom: 0;
    left: var(--mg-bas-position);
    width: 2px;
    transform: translateX(-50%);
    background: #fff;
    box-shadow: 0 0 8px rgba(0, 0, 0, .25);
    pointer-events: none;
}

.mg-bas__handle {
    position: absolute;
    z-index: 8;
    top: 50%;
    left: var(--mg-bas-position);
    width: 48px;
    height: 48px;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translate(-50%, -50%);
    border: 2px solid #fff;
    border-radius: 50%;
    background: #2479F5;
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: ew-resize;
    box-shadow: 0 2px 12px rgba(0, 0, 0, .25);
    appearance: none;
    -webkit-appearance: none;
    touch-action: none;
    transition: box-shadow .15s ease, transform .15s ease;
}

.mg-bas__handle:hover {
    box-shadow: 0 3px 16px rgba(0, 0, 0, .32);
}

.mg-bas__handle.is-dragging {
    cursor: grabbing;
    box-shadow: 0 4px 18px rgba(0, 0, 0, .35);
    transform: translate(-50%, -50%) scale(1.03);
}

.mg-bas__handle:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 3px;
}

.mg-bas__handle svg {
    display: block;
    width: 1em;
    height: 1em;
    fill: currentColor;
}

.mg-bas__handle i {
    display: block;
    line-height: 1;
}

.mg-bas__label {
    position: absolute;
    z-index: 9;
    bottom: 12px;
    display: inline-flex;
    align-items: center;
    padding: 7px 10px;
    color: #fff;
    background: rgba(0, 0, 0, .55);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: .06em;
    pointer-events: none;
    box-sizing: border-box;
    white-space: nowrap;
}

.mg-bas__label--before {
    left: 12px;
}

.mg-bas__label--after {
    right: 12px;
}

.mg-bas__empty {
    width: 100%;
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    border: 1px dashed #bbb;
    background: #fafafa;
    color: #555;
    text-align: center;
}

@media (max-width: 767px) {
    .mg-bas__label {
        bottom: 8px;
        font-size: 10px;
    }

    .mg-bas__label--before {
        left: 8px;
    }

    .mg-bas__label--after {
        right: 8px;
    }
}
