> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Styling & theming

The app uses [`react-native-unistyles`](https://www.unistyles.dev/) v3 for styles. Tokens (colors, spacing, fonts, breakpoints) live under `src/core/theme/`. The root `unistyles.ts` is the orchestration file that pulls those tokens in and calls `StyleSheet.configure`.

## File layout

```
unistyles.ts                  # root entry: imports tokens, calls StyleSheet.configure
src/core/theme/
  index.ts                    # barrel + UnistylesThemes/UnistylesBreakpoints module augmentation
  colors.ts                   # light + dark color palettes
  gradients.ts                # named linear gradients (light + dark) consumed by <TextOutline>
  spacing.ts                  # spacing token map + radius scale
  fonts.ts                    # font assets, sizes, weights, line heights
  breakpoints.ts              # xs / sm / md / lg
  themes.ts                   # composes colors + gradients + spacing + radii into light/dark themes
```

The split is intentional: tokens are **values** (live in `src/core/theme/`), and registration is a **side effect** (lives at root).

## Setup chain

```mermaid
flowchart LR
  entry["index.ts"] --> root["./unistyles.ts"]
  root --> tokens["src/core/theme/index.ts"]
  tokens --> themesFile["themes.ts<br/>(light + dark)"]
  tokens --> bp["breakpoints.ts"]
  themesFile --> colors["colors.ts"]
  themesFile --> spacing["spacing.ts"]
  themesFile --> fonts["fonts.ts"]
  root --> configure["StyleSheet.configure(...)"]
  configure --> registeredThemes["themes: { light, dark }"]
  configure --> registeredBp["breakpoints"]
  configure --> settings["settings: { initialTheme: 'dark' }"]
  babel["babel.config.js<br/>react-native-unistyles/plugin"] --> processes["processes app/ + src/"]
```

`index.ts` imports `./unistyles` before `expo-router/entry`, so themes are registered before any screen mounts.

## Theme shape

```ts
// src/core/theme/themes.ts
import { darkColors, lightColors } from '@core/theme/colors';
import { radius, spacing } from '@core/theme/spacing';

export const darkTheme = {
  colors: darkColors,
  spacing,
  radius,
};
```

| Token       | Purpose                                                                                       | Lives in                        |
| ----------- | --------------------------------------------------------------------------------------------- | ------------------------------- |
| `colors`    | All chrome + semantic tokens. Never use hardcoded hex inline.                                 | `src/core/theme/colors.ts`      |
| `gradients` | Named linear gradients (`type`, `colors`, `stops`, `direction`) consumed by `<TextOutline>`.  | `src/core/theme/gradients.ts`   |
| `spacing`   | Token map: `none / xs(4) / sm(8) / md(12) / lg(16) / xl(24) / xxl(32) / xxxl(48) / huge(64)`. | `src/core/theme/spacing.ts`     |
| `radius`    | Border radius scale (`sm`, `md`, `lg`, `full`).                                               | `src/core/theme/spacing.ts`     |
| `fonts`     | Font assets, weights, sizes, line heights — consumed by `<Text>` and `expo-font`.             | `src/core/theme/fonts.ts`       |
| breakpoints | Responsive bucket sizes.                                                                      | `src/core/theme/breakpoints.ts` |

## Using styles in a component

```tsx
import { StyleSheet } from 'react-native-unistyles';

export const Card = () => <View style={styles.card} />;

const styles = StyleSheet.create((theme) => ({
  card: {
    backgroundColor: theme.colors.surface,
    padding: theme.spacing.lg,
    borderRadius: theme.radius.md,
    borderWidth: 1,
    borderColor: theme.colors.border,
  },
}));
```

## Variants

Use variants for prop-driven styling — variants compose into runtime styles without rerenders.

```tsx
// src/components/PrimaryButton.tsx
export const PrimaryButton = ({ variant = 'primary', disabled }) => {
  styles.useVariants({ variant, disabled });
  return <Pressable style={styles.button}>...</Pressable>;
};

const styles = StyleSheet.create((theme) => ({
  button: {
    height: 48,
    borderRadius: theme.radius.md,
    variants: {
      variant: {
        primary: { backgroundColor: theme.colors.primary },
        secondary: { backgroundColor: theme.colors.accent },
        ghost: {
          backgroundColor: theme.colors.transparent,
          borderWidth: 1,
          borderColor: theme.colors.border,
        },
      },
      disabled: {
        true: { opacity: 0.5 },
        false: { opacity: 1 },
      },
    },
  },
}));
```

```mermaid
flowchart LR
  component[Component renders] --> useVariants["styles.useVariants(propMap)"]
  useVariants --> merger[Unistyles runtime]
  merger --> resolved[Resolved style for current theme + props]
  resolved --> native[React Native style prop]
```

## Gradients

Linear gradients are first-class theme tokens — defined once in
[src/core/theme/gradients.ts](https://github.com/leapgame/leap-sim-piano/blob/f794b594016038c483e2d20b6af56aea0ae1b982/src/core/theme/gradients.ts) and accessed as
`theme.gradients.<name>` from any `StyleSheet.create((theme) => ...)` block,
or applied to text via the [`<TextOutline gradient="...">`](https://github.com/leapgame/leap-sim-piano/blob/f794b594016038c483e2d20b6af56aea0ae1b982/src/components/TextOutline.tsx)
component.

Each gradient is a `LinearGradientToken`:

```ts
{
  type: "linear",
  colors: ["#FFE07A", "#FFC93D"],     // 2+ raw hex / rgba stops
  stops?: [0, 1],                      // optional 0..1 positions, omit for even spacing
  direction?: "vertical",              // "horizontal" | "vertical" | "diagonal-tl-br" | "diagonal-tr-bl" | { angle: 0 }
}
```

Adding a new gradient:

1. Add the entry under the same key in **both** `lightGradients` and
   `darkGradients` in `gradients.ts`. The `satisfies Record<keyof typeof
   lightGradients, LinearGradientToken>` annotation on `darkGradients`
   enforces key parity at compile time.
2. Pick light/dark color stops independently — gradients flip with the
   active theme just like `theme.colors.*`.
3. Reference it from a component:

   ```tsx
   // Theme token
   <TextOutline variant="display" gradient="heroTitle">
     LEVEL UP
   </TextOutline>

   // Inline token — custom colors, stops, and direction without adding a theme key
   <TextOutline
     variant="title"
     weight="bold"
     gradient={{
       type: "linear",
       colors: ["#C084FC", "#53C9FF", "#A4EFFF"],
       stops: [0.265, 0.5, 0.735],
       direction: { angle: 73 },
     }}
   >
     Accent word
   </TextOutline>

   // Two-color shorthand — `startColor` / `endColor` with optional stops + direction
   <TextOutline
     variant="title"
     weight="bold"
     gradient={{ startColor: "#C084FC", endColor: "#53C9FF", direction: "horizontal" }}
   >
     Accent word
   </TextOutline>
   ```

   Button fills accept the same token shape via `gradientFill` on
   [`<PrimaryButton>`](https://github.com/leapgame/leap-sim-piano/blob/f794b594016038c483e2d20b6af56aea0ae1b982/src/components/PrimaryButton.tsx), the app's one pill button — the
   gold monetisation CTA is its `variant="premium"` (`subtitle`, `icon`,
   `contentLayout="spaceBetween"`, `labelGradient`, `height`, `fullWidth` / `align`; it starts
   at `flex-start` unless told otherwise). Its fills and content live beside it in
   `PrimaryButtonFace.tsx` and `PrimaryButtonContent.tsx`.

   `gradientLight` (Play), `gradientLearn` and `premium` are one view with no canvas: the pill
   wears its paint itself (`playPillPaint`, `learnPillPaint`; `nativeLinearPaint` for the gold
   and the Shop's price fill), plus its ring and glow. A fill whose axis no CSS keyword can say
   stays a gradient view. Learn's design radials lean, which a CSS radial cannot: its four
   ellipses are upright ones fitted to them (colours and stops untouched; RMSE 1.8 of 255).

   `gradientFill` overrides the variant's preset sweep (variant chrome —
   ring, glow, radius — is unchanged; `gradientLight` / `gradientLearn` paint their own fill in place of an override).

   Its press, and the sparkles the call-to-action variants throw, are the app's
   [button press](/docs/button-press.md).

   **One flat pill.** Every variant is fully round with a 0.5pt ring, and the `Pressable` itself
   carries the glow, ring, press and disabled dimming — no wrapper, glow or ring view. It must
   not clip (`overflow: "hidden"` cuts its own shadow): fills round themselves and the shine
   clips itself (`ButtonShine` `clipRadius`). Solid pills take a layer shadow; the see-through
   `gradientLearn` takes a `boxShadow`. The white-50% ring is drawn by whatever paints on top
   (`resolvePillRingHost`: the native gradient view, or the pill itself). No part of a button
   draws on a Skia canvas: the old fills were removed after the native ones measured lighter on
   device (mounting 60 pills, DEV 2026-11: worst UI frame 141 → 35 ms for Play, 128 → 41 ms for
   Learn; some of the 60 were off screen, and scrolling was not measured).
   `outlineDark` is two views: a blue pill under a native radial (`uprightRadial`,
   `experimental_backgroundImage` as a plain inline style) and a dark face inset 0.5pt:

   ```tsx
   <PrimaryButton
     label="Get"
     variant="gradientDark"
     gradientFill={{
       type: "linear",
       colors: [theme.colors.buttonLearnGlowPurple, theme.colors.buttonLearnBase],
       stops: [0.2, 0.8],
       direction: "diagonal-tl-br",
     }}
     onPress={onPress}
   />
   ```

   Or read the raw token from a stylesheet for a custom Skia surface:

   ```ts
   const styles = StyleSheet.create((theme) => ({
     hero: { ...theme.gradients.heroTitle }, // pseudo — pass to a Skia <LinearGradient>
   }));
   ```

[`TextOutline`](https://github.com/leapgame/leap-sim-piano/blob/f794b594016038c483e2d20b6af56aea0ae1b982/src/components/TextOutline.tsx) renders gradient text with
`expo-linear-gradient` + `@react-native-masked-view/masked-view` (no Skia
canvas). Outline and drop-shadow are layered RN `<Text>` duplicates behind the
fill.

[`GradientPill`](https://github.com/leapgame/leap-sim-piano/blob/f794b594016038c483e2d20b6af56aea0ae1b982/src/components/GradientPill.tsx) also accepts an optional
`locations` prop (0..1 stop positions) when used directly for low-level
expo-linear-gradient fills.

The angle convention for `{ angle: number }` is screen-space: `0°` runs
top → bottom, `90°` runs left → right, `180°` runs bottom → top, `270°`
runs right → left. Negative or out-of-range angles are normalized into
`[0, 360)`.

## Theme switching at runtime

```ts
import { UnistylesRuntime } from 'react-native-unistyles';

UnistylesRuntime.setTheme('light'); // or 'dark'
```

If you want OS-driven theming, replace `initialTheme: 'dark'` in `StyleSheet.configure` with `adaptiveThemes: true` and let Unistyles follow the system appearance.

## Breakpoints

Registered with Unistyles:

```ts
const breakpoints = { xs: 0, sm: 360, md: 768, lg: 1024 };
```

**Phone vs iPad is never a width breakpoint.** Size for the device class with `IS_TABLET`
(`@core/device/is-tablet`) and `scaleTypeForTablet` (`@core/device/tablet-type-scale`):

```ts
const styles = StyleSheet.create((theme) => ({
  container: {
    paddingHorizontal: IS_TABLET ? theme.spacing.xxxl : theme.spacing.lg,
  },
  title: {
    fontSize: scaleTypeForTablet(theme.fontSizes.title),
  },
}));
```

A width breakpoint cannot tell the two apart: a landscape phone is 568–956 pt wide (`md`), a
portrait iPad mini 744 pt. The app is `requireFullScreen`, so an iPad window never shrinks and the
device check always matches the screen. It also reads in module constants and gameplay math, where
a reactive breakpoint cannot.

**A stylesheet with breakpoint- or orientation-keyed values takes the runtime** — `(theme, _rt)`,
even when it never reads it. Every stylesheet is created when the app starts, and on a width
change Unistyles 3 re-parses a `(theme)`-only sheet only for the views on screen at that moment.
An iPad that starts upright parses the sheets at `md`; when the app then turns landscape, a screen
first opened later (the song result) keeps its `xs`/`md` values for the whole session. A
`(theme, rt)` sheet is refreshed on every runtime change, mounted or not.
`src/core/theme/__tests__/breakpoint-stylesheets.test.ts` fails on a `(theme)`-only sheet that
holds such a value.

## Where to put style code

| Scope                   | Location                                                   |
| ----------------------- | ---------------------------------------------------------- |
| Shared, app-wide        | `src/components/*` (e.g. `Screen`, `PrimaryButton`)        |
| Feature-local           | `src/features/<x>/components/*`                            |
| One-off inside a screen | Co-located `StyleSheet.create` at the bottom of the screen |
| Color tokens            | `src/core/theme/colors.ts`                                 |
| Spacing / radius        | `src/core/theme/spacing.ts`                                |
| Fonts                   | `src/core/theme/fonts.ts`                                  |
| Breakpoints             | `src/core/theme/breakpoints.ts`                            |
| Theme composition       | `src/core/theme/themes.ts`                                 |
| Registration only       | `unistyles.ts` (root)                                      |

## Common pitfalls

- **Never hardcode a hex value.** Add it to the theme first.
- **Never hardcode `fontFamily` strings** (`'Nunito_400Regular'`, `'System'`, …). Use `theme.fonts.primary.*` / `theme.fonts.secondary.*` from `src/core/theme/fonts.ts` (see `.cursor/rules/typography-fonts.mdc`).
- **Don't import `StyleSheet` from `react-native`** — always from `react-native-unistyles` so themes apply.
- **`useVariants` requires the component to actually render.** If you build a variant table but never call `useVariants`, the variant branch is dead code.
- **Babel root.** If a new top-level folder is added (e.g. `packages/ui`), update [babel.config.js](https://github.com/leapgame/leap-sim-piano/blob/f794b594016038c483e2d20b6af56aea0ae1b982/babel.config.js) `autoProcessPaths` so its styles get themed.

***

<small>Source: [`docs/styling-theming.md`](https://github.com/leapgame/leap-sim-piano/blob/f794b594016038c483e2d20b6af56aea0ae1b982/docs/styling-theming.md)</small>
