/* =========================================================================
   MacroKey — Design Tokens
   Shared by the marketing website (apps/web) and the desktop app (app/).
   This is the single source of truth for color, type, spacing, radius,
   elevation and motion. Everything downstream references these variables.

   Theme model:
     :root                         -> light palette (default)
     @media (prefers-color-scheme) -> dark palette when system prefers dark
     [data-theme="dark"|"light"]   -> explicit user override (wins over system)
   ========================================================================= */

:root {
  /* ---- Brand ---------------------------------------------------------- */
  --mk-violet:        #7c5cff;
  --mk-violet-600:    #6d4df5;
  --mk-violet-700:    #5a3fe0;
  --mk-cyan:          #35d0e0;
  --mk-pink:          #ff5c9d;
  --mk-lime:          #b6f36b;

  --grad-brand:  linear-gradient(135deg, #7c5cff 0%, #6d4df5 45%, #35d0e0 100%);
  --grad-brand-soft: linear-gradient(135deg, rgba(124,92,255,.16), rgba(53,208,224,.14));
  --grad-sheen:  linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,0));

  /* ---- Typography ----------------------------------------------------- */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --fs-3xs: .6875rem;   /* 11 */
  --fs-2xs: .75rem;     /* 12 */
  --fs-xs:  .8125rem;   /* 13 */
  --fs-sm:  .875rem;    /* 14 */
  --fs-md:  1rem;       /* 16 */
  --fs-lg:  1.125rem;   /* 18 */
  --fs-xl:  1.375rem;   /* 22 */
  --fs-2xl: 1.75rem;    /* 28 */
  --fs-3xl: 2.25rem;    /* 36 */
  --fs-display: clamp(2.5rem, 1.4rem + 4.6vw, 4.25rem);
  --fs-hero-sub: clamp(1.0625rem, .95rem + .55vw, 1.375rem);

  --lh-tight: 1.12;
  --lh-snug:  1.32;
  --lh-body:  1.62;

  --fw-regular: 400;
  --fw-medium:  500;
  --fw-semibold:600;
  --fw-bold:    700;
  --fw-black:   800;

  --tracking-tight: -0.02em;
  --tracking-wide:  0.02em;
  --tracking-caps:  0.14em;

  /* ---- Spacing scale (4px base) -------------------------------------- */
  --sp-1: .25rem;  --sp-2: .5rem;   --sp-3: .75rem;  --sp-4: 1rem;
  --sp-5: 1.25rem; --sp-6: 1.5rem;  --sp-7: 2rem;    --sp-8: 2.5rem;
  --sp-9: 3rem;    --sp-10: 4rem;   --sp-12: 5rem;   --sp-14: 6rem;
  --sp-16: 8rem;

  /* ---- Radius --------------------------------------------------------- */
  --r-xs: 5px; --r-sm: 8px; --r-md: 11px; --r-lg: 16px; --r-xl: 22px;
  --r-2xl: 30px; --r-full: 999px;

  /* ---- Layout --------------------------------------------------------- */
  --container: 1180px;
  --container-wide: 1320px;
  --header-h: 68px;

  /* ---- Motion --------------------------------------------------------- */
  --ease: cubic-bezier(.22,.61,.36,1);
  --ease-out: cubic-bezier(.16,1,.3,1);
  --ease-spring: cubic-bezier(.34,1.56,.64,1);
  --dur-1: 120ms; --dur-2: 200ms; --dur-3: 320ms; --dur-4: 520ms;

  /* ---- Z-index -------------------------------------------------------- */
  --z-base: 1; --z-sticky: 100; --z-header: 200; --z-drawer: 300;
  --z-modal: 400; --z-toast: 500; --z-tooltip: 600;

  /* =====================================================================
     LIGHT PALETTE (default)
     ===================================================================== */
  --bg:            #f6f7fb;
  --bg-2:          #eef0f7;
  --bg-elevated:   #ffffff;
  --surface:       #ffffff;
  --surface-2:     #f4f5fa;
  --surface-3:     #eceef6;
  --surface-inset: #f0f2f8;

  --border:        #e4e7f0;
  --border-strong: #d3d8e6;
  --border-faint:  #eef0f6;

  --text:          #171a24;
  --text-muted:    #565d70;
  --text-faint:    #6b7186;   /* AA-compliant for small text on --bg */
  --text-oncolor:  #ffffff;

  --primary:       #6d4df5;
  --primary-hover: #5d3ded;
  --primary-press: #5233dd;
  --primary-soft:  rgba(109,77,245,.10);
  --primary-softer:rgba(109,77,245,.055);
  --on-primary:    #ffffff;
  --ring:          rgba(109,77,245,.42);

  --success:   #14a06a;
  --success-soft: rgba(20,160,106,.12);
  --danger:    #e0355b;
  --danger-soft:  rgba(224,53,91,.10);
  --warning:   #9a5f00;   /* AA-compliant when used as small text (.badge-warning) */
  --warning-soft: rgba(154,95,0,.12);
  --info:      #1f8fb0;
  --info-soft: rgba(31,143,176,.12);

  --shadow-color: 220 40% 22%;
  --shadow-xs: 0 1px 2px hsl(var(--shadow-color) / .08);
  --shadow-sm: 0 1px 2px hsl(var(--shadow-color) / .08), 0 2px 4px hsl(var(--shadow-color) / .06);
  --shadow-md: 0 4px 10px hsl(var(--shadow-color) / .09), 0 10px 24px hsl(var(--shadow-color) / .10);
  --shadow-lg: 0 12px 28px hsl(var(--shadow-color) / .14), 0 30px 60px hsl(var(--shadow-color) / .16);
  --shadow-glow: 0 8px 30px rgba(109,77,245,.30);
  --shadow-key: inset 0 -3px 0 rgba(19,22,34,.14), 0 2px 3px hsl(var(--shadow-color) / .16);

  --keycap-bg: linear-gradient(180deg, #ffffff, #eef0f6);
  --keycap-border: #d6dae6;

  color-scheme: light;
}

/* =======================================================================
   DARK PALETTE — via system preference (no explicit override set)
   ======================================================================= */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0a0c12;
    --bg-2:          #0d0f17;
    --bg-elevated:   #12151f;
    --surface:       #141721;
    --surface-2:     #1a1e2b;
    --surface-3:     #222736;
    --surface-inset: #0e111a;

    --border:        #262c3b;
    --border-strong: #363d51;
    --border-faint:  #1c212e;

    --text:          #e8eaf2;
    --text-muted:    #a2a9bd;
    --text-faint:    #8992a8;
    --text-oncolor:  #ffffff;

    --primary:       #8368ff;
    --primary-hover: #937cff;
    --primary-press: #7a5cff;
    --primary-soft:  rgba(131,104,255,.16);
    --primary-softer:rgba(131,104,255,.09);
    --on-primary:    #ffffff;
    --ring:          rgba(131,104,255,.55);

    --success:   #3ddc97;
    --success-soft: rgba(61,220,151,.14);
    --danger:    #ff6584;
    --danger-soft:  rgba(255,101,132,.14);
    --warning:   #ffb454;
    --warning-soft: rgba(255,180,84,.14);
    --info:      #4fd6e8;
    --info-soft: rgba(79,214,232,.14);

    --shadow-color: 232 60% 3%;
    --shadow-xs: 0 1px 2px rgba(0,0,0,.5);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.5), 0 2px 6px rgba(0,0,0,.4);
    --shadow-md: 0 6px 16px rgba(0,0,0,.5), 0 12px 32px rgba(0,0,0,.44);
    --shadow-lg: 0 16px 40px rgba(0,0,0,.6), 0 34px 70px rgba(0,0,0,.5);
    --shadow-glow: 0 10px 40px rgba(131,104,255,.42);
    --shadow-key: inset 0 -3px 0 rgba(0,0,0,.5), 0 2px 4px rgba(0,0,0,.5);

    --keycap-bg: linear-gradient(180deg, #232838, #1a1e2b);
    --keycap-border: #3a4257;

    color-scheme: dark;
  }
}

/* =======================================================================
   DARK PALETTE — explicit override (toggle wins in both directions)
   ======================================================================= */
:root[data-theme="dark"] {
  --bg:            #0a0c12;
  --bg-2:          #0d0f17;
  --bg-elevated:   #12151f;
  --surface:       #141721;
  --surface-2:     #1a1e2b;
  --surface-3:     #222736;
  --surface-inset: #0e111a;

  --border:        #262c3b;
  --border-strong: #363d51;
  --border-faint:  #1c212e;

  --text:          #e8eaf2;
  --text-muted:    #a2a9bd;
  --text-faint:    #6b7286;
  --text-oncolor:  #ffffff;

  --primary:       #8368ff;
  --primary-hover: #937cff;
  --primary-press: #7a5cff;
  --primary-soft:  rgba(131,104,255,.16);
  --primary-softer:rgba(131,104,255,.09);
  --on-primary:    #ffffff;
  --ring:          rgba(131,104,255,.55);

  --success:   #3ddc97;
  --success-soft: rgba(61,220,151,.14);
  --danger:    #ff6584;
  --danger-soft:  rgba(255,101,132,.14);
  --warning:   #ffb454;
  --warning-soft: rgba(255,180,84,.14);
  --info:      #4fd6e8;
  --info-soft: rgba(79,214,232,.14);

  --shadow-color: 232 60% 3%;
  --shadow-xs: 0 1px 2px rgba(0,0,0,.5);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.5), 0 2px 6px rgba(0,0,0,.4);
  --shadow-md: 0 6px 16px rgba(0,0,0,.5), 0 12px 32px rgba(0,0,0,.44);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.6), 0 34px 70px rgba(0,0,0,.5);
  --shadow-glow: 0 10px 40px rgba(131,104,255,.42);
  --shadow-key: inset 0 -3px 0 rgba(0,0,0,.5), 0 2px 4px rgba(0,0,0,.5);

  --keycap-bg: linear-gradient(180deg, #232838, #1a1e2b);
  --keycap-border: #3a4257;

  color-scheme: dark;
}

/* Explicit light override forces light even when system is dark. */
:root[data-theme="light"] { color-scheme: light; }
