/**
 * WB Gamification popups: the shells.
 *
 * Every popup the plugin draws is one of these six shells. Their values come from the
 * tokens in src/shared/design-tokens.css (BuddyNext first, with BuddyNext's own default
 * as the fallback), and their keyframes are identical to BuddyNext's, so a Gamification
 * popup looks and moves like a BuddyNext one on the same page.
 *
 *   Moment  .wb-gam-moment          level up, streak, cohort promotion, community goal
 *   Toast   .wb-gam-toasts/.wb-gam-toast   points, kudos, badge, challenge, approvals, admin
 *   Banner  .wb-gam-banner          inline result messages
 *   Dialog  dialog.wb-gam-dialog    confirm, convert, survey (native <dialog>)
 *   Drawer  dialog.wb-gam-drawer    hub panel
 *   Menu    .wb-gam-menu            suggestion lists
 *
 * This file and design-tokens.css are the only places a raw duration or easing may appear.
 */

/* ── Keyframes (values identical to BuddyNext's) ───────────────────────────── */
@keyframes wb-gam-fade-in {
	from { opacity: 0; }
	to { opacity: 1; }
}
@keyframes wb-gam-fade-out {
	from { opacity: 1; }
	to { opacity: 0; }
}
@keyframes wb-gam-toast-in {
	from { opacity: 0; transform: translateY(10px); }
	to { opacity: 1; transform: translateY(0); }
}
@keyframes wb-gam-toast-out {
	from { opacity: 1; transform: translateY(0); }
	to { opacity: 0; transform: translateY(-10px); }
}
@keyframes wb-gam-dropdown-in {
	from { opacity: 0; transform: translateY(-4px); }
	to { opacity: 1; transform: translateY(0); }
}
@keyframes wb-gam-bounce-in {
	0% { opacity: 0; transform: scale(0.85); }
	60% { opacity: 1; transform: scale(1.04); }
	100% { opacity: 1; transform: scale(1); }
}
@keyframes wb-gam-count-pop {
	0% { opacity: 0; transform: scale(0.5); }
	70% { transform: scale(1.1); }
	100% { opacity: 1; transform: scale(1); }
}

/* ── Shared parts: button, icon disc, close control ────────────────────────── */
.wb-gam-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	box-sizing: border-box;
	min-height: var(--wb-gam-btn-h);
	padding: var(--wb-gam-btn-py) var(--wb-gam-btn-px);
	border: 1px solid transparent;
	border-radius: var(--wb-gam-btn-r);
	font: inherit;
	font-size: 13px;
	font-weight: 600;
	line-height: 1.2;
	text-decoration: none;
	cursor: pointer;
	transition: background-color var(--wb-gam-dur-fast) var(--wb-gam-ease), border-color var(--wb-gam-dur-fast) var(--wb-gam-ease), opacity var(--wb-gam-dur-fast) var(--wb-gam-ease);
}
.wb-gam-btn--primary {
	background: var(--wb-gam-pop-accent);
	color: var(--wb-gam-pop-accent-fg);
}
.wb-gam-btn--secondary {
	background: var(--wb-gam-pop-subtle);
	border-color: var(--wb-gam-pop-line);
	color: var(--wb-gam-pop-text);
}
.wb-gam-btn--danger {
	background: var(--wb-gam-pop-danger);
	color: #ffffff;
}
.wb-gam-btn[disabled],
.wb-gam-btn[aria-disabled="true"] {
	opacity: 0.6;
	cursor: progress;
}
@media (hover: hover) {
	.wb-gam-btn--primary:hover { background: color-mix(in srgb, var(--wb-gam-pop-accent) 88%, #000000); }
	.wb-gam-btn--secondary:hover { border-color: var(--wb-gam-pop-text-3); }
	.wb-gam-btn--danger:hover { background: color-mix(in srgb, var(--wb-gam-pop-danger) 88%, #000000); }
}

.wb-gam-disc {
	display: grid;
	place-items: center;
	flex: none;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	background: var(--wb-gam-pop-accent);
	color: var(--wb-gam-pop-accent-fg);
	font-size: 16px;
	line-height: 1;
}
.wb-gam-disc--success { background: var(--wb-gam-pop-success); color: #ffffff; }
.wb-gam-disc--danger { background: var(--wb-gam-pop-danger); color: #ffffff; }
.wb-gam-disc--info { background: var(--wb-gam-pop-info); color: #ffffff; }
.wb-gam-disc--sm { width: 24px; height: 24px; font-size: 13px; }

/* The one close control: a Lucide x with a 40px hit area. */
.wb-gam-close {
	display: inline-grid;
	place-items: center;
	flex: none;
	box-sizing: border-box;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: var(--wb-gam-pop-r-full);
	background: transparent;
	color: inherit;
	font-size: 18px;
	line-height: 1;
	opacity: 0.7;
	cursor: pointer;
	transition: opacity var(--wb-gam-dur-fast) var(--wb-gam-ease), background-color var(--wb-gam-dur-fast) var(--wb-gam-ease);
}
@media (hover: hover) {
	.wb-gam-close:hover { opacity: 1; background: color-mix(in srgb, currentColor 12%, transparent); }
}

.wb-gam-btn:focus-visible,
.wb-gam-close:focus-visible,
.wb-gam-toast__link:focus-visible,
.wb-gam-banner__action:focus-visible {
	outline: 2px solid var(--wb-gam-pop-accent);
	outline-offset: 2px;
}

/* ── Toast ─────────────────────────────────────────────────────────────────── */
/* BuddyNext's shell: inverted surface, bottom centre, status by the icon disc only.
 * The container is a manual popover so it sits in the top layer and stays above a
 * native dialog opened later; see assets/js/toast-core.js. */
.wb-gam-toasts {
	position: fixed;
	inset: auto;
	z-index: var(--wb-gam-pop-z-toast);
	display: flex;
	flex-direction: column;
	gap: 8px;
	box-sizing: border-box;
	/* 100%, not 100vw: a fixed element resolves percentages against the initial
	 * containing block, which excludes a classic scrollbar. */
	width: min(380px, calc(100% - 32px));
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
	overflow: visible;
	pointer-events: none;
}
/* Positions stay owner-selectable (Settings > Realtime). Bottom-centre is BuddyNext's and the
 * default. The offsets are measured at runtime (toast-core.js): a plugin cannot know in CSS what
 * a theme pins to the top or bottom of the viewport. */
.wb-gam-toasts--bottom-center {
	bottom: var(--wb-gam-toast-offset-bottom, 24px);
	left: 50%;
	transform: translateX(-50%);
	align-items: center;
}
.wb-gam-toasts--bottom-right {
	bottom: var(--wb-gam-toast-offset-bottom, 24px);
	right: 16px;
	align-items: flex-end;
}
.wb-gam-toasts--bottom-left {
	bottom: var(--wb-gam-toast-offset-bottom, 24px);
	left: 16px;
	align-items: flex-start;
}
.wb-gam-toasts--top-center {
	top: var(--wb-gam-toast-offset-top, 16px);
	left: 50%;
	transform: translateX(-50%);
	align-items: center;
}
.wb-gam-toasts--top-right {
	top: var(--wb-gam-toast-offset-top, 16px);
	right: 16px;
	align-items: flex-end;
}
body.admin-bar .wb-gam-toasts--top-center,
body.admin-bar .wb-gam-toasts--top-right {
	--wb-gam-toast-offset-top: calc(32px + 16px);
}
@media (max-width: 782px) {
	body.admin-bar .wb-gam-toasts--top-center,
	body.admin-bar .wb-gam-toasts--top-right {
		--wb-gam-toast-offset-top: calc(46px + 12px);
	}
}

.wb-gam-toast {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto;
	align-items: center;
	gap: 10px;
	box-sizing: border-box;
	width: 100%;
	padding: 12px 6px 12px 14px;
	border-radius: var(--wb-gam-pop-r-lg);
	background: var(--wb-gam-pop-inv-bg);
	color: var(--wb-gam-pop-inv-fg);
	box-shadow: var(--wb-gam-pop-shadow-md);
	font-family: var(--wb-gam-pop-font);
	pointer-events: auto;
	animation: wb-gam-toast-in var(--wb-gam-dur-toast) ease both;
}
/* One line of text is a pill, two lines are the large radius (BuddyNext's rule). */
.wb-gam-toast--single {
	padding-block: 6px;
	padding-inline: 8px 4px;
	border-radius: var(--wb-gam-pop-r-full);
}
.wb-gam-toast--exit {
	animation: wb-gam-toast-out var(--wb-gam-dur-toast) ease both;
}
.wb-gam-toast__message {
	display: block;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.3;
	overflow-wrap: anywhere;
}
.wb-gam-toast__detail {
	display: block;
	font-size: 13px;
	line-height: 1.35;
	opacity: 0.78;
}
.wb-gam-toast__detail[hidden] { display: none; }
.wb-gam-toast__link {
	display: inline-block;
	margin-top: 2px;
	color: inherit;
	font-size: 13px;
	font-weight: 600;
	text-decoration: underline;
	text-underline-offset: 2px;
}
.wb-gam-toast__link[hidden] { display: none; }
.wb-gam-toast .wb-gam-close {
	margin-block: -6px;
}

/* ── Banner ────────────────────────────────────────────────────────────────── */
/* Ink text on a tinted ground, status shown by the icon. Passes AA at 13:1 or better
 * in both themes, which the old coloured-text banners did not (2.96 and 3.22 to 1). */
.wb-gam-banner {
	display: flex;
	align-items: center;
	gap: 10px;
	box-sizing: border-box;
	padding: 12px 14px;
	border: 1px solid var(--wb-gam-pop-line);
	border-radius: var(--wb-gam-pop-r-md);
	background: var(--wb-gam-pop-info-bg);
	color: var(--wb-gam-pop-text);
	font-size: 14px;
	line-height: 1.4;
	animation: wb-gam-dropdown-in var(--wb-gam-dur-menu) ease both;
}
.wb-gam-banner[hidden] { display: none; }
.wb-gam-banner--success { background: var(--wb-gam-pop-success-bg); }
.wb-gam-banner--danger { background: var(--wb-gam-pop-danger-bg); }
.wb-gam-banner__text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
/* Pin the colour on the nodes that paint the words. A host rule on a bare span or button (or a
 * legacy .is-success / .is-error hook the block still carries) must not turn the text white on
 * the pale tint. Two classes beat any single-class or element rule. */
.wb-gam-banner .wb-gam-banner__text,
.wb-gam-banner .wb-gam-banner__action { color: var(--wb-gam-pop-text); }
.wb-gam-banner__action {
	flex: none;
	min-height: 40px;
	padding: 0 8px;
	border: 0;
	background: transparent;
	color: inherit;
	font: inherit;
	font-weight: 600;
	text-decoration: underline;
	cursor: pointer;
}

/* ── Dialog and drawer (native <dialog>) ───────────────────────────────────── */
/* The browser gives the top layer, the focus trap, Escape and the inert page behind.
 * assets/js/dialog.js adds focus return and backdrop click. Enter and exit are transitions
 * so a closing dialog fades instead of vanishing (allow-discrete, with a graceful fallback). */
dialog.wb-gam-dialog,
dialog.wb-gam-drawer {
	box-sizing: border-box;
	padding: 0;
	color: var(--wb-gam-pop-text);
	background: var(--wb-gam-pop-surface);
	box-shadow: var(--wb-gam-pop-shadow-lg);
	font-family: var(--wb-gam-pop-font);
}
dialog.wb-gam-dialog::backdrop,
dialog.wb-gam-drawer::backdrop {
	background: var(--wb-gam-pop-scrim);
	opacity: 0;
	transition: opacity var(--wb-gam-dur) var(--wb-gam-ease), overlay var(--wb-gam-dur) allow-discrete, display var(--wb-gam-dur) allow-discrete;
}
/* Blur is for the modal and the Moment card only; a side panel keeps the page behind it crisp. */
dialog.wb-gam-dialog::backdrop {
	backdrop-filter: blur(var(--wb-gam-pop-blur));
}
dialog.wb-gam-dialog[open]::backdrop,
dialog.wb-gam-drawer[open]::backdrop {
	opacity: 1;
}
@starting-style {
	dialog.wb-gam-dialog[open]::backdrop,
	dialog.wb-gam-drawer[open]::backdrop {
		opacity: 0;
	}
}

dialog.wb-gam-dialog {
	width: min(420px, calc(100% - 32px));
	max-width: none;
	margin: auto;
	border: 1px solid var(--wb-gam-pop-line);
	border-radius: var(--wb-gam-pop-r-lg);
	opacity: 0;
	transform: translateY(8px) scale(0.98);
	transition: opacity var(--wb-gam-dur-fast) var(--wb-gam-ease), transform var(--wb-gam-dur-fast) var(--wb-gam-ease), overlay var(--wb-gam-dur-fast) allow-discrete, display var(--wb-gam-dur-fast) allow-discrete;
}
dialog.wb-gam-dialog--form { width: min(480px, calc(100% - 32px)); }
dialog.wb-gam-dialog[open] {
	opacity: 1;
	transform: none;
	transition-duration: var(--wb-gam-dur-modal);
	transition-timing-function: var(--wb-gam-ease-out);
}
@starting-style {
	dialog.wb-gam-dialog[open] {
		opacity: 0;
		transform: translateY(8px) scale(0.98);
	}
}
.wb-gam-dialog__header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
	padding: 20px 12px 4px 24px;
}
.wb-gam-dialog__title {
	margin: 4px 0 0;
	font-size: 18px;
	font-weight: 600;
	line-height: 1.3;
	color: var(--wb-gam-pop-text); /* a host theme colours h2 itself; the shell must not inherit that */
}
.wb-gam-dialog__body {
	display: flex;
	flex-direction: column;
	gap: 12px;
	padding: 4px 24px 16px;
	color: var(--wb-gam-pop-text-2);
	font-size: 15px;
	line-height: 1.5;
}
.wb-gam-dialog__footer {
	display: flex;
	flex-wrap: wrap;
	justify-content: flex-end;
	gap: 8px;
	padding: 8px 24px 20px;
}

/* Physical right and left on purpose, so rtlcss mirrors the drawer for RTL locales. */
dialog.wb-gam-drawer {
	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	left: auto;
	width: min(520px, 100vw);
	max-width: none;
	height: 100dvh;
	max-height: none;
	margin: 0;
	border: 0;
	border-left: 1px solid var(--wb-gam-pop-line);
	border-radius: 0;
	overflow-y: auto;
	transform: translateX(100%);
	transition: transform var(--wb-gam-dur) var(--wb-gam-ease), overlay var(--wb-gam-dur) allow-discrete, display var(--wb-gam-dur) allow-discrete;
}
dialog.wb-gam-drawer[open] {
	display: flex;
	flex-direction: column;
	transform: translateX(0);
	transition-duration: var(--wb-gam-dur-slow);
	transition-timing-function: var(--wb-gam-ease-out);
}
@starting-style {
	dialog.wb-gam-drawer[open] {
		transform: translateX(100%);
	}
}

/* ── Menu ──────────────────────────────────────────────────────────────────── */
.wb-gam-menu {
	z-index: var(--wb-gam-pop-z-menu);
	box-sizing: border-box;
	padding: 4px 0;
	border: 1px solid var(--wb-gam-pop-line);
	border-radius: var(--wb-gam-pop-r-md);
	background: var(--wb-gam-pop-surface);
	color: var(--wb-gam-pop-text);
	box-shadow: var(--wb-gam-pop-shadow-md);
	font-family: var(--wb-gam-pop-font);
	animation: wb-gam-dropdown-in var(--wb-gam-dur-menu) ease both;
}
.wb-gam-menu[hidden] { display: none; }
.wb-gam-menu__option {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 12px;
	font-size: 14px;
	cursor: pointer;
}
.wb-gam-menu__option[aria-selected="true"] { background: var(--wb-gam-pop-subtle); }
@media (hover: hover) {
	.wb-gam-menu__option:hover { background: var(--wb-gam-pop-subtle); }
}

/* ── Moment card ───────────────────────────────────────────────────────────── */
.wb-gam-moment {
	position: fixed;
	inset: 0;
	z-index: var(--wb-gam-pop-z-modal);
	display: flex;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	padding: 16px;
	background: var(--wb-gam-pop-scrim);
	backdrop-filter: blur(var(--wb-gam-pop-blur));
	animation: wb-gam-fade-in var(--wb-gam-dur) var(--wb-gam-ease) both;
}
.wb-gam-moment[hidden] { display: none; }
.wb-gam-moment__card {
	position: relative;
	z-index: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	box-sizing: border-box;
	width: min(320px, 100%);
	padding: 28px 32px 26px;
	border: 1px solid var(--wb-gam-pop-line);
	border-radius: var(--wb-gam-pop-r-xl);
	background: var(--wb-gam-pop-surface);
	color: var(--wb-gam-pop-text);
	box-shadow: var(--wb-gam-pop-shadow-lg);
	font-family: var(--wb-gam-pop-font);
	text-align: center;
	animation: wb-gam-bounce-in var(--wb-gam-dur-moment) var(--wb-gam-ease-spring) both;
	transition: box-shadow var(--wb-gam-dur) var(--wb-gam-ease);
}
.wb-gam-moment__card.is-glow {
	box-shadow: 0 0 0 5px var(--wb-gam-pop-accent-200), var(--wb-gam-pop-shadow-lg);
}
.wb-gam-moment__ring {
	display: grid;
	place-items: center;
	width: 60px;
	height: 60px;
	margin-bottom: 8px;
	border: 2px solid var(--wb-gam-pop-accent);
	border-radius: 50%;
	background: var(--wb-gam-pop-accent-100);
	color: var(--wb-gam-pop-accent);
}
.wb-gam-moment__ring img {
	width: 38px;
	height: 38px;
	object-fit: contain;
}
.wb-gam-moment__numeral {
	font-size: 22px;
	font-weight: 700;
	line-height: 1;
	font-variant-numeric: tabular-nums;
	animation: wb-gam-count-pop var(--wb-gam-dur-moment) var(--wb-gam-ease) var(--wb-gam-delay-numeral) both;
}
.wb-gam-moment__eyebrow {
	margin: 0;
	color: var(--wb-gam-pop-accent);
	font-size: 12px;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
}
.wb-gam-moment__title {
	margin: 0;
	font-size: 28px;
	font-weight: 700;
	line-height: 1.15;
	overflow-wrap: anywhere;
}
.wb-gam-moment__sub {
	margin: 0 0 12px;
	color: var(--wb-gam-pop-text-2);
	font-size: 15px;
	line-height: 1.45;
}
.wb-gam-moment__sub:empty { display: none; }
.wb-gam-moment__title:last-of-type { margin-bottom: 12px; }

/* Confetti: five accent stops, transform and opacity only (assets/js/celebrate.js). */
.wb-gam-confetti {
	position: absolute;
	inset: 0;
	z-index: 0;
	overflow: hidden;
	pointer-events: none;
}
/* The layer for a burst that starts from a toast: a manual popover, so it paints above the toast
 * host, which is in the top layer too. */
.wb-gam-confetti--fixed {
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	margin: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
}
.wb-gam-cf {
	position: absolute;
	display: block;
	border-radius: 2px;
	will-change: transform, opacity;
}
.wb-gam-cf--dot { border-radius: 50%; }
.wb-gam-cf--1 { background: var(--wb-gam-cf-1); }
.wb-gam-cf--2 { background: var(--wb-gam-cf-2); }
.wb-gam-cf--3 { background: var(--wb-gam-cf-3); }
.wb-gam-cf--4 { background: var(--wb-gam-cf-4); }
.wb-gam-cf--5 { background: var(--wb-gam-cf-5); }

/* ── Reduced motion: 120ms opacity only, no transforms, a ring instead of confetti ─ */
@media (prefers-reduced-motion: reduce) {
	.wb-gam-toast,
	.wb-gam-banner,
	.wb-gam-menu,
	.wb-gam-moment,
	.wb-gam-moment__card {
		animation: wb-gam-fade-in var(--wb-gam-dur-fast) linear both;
	}
	.wb-gam-toast--exit {
		animation: wb-gam-fade-out var(--wb-gam-dur-fast) linear both;
	}
	.wb-gam-moment__numeral {
		animation: none;
	}
	dialog.wb-gam-dialog,
	dialog.wb-gam-dialog[open],
	dialog.wb-gam-drawer,
	dialog.wb-gam-drawer[open] {
		transform: none;
		transition-duration: var(--wb-gam-dur-fast);
	}
	dialog.wb-gam-drawer:not([open]) { opacity: 0; }
	dialog.wb-gam-drawer[open] { opacity: 1; }
	.wb-gam-confetti { display: none; }
}
