# Unity UI Toolkit

The structure is built to port to Unity UI Toolkit (USS): the same tokens, the same class names. Here is what carries over and what needs another route.

| Web | Unity (USS) |
|---|---|
| `CSS variables (--cz-*)` | USS variables, same names. Generate a tokens.uss from tokens.json. |
| `.cz-button, .cz-button--primary` | Same USS class names on VisualElements. |
| `:hover :active :focus :disabled` | USS pseudo-classes of the same name; :checked for Toggle. |
| `[data-state] from Radix` | Add or remove a class from C# (e.g. .is-checked). |
| `box-shadow, gradients` | Not in USS. Use 9-slice sprites (-unity-slice-*) of each block, or draw with Painter2D. |
| `::before glint` | A child VisualElement. |
| `color-mix(), filter` | Pre-compute the colours as extra tokens. |
| `transition` | Supported. Use ease-out-back for --cz-motion-ease-bounce. |
| `@keyframes` | Not in USS. Drive with experimental.animation or a small tween in C#. |
| `@font-face` | Create a Font Asset from the same TTF files. |

## Example

Button.uss:

```css
:root {
  --cz-primary: #B04A2C;
  --cz-outline: #5A3A28;
  --cz-radius-md: 12px;
}

.cz-button {
  border-width: 3px;
  border-color: var(--cz-outline);
  border-radius: var(--cz-radius-md);
  min-height: 48px;
  /* face, rim, wall and contact shadow come from a 9-slice sprite */
  background-image: url("project://database/Assets/UI/button-primary.png");
  -unity-slice-left: 16; -unity-slice-right: 16;
  -unity-slice-top: 12; -unity-slice-bottom: 18;
  transition: translate 140ms ease-out-back;
}

.cz-button:hover { translate: 0 -2px; }
.cz-button:active { translate: 0 6px; }
```

Tip: the 9-slice sprites can be captured from this site with a headless browser, one per variant and state, so the game and the web stay identical.

Docs: https://cozy-ui.solo.engineer/docs/unity/
