/*
 * core/cover block styles: tile, flip, plus (tokens doc §Components: Card,
 * CTA).
 *
 * Shared: the first heading link stretches over the whole cover (whole-box
 * link). To let the link's ::after cover the block, the media/overlay go to
 * z-index -1 inside an isolated stacking context and the inner container stays
 * static.
 */

:is(.is-style-tile, .is-style-flip, .is-style-plus).wp-block-cover {
	min-height: 0;
	color: var(--wp--preset--color--white);
}

:is(.is-style-tile, .is-style-plus).wp-block-cover {
	isolation: isolate;
}

/* Flip isolates only below 1200px: isolation would flatten its 3D faces. */
@media (max-width: 1199.98px) {

	.is-style-flip.wp-block-cover {
		isolation: isolate;
	}
}

:is(.is-style-tile, .is-style-flip, .is-style-plus).wp-block-cover > :is(.wp-block-cover__image-background, .wp-block-cover__video-background, .wp-block-cover__background) {
	z-index: -1;
}

:is(.is-style-tile, .is-style-flip, .is-style-plus).wp-block-cover > .wp-block-cover__inner-container {
	position: static;
}

:is(.is-style-tile, .is-style-flip, .is-style-plus) :is(h1, h2, h3, h4, h5, h6) a {
	color: inherit;
	text-decoration: none;
}

:is(.is-style-tile, .is-style-flip, .is-style-plus) :is(h1, h2, h3, h4, h5, h6) a::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 1;
}

:is(.is-style-tile, .is-style-flip, .is-style-plus):has(a:focus-visible) {
	outline: 2px solid var(--wp--preset--color--primary);
	outline-offset: 2px;
}

:is(.is-style-tile, .is-style-flip, .is-style-plus) :is(h1, h2, h3, h4, h5, h6) a:focus-visible {
	outline: 0;
}

/* Image zoom (media-zoom): 1.1 on hover from 1200px. */
:is(.is-style-tile, .is-style-plus) > .wp-block-cover__image-background {
	transform: scale(1);
	transition: transform 0.3s ease-in;
}

@media (min-width: 1200px) and (hover: hover) {

	:is(.is-style-tile, .is-style-plus):is(:hover, :focus-within) > .wp-block-cover__image-background {
		transform: scale(1.1);
	}
}

/* ------------------------------------------------------------------ *
 * Tile (cards, CTA fullwidth): 4:3, title bottom-left, overlay slides up
 * from the bottom on hover, uppercase title whose 2px frame draws itself.
 * ------------------------------------------------------------------ */

.is-style-tile.wp-block-cover {
	aspect-ratio: 4 / 3;
}

.is-style-tile.wp-block-cover:not(.has-custom-content-position) {
	align-items: flex-end;
	justify-content: flex-start;
}

/*
 * Dark fade from the bottom so the white title stays readable on light
 * photos. ::after comes after the image in paint order at the same z-index.
 */
.is-style-tile.wp-block-cover::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	pointer-events: none;
	background: linear-gradient(to top, rgb(0 0 0 / 0.45) 0%, rgb(0 0 0 / 0.25) 25%, rgb(0 0 0 / 0.08) 50%, rgb(0 0 0 / 0) 70%);
}

.is-style-tile > .wp-block-cover__background {
	top: auto;
	height: 0;
	transition: height 0.4s ease-in-out 0.2s;
}

.is-style-tile:is(:hover, :focus-within) > .wp-block-cover__background {
	height: 100%;
}

/*
 * Touch screens have no hover: keep the overlay so white text stays readable.
 */
@media (hover: none) {

	.is-style-tile > .wp-block-cover__background {
		height: 100%;
	}
}

.is-style-tile :is(h1, h2, h3, h4, h5, h6) {
	display: inline-block;
	margin-bottom: 0;
	padding: clamp(0.4375rem, 0.390625rem + 0.2344vw, 0.625rem) clamp(0.875rem, 0.625rem + 1.25vw, 1.875rem);
	color: inherit;
	text-transform: uppercase;
	background:
		linear-gradient(currentcolor, currentcolor) left top / 0 2px no-repeat,
		linear-gradient(currentcolor, currentcolor) right bottom / 0 2px no-repeat,
		linear-gradient(currentcolor, currentcolor) left top / 2px 0 no-repeat,
		linear-gradient(currentcolor, currentcolor) right bottom / 2px 0 no-repeat;
	transition: background-size 0.4s linear 0.3s;
}

.is-style-tile:is(:hover, :focus-within) :is(h1, h2, h3, h4, h5, h6) {
	background-size: 100% 2px, 100% 2px, 2px 100%, 2px 100%;
}

/* ------------------------------------------------------------------ *
 * Flip (CTA quadrato): square box.
 * < 1200px: text over the image on a 50% black overlay, white text.
 * ≥ 1200px: 3D card — front = image, back = white panel with the text,
 * flips on hover/focus. Reduced motion: cross-fade instead of rotating.
 * ------------------------------------------------------------------ */

.is-style-flip.wp-block-cover {
	aspect-ratio: 1;
}

.is-style-flip :is(h1, h2, h3, h4, h5, h6) {
	color: inherit;
}

/*
 * Below 1200px the text sits on the image: a dark layer keeps the white text
 * readable whatever the cover's own overlay (the migrated ones have none),
 * and the box grows past the square when the text is longer, so nothing is
 * cut off.
 */
@media (max-width: 1199.98px) {

	.is-style-flip.wp-block-cover {
		aspect-ratio: auto;
		min-height: 20rem;
		padding-block: var(--wp--preset--spacing--50);
	}

	.is-style-flip.wp-block-cover::after {
		content: "";
		position: absolute;
		inset: 0;
		z-index: -1;
		pointer-events: none;
		background-color: rgb(0 0 0 / 55%);
	}
}

@media (min-width: 1200px) {

	/*
	 * The cover stays still and its two faces turn (front = image, back =
	 * inner container), under the cover's perspective. Hovering the still box
	 * keeps the hover steady: a turning box shrinks under the pointer mid-turn,
	 * loses :hover and stutters. overflow stays visible so the faces are not
	 * clipped while they turn.
	 */
	.is-style-flip.wp-block-cover {
		overflow: visible;
		perspective: 1000px;
	}

	.is-style-flip.wp-block-cover > :is(.wp-block-cover__image-background, .wp-block-cover__video-background, .wp-block-cover__inner-container) {
		backface-visibility: hidden;
		transition: transform 0.6s ease;
	}

	.is-style-flip.wp-block-cover:is(:hover, :focus-within) > :is(.wp-block-cover__image-background, .wp-block-cover__video-background) {
		transform: rotateY(180deg);
	}

	/* No overlay on the front face: the image is shown clean. */
	.is-style-flip.wp-block-cover > .wp-block-cover__background {
		display: none;
	}

	.is-style-flip.wp-block-cover > .wp-block-cover__inner-container {
		position: absolute;
		inset: 0;
		box-sizing: border-box;
		width: auto;
		display: flex;
		flex-direction: column;
		justify-content: center;
		padding: var(--wp--preset--spacing--section) var(--wp--preset--spacing--40);
		background-color: var(--wp--preset--color--white);
		color: var(--wp--preset--color--body-color);
		text-align: left;
		transform: rotateY(-180deg);
	}

	/*
	 * The back reads left-aligned like the old site (the constrained
	 * layout centres its children).
	 */
	.is-style-flip.wp-block-cover > .wp-block-cover__inner-container > * {
		margin-inline: 0 !important;
	}

	.is-style-flip.wp-block-cover:is(:hover, :focus-within) > .wp-block-cover__inner-container {
		transform: rotateY(0deg);
	}

	/*
	 * Back face title: in a taupe frame like the old site (the heading
	 * "Riquadro" look, blocks/heading.css), at h4 size so long names fit.
	 */
	.is-style-flip.wp-block-cover > .wp-block-cover__inner-container > .wp-block-heading:first-child {
		width: fit-content;
		max-width: 100%;
		box-sizing: border-box;
		margin-block: 0 var(--wp--preset--spacing--40);
		padding:
			clamp(0.4375rem, 0.390625rem + 0.2344vw, 0.625rem)
			clamp(0.875rem, 0.625rem + 1.25vw, 1.875rem);
		border: 2px solid var(--wp--preset--color--primary);
		font-size: var(--wp--preset--font-size--h-4);
		line-height: 1.55;
	}
}

@media (min-width: 1200px) and (max-width: 1499.98px) {

	.is-style-flip.wp-block-cover {
		aspect-ratio: 1 / 1.1;
	}
}

/* Reduced motion: no rotation, the back face cross-fades in. */
@media (min-width: 1200px) and (prefers-reduced-motion: reduce) {

	.is-style-flip.wp-block-cover > *,
	.is-style-flip.wp-block-cover:is(:hover, :focus-within) > * {
		transform: none;
	}

	.is-style-flip.wp-block-cover > .wp-block-cover__inner-container {
		opacity: 0;
		transition: opacity 0.2s linear;
	}

	.is-style-flip.wp-block-cover:is(:hover, :focus-within) > .wp-block-cover__inner-container {
		opacity: 1;
	}
}

/* ------------------------------------------------------------------ *
 * Plus (CTA quadrato trasparente, plus-fadein): square, centred text on
 * the overlay. Hover ≥ 1200px: overlay and text fade out, image zooms,
 * a white plus-circle icon (CSS mask SVG) rises into the centre.
 * ------------------------------------------------------------------ */

.is-style-plus.wp-block-cover {
	--ragazzo-plus-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 0a12 12 0 1 0 0 24 12 12 0 0 0 0-24Zm1.5 6v4.5H18v3h-4.5V18h-3v-4.5H6v-3h4.5V6Z'/%3E%3C/svg%3E");
	aspect-ratio: 1;
	text-align: center;
}

.is-style-plus.wp-block-cover::before {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	z-index: 0;
	width: var(--wp--preset--font-size--h-2);
	height: var(--wp--preset--font-size--h-2);
	background-color: var(--wp--preset--color--white);
	mask: var(--ragazzo-plus-icon) center / contain no-repeat;
	transform: translate(-50%, -80%);
	visibility: hidden;
	transition: transform 0.3s linear;
}

.is-style-plus > .wp-block-cover__background {
	transition: opacity 0.3s linear;
}

.is-style-plus > .wp-block-cover__inner-container {
	transition: opacity 0.2s linear;
}

@media (min-width: 1200px) and (hover: hover) {

	.is-style-plus:is(:hover, :focus-within) > .wp-block-cover__background,
	.is-style-plus:is(:hover, :focus-within) > .wp-block-cover__inner-container {
		opacity: 0;
	}

	.is-style-plus:is(:hover, :focus-within)::before {
		visibility: visible;
		transform: translate(-50%, -50%);
	}
}

/*
 * Reduced motion: no zoom, no sliding; state changes are instant (base.css
 * also zeroes durations).
 */
@media (prefers-reduced-motion: reduce) {

	:is(.is-style-tile, .is-style-plus) > .wp-block-cover__image-background,
	:is(.is-style-tile, .is-style-plus):is(:hover, :focus-within) > .wp-block-cover__image-background {
		transform: none;
		transition: none;
	}

	.is-style-plus:is(:hover, :focus-within)::before {
		transform: translate(-50%, -50%);
	}
}


/*
 * Page hero (className `is-page-hero`, e.g. Chi siamo): breadcrumbs and title
 * at the top left, where the other pages show them under the header. From
 * 1200px the header is fixed over the hero (has-transparent-header), so the
 * content starts below it (header 75px + the breadcrumbs' spacing).
 */
.is-page-hero.wp-block-cover {
	padding-top: var(--wp--preset--spacing--30);
	padding-bottom: var(--wp--preset--spacing--section);
}

@media (min-width: 1200px) {

	.has-transparent-header .is-page-hero.wp-block-cover {
		padding-top: calc(75px + var(--wp--preset--spacing--30));
	}
}

.is-page-hero .wp-block-cover__inner-container > .wp-block-breadcrumbs + * {
	margin-top: var(--wp--preset--spacing--section);
}
