# Theme and Palette System

> Reusable visual-system specification for the MrJuaumBR ecosystem and future web projects. The filename intentionally preserves the project's existing spelling, `theme-pallete.md`. In prose, use **palette**.

## 1. Purpose and non-negotiable outcome

Use one implementation contract for the portfolio, project microsites, tools, dashboards, games, and future related sites, while allowing each site to develop its own skin catalog and visual world. The main website owns its catalog of skins; a microsite may have a completely different skin, artwork, and default treatment. Share semantic token roles, interaction conventions, accessibility, and responsive behavior—not necessarily the same skins, palettes, or backgrounds.

Every interface must support:

- a **skin**: the visual identity or product world; use the main website's catalog only on that site, and let other sites define skins suited to their own product;

- an **appearance mode**: dark or light;

- a **palette**: the accent combination selected within that skin and mode;

- optional **effect preferences**: animated borders, particles, seasonal effects, background motion, and other non-essential decoration.

These are separate concepts. Do not encode a whole theme as one unstructured color class, and do not make a palette responsible for changing layout, typography, or component behavior.

## 2. State model

Represent the active visual state as a serializable object:

```
{
  skin: 'default',
  mode: 'dark',
  palette: 'a',
  effects: {
    animatedBorder: true,
    backgroundMotion: true
  }
}
```

The minimum valid state is:

```
{ skin: 'default', mode: 'dark', palette: 'a' }
```

Use allowlists for `skin`, `mode`, and `palette`. If persisted data is missing, malformed, or points to an unknown option, fall back to the default state rather than trusting arbitrary class names or CSS values. Never place unsanitized user-controlled values into a class name, selector, CSS property name, or HTML fragment.

The main website already demonstrates the intended separation:

- `skin-*` classes select a visual world;

- `theme-dark` and `theme-light` select the appearance mode;

- `palette-a` through `palette-d` select the accent option;

- `localStorage` persists the choice;

- each skin can remember its own mode and palette selection.

Future projects should preserve this separation with a project-specific skin allowlist and a namespaced storage key, so settings do not accidentally overwrite another site's preferences. Consolidate state into one small theme controller where practical.

## 3. Naming contract

Use these names consistently across HTML, CSS, JavaScript, documentation, and stored state:

| Concept | Recommended class/state key | Meaning |
| --- | --- | --- |
| Skin | `skin-default`, `skin-cyberpunk` | Product or art direction; may alter shape, typography, density, and decoration |
| Appearance | `theme-dark`, `theme-light` | Surface, text, border, shadow, and background contrast system |
| Palette | `palette-a`, `palette-b` | Accent family inside the selected skin and appearance |
| Primary action | `--color-primary` | Main interactive/action color |
| Primary emphasis | `--color-primary-strong` | High-contrast hover, selected, or active state |
| Secondary accent | `--color-accent` | Supporting highlight, icon, badge, or decorative emphasis |
| Page background | `--color-bg` | Lowest-level page background |
| Surface | `--color-surface` | Card, panel, input, dropdown, or modal surface |
| Text | `--color-text` | Main readable text |
| Muted text | `--color-text-muted` | Secondary text; must remain readable |
| Border | `--color-border` | Dividers and component boundaries |

The existing site uses names such as `--bg-dark`, `--surface`, `--text`, `--text-muted`, `--primary`, and `--primary-light`. Treat those as legacy aliases during migration, but use the semantic `--color-*` vocabulary for new projects. A compatibility layer may map old names to new tokens:

```css
:root {
  --bg-dark: var(--color-bg);
  --surface: var(--color-surface);
  --text: var(--color-text);
  --text-muted: var(--color-text-muted);
  --border: var(--color-border);
  --primary: var(--color-primary);
  --primary-light: var(--color-primary-strong);
  --accent: var(--color-accent);
}
```

## 4. Token architecture

### 4.1 Global, mode, skin, and palette layers

Keep tokens layered so a new skin does not require duplicating every component rule.

1. **Global tokens** define typography, spacing, radii, z-index layers, motion durations, and layout limits.

1. **Mode tokens** define dark/light contrast and surface relationships.

1. **Skin tokens** define the identity-specific visual treatment.

1. **Palette tokens** define the accent colors for the active skin and mode.

1. **Component tokens** define local adjustments and should consume semantic tokens rather than raw colors.

Example structure:

```css
:root {
  --font-sans: Inter, system-ui, sans-serif;
  --font-display: inherit;
  --radius-sm: .375rem;
  --radius-md: .75rem;
  --radius-lg: 1rem;
  --space-1: .25rem;
  --space-2: .5rem;
  --space-3: .75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --content-max: 82rem;
  --motion-fast: 160ms;
  --motion-normal: 240ms;
  --motion-slow: 500ms;
}

body.theme-dark {
  --color-bg: #0b0c10;
  --color-surface: #1f2833;
  --color-surface-raised: #273344;
  --color-text: #e0e0e0;
  --color-text-muted: #a0a0a0;
  --color-border: #2c3e50;
  --color-header: rgb(11 12 16 / 95%);
  --color-shadow: 0 8px 20px rgb(0 0 0 / 50%);
}

body.theme-light {
  --color-bg: #f5f5f7;
  --color-surface: #fff;
  --color-surface-raised: #fff;
  --color-text: #1e1e2f;
  --color-text-muted: #4a4a5a;
  --color-border: #d1d5db;
  --color-header: rgb(255 255 255 / 95%);
  --color-shadow: 0 8px 20px rgb(0 0 0 / 10%);
}
```

Use the same semantic token names in every project. A skin may override values or add identity tokens, but must not make a component depend on skin-specific names such as `--cyberpunk-blue`.

### 4.2 Required contrast roles

Every skin/mode/palette combination must provide at least:

- page background;

- normal surface;

- raised surface/dropdown/modal surface;

- main text;

- muted text;

- border/divider;

- primary action;

- primary strong/hover;

- accent;

- focus indicator;

- success, warning, danger, and informational status colors.

Do not assume the accent is readable on every surface. Define foreground and background pairs where necessary, for example `--color-primary-text` for text placed on a primary-colored button.

### 4.3 Palette definition

A palette is a small semantic definition, not a random list of hex values. Each palette should have a clear name, purpose, swatch, and values for both dark and light mode. A palette may change its values by mode to preserve contrast, but its identity should remain recognizable.

```
const paletteDefinitions = {
  default: {
    dark: [
      { key: 'a', name: 'Amethyst', swatch: '#8b5cf6', primary: '#7b2cbf', strong: '#b36df3', accent: '#64dfdf' },
      { key: 'b', name: 'Rose', swatch: '#ec4899', primary: '#b23b7a', strong: '#e45b9e', accent: '#ff9ab9' }
    ],
    light: [
      { key: 'a', name: 'Amethyst', swatch: '#8b5cf6', primary: '#6d28d9', strong: '#8b5cf6', accent: '#0f9f95' },
      { key: 'b', name: 'Rose', swatch: '#ec4899', primary: '#be185d', strong: '#db2777', accent: '#f472b6' }
    ]
  }
};
```

Keep names user-facing and stable. Do not expose internal keys as labels. If the palette is changed or removed in a future version, migrate the stored key or use a safe fallback.

## 5. Applying state

Apply the active skin, mode, and palette to one stable root, normally `<body>` or an application root. Remove only the known classes before adding the new ones.

```
const VALID = {
  // Main-site catalog only. Each other site supplies its own validated allowlist.
  // Main-site catalog only. Each other site supplies its own validated allowlist.
  skins: ['default', 'cyberpunk', 'discord', 'solo-leveling', 'xbox-360', 'windows-xp', 'piece-ocean', 'kaiju-war'],
  modes: ['dark', 'light'],
  palettes: ['a', 'b', 'c', 'd']
};

function normalizeTheme(input = {}) {
  return {
    skin: VALID.skins.includes(input.skin) ? input.skin : 'default',
    mode: VALID.modes.includes(input.mode) ? input.mode : 'dark',
    palette: VALID.palettes.includes(input.palette) ? input.palette : 'a'
  };
}

function applyTheme(input, { persist = true } = {}) {
  const theme = normalizeTheme(input);
  const root = document.body;
  root.classList.remove(
    ...VALID.skins.map(value => `skin-${value}`),
    ...VALID.modes.map(value => `theme-${value}`),
    ...VALID.palettes.map(value => `palette-${value}`)
  );
  root.classList.add(`skin-${theme.skin}`, `theme-${theme.mode}`, `palette-${theme.palette}`);
  if (persist) localStorage.setItem('ecosystemTheme', JSON.stringify(theme));
  document.dispatchEvent(new CustomEvent('themechange', { detail: theme }));
}
```

Use a small inline boot script before the main stylesheet or before first paint when possible, so the page does not flash the default theme before restoring the saved theme. If that is not practical, use a short transition-free startup state and enable transitions after the initial theme is applied.

Persist theme preferences in a namespaced key, for example `ecosystemTheme` or `${projectId}:theme`. The current site has legacy keys (`siteSkin`, `skinPalettes`, and `themePreset`); future implementations should read them only for migration, then write the new format.

## 6. Skin rules

A skin may modify:

- typography family, weight, casing, and letter spacing;

- border radius and component silhouette;

- surface treatment, texture, gradients, and shadows;

- decorative effects;

- layout density when the content remains usable;

- component-specific visual styling;

- site-specific background art and motion, provided they use that skin's palette/mode tokens.

A skin must not:

- remove required content;

- make controls usable only with a mouse or hover;

- set a fixed width that breaks on small screens;

- override the accessible focus indicator without replacing it;

- use a hard-coded light text color on an unknown surface;

- alter semantic HTML or data behavior merely to look different;

- create horizontal overflow for the page.

Keep skin overrides grouped together and place responsive overrides next to the base skin rules. The current site contains several skin-specific layouts, including project tabs that become a horizontal scroll region on smaller screens; preserve the behavior but verify it at intermediate widths and with keyboard navigation.

## 7. Component consumption rules

Components must consume semantic tokens:

```css
.card {
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: var(--color-shadow);
}

.button-primary {
  color: var(--color-primary-text);
  background: var(--color-primary);
}

.button-primary:hover,
.button-primary:focus-visible {
  background: var(--color-primary-strong);
}
```

Do not scatter raw hex values across component rules. Raw colors are allowed only for immutable content-specific values, such as a game’s official brand color, and must be isolated behind a custom property such as `--game-color`.

For generated content, set classes and CSS variables through DOM APIs rather than concatenating untrusted data into HTML. Theme changes must restyle already-rendered content without requiring a full page reload.

## 8. Controls and persistence UX

The theme control should expose:

1. skin selector;

1. dark/light options;

1. palette choices with a visible swatch and accessible name;

1. optional effect toggles.

Every button needs `type="button"` when it is not a form submit. Use a real `<select>` for a compact skin list when appropriate. Make the active choice programmatically identifiable with `aria-pressed`, `aria-current`, or an equivalent state. Close popovers on outside click and Escape, return focus to the trigger when closing, and ensure the panel is reachable by keyboard.

Store separate preferences per skin when that is the intended experience. On the main site, switching from Default to Cyberpunk may restore the user's last Cyberpunk mode and palette rather than silently applying Default's selection. Keep storage namespaced per site; a unique microsite skin should not leak into the main site's state.

## 8.1 Themed window components

Window-like overlays must be theme-aware from the beginning. A store or desktop-style tool should use semantic classes such as `.window`, `.window-titlebar`, `.window-body`, `.window-control`, and `.window-resize-handle`; the component must consume the active skin, mode, palette, and effect tokens without changing its JavaScript behavior.

At minimum, provide tokens or token combinations for:

- window surface and raised surface;

- title-bar surface;

- title-bar text;

- control foreground and hover background;

- close/destructive control state;

- border and resize-handle color;

- overlay/backdrop color;

- window shadow;

- focus ring.

The component must support default, minimized, maximized, closed, focused, dragging, resizing, loading, empty, and error states. Skin CSS may change the title-bar shape, gradient, border, shadow, and typography, but it must not remove the title, controls, focus indicator, body scrolling, or small-screen fallback.

Keep window geometry and theme state separate. Changing a skin or palette should recolor and restyle the open window without resetting its content or corrupting its position. When geometry is persisted, validate and clamp it after every viewport resize and after applying a different skin.

## 9. Motion and effect preferences

Particles, animated gradients, seasonal effects, animated borders, themed ocean/cloud/lightning backgrounds, hover transforms, and carousel movement are decoration. They must never be the only way to understand state. Each site's background effects follow that site's active skin, mode, and palette tokens rather than a fixed color that ignores user selection.

Honor:

```css
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
```

Also provide an in-product effect toggle when the project uses substantial continuous motion. Persist that preference independently from the color state. Do not regenerate expensive effects on every minor DOM event; regenerate only after a real theme or effect change.

## 10. New-project checklist

Before considering the visual system complete:

- Define at least one default skin with dark and light modes.

- Define at least two palettes and validate every foreground/background pair.

- Ensure every component uses semantic tokens rather than hard-coded theme colors.

- Verify dropdowns, cards, tables, inputs, links, buttons, badges, modals, and focus rings in all combinations.

- Verify the saved state survives reload and malformed storage is harmless.

- Verify the default theme appears correctly when JavaScript is disabled or fails.

- Verify reduced motion and keyboard operation.

- Verify no skin introduces horizontal page overflow.

- Verify a new skin can be added by defining tokens and scoped overrides without rewriting application logic.
## 10. Shared universal assets and site-specific skin catalogs

Load `/universal-global.css` after project component styles and `/universal-global.js` after the page DOM and existing project scripts when those shared assets are part of the project. They provide the main site's appearance launcher and shared controls; a microsite may adapt or omit site-specific presentation controls when its information architecture requires a different experience. Keep every control keyboard- and touch-reachable.

The main website catalog includes **One Piece Ocean** (`skin-piece-ocean`, legacy display name Piece Ocean; clear sky, slowly moving clouds and seabirds, and animated layered ocean waves) and **Kaiju War** (`skin-kaiju-war`, defense-force surfaces and animated electric energy). These are main-site skins, not a mandatory catalog for every ecosystem site. Other sites may use wholly different skins. Preserve dark/light modes and semantic palette roles where offered. Kaiju War's electric blue is its default palette only; every effect must harmonize with the active palette and mode.

The global layer also provides `window.MrJuaumUI.notify(message, {type, duration, progress})` with success/danger/warn/info variants, dismiss control, timed progress and motion-aware entrance, plus `window.MrJuaumUI.openWindow({title, content, width})` with minimize, maximize and close controls. Treat window content as trusted application markup only; sanitize untrusted content. Keep z-indexes, safe-area insets, and mobile geometry centralized.

The `universal-global.js` language setting persists `en` or `pt-BR` and sets `<html lang>`; each project should supply translated copy through `data-i18n` or its own locale dictionary. Do not imply static strings are translated merely because the document language changed.


### 10.1 Main-site palettes and animated backgrounds

On the main site, One Piece Ocean retains the existing palette names `Monkeyd`, `Namorange`, `Gomu (Purple)`, and `FrankCoke`; Kaiju War retains `Kafka Electric Blue` (slot A and default), `Tesla Arc Cyan`, `Kaiju Flare`, and `Reactor Gold`. Give each palette a visible swatch, selected state, semantic primary/strong/accent values for each supported mode, and per-skin persistence. Other sites may define their own palette names and skin settings.

Animate One Piece Ocean with slow, layered wave motion, subtle changing reflections, gently moving clouds, and distant seabirds; the overall result should evoke a living ocean and sky without distracting from reading. Animate Kaiju War's irregular electrical rays and lightning using the active palette tokens, with brightness and glow adjusted for the active mode. Keep effects behind interactive content, disable motion under `prefers-reduced-motion` or the site's effects-off control, and retain an intentional static background when motion is disabled. Do not hard-code electric blue outside Kaiju War's default palette values.
