# Overview

import { Callout } from "fumadocs-ui/components/callout";
import { Accordion, Accordions } from "fumadocs-ui/components/accordion";
import { Step, Steps } from "fumadocs-ui/components/steps";
import { Tabs, Tab } from "fumadocs-ui/components/tabs";
import { Badge, Card, CardContent, CardHeader, CardTitle } from "@pycolors/ui";
import {
  ArrowRight,
  Blocks,
  CheckCircle,
  CircleDot,
  Layers3,
  Layers,
  Ruler,
  Palette,
  Sparkles,
  Type,
  XCircle,
} from "lucide-react";
import { PreferAvoid } from "@/components/docs/prefer-avoid";
import { DocsLinks } from "@/components/docs/docs-links";
import { DocsFeatureGrid } from "@/components/docs/docs-feature-grid";

<div className="flex flex-wrap items-center gap-2">
  <Badge variant="outline">
    Design System
  </Badge>

  <Badge>
    Tokens
  </Badge>
</div>

## The foundation of every interface

Design tokens are the **single source of truth** for the visual language of PyColors UI.

They encode small decisions that every component can consume:

* radius
* elevation
* color roles
* typography roles
* future motion, spacing, and layering rules

Tokens are not components. They are not random CSS values. They are **design decisions expressed as reusable variables**.

<Callout title="Why this matters">
  Without tokens, every component slowly starts making its own visual decisions.
  That creates drift, makes refactors risky, and weakens the premium feeling of
  the product over time.
</Callout>

### What tokens control

<DocsFeatureGrid
  columns={3}
  tone="platform"
  items={[
  {
    title: "Geometry",
    description:
      "Radius tokens keep buttons, cards, inputs, and overlays visually related.",
    icon: Ruler,
  },
  {
    title: "Elevation",
    description:
      "Shadow tokens define calm, predictable depth across cards, menus, and modals.",
    icon: Layers3,
  },
  {
    title: "System intent",
    description:
      "Tokens make design intent explicit so the product can scale without visual drift.",
    icon: Sparkles,
  },
]}
/>

## Pair surfaces with their foreground tokens

Use `primary` with `primary-foreground`, and `destructive` with
`destructive-foreground`. Their foregrounds use dark text in dark mode because
those semantic surfaces become lighter; hard-coded white text does not retain
readable contrast. The light-mode `muted-foreground` also supports text on the
muted surface. Custom palettes, opacity and layered backgrounds still require
contrast checks in their actual context.

## Steps

<Steps>
  <Step>
    ### Start from design decisions

    A token exists when a visual decision should be shared by the system.

    Instead of asking every component to decide its own radius, shadow, or surface treatment, PyColors defines those decisions once.

    ```text title="system-flow.txt"
    Design decisions
      ↓
    Tokens
      ↓
    Tailwind utilities
      ↓
    UI components
      ↓
    Product surfaces
    ```

    This flow keeps components small while the system stays expressive.
  </Step>

  <Step>
    ### Define tokens centrally

    Tokens are defined as CSS variables and mapped into utilities.

    ```css title="tokens.css"
    :root {
      --radius: 0.625rem;
    }

    @theme inline {
      --radius-md: calc(var(--radius) - 2px);
      --radius-lg: var(--radius);
      --radius-xl: calc(var(--radius) + 4px);
    }
    ```

    The raw value stays in the token layer. Components consume the utility.

    ```tsx title="components/product-card.tsx"
    export function ProductCard() {
      return (
        <article className="rounded-lg border bg-card p-6 shadow-sm">
          <h2 className="text-lg font-semibold tracking-tight">Product surface</h2>
          <p className="mt-2 text-sm leading-6 text-muted-foreground">
            This surface consumes tokens indirectly through utilities.
          </p>
        </article>
      );
    }
    ```
  </Step>

  <Step>
    ### Extend only when the system needs it

    Not every visual value needs to become a token on day one.

    A new token should exist when it:

    * appears in multiple places
    * expresses a reusable product decision
    * improves theming or consistency
    * reduces duplicated local styling
    * makes future changes safer

    <Callout type="info" title="System rule">
      Tokenize repeated design decisions, not one-off visual preferences.
    </Callout>
  </Step>
</Steps>

## Token categories

PyColors intentionally starts with a small token surface. That keeps the system understandable and avoids token sprawl too early.

| Category   | Purpose                                           | Current status |
| ---------- | ------------------------------------------------- | -------------- |
| Radius     | Corner geometry for controls, cards, and overlays | Active         |
| Shadows    | Elevation for surfaces and floating layers        | Active         |
| Colors     | Semantic surface, text, state, and chart roles    | Active         |
| Typography | Font roles, hierarchy, labels, and density        | Active         |
| Spacing    | Product layout rhythm and density                 | Future         |
| Motion     | Transitions, easing, and interaction feel         | Future         |
| Z-index    | Layering rules for overlays and navigation        | Future         |

<Callout title="Why the surface is intentionally small">
  A smaller token system is easier to understand, document, and maintain.
  PyColors adds tokens when they clarify the system, not when they create extra
  vocabulary.
</Callout>

## Decision guide

Use a token when:

* the value appears across multiple components
* changing it globally would be useful
* the value carries product meaning
* it improves consistency across light and dark mode
* it prevents teams from inventing local alternatives

Avoid creating a token when:

* the value is purely decorative
* it only appears once
* the name would be vague
* the token duplicates an existing role
* it makes the system harder to understand

<PreferAvoid
  prefer={[
  "tokens for repeated visual decisions",
  "semantic names that describe intent",
  "centralized values exposed through utilities",
  "small scales that are easy to remember",
  "documentation that explains when to use each token",
]}
  avoid={[
  "tokenizing every one-off value",
  "names that describe appearance only",
  "duplicating existing semantic roles",
  "hardcoding token values inside components",
  "adding scales before the product needs them",
]}
/>

### Token flow

<Tabs items={["Model", "Component"]}>
  <Tab value="Model">
    <div className="rounded-2xl border border-border/60 bg-card p-6">
      <div className="grid gap-4 md:grid-cols-4">
        <div>
          <div className="flex h-8 w-8 items-center justify-center rounded-md bg-primary/10 text-xs font-medium text-primary">
            1
          </div>

          <div className="mt-3 text-sm font-medium text-foreground">
            Decision
          </div>

          <div className="mt-2 text-sm leading-6 text-muted-foreground">
            The system needs a consistent corner feel.
          </div>
        </div>

        <div>
          <div className="flex h-8 w-8 items-center justify-center rounded-md bg-primary/10 text-xs font-medium text-primary">
            2
          </div>

          <div className="mt-3 text-sm font-medium text-foreground">
            Token
          </div>

          <div className="mt-2 text-sm leading-6 text-muted-foreground">
            `--radius-lg` defines the shared geometry.
          </div>
        </div>

        <div>
          <div className="flex h-8 w-8 items-center justify-center rounded-md bg-primary/10 text-xs font-medium text-primary">
            3
          </div>

          <div className="mt-3 text-sm font-medium text-foreground">
            Utility
          </div>

          <div className="mt-2 text-sm leading-6 text-muted-foreground">
            `rounded-lg` exposes the token to components.
          </div>
        </div>

        <div>
          <div className="flex h-8 w-8 items-center justify-center rounded-md bg-primary/10 text-xs font-medium text-primary">
            4
          </div>

          <div className="mt-3 text-sm font-medium text-foreground">
            Surface
          </div>

          <div className="mt-2 text-sm leading-6 text-muted-foreground">
            Cards, dialogs, and panels feel related.
          </div>
        </div>
      </div>
    </div>
  </Tab>

  <Tab value="Component">
    ```tsx title="components/settings-card.tsx"
    export function SettingsCard() {
      return (
        <section className="rounded-lg border border-border bg-card p-6 shadow-sm">
          <div className="flex items-center gap-2">
            <CircleDot className="h-4 w-4 text-primary" />
            <h2 className="text-sm font-medium text-foreground">
              Workspace settings
            </h2>
          </div>
          <p className="mt-2 text-sm leading-6 text-muted-foreground">
            The component consumes tokens through semantic utilities.
          </p>
        </section>
      );
    }
    ```
  </Tab>
</Tabs>

## Start here

<DocsLinks
  variant="compact"
  tone="platform"
  items={[
  {
    title: "Radius",
    href: "/docs/design-system/tokens/radius",
    description:
      "Understand the corner geometry used across controls, cards, and overlays.",
    icon: Ruler,
  },
  {
    title: "Shadows",
    href: "/docs/design-system/tokens/shadows",
    description:
      "Learn how elevation creates calm, predictable depth across surfaces.",
    icon: Layers3,
  },
]}
/>

## Common questions

<Accordions type="single">
  <Accordion title="Are tokens the same as Tailwind utilities?">
    No. Tokens define the value and intent. Utilities expose those tokens to components. A component should consume the utility, not hardcode the raw value.
  </Accordion>

  <Accordion title="Should every design value become a token?">
    No. Tokens should represent repeated system decisions. Tokenizing every value
    too early creates complexity without improving consistency.
  </Accordion>

  <Accordion title="Can I customize the token values?">
    Yes. The goal is to keep the public roles stable while allowing the underlying values to change. This gives you theme flexibility without rewriting components.
  </Accordion>
</Accordions>

## Next steps

<DocsLinks
  variant="grid"
  tone="platform"
  items={[
  {
    title: "Colors",
    href: "/docs/design-system/colors",
    description:
      "Learn how semantic color roles extend the same token logic across surfaces, text, and states.",
    icon: Palette,
  },
  {
    title: "Theme Builder",
    href: "/tools/theme-builder",
    description:
      "Generate semantic CSS overrides to place after the public token stylesheet import.",
    icon: ArrowRight,
  },
  {
    title: "Typography",
    href: "/docs/design-system/typography",
    description:
      "Review hierarchy, font roles, labels, and readable product structure.",
    icon: Type,
  },
  {
    title: "UI Components",
    href: "/docs/ui",
    description:
      "Move from foundations to reusable primitives built on the token system.",
    icon: Blocks,
  },
  {
    title: "Why PyColors UI",
    href: "/docs/ui/why-pycolors-ui",
    description:
      "Understand the philosophy and trade-offs behind the component system.",
    icon: Sparkles,
  },
]}
/>