/**
 * Simple Math CAPTCHA - front-end styles.
 * A lightweight reCAPTCHA-style "I'm not a robot" widget: click -> spinner ->
 * animated green checkmark. Theme-inheriting, no external libraries.
 */

.smc-captcha {
	/*
	 * Theme hooks. Override any of these to match a client's brand, e.g.:
	 *   .smc-captcha { --smc-accent: #0073aa; --smc-success: #22c55e; }
	 */
	--smc-accent: #1a73e8;
	--smc-success: #1db954;
	--smc-error: #b32d2e;
	--smc-rc-bg: #f9f9f9;
	--smc-rc-border: #d3d3d3;
	--smc-rc-box-border: #b7b7b7;

	margin: 1em 0;
	font-size: inherit;
	line-height: 1.5;
	color: inherit;
}

/* Outer widget card. */
.smc-rc {
	display: inline-flex;
	align-items: center;
	gap: 0.75em;
	padding: 0.65em 0.85em;
	min-width: 15em;
	background: var(--smc-rc-bg);
	border: 1px solid var(--smc-rc-border);
	border-radius: 3px;
	box-shadow: 0 0 3px 1px rgba( 0, 0, 0, 0.06 );
	box-sizing: border-box;
}

.smc-rc__anchor {
	display: inline-flex;
	align-items: center;
	gap: 0.75em;
	margin: 0;
	cursor: pointer;
	user-select: none;
	font-weight: 400;
}

/* Square that holds the empty box / spinner / tick. */
.smc-rc__box {
	position: relative;
	width: 28px;
	height: 28px;
	flex: 0 0 auto;
}

/* Empty checkbox drawn with a pseudo-element so we can cross-fade it. */
.smc-rc__box::before {
	content: "";
	position: absolute;
	inset: 0;
	background: #fff;
	border: 2px solid var(--smc-rc-box-border);
	border-radius: 3px;
	transition: opacity 0.15s ease;
}

/* The real checkbox sits on top, invisible, to capture clicks + keyboard. */
.smc-rc__input {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	margin: 0;
	opacity: 0;
	cursor: pointer;
	z-index: 2;
}

.smc-rc__box:focus-within::before {
	border-color: var(--smc-accent);
	box-shadow: 0 0 0 3px rgba( 26, 115, 232, 0.25 );
}

/* Circular spinner shown while "verifying". */
.smc-rc__spinner {
	position: absolute;
	inset: 2px;
	border: 3px solid rgba( 0, 0, 0, 0.15 );
	border-top-color: var(--smc-accent);
	border-radius: 50%;
	opacity: 0;
	pointer-events: none;
}

/* Green tick. */
.smc-rc__check {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	transform: scale( 0.5 );
	transition: opacity 0.15s ease, transform 0.15s ease;
	pointer-events: none;
}

.smc-rc__check-path {
	fill: none;
	stroke: var(--smc-success);
	stroke-width: 3;
	stroke-linecap: round;
	stroke-linejoin: round;
	stroke-dasharray: 28;
	stroke-dashoffset: 28;
}

/* --- Checking state --------------------------------------------------- */
.smc-captcha.smc-is-checking .smc-rc__box::before {
	opacity: 0;
}

.smc-captcha.smc-is-checking .smc-rc__spinner {
	opacity: 1;
	animation: smc-spin 0.7s linear infinite;
}

/* --- Verified state --------------------------------------------------- */
.smc-captcha.smc-is-verified .smc-rc__box::before {
	opacity: 0;
}

.smc-captcha.smc-is-verified .smc-rc__check {
	opacity: 1;
	transform: scale( 1 );
}

.smc-captcha.smc-is-verified .smc-rc__check-path {
	animation: smc-draw 0.4s ease forwards;
}

/* --- Error state ------------------------------------------------------ */
.smc-captcha.smc-is-invalid .smc-rc__box::before {
	border-color: var(--smc-error);
}

.smc-captcha.smc-is-invalid .smc-rc__label {
	color: var(--smc-error);
}

.smc-captcha__error {
	display: block;
	margin-top: 0.4em;
	min-height: 1em;
	color: var(--smc-error);
	font-size: 0.9em;
}

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

@keyframes smc-draw {
	to {
		stroke-dashoffset: 0;
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.smc-captcha.smc-is-checking .smc-rc__spinner,
	.smc-captcha.smc-is-verified .smc-rc__check-path {
		animation-duration: 0.01ms;
	}
}

/* Visually hidden honeypot - kept out of the accessibility tree and tab order. */
.smc-captcha__hp {
	position: absolute !important;
	left: -9999px !important;
	top: auto !important;
	width: 1px !important;
	height: 1px !important;
	overflow: hidden !important;
}
