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

html,
body {
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #ffffff;
  color: #333;
}

.portal-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 100%;
  overflow: hidden;
}

/* Avatar Section */
.avatar-section {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 20px;
  background: #ffffff;
}

/* Reset Button (Top Left) */
.reset-btn {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: white;
  font-size: 20px;
  cursor: pointer;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.reset-btn:hover {
  background: rgba(255, 0, 0, 0.6);
  border-color: rgba(255, 255, 255, 0.6);
  transform: rotate(180deg);
}

.reset-btn:active {
  transform: rotate(180deg) scale(0.9);
}

/* Settings Button (Top Right) */
.settings-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: white;
  font-size: 20px;
  cursor: pointer;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.settings-btn:hover {
  background: rgba(102, 126, 234, 0.6);
  border-color: rgba(255, 255, 255, 0.6);
  transform: rotate(90deg);
}

.settings-btn:active {
  transform: rotate(90deg) scale(0.9);
}

/* Idle video - Desktop default */
#idleVideo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

#avatarCanvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
}

/* Mode / Fallback Banner */
.mode-banner {
  position: absolute;
  bottom: 80px;
  right: 12px;
  z-index: 100;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  text-align: right;
  pointer-events: none;
  opacity: 0.92;
  max-width: 70%;
  white-space: nowrap;
  animation: bannerFadeIn 0.3s ease;
}
.mode-banner.fallback {
  background: #ff9800;
  color: #fff;
}
.mode-banner.error {
  background: #f44336;
  color: #fff;
}
.mode-banner.active {
  background: rgba(76, 175, 80, 0.85);
  color: #fff;
}
@keyframes bannerFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 0.92;
    transform: translateY(0);
  }
}

/* Removed - now using .avatar-bottom-controls instead */

/* Controls Section */
.controls-section {
  flex: 0 0 auto;
  background: white;
  padding: 20px;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
  max-height: 50vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.control-group {
  margin-bottom: 16px;
  flex-shrink: 0;
}

.control-group:last-child {
  margin-bottom: 0;
}

#adminPanel {
  display: none;
  padding: 15px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}

/* Conversation control group should expand to fill space */
.control-group:has(#transcript) {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #667eea;
  text-transform: uppercase;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

/* Buttons */
.button-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 100px;
  justify-content: center;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(102, 126, 234, 0.3);
}

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

/* Talk Button - Two Line Text */
#talkBtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

#talkBtn .btn-text {
  font-size: 10px;
  line-height: 1.1;
  text-align: center;
}

#talkBtn .btn-icon {
  font-size: 16px;
}

/* Talk Button - Glow Green When Active */
#talkBtn.active {
  background: linear-gradient(135deg, #4caf50 0%, #2e7d32 100%);
  box-shadow:
    0 0 20px rgba(76, 175, 80, 0.6),
    0 0 40px rgba(76, 175, 80, 0.4);
  animation: talkGlow 2s ease-in-out infinite;
}

#talkBtn.active:hover {
  background: linear-gradient(135deg, #66bb6a 0%, #388e3c 100%);
  box-shadow:
    0 0 25px rgba(76, 175, 80, 0.8),
    0 0 50px rgba(76, 175, 80, 0.5);
}

@keyframes talkGlow {
  0%,
  100% {
    box-shadow:
      0 0 20px rgba(76, 175, 80, 0.6),
      0 0 40px rgba(76, 175, 80, 0.4);
  }
  50% {
    box-shadow:
      0 0 30px rgba(76, 175, 80, 0.8),
      0 0 60px rgba(76, 175, 80, 0.6);
  }
}

.btn-secondary {
  background: #f0f0f0;
  color: #333;
}

.btn-secondary:hover {
  background: #e0e0e0;
}

/* Stop Button - Darker Gradient */
#stopBtn {
  background: linear-gradient(135deg, #434343 0%, #000000 100%);
  color: white;
}

#stopBtn:hover:not(:disabled) {
  background: linear-gradient(135deg, #555555 0%, #1a1a1a 100%);
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
}

#stopBtn:active:not(:disabled) {
  transform: translateY(0);
}

/* Interrupt Button - Orange/Amber for "stop her" */
#interruptBtn {
  display: none; /* Hidden by default, shown when assistant is speaking */
  background: linear-gradient(135deg, #ff9800 0%, #e65100 100%);
  color: white;
}

#interruptBtn:hover {
  background: linear-gradient(135deg, #ffa726 0%, #ef6c00 100%);
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(255, 152, 0, 0.4);
}

#interruptBtn:active {
  transform: translateY(0);
}

#interruptBtn.visible {
  display: flex;
  animation: interruptPulse 1.5s ease-in-out infinite;
}

@keyframes interruptPulse {
  0%,
  100% {
    box-shadow: 0 0 8px rgba(255, 152, 0, 0.4);
  }
  50% {
    box-shadow:
      0 0 20px rgba(255, 152, 0, 0.8),
      0 0 40px rgba(255, 152, 0, 0.3);
  }
}

/* Admin Button - Darker Gradient */
#adminToggleBottom {
  background: linear-gradient(135deg, #2c3e50 0%, #1a252f 100%);
  color: white;
}

#adminToggleBottom:hover {
  background: linear-gradient(135deg, #34495e 0%, #2c3e50 100%);
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(44, 62, 80, 0.4);
}

#adminToggleBottom:active {
  transform: translateY(0);
}

/* Camera Toggle Button */
#cameraToggleBtn {
  background: linear-gradient(135deg, #555555 0%, #333333 100%);
  color: white;
}

#cameraToggleBtn:hover {
  background: linear-gradient(135deg, #666666 0%, #444444 100%);
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(85, 85, 85, 0.4);
}

#cameraToggleBtn:active {
  transform: translateY(0);
}

#cameraToggleBtn.active {
  background: linear-gradient(135deg, #f44336 0%, #c62828 100%);
  box-shadow:
    0 0 20px rgba(244, 67, 54, 0.6),
    0 0 40px rgba(244, 67, 54, 0.4);
  animation: cameraGlow 2s ease-in-out infinite;
}

#cameraToggleBtn.active:hover {
  background: linear-gradient(135deg, #e57373 0%, #d32f2f 100%);
  box-shadow:
    0 0 25px rgba(244, 67, 54, 0.8),
    0 0 50px rgba(244, 67, 54, 0.5);
}

@keyframes cameraGlow {
  0%,
  100% {
    box-shadow:
      0 0 20px rgba(244, 67, 54, 0.6),
      0 0 40px rgba(244, 67, 54, 0.4);
  }
  50% {
    box-shadow:
      0 0 30px rgba(244, 67, 54, 0.8),
      0 0 60px rgba(244, 67, 54, 0.6);
  }
}

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

.btn-icon {
  font-size: 16px;
}

/* Bottom Control Bar (Emotion Buttons + Talk/Stop Buttons) */
.avatar-bottom-controls {
  position: absolute;
  bottom: 15px;
  left: 15px;
  right: 15px;
  display: flex;
  gap: 10px;
  align-items: center;
  background: rgba(255, 255, 255, 0.95);
  padding: 10px;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

/* Emotion Buttons Container (2 rows × 8 buttons) */
.emotion-buttons-container {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  flex: 1;
}

.emotion-btn {
  padding: 4px 2px;
  border: 2px solid #e0e0e0;
  background: white;
  color: #333;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  cursor: default;
  transition: all 0.25s ease;
  white-space: nowrap;
  text-align: center;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

/* Blazing red highlight for detected emotion */
.emotion-btn.active {
  color: white;
  border-color: #ff1744;
  background: #ff1744;
  box-shadow:
    0 0 10px rgba(255, 23, 68, 0.7),
    0 0 20px rgba(255, 23, 68, 0.4);
  transform: scale(1.1);
  z-index: 1;
}

/* Glow pulse animation when emotion changes */
@keyframes emotionPulse {
  0% {
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(255, 23, 68, 0.7);
  }
  50% {
    transform: scale(1.2);
    box-shadow:
      0 0 18px rgba(255, 23, 68, 0.9),
      0 0 30px rgba(255, 23, 68, 0.5);
  }
  100% {
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(255, 23, 68, 0.7);
  }
}

.emotion-btn.pulse {
  animation: emotionPulse 0.5s ease-out;
}

/* Talk/Stop Buttons Container (Constant Size for Touch) */
.action-buttons-container {
  display: flex;
  gap: 8px;
}

.action-buttons-container .btn {
  min-width: 80px;
  min-height: 44px; /* Touch-friendly minimum size */
  padding: 10px 16px;
  font-size: 13px;
  white-space: nowrap;
}

/* Text Input */
#textInput {
  width: 100%;
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  transition: border-color 0.3s ease;
}

#textInput:focus {
  outline: none;
  border-color: #667eea;
}

/* Conversation Log */
.conversation-log {
  flex: 1;
  overflow-y: auto;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background-color: #f9f9f9;
  padding: 12px;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 0;
}

.conversation-message {
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  border-left: 4px solid transparent;
}

.conversation-message.system {
  background-color: #f0f0f0;
  border-left-color: #999;
  color: #666;
  font-style: italic;
}

.transcript-user,
.conversation-message.user {
  background: linear-gradient(135deg, rgba(19, 239, 147, 0.25), rgba(19, 239, 147, 0.15));
  border: 1px solid rgba(19, 239, 147, 0.3);
  border-left: 4px solid #13ef93;
  color: #1a1a1a;
}

.transcript-agent,
.conversation-message.agent {
  background: linear-gradient(135deg, rgba(240, 68, 56, 0.25), rgba(240, 68, 56, 0.15));
  border: 1px solid rgba(240, 68, 56, 0.3);
  border-left: 4px solid #f04438;
  color: #1a1a1a;
}

/* Legacy transcript styles (for backwards compatibility) */
.transcript {
  background: #f9f9f9;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  min-height: 40px;
  font-size: 13px;
  color: #666;
}

.transcript.has-content {
  background: #f0f2ff;
  border-color: #667eea;
  color: #333;
}

/* Status */
.status {
  padding: 10px;
  border-radius: 8px;
  font-size: 12px;
  text-align: center;
  min-height: 20px;
  display: none;
}

.status.show {
  display: block;
}

.status.info {
  background: #d1ecf1;
  color: #0c5460;
  border: 1px solid #bee5eb;
}

.status.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.status.success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

/* Responsive Design */
@media (min-width: 768px) {
  .portal-container {
    flex-direction: row;
  }

  .avatar-section {
    flex: 1;
    border-radius: 0;
  }

  .controls-section {
    flex: 0 0 400px;
    border-radius: 0;
    max-height: 100vh;
    border-left: 1px solid rgba(0, 0, 0, 0.1);
  }

  .emotion-btn {
    min-width: auto;
  }

  .button-group.action-buttons {
    flex-direction: column;
  }

  .btn {
    min-width: auto;
  }
}

@media (max-width: 768px) {
  /* MOBILE: Remove ALL gaps and padding for maximum screen usage */
  html,
  body {
    overflow: hidden; /* Prevent any scrolling */
  }

  .portal-container {
    gap: 0;
    height: 100vh; /* Full viewport height */
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
  }

  .controls-section {
    flex: 1; /* Take remaining space (bottom half) */
    padding: 16px;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* Allow scrolling if content is too long */
  }

  .btn {
    padding: 10px 12px;
    font-size: 13px;
    min-width: 80px;
  }

  .emotion-btn {
    padding: 5px 8px;
    font-size: 10px;
  }

  .avatar-bottom-controls {
    bottom: 0; /* Flush to bottom - no gap */
    left: 0;
    right: 0;
    padding: 4px; /* Reduced from 8px */
    gap: 4px; /* Reduced from 8px */
    border-radius: 0; /* No rounded corners on mobile */
    margin-top: 20px; /* Push buttons down 20px from avatar */
  }

  .action-buttons-container .btn {
    min-width: 70px;
    min-height: 36px; /* Reduced from 44px - thinner buttons */
    padding: 4px 8px; /* Reduced from 8px 12px */
    font-size: 12px;
  }

  .avatar-section {
    flex: 0 0 50vh; /* Take exactly top half of screen */
    max-height: 50vh;
    padding: 0; /* Remove all padding on mobile for maximum space */
    background: rgba(255, 255, 255, 0.05); /* Lighter background to blend better */
    align-items: center; /* Keep centered in the top half */
    justify-content: center;
  }

  /* Make video fit within top half and move up 50px */
  #idleVideo,
  #avatarCanvas {
    max-height: 50vh;
    width: auto;
    object-fit: contain;
    transform: translateY(-50px); /* Move just the avatar up 50px */
  }

  /* MOBILE: Hide emotion buttons, make 4 action buttons evenly spaced */
  .emotion-buttons-container {
    display: none; /* Hide emotion buttons on mobile */
  }

  .action-buttons-container {
    flex: 1; /* Take full width */
    justify-content: space-between; /* Evenly space the 4 buttons */
  }

  .action-buttons-container .btn {
    flex: 1; /* Each button takes equal space */
    min-width: 0; /* Allow buttons to shrink */
    max-width: none; /* Allow buttons to grow */
  }

  /* Make icons 100% bigger on mobile (double size) */
  .btn-icon {
    font-size: 36px !important; /* 100% bigger than 16px (16 + 16 + 4 more) */
  }

  #talkBtn .btn-icon {
    font-size: 36px !important; /* Override talk button icon too */
  }

  /* Hide button text on mobile - show only icons */
  .btn-text {
    display: none;
  }
}

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

.btn-recording {
  animation: spin 2s linear infinite;
}

/* Camera Preview */
.camera-preview {
  display: none;
  position: absolute;
  top: 20px;
  right: 20px;
  width: 150px;
  height: 150px;
  border: 2px solid #00ff00;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 4px 15px rgba(0, 255, 0, 0.3);
  z-index: 100;
}

.camera-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
}

.preview-label {
  position: absolute;
  top: 5px;
  left: 5px;
  background: rgba(0, 0, 0, 0.7);
  color: #00ff00;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: bold;
  pointer-events: none;
}

/* Status Indicator - Professional, subtle */
.status-indicator {
  position: fixed;
  top: 10px;
  right: 10px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #00ff00;
  box-shadow: 0 0 8px #00ff00;
  z-index: 1000;
}

/* Emotion Detection Panel */
.emotion-detection {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 12px;
  border: 1px solid #e0e0e0;
}

.emotion-bar {
  display: grid;
  grid-template-columns: 70px 1fr 50px;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
}

.emotion-bar:last-child {
  margin-bottom: 0;
}

.emotion-name {
  font-weight: 500;
  color: #333;
  text-align: right;
}

.emotion-bar-fill {
  height: 20px;
  background: #e0e0e0;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.emotion-bar-value {
  height: 100%;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  border-radius: 10px;
  transition: width 0.3s ease;
}

.emotion-score {
  font-weight: 600;
  color: #667eea;
  text-align: right;
  min-width: 40px;
}

#aiProvider {
  width: 100%;
  padding: 10px;
  border-radius: 4px;
  background: #2a2a2a;
  color: white;
  border: 2px solid #555;
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 10px;
}

#microphoneSelect {
  width: 100%;
  padding: 10px;
  border-radius: 4px;
  background: #2a2a2a;
  color: white;
  border: 2px solid #555;
  font-size: 14px;
  cursor: pointer;
}
.llm-model-select {
  width: 100%;
  padding: 10px;
  border-radius: 4px;
  background: #2a2a2a;
  color: white;
  border: 2px solid #555;
  font-size: 14px;
  cursor: pointer;
}
#ttsModel {
  width: 100%;
  padding: 10px;
  border-radius: 4px;
  background: #2a2a2a;
  color: white;
  border: 2px solid #555;
  font-size: 14px;
  cursor: pointer;
}

/* Admin Panel Form Groups */
.admin-form-group {
  margin-bottom: 15px;
}

.admin-label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
}

.info-subtext {
  font-size: 11px;
  color: #aaa;
  font-weight: normal;
}

/* Hume EVI Checkbox */
.checkbox-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  -webkit-user-select: none;
  -webkit-user-select: none;
  user-select: none;
}

.hume-checkbox {
  width: 20px;
  height: 20px;
  margin-right: 10px;
  cursor: pointer;
  accent-color: #9c27b0;
}

.checkbox-bold-text {
  font-weight: bold;
}

.checkbox-description {
  font-size: 12px;
  color: #aaa;
  margin-top: 5px;
  margin-left: 30px;
}

/* Settings Footer */
.settings-footer {
  text-align: center;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

#settingsStatus {
  font-size: 12px;
  color: #4caf50;
  margin-bottom: 8px;
  min-height: 18px;
}

#saveSettings {
  width: 100%;
  padding: 8px;
  background: #4caf50;
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
}

/* Info Panels (Button Guide & Emotion Mapping) */
.info-panel {
  margin-top: 20px;
  padding: 15px;
  border-radius: 8px;
}

.info-panel-guide {
  background: rgba(76, 175, 80, 0.1);
  border: 1px solid rgba(76, 175, 80, 0.3);
}

.info-panel-mapping {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.info-panel-header {
  margin: 0 0 10px 0;
}

.info-panel-guide .info-panel-header {
  font-size: 14px;
  color: #2e7d32;
}

.info-panel-mapping .info-panel-header {
  font-size: 13px;
  color: #aaa;
}

.info-panel-guide .info-panel-content {
  font-size: 12px;
  line-height: 1.8;
  color: #000000;
}

.info-panel-mapping .info-panel-content {
  font-size: 11px;
  line-height: 1.6;
  color: #999;
}

.info-item {
  margin-bottom: 8px;
}

/* Colored label text */
.text-green {
  color: #4caf50;
}
.text-red {
  color: #f44336;
}
.text-blue {
  color: #2196f3;
}
.text-orange {
  color: #ff9800;
}
.text-purple {
  color: #9c27b0;
}
.text-pink {
  color: #e91e63;
}
.text-cyan {
  color: #00bcd4;
}
.text-grey {
  color: #9e9e9e;
}

/* Hidden audio player */
#audioPlayer {
  display: none;
}
