/* =============================================
   Quiz Page — AI-powered edition
   ============================================= */

.quiz-container {
  max-width: 720px;
  padding-top: 48px;
  padding-bottom: 80px;
}

.quiz-screen { width: 100%; }
.hidden { display: none !important; }

/* ── API KEY WARNING ── */
.api-warning {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: #fff7ed;
  border: 1.5px solid #fed7aa;
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 24px;
  font-size: 0.9rem;
  color: #9a3412;
  line-height: 1.6;
}

.api-warning-icon { font-size: 1.2rem; flex-shrink: 0; }
.api-warning a    { color: #c2410c; font-weight: 600; }
.api-warning code {
  background: #ffedd5;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.82rem;
}

/* ══════════════════════════════════════
   SETUP SCREEN
   ══════════════════════════════════════ */
.setup-card {
  background: var(--white);
  border: 1.5px solid var(--gray-100);
  border-radius: var(--radius-xl);
  padding: 40px;
}

.setup-card h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gray-900);
  margin-bottom: 6px;
  letter-spacing: -0.4px;
}

.setup-sub {
  font-size: 0.95rem;
  color: var(--gray-500);
  margin-bottom: 32px;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 28px;
}

.setup-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setup-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--gray-500);
}

.select-wrap {
  position: relative;
}

.select-wrap select {
  width: 100%;
  padding: 11px 38px 11px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--gray-800);
  background: white;
  appearance: none;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.select-wrap select:focus {
  outline: none;
  border-color: var(--green-400);
  box-shadow: 0 0 0 3px rgba(34,197,94,0.12);
}

.sel-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  pointer-events: none;
  font-size: 0.85rem;
}

/* Level pill toggle */
.pill-toggle {
  display: inline-flex;
  background: var(--gray-100);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
  width: 100%;
}

.pill-btn {
  flex: 1;
  padding: 9px 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--gray-500);
  background: transparent;
  transition: all var(--transition);
  white-space: nowrap;
}

.pill-btn.active {
  background: var(--green-600);
  color: white;
  box-shadow: var(--shadow-sm);
}

.generate-btn {
  width: 100%;
  font-size: 1rem;
  padding: 15px;
  gap: 8px;
}

.btn-icon { font-size: 1.1rem; }

/* ══════════════════════════════════════
   LOADING SCREEN
   ══════════════════════════════════════ */
.loading-card {
  text-align: center;
  padding: 80px 24px;
  background: var(--white);
  border: 1.5px solid var(--gray-100);
  border-radius: var(--radius-xl);
}

/* Spinner */
.spinner {
  width: 52px;
  height: 52px;
  border: 4px solid var(--green-100);
  border-top-color: var(--green-600);
  border-radius: 50%;
  margin: 0 auto 28px;
  animation: spin 0.8s linear infinite;
}

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

.loading-card h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 8px;
}

.loading-card p {
  font-size: 0.95rem;
  color: var(--gray-500);
}

.loading-sub {
  font-size: 0.82rem !important;
  margin-top: 6px;
  color: var(--gray-400) !important;
}

/* ══════════════════════════════════════
   QUESTION SCREEN
   ══════════════════════════════════════ */
.progress-wrap {
  margin-bottom: 24px;
}

.progress-bar {
  height: 6px;
  background: var(--gray-100);
  border-radius: 100px;
  overflow: hidden;
  margin-bottom: 10px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green-400), var(--green-600));
  border-radius: 100px;
  transition: width 0.5s ease;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--gray-500);
  font-weight: 500;
}

#liveScore { font-weight: 700; color: var(--green-700); }

.question-card {
  background: var(--white);
  border: 1.5px solid var(--gray-100);
  border-radius: var(--radius-xl);
  padding: 36px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.question-header {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.topic-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  background: var(--green-100);
  color: var(--green-800);
  padding: 4px 12px;
  border-radius: 100px;
}

.level-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  background: var(--gray-100);
  color: var(--gray-600);
  padding: 4px 12px;
  border-radius: 100px;
}

.question-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gray-900);
  line-height: 1.6;
  margin-bottom: 24px;
}

/* Options */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 18px;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-md);
  background: white;
  cursor: pointer;
  text-align: left;
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--gray-700);
  font-weight: 500;
  transition: all var(--transition);
  line-height: 1.45;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--green-400);
  background: var(--green-50);
  color: var(--green-800);
}

.option-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--gray-100);
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: all var(--transition);
}

.option-btn:hover:not(:disabled) .option-letter {
  background: var(--green-200);
  color: var(--green-800);
}

/* Answered states */
.option-btn.correct {
  border-color: var(--green-500);
  background: #f0fdf4;
  color: var(--green-800);
}

.option-btn.correct .option-letter {
  background: var(--green-500);
  color: white;
}

.option-btn.wrong {
  border-color: #ef4444;
  background: #fef2f2;
  color: #991b1b;
}

.option-btn.wrong .option-letter {
  background: #ef4444;
  color: white;
}

.option-btn.reveal {
  /* Correct answer revealed when user chose wrong */
  border-color: var(--green-300);
  background: #f0fdf4;
  color: var(--green-800);
  opacity: 0.75;
}

.option-btn.reveal .option-letter {
  background: var(--green-300);
  color: var(--green-900);
}

/* Explanation box */
.explanation-box {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-top: 20px;
  padding: 18px 20px;
  border-radius: var(--radius-md);
  animation: fadeUp 0.3s ease;
}

.explanation-box.is-correct {
  background: #f0fdf4;
  border: 1.5px solid var(--green-200);
}

.explanation-box.is-wrong {
  background: #fef2f2;
  border: 1.5px solid #fecaca;
}

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

.explanation-icon { font-size: 1.4rem; flex-shrink: 0; }

.explanation-body { font-size: 0.9rem; line-height: 1.6; }

.explanation-body strong {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.explanation-box.is-correct strong { color: var(--green-800); }
.explanation-box.is-wrong strong   { color: #991b1b; }
.explanation-box.is-correct p      { color: var(--green-700); }
.explanation-box.is-wrong p        { color: #b91c1c; }

/* Question navigation */
.question-nav {
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

/* ══════════════════════════════════════
   RESULTS SCREEN
   ══════════════════════════════════════ */
.results-card {
  background: var(--white);
  border: 1.5px solid var(--gray-100);
  border-radius: var(--radius-xl);
  padding: 44px 40px;
  text-align: center;
}

/* SVG score ring */
.score-ring {
  position: relative;
  width: 130px;
  height: 130px;
  margin: 0 auto 24px;
}

.score-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.score-track {
  fill: none;
  stroke: var(--gray-100);
  stroke-width: 8;
}

.score-arc {
  fill: none;
  stroke: var(--green-500);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 264; /* 2π × 42 */
  stroke-dashoffset: 264;
  transition: stroke-dashoffset 1s cubic-bezier(0.16, 1, 0.3, 1);
}

.score-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.score-num {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--green-700);
  line-height: 1;
}

.score-denom {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-400);
  margin-top: 10px;
}

.results-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--gray-900);
  margin-bottom: 6px;
  letter-spacing: -0.3px;
}

.results-sub {
  font-size: 0.95rem;
  color: var(--gray-500);
  margin-bottom: 32px;
}

/* Per-question review */
.review-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  margin-bottom: 32px;
}

.review-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--gray-100);
  background: var(--gray-50);
}

.review-item.review-correct { border-color: var(--green-200); background: #f0fdf4; }
.review-item.review-wrong   { border-color: #fecaca;          background: #fef2f2; }

.review-icon { font-size: 1rem; flex-shrink: 0; margin-top: 2px; }

.review-body { font-size: 0.85rem; line-height: 1.5; }

.review-body .review-q {
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 4px;
}

.review-body .review-ans {
  color: var(--gray-500);
}

.review-body .review-ans span { font-weight: 600; }
.review-correct .review-ans span { color: var(--green-700); }
.review-wrong   .review-ans span { color: #b91c1c; }

.results-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ══════════════════════════════════════
   ERROR SCREEN
   ══════════════════════════════════════ */
.error-card {
  text-align: center;
  padding: 64px 24px;
  background: var(--white);
  border: 1.5px solid #fecaca;
  border-radius: var(--radius-xl);
}

.error-icon { font-size: 2.5rem; margin-bottom: 16px; }

.error-card h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 8px;
}

.error-card p {
  font-size: 0.95rem;
  color: var(--gray-500);
  margin-bottom: 8px;
}

.error-detail {
  font-size: 0.82rem;
  color: #b91c1c;
  background: #fef2f2;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 16px auto 24px;
  max-width: 480px;
  text-align: left;
  font-family: monospace;
  word-break: break-word;
}

/* ══════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════ */
@media (max-width: 600px) {
  .setup-grid    { grid-template-columns: 1fr; }
  .setup-card    { padding: 24px 20px; }
  .question-card { padding: 24px 18px; }
  .results-card  { padding: 32px 20px; }
  .question-nav  { flex-direction: column-reverse; }
  .question-nav .btn { width: 100%; }
  .results-actions   { flex-direction: column; }
  .results-actions .btn { width: 100%; }
}
