/*
 * Button block styles
 *
 * Enqueued for core/button via wp_enqueue_block_style().
 * Base button typography, spacing, radius, border, fill colors, :hover,
 * :active and the :focus-visible outline live in theme.json
 * (styles.elements.button). Button colors are surface aware: every value is a
 * `--wp--custom--color--button--*` token that surface-schemes.css redefines,
 * so the same button reads correctly on light and dark sections.
 * Kindling variation hover colors live in
 * theme.json > styles.blocks.core/button.variations.<slug>[":hover"].
 * This file covers the layout, icon and state rules theme.json cannot express,
 * plus the core `outline` variation, which is intentionally left custom.
 *
 * @package Kindling
 * @since 1.0.0
 */

/* Buttons stretch to the full width of the container on small phones. */
@media only screen and (max-width: 600px) {
	.wp-block-buttons,
	.wp-block-button {
		width: 100%;
	}

	.wp-block-button .wp-block-button__link {
		display: flex;
		justify-content: center;
		width: 100%;
	}
}

/*
 * Base button border, hover border color and the :focus-visible outline now
 * live in theme.json (styles.elements.button). The colour transition is
 * provided globally for `a, button` in style.css.
 */

/* External link: primary fill with a trailing icon. */
.wp-block-button.is-style-external-link > .wp-block-button__link,
.wp-block-button .wp-block-button__link.is-style-external-link {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--wp--custom--spacing--8);
}

.wp-block-button.is-style-external-link > .wp-block-button__link::after,
.wp-block-button .wp-block-button__link.is-style-external-link::after {
	content: '';
	display: block;
	flex-shrink: 0;
	width: 16px;
	height: 16px;
	background-color: var(
		--wp--custom--color--button--external-link--icon,
		currentColor
	);
	mask-image: url('../../images/icons/external-link.svg');
	mask-size: contain;
	mask-repeat: no-repeat;
	mask-position: center;
	-webkit-mask-image: url('../../images/icons/external-link.svg');
	-webkit-mask-size: contain;
	-webkit-mask-repeat: no-repeat;
	-webkit-mask-position: center;
}

/*
 * Base and hover colors for external-link and fill-light now live in
 * theme.json: base border/background/text in styles/buttons/*.json, hover in
 * styles.blocks.core/button.variations.<slug>[":hover"].
 */

/* Outline: transparent fill, 2px border in the surface's outline color. */
.wp-block-button.is-style-outline > .wp-block-button__link:not(.has-text-color),
.wp-block-button .wp-block-button__link.is-style-outline:not(.has-text-color) {
	color: var(--wp--custom--color--button--outline--text);
}

/*
 * Core's outline style ships its own background, border and padding at the same
 * specificity, so these rules match it with :not(.has-background) and restate
 * the theme padding. The border is 1px heavier than the fill button's, so the
 * padding gives that 1px back and both buttons share one height.
 */
.wp-block-button.is-style-outline > .wp-block-button__link:not(.has-background),
.wp-block-button .wp-block-button__link.is-style-outline:not(.has-background) {
	background-color: var(--wp--custom--color--button--outline--background);
	background-image: none;
}

.wp-block-button.is-style-outline > .wp-block-button__link,
.wp-block-button .wp-block-button__link.is-style-outline {
	padding: calc(var(--wp--custom--spacing--16) - 1px)
		calc(var(--wp--custom--spacing--28) - 1px);
	border: 2px solid var(--wp--custom--color--button--outline--border);
}

.wp-block-button.is-style-outline > .wp-block-button__link:hover:not(.has-background),
.wp-block-button
	.wp-block-button__link.is-style-outline:hover:not(.has-background) {
	background-color: var(
		--wp--custom--color--button--outline--hover--background
	);
}

.wp-block-button.is-style-outline > .wp-block-button__link:hover,
.wp-block-button .wp-block-button__link.is-style-outline:hover {
	border-color: var(--wp--custom--color--button--outline--hover--border);
	color: var(--wp--custom--color--button--outline--hover--text);
}

/*
 * Tertiary: borderless text button with an underline rule and trailing arrow.
 *
 * The rule is a bottom border rather than text-decoration so it runs under the
 * arrow too. It uses the surface's link underline token, like text links.
 *
 * Colors are deliberately absent here. They live in
 * styles/buttons/tertiary.json (base) and theme.json (:hover). Restating the
 * base colors at this specificity would beat the generated hover rule, because
 * WordPress emits variation pseudo states inside `:where()` at (0,1,0).
 */
.wp-block-button.is-style-tertiary > .wp-block-button__link,
.wp-block-button .wp-block-button__link.is-style-tertiary {
	display: inline-flex;
	align-items: center;
	gap: var(--wp--custom--spacing--8);
	padding: 0 0 var(--wp--custom--spacing--4);
	border: 0;
	border-bottom: 2px solid var(--wp--custom--color--text--link-underline);
	border-radius: 0;
	text-transform: none;
}

.wp-block-button.is-style-tertiary > .wp-block-button__link::after,
.wp-block-button .wp-block-button__link.is-style-tertiary::after {
	content: '';
	display: block;
	flex-shrink: 0;
	width: 16px;
	height: 16px;
	position: relative;
	right: 0;
	background-color: var(--wp--custom--color--button--tertiary--icon);
	mask-image: url('../../images/icons/arrow-right.svg');
	mask-size: contain;
	mask-repeat: no-repeat;
	mask-position: center;
	-webkit-mask-image: url('../../images/icons/arrow-right.svg');
	-webkit-mask-size: contain;
	-webkit-mask-repeat: no-repeat;
	-webkit-mask-position: center;
	transition:
		background-color 0.2s ease-out,
		right 0.2s ease-out;
}

/* Tertiary hover colors live in theme.json; the arrow below stays here. */

.wp-block-button.is-style-tertiary > .wp-block-button__link:hover::after,
.wp-block-button .wp-block-button__link.is-style-tertiary:hover::after {
	background-color: var(--wp--custom--color--button--tertiary--hover--icon);
	right: -4px;
}

@media only screen and (max-width: 600px) {
	.wp-block-button.is-style-tertiary > .wp-block-button__link,
	.wp-block-button .wp-block-button__link.is-style-tertiary {
		width: auto;
		justify-content: flex-start;
	}
}

/*
 * Disabled state.
 *
 * theme.json has no :disabled pseudo state for buttons, so it lives here. It
 * covers native disabled buttons and links marked aria-disabled.
 */
.wp-element-button:disabled,
.wp-element-button[aria-disabled='true'],
.wp-block-button__link[aria-disabled='true'] {
	border-color: var(--wp--custom--color--button--disabled--border);
	background-color: var(--wp--custom--color--button--disabled--background);
	color: var(--wp--custom--color--button--disabled--text);
	cursor: not-allowed;
	pointer-events: none;
}

/*
 * Legacy markup compatibility.
 *
 * WordPress generates block style variation styles for the wrapper shape only
 * (`.wp-block-button.is-style-X .wp-block-button__link`). Older saved content
 * can carry `is-style-X` on the anchor instead, which the generated rules do
 * not match. These selectors restore the colors that moved to theme.json for
 * that shape only, so they cannot affect modern markup.
 *
 * Remove once content has been confirmed free of anchor-classed variations:
 *   SELECT ID FROM wp_posts
 *   WHERE post_content REGEXP 'wp-block-button__link[^"]*is-style-'
 *   AND post_status != 'trash';
 */
.wp-block-button .wp-block-button__link.is-style-external-link {
	border-color: var(--wp--custom--color--button--external-link--background);
}

.wp-block-button .wp-block-button__link.is-style-external-link:hover {
	background-color: var(
		--wp--custom--color--button--external-link--hover--background
	);
	border-color: var(
		--wp--custom--color--button--external-link--hover--background
	);
	color: var(--wp--custom--color--button--external-link--hover--text);
}

.wp-block-button .wp-block-button__link.is-style-fill-light {
	border-color: var(--wp--custom--color--button--fill-light--background);
}

.wp-block-button .wp-block-button__link.is-style-fill-light:hover {
	background-color: var(
		--wp--custom--color--button--fill-light--hover--background
	);
	border-color: var(
		--wp--custom--color--button--fill-light--hover--background
	);
	color: var(--wp--custom--color--button--fill-light--hover--text);
}

.wp-block-button .wp-block-button__link.is-style-tertiary {
	background-color: var(--wp--custom--color--button--tertiary--background);
	color: var(--wp--custom--color--button--tertiary--text);
}

.wp-block-button .wp-block-button__link.is-style-tertiary:hover {
	background-color: var(
		--wp--custom--color--button--tertiary--hover--background
	);
	color: var(--wp--custom--color--button--tertiary--hover--text);
}

/*
 * Share (inc/share.php): small uppercase text with a Teal share arrow, no box.
 * The link shares the current page; assets/js/share.js handles the click.
 */
.wp-block-button.is-style-share > .wp-block-button__link {
	display: inline-flex;
	align-items: center;
	gap: var(--wp--custom--spacing--8);
	padding: var(--wp--custom--spacing--4) 0;
	color: var(--wp--custom--color--text--heading);
	background: none;
	border: 0;
	border-radius: 0;
	font-size: var(--wp--preset--font-size--small);
	font-weight: 600;
	letter-spacing: 0.14em;
	line-height: 1.3;
	text-transform: uppercase;

	&::after {
		content: '';
		flex-shrink: 0;
		width: 16px;
		height: 16px;
		background-color: var(--wp--preset--color--theme-14);
		mask: url('../../images/icons/share.svg') center / contain no-repeat;
		-webkit-mask: url('../../images/icons/share.svg') center / contain no-repeat;
	}

	&:hover {
		color: var(--wp--custom--color--text--link-hover);
		background: none;
	}
}

@media only screen and (max-width: 600px) {
	.wp-block-buttons:has(> .wp-block-button.is-style-share),
	.wp-block-button.is-style-share {
		width: auto;
	}

	.wp-block-button.is-style-share .wp-block-button__link {
		width: auto;
	}
}
