/* 3D card stack, enabled by services-stack.js. The grid becomes the "grid" layout. */

.mfb-services__stage.is-stack {
	/* Cards keep their own colours whatever the section background. */
	--mfb-section-text: initial;
	--mfb-section-heading: initial;
	--mfb-section-muted: initial;
	position: relative;
	height: 100svh;
	min-height: 38.75rem;
	overflow: hidden;
	background: var(--mfb-stack-bg, var(--mfb-color-sand));
	color: var(--mfb-color-text);
	transition: background-color 0.6s ease;
}

.is-stack .mfb-services__label {
	position: absolute;
	inset: 2.5rem 0 auto;
	z-index: 6;
	margin: 0;
	pointer-events: none;
}

.is-stack .mfb-stack,
.is-stack .mfb-stack__canvas {
	position: absolute;
	inset: 0;
}

.is-stack .mfb-stack__canvas {
	z-index: 2;
	width: 100%;
	height: 100%;
	pointer-events: none;
}

.mfb-stack__reveal {
	position: absolute;
	top: 0;
	z-index: 1;
	width: 50%;
	height: 100%;
	pointer-events: none;
	will-change: transform;
}

.mfb-stack__reveal--prev {
	left: 0;
	border-radius: 30vh 0 0 30vh / 50vh 0 0 50vh;
	transform-origin: right center;
}

.mfb-stack__reveal--next {
	right: 0;
	border-radius: 0 30vh 30vh 0 / 0 50vh 50vh 0;
	transform-origin: left center;
}

.mfb-stack__zone {
	position: absolute;
	top: 0;
	z-index: 3;
	display: flex;
	align-items: center;
	width: calc(50% - 9.5rem);
	height: 100%;
	padding: 0;
	border: 0;
	background: none;
	color: var(--mfb-color-ink);
	font: inherit;
	text-decoration: none;
	cursor: pointer;
}

/* Labels sit beside the card rather than at the screen edges. The swung card
   reaches about 0.4 × stage height from the centre, so the label starts at
   0.45 ×, measured from the zone's inner edge (9.5rem from the centre), and
   never closer to the screen edge than its own width allows. */
.mfb-stack__zone {
	--mfb-label-inset: max(var(--mfb-space-md), min(0.45 * max(100svh, 38.75rem) - 9.5rem, 50% - 19.5rem));
}

.mfb-stack__zone--prev {
	left: 0;
	justify-content: flex-end;
	padding-right: var(--mfb-label-inset);
}

.mfb-stack__zone--next {
	right: 0;
	justify-content: flex-start;
	padding-left: var(--mfb-label-inset);
}

.mfb-stack__zone:focus-visible {
	outline: none;
}

/* Text labels with a detached underline, as on the original card stack:
   at rest the underline sits offset towards the card; when the column is
   active the label turns ink (white would fail contrast on the light cards)
   and the underline slides back under the text. */
.mfb-stack__action {
	position: relative;
	display: inline-block;
	padding-bottom: 0.55em;
	color: color-mix(in srgb, var(--mfb-stack-bg, var(--mfb-color-sand)) 35%, #000);
	font-size: var(--mfb-text-body);
	font-weight: 500;
	line-height: 1;
	white-space: nowrap;
	transition:
		color 0.3s ease,
		font-weight 0.3s ease,
		translate 0.45s var(--mfb-ease);
}

.mfb-stack__action::after {
	content: "";
	position: absolute;
	right: 0;
	bottom: 0;
	left: 0;
	height: 2px;
	background: currentColor;
	transition: transform 0.45s var(--mfb-ease);
}

.mfb-stack__zone--prev .mfb-stack__action::after {
	transform: translateX(0.6em);
}

.mfb-stack__zone--next .mfb-stack__action::after {
	transform: translateX(-0.6em);
}

.mfb-stack__zone:focus-visible .mfb-stack__action {
	color: var(--mfb-color-ink);
	font-weight: 600;
	outline: 2px solid currentColor;
	outline-offset: 0.5em;
}

.mfb-stack__zone:focus-visible .mfb-stack__action::after {
	transform: none;
}

/* On touch screens :hover sticks after a tap, so hover styling is pointer-only. */
@media (hover: hover) {
	.mfb-stack__zone:hover .mfb-stack__action {
		color: var(--mfb-color-ink);
		font-weight: 600;
	}

	.mfb-stack__zone:hover .mfb-stack__action::after {
		transform: none;
	}
}

.mfb-stack-toggle {
	position: absolute;
	bottom: max(1.75rem, env(safe-area-inset-bottom));
	left: 50%;
	z-index: 7;
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 5.5rem;
	height: 3rem;
	padding: 0.25rem;
	border: 0;
	border-radius: var(--mfb-radius-pill);
	background: var(--mfb-color-ink);
	transform: translateX(-50%);
	cursor: pointer;
}

.mfb-stack-toggle[hidden] {
	display: none;
}

.mfb-stack-toggle__thumb {
	position: absolute;
	top: 0.25rem;
	left: 0.25rem;
	width: 2.5rem;
	height: 2.5rem;
	border-radius: 50%;
	background: var(--mfb-color-white);
	transition: transform 0.55s cubic-bezier(0.65, 0, 0.35, 1);
}

.mfb-stack-toggle__icon {
	position: relative;
	display: grid;
	place-items: center;
	width: 2.5rem;
	height: 2.5rem;
}

.mfb-stack-toggle__icon--stack::before {
	content: "";
	width: 0.75rem;
	height: 1rem;
	border-radius: 3px;
	background: var(--mfb-color-ink);
	transition: background-color 0.4s ease;
}

.mfb-stack-toggle__icon--grid {
	grid-template-columns: repeat(2, 0.375rem);
	gap: 0.25rem;
	place-content: center;
}

.mfb-stack-toggle__icon--grid i {
	width: 0.375rem;
	height: 0.375rem;
	border-radius: 50%;
	background: var(--mfb-color-white);
	transition: background-color 0.4s ease;
}

.is-grid .mfb-stack-toggle__thumb {
	transform: translateX(2.5rem);
}

.is-grid .mfb-stack-toggle__icon--stack::before {
	background: var(--mfb-color-white);
}

.is-grid .mfb-stack-toggle__icon--grid i {
	background: var(--mfb-color-ink);
}

/* Grid layout inside the stage */

.is-stack .mfb-services__grid {
	position: absolute;
	inset: 0;
	z-index: 4;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	align-content: center;
	width: min(94vw, 117.5rem);
	padding: clamp(6rem, 9vh, 7.75rem) var(--mfb-space-sm) clamp(6.5rem, 11vh, 9rem);
	visibility: hidden;
	opacity: 0;
	transform: translateY(1.5rem);
	transition:
		opacity 0.55s ease,
		transform 0.65s cubic-bezier(0.22, 1, 0.36, 1),
		visibility 0.55s;
}

.is-stack .mfb-service-card {
	width: min(100%, (100svh - 15rem) * 0.64);
	margin-inline: auto;
}

.is-grid .mfb-services__grid {
	visibility: visible;
	opacity: 1;
	transform: none;
}

.is-stack .mfb-stack__canvas,
.is-stack .mfb-stack__zone,
.is-stack .mfb-stack__reveal {
	transition: opacity 0.4s ease;
}

.is-grid .mfb-stack__canvas,
.is-grid .mfb-stack__zone,
.is-grid .mfb-stack__reveal {
	opacity: 0;
	pointer-events: none;
}

@media (max-width: 61.25em) {
	/* Two or one column may not fit the stage height, so this layout scrolls.
	   The side padding keeps card shadows inside the scroll box. */
	.is-stack .mfb-services__grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		align-content: start;
		overflow-y: auto;
		overscroll-behavior-y: contain;
	}
}

/* Squarer screens: the swung card would cover side labels, so they move under the stack. */
@media (min-width: 48em) and (max-aspect-ratio: 3 / 2) {
	.is-stack .mfb-stack__zone {
		align-items: flex-end;
		width: 50%;
		padding: 0 1.25rem 6.5rem;
	}

	.is-stack .mfb-stack__zone--prev {
		justify-content: flex-end;
	}

	.is-stack .mfb-stack__zone--next {
		justify-content: flex-start;
	}
}

@media (max-width: 47.999em) {
	.is-stack .mfb-stack {
		touch-action: pan-y;
	}

	/* As on the original homepage: the labels sit at the screen edges, below the stack. */
	.is-stack .mfb-stack__zone {
		align-items: flex-end;
		width: 50%;
		padding: 0 1rem 6.5rem;
	}

	.is-stack .mfb-stack__zone--prev {
		justify-content: flex-start;
	}

	.is-stack .mfb-stack__zone--next {
		justify-content: flex-end;
	}

	.mfb-stack-toggle {
		bottom: max(1.25rem, env(safe-area-inset-bottom));
	}

	/* The active label steps in from the edge towards the card. */
	.is-stack .mfb-stack__zone--prev:focus-visible .mfb-stack__action {
		translate: 3rem 0;
	}

	.is-stack .mfb-stack__zone--next:focus-visible .mfb-stack__action {
		translate: -3rem 0;
	}

	.is-stack .mfb-services__grid {
		grid-template-columns: minmax(0, 1fr);
		width: min(90vw, 28.75rem);
		padding-block: 6rem 7.5rem;
	}

	.is-stack .mfb-service-card {
		width: 100%;
	}

	.mfb-stack.is-dragging {
		cursor: grabbing;
		user-select: none;
	}
}

@media (max-width: 47.999em) and (hover: hover) {
	.is-stack .mfb-stack__zone--prev:hover .mfb-stack__action {
		translate: 3rem 0;
	}

	.is-stack .mfb-stack__zone--next:hover .mfb-stack__action {
		translate: -3rem 0;
	}
}
