/**
 * SuperClaude Magic 8-Ball - Enhanced UI/UX
 * Frontend Persona + Magic MCP + Ultra Compressed Design
 */

/* CSS Custom Properties (Design System) */
:root {
  /* Colors */
  --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --dark-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  --ball-surface: radial-gradient(ellipse at 25% 25%, #4a4a4a 0%, #1a1a1a 50%, #000 100%);
  --ball-highlight: radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.8) 0%, rgba(255,255,255,0.3) 30%, transparent 60%);
  --answer-window: radial-gradient(ellipse, rgba(20,20,60,0.9) 0%, rgba(0,0,20,0.95) 100%);
  
  /* Shadows & Effects */
  --shadow-primary: 0 20px 60px rgba(0,0,0,0.4);
  --shadow-elevated: 0 30px 80px rgba(0,0,0,0.5);
  --shadow-inset: inset 0 10px 30px rgba(255,255,255,0.1);
  --glow-primary: 0 0 40px rgba(102, 126, 234, 0.3);
  
  /* Typography */
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mystical: 'Georgia', serif;
  
  /* Timing */
  --duration-fast: 0.2s;
  --duration-medium: 0.4s;
  --duration-slow: 0.8s;
  --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark theme variables */
[data-theme="dark"] {
  --primary-gradient: var(--dark-gradient);
  --text-primary: #ffffff;
  --text-secondary: rgba(255,255,255,0.8);
}

/* Reset & Base */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-primary);
  background: var(--primary-gradient);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background var(--duration-medium) var(--ease-smooth);
  overflow-x: hidden;
}

/* Theme Toggle */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 50px;
  height: 26px;
  background: rgba(255,255,255,0.2);
  border-radius: 13px;
  border: none;
  cursor: pointer;
  transition: all var(--duration-medium);
  backdrop-filter: blur(10px);
  z-index: 100;
}

.theme-toggle::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform var(--duration-medium) var(--ease-bounce);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

[data-theme="dark"] .theme-toggle::before {
  transform: translateX(24px);
  background: #1a1a2e;
}

/* Main Container */
.container {
  text-align: center;
  color: white;
  max-width: 500px;
  width: 100%;
  padding: 2rem;
  position: relative;
}

/* Typography */
h1 {
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  margin-bottom: 0.5rem;
  text-shadow: 2px 4px 8px rgba(0,0,0,0.4);
  background: linear-gradient(45deg, #fff, #e0e7ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 1.125rem;
  margin-bottom: 2rem;
  opacity: 0.9;
  font-weight: 400;
  letter-spacing: 0.01em;
}

/* Input Section */
.input-section {
  margin-bottom: 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  perspective: 1000px;
}

#questionInput {
  padding: 1rem 1.5rem;
  font-size: 1rem;
  border: none;
  border-radius: 2rem;
  background: rgba(255,255,255,0.95);
  color: #1a1a2e;
  outline: none;
  transition: all var(--duration-medium) var(--ease-smooth);
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
  backdrop-filter: blur(10px);
  font-family: var(--font-primary);
  width: 100%;
  text-align: center;
}

#questionInput:focus {
  background: white;
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 12px 40px rgba(0,0,0,0.15), var(--glow-primary);
}

#questionInput::placeholder {
  color: #6b7280;
  font-weight: 400;
}

/* Enhanced Shake Button */
#shakeButton {
  padding: 1rem 2rem;
  font-size: 1.125rem;
  font-weight: 600;
  border: none;
  border-radius: 2rem;
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 50%, #ff3838 100%);
  color: white;
  cursor: pointer;
  transition: all var(--duration-medium) var(--ease-bounce);
  box-shadow: 0 8px 32px rgba(255,107,107,0.3);
  position: relative;
  overflow: hidden;
  font-family: var(--font-primary);
  letter-spacing: 0.02em;
  transform-style: preserve-3d;
}

#shakeButton::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  transition: left var(--duration-slow);
}

#shakeButton:hover {
  transform: translateY(-4px) scale(1.05);
  box-shadow: 0 16px 48px rgba(255,107,107,0.4), var(--glow-primary);
}

#shakeButton:hover::before {
  left: 100%;
}

#shakeButton:active {
  transform: translateY(-2px) scale(1.02);
}

#shakeButton:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

/* Revolutionary 3D Magic 8-Ball */
.magic-ball-container {
  perspective: 1200px;
  perspective-origin: center center;
  margin: 0 auto;
  width: 320px;
  height: 320px;
  position: relative;
}

#eightBall {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform var(--duration-slow) var(--ease-smooth);
  cursor: pointer;
}

/* Sphere Base */
.sphere {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--ball-surface);
  position: relative;
  box-shadow: 
    var(--shadow-primary),
    var(--shadow-inset),
    inset 0 -20px 40px rgba(0,0,0,0.4);
  border: 2px solid #111;
  transform-style: preserve-3d;
}

/* Sphere Highlight */
.sphere::before {
  content: '';
  position: absolute;
  top: 10%;
  left: 20%;
  width: 60%;
  height: 40%;
  border-radius: 50%;
  background: var(--ball-highlight);
  opacity: 0.6;
  filter: blur(1px);
  transform: rotate(-15deg);
}

/* Number 8 Circle */
.number-eight {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translateX(-50%) rotateX(15deg);
  width: 48px;
  height: 48px;
  background: radial-gradient(circle, #ffffff 0%, #f0f0f0 100%);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 900;
  font-size: 1.5rem;
  color: #1a1a2e;
  box-shadow: 
    0 4px 16px rgba(0,0,0,0.3),
    inset 0 2px 8px rgba(255,255,255,0.5),
    inset 0 -2px 8px rgba(0,0,0,0.1);
  font-family: var(--font-primary);
  z-index: 10;
}

/* Answer Window */
.answer-window {
  position: absolute;
  bottom: 25%;
  left: 50%;
  transform: translateX(-50%) rotateX(-10deg);
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: var(--answer-window);
  display: flex;
  justify-content: center;
  align-items: center;
  border: 3px solid rgba(0,20,60,0.8);
  box-shadow: 
    inset 0 8px 32px rgba(0,0,0,0.6),
    0 0 20px rgba(20,20,60,0.4);
  backdrop-filter: blur(2px);
}

/* Floating Answer Text */
#answerText {
  color: #e0f2fe;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
  padding: 1rem;
  opacity: 0;
  transition: all 1.5s var(--ease-smooth);
  position: absolute;
  width: 90%;
  line-height: 1.3;
  text-shadow: 
    0 0 10px rgba(224,242,254,0.8),
    0 2px 4px rgba(0,0,0,0.9);
  font-family: var(--font-mystical);
  letter-spacing: 0.02em;
  transform: translateY(10px) scale(0.9);
  z-index: 5;
}

#answerText.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  animation: mysticalGlow 2s ease-in-out infinite alternate;
}

@keyframes mysticalGlow {
  from { text-shadow: 0 0 10px rgba(224,242,254,0.8), 0 2px 4px rgba(0,0,0,0.9); }
  to { text-shadow: 0 0 20px rgba(224,242,254,1), 0 2px 4px rgba(0,0,0,0.9); }
}

/* Loading Animation */
#loadingMessage {
  color: #e0f2fe;
  font-size: 0.875rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  font-family: var(--font-primary);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(224,242,254,0.3);
  border-top: 3px solid #e0f2fe;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Physics-based Shake Animation */
@keyframes physicsShake {
  0% { transform: translateX(0) rotateZ(0deg) rotateY(0deg); }
  10% { transform: translateX(-8px) rotateZ(-3deg) rotateY(-5deg); }
  20% { transform: translateX(8px) rotateZ(2deg) rotateY(5deg); }
  30% { transform: translateX(-6px) rotateZ(-2deg) rotateY(-3deg); }
  40% { transform: translateX(6px) rotateZ(2deg) rotateY(3deg); }
  50% { transform: translateX(-4px) rotateZ(-1deg) rotateY(-2deg); }
  60% { transform: translateX(4px) rotateZ(1deg) rotateY(2deg); }
  70% { transform: translateX(-2px) rotateZ(-0.5deg) rotateY(-1deg); }
  80% { transform: translateX(2px) rotateZ(0.5deg) rotateY(1deg); }
  90% { transform: translateX(-1px) rotateZ(-0.2deg) rotateY(-0.5deg); }
  100% { transform: translateX(0) rotateZ(0deg) rotateY(0deg); }
}

.shaking {
  animation: physicsShake 1.2s ease-out;
}

/* Interactive Effects */
.magic-ball-container:hover .sphere {
  transform: rotateY(5deg) rotateX(2deg);
  box-shadow: 
    var(--shadow-elevated),
    var(--shadow-inset),
    inset 0 -20px 40px rgba(0,0,0,0.4),
    var(--glow-primary);
}

/* Accessibility Features */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus Styles */
#questionInput:focus,
#shakeButton:focus {
  outline: 3px solid rgba(255,255,255,0.6);
  outline-offset: 2px;
}

.theme-toggle:focus {
  outline: 2px solid rgba(255,255,255,0.8);
  outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  :root {
    --ball-surface: radial-gradient(ellipse at 25% 25%, #ffffff 0%, #666666 50%, #000000 100%);
    --answer-window: radial-gradient(ellipse, rgba(255,255,255,0.95) 0%, rgba(200,200,200,0.98) 100%);
  }
  
  #answerText {
    color: #000000;
    text-shadow: none;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .shaking {
    animation: none;
    transform: translateX(2px);
  }
}

/* Responsive Design */
@media (max-width: 480px) {
  .container {
    padding: 1.5rem 1rem;
  }
  
  .magic-ball-container {
    width: 280px;
    height: 280px;
  }
  
  .answer-window {
    width: 120px;
    height: 120px;
  }
  
  #answerText {
    font-size: 0.8rem;
    padding: 0.75rem;
  }
  
  .number-eight {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
  }
  
  .theme-toggle {
    top: 15px;
    right: 15px;
    width: 44px;
    height: 24px;
  }
}

@media (max-width: 320px) {
  .magic-ball-container {
    width: 240px;
    height: 240px;
  }
  
  .answer-window {
    width: 100px;
    height: 100px;
  }
  
  #answerText {
    font-size: 0.75rem;
  }
}

/* Performance Optimizations */
.sphere,
.answer-window,
#answerText {
  will-change: transform, opacity;
}

/* Print Styles */
@media print {
  body {
    background: white;
    color: black;
  }
  
  .theme-toggle {
    display: none;
  }
  
  .magic-ball-container {
    filter: grayscale(100%);
  }
}