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

/* Academic Type Theory Playground Design System
All colors MUST be HSL. Mathematical typography optimized.
*/

@layer base {
  :root {
    /* Light Academic Theme */
    --background: 0 0% 100%;
    --foreground: 220 20% 20%;

    --card: 0 0% 100%;
    --card-foreground: 220 20% 20%;

    --popover: 0 0% 100%;
    --popover-foreground: 220 20% 20%;

    /* Soft Academic Primary */
    --primary: 220 70% 50%;
    --primary-foreground: 0 0% 100%;
    --primary-glow: 220 70% 60%;

    /* Light Secondary */
    --secondary: 220 15% 95%;
    --secondary-foreground: 220 20% 30%;

    /* Soft Muted */
    --muted: 220 15% 96%;
    --muted-foreground: 220 20% 60%;

    /* Light Accent */
    --accent: 220 70% 95%;
    --accent-foreground: 220 70% 40%;

    /* Error/Destructive */
    --destructive: 0 65% 55%;
    --destructive-foreground: 0 0% 100%;

    /* Light Borders */
    --border: 220 15% 90%;
    --input: 220 15% 90%;
    --ring: 220 70% 50%;

    /* Custom Light Variables */
    --algorithm-bg: 220 70% 98%;
    --rule-bg: 220 15% 98%;
    --derivation-bg: 0 0% 99%;
    --code-bg: 220 20% 98%;
    --highlight: 220 70% 95%;
    
    /* Typography */
    --math-font: 'Roboto Slab', 'Computer Modern', 'Latin Modern Math', serif;
    --code-font: 'Roboto Mono', 'Monaco', monospace;
    
    /* Gradients */
    --gradient-primary: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--primary-glow)));
    --gradient-card: linear-gradient(180deg, hsl(0 0% 100%), hsl(210 40% 99%));
    
    /* Material Design Shadows */
    --shadow-elegant: 0 8px 16px -4px hsl(var(--primary) / 0.2);
    --shadow-card: 0 2px 8px -2px hsl(var(--primary) / 0.12);
    --shadow-material-1: 0 1px 3px hsl(0 0% 0% / 0.12), 0 1px 2px hsl(0 0% 0% / 0.24);
    --shadow-material-2: 0 3px 6px hsl(0 0% 0% / 0.16), 0 3px 6px hsl(0 0% 0% / 0.23);
    --shadow-material-3: 0 10px 20px hsl(0 0% 0% / 0.19), 0 6px 6px hsl(0 0% 0% / 0.23);
    
    /* Animations */
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --radius: 0.5rem;

    --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%;
    
    /* Modern polished shadows */
    --shadow-subtle: 0 1px 3px 0 hsl(var(--foreground) / 0.1), 0 1px 2px -1px hsl(var(--foreground) / 0.1);
    --shadow-medium: 0 4px 6px -1px hsl(var(--foreground) / 0.1), 0 2px 4px -2px hsl(var(--foreground) / 0.1);
    --shadow-large: 0 10px 15px -3px hsl(var(--foreground) / 0.1), 0 4px 6px -4px hsl(var(--foreground) / 0.1);
  }

  .dark {
    /* Dark Academic Theme */
    --background: 215 28% 8%;
    --foreground: 210 40% 95%;

    --card: 215 28% 10%;
    --card-foreground: 210 40% 95%;

    --popover: 215 28% 10%;
    --popover-foreground: 210 40% 95%;

    --primary: 221 83% 65%;
    --primary-foreground: 215 28% 8%;
    --primary-glow: 221 83% 75%;

    --secondary: 215 28% 15%;
    --secondary-foreground: 210 40% 90%;

    --muted: 215 28% 12%;
    --muted-foreground: 215 16% 65%;

    --accent: 221 83% 20%;
    --accent-foreground: 221 83% 85%;

    --destructive: 0 72% 60%;
    --destructive-foreground: 210 40% 98%;

    --border: 215 28% 18%;
    --input: 215 28% 18%;
    --ring: 221 83% 65%;
    
    /* Dark Academic Variables */
    --algorithm-bg: 221 83% 12%;
    --rule-bg: 215 28% 12%;
    --derivation-bg: 215 28% 9%;
    --code-bg: 215 25% 11%;
    --highlight: 221 83% 20%;
    
    /* Dark Gradients */
    --gradient-primary: linear-gradient(135deg, hsl(var(--primary)), hsl(var(--primary-glow)));
    --gradient-card: linear-gradient(180deg, hsl(215 28% 10%), hsl(215 28% 8%));
    
    /* Dark Shadows */
    --shadow-elegant: 0 10px 30px -10px hsl(0 0% 0% / 0.3);
    --shadow-card: 0 4px 20px -4px hsl(0 0% 0% / 0.2);
    --sidebar-background: 240 5.9% 10%;
    --sidebar-foreground: 240 4.8% 95.9%;
    --sidebar-primary: 224.3 76.3% 48%;
    --sidebar-primary-foreground: 0 0% 100%;
    --sidebar-accent: 240 3.7% 15.9%;
    --sidebar-accent-foreground: 240 4.8% 95.9%;
    --sidebar-border: 240 3.7% 15.9%;
    --sidebar-ring: 217.2 91.2% 59.8%;
    
    /* Dark theme shadows */
    --shadow-subtle: 0 1px 3px 0 hsl(0 0% 0% / 0.3), 0 1px 2px -1px hsl(0 0% 0% / 0.3);
    --shadow-medium: 0 4px 6px -1px hsl(0 0% 0% / 0.3), 0 2px 4px -2px hsl(0 0% 0% / 0.3);
    --shadow-large: 0 10px 15px -3px hsl(0 0% 0% / 0.3), 0 4px 6px -4px hsl(0 0% 0% / 0.3);
  }
}

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

  body {
    @apply bg-background text-foreground font-sans;
    font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    height: 100vh;
    margin: 0;
    padding: 0;
  }
  
  html {
    overflow: hidden;
    height: 100vh;
    margin: 0;
    padding: 0;
  }
  
  /* Mathematical Typography */
  .math-text {
    font-family: var(--math-font);
    font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
  }
  
  .code-text {
    font-family: var(--code-font);
    font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
  }
  
  /* KaTeX Custom Styling */
  .katex {
    font-size: 1.1em !important;
  }
  
  .katex-display {
    margin: 1em 0 !important;
  }

  /* Mobile responsive KaTeX */
  @media (max-width: 768px) {
    .katex {
      font-size: 0.85em !important;
    }
    
    .katex-display {
      font-size: 0.9em !important;
      margin: 0.5em 0 !important;
    }
    
    .math-text {
      word-break: break-word;
      overflow-wrap: break-word;
    }
    
    /* Horizontal scroll for long formulas */
    .math-text.overflow-x-auto {
      scrollbar-width: thin;
      scrollbar-color: hsl(var(--muted-foreground) / 0.5) transparent;
    }
    
    .math-text.overflow-x-auto::-webkit-scrollbar {
      height: 4px;
    }
    
    .math-text.overflow-x-auto::-webkit-scrollbar-track {
      background: transparent;
    }
    
    .math-text.overflow-x-auto::-webkit-scrollbar-thumb {
      background-color: hsl(var(--muted-foreground) / 0.5);
      border-radius: 2px;
    }
    
    /* Mobile-specific improvements */
    .academic-panel {
      border-radius: 0.75rem;
      padding: 1rem;
    }
    
    /* Better touch targets */
    .touch-manipulation {
      touch-action: manipulation;
    }
    
    /* Mobile card padding */
    .card {
      @apply p-3;
    }
  }
  
  /* Enhanced mobile breakpoints */
  @media (max-width: 640px) {
    /* Smaller text for very small screens */
    .katex {
      font-size: 0.8em !important;
    }
    
    /* Tighter spacing on small screens */
    .space-y-4 > * + * {
      margin-top: 1rem;
    }
    
    /* Compact button styling */
    button {
      min-height: 44px; /* Ensure good touch targets */
    }
  }
  
  /* Tablet optimizations */
  @media (min-width: 768px) and (max-width: 1024px) {
    .container {
      max-width: 100%;
      padding-left: 1.5rem;
      padding-right: 1.5rem;
    }
  }
  


  /* Smooth transition classes */
  .transition-smooth {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .transition-fast {
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .transition-slow {
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Enhanced hover scale effects */
  .hover-scale {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .hover-scale:hover {
    transform: scale(1.02) translateY(-2px);
    box-shadow: var(--shadow-elegant);
  }
  
  .hover-scale-sm {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .hover-scale-sm:hover {
    transform: scale(1.01) translateY(-1px);
    box-shadow: var(--shadow-card);
  }

  /* Enhanced interactive button effects */
  .btn-interactive {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(0);
    position: relative;
    overflow: hidden;
  }
  
  .btn-interactive:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-elegant);
  }
  
  .btn-interactive:active {
    transform: translateY(0);
    transition: all 0.1s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  /* Button ripple effect */
  .btn-interactive::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: hsl(var(--primary) / 0.1);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
  }
  
  .btn-interactive:active::before {
    width: 300px;
    height: 300px;
  }

  /* Enhanced glow effects */
  .glow-primary {
    box-shadow: 0 0 20px hsl(var(--primary) / 0.3);
    transition: all 0.3s ease;
  }
  
  .glow-primary:hover {
    box-shadow: 0 0 40px hsl(var(--primary) / 0.6), 0 0 60px hsl(var(--primary) / 0.3);
    transform: translateY(-2px);
  }
  
  /* Loading spinner animations */
  .loading-spin {
    animation: spin 1s linear infinite;
  }
  
  .loading-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  }
  
  .loading-bounce {
    animation: bounce 1s infinite;
  }
  
  /* Inference process loading animation */
  .inference-loading {
    position: relative;
    overflow: hidden;
  }
  
  .inference-loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, hsl(var(--primary) / 0.2), transparent);
    animation: shimmer 2s infinite;
  }
  
  @keyframes shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
  }
  
  /* Card hover effects */
  .card-hover {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
  }
  
  .card-hover:hover {
    transform: translateY(-4px) scale(1.01);
    box-shadow: var(--shadow-elegant);
  }
  
  /* Interactive list item effects */
  .list-item-hover {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
  }
  
  .list-item-hover::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 3px;
    background: hsl(var(--primary));
    transform: scaleY(0);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .list-item-hover:hover {
    background: hsl(var(--accent) / 0.5);
    transform: translateX(4px);
  }
  
  .list-item-hover:hover::before {
    transform: scaleY(1);
  }

  /* Academic Panel Styling */
  .academic-panel {
    background: var(--gradient-card);
    border: 1px solid hsl(var(--border));
    box-shadow: var(--shadow-medium);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .academic-panel:hover {
    box-shadow: var(--shadow-large);
    transform: translateY(-1px);
  }
  
  /* Derivation Step Highlighting */
  .derivation-step {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 0.5rem;
    padding: 0.75rem;
    box-shadow: var(--shadow-subtle);
  }
  
  .derivation-step:hover {
    background: hsl(var(--highlight) / 0.3);
    box-shadow: var(--shadow-medium);
    transform: scale(1.01);
  }
  
  .derivation-step.active {
    background: hsl(var(--highlight) / 0.5);
    border: 2px solid hsl(var(--primary));
    box-shadow: var(--shadow-medium);
  }
  
  /* Line clamp utilities for long URLs */
  .line-clamp-2 {
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
  }
  
  /* Responsive auto-grid for Typing Rules */
  .auto-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(var(--min-column-width, 280px), 1fr));
    grid-auto-columns: minmax(var(--min-column-width, 280px), 1fr);
    max-width: 100%;
  }
  
  /* Ensure rules don't get too wide on large screens */
  .auto-grid > * {
    max-width: 100%;
    min-width: 0;
  }
  
  /* Responsive grid for worklist/reduction rules */
  .auto-grid[style*="--min-column-width: 350px"] {
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  }
  
  /* Responsive grid for traditional premise/conclusion rules */
  .auto-grid[style*="--min-column-width: 280px"] {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }
}