On this page

← All documentation

theme.css

The validated CSS subset of a theme: how it is rewritten, how to reach the game's elements, plate variables, specificity, motion, images, limits and the full allow-list.

theme.css gives a look to the classes that your theme.ts creates. It is optional: a theme with no templates needs none. It is not ordinary CSS: Rust reads it, keeps only a validated subset, and rewrites it so that it can only affect your theme. A file that breaks a rule removes the whole theme from the list, with the line number in the message.

This page explains how to think about the subset. The exhaustive list of selectors, at-rules and properties is generated from the validator and always matches it.

What theme.css is for

Tokens set the palette, the fonts and the shapes of the whole game. theme.css is for what tokens cannot say: the layout of the boxes you add in a template, a gradient behind one of them, a border on the Play strip, a slanted card, a motion. Everything the game already draws keeps following your tokens; use theme.css to place and decorate your own classes and to adjust a few of the game's elements through their marks.

A template and its stylesheet go together. Every class a template uses must either be defined in theme.css (even a class that only names a box) or be a class the screen lists (song-select, pv-screen… the contracts reference lists them per screen). A class that is neither is refused, and a class that is both is ambiguous. A small stylesheet for the first layout:

/* The classes of theme.ts: two columns, the library first, the selected map second. */
.screen { display: flex; flex-direction: row; align-items: stretch; gap: var(--pv-s6); height: 100%; min-height: 0; }
.map { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; min-height: 0; }
.library { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; min-height: 0; }
.map > .details { display: flex; flex-direction: column; flex: 1 1 0; min-height: 0; overflow: hidden; }

/* The Play strip stays pinned above the heading; a hairline under it separates it from the map. */
.map > .play { border-bottom: 1px solid var(--pv-line); padding-bottom: var(--pv-s3); }

How it is rewritten

Before the page sees your file, the validator:

  • renames every class .name to .tpl-<id>-name (<id> is your theme's id), in the stylesheet and in the templates that use it;
  • places every selector under [data-direction="<id>"], so a rule can only apply while your theme is worn;
  • renames every @keyframes and the animations that use it the same way;
  • replaces each url("images/x.png") by the address the game serves that picture at.
/* what you write */
.play { border-bottom: 1px solid var(--pv-line); }

/* what the page receives (for a theme named "first-layout") */
[data-direction="first-layout"] .tpl-first-layout-play { border-bottom: 1px solid var(--pv-line); }

You never write the prefix yourself. Class names are lower-case letters, digits and hyphens, starting with a letter, 40 characters at most.

Selectors

  • A rule starts with one of your classes: .name. No element selector (div), no *, no #id, no :root, no body.
  • After the first compound selector you may use [data-state], [data-state="value"] (letters, digits, -, _ and ., 40 characters at most) and your classes. Attributes are data-<name> only, with = as the only operator.
  • States: :hover, :focus-visible, :focus-within, :active, :disabled, :first-child, :last-child. :not(…), :is(…) and :where(…) take your classes and these states, not nested.
  • Combinators: descendant (a space) and >. Lists separated by commas.
  • Pseudo-elements: ::before and ::after, once, at the end of a selector, with a content that is none, normal or one short string (80 characters at most, no \, no attr(), no counter). The text they draw is decoration that a screen reader may still read: never put information in it. Use them for arrows, rules and diamonds without adding a node.

Reaching the game's elements

The game draws most of the screen itself. You reach its elements by their data-* marks, never by their classes (the game's classes are not part of the contract and may change).

  • data-part: the named parts of a contract, such as [data-part='play'] on the Play button or [data-part='tablist'] on the tabs. The parts of each contract are in the contracts reference.
  • data-contract: the root of a component or a card, such as [data-contract='library.setCard']. The dot is allowed in a value so that you can name a contract.
  • State marks the game puts on its elements: [data-active] (the open or selected card), [data-selected], [data-state], [data-edge] (the accent edge of a plate), [data-entering] (the selection just settled).

Your selector must still start with one of your classes, so give an ancestor a class in your template and descend from it:

.bar [data-part='play'] { … }
.stage .deck [data-part='tablist'] { … }
.rack [data-contract='library.setCard'][data-active] { … }

The recipes in the cookbook do exactly this.

Variables

A rule may set only these custom properties; the validator refuses any other.

  • --tpl-* variables of your theme. A template node sets one with vars: { '--tpl-i': 3 }, and the stylesheet reads it with var(--tpl-i), for example inside a calc(). This is how data reaches the stylesheet: the equalizer recipe passes each bar's height as --tpl-live.
  • Plate variables of the design system: --plate and --edge (a colour or a gradient) and --clip and --clip-edge (a shape). A plate (.pv-plate, the map header, a card) paints its background and its edge with them, so a rule can redraw the plates of a region.
  • Design tokens --pv-* of the types colour, length, font, weight, opacity, easing, clip, filter, duration, shadow, ratio and case, with the same grammar as tokens.css. Set by a rule, a token applies to its subtree only.
  • Variables the game puts on its own elements can be read with var(): --set-color, --edge, --difficulty-color, --row-distance, --selection-color. The contracts reference lists those of each screen and contract.

What stays in tokens.css: layout words, images, the shade layers (--pv-shade), the map picture's filter (--pv-art-filter) and the colour scheme. The page reads them at the root.

/* A design token can be set by a rule: here the heading's rating is smaller. `--plate` is the variable plates paint their background with: transparent lets the picture show. */
.hero-main { display: flex; flex-direction: column; gap: var(--pv-s1); min-width: 0; --pv-fs-rating: clamp(44px, 4.2vw, 76px); --pv-plate-filter: none; }
.hero-main [data-edge] { --plate: transparent; --edge: linear-gradient(180deg, var(--difficulty-color), transparent); }

The first rule sets two tokens for the banner's subtree only. The second one redraws the plate of the title, so that the map's picture shows through.

Specificity against the game's components

A rule of yours is prefixed and scoped, but it may still be less specific than a rule of one of the game's components (.game .scroller button), and then the game wins. You cannot use !important. To win without it, repeat a mark so that your selector weighs more:

.tabs [data-part='tablist'] [data-part='tab'][data-part][data-tab] { … }

Do not try to target the game's classes (.bar-menu, .search-bar); adjust fine details with tokens set on the right subtree instead: --pv-line: transparent on [data-contract='library.search'] removes the hairlines of the search bar. The three menus of the search bar carry data-part="group", "sort" and "filter" so that a theme can dress all three alike.

Rules, properties and values

  • At-rules: @keyframes and @media only. @media accepts (min-width | max-width | min-height | max-height: <n>px) (a whole number from 1 to 10 000) and (prefers-reduced-motion: reduce | no-preference), at most two conditions joined by and. No at-rule inside @media.
  • Properties: an allow-list (layout, typography, colours, borders, shadows, clip-path, transforms, transitions, animations…) with typed values: lengths, colours, var(--pv-*), calc(), color-mix(), gradients. z-index is a whole number from -50 to 50. position is any value but fixed. filter takes blur, saturate, brightness, contrast, grayscale, sepia, hue-rotate and drop-shadow; backdrop-filter takes blur (0 to 64 px) and saturate (0 to 4), as written numbers. writing-mode sets vertical text; mask-image takes a gradient or a picture of images/ (with mask-size, mask-position, mask-repeat) for an edge that fades out.
  • Refused anywhere: !important, @import, @font-face (a theme's fonts are declared in theme.json, fonts), expression, a backslash escape, a url that is not url("images/…").
  • Every colour comes from a token in a well-made theme: var(--pv-text), var(--pv-line), var(--difficulty-color). A hard-coded colour will not follow a light variant or the player's accent.

Animation and motion

The central rule: no infinite animation on a screen at rest. An infinite loop repaints its area every frame even when nothing else moves; it was measured at about three CPU cores for fifteen equalizer bars and two glows on an idle menu. The validator accepts infinite but warns ("<id>": theme.css: warning: line N: an infinite animation repaints the page every frame…). See concepts for the reasoning.

So decorative motion plays once per selection:

  • hang it on [data-entering] (put data: { entering: c.bind('selection.entering') } on the node so it carries the attribute), with a finite iteration count; or on :hover and :focus-visible;
  • wrap every moving animation and transition in @media (prefers-reduced-motion: no-preference). The game's own motion stops under reduced motion, yours does not unless you wrap it (concepts);
  • move with transform and opacity, not with width, height or top, which lay the page out again each frame;
  • do not put a transition on elements that update many times a second, such as the live bars.

A rule of the equalizer recipe that follows all of this:

/* A bar is always full height and is SCALED: `transform` does not lay the page out again, where `height` would, thirty times a second. `--tpl-live` runs from 4 to 100.
   There is NO `transition` here: the page has already eased the levels, and a transition makes the browser restyle every bar on every frame for nothing the eye can see. */
.eq-bar {
  flex: 1 1 0;
  min-width: 2px;
  height: 100%;
  opacity: .75;
  transform-origin: bottom;
  transform: scaleY(calc(var(--tpl-live) / 100));
  background: linear-gradient(180deg, var(--pv-accent), color-mix(in srgb, var(--pv-accent) 20%, transparent));
}

An @keyframes may have 24 steps at most, and an animation must name a @keyframes of the same file.

filter, box-shadow and clip-path

A filter or a box-shadow set on the same element as a clip-path is cut by that clip-path: the shadow lies outside the shape, so it disappears. To get a shadow that follows a cut shape, put filter: drop-shadow(…) on a parent of the clipped element, and the clip-path on the child:

.tile-shadow { filter: drop-shadow(0 4px 8px rgb(0 0 0 / .5)); }
.tile { clip-path: polygon(16px 0, 100% 0, 100% 100%, 0 100%); }

In the template, .tile-shadow is a box that holds the .tile box. The same applies to the game's plates: they are cut shapes, which is why their depth is the token --pv-plate-filter (a drop-shadow) and not a box shadow.

Images

A picture is url("images/x.png"), and only that: a file of your folder's images/ (png, jpg, jpeg, webp, gif or svg, 4 MiB at most). No remote address, no data:. A path that does not exist, leaves the folder or is not a picture is refused. A template names the same files with an image node (c.image('images/x.png', { alt: '' })), and a token with image("images/x.png").

The map's own picture is not one of yours: a template reads its path with c.bind('map.background') into an image node, as the hero-banner recipe does.

Limits

Limit Value
File size 256 KiB
Rules 2048
Declarations in one rule 40
Steps in one @keyframes 24
Length of a content string 80 characters
z-index -50 to 50
Images 4 MiB each, 512 files, 4 levels

A file over a limit or outside the subset removes the theme from the list, with the line number in the message ("<id>": theme.css: line N: …). Fix the file and use Reload themes.

The exhaustive list

This part is generated from the validator in crates/themes/src/stylesheet.rs. It is also available alone as the CSS allow-list.

  • Limits: file <= 256 KiB; <= 2048 rules (style rules + keyframe steps); <= 40 declarations per rule; <= 200 words/numbers per value; functions nest <= 5; strings <= 80 chars (no \); class, keyframes name <= 40 chars (a-z 0-9 -, start with a letter); data-name <= 24, data value <= 40; no !important, no nesting, comments allowed.
  • Selectors: .class first (compound .a.b), [data-x], [data-x="v"]; :hover :focus-visible :focus-within :active :disabled :first-child :last-child; :not(.a) :is(.a) :where(.a) (classes only, not nested); ::before ::after (once, last, with content); combinators: descendant, >; comma lists. Refused: elements, *, #id, +, ~, &.
  • At-rules: @keyframes @media only. @media (<feature>: <value>) <= 2 joined by and; features max-width min-width max-height min-height prefers-reduced-motion (px 1..10000; reduced-motion reduce|no-preference); style rules only inside. @keyframes name steps from|to|n%, <= 24; every animation name must be defined in the file.
  • Values: length px|em|rem|vw|vh|vmin|vmax|ch or 0 (|n| <= 10000); % (<= 10000); number (<= 100000); angle deg|turn|rad (<= 3600); time s|ms (<= 60000); fr (<= 1000); "string"; colour #rgb|#rgba|#rrggbb|#rrggbbaa; url("images/<file>") of a picture the theme has; plain words are accepted unless the property is a closed list; var(--x[, fallback]) anywhere.
  • Properties (any other property is refused; * = every property with that prefix): length: letter-spacing word-spacing; length+color: box-shadow text-shadow; length+number+color: outline, outline-; length+percentage: background- bottom column-gap flex-basis gap height inset left margin, margin-* mask-position mask-size max-height max-width min-height min-width object-position padding, padding-* right row-gap top transform-origin width; length+percentage+number: flex font-* line-height; length+percentage+number+color: border, border-* (except border-image*) text-; length+percentage+number+color+angle+url+gradient: background; length+percentage+number+fraction+string+grid: grid, grid-; length+percentage+number+string: font; percentage+number: opacity; number: aspect-ratio flex-grow flex-shrink order; number+time+easing: animation-* transition, transition-; color: background-color color; string: content font-family; url+gradient: background-image mask-image; transform: transform; filter+backdrop: filter; backdrop: backdrop-filter; shape: clip-path; words: align- flex-direction flex-flow flex-wrap justify-* overflow-wrap place-* white-space word-break.
  • Closed words: cursor: auto|default|pointer|text|move|not-allowed|grab|grabbing|wait|help|crosshair|progress|zoom-in|zoom-out|none; display: flex|grid|block|none|inline-flex|inline-block|inline|inline-grid|contents; mask-repeat: repeat|no-repeat|repeat-x|repeat-y|round|space; mix-blend-mode: normal|multiply|screen|overlay|darken|lighten|color-dodge|color-burn|hard-light|soft-light|difference|exclusion|hue|saturation|color|luminosity|plus-lighter; object-fit: fill|contain|cover|none|scale-down; overflow: visible|hidden|auto|scroll|clip; overflow-x: visible|hidden|auto|scroll|clip; overflow-y: visible|hidden|auto|scroll|clip; pointer-events: auto|none; position: static|relative|absolute|sticky; visibility: visible|hidden|collapse; writing-mode: horizontal-tb|vertical-rl|vertical-lr|sideways-rl|sideways-lr; z-index: integer -50..50|auto; content: string (no attr(), counters).
  • Functions: backdrop: blur saturate; color: rgb rgba hsl hsla hwb color-mix; easing: cubic-bezier steps; filter: blur brightness contrast drop-shadow grayscale hue-rotate saturate sepia; gradient: linear-gradient repeating-linear-gradient radial-gradient repeating-radial-gradient conic-gradient repeating-conic-gradient; grid: repeat minmax fit-content; math: calc min max clamp var; shape: polygon inset; transform: translate translatex translatey translatez translate3d scale scalex scaley scale3d rotate rotatex rotatey rotatez skew skewx skewy.
  • Variables: --tpl-<name> (<= 32 chars, any value); design tokens of kind case|clip|color|duration|easing|filter|font|length|opacity|ratio|shadow|weight (subtree only; the other kinds and --pv-art-filter stay in tokens.css); plate variables --plate --edge --clip --clip-edge. Class names become .tpl-<id>-name and every rule is scoped under [data-direction="<id>"].

Source in the game repository: docs/themes.md,crates/themes/src/stylesheet.rs,crates/themes/src/library.rs,apps/web/src/theme/tokens.css,apps/web/src/menu/settled.ts