:root {
  --primary: #6C3CE1;
  --primary-light: #8B5CF6;
  --primary-dark: #5521C6;
  --secondary: #F59E0B;
  --secondary-light: #FBBF24;
  --success: #10B981;
  --danger: #EF4444;
  --danger-light: #FCA5A5;
  --warning: #F59E0B;
  --dark: #1A1A2E;
  --dark-2: #16213E;
  --dark-3: #0F3460;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --white: #FFFFFF;
  --font-ar: 'Cairo', sans-serif;
  --font-fr: 'Inter', sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.12);
  --shadow-colored: 0 4px 20px rgba(108,60,225,0.25);
  --transition: all 0.3s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-ar);
  background: var(--gray-100);
  color: var(--gray-800);
  min-height: 100vh;
  overflow-x: hidden;
}

body[data-lang="fr"] { font-family: var(--font-fr); }

.rtl { direction: rtl; text-align: right; }
.ltr { direction: ltr; text-align: left; }

/* ========== NAVBAR ========== */
.navbar {
  background: var(--white);
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.nav-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--primary);
}

.brand-icon { font-size: 1.5rem; }

.nav-menu {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-link {
  text-decoration: none;
  color: var(--gray-600);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.9rem;
  transition: var(--transition);
}

.nav-link:hover { color: var(--primary); background: var(--gray-100); }

.nav-play-btn {
  background: var(--primary) !important;
  color: var(--white) !important;
  font-weight: 700;
}

.nav-play-btn:hover { background: var(--primary-dark) !important; }

.nav-admin { color: var(--warning); }

.nav-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-points {
  background: linear-gradient(135deg, var(--secondary), var(--secondary-light));
  color: var(--dark);
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 0.85rem;
}

.nav-lang {
  border: 1px solid var(--gray-300);
  border-radius: 20px;
  font-size: 0.8rem;
  padding: 4px 12px;
}

.nav-logout { color: var(--danger) !important; }

.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.nav-toggle span {
  width: 24px;
  height: 2.5px;
  background: var(--gray-700);
  border-radius: 2px;
  transition: var(--transition);
}

.btn-primary-sm {
  background: var(--primary) !important;
  color: var(--white) !important;
  border-radius: 20px;
}

/* ========== MAIN CONTENT ========== */
.main-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  min-height: calc(100vh - 64px - 120px);
}

/* ========== FOOTER ========== */
.site-footer {
  background: var(--gray-800, #1f2937);
  color: var(--gray-400, #9ca3af);
  padding: 1.5rem 1rem;
  text-align: center;
  margin-top: 2rem;
}
.footer-container {
  max-width: 1280px;
  margin: 0 auto;
}
.footer-links {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.footer-links a {
  color: var(--gray-400, #9ca3af);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.2s;
}
.footer-links a:hover {
  color: var(--purple, #8b5cf6);
}
.footer-copy {
  font-size: 0.8rem;
  opacity: 0.7;
}

/* ========== CARDS ========== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  transition: var(--transition);
}

.card:hover { box-shadow: var(--shadow-lg); }

.card-header {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--gray-100);
}

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: var(--white);
  box-shadow: var(--shadow-colored);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(108,60,225,0.35);
}

.btn-secondary {
  background: var(--gray-200);
  color: var(--gray-700);
}

.btn-secondary:hover { background: var(--gray-300); }

.btn-success {
  background: var(--success);
  color: var(--white);
}

.btn-danger {
  background: var(--danger);
  color: var(--white);
}

.btn-lg {
  padding: 16px 40px;
  font-size: 1.2rem;
  border-radius: var(--radius);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.85rem;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ========== FORMS ========== */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
  color: var(--gray-700);
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  transition: var(--transition);
  background: var(--white);
  color: var(--gray-800);
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108,60,225,0.1);
}

.form-input::placeholder { color: var(--gray-400); }

.form-select {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: var(--white);
  cursor: pointer;
  appearance: none;
  color: var(--gray-800);
}

.form-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

/* ========== STATS GRID ========== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }

.stat-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 0.85rem; color: var(--gray-500); margin-top: 0.25rem; }

.stat-card.gold { border-top: 3px solid var(--secondary); }
.stat-card.purple { border-top: 3px solid var(--primary); }
.stat-card.green { border-top: 3px solid var(--success); }
.stat-card.red { border-top: 3px solid var(--danger); }

/* ========== AUTH PAGES ========== */
.auth-container {
  max-width: 440px;
  margin: 2rem auto;
}

.auth-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 0.5rem;
  color: var(--dark);
}

.auth-subtitle {
  text-align: center;
  color: var(--gray-500);
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

.auth-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.9rem;
  color: var(--gray-500);
}

.auth-footer a { color: var(--primary); font-weight: 600; text-decoration: none; }

/* ========== LANDING PAGE ========== */
.hero {
  text-align: center;
  padding: 4rem 1rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--dark-3) 100%);
  border-radius: var(--radius-lg);
  color: var(--white);
  margin-bottom: 2rem;
}

.hero-title {
  font-size: 2.8rem;
  font-weight: 800;
  margin-bottom: 1rem;
  line-height: 1.2;
}

.hero-subtitle {
  font-size: 1.2rem;
  opacity: 0.9;
  margin-bottom: 2rem;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.hero-actions { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin: 2rem 0;
}

.feature-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.feature-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-lg); }

.feature-icon { font-size: 3rem; margin-bottom: 1rem; }
.feature-title { font-size: 1.2rem; font-weight: 700; margin-bottom: 0.5rem; color: var(--dark); }
.feature-desc { color: var(--gray-500); font-size: 0.95rem; line-height: 1.6; }

/* ========== GAME / ANSWER PAGE ========== */
.game-layout {
  display: flex;
  flex-direction: row;
  height: calc(100vh - 64px);
  height: calc(100dvh - 64px);
  max-width: 100%;
  padding: 0;
  overflow: hidden;
}

.game-center {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.video-section {
  flex-shrink: 0;
  background: #000;
  width: 100%;
  height: 55%;
}

.video-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
}

.video-wrapper iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.ad-banner-side {
  width: 160px;
  min-width: 160px;
  flex-shrink: 0;
  background: var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  overflow: hidden;
}

.ad-banner-side img { max-width: 100%; height: auto; }

.answer-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.3rem 0.75rem;
  overflow: hidden;
}

.question-display {
  text-align: center;
  padding: 0.25rem;
}

.question-meta {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.3rem;
  flex-wrap: wrap;
}

.question-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-type { background: var(--primary); color: var(--white); }
.badge-points { background: var(--secondary); color: var(--dark); }
.badge-timer { background: var(--danger); color: var(--white); font-variant-numeric: tabular-nums; }

.question-text {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 0.75rem;
  line-height: 1.4;
}

.question-image {
  max-width: 250px;
  max-height: 120px;
  margin: 0 auto 0.75rem;
  border-radius: var(--radius-sm);
}

.timer-bar-container {
  margin-bottom: 0.3rem;
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
  max-width: 500px;
  margin: 0 auto;
}

.option-btn {
  padding: 10px 6px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--white);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  transition: var(--transition);
  text-align: center;
  color: var(--gray-800);
}

.option-btn:hover { border-color: var(--primary); background: rgba(108,60,225,0.05); }
.option-btn.selected { border-color: var(--primary); background: rgba(108,60,225,0.1); color: var(--primary); }
.option-btn.correct { border-color: var(--success); background: rgba(16,185,129,0.1); color: var(--success); }
.option-btn.wrong { border-color: var(--danger); background: rgba(239,68,68,0.1); color: var(--danger); }
.option-btn:disabled { cursor: not-allowed; opacity: 0.7; }

.feedback-message {
  text-align: center;
  padding: 0.5rem;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 0.95rem;
  margin-top: 0.5rem;
  animation: slideUp 0.3s ease;
}

.feedback-correct { background: rgba(16,185,129,0.1); color: var(--success); border: 2px solid var(--success); }
.feedback-wrong { background: rgba(239,68,68,0.1); color: var(--danger); border: 2px solid var(--danger); }

.ad-banner-bottom {
  background: var(--gray-200);
  padding: 0.2rem;
  text-align: center;
  height: 50px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ad-banner-bottom img { max-height: 46px; }

/* Result phase */
.result-display {
  text-align: center;
  padding: 0.25rem;
}

.result-stats {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin: 0.4rem 0;
  flex-wrap: wrap;
}

.result-stat { text-align: center; }
.result-stat-value { font-size: 1.1rem; font-weight: 800; color: var(--primary); }
.result-stat-label { font-size: 0.75rem; color: var(--gray-500); }

.mini-leaderboard {
  max-width: 500px;
  margin: 0.25rem auto;
  max-height: 100px;
  overflow-y: auto;
}

.mini-leaderboard table {
  width: 100%;
  border-collapse: collapse;
}

.mini-leaderboard th {
  font-weight: 600;
  color: var(--gray-500);
  font-size: 0.8rem;
  padding: 8px;
  border-bottom: 2px solid var(--gray-200);
}

.mini-leaderboard td {
  padding: 8px;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--gray-100);
}

.mini-leaderboard tr:nth-child(1) td:first-child::before { content: '🥇 '; }
.mini-leaderboard tr:nth-child(2) td:first-child::before { content: '🥈 '; }
.mini-leaderboard tr:nth-child(3) td:first-child::before { content: '🥉 '; }

/* Timer bar */
.timer-bar-container {
  width: 100%;
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  margin: 1rem 0;
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--success), var(--warning), var(--danger));
  border-radius: 3px;
  transition: width 1s linear;
}

/* Waiting state */
.waiting-state {
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--gray-500);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.waiting-state .spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--gray-200);
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 1rem;
}

/* ========== DASHBOARD ========== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.dashboard-full { grid-column: 1 / -1; }

.start-btn-container { text-align: center; margin: 2rem 0; }

/* ========== STORE ========== */
.store-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.reward-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  transition: var(--transition);
}

.reward-card:hover { transform: translateY(-3px); }

.reward-logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
  margin-bottom: 1rem;
}

.reward-name { font-weight: 700; font-size: 1.1rem; margin-bottom: 0.5rem; }

.reward-price {
  font-size: 1.3rem;
  font-weight: 800;
  margin: 0.5rem 0;
}

.reward-price.affordable { color: var(--success); }
.reward-price.expensive { color: var(--danger); }

.code-reveal {
  background: var(--gray-100);
  border: 2px dashed var(--success);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-family: monospace;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 2px;
  margin: 1rem 0;
  word-break: break-all;
}

/* ========== LEADERBOARD PAGE ========== */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard-table th {
  background: var(--primary);
  color: var(--white);
  padding: 12px 16px;
  font-weight: 600;
}

.leaderboard-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gray-100);
}

.leaderboard-table tr:hover td { background: var(--gray-100); }

.rank-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
}

.rank-1 { background: #FFD700; color: #7C6200; }
.rank-2 { background: #C0C0C0; color: #555; }
.rank-3 { background: #CD7F32; color: #fff; }

/* ========== PROFILE SECTION ========== */
.profile-section { max-width: 500px; }

/* ========== TOAST / ALERTS ========== */
.toast-container {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  animation: slideDown 0.3s ease, fadeOut 0.3s ease 2.7s;
  pointer-events: auto;
  max-width: 400px;
  text-align: center;
}

.toast-success { background: var(--success); color: var(--white); }
.toast-error { background: var(--danger); color: var(--white); }
.toast-info { background: var(--primary); color: var(--white); }

/* ========== ONLINE INDICATOR ========== */
.online-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--gray-500);
}

.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}

/* ========== ANIMATIONS ========== */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeOut { to { opacity: 0; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ========== MODAL ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 1rem;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease;
}

.modal-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .nav-toggle { display: flex; }

  .nav-menu {
    display: none;
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--white);
    flex-direction: column;
    padding: 1rem;
    box-shadow: var(--shadow-lg);
    gap: 0.25rem;
  }

  .nav-menu.active { display: flex; }

  .nav-user {
    flex-direction: column;
    gap: 0.25rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--gray-200);
    margin-top: 0.5rem;
  }

  .hero-title { font-size: 1.8rem; }
  .hero { padding: 2.5rem 1rem; }

  .dashboard-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  .options-grid { grid-template-columns: 1fr 1fr; gap: 0.3rem; }

  .ad-banner-side { display: none; }

  .game-layout {
    flex-direction: column;
    height: calc(100vh - 64px);
    height: calc(100dvh - 64px);
    overflow: hidden;
  }

  .video-section { height: 45%; }

  .answer-main { padding: 0.3rem 0.5rem; }

  .ad-banner-bottom { height: 40px; min-height: 40px; }

  .question-display { padding: 0.15rem; }

  .option-btn { padding: 8px 4px; font-size: 0.85rem; }

  .question-text { font-size: 1.1rem; }

  .store-grid { grid-template-columns: 1fr; }

  .result-stats { gap: 1rem; }
}

@media (max-width: 1024px) {
  .ad-banner-side { width: 120px; min-width: 120px; }
  .video-section { height: 50%; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.4rem; }
  .hero-title { font-size: 1.5rem; }
  .hero-subtitle { font-size: 1rem; }
  .auth-card { padding: 1.5rem; }

  .video-section { height: 40%; }
  .ad-banner-bottom { height: 35px; min-height: 35px; }
  .option-btn { padding: 7px 4px; font-size: 0.8rem; }
  .options-grid { gap: 0.25rem; }
  .question-meta { gap: 0.4rem; margin-bottom: 0.2rem; }
  .question-badge { padding: 2px 8px; font-size: 0.7rem; }
  .feedback-message { padding: 0.25rem; font-size: 0.8rem; margin-top: 0.2rem; }
}

/* Short screens (landscape phones) */
@media (max-height: 600px) {
  .video-section { height: 40%; }
  .ad-banner-bottom { height: 30px; min-height: 30px; }
  .option-btn { padding: 5px 3px; font-size: 0.75rem; }
  .options-grid { gap: 0.2rem; }
}

@media (min-width: 1024px) {
  .video-section { height: 55%; }
}
