/* ─────────────────────────────────────────────────────────────────────────────
   Design System: Unified Design Tokens & Theme Variables

   This file defines the core design tokens for the AnimationPipeline UI.
   It supports light and dark themes through CSS custom properties.

   Usage:
     - Colors: var(--color-bg-primary), var(--color-text-primary), etc.
     - Spacing: var(--space-xs), var(--space-sm), etc.
     - Typography: var(--font-family), var(--font-size-base), etc.
     - Radius: var(--radius-sm), var(--radius-md), etc.
     - Shadows: var(--shadow-sm), var(--shadow-md), etc.

   Theme Toggle:
     - Default: dark theme (system preference or localStorage)
     - Light: Set html[data-theme="light"] via JavaScript
     - Persistence: Stored in localStorage key "app-theme"
───────────────────────────────────────────────────────────────────────────────*/

:root {
  /* ──────────────────────────────────────────────────────────────────────────
     SPACING SCALE (3px base)
  ──────────────────────────────────────────────────────────────────────────*/
  --space-xs: 3px;
  --space-sm: 6px;
  --space-md: 8px;
  --space-lg: 12px;
  --space-xl: 16px;
  --space-2xl: 20px;
  --space-3xl: 24px;
  --space-4xl: 32px;
  --space-5xl: 40px;
  --space-6xl: 48px;
  --space-7xl: 64px;

  /* ──────────────────────────────────────────────────────────────────────────
     TYPOGRAPHY
  ──────────────────────────────────────────────────────────────────────────*/
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  --font-family-mono: 'Monaco', 'Courier New', monospace;

  --font-size-xs: 10px;
  --font-size-sm: 11px;
  --font-size-base: 12px;
  --font-size-md: 13px;
  --font-size-lg: 14px;
  --font-size-xl: 16px;
  --font-size-2xl: 18px;
  --font-size-3xl: 24px;
  --font-size-4xl: 32px;

  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  --line-height-tight: 1.3;
  --line-height-normal: 1.5;
  --line-height-loose: 1.8;

  /* ──────────────────────────────────────────────────────────────────────────
     BORDER RADIUS
  ──────────────────────────────────────────────────────────────────────────*/
  --radius-xs: 2px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
  --radius-pill: 20px;

  /* ──────────────────────────────────────────────────────────────────────────
     SHADOWS (elevation system)
  ──────────────────────────────────────────────────────────────────────────*/
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.15);
  --shadow-xl: 0 8px 16px rgba(0, 0, 0, 0.2);

  /* ──────────────────────────────────────────────────────────────────────────
     Z-INDEX SCALE
  ──────────────────────────────────────────────────────────────────────────*/
  --z-dropdown: 1000;
  --z-sticky: 999;
  --z-fixed: 998;
  --z-modal: 1001;
  --z-tooltip: 1002;

  /* ──────────────────────────────────────────────────────────────────────────
     COLOR PALETTE - DARK THEME (default)

     Improved contrast over legacy colors:
     - Old #888 (text secondary) → #a0a0a0 (4.5:1 contrast on dark)
     - Old #bfbfbf → #a0a0a0 (same)
     - Old #444 (text tertiary) → #606060 (3.1:1 contrast on dark)
  ──────────────────────────────────────────────────────────────────────────*/

  /* Neutral backgrounds */
  --color-bg-primary: #0a0a0f;
  --color-bg-secondary: #0d0d12;
  --color-bg-tertiary: #111111;
  --color-bg-elevated: #141414;

  /* Surface for interactions */
  --color-surface-primary: #0d0d12;
  --color-surface-secondary: #141414;

  /* Text colors (with improved contrast) */
  --color-text-primary: #ffffff;      /* 21:1 on dark bg */
  --color-text-secondary: #a0a0a0;    /* 4.5:1 on dark bg */
  --color-text-tertiary: #606060;     /* 3.1:1 on dark bg */
  --color-text-disabled: #3a3a3a;     /* 1.6:1 on dark bg, for disabled state */

  /* Borders */
  --color-border-primary: #1a1a1a;
  --color-border-secondary: #252525;
  --color-border-focus: #3a3a3a;
  --color-border-interactive: #444444;

  /* Semantic accent colors */
  --color-primary: #e94560;           /* Primary action/emphasis */
  --color-primary-dark: #d63d57;      /* Darker variant for light theme */
  --color-primary-hover: #d63d57;
  --color-primary-active: #c0354f;
  --color-primary-bg: rgba(233, 69, 96, 0.08);

  --color-success: #27ae60;
  --color-success-dark: #1e8449;
  --color-success-bg: rgba(39, 174, 96, 0.08);

  --color-warning: #f39c12;
  --color-warning-dark: #d68910;
  --color-warning-bg: rgba(243, 156, 18, 0.08);

  --color-danger: #e74c3c;
  --color-danger-dark: #c0392b;
  --color-danger-bg: rgba(231, 76, 60, 0.08);

  --color-info: #3498db;
  --color-info-dark: #2980b9;
  --color-info-bg: rgba(52, 152, 219, 0.08);

  /* Component-specific colors (can be overridden in light theme) */
  --color-input-bg: #1e1e1e;
  --color-input-border: #333333;
  --color-input-border-focus: #bfbfbf;
  --color-input-text: #cccccc;

  --color-button-ghost-bg: transparent;
  --color-button-ghost-text: #888888;
  --color-button-ghost-border: #2a2a2a;
  --color-button-ghost-hover-text: #cccccc;
  --color-button-ghost-hover-border: #444444;

  --color-scrollbar-thumb: #222222;
  --color-scrollbar-thumb-hover: #333333;

  /* Audio effect specific colors (kept for backward compatibility) */
  --color-audio-active: #5a5;
  --color-audio-status-rendering: #a80;
  --color-audio-status-ready: #484;
  --color-audio-status-error: #a44;
}

/* ─────────────────────────────────────────────────────────────────────────────
   LIGHT THEME OVERRIDES

   Applied when:
   - html[data-theme="light"] is set, OR
   - User's system preference is light (media query)
───────────────────────────────────────────────────────────────────────────────*/

@media (prefers-color-scheme: light) {
  :root {
    /* Backgrounds */
    --color-bg-primary: #f5f3f0;
    --color-bg-secondary: #ffffff;
    --color-bg-tertiary: #fafaf8;
    --color-bg-elevated: #ffffff;

    /* Surfaces */
    --color-surface-primary: #ffffff;
    --color-surface-secondary: #fafaf8;

    /* Text (inverted for light background) */
    --color-text-primary: #1a1a1a;      /* 20:1 on light bg */
    --color-text-secondary: #505050;    /* 7.0:1 on light bg */
    --color-text-tertiary: #808080;     /* 5.0:1 on light bg */
    --color-text-disabled: #c0c0c0;     /* 1.4:1 on light bg */

    /* Borders */
    --color-border-primary: #e0dcd8;
    --color-border-secondary: #d8d4d0;
    --color-border-focus: #999999;
    --color-border-interactive: #a0a0a0;

    /* Semantic colors adjusted for light theme */
    --color-primary: #d63d57;           /* Darker red */
    --color-primary-dark: #b82d47;
    --color-primary-hover: #b82d47;
    --color-primary-active: #9d2540;
    --color-primary-bg: rgba(214, 61, 87, 0.08);

    --color-success: #1e8449;
    --color-success-dark: #145a32;
    --color-success-bg: rgba(30, 132, 73, 0.08);

    --color-warning: #d68910;
    --color-warning-dark: #b86e0d;
    --color-warning-bg: rgba(214, 137, 16, 0.08);

    --color-danger: #c0392b;
    --color-danger-dark: #a63321;
    --color-danger-bg: rgba(192, 57, 43, 0.08);

    --color-info: #2980b9;
    --color-info-dark: #1f618d;
    --color-info-bg: rgba(41, 128, 185, 0.08);

    /* Component colors for light theme */
    --color-input-bg: #ffffff;
    --color-input-border: #d8d4d0;
    --color-input-border-focus: #606060;
    --color-input-text: #1a1a1a;

    --color-button-ghost-bg: transparent;
    --color-button-ghost-text: #505050;
    --color-button-ghost-border: #d8d4d0;
    --color-button-ghost-hover-text: #1a1a1a;
    --color-button-ghost-hover-border: #999999;

    --color-scrollbar-thumb: #d8d4d0;
    --color-scrollbar-thumb-hover: #c0bab6;
  }
}

/* Allow explicit light theme override via data attribute */
[data-theme="light"] {
  --color-bg-primary: #f5f3f0;
  --color-bg-secondary: #ffffff;
  --color-bg-tertiary: #fafaf8;
  --color-bg-elevated: #ffffff;
  --color-surface-primary: #ffffff;
  --color-surface-secondary: #fafaf8;
  --color-text-primary: #1a1a1a;
  --color-text-secondary: #505050;
  --color-text-tertiary: #808080;
  --color-text-disabled: #c0c0c0;
  --color-border-primary: #e0dcd8;
  --color-border-secondary: #d8d4d0;
  --color-border-focus: #999999;
  --color-border-interactive: #a0a0a0;
  --color-primary: #d63d57;
  --color-primary-dark: #b82d47;
  --color-primary-hover: #b82d47;
  --color-primary-active: #9d2540;
  --color-primary-bg: rgba(214, 61, 87, 0.08);
  --color-success: #1e8449;
  --color-success-dark: #145a32;
  --color-success-bg: rgba(30, 132, 73, 0.08);
  --color-warning: #d68910;
  --color-warning-dark: #b86e0d;
  --color-warning-bg: rgba(214, 137, 16, 0.08);
  --color-danger: #c0392b;
  --color-danger-dark: #a63321;
  --color-danger-bg: rgba(192, 57, 43, 0.08);
  --color-info: #2980b9;
  --color-info-dark: #1f618d;
  --color-info-bg: rgba(41, 128, 185, 0.08);
  --color-input-bg: #ffffff;
  --color-input-border: #d8d4d0;
  --color-input-border-focus: #606060;
  --color-input-text: #1a1a1a;
  --color-button-ghost-bg: transparent;
  --color-button-ghost-text: #505050;
  --color-button-ghost-border: #d8d4d0;
  --color-button-ghost-hover-text: #1a1a1a;
  --color-button-ghost-hover-border: #999999;
  --color-scrollbar-thumb: #d8d4d0;
  --color-scrollbar-thumb-hover: #c0bab6;
}

/* Explicit dark theme - ensure it overrides any light preference */
[data-theme="dark"] {
  --color-bg-primary: #0a0a0f;
  --color-bg-secondary: #0d0d12;
  --color-bg-tertiary: #111111;
  --color-bg-elevated: #141414;
  --color-surface-primary: #0d0d12;
  --color-surface-secondary: #141414;
  --color-text-primary: #ffffff;
  --color-text-secondary: #a0a0a0;
  --color-text-tertiary: #606060;
  --color-text-disabled: #3a3a3a;
  --color-border-primary: #1a1a1a;
  --color-border-secondary: #252525;
  --color-border-focus: #3a3a3a;
  --color-border-interactive: #444444;
  --color-primary: #e94560;
  --color-primary-dark: #d63d57;
  --color-primary-hover: #d63d57;
  --color-primary-active: #c0354f;
  --color-primary-bg: rgba(233, 69, 96, 0.08);
  --color-success: #27ae60;
  --color-success-dark: #1e8449;
  --color-success-bg: rgba(39, 174, 96, 0.08);
  --color-warning: #f39c12;
  --color-warning-dark: #d68910;
  --color-warning-bg: rgba(243, 156, 18, 0.08);
  --color-danger: #e74c3c;
  --color-danger-dark: #c0392b;
  --color-danger-bg: rgba(231, 76, 60, 0.08);
  --color-info: #3498db;
  --color-info-dark: #2980b9;
  --color-info-bg: rgba(52, 152, 219, 0.08);
  --color-input-bg: #1e1e1e;
  --color-input-border: #333333;
  --color-input-border-focus: #bfbfbf;
  --color-input-text: #cccccc;
  --color-button-ghost-bg: transparent;
  --color-button-ghost-text: #888888;
  --color-button-ghost-border: #2a2a2a;
  --color-button-ghost-hover-text: #cccccc;
  --color-button-ghost-hover-border: #444444;
  --color-scrollbar-thumb: #222222;
  --color-scrollbar-thumb-hover: #333333;
}

/* ─────────────────────────────────────────────────────────────────────────────
   GLOBAL STYLES
───────────────────────────────────────────────────────────────────────────────*/

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background-color: var(--color-bg-primary);
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: var(--color-bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--color-scrollbar-thumb);
  border-radius: var(--radius-xs);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-scrollbar-thumb-hover);
}

/* Link styles */
a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--color-primary-hover);
}

/* Focus visible for accessibility */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
