/* ============================================================================
   DEADHYDRA AI - ENHANCED UI/UX
   Modern glassmorphism dark theme with premium feel
   Optimized for mobile and desktop
   ============================================================================ */

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.4);
  --secondary: #ec4899;
  --secondary-hover: #db2777;
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.4);
  --warning: #f59e0b;
  --warning-glow: rgba(245, 158, 11, 0.4);
  --purple: #8b5cf6;
  --purple-glow: rgba(139, 92, 246, 0.4);
  
  --bg-dark: #030712;
  --bg-card: rgba(17, 24, 39, 0.8);
  --bg-card-hover: rgba(31, 41, 55, 0.9);
  --bg-input: rgba(17, 24, 39, 0.9);
  --bg-glass: rgba(255, 255, 255, 0.03);
  
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px var(--primary-glow);
  
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;
}

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

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-dark);
  background-image: 
    radial-gradient(ellipse at top, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(236, 72, 153, 0.1) 0%, transparent 50%),
    radial-gradient(ellipse at bottom left, rgba(139, 92, 246, 0.1) 0%, transparent 50%);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
}

/* Smooth scrolling */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* ============================================================================
   APP LAYOUT
   ============================================================================ */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
  gap: 16px;
}

/* ============================================================================
   HEADER
   ============================================================================ */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  gap: 16px;
  flex-wrap: wrap;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: white;
  box-shadow: var(--shadow-md);
}

.header-text h1 {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--text-primary), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.813rem;
  font-weight: 500;
}

.subtitle a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.subtitle a:hover {
  color: var(--secondary);
}

/* Status Badge */
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 50px;
  font-weight: 600;
  font-size: 0.813rem;
  letter-spacing: 0.02em;
  transition: all var(--transition-normal);
  background: var(--bg-glass);
  border: 1px solid var(--border);
}

.status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: none;
}

.status.listening {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: #34d399;
  box-shadow: 0 0 20px var(--success-glow);
}

.status.listening::before {
  background: var(--success);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

.status.thinking {
  background: rgba(245, 158, 11, 0.1);
  border-color: rgba(245, 158, 11, 0.3);
  color: #fbbf24;
  box-shadow: 0 0 20px var(--warning-glow);
}

.status.thinking::before {
  background: var(--warning);
  animation: pulse-dot 0.8s ease-in-out infinite;
}

.status.speaking {
  background: rgba(139, 92, 246, 0.1);
  border-color: rgba(139, 92, 246, 0.3);
  color: #a78bfa;
  box-shadow: 0 0 20px var(--purple-glow);
}

.status.speaking::before {
  background: var(--purple);
  animation: pulse-dot 1s ease-in-out infinite;
}

.status.error {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.7; }
}

/* ============================================================================
   MAIN LAYOUT
   ============================================================================ */

main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  flex: 1;
  min-height: 0;
}

/* ============================================================================
   PANELS - Glassmorphism Cards
   ============================================================================ */

.avatar-panel, .chat-panel {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.avatar-panel:hover, .chat-panel:hover {
  border-color: var(--border-hover);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.panel-header .icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: white;
}

.panel-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ============================================================================
   AVATAR CANVAS
   ============================================================================ */

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-height: 380px;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: radial-gradient(circle at 50% 30%, rgba(99, 102, 241, 0.1) 0%, transparent 60%),
              radial-gradient(circle at center, #111827 0%, #030712 100%);
  border: 1px solid var(--border);
}

#avatarCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(3, 7, 18, 0.95);
  gap: 16px;
  z-index: 10;
}

.loading-overlay.hidden {
  display: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-text {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================================
   CONTROLS
   ============================================================================ */

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.selectors-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.selector-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.selector-group label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

select {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
}

select:hover {
  border-color: var(--border-hover);
  background-color: var(--bg-card-hover);
}

select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* Action Buttons */
.buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  border: none;
  font-size: 0.938rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.btn i {
  font-size: 1rem;
}

.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: white;
  box-shadow: var(--shadow-sm);
}

.btn.primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md), 0 0 30px var(--primary-glow);
}

.btn.primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn.primary.active {
  background: linear-gradient(135deg, var(--success), #059669);
  animation: glow-pulse 2s ease-in-out infinite;
}

@keyframes glow-pulse {
  0%, 100% { box-shadow: var(--shadow-sm), 0 0 20px var(--success-glow); }
  50% { box-shadow: var(--shadow-md), 0 0 40px var(--success-glow); }
}

.btn.secondary {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn.secondary:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  transform: translateY(-2px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ============================================================================
   CHAT PANEL
   ============================================================================ */

.chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 200px;
  max-height: 450px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

/* Custom Scrollbar */
.chat-log::-webkit-scrollbar {
  width: 6px;
}

.chat-log::-webkit-scrollbar-track {
  background: transparent;
}

.chat-log::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.chat-log::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Welcome Message */
.welcome-message {
  text-align: center;
  padding: 32px 20px;
}

.welcome-message .welcome-icon {
  font-size: 3rem;
  margin-bottom: 16px;
  display: block;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-message h3 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.welcome-message p {
  color: var(--text-secondary);
  font-size: 0.938rem;
  line-height: 1.6;
}

.welcome-message strong {
  color: var(--primary);
}

.welcome-message .hint {
  margin-top: 16px;
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.welcome-message .hint-tag {
  padding: 6px 12px;
  background: var(--bg-glass);
  border: 1px solid var(--border);
  border-radius: 50px;
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.welcome-message .hint-tag i {
  font-size: 0.7rem;
  color: var(--primary);
}

/* Chat Bubbles */
.chat-bubble {
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  max-width: 85%;
  word-wrap: break-word;
  font-size: 0.938rem;
  line-height: 1.6;
  animation: bubble-in 0.3s ease;
  position: relative;
}

@keyframes bubble-in {
  from { 
    opacity: 0; 
    transform: translateY(10px) scale(0.98); 
  }
  to { 
    opacity: 1; 
    transform: translateY(0) scale(1); 
  }
}

.chat-bubble.user {
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.chat-bubble.assistant {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.chat-bubble.assistant strong {
  color: var(--primary);
  font-weight: 600;
}

.chat-bubble.assistant em {
  color: var(--text-secondary);
  font-style: italic;
}

.chat-bubble.assistant code {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.85em;
}

.chat-bubble.assistant pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.chat-bubble.assistant pre code {
  background: none;
  padding: 0;
}

.chat-bubble.error {
  background: rgba(239, 68, 68, 0.1);
  color: #fca5a5;
  align-self: center;
  text-align: center;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* ============================================================================
   INPUT AREA
   ============================================================================ */

.input-row {
  display: flex;
  gap: 10px;
  padding: 4px;
  background: var(--bg-input);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input-row:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
  
}

#textInput {
  flex: 1;
  padding: 14px 16px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.938rem;
  font-weight: 500;
}

#textInput::placeholder {
  color: var(--text-muted);
}

#textInput:focus {
  outline: none;
  border-radius: var(--radius-lg);
}

#sendButton {
  padding: 14px 24px;
  border-radius: var(--radius-md);
  margin: 4px;
}

/* ============================================================================
   FOOTER
   ============================================================================ */

footer {
  text-align: center;
  padding: 20px;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
}

footer p {
  color: var(--text-secondary);
  font-size: 0.813rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

footer p i {
  color: var(--primary);
}

footer a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  transition: color var(--transition-fast);
}

footer a:hover {
  color: var(--secondary);
}

footer .divider {
  color: var(--text-muted);
}

/* ============================================================================
   RESPONSIVE - TABLET
   ============================================================================ */

@media (max-width: 1024px) {
  .app {
    padding: 12px;
  }
  
  main {
    gap: 12px;
  }
  
  .avatar-panel, .chat-panel {
    padding: 16px;
  }
  
  .canvas-wrap {
    max-height: 320px;
  }
}

/* ============================================================================
   RESPONSIVE - MOBILE
   ============================================================================ */

@media (max-width: 768px) {
  main {
    grid-template-columns: 1fr;
  }
  
  header {
    padding: 14px 16px;
    border-radius: var(--radius-lg);
  }
  
  .logo {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }
  
  .header-text h1 {
    font-size: 1.25rem;
  }
  
  .subtitle {
    font-size: 0.75rem;
  }
  
  .status {
    padding: 8px 14px;
    font-size: 0.75rem;
  }
  
  .avatar-panel, .chat-panel {
    border-radius: var(--radius-lg);
    padding: 14px;
  }
  
  .canvas-wrap {
    max-height: 280px;
    aspect-ratio: 4/3;
  }
  
  .selectors-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  
  .buttons {
    grid-template-columns: 1fr 1fr;
  }
  
  .btn {
    padding: 12px 16px;
    font-size: 0.875rem;
  }
  
  .chat-log {
    min-height: 250px;
    max-height: 350px;
    padding: 12px;
  }
  
  .chat-bubble {
    max-width: 90%;
    padding: 12px 14px;
    font-size: 0.875rem;
  }
  
  #textInput {
    padding: 12px 14px;
    font-size: 1rem; /* Prevents zoom on iOS */
  }
  
  #sendButton {
    padding: 12px 18px;
  }
  
  footer {
    border-radius: var(--radius-lg);
    padding: 16px;
  }
  
  footer p {
    font-size: 0.75rem;
  }
}

/* ============================================================================
   RESPONSIVE - SMALL MOBILE
   ============================================================================ */

@media (max-width: 400px) {
  .app {
    padding: 8px;
    gap: 10px;
  }
  
  header {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
  
  .header-left {
    justify-content: center;
  }
  
  .status {
    align-self: center;
  }
  
  .buttons {
    grid-template-columns: 1fr;
  }
  
  .canvas-wrap {
    max-height: 240px;
  }
  
  .welcome-message {
    padding: 20px 12px;
  }
  
  .welcome-message .emoji {
    font-size: 2.5rem;
  }
  
  .welcome-message h3 {
    font-size: 1.125rem;
  }
}

/* ============================================================================
   DARK MODE ENHANCEMENTS
   ============================================================================ */

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
  }
}

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */

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

/* Focus visible for keyboard navigation */
.btn:focus-visible,
select:focus-visible,
#textInput:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ============================================================================
   TOUCH OPTIMIZATIONS
   ============================================================================ */

@media (hover: none) and (pointer: coarse) {
  .btn:hover {
    transform: none;
  }
  
  .btn:active {
    transform: scale(0.98);
  }
  
  select, .btn, #textInput {
    min-height: 48px;
  }
}
