# Styles, Overlays & Unstyled Components (https://crow.build/docs/ui/styling)

Crow enforces a strict separation between **behavior** and **visual design**. Core modules never depend on Material 3 or Lens (`checkCoreIndependence`). Instead, `crow-ui` ships a high-performance style engine (`crow.style`), unstyled component bases, and a unified overlay layer.

## `crow-style`: Immutable Styles with Per-State Springs [#crow-style-immutable-styles-with-per-state-springs]

Define visual styling as composable `Style` values with state blocks (`pressed`, `focused`, `focusVisible`, `hovered`, `dragged`, `selected`, `disabled`, `error`) resolved in fixed precedence:

```kotlin
private val PrimaryPill = style {
    background { LocalTheme.current.accent }
    contentColor { LocalTheme.current.onAccent }
    shape(RoundedCornerShape(999.dp))
    padding(horizontal = 20.dp, vertical = 12.dp)

    hovered { overlay(0x14FFFFFF) }
    pressed { scale(0.96f); overlay(0x26FFFFFF) }
    disabled {
        background { LocalTheme.current.surfaceMuted }
        contentColor { LocalTheme.current.textMuted }
    }
}
```

Compose styles with `+` (deep-merging state blocks cleanly):

```kotlin
val DestructivePill = PrimaryPill + style {
    background(0xFFDC2626.toInt())
}
```

### Why It's Fast [#why-its-fast]

- All eight interactive states live in a single immediate-lane bitmask (`Interaction`).
- `Modifier.style(style, interaction)` creates **at most one binding per render phase** (draw, layer, layout).
- Colors interpolate in **premultiplied OKLab**, and scale/offset/overlay springs run directly inside the node with **zero graph flushes per frame**.
- Token lambdas (`background { ... }`) evaluate when applied, so top-level `val` styles automatically follow live dark/light theme switches.

## Unstyled Components (Bases) [#unstyled-components-bases]

Core ships accessible, keyboard-aware unstyled bases that wire `Interaction`, semantics roles, focus, and cascading `LocalContentColor` / `LocalTextStyle`:

- **`ButtonBase`** — clickable action with disabled press cancellation
- **`ToggleBase`**, **`SwitchBase`**, **`CheckboxBase`**, **`RadioButtonBase`**, **`RadioGroup`** — selection & checked states
- **`DialogBase`**, **`PopupBase`**, **`SheetBase`**, **`BalloonBase`**, **`SpotlightScrim`** — modal & anchored surfaces

```kotlin
ButtonBase(
    onClick = { saveDraft() },
    style = PrimaryPill,
    enabled = canSave,
) {
    Text("Save Draft")
}
```

## The `Overlay` Primitive [#the-overlay-primitive]

Dialogs, bottom sheets, popups, tooltips, menus, and snackbars all render on `CrowView`'s unified overlay layer — **never** leaky separate `PopupWindow`s:

- **Lexical owner & contexts**: An `Overlay` inherits the owner and `Context` values of its declaration site while rendering above all content.
- **Entering / Open / Exiting**: Reopening a sheet or dialog mid-exit reverses the same overlay seamlessly.
- **Back & focus stacking**: Overlays capture system back in stack order, cancel touches beneath, suspend IME focus when opening, and restore focus to the opener on close.
- **Same-frame anchored placement**: `PopupBase` and `BalloonBase` recompute flip/shift/RTL positioning right before draw so anchored popovers track scrolls without a single frame of lag.