* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --green: #059669;
  --green-light: #d1fae5;
  --red: #dc2626;
  --red-light: #fee2e2;
  --yellow: #d97706;
  --yellow-light: #fef3c7;
  --blue: #2563eb;
  --blue-light: #dbeafe;
  --bg: #f5f3ff;
  --text: #1e1b4b;
  --card-bg: #ffffff;
  --radius: 16px;
}

body {
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Header */
header {
  background: linear-gradient(135deg, var(--purple) 0%, #4f46e5 100%);
  color: white;
  padding: 20px 24px 24px;
  position: relative;
}

.back-link {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  font-size: 14px;
  display: inline-block;
  margin-bottom: 12px;
  transition: color 0.2s;
}

.back-link:hover { color: white; }

#header-content {
  text-align: center;
}

#header-icon {
  font-size: 48px;
  display: block;
  margin-bottom: 8px;
}

header h1 {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 4px;
}

header p {
  font-size: 14px;
  opacity: 0.85;
}

/* Topic Nav */
#topic-nav {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  overflow-x: auto;
}

.topic-btn {
  flex-shrink: 0;
  padding: 10px 18px;
  border: 2px solid #e5e7eb;
  border-radius: 50px;
  background: white;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: all 0.2s;
}

.topic-btn:hover {
  border-color: var(--purple);
  color: var(--purple);
}

.topic-btn.active {
  background: var(--purple);
  border-color: var(--purple);
  color: white;
}

/* Main */
main {
  padding: 20px;
  max-width: 700px;
  margin: 0 auto;
}

.section { display: none; }
.section.active { display: block; }

/* Card */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}

/* Buttons */
.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--purple);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 16px;
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover { background: #6d28d9; transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  padding: 10px 20px;
  background: var(--purple-light);
  color: var(--purple);
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-secondary:hover { background: #ddd6fe; }

/* Category Picker */
#quiz-category-picker {
  margin-bottom: 16px;
}

.category-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #6b7280;
  margin-bottom: 10px;
}

#quiz-category-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cat-btn {
  padding: 8px 16px;
  border: 2px solid #e5e7eb;
  border-radius: 50px;
  background: white;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s;
  white-space: nowrap;
}

.cat-btn:hover {
  border-color: var(--purple);
  color: var(--purple);
}

.cat-btn.active {
  background: var(--purple);
  border-color: var(--purple);
  color: white;
}

/* Quiz */
#quiz-progress {
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#quiz-question {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 20px;
  line-height: 1.4;
}

#quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  padding: 14px 18px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  background: white;
  text-align: left;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--purple);
  background: var(--purple-light);
}

.option-btn.correct {
  border-color: var(--green);
  background: var(--green-light);
  color: var(--green);
}

.option-btn.wrong {
  border-color: var(--red);
  background: var(--red-light);
  color: var(--red);
}

#quiz-feedback {
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
}

#quiz-feedback.correct { background: var(--green-light); color: var(--green); }
#quiz-feedback.wrong { background: var(--red-light); color: var(--red); }

#quiz-explanation {
  margin-top: 10px;
  padding: 12px 16px;
  border-radius: 10px;
  background: #f0f4ff;
  color: #3a4a7a;
  font-size: 14px;
  line-height: 1.5;
  border-left: 4px solid #6b8cff;
}

/* Score */
#quiz-score { text-align: center; }

.score-circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: var(--purple);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 32px;
  font-weight: 800;
}

#score-message {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

/* Flashcards */
.flashcard-container { text-align: center; }

.flashcard {
  width: 100%;
  height: 260px;
  perspective: 1000px;
  cursor: pointer;
  margin-bottom: 10px;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 12px;
}

.flashcard-front {
  background: linear-gradient(135deg, var(--purple-light), #c7d2fe);
}

.flashcard-back {
  background: linear-gradient(135deg, var(--yellow-light), #fde68a);
  transform: rotateY(180deg);
}

.card-label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  opacity: 0.6;
  text-transform: uppercase;
}

.card-icon { font-size: 56px; }

.flashcard-front h2 { font-size: 26px; font-weight: 800; }

.flashcard-back p {
  font-size: 16px;
  line-height: 1.6;
  font-weight: 500;
  text-align: center;
}

.tap-hint {
  font-size: 13px;
  color: #9ca3af;
  margin-bottom: 16px;
}

.flashcard-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#fc-counter {
  font-size: 14px;
  font-weight: 600;
  color: #6b7280;
}

/* Fun Facts */
#facts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.fact-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 3px 12px rgba(0,0,0,0.07);
  border-left: 5px solid;
}

.fact-card:nth-child(4n+1) { border-color: var(--purple); }
.fact-card:nth-child(4n+2) { border-color: var(--green); }
.fact-card:nth-child(4n+3) { border-color: var(--yellow); }
.fact-card:nth-child(4n+4) { border-color: var(--blue); }

.fact-icon { font-size: 32px; margin-bottom: 10px; }
.fact-card h3 { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.fact-card p { font-size: 14px; line-height: 1.5; color: #4b5563; }

/* Match Game */
.match-instructions {
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
  color: #4b5563;
}

#match-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.match-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.match-item {
  padding: 14px 12px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  background: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.match-item:hover:not(.matched):not(.selected) {
  border-color: var(--purple);
  background: var(--purple-light);
}

.match-item.selected {
  border-color: var(--blue);
  background: var(--blue-light);
  color: var(--blue);
}

.match-item.matched {
  border-color: var(--green);
  background: var(--green-light);
  color: var(--green);
  cursor: default;
}

.match-item.wrong-flash {
  border-color: var(--red);
  background: var(--red-light);
}

#match-result {
  text-align: center;
  padding: 16px;
  font-size: 20px;
  font-weight: 700;
  margin-top: 16px;
  border-radius: 12px;
  background: var(--green-light);
  color: var(--green);
}

.hidden { display: none !important; }

@media (max-width: 480px) {
  header h1 { font-size: 22px; }
  #quiz-question { font-size: 18px; }
  .flashcard { height: 220px; }
  .card-icon { font-size: 42px; }
}
