/**
 * Mardi Gras in Saugatuck — motion and easter eggs (front end only).
 *
 * Paired with assets/js/festive.js. The site is complete without either:
 * html.mg-js is set when the script can run, html.mg-motion when the visitor
 * has not asked for reduced motion. Every animation also sits inside
 * prefers-reduced-motion: no-preference, runs once and finishes within 5s,
 * and nothing flashes.
 */

/* -------------------------------------------------------------------------
 * Live messages and the Konami banner
 * ---------------------------------------------------------------------- */

.mg-banner {
	position: fixed;
	top: 16px;
	left: 50%;
	z-index: 1001;
	max-width: calc(100% - 32px);
	padding: 12px 22px 10px;
	border: 1.5px solid var(--mg-gold);
	border-radius: 999px;
	background: var(--mg-deep-purple);
	color: var(--mg-gold);
	font-family: var(--mg-label);
	font-size: var(--wp--preset--font-size--label-s);
	font-weight: 700;
	letter-spacing: 0.14em;
	text-align: center;
	text-transform: uppercase;
	transform: translateX(-50%);
	pointer-events: none;
}

.mg-confetti {
	position: fixed;
	inset: 0;
	z-index: 1000;
	overflow: hidden;
	pointer-events: none;
}

.mg-confetti i {
	position: absolute;
	top: -24px;
	left: var(--x);
	width: var(--s);
	height: var(--s);
	border-radius: 50%;
	background:
		radial-gradient(circle at 34% 34%, rgba(255, 255, 255, 0.9) 0 16%, transparent 20%),
		var(--c);
}

/* Inline corner scrolls added by the script (see 2. below). */
.is-style-corner-scroll > svg {
	display: block;
	width: 100%;
	height: 100%;
}

/* The corners are appended inside the frame, so cancel the block gap and
 * width rules core's layouts give every child. */
.mg-scroll-corners {
	position: absolute;
	inset: var(--mg-corner-inset);
	margin: 0 !important;
	max-width: none !important;
	pointer-events: none;
}

.mg-scroll-corners > svg {
	position: absolute;
	width: var(--mg-corner);
	height: var(--mg-corner);
}

.mg-scroll-corners > svg:nth-child(1) { top: 0; left: 0; }
.mg-scroll-corners > svg:nth-child(2) { top: 0; right: 0; transform: rotate(90deg); }
.mg-scroll-corners > svg:nth-child(3) { right: 0; bottom: 0; transform: rotate(180deg); }
.mg-scroll-corners > svg:nth-child(4) { bottom: 0; left: 0; transform: rotate(270deg); }

/* -------------------------------------------------------------------------
 * Masquerade glow: hovering the Masquerade section's heading, numeral or
 * ticket button (or focusing the button) lights the night. Below 1024px
 * the script adds is-glowing whenever 35% of the section is on screen (decorative; the fade is in the motion block below).
 * ---------------------------------------------------------------------- */

.mg-masquerade-glow::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	pointer-events: none;
	background:
		radial-gradient(circle at 16% 28%, rgba(248, 200, 56, 0.2), transparent 38%),
		radial-gradient(circle at 84% 72%, rgba(111, 85, 154, 0.5), transparent 46%),
		radial-gradient(circle at 62% 12%, rgba(144, 200, 88, 0.14), transparent 34%);
	opacity: 0;
}

.mg-masquerade-glow :is(.wp-block-heading, .is-style-numeral) {
	cursor: default;
}

.mg-masquerade-glow:has(:is(.wp-block-heading, .is-style-numeral, .wp-block-button__link):hover, .wp-block-button__link:focus-visible)::after,
.mg-masquerade-glow.is-glowing::after {
	opacity: 1;
}

.mg-masquerade-glow:has(:is(.wp-block-heading, .is-style-numeral, .wp-block-button__link):hover, .wp-block-button__link:focus-visible)::before,
.mg-masquerade-glow.is-glowing::before {
	filter: brightness(1.8) saturate(1.3);
}

.mg-masquerade-glow:has(:is(.wp-block-heading, .is-style-numeral, .wp-block-button__link):hover, .wp-block-button__link:focus-visible) .has-gold-color,
.mg-masquerade-glow.is-glowing .has-gold-color {
	text-shadow: 0 0 18px rgba(248, 200, 56, 0.55);
}

@media (prefers-reduced-motion: no-preference) {

	/* ---------------------------------------------------------------------
	 * 1. Beads settle: swags drop in and sway once when first seen.
	 * ------------------------------------------------------------------ */

	html.mg-motion .is-style-bead-swag:not(.is-settled) {
		transform: translateY(-12px);
	}

	html.mg-motion .is-style-bead-swag.is-settled {
		transform-origin: 50% 0;
		animation: mg-settle-sway 1.3s cubic-bezier(0.3, 0.6, 0.4, 1) both;
	}

	html.mg-motion .is-style-harlequin-beads:not(.is-settled)::after {
		transform: translateY(-12px);
	}

	html.mg-motion .is-style-harlequin-beads.is-settled::after {
		animation: mg-settle 1.3s cubic-bezier(0.3, 0.6, 0.4, 1) both;
	}

	@keyframes mg-settle {
		0% { transform: translateY(-12px); }
		45% { transform: translateY(3px); }
		70% { transform: translateY(-1px); }
		100% { transform: none; }
	}

	@keyframes mg-settle-sway {
		0% { transform: translateY(-12px) rotate(-1.2deg); }
		45% { transform: translateY(3px) rotate(0.8deg); }
		70% { transform: translateY(-1px) rotate(-0.3deg); }
		100% { transform: none; }
	}

	/* ---------------------------------------------------------------------
	 * 2. Corner scrolls draw themselves. The script swaps the background
	 *    images for inline SVG; html.mg-static-scrolls means it couldn't.
	 * ------------------------------------------------------------------ */

	html.mg-motion:not(.mg-static-scrolls) .is-style-corner-scroll,
	html.mg-motion:not(.mg-static-scrolls) .is-style-scroll-frame::before {
		background-image: none;
	}

	/* Transitions rather than keyframes, so a scroll can also draw back out
	 * (event cards on the Home timeline, below). */
	.mg-live-scroll .mg-scroll-line {
		stroke-dasharray: 1;
		stroke-dashoffset: 1;
		transition: stroke-dashoffset 0.8s cubic-bezier(0.5, 0, 0.3, 1);
	}

	.mg-live-scroll .mg-scroll-gem {
		opacity: 0;
		transform: scale(0) rotate(-90deg);
		transform-box: fill-box;
		transform-origin: center;
		transition: opacity 0.3s ease, transform 0.3s ease;
	}

	.is-drawn .mg-live-scroll .mg-scroll-line,
	.is-lit .mg-live-scroll .mg-scroll-line {
		stroke-dashoffset: 0;
		transition-duration: 1.4s;
	}

	:is(.is-drawn, .is-lit) .mg-live-scroll .mg-scroll-line:nth-child(2) { transition-delay: 0.15s; }
	:is(.is-drawn, .is-lit) .mg-live-scroll .mg-scroll-line:nth-child(3) { transition-delay: 0.45s; }
	:is(.is-drawn, .is-lit) .mg-live-scroll .mg-scroll-line:nth-child(4) { transition-delay: 0.6s; }

	:is(.is-drawn, .is-lit) .mg-live-scroll .mg-scroll-gem {
		opacity: 1;
		transform: none;
		transition: opacity 0.3s ease 1.2s, transform 0.5s cubic-bezier(0.3, 1.6, 0.5, 1) 1.2s;
	}

	/* Event cards that follow the Home timeline: corners draw while the
	 * card is lit and draw back out when the parasol moves on. Below 782px
	 * the timeline is hidden and the cards draw once, like other frames. */
	@media (min-width: 782px) {
		.mg-lit-route .mg-event-card:not(.is-lit) .mg-live-scroll .mg-scroll-line {
			stroke-dashoffset: 1;
			transition-delay: 0s;
			transition-duration: 0.8s;
		}

		.mg-lit-route .mg-event-card:not(.is-lit) .mg-live-scroll .mg-scroll-gem {
			opacity: 0;
			transform: scale(0) rotate(-90deg);
			transition: opacity 0.3s ease, transform 0.3s ease;
		}
	}

	/* ---------------------------------------------------------------------
	 * 3. Second-line parasol walks under the Home timeline as you scroll.
	 *    The script sets --mg-parade (0–1) and lights the stop it has
	 *    reached, plus the matching event card.
	 * ------------------------------------------------------------------ */

	html.mg-motion .mg-timeline {
		position: relative;
	}

	html.mg-motion .mg-timeline::after {
		content: "";
		position: absolute;
		top: calc(50% + 22px);
		left: calc(16.667% - 16px + var(--mg-parade, 0) * 66.667%);
		width: 32px;
		height: 40px;
		background: url("../images/parasol.svg") no-repeat center / contain;
		transform: rotate(calc(sin(var(--mg-parade, 0) * 25rad) * 10deg));
		transform-origin: 50% 95%;
		pointer-events: none;
	}

	/* Tablet and up, the Day schedule pins while the parasol walks: the
	 * runway spacer gives it scroll distance, and the script sets
	 * --mg-stage-top so the cards and timeline stay on screen. */
	@media (min-width: 782px) {
		html.mg-motion .mg-parade-stage {
			position: sticky;
			top: var(--mg-stage-top, 0px);
		}

		html.mg-motion .mg-parade-runway {
			height: 120vh !important;
		}

		/* One row of cards, so each sits over its stop on the line. */
		html.mg-motion .mg-parade-stage .mg-event-grid {
			grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
			gap: clamp(16px, 2.2vw, 32px);
		}
	}

	html.mg-motion .mg-timeline .mg-hour,
	html.mg-motion .mg-event-card {
		transition: background-color 0.5s ease, color 0.5s ease, border-color 0.5s ease, box-shadow 0.5s ease;
	}

	html.mg-motion .mg-timeline .mg-hour.is-lit {
		border-color: var(--mg-deep-purple);
		background-color: var(--mg-deep-purple) !important;
		color: var(--mg-gold) !important;
	}

	html.mg-motion .mg-event-card.is-lit {
		border-color: var(--mg-purple);
		box-shadow: 0 0 0 1.5px var(--mg-purple), 0 0 32px rgba(248, 200, 56, 0.55);
	}

	/* ---------------------------------------------------------------------
	 * 5. Masquerade glow fades in and out.
	 * ------------------------------------------------------------------ */

	.mg-masquerade-glow::before,
	.mg-masquerade-glow::after,
	.mg-masquerade-glow .has-gold-color {
		transition: opacity 1s ease, filter 1s ease, text-shadow 1s ease;
	}

	/* ---------------------------------------------------------------------
	 * Event sketches drift up into view as they arrive and lift away as
	 * they scroll off the top (the script sets is-visible / is-past).
	 * ------------------------------------------------------------------ */

	html.mg-motion .mg-sketch {
		opacity: 0;
		transform: translateY(48px) rotate(-4deg) scale(0.94);
		transform-origin: 50% 80%;
		transition: opacity 0.8s ease, transform 1.1s cubic-bezier(0.2, 0.8, 0.3, 1.12);
	}

	html.mg-motion .mg-sketch.is-visible {
		opacity: 1;
		transform: none;
	}

	html.mg-motion .mg-sketch.is-past {
		transform: translateY(-40px) rotate(3deg) scale(0.96);
	}

	/* ---------------------------------------------------------------------
	 * Photo band: the mosaic fades up in a short stagger, once.
	 * ------------------------------------------------------------------ */

	html.mg-motion .is-style-mosaic figure.wp-block-image {
		opacity: 0;
		transform: translateY(24px);
		transition: opacity 0.7s ease, transform 0.8s cubic-bezier(0.2, 0.8, 0.3, 1);
	}

	html.mg-motion .is-style-mosaic.is-revealed figure.wp-block-image {
		opacity: 1;
		transform: none;
	}

	html.mg-motion .is-style-mosaic figure.wp-block-image:nth-of-type(2) { transition-delay: 0.08s; }
	html.mg-motion .is-style-mosaic figure.wp-block-image:nth-of-type(3) { transition-delay: 0.16s; }
	html.mg-motion .is-style-mosaic figure.wp-block-image:nth-of-type(4) { transition-delay: 0.24s; }
	html.mg-motion .is-style-mosaic figure.wp-block-image:nth-of-type(5) { transition-delay: 0.32s; }

	/* ---------------------------------------------------------------------
	 * 7. Joy hover: the About cameo tilts and its gold ring shimmers once.
	 * ------------------------------------------------------------------ */

	.mg-cameo.is-joy .wp-block-image {
		transition: transform 0.5s cubic-bezier(0.3, 0.7, 0.4, 1.3);
	}

	.mg-cameo.is-joy:is(:hover, :focus-within) .wp-block-image {
		transform: rotate(-4deg);
	}

	.mg-cameo.is-joy:is(:hover, :focus-within)::after {
		animation: mg-shimmer 1.4s ease-out;
	}

	@keyframes mg-shimmer {
		0% { box-shadow: 0 0 0 0 rgba(248, 200, 56, 0); }
		40% { box-shadow: 0 0 22px 2px rgba(248, 200, 56, 0.7), inset 0 0 14px rgba(248, 200, 56, 0.45); }
		100% { box-shadow: 0 0 0 0 rgba(248, 200, 56, 0); }
	}

	/* ---------------------------------------------------------------------
	 * 7b. LED strings glow: the bulbs on the CTA and newsletter bands breathe.
	 * ------------------------------------------------------------------ */

	html.mg-motion :is(.mg-cta-band, .mg-newsletter-band)::after,
	html.mg-motion .is-style-led-string {
		animation: mg-led 3.2s ease-in-out infinite alternate;
	}

	@keyframes mg-led {
		from { filter: brightness(0.9) saturate(1); }
		to { filter: brightness(1.15) saturate(1.25); }
	}

	/* ---------------------------------------------------------------------
	 * 8. Cheerful 404: the swag sags.
	 * ------------------------------------------------------------------ */

	html.mg-motion .is-style-bead-swag-drooping {
		animation: mg-droop 1.6s cubic-bezier(0.4, 0, 0.3, 1.4) 0.3s both;
	}

	/* The art is drawn sagging; it starts level and drops. */
	@keyframes mg-droop {
		from { transform: rotate(-7deg); }
	}

	/* ---------------------------------------------------------------------
	 * 9. Konami code: bead confetti (the script skips it for reduced motion)
	 * ------------------------------------------------------------------ */

	.mg-confetti i {
		animation: mg-fall var(--d) cubic-bezier(0.35, 0.1, 0.6, 1) var(--delay) both;
	}

	@keyframes mg-fall {
		to { transform: translate(var(--drift), calc(100vh + 48px)); }
	}

	.mg-banner {
		animation: mg-pop 0.4s cubic-bezier(0.3, 1.4, 0.5, 1) both;
	}

	.mg-banner {
		--mg-pop-x: -50%;
	}

	@keyframes mg-pop {
		from { opacity: 0; transform: translate(var(--mg-pop-x, 0), 12px) scale(0.96); }
		to { opacity: 1; transform: translate(var(--mg-pop-x, 0), 0); }
	}
}
