/*
 * Colors, inherited from the active theme. cjbec_theme_color_vars()
 * overrides the link and accent colors with the theme's own link and button
 * colors (theme.json); these are the fallbacks for themes that don't set them.
 * Neutral colors mix the surrounding text color, so they suit light and dark
 * themes alike.
 */
:root {
	--cjbec-link: currentColor;
	--cjbec-link-hover: var(--cjbec-link);
	--cjbec-accent: var(--cjbec-link);
	--cjbec-accent-hover: var(--cjbec-accent);
	--cjbec-surface: var(--wp--preset--color--base, Canvas);
	--cjbec-on-accent: var(--cjbec-surface);
	--cjbec-muted: color-mix(in srgb, currentColor 70%, transparent);
	--cjbec-border: color-mix(in srgb, currentColor 20%, transparent);
	--cjbec-tint: color-mix(in srgb, currentColor 6%, transparent);
}

/*
 * For every visitor: the avatar slot in the header (Account Button block) and
 * at the end of the Comments heading. Logged-in users see their avatar there;
 * logged-out visitors, a log-in icon.
 */
.wp-block-cjb-enhanced-comments-account-button {
	display: flex;
	flex-shrink: 0;
	align-items: center;
	gap: 12px;
}

.wp-block-comments-title.has-commenter-avatar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--wp--preset--spacing--small, 1rem);
}

.cjbec-comments-title__actions {
	display: flex;
	flex-shrink: 0;
	align-items: center;
	gap: var(--wp--preset--spacing--small, 1rem);
	margin-block: -6px;
}

.cjbec-account-button,
.cjbec-comments-title__account {
	display: flex;
	color: inherit;
}

.cjbec-account-button img,
.cjbec-comments-title__account img,
.cjbec-login-icon {
	flex-shrink: 0;
	max-width: none;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	object-fit: cover;
}

a:hover > :is(.cjbec-login-icon, .cjbec-login-label) {
	color: var(--cjbec-link-hover);
}

/* "Log in" beside the icon (Comments heading; Account Button when its label
   is on): bold, small, and not in the heading's capitals. */
.cjbec-account-button,
.cjbec-comments-title__account {
	align-items: center;
	gap: 0.4em;
	text-decoration: none;
}

.cjbec-login-label {
	font-size: var(--wp--preset--font-size--x-small, 0.875rem);
	font-weight: 700;
	letter-spacing: normal;
	text-transform: none;
	white-space: nowrap;
}

/* Account Button, "Button" style: for visitors, the log-in link in the
   theme's button colors and corners (logged-in readers keep their avatar). */
.is-style-button .cjbec-account-button--guest {
	padding: 0.4em;
	border-radius: var(--cjbec-button-radius, 0);
	background: var(--cjbec-accent);
	color: var(--cjbec-on-accent);
	font-size: var(--wp--preset--font-size--x-small, 0.875rem);
}

.is-style-button .cjbec-account-button--guest:has(.cjbec-login-label) {
	padding-inline-end: 0.9em;
}

.is-style-button .cjbec-account-button--guest:hover {
	background: var(--cjbec-accent-hover);
}

.is-style-button .cjbec-account-button--guest:hover > * {
	color: inherit;
}

.is-style-button .cjbec-account-button--guest .cjbec-login-icon {
	width: 1.6em;
	height: 1.6em;
}

/*
 * A checkbox drawn as a switch (still a native checkbox, role="switch"): the
 * Account panel's reply-emails setting and the comment form's cookie consent.
 * Themes often style every input (some with !important), hence :root for
 * specificity and !important on the corners.
 */
:root input.cjbec-switch[type="checkbox"] {
	appearance: none;
	position: relative;
	flex-shrink: 0;
	box-sizing: border-box;
	width: 2.25rem;
	height: 1.25rem;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 1rem !important;
	background: color-mix(in srgb, currentColor 35%, transparent);
	cursor: pointer;
	transition: background-color 0.15s;
}

.cjbec-switch::before {
	content: "";
	position: absolute;
	top: 2px;
	left: 2px;
	width: calc(1.25rem - 4px);
	height: calc(1.25rem - 4px);
	border-radius: 50%;
	background: var(--cjbec-surface);
	transition: translate 0.15s;
}

:root input.cjbec-switch[type="checkbox"]:checked {
	background: var(--cjbec-accent);
}

.cjbec-switch:checked::before {
	translate: 1rem 0;
}

.cjbec-switch:focus-visible {
	outline: 2px solid var(--cjbec-accent);
	outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
	.cjbec-switch,
	.cjbec-switch::before {
		transition: none;
	}
}

/* Custom-drawn controls can lose their state in forced-colors mode. */
@media (forced-colors: active) {
	:root input.cjbec-switch[type="checkbox"] {
		appearance: auto;
		width: auto;
		height: auto;
	}

	.cjbec-switch::before {
		content: none;
	}
}
