/*
 * The Analytics question (ADR-012): a draggable glass panel in the top layer,
 * so it never moves the page. Yes and No share one rule: neither is louder.
 * Frosted by default; the script sets data-vt-glass only in an engine that
 * renders SVG backdrop filters, and only then is the refraction used.
 * Colours are the approved glass look (design/realistic-glass-example.html),
 * from theme.json custom.glass, so a piece's palette slots cannot recolour it.
 * Enqueued only when VERITARA_GA_MEASUREMENT_ID is set.
 */
@layer components {

	.vt-analytics {
		--vt-glass-ground: var(--wp--custom--glass--ground);
		--vt-glass-card: var(--wp--custom--glass--card);
		--vt-glass-ink: var(--wp--custom--glass--ink);
		--vt-glass-muted: var(--wp--custom--glass--muted);
		--vt-glass-accent: var(--wp--custom--glass--accent);
		--vt-glass-on-accent: var(--wp--custom--glass--on-accent);
		--vt-glass-halo: var(--wp--custom--glass--halo);
		--vt-glass-radius: 28px;

		position: fixed;
		inset:
			auto max(24px, env(safe-area-inset-right))
			max(24px, env(safe-area-inset-bottom)) auto;
		box-sizing: border-box;
		inline-size: min(26rem, 100% - 24px);
		max-block-size: calc(100dvh - 24px);
		margin: 0;
		padding: 0 14px 14px;
		overflow: auto;
		isolation: isolate;
		border: 0;
		border-radius: var(--vt-glass-radius);

		/*
		 * Frosted fallback. The ground alone keeps page text behind faint even
		 * where no backdrop filter is painted at all; the blur softens the rest.
		 */
		background: color-mix(in srgb, var(--vt-glass-ground) 82%, transparent);
		backdrop-filter: blur(16px) saturate(1.2);
		box-shadow:
			0 26px 70px -20px var(--wp--custom--glass--shadow),
			inset 0 0 0 1px var(--wp--custom--glass--edge),
			inset 0 2px 2px var(--wp--custom--glass--shine),
			inset 0 -2px 3px var(--wp--custom--glass--inner-shadow);
		color: var(--vt-glass-ink);
		font-family: var(--wp--preset--font-family--text);
		font-size: var(--wp--preset--font-size--note);
		line-height: 1.5;
	}

	/* Two filter IDs: swapping them makes Chromium repaint a changed map. */
	.vt-analytics[data-vt-glass] {
		background: var(--wp--custom--glass--clear);
	}

	.vt-analytics[data-vt-glass="a"] {
		backdrop-filter: url(#vt-analytics-lens-a) saturate(1.35);
	}

	.vt-analytics[data-vt-glass="b"] {
		backdrop-filter: url(#vt-analytics-lens-b) saturate(1.35);
	}

	.vt-analytics[data-vt-glass]::before {
		content: "";
		position: absolute;
		inset: 0;
		z-index: -1;
		border-radius: inherit;
		background-image: var(--vt-glass-facets, none);
		opacity: 0.05;
		pointer-events: none;
	}

	.vt-analytics:focus-visible {
		outline: 3px solid var(--vt-glass-accent);
		outline-offset: 2px;
	}

	/* The example's 108px head: enough glass above the card to play with. */
	.vt-analytics__head {
		position: relative;
		display: grid;
		place-items: center;
		min-block-size: 108px;
		box-sizing: border-box;
		padding: 24px 48px 12px;
	}

	/* The whole head is the grab area; the title lets pointers through to it. */
	.vt-analytics__handle {
		position: absolute;
		inset: 0;
		margin: 0;
		padding: 0;
		border: 0;
		border-radius: var(--vt-glass-radius) var(--vt-glass-radius) 0 0;
		background: none;
		cursor: grab;
		touch-action: none;
		-webkit-user-select: none;
		user-select: none;
	}

	.vt-analytics__handle::before {
		content: "";
		position: absolute;
		inset-block-start: 10px;
		inset-inline-start: calc(50% - 18px);
		inline-size: 36px;
		block-size: 4px;
		border-radius: 8px;
		background: var(--wp--custom--glass--rim);
		box-shadow: 0 1px 3px var(--wp--custom--glass--pill-shadow);
	}

	.vt-analytics__handle[data-dragging] {
		cursor: grabbing;
	}

	.vt-analytics__question {
		position: relative;
		margin: 0;
		font-family: var(--wp--preset--font-family--display);
		font-size: 28px;
		font-style: italic;
		line-height: 1.15;
		letter-spacing: -0.02em;
		text-align: center;
		pointer-events: none;

		/* An opaque edge keeps the letters apart from the bent page behind. */
		text-shadow:
			-2px -2px 0 var(--vt-glass-halo),
			0 -2px 0 var(--vt-glass-halo),
			2px -2px 0 var(--vt-glass-halo),
			2px 0 0 var(--vt-glass-halo),
			2px 2px 0 var(--vt-glass-halo),
			0 2px 0 var(--vt-glass-halo),
			-2px 2px 0 var(--vt-glass-halo),
			-2px 0 0 var(--vt-glass-halo),
			0 0 6px var(--vt-glass-halo),
			0 0 12px var(--vt-glass-halo);
	}

	.vt-analytics__close {
		position: absolute;
		inset-block-start: 10px;
		inset-inline-end: 10px;
		z-index: 1;
		display: grid;
		place-items: center;
		inline-size: 40px;
		block-size: 40px;
		padding: 0;
		border: 1px solid var(--wp--custom--glass--rim);
		border-radius: 50%;
		background: var(--vt-glass-ground);
		color: var(--vt-glass-ink);
		font:
			22px/1 system-ui,
			sans-serif;
		cursor: pointer;
	}

	.vt-analytics__card {
		padding: 18px 20px 20px;
		border: 1px solid var(--wp--custom--glass--rim);
		border-radius: calc(var(--vt-glass-radius) - 12px);
		background: var(--vt-glass-card);
		box-shadow: 0 2px 10px var(--wp--custom--glass--card-shadow);
	}

	.vt-analytics__line,
	.vt-analytics__answer {
		margin: 0;
		color: var(--vt-glass-muted);
	}

	.vt-analytics__line a {
		color: var(--vt-glass-ink);
		text-underline-offset: 0.2em;
	}

	.vt-analytics__answer {
		margin-block-start: 8px;
		font-family: var(--wp--preset--font-family--mono);
		font-size: var(--wp--preset--font-size--label);
	}

	.vt-analytics__choices {
		display: grid;
		grid-template-columns: 1fr 1fr;
		gap: 10px;
		margin-block-start: 16px;
	}

	.vt-analytics__choice {
		min-block-size: 48px;
		padding: 0 16px;
		border: 1px solid var(--wp--custom--glass--button-rim);
		border-radius: 13px;
		background: var(--vt-glass-accent);
		color: var(--vt-glass-on-accent);
		font-family: var(--wp--preset--font-family--text);
		font-size: 15px;
		font-weight: 600;
		line-height: 1.2;
		cursor: pointer;
	}

	/* Reopened: the current answer, whichever it is, gets the same mark. */
	.vt-analytics__choice[aria-pressed="true"] {
		box-shadow:
			inset 0 0 0 2px var(--vt-glass-on-accent),
			0 0 0 2px var(--vt-glass-accent);
	}

	.vt-analytics__choice[aria-pressed="true"]::before {
		content: "✓\00a0" / "";
	}

	.vt-analytics__choice:hover,
	.vt-analytics__close:hover {
		filter: brightness(1.08);
	}

	.vt-analytics
	:is(
		.vt-analytics__choice,
		.vt-analytics__close,
		.vt-analytics__line a
	):focus-visible {
		outline: 3px solid var(--vt-glass-accent);
		outline-offset: 3px;
	}

	.vt-analytics__handle:focus-visible {
		outline: 3px solid var(--vt-glass-accent);
		outline-offset: -3px;
	}

	/* The refraction's SVG filters: present for reference, never painted. */
	.vt-analytics-defs {
		position: absolute;
		inline-size: 0;
		block-size: 0;
		overflow: hidden;
		pointer-events: none;
	}

	/* The footer's Cookies link, on the copyright line. */
	.vt-cookies {
		display: inline-flex;
		align-items: center;
		gap: 6px;
		min-block-size: 24px;
		margin-inline-start: auto;
		padding: 0;
		border: 0;
		background: none;
		color: inherit;
		font: inherit;
		text-decoration: none;
		cursor: pointer;
	}

	.vt-cookies:hover {
		color: var(--mark);
	}

	.vt-cookies__icon {
		flex: none;
		inline-size: 14px;
		block-size: 14px;
		fill: currentcolor;
	}

	.vt-cookies__bitten,
	.vt-cookies[data-vt-cookie="yes"] .vt-cookies__whole {
		display: none;
	}

	.vt-cookies[data-vt-cookie="yes"] .vt-cookies__bitten {
		display: inline;
	}

	.vt-cookies__state {
		position: absolute;
		inline-size: 1px;
		block-size: 1px;
		overflow: hidden;
		clip-path: inset(50%);
		white-space: nowrap;
	}

	@media (width <= 560px) {

		.vt-analytics {
			inset: auto 12px max(12px, env(safe-area-inset-bottom));
			inline-size: auto;
			padding: 0 10px 10px;
		}

		.vt-analytics__head {
			min-block-size: 64px;
			padding-block: 22px 8px;
		}

		.vt-analytics__question {
			font-size: 22px;
		}

		.vt-analytics__card {
			padding: 14px 16px 16px;
		}

		.vt-analytics__choices {
			margin-block-start: 12px;
		}
	}

	@media (prefers-reduced-transparency: reduce) {

		.vt-analytics,
		.vt-analytics[data-vt-glass] {
			background: var(--vt-glass-ground);
			backdrop-filter: none;
		}

		.vt-analytics[data-vt-glass]::before {
			content: none;
		}
	}

	@media (forced-colors: active) {

		.vt-analytics {
			border: 1px solid CanvasText;
		}
	}

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

		.vt-analytics:popover-open {
			animation:
				vt-analytics-arrive 600ms
				var(--wp--custom--motion--ease-spring) both;
		}
	}

	/*
	 * Arrival only: answering closes it at once. Dragging moves `translate`,
	 * so the two never fight.
	 */
	@keyframes vt-analytics-arrive {

		from {
			opacity: 0;
			transform: translateY(40px);
		}
	}
}
