Skip to content

Dark/Light mode toggle #12

@Empreiteiro

Description

@Empreiteiro

Description

Add a theme toggle allowing users to switch between dark mode (current default) and a light mode variant.

Details

  • Toggle button: Sun/moon icon in the header, next to the "+ New Battle" button
  • Persistence: Save preference in localStorage, default to system preference (prefers-color-scheme)
  • Theme implementation: Use CSS custom properties (already defined in @theme block in index.css) with two sets of values
  • Light mode color scheme:
    • Background: #ffffff#f6f8fa (GitHub-style light bg)
    • Cards: #ffffff with subtle border
    • Text: #1f2328 (primary), #656d76 (muted)
    • Borders: #d0d7de
    • Territory grid: Lighter neutral cells, same participant colors but on white background
    • Pixel font and accent colors remain the same for brand consistency

Implementation Approach

  1. Add a ThemeProvider context wrapping the app
  2. Toggle adds/removes a data-theme="light" attribute on <html>
  3. CSS variables swap based on [data-theme="light"] selector
  4. All existing bg-dark-*, text-dark-*, border-dark-* classes reference the CSS variables, so they auto-switch
  5. Canvas rendering in TerritoryArena reads theme context to adjust background/border colors

Acceptance Criteria

  • Toggle button in header switches between dark and light mode
  • Preference persisted in localStorage
  • Defaults to system preference on first visit
  • All pages render correctly in both modes
  • Territory grid canvas adapts to light background
  • Pixel font and accent colors remain consistent
  • No flash of wrong theme on page load

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions