/* ==========================================================================
   MageMinion brand: page loader, micro-motion, scroll reveals.
   Front end only (not loaded in the block editor); enqueued after techdigest.css
   and techdigest-mobile.css in inc/setup.php. Tokens come from techdigest.css.
   No !important outside the prefers-reduced-motion reset at the end.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Page loader ("hat drop"). Only exists when inc/loader.php added html.mm-loading in <head>.
   Decorative: aria-hidden, no pointer events (never blocks clicks or focus), fixed
   position (no layout shift).
   -------------------------------------------------------------------------- */

.mm-loader {
	display: none;
}

html.mm-loading .mm-loader {
	display: flex;
	position: fixed;
	inset: 0;
	z-index: 100000;
	align-items: center;
	justify-content: center;
	background: var(--td-ground);
	pointer-events: none;
	transition: opacity 0.35s ease, visibility 0.35s ease;
}

/* Safety net: if scripts never finish, the loader is fully gone on its own by 2.6s (2.25s delay + 0.35s fade). */
html.mm-loading:not(.mm-loaded) .mm-loader {
	animation: mm-auto-hide 0.35s ease 2.25s forwards;
}

html.mm-loading.mm-loaded .mm-loader {
	opacity: 0;
	visibility: hidden;
}

.mm-loader__inner {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 18px;
}

.mm-loader__mark {
	overflow: visible;
}

.mm-loader__hat {
	transform-box: fill-box;
	transform-origin: 50% 100%;
	animation: mm-hat-drop 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.mm-loader__word {
	margin: 0;
	height: 1.1em;
	font-family: var(--td-mono);
	font-weight: 700;
	font-size: clamp(28px, 6vw, 44px);
	line-height: 1;
}

.mm-loader__word span {
	display: inline-block;
	vertical-align: bottom;
	animation: mm-fade-up 0.4s ease-out 0.25s both;
}

.mm-loader__word b {
	font-weight: 700;
	color: var(--td-ink);
}

.mm-loader__word i {
	font-style: normal;
	color: var(--td-violet);
}

.mm-loader__word em {
	font-style: normal;
	color: var(--td-violet-ink);
}

.mm-loader__bar {
	width: 220px;
	max-width: 70vw;
	height: 12px;
	border: var(--td-border);
	border-radius: var(--td-radius-pill);
	background: var(--td-paper);
	overflow: hidden;
}

.mm-loader__bar span {
	display: block;
	height: 100%;
	background: var(--td-lime);
	transform-origin: left center;
	animation: mm-bar 0.9s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes mm-auto-hide {
	to { opacity: 0; visibility: hidden; }
}

@keyframes mm-hat-drop {
	from { transform: translateY(-16px); opacity: 0; }
	to { transform: none; opacity: 1; }
}

@keyframes mm-fade-up {
	from { opacity: 0; transform: translateY(6px); }
	to { opacity: 1; transform: none; }
}

@keyframes mm-bar {
	from { transform: scaleX(0); }
	to { transform: scaleX(1); }
}


/* --------------------------------------------------------------------------
   Micro-motion. Cards use the shared sticker rule in techdigest.css; hover only
   overrides --td-card-shadow and transform. Hover effects are for real pointers only.
   -------------------------------------------------------------------------- */

.td-card,
:where(.td-theme .entries) .entry-card {
	transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.wp-block-button[class*='is-style-td-'] .wp-block-button__link,
.td-newsletter button,
.td-newsletter .wpcf7-submit,
.td-actionbar__btn {
	transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.td-tabbar__icon {
	transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.32s cubic-bezier(0.3, 1.4, 0.4, 1);
}

.td-tabbar__item.is-active .td-tabbar__icon {
	transform: scale(1.04);
}

/* Press: buttons sink into their shadow. Same specificity as the hover rule in techdigest.css, later in the cascade. */
.wp-block-button[class*='is-style-td-'] .wp-block-button__link:active,
.td-newsletter button:active,
.td-newsletter .wpcf7-submit:active {
	transform: translate(3px, 3px);
	box-shadow: none;
}

.td-actionbar__btn:active {
	transform: scale(0.88);
}

/* Card hover (1.5.15). A transform moves the hit area too: with the pointer near a card's edge, the lift moved
   the card out from under it, the hover ended, the card dropped back, and the card pulsed for as long as the
   pointer rested there. So the hover is read from something that never moves:
   - Home "Latest" cards (.td-card, only in patterns/latest-posts.php) lift when their query-loop <li> is hovered.
   - Archive cards (Blocksy's article.entry-card) have no wrapper of their own, so they don't move at all:
     the larger shadow alone shows the lift. */
@media (hover: hover) {
	.wp-block-post:hover > .td-card {
		--td-card-shadow: var(--td-shadow-xl);
		transform: translate(calc(var(--td-off-sm) * -1), calc(var(--td-off-sm) * -1)) rotate(-0.6deg);
	}

	.td-theme .entries .entry-card:hover {
		--td-card-shadow: var(--td-shadow-xl);
	}

	.td-pill:hover,
	.td-topics a:hover,
	.td-chip a:hover,
	.td-theme .entry-meta .meta-categories a:hover {
		animation: mm-wiggle 0.5s ease-in-out;
	}
}

/* A pop, not a tilt (1.5.15): a rotation moved the chip's corners up to ~3px, so a pointer resting on a corner
   left it, the wiggle stopped, the chip came back under the pointer and the wiggle restarted. Scaling up from
   1 only ever grows the hit area. The name stays mm-wiggle for the reduced-motion reset below. */
@keyframes mm-wiggle {
	0%, 100% { transform: scale(1); }
	40% { transform: scale(1.08); }
	70% { transform: scale(1.03); }
}

/* --------------------------------------------------------------------------
   Scroll reveals. techdigest.js adds .mm-reveal / .mm-reveal--zine ONLY to elements that are
   below the fold when the page loads, then .is-inview as they scroll into view. Without
   JS (or IntersectionObserver, or with reduced motion) the classes never appear, so nothing is
   ever hidden. Cards use the individual `translate` property so their hover `transform` is left
   alone. Zine headings settle with mm-wobble-in, whose `forwards` fill keeps
   `transform: rotate(-2deg)`; keep it in step with the zine rotation in techdigest.css.
   -------------------------------------------------------------------------- */

.mm-reveal {
	opacity: 0;
	translate: 0 28px;
	transition:
		opacity 0.5s ease var(--mm-delay, 0s),
		translate 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) var(--mm-delay, 0s),
		transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1),
		box-shadow 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.mm-reveal.is-inview {
	opacity: 1;
	translate: none;
}

.mm-reveal--zine {
	opacity: 0;
}

.mm-reveal--zine.is-inview {
	opacity: 1;
}

html.mm-js .is-style-td-zine.is-inview:not(.td-masthead),
html.mm-js .is-style-td-zine-violet.is-inview {
	animation: mm-wobble-in 0.45s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}

@keyframes mm-wobble-in {
	from { opacity: 0; transform: translateY(12px) rotate(-3deg); }
	to { opacity: 1; transform: rotate(-2deg); }
}

@media print {
	.mm-reveal,
	.mm-reveal--zine {
		opacity: 1;
		translate: none;
	}
}

/* --------------------------------------------------------------------------
   Reduced motion: no loader, no reveals, no hover/press movement. !important is
   standard here: it must beat every state set above or by inline styles.
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	html.mm-loading .mm-loader {
		display: none;
	}

	.mm-reveal,
	.mm-reveal--zine {
		opacity: 1 !important;
		translate: none !important;
		animation: none !important;
		transition: none !important;
	}

	.td-card,
	.td-theme .entries .entry-card,
	.td-tabbar__icon,
	.wp-block-button[class*='is-style-td-'] .wp-block-button__link,
	.td-newsletter button,
	.td-newsletter .wpcf7-submit,
	.td-actionbar__btn {
		transition: none !important;
		animation: none !important;
	}

	.wp-block-post:hover > .td-card,
	.wp-block-button[class*='is-style-td-'] .wp-block-button__link:active,
	.td-newsletter button:active,
	.td-newsletter .wpcf7-submit:active,
	.td-actionbar__btn:active,
	.td-tabbar__item.is-active .td-tabbar__icon {
		transform: none !important;
	}

	.td-pill:hover,
	.td-topics a:hover,
	.td-chip a:hover,
	.td-theme .entry-meta .meta-categories a:hover {
		animation: none !important;
	}
}
