/* ============================================================
   qna-v2.css  —  Shared styles for Smart Practice & Past Paper
   ============================================================ */

/* Kill padding-top on quiz-page layouts — they manage their own viewport via 100dvh flex.
   Scoped to .quiz-page so quiz.html (setup page, same stylesheet) keeps its normal padding. */
body.quiz-page { padding: 0 !important; margin: 0; }

/* Guarantee [hidden] works even when a class sets display: flex/block */
[hidden] { display: none !important; }

/* --- Page layout ----------------------------------------- */

.quiz-page {
  background: #F5F7FA;
  height: 100dvh;
  overflow: hidden;          /* only .quiz-main scrolls; header stays fixed */
  display: flex;
  flex-direction: column;
  font-family: var(--font-main, 'Lexend', sans-serif);
}

/* --- Quiz header ----------------------------------------- */

.quiz-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--border, #E2E8F0);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 0 16px;
  height: 56px;
  flex-shrink: 0;
}

/* Always push the right-side element (timer badge / end btn) to the right edge */
.quiz-header > :last-child { justify-self: end; }
.quiz-header > :first-child { justify-self: start; }

.quiz-back-btn,
.quiz-end-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  color: var(--muted, #64748B);
  font-family: var(--font-main, 'Lexend', sans-serif);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s;
}

.quiz-back-btn:hover,
.quiz-end-btn:hover {
  background: var(--border, #E2E8F0);
}

.quiz-back-btn svg,
.quiz-end-btn svg {
  width: 20px;
  height: 20px;
}

.quiz-subject-label {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
  text-align: center;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Mastery strip (Smart Practice only) ----------------- */

.mastery-strip {
  background: #fff;
  border-bottom: 1px solid var(--border, #E2E8F0);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.mastery-topic {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted, #64748B);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 38%;
}

.mastery-bar-track {
  flex: 1;
  height: 8px;
  background: var(--border, #E2E8F0);
  border-radius: 4px;
  overflow: hidden;
}

.mastery-bar-fill {
  height: 100%;
  background: #004643;
  border-radius: 4px;
  transition: width 0.7s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 2px;
}

.mastery-pct {
  font-size: 12px;
  font-weight: 700;
  color: #004643;
  min-width: 34px;
  text-align: right;
}

/* --- Main content area ----------------------------------- */

.quiz-main {
  flex: 1;
  padding: 20px 16px 180px;
  overflow-y: auto;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

/* --- Loading state --------------------------------------- */

.quiz-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  gap: 16px;
  color: var(--muted, #64748B);
  font-size: 15px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border, #E2E8F0);
  border-top-color: #004643;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Question card --------------------------------------- */

.question-meta {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted, #64748B);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 14px;
}

.question-text {
  font-size: 18px;
  line-height: 1.55;
  color: #111827;
  font-weight: 500;
  margin-bottom: 28px;
}

/* --- Options grid ---------------------------------------- */

.options-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  background: #fff;
  border: 1.5px solid var(--border, #E2E8F0);
  border-radius: 12px;
  font-size: 15px;
  font-family: var(--font-main, 'Lexend', sans-serif);
  color: #111827;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.08s;
  min-height: 56px;
  line-height: 1.4;
}

.option-btn:active:not(:disabled) {
  transform: scale(0.985);
}

.option-btn:hover:not(:disabled):not(.correct):not(.wrong):not(.selected) {
  border-color: #004643;
  background: rgba(0, 70, 67, 0.04);
}

.option-letter {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  background: #F1F5F9;
  color: var(--muted, #64748B);
  font-size: 12px;
  font-weight: 700;
  transition: background 0.15s, color 0.15s;
}

.option-text {
  flex: 1;
}

/* Selected (Past Paper pre-submit) */
.option-btn.selected {
  border-color: #004643;
  background: rgba(0, 70, 67, 0.06);
}

.option-btn.selected .option-letter {
  background: #004643;
  color: #fff;
}

/* Correct answer revealed */
.option-btn.correct {
  background: rgba(16, 185, 129, 0.1);
  border-color: #10B981;
  color: #065F46;
}

.option-btn.correct .option-letter {
  background: #10B981;
  color: #fff;
}

/* Wrong choice revealed */
.option-btn.wrong {
  background: rgba(239, 68, 68, 0.08);
  border-color: #EF4444;
  color: #991B1B;
}

.option-btn.wrong .option-letter {
  background: #EF4444;
  color: #fff;
}

.option-btn:disabled {
  cursor: default;
}

/* --- Feedback bar (Smart Practice) ----------------------- */

.feedback-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 2px solid var(--border, #E2E8F0);
  padding: 16px 20px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 200;
  max-width: 640px;
  margin: 0 auto;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.08);
}

.feedback-bar.visible {
  transform: translateY(0);
}

.feedback-bar.correct-feedback {
  border-top-color: #10B981;
}

.feedback-bar.wrong-feedback {
  border-top-color: #EF4444;
}

.feedback-result {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.feedback-icon {
  font-size: 22px;
  line-height: 1;
}

.feedback-title {
  font-size: 19px;
  font-weight: 700;
}

.correct-feedback .feedback-title { color: #065F46; }
.wrong-feedback .feedback-title   { color: #991B1B; }

.feedback-delta {
  font-size: 13px;
  color: var(--muted, #64748B);
  margin-bottom: 12px;
  padding-left: 30px;
}

.feedback-explanation {
  font-size: 14px;
  color: #374151;
  line-height: 1.55;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: #F8FAFC;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 8px;
}

.feedback-continue {
  width: 100%;
  padding: 15px;
  background: #004643;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-main, 'Lexend', sans-serif);
  cursor: pointer;
  transition: opacity 0.15s;
}

.feedback-continue:active { opacity: 0.85; }

.correct-feedback .feedback-continue { background: #059669; }
.wrong-feedback .feedback-continue   { background: #DC2626; }

/* --- Session summary (Smart Practice) ------------------- */

.session-summary {
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 0 40px;
}

.summary-header {
  text-align: center;
  padding: 28px 0 24px;
}

.summary-score {
  font-size: 64px;
  font-weight: 800;
  color: #004643;
  line-height: 1;
}

.summary-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted, #64748B);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

.summary-message {
  font-size: 16px;
  color: #374151;
  margin-top: 8px;
  line-height: 1.4;
}

.summary-topics {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.topic-row {
  background: #fff;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 12px;
  padding: 14px 16px;
}

.topic-row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.topic-name {
  font-size: 14px;
  font-weight: 600;
  color: #111827;
}

.topic-delta {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
}

.topic-delta.positive {
  color: #065F46;
  background: rgba(16, 185, 129, 0.12);
}

.topic-delta.zero {
  color: var(--muted, #64748B);
  background: #F1F5F9;
}

.topic-delta.negative {
  color: #991B1B;
  background: rgba(239, 68, 68, 0.1);
}

.topic-bar-track {
  height: 8px;
  background: var(--border, #E2E8F0);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.topic-bar-before {
  position: absolute;
  inset: 0;
  width: 0;
  background: rgba(0, 70, 67, 0.25);
  border-radius: 4px;
}

.topic-bar-fill {
  position: absolute;
  inset: 0;
  width: 0;
  background: #004643;
  border-radius: 4px;
  transition: width 1s ease 0.4s;
}

.topic-accuracy {
  font-size: 12px;
  color: var(--muted, #64748B);
  margin-top: 6px;
}

/* --- Summary actions ------------------------------------- */

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

.btn-primary {
  width: 100%;
  padding: 15px;
  background: #004643;
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-main, 'Lexend', sans-serif);
  cursor: pointer;
  transition: opacity 0.15s;
  text-align: center;
}

.btn-primary:active { opacity: 0.85; }

.btn-ghost-link {
  display: block;
  width: 100%;
  padding: 15px;
  background: transparent;
  color: #004643;
  border: 1.5px solid #004643;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-main, 'Lexend', sans-serif);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  box-sizing: border-box;
}

/* === SETUP PAGE (quiz.html) ============================== */

.setup-steps-wrap {
  position: relative;
}

.setup-step {
  display: none;
}

.setup-step.active {
  display: block;
}

/* Subject section header */
.setup-hint {
  font-size: 13px;
  color: var(--muted, #64748B);
  margin-bottom: 16px;
}

/* Mode cards */
.mode-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.mode-card {
  border: 1.5px solid var(--border, #E2E8F0);
  border-radius: 16px;
  padding: 18px 20px;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.2s, transform 0.1s;
  position: relative;
  overflow: hidden;
}

.mode-card:hover {
  border-color: #004643;
}

.mode-card:active {
  transform: scale(0.99);
}

.mode-card.selected {
  border-color: #004643;
  background: rgba(0, 70, 67, 0.03);
}

/* Glow = system's recommendation. No label. */
.mode-card.recommended {
  box-shadow: 0 0 0 2px rgba(0, 119, 98, 0.25), 0 8px 24px rgba(0, 119, 98, 0.12);
}

.mode-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(0, 70, 67, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  color: #004643;
}

.mode-card.selected .mode-card-icon,
.mode-card.recommended .mode-card-icon {
  background: #004643;
  color: #fff;
}

.mode-card-title {
  font-size: 16px;
  font-weight: 700;
  color: #111827;
  margin-bottom: 4px;
}

.mode-card-desc {
  font-size: 13px;
  color: var(--muted, #64748B);
  line-height: 1.45;
}

/* Past Paper extras (year + timer) */
.paper-extras {
  display: none;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border, #E2E8F0);
  animation: fadeIn 0.2s ease;
}

.paper-extras.visible {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.extras-label {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 8px;
}

.timer-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
}

.timer-toggle-label {
  font-size: 14px;
  color: #374151;
}

/* Step navigation */
.step-nav {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}

.btn-back-step {
  padding: 12px 20px;
  background: #F1F5F9;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-main, 'Lexend', sans-serif);
  color: #374151;
  cursor: pointer;
}

.btn-next-step,
.btn-start-session {
  flex: 1;
  padding: 14px;
  background: #004643;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-main, 'Lexend', sans-serif);
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-next-step:disabled,
.btn-start-session:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* === PAST PAPER PAGE ==================================== */

/* Paper nav bar below header */
.paper-nav-bar {
  background: #fff;
  border-bottom: 1px solid var(--border, #E2E8F0);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted, #64748B);
  flex-shrink: 0;
}

.paper-q-counter {
  font-weight: 600;
  color: #111827;
}

.paper-answered-count {
  font-size: 12px;
}

/* Timer */
.timer-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #F0FDF4;
  border: 1px solid #A7F3D0;
  border-radius: 20px;
  padding: 4px 10px;
}

.timer-display {
  font-size: 14px;
  font-weight: 700;
  color: #065F46;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
}

.timer-display.warning {
  color: #DC2626;
}

.timer-badge.warning {
  background: #FEF2F2;
  border-color: #FECACA;
}

/* Bottom controls for Past Paper */
.paper-controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid var(--border, #E2E8F0);
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  gap: 10px;
  z-index: 100;
  max-width: 640px;
  margin: 0 auto;
}

.btn-paper-prev {
  padding: 13px 20px;
  background: #F1F5F9;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-main, 'Lexend', sans-serif);
  color: #374151;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-paper-prev:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-paper-next,
.btn-paper-submit {
  flex: 1;
  padding: 13px 20px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-main, 'Lexend', sans-serif);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-paper-next {
  background: #004643;
}

.btn-paper-submit {
  background: #059669;
}

/* Review panel (after submit) */
.review-panel {
  padding: 16px 0 60px;
}

.review-header {
  text-align: center;
  padding: 24px 0 20px;
}

.review-score {
  font-size: 56px;
  font-weight: 800;
  color: #004643;
  line-height: 1;
}

.review-stats {
  font-size: 15px;
  color: var(--muted, #64748B);
  margin-top: 6px;
}

.review-questions {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.review-question {
  background: #fff;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 12px;
  padding: 16px;
}

.review-question.correct {
  border-left: 3px solid #10B981;
}

.review-question.wrong {
  border-left: 3px solid #EF4444;
}

.review-question.unanswered {
  border-left: 3px solid var(--border, #E2E8F0);
  opacity: 0.7;
}

.review-q-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.review-q-num {
  font-size: 11px;
  font-weight: 700;
  background: #F1F5F9;
  padding: 2px 7px;
  border-radius: 6px;
  color: var(--muted, #64748B);
}

.review-q-subject {
  font-size: 11px;
  color: var(--muted, #64748B);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.review-q-text {
  font-size: 14px;
  color: #111827;
  margin-bottom: 10px;
  line-height: 1.45;
}

.review-q-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.review-q-options .option-btn {
  padding: 10px 12px;
  min-height: 0;
  font-size: 13px;
}

.review-actions {
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Responsive max-width container centering */
@media (min-width: 640px) {
  .quiz-main {
    padding-left: 24px;
    padding-right: 24px;
  }

  .feedback-bar,
  .paper-controls {
    left: 50%;
    right: auto;
    transform: translateX(-50%) translateY(100%);
    width: 100%;
  }

  .feedback-bar.visible {
    transform: translateX(-50%) translateY(0);
  }
}
