/* ============================================
   ORBIT INTERACTION SYSTEM
   Beautiful game-like mini-interactions UI
   ============================================ */

/* ============================================
   ORBIT SYSTEM CONTAINER
   ============================================ */

.orbit-system {
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 1000;
  width: 100vw;
  height: 100vh;
  pointer-events: none; /* Allow clicks through, except on children */
}

.orbit-system.hidden {
  display: none;
}

/* Bubbles should allow pointer events */
.orbit-system .orbit-bubble {
  pointer-events: auto;
}

/* ============================================
   AVATAR GLOW (for existing tutor avatar)
   ============================================ */

.tutor-avatar.has-orbit-available {
  animation: orbit-avatar-glow 2s ease-in-out infinite !important;
}

@keyframes orbit-avatar-glow {
  0%, 100% {
    filter: drop-shadow(0 0 10px rgba(102, 126, 234, 0.3));
  }
  50% {
    filter: drop-shadow(0 0 20px rgba(102, 126, 234, 0.8));
  }
}

/* ============================================
   BUBBLES CONTAINER & INDIVIDUAL BUBBLES
   ============================================ */

.orbit-bubbles-container {
  position: relative;
  width: 100%;
  height: 100%;
}

.orbit-bubble {
  position: absolute;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  pointer-events: auto;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 12px;
  font-weight: 600;
  /* Position will be set by JavaScript */
}

/* ============================================
   BUBBLE STATE: PLANNED
   ============================================ */

.orbit-bubble.state-planned {
  background: transparent;
  border: 2px dotted #9CA3AF;
  color: #9CA3AF;
  opacity: 0.5;
  animation: planned-pulse 2s ease-in-out infinite;
  cursor: default;
}

@keyframes planned-pulse {
  0%, 100% {
    opacity: 0.3;
    transform: scale(1);
  }
  50% {
    opacity: 0.6;
    transform: scale(1.05);
  }
}

/* ============================================
   BUBBLE STATE: LOCKED
   ============================================ */

.orbit-bubble.state-locked {
  background: linear-gradient(135deg, #E5E7EB 0%, #D1D5DB 100%);
  border: 2px solid #9CA3AF;
  color: #6B7280;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  cursor: not-allowed;
  filter: grayscale(0.8);
}

.orbit-bubble.state-locked::before {
  content: '🔒';
  font-size: 16px;
}

.orbit-bubble.state-locked:hover {
  transform: translateX(2px);
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* ============================================
   BUBBLE STATE: AVAILABLE
   ============================================ */

.orbit-bubble.state-available {
  background: linear-gradient(135deg, #667EEA 0%, #48BB78 100%);
  border: 2px solid #667EEA;
  color: white;
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
  cursor: pointer;
  /* No default animation - will be added temporarily on unlock */
}

/* Pulsing animation - applied for 10 seconds after unlock */
.orbit-bubble.state-available.pulsing {
  animation: available-pulse 2s ease-in-out infinite;
}

/* NEW badge for most recently unlocked bubble */
.orbit-bubble.recent::after {
  content: 'NEW';
  position: absolute;
  top: -8px;
  right: -8px;
  background: linear-gradient(135deg, #FF6B6B 0%, #EE5A6F 100%);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(255, 107, 107, 0.4);
  z-index: 10;
  animation: badge-pop 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  letter-spacing: 0.5px;
}

@keyframes badge-pop {
  0% {
    transform: scale(0) rotate(-12deg);
    opacity: 0;
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

/* Play icon for available bubbles */
.orbit-bubble.state-available::before {
  content: '';
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 8px 0 8px 14px;
  border-color: transparent transparent transparent white;
  /* Center the triangle */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-40%, -50%); /* Slight offset left for visual centering */
}

@keyframes available-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(102, 126, 234, 0.6);
  }
}

.orbit-bubble.state-available:hover {
  transform: scale(1.15) !important;
  box-shadow: 0 8px 28px rgba(102, 126, 234, 0.7) !important;
}

.orbit-bubble.state-available:active {
  transform: scale(1.05) !important;
}

/* ============================================
   BUBBLE STATE: COMPLETED
   ============================================ */

.orbit-bubble.state-completed {
  background: linear-gradient(135deg, #48BB78 0%, #38A169 100%);
  border: 2px solid #38A169;
  color: white;
  box-shadow: 0 2px 12px rgba(72, 187, 120, 0.3);
  cursor: pointer;
  transform: scale(0.9);
}

.orbit-bubble.state-completed::before {
  content: '✓';
  font-size: 20px;
}

.orbit-bubble.state-completed:hover {
  transform: scale(1) !important;
  box-shadow: 0 4px 16px rgba(72, 187, 120, 0.5);
}

/* ============================================
   UNLOCK ANIMATION
   ============================================ */

@keyframes unlock-sequence {
  0% {
    transform: scale(1);
    filter: grayscale(0.8);
  }
  30% {
    transform: scale(1.2);
  }
  50% {
    transform: scale(1.15);
    filter: grayscale(0);
  }
  70% {
    transform: scale(1.25);
  }
  100% {
    transform: scale(1);
    filter: grayscale(0);
  }
}

.orbit-bubble.unlocking {
  animation: unlock-sequence 1.2s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* ============================================
   SPARKLE PARTICLES (ON UNLOCK)
   ============================================ */

.sparkle-particle {
  position: absolute;
  width: 6px;
  height: 6px;
  background: radial-gradient(circle, #FFF9C4 0%, #FFD700 100%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 1001;
  animation: sparkle-burst 0.6s ease-out forwards;
}

@keyframes sparkle-burst {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) scale(0);
    opacity: 0;
  }
}

/* ============================================
   TOAST NOTIFICATION
   ============================================ */

.orbit-toast {
  position: fixed;
  /* Position set dynamically by JavaScript */
  z-index: 1002;
  background: white;
  padding: 8px 12px; /* Reduced from 12px 16px */
  border-radius: 10px; /* Slightly smaller */
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 8px; /* Reduced from 12px */
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap; /* Prevent text wrapping */
  font-size: 0.875rem; /* 14px - smaller font */
}

.orbit-toast.hidden {
  opacity: 0;
  transform: translateY(-50%) translateX(-20px);
}

.orbit-toast.visible {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
  animation: toast-bounce 0.5s ease-out;
}

@keyframes toast-bounce {
  0% {
    transform: translateY(-50%) translateX(-20px);
  }
  60% {
    transform: translateY(-50%) translateX(5px);
  }
  100% {
    transform: translateY(-50%) translateX(0);
  }
}

.toast-icon {
  font-size: 20px; /* Reduced from 24px */
  animation: toast-icon-spin 0.6s ease-out;
}

@keyframes toast-icon-spin {
  0% {
    transform: rotate(0deg) scale(0);
  }
  50% {
    transform: rotate(180deg) scale(1.2);
  }
  100% {
    transform: rotate(360deg) scale(1);
  }
}

.toast-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toast-title {
  font-weight: 600;
  font-size: 14px;
  color: #1F2937;
}

.toast-message {
  font-size: 12px;
  color: #6B7280;
}

/* ============================================
   WIDGET POPOVER
   ============================================ */

.orbit-widget {
  position: fixed;
  z-index: 99999; /* Very high - above all canvas, graph, and UI elements */
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  width: 500px;
  height: 600px;
  overflow: hidden;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  /* Position will be set by JavaScript */
}

.orbit-widget.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9);
}

.orbit-widget.visible {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

/* Dragging state */
.orbit-widget.dragging {
  cursor: grabbing;
  transition: none;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
}

/* Maximized state - nearly full screen with margins */
.orbit-widget.maximized {
  top: 20px !important;
  left: 20px !important;
  right: 20px !important;
  bottom: 20px !important;
  width: calc(100vw - 40px) !important;
  height: calc(100vh - 40px) !important;
  border-radius: 16px;
  z-index: 100000 !important; /* Even higher when maximized */
}

.orbit-widget.maximized .widget-header {
  cursor: default; /* Can't drag when maximized */
}

/* Widget Header (drag handle) */
.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 16px 16px 0 0;
  cursor: move; /* Indicate draggable */
  user-select: none; /* Prevent text selection while dragging */
}

.widget-header:hover {
  background: linear-gradient(135deg, #5a6fd0 0%, #6a418c 100%);
}

.widget-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.widget-actions {
  display: flex;
  gap: 8px;
}

.widget-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  color: white;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

.widget-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

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

.widget-btn.hidden {
  display: none;
}

.widget-retry-btn {
  background: rgba(248, 113, 113, 0.3);
  border-color: rgba(248, 113, 113, 0.5);
}

.widget-retry-btn:hover {
  background: rgba(248, 113, 113, 0.4);
}

/* Widget Content */
.widget-content {
  flex: 1;
  overflow: auto;
  background: #F9FAFB;
}

/* Widget Footer */
.widget-footer {
  padding: 16px 20px;
  background: white;
  border-top: 1px solid #E5E7EB;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.widget-action-btn {
  padding: 10px 20px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.widget-action-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

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

/* ============================================
   BACKDROP (when widget is open)
   ============================================ */

.orbit-widget-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(2px);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.orbit-widget-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
  .orbit-system {
    top: 10px;
    left: 10px;
  }
  
  .orbit-avatar {
    width: 40px;
    height: 40px;
  }
  
  .orbit-avatar-emoji {
    font-size: 22px;
  }
  
  .orbit-bubble {
    width: 32px;
    height: 32px;
    font-size: 10px;
  }
  
  .orbit-widget {
    width: 90vw;
    max-width: 350px;
    max-height: 70vh;
  }
  
  .orbit-toast {
    left: 70px;
    font-size: 12px;
  }
}

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

.orbit-bubble:focus {
  outline: 3px solid #667EEA;
  outline-offset: 2px;
}

.widget-btn:focus {
  outline: 2px solid white;
  outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .orbit-avatar-emoji,
  .orbit-bubble,
  .orbit-toast,
  .orbit-widget {
    animation: none !important;
    transition: none !important;
  }
}

/* ============================================
   LOADING STATES
   ============================================ */

.widget-content.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.widget-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #E5E7EB;
  border-top-color: #667EEA;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ============================================
   VALIDATION ERROR UI
   ============================================ */

.validation-error-container,
.generic-error-container {
  padding: 40px 20px;
  text-align: center;
  max-width: 500px;
  margin: 0 auto;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.error-icon {
  font-size: 64px;
  margin-bottom: 20px;
  animation: error-shake 0.5s ease-in-out;
}

@keyframes error-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  50% { transform: translateX(10px); }
  75% { transform: translateX(-5px); }
}

.error-title {
  color: #dc2626;
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 16px;
  line-height: 1.4;
}

.error-details {
  background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
  border: 1px solid #fecaca;
  border-radius: 12px;
  padding: 20px;
  margin: 20px 0;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.1);
}

.error-message {
  color: #991b1b;
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 12px;
  font-family: 'Monaco', 'Courier New', 'Consolas', monospace;
  word-break: break-word;
  background: rgba(255, 255, 255, 0.5);
  padding: 12px;
  border-radius: 6px;
}

.error-location {
  color: #6b7280;
  font-size: 12px;
  margin-top: 8px;
  font-weight: 500;
}

.error-help {
  color: #6b7280;
  font-size: 14px;
  margin: 20px 0;
  line-height: 1.6;
}

.error-actions {
  margin-top: 24px;
}

.retry-button {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
  border: none;
  padding: 12px 32px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: 16px;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.retry-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.retry-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

/* Dark mode support for error UI */
@media (prefers-color-scheme: dark) {
  .error-details {
    background: linear-gradient(135deg, #3f1f1f 0%, #4f2626 100%);
    border-color: #7f1d1d;
  }
  
  .error-message {
    color: #fca5a5;
    background: rgba(0, 0, 0, 0.3);
  }
  
  .error-help {
    color: #9ca3af;
  }
}

