/* Copyright (c) Cratis. All rights reserved. */
/* Licensed under the MIT license. See LICENSE file in the project root for full license information. */

/*
 * Scene design-system anatomy -> Cratis Components CSS variables.
 *
 * `@cratis/components` reads a `--cratis-*` variable layer (its own `tokens.css`) rather than
 * PrimeReact's variables directly, so that one build works across PrimeReact major versions: each token
 * resolves the PrimeReact 11 design token first and falls back to the legacy version 10 theme variable.
 * That indirection is the seam this file plugs into.
 *
 * Scene components take their look from a design system's anatomy: "my `primary` variant's `background`
 * in `hover`". `SceneThemeProvider` writes that anatomy onto its wrapping element as
 * `--ds-<component>-<variant>-<part>[-<state>]` custom properties. This stylesheet inserts those in front
 * of the library's own chain, so a design system drives `@cratis/components` without either side knowing
 * the other exists: Scene never learns what `--cratis-surface-card` is, and the library never learns what
 * a design system is. No rule here names a token of a design system - only the anatomy of the components
 * the library draws (Shell, Card, Menu, Button, Text).
 *
 *   --cratis-surface-card: var(--ds-card-default-background, var(--p-content-background, var(--surface-card)));
 *                              ^ design-system anatomy     ^ PrimeReact v11        ^ v10 legacy
 *
 * Three consequences worth stating, because each one is a decision:
 *
 * - The anatomy value is only a *first* preference. Every mapping keeps the library's original fallback
 *   chain behind it, so a design system that gives a component fewer parts leaves the others exactly as
 *   the active PrimeReact theme had them, rather than blanking them.
 *
 * - The rules are scoped to the element a design is applied to, never to `:root`. `applyDesign` writes
 *   onto the `SceneThemeProvider`'s element, so `--ds-*` does not exist at the document root; a `:root`
 *   rule here would resolve every mapping to nothing and wipe out the PrimeReact fallbacks this file is
 *   supposed to preserve. Both attributes are matched because a host may apply a design through
 *   `applyDesign` directly (`data-scene-theme`) rather than through the provider
 *   (`data-scene-theme-root`).
 *
 * - Only what the library draws is mapped. `--cratis-primary-500`, `--cratis-green-500` and the rest of
 *   the primitive palette are left untouched, so they keep resolving against the PrimeReact theme.
 *   Inventing anatomy for them would be asserting parts the design systems on the other side do not have.
 */

[data-scene-theme-root],
[data-scene-theme] {
    /* Surfaces: the card, the page canvas, the menu's hover and the popover */
    --cratis-surface-0: var(--ds-card-default-background, var(--p-surface-0, var(--surface-0)));
    --cratis-surface-100: var(--ds-menu-default-background-hover, var(--p-surface-100, var(--surface-100)));
    --cratis-surface-ground: var(--ds-page-default-background, var(--p-content-background, var(--surface-ground)));
    --cratis-surface-section: var(--ds-menu-default-background-hover, var(--p-content-hover-background, var(--surface-section)));
    --cratis-surface-card: var(--ds-card-default-background, var(--p-content-background, var(--surface-card)));
    --cratis-surface-overlay: var(--ds-popover-default-background, var(--p-overlay-modal-background, var(--surface-overlay)));
    --cratis-surface-hover: var(--ds-menu-default-background-hover, var(--p-content-hover-background, var(--surface-hover)));
    --cratis-surface-border: var(--ds-card-default-border, var(--p-content-border-color, var(--surface-border)));

    /* Text */
    --cratis-text-color: var(--ds-text-default-text, var(--p-text-color, var(--text-color)));
    --cratis-text-color-secondary: var(--ds-text-muted-text, var(--p-text-muted-color, var(--text-color-secondary)));

    /* Primary brand: the primary button */
    --cratis-primary-color: var(--ds-button-primary-background, var(--p-primary-color, var(--primary-color)));
    --cratis-primary-color-text: var(--ds-button-primary-text, var(--p-primary-contrast-color, var(--primary-color-text)));

    /* Highlight / selection: the selected menu item */
    --cratis-highlight-bg: var(--ds-menu-default-background-selected, var(--p-highlight-background, var(--highlight-bg)));
    --cratis-highlight-text-color: var(--ds-menu-default-text-selected, var(--p-highlight-color, var(--highlight-text-color)));

    /* Geometry */
    --cratis-border-radius: var(--ds-card-default-radius, var(--p-content-border-radius, var(--border-radius)));

    /* Effects: the keyboard focus indicator */
    --cratis-focus-ring: var(--ds-button-primary-shadow-focus, var(--p-focus-ring-shadow, var(--focus-ring)));
}
