/* ════════════════════════════════════════════════════════════
   Athena Design Tokens — single source of truth
   Bold redesign: bento layout, glassmorphism accents, CJK-first,
   auto dark mode via prefers-color-scheme, motion-safe.
   ════════════════════════════════════════════════════════════ */

:root {
  /* ── Brand palette ── */
  --brand-50:  #f5f3ff;
  --brand-100: #ede9fe;
  --brand-200: #ddd6fe;
  --brand-300: #c4b5fd;
  --brand-400: #a78bfa;
  --brand-500: #8b5cf6;
  --brand-600: #7c3aed;  /* Athena primary */
  --brand-700: #6d28d9;
  --brand-800: #5b21b6;
  --brand-900: #4c1d95;

  /* ── Warm accent (amber for highlights/badges) ── */
  --accent-50:  #fffbeb;
  --accent-100: #fef3c7;
  --accent-300: #fcd34d;
  --accent-500: #f59e0b;
  --accent-700: #b45309;

  /* ── Cyan (graph edges, info) ── */
  --cyan-500: #06b6d4;
  --cyan-700: #0e7490;

  /* ── Semantic ── */
  --success-50:  #ecfdf5;
  --success-500: #10b981;
  --success-700: #047857;
  --warning-50:  #fffbeb;
  --warning-500: #f59e0b;
  --warning-700: #b45309;
  --danger-50:   #fef2f2;
  --danger-500:  #ef4444;
  --danger-700:  #b91c1c;

  /* ── Neutrals (slate-based for depth) ── */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --slate-950: #020617;

  /* ── Surface tokens (light mode default) ── */
  --bg:           #faf9f6;   /* warm paper */
  --bg-subtle:    #f4f3ef;
  --surface:      #ffffff;
  --surface-2:    #fbfaf7;   /* alt surface */
  --surface-glass: rgba(255, 255, 255, 0.72);
  --ink:          var(--slate-900);
  --ink-soft:     var(--slate-700);
  --muted:        var(--slate-500);
  --border:       var(--slate-200);
  --border-soft:  var(--slate-100);
  --border-strong: var(--slate-300);

  /* ── Semantic aliases (consume these in components) ── */
  --color-primary:      var(--brand-600);
  --color-primary-hover: var(--brand-700);
  --color-primary-soft: var(--brand-100);
  --color-on-primary:   #ffffff;
  --color-accent:       var(--accent-500);
  --color-success:      var(--success-500);
  --color-warning:      var(--warning-500);
  --color-danger:       var(--danger-500);
  --color-info:         var(--cyan-500);

  /* ── Typography ── */
  --font-display: "Sora", "PingFang SC", "Hiragino Sans GB",
                  "Source Han Sans SC", "Noto Sans SC", "Microsoft YaHei",
                  -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-body:    "Inter", "PingFang SC", "Hiragino Sans GB",
                  "Source Han Sans SC", "Noto Sans SC", "Microsoft YaHei",
                  -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-serif:   "Newsreader", "Source Serif Pro", "Noto Serif SC",
                  "Source Han Serif SC", Georgia, serif;
  --font-mono:    "JetBrains Mono", "Fira Code", "Cascadia Code",
                  "SF Mono", Consolas, monospace;
  --font: var(--font-body);

  /* ── Modular type scale (1.25 ratio, base 16px) ── */
  --text-xs:   0.75rem;     /* 12 */
  --text-sm:   0.875rem;    /* 14 */
  --text-base: 1rem;        /* 16 */
  --text-lg:   1.125rem;    /* 18 */
  --text-xl:   1.25rem;     /* 20 */
  --text-2xl:  1.5rem;      /* 24 */
  --text-3xl:  1.875rem;    /* 30 */
  --text-4xl:  2.25rem;     /* 36 */
  --text-5xl:  3rem;        /* 48 */
  --leading-tight: 1.2;
  --leading-snug:  1.4;
  --leading-normal: 1.6;
  --leading-relaxed: 1.75;
  --tracking-tight:  -0.02em;
  --tracking-normal: 0;
  --tracking-wide:   0.04em;
  --tracking-wider:  0.08em;

  /* ── Spacing (4px grid) ── */
  --space-0:  0;
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  /* ── Radius ── */
  --radius-sm:  6px;
  --radius:     10px;
  --radius-md:  12px;
  --radius-lg:  16px;
  --radius-xl:  20px;
  --radius-2xl: 28px;
  --radius-pill: 9999px;

  /* ── Layered shadows (Apple-style, never flat) ── */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow:    0 4px 8px rgba(15, 23, 42, 0.04), 0 2px 4px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 16px rgba(15, 23, 42, 0.06), 0 4px 8px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 24px rgba(15, 23, 42, 0.08), 0 4px 8px rgba(15, 23, 42, 0.04);
  --shadow-xl: 0 20px 40px rgba(15, 23, 42, 0.10), 0 8px 16px rgba(15, 23, 42, 0.06);
  --shadow-glow: 0 0 0 1px rgba(124, 58, 237, 0.12), 0 8px 24px rgba(124, 58, 237, 0.18);

  /* ── Motion ── */
  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --motion-fast: 150ms var(--ease-out);
  --motion-base: 220ms var(--ease-out);
  --motion-slow: 320ms var(--ease-out);
  --motion-spring: 420ms var(--ease-spring);
  --transition: var(--motion-base);

  /* ── Layout ── */
  --sidebar-w: 248px;
  --content-max: none;          /* full-bleed — reading measure handled per-element via --reading-width */
  --reading-width: 70ch;        /* concept detail prose stays narrow for ergonomics */
  --content-padding-x: 48px;    /* generous side gutters so content doesn't kiss viewport edge */
  --topbar-h: 64px;
  --z-base: 0;
  --z-sticky: 10;
  --z-sidebar: 20;
  --z-header: 30;
  --z-popover: 40;
  --z-modal: 50;
  --z-toast: 1000;

  /* ── Glass effect ── */
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.6);
  --glass-blur: 16px;

  /* ── Legacy aliases (transitional dual-naming for migration) ──
     Maps old variable names used in existing templates to new tokens.
     Prefer the new names in new code; these exist to keep existing
     templates working during incremental migration. */
  --text: var(--ink);
  --text-soft: var(--ink-soft);
  --accent: var(--color-primary);
  --accent-light: var(--color-primary-soft);
  --accent-hover: var(--color-primary-hover);
  --success-light: var(--success-50);
  --warning-light: var(--warning-50);
  --danger-light: var(--danger-50);
  --border-light: var(--border-soft);

  color-scheme: light;
}

/* ════════════════════════════════════════════════════════════
   Dark mode — auto via OS preference
   ════════════════════════════════════════════════════════════ */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #0b0b10;
    --bg-subtle:    #131319;
    --surface:      #16161e;
    --surface-2:    #1c1c26;
    --surface-glass: rgba(22, 22, 30, 0.72);
    --ink:          #f4f4f5;
    --ink-soft:     #d4d4d8;
    --muted:        #a1a1aa;
    --border:       #27272f;
    --border-soft:  #1f1f27;
    --border-strong: #3f3f4a;

    /* Brighten brand for dark */
    --color-primary:      var(--brand-500);
    --color-primary-hover: var(--brand-400);
    --color-primary-soft: rgba(139, 92, 246, 0.16);

    /* Soften semantic backgrounds for dark */
    --success-50:  rgba(16, 185, 129, 0.12);
    --warning-50:  rgba(245, 158, 11, 0.12);
    --danger-50:   rgba(239, 68, 68, 0.14);

    /* Deeper shadows on dark */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow:    0 4px 8px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 16px rgba(0, 0, 0, 0.5), 0 4px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.55), 0 4px 8px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.6), 0 8px 16px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 0 1px rgba(139, 92, 246, 0.24), 0 12px 28px rgba(124, 58, 237, 0.28);

    --glass-bg: rgba(22, 22, 30, 0.72);
    --glass-border: rgba(255, 255, 255, 0.06);

    color-scheme: dark;
  }
}

/* ════════════════════════════════════════════════════════════
   Reduced motion — vestibular safety
   ════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  :root {
    --motion-fast: 0ms;
    --motion-base: 0ms;
    --motion-slow: 0ms;
    --motion-spring: 0ms;
    --transition: 0ms;
    --ease-out: linear;
    --ease-spring: linear;
  }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
