/*
 * Facilities — Hover Reveal Cards
 * Port of the 21st.dev hover-reveal card grid.
 *
 * Note on selectors: root modifiers (cw-fac--hover, cw-fac--carousel-mobile) sit on the
 * same element as .cw-w, so they must be written compound (.cw-w.cw-fac--hover), never
 * as a descendant.
 */

.cw-fac {
	--cw-fg: #18181b;
	--cw-muted: #71717a;

	--cw-columns: 4;
	--cw-gap: 1rem;
	--cw-card-height: 320px;
	--cw-card-radius: 0.75rem;
	--cw-per-view: 1.15;

	--cw-overlay: rgba(0, 0, 0, 0.8);
	--cw-dim-opacity: 0.6;
	--cw-dim-blur: 2px;
	--cw-dim-scale: 0.97;
	--cw-hover-scale: 1.05;
	--cw-speed: 500ms;

	position: relative;
	width: 100%;
	color: var(--cw-fg);
}

.cw-fac__inner {
	width: 100%;
	max-width: 1152px;
	margin-inline: auto;
}

/* --------------------------------------------------------------------- Title block */

.cw-fac__header {
	margin-bottom: 3rem;
	text-align: center;
}

.cw-fac__eyebrow {
	display: block;
	font-size: 0.875rem;
	font-weight: 700;
	line-height: 1.3;
	letter-spacing: 0.08em;
	color: #2f5fbf;
}

.cw-fac__heading {
	display: block;
	margin-top: 0.75rem;
}

.cw-fac__title {
	/* inline-block so a capped width follows the alignment instead of staying left. */
	display: inline-block;
	font-size: clamp(1.75rem, 1.3rem + 1.6vw, 2.25rem);
	font-weight: 600;
	line-height: 1.2;
	letter-spacing: -0.02em;
	color: var(--cw-fg);
	text-wrap: balance;
}

.cw-w .cw-fac__description {
	display: inline-block;
	margin-top: 0.75rem;
	font-size: 1rem;
	line-height: 1.6;
	color: var(--cw-muted);
	text-wrap: pretty;
}

/* --------------------------------------------------------------------------- Grid */

.cw-fac__grid {
	display: grid;
	grid-template-columns: repeat(var(--cw-columns), minmax(0, 1fr));
	gap: var(--cw-gap);
}

/* --------------------------------------------------------------------------- Cards */

.cw-w .cw-fac__card {
	position: relative;
	display: block;
	height: var(--cw-card-height);
	overflow: hidden;
	border-radius: var(--cw-card-radius);
	background-color: #e4e4e7;
	cursor: pointer;
	transition: transform var(--cw-speed) ease-in-out, opacity var(--cw-speed) ease-in-out,
		filter var(--cw-speed) ease-in-out;
	/* Promotes the card to its own layer so the blur transition stays smooth. */
	will-change: transform;
}

.cw-fac--shadow .cw-fac__card {
	box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

.cw-w .cw-fac__image {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.cw-fac__overlay {
	position: absolute;
	inset: auto 0 0 0;
	height: 100%;
	background-image: linear-gradient(
		to top,
		var(--cw-overlay) 0%,
		color-mix(in srgb, var(--cw-overlay) 50%, transparent) 40%,
		transparent 100%
	);
	pointer-events: none;
}

/* Browsers without color-mix() still get a readable two-stop gradient. */
@supports not (color: color-mix(in srgb, red 50%, transparent)) {
	.cw-fac__overlay {
		background-image: linear-gradient(to top, var(--cw-overlay) 0%, transparent 100%);
	}
}

.cw-fac__content {
	position: absolute;
	inset: auto 0 0 0;
	display: flex;
	flex-direction: column;
	padding: 1.5rem;
	color: #ffffff;
}

.cw-fac__card-subtitle {
	font-size: 0.875rem;
	font-weight: 300;
	line-height: 1.4;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	opacity: 0.8;
}

.cw-fac__card-heading {
	display: block;
	margin-top: 0.25rem;
}

.cw-fac__card-title {
	display: block;
	font-size: 1.25rem;
	font-weight: 600;
	line-height: 1.3;
	color: #ffffff;
}

/* ------------------------------------------------------------------- Hover reveal */

/* Hovering the grid dims every card; the hovered one then overrides that. The second
   rule ties on specificity and wins by coming later, so no !important is needed.
   Wrapped in a hover-capable media query so touch devices never get a stuck state. */
@media (hover: hover) and (pointer: fine) {
	/* :has() rather than :hover on the grid: grid-level hover is also true when the
	   pointer sits in the gap between cards, which left every card dimmed with none
	   highlighted. Browsers without :has() simply don't dim, which is harmless.
	
	   The inner :where() is load-bearing. :has() otherwise takes the specificity of its
	   argument, pushing this rule to (0,6,0) — above the highlight rule at (0,5,0) — so
	   the hovered card dimmed along with the others. :where() contributes nothing, which
	   leaves this at (0,4,0) and lets the highlight win. */
	.cw-w.cw-fac--hover .cw-fac__grid:has(:where(.cw-fac__card:hover)) .cw-fac__card,
	.cw-w.cw-fac--hover .cw-fac__grid:has(:where(.cw-fac__card:focus-visible)) .cw-fac__card {
		transform: scale(var(--cw-dim-scale));
		opacity: var(--cw-dim-opacity);
		filter: blur(var(--cw-dim-blur));
	}

	.cw-w.cw-fac--hover .cw-fac__grid .cw-fac__card:hover,
	.cw-w.cw-fac--hover .cw-fac__grid .cw-fac__card:focus-visible {
		transform: scale(var(--cw-hover-scale));
		opacity: 1;
		filter: none;
		z-index: 2;
	}
}

.cw-w .cw-fac__card:focus-visible {
	outline: 2px solid var(--cw-fg);
	outline-offset: 3px;
}

/* ---------------------------------------------------------------- Mobile carousel */

/* Native scroll-snap, same as the How It Works widget: swipe, momentum and keyboard
   scrolling all come from the browser, so no JavaScript is involved. */
.cw-fac__grid {
	scrollbar-width: none;
	-ms-overflow-style: none;
}

/* A horizontal scroller clips vertically too, so a card scaled up on hover would be cut
   off. This reserves exactly the extra height the scale needs, then cancels it with a
   negative margin so the layout is unchanged. */
.cw-fac {
	--cw-scroll-pad: calc(((var(--cw-hover-scale) - 1) * var(--cw-card-height)) / 2 + 6px);
}

.cw-w.cw-fac--carousel-always .cw-fac__grid {
	display: flex;
	grid-template-columns: none;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	padding: var(--cw-scroll-pad);
	margin: calc(var(--cw-scroll-pad) * -1);
}

.cw-w.cw-fac--carousel-always.cw-fac--snap .cw-fac__grid {
	scroll-snap-type: x mandatory;
}

.cw-w.cw-fac--carousel-always .cw-fac__card {
	flex: 0 0 calc((100% - (var(--cw-per-view) - 1) * var(--cw-gap)) / var(--cw-per-view));
	max-width: calc((100% - (var(--cw-per-view) - 1) * var(--cw-gap)) / var(--cw-per-view));
	scroll-snap-align: start;
}

.cw-fac__grid::-webkit-scrollbar {
	display: none;
}

@media (max-width: 767px) {
	.cw-w.cw-fac--carousel-mobile .cw-fac__grid {
		display: flex;
		grid-template-columns: none;
		overflow-x: auto;
		overscroll-behavior-x: contain;
		/* Room for the card shadows, cancelled by the negative margin. */
		padding: var(--cw-scroll-pad);
		margin: calc(var(--cw-scroll-pad) * -1);
	}

	.cw-w.cw-fac--carousel-mobile.cw-fac--snap .cw-fac__grid {
		scroll-snap-type: x mandatory;
	}

	.cw-w.cw-fac--carousel-mobile .cw-fac__card {
		flex: 0 0 calc((100% - (var(--cw-per-view) - 1) * var(--cw-gap)) / var(--cw-per-view));
		max-width: calc((100% - (var(--cw-per-view) - 1) * var(--cw-gap)) / var(--cw-per-view));
		scroll-snap-align: start;
	}

	.cw-fac__header {
		margin-bottom: 2rem;
	}
}

@media (max-width: 1024px) {
	.cw-w.cw-fac--carousel-tablet .cw-fac__grid {
		display: flex;
		grid-template-columns: none;
		overflow-x: auto;
		overscroll-behavior-x: contain;
		padding: var(--cw-scroll-pad);
		margin: calc(var(--cw-scroll-pad) * -1);
	}

	.cw-w.cw-fac--carousel-tablet.cw-fac--snap .cw-fac__grid {
		scroll-snap-type: x mandatory;
	}

	.cw-w.cw-fac--carousel-tablet .cw-fac__card {
		flex: 0 0 calc((100% - (var(--cw-per-view) - 1) * var(--cw-gap)) / var(--cw-per-view));
		max-width: calc((100% - (var(--cw-per-view) - 1) * var(--cw-gap)) / var(--cw-per-view));
		scroll-snap-align: start;
	}
}

@media (prefers-reduced-motion: reduce) {
	.cw-w .cw-fac__card {
		transition: none;
	}
}
