/*
 * loom-tokens.css -- the Loom design-system token vocabulary.
 *
 * This is the SHARED CONTRACT every Loom package and project styles
 * against: a small, stable set of `--loom-*` CSS custom properties.
 * Packages (The Stacks, The Round Table, …) reference these tokens; a
 * project sets them once and every package inherits the look.
 *
 * The values below are the DEFAULT GRAYSCALE THEME -- a deliberately
 * neutral skin so anything ships looking coherent before a project does
 * any theming. It is the skin, not the standard: override any token by
 * redefining it under `:root` in your own stylesheet (loaded after this
 * one). The vocabulary (the token NAMES + meanings) is the standard and
 * is intended to stay small and stable; add project-specific tokens in
 * your own namespace, not here.
 *
 * Override example (a project's own theme.css, loaded after this file):
 *   :root { --loom-accent: #3b82f6; --loom-accent-text: #fff; --loom-radius: 4px; }
 *
 * LIGHT THEME: a second, medium-light skin lives in the
 * `:root[data-theme="light"]` block at the bottom of this file. It is opt-in
 * and SELECTABLE — set `data-theme="light"` on <html> to switch. The shared
 * runtime `loom-theme.js` manages a three-state preference (auto / light /
 * dark), persists it, and follows the OS when set to auto. Bare `:root` (no
 * attribute, or `data-theme="dark"`) is the medium-dark default. The light
 * block only overrides the tokens that genuinely differ; unlisted tokens
 * (fonts, radius) cascade from the default. Project overrides still belong in
 * your own stylesheet, loaded after this file.
 */

/* The Loom icon standard (.loom-icon, Tabler sprite). @import must precede the
   font-faces below; it pulls the icon rules in for every surface that loads the
   tokens. (Surfaces that don't load tokens point their own icon-CSS slot at
   loom-icons.css directly — see the-stacks.) */
@import "loom-icons.css";

/* ── Brand typography (self-hosted, OFL) ───────────────────────────────
   System 1: Manrope = identity (wordmark + headings), Inter = communication
   (body + UI), JetBrains Mono = building (code). Self-hosted woff2 under
   fonts/ — no external CDN. font-display:swap so text paints immediately in
   the fallback and re-renders when the face loads. */
@font-face{font-family:'Manrope';font-style:normal;font-weight:500;font-display:swap;src:url('fonts/manrope-500.woff2') format('woff2')}
@font-face{font-family:'Manrope';font-style:normal;font-weight:600;font-display:swap;src:url('fonts/manrope-600.woff2') format('woff2')}
@font-face{font-family:'Inter';font-style:normal;font-weight:400;font-display:swap;src:url('fonts/inter-400.woff2') format('woff2')}
@font-face{font-family:'Inter';font-style:normal;font-weight:500;font-display:swap;src:url('fonts/inter-500.woff2') format('woff2')}
@font-face{font-family:'Inter';font-style:normal;font-weight:600;font-display:swap;src:url('fonts/inter-600.woff2') format('woff2')}
@font-face{font-family:'Inter';font-style:normal;font-weight:700;font-display:swap;src:url('fonts/inter-700.woff2') format('woff2')}
@font-face{font-family:'JetBrains Mono';font-style:normal;font-weight:400;font-display:swap;src:url('fonts/jetbrains-mono-400.woff2') format('woff2')}

:root {
    /* ── Surfaces ──────────────────────────────────────────────────── */
    --loom-bg:           #131314;   /* page background (furthest back)   */
    --loom-surface:      #1c1c1f;   /* raised panels, cards, inputs      */
    --loom-line:         #2e2e32;   /* borders, dividers, hairlines      */

    /* ── Text ──────────────────────────────────────────────────────── */
    --loom-text:         #e8e8ea;   /* primary text                      */
    --loom-muted:        #9a9aa0;   /* secondary / de-emphasized text    */

    /* Deeper surfaces (raised levels above --loom-surface) + hover state. */
    --loom-surface-2:    #232327;   /* nested panels, popovers, menus     */
    --loom-surface-hover:#2a2a2e;   /* hover/active row background        */

    /* Text depth: --loom-faint is the dimmest (timestamps, hints). */
    --loom-faint:        #76767c;   /* tertiary / faint text             */

    /* ── Brand / accent ────────────────────────────────────────────── */
    /* --loom-accent is a neutral light-gray by default -- projects override
       it with their brand color. --loom-accent-text is the readable
       foreground used ON TOP of a filled accent (buttons, badges).
       --loom-info is the shared CHROMATIC accent (links, focus, primary
       action) -- a real blue so surfaces aren't forced to a gray accent.
       --loom-text-inverse is white text ON saturated colored fills.
       --loom-info-fill is a SEPARATE, deeper blue for info-colored FILLS
       that carry --loom-text-inverse (primary buttons, active nav): on the
       dark skin --loom-info is intentionally a lighter blue so LINKS read on
       the near-black page (AA), which leaves white-on-it at only 3.26:1 — so
       fills use this darker shade instead (white-on-it = 5.17:1, AA). On the
       light skin the two coincide (#2563eb), so light inherits this value. */
    --loom-accent:       #c8c8cc;
    --loom-accent-text:  #131314;
    --loom-info:         #4f8cf8;   /* links, focus, primary chromatic accent */
    --loom-info-text:    #7fa9fc;   /* lighter, for info text on dark         */
    --loom-info-fill:    #2563eb;   /* deeper blue for fills w/ white text     */
    --loom-info-rgb:     79, 140, 248;   /* for rgba() glows/tints            */
    --loom-text-inverse: #ffffff;   /* text on saturated fills            */

    /* ── Status ────────────────────────────────────────────────────── */
    /* Intentionally muted-but-real hues: a status color rendered in gray
       defeats its purpose. Override to grays if you want a pure-mono UI.
       Each has a -text (lighter, for text on dark) + -rgb (for rgba()
       glows/tints/borders at arbitrary opacity). */
    --loom-ok:           #6fae7e;   /* success / positive                */
    --loom-ok-text:      #8fce9e;
    --loom-ok-rgb:       111, 174, 126;
    --loom-warn:         #c7a76a;   /* warning / caution                 */
    --loom-warn-text:    #dcc28a;
    --loom-warn-rgb:     199, 167, 106;
    --loom-err:          #c77b7b;   /* error / danger                    */
    --loom-err-text:     #e09a9a;
    --loom-err-rgb:      199, 123, 123;

    /* ── Feature accents ───────────────────────────────────────────── */
    /* Promoted from The Round Table so any surface can use a small palette
       of distinct accents (rooms, type badges, references). Each has a
       -text + -rgb companion like the status colors. */
    --loom-purple:       #a855f7;   --loom-purple-text:  #c084fc;  --loom-purple-rgb:  168, 85, 247;
    --loom-teal:         #38bdf8;   --loom-teal-text:    #7dd3fc;  --loom-teal-rgb:    56, 189, 248;
    --loom-indigo:       #818cf8;   --loom-indigo-text:  #a5b4fc;  --loom-indigo-rgb:  99, 102, 241;
    --loom-gold:         #c7a76a;   --loom-gold-text:    #d8bd8a;  --loom-gold-rgb:    201, 168, 124;
    --loom-rose:         #f472b6;   --loom-rose-text:    #f9a8d4;  --loom-rose-rgb:    244, 114, 182;

    /* ── Overlays / elevation ──────────────────────────────────────── */
    /* Black scrims (modals, lightboxes, shadows) + white hover tints +
       a shadow-rgb for box-shadow composition. */
    --loom-scrim:        rgba(0, 0, 0, 0.6);   /* modal/lightbox backdrop */
    --loom-overlay-1:    rgba(0, 0, 0, 0.3);   /* light scrim / soft shadow */
    --loom-overlay-2:    rgba(0, 0, 0, 0.5);
    --loom-overlay-3:    rgba(0, 0, 0, 0.8);   /* heavy scrim             */
    --loom-hover:        rgba(255, 255, 255, 0.05);  /* hover tint        */
    --loom-hover-strong: rgba(255, 255, 255, 0.08);
    --loom-hover-rgb:    255, 255, 255;        /* white-tint composition  */
    --loom-shadow-rgb:   0, 0, 0;              /* rgba(var(--loom-shadow-rgb), .3) */
    --loom-muted-rgb:    154, 154, 160;        /* neutral grey tint/border */

    /* ── Typography (System 1) ─────────────────────────────────────── */
    /* --loom-font       = body + UI (Inter); --loom-font-brand = wordmark +
       headings (Manrope); --loom-font-mono = code (JetBrains Mono). Each keeps
       a system fallback stack so an unstyled/offline load still reads well. */
    --loom-font:         "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --loom-font-brand:   "Manrope", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --loom-font-mono:    "JetBrains Mono", ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;

    /* ── Shape ─────────────────────────────────────────────────────── */
    --loom-radius:       8px;       /* default corner radius             */

    /* ── Scales (added 2026-11-17, graphic-standards.md §9-§11) ────────
       Radius, z-index and shadow are named from the values admin-core already
       renders, so adopting them changes nothing on screen. The type scale
       (--loom-fs-*) is the target, not the current render: admin-core today
       uses nearby sizes (card h3 1.05rem, th .82rem, pill .78rem, label .85rem,
       users h2 1.15rem), and adopting fs-* moves those by up to 1.6px (see the
       2026-11-17 audit). Theme-independent except the shadows, which the
       light skin softens below. */

    /* Corner radius. --loom-radius (8px, above) stays the default. */
    --loom-radius-sm:    4px;       /* code, kbd, focus-ring corners      */
    --loom-radius-md:    6px;       /* buttons, inputs, chips, nav items  */
    --loom-radius-lg:    10px;      /* cards, dialogs, front-door card    */
    --loom-radius-pill:  999px;     /* pills, tags, project chips         */

    /* Type sizes (rem; html stays 16px, body is --loom-fs-base). */
    --loom-fs-xs:        0.75rem;   /* 12px  pills, meta, endorsement     */
    --loom-fs-sm:        0.8125rem; /* 13px  table heads, captions, hints */
    --loom-fs-ui:        0.875rem;  /* 14px  nav, labels, secondary text  */
    --loom-fs-base:      0.9375rem; /* 15px  body text                    */
    --loom-fs-md:        1.0625rem; /* 17px  card titles (h3)             */
    --loom-fs-lg:        1.25rem;   /* 20px  section titles (h2)          */
    --loom-fs-xl:        1.5rem;    /* 24px  page titles (h1)             */
    --loom-lh:           1.5;       /* body                               */
    --loom-lh-tight:     1.25;      /* headings, buttons                  */

    /* Spacing (a 4px base). */
    --loom-space-1:      0.25rem;   /* 4px  */
    --loom-space-2:      0.5rem;    /* 8px  */
    --loom-space-3:      0.75rem;   /* 12px */
    --loom-space-4:      1rem;      /* 16px */
    --loom-space-5:      1.5rem;    /* 24px */
    --loom-space-6:      2rem;      /* 32px */
    --loom-space-7:      3rem;      /* 48px */

    /* Elevation. Black at fixed alphas, composed from --loom-shadow-rgb. */
    --loom-shadow-sm:    0 1px 2px rgba(var(--loom-shadow-rgb), 0.25);    /* raised chip     */
    --loom-shadow-md:    0 8px 22px rgba(var(--loom-shadow-rgb), 0.28);   /* menus, popovers */
    --loom-shadow-lg:    0 8px 32px rgba(var(--loom-shadow-rgb), 0.30);   /* dialogs, front-door card */

    /* Focus: one ring everywhere (WCAG 2.4.7). */
    --loom-focus-width:  2px;
    --loom-focus-offset: 2px;
    --loom-focus-ring:   var(--loom-focus-width) solid var(--loom-info);

    /* Motion. Nothing loops except a working spinner (§9). */
    --loom-dur-fast:     150ms;     /* hover colour, small state flips    */
    --loom-dur:          250ms;     /* disclosure, fades, state changes   */
    --loom-dur-slow:     350ms;     /* dialog / sheet entrances           */
    --loom-ease:         ease;
    --loom-transition:   color var(--loom-dur-fast) var(--loom-ease), background-color var(--loom-dur-fast) var(--loom-ease), border-color var(--loom-dur-fast) var(--loom-ease), box-shadow var(--loom-dur-fast) var(--loom-ease);

    /* States. */
    --loom-disabled-opacity: 0.55;  /* disabled controls (not the working one) */

    /* Stacking. Fix a stacking context before inventing a number. */
    --loom-z-raised:     1;
    --loom-z-sticky:     50;        /* the admin bar                      */
    --loom-z-dropdown:   60;        /* menus that open from the bar       */
    --loom-z-overlay:    900;       /* scrims                             */
    --loom-z-modal:      1000;      /* dialogs                            */
    --loom-z-toast:      1100;      /* transient flash                    */
    --loom-z-skip:       1200;      /* the skip link, always on top       */

    /* Breakpoints can't be custom properties (var() is not allowed in a
       @media query), so they live in graphic-standards.md §10:
       narrow ≤ 640px (the admin bar's hamburger), and
       (pointer: coarse) for 44px touch targets. */
}

/*
 * ════════════════════════════════════════════════════════════════════
 *  LIGHT THEME — the medium-light skin (selectable; mirrors the default).
 *
 *  Applied when <html data-theme="light"> is set (by loom-theme.js or the
 *  inline FOUC stub). This is NOT a mechanical lightness flip: tokens whose
 *  meaning is dark-specific are re-derived, not inverted —
 *    • the `*-text` companions are the LIGHT-mode siblings (DARKER, for text
 *      ON a light surface — the dark theme's were lighter, for text on dark);
 *    • `--loom-hover*` flip from WHITE tints to BLACK tints (a white tint is
 *      invisible on a light surface);
 *    • `--loom-accent` inverts to a dark neutral so it still reads against
 *      the page; status/feature hues are deepened for AA contrast on light.
 *  Medium-light (bg #f3f3f4), deliberately NOT stark white — the mirror of
 *  the default's medium-dark #131314. Only changed tokens appear here; the
 *  rest (fonts, radius) cascade from :root above.
 * ════════════════════════════════════════════════════════════════════ */
:root[data-theme="light"] {
    /* ── Surfaces ──────────────────────────────────────────────────── */
    --loom-bg:           #f3f3f4;   /* page background (furthest back)   */
    --loom-surface:      #ffffff;   /* raised panels, cards, inputs      */
    --loom-line:         #d9d9dd;   /* borders, dividers, hairlines      */

    /* ── Text ──────────────────────────────────────────────────────── */
    --loom-text:         #1b1b1e;   /* primary text (near-black, not #000) */
    --loom-muted:        #5d5d64;   /* secondary  (≈6.5:1 on #fff)       */

    --loom-surface-2:    #f7f7f9;   /* nested panels, popovers, menus     */
    --loom-surface-hover:#ececef;   /* hover/active row background        */

    --loom-faint:        #74747b;   /* tertiary / faint  (≈4.6:1 on #fff) */

    /* ── Brand / accent ────────────────────────────────────────────── */
    /* Accent inverts to a dark neutral so it reads on a light page; its
       readable foreground flips to white. --loom-info deepens to a blue
       that hits AA on white; --loom-info-text is darker still (text on
       light). --loom-text-inverse stays white (it sits on saturated fills). */
    --loom-accent:       #3a3a3e;
    --loom-accent-text:  #ffffff;
    --loom-info:         #2563eb;   /* links, focus, primary chromatic accent */
    --loom-info-text:    #1d4ed8;   /* darker, for info text on light         */
    --loom-info-rgb:     37, 99, 235;
    --loom-text-inverse: #ffffff;

    /* ── Status ────────────────────────────────────────────────────── */
    /* Deepened hues so the color reads as text on a light surface; the
       -text siblings are the on-light text shades, -rgb match the base. */
    --loom-ok:           #2e7d46;
    --loom-ok-text:      #1f7a3d;
    --loom-ok-rgb:       46, 125, 70;
    --loom-warn:         #9a6f15;
    --loom-warn-text:    #845f10;
    --loom-warn-rgb:     154, 111, 21;
    --loom-err:          #c0392b;
    --loom-err-text:     #b32d20;
    --loom-err-rgb:      192, 57, 43;

    /* ── Feature accents ───────────────────────────────────────────── */
    /* Deepened so each reads on a light surface; -text a touch darker. */
    --loom-purple:       #8b35d6;   --loom-purple-text:  #7c2fc0;  --loom-purple-rgb:  139, 53, 214;
    --loom-teal:         #0e7faf;   --loom-teal-text:    #0b6f9a;  --loom-teal-rgb:    14, 127, 175;
    --loom-indigo:       #4f55d6;   --loom-indigo-text:  #4348c0;  --loom-indigo-rgb:  79, 85, 214;
    --loom-gold:         #9a6f15;   --loom-gold-text:    #845f10;  --loom-gold-rgb:    154, 111, 21;
    --loom-rose:         #be185d;   --loom-rose-text:    #9d174d;  --loom-rose-rgb:    190, 24, 93;

    /* ── Overlays / elevation ──────────────────────────────────────── */
    /* Scrims stay black (a dim over content). Hover tints flip WHITE→BLACK
       (a white tint is invisible on light); shadow-rgb stays black. */
    --loom-scrim:        rgba(0, 0, 0, 0.5);
    --loom-overlay-1:    rgba(0, 0, 0, 0.12);
    --loom-overlay-2:    rgba(0, 0, 0, 0.25);
    --loom-overlay-3:    rgba(0, 0, 0, 0.45);
    --loom-hover:        rgba(0, 0, 0, 0.04);
    --loom-hover-strong: rgba(0, 0, 0, 0.07);
    --loom-hover-rgb:    0, 0, 0;
    --loom-shadow-rgb:   0, 0, 0;
    --loom-muted-rgb:    93, 93, 100;

    /* ── Elevation (2026-11-17) ────────────────────────────────────── */
    /* The dark alphas read as smudges on a light page; same geometry, lighter. */
    --loom-shadow-sm:    0 1px 2px rgba(var(--loom-shadow-rgb), 0.08);
    --loom-shadow-md:    0 8px 22px rgba(var(--loom-shadow-rgb), 0.12);
    --loom-shadow-lg:    0 8px 32px rgba(var(--loom-shadow-rgb), 0.14);
}
