For developers

3. Themes

From the THINQ Site developer guide, in the guide's own words. The same text ships with every site's core.

A theme is a set of CSS custom properties (tokens) plus a small options schema the admin can change. Core's blocks, header and footer all read their colours from those tokens, so a theme restyles the whole public site without touching a component. The admin has its own fixed look and is not affected by your theme.

3.1 Where it lives and how it is picked

  • Write it at src/themes/<your-theme>/index.ts, exporting a ThemeDefinition.
  • Register it in src/themes/index.ts (your copy of core's registry).
  • An admin picks it in Appearance → Theme. The choice and its options are stored in content/theme.json:
{ "themeId": "encore", "options": { "palette": "stage", "headingScale": "md" } }

To make your theme the default for a fresh deployment, set themeId in your repo's content/theme.json.

3.2 The ThemeDefinition

From core/src/framework/theme.ts:

type ThemeDefinition = {
  id: string;                                   // stored in theme.json
  name: string;                                 // shown in Appearance
  description: string;                          // one line under the name
  tokens: Record<string, string>;               // base token map
  optionsSchema: z.ZodObject<z.ZodRawShape>;    // what the admin can change
  defaultOptions: Record<string, unknown>;
  resolveTokens(options: Record<string, unknown>): Record<string, string>;
};

A complete theme:

// src/themes/encore/index.ts
import { z } from "zod";
import type { ThemeDefinition } from "@/framework/theme";

const optionsSchema = z.object({
  palette: z.enum(["stage", "studio"]),
  headingScale: z.enum(["sm", "md", "lg"]),
});

const PALETTES = {
  stage:  { "--sunset-1": "#b3124e", "--sunset-2": "#6a2c91", "--sunset-3": "#f2a900" },
  studio: { "--sunset-1": "#0f6e8c", "--sunset-2": "#e4572e", "--sunset-3": "#76b041" },
} as const;

const HEADING_SCALES = { sm: "0.92", md: "1", lg: "1.1" } as const;

const tokens: Record<string, string> = {
  "--ink": "#ffffff",            // page background (this is a light theme)
  "--ink-soft": "#f6f3f8",       // raised surfaces: cards, panels
  "--cream": "#1c1424",          // body text
  "--cream-dim": "#5e5566",      // secondary text
  "--sunset-1": "#b3124e",       // accent ramp, light end
  "--sunset-2": "#6a2c91",       // primary accent: buttons, links
  "--sunset-3": "#f2a900",       // accent ramp, far end
  "--line": "rgba(28, 20, 36, 0.12)",   // hairlines and borders
  "--grain-opacity": "0",        // the film-grain overlay; 0 turns it off
  "--heading-scale": "1",        // scales the root font size

  // Your own extras (§3.4)
  "--encore-magenta": "#b3124e",
  "--encore-teal": "#0e6f8c",
};

export const encoreTheme: ThemeDefinition = {
  id: "encore",
  name: "Encore",
  description: "Encore Performing Arts.",
  tokens,
  optionsSchema,
  defaultOptions: { palette: "stage", headingScale: "md" },
  resolveTokens(options) {
    const o = optionsSchema.parse({ ...this.defaultOptions, ...options });
    return { ...this.tokens, ...PALETTES[o.palette], "--heading-scale": HEADING_SCALES[o.headingScale] };
  },
};
// src/themes/index.ts: add yours to the list, leave the rest of the file alone
import { encoreTheme } from "./encore";
export const themes: ThemeDefinition[] = [retrofuturistTheme, daylightTheme, encoreTheme];

The root layout calls resolveTokens on the server and writes every token it returns as an inline style on <html>, so every token is available everywhere on the page as var(--name).

3.3 The core tokens are carriers, not descriptions

Token What it carries Tailwind class
--ink The page background bg-ink, text-ink
--ink-soft Raised surfaces bg-ink-soft
--cream Primary text text-cream
--cream-dim Secondary text text-cream-dim
--sunset-1 / -2 / -3 The accent ramp, used for gradients, links and buttons text-sunset-2, bg-sunset-1, …
--line Borders and dividers border-[var(--line)]
--on-accent Readable text colour on an accent background (computed) text-[var(--on-accent)]
--grain-opacity Film-grain overlay strength (none)
--heading-scale Multiplies the root font size (none)
--font-display / --font-mono Body and monospace font families (§3.6) font-sans, font-mono

The names are historical: the first theme was a dark "retro-futurist" one, so the background is --ink and the text is --cream. In a white theme --ink is white. Around a hundred core components use these names, so keep the names and change the values, and write a comment next to each saying what it is in your design.

3.4 More colours than the core set

Add as many of your own tokens as the design needs. Prefix them with your site's name so they can never collide with a future core token:

"--encore-magenta": "#b3124e",
"--encore-violet": "#6a2c91",

Then use them in your components:

<section className="bg-[var(--encore-teal)] text-white">…</section>
<span style={{ color: "var(--encore-magenta)" }}>…</span>

Core blocks won't use your extra tokens; they only know the core set. To change how a core block looks, change the core tokens (or see Blocks §4.11).

3.5 The brand colour setting

Settings → Brand color in the admin lets an operator set one hex colour. When it is set, it is laid over the theme's accent at render time:

Token Value
--sunset-2 The brand colour, exactly
--sunset-1 A lighter, slightly warmer step derived from it
--sunset-3 A step shifted round the colour wheel
--on-accent Dark or white, from the brand colour's luminance

So brand colour always wins over your theme's --sunset-* values when it is set. If your design's accents must not be operator-changeable, use your own tokens (§3.4) for them, and leave the brand colour empty or set it to the design's primary accent.

When resolveTokens alone is used, the brand colour is ignored. Core's layout uses resolveSiteTokens (theme plus brand colour). Anything of yours that needs the resolved tokens on the server should use that too.

3.6 Fonts

Load fonts in your theme with Next's font loader, and point --font-display at them. next/font downloads the files when the site builds and serves them from the site itself, so there is no request to Google from a visitor's browser and nothing to add to the security policy.

Google Fonts:

// src/themes/encore/index.ts
import { Poppins } from "next/font/google";

const poppins = Poppins({ subsets: ["latin"], weight: ["400", "600", "800"], display: "swap" });

const tokens: Record<string, string> = {
  // … the rest of your tokens …
  "--font-display": poppins.style.fontFamily,   // the site's main font
};

Your own font files (a licensed typeface, for example): put them next to the theme and use next/font/local:

import localFont from "next/font/local";

const brand = localFont({
  src: [
    { path: "./fonts/Brand-Regular.woff2", weight: "400", style: "normal" },
    { path: "./fonts/Brand-Bold.woff2", weight: "700", style: "normal" },
  ],
  display: "swap",
});

// "--font-display": brand.style.fontFamily,

A separate heading font: give it its own token and use it where you want it:

const display = Anton({ subsets: ["latin"], weight: "400" });
// tokens:
"--font-display": poppins.style.fontFamily,
"--encore-heading": display.style.fontFamily,
<h2 className="[font-family:var(--encore-heading)] text-5xl uppercase">…</h2>

How it works: the loader call must be at the top level of a module (not inside a function). Because the theme file is imported by the root layout, the font's @font-face rules and preload links are included on every page. --font-display set by your theme replaces core's default (Space Grotesk), because theme tokens are written on <html> itself. The body, and Tailwind's font-sans, use var(--font-display).

Verified on 2026-10-21 in a production build of the Encore site with Poppins: the body and headings computed to Poppins, "Poppins Fallback", and the 400, 600 and 800 weights were preloaded from the site's own /_next/static/media/.

This needs core from 2026-10-21 or later. Before then, a theme that called next/font built fine but failed npm test (Poppins is not a function), because the test runner loads the theme outside Next. Since the tests are a cascade gate, that would have stopped core updates reaching the site. The test runner now stubs next/font; with it, all 274 tests passed on the Encore site with Poppins loaded.

Tips:

  • Only load the weights you use. Each one is a file a visitor downloads.
  • Variable fonts (most Google Fonts) need no weight list.
  • A <link> to fonts.googleapis.com pasted into Settings → Custom code → Head also works (styles and fonts from any https host are allowed), but it adds a request to Google on every page view and can't be preloaded. Prefer next/font.

3.7 Styling: Tailwind and CSS

  • Tailwind v4 is available in every component. Core's tokens are registered as Tailwind colours (bg-ink, text-cream, text-sunset-2), and arbitrary values work for anything else (bg-[var(--encore-teal)], min-w-57.5).

  • Tailwind scans the assembled source for class names, so a class only exists if it appears as a complete string in the code. Build class names from complete strings:

    // works
    const accent = { tour: "text-[var(--encore-orange)]", nationals: "text-[var(--encore-violet)]" };
    // does not: Tailwind never sees "text-[var(--encore-orange)]"
    const cls = `text-[var(--encore-${color})]`;
    
  • Four class names are deliberately never generated, because migrated WordPress markup uses them to mean something else: container, table, size-full, w-100. Use mx-auto max-w-6xl, grid/flex, size-[100%] or w-full instead.

  • Your own stylesheet. For styles that are easier as CSS than as classes (keyframes, [data-nav] rules, vendor-widget overrides), put a CSS file in your feature and import it from your header component:

    // src/features/encore/Header.tsx
    "use client";
    import "./encore.css";
    

    It is bundled and loaded on every page. Verified on 2026-10-21 in a production build of the Encore site. It is also loaded in the admin (the admin loads your feature to preview your blocks), so scope every rule to your own classes or attributes (.encore-…, [data-nav="tour"], header.encore-header a) and never style bare elements (h1, a, body). An unscoped rule restyles the admin too.

  • globals.css is core's and holds both the site's base styles and the admin's look. Don't replace it (see §2.5).

3.8 Checklist

  • Theme file at src/themes/<yours>/index.ts, registered in src/themes/index.ts
  • Every core token given a value, with a comment saying what it is in your design
  • Extra colours prefixed with your site name
  • Fonts loaded with next/font, --font-display set
  • content/theme.json points at your theme
  • Checked with the brand colour both empty and set
  • Checked a light theme's text contrast on --ink-soft panels, not just the page

This text is maintained in thinq-site-core at docs/developers/03-themes.md (commit e72488e) and published here unchanged.