/* ==========================================================================
   Aura · Apple Design Tokens
   Optical Typography, Adaptive Materials, Light/Dark Semantic Palette,
   Reduced Motion & Accessibility Media Queries
   ========================================================================== */

:root {
  color-scheme: light;

  /* --- Font Stack (Platform System Fonts with Optical Sizing) --- */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display",
    "PingFang SC", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* --- Semantic Palette (Light Mode · Crisp Paper & Translucent Glass) --- */
  --bg-canvas: #F5F5F7;
  --bg-elevated: #FFFFFF;
  --bg-secondary: #EFEFF4;
  --bg-tertiary: rgba(118, 118, 128, 0.10);
  --bg-hover: rgba(118, 118, 128, 0.14);

  /* Translucent Materials */
  --mat-header: rgba(245, 245, 247, 0.72);
  --mat-sheet: rgba(255, 255, 255, 0.88);
  --mat-popover: rgba(255, 255, 255, 0.90);
  --mat-control: rgba(255, 255, 255, 0.78);
  --mat-seg-track: rgba(118, 118, 128, 0.12);
  --mat-seg-thumb: #FFFFFF;

  /* Typography Colors */
  --ink-primary: #1D1D1F;
  --ink-secondary: #6E6E73;
  --ink-tertiary: #86868B;
  --ink-on-accent: #FFFFFF;

  /* Hairlines & Specular Edges */
  --hairline: rgba(60, 60, 67, 0.10);
  --hairline-strong: rgba(60, 60, 67, 0.18);
  --specular-edge: rgba(255, 255, 255, 0.75);

  /* Apple System Accents */
  --accent-blue: #007AFF;
  --accent-blue-soft: rgba(0, 122, 255, 0.11);
  --accent-indigo: #5856D6;
  --accent-indigo-soft: rgba(88, 86, 214, 0.11);
  --accent-green: #34C759;
  --accent-green-soft: rgba(52, 199, 89, 0.13);
  --accent-amber: #FF9500;
  --accent-amber-soft: rgba(255, 149, 0, 0.13);
  --accent-red: #FF3B30;
  --accent-red-soft: rgba(255, 59, 48, 0.12);

  /* Chat Surfaces */
  --bubble-user-bg: #007AFF;
  --bubble-user-ink: #FFFFFF;
  --bubble-ai-bg: #FFFFFF;
  --bubble-ai-ink: #1D1D1F;

  /* Elevation Shadows (Context-aware layered softness) */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.05), 0 0 0 0.5px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.16), 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-popover: 0 14px 40px rgba(0, 0, 0, 0.14), 0 0 0 0.5px rgba(0, 0, 0, 0.06);
  --scrim: rgba(0, 0, 0, 0.28);

  /* Radii (Squircle-inspired harmonious scale) */
  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 24px;
  --r-xl: 30px;
  --r-pill: 9999px;

  /* Layout Rhythm (rem so Dynamic Type scales harmoniously) */
  --max-width: 920px;
  --header-h: 60px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  /* Blur Radii */
  --blur-sm: 16px;
  --blur-md: 24px;
  --blur-lg: 34px;
}

/* ==========================================================================
   Dark Mode (Rich True-Obsidian Depth & Luminous Vibrancy)
   ========================================================================== */
[data-theme="dark"] {
  color-scheme: dark;

  --bg-canvas: #000000;
  --bg-elevated: #1C1C1E;
  --bg-secondary: #2C2C2E;
  --bg-tertiary: rgba(118, 118, 128, 0.24);
  --bg-hover: rgba(142, 142, 147, 0.30);

  --mat-header: rgba(14, 14, 16, 0.78);
  --mat-sheet: rgba(28, 28, 31, 0.95);
  --mat-popover: rgba(38, 38, 42, 0.95);
  --mat-control: rgba(44, 44, 46, 0.86);
  --mat-seg-track: rgba(118, 118, 128, 0.24);
  --mat-seg-thumb: #3A3A3C;

  --ink-primary: #F5F5F7;
  --ink-secondary: #A1A1A6;
  --ink-tertiary: #6E6E73;

  --hairline: rgba(255, 255, 255, 0.10);
  --hairline-strong: rgba(255, 255, 255, 0.18);
  --specular-edge: rgba(255, 255, 255, 0.14);

  --accent-blue: #0A84FF;
  --accent-blue-soft: rgba(10, 132, 255, 0.18);
  --accent-indigo: #5E5CE6;
  --accent-indigo-soft: rgba(94, 92, 230, 0.20);
  --accent-green: #30D158;
  --accent-green-soft: rgba(48, 209, 88, 0.18);
  --accent-amber: #FF9F0A;
  --accent-amber-soft: rgba(255, 159, 10, 0.18);
  --accent-red: #FF453A;
  --accent-red-soft: rgba(255, 69, 58, 0.18);

  --bubble-user-bg: #0A84FF;
  --bubble-user-ink: #FFFFFF;
  --bubble-ai-bg: #1C1C1E;
  --bubble-ai-ink: #F5F5F7;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.30), 0 0 0 0.5px rgba(255, 255, 255, 0.08);
  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.42), 0 0 0 0.5px rgba(255, 255, 255, 0.08);
  --shadow-md: 0 14px 36px rgba(0, 0, 0, 0.56), 0 0 0 0.5px rgba(255, 255, 255, 0.10);
  --shadow-lg: 0 28px 72px rgba(0, 0, 0, 0.72), 0 0 0 0.5px rgba(255, 255, 255, 0.12);
  --shadow-popover: 0 18px 46px rgba(0, 0, 0, 0.65), 0 0 0 0.5px rgba(255, 255, 255, 0.12);
  --scrim: rgba(0, 0, 0, 0.62);
}

/* ==========================================================================
   Accessibility Preferences (Apple HIG)
   ========================================================================== */
@media (prefers-reduced-transparency: reduce) {
  :root {
    --mat-header: #F5F5F7;
    --mat-sheet: #FFFFFF;
    --mat-popover: #FFFFFF;
    --mat-control: #FFFFFF;
    --blur-sm: 0px;
    --blur-md: 0px;
    --blur-lg: 0px;
  }
  [data-theme="dark"] {
    --mat-header: #000000;
    --mat-sheet: #1C1C1E;
    --mat-popover: #2C2C2E;
    --mat-control: #2C2C2E;
  }
}

@media (prefers-contrast: more) {
  :root {
    --hairline: rgba(0, 0, 0, 0.28);
    --hairline-strong: rgba(0, 0, 0, 0.45);
    --ink-secondary: #3A3A3C;
  }
  [data-theme="dark"] {
    --hairline: rgba(255, 255, 255, 0.30);
    --hairline-strong: rgba(255, 255, 255, 0.50);
    --ink-secondary: #D1D1D6;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
