/* ====================================================
   CSS Custom Properties – design tokens
==================================================== */
:root {
  --bg: #0a0e1a;
  --surface: #111827;
  --surface2: #1c2537;
  --border: #2a3a55;
  --accent: #38bdf8;
  --accent2: #818cf8;
  --gold: #fbbf24;
  --danger: #f87171;
  --success: #34d399;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --radius: 16px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ====================================================
   Reset & Base
==================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  scroll-behavior: smooth;
}

body {
  font-family: "Cairo", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* Animated starfield background */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(
      2px 2px at 20% 30%,
      rgba(56, 189, 248, 0.4) 0%,
      transparent 100%
    ),
    radial-gradient(
      3px 3px at 80% 10%,
      rgba(129, 140, 248, 0.4) 0%,
      transparent 100%
    ),
    radial-gradient(
      4px 4px at 50% 70%,
      rgba(251, 191, 36, 0.3) 0%,
      transparent 100%
    ),
    radial-gradient(
      1px 1px at 10% 80%,
      rgba(56, 189, 248, 0.3) 0%,
      transparent 100%
    ),
    radial-gradient(
      1px 1px at 90% 60%,
      rgba(129, 140, 248, 0.3) 0%,
      transparent 100%
    );
  background-size:
    200px 200px,
    300px 300px,
    250px 250px,
    180px 180px,
    220px 220px;
  animation: stars 30s linear infinite;
  pointer-events: none;
  z-index: 0;
}
@keyframes stars {
  from {
    transform: translateY(0) translateX(0);
  }
  to {
    transform: translateY(150px) translateX(100px);
  }
}

/* Gradient orbs */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(
      ellipse 600px 400px at 10% 20%,
      rgba(56, 189, 248, 0.08) 0%,
      transparent 60%
    ),
    radial-gradient(
      ellipse 500px 500px at 90% 80%,
      rgba(129, 141, 248, 0.09) 0%,
      transparent 60%
    );
  pointer-events: none;
  z-index: 0;
}

/* ====================================================
   Layout
==================================================== */
#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 16px 24px;
}

.screen {
  display: none;
  width: 100%;
  max-width: 780px;
  animation: fadeUp 0.4s ease forwards;
}
.screen.active {
  display: block;
}

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

/* ====================================================
   Cards / Surfaces
==================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  backdrop-filter: blur(8px);
}

/* ====================================================
   Typography
==================================================== */
h1 {
  font-family: "Tajawal", sans-serif;
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: 900;
  line-height: 1.1;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
h2 {
  font-family: "Tajawal", sans-serif;
  font-size: clamp(1.2rem, 3vw, 1.8rem);
  font-weight: 800;
}
p {
  line-height: 1.8;
}

/* ====================================================
   Buttons
==================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border-radius: 12px;
  border: none;
  font-family: "Cairo", sans-serif;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}
.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.3);
}
.btn-primary:hover {
  box-shadow: 0 0 32px rgba(56, 189, 248, 0.5);
  transform: translateY(-2px);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--border);
}

.btn-gold {
  background: linear-gradient(135deg, var(--gold), #f59e0b);
  color: #1a1000;
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.3);
}
.btn-gold:hover {
  box-shadow: 0 0 28px rgba(251, 191, 36, 0.5);
  transform: translateY(-2px);
}

.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.3);
}
.btn-danger:hover {
  background: rgba(248, 113, 113, 0.25);
}

.btn-success {
  background: rgba(52, 211, 153, 0.15);
  color: var(--success);
  border: 1px solid rgba(52, 211, 153, 0.3);
}
.btn-success:hover {
  background: rgba(52, 211, 153, 0.25);
}

/* ====================================================
   Welcome Screen
==================================================== */
#welcome-screen {
  text-align: center;
}
.logo-area {
  margin-bottom: 32px;
}
.logo-icon {
  font-size: 72px;
  display: block;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-12px);
  }
}
.welcome-desc {
  color: var(--text-muted);
  font-size: 1.05rem;
  max-width: 520px;
  margin: 16px auto 36px;
}
.stats-bar {
  display: flex;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 36px;
}
.stat-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 10px 20px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.stat-chip span {
  color: var(--accent);
  font-weight: 700;
}

/* ====================================================
   Level Select Screen
==================================================== */
.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 16px;
  margin-top: 24px;
}
.level-card {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.level-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  opacity: 0;
  transition: var(--transition);
}
.level-card:hover::before {
  opacity: 0.1;
}
.level-card:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(56, 189, 248, 0.2);
}
.level-card.completed {
  border-color: var(--success);
}
.level-card.completed::before {
  background: linear-gradient(135deg, var(--success), #059669);
}
.level-emoji {
  font-size: 1rem;
  display: block;
  margin-bottom: 8px;
  position: relative;
}
.level-name {
  font-weight: 700;
  font-size: 0.95rem;
  position: relative;
}
.level-range {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
  position: relative;
}
.level-progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 12px;
  overflow: hidden;
  position: relative;
}
.level-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* ====================================================
   Quiz Screen
==================================================== */
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.quiz-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 6px 16px;
  font-size: 0.85rem;
  font-weight: 600;
}
.badge-accent {
  border-color: var(--accent);
  color: var(--accent);
}
.badge-gold {
  border-color: var(--gold);
  color: var(--gold);
}

.score-display {
  font-family: "Tajawal", sans-serif;
  font-size: 1.6rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--gold), #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Progress bar */
.progress-wrap {
  background: var(--surface2);
  border-radius: 99px;
  height: 8px;
  margin-bottom: 28px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 99px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}
.progress-fill::after {
  content: "";
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 8px;
  background: var(--accent2);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent2);
}

/* Question card */
.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 20px;
  position: relative;
}
.question-number {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.q-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent);
}
.question-text {
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  font-weight: 600;
  line-height: 1.9;
}

/* Answer area */
.answer-input {
  width: 100%;
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 14px 20px;
  color: var(--text);
  font-family: "Cairo", sans-serif;
  font-size: 1rem;
  outline: none;
  transition: var(--transition);
  resize: none;
}
.answer-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.actions .btn {
  flex: 1;
  min-width: 120px;
}

/* Feedback banner */
.feedback {
  border-radius: 12px;
  padding: 14px 20px;
  font-weight: 600;
  margin-top: 16px;
  display: none;
  animation: fadeUp 0.3s ease;
  font-size: 0.95rem;
}
.feedback.show {
  display: block;
}
.feedback.correct {
  background: rgba(52, 211, 153, 0.15);
  border: 1px solid rgba(52, 211, 153, 0.35);
  color: var(--success);
}
.feedback.wrong {
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: var(--danger);
}
.feedback.info {
  background: rgba(251, 191, 36, 0.12);
  border: 1px solid rgba(251, 191, 36, 0.3);
  color: var(--gold);
}

/* Nav between questions */
.nav-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.nav-row .btn {
  min-width: 110px;
}

/* ====================================================
   Celebration Overlay
==================================================== */
#celebration {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1000;
}
.celebration-msg {
  background: linear-gradient(
    135deg,
    rgba(52, 211, 153, 0.9),
    rgba(56, 189, 248, 0.9)
  );
  backdrop-filter: blur(12px);
  border-radius: 24px;
  padding: 32px 48px;
  text-align: center;
  font-family: "Tajawal", sans-serif;
  font-size: clamp(1.4rem, 5vw, 2.2rem);
  font-weight: 900;
  color: #fff;
  box-shadow: 0 0 60px rgba(52, 211, 153, 0.5);
  opacity: 0;
  transform: scale(0.6);
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.celebration-msg.show {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}
/* Confetti */
.confetti-wrap {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  0% {
    transform: translateY(-20px) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(110vh) rotate(720deg);
    opacity: 0;
  }
}

/* ====================================================
   Results Screen
==================================================== */
.result-hero {
  text-align: center;
  padding: 32px 0 24px;
}
.result-icon {
  font-size: 5rem;
  animation: float 2s ease-in-out infinite;
}
.result-score {
  font-family: "Tajawal", sans-serif;
  font-size: clamp(3rem, 10vw, 5rem);
  font-weight: 900;
  background: linear-gradient(135deg, var(--gold), #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.result-label {
  color: var(--text-muted);
  font-size: 1rem;
  margin-top: 4px;
}
.result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 28px;
}

/* ====================================================
   Misc
==================================================== */
.section-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Score flash animation */
@keyframes scoreFlash {
  0% {
    transform: scale(1);
  }
  30% {
    transform: scale(1.3);
  }
  100% {
    transform: scale(1);
  }
}
.score-flash {
  animation: scoreFlash 0.4s ease;
}

/* ====================================================
   Responsive
==================================================== */
@media (max-width: 480px) {
  .card {
    padding: 20px;
  }
  .quiz-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .actions {
    flex-direction: column;
  }
  .nav-row {
    flex-direction: column-reverse;
  }
  .nav-row .btn {
    width: 100%;
  }
}

/* ====================================================
   Language Switcher
==================================================== */
.lang-switcher {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
}

[dir="rtl"] .lang-switcher {
  right: auto;
  left: 16px;
}

.lang-switcher select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: "Cairo", sans-serif;
  font-size: 0.7rem;
  cursor: pointer;
  outline: none;
  transition: var(--transition);
}

.lang-switcher select:hover {
  border-color: var(--accent);
}

.lang-switcher select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

