/*
 * Block-style paint: kadence/postgrid + is-style-bookflow
 *
 * 3D coverflow choreography synced with Splide autoplay.
 * Registered as block-style by the `palmetto` plugin; this file
 * paints it from the child theme (Layer 3) per the plugin/theme split.
 *
 * Each chain offset has a static transform + a 600ms animation that
 * morphs to the rest scale of the column ONE LEFT (Splide moves the
 * list leftward by one column per tick). Animation `forwards` makes
 * the end value persist so when `.is-active` flips and chain
 * re-matches, the new rule's static matches → no jiggle.
 *
 * Transforms target `.kt-blocks-post-grid-item` (the article element
 * = 2 levels above `.kadence-post-image`, 1 level below
 * `.splide__slide`). Why this level:
 *   - `.splide__slide` itself is off-limits — Splide animates its
 *     siblings via `.splide__list` translateX and our transform would
 *     collide.
 *   - The article element is where Kadence applies its own
 *     `displayShadow` box-shadow (see
 *     class-kadence-blocks-pro-postgrid-block.php @line 929), so any
 *     shadow set via the block's Inspector scales naturally with the
 *     coverflow transform.
 */

@keyframes pp-bookflow-c0-shrink { from { transform: scale(.6);                  } to { transform: scale(.5);                  } }
@keyframes pp-bookflow-c1-shrink { from { transform: scale(.85) translateX(-15%); } to { transform: scale(.6);                  } }
@keyframes pp-bookflow-c2-shrink { from { transform: scale(1);                   } to { transform: scale(.85) translateX(-15%); } }
@keyframes pp-bookflow-c3-grow   { from { transform: scale(.85) translateX(15%);  } to { transform: scale(1);                   } }
@keyframes pp-bookflow-c4-grow   { from { transform: scale(.6);                  } to { transform: scale(.85) translateX(15%);  } }
@keyframes pp-bookflow-c5-grow   { from { transform: scale(.5);                  } to { transform: scale(.6);                  } }

.wp-block-kadence-postgrid.is-style-bookflow .kt-post-grid-layout-carousel-wrap { padding: 40px 0; }

/* Kill the <ul> bullets BEFORE Splide initialises. The raw server markup is
   `ul.kt-post-grid-wrap`; Splide upgrades it to `.splide__list` (whose own CSS
   clears list styling) only after JS runs — until then default bullets flash.
   This sheet loads in <head>, so clearing them on the pre-init class makes it
   independent of the JS init. Both classes covered so it stays clear through
   the upgrade. */
.wp-block-kadence-postgrid.is-style-bookflow .kt-post-grid-wrap,
.wp-block-kadence-postgrid.is-style-bookflow .splide__list {
	list-style: none;
	margin: 0;
	padding: 0;
}
/* X-axis clip needed for the slider to hide off-window slides, but Y-axis
   stays visible so drop-shadows below covers don't get cut off.
   `overflow-x: clip` not `hidden` — CSS spec auto-promotes one axis to
   `auto` if the other is `hidden`, but `clip` doesn't create a scroll
   container, so `overflow-y: visible` actually sticks. */
.wp-block-kadence-postgrid.is-style-bookflow .splide__track {
	overflow-x: clip;
	overflow-y: visible;
}
.wp-block-kadence-postgrid.is-style-bookflow .splide__list {
	align-items: center;
	--pp-bookflow-delay: 4200ms;
	/* Drag is disabled in the bookflow runtime JS — override Splide's
	   default `cursor: grab` so the cursor doesn't suggest a draggable
	   surface. */
	cursor: default;
}
.wp-block-kadence-postgrid.is-style-bookflow .splide__list.pp-steady { --pp-bookflow-delay: 3600ms; }

/* Default rest for the article (off-window slides). */
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide .kt-blocks-post-grid-item {
	transform-origin: 50% 75%;
	transform: scale(.5);
}

/* Inner wrapper holds the cover image + the spine/page pseudo-elements +
   the drop shadow. Hover lifts the whole stack upward with a slight
   overshoot ("back" easing) — the book pops off the shelf. Shadow
   deepens simultaneously so it reads as "further from ground". */
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide .kadence-post-image {
	position: relative;
	transition: transform 350ms cubic-bezier(.34, 1.56, .64, 1),
	            box-shadow 350ms ease;
	box-shadow: 0 14px 24px -10px rgba(50, 40, 30, .5),
	            0 4px 8px -2px rgba(50, 40, 30, .3);
}
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide .kt-blocks-post-grid-item:hover .kadence-post-image {
	transform: translateY(-14px);
	box-shadow: 0 28px 36px -12px rgba(50, 40, 30, .55),
	            0 8px 14px -4px rgba(50, 40, 30, .35);
}

/* PAGE STACK — pseudo-strip mostly OUTSIDE the cover's right edge,
   faking the visible side of book pages. z-index 0 so it sits behind
   the cover image; only the part extending outside the cover (~10px
   on the right) is visible at rest. With hover-rotation revealing the
   right side, more of it becomes visible. */
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide .kadence-post-image::before {
	content: '';
	position: absolute;
	top: 2%;
	right: -7px;
	width: 7px;
	height: 96%;
	background: linear-gradient(
		to right,
		#ffffff 0%, #f0f3f5 50%, #d4dade 100%
	);
	border-radius: 0 2px 2px 0;
	box-shadow: 1px 1px 2px rgba(0, 0, 0, .12);
	opacity: .8;
	z-index: 0;
	pointer-events: none;
}

/* BINDING SHADOW — solid dark strip on the LEFT edge of the cover
   simulating the hardcover binding crease. z-index 2 above the cover
   image. On hover-rotation the binding visually "tilts" with the
   cover face. */
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide .kadence-post-image::after {
	content: '';
	position: absolute;
	top: 0;
	left: 0;
	width: 18px;
	height: 100%;
	background: linear-gradient(
		to right,
		rgba(0, 0, 0, .45) 0%,
		rgba(0, 0, 0, .22) 40%,
		rgba(0, 0, 0, .08) 75%,
		rgba(0, 0, 0, 0) 100%
	);
	z-index: 2;
	pointer-events: none;
}

/* BINDING GROOVE — thin dark vertical line ~10px from the left edge,
   inside the binding shadow zone. Mimics the codepen's `.cover:after`
   detail (a 3px stripe with subtle white halo). z-index 3 to sit above
   the binding shadow + cover image. Uses the otherwise-empty
   `.kadence-post-image-intrisic` element as the host. */
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide .kadence-post-image-intrisic::before {
	content: '';
	position: absolute;
	top: 0;
	bottom: 0;
	left: 7px;
	width: 1px;
	background: rgba(0, 0, 0, .7);
	box-shadow:
		-1px 0 1px rgba(0, 0, 0, .25),
		1px 0 2px rgba(255, 255, 255, .45);
	z-index: 3;
	pointer-events: none;
}

/* Stacking — bigger slides on top so wings don't overlap centre awkwardly. */
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide { z-index: 1; }
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide.is-active { z-index: 3; }
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide.is-active + .splide__slide { z-index: 6; }
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide.is-active + .splide__slide + .splide__slide { z-index: 10; }
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide.is-active + .splide__slide + .splide__slide + .splide__slide { z-index: 6; }
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide.is-active + .splide__slide + .splide__slide + .splide__slide + .splide__slide { z-index: 3; }

/* Per-chain-position rest transforms + 600ms morph animation. */
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide.is-active .kt-blocks-post-grid-item {
	transform: scale(.6);
	animation: pp-bookflow-c0-shrink 600ms ease var(--pp-bookflow-delay) forwards;
}
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide.is-active + .splide__slide .kt-blocks-post-grid-item {
	transform: scale(.85) translateX(-15%);
	animation: pp-bookflow-c1-shrink 600ms ease var(--pp-bookflow-delay) forwards;
}
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide.is-active + .splide__slide + .splide__slide .kt-blocks-post-grid-item {
	transform: scale(1);
	animation: pp-bookflow-c2-shrink 600ms ease var(--pp-bookflow-delay) forwards;
}
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide.is-active + .splide__slide + .splide__slide + .splide__slide .kt-blocks-post-grid-item {
	transform: scale(.85) translateX(15%);
	animation: pp-bookflow-c3-grow 600ms ease var(--pp-bookflow-delay) forwards;
}
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide.is-active + .splide__slide + .splide__slide + .splide__slide + .splide__slide .kt-blocks-post-grid-item {
	transform: scale(.6);
	animation: pp-bookflow-c4-grow 600ms ease var(--pp-bookflow-delay) forwards;
}
.wp-block-kadence-postgrid.is-style-bookflow .splide__slide.is-active + .splide__slide + .splide__slide + .splide__slide + .splide__slide + .splide__slide .kt-blocks-post-grid-item {
	transform: scale(.5);
	animation: pp-bookflow-c5-grow 600ms ease var(--pp-bookflow-delay) forwards;
}

/* Hide Kadence meta header / footer so only the cover shows. */
.wp-block-kadence-postgrid.is-style-bookflow .kt-blocks-post-grid-item-inner,
.wp-block-kadence-postgrid.is-style-bookflow .kt-blocks-post-top-meta,
.wp-block-kadence-postgrid.is-style-bookflow .kt-blocks-post-comments,
.wp-block-kadence-postgrid.is-style-bookflow .kt-blocks-post-footer,
.wp-block-kadence-postgrid.is-style-bookflow .entry-content,
.wp-block-kadence-postgrid.is-style-bookflow .entry-header {
	display: none !important;
}

/* ===========================================================================
 * Editor preview overrides
 * ---------------------------------------------------------------------------
 * In the block-editor canvas Kadence Pro initialises Splide but assigns
 * `width: 0px` to every `.splide__slide` for the bookflow variant (different
 * Splide option chain than the standard postgrid carousel — root cause not
 * worth chasing). Result: every slide + article collapses to 0×0 and the
 * author sees an empty placeholder where the bookflow postgrid should be.
 *
 * Per user direction: a flat grid preview of cover images is enough — the
 * 3D coverflow choreography only matters on the frontend where Splide is
 * fully initialised. These overrides bypass the broken Splide layout in
 * editor only (scoped via `.editor-styles-wrapper` which exists only there).
 * Frontend is unaffected.
 * ========================================================================= */

/* Force a SINGLE-ROW carousel layout — mimics the standard Kadence
 * postgrid carousel preview (4 visible cards, overflow clipped). */
.editor-styles-wrapper .wp-block-kadence-postgrid.is-style-bookflow .splide__list {
	flex-wrap: nowrap !important;
	align-items: stretch !important;
	display: flex !important;
}
.editor-styles-wrapper .wp-block-kadence-postgrid.is-style-bookflow .splide__slide {
	width: 25% !important;
	flex-shrink: 0 !important;
	flex-basis: 25% !important;
	padding: 0 12px;
	box-sizing: border-box;
}

/* Disable the coverflow transform / animation choreography — they're
 * designed for Splide's autoplay-driven `.is-active` modifier flow which
 * doesn't run in editor. Without this every slide stays at the default
 * `scale(.5)` rest, shrinking covers to 50%. */
.editor-styles-wrapper .wp-block-kadence-postgrid.is-style-bookflow .splide__slide .kt-blocks-post-grid-item,
.editor-styles-wrapper .wp-block-kadence-postgrid.is-style-bookflow .splide__slide .kt-post-grid-item {
	transform: none !important;
	animation: none !important;
}
