/*
 * Flip-tile pattern family (odd/tasks/pattern-wall-pages.md, T2; owner decision L9
 * "Flip con fallback en touch").
 *
 * Opt-in structural sheet, enqueued on `enqueue_block_assets` by the shared loop in
 * functions.php, so the interaction works on the visitor's page AND on the editor canvas.
 * Scoped to `.cs-flip-tile` only: nothing here reaches another family's markup. The family does
 * not reuse the HubSpot payload-emulation selectors, which belong to the layer a converted page
 * stops loading (constraint S3).
 *
 * Geometry is declared HERE, once on the section, and that is a correction of the first cut
 * (measured, not designed): the measured numbers used to travel as CSS custom properties inline
 * on the section, and THIS WordPress cannot save a custom property from block attributes —
 * `style` with a `--cs-*` key lands in the block comment and is dropped from the markup. The
 * registered pattern therefore parsed with 21 INVALID groups out of 72 blocks (measured: the
 * section plus both faces of all ten tiles). The numbers below are the same measured ones
 * (feature doc L8), so every `var(--cs-flip-tile-*, …)` in this sheet — and a converted page,
 * whose blocks carry no geometry of their own — resolves to exactly what it resolved to before.
 * Each tile's face colours still travel as the block's own `style.color` attributes, because
 * those ARE declarable and the source declares them per tile.
 *
 * This file owns only the mechanics no block attribute can express: the 3D context, the
 * back-face hiding, the rotation, keyboard parity, the no-hover stack and reduced motion.
 *
 * The recovered design this reproduces lives in docs/reference/hubspot-module-css/
 * module_Flip_Tile.min.css and in the legacy section of style.css; the same two deliberate
 * repairs are carried here, for the same reasons:
 *   1. the back face must pre-rotate rotateX(180deg), or after the flip the viewer sees its
 *      own backface and the revealed definition is invisible;
 *   2. :focus-within flips the tile like hover, so the back text is reachable without a
 *      pointer — a tile whose back never shows is a tile whose content is lost.
 */

/* --- the measured geometry (L8), inherited by every tile of the section ------------------------
   250px tile, 10px tile margin, 110px badge with 30px padding and a 50px glyph, 25px back-face
   padding, the badge 45px from the tile top and the label 5px under it. At the theme's 16px root
   these are the same lengths the sheet's own var() fallbacks spell in rem (15.625/0.625/6.875/
   1.875/3.125/1.5625rem), so a page keeps the exact geometry it has today. */
.cs-flip-tile {
	--cs-flip-tile-size: 250px;
	--cs-flip-tile-margin: 10px;
	--cs-flip-tile-badge: 110px;
	--cs-flip-tile-pad: 30px;
	--cs-flip-tile-glyph: 50px;
	--cs-flip-tile-back-pad: 25px;
	--cs-flip-tile-badge-mt: 45px;
	--cs-flip-tile-label-mt: 5px;
}

/* --- the row: a centered wrapping set of tiles --- */
.cs-flip-tile__row {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	align-items: flex-start;
	width: 100%;
}

/* --- one tile: the 3D viewport --- */
.cs-flip-tile__card {
	position: relative;
	width: var(--cs-flip-tile-size, 15.625rem);
	height: var(--cs-flip-tile-size, 15.625rem);
	margin: var(--cs-flip-tile-margin, 0.625rem);
	perspective: 1000px;
	background-color: transparent;
	flex: 0 0 auto;
}

.cs-flip-tile__inner {
	position: relative;
	width: 100%;
	height: 100%;
	text-align: center;
	transform-style: preserve-3d;
	transition: transform 0.6s;
}

/* Hover and keyboard both flip the tile (repair 2). */
.cs-flip-tile__card:hover .cs-flip-tile__inner,
.cs-flip-tile__card:focus-within .cs-flip-tile__inner {
	transform: rotateX(180deg);
}

/* --- the two faces --- */
.cs-flip-tile__front,
.cs-flip-tile__back {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	width: 100%;
	height: 100%;
	backface-visibility: hidden;
	-webkit-backface-visibility: hidden;
	box-sizing: border-box;
}

/* Front: the measured card surface and hairline border. The pair is TOP-anchored, not centered:
   the live badge carries `margin: 45px 0 0` and the label `margin: 5px 0 0`, and those numbers
   come from the section's custom properties above. `justify-content` stays at its flex-start
   default so the air is the source's own, not a centered guess. */
/* flex-start, not center: the measured front anchors its badge 45px from the tile top, and a
   centered pair would sit ~20px lower and swallow the source's own margins. */
.cs-flip-tile__front {
	justify-content: flex-start;
	background-color: #fafafa;
	border: 1px solid #e4e4e4;
	color: #444444;
}

.cs-flip-tile .cs-flip-tile__badge {
	margin: var(--cs-flip-tile-badge-mt, 45px) 0 0;
}

.cs-flip-tile .cs-flip-tile__term {
	margin: var(--cs-flip-tile-label-mt, 5px) 0 0;
	padding-inline: 5px; /* measured on the live label */
}

/* The badge is a circle holding the glyph; its size, padding and glyph size come from the
   section's custom properties. An empty badge is the owner's decision for a glyph the theme
   does not ship (L9), and the circle still paints at the measured size. */
.cs-flip-tile__badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--cs-flip-tile-badge, 6.875rem);
	height: var(--cs-flip-tile-badge, 6.875rem);
	padding: var(--cs-flip-tile-pad, 1.875rem);
	border-radius: 50%;
	background-color: #fa333e;
	box-sizing: border-box;
	flex: 0 0 auto;
}

.cs-flip-tile__glyph {
	margin: 0;
	width: auto;
	line-height: inherit;
}

.cs-flip-tile__glyph img {
	display: block;
	width: var(--cs-flip-tile-glyph, 3.125rem);
	height: var(--cs-flip-tile-glyph, 3.125rem);
}

/* (the label's margin above is the measured one; `.entry-content h4` would otherwise bring its
   own 1.5em/.5em air, which is why these rules are scoped to two classes) */

/* Back: pre-rotated (repair 1). Its colours arrive as the tile block's own style.color
   attributes and win over the sheet. */
.cs-flip-tile__back {
	transform: rotateX(180deg);
}

.cs-flip-tile .cs-flip-tile__definition {
	margin: 0;
	padding: var(--cs-flip-tile-back-pad, 1.5625rem);
}

/* The faces center their children, and a flex item would otherwise shrink to its text; the
   measured card paints its surface edge to edge, so the label and the definition fill it. */
.cs-flip-tile__term,
.cs-flip-tile__definition {
	width: 100%;
	box-sizing: border-box;
}

/* A definition link keeps the tile's own text colour, which may sit on any background. */
.cs-flip-tile__back a {
	color: inherit;
}

/* --- motion preference: keep the flip, drop the animation --- */
@media (prefers-reduced-motion: reduce) {
	.cs-flip-tile__inner {
		transition: none;
	}
}

/* --- no-hover devices (phones, tablets): owner decision L9 ---
   A tile that only reveals its definition under a pointer loses that content on touch, so here
   both faces stack: the card stops being a 3D viewport, each face becomes static and grows with
   its text, and the rotation is removed. Nothing is hidden and nothing is clipped. */
@media (hover: none) {
	.cs-flip-tile__card {
		width: 100%;
		height: auto;
		max-width: var(--cs-flip-tile-size, 15.625rem);
		perspective: none;
	}

	.cs-flip-tile__inner,
	.cs-flip-tile__card:hover .cs-flip-tile__inner,
	.cs-flip-tile__card:focus-within .cs-flip-tile__inner {
		height: auto;
		transform: none;
		transform-style: flat;
	}

	.cs-flip-tile__front,
	.cs-flip-tile__back {
		position: static;
		inset: auto;
		height: auto;
		backface-visibility: visible;
		-webkit-backface-visibility: visible;
	}

	.cs-flip-tile__front {
		border-radius: 0;
	}

	.cs-flip-tile__back {
		transform: none;
		border-radius: 0;
	}
}
