/* ===== MATHQUEST STYLES ===== */
:root {
  --bg: #0a0a1a;
  --bg2: #0f0f2a;
  --card: #13132e;
  --card2: #1a1a3e;
  --border: #2a2a5a;
  --neon-lime: #ccff00;
  --neon-pink: #ff3cac;
  --neon-cyan: #00f5ff;
  --neon-orange: #ff6b2b;
  --neon-purple: #b44fff;
  --text: #f0f0ff;
  --text-dim: #8888bb;
  --correct: #00ff88;
  --wrong: #ff4466;
  --font-display: 'Fredoka One', cursive;
  --font-body: 'Nunito', sans-serif;
  --radius: 18px;
  --radius-sm: 10px;
}

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

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow-x: hidden;
}

#particleCanvas {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 0;
}

/* ===== SCREENS ===== */
.screen {
  display: none; position: relative; z-index: 1;
  min-height: 100vh; width: 100%;
  animation: screenIn 0.4s ease;
}
.screen.active { display: flex; justify-content: center; align-items: flex-start; }

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

/* ===== HOME SCREEN ===== */
.home-container {
  width: 100%; max-width: 560px;
  padding: 32px 20px 48px;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
}

.logo-area { text-align: center; }
.logo-icon {
  font-size: 72px; line-height: 1;
  animation: floatBob 3s ease-in-out infinite;
  display: block;
}
@keyframes floatBob {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-12px); }
}
.logo-title {
  font-family: var(--font-display);
  font-size: clamp(42px, 10vw, 64px);
  background: linear-gradient(135deg, var(--neon-lime), var(--neon-cyan), var(--neon-pink));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1; margin-top: 8px;
  filter: drop-shadow(0 0 20px rgba(204,255,0,0.4));
}
.logo-sub {
  font-size: 15px; color: var(--text-dim); font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase; margin-top: 6px;
}

/* Name Input */
.name-input-wrap { width: 100%; }
.name-input-wrap input {
  width: 100%; padding: 14px 20px;
  background: var(--card); border: 2px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-family: var(--font-body); font-size: 16px; font-weight: 700;
  outline: none; transition: border-color 0.2s, box-shadow 0.2s;
  text-align: center;
}
.name-input-wrap input:focus {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 0 3px rgba(0,245,255,0.15);
}
.name-input-wrap input::placeholder { color: var(--text-dim); }

/* Section Label */
.section-label {
  font-size: 13px; font-weight: 900; letter-spacing: 2px;
  text-transform: uppercase; color: var(--text-dim);
  align-self: flex-start;
}

/* Topic Grid */
.topic-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px; width: 100%;
}
@media (max-width: 480px) { .topic-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 340px) { .topic-grid { grid-template-columns: repeat(2, 1fr); } }

.topic-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 14px 8px;
  background: var(--card); border: 2px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  transition: all 0.2s; color: var(--text);
  font-family: var(--font-body);
}
.topic-btn:hover {
  border-color: var(--neon-cyan); background: var(--card2);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,245,255,0.15);
}
.topic-btn.active {
  border-color: var(--neon-lime); background: rgba(204,255,0,0.08);
  box-shadow: 0 0 20px rgba(204,255,0,0.2);
}
.topic-icon { font-size: 26px; line-height: 1; }
.topic-name { font-size: 11px; font-weight: 800; text-align: center; line-height: 1.2; }

/* Difficulty */
.difficulty-row { display: flex; gap: 10px; width: 100%; }
.diff-btn {
  flex: 1; padding: 12px 8px;
  background: var(--card); border: 2px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
  font-family: var(--font-body); font-size: 14px; font-weight: 800;
  color: var(--text); transition: all 0.2s;
}
.diff-btn:hover { border-color: var(--neon-orange); transform: translateY(-2px); }
.diff-btn.active {
  border-color: var(--neon-orange); background: rgba(255,107,43,0.12);
  box-shadow: 0 0 16px rgba(255,107,43,0.25);
}

/* Start Button */
.btn-start {
  width: 100%; padding: 18px 32px;
  background: linear-gradient(135deg, var(--neon-lime), var(--neon-cyan));
  border: none; border-radius: var(--radius);
  font-family: var(--font-display); font-size: 22px;
  color: #0a0a1a; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  transition: all 0.2s; position: relative; overflow: hidden;
  box-shadow: 0 8px 32px rgba(204,255,0,0.3);
}
.btn-start:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 16px 48px rgba(204,255,0,0.45);
}
.btn-start:active { transform: scale(0.97); }
.btn-arrow { font-size: 24px; transition: transform 0.2s; }
.btn-start:hover .btn-arrow { transform: translateX(6px); }

/* Highscore Bar */
.highscore-bar {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 50px; padding: 10px 24px;
  font-size: 14px; font-weight: 700; color: var(--text-dim);
}
.highscore-bar strong { color: var(--neon-lime); }

/* ===== GAME SCREEN ===== */
.game-container {
  width: 100%; max-width: 560px;
  padding: 16px 16px 32px;
  display: flex; flex-direction: column; gap: 12px;
}

/* Top Bar */
.game-topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.topbar-left { display: flex; align-items: center; gap: 8px; }
.btn-home {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--card); border: 2px solid var(--border);
  font-size: 18px; cursor: pointer; transition: all 0.2s;
  display: flex; align-items: center; justify-content: center;
}
.btn-home:hover { border-color: var(--neon-pink); transform: scale(1.1); }
.topic-badge {
  background: var(--card2); border: 1px solid var(--border);
  border-radius: 50px; padding: 6px 14px;
  font-size: 13px; font-weight: 800;
}

/* Timer Ring */
.timer-ring-wrap {
  position: relative; width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
}
.timer-ring { width: 52px; height: 52px; transform: rotate(-90deg); }
.timer-ring-bg { fill: none; stroke: var(--border); stroke-width: 3; }
.timer-ring-fill {
  fill: none; stroke: var(--neon-cyan); stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 113; stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear, stroke 0.3s;
}
.timer-text {
  position: absolute; font-family: var(--font-display);
  font-size: 16px; color: var(--text);
}

/* Score */
.score-display { text-align: right; }
.score-label { display: block; font-size: 10px; font-weight: 900; letter-spacing: 2px; color: var(--text-dim); }
.score-val {
  font-family: var(--font-display); font-size: 26px;
  color: var(--neon-lime);
  text-shadow: 0 0 12px rgba(204,255,0,0.5);
}

/* XP Bar */
.xp-bar-wrap { display: flex; align-items: center; gap: 10px; }
.xp-bar-track {
  flex: 1; height: 8px; background: var(--card2);
  border-radius: 50px; overflow: hidden;
}
.xp-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--neon-purple), var(--neon-pink));
  border-radius: 50px; transition: width 0.5s ease;
}
.xp-label { font-size: 12px; font-weight: 900; color: var(--neon-purple); white-space: nowrap; }

/* Streak */
.streak-display {
  text-align: center; font-size: 14px; font-weight: 800;
  color: var(--neon-orange); min-height: 20px;
  transition: all 0.3s;
}

/* Question Card */
.question-card {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: 24px; padding: 28px 24px;
  text-align: center; position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,0.4);
  transition: transform 0.15s;
}
.question-card.shake {
  animation: shake 0.4s ease;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%      { transform: translateX(-8px); }
  40%      { transform: translateX(8px); }
  60%      { transform: translateX(-6px); }
  80%      { transform: translateX(6px); }
}
.question-card.correct-flash {
  animation: correctFlash 0.4s ease;
}
@keyframes correctFlash {
  0%   { border-color: var(--border); }
  50%  { border-color: var(--correct); box-shadow: 0 0 40px rgba(0,255,136,0.4); }
  100% { border-color: var(--border); }
}

.question-number {
  font-size: 12px; font-weight: 900; letter-spacing: 2px;
  color: var(--text-dim); text-transform: uppercase; margin-bottom: 8px;
}
.question-mascot {
  font-size: 48px; line-height: 1; margin-bottom: 12px;
  animation: mascotPulse 2s ease-in-out infinite;
}
@keyframes mascotPulse {
  0%,100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}
.question-text {
  font-family: var(--font-display);
  font-size: clamp(28px, 8vw, 42px);
  color: var(--text); line-height: 1.2;
  text-shadow: 0 0 20px rgba(204,255,0,0.2);
}
.question-hint {
  font-size: 13px; color: var(--text-dim); margin-top: 8px;
  font-weight: 600; min-height: 18px;
}

/* Answers Grid */
.answers-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.answer-btn {
  padding: 18px 12px;
  background: var(--card); border: 2px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  font-family: var(--font-display); font-size: 22px;
  color: var(--text); transition: all 0.15s;
  position: relative; overflow: hidden;
}
.answer-btn:hover:not(:disabled) {
  border-color: var(--neon-cyan); background: var(--card2);
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 8px 24px rgba(0,245,255,0.2);
}
.answer-btn:active:not(:disabled) { transform: scale(0.96); }
.answer-btn.correct {
  border-color: var(--correct); background: rgba(0,255,136,0.12);
  box-shadow: 0 0 24px rgba(0,255,136,0.3);
  animation: correctPop 0.3s ease;
}
@keyframes correctPop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}
.answer-btn.wrong {
  border-color: var(--wrong); background: rgba(255,68,102,0.12);
  animation: wrongShake 0.3s ease;
}
@keyframes wrongShake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-6px); }
  75%      { transform: translateX(6px); }
}
.answer-btn:disabled { cursor: not-allowed; opacity: 0.7; }

/* Feedback Overlay */
.feedback-overlay {
  position: absolute; inset: 0;
  background: rgba(10,10,26,0.85);
  border-radius: 24px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px;
  z-index: 10; backdrop-filter: blur(4px);
  animation: feedbackIn 0.2s ease;
}
@keyframes feedbackIn {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: scale(1); }
}
.feedback-overlay.hidden { display: none; }
.feedback-icon { font-size: 56px; animation: iconBounce 0.4s ease; }
@keyframes iconBounce {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}
.feedback-msg {
  font-family: var(--font-display); font-size: 28px;
  color: var(--text);
}
.feedback-points {
  font-family: var(--font-display); font-size: 22px;
  color: var(--neon-lime);
  text-shadow: 0 0 12px rgba(204,255,0,0.6);
}

/* ===== RESULTS SCREEN ===== */
.results-container {
  width: 100%; max-width: 560px;
  padding: 40px 20px 60px;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
}
.results-trophy {
  font-size: 80px; line-height: 1;
  animation: trophySpin 0.6s ease, floatBob 3s ease-in-out 0.6s infinite;
}
@keyframes trophySpin {
  from { transform: rotateY(0deg) scale(0); }
  to   { transform: rotateY(360deg) scale(1); }
}
.results-title {
  font-family: var(--font-display); font-size: 36px;
  background: linear-gradient(135deg, var(--neon-lime), var(--neon-cyan));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.results-player { font-size: 18px; font-weight: 800; color: var(--text-dim); }

.results-stats {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px; width: 100%;
}
@media (max-width: 400px) { .results-stats { grid-template-columns: repeat(2, 1fr); } }

.stat-card {
  background: var(--card); border: 2px solid var(--border);
  border-radius: var(--radius); padding: 16px 8px;
  text-align: center;
  animation: statPop 0.4s ease both;
}
.stat-card:nth-child(1) { animation-delay: 0.1s; }
.stat-card:nth-child(2) { animation-delay: 0.2s; }
.stat-card:nth-child(3) { animation-delay: 0.3s; }
.stat-card:nth-child(4) { animation-delay: 0.4s; }
@keyframes statPop {
  from { opacity: 0; transform: translateY(20px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.stat-icon { font-size: 24px; margin-bottom: 6px; }
.stat-val { font-family: var(--font-display); font-size: 26px; color: var(--neon-lime); }
.stat-label { font-size: 11px; font-weight: 800; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-top: 4px; }

.results-grade {
  display: flex; align-items: center; gap: 12px;
  background: var(--card2); border: 2px solid var(--border);
  border-radius: 50px; padding: 14px 28px;
  font-family: var(--font-display); font-size: 22px;
}

.results-actions { display: flex; gap: 12px; width: 100%; }
.btn-play-again, .btn-change-topic {
  flex: 1; padding: 16px;
  border-radius: var(--radius); border: none; cursor: pointer;
  font-family: var(--font-display); font-size: 16px;
  transition: all 0.2s;
}
.btn-play-again {
  background: linear-gradient(135deg, var(--neon-lime), var(--neon-cyan));
  color: #0a0a1a;
  box-shadow: 0 6px 24px rgba(204,255,0,0.3);
}
.btn-play-again:hover { transform: translateY(-3px); box-shadow: 0 12px 36px rgba(204,255,0,0.45); }
.btn-change-topic {
  background: var(--card); border: 2px solid var(--border);
  color: var(--text);
}
.btn-change-topic:hover { border-color: var(--neon-pink); transform: translateY(-3px); }

.new-highscore-banner {
  background: linear-gradient(135deg, var(--neon-orange), var(--neon-pink));
  color: white; border-radius: 50px; padding: 12px 28px;
  font-family: var(--font-display); font-size: 18px;
  animation: bannerPulse 1s ease-in-out infinite alternate;
}
@keyframes bannerPulse {
  from { box-shadow: 0 0 20px rgba(255,107,43,0.4); }
  to   { box-shadow: 0 0 40px rgba(255,60,172,0.6); }
}
.new-highscore-banner.hidden { display: none; }

/* ===== COMBO BURST ===== */
.combo-burst {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  animation: comboBurstAnim 0.8s ease forwards;
}
.combo-burst.hidden { display: none; }
@keyframes comboBurstAnim {
  0%   { opacity: 0; transform: scale(0.5); }
  30%  { opacity: 1; transform: scale(1.2); }
  70%  { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.5); }
}
.combo-text {
  font-family: var(--font-display); font-size: clamp(36px, 10vw, 64px);
  background: linear-gradient(135deg, var(--neon-orange), var(--neon-pink));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 30px rgba(255,107,43,0.8));
  text-align: center;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== UTILITY ===== */
.hidden { display: none !important; }