/*
 * Buttons: pill + circular arrow chip (pass 4, section 2).
 * Anatomy: label + chip at the right end, chip diameter = height - 8px, inset 4px.
 * The chip is ::before (it grows to fill the pill on hover); the arrow is ::after, a two-layer mask:
 * layer 1 leaves in its direction while layer 2 (the twin) arrives from the opposite side.
 * Everything is CSS so the editor shows the real design and saved markup stays core's.
 */

.wp-block-button {
	--h: 48px;
	--fs: 1.0625rem;
	--aw: 18px;
	--gap: 14px;
	--dx: 13px;
	--dy: -13px;
	--ar: var(--bt-ar-ne-18);
	--ar-base: none;
	--fill: var(--wp--custom--button--primary--fill);
	--fg: var(--wp--custom--button--primary--fg);
	--bd: var(--wp--custom--button--primary--border);
	--chip: var(--wp--custom--button--primary--chip);
	--chip-fg: var(--wp--custom--button--primary--chip-fg);
	--hfg: var(--wp--custom--button--primary--hover-fg);
	--hbd: var(--wp--custom--button--primary--hover-border);
	--t-fill: var(--wp--custom--motion--fill, 320ms);
	--t-arrow: var(--wp--custom--motion--arrow, 220ms);
	--t-press: var(--wp--custom--motion--press, 120ms);
	--ease: var(--wp--custom--motion--ease, cubic-bezier(0.2, 0.7, 0.2, 1));
}

/* sizes */
.wp-block-button.bt-size-l { --h: 56px; --fs: 1.125rem; --aw: 20px; }
.wp-block-button.bt-size-s { --h: 40px; --fs: 0.9375rem; --aw: 16px; --gap: 10px; }

@media (max-width: 960px) {
	/* Touch targets stay at least 48px on small screens. */
	.wp-block-button.bt-size-s { --h: 48px; --fs: 1rem; --aw: 18px; --gap: 14px; }
}

/* arrow directions (pass 4 arrow semantics): exit offset and the 18px mask */
.wp-block-button.bt-arrow-ne { --dx: 13px; --dy: -13px; --ar: var(--bt-ar-ne-18); }
.wp-block-button.bt-arrow-e { --dx: 16px; --dy: 0px; --ar: var(--bt-ar-e-18); }
.wp-block-button.bt-arrow-s { --dx: 0px; --dy: 16px; --ar: var(--bt-ar-s-18); --ar-base: var(--bt-ar-s-18-base); }
.wp-block-button.bt-arrow-w { --dx: -16px; --dy: 0px; --ar: var(--bt-ar-w-18); }
.wp-block-button.bt-arrow-x { --dx: 9px; --dy: -9px; --ar: var(--bt-ar-x-18); --ar-base: var(--bt-ar-x-18-base); }

.wp-block-button.bt-size-l.bt-arrow-ne { --ar: var(--bt-ar-ne-20); }
.wp-block-button.bt-size-l.bt-arrow-e { --ar: var(--bt-ar-e-20); }
.wp-block-button.bt-size-l.bt-arrow-s { --ar: var(--bt-ar-s-20); --ar-base: var(--bt-ar-s-20-base); }
.wp-block-button.bt-size-l.bt-arrow-w { --ar: var(--bt-ar-w-20); }
.wp-block-button.bt-size-l.bt-arrow-x { --ar: var(--bt-ar-x-20); --ar-base: var(--bt-ar-x-20-base); }

@media (min-width: 961px) {
	.wp-block-button.bt-size-s.bt-arrow-ne { --ar: var(--bt-ar-ne-16); }
	.wp-block-button.bt-size-s.bt-arrow-e { --ar: var(--bt-ar-e-16); }
	.wp-block-button.bt-size-s.bt-arrow-s { --ar: var(--bt-ar-s-16); --ar-base: var(--bt-ar-s-16-base); }
	.wp-block-button.bt-size-s.bt-arrow-w { --ar: var(--bt-ar-w-16); }
	.wp-block-button.bt-size-s.bt-arrow-x { --ar: var(--bt-ar-x-16); --ar-base: var(--bt-ar-x-16-base); }
}

/* variants */
.wp-block-button.is-style-secondary {
	--fill: var(--wp--custom--button--secondary--fill);
	--fg: var(--wp--custom--button--secondary--fg);
	--bd: var(--wp--custom--button--secondary--border);
	--chip: var(--wp--custom--button--secondary--chip);
	--chip-fg: var(--wp--custom--button--secondary--chip-fg);
	--hfg: var(--wp--custom--button--secondary--hover-fg);
	--hbd: var(--wp--custom--button--secondary--hover-border);
}

.wp-block-button.is-style-on-image {
	--fill: var(--wp--custom--button--on-image--fill);
	--fg: var(--wp--custom--button--on-image--fg);
	--bd: var(--wp--custom--button--on-image--border);
	--chip: var(--wp--custom--button--on-image--chip);
	--chip-fg: var(--wp--custom--button--on-image--chip-fg);
	--hfg: var(--wp--custom--button--on-image--hover-fg);
	--hbd: var(--wp--custom--button--on-image--hover-border);
}

:where(.has-surface-dark-background-color, .is-style-card-ink, .bt-footer) .wp-block-button.is-style-secondary {
	--fill: var(--wp--custom--button--secondary-on-dark--fill);
	--fg: var(--wp--custom--button--secondary-on-dark--fg);
	--bd: var(--wp--custom--button--secondary-on-dark--border);
	--chip: var(--wp--custom--button--secondary-on-dark--chip);
	--chip-fg: var(--wp--custom--button--secondary-on-dark--chip-fg);
	--hfg: var(--wp--custom--button--secondary-on-dark--hover-fg);
	--hbd: var(--wp--custom--button--secondary-on-dark--hover-border);
}

:where(.has-surface-dark-background-color) .wp-block-button:not(.is-style-secondary, .is-style-on-image, .is-style-text-link) {
	--hbd: transparent;
}

/* pill */
.wp-block-button:not(.is-style-text-link) .wp-block-button__link {
	position: relative;
	isolation: isolate;
	overflow: visible;
	display: inline-flex;
	align-items: center;
	box-sizing: border-box;
	height: var(--h);
	min-height: var(--h);
	padding: 0 calc(var(--h) + var(--gap) - 4px) 0 calc(var(--h) * 0.5);
	border: 0;
	border-radius: 999px;
	background: var(--fill);
	color: var(--fg);
	box-shadow: inset 0 0 0 1.5px var(--bd);
	font-family: var(--wp--preset--font-family--text);
	font-size: var(--fs);
	font-weight: 600;
	letter-spacing: 0.005em;
	line-height: 1;
	text-align: left;
	text-decoration: none;
	white-space: nowrap;
	word-break: normal;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
	transition: color var(--t-fill) var(--ease), box-shadow var(--t-fill) var(--ease), transform var(--t-press) var(--ease);
}

/* the chip, which grows to fill on hover and focus.
   It reaches 1px past the pill on every side. If it matched the pill exactly, its anti-aliased rounded ends
   would sit on the pill's own anti-aliased ends and let the fill and border colours show through as a faint
   vertical line at the left and right (Sprint 8a, owner feedback 9 November). The 1px overhang covers those
   pixels completely; the circle's centre moves 1px left to stay on the arrow, and the pill no longer clips
   its children (the chip has its own clip). The same fix is in search.css and the carousel icon buttons. */
.wp-block-button:not(.is-style-text-link) .wp-block-button__link::before {
	content: "";
	position: absolute;
	inset: -1px;
	z-index: -1;
	border-radius: 999px;
	background: var(--chip);
	clip-path: circle(calc(var(--h) * 0.5 - 4px) at calc(100% - var(--h) * 0.5 - 1px) 50%);
	transition: clip-path var(--t-fill) var(--ease);
}

/* the arrow and its twin */
.wp-block-button .wp-block-button__link::after {
	content: "";
	position: absolute;
	top: 50%;
	right: calc(var(--h) * 0.5 - var(--aw) * 0.5);
	width: var(--aw);
	height: var(--aw);
	margin-top: calc(var(--aw) * -0.5);
	background: var(--chip-fg);
	-webkit-mask-image: var(--ar), var(--ar), var(--ar-base);
	mask-image: var(--ar), var(--ar), var(--ar-base);
	-webkit-mask-position: 0 0, calc(var(--dx) * -1.5) calc(var(--dy) * -1.5), 0 0;
	mask-position: 0 0, calc(var(--dx) * -1.5) calc(var(--dy) * -1.5), 0 0;
	-webkit-mask-size: 100% 100%;
	mask-size: 100% 100%;
	-webkit-mask-repeat: no-repeat;
	mask-repeat: no-repeat;
	pointer-events: none;
	transition: -webkit-mask-position var(--t-arrow) var(--ease), mask-position var(--t-arrow) var(--ease);
}

.wp-block-button .wp-block-button__link:is(:hover, :focus-visible) {
	color: var(--hfg);
	box-shadow: inset 0 0 0 1.5px var(--hbd);
	text-decoration: none;
}

.wp-block-button:not(.is-style-text-link) .wp-block-button__link:is(:hover, :focus-visible)::before {
	clip-path: circle(150% at calc(100% - var(--h) * 0.5 - 1px) 50%);
}

.wp-block-button .wp-block-button__link:is(:hover, :focus-visible)::after {
	-webkit-mask-position: var(--dx) var(--dy), 0 0, 0 0;
	mask-position: var(--dx) var(--dy), 0 0, 0 0;
}

.wp-block-button:not(.is-style-text-link) .wp-block-button__link:active {
	transform: scale(0.98);
}

/* no arrow: an in-place action; the fill grows from the centre */
.wp-block-button.bt-arrow-none:not(.is-style-text-link) .wp-block-button__link {
	justify-content: center;
	padding: 0 calc(var(--h) * 0.5);
}

.wp-block-button.bt-arrow-none .wp-block-button__link::after {
	content: none;
}

.wp-block-button.bt-arrow-none:not(.is-style-text-link) .wp-block-button__link::before {
	clip-path: circle(0 at 50% 50%);
}

.wp-block-button.bt-arrow-none:not(.is-style-secondary, .is-style-on-image, .is-style-text-link) .wp-block-button__link::before {
	background: var(--wp--custom--button--plain-primary-chip);
}

.wp-block-button.bt-arrow-none:not(.is-style-secondary, .is-style-on-image, .is-style-text-link) .wp-block-button__link:is(:hover, :focus-visible) {
	color: var(--fg);
}

.wp-block-button.bt-arrow-none:not(.is-style-text-link) .wp-block-button__link:is(:hover, :focus-visible)::before {
	clip-path: circle(150% at 50% 50%);
}

/* disabled */
.wp-block-button .wp-block-button__link:is([aria-disabled="true"], :disabled) {
	--fill: #e6ded2;
	--fg: #5e5a66;
	--bd: transparent;
	--chip: #d9d2c7;
	--chip-fg: #5e5a66;
	--hfg: #5e5a66;
	--hbd: transparent;
	cursor: not-allowed;
	transform: none;
}

.wp-block-button .wp-block-button__link:is([aria-disabled="true"], :disabled)::before {
	clip-path: circle(calc(var(--h) * 0.5 - 4px) at calc(100% - var(--h) * 0.5 - 1px) 50%) !important;
}

/* ---------- text link: label + small arrow; the underline draws left to right ---------- */
.wp-block-button.is-style-text-link {
	--aw: 16px;
	--ar: var(--bt-ar-ne-16);
	--chip-fg: currentcolor;
	--tl-fs: 1.125rem;
}

.wp-block-button.is-style-text-link.bt-arrow-e { --ar: var(--bt-ar-e-16); }
.wp-block-button.is-style-text-link.bt-arrow-w { --ar: var(--bt-ar-w-16); }
.wp-block-button.is-style-text-link.bt-arrow-s { --ar: var(--bt-ar-s-16); --ar-base: var(--bt-ar-s-16-base); }
.wp-block-button.is-style-text-link.bt-arrow-x { --ar: var(--bt-ar-x-16); --ar-base: var(--bt-ar-x-16-base); }
.wp-block-button.is-style-text-link.bt-size-l { --tl-fs: 1.25rem; }
.wp-block-button.is-style-text-link.bt-size-s { --tl-fs: 1rem; }

.wp-block-button.is-style-text-link .wp-block-button__link {
	position: relative;
	display: inline-flex;
	align-items: center;
	box-sizing: border-box;
	min-height: 44px;
	height: auto;
	padding: 0 26px 0 0;
	border-radius: 0;
	background: none;
	color: inherit;
	box-shadow: none;
	font-family: var(--wp--preset--font-family--text);
	font-size: var(--tl-fs);
	font-weight: 600;
	line-height: 1.6;
	text-align: left;
	text-decoration: none;
	white-space: normal;
}

.wp-block-button.is-style-text-link .wp-block-button__link::before {
	content: "";
	position: absolute;
	left: 0;
	right: 26px;
	top: calc(50% + 0.8em + 1px);
	height: 1.5px;
	background-image: linear-gradient(currentcolor, currentcolor), linear-gradient(color-mix(in srgb, currentcolor 30%, transparent), color-mix(in srgb, currentcolor 30%, transparent));
	background-repeat: no-repeat;
	background-position: 0 100%, 0 100%;
	background-size: 0% 1.5px, 100% 1px;
	transition: background-size var(--t-fill) var(--ease);
}

.wp-block-button.is-style-text-link .wp-block-button__link:is(:hover, :focus-visible) {
	color: inherit;
}

.wp-block-button.is-style-text-link .wp-block-button__link:is(:hover, :focus-visible)::before {
	background-size: 100% 1.5px, 100% 1px;
}

.wp-block-button.is-style-text-link .wp-block-button__link::after {
	right: 1px;
}

.wp-block-button.is-style-text-link.bt-arrow-none .wp-block-button__link {
	padding-right: 0;
}

.wp-block-button.is-style-text-link.bt-arrow-none .wp-block-button__link::before {
	right: 0;
}

/* tones for text links */
.wp-block-button.bt-tone-leaf { color: var(--wp--preset--color--leaf-text); }
.wp-block-button.bt-tone-primary { color: var(--wp--preset--color--primary-text); }
.wp-block-button.bt-tone-soft { color: var(--wp--preset--color--contrast-2); }

/* buttons rows */
.wp-block-buttons {
	row-gap: 12px;
}

@media (prefers-reduced-motion: reduce) {
	.wp-block-button .wp-block-button__link::after {
		-webkit-mask-position: 0 0, 100px 100px, 0 0 !important;
		mask-position: 0 0, 100px 100px, 0 0 !important;
	}

	.wp-block-button .wp-block-button__link:active {
		transform: none !important;
	}
}

/* Phones: a label longer than the column wraps inside its pill instead of pushing past the screen
   (for example "Portakal ağacı ön siparişi ver" at 320px, or the large "Sponsorluk için bizimle konuşun"
   at 390px, which was 12px wider than its column). A label that fits keeps one line and the pill's
   height (min-height), so only the long ones change. Sprint 10: was below 390px only. */
@media (max-width: 600px) {
	.wp-block-button:not(.is-style-text-link) {
		max-width: 100%;
	}

	.wp-block-button:not(.is-style-text-link) .wp-block-button__link {
		height: auto;
		padding-block: 8px;
		line-height: 1.2;
		white-space: normal;
	}
}
