/**
 * Castra Before / After Comparison — frontend styles.
 * Scoped entirely under .castra-before-after to avoid leaking into the theme.
 */

.castra-before-after {
	--castra-ba-accent: #c3a06a;
	--castra-ba-accent-soft: #e2c48f;
	--castra-ba-ink: #13141a;
	--castra-ba-surface: #fff;
	--castra-ba-radius: 12px;
	--castra-ba-handle-size: 46px;

	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
	margin: 2.5em auto;
}

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

.castra-ba-wrapper {
	position: relative;
	display: block;
	width: 100%;
	outline: none;
}

.castra-ba-wrapper:focus-visible .castra-ba-stage {
	box-shadow: 0 8px 28px rgba(19, 20, 26, 0.16), 0 0 0 3px rgba(195, 160, 106, 0.45);
}

.castra-ba-stage {
	position: relative;
	width: 100%;
	aspect-ratio: var(--castra-ba-ratio, 4 / 5);
	overflow: hidden;
	border-radius: var(--castra-ba-radius);
	background: #f2ede3;
	box-shadow: 0 8px 24px rgba(19, 20, 26, 0.12);
	cursor: ew-resize;
	touch-action: pan-y;
	transition: box-shadow 0.2s ease;
}

.castra-ba-image {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	object-position: center;
	display: block;
	pointer-events: none;
	user-select: none;
	-webkit-user-drag: none;
}

.castra-ba-after-container {
	position: absolute;
	inset: 0;
	overflow: hidden;
	/* Reveal the "after" image from the right, keeping the "before" image
	   (the unclipped base layer) anchored on the left — so the before/after
	   labels always match the image content on their side of the handle. */
	clip-path: inset(0 0 0 var(--castra-ba-pos, 50%));
	will-change: clip-path;
}

.castra-ba-after-container .castra-ba-image {
	position: absolute;
	inset: 0;
}

/* Divider line + handle. */
.castra-ba-divider {
	position: absolute;
	top: 0;
	bottom: 0;
	left: var(--castra-ba-pos, 50%);
	width: 2px;
	margin-left: -1px;
	background: rgba(255, 255, 255, 0.85);
	box-shadow: 0 0 0 1px rgba(19, 20, 26, 0.08);
	pointer-events: none;
	will-change: left;
}

.castra-ba-handle {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: var(--castra-ba-handle-size);
	height: var(--castra-ba-handle-size);
	min-width: 44px;
	min-height: 44px;
	padding: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 3px;
	border-radius: 50%;
	background: var(--castra-ba-surface);
	border: 1px solid rgba(19, 20, 26, 0.12);
	box-shadow: 0 4px 14px rgba(19, 20, 26, 0.2);
	color: var(--castra-ba-ink);
	cursor: ew-resize;
	pointer-events: auto;
	transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.castra-ba-handle svg {
	display: block;
}

.castra-ba-handle svg:first-child {
	margin-right: -1px;
}

.castra-ba-stage:hover .castra-ba-handle {
	border-color: var(--castra-ba-accent);
	color: var(--castra-ba-accent);
	box-shadow: 0 6px 18px rgba(19, 20, 26, 0.26);
}

.castra-ba-wrapper.is-dragging .castra-ba-handle {
	transform: translate(-50%, -50%) scale(1.08);
	border-color: var(--castra-ba-accent);
	color: var(--castra-ba-accent);
	box-shadow: 0 6px 20px rgba(19, 20, 26, 0.3);
}

.castra-ba-wrapper.is-dragging .castra-ba-after-container,
.castra-ba-wrapper.is-dragging .castra-ba-divider {
	transition: none;
}

/* Smooth, non-laggy transition only when NOT actively dragging (click-to-move
   and the one-time intro animation), disabled instantly on drag start above. */
.castra-ba-after-container,
.castra-ba-divider {
	transition: clip-path 0.2s ease, left 0.2s ease;
}

/* Labels. */
.castra-ba-label {
	position: absolute;
	top: 14px;
	z-index: 2;
	max-width: calc(50% - 22px);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	font-family: inherit;
	font-size: 11px;
	font-weight: 500;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: #fff;
	background: rgba(19, 20, 26, 0.5);
	padding: 5px 10px;
	border-radius: 3px;
	pointer-events: none;
	line-height: 1;
}

.castra-ba-label--before {
	left: 14px;
}

.castra-ba-label--after {
	right: 14px;
}

/* Responsive tweaks. */
@media (max-width: 480px) {
	.castra-before-after {
		margin: 1.75em auto;
	}

	.castra-ba-stage {
		border-radius: 8px;
	}

	.castra-ba-label {
		font-size: 10px;
		padding: 4px 8px;
		top: 10px;
		max-width: calc(50% - 16px);
	}

	.castra-ba-label--before {
		left: 10px;
}

	.castra-ba-label--after {
		right: 10px;
}
}

@media (prefers-reduced-motion: reduce) {
	.castra-ba-after-container,
	.castra-ba-divider,
	.castra-ba-handle {
		transition: none !important;
	}
}
