.profile-photo-editor {
	position: fixed;
	inset: 0;
	z-index: 1000001;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1rem;
	box-sizing: border-box;
}

.profile-photo-editor[hidden] {
	display: none !important;
}

.profile-photo-editor__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.55);
}

.profile-photo-editor__dialog {
	position: relative;
	box-sizing: border-box;
	width: min(100%, 420px);
	max-height: calc(100vh - 2rem);
	/* Mobile browser toolbars: keep the action row inside the visible viewport. */
	max-height: calc(100dvh - 2rem);
	overflow: auto;
	overscroll-behavior: contain;
	background: var(--profile2-card, #fff);
	border: 1px solid var(--profile2-border, #e5e7eb);
	border-radius: var(--profile2-radius, 12px);
	box-shadow: var(--profile2-shadow, 0 12px 40px rgba(0, 0, 0, 0.18));
	padding: 1rem 1rem 0;
}

.profile-photo-editor__title {
	margin: 0 0 0.75rem;
	font-size: var(--sda-heading-4, 1.25rem);
	font-weight: 700;
	color: var(--profile2-text, #111);
	text-align: center;
}

.profile-photo-editor__stage {
	position: relative;
	width: 100%;
	height: min(52vh, 360px);
	min-height: 240px;
	background: var(--profile2-bg, #f3f4f6);
	border-radius: 10px;
	overflow: hidden;
}

.profile-photo-editor__stage .cropper-view-box {
	overflow: visible !important;
}

.profile-photo-editor__stage .cropper-container {
	max-height: min(52vh, 360px);
}

.profile-photo-editor__stage .cropper-bg {
	background-image: none !important;
	background-color: var(--profile2-bg, #f3f4f6) !important;
}

.profile-photo-editor__stage-msg {
	position: absolute;
	inset: 0;
	z-index: 3;
	display: flex;
	align-items: center;
	justify-content: center;
	margin: 0;
	padding: 1rem;
	text-align: center;
	font-size: 0.875rem;
	color: var(--profile2-muted, #6b7280);
	pointer-events: none;
}

.profile-photo-editor__stage-msg--failed {
	flex-direction: column;
	gap: 0.75rem;
	pointer-events: auto;
}

.profile-photo-editor.is-failed .profile-photo-editor__hint,
.profile-photo-editor.is-failed .profile-photo-editor__tools,
.profile-photo-editor.is-failed .profile-photo-editor__emojis,
.profile-photo-editor.is-failed .profile-photo-editor__apply {
	display: none;
}

.profile-photo-editor__links {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0 0.5rem;
	margin: 0;
}

.profile-photo-editor__link {
	min-height: 44px;
	padding: 0.5rem 0.25rem;
	border: none;
	background: transparent;
	font: inherit;
	font-size: 0.8125rem;
	font-weight: 600;
	letter-spacing: normal;
	text-transform: none;
	color: var(--profile2-muted, #6b7280);
	text-decoration: underline;
	cursor: pointer;
}

.profile-photo-editor__remove {
	display: none;
	color: #b42318;
}

.profile-photo-editor.can-remove .profile-photo-editor__remove {
	display: inline-block;
}

.profile-photo-editor__skip {
	display: none;
}

.profile-photo-editor.has-file .profile-photo-editor__skip {
	display: inline-block;
}

.profile-photo-editor.is-failed .profile-photo-editor__links {
	display: none;
}

.profile-photo-editor__choose--other:not(:first-of-type) {
	background: transparent;
	color: var(--profile2-text, #111);
}

.profile-photo-editor__choose {
	font: inherit;
	cursor: pointer;
	border-radius: 999px;
	border: 1px solid var(--profile2-text, #111);
	background: var(--profile2-text, #111);
	color: var(--profile2-bg, #fff);
	padding: 0.5rem 1rem;
	min-height: 44px;
	font-size: 0.875rem;
	font-weight: 600;
}

.profile-photo-editor__stage.is-loading .profile-photo-editor__image {
	opacity: 0;
}

.profile-photo-editor__image {
	display: block;
	max-width: 100%;
	max-height: min(52vh, 360px);
	width: auto;
	height: auto;
	margin: 0 auto;
}

.profile-photo-editor__tools {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	justify-content: center;
	margin: 0.75rem 0 0.5rem;
}

.profile-photo-editor__tools button,
.profile-photo-editor__actions button {
	font: inherit;
	cursor: pointer;
	border-radius: 999px;
	border: 1px solid var(--profile2-border, #d1d5db);
	background: var(--profile2-bg, #f9fafb);
	color: var(--profile2-text, #111);
	padding: 0.4rem 0.85rem;
	min-height: 44px;
	font-size: 0.875rem;
	font-weight: 600;
}

.profile-photo-editor__tools button:hover,
.profile-photo-editor__actions button:hover {
	background: #eee;
}

.profile-photo-editor__emojis {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
	justify-content: center;
	margin-bottom: 0.75rem;
}

.profile-photo-editor__emoji-btn {
	font-size: 1.35rem;
	line-height: 1;
	padding: 0.35rem 0.45rem;
	min-width: 44px;
	min-height: 44px;
	margin: 0;
	border: none;
	background: transparent;
	border-radius: 8px;
	cursor: pointer;
}

.profile-photo-editor__emoji-btn:hover {
	background: rgba(0, 0, 0, 0.06);
}

.profile-photo-editor__sticker {
	position: absolute;
	line-height: 1;
	user-select: none;
	touch-action: none;
	transform: translate(-50%, -50%);
	z-index: 2;
}

.profile-photo-editor__sticker-inner {
	--sticker-scale: 1;
	--sticker-half: 1.25rem;
	/* A span ignores width/height unless it is a block; without this the sticker
	   measures 0x0 and is dropped from the exported photo. */
	display: block;
	position: relative;
	width: calc(var(--sticker-half) * 2);
	height: calc(var(--sticker-half) * 2);
	transform-origin: center center;
}

.profile-photo-editor__sticker-face {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: calc(var(--sticker-half) * 2);
	line-height: 1;
	cursor: grab;
	transform: scale(var(--sticker-scale));
	transform-origin: center center;
}

.profile-photo-editor__sticker.is-dragging .profile-photo-editor__sticker-face {
	cursor: grabbing;
}

.profile-photo-editor__sticker-rotate {
	position: absolute;
	left: calc(50% + var(--sticker-half) * var(--sticker-scale));
	top: calc(50% - var(--sticker-half) * var(--sticker-scale));
	transform: translate(-50%, -50%);
	width: 1.1rem;
	height: 1.1rem;
	border-radius: 50%;
	background: var(--profile2-card, #fff);
	border: 2px solid var(--profile2-primary, #1181f2);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
	cursor: grab;
	touch-action: none;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 0.65rem;
	line-height: 1;
	color: var(--profile2-primary, #1181f2);
	font-weight: 700;
}

.profile-photo-editor__sticker.is-rotating .profile-photo-editor__sticker-rotate {
	cursor: grabbing;
}

.profile-photo-editor__sticker-scale {
	position: absolute;
	left: calc(50% - var(--sticker-half) * var(--sticker-scale));
	top: calc(50% + var(--sticker-half) * var(--sticker-scale));
	transform: translate(-50%, -50%);
	width: 1.1rem;
	height: 1.1rem;
	border-radius: 50%;
	background: var(--profile2-card, #fff);
	border: 2px solid #16a34a;
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
	cursor: nwse-resize;
	touch-action: none;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 0.55rem;
	line-height: 1;
	color: #16a34a;
	font-weight: 700;
}

.profile-photo-editor__sticker.is-scaling .profile-photo-editor__sticker-scale {
	cursor: nwse-resize;
}

.profile-photo-editor__hint {
	margin: 0 0 0.5rem;
	text-align: center;
	font-size: 0.8125rem;
	color: var(--profile2-muted, #6b7280);
}

.profile-photo-editor__actions {
	display: flex;
	gap: 0.5rem;
	justify-content: center;
	padding: 0.25rem 0 1.25rem;
}

/* Photo options and the action row stay reachable when the dialog scrolls. */
.profile-photo-editor__footer {
	position: sticky;
	bottom: 0;
	z-index: 4;
	padding-top: 0.25rem;
	background: var(--profile2-card, #fff);
}

@media (max-width: 360px) {
	.profile-photo-editor__tools button {
		padding: 0.4rem 0.6rem;
		font-size: 0.75rem;
		letter-spacing: 0.02em;
	}
}

@media (max-height: 840px) {
	.profile-photo-editor__stage {
		height: min(38vh, 360px);
		min-height: 160px;
	}

	.profile-photo-editor__stage .cropper-container,
	.profile-photo-editor__image {
		max-height: min(38vh, 360px);
	}
}

.profile-photo-editor__actions .profile-photo-editor__apply {
	background: #000;
	color: #fff;
	border-color: #000;
}

.profile-photo-editor__actions .profile-photo-editor__apply:hover {
	background: #333;
}

.profile2-account-page .profile-photo-editor__subtitle {
	margin: -0.25rem 0 0.75rem;
	text-align: center;
	font-size: 0.875rem;
	color: var(--profile2-muted, #6b7280);
}

label.profile-photo-editor-toggle,
.profile2-account-page label.profile-photo-editor-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	width: auto;
	min-height: 44px;
	margin: 0.5rem 0 0;
	padding: 0;
	cursor: pointer;
}

label.profile-photo-editor-toggle > span,
.profile2-account-page label.profile-photo-editor-toggle > span {
	margin: 0;
	font-size: 0.875rem;
	font-weight: 400;
	line-height: 1.3;
	letter-spacing: normal;
	text-transform: none;
	text-align: left;
	color: var(--profile2-text, #111);
}

label.profile-photo-editor-toggle > .profile-photo-editor-toggle__input,
.profile2-account-page label.profile-photo-editor-toggle > .profile-photo-editor-toggle__input {
	flex: 0 0 auto;
	width: 1.25rem;
	height: 1.25rem;
	margin: 0;
	accent-color: var(--profile2-text, #111);
}

.profile-photo-actions [hidden] {
	display: none !important;
}
