.history-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 70px 20px;
}

.history-header {
  margin-bottom: 28px;
}

.history-title {
  font-family: 'Unbounded', sans-serif;
  font-size: clamp(30px, 5vw, 46px);
  color: var(--dark);
  margin-bottom: 12px;
}

.history-desc {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.6;
}

.quiz-card {
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);

  border: 1px solid rgba(255,255,255,0.24);
  border-radius: 28px;

  padding: 32px;

  box-shadow:
    0 12px 40px rgba(108,92,231,0.08),
    0 0 40px rgba(108,92,231,0.04);
}

.quiz-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}

#questionCounter,
#scoreCounter {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.progress {
  width: 100%;
  height: 10px;
  background: rgba(108,92,231,0.12);
  border-radius: 50px;
  overflow: hidden;
  margin-bottom: 28px;
}

#progressBar {
  width: 0%;
  height: 100%;
  background: var(--purple);
  border-radius: 50px;
  transition: width 0.3s ease;
}

.question-meta {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.question-meta span {
  background: rgba(108,92,231,0.1);
  color: var(--purple);
  padding: 7px 14px;
  border-radius: 50px;
  font-size: 13px;
  font-weight: 600;
}

#question {
  font-family: 'Unbounded', sans-serif;
  font-size: clamp(20px, 3vw, 28px);
  color: var(--dark);
  line-height: 1.4;
  margin-bottom: 24px;
}

#answers {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.answer-btn {
  width: 100%;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--white);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  text-align: left;

  transition:
    border-color 0.18s ease,
    transform 0.18s ease,
    background 0.18s ease;
}

.answer-btn:hover {
  transform: translateY(-2px);
  border-color: var(--purple);
}

.answer-btn:disabled {
  cursor: default;
}

.answer-btn.correct {
  border: 2px solid #1faa68;
  background: transparent;
  color: inherit;
}

.answer-btn.wrong {
  border: 2px solid #d65c45;
  background: transparent;
  color: inherit;
}

body.dark-theme .answer-btn.correct {
  border: 2px solid #35d07f;
  background: transparent;
}

body.dark-theme .answer-btn.wrong {
  border: 2px solid #ff7b66;
  background: transparent;
}

#nextBtn {
  margin-top: 26px;
  padding: 15px 26px;
  border: none;
  border-radius: 50px;
  background: var(--purple);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: none;
  transition: 0.2s;
}

#nextBtn:hover {
  background: #5a4bd1;
  transform: translateY(-2px);
}

#resultBox {
  margin-top: 20px;
}

.ai-box {
  margin-top: 24px;
  padding: 22px;
  border-radius: 20px;
  background: rgba(108,92,231,0.08);
  border: 1px solid rgba(108,92,231,0.15);
}

.ai-title {
  font-family: 'Unbounded', sans-serif;
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--purple);
}

.ai-text {
  line-height: 1.7;
  color: var(--text);
  font-size: 15px;
}

.ai-loading {
  margin-top: 22px;
  padding: 18px 20px;
  border-radius: 18px;
  background: rgba(108,92,231,0.08);
  border: 1px solid rgba(108,92,231,0.14);
  color: var(--purple);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.ai-error {
  margin-top: 20px;
  color: #ff7675;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots i {
  width: 6px;
  height: 6px;
  background: var(--purple);
  border-radius: 50%;
  animation: typingDot 1s infinite ease-in-out;
}

.typing-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingDot {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.4;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

.final-card {
  background: var(--purple-pale);
  border-radius: 24px;
  padding: 28px;
  text-align: center;
}

.final-card h2 {
  font-family: 'Unbounded', sans-serif;
  color: var(--dark);
  margin-bottom: 12px;
}

.final-score {
  font-family: 'Unbounded', sans-serif;
  font-size: 42px;
  color: var(--purple);
  margin: 18px 0;
}

.final-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.restart-btn,
.review-btn {
  padding: 14px 26px;
  border: none;
  border-radius: 50px;
  font-weight: 600;
  cursor: pointer;
}

.restart-btn {
  background: var(--purple);
  color: white;
}

.review-btn {
  background: var(--purple);
  color: white;
}

.quiz-stats {
  display: flex;
  align-items: center;
  gap: 12px;
}

#timer {
  background: rgba(225,112,85,0.12);
  color: var(--orange);
  padding: 7px 14px;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 700;
}

.start-quiz-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 40px;
  text-align: center;
}

.start-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.start-quiz-card h2 {
  font-family: 'Unbounded', sans-serif;
  color: var(--dark);
  margin-bottom: 12px;
}

.start-quiz-card p {
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 24px;
}

.start-info {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

.start-info span {
  background: rgba(108,92,231,0.1);
  color: var(--purple);
  padding: 8px 14px;
  border-radius: 50px;
  font-size: 13px;
  font-weight: 600;
}

#startQuizBtn {
  padding: 15px 30px;
  border: none;
  border-radius: 50px;
  background: var(--purple);
  color: white;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

#quizCard {
  display: none;
}

.fade-in {
  animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.back-link {
  display: inline-flex;
  margin-top: 16px;
  color: var(--purple);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.back-link:hover {
  text-decoration: underline;
}

/* DARK */

body.dark-theme .quiz-card,
body.dark-theme .start-quiz-card,
body.dark-theme .final-card {
  background: #181c25;
}

body.dark-theme .history-title,
body.dark-theme #question,
body.dark-theme .final-card h2,
body.dark-theme .start-quiz-card h2 {
  color: white;
}

body.dark-theme .history-desc,
body.dark-theme #questionCounter,
body.dark-theme #scoreCounter,
body.dark-theme .start-quiz-card p {
  color: #a0a7b5;
}

body.dark-theme .answer-btn {
  background: #11141c;
  color: white;
  border-color: rgba(255,255,255,0.06);
}

body.dark-theme .answer-btn:hover {
  border-color: var(--purple);
}

body.dark-theme .question-meta span,
body.dark-theme .start-info span {
  background: rgba(108,92,231,0.15);
}

body.dark-theme .review-btn {
  background: var(--purple);
  color: white;
}

body.dark-theme .ai-box,
body.dark-theme .ai-loading {
  background: rgba(108,92,231,0.14);
}

body.dark-theme #timer {
  background: rgba(225,112,85,0.18);
}

/* MOBILE */

@media (max-width: 768px) {
.final-stats {
  flex-direction: column;
}
  .history-page {
    padding: 40px 20px;
  }

  .quiz-card {
    padding: 24px;
  }

  .quiz-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .quiz-stats {
    flex-wrap: wrap;
  }

  .answer-btn {
    font-size: 15px;
    padding: 16px;
    line-height: 1.45;
  }

  .final-actions {
    flex-direction: column;
  }

  .review-btn,
  .restart-btn {
    width: 100%;
  }
}

.final-stats {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 20px;
}

.final-stats div {
  background: rgba(108,92,231,0.1);
  border-radius: 18px;
  padding: 14px 18px;
  min-width: 110px;
}

.final-stats strong {
  display: block;
  font-family: 'Unbounded', sans-serif;
  font-size: 22px;
  color: var(--purple);
}

.final-stats span {
  font-size: 13px;
  color: var(--muted);
}

.mistakes-wrap {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.mistakes-wrap h2 {
  font-family: 'Unbounded', sans-serif;
  color: var(--dark);
  margin-bottom: 8px;
}

.mistake-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 22px;
  text-align: left;
}

.mistake-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.mistake-top span {
  background: rgba(108,92,231,0.1);
  color: var(--purple);
  padding: 7px 12px;
  border-radius: 50px;
  font-size: 12px;
  font-weight: 700;
}

.mistake-card h3 {
  font-size: 18px;
  line-height: 1.5;
  color: var(--dark);
  margin-bottom: 14px;
}

.mistake-card p {
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 8px;
}

body.dark-theme .mistakes-wrap h2,
body.dark-theme .mistake-card h3 {
  color: white;
}

body.dark-theme .mistake-card {
  background: #181c25;
  border-color: rgba(255,255,255,0.08);
}