/**
 * Motion layer (CLAUDE-SPRINT-01, C-MOTION).
 *
 * Card-to-modal morph, size cue, sheet swipe, free-delivery moment, pressed
 * states and page cross-fades. Subtle and fast per 07 §6; every effect is
 * instant under prefers-reduced-motion. Behaviour lives in motion.js.
 */

/* 1. Card → modal morph: a top-layer surface for the flying clones. */
.bs-morph {
	position: fixed;
	inset: 0;
	width: auto;
	height: auto;
	max-width: none;
	max-height: none;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	overflow: visible;
	pointer-events: none;
}

.bs-morph__item {
	position: absolute;
	transform-origin: 50% 50%;
	will-change: transform;
}

.bs-morph__item img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: contain;
}

/* 2. Size cue: the stage pizza reflects the chosen size (no size 0.92, Regular 0.86, Large 1). */
#bs-item-modal [data-bs-pizza-scale] .bs-stage__visual-wrap > .bs-stage__img {
	scale: 0.92;
	transition: transform 0.35s var(--bs-ease-out), scale 220ms var(--bs-ease-out);
}

#bs-item-modal [data-bs-pizza-scale="regular"] .bs-stage__visual-wrap > .bs-stage__img {
	scale: 0.86;
}

#bs-item-modal [data-bs-pizza-scale="large"] .bs-stage__visual-wrap > .bs-stage__img {
	scale: 1;
}

#bs-item-modal [data-bs-size-instant] .bs-stage__visual-wrap > .bs-stage__img {
	transition: none;
}

/* 3. Sheet swipe: the stage and header take vertical drags; the options body keeps native scrolling. */
@media (max-width: 899px) {
	#bs-item-modal .bs-stage,
	#bs-item-modal .bs-modal-opts__header {
		touch-action: none;
		touch-action: pinch-zoom;
	}
}

#bs-item-modal::backdrop {
	opacity: calc(1 - var(--bs-sheet-progress, 0) * 0.6);
	transition: opacity 200ms var(--bs-ease-out, ease-out);
}

#bs-item-modal[data-bs-sheet="drag"]::backdrop {
	transition: none;
}

#bs-item-modal[data-bs-sheet="closing"]::backdrop {
	opacity: 0;
	transition-duration: 180ms;
}

/* 4. Free-delivery moment: the brand star pops beside the unlocked label. */
.bs-delivery-progress [data-bs-cart-progress-label] {
	position: relative;
}

.bs-delivery-progress[data-bs-free-moment] [data-bs-cart-progress-label]::after {
	position: absolute;
	top: 50%;
	left: 100%;
	width: 14px;
	height: 14px;
	margin: -7px 0 0 6px;
	background: var(--bs-yellow-400);
	clip-path: polygon(50% 8.33%, 62.88% 34.42%, 91.67% 38.63%, 70.83% 58.92%, 75.75% 87.58%, 50% 74.04%, 24.25% 87.58%, 29.17% 58.92%, 8.33% 38.63%, 37.13% 34.42%);
	content: "";
	pointer-events: none;
	animation: bsFreeStar 360ms var(--bs-ease-out) var(--bs-free-star-delay, 90ms) both;
}

@keyframes bsFreeStar {
	0% { opacity: 0; transform: scale(0.3) rotate(-30deg); }
	40% { opacity: 1; transform: scale(1.3) rotate(6deg); }
	65% { opacity: 1; transform: scale(1) rotate(0deg); }
	100% { opacity: 0; transform: scale(1) rotate(0deg); }
}

/* 5. Pressed states: one press (0.97, 100 ms) for primary buttons, "+" add buttons, chips and size tiles. */
.bs-extra-card__add,
.bs-deal-step,
.bs-dock__cart-btn {
	transition: transform var(--bs-dur-fast) var(--bs-ease-out);
}

.bs-header__area-btn {
	transition: background-color var(--bs-dur-fast) var(--bs-ease-out), border-color var(--bs-dur-fast) var(--bs-ease-out), transform var(--bs-dur-fast) var(--bs-ease-out);
}

.bs-btn-primary:not(:disabled):active,
.bs-btn-whatsapp:not(:disabled):active,
#place_order:not(:disabled):active,
.bs-header__cart-btn:active,
.bs-card__add-btn:active,
.bs-extra-card__add:not(:disabled):active,
.bs-chip-btn:active,
.bs-cats__pill:active,
.bs-header__area-btn:active,
.bs-deal-step:active,
.bs-size-tile:active {
	transform: scale(0.97);
	transition-duration: 100ms;
}

/* Replaces the older pop on the card "+" so every press feels the same. */
.bs-card__add-btn:active {
	animation: none;
}

.bs-dock__cart-btn:active {
	transform: translateY(-16px) scale(0.97);
	transition-duration: 100ms;
}

/* Pressing a card's "+" presses the button, not the whole card as well. */
.bs-card--list:has(.bs-card__add-btn:active),
.bs-card--deal:has(.bs-card__add-btn:active) {
	transform: none;
}

@media (hover: hover) {
	.bs-card--list:hover:has(.bs-card__add-btn:active),
	.bs-card--deal:hover:has(.bs-card__add-btn:active) {
		transform: translateY(-2px);
	}
}

/*
 * 6. Cross-page transitions: one quick root cross-fade.
 * The opt-in (@view-transition { navigation: auto; }) is deliberately not in this file:
 * Chromium reads it before a heavy page such as the menu has applied external CSS, then
 * skips the transition with an uncaught "Transition was skipped" error. It must be printed
 * inline in <head> (see the C-MOTION report); until then this rule stays inert.
 * The header and dock are not given a view-transition-name: WebKit does not paint named
 * elements during a cross-document transition, so they would blink out. In the root fade
 * their identical pixels blend into themselves and they stay still.
 */
@media (prefers-reduced-motion: no-preference) {
	/* The group too, so the transition (and its click-blocking overlay) ends with the fade. */
	::view-transition-group(root),
	::view-transition-old(root),
	::view-transition-new(root) {
		animation-duration: 160ms;
		animation-timing-function: var(--bs-ease-out, ease-out);
	}
}

@media (prefers-reduced-motion: reduce) {
	.bs-morph {
		display: none;
	}

	/* blackstar.css turns every transition into 0.01 ms here; on the dragged sheet that still lags a frame. */
	#bs-item-modal {
		transition: none;
	}

	#bs-item-modal [data-bs-pizza-scale] .bs-stage__visual-wrap > .bs-stage__img,
	#bs-item-modal::backdrop {
		transition: none;
	}

	.bs-delivery-progress[data-bs-free-moment] [data-bs-cart-progress-label]::after {
		display: none;
	}
}
