/* Comparison Modal / Backdrop */

.ii-compare-backdrop {
	position: fixed;
	inset: 0;
	z-index: 9995;
	background: rgba(6, 6, 10, 0.92);
	backdrop-filter: blur(16px) saturate(0.8);
	-webkit-backdrop-filter: blur(16px) saturate(0.8);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 20px;
	opacity: 0;
	transition: opacity 0.35s ease;
	overscroll-behavior: none;
}

.ii-compare-backdrop.is-open {
	opacity: 1;
}

.ii-compare-modal {
	position: relative;
	width: 100%;
	max-width: 1280px;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 20px;
	transform: scale(0.94) translateY(16px);
	transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.ii-compare-backdrop.is-open .ii-compare-modal {
	transform: scale(1) translateY(0);
}

/* Before–After Slider Core */

.ii-compare-stage {
	position: relative;
	width: 100%;
	overflow: hidden;
	border-radius: 16px;
	box-shadow:
		0 0 0 1px rgba(255, 255, 255, 0.07),
		0 32px 64px rgba(0, 0, 0, 0.6),
		0 8px 24px rgba(0, 0, 0, 0.4);
	user-select: none;
	touch-action: pan-y pinch-zoom;
	max-height: calc(100svh - 200px);
	background: #0c0c12;
	animation: iiCompareStageIn 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both;
	min-height: 260px;
}

.ii-compare-stage.has-loaded {
	min-height: 0;
}

@keyframes iiCompareStageIn {
	from {
		opacity: 0;
		transform: scale(0.97);
	}

	to {
		opacity: 1;
		transform: scale(1);
	}
}

.ii-compare-img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: contain;
	object-position: center;
	display: block;
	pointer-events: none;
	will-change: clip-path;
}

.ii-compare-img-before {
	z-index: 1;
}

.ii-compare-img-after {
	z-index: 2;
	clip-path: inset(0 0 0 50%);
	transition: clip-path 0s;
}

/* Skeleton while images load */
.ii-compare-img-placeholder {
	position: absolute;
	inset: 0;
	z-index: 10;
	border-radius: 16px;
	overflow: hidden;
	display: flex;
}

.ii-compare-img-placeholder::before,
.ii-compare-img-placeholder::after {
	content: '';
	flex: 1;
	background: linear-gradient(
		90deg,
		var(--ii-bg-secondary, #f3f4f6) 25%,
		var(--ii-bg-hover, #e5e7eb) 50%,
		var(--ii-bg-secondary, #f3f4f6) 75%
	);
	background-size: 400% 100%;
	animation: iiSkeletonShimmer 1.8s infinite linear;
}

.ii-compare-img-placeholder::after {
	animation-delay: 0.15s;
}

.ii-compare-img-placeholder .ii-cph-divider {
	position: absolute;
	inset: 0;
	left: 50%;
	width: 2px;
	transform: translateX(-50%);
	background: rgba(0, 0, 0, 0.12);
	z-index: 1;
}

.ii-compare-img-placeholder .ii-cph-handle {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.08);
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: center;
}

.ii-compare-img-placeholder .ii-cph-handle svg {
	opacity: 0.25;
}

.ii-compare-img-placeholder .ii-cph-label {
	position: absolute;
	bottom: 18px;
	height: 22px;
	border-radius: 6px;
	background: rgba(0, 0, 0, 0.08);
	z-index: 2;
}

.ii-compare-img-placeholder .ii-cph-label-before {
	left: 16px;
	width: 64px;
}

.ii-compare-img-placeholder .ii-cph-label-after {
	right: 16px;
	width: 64px;
}

/* Divider line */
.ii-compare-divider {
	position: absolute;
	top: 0;
	bottom: 0;
	left: 50%;
	width: 2px;
	background: linear-gradient(
		180deg,
		transparent 0%,
		rgba(255, 255, 255, 0.95) 8%,
		rgba(255, 255, 255, 0.95) 92%,
		transparent 100%
	);
	transform: translateX(-50%);
	z-index: 10;
	pointer-events: none;
	will-change: left;
	box-shadow: 0 0 12px rgba(255, 255, 255, 0.3);
}

/* Drag handle */
.ii-compare-handle {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: #ffffff;
	box-shadow:
		0 0 0 3px rgba(37, 99, 235, 0.25),
		0 4px 20px rgba(0, 0, 0, 0.4),
		0 2px 8px rgba(0, 0, 0, 0.25);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 11;
	cursor: ew-resize;
	pointer-events: all;
	transition:
		box-shadow 0.2s ease,
		background 0.2s ease,
		transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1);
	will-change: left, transform;
}

.ii-compare-handle:hover,
.ii-compare-stage.is-dragging .ii-compare-handle {
	box-shadow:
		0 0 0 4px rgba(37, 99, 235, 0.35),
		0 8px 28px rgba(0, 0, 0, 0.45);
	background: #f0f6ff;
	transform: translate(-50%, -50%) scale(1.08);
}

.ii-compare-handle-icon {
	display: flex;
	align-items: center;
	gap: 3px;
	color: var(--ii-accent, #2563eb);
}

.ii-compare-handle-icon svg {
	width: 12px;
	height: 12px;
	flex-shrink: 0;
}

/* Pulse ring on initial load (stops after first interaction) */
.ii-compare-handle::before {
	content: '';
	position: absolute;
	inset: -8px;
	border-radius: 50%;
	border: 2px solid rgba(37, 99, 235, 0.4);
	animation: iiCompareHandlePulse 2s ease-out 0.8s 3;
	pointer-events: none;
}

.ii-compare-stage.is-dragging .ii-compare-handle::before,
.ii-compare-stage.has-interacted .ii-compare-handle::before {
	animation: none;
	display: none;
}

@keyframes iiCompareHandlePulse {
	0% {
		transform: scale(1);
		opacity: 0.7;
	}

	100% {
		transform: scale(1.8);
		opacity: 0;
	}
}

/* Wide hit zone for easier grabbing */
.ii-compare-divider-hit {
	position: absolute;
	top: 0;
	bottom: 0;
	left: 50%;
	width: 48px;
	transform: translateX(-50%);
	z-index: 9;
	cursor: ew-resize;
	will-change: left;
}

/* Smooth center animation */
.ii-compare-stage.is-animating-to-center .ii-compare-img-after,
.ii-compare-stage.is-animating-to-center .ii-compare-divider,
.ii-compare-stage.is-animating-to-center .ii-compare-handle,
.ii-compare-stage.is-animating-to-center .ii-compare-divider-hit,
.ii-compare-stage.is-animating-to-center .ii-compare-readout {
	transition:
		left 0.4s cubic-bezier(0.2, 0.8, 0.2, 1),
		clip-path 0.4s cubic-bezier(0.2, 0.8, 0.2, 1),
		transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Labels & Readout */

.ii-compare-label {
	position: absolute;
	top: 14px;
	z-index: 8;
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 5px 12px 5px 8px;
	border-radius: var(--ii-radius-rounded);
	font-size: 12px;
	font-weight: 600;
	letter-spacing: normal;
	text-transform: none;
	pointer-events: none;
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	border: 1px solid rgba(255, 255, 255, 0.14);
	font-family: var(--ii-font-body, Inter, sans-serif);
	white-space: nowrap;
	max-width: calc(50% - 60px);
	overflow: hidden;
	text-overflow: ellipsis;
	transition: opacity 0.2s ease;
}

.ii-compare-label-before {
	left: 14px;
	background: rgba(20, 20, 28, 0.78);
	color: rgba(255, 255, 255, 0.9);
}

.ii-compare-label-after {
	right: 14px;
	background: rgba(37, 99, 235, 0.82);
	color: #ffffff;
}

.ii-compare-label-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	flex-shrink: 0;
}

.ii-compare-label-before .ii-compare-label-dot {
	background: rgba(255, 255, 255, 0.6);
}

.ii-compare-label-after .ii-compare-label-dot {
	background: rgba(255, 255, 255, 0.9);
}

.ii-compare-stage.is-dragging .ii-compare-label {
	opacity: 0.4;
}

/* Percentage readout near handle bottom */
.ii-compare-readout {
	position: absolute;
	bottom: 14px;
	left: 50%;
	transform: translateX(-50%);
	background: rgba(10, 10, 16, 0.82);
	backdrop-filter: blur(10px);
	border: 1px solid rgba(255, 255, 255, 0.1);
	color: rgba(255, 255, 255, 0.85);
	font-size: 11px;
	font-weight: 600;
	padding: 4px 10px;
	border-radius: 10px;
	z-index: 12;
	pointer-events: none;
	white-space: nowrap;
	font-family: 'SFMono-Regular', 'Consolas', monospace;
	will-change: left, transform;
	opacity: 0;
	transition: opacity 0.15s ease;
}

.ii-compare-stage.is-dragging .ii-compare-readout,
.ii-compare-stage.show-readout .ii-compare-readout {
	opacity: 1;
}

/* Controls Bar */

.ii-compare-controls {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	gap: 12px;
	padding: 0 4px;
}

.ii-compare-controls-left {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
	flex: 1;
}

.ii-compare-controls-center {
	display: flex;
	align-items: center;
	gap: 6px;
	flex-shrink: 0;
}

.ii-compare-controls-right {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-shrink: 0;
}

/* Info pill */
.ii-compare-info-pill {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 5px 10px;
	border-radius: 8px;
	font-size: 11px;
	font-weight: 500;
	color: rgba(200, 200, 215, 0.85);
	background: rgba(255, 255, 255, 0.06);
	border: 1px solid rgba(255, 255, 255, 0.08);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 220px;
	font-family: var(--ii-font-body, Inter, sans-serif);
}

.ii-compare-info-pill svg {
	flex-shrink: 0;
	opacity: 0.7;
}

/* Control buttons */
.ii-compare-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	height: 36px;
	padding: 0 14px;
	border-radius: 10px;
	border: 1px solid rgba(255, 255, 255, 0.12);
	background: rgba(255, 255, 255, 0.07);
	color: rgba(220, 220, 235, 0.9);
	font-size: 12px;
	font-weight: 600;
	cursor: pointer;
	transition:
		background 0.18s ease,
		border-color 0.18s ease,
		color 0.18s ease,
		transform 0.12s ease;
	font-family: var(--ii-font-body, Inter, sans-serif);
	white-space: nowrap;
	outline: none;
}

.ii-compare-btn:hover {
	background: rgba(255, 255, 255, 0.13);
	border-color: rgba(255, 255, 255, 0.22);
	color: #ffffff;
}

.ii-compare-btn:active {
	transform: scale(0.95);
}

.ii-compare-btn:focus-visible {
	box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.5);
}

.ii-compare-btn.is-icon-only {
	width: 36px;
	padding: 0;
}

.ii-compare-btn-swap svg {
	transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.ii-compare-btn-swap:hover svg {
	transform: rotate(180deg);
}

.ii-compare-btn-reset {
	background: rgba(37, 99, 235, 0.15);
	border-color: rgba(37, 99, 235, 0.35);
	color: #90b8fd;
}

.ii-compare-btn-reset:hover {
	background: rgba(37, 99, 235, 0.25);
	border-color: rgba(37, 99, 235, 0.55);
	color: #c0d8ff;
}

.ii-compare-btn-close {
	background: rgba(239, 68, 68, 0.12);
	border-color: rgba(239, 68, 68, 0.25);
	color: rgba(248, 113, 113, 0.9);
}

.ii-compare-btn-close:hover {
	background: rgba(239, 68, 68, 0.22);
	border-color: rgba(239, 68, 68, 0.45);
	color: #fca5a5;
}

.ii-compare-pct-display {
	min-width: 44px;
	text-align: center;
	font-size: 12px;
	font-weight: 700;
	color: rgba(200, 200, 215, 0.75);
	font-family: 'SFMono-Regular', 'Consolas', monospace;
	letter-spacing: 0.02em;
}

/* Reduced Motion */

@media (prefers-reduced-motion: reduce) {
	.ii-compare-backdrop,
	.ii-compare-modal,
	.ii-compare-stage,
	.ii-compare-handle,
	.ii-compare-cancel-bar {
		transition: none;
		animation: none;
	}

	.ii-compare-handle::before {
		display: none;
	}

	@keyframes iiComparePulse {
		from {
		}

		to {
		}
	}

	@keyframes iiCompareHandlePulse {
		from {
		}

		to {
		}
	}

	@keyframes iiCompareCancelBarIn {
		from {
		}

		to {
		}
	}
}

/* Dark Theme */

[data-theme='dark'] .ii-compare-backdrop {
	background: rgba(4, 4, 8, 0.95);
}

[data-theme='dark'] .ii-compare-img-placeholder::before,
[data-theme='dark'] .ii-compare-img-placeholder::after {
	background-image: linear-gradient(
		90deg,
		var(--ii-dk-shimmer-base, #18181e) 25%,
		var(--ii-dk-shimmer-peak, #1f1f26) 50%,
		var(--ii-dk-shimmer-base, #18181e) 75%
	);
}

[data-theme='dark'] .ii-compare-img-placeholder .ii-cph-divider {
	background: rgba(255, 255, 255, 0.08);
}

[data-theme='dark'] .ii-compare-img-placeholder .ii-cph-handle {
	background: rgba(255, 255, 255, 0.06);
}

[data-theme='dark'] .ii-compare-img-placeholder .ii-cph-label {
	background: rgba(255, 255, 255, 0.06);
}

/* Cancel bar reads well on both themes since it uses accent blue */

/* Responsive */

@media (max-width: 768px) {
	.ii-compare-backdrop {
		padding: 12px;
	}

	.ii-compare-modal {
		gap: 12px;
	}

	.ii-compare-stage {
		max-height: calc(100svh - 160px);
		border-radius: 12px;
	}

	.ii-compare-handle {
		width: 40px;
		height: 40px;
	}

	.ii-compare-handle-icon svg {
		width: 16px;
		height: 16px;
	}

	/* Cancel bar: compress on small screens */
	.ii-compare-cancel-bar {
		padding: 8px 12px;
	}

	.ii-compare-cancel-bar-text {
		font-size: 12px;
	}

	.ii-compare-controls {
		flex-wrap: wrap;
		gap: 8px;
	}

	.ii-compare-controls-left {
		order: 2;
		flex: 1 1 100%;
	}

	.ii-compare-controls-center,
	.ii-compare-controls-right {
		order: 1;
		flex: 0 0 auto;
	}

	.ii-compare-controls-center {
		margin: 0 auto;
	}

	.ii-compare-info-pill span {
		display: none;
	}

	.ii-compare-info-pill {
		padding: 5px 8px;
		max-width: none;
	}

	.ii-compare-label {
		font-size: 10px;
		padding: 4px 8px 4px 6px;
	}

	/* Wider drag hit area on touch */
	.ii-compare-divider-hit {
		width: 64px;
	}
}

@media (max-width: 480px) {
	.ii-compare-btn .ii-compare-btn-text {
		display: none;
	}

	.ii-compare-btn:not(.is-icon-only) {
		width: 36px;
		padding: 0;
	}

	.ii-compare-cancel-bar-text {
		display: none;
		/* icon only on tiny screens */
	}
}
