.aipe-container {
	--aipe-theme-color: #2271b1;
	max-width: 480px;
	margin: 0 auto;
	padding: 24px;
	border: 1px solid #e0e0e0;
	border-radius: 12px;
	font-family: inherit;
	box-sizing: border-box;
}

.aipe-container * {
	box-sizing: border-box;
}

/* Themes often reset [hidden] without !important; keep our panels truly hidden. */
.aipe-container [hidden] {
	display: none !important;
}

.aipe-frame {
	position: relative;
	width: 100%;
	aspect-ratio: var(--aipe-frame-ratio, 3 / 4);
	max-height: 640px;
	overflow: hidden;
	border: 2px dashed #ccc;
	border-radius: 12px;
	background: #fafafa;
	--aipe-reveal: 100%;
}

.aipe-frame.is-empty {
	cursor: pointer;
}

.aipe-frame.is-busy,
.aipe-frame.is-result {
	border-style: solid;
	border-color: transparent;
}

.aipe-frame:focus-visible {
	outline: 2px solid var(--aipe-theme-color);
	outline-offset: 2px;
}

.aipe-frame-placeholder {
	position: absolute;
	inset: 0;
	display: none;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 10px;
	padding: 24px;
	color: #888;
	text-align: center;
}

.aipe-frame.is-empty .aipe-frame-placeholder {
	display: flex;
}

.aipe-frame:not(.is-empty) .aipe-frame-placeholder {
	display: none;
}

.aipe-frame-placeholder-icon {
	width: 40px;
	height: 40px;
}

.aipe-frame-placeholder-text {
	font-weight: 600;
}

.aipe-frame-img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: none;
	pointer-events: none;
}

.aipe-frame.is-busy .aipe-frame-before,
.aipe-frame.is-result .aipe-frame-before,
.aipe-frame.is-result .aipe-frame-after {
	display: block;
}

.aipe-frame.is-empty .aipe-frame-img {
	display: none;
}

.aipe-frame-before {
	z-index: 1;
}

.aipe-frame-after {
	z-index: 2;
	clip-path: inset( 0 calc( 100% - var( --aipe-reveal, 100% ) ) 0 0 );
}

.aipe-frame-loading {
	position: absolute;
	inset: 0;
	z-index: 3;
	display: none;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	background: rgba(0, 0, 0, 0.45);
	color: #fff;
	pointer-events: none;
}

.aipe-frame.is-busy .aipe-frame-loading {
	display: flex;
	pointer-events: auto;
}

.aipe-frame:not(.is-busy) .aipe-frame-loading {
	display: none;
}

.aipe-spinner {
	width: 36px;
	height: 36px;
	border: 3px solid rgba(255, 255, 255, 0.35);
	border-top-color: #fff;
	border-radius: 50%;
	animation: aipe-spin 0.8s linear infinite;
}

@keyframes aipe-spin {
	to {
		transform: rotate(360deg);
	}
}

.aipe-frame-loading-label {
	font-size: 0.9em;
	font-weight: 500;
}

.aipe-compare {
	position: absolute;
	inset: 0;
	z-index: 4;
	display: none;
	pointer-events: none;
}

.aipe-frame.is-result .aipe-compare {
	display: block;
}

.aipe-frame:not(.is-result) .aipe-compare {
	display: none;
}

.aipe-compare-handle {
	position: absolute;
	top: 0;
	bottom: 0;
	left: var(--aipe-reveal, 100%);
	width: 0;
	transform: translateX(-50%);
	pointer-events: auto;
	cursor: ew-resize;
	touch-action: none;
}

.aipe-compare-handle::before {
	content: '';
	position: absolute;
	top: 0;
	bottom: 0;
	left: 50%;
	width: 2px;
	background: #fff;
	transform: translateX(-50%);
	box-shadow: 0 0 4px rgba(0, 0, 0, 0.4);
}

.aipe-compare-handle-grip {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 34px;
	height: 34px;
	border-radius: 50%;
	background: #fff;
	transform: translate(-50%, -50%);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.aipe-compare-handle-grip::before,
.aipe-compare-handle-grip::after {
	content: '';
	position: absolute;
	top: 50%;
	width: 0;
	height: 0;
	border-top: 5px solid transparent;
	border-bottom: 5px solid transparent;
	transform: translateY(-50%);
}

.aipe-compare-handle-grip::before {
	left: 8px;
	border-right: 6px solid #999;
}

.aipe-compare-handle-grip::after {
	right: 8px;
	border-left: 6px solid #999;
}

.aipe-controls {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 14px;
	margin-top: 14px;
}

.aipe-arrow {
	width: 34px;
	height: 34px;
	border-radius: 50%;
	border: 1px solid #ddd;
	background: #fff;
	color: #333;
	font-size: 1.2em;
	line-height: 1;
	cursor: pointer;
}

.aipe-arrow:hover {
	background: #f2f2f2;
}

.aipe-controls-caption {
	font-size: 0.85em;
	color: #777;
}

.aipe-error {
	margin-top: 16px;
	padding: 10px 14px;
	background: #fdecea;
	color: #611a15;
	border-radius: 6px;
	font-size: 0.9em;
}

.aipe-actions {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 12px;
	margin-top: 18px;
	flex-wrap: wrap;
}

.aipe-reset-btn {
	padding: 10px 18px;
	background: transparent;
	border: 1px solid var(--aipe-theme-color);
	border-radius: 6px;
	color: var(--aipe-theme-color);
	font-weight: 500;
	cursor: pointer;
}

.aipe-download-btn {
	display: inline-block;
	padding: 10px 18px;
	background: var(--aipe-theme-color);
	color: #fff;
	border-radius: 6px;
	text-decoration: none;
	font-weight: 500;
}

@media ( max-width: 480px ) {
	.aipe-container {
		padding: 16px;
		border-radius: 0;
	}
}
