/**
 * Before After — Common base CSS ( loads for every style ).
 *
 * Owns the shared skeleton: the frame, the clipped "before" layer, divider,
 * handle and labels for both orientations. The after image sits in normal
 * flow so the frame always sizes itself correctly ( no width / alignment
 * surprises ); a fixed aspect ratio switches it to absolute + cover.
 * Per-style files paint the divider, handle and label chrome.
 * CSS variables drive theme and sizing:
 *   --captwiki-ba-pos           → live divider position ( % )
 *   --captwiki-ba-line          → divider line colour
 *   --captwiki-ba-handle        → handle diameter
 *   --captwiki-ba-handle-bg     → handle background
 *   --captwiki-ba-handle-color  → handle arrow colour
 *   --captwiki-ba-ratio         → fixed aspect ratio ( when set )
 *
 * @package captain-widgets-kit
 * @since   1.7.0
 */

.captwiki-ba {
	--captwiki-ba-line: #ffffff;
	--captwiki-ba-handle: 44px;
	--captwiki-ba-handle-bg: #ffffff;
	--captwiki-ba-handle-color: #1f2937;
	display: block;
	width: 100%;
	max-width: 100%;
	box-sizing: border-box;
}

.captwiki-ba *,
.captwiki-ba *::before,
.captwiki-ba *::after {
	box-sizing: border-box;
}

/* ── Frame ─────────────────────────────────────────────── */
.captwiki-ba__frame {
	position: relative;
	width: 100%;
	overflow: hidden;
	border-radius: 12px;
	-webkit-user-select: none;
	user-select: none;
	touch-action: none;
}

.captwiki-ba--fixed-ratio .captwiki-ba__frame {
	aspect-ratio: var( --captwiki-ba-ratio, 4 / 3 );
}

/* ── Images ────────────────────────────────────────────── */
.captwiki-ba__after-img {
	display: block;
	width: 100%;
	height: auto;
	margin: 0;
}

.captwiki-ba--fixed-ratio .captwiki-ba__after-img {
	position: absolute;
	inset: 0;
	height: 100%;
	object-fit: cover;
}

.captwiki-ba__before {
	position: absolute;
	inset: 0;
	overflow: hidden;
}

.captwiki-ba--horizontal .captwiki-ba__before {
	clip-path: inset( 0 calc( 100% - var( --captwiki-ba-pos, 50% ) ) 0 0 );
}

.captwiki-ba--vertical .captwiki-ba__before {
	clip-path: inset( 0 0 calc( 100% - var( --captwiki-ba-pos, 50% ) ) 0 );
}

.captwiki-ba__before-img {
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
	object-fit: cover;
}

/* ── Divider & handle ──────────────────────────────────── */
.captwiki-ba__divider {
	position: absolute;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: ew-resize;
	outline: none;
}

.captwiki-ba--horizontal .captwiki-ba__divider {
	top: 0;
	bottom: 0;
	left: var( --captwiki-ba-pos, 50% );
	width: 0;
}

.captwiki-ba--vertical .captwiki-ba__divider {
	left: 0;
	right: 0;
	top: var( --captwiki-ba-pos, 50% );
	height: 0;
	cursor: ns-resize;
}

/* The visible line. */
.captwiki-ba__divider::before {
	content: "";
	position: absolute;
	background: var( --captwiki-ba-line );
}

.captwiki-ba--horizontal .captwiki-ba__divider::before {
	top: 0;
	bottom: 0;
	left: -1.5px;
	width: 3px;
}

.captwiki-ba--vertical .captwiki-ba__divider::before {
	left: 0;
	right: 0;
	top: -1.5px;
	height: 3px;
}

.captwiki-ba__divider:focus-visible .captwiki-ba__handle {
	outline: 2px solid #6d5efc;
	outline-offset: 3px;
}

.captwiki-ba__handle {
	position: relative;
	z-index: 1;
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: center;
	width: var( --captwiki-ba-handle );
	height: var( --captwiki-ba-handle );
	background: var( --captwiki-ba-handle-bg );
	border-radius: 50%;
	color: var( --captwiki-ba-handle-color );
	box-shadow: 0 4px 14px rgba( 17, 24, 39, 0.3 );
}

.captwiki-ba__arrows {
	width: 55%;
	height: 55%;
}

.captwiki-ba--vertical .captwiki-ba__arrows {
	transform: rotate( 90deg );
}

/* ── Labels ────────────────────────────────────────────── */
.captwiki-ba__label {
	position: absolute;
	z-index: 1;
	padding: 5px 14px;
	background: rgba( 17, 24, 39, 0.65 );
	border-radius: 6px;
	color: #ffffff;
	font-size: 12px;
	font-weight: 700;
	letter-spacing: 0.06em;
	line-height: 1.4;
	text-transform: uppercase;
	pointer-events: none;
}

.captwiki-ba--horizontal .captwiki-ba__label--before {
	top: 14px;
	left: 14px;
}

.captwiki-ba--horizontal .captwiki-ba__label--after {
	top: 14px;
	right: 14px;
}

.captwiki-ba--vertical .captwiki-ba__label--before {
	top: 14px;
	left: 14px;
}

.captwiki-ba--vertical .captwiki-ba__label--after {
	bottom: 14px;
	left: 14px;
}
