@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  :root {
    /* Base colors - Light theme */
    --background: 240 100% 99%;
    --foreground: 213 27% 12%;
    --card: 0 0% 100%;
    --card-foreground: 213 27% 12%;
    --popover: 0 0% 100%;
    --popover-foreground: 213 27% 12%;
    --primary: 213 94% 18%;
    --primary-foreground: 0 0% 98%;
    --secondary: 180 94% 92%;
    --secondary-foreground: 180 94% 12%;
    --muted: 220 14% 96%;
    --muted-foreground: 220 8% 46%;
    --accent: 25 95% 53%;
    --accent-foreground: 0 0% 98%;
    --success: 142 76% 36%;
    --success-foreground: 0 0% 98%;
    --warning: 38 92% 50%;
    --warning-foreground: 0 0% 98%;
    --destructive: 0 84% 60%;
    --destructive-foreground: 0 0% 98%;
    --border: 220 13% 91%;
    --input: 220 13% 91%;
    --ring: 213 94% 18%;
    --radius: 0.75rem;

    /* Element group colors */
    --metal: 280 100% 70%;
    --nonmetal: 120 100% 25%;
    --metalloid: 45 100% 50%;
    --noble-gas: 260 100% 50%;

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, hsl(213 94% 18%), hsl(180 94% 32%));
    --gradient-card: linear-gradient(145deg, hsl(0 0% 100%), hsl(220 14% 96%));
    --gradient-element: linear-gradient(135deg, hsl(var(--accent)), hsl(25 95% 63%));
    --gradient-cta: linear-gradient(135deg, hsl(var(--accent)), hsl(25 95% 63%));

    /* Animations */
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);

    /* Sidebar - Light */
    --sidebar-background: 0 0% 98%;
    --sidebar-foreground: 240 5.3% 26.1%;
    --sidebar-primary: 240 5.9% 10%;
    --sidebar-primary-foreground: 0 0% 98%;
    --sidebar-accent: 240 4.8% 95.9%;
    --sidebar-accent-foreground: 240 5.9% 10%;
    --sidebar-border: 220 13% 91%;
    --sidebar-ring: 217.2 91.2% 59.8%;
  }

  /* PWA Optimizations */
  body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
    overscroll-behavior: none;
  }

  /* Performance optimizations */
  .periodic-table-container {
    will-change: transform;
    transform: translateZ(0);
  }
  
  /* Lazy loading optimization */
  img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s;
  }
  
  img[loading="lazy"].loaded {
    opacity: 1;
  }
  
  /* Reduce motion for users who prefer it */
  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }

  /* Mobile touch optimizations */
  @media (max-width: 768px) {
    * {
      -webkit-tap-highlight-color: transparent;
    }
    
    button, .cursor-pointer {
      touch-action: manipulation;
      -webkit-touch-callout: none;
      -webkit-user-select: none;
      user-select: none;
    }
    
    html, body {
      overflow-x: hidden;
      position: relative;
    }
  }

  .dark {
    /* --- Enhanced Dark Theme: "Stellar Horizon" --- */
    --background: 240 25% 6%;
    --foreground: 220 20% 95%;
    --card: 240 25% 10%;
    --card-foreground: 220 20% 95%;
    --popover: 240 25% 10%;
    --popover-foreground: 220 20% 95%;
    --primary: 270 90% 70%;
    --primary-foreground: 270 90% 98%;
    --secondary: 240 15% 18%;
    --secondary-foreground: 220 20% 85%;
    --muted: 240 10% 25%;
    --muted-foreground: 240 10% 50%;
    --accent: 180 90% 55%;
    --accent-foreground: 240 25% 8%;
    --accent-alt: 330 90% 65%;
    --accent-alt-foreground: 330 90% 98%;
    --success: 140 70% 45%;
    --success-foreground: 140 70% 98%;
    --warning: 40 95% 60%;
    --warning-foreground: 40 95% 10%;
    --destructive: 0 80% 60%;
    --destructive-foreground: 0 80% 98%;
    --border: 240 15% 25%;
    --input: 240 15% 30%;
    --ring: 180 90% 60%;
    
    /* Simplified gradients for better compatibility */
    --gradient-primary: linear-gradient(135deg, hsl(270 90% 70%), hsl(180 90% 55%));
    --gradient-card: linear-gradient(145deg, hsla(240, 25%, 10%, 0.7), hsla(240, 25%, 10%, 0.5));
    --gradient-cta: linear-gradient(135deg, hsl(270 90% 70%), hsl(330 90% 65%));

    /* Sidebar variables for dark theme */
    --sidebar-background: 240 25% 8%;
    --sidebar-foreground: 220 20% 85%;
    --sidebar-primary: 270 90% 70%;
    --sidebar-primary-foreground: 270 90% 98%;
    --sidebar-accent: 240 15% 15%;
    --sidebar-accent-foreground: 220 20% 92%;
    --sidebar-border: 240 15% 20%;
    --sidebar-ring: 180 90% 60%;
  }

  /* NEW STYLES: These classes should be applied directly to your components */
  .dark body {
    background-color: hsl(var(--background));
    background-image: radial-gradient(
      ellipse at 70% 30%,
      hsla(270, 50%, 25%, 0.3),
      hsla(var(--background), 0) 50%
    ),
    radial-gradient(
      ellipse at 30% 70%,
      hsla(180, 50%, 20%, 0.3),
      hsla(var(--background), 0) 50%
    );
  }

  .dark .glass-card {
    background: var(--gradient-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid hsl(var(--border));
    box-shadow: 0 8px 32px 0 hsla(240, 30%, 5%, 0.37);
  }
  
  .dark .quiz-option {
    background-color: hsl(var(--secondary));
    border: 1px solid hsl(var(--border));
    transition: all 0.2s ease-in-out;
  }

  .dark .quiz-option:hover {
    transform: translateY(-4px);
    border-color: hsl(var(--accent));
    box-shadow: 0 0 20px hsla(var(--accent), 0.3);
    background-color: hsl(var(--muted));
  }
}

@layer base {
  * {
    @apply border-border;
  }

  body {
    @apply bg-background text-foreground;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    overscroll-behavior: none;
    touch-action: manipulation;
  }
  
  @media (max-width: 768px) {
    body {
      font-size: 14px;
    }
  }
  
  html, body {
    overflow-x: hidden;
  }
  
  html {
    scroll-behavior: smooth;
  }
  
  button, [role="button"], input, select, textarea {
    min-height: 44px;
    min-width: 44px;
  }
  
  .hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
  }
  
  .hide-scrollbar::-webkit-scrollbar {
    display: none;
  }

  .font-mono {
    font-family: 'JetBrains Mono', 'Menlo', 'Monaco', 'Consolas', monospace;
  }

  /* Other Themes (Unchanged from your original) */
  .wizara {
    --background: 270 15% 8%; --foreground: 270 15% 95%; --card: 270 15% 12%; --card-foreground: 270 15% 95%; --primary: 270 95% 60%; --primary-foreground: 270 15% 8%; --secondary: 270 15% 18%; --secondary-foreground: 270 15% 95%; --accent: 280 100% 70%; --accent-foreground: 270 15% 8%; --border: 270 15% 20%; --input: 270 15% 20%; --ring: 270 95% 60%; --gradient-primary: linear-gradient(135deg, hsl(270 95% 60%), hsl(280 100% 70%)); --gradient-card: linear-gradient(145deg, hsl(270 15% 12%), hsl(270 15% 16%));
  }
  .wizard {
    --background: 240 25% 6%; --foreground: 240 25% 95%; --card: 240 25% 10%; --card-foreground: 240 25% 95%; --primary: 200 100% 60%; --primary-foreground: 240 25% 6%; --secondary: 240 25% 14%; --secondary-foreground: 240 25% 95%; --accent: 300 100% 70%; --accent-foreground: 240 25% 6%; --border: 240 25% 18%; --input: 240 25% 18%; --ring: 200 100% 60%; --gradient-primary: linear-gradient(135deg, hsl(240 25% 6%), hsl(300 100% 20%)); --gradient-card: linear-gradient(145deg, hsl(240 25% 10%), hsl(240 25% 14%));
  }
  .nature {
    --background: 120 20% 8%; --foreground: 120 20% 95%; --card: 120 20% 12%; --card-foreground: 120 20% 95%; --primary: 120 80% 50%; --primary-foreground: 120 20% 8%; --secondary: 120 20% 16%; --secondary-foreground: 120 20% 95%; --accent: 80 100% 60%; --accent-foreground: 120 20% 8%; --border: 120 20% 20%; --input: 120 20% 20%; --ring: 120 80% 50%; --gradient-primary: linear-gradient(135deg, hsl(120 80% 25%), hsl(80 100% 40%)); --gradient-card: linear-gradient(145deg, hsl(120 20% 12%), hsl(120 20% 16%));
  }
  .neon {
    --background: 300 30% 8%; --foreground: 300 30% 95%; --card: 300 30% 12%; --card-foreground: 300 30% 95%; --primary: 320 100% 60%; --primary-foreground: 300 30% 8%; --secondary: 300 30% 16%; --secondary-foreground: 300 30% 95%; --accent: 180 100% 60%; --accent-foreground: 300 30% 8%; --border: 300 30% 20%; --input: 300 30% 20%; --ring: 320 100% 60%; --gradient-primary: linear-gradient(135deg, hsl(320 100% 60%), hsl(180 100% 60%)); --gradient-card: linear-gradient(145deg, hsl(300 30% 12%), hsl(300 30% 16%));
  }
}

/* Animations */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in-only {
  animation: fade-in 0.7s ease-out forwards;
}

@keyframes button-glow {
  0% {
    box-shadow: 0 0 5px hsla(var(--primary), 0), 0 0 10px hsla(var(--primary), 0);
  }
  50% {
    box-shadow: 0 0 10px hsla(var(--primary), 0.5), 0 0 20px hsla(var(--primary), 0.3);
  }
  100% {
    box-shadow: 0 0 5px hsla(var(--primary), 0), 0 0 10px hsla(var(--primary), 0);
  }
}

.dark .pulsing-button {
  animation: button-glow 3s infinite ease-in-out;
}
