:root {
  /* Colors */
  --bg-color: #0a0a1a;
  --bg-darker: #05050f;
  --surface-glass: rgba(255, 255, 255, 0.05);
  --surface-glass-heavy: rgba(255, 255, 255, 0.1);
  --primary: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.4);
  --secondary: #06b6d4;
  --accent: #f59e0b;
  --success: #10b981;
  --error: #ef4444;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  
  /* Gradints */
  --grad-primary: linear-gradient(135deg, #6366f1, #a855f7);
  --grad-secondary: linear-gradient(135deg, #06b6d4, #3b82f6);
  --grad-surface: linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.03));
  
  /* Spacing & Borders */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-xl: 32px;
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Splash Screen */
.splash {
  position: fixed;
  inset: 0;
  background: var(--bg-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease, visibility 0.5s;
}

.splash.hidden {
  opacity: 0;
  visibility: hidden;
}

.splash-logo {
  width: 80px;
  height: 80px;
  margin-bottom: 24px;
  animation: pulse 2s infinite ease-in-out;
}

.splash-title {
  font-size: 2.5rem;
  font-weight: 900;
  background: var(--grad-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

.splash-sub {
  color: var(--text-secondary);
  font-size: 1rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 32px;
}

.splash-loader {
  width: 120px;
  height: 4px;
  background: var(--surface-glass);
  border-radius: 2px;
  overflow: hidden;
}

.splash-bar {
  width: 40%;
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  animation: loading 1.5s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0px var(--primary-glow)); }
  50% { transform: scale(1.1); filter: drop-shadow(0 0 15px var(--primary-glow)); }
}

@keyframes loading {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

/* Typography */
h1, h2, h3, h4 {
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Glassmorphism Components */
.glass {
  background: var(--grad-surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.glass-card {
  padding: 24px;
  transition: transform 0.3s ease, border-color 0.3s ease;
}

.glass-card:hover {
  transform: translateY(-4px);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  font-family: inherit;
  font-size: 1rem;
  gap: 8px;
}

.btn-primary {
  background: var(--grad-primary);
  color: white;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: scale(1.02);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: var(--surface-glass-heavy);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Navigation */
.navbar {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 24px;
  right: 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 1000;
  padding: 0 16px;
}

.nav-item {
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 500;
  transition: color 0.3s ease;
  flex: 1;
}

.nav-item.active {
  color: var(--primary);
}

.nav-icon {
  font-size: 1.5rem;
  margin-bottom: 2px;
}

/* Container */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(110px + env(safe-area-inset-bottom));
}

/* Inputs */
.input-group {
  margin-bottom: 20px;
}

.input-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.input-field {
  width: 100%;
  background: var(--surface-glass);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 14px 16px;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  transition: all 0.3s ease;
}

.input-field:focus {
  outline: none;
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

/* Page Transitions */
.page {
  animation: fadeIn 0.4s ease-out;
}

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

/* Auth Styles */
.auth-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top right, rgba(99, 102, 241, 0.15), transparent),
              radial-gradient(circle at bottom left, rgba(6, 182, 212, 0.1), transparent);
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

/* Home Styles */
.welcome-header {
  margin-bottom: 32px;
}

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

.home-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px !important;
  min-height: 140px;
  text-decoration: none !important;
  color: inherit;
}

.home-card i {
  font-size: 2rem;
  margin-bottom: 8px;
}

.home-card h3 {
  font-size: 1rem;
  margin-bottom: 4px;
  color: #fff !important;
  text-decoration: none !important;
}

@media (max-width: 360px) {
  .home-grid {
    gap: 8px;
  }
  .home-card {
    padding: 12px !important;
    min-height: 120px;
  }
  .home-card i {
    font-size: 1.5rem;
  }
}

/* Quiz Styles */
.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.option-btn {
  width: 100%;
  text-align: left;
  padding: 16px 20px;
  margin-bottom: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  background: var(--surface-glass);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 1rem;
}

.option-btn:hover:not(:disabled) {
  background: var(--surface-glass-heavy);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.option-btn.selected {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}

.option-btn.correct {
  background: rgba(34, 197, 94, 0.2) !important;
  border-color: var(--success) !important;
  color: #fff !important;
}

.option-btn.wrong {
  background: rgba(239, 68, 68, 0.1);
}

/* Toast */
#toast-container {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 90%;
  max-width: 400px;
}

.toast {
  padding: 16px;
  border-radius: var(--radius-md);
  background: rgba(15, 15, 30, 0.9);
  backdrop-filter: blur(10px);
  color: white;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  border-left: 4px solid var(--primary);
  animation: slideInDown 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes slideInDown {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
/* Total Layout Reset - Flex-Box Fill Strategy */
.chat-page-container {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  background: var(--bg-main);
  z-index: 1000;
  padding-top: env(safe-area-inset-top, 0px); /* Respect mobile safe area */
}

@media (max-width: 768px) {
  .chat-page-container {
    padding-top: calc(15px + env(safe-area-inset-top)); /* Extra breathing room for mobile status bar */
  }
}

.chat-header {
  flex: 0 0 auto;
  padding: 8px 20px; /* Reduced by 50% as requested */
  background: var(--surface-glass-heavy);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-middle-section {
  flex: 1 1 auto;
  display: flex;
  overflow: hidden;
  position: relative;
}

.chat-sidebar {
  position: absolute;
  left: -280px;
  top: 0;
  bottom: 0;
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  z-index: 2000;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: #0f172a; /* Solid background */
  box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  opacity: 1 !important;
}

.chat-sidebar.open {
  left: 0;
}

.chat-messages-area {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  padding: 20px;
  gap: 16px;
  background: transparent;
}

.chat-input-container {
  flex: 0 0 auto;
  position: relative;
  bottom: 0;
  width: 100%;
  background: var(--surface-glass-heavy);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 12px 20px;
  z-index: 100;
  backdrop-filter: blur(20px);
  margin-bottom: 15px;
}

#chat-input {
  resize: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
  max-height: 120px;
  padding-top: 12px;
  padding-bottom: 12px;
  line-height: 1.5;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  width: 100%;
  font-size: 16px !important; /* Prevents auto-zoom on mobile iOS/Chrome */
  touch-action: manipulation;
}

#toggle-sidebar {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: white !important;
  padding: 8px !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

#toggle-sidebar svg {
  stroke: #ffffff !important;
  stroke-width: 3px !important;
}

.chat-bottom-nav {
  flex: 0 0 auto;
  height: 64px;
  background: var(--surface-glass-heavy);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-around;
  align-items: center;
  backdrop-filter: blur(20px);
}

/* UI Components */
.conv-item {
  padding: 12px;
  margin: 4px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
}

.conv-item.active {
  background: var(--grad-primary);
  color: white;
}

.conv-item:hover:not(.active) {
  background: rgba(255, 255, 255, 0.05);
}

/* Temporary toggle to hide original navbar on chat page only */
body:has(.chat-page-container) .navbar:not(.chat-bottom-nav) {
  display: none !important;
}

/* --- Onboarding Modal --- */
.onboarding-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.onboarding-overlay.active {
  opacity: 1;
  pointer-events: all;
}
.onboarding-modal {
  width: 90%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  position: relative;
  overflow: hidden;
  transform: translateY(20px) scale(0.95);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.onboarding-overlay.active .onboarding-modal {
  transform: translateY(0) scale(1);
}
.onboarding-slides {
  position: relative;
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 24px;
}
.onboarding-slide {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  opacity: 0;
  pointer-events: none;
  transition: all 0.4s ease;
  transform: translateX(20px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.onboarding-slide.active {
  opacity: 1;
  pointer-events: all;
  transform: translateX(0);
}
.onboarding-slide.prev {
  transform: translateX(-20px);
  opacity: 0;
}

@keyframes float {
  0% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
  100% { transform: translateY(0px); }
}
.onboarding-icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}
.onboarding-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-primary);
  direction: rtl;
}
.onboarding-text {
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
  direction: rtl;
}
.onboarding-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.onboarding-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 20px;
}
.onboarding-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  transition: background 0.3s ease, transform 0.3s ease;
}
.onboarding-dot.active {
  background: var(--primary);
  transform: scale(1.2);
}
