Dark mode

From egregore-labs/egregore · View interactive version

Dark mode is an AI agent skill from the GitHub repository egregore-labs/egregore. Use when authoring or modifying browser-rendered visual output: HTML, CSS, React SSR, artifact templates, markdown renderers, design tokens, themes, or composed pages. Do not invoke for an ordinary /view render—the checked-in renderer already owns its theme contract. The load-bearing rule is that th

How to use this skill

Skill file

Dark Mode

Voice Complex

This skill governs browser visual rendering: theme tokens and theme behavior. It carries no palette; every color comes from the design system.

Shared aesthetic: voice-bedrock (.claude/rules/voice-bedrock.md).

For pair routing, component profiles, or adding a pair: packages/design-system/skill/SKILL.md.

For terminal rendering: tui-design skill.

For product copy in rendered pages: product-voice skill.

For prose content in rendered pages: egregore-voice skill.

When to invoke

User says: "dark mode", "theme toggle", "color system", "card surface", "make this work in dark mode", or any request to generate or modify browser-rendered visual output (HTML, CSS, React SSR, Egregore artifacts, design tokens).

Not this:

owns and tests its theme contract

The rule

If a renderer emits style="color:#15212e", theming loses: CSS can re-theme a value only when the rendered value is itself a variable reference. Every theme-sensitive color, in a stylesheet or an inline style prop, is var(--token) at the render site.

Where colors come from

Highlights

No side stripes: a coloured bar down one side of a box is retired in every render. Mark reading emphasis with a marker under the words (.eg-mark), a label in the margin (.eg-margin holding an .eg-label) or a quote with a hanging opening mark (.eg-quote). Mark status with a quiet panel (.eg-panel) whose .eg-label carries the tone's shape (● ok, ◆ note, ▲ warn, ■ critical, ○ neutral), so the state reads without colour and in both themes. A selected item gets weight plus a filled shape, never a stripe. The classes are RECIPE_CSS in packages/egregore-artifacts/lib/recipe.js, which the kit's shell injects into every render; the design system skill has the full rule.

The theme contract

The kit's renderers set three attributes on <html>:

| Attribute | Value | Role |

|---|---|---|

| data-theme | resolved theme id, e.g. ledger or bedrock | the only CSS selector |

| data-theme-pair | pair id, e.g. sovereign | names the family; never a CSS selector |

| data-theme-mode | auto, light or dark | the reader's choice |

Anti-Patterns

| Pattern | Why It Breaks | Instead |

|---|---|---|

| style={{ color: palette.ink }} with a JS constant | SSR resolves the constant to a fixed hex, so the theme cannot override it | style={{ color: 'var(--ink)' }} or a class |

| background: white on cards | The card stays white in a dark theme | background: var(--card) |

| border: 1px solid rgba(0, 0, 0, 0.08) | A light-only value inside a themeable component | var(--line) or var(--line-soft) |

| [data-theme="dark"] overrides or .dark-* classes | Theme ids are names like bedrock, and role tokens already flip per resolved theme | Style with role tokens; add no per-mode overrides |

| Selecting on data-theme-pair | The pair names the family; it is not a selector | Use role tokens, or [data-theme="<theme id>"] when one theme needs its own rule |

| opacity: 0.5 on colored text | Contrast changes unpredictably between themes | var(--ink-soft) or var(--ink-faint) |

| @media (prefers-color-scheme: dark) as the only mechanism | No manual override and no persistence | The three-state mode above |

| Theme state on body or a wrapper div | Portals, overlays and shells fall out of sync | The three attributes on <html> |

| Restoring the saved mode after the page renders | A flash of the wrong theme | A blocking <head> script |

Context Modes

Pre-Ship Checklist

  1. No hex or resolved color constant in any render path that emits inline styles.
  2. Every var(--x) the page uses is defined for both members of its pair (for sovereign: ledger and bedrock).
  3. <html> carries all three attributes, and the mode is restored in <head> before paint.
  4. The toggle cycles light → auto → dark; the choice survives a reload where storage works, and nothing throws where it does not.
  5. Print and phone-width layouts still work.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.