/*!
 * Popup Studio – frontend styles
 * Native <dialog>, theme-driven colors, GPU-friendly animations.
 */

@property --pops-angle {
	syntax: "<angle>";
	inherits: false;
	initial-value: 0deg;
}

/* ---------- Base ---------- */
dialog.pops {
	--pops-ease-spring: cubic-bezier(.2, 1.35, .3, 1);
	--pops-ease-out: cubic-bezier(.16, 1, .3, 1);
	--pops-dur: .62s;
	--pops-muted: color-mix(in srgb, var(--pops-text) 68%, transparent);
	--pops-line: color-mix(in srgb, var(--pops-text) 12%, transparent);
	--pops-card: var(--pops-bg);
	--pops-glow: var(--pops-accent);
	position: fixed;
	z-index: var(--pops-z, 99990);
	margin: 0;
	padding: 0;
	border: 0;
	max-width: none;
	max-height: none;
	background: transparent;
	color: var(--pops-text);
	overflow: visible;
	font: inherit;
	line-height: 1.55;
	-webkit-font-smoothing: antialiased;
}
dialog.pops:not([open]) { display: none; }
dialog.pops *, dialog.pops *::before, dialog.pops *::after { box-sizing: border-box; }
dialog.pops:focus { outline: none; }

/* Backdrop */
dialog.pops::backdrop {
	background: rgb(8 10 18 / .58);
	-webkit-backdrop-filter: blur(8px) saturate(1.25);
	backdrop-filter: blur(8px) saturate(1.25);
	opacity: 0;
	transition: opacity .45s ease;
}
dialog.pops.is-open::backdrop { opacity: 1; }
dialog.pops.is-closing::backdrop { opacity: 0; transition-duration: .3s; }
dialog.pops.pops--no-blur::backdrop { -webkit-backdrop-filter: none; backdrop-filter: none; }
dialog.pops.pops--no-overlay::backdrop { background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; }

/* ---------- Layout types ---------- */
dialog.pops--modal[open],
dialog.pops--fullscreen[open] {
	inset: 0;
	width: 100%;
	height: 100%;
	display: grid;
	place-items: center;
	padding: clamp(12px, 4vw, 40px);
	overflow-y: auto;
	overscroll-behavior: contain;
}
.pops--modal .pops__frame { width: min(var(--pops-width), 100%); }

.pops--fullscreen .pops__frame { width: 100%; min-height: 100%; display: grid; }
.pops--fullscreen .pops__card { border-radius: calc(var(--pops-radius) * 1.2); display: grid; place-content: center; min-height: calc(100dvh - 2 * clamp(12px, 4vw, 40px)); }
.pops--fullscreen .pops__body { max-width: min(var(--pops-width), 100%); margin-inline: auto; text-align: center; }

dialog.pops--slidein { inset: auto; }
dialog.pops--slidein[open] {
	width: min(var(--pops-width), calc(100vw - 32px));
	margin: 16px;
}
/* Slide-ins keep clear of open bars and scroll when their content is taller than the space. */
.pops--slidein .pops__card { max-height: calc(100dvh - 32px - var(--pops-bar-top, 0px) - var(--pops-bar-bottom, 0px)); overflow-y: auto; overscroll-behavior: contain; }
.pops--slidein.pops--img-top .pops__media { aspect-ratio: 16 / 6; }
.pops--slidein.pops--pos-bottom-right { right: 0; bottom: var(--pops-bar-bottom, 0px); }
.pops--slidein.pops--pos-bottom-left { left: 0; bottom: var(--pops-bar-bottom, 0px); }
.pops--slidein.pops--pos-top-right { right: 0; top: var(--pops-bar-top, 0px); }
.pops--slidein.pops--pos-top-left { left: 0; top: var(--pops-bar-top, 0px); }
.admin-bar .pops--slidein.pops--pos-top-right, .admin-bar .pops--slidein.pops--pos-top-left { top: calc(var(--wp-admin--admin-bar--height, 32px) + var(--pops-bar-top, 0px)); }

dialog.pops--bar { inset-block: auto; }
dialog.pops--bar[open] { left: 0; right: 0; width: 100%; }
.pops--bar.pops--pos-top { top: 0; }
.pops--bar.pops--pos-bottom { bottom: 0; }
.admin-bar .pops--bar.pops--pos-top { top: var(--wp-admin--admin-bar--height, 32px); }
.pops--bar .pops__card { border-radius: 0; border-inline: 0; box-shadow: 0 6px 24px -10px rgb(0 0 0 / .25); }
.pops--bar .pops__body { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .4rem 1.25rem; padding: .85rem 3.5rem .85rem 1.25rem; text-align: center; }
.pops--bar .pops__title { font-size: 1.05rem; margin: 0; }
.pops--bar .pops__content { display: contents; }
.pops--bar .pops__content > * { margin: 0 !important; }
.pops--bar .pops__close { top: 50%; translate: 0 -50%; }

dialog.pops--drawer[open] { top: 0; bottom: 0; height: 100%; width: min(var(--pops-width), 100vw); }
.pops--drawer.pops--pos-right { right: 0; left: auto; }
.pops--drawer.pops--pos-left { left: 0; right: auto; }
.pops--drawer .pops__frame, .pops--drawer .pops__card { height: 100%; }
.pops--drawer .pops__card { border-radius: 0; overflow-y: auto; }
.pops--drawer.pops--pos-right .pops__card { border-radius: var(--pops-radius) 0 0 var(--pops-radius); }
.pops--drawer.pops--pos-left .pops__card { border-radius: 0 var(--pops-radius) var(--pops-radius) 0; }

/* ---------- Card ---------- */
.pops__frame { position: relative; isolation: isolate; }
.pops__card {
	position: relative;
	overflow: hidden;
	border-radius: var(--pops-radius);
	background: var(--pops-card);
	border: 1px solid var(--pops-line);
	box-shadow:
		0 1px 2px rgb(0 0 0 / .06),
		0 12px 28px -6px rgb(0 0 0 / .22),
		0 40px 90px -20px rgb(0 0 0 / .38);
}
.pops--glass .pops__card {
	background: color-mix(in srgb, var(--pops-bg) 90%, transparent);
	-webkit-backdrop-filter: blur(24px) saturate(1.6);
	backdrop-filter: blur(24px) saturate(1.6);
}
.pops--is-inline.pops--glass .pops__card { background: color-mix(in srgb, var(--pops-bg) 96%, transparent); }
.pops--drawer.pops--glass .pops__card, .pops--bar.pops--glass .pops__card { background: color-mix(in srgb, var(--pops-bg) 98%, transparent); }
.pops--glass .pops__card::before {
	content: "";
	position: absolute;
	inset: 0;
	pointer-events: none;
	border-radius: inherit;
	background:
		radial-gradient(120% 70% at 0% 0%, color-mix(in srgb, var(--pops-glow) 16%, transparent), transparent 60%),
		radial-gradient(90% 60% at 100% 100%, color-mix(in srgb, var(--pops-glow) 10%, transparent), transparent 65%);
}
.pops__body { position: relative; padding: clamp(1.5rem, 4vw, 2.5rem); }
.pops__title {
	margin: 0 0 .6rem;
	font-size: clamp(1.4rem, 1.1rem + 1.4vw, 2rem);
	line-height: 1.15;
	letter-spacing: -.02em;
	color: inherit;
	text-wrap: balance;
}
.pops__content { color: var(--pops-muted); }
.pops__content > :first-child { margin-top: 0; }
.pops__content > :last-child { margin-bottom: 0; }
.pops__content :is(h1, h2, h3, h4, strong) { color: var(--pops-text); }
.pops__content a:not([class*="button"]):not(.pops-open) { color: var(--pops-accent); text-underline-offset: .2em; }
.pops__content img { max-width: 100%; height: auto; }
.pops__content iframe { max-width: 100%; border: 0; }
.pops__content .wp-block-buttons { margin-top: 1.25rem; }

/* Aurora: animated glow around the card */
.pops__aurora {
	position: absolute;
	inset: -2px;
	z-index: -1;
	border-radius: calc(var(--pops-radius) + 2px);
	background: conic-gradient(from var(--pops-angle),
		var(--pops-glow),
		color-mix(in oklch, var(--pops-glow), #ff4fd8 55%),
		color-mix(in oklch, var(--pops-glow), #3cc8ff 55%),
		var(--pops-glow));
	animation: pops-spin 7s linear infinite;
}
.pops__aurora::after {
	content: "";
	position: absolute;
	inset: 6%;
	border-radius: inherit;
	background: inherit;
	filter: blur(38px);
	opacity: .55;
}
.pops--bar .pops__aurora, .pops--drawer .pops__aurora, .pops--fullscreen .pops__aurora { display: none; }
@keyframes pops-spin { to { --pops-angle: 360deg; } }

/* Media */
.pops__media { margin: 0; position: relative; }
.pops__img { display: block; width: 100%; height: 100%; object-fit: cover; }
.pops--img-top .pops__media { aspect-ratio: 16 / 7; max-height: 32vh; width: 100%; overflow: hidden; }
.pops--img-top .pops__img { transform: scale(1.06); transition: transform 1.4s var(--pops-ease-out); }
.pops--img-top.is-open .pops__img { transform: scale(1); }
@media (min-width: 640px) {
	.pops--img-left .pops__card { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); }
	.pops--img-left .pops__media { min-height: 100%; }
}
@media (max-width: 639px) {
	.pops--img-left .pops__media { aspect-ratio: 16 / 8; overflow: hidden; }
}
.pops--img-background .pops__media { position: absolute; inset: 0; }
.pops--img-background .pops__media::after {
	content: "";
	position: absolute;
	inset: 0;
	background: linear-gradient(180deg, rgb(0 0 0 / .15) 0%, rgb(0 0 0 / .72) 100%);
}
.pops--img-background .pops__body { color: #fff; min-height: 340px; display: flex; flex-direction: column; justify-content: flex-end; }
.pops--img-background .pops__content, .pops--img-background .pops__content :is(h1, h2, h3, h4, strong) { color: rgb(255 255 255 / .9); }

/* ---------- Buttons ---------- */
.pops .wp-block-button__link:not(.has-background),
.pops .pops-button,
.pops .pops-dismiss + .wp-block-button__link {
	position: relative;
	overflow: hidden;
	background: var(--pops-accent);
	color: var(--pops-on-accent);
	border: 0;
	border-radius: max(10px, calc(var(--pops-radius) * .55));
	padding: .8em 1.5em;
	font-weight: 600;
	text-decoration: none;
	box-shadow: 0 8px 22px -8px color-mix(in srgb, var(--pops-accent) 75%, transparent);
	transition: transform .25s var(--pops-ease-out), box-shadow .25s ease, filter .25s ease;
}
.pops .wp-block-button__link:not(.has-background)::after,
.pops .pops-button::after {
	content: "";
	position: absolute;
	inset: 0;
	background: linear-gradient(110deg, transparent 30%, rgb(255 255 255 / .38) 50%, transparent 70%);
	translate: -110% 0;
	animation: pops-sheen 3.6s ease-in-out 1.2s infinite;
}
.pops .wp-block-button__link:not(.has-background):hover,
.pops .pops-button:hover { transform: translateY(-2px); filter: brightness(1.06); box-shadow: 0 14px 30px -10px color-mix(in srgb, var(--pops-accent) 85%, transparent); }
.pops .wp-block-button__link:focus-visible,
.pops .pops-button:focus-visible,
.pops button:focus-visible,
.pops a:focus-visible { outline: 3px solid color-mix(in srgb, var(--pops-accent) 70%, transparent); outline-offset: 3px; }
@keyframes pops-sheen { 0%, 60% { translate: -110% 0; } 100% { translate: 110% 0; } }

.pops-dismiss {
	appearance: none;
	background: none;
	border: 0;
	padding: .6em .4em;
	color: var(--pops-muted, inherit);
	font: inherit;
	font-size: .92em;
	cursor: pointer;
	text-decoration: underline;
	text-decoration-color: color-mix(in srgb, currentColor 35%, transparent);
	text-underline-offset: .25em;
}
.pops-dismiss:hover { color: var(--pops-text, inherit); }

/* Close button with countdown ring */
.pops__close {
	position: absolute;
	top: .75rem;
	right: .75rem;
	z-index: 3;
	display: grid;
	place-items: center;
	width: 2.4rem;
	height: 2.4rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: color-mix(in srgb, var(--pops-bg) 70%, transparent);
	color: var(--pops-text);
	cursor: pointer;
	-webkit-backdrop-filter: blur(8px);
	backdrop-filter: blur(8px);
	box-shadow: 0 0 0 1px var(--pops-line);
	transition: transform .35s var(--pops-ease-spring), background .2s ease, opacity .3s ease;
}
.pops__close:hover { transform: rotate(90deg) scale(1.06); background: color-mix(in srgb, var(--pops-text) 10%, var(--pops-bg)); }
.pops__close svg { grid-area: 1 / 1; width: 1.1rem; height: 1.1rem; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.pops__close .pops__ring { width: 100%; height: 100%; rotate: -90deg; opacity: 0; stroke: var(--pops-accent); stroke-width: 2.5; stroke-dasharray: 100.5; stroke-dashoffset: 0; }
.pops__close.is-waiting { pointer-events: none; opacity: .55; }
.pops__close.is-waiting .pops__ring { opacity: 1; animation: pops-ring var(--pops-wait, 3s) linear forwards; }
@keyframes pops-ring { from { stroke-dashoffset: 100.5; } to { stroke-dashoffset: 0; } }
.pops--img-background .pops__close { background: rgb(0 0 0 / .35); color: #fff; }

/* ---------- Animations ---------- */
.pops.is-open .pops__frame { animation: var(--pops-in) var(--pops-dur) var(--pops-ease) both; }
.pops.is-closing .pops__frame { animation: pops-out .3s ease-in both; }

.pops--anim-spring { --pops-in: pops-spring; --pops-ease: var(--pops-ease-spring); }
.pops--anim-fade { --pops-in: pops-fade; --pops-ease: ease-out; --pops-dur: .45s; }
.pops--anim-slide { --pops-in: pops-slide-up; --pops-ease: var(--pops-ease-out); }
.pops--anim-flip { --pops-in: pops-flip; --pops-ease: var(--pops-ease-out); --pops-dur: .8s; }
.pops--anim-unblur { --pops-in: pops-unblur; --pops-ease: var(--pops-ease-out); --pops-dur: .75s; }
.pops--anim-drop { --pops-in: pops-drop; --pops-ease: linear; --pops-dur: .9s; }
.pops--anim-none { --pops-in: none; }

.pops--slidein.pops--pos-bottom-right.pops--anim-slide, .pops--slidein.pops--pos-top-right.pops--anim-slide, .pops--drawer.pops--pos-right { --pops-in: pops-slide-left; }
.pops--slidein.pops--pos-bottom-left.pops--anim-slide, .pops--slidein.pops--pos-top-left.pops--anim-slide, .pops--drawer.pops--pos-left { --pops-in: pops-slide-right; }
.pops--bar.pops--pos-top { --pops-in: pops-slide-down; --pops-ease: var(--pops-ease-out); }
.pops--bar.pops--pos-bottom { --pops-in: pops-slide-up; --pops-ease: var(--pops-ease-out); }
.pops--drawer { --pops-ease: var(--pops-ease-out); --pops-dur: .55s; }
.pops--drawer.pops--pos-right.is-closing .pops__frame { animation: pops-slide-left .3s ease-in reverse both; }
.pops--drawer.pops--pos-left.is-closing .pops__frame { animation: pops-slide-right .3s ease-in reverse both; }

@keyframes pops-spring { from { opacity: 0; transform: translateY(28px) scale(.86); } 45% { opacity: 1; } to { opacity: 1; transform: none; } }
@keyframes pops-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pops-slide-up { from { opacity: 0; transform: translateY(60px); } to { opacity: 1; transform: none; } }
@keyframes pops-slide-down { from { opacity: 0; transform: translateY(-60px); } to { opacity: 1; transform: none; } }
@keyframes pops-slide-left { from { opacity: 0; transform: translateX(70px); } to { opacity: 1; transform: none; } }
@keyframes pops-slide-right { from { opacity: 0; transform: translateX(-70px); } to { opacity: 1; transform: none; } }
@keyframes pops-flip { from { opacity: 0; transform: perspective(1100px) rotateX(-24deg) translateY(30px) scale(.94); } to { opacity: 1; transform: none; } }
@keyframes pops-unblur { from { opacity: 0; filter: blur(18px); transform: scale(1.06); } to { opacity: 1; filter: none; transform: none; } }
@keyframes pops-drop {
	0% { opacity: 0; transform: translateY(-70px); animation-timing-function: cubic-bezier(.5, 0, 1, .5); }
	55% { opacity: 1; transform: translateY(0); animation-timing-function: cubic-bezier(0, .5, .5, 1); }
	72% { transform: translateY(-14px); animation-timing-function: cubic-bezier(.5, 0, 1, .5); }
	86% { transform: translateY(0); animation-timing-function: cubic-bezier(0, .5, .5, 1); }
	93% { transform: translateY(-4px); }
	100% { opacity: 1; transform: none; }
}
@keyframes pops-out { to { opacity: 0; transform: translateY(12px) scale(.96); } }

/* Content enters in a gentle cascade */
.pops--stagger.is-open .pops__title,
.pops--stagger.is-open .pops__content > * {
	animation: pops-rise .7s var(--pops-ease-out) both;
	animation-delay: calc(var(--pops-i, 0) * 70ms + 160ms);
}
@keyframes pops-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* Conversion feedback */
.pops.is-converted .pops__card { animation: pops-pulse .6s var(--pops-ease-spring); }
@keyframes pops-pulse { 40% { transform: scale(1.025); } }
.pops__confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* ---------- Mobile bottom sheet ---------- */
@media (max-width: 600px) {
	dialog.pops--modal.pops--sheet[open] { place-items: end stretch; padding: 0; padding-top: 10vh; }
	.pops--modal.pops--sheet .pops__frame { width: 100%; }
	.pops--modal.pops--sheet .pops__card { border-radius: var(--pops-radius) var(--pops-radius) 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
	.pops--modal.pops--sheet .pops__card::after {
		content: "";
		position: absolute;
		top: 8px;
		left: 50%;
		translate: -50% 0;
		width: 42px;
		height: 5px;
		border-radius: 99px;
		background: var(--pops-line);
	}
	.pops--modal.pops--sheet .pops__aurora { display: none; }
	.pops--modal.pops--sheet { --pops-in: pops-slide-up; --pops-ease: var(--pops-ease-out); }
	dialog.pops--slidein[open] { width: calc(100vw - 16px); margin: 8px; }
	.pops--bar .pops__body { padding-right: 3.25rem; }
}

/* ---------- Dark scheme (follows visitor's system setting) ---------- */
@media (prefers-color-scheme: dark) {
	dialog.pops--system:not(.pops--dark) {
		--pops-bg: #14161c;
		--pops-text: #f4f5f7;
	}
}

/* ---------- Countdown & coupon (usable inside and outside popups) ---------- */
.pops-countdown { display: inline-flex; gap: .5rem; font-variant-numeric: tabular-nums; }
.pops-cd__unit {
	display: grid;
	justify-items: center;
	min-width: 3.6rem;
	padding: .55rem .4rem .45rem;
	border-radius: 12px;
	background: color-mix(in srgb, var(--pops-accent, currentColor) 12%, transparent);
	border: 1px solid color-mix(in srgb, var(--pops-accent, currentColor) 24%, transparent);
}
.pops-cd__unit b { font-size: 1.6rem; line-height: 1; color: var(--pops-text, inherit); }
.pops-cd__unit b.is-tick { animation: pops-tick .45s var(--pops-ease-spring, ease); }
.pops-cd__unit small { margin-top: .25rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; opacity: .7; }
@keyframes pops-tick { from { transform: translateY(-35%); opacity: .2; } }

.pops-code {
	appearance: none;
	display: inline-grid;
	justify-items: center;
	gap: .15rem;
	padding: .8rem 1.4rem;
	border: 2px dashed color-mix(in srgb, var(--pops-accent, currentColor) 65%, transparent);
	border-radius: 14px;
	background: color-mix(in srgb, var(--pops-accent, currentColor) 8%, transparent);
	color: var(--pops-text, inherit);
	font: inherit;
	cursor: copy;
	transition: transform .25s ease, background .25s ease;
}
.pops-code:hover { transform: translateY(-1px); background: color-mix(in srgb, var(--pops-accent, currentColor) 14%, transparent); }
.pops-code__value { font-size: 1.35rem; font-weight: 700; letter-spacing: .12em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.pops-code__hint { font-size: .75rem; opacity: .65; }
.pops-code.is-copied { border-style: solid; }

.pops-toast {
	position: fixed;
	left: 50%;
	bottom: 24px;
	z-index: 2147483000;
	translate: -50% 0;
	padding: .6rem 1.1rem;
	border-radius: 99px;
	background: #111;
	color: #fff;
	font-size: .9rem;
	box-shadow: 0 10px 30px rgb(0 0 0 / .3);
	animation: pops-toast 2.2s var(--pops-ease-out, ease) both;
	pointer-events: none;
}
@keyframes pops-toast { 0% { opacity: 0; transform: translateY(14px); } 12%, 82% { opacity: 1; transform: none; } 100% { opacity: 0; } }

html.pops-lock, html.pops-lock body { overflow: hidden !important; }

/* Live preview: settings changes apply instantly without replaying the entrance */
.pops--instant .pops__frame, .pops--instant .pops__title, .pops--instant .pops__content > *, .pops--instant .pops__img { animation: none !important; transition: none !important; }
dialog.pops--instant::backdrop { transition: none; }

/* ---------- Accessibility: reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
	dialog.pops, dialog.pops * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
	.pops__aurora { animation: none; }
	.pops .wp-block-button__link::after, .pops .pops-button::after { display: none; }
}

@media print { dialog.pops { display: none !important; } }
