--- name: theme-factory description: Builds a complete, consistent light and dark design theme from a description of a brand or product, delivered as CSS variables, a Tailwind config or a typed theme object. Use when a user says "create a theme for", "set up design tokens", "give me a dark mode that works", "clean up our colors", or has too many near-duplicate shades in a codebase. --- # Theme Factory Turns a short description ("rugged and high-contrast, readable outdoors") into a full token system: color roles, type, spacing, radius, shadow and motion, in both light and dark. ## When to use this - Starting a project and wanting the foundations settled once. - A codebase has drifted into many similar blues and an inverted-colors dark mode. - The user needs the same theme in more than one format. ## Procedure 1. **Ask five things**, then proceed on assumptions for anything unanswered: the product and audience, the feeling in three words, any fixed brand colors or fonts, the target format (CSS variables, Tailwind, or a JavaScript or TypeScript object), and where it will be used (phone outdoors, dim office, print). 2. **If auditing existing code,** list every distinct color value found, group near-duplicates, and propose which one each collapses into. Show the map before changing anything. 3. **Define the palette by role, not by name.** Neutral scale of ten steps, a primary scale, an accent, and success, warning and danger. Write roles as `surface`, `surface-raised`, `border`, `text`, `text-muted`, `primary`, `on-primary`, `accent`, `focus-ring`, and the status colors with their `on-` partners. 4. **Check contrast for every text pairing.** Body text and `on-` colors need 4.5 to 1; large text and interface outlines need 3 to 1. Adjust values until all pass, and record the ratios in a table. 5. **Design dark mode separately.** Do not invert. Use a dark surface that is not pure black, lower chroma on large colored areas, slightly lighter primaries, and shadows replaced or softened by lighter surfaces and borders. Re-run the contrast checks. 6. **Set the non-color tokens.** Type: families with fallbacks and a scale of six to eight sizes with line heights. Space: a 4-pixel base scale. Radius: three steps. Shadow: three levels. Motion: two durations and one easing, with a reduced-motion override. 7. **Emit the code in the requested format.** - CSS: `:root` for light, and a dark block applied both through `prefers-color-scheme` and a `data-theme` attribute so a manual toggle wins. - Tailwind: map colors to the CSS variables so one source of truth drives both modes. - Object: a typed light and dark pair with identical keys. 8. **Show it working.** Provide a tiny sample (heading, paragraph, button, input, card, alert) using only the tokens, so the user can see both modes at once. ## Output format - Short rationale (three sentences). - Token tables: color roles with light and dark values, contrast results, type scale, spacing, radius, shadow. - The code block(s) for the chosen format. - The sample snippet and a three-line migration note for replacing hard-coded values. ## Guardrails - Never ship a color pairing that fails the contrast check; fix it or flag it. - Every light token needs a dark counterpart with the same name. - Keep the token count small; if a role is used once, remove it. - Use fonts that have a stated fallback and mention licensing for paid ones. - Do not copy another company's published palette; derive values from the user's description. ## Quality checks Before sending, confirm each of these: - Every text and background pairing has a recorded ratio that meets the target. - Each light token has a dark twin with the same name and a sensible value. - The sample snippet uses only tokens, with no hard-coded colors. - Focus rings are visible against both surface colors in both modes. - Primary, accent and status colors are distinguishable without relying on hue alone. - The reduced-motion override is present if any transition is defined.