/*
    Design tokens — the single source of truth for colour, spacing and type.

    Two rules govern everything in this file and every stylesheet that consumes it:

      1. NO hardcoded colours outside this file. Components reference var(--bb-*) only, so a
         theme change is a token swap rather than a search-and-replace (F20 §3).

      2. NO physical direction properties anywhere. Use margin-inline-start, not margin-left;
         inset-inline-end, not right; text-align: start, not left. This is what makes Arabic RTL
         a single dir attribute instead of a stylesheet rewrite (F19 §5), and it is enforced by
         SourceConventionTests — a physical property fails the build.

    P11 replaces the fixed values below with the admin-configurable Theme entity.
*/

:root {
    /* Night Show entry and receiver chrome. Values match BrandPalette in Contracts. */
    --bb-night-field: #12102E;
    --bb-night-surface: #221D55;
    --bb-night-border: #746CB4;
    --bb-night-text: #F7F5FF;
    --bb-night-muted: #B9B4DC;
    --bb-night-mint: #3DDCB0;
    --bb-night-gold: #FFC23D;
    --bb-night-ink: #17132F;
    --bb-night-coral: #FF6B81;
    --bb-screen-bg: var(--bb-night-field);
    --bb-screen-fg: var(--bb-night-text);

    /* ---- Brand ------------------------------------------------------------------- */
    --bb-color-primary: #6D28D9; /* P21 violet — white on it 7.10:1, as text on white 7.10:1 */
    --bb-color-secondary: #2E86DE;
    --bb-color-accent: #F2A900;

    /* ---- Surfaces ---------------------------------------------------------------- */
    --bb-color-surface: #FFFFFF;
    --bb-color-surface-alt: #F5F7FA;
    --bb-color-border: #DCE1E7;
    --bb-color-text: #14181D;
    --bb-color-text-muted: #5B6672;
    /* The licensed cyan option artwork needs dark text, independently of page surfaces. */
    --bb-option-art-text: #14181D;

    /* ---- Status ------------------------------------------------------------------ */
    --bb-color-success: #1E8E3E;
    --bb-color-warning: #F2A900;
    --bb-color-danger: #C5221F;
    --bb-color-info: #2E86DE;

    /*  ---- Teams -------------------------------------------------------------------
        Blue and amber, never red and green: roughly 8% of men cannot distinguish the
        latter, and the entire game is "which team owns this hex" (F20 §4). Pattern fills
        accompany these on the board so ownership survives greyscale too. */
    --bb-team-1: #2373C8;
    --bb-team-2: #E49504;
    --bb-team-3: #8E44AD;
    --bb-team-4: #16A085;

    /* ---- Board ------------------------------------------------------------------- */
    --bb-hex-unclaimed: #E1E6EA;
    --bb-occupy-unclaimed: #221D55;
    --bb-occupy-letter: #F7F5FF;
    --bb-occupy-edge: #12102E;
    --bb-hex-active: #FDEFCA;
    --bb-hex-blocked: #919FAC;
    --bb-hex-stroke: #B4BCC5;

    /* P36 -- the seated rim of a tile, from referenceart/game_mockup2.jpg. Dark navy rather than
       neutral grey: on the reference board the edge reads as the shadowed side of a moulded piece,
       and a grey rim over a blue tile looks like a border instead. */
    --bb-hex-edge: rgba(12, 30, 56, 0.55);

    /* P36 -- the field the board sits on, from referenceart/game_mockup2.jpg: a royal blue ground
       carrying the confetti, not the near-black the projector used and not the page surface the
       landing card inherited. One token, because the TV, the phone and the demo card draw the same
       GameScreen and the art is one game, not three. Deep enough that the screen's white chrome
       clears AA on it. */
    --bb-board-field: #134FA5;
    --bb-hex-active-stroke: #F2A900;
    --bb-pick-hint: #7DF6FF;
    --bb-hex-letter: #16283F;

    /* ---- Spacing scale ----------------------------------------------------------- */
    --bb-space-1: 0.25rem;
    --bb-space-2: 0.5rem;
    --bb-space-3: 0.75rem;
    --bb-space-4: 1rem;
    --bb-space-5: 1.5rem;
    --bb-space-6: 2rem;
    --bb-space-8: 3rem;

    /* ---- Radii & elevation -------------------------------------------------------- */
    --bb-radius-sm: 4px;
    --bb-radius-md: 6px;
    --bb-radius-lg: 12px;
    --bb-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.08);
    --bb-shadow-2: 0 4px 12px rgba(0, 0, 0, 0.12);

    /* ---- Type -------------------------------------------------------------------- */

    /*  The Arabic families are in the BASE stack, not only in the :lang(ar) rule below.

        A browser resolves font-family per glyph, not per element, so listing them here is what
        gives an Arabic glyph a defined face when it appears inside an otherwise-Latin page. That
        is not a rare case: dir and lang are set on question and clue containers only, while team
        names, player names and the buzz order are typed by people and can be in either script on
        any surface. <bdi> fixes the order those glyphs appear in; this is what decides how they
        look (11.A.4, 11.B.1).

        Latin-first ordering matters — the first family containing a given glyph wins, so Latin
        text still renders in the Latin face and only the Arabic glyphs fall through. */
    --bb-font-sans:
        system-ui, -apple-system, "Segoe UI", "Helvetica Neue", "Noto Sans", Arial,
        "Noto Sans Arabic", Tahoma,
        sans-serif;

    /*  Arabic-first, for surfaces the session itself is in. Segoe UI covers Arabic on Windows and
        is listed second so a corporate handset needs no download at all. */
    --bb-font-arabic: "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;

    /*  Display face for the projector's largest text. Kufi is a headline style and is wrong for
        body copy, so it is a separate token rather than part of the stack above. */
    --bb-font-arabic-display: "Noto Kufi Arabic", "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif;

    /*  Display face for headings and scores on the lean surfaces (P21.B). Latin-first for the
        same per-glyph reason as --bb-font-sans; falls to the Arabic display face, then system. */
    --bb-font-display-primary: "Baloo 2", "Baloo Bhaijaan 2";
    --bb-font-display: var(--bb-font-display-primary), var(--bb-font-arabic-display);

    --bb-font-scale: 1;

    /* ---- Motion ------------------------------------------------------------------ */
    --bb-transition-fast: 120ms ease;
    --bb-transition-base: 200ms ease;

    /* Mirror Contracts/Presentation/MotionTokens.cs. */
    --bb-motion-appear: 300ms;
    --bb-motion-settle: 240ms;
    --bb-motion-emphasise: 520ms;
    --bb-motion-warn: 460ms;
    --bb-motion-fail: 420ms;
    --bb-motion-celebrate: 700ms;
    --bb-motion-transition: 300ms;
    --bb-motion-tick: 100ms;
    --bb-ease-standard: cubic-bezier(0.2, 0, 0, 1);
    --bb-ease-decelerate: cubic-bezier(0.05, 0.7, 0.1, 1);
    --bb-ease-accelerate: cubic-bezier(0.3, 0, 0.8, 0.15);
    --bb-ease-overshoot: cubic-bezier(0.2, 1.5, 0.4, 1);
    --bb-ease-breathe: cubic-bezier(0.42, 0, 0.58, 1);
    --bb-loop-urgent: 1000ms;
    --bb-loop-pulse: 1600ms;
    --bb-loop-breathe: 2400ms;
    --bb-loop-drift: 6000ms;
    --bb-loop-shake: 300ms;
}

/*  Root for a whole-document theme (the lean surfaces), or any scope element carrying the
    attribute — BareLayout sets it on <main> when MudBlazor is in dark mode, which is what keeps
    the token layer and the MudBlazor palette from disagreeing about the page behind the
    components (found by the dark-mode axe run: a light token background under dark Mud content). */
:root[data-theme="dark"],
[data-theme="dark"] {
    --bb-color-surface: #161B22;
    --bb-color-surface-alt: #0E1116;
    --bb-color-border: #2B3440;
    --bb-color-text: #F5F7FA;
    --bb-color-text-muted: #9AA5B1;

    --bb-color-primary: #A78BFA; /* P21 — on dark surface 6.36:1 */
    --bb-color-secondary: #5AA9F0;

    --bb-hex-unclaimed: #1B2430;
    --bb-hex-active: #3A3320;
    --bb-hex-blocked: #39424E;
    --bb-hex-stroke: #2B3440;

    /* Dark theme: the rim goes nearly black so tiles still separate from a dark field, and the
       glyph on a pale tile goes darker still for the same reason it is light on a claimed one. */
    --bb-hex-edge: rgba(0, 0, 0, 0.62);
    --bb-hex-letter: #0B1622;
}

/*  ---- Presentation tiers ---------------------------------------------------------
    How strongly a recorded beat is felt. A beat's root element carries data-beat-tier (minor,
    notable, major or climax), which resolves to three properties every consequence reads: how far
    it overshoots on entry, how much it glows, and how long it takes. A new layer gets matching
    weight by declaring its tier on the server, not by styling itself. Motion is brief and returns
    to rest; reduced motion keeps the colour, glow and text and drops the movement. */
:root {
    --bb-beat-glow-rgb: 141 241 193; /* #8DF1C1 as channels, so a tier can scale its alpha */
    --bb-beat-minor-scale: 1;     --bb-beat-minor-glow: 0;    --bb-beat-minor-duration: 300ms;
    --bb-beat-notable-scale: 1.03; --bb-beat-notable-glow: .35; --bb-beat-notable-duration: 420ms;
    --bb-beat-major-scale: 1.08;  --bb-beat-major-glow: .65;  --bb-beat-major-duration: 560ms;
    --bb-beat-climax-scale: 1.15; --bb-beat-climax-glow: 1;   --bb-beat-climax-duration: 800ms;
    --bb-beat-minor-particles: 0;
    --bb-beat-notable-particles: 6;
    --bb-beat-major-particles: 12;
    --bb-beat-climax-particles: 24;
}

[data-beat-tier="minor"] { --beat-scale: var(--bb-beat-minor-scale); --beat-glow: var(--bb-beat-minor-glow); --beat-duration: var(--bb-beat-minor-duration); }
[data-beat-tier="notable"] { --beat-scale: var(--bb-beat-notable-scale); --beat-glow: var(--bb-beat-notable-glow); --beat-duration: var(--bb-beat-notable-duration); }
[data-beat-tier="major"] { --beat-scale: var(--bb-beat-major-scale); --beat-glow: var(--bb-beat-major-glow); --beat-duration: var(--bb-beat-major-duration); }
[data-beat-tier="climax"] { --beat-scale: var(--bb-beat-climax-scale); --beat-glow: var(--bb-beat-climax-glow); --beat-duration: var(--bb-beat-climax-duration); }

/* Stamped CSS clips hold until recordedAnimations sets their document-timeline anchor.
   A clip may declare its animation with an inline shorthand. The controller resumes
   playback through the Web Animations API. Unstamped ambient animations run normally. */
[data-presentation-start][data-presentation-end] { animation-play-state: paused !important; }

/* Ambient loops yield to the recorded board action and keep their current pose. */
:is([data-board-resolving], [data-board-retained]) [data-board-ambient] {
    animation-play-state: paused !important;
}

/*  Arabic uses a taller line box than Latin at the same size; without this, Arabic text in
    dense admin grids clips its ascenders. */
:root:lang(ar),
[dir="rtl"] {
    --bb-font-sans: var(--bb-font-arabic);
    line-height: 1.75;
}

@media (prefers-reduced-motion: reduce) {
    :root {
        --bb-transition-fast: 0ms;
        --bb-transition-base: 0ms;
    }
}
