:root {
  --bg-1: #f8fff9;
  --bg-2: #e8f8ec;
  --bg-3: #d6f2df;
  --card-bg: rgba(255, 255, 255, 0.92);
  --card-border: rgba(16, 185, 129, 0.2);
  --text-main: #0f172a;
  --text-muted: #64748b;
  --accent: #16a34a;
  --accent-dark: #15803d;
  --correct: #16a34a;
  --wrong: #dc2626;
  --ease-smooth: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out-soft: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --dur-screen: 0.5s;
  --dur-card: 0.55s;
  --dur-content: 0.48s;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Cairo", sans-serif;
  color: var(--text-main);
  background: linear-gradient(135deg, var(--bg-1), var(--bg-2), var(--bg-3));
  background-size: 180% 180%;
  animation: bgShift 12s ease infinite;
  overflow-x: hidden;
}

.animated-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 15% 20%, rgba(22, 163, 74, 0.14), transparent 28%),
    radial-gradient(circle at 85% 70%, rgba(16, 185, 129, 0.11), transparent 30%);
  z-index: 0;
}

.game-wrapper {
  position: relative;
  z-index: 1;
}

.screen {
  display: none;
  opacity: 0;
  transform: translateY(18px) scale(0.97);
  transition: opacity var(--dur-screen) var(--ease-out-soft),
    transform var(--dur-screen) var(--ease-smooth);
  will-change: opacity, transform;
}

.screen.active {
  display: block;
  opacity: 1;
  transform: translateY(0) scale(1);
}

.glass-card {
  max-width: 720px;
  padding: 1.25rem;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  border-radius: 1.25rem;
  box-shadow: 0 16px 38px rgba(2, 44, 34, 0.12);
}

.quiz-card {
  max-width: 980px;
  transform-origin: center top;
}

.quiz-card.quiz-card-enter {
  animation: quizCardEnter var(--dur-card) var(--ease-smooth) both;
}

@keyframes quizCardEnter {
  from {
    opacity: 0;
    transform: translateY(28px) scale(0.96);
    filter: blur(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

#quiz-main-panel.question-content-in .question-card {
  animation: quizContentUp var(--dur-content) var(--ease-smooth) both;
}

#quiz-main-panel.question-content-out .question-card,
#quiz-main-panel.question-content-out .answer-stagger-col,
#quiz-main-panel.question-content-out .quiz-actions,
#quiz-main-panel.question-content-out .feedback-message:not(:empty) {
  animation: quizContentOut 0.2s var(--ease-out-soft) both;
}

#quiz-main-panel.question-content-in .answer-stagger-col {
  animation: quizContentUp 0.42s var(--ease-smooth) both;
  animation-delay: calc(0.08s + var(--stagger, 0) * 0.07s);
}

#quiz-main-panel.question-content-in .quiz-actions {
  animation: quizContentUp 0.4s var(--ease-smooth) both;
  animation-delay: 0.28s;
}

#quiz-main-panel.question-content-in .feedback-message:not(:empty) {
  animation: quizFadeIn 0.35s var(--ease-smooth) both;
  animation-delay: 0.32s;
}

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

@keyframes quizFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes quizContentOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

#quiz-screen .top-bar .stat-pill {
  opacity: 0;
  transform: translateY(8px);
}

#quiz-screen.screen.active .top-bar .stat-pill {
  animation: quizPillIn 0.45s var(--ease-smooth) forwards;
}

#quiz-screen.screen.active .top-bar .stat-pill:nth-child(1) {
  animation-delay: 0.05s;
}
#quiz-screen.screen.active .top-bar .stat-pill:nth-child(2) {
  animation-delay: 0.12s;
}
#quiz-screen.screen.active .top-bar .stat-pill:nth-child(3) {
  animation-delay: 0.19s;
}

@keyframes quizPillIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#quiz-screen.screen.active .custom-progress {
  animation: quizProgressIn 0.55s var(--ease-smooth) both;
  animation-delay: 0.15s;
}

@keyframes quizProgressIn {
  from {
    opacity: 0;
    transform: scaleX(0.92);
  }
  to {
    opacity: 1;
    transform: scaleX(1);
  }
}

#quiz-screen.screen.active .question-palette-wrap {
  animation: quizSidebarIn 0.5s var(--ease-smooth) both;
  animation-delay: 0.12s;
}

@keyframes quizSidebarIn {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.game-badge {
  background: rgba(22, 163, 74, 0.1);
  color: var(--accent-dark);
  border: 1px solid rgba(22, 163, 74, 0.3);
}

.game-title {
  font-weight: 800;
  letter-spacing: 0.2px;
  margin-bottom: 0.5rem;
}

.game-subtitle {
  color: var(--text-muted);
}

.custom-select,
.custom-select:focus {
  border-radius: 0.75rem;
  background-color: #ffffff;
  border-color: #cbd5e1;
  color: #0f172a;
  box-shadow: none;
}

.custom-select option {
  color: #111827;
}

.start-btn {
  border: none;
  border-radius: 0.9rem;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  font-weight: 700;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 22px rgba(22, 163, 74, 0.28);
}

.leaderboard-box {
  border: 1px solid #d1fae5;
  border-radius: 1rem;
  padding: 0.85rem;
  background: #f8fff9;
}

.leaderboard-list .list-group-item {
  background: #ffffff;
  color: #0f172a;
  border-color: #dcfce7;
  border-radius: 0.7rem !important;
  margin-bottom: 0.45rem;
}

.top-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}

.stat-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.65rem 0.5rem;
  border-radius: 0.8rem;
  background: #ffffff;
  border: 1px solid #dcfce7;
  font-weight: 600;
  color: #14532d;
  box-shadow: 0 6px 14px rgba(22, 163, 74, 0.08);
}

.custom-progress {
  height: 0.8rem;
  border-radius: 999px;
  background-color: #dcfce7;
}

.custom-progress .progress-bar {
  border-radius: 999px;
  background: linear-gradient(90deg, #22c55e, #15803d);
  transition: width 0.35s ease;
}

.question-palette-wrap {
  border: 1px solid #dcfce7;
  background: #ffffff;
  border-radius: 1rem;
  padding: 0.85rem;
  height: fit-content;
}

.question-palette {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
}

.question-box {
  height: 2.2rem;
  border-radius: 0.7rem;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  font-weight: 700;
  transition: all 0.25s ease;
  cursor: pointer;
}

.question-box:hover:not(.active) {
  border-color: #86efac;
  background: #f0fdf4;
  transform: translateY(-1px);
}

.question-box:focus-visible {
  outline: 2px solid #22c55e;
  outline-offset: 2px;
}

.question-box.active {
  border-color: var(--accent);
  background: #dcfce7;
  color: #14532d;
  box-shadow: 0 6px 16px rgba(22, 163, 74, 0.22);
}

.question-box.done {
  border-color: #22c55e;
  background: #22c55e;
  color: #ffffff;
}

.quiz-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1rem;
  direction: ltr;
}

.quiz-layout > * {
  direction: rtl;
}

.quiz-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: space-between;
}

.quiz-actions .btn {
  border-radius: 0.8rem;
  min-width: 120px;
  font-weight: 700;
}

.question-card {
  border-radius: 1rem;
  padding: 1rem;
  background: #ffffff;
  border: 1px solid #dcfce7;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.05);
}

.question-text {
  font-size: clamp(1.05rem, 2.4vw, 1.45rem);
  text-align: center;
  font-weight: 700;
  line-height: 1.8;
}

.question-image-wrap {
  text-align: center;
}

.question-image-wrap img {
  max-height: min(42vh, 360px);
  width: auto;
  max-width: 100%;
  object-fit: contain;
}

.answer-btn {
  width: 100%;
  border: 0;
  border-radius: 0.9rem;
  padding: 0.95rem;
  color: #0f172a;
  font-weight: 600;
  background: #ffffff;
  border: 1px solid #bbf7d0;
  transition: transform 0.15s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.answer-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  background: #f0fdf4;
  box-shadow: 0 8px 16px rgba(22, 163, 74, 0.12);
}

.answer-btn:active:not(:disabled),
.answer-btn.clicked {
  transform: scale(0.98);
}

.answer-btn.picked {
  background: #ecfdf5;
  border-color: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.22);
  color: #0f172a;
}

.answer-btn.correct {
  background: #dcfce7;
  border-color: #22c55e;
  color: #14532d;
}

.answer-btn.wrong {
  background: #fee2e2;
  border-color: #ef4444;
  color: #7f1d1d;
}

.feedback-message {
  min-height: 1.6rem;
  font-weight: 700;
  text-align: center;
}

.feedback-message.ok {
  color: #15803d;
}

.feedback-message.bad {
  color: #b91c1c;
}

.final-score {
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 800;
  margin-bottom: 0.5rem;
}

.final-message {
  color: var(--text-muted);
  font-size: 1.05rem;
}

.btn-outline-light {
  --bs-btn-color: #166534;
  --bs-btn-border-color: #22c55e;
  --bs-btn-hover-bg: #22c55e;
  --bs-btn-hover-border-color: #22c55e;
  --bs-btn-hover-color: #ffffff;
}

.overlay-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.38);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.38s var(--ease-out-soft), visibility 0s linear 0.38s;
}

.overlay-backdrop.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.38s var(--ease-out-soft), visibility 0s linear 0s;
}

.overlay-card {
  width: min(420px, 95vw);
  background: #ffffff;
  border-radius: 1rem;
  padding: 1.25rem;
  border: 1px solid #dcfce7;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.2);
  transform: scale(0.94) translateY(10px);
  opacity: 0;
  transition: transform 0.38s var(--ease-smooth), opacity 0.38s var(--ease-smooth);
}

.overlay-backdrop.show .overlay-card {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.overlay-icon {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  margin: 0 auto 0.7rem;
  border-radius: 50%;
  color: #15803d;
  background: #dcfce7;
  font-size: 1.4rem;
}

.loading-card {
  width: min(380px, 94vw);
}

.loading-spinner {
  width: 52px;
  height: 52px;
  margin-inline: auto;
  border: 5px solid #dcfce7;
  border-top-color: #16a34a;
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

@keyframes bgShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

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

@media (max-width: 576px) {
  .glass-card {
    padding: 1rem;
    border-radius: 1rem;
  }

  .top-bar {
    grid-template-columns: 1fr;
  }

  .quiz-layout {
    grid-template-columns: 1fr;
  }

  .question-palette {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .quiz-actions .btn {
    flex: 1 1 100%;
  }
}

/* بطاقة معلومات الاختبار (exam.html) */
.exam-info-card {
  border: 1px solid rgba(22, 163, 74, 0.25);
  border-radius: 1rem;
  padding: 1.15rem 1.25rem;
  background: linear-gradient(180deg, #ffffff 0%, #f8fff9 100%);
  text-align: right;
}

.exam-info-title {
  color: #0f172a;
  font-weight: 800;
}

.exam-info-stat {
  padding: 0.65rem 0.75rem;
  border-radius: 0.75rem;
  background: #ffffff;
  border: 1px solid #dcfce7;
  height: 100%;
}

.exam-info-label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.exam-info-value {
  display: block;
  font-size: 1.1rem;
  color: #14532d;
}

.exam-chapters-list {
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid #e2e8f0;
}

.exam-chapters-list .list-group-item {
  background: #ffffff;
  border-color: #e2e8f0;
}

.exam-chapter-item {
  font-size: 0.95rem;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-screen: 0.01ms;
    --dur-card: 0.01ms;
    --dur-content: 0.01ms;
  }

  .screen,
  .overlay-backdrop,
  .overlay-card,
  .quiz-card.quiz-card-enter,
  #quiz-main-panel.question-content-in .question-card,
  #quiz-main-panel.question-content-in .answer-stagger-col,
  #quiz-main-panel.question-content-in .quiz-actions,
  #quiz-screen .top-bar .stat-pill,
  #quiz-screen.screen.active .custom-progress,
  #quiz-screen.screen.active .question-palette-wrap {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  #quiz-screen .top-bar .stat-pill {
    opacity: 1 !important;
    transform: none !important;
  }
}
