Tokens and Styling

The product’s player surfaces read the tokens through the generated bridge; the sample-tokens and sample-light samples recolour them.

A token is a CSS custom property a theme sets. App tokens are --th-<name>; table tokens are --tbl-<name>. Token names are a semver API: a theme built against one contract version keeps working against a compatible one.

Token names

The contract defines 32 app tokens and 21 table tokens, each with a kind and the product’s current value as its default (APP_TOKENS and TABLE_TOKENS in src/themes/tokens.ts, exported as tokens.json by npm run themes:export-contract).

GroupTokens
Surfaces and text--th-bg, --th-surface, --th-surface-raised, --th-surface-hover, --th-border, --th-text, --th-muted, --th-subtle
Accent and status--th-accent, --th-accent-soft, --th-accent-ink, --th-success, --th-warning, --th-danger, --th-danger-soft, --th-focus
Type--th-font-body, --th-font-display, --th-font-mono
Shape and space--th-radius, --th-radius-lg, --th-radius-button, --th-shadow, --th-space-page, --th-page-max, --th-header-height, --th-sidebar-width, --th-row-padding, --th-motion, --th-hero, --th-layer-header, --th-layer-menu
Table--tbl-felt, --tbl-felt-edge, --tbl-felt-line, --tbl-rail, --tbl-bar, --tbl-card-face, --tbl-card-ink, --tbl-suit-red, --tbl-suit-club, --tbl-suit-diamond, --tbl-card-back, --tbl-pot-bg, --tbl-seat-bg, --tbl-seat-active, --tbl-seat-winner, --tbl-timer, --tbl-timer-warning, --tbl-chip, --tbl-dealer-button, --tbl-font, --tbl-radius

A theme sets them in tokens.json, named by the manifest’s tokens field. It may be sparse; unset tokens keep their defaults. Two of the five values sample-tokens sets:

{ "--th-accent": "#0d9488", "--tbl-felt": "#7f1d1d" }

Values must match the token’s kind: a colour, length, number, font stack, shadow, duration or package-relative path (tokens.value). An unknown name is a warning (tokens.unknown).

A path token (--th-hero, --tbl-card-back) names a file in the package, as url(assets/back.svg) or assets/back.svg, or is none. The token sheet below is served from the API, so the server rewrites each path to the package’s public URL (url("/themes/<slug>/<version>/assets/back.svg")) before it puts the token on :root.

How tokens reach the page

GET /api/v1/config/theme.css is linked from every page. It puts the active theme’s merged tokens (parent first, child winning) on :root inside @layer pe-tokens, and appends the operator’s custom CSS (unlayered, so it wins over both layers). The theme’s own dist/theme.css is added when the theme loads.

Layer order. Every page uses @layer theme, base, components, utilities, pe-tokens, pe-theme;: Tailwind’s layers (the product’s own stylesheet, first in the page), then the tokens, then the theme. The token sheet declares this order, the runtime inserts the theme’s stylesheet right after the token sheet, and every built theme sheet restates the same order. A rule in your stylesheet therefore wins over your tokens.json value for the same property on the same element, including on :root. That is how a theme sets scheme-dependent tokens (:root[data-theme="<slug>"][data-color-scheme="dark"] { --th-bg: … }) or tokens that follow a setting (:root[data-theme="<slug>"][data-th-setting-corners="square"] { --th-radius: 0 }), and they reach the product’s own pages and the standard table too. Themes built before this order was fixed open with @layer theme, base, components, utilities, pe-theme;; because their sheet now comes after the token sheet, pe-tokens still lands before pe-theme for them.

Open pages follow changes without a reload: on appearance_updated (activation, rollback, saved settings, tokens or custom CSS, a change to the players’ theme choice) the runtime re-reads the token sheet, swapping in the new one only once it has loaded, and re-resolves the theme, so parts, views, token values and custom CSS all update live.

Where tokens apply

Tokens apply to the player, agent and table surfaces. Each layout root carries data-surface="player|agent|admin|table".

The admin panel is pinned. While the admin panel is mounted, data-surface="admin" on the document sets every token to the admin’s own values, so operator tokens never reach the back office or overlays rendered over it. The admin has its own colour scheme, light by default, with a dark option each admin can switch to (it is remembered per browser and is independent of the site theme and the player colour scheme). A theme cannot restyle the admin panel.

How the product’s own styles follow tokens

The product’s components use Tailwind palette classes. A generated bridge (client/src/core/theme/bridge.css, from npm run themes:bridge) maps each palette shade in use to a token with the exact default as its fallback, so a theme that sets --th-accent recolours every player surface without the product’s components changing.

Two limits of the bridge matter to theme authors:

  • One utility serves more than one role. White text is used both for headings and for text on accent buttons, and one gray is used both as a background and as a border.
  • A light colour scheme therefore needs care. The role tokens recolour the page, cards and raised surfaces (--th-bg, --th-surface, --th-surface-raised), primary and secondary text (--th-text, --th-muted) and the accent; the page background and the text colour that plugin cards inherit follow --th-bg and --th-text too. Other shades (gray-200 and gray-300 body text, gray-500 hints, gray-600 control borders, white headings, the 300 and 400 status shades) keep their dark-scheme values unless the theme maps them: sample-light does that in its stylesheet with per-shade custom properties on its own root, :root[data-theme='sample-light'] { --th-gray-300: #334155; --th-white: #0f172a; … }. Mapping white to a dark colour also darkens text on accent fills that still use text-white instead of text-on-accent; check those with a contrast checker. A theme that wants finer control styles its own parts and views.

The standard table layout does not read --tbl-* directly; it has its own custom properties (--table-felt, --table-rail). A table skin maps the table tokens onto them; see Table Layouts and the Gameplay Boundary.

Theme stylesheets

  • The build writes dist/theme.css opening with @layer theme, base, components, utilities, pe-tokens, pe-theme; and wraps the theme’s rules in @layer pe-theme { … }. pe-theme is the last layer, so theme rules win over the product’s layered styles and the token sheet on equal specificity. A theme must not declare any other layer (css.layer): the order statement may name pe-tokens, but the only layer block allowed is pe-theme. Tailwind’s own layers are flattened into it.
  • Scope every rule with [data-theme="<slug>"]. The product sets data-theme on <html> to the active, resolved theme: the site theme, an admin’s preview or a player’s own choice, default when no theme is active or after a theme failed. It changes live when the theme changes, without a reload, so [data-theme="<slug>"] .my-class applies exactly while your theme is active. Putting data-theme="<slug>" on the root of each part, view and section as well ([data-theme="<slug>"].my-class) keeps a rule tied to your own markup. A child theme’s parts sit under its own slug, not its parent’s. No product rule matches data-theme, so default renders exactly as before. The one exception is a skin of the standard layout, which is scoped to the DOM contract ([data-pe="table"]).
  • Unlayered product styles (the standard layout’s defaults on its own nodes) beat any layered rule. Style a node’s children, or set the custom property the node reads, rather than fighting the node itself.
  • A theme may use Tailwind 4 utilities: import tailwindcss/theme.css and tailwindcss/utilities.css with prefix(<letters of the slug>), never tailwindcss itself, which carries preflight. The build rejects the unprefixed or preflight form, so a theme never resets the product’s base styles.
  • The validator rejects @import in the built sheet, non-relative url(), expression(), !important on contract nodes, and hiding a contract node. The build inlines relative @imports of your own files before that check. See Validation and Scanner Rules.
  • Prefer logical properties (padding-inline, margin-block-end); theme lint-rtl flags physical ones.

Fonts

Fonts are self-hosted: woff2 files with a licence text per family, latin and latin-ext subsets, font-display: swap. The content security policy blocks fonts from third parties and inline data: fonts. npm run theme -- fonts <dir> --family <id> copies an installed @fontsource/<id> family into fonts/<id>/ with its licence, writes src/styles/fonts.css and records it in theme.json. Refer to font files with root-relative URLs (url(/fonts/inter/inter-latin-400-normal.woff2)); the build checks they exist. No theme may reference fonts.googleapis.com (package.google-fonts).

Colour schemes

A theme declares the schemes it supports in colorSchemes (dark, light); the first is its own (default) scheme. There is no manifest field for "follow the device": that is the operator’s choice. A theme that declares none gets the operator’s Scheme for themes that declare none (defaultColorScheme).

The scheme a page shows is decided by the host, in this order:

  1. The player’s own choice, while the operator lets players choose (allowUserThemeChoice; the Player theme choice panel in Appearance): dark, light, or match the device, within the schemes the theme declares.
  2. The operator’s Default colour scheme (colorSchemeSource) for guests and players without a choice: Theme default (theme, the default) shows the theme’s first scheme; Follow the device (device) shows the scheme prefers-color-scheme asks for when the theme declares both, and switches live when the device changes.
  3. Otherwise the theme’s first scheme. A theme that declares one scheme always keeps it.

The host puts the result on the root as data-color-scheme="dark|light" (and the dark class for the product’s own Tailwind pages), and useColorScheme() returns it and re-renders when it changes. The attribute is set before the first paint on a reload (a small blocking script reads the scheme the runtime cached on the previous visit, following the device again when that is the rule), so a page does not flash the other scheme. A theme that supports both schemes styles them with [data-color-scheme="light"][data-theme="<slug>"] … (both attributes are on <html>), or [data-color-scheme="light"] [data-theme="<slug>"].my-class for markup that carries its own data-theme. Do not read prefers-color-scheme in theme CSS: the attribute already carries the device’s scheme when that is the rule, and a media query would override a player’s explicit choice.

Scheme-dependent contract tokens go on the root, in your stylesheet: keep the default scheme’s values in tokens.json and override the others with :root[data-theme="<slug>"][data-color-scheme="dark"] { --th-bg: …; }. The layer order above makes these win over the token sheet, so the product’s own pages follow the scheme too.

To try schemes and the player’s choice without a host, theme dev takes --scheme light|dark|system and --player-choice (see Building and Packaging › dev).

Table tokens and precedence

For the table surface, values resolve in this order, later winning: layout defaults → the active theme’s --tbl-* tokens → the table skin’s tokens → the player’s own preferences. See Table Layouts and the Gameplay Boundary.

Operator custom CSS

Operators add custom CSS in Site & Content › Customise. It is checked with the same CSS rules as a theme stylesheet, served at the end of the token sheet while appearance is enabled, and, like tokens, appears after a reload.

Try the live demo Pricing

Have questions about Poker Engine? We reply fast.