# Theming @sylar_iii/ui

Every element reads its colors, radius and shadows from CSS custom properties. Set them once on `:root` (or on any ancestor) and every element follows. The package ships the theme in two forms: **plain CSS** for any framework, and **Sass** for builds that compile styles.

## Presets and modes

| Preset | Look |
| --- | --- |
| `default` | Violet and magenta (the default) |
| `dark-green` | Green |
| `lime` | Lime |
| `orange` | Orange |
| `gold` | Gold |
| `crystal` | Cyan |
| `dark-blue` | Blue |
| `pink` | Pink |

Every preset has a `dark` and a `light` palette. The mode is the `data-theme` attribute on `<html>`:

```html
<html data-theme="dark">   <!-- or "light" -->
```

Without the attribute the dark palette applies.

## Tokens

Each preset sets these tokens for each mode (the names are the public contract):

| Token | Meaning |
| --- | --- |
| `--sylar-primary`, `--sylar-secondary`, `--sylar-accent` | Brand colors. `primary` is the default tone of most elements. |
| `--sylar-primary-bg`, `--sylar-secondary-bg`, `--sylar-accent-bg` | 16% tints of the brand colors. |
| `--sylar-violet` | Alias of the secondary color. |
| `--sylar-gradient` | `linear-gradient(135deg, …)` built from primary, accent and secondary. |
| `--sylar-bg` | Page background. |
| `--sylar-surface` | Cards, menus, fields. |
| `--sylar-hover` | Hover background. |
| `--sylar-border` | Borders and dividers. |
| `--sylar-text` | Body text. |
| `--sylar-muted` | Secondary text, hints, placeholders. |
| `--sylar-code` | Code text. |
| `--sylar-header` | Translucent header background. |
| `--sylar-selection` | Text selection and selected rows. |
| `--sylar-glow-primary`, `--sylar-glow-secondary` | Soft glows. |
| `--app-background` | Page background alias (`var(--sylar-bg)`). |

The base stylesheet also defines neutral and status scales (`--grey-1` to `--grey-5`, `--black-1` to `--black-4`, `--white-1` to `--white-4`, `--red-1`, `--red-2`, `--green-1`, `--green-2`) used by the portal and a few elements. Prefer the `--sylar-*` tokens in your own CSS.

## Plain CSS (React, Vue, Svelte, HTML, any build)

The package ships compiled CSS under `theme/css/`:

| File | Contents |
| --- | --- |
| `base.css` | Base tokens (the `default` palette) and the base styles. Load it first. |
| `<preset>.css` | One preset (`lime.css`, `dark-blue.css`, …). Load it after `base.css`. |
| `utilities.css` | Optional utility classes (`d-flex`, `gap-05rem`, `fs-09rem`, …). |

Load `base.css`, then exactly one preset file. Each preset file redeclares the tokens for both modes, so it overrides the defaults.

**React, Vue, Svelte, Vite apps.** Import them once in the app entry (for example `src/main.ts` or `src/main.tsx`):

```ts
import '@sylar_iii/ui/theme/css/base.css';
import '@sylar_iii/ui/theme/css/lime.css';
document.documentElement.dataset['theme'] = 'dark';
```

**Plain HTML.** Link the files in `<head>, in this order:

```html
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@sylar_iii/ui@1/theme/css/base.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@sylar_iii/ui@1/theme/css/lime.css">
```

**Angular with plain CSS.** Add the two files to `"styles"` in `angular.json` (`projects -> <app> -> architect -> build -> options`), before your own styles:

```json
"styles": [
  "node_modules/@sylar_iii/ui/theme/css/base.css",
  "node_modules/@sylar_iii/ui/theme/css/lime.css",
  "src/styles.scss"
]
```

## Sass (compiled theme)

For a Sass build, `@use` the theme entry and choose a preset. The entry compiles the chosen preset into `:root` and `:root[data-theme='dark' | 'light']`:

```scss
@use '@sylar_iii/ui/theme/sylar.theme' with (
  $preset: 'lime',
  $dark-overrides: (),
  $light-overrides: ()
);
```

To ship every preset and switch at runtime with `data-color-theme="<preset>"` on `<html>`, `@use '@sylar_iii/ui/theme/sylar.theme-presets';` once (it adds one selector per preset).

The Sass sources (`sylar.theme-core.scss`, `sylar.theme.scss`, `sylar.theme-presets.scss`) are plain SCSS and are not compiled by the package; your build compiles them.

## Custom palette

Pick one preset as the base and override only the tokens you change. Each mode needs the ten palette keys: `primary`, `secondary`, `accent`, `background`, `surface`, `hover`, `border`, `text`, `muted`, `code`. Optional: `gradient-middle` and `gradient-end` (the gradient defaults to accent and secondary).

**Sass (recommended).** Overrides are merged into the chosen preset. Derived tokens (tints, gradient, glows) are recomputed from them:

```scss
@use '@sylar_iii/ui/theme/sylar.theme' with (
  $preset: 'default',
  $dark-overrides: (primary: #0ea5e9, accent: #38bdf8),
  $light-overrides: (primary: #0369a1, accent: #0284c7)
);
```

**Plain CSS.** Declare the tokens yourself in a stylesheet loaded after the preset. Redeclare the derived tokens too, or they keep the preset values:

```css
:root[data-theme='dark'] {
  --sylar-primary: #0ea5e9;
  --sylar-primary-bg: color-mix(in srgb, #0ea5e9 16%, transparent);
  --sylar-accent: #38bdf8;
}
:root[data-theme='light'] {
  --sylar-primary: #0369a1;
  --sylar-primary-bg: color-mix(in srgb, #0369a1 16%, transparent);
  --sylar-accent: #0284c7;
}
```

Keep text readable on `--sylar-bg` and `--sylar-surface` in both modes (check contrast in dark and light).

## Element hooks

Set these on the element (`style="--sylar-…: …"` or a class) or on an ancestor. Each one falls back to the shared tokens when unset. Element properties such as `color` or `radius` write the same variables for you.

| Element | Hooks |
| --- | --- |
| `sy-badge` | `--sylar-badge-color`, `--sylar-badge-text`, `--sylar-badge-font`, `--sylar-badge-font-size`, `--sylar-badge-font-weight`, `--sylar-badge-padding`, `--sylar-badge-radius` |
| `sy-button` | `--sylar-button-color`, `--sylar-button-text`, `--sylar-button-hover-bg`, `--sylar-button-gradient`, `--sylar-button-padding`, `--sylar-button-radius`, `--sylar-button-shadow`, `--sylar-button-ripple`, `--sylar-button-neon-ink` |
| `sy-icon` | `--sylar-accent` (default icon color) |
| `sy-grid-menu` | `--sylar-grid-menu-cell`, `--sylar-grid-menu-gap`, `--sylar-grid-menu-ring`, `--sylar-grid-menu-radius`, `--sylar-grid-menu-icon-size`, `--sylar-grid-menu-item-bg`, `--sylar-grid-menu-item-hover`, `--sylar-grid-menu-icon`, `--sylar-grid-menu-toggle`, `--sylar-grid-menu-toggle-icon`, `--sylar-grid-menu-dot` |
| `sy-sidebar` | Uses `--sylar-text`, `--sylar-muted`, `--sylar-accent`, `--sylar-hover`, `--sylar-border`, `--sylar-bg`. |
| `sy-input` | `--sylar-input-accent`, `--sylar-input-bg`, `--sylar-input-border`, `--sylar-input-addon-bg`, `--sylar-input-radius`, `--sylar-input-height`, `--sylar-input-soft-dark`, `--sylar-input-soft-light`, `--sylar-input-soft-depth`, `--sylar-input-otp-gap`, `--sylar-input-otp-size`, `--sylar-input-weak`, `--sylar-input-fair`, `--sylar-input-good`, `--sylar-input-success` |
| `sy-phone-input` | Uses `--sylar-text`, `--sylar-muted`, `--sylar-accent`, `--sylar-surface`, `--sylar-border`, `--sylar-hover`, `--sylar-bg`. |

Elements draw inside a shadow root. Use the `::part(button)` selector on `sy-button` for its inner native button, or the element's own properties for everything else.

## Accessibility and motion

- Focus rings follow the element tone or accent (`--sylar-primary` / `--sylar-accent`); keep them visible in both modes.
- Motion (button ripple, grid-menu burst, sidebar slide, input and phone-input transitions) is turned off by `prefers-reduced-motion: reduce`.
- Check every preset in dark and light mode, including hover, focus, disabled and error states, before shipping a custom palette.
