/**
 * SBX Image Compare.
 *
 * The "before" image sits in normal flow and sets the figure's size; the
 * "after" image is absolutely positioned over it and clipped from the left by
 * --sbx-ic-exposure. A full-bleed range input drives that variable (via the
 * JS), and its thumb is styled as the draggable handle — so the control is a
 * real, focusable, keyboard-operable form element.
 */

.sbx-image-compare {
	--sbx-ic-exposure: 50%;
	--sbx-ic-divider-width: 2px;
	--sbx-ic-divider-color: rgba( 0, 0, 0, 0.9 );
	--sbx-ic-handle-size: clamp( 2.5rem, 8vmin, 4rem );
	--sbx-ic-handle-bg: rgba( 255, 255, 255, 0.9 );
	--sbx-ic-handle-border-color: rgba( 0, 0, 0, 0.9 );
	--sbx-ic-handle-border-width: 2px;
	--sbx-ic-focus-color: hsl( 200 100% 80% );
	--sbx-ic-handle-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23222222' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 6 4 12 9 18'/%3E%3Cpath d='M15 6 20 12 15 18'/%3E%3C/svg%3E");

	position: relative;
	display: block;
	margin: 0;
	overflow: hidden;
	line-height: 0;
}

.sbx-image-compare__img {
	display: block;
	width: 100%;
	height: auto;
}

.sbx-image-compare__img--after {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	clip-path: inset( 0 0 0 var( --sbx-ic-exposure ) );
}

.sbx-image-compare__divider {
	position: absolute;
	inset-block: 0;
	left: var( --sbx-ic-exposure );
	width: var( --sbx-ic-divider-width );
	transform: translateX( -50% );
	background: var( --sbx-ic-divider-color );
	pointer-events: none;
	z-index: 3;
}

/* Each label sits in a full-size layer clipped to its own image region (the
   same --sbx-ic-exposure that clips the image), so the divider reveals/hides it
   as it sweeps across — and vice versa for the other side. */
.sbx-image-compare__layer {
	position: absolute;
	inset: 0;
	z-index: 4;
	pointer-events: none;
}

.sbx-image-compare__layer--before {
	clip-path: inset( 0 calc( 100% - var( --sbx-ic-exposure ) ) 0 0 );
}

.sbx-image-compare__layer--after {
	clip-path: inset( 0 0 0 var( --sbx-ic-exposure ) );
}

.sbx-image-compare__label {
	position: absolute;
	bottom: 0.75rem;
	margin: 0;
	padding: 0.15em 0.5em;
	font-size: 0.85rem;
	line-height: normal;
	color: #fff;
	background: rgba( 0, 0, 0, 0.55 );
	border-radius: 0.25rem;
}

.sbx-image-compare__label--before {
	left: 0.75rem;
}

.sbx-image-compare__label--after {
	right: 0.75rem;
}

/* Full-bleed range input; its thumb is the handle. */
.sbx-image-compare__range {
	position: absolute;
	inset: 0;
	width: calc( 100% + var( --sbx-ic-handle-size ) );
	height: 100%;
	margin: 0 calc( var( --sbx-ic-handle-size ) / -2 );
	z-index: 5;
	cursor: col-resize;
	background: transparent;
	border: none;
	-webkit-appearance: none;
	appearance: none;
}

.sbx-image-compare__range::-webkit-slider-thumb {
	-webkit-appearance: none;
	width: var( --sbx-ic-handle-size );
	height: var( --sbx-ic-handle-size );
	border-radius: 50%;
	border: var( --sbx-ic-handle-border-width ) solid var( --sbx-ic-handle-border-color );
	background-color: var( --sbx-ic-handle-bg );
	background-image: var( --sbx-ic-handle-icon );
	background-size: 65%;
	background-position: center;
	background-repeat: no-repeat;
	cursor: col-resize;
}

.sbx-image-compare__range::-moz-range-thumb {
	width: var( --sbx-ic-handle-size );
	height: var( --sbx-ic-handle-size );
	border-radius: 50%;
	border: var( --sbx-ic-handle-border-width ) solid var( --sbx-ic-handle-border-color );
	background-color: var( --sbx-ic-handle-bg );
	background-image: var( --sbx-ic-handle-icon );
	background-size: 65%;
	background-position: center;
	background-repeat: no-repeat;
	cursor: col-resize;
}

/* Visible focus ring on the handle (keyboard users). */
.sbx-image-compare__range:focus-visible {
	outline: none;
}

.sbx-image-compare__range:focus-visible::-webkit-slider-thumb {
	box-shadow: 0 0 0 var( --sbx-ic-handle-border-width ) var( --sbx-ic-focus-color );
}

.sbx-image-compare__range:focus-visible::-moz-range-thumb {
	box-shadow: 0 0 0 var( --sbx-ic-handle-border-width ) var( --sbx-ic-focus-color );
}

.sbx-image-compare__placeholder {
	margin: 0;
	padding: 2rem;
	text-align: center;
	line-height: normal;
	color: var( --neutral-medium, #777 );
	background: var( --neutral-ultra-light, #f3f3f3 );
}

/* Keep the divider visible in forced-colours / high-contrast mode. */
@media ( forced-colors: active ) {
	.sbx-image-compare__divider {
		background: CanvasText;
	}
}

/* No-JS / pre-init fallback: the range handle only does something once the
   script wires it up (it sets data-sbx-ic-ready). Until then, hide it so it
   doesn't look interactive — the inline start position still shows a static
   before/after split with the divider. */
.sbx-image-compare:not( [data-sbx-ic-ready="true"] ) .sbx-image-compare__range {
	display: none;
}
