/**
 * Ian's Pizza — [stack_animation] box stack scene
 *
 * Enqueued from inc/ip-stack-animation.php, and only on pages that actually
 * contain the shortcode.
 *
 * ---------------------------------------------------------------------------
 * SCOPING RULE — every selector in this file starts with .ip-stack
 * ---------------------------------------------------------------------------
 * Nothing here may style a bare element, a theme class, or anything outside the
 * scene. `.ip-stack p { ... }`, never `p { ... }`.
 *
 * The prototype's own class names were deliberately renamed on the way in. It
 * used .box, .face, .top, .left, .stack, .progress — none of which collide with
 * the theme's stylesheet today, but all of which are names someone could
 * plausibly add to it later. Prefixing protects the scene in both directions:
 * nothing here escapes, and nothing global reaches in.
 *
 * Custom properties live on .ip-stack rather than :root for the same reason.
 *
 * NOT ported from the prototype, deliberately:
 *   - the `*` and `html` global resets, which would have reached the whole site
 *   - the intro/outro placeholder sections and their copy
 *   - the plum page background and the light/dark :root theme blocks
 *   - the Bricolage Grotesque webfont (the theme has its own faces)
 *   - the debug progress bar
 * The scene is transparent, so the page behind it supplies the background.
 */

.ip-stack {
	position: relative;
	width: 100%;

	/* Box geometry. Height tracks the 1200x173 edge artwork ratio.
	   These are the BOX width; what matters is the painted width of the rotated
	   stack, measured at its widest — the END of the animation, where the boxes
	   have separated and moved toward the camera. Measured, not derived.
	     438px box -> ~800px painted at full spread  (the desktop cap)
	     60vw box  -> ~111% of viewport, i.e. ~90% of the stack on screen
	   Change these only against a fresh measurement of the exploded state. */
	--ip-stack-w: min(60vw, 438px);
	--ip-stack-d: var(--ip-stack-w);
	--ip-stack-h: calc(var(--ip-stack-w) * 173 / 1200);

	/* Plain cardboard, for the unprinted underside of a box. */
	--ip-stack-board: #D9CDB8;
	--ip-stack-shadow: rgba(66, 50, 61, 0.45);
}

.ip-stack__scene {
	position: relative;
	display: grid;
	place-items: center;
	width: 100%;
	/* A full-height stage, no longer pinned: the exploded stack and the
	   laid-flat detail view both need the room. Deliberately vh, not dvh — dvh
	   changes as mobile browser chrome hides and shows, which would resize the
	   stage and shift the page under the reader mid-scroll. */
	height: 100vh;
	/* Perspective is proportional to the box, never a fixed length.
	   The prototype was tuned at a 320px box with 1200px perspective — a ratio
	   of 3.75. Enlarging the box while leaving perspective fixed exaggerates
	   depth: the boxes separate along Y, rotationX turns most of that into Z,
	   and the top box then rushes the camera and balloons. Holding the ratio
	   keeps the composition identical at any size. */
	perspective: calc(var(--ip-stack-w) * 3.75);
}

.ip-stack__boxes {
	position: relative;
	width: var(--ip-stack-w);
	height: var(--ip-stack-h);
	transform-style: preserve-3d;
}

/* Hold the scene until every lid has decoded, so none of them decode mid-scroll
   the first time a lower box is uncovered. `.is-ready` is set by the script
   after the decode, or after a 2.5s ceiling, whichever comes first — and
   immediately in the static and no-GSAP paths. */
.ip-stack__scene {
	opacity: 0;
	transition: opacity .35s ease;
}

.ip-stack.is-ready .ip-stack__scene {
	opacity: 1;
}

/* Belt and braces: if the script never runs at all, nothing should stay
   invisible. */
@media (scripting: none) {
	.ip-stack__scene {
		opacity: 1;
	}
}

.ip-stack__shadow {
	position: absolute;
	left: 50%;
	top: 50%;
	width: calc(var(--ip-stack-w) * 1.3);
	height: calc(var(--ip-stack-w) * 0.5);
	margin-left: calc(var(--ip-stack-w) * -0.65);
	margin-top: calc(var(--ip-stack-w) * 0.5);
	border-radius: 50%;
	background: radial-gradient(closest-side, var(--ip-stack-shadow), transparent);
	/* No blur: the gradient is already soft, and blurring an element that is
	   being scaled every frame is an expensive full repaint for no visible
	   gain. */
	pointer-events: none;
}

/* The pizza wheel. The clip is the stage, but only sideways: the wheel hangs
   off the right edge and must not widen the page, while top and bottom it
   runs past the stage instead of stopping on a hard line. overflow: clip is
   what allows one axis clipped and the other visible (hidden would force the
   other axis to scroll), so hidden stays as the fallback for older browsers.
   A sibling of the 3D stack, so the stack is never clipped or flattened.
   Hidden until a box opens; the script sizes, places and turns it. */
.ip-stack__wheel-clip {
	position: absolute;
	inset: 0;
	overflow: hidden;
	pointer-events: none;
}

@supports (overflow: clip) {
	.ip-stack__wheel-clip {
		overflow-x: clip;
		overflow-y: visible;
	}
}

.ip-stack__wheel {
	position: absolute;
	left: 0;
	top: 0;
	max-width: none;
	height: auto;
	visibility: hidden;
	will-change: transform;
}

.ip-stack.is-static .ip-stack__wheel-clip {
	display: none;
}

/* Desktop only. */
@media screen and (max-width: 859px) {
	.ip-stack__wheel-clip {
		display: none;
	}
}

/* Under the box laid out in the detail view. Sized, placed and faded by the
   script; flat and behind the 3D stack, so it can never z-fight a face. A
   soft gradient with no edge of its own, set a little low: the box covers the
   middle and only the fall-off shows below. (A box-shadow on a square showed
   the square's own pale edge under the tilted lid.) Soft, but visible: at
   .26 it darkened the page by about 2% and read as no shadow at all
   (2026-09-30). */
.ip-stack__hero-shadow {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 0;
	height: 0;
	border-radius: 50%;
	background: radial-gradient(closest-side, rgba(30, 20, 28, .42), rgba(30, 20, 28, .18) 70%, rgba(30, 20, 28, 0));
	opacity: 0;
	pointer-events: none;
}

.ip-stack.is-static .ip-stack__hero-shadow {
	display: none;
}

/* --------------------------------------------------------------------------
   The box — six faces around a .ip-stack__lift, which carries the hover offset
   so it never fights the scroll tween.
   -------------------------------------------------------------------------- */

.ip-stack__box,
.ip-stack__lift,
.ip-stack__card {
	position: absolute;
	inset: 0;
	transform-style: preserve-3d;
}

/* The box is a real <button>, so the user-agent styling has to go before it
   can act as a 3D transform container. pointer-events:none keeps the button
   box itself from swallowing hover — only the painted faces take the pointer —
   while the element stays keyboard focusable and activatable. */
/* No grey flash on tap in iOS Safari, anywhere in the scene. */
.ip-stack,
.ip-stack * {
	-webkit-tap-highlight-color: transparent;
}

.ip-stack__box {
	appearance: none;
	-webkit-appearance: none;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	font: inherit;
	color: inherit;
	text-align: inherit;
	pointer-events: none;
	outline: none;
}

.ip-stack__face {
	position: absolute;
	left: 50%;
	top: 50%;
	backface-visibility: hidden;
	background-color: var(--ip-stack-board);
	background-size: 100% 100%;
	background-repeat: no-repeat;
	pointer-events: auto;
}

.ip-stack.is-spreadable .ip-stack__face {
	cursor: pointer;
}

/* The keyboard ring, for keyboard use only. [data-pointer] is set by the
   script while the last input was a mouse or touch: closing a panel hands
   focus back to its box, and Safari counted that as keyboard focus, leaving
   a yellow outline on the box after a tap. */
.ip-stack__box:focus-visible .ip-stack__face--top {
	outline: 3px solid #FBE140;
	outline-offset: -3px;
}

.ip-stack[data-pointer] .ip-stack__box:focus-visible .ip-stack__face--top,
.ip-stack[data-pointer].is-static .ip-stack__box:focus-visible {
	outline: none;
}

.ip-stack__face--top,
.ip-stack__face--bottom {
	width: var(--ip-stack-w);
	height: var(--ip-stack-d);
	margin: calc(var(--ip-stack-d) / -2) 0 0 calc(var(--ip-stack-w) / -2);
}

.ip-stack__face--front,
.ip-stack__face--back {
	width: var(--ip-stack-w);
	height: var(--ip-stack-h);
	margin: calc(var(--ip-stack-h) / -2) 0 0 calc(var(--ip-stack-w) / -2);
}

.ip-stack__face--left,
.ip-stack__face--right {
	width: var(--ip-stack-d);
	height: var(--ip-stack-h);
	margin: calc(var(--ip-stack-h) / -2) 0 0 calc(var(--ip-stack-d) / -2);
}

.ip-stack__face--top    { transform: rotateX(90deg)   translateZ(calc(var(--ip-stack-h) / 2)); }
.ip-stack__face--bottom { transform: rotateX(-90deg)  translateZ(calc(var(--ip-stack-h) / 2)); }
.ip-stack__face--front  { transform: translateZ(calc(var(--ip-stack-d) / 2)); }
.ip-stack__face--back   { transform: rotateY(180deg)  translateZ(calc(var(--ip-stack-d) / 2)); }
.ip-stack__face--right  { transform: rotateY(90deg)   translateZ(calc(var(--ip-stack-w) / 2)); }
.ip-stack__face--left   { transform: rotateY(-90deg)  translateZ(calc(var(--ip-stack-w) / 2)); }

/* Light sits up and to the right, so the left edge falls into shade.
   This was `filter: brightness()` in the prototype. A filter on an element
   inside a preserve-3d context forces the browser to rasterise and flatten it
   — Safari especially — which is a well-known source of jitter and z-fighting
   in 3D scenes. A flat tint overlay is visually equivalent and stays on the
   compositor. brightness(.94) ~= 6% black, brightness(.72) ~= 28% black. */
.ip-stack__face--front::after,
.ip-stack__face--left::after {
	content: "";
	position: absolute;
	inset: 0;
	pointer-events: none;
}

.ip-stack__face--front::after { background: rgba(0, 0, 0, 0.06); }
.ip-stack__face--left::after  { background: rgba(0, 0, 0, 0.28); }

/* --------------------------------------------------------------------------
   Packaging art. Lid on top, edge strip reused on all four sides.
   Paths are relative to this file: css/ -> img/stack/
   -------------------------------------------------------------------------- */

.ip-stack__box[data-flavor="cheese"] .ip-stack__face--top {
	background-image: url("../img/stack/lid-cheese.webp");
}
.ip-stack__box[data-flavor="cheese"] :is(.ip-stack__face--front, .ip-stack__face--back, .ip-stack__face--left, .ip-stack__face--right) {
	background-image: url("../img/stack/edge-cheese.webp");
}

.ip-stack__box[data-flavor="pepperoni"] .ip-stack__face--top {
	background-image: url("../img/stack/lid-pepperoni.webp");
}
.ip-stack__box[data-flavor="pepperoni"] :is(.ip-stack__face--front, .ip-stack__face--back, .ip-stack__face--left, .ip-stack__face--right) {
	background-image: url("../img/stack/edge-pepperoni.webp");
}

.ip-stack__box[data-flavor="sausage"] .ip-stack__face--top {
	background-image: url("../img/stack/lid-sausage.webp");
}
.ip-stack__box[data-flavor="sausage"] :is(.ip-stack__face--front, .ip-stack__face--back, .ip-stack__face--left, .ip-stack__face--right) {
	background-image: url("../img/stack/edge-sausage.webp");
}

.ip-stack__box[data-flavor="macncheese"] .ip-stack__face--top {
	background-image: url("../img/stack/lid-macncheese.webp");
}
.ip-stack__box[data-flavor="macncheese"] :is(.ip-stack__face--front, .ip-stack__face--back, .ip-stack__face--left, .ip-stack__face--right) {
	background-image: url("../img/stack/edge-macncheese.webp");
}

/* --------------------------------------------------------------------------
   Legend — names what's in the stack, and is the accessible text for it.
   -------------------------------------------------------------------------- */

.ip-stack__legend {
	position: absolute;
	left: 1.25rem;
	bottom: 1.25rem;
	margin: 0;
	max-width: calc(100% - 2.5rem);
	font-size: 0.95rem;
	opacity: 0.75;
}

/* --------------------------------------------------------------------------
   Static fallback — `prefers-reduced-motion`, no GSAP, or no JavaScript.

   The same markup, laid out as a flat grid of lids. Nothing here has to be
   kept in sync with the animated scene because there is only one set of boxes;
   the 3D positioning is all applied by script, so simply not applying it
   leaves ordinary flow behind.
   -------------------------------------------------------------------------- */

.ip-stack.is-static .ip-stack__scene {
	height: auto;
	min-height: 0;
	padding-block: 2rem;
	perspective: none;
}

.ip-stack.is-static .ip-stack__boxes {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
	gap: 1.25rem;
	width: min(100%, 720px);
	height: auto;
	transform-style: flat;
	padding-inline: 1.25rem;
}

.ip-stack.is-static .ip-stack__box {
	position: relative;
	inset: auto;
	pointer-events: auto;
	cursor: pointer;
	transform-style: flat;
	/* A square tile: the lid artwork is 1:1. */
	aspect-ratio: 1;
}

.ip-stack.is-static .ip-stack__lift,
.ip-stack.is-static .ip-stack__card {
	position: absolute;
	inset: 0;
	transform-style: flat;
}

/* Only the lid is shown flat on: an edge strip seen face-on reads as a stripe. */
.ip-stack.is-static .ip-stack__face--front,
.ip-stack.is-static .ip-stack__face--left {
	display: none;
}

.ip-stack.is-static .ip-stack__face--top {
	position: absolute;
	inset: 0;
	width: auto;
	height: auto;
	margin: 0;
	transform: none;
	border-radius: 4px;
}

.ip-stack.is-static .ip-stack__box:focus-visible {
	outline: 3px solid #FBE140;
	outline-offset: 3px;
}

/* The floor shadow belongs to the 3D scene. In the flat grid it has nothing to
   sit under, and because the scene is not pinned it paints over whatever
   follows on the page. */
.ip-stack.is-static .ip-stack__shadow {
	display: none;
}

.ip-stack.is-static .ip-stack__legend {
	position: static;
	margin-top: 1.25rem;
	text-align: center;
	max-width: none;
}

/* --------------------------------------------------------------------------
   Interaction hint — both are rendered, one is shown.
   -------------------------------------------------------------------------- */

.ip-stack__hint {
	margin: 0 0 1rem;
	text-align: center;
	opacity: .75;
}

.ip-stack__hint--static {
	display: none;
}

.ip-stack.is-static .ip-stack__hint--motion {
	display: none;
}

.ip-stack.is-static .ip-stack__hint--static {
	display: block;
}

/* --------------------------------------------------------------------------
   Flavour panel — shares the stage with the box, rather than covering it.

   Desktop: the box lays flat on the left half, the copy comes in on the right.
   Mobile: the box goes to the top half, the copy below it. The halves are set
   here; the box's own travel is computed in the script, because it has to be
   worked out against the stack's live 3D rotation.
   -------------------------------------------------------------------------- */

.ip-stack__detail {
	position: absolute;
	inset: 0;
	display: grid;
	pointer-events: none;
	z-index: 5;
}

/* All panels occupy the same cell so only one is ever seen; the media queries
   below then move that cell to whichever half the box is not using. This has to
   come first — `grid-area` and `grid-column` are the same specificity, so a
   later `grid-area: 1 / 1` would quietly undo them. */
.ip-stack__panel {
	position: relative;
	grid-row: 1;
	grid-column: 1;
	pointer-events: auto;
}

/* Desktop: box left, copy right. */
@media screen and (min-width: 860px) {
	.ip-stack__detail {
		grid-template-columns: 50% 50%;
	}

	.ip-stack__panel {
		grid-row: 1;
		grid-column: 2;
		align-self: center;
		padding-right: clamp(1.5rem, 5vw, 5rem);
		padding-left: clamp(1rem, 2vw, 2rem);
		max-width: 34rem;
	}
}

/* Mobile: box in the top 47%, the copy below it, and the arrows below the
   copy (2026-10-01; the box went full width and the arrows left its edges). */
@media screen and (max-width: 859px) {
	.ip-stack__detail {
		grid-template-rows: 47% auto 1fr;
	}

	.ip-stack__panel-inner {
		padding: 1.25rem 1.25rem 1.4rem;
	}

	.ip-stack__panel-title {
		font-size: 1.75rem;
	}

	.ip-stack__panel-body,
	.ip-stack__panel-footer {
		font-size: .875rem;
		line-height: 1.45;
	}

	.ip-stack__panel-body {
		margin-bottom: .75em;
	}

	.ip-stack__panel {
		grid-row: 2;
		grid-column: 1;
		align-self: start;
		padding: 0 1.5rem;
		overflow-y: auto;
	}
}

.ip-stack__panel[hidden] {
	display: none;
}

/* Every panel is Kalamata with light text. The colour belongs to the page
   instead: the section behind the stack fades to the open box's main fill,
   which the page's own stylesheet keys off [data-open] on the root (see
   anywhere.css). The CTA is the theme's .btn-outline, which takes the text
   colour. */
.ip-stack__panel-inner {
	position: relative;
	padding: clamp(1.5rem, 3vw, 2.5rem);
	border-radius: 22px;   /* the theme's .card radius */
	background: #42323D;
	color: #fff;
}

.ip-stack__panel-inner a.btn-outline,
.ip-stack__panel-inner a.btn-outline:visited {
	color: #fff !important;   /* the theme colours links; this is a button */
	border-color: #fff;
}

.ip-stack__panel-inner a.btn-outline:hover,
.ip-stack__panel-inner a.btn-outline:focus-visible {
	background: #fff;
	color: #42323D !important;
}

/* The panel takes focus on open so Escape and the arrow keys work. It is not
   a control, so it gets no ring — that was the blue outline on iOS. */
.ip-stack__panel:focus {
	outline: none;
}

.ip-stack__panel-close {
	position: absolute;
	/* Above the staggered lines: their will-change gives each its own layer,
	   and on a phone the tagline ran under the button and ate the tap. */
	z-index: 1;
	top: .5rem;
	right: .5rem;
	/* 44px, the same tap target the locator's call button uses. */
	width: 44px;
	height: 44px;
	display: flex;
	align-items: center;
	justify-content: center;
	appearance: none;
	-webkit-appearance: none;
	border: 0;
	border-radius: 50%;
	background: none;
	color: inherit;
	font-size: 1.75rem;
	line-height: 1;
	cursor: pointer;
}

.ip-stack__panel-close:hover,
.ip-stack__panel-close:focus-visible {
	background: rgba(255, 255, 255, .14);
}

/* The children the script staggers in. Their resting state is the animated-in
   one, so with no JavaScript, or with GSAP missing, the copy simply reads. */
.ip-stack__panel [data-ip-stack-anim] {
	will-change: transform, opacity;
}

.ip-stack__panel-title {
	margin: 0 0 .35em;
	padding-right: 2.5rem;   /* clear of the close button */
	font-size: clamp(2rem, 4vw, 3.25rem);
	line-height: 1;
}

.ip-stack__panel-body {
	margin: 0 0 1em;
	font-size: clamp(1rem, 1.4vw, 1.1875rem);
	max-width: 34ch;
}

.ip-stack__panel-footer {
	margin: 0 0 1.25em;
	padding-top: .75em;
	border-top: 1px solid rgba(255, 255, 255, .25);
	font-size: .9375rem;
	/* A softer colour, not opacity: the stagger animates opacity and clears
	   it when done, so a resting opacity snapped in at the end. */
	color: rgba(255, 255, 255, .8);
	max-width: 34ch;
}

.ip-stack__panel-cta {
	margin: 0;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: .75rem 1.25rem;
}

/* The optional secondary link beside "Find a store": a plain underlined link,
   white on the Kalamata panel. */
.ip-stack__panel-more,
.ip-stack__panel-more:visited {
	color: #fff !important;   /* the theme colours links */
	font-family: 'Work Sans', sans-serif;
	font-size: .9375rem;
	font-weight: 700;
	text-decoration: underline;
	text-underline-offset: .2em;
}

/* While a box is laid out flat, the legend and the hint would only compete. */
.ip-stack.is-open .ip-stack__legend,
.ip-stack.is-open .ip-stack__hint {
	opacity: 0;
	transition: opacity .25s ease;
	pointer-events: none;
}

/* The whole stack stops taking hover once a box is open, so the spread does not
   fight the flat-out. */
.ip-stack.is-open .ip-stack__face {
	cursor: default;
}

.ip-stack.is-open .ip-stack__box[aria-expanded="true"] .ip-stack__face {
	cursor: pointer;
}

/* --------------------------------------------------------------------------
   Static fallback: no stage to share, so the panel is a plain block under the
   grid rather than a half of the screen.
   -------------------------------------------------------------------------- */

.ip-stack.is-static .ip-stack__detail {
	position: static;
	display: block;
	margin-top: 1.5rem;
}

.ip-stack.is-static .ip-stack__panel {
	grid-area: auto;
	max-width: 42rem;
	margin-inline: auto;
	padding: 0 1.25rem;
}

.ip-stack.is-static .ip-stack__panel-close {
	position: static;
	margin-left: auto;
}

/* Editor-only slot for the heating instructions, pending the copy off the box. */
/* --------------------------------------------------------------------------
   Flavour arrows — shown while a box is open. Arrow keys and a horizontal
   swipe do the same. Vertically centred on the open box: the middle of the
   stage on desktop, the middle of the top half on phones.
   -------------------------------------------------------------------------- */

.ip-stack__nav {
	position: absolute;
	inset: 0;
	pointer-events: none;
	z-index: 1;
}

.ip-stack__nav[hidden] {
	display: none;
}

.ip-stack__nav-btn {
	position: absolute;
	top: 50%;
	width: 48px;
	height: 48px;
	margin-top: -24px;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	appearance: none;
	-webkit-appearance: none;
	border: 0;
	border-radius: 50%;
	background: #42323D;
	color: #fff;
	cursor: pointer;
	pointer-events: auto;
	transition: transform .15s ease;
}

/* Real hover only: on touch screens :hover sticks after a tap. */
@media (hover: hover) {
	.ip-stack__nav-btn:hover {
		transform: scale(1.06);
	}
}

.ip-stack__nav-btn:focus {
	outline: none;
}

.ip-stack__nav-btn:focus-visible {
	outline: 3px solid #FBE140;
	outline-offset: 2px;
}

.ip-stack__nav-btn--prev { left: clamp(.5rem, 2vw, 1.5rem); }
.ip-stack__nav-btn--next { right: clamp(.5rem, 2vw, 1.5rem); }

@media screen and (max-width: 859px) {
	/* A centred row under the text panel, in the detail grid's third row
	   (2026-10-01): the box is full width now, so nothing may sit over it. */
	.ip-stack__nav {
		position: static;
		grid-row: 3;
		grid-column: 1;
		align-self: start;
		display: flex;
		justify-content: center;
		gap: 1rem;
		padding-top: .75rem;
	}

	.ip-stack__nav-btn {
		position: static;
		width: 44px;
		height: 44px;
		margin: 0;
		box-shadow: 0 3px 10px rgba(30, 20, 28, .3);
	}
}

/* Let a horizontal swipe reach the script while a box is open; vertical
   scrolling is untouched. */
.ip-stack.is-open .ip-stack__scene {
	touch-action: pan-y;
}

/* Static fallback: a plain row above the panel. */
.ip-stack.is-static .ip-stack__nav {
	position: static;
	display: flex;
	justify-content: center;
	gap: 1rem;
	margin-bottom: 1rem;
}

.ip-stack.is-static .ip-stack__nav[hidden] {
	display: none;
}

.ip-stack.is-static .ip-stack__nav-btn {
	position: static;
	margin: 0;
}
