/* TombPlay Main Styles - Theme-Aware Colors */

:root {
  /* Theme Colors (set by theme system, with default purple values) */
  --primary-color: #a78bfa;
  --secondary-color: #8b5cf6;
  --accent-color: #c4b5fd;
  --glow-color: #a78bfa;

  /* Legacy purple variables - now derived from theme colors */
  --primary-purple: var(--secondary-color);
  --secondary-purple: var(--secondary-color);
  --dark-purple: var(--secondary-color);
  --light-purple: var(--primary-color);
  --purple-glow: color-mix(in srgb, var(--primary-color) 50%, transparent);

  /* Background Colors (overridden by themes) */
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #2a2a2a;
  --bg-card: var(--bg-secondary);
  --bg-card-hover: var(--bg-tertiary);
  --bg-elevated: var(--bg-tertiary);

  /* Text Colors (overridden by themes) */
  --text-color: #ffffff;
  --text-primary: var(--text-color);
  --text-secondary: #a0a0a0;
  --text-tertiary: #707070;

  /* Accent Colors */
  --accent-pink: #ec4899;
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-orange: #f59e0b;

  /* Gradients - derived from theme colors */
  --gradient-primary: linear-gradient(135deg, var(--secondary-color) 0%, var(--primary-color) 100%);
  --gradient-secondary: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Shadows */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.5);

  /* Discord Safe Area Insets - Prefer Discord vars, fallback to env for iOS */
  --sait: var(--discord-safe-area-inset-top, env(safe-area-inset-top, 0px));
  --saib: var(--discord-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --sail: var(--discord-safe-area-inset-left, env(safe-area-inset-left, 0px));
  --sair: var(--discord-safe-area-inset-right, env(safe-area-inset-right, 0px));
  --shadow-glow: 0 0 20px color-mix(in srgb, var(--glow-color, var(--primary-color)) 50%, transparent);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 300ms ease;
  --transition-slow: 500ms ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #000000; /* Solid black base for theme animations */
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  padding-left: var(--sail);
  padding-right: var(--sair);
  /* Remove top/bottom padding - let fixed elements handle safe areas */
  padding-top: 0;
  padding-bottom: 0;
  position: relative; /* Establish positioning context for animations */
}

/* Top Navigation Bar */
.top-nav {
  position: fixed;
  /* Position underneath Discord Activity bar */
  top: var(--sait);
  left: 0;
  right: 0;
  height: 50px;
  background: var(--bg-secondary);
  border-bottom: 1px solid rgba(139, 92, 246, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--spacing-md);
  z-index: 3000;
  box-shadow: var(--shadow-md);
}

.nav-left {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gradient-primary);
  padding: 2px;
  box-shadow: var(--shadow-glow);
}

.user-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-tertiary);
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.username {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-stats {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.user-level {
  display: flex;
  align-items: center;
  gap: 4px;
}

.level-badge {
  background: var(--gradient-primary);
  color: white;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.xp-bar {
  width: 60px;
  height: 3px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  background: var(--gradient-primary);
  border-radius: 2px;
  transition: width var(--transition-normal);
}

.nav-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.app-title {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 1.5px;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 20px var(--purple-glow);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.online-count {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-card);
  padding: 4px 8px;
  border-radius: var(--radius-md);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-green);
}

.online-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
  animation: pulse 2s ease-in-out infinite;
}

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

.notification-bell {
  position: relative;
  cursor: pointer;
  font-size: 18px;
  transition: transform var(--transition-fast);
}

.notification-bell:hover {
  transform: scale(1.1);
}

.notification-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: var(--accent-red);
  color: white;
  font-size: 8px;
  font-weight: 700;
  padding: 2px 4px;
  border-radius: 8px;
  min-width: 14px;
  text-align: center;
}

/* Main App Container */
.app-container {
  position: fixed;
  /* Account for Discord safe area + top nav height */
  top: calc(var(--sait) + 50px);
  left: 0;
  right: 0;
  /* Account for bottom tab bar + safe area */
  bottom: calc(50px + var(--saib));
  /* CRITICAL: Set explicit height for scrolling to work */
  height: calc(100vh - var(--sait) - var(--saib) - 100px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--spacing-md);
  background: var(--bg-primary);
  /* Enable smooth scrolling on iOS */
  -webkit-overflow-scrolling: touch;
  /* Ensure touch events work properly */
  touch-action: pan-y;
  /* Force GPU acceleration for smoother scrolling */
  will-change: scroll-position;
}

.app-container::-webkit-scrollbar {
  width: 6px;
}

.app-container::-webkit-scrollbar-track {
  background: transparent;
}

.app-container::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--secondary-color, #8b5cf6) 40%, transparent);
  border-radius: 3px;
}

.app-container::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--secondary-color, #8b5cf6) 65%, transparent);
}

/* Bottom Tab Bar */
.tab-bar {
  position: fixed;
  /* Position above safe area */
  bottom: var(--saib);
  left: 0;
  right: 0;
  height: 50px;
  background: var(--bg-secondary);
  border-top: 1px solid rgba(139, 92, 246, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 3000;
  box-shadow: 0 -4px 8px rgba(0, 0, 0, 0.4);
}

.tab-button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0 var(--spacing-xs) var(--spacing-xs);
  transition: all var(--transition-fast);
  position: relative;
}

.tab-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 3px;
  background: var(--gradient-primary);
  transition: width var(--transition-normal);
}

.tab-button.active::before {
  width: 60%;
}

.tab-button.active {
  color: var(--primary-purple);
}

.tab-button:hover {
  color: var(--light-purple);
  transform: translateY(-2px);
}

.tab-icon {
  font-size: 18px;
}

.tab-label {
  font-size: 11px;
  font-weight: 600;
}

/* Splash Screen */
.splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 1s ease-out;
  pointer-events: all;
}

.splash-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.splash-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #34353a;
  z-index: 1;
}

.splash-video {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: auto;
  height: auto;
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
  z-index: 2;
}

/* Loading State */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 18px;
  color: var(--text-secondary);
}

/* Modal */
.modal {
  position: fixed;
  /* Constrained within navigation boundaries */
  top: calc(var(--sait) + 50px);
  left: 0;
  right: 0;
  bottom: calc(var(--saib) + 50px);
  z-index: 5000; /* Above app content but constrained within nav bars */
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-lg);
}

.modal-overlay {
  position: fixed;
  /* Constrained within navigation boundaries */
  top: calc(var(--sait) + 50px);
  left: 0;
  right: 0;
  bottom: calc(var(--saib) + 50px);
  background: rgba(0, 0, 0, 0.8);
  /* NO blur - removed to prevent interaction issues */
  z-index: 5001;
  cursor: pointer;
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  max-width: 600px;
  width: 100%;
  /* Calculate max height accounting for navigation bars and padding */
  max-height: calc(100vh - var(--sait) - var(--saib) - 100px - (var(--spacing-lg) * 2));
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(139, 92, 246, 0.3);
  z-index: 5002;
  cursor: default;
  /* Enable smooth scrolling on iOS */
  -webkit-overflow-scrolling: touch;
  /* Ensure touch events work properly */
  touch-action: pan-y;
}

.modal-content::-webkit-scrollbar {
  width: 6px;
}

.modal-content::-webkit-scrollbar-track {
  background: transparent;
}

.modal-content::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--secondary-color, #8b5cf6) 40%, transparent);
  border-radius: 3px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--secondary-color, #8b5cf6) 65%, transparent);
}

/* Utility Classes */
.gradient-text {
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.glow {
  box-shadow: var(--shadow-glow);
}

.hidden {
  display: none !important;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
  /* Reduce top nav height on mobile */
  .top-nav {
    height: 56px;
    padding: 0 var(--spacing-md);
  }

  /* Adjust app container for mobile nav bars with safe areas */
  .app-container {
    top: calc(var(--sait) + 56px);
    bottom: calc(56px + var(--saib));
    padding: var(--spacing-md);
  }

  /* Adjust modal padding for mobile nav bars */
  .modal {
    top: calc(var(--sait) + 56px);
    bottom: calc(var(--saib) + 56px);
  }

  .modal-content {
    max-height: calc(100vh - var(--sait) - var(--saib) - 112px - (var(--spacing-lg) * 2));
  }

  /* Reduce bottom tab bar height on mobile */
  .tab-bar {
    height: 56px;
  }

  /* Smaller user avatar on mobile */
  .user-avatar {
    width: 40px;
    height: 40px;
  }

  /* Smaller username font */
  .username {
    font-size: 14px;
    max-width: 70px;
  }

  /* Smaller app title */
  .app-title {
    font-size: 20px;
  }

  /* Hide XP bar on very small screens */
  .xp-bar {
    width: 60px;
  }

  /* Smaller tab icons */
  .tab-icon {
    font-size: 18px;
  }

  .tab-label {
    font-size: 11px;
  }

  /* Adjust user level badge */
  .level-badge {
    font-size: 11px;
    padding: 2px 6px;
  }

  /* Smaller online count */
  .online-count {
    font-size: 12px;
    padding: 4px 8px;
  }

  /* Smaller notification bell */
  .notification-bell {
    font-size: 20px;
  }
}

/* Extra small mobile devices */
@media (max-width: 480px) {
  /* Further reduce heights on very small screens */
  .top-nav {
    height: 50px;
  }

  .app-container {
    top: calc(var(--sait) + 50px);
    bottom: calc(50px + var(--saib));
    padding: var(--spacing-sm);
  }

  .modal {
    top: calc(var(--sait) + 50px);
    bottom: calc(var(--saib) + 50px);
    padding: var(--spacing-md);
  }

  .modal-content {
    max-height: calc(100vh - var(--sait) - var(--saib) - 100px - (var(--spacing-md) * 2));
  }

  .tab-bar {
    height: 50px;
  }

  /* Hide XP bar on extra small screens */
  .xp-bar {
    display: none;
  }

  /* Smaller gaps */
  .nav-left {
    gap: var(--spacing-sm);
  }

  .nav-right {
    gap: var(--spacing-md);
  }

  /* Hide online count text on extra small screens */
  .online-count span:not(.online-dot) {
    display: none;
  }

  .online-count {
    padding: 6px;
  }
}

/* ============================================
   Toast Notifications
   ============================================ */

.toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-sm);
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  color: var(--text-primary);
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  max-width: 90vw;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  pointer-events: auto;
}

.toast-show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  background: linear-gradient(135deg, var(--accent-green), #059669);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.toast-error {
  background: linear-gradient(135deg, var(--accent-red), #dc2626);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.toast-info {
  background: linear-gradient(135deg, var(--primary-purple), var(--secondary-purple));
  border: 1px solid rgba(139, 92, 246, 0.3);
}
