/* ═══════════════════════════════════════════════════════════════════════════
   tokens.css — Family Signals design tokens (SINGLE SOURCE OF TRUTH)
   Loaded FIRST, before every other stylesheet.

   Structure:
     1. Primitives     — raw scales (space, type, radius, elevation, motion)
     2. Semantic base  — brand + structural tokens that do NOT change by theme
   Colour VALUES that flip between dark/light live in theme.css, which overrides
   the semantic colour tokens per [data-theme]. Everything here is theme-neutral
   so a token can be referenced anywhere without worrying about load order.

   This file consolidates variables that were previously duplicated across
   base.css and theme.css (20 vars defined twice, same values). Define once here.
   ═══════════════════════════════════════════════════════════════════════════ */
:root {
  /* ── 1a. Spacing scale (4px base) ─────────────────────────────────────── */
  --space-0:   0;
  --space-1:   4px;
  --space-2:   8px;
  --space-3:   12px;
  --space-4:   16px;
  --space-5:   20px;
  --space-6:   24px;
  --space-8:   32px;
  --space-10:  40px;
  --space-12:  48px;
  --space-16:  64px;

  /* ── 1b. Typography ───────────────────────────────────────────────────── */
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body:    'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono:    'DM Mono', ui-monospace, monospace;
  --text-xs:   0.72rem;
  --text-sm:   0.82rem;
  --text-base: 0.94rem;
  --text-md:   1.02rem;
  --text-lg:   1.2rem;
  --text-xl:   1.5rem;
  --text-2xl:  2rem;
  --leading-tight:  1.2;
  --leading-normal: 1.5;
  --leading-loose:  1.7;
  --weight-regular: 400;
  --weight-medium:  500;
  --weight-semibold:600;

  /* ── 1c. Radius scale ─────────────────────────────────────────────────── */
  --radius-sm:   6px;
  --radius:      10px;
  --radius-lg:   16px;
  --radius-xl:   20px;
  --radius-full: 999px;
  /* aliases kept for existing component rules */
  --btn-radius:   8px;
  --card-radius:  20px;
  --node-radius-m:12px;

  /* ── 1d. Elevation (shadow) scale ─────────────────────────────────────── */
  --elevation-1: 0 1px 2px rgba(0,0,0,0.20);
  --elevation-2: 0 2px 8px rgba(0,0,0,0.28);
  --elevation-3: 0 8px 24px rgba(0,0,0,0.35);
  --elevation-4: 0 16px 48px rgba(0,0,0,0.45);

  /* ── 1e. Motion ───────────────────────────────────────────────────────── */
  --transition:      0.18s ease;
  --anim-speed:      0.22s;
  --anim-curve:      cubic-bezier(0.34, 1.56, 0.64, 1);
  --anim-curve-out:  cubic-bezier(0.25, 0.46, 0.45, 0.94);

  /* ── 1f. Structural layout (theme-neutral) ────────────────────────────── */
  --sidebar-w:   210px;
  --inspector-w: 290px;
  --topbar-h:    52px;

  /* ── 1g. Glass surface tokens (used by node cards + panels) ───────────── */
  --glass-blur:      12px;
  --glass-bg:        rgba(19,29,48,0.55);
  --glass-border:    rgba(120,150,210,0.22);
  --glass-highlight: rgba(255,255,255,0.04);
}

/* Respect users who ask for less motion — global, applies everywhere. */
@media (prefers-reduced-motion: reduce) {
  :root { --transition: 0s; --anim-speed: 0s; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;   /* FR-MOB-030: also disable smooth scroll */
  }
  html { scroll-behavior: auto !important; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   FR-MOB-001 — Canonical responsive breakpoints (single source)
   Mirrored in core/device-context.js (BP). Adjust in BOTH places together.

     small mobile     max-width: 374px
     standard mobile  375–480px
     large mobile     481–600px
     tablet           601–1024px
     desktop          min-width: 1025px

   CSS custom properties cannot be used inside @media queries, so these values
   are documented here and written literally in the media queries that use them.
   DeviceContext also exposes them at runtime as <html data-tier="..."> so JS-
   and CSS-driven responsiveness stay on the same numbers.
   ═══════════════════════════════════════════════════════════════════════════ */
:root {
  --bp-small-mobile:    374px;
  --bp-standard-mobile: 480px;
  --bp-large-mobile:    600px;
  --bp-tablet:          1024px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   FR-MOB-021 — Responsive type scale (single source of truth)
   The type tokens above are the desktop scale. Here we REDEFINE their values at
   mobile widths so every element that uses a token scales down automatically,
   while keeping the hierarchy intact (the ratios between steps are preserved,
   just compressed). Components should reference var(--text-*) rather than
   hardcoding sizes — then this block is the ONLY place mobile type is tuned.

   Note: CSS custom properties CAN be reassigned inside a media-query :root;
   elements reading var(--text-xl) then pick up the smaller value with no
   per-component media queries.
   ═══════════════════════════════════════════════════════════════════════════ */

/* Tablet + large mobile (≤600px): gently reduce the large end of the scale. */
@media (max-width: 600px) {
  :root {
    --text-2xl: 1.6rem;   /* 2rem   → 1.6rem  */
    --text-xl:  1.3rem;   /* 1.5rem → 1.3rem  */
    --text-lg:  1.1rem;   /* 1.2rem → 1.1rem  */
    --text-md:  1rem;     /* 1.02rem→ 1rem    */
    /* base/sm/xs stay ~the same — body text should not shrink below comfort. */
    --text-base: 0.94rem;
    --text-sm:   0.82rem;
  }
}

/* Small / standard mobile (≤480px): compress the large headings a touch more,
   preserving the step ratios so H1 still clearly outranks H2 outranks body. */
@media (max-width: 480px) {
  :root {
    --text-2xl: 1.45rem;
    --text-xl:  1.2rem;
    --text-lg:  1.05rem;
  }
}

/* Smallest phones (≤374px): the floor — never shrink body text, only headings. */
@media (max-width: 374px) {
  :root {
    --text-2xl: 1.3rem;
    --text-xl:  1.12rem;
  }
}
