# @shachi-ui/styles

CSS for Shachi UI: design tokens, base styles, layout primitives, utilities, and the themes that style [`@shachi-ui/components`](https://www.npmjs.com/package/@shachi-ui/components).

## Installation

Install the package using your preferred package manager:

```sh
npm install @shachi-ui/styles
# or
pnpm add @shachi-ui/styles
# or
yarn add @shachi-ui/styles
```

## Usage

### Import the bundled modules

Each module is a built, minified stylesheet. Import the ones you need, or all of them:

```css
/* Layers, design tokens, defaults, document setup */
@import "@shachi-ui/styles/core";

/* Layout primitives (stack, cluster, grid, …) */
@import "@shachi-ui/styles/compositions";

/* Base styles for HTML elements */
@import "@shachi-ui/styles/elements";

/* Utility classes */
@import "@shachi-ui/styles/utilities";

/* A theme for the components */
@import "@shachi-ui/styles/themes/brutal";
```

Always include `core`: it declares the layers and the `--sh-*` tokens the other modules rely on. Beyond that, order does not matter: the cascade is decided by those layers, not by the order of the imports.

### Import source files (before build processing)

For more control over the build process, you can import specific source files. **Add the `.css` extension**: a subpath without it resolves to the built bundle, one with it resolves to the matching source file under `src/`.

```css
/* Import specific core styles */
@import "@shachi-ui/styles/core/defaults.css";
@import "@shachi-ui/styles/core/document.css";
@import "@shachi-ui/styles/core/tokens.css";

/* Import specific compositions */
@import "@shachi-ui/styles/compositions/stack.css";

/* Import specific element styles */
@import "@shachi-ui/styles/elements/anchor.css";

/* Import specific utility styles */
@import "@shachi-ui/styles/utilities/flow.css";

/* Import specific theme component styles */
@import "@shachi-ui/styles/themes/brutal/components/icon.css";
```

Compositions read a set of registered custom properties, so import `compositions/properties.css` alongside them if you cherry-pick individual primitives.

This approach allows you to:

- Choose which parts of Shachi to include
- Apply your own build processing (minification, bundling, etc.)
- Customize the layer organization
- Optimize bundle size by including only what you need

## Layers structure

This package uses the CSS Cascade Layers feature (`@layer`) to organize styles in a predictable and extensible way. All Shachi styles are scoped under the `shachi` namespace to avoid conflicts with existing stylesheets.

The layer order is defined in `core/layers.css` as:

1. **shachi.core**: tokens, defaults, document setup
2. **shachi.elements**: base styles for HTML elements
3. **shachi.compositions**: layout primitives
4. **shachi.themes**: theme styles for `sh-*` elements and their `::part()`s
5. **shachi.utilities**: utility classes

When two rules have comparable specificity, rules in later layers win.

## Available modules

### Core (`@shachi-ui/styles/core`)

The foundation: layer declarations, design tokens (`--sh-color-*`, `--sh-font-family`, `--sh-focus-outline`, …), a CSS reset, and document setup. It also hides custom elements until they are defined, which keeps components from flashing unstyled while they load. The rule matches every custom element on the page, not only `sh-*`, and gives up after two seconds: an element whose definition never loads then appears, without its behavior.

### Compositions (`@shachi-ui/styles/compositions`)

Layout primitives, one class each: `.stack`, `.cluster`, `.split`, `.flank`, `.frame`, `.grid`. They carry structure only — no colors, borders, or typography — and are tuned through `--sh-`-prefixed custom properties (`--sh-gap`, `--sh-align`, …) rather than modifier classes.

### Elements (`@shachi-ui/styles/elements`)

Base styles for plain HTML elements. It covers anchors for now.

### Utilities (`@shachi-ui/styles/utilities`)

Utility classes like `.flow` for managing spacing and `.visually-hidden` for screen-reader-only content.

### Themes (`@shachi-ui/styles/themes/*`)

The visual design of the components. The components ship structure only, and a theme styles each `sh-*` element and its shadow parts through `::part()`:

- `@shachi-ui/styles/themes/brutal`: a bold, high-contrast theme

### Global text size

Primary component text in the brutal theme inherits the surrounding font size without a default reduction.
Secondary text, explicit button sizes, and rating symbols retain their relative proportions.
Set the root size to change the global scale, or set a container size to scale its components locally.

### Adding your own styles

You can add your own styles in a specific layer to control their priority. To ensure your styles work well with Shachi, you can either:

**Option 1: Use the same layer structure**

```css
@layer shachi.themes {
	:root {
		--my-custom-color: #ff0000;
	}
}

@layer shachi.themes {
	sh-button[variant="primary"]::part(button) {
		background-color: var(--my-custom-color);
	}
}
```

**Option 2: Create your own layer namespace**

```css
@layer my-app.something;

@layer my-app.something {
	.cool-class {
		/* Some styles */
	}
}
```
