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

:root {
  --bg: #0f0f13;
  --surface: #1a1a24;
  --border: #2a2a3a;
  --purple: #7c3aed;
  --purple-light: #a78bfa;
  --pink: #ec4899;
  --green: #22c55e;
  --yellow: #eab308;
  --gray: #3f3f56;
  --text: #f1f1f5;
  --text-muted: #8888aa;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100dvh;
  overflow-x: hidden;
}

/* SCREENS */
.screen { display: none; flex-direction: column; min-height: 100dvh; padding: 24px 20px; }
.screen.active { display: flex; }

/* HOME */
#screen-home { align-items: center; justify-content: center; gap: 20px; text-align: center; }
#screen-home h1 { font-size: 2.5rem; font-weight: 800; color: var(--purple-light); }

.home-header { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.streak { font-size: 1.4rem; font-weight: 700; }
.xp-bar-wrap { width: 100%; height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; }
.xp-bar { height: 100%; background: linear-gradient(90deg, var(--purple), var(--pink)); width: 0%; transition: width 0.4s ease; border-radius: 99px; }
.xp-label { font-size: 0.85rem; color: var(--text-muted); }

/* BUTTONS */
.btn-primary {
  background: var(--purple);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 16px 48px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  max-width: 280px;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.8; }

.btn-secondary {
  background: transparent;
  color: var(--purple-light);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 48px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  max-width: 280px;
  transition: border-color 0.15s;
}
.btn-secondary:active { border-color: var(--purple); }

.btn-back {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 4px 0;
  align-self: flex-start;
}

/* GAME SCREEN */
#screen-game { gap: 16px; }
.game-header { display: flex; justify-content: space-between; align-items: center; }
.score-pill { background: var(--surface); border: 1px solid var(--border); border-radius: 99px; padding: 4px 14px; font-size: 0.85rem; color: var(--yellow); font-weight: 700; }

.question-wrap { display: flex; flex-direction: column; gap: 16px; flex: 1; }
.question-wrap.hidden { display: none; }
.q-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }

/* FLASHCARD */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
}
.card-front, .card-back {
  text-align: center;
}
.card-front { font-size: 1.5rem; font-weight: 700; }
.card-back { color: var(--text-muted); font-size: 1rem; font-weight: 400; display: none; line-height: 1.6; }
.card[data-flipped="true"] .card-front { display: none; }
.card[data-flipped="true"] .card-back { display: block; }

.hint { font-size: 0.8rem; color: var(--text-muted); text-align: center; }

.fc-actions { display: flex; gap: 12px; }
.fc-actions.hidden { display: none; }
.btn-miss { flex: 1; background: transparent; border: 1.5px solid var(--pink); color: var(--pink); border-radius: var(--radius); padding: 14px; font-size: 1rem; font-weight: 700; cursor: pointer; }
.btn-got  { flex: 1; background: var(--green); border: none; color: white; border-radius: var(--radius); padding: 14px; font-size: 1rem; font-weight: 700; cursor: pointer; }

/* MULTIPLE CHOICE */
.definition { font-size: 1.05rem; line-height: 1.6; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }

.choices { display: flex; flex-direction: column; gap: 10px; }
.choice-btn {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s;
}
.choice-btn.correct { border-color: var(--green); color: var(--green); }
.choice-btn.wrong   { border-color: var(--pink); color: var(--pink); }

/* FILL IN THE BLANK */
#fill-input {
  background: var(--surface);
  border: 1.5px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 16px 18px;
  font-size: 1.1rem;
  width: 100%;
  outline: none;
}
#fill-input:focus { border-color: var(--purple); }

.fill-feedback { font-size: 0.95rem; text-align: center; font-weight: 600; }
.fill-feedback.correct { color: var(--green); }
.fill-feedback.wrong   { color: var(--pink); }
.fill-feedback.hidden  { display: none; }

/* PROGRESS MAP */
#screen-map { gap: 16px; }
.map-header { display: flex; align-items: center; gap: 16px; }
.map-header h2 { font-size: 1.2rem; font-weight: 700; }

.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  overflow-y: auto;
  padding-bottom: 120px;
}

.map-term {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 4px;
  font-size: 0.65rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.map-term.locked   { color: var(--gray); border-color: var(--gray); opacity: 0.4; }
.map-term.unseen   { color: var(--text-muted); border-color: var(--border); }
.map-term.learning { border-color: var(--yellow); color: var(--yellow); }
.map-term.mastered { border-color: var(--green); color: var(--green); }

.term-detail {
  position: fixed;
  bottom: 24px;
  left: 20px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--purple);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 10;
}
.term-detail.hidden { display: none; }
.term-detail strong { font-size: 1.1rem; color: var(--purple-light); }
.term-detail p { font-size: 0.9rem; line-height: 1.5; color: var(--text-muted); }
.cat-pill { font-size: 0.7rem; background: var(--border); border-radius: 99px; padding: 2px 10px; color: var(--text-muted); align-self: flex-start; }

/* SESSION PROGRESS */
.session-progress {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 4px 12px;
}

/* FLASH OVERLAY */
.flash-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
}
.flash-overlay.flash-correct {
  background: var(--green);
  animation: flash 0.4s ease-out forwards;
}
.flash-overlay.flash-wrong {
  background: var(--pink);
  animation: flash 0.4s ease-out forwards;
}
@keyframes flash {
  0%   { opacity: 0.35; }
  100% { opacity: 0; }
}

/* CONFETTI */
.confetti-container {
  position: fixed;
  inset: 0;
  z-index: 99;
  pointer-events: none;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confetti-fall var(--fall-duration, 0.8s) ease-out forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg) scale(1); opacity: 1; }
  100% { transform: translateY(300px) rotate(720deg) scale(0.3); opacity: 0; }
}

/* SUMMARY SCREEN */
#screen-summary { align-items: center; justify-content: center; }
.summary-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.summary-trophy { font-size: 4rem; animation: pop-in 0.4s ease-out; }
.summary-title { font-size: 1.8rem; font-weight: 800; color: var(--purple-light); }

.summary-stats {
  display: flex;
  gap: 12px;
  width: 100%;
}
.stat-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-value { font-size: 1.8rem; font-weight: 800; color: var(--purple-light); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }

.summary-mastered { width: 100%; text-align: left; }
.summary-mastered.hidden { display: none; }
.summary-mastered-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
#summary-mastered-list { display: flex; flex-wrap: wrap; gap: 6px; }
.mastered-pill {
  background: var(--green);
  color: #000;
  font-size: 0.75rem;
  font-weight: 700;
  border-radius: 99px;
  padding: 4px 12px;
}

/* LEVEL UP SCREEN */
#screen-levelup { align-items: center; justify-content: center; background: var(--bg); }
.levelup-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.levelup-burst {
  font-size: 5rem;
  animation: burst 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.levelup-title {
  font-size: 2.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--purple-light), var(--pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.levelup-subtitle { color: var(--text-muted); font-size: 1rem; }
.levelup-terms { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.levelup-term-pill {
  background: linear-gradient(135deg, var(--purple), var(--pink));
  color: white;
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: 99px;
  padding: 6px 16px;
  animation: pop-in 0.3s ease-out backwards;
}

@keyframes pop-in {
  0%   { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes burst {
  0%   { transform: scale(0) rotate(-20deg); opacity: 0; }
  60%  { transform: scale(1.3) rotate(10deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
