/**
 * Card-finish overlay (foil shimmer). Applies to three places, all via the
 * same [data-finish] attribute:
 *   - Shop grid tile default image  (.pcf-tile-media-link, astra-child theme)
 *   - Fan-out hover cards           (.pcf-fan-card, astra-child theme)
 *   - Single product main image     (.woocommerce-product-gallery__image)
 *
 * Every non-"regular" finish gets the exact same treatment — one rainbow
 * sweep, screen blend. There is no per-finish palette, pattern, or bespoke
 * artwork; past attempts at that (per-family palettes, a licensed gold-leaf
 * border, a generated spiral swirl, masked pattern-reveal layers) all added
 * real complexity for a difference that didn't earn its keep. This is the
 * simple version, on purpose — don't reintroduce per-finish branching here.
 *
 * "regular" is never given the attribute at all (see the PHP/JS that set
 * data-finish) — so this file costs zero markup/CSS for the majority
 * non-foil case, and the selector below can stay a bare [data-finish]
 * rather than an explicit list of every other slug in the taxonomy.
 */

/* ============================================
   CONTAINER PREP
   The tile/fan elements are already position:absolute + overflow:hidden
   (product-tile.css) — nothing to add there. The single-product gallery
   wrapper is not, by default, so it's set up here, unconditionally (cheap,
   and avoids a layout jump the moment JS adds data-finish on variation
   change).
   ============================================ */

.woocommerce-product-gallery__image {
	position: relative;
	overflow: hidden;
}

/* ============================================
   GLOBAL SYNC
   Single canonical cycle length the animation's duration reads from —
   foil-effects.js reads this same custom property (not a duplicated JS
   constant) so the two can never drift out of step. Every card on the page
   shares this exact duration so they all pulse in lockstep — two animations
   only ever start together on every single cycle if their periods are
   IDENTICAL, never just similar.
   ============================================ */

:root {
	--pcf-foil-cycle: 3s;
}

/* ============================================
   SWEEP
   background-size is uniform (220% 220%, not stretched per-axis) so the
   145deg gradient's angle survives on screen — a non-uniform background-size
   shears a diagonal gradient toward vertical. no-repeat is required too:
   without it the panned tile repeats by default, and a repeated background
   always tiles on an axis-aligned grid regardless of the gradient's own
   angle, showing as a straight line cutting across the sweep as the pan
   nears the tile edge.

   Both keyframe ends sit at opacity:0, so the one hard reset a looping CSS
   animation can't avoid (background-position snapping back for the next
   iteration) happens while invisible, reading as seamless. Each leg sets
   its OWN animation-timing-function (ease-in on the rest→peak leg, ease-out
   on peak→rest) rather than one blanket ease-in-out, which stalls right at
   the peak (two decelerating legs meeting at zero velocity from both
   sides).

   The active window (dead-end% -> peak% -> dead-start%) is what actually
   controls how fast the gradient itself travels across the card — that's
   independent of --pcf-foil-cycle, which only controls how often it
   repeats. Widening this window makes the wipe itself take longer without
   touching the repeat rate; narrowing it (as a smaller cycle does by
   proportionally shrinking every phase, wipe included) makes it snappier.
   At the current 60/72/85 split the wipe spans 25% of one cycle — 0.75s of
   the current 3s --pcf-foil-cycle — versus the original 68/75/85 split's
   17%, which read as too quick once the cycle itself was shortened.
   ============================================ */

@keyframes pcf-foil-sweep {
	0%,
	60% {
		opacity: 0;
		background-position: -40% -40%;
		animation-timing-function: ease-in;
	}
	72% {
		opacity: 0.3;
		background-position: 60% 60%;
		animation-timing-function: ease-out;
	}
	85%,
	100% {
		opacity: 0;
		background-position: 160% 160%;
	}
}

[data-finish]::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 2;
	pointer-events: none;
	opacity: 0;
	background-image: linear-gradient(
		145deg,
		transparent 0%,
		rgba(255, 60, 220, 0.7) 40%,
		rgba(60, 230, 255, 0.7) 50%,
		rgba(255, 235, 60, 0.7) 60%,
		transparent 70%
	);
	background-size: 220% 220%;
	background-repeat: no-repeat;
	mix-blend-mode: screen;
	animation-name: pcf-foil-sweep;
	animation-duration: var(--pcf-foil-cycle, 7s);
	animation-iteration-count: infinite;
	/* Set per-element by foil-effects.js / product-tile.js — see the
	   GLOBAL SYNC block above and the paused/running note below. */
	animation-delay: var(--foil-delay, 0s);
	/* Starts paused — the delay above is meaningless (and wrong) until JS
	   sets it from the shared clock; JS flips this to "running" (via
	   --foil-play-state — a custom property, because this is a ::after
	   pseudo-element with no DOM node JS can set inline styles on
	   directly) in the same breath, so the animation never accumulates a
	   single frame of drift before it's correct. */
	animation-play-state: var(--foil-play-state, paused);
}

/* ============================================
   TILE HOVER INTERACTION
   The tile's resting photo already fades to opacity:0 once the fan is out
   and hovered (product-tile.css) — the overlay rides along with it rather
   than being left floating over nothing.

   Forces opacity rather than pausing/cancelling the animation. Both of
   those looked like fixes and weren't:

     - animation: none fully removes the animation. The next time this rule
       stops applying (pointer leaves), that's a brand new instance
       starting its clock at "now," still carrying the OLD computed
       --foil-delay — correct only relative to the moment it was computed,
       long before this hover started. Permanent drift, every hover.

     - animation-play-state: paused freezes the running instance's clock in
       place rather than resetting it — but "frozen" is still wrong: a
       hover can last any length of time, and however long it was stays
       permanently missing once resumed (confirmed live: paused 3s, resumed
       still reading the 3-seconds-ago value while every other card had
       moved on).

   Forcing opacity alone sidesteps the problem instead of solving it: since
   nothing about the animation's timeline is ever touched, un-hovering
   always reveals whatever phase every other card has ALSO naturally
   reached by then. !important is required because a running CSS
   animation's own effect on a property normally wins over a plain
   cascaded value for that same property — without it, the animation's own
   opacity keyframe would keep showing through.
   ============================================ */

ul.products li.product.pcf-tile .pcf-tile-media.has-fan:hover .pcf-tile-media-link[data-finish]::after {
	opacity: 0 !important;
}

/* ============================================
   REDUCED MOTION
   Per spec: pause, don't remove — a static low-opacity indicator still
   marks the card's finish.
   ============================================ */
@media (prefers-reduced-motion: reduce) {
	[data-finish]::after {
		animation: none;
		opacity: 0.3;
		background-position: 60% 60%;
	}
}

/* ============================================
   CARD SILHOUETTE

   Rounds every card image to the corner radius of a real card, so a tile
   reads as a card rather than a photograph of one.

   The number is measured, not guessed. Scryfall's PNG rendition carries a
   genuinely transparent rounded corner, so its alpha channel is the card's
   own die-cut: fitting an arc to that edge (subpixel, on a 745px-wide
   printing) gives a 29.7px radius, i.e. 3.99% of the card's width. The
   physical card is nearer 5%, but the artwork is what shoppers actually
   see, so the artwork is what this matches.

   Why the x / y pair rather than a bare 4%: a percentage border-radius
   resolves horizontally against width but VERTICALLY AGAINST HEIGHT. On a
   5:7 card "4%" would mean 4% of width across and 4% of height down — a
   corner half again as tall as it is wide, visibly egg-shaped. Dividing
   the vertical figure by the 1.4 aspect makes both arms the same number of
   pixels, which is what a circular corner requires.

   Every target already sets overflow:hidden, so the image and the foil
   sweep are both clipped to this shape together.
   ============================================ */

:root {
	--pcf-card-radius: 3.99% / 2.85%;
}

/* The single-product image is the one place the x / y pair is not enough.
   Tiles and fan cards are always exactly 5:7, so a pair divided by 1.4 is
   correct for them forever. This box takes the aspect of whatever is in it:
   5:7 for a scan, but 1:1 for a vendor photograph, where that same pair
   draws a corner half again wider than it is tall (measured: 25.8px across
   against 18.4px down).

   A container query unit sidesteps the axis problem entirely — 3.99cqw is
   3.99% of the container's WIDTH on both axes, so the corner stays circular
   whatever shape the image is. Verified circular in both modes at 25.8px.
   The percentage pair is left above it as the fallback: a browser without
   container query support drops the cqw line as invalid and keeps it. */

.woocommerce-product-gallery {
	container-type: inline-size;
}

.woocommerce-product-gallery__image {
	border-radius: var(--pcf-card-radius, 3.99% / 2.85%);
	border-radius: 3.99cqw;
}
