/* ==========================================================================
   AI Avatar Expression Engine - Stylesheet
   Modern Glassmorphism & Light/Dark Color System
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@500;600;700&family=Fira+Code:wght@400;500&display=swap');

:root {
  /* Light Palette (Matches Video default) */
  --bg-primary: #F8F9FA;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-border: rgba(0, 0, 0, 0.08);
  --bg-hover: #F0F2F5;
  --text-primary: #1C1C1E;
  --text-secondary: #6E6E73;
  --text-muted: #8E8E93;
  --accent-color: #007AFF;
  --accent-glow: rgba(0, 122, 255, 0.15);
  --canvas-bg: #FFFFFF;

  /* State Glow Colors */
  --glow-thinking: rgba(50, 173, 230, 0.3);
  --glow-angry: rgba(255, 59, 48, 0.35);
  --glow-happy: rgba(52, 199, 89, 0.3);
  --glow-writing: rgba(175, 82, 222, 0.3);

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.06);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

[data-theme="dark"] {
  --bg-primary: #0D0F12;
  --bg-card: rgba(22, 26, 32, 0.75);
  --bg-card-border: rgba(255, 255, 255, 0.1);
  --bg-hover: #1C2128;
  --text-primary: #F2F4F8;
  --text-secondary: #9DA7B5;
  --text-muted: #647080;
  --accent-color: #0A84FF;
  --accent-glow: rgba(10, 132, 255, 0.25);
  --canvas-bg: #13171D;

  --shadow-md: 0 12px 40px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  transition: background-color 0.4s ease, color 0.4s ease;
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 24px;
}

/* Header Navbar */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

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

.brand-logo {
  width: 28px;
  height: 28px;
  background: var(--text-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-logo::after {
  content: '';
  width: 10px;
  height: 10px;
  background: var(--bg-primary);
  border-radius: 50%;
}

.brand h1 {
  font-family: 'Outfit', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  background: rgba(52, 199, 89, 0.12);
  color: #34C759;
}

.status-dot {
  width: 6px;
  height: 6px;
  background: #34C759;
  border-radius: 50%;
  box-shadow: 0 0 8px #34C759;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.6; }
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--bg-card-border);
  color: var(--text-primary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: var(--bg-hover);
  border-color: var(--accent-color);
}

/* Main Layout Grid */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 20px;
  flex: 1;
  min-height: 0;
  margin-bottom: 24px;
}

@media (max-width: 1024px) {
  .main-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
}

/* Left Panel: Canvas Stage */
.stage-panel {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow-y: auto;
}

.stage-top-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.emotion-active-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 6px 16px;
  border-radius: 30px;
  background: var(--bg-hover);
  border: 1px solid var(--bg-card-border);
  transition: all 0.3s ease;
}

.canvas-container {
  width: 100%;
  max-width: 440px;
  aspect-ratio: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

canvas {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-md);
  background: var(--canvas-bg);
  box-shadow: inset 0 0 0 1px var(--bg-card-border);
  cursor: grab;
  transition: background-color 0.4s ease;
}

canvas:active {
  cursor: grabbing;
}

/* Manual Expression Switcher Bar */
.manual-controls {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.controls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

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

.btn-tour {
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  border: 1px solid rgba(139, 92, 246, 0.4);
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(59, 130, 246, 0.2));
  color: var(--text-heading);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 10px rgba(139, 92, 246, 0.15);
}

.btn-tour:hover {
  transform: translateY(-1.5px);
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.35), rgba(59, 130, 246, 0.35));
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
}

.btn-tour.playing {
  background: linear-gradient(135deg, #10B981, #059669);
  border-color: #10B981;
  color: #FFFFFF;
  animation: pulse-tour 1.8s infinite ease-in-out;
}

@keyframes pulse-tour {
  0%, 100% { box-shadow: 0 0 10px rgba(16, 185, 129, 0.4); }
  50% { box-shadow: 0 0 22px rgba(16, 185, 129, 0.8); }
}

.emotion-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}

@media (max-width: 600px) {
  .emotion-buttons {
    grid-template-columns: repeat(3, 1fr);
  }
}

.emotion-buttons::-webkit-scrollbar {
  width: 6px;
}

.emotion-buttons::-webkit-scrollbar-track {
  background: transparent;
}

.emotion-buttons::-webkit-scrollbar-thumb {
  background: var(--bg-card-border);
  border-radius: 4px;
}

.emotion-buttons::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.btn-emotion {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--bg-card-border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.btn-emotion:hover {
  background: var(--bg-hover);
  transform: translateY(-1px);
}

.btn-emotion.active {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
  font-weight: 600;
}

/* Right Panel: Dialogue & Sentiment */
.dialogue-panel {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  min-height: 520px;
}

.dialogue-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--bg-card-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sentiment-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}

.confidence-bar-bg {
  width: 80px;
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
}

.confidence-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-color);
  transition: width 0.4s ease;
}

.chat-history {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-bubble {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.5;
  animation: fadeIn 0.3s ease;
}

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

.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent-color);
  color: #FFFFFF;
  border-bottom-right-radius: 4px;
}

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

.bubble-meta {
  font-size: 0.7rem;
  opacity: 0.65;
  margin-top: 4px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

/* Preset Prompt Chips */
.preset-prompts {
  padding: 10px 20px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  border-top: 1px solid var(--bg-card-border);
  background: rgba(0, 0, 0, 0.02);
}

.preset-chip {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--bg-card-border);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-size: 0.78rem;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
}

.preset-chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent-color);
}

/* Chat Input Bar */
.chat-input-area {
  padding: 16px 20px;
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--bg-card-border);
}

.chat-input {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-card-border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.chat-input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn-send {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--text-primary);
  color: var(--bg-primary);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-send:hover {
  opacity: 0.9;
  transform: scale(1.02);
}

/* Navigation Mode Tabs */
.mode-tabs {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  background: var(--bg-card);
  padding: 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-card-border);
}

.mode-tab {
  flex: 1;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.25s ease;
}

.mode-tab:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.mode-tab.active {
  background: var(--bg-primary);
  color: var(--text-heading);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

/* Studio Panel Styling */
.studio-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--bg-card-border);
  padding: 20px;
  gap: 16px;
  box-shadow: var(--shadow-card);
  overflow-y: auto;
  max-height: 800px;
}

.studio-panel.hidden,
.dialogue-panel.hidden {
  display: none !important;
}

.studio-header {
  border-bottom: 1px solid var(--bg-card-border);
  padding-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.studio-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.studio-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  border: 1px solid var(--bg-card-border);
}

.save-form-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.input-emoji {
  width: 44px;
  padding: 8px;
  text-align: center;
  font-size: 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--bg-card-border);
  background: var(--bg-card);
  color: var(--text-primary);
}

.input-custom-name {
  flex: 1;
  padding: 8px 12px;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--bg-card-border);
  background: var(--bg-card);
  color: var(--text-primary);
  outline: none;
}

.btn-emotion.custom {
  border-color: rgba(139, 92, 246, 0.6);
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(236, 72, 153, 0.15));
  font-weight: 600;
}

.studio-group-title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-heading);
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.studio-chip,
.studio-eye-chip {
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 500;
  border-radius: var(--radius-full);
  border: 1px solid var(--bg-card-border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.studio-chip:hover,
.studio-eye-chip:hover {
  border-color: var(--accent-color);
  color: var(--text-primary);
}

.studio-chip.active,
.studio-eye-chip.active {
  background: var(--text-primary);
  color: var(--bg-primary);
  border-color: var(--text-primary);
  font-weight: 600;
}

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

.slider-control {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.slider-control input[type="range"] {
  width: 100%;
  accent-color: var(--accent-color);
}

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

.select-control {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.studio-select {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--bg-card-border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.82rem;
  outline: none;
}

.checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 6px;
}

.studio-toggle {
  font-size: 0.8rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.actions-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  background: transparent;
  padding: 0;
  border: none;
}

.btn-action {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  border: none;
}

.btn-action.primary {
  background: linear-gradient(135deg, #10B981, #059669);
  color: #FFFFFF;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
}

.btn-action.primary:hover {
  transform: translateY(-1.5px);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.4);
}

.btn-action.secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--bg-card-border);
}

.btn-action.secondary:hover {
  border-color: var(--text-primary);
  transform: translateY(-1.5px);
}

/* Modal for Code Integration */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 100;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 90%;
  max-width: 680px;
  background: var(--bg-primary);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-body pre {
  background: #1E1E1E;
  color: #D4D4D4;
  padding: 16px;
  border-radius: var(--radius-sm);
  font-family: 'Fira Code', monospace;
  font-size: 0.82rem;
  max-height: 380px;
  overflow-y: auto;
}
