.uth-image-cropper {
	position: relative;
	z-index: 100;
}

body.uth-crp-open .uth-page,
body.uth-crp-open .uth-tool-hero {
	z-index: 100;
}

body.uth-crp-open {
	overflow: hidden;
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	overscroll-behavior: none;
	touch-action: none;
}

.uth-image-cropper .uth-tool-header {
	max-width: none;
	margin: 0 0 18px;
	text-align: left;
}

.uth-image-cropper .uth-tool-title {
	font-size: clamp(1.65rem, 2.6vw, 2.45rem);
	line-height: 1.16;
}

.uth-image-cropper .uth-tool-description {
	max-width: 760px;
	margin: 8px 0 0;
	font-size: 0.96rem;
	line-height: 1.55;
}

.uth-image-cropper .uth-tool-panel {
	display: grid;
	gap: 18px;
}

/* ---------- Dropzone ---------- */
.uth-crp-dropzone {
	position: relative;
	display: grid;
	place-items: center;
	gap: 8px;
	min-height: 260px;
	padding: 36px 22px;
	text-align: center;
	background: linear-gradient(135deg, rgba(37, 99, 235, 0.06), rgba(15, 118, 110, 0.05));
	border: 2px dashed rgba(37, 99, 235, 0.38);
	border-radius: 20px;
	cursor: pointer;
	transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.uth-crp-dropzone:hover,
.uth-crp-dropzone:focus-within,
.uth-crp-dropzone.is-dragover {
	border-color: var(--uth-primary);
	background: rgba(239, 246, 255, 0.85);
}

.uth-crp-file-input {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.uth-crp-dropzone__icon {
	display: grid;
	place-items: center;
	width: 68px;
	height: 68px;
}

.uth-crp-dropzone__svg {
	width: 52px;
	height: 52px;
	color: var(--uth-primary);
}

.uth-crp-dropzone__title {
	margin: 4px 0 0;
	color: var(--uth-heading);
	font-size: 1.05rem;
	font-weight: 750;
	line-height: 1.4;
}

.uth-crp-dropzone__title strong {
	color: var(--uth-primary);
}

.uth-crp-dropzone__hint {
	margin: 0;
	color: var(--uth-muted);
	font-size: 0.85rem;
	line-height: 1.5;
}

.uth-crp-dropzone__privacy {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	margin: 6px 0 0;
	padding: 6px 12px;
	color: #065f46;
	background: rgba(16, 185, 129, 0.12);
	border-radius: 999px;
	font-size: 0.8rem;
	font-weight: 650;
	line-height: 1.3;
}

.uth-crp-privacy__lock {
	width: 0.8rem;
	height: 0.8rem;
	flex-shrink: 0;
	color: #065f46;
}

/* ---------- Editor layout ---------- */
.uth-crp-editor {
	position: fixed;
	inset: 0;
	z-index: 99990;
	display: flex;
	flex-direction: column;
	gap: 0;
	width: 100vw;
	height: 100vh;
	height: 100dvh;
	padding-bottom: env( safe-area-inset-bottom );
	background: #0f172a;
	color: #e2e8f0;
}

.uth-crp-editor[hidden],
.uth-crp-dropzone[hidden],
.uth-crp-settings[hidden] {
	display: none;
}

/* ---------- Close (new image) ---------- */
.uth-crp-close {
	position: absolute;
	top: 14px;
	right: 16px;
	z-index: 20;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	color: #e2e8f0;
	background: rgba(255, 255, 255, 0.1);
	border: 1px solid rgba(255, 255, 255, 0.16);
	border-radius: 50%;
	cursor: pointer;
	transition: background-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.uth-crp-close svg {
	width: 20px;
	height: 20px;
}

.uth-crp-close:hover,
.uth-crp-close:focus-visible {
	color: #ffffff;
	background: rgba(239, 68, 68, 0.85);
	transform: scale(1.06);
	outline: none;
}
/* ---------- Stage ---------- */
.uth-crp-stage {
	position: relative;
	flex: 1 1 auto;
	min-height: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background:
		linear-gradient(45deg, rgba(148, 163, 184, 0.1) 25%, transparent 25%, transparent 75%, rgba(148, 163, 184, 0.1) 75%),
		linear-gradient(45deg, rgba(148, 163, 184, 0.1) 25%, transparent 25%, transparent 75%, rgba(148, 163, 184, 0.1) 75%);
	background-color: #1e293b;
	background-position: 0 0, 12px 12px;
	background-size: 24px 24px;
}

.uth-crp-stage__inner {
	position: relative;
	flex: 1 1 auto;
	min-height: 0;
	display: grid;
	place-items: center;
	overflow: hidden;
	touch-action: none;
}

.uth-crp-canvas-img {
	position: absolute;
	top: 0;
	left: 0;
	max-width: none;
	max-height: none;
	display: block;
	user-select: none;
	-webkit-user-select: none;
	box-shadow: 0 6px 24px rgba(15, 23, 42, 0.18);
}

/* Before JS sizes the preview, constrain it to the stage so a very large
   photo can never appear "cut off" — it simply fits inside the editor. */
.uth-crp-editor .uth-crp-stage__inner .uth-crp-canvas-img:not(.is-sized) {
	max-width: 100% !important;
	max-height: 100% !important;
	width: auto;
	height: auto;
	inset: 0;
	margin: auto;
}

/* Once JS has applied the exact fit size, let its inline width/height win. */
.uth-crp-editor .uth-crp-stage__inner .uth-crp-canvas-img.is-sized {
	max-width: none !important;
	max-height: none !important;
}

/* The crop overlay and grid are positioned by JS in stage pixels; the padding
   is accounted for so the image keeps a little breathing room on small
   screens and never glues to the very edge of the viewport. */
.uth-crp-grid {
	position: absolute;
	inset: 0;
	pointer-events: none;
	z-index: 2;
	opacity: 1;
	transition: opacity 160ms ease;
}

.uth-crp-grid[hidden] {
	opacity: 0;
}

.uth-crp-grid span {
	position: absolute;
	background: rgba(255, 255, 255, 0.7);
	box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.12);
}

.uth-crp-grid span:nth-child(1) {
	top: 33.333%;
	left: 0;
	right: 0;
	height: 1px;
}

.uth-crp-grid span:nth-child(2) {
	top: 66.666%;
	left: 0;
	right: 0;
	height: 1px;
}

.uth-crp-grid span:nth-child(3) {
	left: 33.333%;
	top: 0;
	bottom: 0;
	width: 1px;
}

.uth-crp-grid span:nth-child(4) {
	left: 66.666%;
	top: 0;
	bottom: 0;
	width: 1px;
}

/* ---------- Crop selection ---------- */
.uth-crp-crop {
	position: absolute;
	z-index: 3;
	outline: 1px solid rgba(255, 255, 255, 0.95);
	box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.5);
	cursor: move;
	touch-action: none;
	-webkit-user-select: none;
	user-select: none;
	-webkit-tap-highlight-color: transparent;
}

.uth-crp-crop:focus-visible {
	outline: 2px solid #ffffff;
	outline-offset: 1px;
}

.uth-crp-crop__dims {
	position: absolute;
	left: 50%;
	top: -26px;
	transform: translateX(-50%);
	padding: 2px 8px;
	color: #ffffff;
	background: rgba(15, 23, 42, 0.8);
	border-radius: 6px;
	font-size: 0.72rem;
	font-weight: 750;
	white-space: nowrap;
	pointer-events: none;
}

.uth-crp-handle {
	position: absolute;
	width: 14px;
	height: 14px;
	background: #ffffff;
	border: 2px solid var(--uth-primary);
	border-radius: 3px;
	z-index: 4;
	touch-action: none;
	-webkit-user-select: none;
	user-select: none;
}

/* Bigger touch targets on mobile so the crop handles are easier to grab. */
@media (pointer: coarse) {
	.uth-crp-handle {
		width: 20px;
		height: 20px;
		border-width: 3px;
	}

	.uth-crp-handle--nw { top: -10px; left: -10px; }
	.uth-crp-handle--n  { top: -10px; left: 50%; margin-left: -10px; }
	.uth-crp-handle--ne { top: -10px; right: -10px; }
	.uth-crp-handle--e  { top: 50%; right: -10px; margin-top: -10px; }
	.uth-crp-handle--se { bottom: -10px; right: -10px; }
	.uth-crp-handle--s  { bottom: -10px; left: 50%; margin-left: -10px; }
	.uth-crp-handle--sw { bottom: -10px; left: -10px; }
	.uth-crp-handle--w  { top: 50%; left: -10px; margin-top: -10px; }
}

.uth-crp-handle--nw { top: -7px; left: -7px; cursor: nwse-resize; }
.uth-crp-handle--n  { top: -7px; left: 50%; margin-left: -7px; cursor: ns-resize; }
.uth-crp-handle--ne { top: -7px; right: -7px; cursor: nesw-resize; }
.uth-crp-handle--e  { top: 50%; right: -7px; margin-top: -7px; cursor: ew-resize; }
.uth-crp-handle--se { bottom: -7px; right: -7px; cursor: nwse-resize; }
.uth-crp-handle--s  { bottom: -7px; left: 50%; margin-left: -7px; cursor: ns-resize; }
.uth-crp-handle--sw { bottom: -7px; left: -7px; cursor: nesw-resize; }
.uth-crp-handle--w  { top: 50%; left: -7px; margin-top: -7px; cursor: ew-resize; }

/* ---------- Stage toolbar ---------- */
.uth-crp-toolsbar {
	flex: none;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	margin: 0;
	padding: 10px 14px;
	background: rgba(15, 23, 42, 0.96);
	border-top: 1px solid rgba(255, 255, 255, 0.14);
	z-index: 10;
}

.uth-crp-toolsbar__group {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 4px;
}

.uth-crp-toolsbar__group + .uth-crp-toolsbar__group {
	padding-left: 10px;
	border-left: 1px solid rgba(255, 255, 255, 0.16);
}

.uth-crp-iconbtn {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	min-height: 36px;
	padding: 6px 11px;
	color: #e2e8f0;
	background: transparent;
	border: 1px solid transparent;
	border-radius: 10px;
	font: inherit;
	font-size: 0.76rem;
	font-weight: 700;
	line-height: 1.2;
	cursor: pointer;
	transition: color 150ms ease, background-color 150ms ease, border-color 150ms ease;
}

.uth-crp-iconbtn svg {
	width: 17px;
	height: 17px;
	flex-shrink: 0;
}

.uth-crp-iconbtn:hover,
.uth-crp-iconbtn:focus-visible {
	color: #ffffff;
	background: rgba(255, 255, 255, 0.14);
	outline: none;
}

.uth-crp-iconbtn.is-active {
	color: #ffffff;
	background: linear-gradient(135deg, var(--uth-primary), #0f766e);
	border-color: transparent;
}

.uth-crp-iconbtn:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.uth-crp-iconbtn--crop {
	color: #ffffff;
	background: linear-gradient(135deg, var(--uth-primary), #0f766e);
	border-color: transparent;
}

.uth-crp-iconbtn--crop:hover,
.uth-crp-iconbtn--crop:focus-visible {
	background: linear-gradient(135deg, #1d4ed8, #0f766e);
}

.uth-crp-iconbtn.is-applied {
	color: #065f46;
	background: rgba(52, 211, 153, 0.9);
	border-color: transparent;
}

.uth-crp-iconbtn--download {
	color: #ffffff;
	background: rgba(255, 255, 255, 0.16);
	border-color: rgba(255, 255, 255, 0.2);
}

.uth-crp-iconbtn--download:hover,
.uth-crp-iconbtn--download:focus-visible {
	background: rgba(16, 185, 129, 0.85);
	border-color: transparent;
}

/* ---------- Settings panel (overlay — image area never shrinks) ---------- */
.uth-crp-settings {
	position: absolute;
	top: 0;
	right: 0;
	bottom: 0;
	z-index: 30;
	width: min(380px, 92vw);
	max-height: 100%;
	overflow: auto;
	margin: 0;
	padding: 20px 18px 24px;
	background: rgba(15, 23, 42, 0.97);
	border-left: 1px solid rgba(255, 255, 255, 0.14);
	box-shadow: -18px 0 40px rgba(0, 0, 0, 0.45);
	animation: uth-crp-settings-in 180ms ease;
}

@keyframes uth-crp-settings-in {
	from {
		transform: translateX(24px);
		opacity: 0;
	}
	to {
		transform: translateX(0);
		opacity: 1;
	}
}

.uth-crp-settings__inner {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: 20px;
}

.uth-crp-settings__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 16px;
}

.uth-crp-settings__title {
	color: #f1f5f9;
	font-size: 1rem;
	font-weight: 800;
}

.uth-crp-settings__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	padding: 0;
	color: #e2e8f0;
	background: rgba(255, 255, 255, 0.08);
	border: 1px solid rgba(148, 163, 184, 0.3);
	border-radius: 50%;
	cursor: pointer;
	transition: color 150ms ease, background-color 150ms ease;
}

.uth-crp-settings__close svg {
	width: 16px;
	height: 16px;
}

.uth-crp-settings__close:hover,
.uth-crp-settings__close:focus-visible {
	color: #ffffff;
	background: rgba(239, 68, 68, 0.85);
	outline: none;
}

.uth-crp-control {
	display: grid;
	gap: 8px;
	min-width: 0;
}

.uth-crp-control__label {
	color: #f1f5f9;
	font-size: 0.84rem;
	font-weight: 750;
	line-height: 1.3;
}

.uth-crp-control__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
}

.uth-crp-control__value {
	min-width: 52px;
	padding: 3px 10px;
	color: #bfdbfe;
	background: rgba(37, 99, 235, 0.22);
	border: 1px solid rgba(96, 165, 250, 0.3);
	border-radius: 999px;
	font-size: 0.8rem;
	font-weight: 800;
	line-height: 1.4;
	text-align: center;
}

.uth-crp-ratios {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.uth-crp-ratio {
	min-width: 44px;
	padding: 6px 10px;
	color: #e2e8f0;
	background: rgba(255, 255, 255, 0.08);
	border: 1px solid rgba(148, 163, 184, 0.3);
	border-radius: 999px;
	font: inherit;
	font-size: 0.76rem;
	font-weight: 700;
	line-height: 1.3;
	cursor: pointer;
	transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.uth-crp-ratio:hover,
.uth-crp-ratio:focus-visible {
	border-color: rgba(96, 165, 250, 0.6);
	outline: none;
}

.uth-crp-ratio.is-active {
	color: #ffffff;
	background: linear-gradient(135deg, var(--uth-primary), #0f766e);
	border-color: transparent;
}

.uth-crp-custom-ratio {
	display: flex;
	align-items: center;
	gap: 8px;
}

.uth-crp-custom-ratio .uth-select {
	min-height: 40px;
	text-align: center;
	color: #e2e8f0;
	background: rgba(255, 255, 255, 0.08);
	border-color: rgba(148, 163, 184, 0.3);
}

.uth-crp-custom-ratio__sep {
	color: #94a3b8;
	font-weight: 800;
}

.uth-crp-custom-ratio .uth-button {
	padding: 9px 14px;
}

.uth-crp-range {
	width: 100%;
	min-width: 0;
	height: 6px;
	margin: 2px 0;
	background: linear-gradient(90deg, var(--uth-primary), #0f766e);
	border-radius: 999px;
	appearance: none;
	-webkit-appearance: none;
	cursor: pointer;
}

.uth-crp-range::-webkit-slider-thumb {
	width: 18px;
	height: 18px;
	background: #ffffff;
	border: 3px solid var(--uth-primary);
	border-radius: 50%;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
	appearance: none;
	-webkit-appearance: none;
}

.uth-crp-range::-moz-range-thumb {
	width: 16px;
	height: 16px;
	background: #ffffff;
	border: 3px solid var(--uth-primary);
	border-radius: 50%;
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.uth-crp-btnrow {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.uth-crp-preset {
	padding: 6px 14px;
	color: #e2e8f0;
	background: rgba(255, 255, 255, 0.08);
	border: 1px solid rgba(148, 163, 184, 0.3);
	border-radius: 999px;
	font: inherit;
	font-size: 0.8rem;
	font-weight: 700;
	line-height: 1.3;
	cursor: pointer;
	transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.uth-crp-preset:hover,
.uth-crp-preset:focus-visible {
	border-color: rgba(96, 165, 250, 0.6);
	outline: none;
}

.uth-crp-preset.is-active {
	color: #ffffff;
	background: linear-gradient(135deg, var(--uth-primary), #0f766e);
	border-color: transparent;
}

.uth-crp-check {
	display: flex;
	align-items: center;
	gap: 8px;
	color: #e2e8f0;
	font-size: 0.84rem;
	font-weight: 650;
	line-height: 1.4;
	cursor: pointer;
}

.uth-crp-check input {
	width: 17px;
	height: 17px;
	accent-color: var(--uth-primary);
}

.uth-crp-outputrow {
	display: grid;
	grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
	gap: 10px;
	align-items: start;
}

.uth-crp-select .uth-select {
	color: #e2e8f0;
	background: rgba(255, 255, 255, 0.08);
	border-color: rgba(148, 163, 184, 0.3);
}

.uth-crp-quality {
	display: grid;
	gap: 4px;
}

.uth-crp-quality__value {
	color: #bfdbfe;
	font-size: 0.8rem;
	font-weight: 800;
	line-height: 1.4;
}

.uth-crp-outputinfo {
	margin: 0;
	color: #94a3b8;
	font-size: 0.8rem;
	line-height: 1.5;
}

.uth-crp-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
}

.uth-crp-actions .uth-button {
	flex: 1 1 auto;
}

/* ---------- Status ---------- */
.uth-crp-status {
	position: absolute;
	left: 14px;
	top: 14px;
	z-index: 15;
	max-width: 60%;
	padding: 6px 12px;
	color: #cbd5e1;
	background: rgba(15, 23, 42, 0.7);
	border-radius: 999px;
	font-size: 0.82rem;
	line-height: 1.4;
	backdrop-filter: blur(6px);
	pointer-events: none;
}

.uth-crp-status.is-error {
	color: #fecaca;
	background: rgba(153, 27, 27, 0.75);
}

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
	.uth-crp-settings {
		top: auto;
		right: 0;
		left: 0;
		bottom: 0;
		width: 100%;
		max-height: 55vh;
		border-left: 0;
		border-top: 1px solid rgba(255, 255, 255, 0.14);
		box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.45);
	}

	.uth-crp-settings__inner {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 16px 18px;
	}

	@keyframes uth-crp-settings-in {
		from {
			transform: translateY(24px);
			opacity: 0;
		}
		to {
			transform: translateY(0);
			opacity: 1;
		}
	}
}

@media (max-width: 640px) {
	.uth-crp-dropzone {
		min-height: 200px;
		padding: 26px 16px;
	}

	.uth-crp-outputrow {
		grid-template-columns: minmax(0, 1fr);
	}

	.uth-crp-crop__dims {
		top: -24px;
		font-size: 0.66rem;
	}

	.uth-crp-iconbtn span {
		display: none;
	}

	.uth-crp-iconbtn {
		padding: 9px;
	}

	.uth-crp-close {
		top: 10px;
		right: 10px;
	}

	.uth-crp-toolsbar {
		padding: 8px;
		gap: 6px;
	}

	.uth-crp-toolsbar__group {
		flex: 1 1 auto;
		justify-content: center;
	}

	.uth-crp-toolsbar__group + .uth-crp-toolsbar__group {
		padding-left: 6px;
	}

	.uth-crp-settings {
		padding: 16px 14px 20px;
		max-height: 60vh;
	}
}

/* Crop box + grid are hidden until the user taps the Crop button. This is
   CSS-enforced so a fresh upload always shows the whole image cleanly, even
   before JS has run. */
.uth-crp-editor:not(.is-cropping) .uth-crp-crop,
.uth-crp-editor:not(.is-cropping) .uth-crp-grid,
.uth-crp-editor:not(.is-cropping) .uth-crp-crop__shade {
	display: none !important;
}

.uth-crp-editor.is-cropping .uth-crp-crop,
.uth-crp-editor.is-cropping .uth-crp-grid {
	display: block;
}
