:root,
.wb-gam-scheme-light,
.wb-gam-scheme-dark {
	/* Spacing scale (used by SpacingControl) */
	--wb-gam-space-0: 0;
	--wb-gam-space-xs: 4px;
	--wb-gam-space-sm: 8px;
	--wb-gam-space-md: 16px;
	--wb-gam-space-lg: 24px;
	--wb-gam-space-xl: 32px;
	--wb-gam-space-2xl: 48px;
	--wb-gam-space-3xl: 64px;

	/* Border radius scale (md/lg tuned to match assets/css/hub.css) */
	--wb-gam-radius-none: 0;
	--wb-gam-radius-sm: 6px;
	--wb-gam-radius-md: 10px;
	--wb-gam-radius-lg: 14px;
	--wb-gam-radius-xl: 18px;
	--wb-gam-radius-full: 9999px;

	/* Shadow presets (sm/md tuned to match assets/css/hub.css - softer than Tailwind defaults) */
	--wb-gam-shadow-none: none;
	--wb-gam-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
	--wb-gam-shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
	--wb-gam-shadow-lg: 0 10px 24px rgba(0, 0, 0, 0.10);
	--wb-gam-shadow-xl: 0 20px 32px rgba(0, 0, 0, 0.12);

	/* Typography scale */
	--wb-gam-font-xs: 12px;
	--wb-gam-font-sm: 14px;
	--wb-gam-font-md: 16px;
	--wb-gam-font-lg: 18px;
	--wb-gam-font-xl: 20px;
	--wb-gam-font-2xl: 24px;
	--wb-gam-font-3xl: 30px;
	--wb-gam-font-4xl: 36px;
	--wb-gam-font-5xl: 48px;

	/* Font weights */
	--wb-gam-weight-normal: 400;
	--wb-gam-weight-medium: 500;
	--wb-gam-weight-semibold: 600;
	--wb-gam-weight-bold: 700;

	/* Line heights */
	--wb-gam-leading-tight: 1.25;
	--wb-gam-leading-normal: 1.5;
	--wb-gam-leading-relaxed: 1.75;

	/* Colors - neutral palette. Mapped to the host theme's color tokens so
	 * the plugin follows the theme's light/dark mode automatically. BuddyX
	 * and BuddyX Pro expose `--bx-color-*` and flip them under
	 * :root[data-bx-mode="dark"] (and prefers-color-scheme); consuming those
	 * here means cards/text/borders go dark with the theme. Any theme that
	 * doesn't define `--bx-color-*` falls back to the original light values,
	 * so behaviour is unchanged off the BuddyX family. Only NEUTRALS map to
	 * the theme - brand/semantic colors (accent, success, fire, medals) stay
	 * constant across modes. Muted/light text use color-mix so they keep a
	 * readable contrast against whichever surface the theme provides. */
	--wb-gam-color-white: var(--bx-color-bg-elevated, var(--reign-site-sections-bg-color, #ffffff));
	--wb-gam-color-text: var(--bx-color-fg, var(--reign-site-body-text-color, #1a1a2e));
	/* Secondary text is the theme text faded toward the card, but never below WCAG AA: on BuddyX's
	 * mid-grey #505050 text, 50% measured 2.4:1 and 70% 3.7:1; 80% clears 4.5:1 on the card and on
	 * the Hub's tinted stat tiles. */
	--wb-gam-color-text-muted: color-mix(in srgb, var(--bx-color-fg, var(--reign-site-body-text-color, #1a1a2e)) 84%, var(--bx-color-bg-elevated, var(--reign-site-sections-bg-color, #ffffff)));
	--wb-gam-color-text-light: color-mix(in srgb, var(--bx-color-fg, var(--reign-site-body-text-color, #1a1a2e)) 80%, var(--bx-color-bg-elevated, var(--reign-site-sections-bg-color, #ffffff)));
	--wb-gam-color-border: var(--bx-color-border, var(--reign-site-border-color, #e2e3ed));
	--wb-gam-color-border-hover: var(--bx-color-border, var(--reign-site-border-color, #c8c9d9));
	--wb-gam-color-surface: var(--bx-color-bg-elevated, var(--reign-site-sections-bg-color, #ffffff));
	--wb-gam-color-surface-hover: var(--bx-color-bg-muted, var(--reign-site-secondary-bg-color, #f7f7fb));
	--wb-gam-color-surface-alt: var(--bx-color-bg-muted, var(--reign-site-secondary-bg-color, #f1f5f9));
	--wb-gam-color-page: var(--bx-color-bg-page, var(--reign-site-secondary-bg-color, #f8fafc));
	/* Accent - follows the HOST THEME's link/accent colour before the brand purple.
	   Chain: site-owner override (--wbcom-link-color, from Settings > Appearance)
	   -> BuddyX (--bx-color-accent) -> Reign (--reign-site-button-bg-color) -> brand.
	   Until 1.6.4 the chain stopped at --wbcom-link-color, so on Reign every accent
	   in the plugin (buttons, icon chips, links) rendered brand purple while the
	   rest of the page used Reign's blue - the plugin looked bolted on rather than
	   part of the theme. */
	--wb-gam-color-accent: var(--wbcom-link-color, var(--bn-accent, var(--bx-color-accent, var(--reign-site-button-bg-color, #5b4cdb))));
	--wb-gam-color-accent-hover: var(--wbcom-link-hover-color, var(--bn-accent-600, var(--bx-color-accent-hover, var(--reign-site-button-bg-hover-color, #4338b2))));
	/* Tint backgrounds (icon chips, accent pills) are mixed OVER the theme
	 * surface so they're a faint light tint in light mode and a faint dark
	 * tint in dark mode - no opaque light blob on a dark card. */
	--wb-gam-color-accent-light: color-mix(in srgb, var(--wb-gam-color-accent) 14%, var(--wb-gam-color-surface));
	/* Accent text (point numbers, labels) is the accent blended half-way into an ink: the theme's
	 * text darkened toward black in light mode, the theme's light text in dark mode (redefined
	 * there). Blending with BuddyX's mid-grey #505050 text alone left an orange accent at 4.07:1 and
	 * yellow under 4:1; with the ink every accent tried (red, orange, yellow, green, cyan, violet)
	 * measures at least 4.5:1 on the card and on tinted rows, and keeps its hue. */
	--wb-gam-color-accent-ink: color-mix(in srgb, var(--wb-gam-color-text) 40%, #000000);
	/* An owner's own accent (block setting, no card colour) is held to this OKLCH lightness range when it is
	 * used as text (CSS.php): at most 0.5 on a light surface (4.5:1 on white and on a tinted row), at least
	 * 0.72 on a dark one. Hue and chroma stay the owner's. */
	--wb-gam-accent-l-min: 0;
	--wb-gam-accent-l-max: 0.5;
	--wb-gam-color-accent-text: color-mix(in srgb, var(--wb-gam-color-accent) 50%, var(--wb-gam-color-accent-ink));
	/* Follows the theme's accent, like every other accent tint (was a fixed brand-purple rgba). */
	--wb-gam-color-accent-ring: color-mix(in srgb, var(--wb-gam-color-accent) 20%, transparent);

	/* Colors - semantic. The solid hue stays constant; the `-bg` tint is
	 * mixed over the theme surface so status chips / podium rows / pills
	 * adapt to dark mode instead of showing an opaque light blob. (The
	 * `-soft` rgba variants were already surface-agnostic.) */
	--wb-gam-color-success: #0d9f6e;
	--wb-gam-color-success-bg: color-mix(in srgb, var(--wb-gam-color-success) 12%, var(--wb-gam-color-surface));
	/* #047857 measured 4.27:1 on its own tint over a cream owner card; this holds 5:1 there, 5.6:1 on white. */
	--wb-gam-color-success-strong: #046c4e;
	--wb-gam-color-success-soft: rgba(13, 159, 110, 0.12);
	/* Text on a solid success fill: white on #0d9f6e is 3.4:1, this near-black green is 5.7:1. */
	--wb-gam-color-success-ink: #03130b;

	/* League tier accents (cohort rank). These are deliberately literal -- bronze is
	 * bronze -- but they belong here rather than hardcoded inside a block stylesheet.
	 * As tokens the owner can rebrand a tier, and the dark-mode block below can lift
	 * the darker medals so Bronze and Obsidian do not disappear against a dark
	 * surface. Hardcoded in cohort-rank/style.css, they could do neither. */
	--wb-gam-tier-bronze: #b45309;
	--wb-gam-tier-silver: #6b7280;
	--wb-gam-tier-gold: #d97706;
	--wb-gam-tier-diamond: #2563eb;
	--wb-gam-tier-obsidian: #4b5563;
	--wb-gam-color-warning: #c2770e;
	--wb-gam-color-warning-bg: color-mix(in srgb, var(--wb-gam-color-warning) 12%, var(--wb-gam-color-surface));
	/* amber-800: #b45309 measured 3.97:1 as a bonus pill on the green tint of a completed challenge. */
	--wb-gam-color-warning-strong: #92400e;
	--wb-gam-color-warning-soft: rgba(245, 158, 11, 0.15);
	--wb-gam-color-danger: #ef4444;
	--wb-gam-color-danger-bg: color-mix(in srgb, var(--wb-gam-color-danger) 12%, var(--wb-gam-color-surface));
	--wb-gam-color-danger-strong: #b91c1c;
	--wb-gam-color-danger-soft: rgba(185, 28, 28, 0.10);
	/* blue-700: #2563eb measured 4.37:1 as 11px text on its own tint. */
	--wb-gam-color-info: #1d4ed8;
	--wb-gam-color-info-bg: color-mix(in srgb, var(--wb-gam-color-info) 12%, var(--wb-gam-color-surface));
	--wb-gam-color-info-soft: rgba(37, 99, 235, 0.10);

	/* Extra neutrals - surface-muted is the "card lifted off a panel"
	 * shade. Border-strong is the focus / hover stroke. Theme-mapped (see
	 * the neutral palette note above). */
	/* Rows on a card: the card's own surface, a step toward the ink. A theme's muted shade can sit on
	 * either side of its card (BuddyX: #fafafa on #fff at 1.04:1 in light, #101010 under #161616 in dark),
	 * so it cannot separate rows from their card in both modes. */
	--wb-gam-color-surface-muted: color-mix(in srgb, var(--wb-gam-color-text) 5%, var(--wb-gam-color-surface));
	--wb-gam-color-border-strong: var(--bx-color-border, var(--reign-site-border-color, #d1d5db));
	--wb-gam-color-locked-soft: rgba(156, 163, 175, 0.16);
	--wb-gam-color-primary-soft: color-mix(in srgb, var(--wb-gam-color-accent) 10%, transparent);

	/* Accent variants tied to per-block accent (fire, gold-soft). */
	--wb-gam-color-fire: #f59e0b;
	--wb-gam-color-fire-light: #f97316;
	--wb-gam-color-fire-strong: #b45309;
	--wb-gam-color-fire-soft: rgba(245, 158, 11, 0.15);
	--wb-gam-color-fire-gradient: linear-gradient(90deg, #f97316 0%, #f59e0b 100%);

	/* Streak heatmap - 4 intensity steps of the primary accent (purple
	 * family). Cell-0 is the empty state (border-strength), 1→4 ramps
	 * from soft to deepest. Kept distinct from the regular primary
	 * palette so heatmap legibility doesn't depend on theme accent. */
	--wb-gam-color-heatmap-0: var(--wb-gam-color-border);
	--wb-gam-color-heatmap-1: #c4b5fd;
	--wb-gam-color-heatmap-2: #a78bfa;
	--wb-gam-color-heatmap-3: #7c3aed;
	--wb-gam-color-heatmap-4: #4c1d95;

	/* Rank/medal palette (used by leaderboard, top-members, year-recap) */
	--wb-gam-color-gold: #b8860b;
	/* gray-600: #6b7280 measured 4.47:1 on the tinted leaderboard rows. */
	--wb-gam-color-silver: #4b5563;
	--wb-gam-color-bronze: #a0522d;
	/* A light ground for uploaded badge art (often dark line-art on transparent). Fixed on
	 * purpose: it does not flip in dark mode, because the art needs a light surface there most. */
	--wb-gam-color-art-tile: #f8fafc;
	/* Gold as TEXT (rank number, "1st place", badge counts, a badge behind white text). The medal
	 * gold is 3.25:1 on white and 2.9:1 on the cream first-place row; this ink is 5.37:1 and
	 * 4.78:1. Silver (4.83:1) and bronze (6.1:1) already pass. Dark mode uses the medal itself. */
	--wb-gam-color-gold-text: color-mix(in srgb, #b8860b 75%, #000000);

	/* Interaction states */
	--wb-gam-color-disabled: var(--wb-gam-color-surface-alt);
	--wb-gam-color-disabled-text: var(--wb-gam-color-text-light);
	--wb-gam-color-focus: #ffd54a;

	/* Responsive breakpoints (used by CSS generation utility) */
	--wb-gam-bp-tablet: 1024px;
	--wb-gam-bp-mobile: 767px;

	/* Transition. Aliases of the locked motion scale below: the plugin used to carry its own
	 * 150/300/500ms scale next to BuddyNext's 120/200/400ms, which is how one screen ended up
	 * with fourteen different durations. */
	--wb-gam-transition-fast: var(--wb-gam-dur-fast) var(--wb-gam-ease);
	--wb-gam-transition-normal: var(--wb-gam-dur) var(--wb-gam-ease);
	--wb-gam-transition-slow: var(--wb-gam-dur-slow) var(--wb-gam-ease);

	/* Z-index scale */
	--wb-gam-z-below: -1;
	--wb-gam-z-base: 0;
	--wb-gam-z-above: 1;
	--wb-gam-z-dropdown: 10;
	--wb-gam-z-overlay: 100;
	--wb-gam-z-modal: 1000;

	/* ── Shorthand aliases ──────────────────────────────────────────
	 * Per-block stylesheets in src/Blocks/<slug>/style.css consume
	 * these short names. Defined here (not frontend.css) so the
	 * `wb-gam-tokens` handle is sufficient - blocks no longer depend
	 * on the legacy `wb-gamification` (frontend.css) bundle being
	 * enqueued. */
	--wb-gam-primary: var(--wb-gam-color-accent);
	--wb-gam-primary-light: var(--wb-gam-color-accent-light);
	--wb-gam-primary-text: var(--wb-gam-color-accent-text);
	--wb-gam-text: var(--wb-gam-color-text);
	--wb-gam-text-secondary: var(--wb-gam-color-text-muted);
	--wb-gam-text-muted: var(--wb-gam-color-text-light);
	--wb-gam-border: var(--wb-gam-color-border);
	--wb-gam-card-bg: var(--wb-gam-color-surface);
	--wb-gam-card-bg-hover: var(--wb-gam-color-surface-hover);
	--wb-gam-radius: var(--wb-gam-radius-md);
	--wb-gam-radius-card: var(--wb-gam-radius-md);
	--wb-gam-shadow: var(--wb-gam-shadow-sm);
	--wb-gam-shadow-hover: var(--wb-gam-shadow-md);
	--wb-gam-gap: var(--wb-gam-space-md);
	--wb-gam-transition: var(--wb-gam-transition-fast);
	--wb-gam-gold: var(--wb-gam-color-gold);
	--wb-gam-silver: var(--wb-gam-color-silver);
	--wb-gam-bronze: var(--wb-gam-color-bronze);
	--wb-gam-fill: var(--wb-gam-color-accent);
	--wb-gam-recap-accent: var(--wb-gam-color-accent);
}

/* ── Popup system ───────────────────────────────────────────────────────────
 * The one home for every popup value: toast, banner, dialog, drawer, menu and the
 * Moment card. Designed in the Popup Atlas and agreed with the BuddyNext session.
 *
 * Every token reads BuddyNext first. The fallback is BuddyNext's own default, so the
 * plugin renders identically on a site without BuddyNext and follows BuddyNext's
 * numbers automatically when they change (BuddyNext also flips these in dark mode).
 * A popup stylesheet must use these tokens and never a literal; bin/check-motion-tokens.sh
 * fails the build on a raw duration or easing outside this file and popups.css.
 */
:root {
	/* Colour */
	--wb-gam-pop-surface: var(--bn-surface, var(--wb-gam-color-surface));
	--wb-gam-pop-text: var(--bn-text-1, var(--wb-gam-color-text));
	--wb-gam-pop-text-2: var(--bn-text-2, var(--wb-gam-color-text-muted));
	--wb-gam-pop-text-3: var(--bn-text-3, var(--wb-gam-color-text-light));
	--wb-gam-pop-line: var(--bn-line, var(--bn-border, var(--wb-gam-color-border)));
	--wb-gam-pop-subtle: var(--bn-bg-subtle, var(--wb-gam-color-surface-alt));
	/* Inside BuddyNext the fill is BuddyNext's button fill (the accent deepened only as far as a
	 * white label needs) and the label below is its pair, so a gamification button reads like
	 * BuddyNext's own Post button. The raw accent-500 with our own label rule gave black on blue. */
	/* Toasts and popups fit any site (TOASTS.md): BuddyNext's pair, then the host theme's own accent
	   (Wbcom themes, then block-theme presets), then a neutral ink. Never the plugin's brand colour. */
	--wb-gam-pop-accent: var(--bn-accent-solid, var(--bn-accent, var(--wbcom-link-color, var(--bx-color-accent, var(--reign-site-button-bg-color, var(--wp--preset--color--primary, var(--wp--preset--color--accent-1, var(--wp--preset--color--contrast, #1e1e1e))))))));
	/* Text ON the accent. Each theme pairs its button colour with a text colour (BuddyX's
	 * accent-inverse, Reign's button text), so read that pair before assuming white: Reign dark's
	 * #97c0ee button with white text measured 1.89:1, with Reign's own #111111 it is 9.97:1. */
	--wb-gam-pop-accent-fg: var(--bn-accent-fg, var(--bx-color-accent-inverse, var(--reign-site-button-text-color, #ffffff)));
	/* Hover / pressed fill for a button on the accent. Hover feedback must move the fill AWAY from the
	 * label (opacity, brightness() and a darker mix with a dark label all moved it toward the label and
	 * measured 3.79:1 to 4.36:1). The browsers below that cannot read the label back keep a white label,
	 * so darken; the @supports block further down replaces this with the exact opposite of the label. */
	--wb-gam-pop-accent-hover: color-mix(in srgb, var(--wb-gam-pop-accent) 88%, #000000);
	--wb-gam-pop-accent-100: var(--bn-accent-100, color-mix(in srgb, var(--wb-gam-pop-accent) 12%, var(--wb-gam-pop-surface)));
	--wb-gam-pop-accent-200: var(--bn-accent-200, color-mix(in srgb, var(--wb-gam-pop-accent) 24%, var(--wb-gam-pop-surface)));
	--wb-gam-pop-success: var(--bn-success, var(--wb-gam-color-success));
	--wb-gam-pop-success-bg: var(--bn-success-bg, var(--wb-gam-color-success-bg));
	--wb-gam-pop-danger: var(--bn-danger, var(--wb-gam-color-danger));
	--wb-gam-pop-danger-bg: var(--bn-danger-bg, var(--wb-gam-color-danger-bg));
	--wb-gam-pop-info: var(--bn-info, var(--wb-gam-color-info));
	--wb-gam-pop-info-bg: var(--bn-info-bg, var(--wb-gam-color-info-bg));
	/* The toast is BuddyNext's inverted surface: the text colour as the ground. */
	--wb-gam-pop-inv-bg: var(--bn-text-1, var(--wb-gam-color-text));
	--wb-gam-pop-inv-fg: var(--bn-bg, var(--wb-gam-color-page));

	/* Confetti: five stops of the community's accent plus white. Never a rainbow. */
	--wb-gam-cf-1: var(--bn-accent-500, var(--wb-gam-pop-accent));
	--wb-gam-cf-2: var(--bn-accent-400, color-mix(in srgb, var(--wb-gam-pop-accent) 65%, #ffffff));
	--wb-gam-cf-3: var(--bn-accent-600, color-mix(in srgb, var(--wb-gam-pop-accent) 85%, #20262e));
	--wb-gam-cf-4: var(--bn-accent-800, color-mix(in srgb, var(--wb-gam-pop-accent) 68%, #20262e));
	--wb-gam-cf-5: #ffffff;

	/* Shape and elevation */
	--wb-gam-pop-r-sm: var(--bn-r-sm, 5px);
	--wb-gam-pop-r-md: var(--bn-r-md, 10px);
	--wb-gam-pop-r-lg: var(--bn-r-lg, 14px);
	--wb-gam-pop-r-xl: var(--bn-r-xl, 20px);
	--wb-gam-pop-r-full: var(--bn-r-full, 9999px);
	--wb-gam-pop-shadow-md: var(--bn-shadow-md, 0 2px 4px rgba(0, 0, 0, 0.04), 0 8px 16px rgba(0, 0, 0, 0.06));
	--wb-gam-pop-shadow-lg: var(--bn-shadow-lg, 0 8px 16px rgba(0, 0, 0, 0.06), 0 24px 48px rgba(0, 0, 0, 0.12));
	--wb-gam-pop-scrim: var(--bn-overlay, color-mix(in srgb, #20262e 55%, transparent));
	--wb-gam-pop-blur: 2px;

	/* Layers. Never a literal in a stylesheet. */
	--wb-gam-pop-z-menu: var(--bn-z-menu, 99000);
	--wb-gam-pop-z-modal: var(--bn-z-modal, 100100);
	--wb-gam-pop-z-toast: var(--bn-z-toast, 100200);

	/* Buttons: BuddyNext's shared button. */
	--wb-gam-btn-h: var(--bn-btn-h, 40px);
	--wb-gam-btn-r: var(--bn-btn-r, var(--bn-r-md, 10px));
	--wb-gam-btn-py: var(--bn-btn-py, 8px);
	--wb-gam-btn-px: var(--bn-btn-px, 16px);

	/* Type */
	--wb-gam-pop-font: var(--bn-font-body, inherit);

	/* Motion: BuddyNext's three timings and two easings, plus the four keyframe timings
	 * BuddyNext's own toast, modal, dropdown and bounce-in use. */
	--wb-gam-dur-fast: var(--bn-dur-fast, 120ms);
	--wb-gam-dur: var(--bn-dur, 200ms);
	--wb-gam-dur-slow: var(--bn-dur-slow, 400ms);
	--wb-gam-dur-toast: 250ms;
	--wb-gam-dur-modal: 180ms;
	--wb-gam-dur-menu: 150ms;
	--wb-gam-dur-moment: 500ms;
	--wb-gam-delay-numeral: 300ms;
	--wb-gam-ease: var(--bn-ease, cubic-bezier(0.2, 0.8, 0.2, 1));
	--wb-gam-ease-out: var(--bn-ease-out, cubic-bezier(0.16, 1, 0.3, 1));
	--wb-gam-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Dark-mode accent ───────────────────────────────────────────────────────
 * The THEME's accent still wins here. Only the final fallback changes: on a
 * dark surface the brand purple is lightened so glyphs, links, the level
 * progress bar and accent pills keep their punch and contrast.
 *
 * Until 1.6.4 this block set the lightened purple UNCONDITIONALLY - a per-mode
 * internal literal that overrode the whole theme chain. The result: on any dark
 * theme, every accent in the plugin painted brand purple regardless of what the
 * theme's accent was. On Reign (accent #97c0ee, a blue) the plugin's buttons and
 * icon chips came out purple against a blue-accented page, so it read as bolted
 * on rather than part of the theme. A theme-mapped token that a per-mode literal
 * later overwrites is not theme-mapped at all.
 *
 * Chain, unchanged from :root - only the tail differs:
 *   --wbcom-link-color            site-owner override (Settings > Appearance)
 *   --bx-color-accent            BuddyX / BuddyX Pro
 *   --reign-site-button-bg-color Reign (its ACCENT; --reign-site-link-color is
 *                                #ffffff in dark - that is link TEXT, not a brand
 *                                colour, and would give white-on-white buttons)
 *   lightened brand purple       themes exposing no accent token
 *
 * Scoped to the dark selectors the whole Wbcom theme family uses: data-bx-mode
 * (BuddyX, BuddyX Pro AND Reign 8.x all set it), the prefers-color-scheme auto
 * path, and the legacy .buddyx-dark-theme body class. accent-light / accent-text
 * cascade from --wb-gam-color-accent, so they follow automatically. */
:root[data-bx-mode="dark"],
:root[data-theme="dark"],
body.buddyx-dark-theme,
.wb-gam-scheme-dark {
	/* An owner's own accent (block setting) is any colour at all: #cc0000 half-mixed into the ink read
	 * 3.10:1 on Reign's dark surface. Pull it further toward the ink in dark; the theme accent keeps 50%. */
	--wb-gam-owner-accent-mix: 35%;
	--wb-gam-accent-l-min: 0.72;
	--wb-gam-accent-l-max: 1;
	--wb-gam-color-accent: var(--wbcom-link-color, var(--bn-accent, var(--bx-color-accent, var(--reign-site-button-bg-color, color-mix(in srgb, #5b4cdb 60%, #ffffff)))));
	--wb-gam-color-accent-hover: var(--wbcom-link-hover-color, var(--bn-accent-600, var(--bx-color-accent-hover, var(--reign-site-button-bg-hover-color, color-mix(in srgb, #5b4cdb 45%, #ffffff)))));
	--wb-gam-color-accent-ink: var(--wb-gam-color-text);

	/* Lift the dark medals. Bronze (#b45309) and Obsidian (#4b5563) are dark enough to
	 * sink into a dark surface -- the member's own league tier becomes the one thing
	 * they cannot read. Mixing toward white keeps each medal recognisably itself while
	 * restoring contrast. This is only expressible because the tiers are tokens. */
	--wb-gam-tier-bronze: color-mix(in srgb, #b45309 65%, #ffffff);
	--wb-gam-tier-silver: color-mix(in srgb, #6b7280 55%, #ffffff);
	--wb-gam-tier-obsidian: color-mix(in srgb, #4b5563 55%, #ffffff);

	/* The RANK medals needed exactly the same lift and never got it. The league tiers above were
	 * fixed; the rank palette sitting right beside them -- leaderboard positions 1/2/3, the
	 * top-members podium, year-recap -- kept its light-mode values and sank into the dark surface.
	 * Measured against a #161616 surface: silver #6b7280 = 3.74:1, bronze #a0522d = 3.22:1, both
	 * under the 4.5:1 WCAG AA floor. Gold clears it at 5.56:1 and is left as it is. */
	--wb-gam-color-silver: color-mix(in srgb, #6b7280 45%, #ffffff);
	--wb-gam-color-bronze: color-mix(in srgb, #a0522d 50%, #ffffff);
	--wb-gam-color-gold-text: color-mix(in srgb, var(--wb-gam-color-gold) 70%, #ffffff);

	/* Text on the lightened brand accent: white on it is 2.68:1, this ink is 6.37:1. A theme's
	 * own pair still wins. */
	--wb-gam-pop-accent-fg: var(--bn-accent-fg, var(--bx-color-accent-inverse, var(--reign-site-button-text-color, #1a1a2e)));
	--wb-gam-pop-accent-hover: color-mix(in srgb, var(--wb-gam-pop-accent) 88%, #ffffff);

	/* Lift the "-strong" status inks, info and the deepest heatmap step for a dark surface. The
	 * light values measure 2.3:1 to 3.6:1 on #161616 / #1f2937 / #15181f (heatmap-4 1.3:1); the
	 * mixes below measure at least 5.2:1 on all three (heatmap-4 4.5:1), and stay recognisably
	 * green, amber, red, blue and violet. Warning is lifted to 50% so a bonus pill on the green tint
	 * of a completed challenge still clears 4.5:1 (60% measured 4.34:1 there). */
	--wb-gam-color-success-strong: color-mix(in srgb, #047857 60%, #ffffff);
	--wb-gam-color-warning-strong: color-mix(in srgb, #b45309 50%, #ffffff);
	--wb-gam-color-danger-strong: color-mix(in srgb, #b91c1c 55%, #ffffff);
	--wb-gam-color-fire-strong: color-mix(in srgb, #b45309 60%, #ffffff);
	--wb-gam-color-info: color-mix(in srgb, #2563eb 60%, #ffffff);
	--wb-gam-color-heatmap-4: color-mix(in srgb, #4c1d95 55%, #ffffff);
}
@media (prefers-color-scheme: dark) {
	:root[data-bx-mode="auto"] {
		--wb-gam-owner-accent-mix: 35%;
		--wb-gam-accent-l-min: 0.72;
		--wb-gam-accent-l-max: 1;
		--wb-gam-color-accent: var(--wbcom-link-color, var(--bn-accent, var(--bx-color-accent, var(--reign-site-button-bg-color, color-mix(in srgb, #5b4cdb 60%, #ffffff)))));
		--wb-gam-color-accent-hover: var(--wbcom-link-hover-color, var(--bn-accent-600, var(--bx-color-accent-hover, var(--reign-site-button-bg-hover-color, color-mix(in srgb, #5b4cdb 45%, #ffffff)))));
		--wb-gam-color-accent-ink: var(--wb-gam-color-text);

		/* Auto-mode is a dark surface too. Lifting the medals only on the explicit dark
		 * selectors would leave every owner who never touched the toggle reading 3.2:1 bronze. */
		--wb-gam-tier-bronze: color-mix(in srgb, #b45309 65%, #ffffff);
		--wb-gam-tier-silver: color-mix(in srgb, #6b7280 55%, #ffffff);
		--wb-gam-tier-obsidian: color-mix(in srgb, #4b5563 55%, #ffffff);
		--wb-gam-color-silver: color-mix(in srgb, #6b7280 45%, #ffffff);
		--wb-gam-color-bronze: color-mix(in srgb, #a0522d 50%, #ffffff);
		--wb-gam-color-gold-text: color-mix(in srgb, var(--wb-gam-color-gold) 70%, #ffffff);
		/* Text on the lightened brand accent: white on it is 2.68:1, this ink is 6.37:1. A theme's
		 * own pair still wins. */
		--wb-gam-pop-accent-fg: var(--bn-accent-fg, var(--bx-color-accent-inverse, var(--reign-site-button-text-color, #1a1a2e)));
		--wb-gam-pop-accent-hover: color-mix(in srgb, var(--wb-gam-pop-accent) 88%, #ffffff);

		/* Lift the "-strong" status inks, info and the deepest heatmap step for a dark surface. The
		 * light values measure 2.3:1 to 3.6:1 on #161616 / #1f2937 / #15181f (heatmap-4 1.3:1); the
		 * mixes below measure at least 5.2:1 on all three (heatmap-4 4.5:1), and stay recognisably
		 * green, amber, red, blue and violet. */
		--wb-gam-color-success-strong: color-mix(in srgb, #047857 60%, #ffffff);
		--wb-gam-color-warning-strong: color-mix(in srgb, #b45309 50%, #ffffff);
		--wb-gam-color-danger-strong: color-mix(in srgb, #b91c1c 55%, #ffffff);
		--wb-gam-color-fire-strong: color-mix(in srgb, #b45309 60%, #ffffff);
		--wb-gam-color-info: color-mix(in srgb, #2563eb 60%, #ffffff);
		--wb-gam-color-heatmap-4: color-mix(in srgb, #4c1d95 55%, #ffffff);
	}
}

/* Label colour on accent buttons, picked from the accent's own relative luminance: black on an accent
 * lighter than Y = 0.1791, white on a darker one. That is the luminance where black and white tie, so
 * the winner is at least 4.58:1 on ANY accent; the earlier pick by oklch lightness (round(1.07 - l))
 * measured 3.98:1 on about 2% of the sRGB gamut (an owner-chosen mid-tone accent). Overrides a theme's
 * button text pair, which is the one that failed. Browsers without relative colours keep the value above.
 * Inside BuddyNext its own pair wins (--bn-accent-fg with --bn-accent-solid, the fill above): the two
 * rules disagree near the middle, and the default blue got a black label from this one.
 * --wb-gam-pop-accent-hover is the pressed / hover fill: the accent moved 12% AWAY from the label (toward
 * white under a black label, toward black under a white one), so the pair is never worse than at rest. */
@supports (color: oklch(from red l c h)) {
	/* The dark selectors too: they restore the theme's pair (BuddyX dark: white on its orange, 3.36:1). */
	:root,
	:root[data-bx-mode="dark"],
	:root[data-theme="dark"],
	body.buddyx-dark-theme,
	.wb-gam-scheme-light,
	.wb-gam-scheme-dark {
		--wb-gam-pop-accent-fg: var(--bn-accent-fg, color(from var(--wb-gam-pop-accent) srgb-linear calc(1 - round(clamp(0, calc((0.2126 * r + 0.7152 * g + 0.0722 * b - 0.1791) * 1000), 1))) calc(1 - round(clamp(0, calc((0.2126 * r + 0.7152 * g + 0.0722 * b - 0.1791) * 1000), 1))) calc(1 - round(clamp(0, calc((0.2126 * r + 0.7152 * g + 0.0722 * b - 0.1791) * 1000), 1)))));
		--wb-gam-pop-accent-hover: color-mix(in srgb, var(--wb-gam-pop-accent) 88%, oklch(from var(--wb-gam-pop-accent-fg) round(1 - l) 0 0));
	}
	@media (prefers-color-scheme: dark) {
		:root[data-bx-mode="auto"] {
			--wb-gam-pop-accent-fg: var(--bn-accent-fg, color(from var(--wb-gam-pop-accent) srgb-linear calc(1 - round(clamp(0, calc((0.2126 * r + 0.7152 * g + 0.0722 * b - 0.1791) * 1000), 1))) calc(1 - round(clamp(0, calc((0.2126 * r + 0.7152 * g + 0.0722 * b - 0.1791) * 1000), 1))) calc(1 - round(clamp(0, calc((0.2126 * r + 0.7152 * g + 0.0722 * b - 0.1791) * 1000), 1)))));
			--wb-gam-pop-accent-hover: color-mix(in srgb, var(--wb-gam-pop-accent) 88%, oklch(from var(--wb-gam-pop-accent-fg) round(1 - l) 0 0));
		}
	}
}

/* ── Owner card colour ──────────────────────────────────────────────────────
 * A block whose owner set a Card background carries .wb-gam-scheme-light or
 * .wb-gam-scheme-dark, picked from that colour (WBGam\Blocks\CSS::ink_for()). The
 * light or dark token set above is declared again on the block, so every token
 * built from the surface or the text resolves against the owner's card instead of
 * the page's mode: a cream card on a dark page reads as a light card. The block's
 * own rule (CSS.php) then pins text and surfaces to that card.
 * Popups and headings here follow the card, not BuddyNext or the theme. */
@supports (color: oklch(from red l c h)) {
	/* The theme's accent (or the owner's) as text on an owner's card: its lightness held to the range the card
	 * allows (--wb-gam-accent-l-min / -max, set per card by CSS.php card_tokens()). */
	.wb-gam-scheme-light,
	.wb-gam-scheme-dark {
		--wb-gam-color-accent-text: oklch(from var(--wb-gam-color-accent) clamp(var(--wb-gam-accent-l-min), l, var(--wb-gam-accent-l-max)) min(c, 0.11) h);
	}
}
.wb-gam-scheme-light {
	color-scheme: light;
}
.wb-gam-scheme-dark {
	color-scheme: dark;
}
.wb-gam-scheme-light,
.wb-gam-scheme-dark {
	--wb-gam-pop-surface: var(--wb-gam-color-surface);
	--wb-gam-pop-text: var(--wb-gam-color-text);
	--wb-gam-pop-text-2: var(--wb-gam-color-text-muted);
	--wb-gam-pop-text-3: var(--wb-gam-color-text-light);
	--wb-gam-pop-subtle: var(--wb-gam-color-surface-alt);
	--wb-gam-pop-inv-bg: var(--wb-gam-color-text);
}
/* ── Keyboard focus ring: one rule for every control in the 19 blocks and the hub ──
 * A 2px ring, offset 2px, in --wb-gam-focus-ring: the card's own ink (or accent text) when the owner set
 * card colours (CSS.php card_tokens()), else the accent's text colour on the theme surface; both read 4.5:1
 * on the surface they sit on. A 4px halo in the surface colour sits either side of it (the box-shadow
 * spans the gap and the band outside the ring), so the pair stays visible on a card of any colour and on
 * any page colour around it: whichever of ring or halo the backdrop swallows, the other reaches 3:1.
 * !important with specificity (0,4,0): BuddyX 5.1.3 ships `:focus-visible { outline: 2px solid #2271b1 !important }`
 * (0,1,0) and `... :focus { box-shadow: none !important }`; between two !important declarations the higher
 * specificity wins, so the ring stays ours inside our own controls and the theme's applies everywhere else.
 * :focus-visible keeps it off mouse clicks. There is no outline: none anywhere in the blocks without this
 * replacement. The second selector list covers the controls that sit outside a block wrapper (popups, the
 * badge share page, the profile privacy toggle, the hub's convert form), at (0,2,0). */
[class*="wp-block-wb-gamification"] :is(a, button, input, select, textarea, summary, [tabindex]:not([tabindex="-1"])):focus-visible,
:is(.wb-gam-btn, .wb-gam-close, .wb-gam-toast__link, .wb-gam-banner__action, .wb-gam-share-card__action, .wb-gam-profile-privacy__toggle, .gam-stat__convert, .gam-card, .wbgam-convert-form__field select, .wbgam-convert-form__field input):focus-visible {
	outline: 2px solid var(--wb-gam-focus-ring, var(--wb-gam-color-accent-text, currentColor)) !important;
	outline-offset: 2px !important;
	box-shadow: 0 0 0 6px var(--wb-gam-color-surface, #fff) !important;
}
/* ── Form controls: text, fill, border, placeholder and autofill from the card's own tokens ──
 * BuddyX styles `input[type=text]`, `textarea`, `select` and their :focus at (0,1,1) / (0,2,1) with its
 * own colour, fill and border: on a dark owner card the typed text read rgb(80,80,80) on rgb(20,33,61)
 * (1.95:1) and the recipient field turned white. Every input, textarea and select in our blocks, the hub
 * convert form and the shortcode forms takes the card's tokens instead, !important so no theme form rule
 * splits the pair. --wb-gam-color-text / -surface / -text-light are the card-derived tokens on an owner
 * card (CSS.php card_tokens()) and the theme-derived ones elsewhere. The border is the only boundary of
 * a field that shares the card's colour, so it is mixed 65% toward the text colour (3:1 or more on any
 * card, WCAG 1.4.11); the placeholder is --wb-gam-color-text-light (4.5:1, opacity 1 because Firefox
 * dims it). Chromium paints an autofilled field with its own fill: the text fill colour is forced and the
 * fill transition is held so the card colour stays. Checkboxes, radios and buttons keep their own look. */
:is([class*="wp-block-wb-gamification"], .wb-gam-give-kudos, .wb-gam-submit-achievement, .wbgam-convert-form) :is(input:not([type="checkbox"], [type="radio"], [type="hidden"], [type="submit"], [type="button"], [type="reset"], [type="range"], [type="color"], [type="file"], [type="image"]), textarea, select) {
	--wb-gam-field-border: color-mix(in srgb, var(--wb-gam-color-text) 65%, var(--wb-gam-color-surface));
	color: var(--wb-gam-color-text) !important;
	background-color: var(--wb-gam-color-surface) !important;
	border-color: var(--wb-gam-field-border) !important;
}
:is([class*="wp-block-wb-gamification"], .wb-gam-give-kudos, .wb-gam-submit-achievement, .wbgam-convert-form) :is(input:not([type="checkbox"], [type="radio"], [type="hidden"], [type="submit"], [type="button"], [type="reset"], [type="range"], [type="color"], [type="file"], [type="image"]), textarea, select):is(:focus, :focus-visible) {
	border-color: var(--wb-gam-focus-ring, var(--wb-gam-color-accent-text)) !important;
}
:is([class*="wp-block-wb-gamification"], .wb-gam-give-kudos, .wb-gam-submit-achievement, .wbgam-convert-form) :is(input, textarea)::placeholder {
	color: var(--wb-gam-color-text-light) !important;
	opacity: 1 !important;
}
:is([class*="wp-block-wb-gamification"], .wb-gam-give-kudos, .wb-gam-submit-achievement, .wbgam-convert-form) :is(input, textarea, select):-webkit-autofill {
	-webkit-text-fill-color: var(--wb-gam-color-text) !important;
	caret-color: var(--wb-gam-color-text);
	transition: background-color 600000s 0s !important;
}
:is([class*="wp-block-wb-gamification"], .wb-gam-give-kudos, .wb-gam-submit-achievement, .wbgam-convert-form) select option {
	color: var(--wb-gam-color-text) !important;
	background-color: var(--wb-gam-color-surface) !important;
}
/* ── Accent buttons: fill AND label from the one pair the helper computed ──
 * --wb-gam-pop-accent is the fill, --wb-gam-pop-accent-fg its contrast-safe label (4.5:1 on any accent,
 * derived above), --wb-gam-pop-accent-hover the pressed fill. A theme's own button rule (BuddyX
 * `button[type=submit]`, (0,1,1), and its :hover, (0,2,1)) beats a single-class selector, so the fill went
 * to the theme's red under our white label (3.46:1 on BuddyX, 3.87:1 on BuddyX Pro). One rule here, !important
 * so no theme can split the pair; the per-component stylesheets keep only layout. A disabled control keeps
 * its own colours only where a component says so with !important (the Redeem button). */
:is(.wb-gam-give-kudos__submit, .wb-gam-submit-achievement__submit, .wb-gam-recap__share-btn, .gam-nudge__action, .wb-gam-btn--primary, .wb-gam-share-card__cta-primary, .wb-gam-profile-privacy__toggle, .gam-lb-pill--active) {
	background-color: var(--wb-gam-pop-accent) !important;
	border-color: var(--wb-gam-pop-accent) !important;
	color: var(--wb-gam-pop-accent-fg) !important;
}
:is(.wb-gam-give-kudos__submit, .wb-gam-submit-achievement__submit, .wb-gam-recap__share-btn, .gam-nudge__action, .wb-gam-btn--primary, .wb-gam-share-card__cta-primary, .wb-gam-profile-privacy__toggle, .gam-lb-pill--active):is(:hover, :active):not(:disabled) {
	background-color: var(--wb-gam-pop-accent-hover) !important;
	border-color: var(--wb-gam-pop-accent-hover) !important;
}
/* Links inside a block that carries owner colours take the card's text colour, not the theme's link colour
 * (BuddyX dark paints #f5f5f5 links on a cream card, 1.1:1). Buttons and other classed controls keep their own. */
:is(.wb-gam-scheme-light, .wb-gam-scheme-dark) a:not([class*="btn"], [class*="__action"], [class*="__cta"], [class*="__login"]):is(:link, :visited) {
	/* !important: BuddyX styles content links at (0,5,1) (.entry-content a:not(...)x4), above anything a block can write. */
	color: var(--wb-gam-color-text) !important;
}
.wb-gam-scheme-light :is(h1, h2, h3, h4, h5, h6),
.wb-gam-scheme-dark :is(h1, h2, h3, h4, h5, h6) {
	color: inherit;
}
