/**
 * Core Button block: theme styles (inc/block-styles.php).
 *
 *   primary     the default: Royal Sapphire with the square arrow tile (B7)
 *   secondary   Lavender tint with Royal Sapphire text (7.53:1)
 *   light       Arctic White with Royal Sapphire text, for dark backgrounds
 *   text-arrow  a text link with a trailing arrow
 *
 * Buttons with no style class, and the old core "fill" class, look like
 * primary (primary is the default style). Inside a dark surface the primary
 * button turns light by itself: surfaces set --pfa-btn-* (core-group.css),
 * so a Royal Sapphire button never sits on a Royal Sapphire band.
 *
 * Loaded only on pages that use a Button block, and in the editor.
 * Tokens: assets/css/base.css (--pfa-*). Target size 44px or more (WCAG 2.5.8).
 * The arrow is a CSS mask, so its colour comes from the tokens; it is
 * decorative and always next to visible text.
 */

.wp-block-button {
	--pfa-mask-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.25' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14M13 6l6 6-6 6'/%3E%3C/svg%3E");
}

/* -------------------------------------------------------------------------
 * Shared shape: primary, secondary, light (and legacy fill/outline)
 * ---------------------------------------------------------------------- */

.wp-block-button:is(.is-style-primary, .is-style-secondary, .is-style-light, .is-style-fill, .is-style-outline) > .wp-block-button__link,
.wp-block-button:not([class*="is-style-"]) > .wp-block-button__link {
	box-sizing: border-box;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: var(--pfa-space-3);
	min-height: 3.25rem;
	padding: var(--pfa-space-3) var(--pfa-space-5);
	border: 2px solid transparent;
	border-radius: var(--pfa-radius-btn);
	font-family: inherit;
	font-size: var(--pfa-fs-body);
	font-weight: 600;
	line-height: 1.25;
	text-align: center;
	text-decoration: none;
}

/* -------------------------------------------------------------------------
 * Primary (default) and light: label, then the square arrow tile
 * ---------------------------------------------------------------------- */

.wp-block-button:is(.is-style-primary, .is-style-fill, .is-style-light) > .wp-block-button__link,
.wp-block-button:not([class*="is-style-"]) > .wp-block-button__link {
	position: relative;
	padding-inline-end: calc(var(--pfa-space-2) + 2.25rem + var(--pfa-space-4));
}

.wp-block-button:is(.is-style-primary, .is-style-fill) > .wp-block-button__link,
.wp-block-button:not([class*="is-style-"]) > .wp-block-button__link {
	background-color: var(--pfa-btn-bg, var(--pfa-sapphire));
	color: var(--pfa-btn-fg, var(--pfa-arctic));
}

.wp-block-button.is-style-light > .wp-block-button__link {
	--pfa-btn-tile: var(--pfa-sapphire);
	--pfa-btn-arrow: var(--pfa-arctic);
	background-color: var(--pfa-arctic);
	color: var(--pfa-sapphire);
}

/* The tile (::after) and the arrow drawn on top of it (::before). */
.wp-block-button:is(.is-style-primary, .is-style-fill, .is-style-light) > .wp-block-button__link::after,
.wp-block-button:not([class*="is-style-"]) > .wp-block-button__link::after,
.wp-block-button:is(.is-style-primary, .is-style-fill, .is-style-light) > .wp-block-button__link::before,
.wp-block-button:not([class*="is-style-"]) > .wp-block-button__link::before {
	content: "";
	position: absolute;
	inset-block-start: 50%;
	inset-inline-end: var(--pfa-space-2);
	width: 2.25rem;
	height: 2.25rem;
	border-radius: 10px;
	transform: translateY(-50%);
	pointer-events: none;
}

.wp-block-button:is(.is-style-primary, .is-style-fill, .is-style-light) > .wp-block-button__link::after,
.wp-block-button:not([class*="is-style-"]) > .wp-block-button__link::after {
	background-color: var(--pfa-btn-tile, var(--pfa-arctic));
}

.wp-block-button:is(.is-style-primary, .is-style-fill, .is-style-light) > .wp-block-button__link::before,
.wp-block-button:not([class*="is-style-"]) > .wp-block-button__link::before {
	z-index: 1;
	background-color: var(--pfa-btn-arrow, var(--pfa-sapphire));
	-webkit-mask: var(--pfa-mask-arrow) center / 1.125rem 1.125rem no-repeat;
	mask: var(--pfa-mask-arrow) center / 1.125rem 1.125rem no-repeat;
}

/* -------------------------------------------------------------------------
 * Secondary (and legacy outline)
 * ---------------------------------------------------------------------- */

.wp-block-button.is-style-secondary > .wp-block-button__link {
	background-color: var(--pfa-lavender-tint);
	color: var(--pfa-sapphire);
}

.wp-block-button.is-style-outline > .wp-block-button__link {
	border-color: currentColor;
	background-color: transparent;
	color: inherit;
}

/* -------------------------------------------------------------------------
 * Text link with arrow
 * ---------------------------------------------------------------------- */

/* Inline-block (not flex) so the arrow follows the last word when the label
   wraps; the padding keeps the target at least 44px tall. */
.wp-block-button.is-style-text-arrow > .wp-block-button__link {
	box-sizing: border-box;
	display: inline-block;
	min-height: 2.75rem;
	padding: 0.625rem 0;
	border: 0;
	border-radius: 0;
	background: none;
	color: inherit;
	font-family: inherit;
	font-size: inherit;
	font-weight: 600;
	line-height: 1.4;
	text-align: start;
	text-decoration-line: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 3px;
}

.wp-block-button.is-style-text-arrow > .wp-block-button__link::after {
	content: "";
	display: inline-block;
	width: 1.25rem;
	height: 1.25rem;
	margin-inline-start: 0.375rem;
	vertical-align: -0.3em;
	background-color: currentColor;
	-webkit-mask: var(--pfa-mask-arrow) center / contain no-repeat;
	mask: var(--pfa-mask-arrow) center / contain no-repeat;
}

/* Front end: pfa_text_arrow_tail() (inc/block-styles.php) wraps the label's
   last word in span.pfa-arrow-tail and the arrow moves onto that span, so the
   line never breaks before the arrow. Scoped to the link: a link to an
   unpublished page becomes plain text (span.pfa-link-pending) and shows no
   arrow. Without :has() the link keeps its own arrow. */
.wp-block-button.is-style-text-arrow > .wp-block-button__link .pfa-arrow-tail {
	white-space: nowrap;
}

@supports selector(:has(a)) {
	.wp-block-button.is-style-text-arrow > .wp-block-button__link:has(.pfa-arrow-tail)::after {
		content: none;
	}

	.wp-block-button.is-style-text-arrow > .wp-block-button__link .pfa-arrow-tail::after {
		content: "";
		display: inline-block;
		width: 1.25rem;
		height: 1.25rem;
		margin-inline-start: 0.375rem;
		vertical-align: -0.3em;
		background-color: currentColor;
		-webkit-mask: var(--pfa-mask-arrow) center / contain no-repeat;
		mask: var(--pfa-mask-arrow) center / contain no-repeat;
	}
}

/* -------------------------------------------------------------------------
 * Hover and focus
 * ---------------------------------------------------------------------- */

@media (hover: hover) {
	.wp-block-button:is(.is-style-primary, .is-style-fill) > .wp-block-button__link:hover,
	.wp-block-button:not([class*="is-style-"]) > .wp-block-button__link:hover {
		background-color: var(--pfa-btn-bg-hover, var(--pfa-sapphire-700));
	}

	/* Royal Sapphire on Soft Lavender is 4.78:1: fine for 18px SemiBold labels. */
	.wp-block-button.is-style-secondary > .wp-block-button__link:hover {
		background-color: var(--pfa-lavender);
	}

	.wp-block-button.is-style-light > .wp-block-button__link:hover {
		background-color: var(--pfa-lavender-tint);
	}

	.wp-block-button.is-style-text-arrow > .wp-block-button__link:hover {
		text-decoration-thickness: 2px;
	}
}

.wp-block-button > .wp-block-button__link:focus-visible {
	outline: 3px solid var(--pfa-focus, var(--pfa-sapphire));
	outline-offset: 3px;
}

@media (prefers-reduced-motion: no-preference) {
	.wp-block-button > .wp-block-button__link {
		transition: background-color 150ms ease, color 150ms ease;
	}
}

/* -------------------------------------------------------------------------
 * Small screens: filled buttons use the full width (easier to tap).
 * ---------------------------------------------------------------------- */

@media (max-width: 479px) {
	.wp-block-buttons > .wp-block-button:not(.is-style-text-arrow) {
		flex: 1 1 100%;
	}

	.wp-block-buttons > .wp-block-button:not(.is-style-text-arrow) > .wp-block-button__link {
		width: 100%;
		padding-inline-start: var(--pfa-space-4);
	}

	/* A secondary button stacked with a primary one keeps clear on its right
	   what the primary's arrow tile takes, so both labels share one centre
	   line. */
	.wp-block-buttons:has(> .wp-block-button:is(.is-style-primary, .is-style-fill, .is-style-light, :not([class*="is-style-"]))) > .wp-block-button.is-style-secondary > .wp-block-button__link {
		padding-inline-end: calc(var(--pfa-space-2) + 2.25rem + var(--pfa-space-4));
	}
}

@media (forced-colors: active) {
	.wp-block-button > .wp-block-button__link {
		border-color: ButtonText;
	}

	.wp-block-button > .wp-block-button__link::before,
	.wp-block-button > .wp-block-button__link::after,
	.wp-block-button > .wp-block-button__link .pfa-arrow-tail::after {
		forced-color-adjust: none;
		background-color: ButtonText;
	}

	.wp-block-button:is(.is-style-primary, .is-style-fill, .is-style-light) > .wp-block-button__link::after,
	.wp-block-button:not([class*="is-style-"]) > .wp-block-button__link::after {
		background-color: transparent;
	}
}
