/**
 * Soupy - Main Styles
 * 
 * AI Agent Guide:
 * - Global styles & resets
 * - Layout & positioning
 * - Component styles (orb, UI, settings, debug)
 * - Animations
 * - Mobile responsive
 */

/* ============================================================================
   GLOBAL STYLES & RESET
   ============================================================================ */

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: #1c1c1c;
  color: white;
  /* Mobile optimizations */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* ============================================================================
   CANVAS & 3D SCENE
   ============================================================================ */

#canvas-container {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  z-index: 1;
}

/* ============================================================================
   LOGO
   ============================================================================ */

#logo {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-family: Georgia, serif;
  font-size: 1.5rem;
  font-weight: 300;
  color: rgba(255, 255, 255, 0.7);
  z-index: 5;
  pointer-events: none;
  transition: opacity 0.3s ease;
  letter-spacing: 0.1em;
}

#logo:hover {
  opacity: 1;
}

/* ============================================================================
   SETTINGS BUTTON
   ============================================================================ */

#settings-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  min-height: 40px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 10px;
  cursor: pointer;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: none;
}

#settings-icon {
  display: flex;
  flex-direction: column;
  gap: 3px;
  pointer-events: none;
}

.hamburger-line {
  width: 18px;
  height: 2px;
  background: white;
  border-radius: 1px;
  transition: all 0.3s ease;
}

@media (hover: hover) and (pointer: fine) {
  #settings-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
  }
  
  #settings-btn:hover .hamburger-line {
    background: rgba(255, 255, 255, 1);
  }
}

#settings-btn:active {
  transform: scale(0.95);
}

/* ============================================================================
   MEMORY INDICATOR
   ============================================================================ */

#memory-indicator {
  position: fixed;
  top: 20px;
  left: 20px;
  display: none !important; /* Hidden for now - remove !important to re-enable */
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(107, 70, 193, 0.15);
  border: 1px solid rgba(107, 70, 193, 0.3);
  border-radius: 20px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.9);
  animation: fadeIn 0.3s ease;
}

#memory-indicator .memory-icon {
  font-size: 16px;
  animation: pulse 2s ease-in-out infinite;
}

#memory-indicator .memory-count {
  font-weight: 600;
  color: #a78bfa;
  min-width: 12px;
  text-align: center;
}

#memory-indicator .memory-clear {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.7);
  font-size: 18px;
  line-height: 1;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 0;
  margin-left: 4px;
}

#memory-indicator .memory-clear:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  color: #ef4444;
  transform: scale(1.1);
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mobile adjustments for memory indicator */
@media (max-width: 768px) {
  #memory-indicator {
    top: 10px;
    left: 10px;
    padding: 6px 10px;
    font-size: 12px;
  }
  
  #memory-indicator .memory-icon {
    font-size: 14px;
  }
  
  #memory-indicator .memory-clear {
    width: 18px;
    height: 18px;
    font-size: 16px;
  }
}

/* ============================================================================
   USER INTERFACE
   ============================================================================ */

#ui {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 650px;
  z-index: 10;
  /* Safe area for notched devices */
  padding-bottom: env(safe-area-inset-bottom);
}

/* Movie-style captions - visible on any background */
#response-text {
  color: white;
  text-align: center;
  margin-bottom: 20px;
  min-height: 60px;
  padding: 8px 20px;
  font-size: 18px;
  line-height: 1.5;
  letter-spacing: 0.03em;
  font-weight: 500;
  /* Black text shadow for visibility (like movie subtitles) */
  text-shadow: 
    -2px -2px 4px rgba(0, 0, 0, 0.9),
    2px -2px 4px rgba(0, 0, 0, 0.9),
    -2px 2px 4px rgba(0, 0, 0, 0.9),
    2px 2px 4px rgba(0, 0, 0, 0.9),
    0 0 8px rgba(0, 0, 0, 0.8);
}

/* Subtle glass input box - blends with scenes */
#input-container {
  display: flex;
  gap: 12px;
  /* Subtle background - just enough for visibility */
  background: 
    linear-gradient(
      135deg,
      rgba(0, 0, 0, 0.35),
      rgba(0, 0, 0, 0.3)
    ),
    rgba(255, 255, 255, 0.06);
  /* Reduced blur for subtlety, less saturation */
  backdrop-filter: blur(12px) saturate(120%);
  -webkit-backdrop-filter: blur(12px) saturate(120%);
  padding: 18px 24px;
  border-radius: 30px;
  /* More visible, crisp border */
  border: 1.5px solid rgba(255, 255, 255, 0.4);
  /* Subtle shadow - less glowy */
  box-shadow: 
    0 4px 16px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transition: all 0.3s ease;
}

#user-input {
  flex: 1;
  background: transparent;
  border: none;
  color: white;
  font-size: 16px;
  outline: none;
  padding: 0;
}

#user-input::placeholder {
  color: rgba(255, 255, 255, 0.5);
}

#send-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  padding: 10px 22px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.2s ease;
  white-space: nowrap;
  min-height: 44px;
}

#send-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

#send-btn:active:not(:disabled) {
  transform: translateY(0);
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================================
   ANIMATIONS
   ============================================================================ */

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ============================================================================
   DEBUG PANEL
   ============================================================================ */

#debug-panel {
  position: absolute;
  top: 100px;
  right: 20px;
  background: rgba(0, 0, 0, 0.85);
  border: 2px solid #00ff00;
  border-radius: 8px;
  padding: 15px;
  color: #00ff00;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  z-index: 100;
  max-width: 450px;
  max-height: 80vh;
  overflow-y: auto;
  line-height: 1.6;
  /* Hidden by default - JavaScript will show it if DEBUG_MODE is true */
  display: none;
}

#debug-panel h3 {
  margin: 0 0 10px 0;
  font-size: 14px;
  color: #00ff00;
  border-bottom: 1px solid #00ff00;
  padding-bottom: 5px;
}

#debug-state {
  margin-bottom: 10px;
}

#debug-current-scene {
  margin-bottom: 10px;
  color: #ffff00;
}

#debug-queue {
  color: #00aaff;
  font-size: 11px;
}

#debug-timer {
  margin-bottom: 10px;
  color: #ff9900;
}

#debug-text-length {
  color: #cc00ff;
  font-size: 11px;
}

.debug-section {
  margin-top: 15px;
  padding-top: 10px;
  border-top: 1px solid #00ff00;
}

.debug-subtitle {
  font-weight: bold;
  color: #00ffff;
  margin-bottom: 8px;
  font-size: 12px;
}

#debug-raw-stream, #debug-scene-code {
  background: rgba(0, 0, 0, 0.5);
  padding: 8px;
  border-radius: 4px;
  max-height: 180px;
  overflow-y: auto;
  font-size: 10px;
  line-height: 1.4;
  color: #aaaaaa;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid #444;
  font-family: 'Courier New', monospace;
}

#debug-scene-code {
  color: #ffaa00;
  border-color: #ffaa00;
}

#debug-raw-stream::-webkit-scrollbar, #debug-scene-code::-webkit-scrollbar {
  width: 6px;
}

#debug-raw-stream::-webkit-scrollbar-track, #debug-scene-code::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.3);
}

#debug-raw-stream::-webkit-scrollbar-thumb {
  background: #00ff00;
  border-radius: 3px;
}

#debug-scene-code::-webkit-scrollbar-thumb {
  background: #ffaa00;
  border-radius: 3px;
}

/* ============================================================================
   SETTINGS MODAL
   ============================================================================ */

#settings-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

#settings-modal.open {
  display: flex;
}

.settings-content {
  background: rgba(40, 40, 40, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 16px;
  padding: 32px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.settings-content h2 {
  margin: 0 0 24px 0;
  font-size: 1.5rem;
  font-weight: 600;
  color: #fff;
}

.setting-item {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.setting-item:last-of-type {
  border-bottom: none;
  margin-bottom: 32px;
  padding-bottom: 0;
}

.setting-item label {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.9);
}

.setting-label {
  font-weight: 500;
}

.toggle-btn {
  padding: 8px 20px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s ease;
  min-width: 80px;
}

.toggle-btn.active {
  background: rgba(76, 175, 80, 0.2);
  border-color: rgba(76, 175, 80, 0.5);
  color: #4CAF50;
}

.toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
}

.speed-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.speed-btn {
  flex: 1;
  min-width: 60px;
  padding: 10px 16px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.2s ease;
}

.speed-btn.active {
  background: rgba(33, 150, 243, 0.2);
  border-color: rgba(33, 150, 243, 0.5);
  color: #2196F3;
}

.speed-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

/* Voice Buttons */
.voice-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.voice-btn {
  padding: 12px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.95rem;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.voice-btn .voice-name {
  font-weight: 600;
  font-size: 1rem;
}

.voice-btn .voice-desc {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.6);
}

.voice-btn.active {
  background: rgba(33, 150, 243, 0.2);
  border-color: rgba(33, 150, 243, 0.5);
  color: #2196F3;
}

.voice-btn.active .voice-desc {
  color: rgba(33, 150, 243, 0.8);
}

.voice-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.close-btn {
  width: 100%;
  padding: 12px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.settings-credit {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  text-align: center;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.5);
  font-weight: 300;
}

.settings-credit a {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.settings-credit a:hover {
  color: #ff6b9d;
}

/* ============================================================================
   MOBILE & RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
  #logo {
    font-size: 1.25rem;
    top: 16px;
  }
  
  #settings-btn {
    top: max(16px, env(safe-area-inset-top, 16px) + 8px);
    right: 16px;
    width: 44px;
    height: 44px;
    min-height: 44px;
  }
  
  #settings-icon {
    gap: 4px;
  }
  
  .hamburger-line {
    width: 20px;
    height: 2px;
  }
  
  #ui {
    width: 92%;
    bottom: 20px;
  }
  
  #response-text {
    font-size: 16px;
    min-height: 50px;
    padding: 6px 16px;
    margin-bottom: 16px;
  }
  
  .settings-content {
    padding: 20px;
    max-width: 85%;
  }
  
  .settings-content h2 {
    font-size: 1.3rem;
    margin-bottom: 20px;
  }
  
  .setting-item {
    margin-bottom: 20px;
    padding-bottom: 20px;
  }
  
  .setting-item:last-of-type {
    margin-bottom: 24px;
  }
  
  .speed-buttons {
    gap: 6px;
  }
  
  .speed-btn {
    min-width: 50px;
    padding: 8px 12px;
    font-size: 0.9rem;
  }
  
  .voice-buttons {
    gap: 6px;
  }
  
  .voice-btn {
    padding: 10px;
  }
  
  .voice-btn .voice-name {
    font-size: 0.95rem;
  }
  
  .voice-btn .voice-desc {
    font-size: 0.8rem;
  }
}

@media (max-width: 480px) {
  #ui {
    width: 94%;
    bottom: 16px;
  }
  
  #response-text {
    font-size: 15px;
    min-height: 45px;
    padding: 6px 12px;
    margin-bottom: 12px;
    line-height: 1.4;
  }
  
  #input-container {
    padding: 14px 18px;
  }
  
  #user-input {
    font-size: 16px;
  }
  
  #send-btn {
    padding: 8px 18px;
    font-size: 14px;
  }
  
  .settings-content {
    padding: 16px;
    max-width: 90%;
    max-height: 85vh;
    overflow-y: auto;
  }
  
  .settings-content h2 {
    font-size: 1.2rem;
    margin-bottom: 16px;
  }
  
  .setting-item {
    margin-bottom: 16px;
    padding-bottom: 16px;
  }
  
  .setting-item:last-of-type {
    margin-bottom: 20px;
  }
  
  .setting-item label {
    margin-bottom: 8px;
    font-size: 0.95rem;
  }
  
  .voice-btn {
    padding: 8px;
  }
  
  .voice-btn .voice-name {
    font-size: 0.9rem;
  }
  
  .voice-btn .voice-desc {
    font-size: 0.75rem;
  }
  
  .close-btn {
    padding: 10px;
    font-size: 0.95rem;
  }
  
  .settings-credit {
    font-size: 0.75rem;
    margin-top: 12px;
  }
}

