:root {
  --bg: #f0f0ff;
  --bg2: #e8e8f8;
  --card: #ffffff;
  --text: #2d2d44;
  --text2: #6b6b8a;
  --primary: #7c3aed;
  --primary-light: #a78bfa;
  --secondary: #06b6d4;
  --accent: #f59e0b;
  --accent2: #ef4444;
  --success: #10b981;
  --error: #ef4444;
  --shadow: 0 8px 32px rgba(124,58,237,.12);
  --shadow-lg: 0 16px 48px rgba(124,58,237,.18);
  --radius: 20px;
  --radius-sm: 12px;
}
[data-theme="dark"] {
  --bg: #1a1a2e;
  --bg2: #16213e;
  --card: #1e2746;
  --text: #eaeaff;
  --text2: #9d9dbb;
  --shadow: 0 8px 32px rgba(0,0,0,.3);
  --shadow-lg: 0 16px 48px rgba(0,0,0,.4);
}
* { margin:0; padding:0; box-sizing:border-box; }
body {
  font-family:'Nunito',sans-serif;
  background:var(--bg);
  color:var(--text);
  min-height:100vh;
  overflow-x:hidden;
  transition:background .3s,color .3s;
}
h1,h2,h3 { font-family:'Fredoka One',cursive; }
.screen { display:none; min-height:100vh; padding:20px; align-items:center; justify-content:center; flex-direction:column; }
.screen.active { display:flex; animation:fadeIn .4s ease; }
@keyframes fadeIn { from{opacity:0;transform:translateY(20px)} to{opacity:1;transform:translateY(0)} }

/* Welcome */
#welcome-screen { background:linear-gradient(135deg,#7c3aed 0%,#06b6d4 50%,#7c3aed 100%); background-size:200% 200%; animation:gradientShift 6s ease infinite; position:relative; }
@keyframes gradientShift { 0%,100%{background-position:0% 50%} 50%{background-position:100% 50%} }
.floating-emojis { position:absolute; top:0; left:0; width:100%; height:100%; pointer-events:none; overflow:hidden; }
.float-emoji { position:absolute; font-size:2rem; top:-50px; left:var(--x); animation:floatDown 6s var(--d) infinite linear; opacity:.6; }
@keyframes floatDown { 0%{top:-50px;transform:rotate(0)} 100%{top:110vh;transform:rotate(360deg)} }
.welcome-card {
  background:var(--card);
  padding:40px 32px;
  border-radius:var(--radius);
  box-shadow:var(--shadow-lg);
  text-align:center;
  max-width:420px;
  width:100%;
  position:relative;
  z-index:1;
}
.brain-icon { font-size:4rem; margin-bottom:10px; animation:pulse 2s ease infinite; }
@keyframes pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.1)} }
.welcome-card h1 { font-size:2.5rem; background:linear-gradient(135deg,var(--primary),var(--secondary)); -webkit-background-clip:text; -webkit-text-fill-color:transparent; background-clip:text; margin-bottom:8px; }
.subtitle { color:var(--text2); margin-bottom:24px; font-size:1.05rem; }
.input-group { margin-bottom:16px; text-align:left; }
.input-group label { display:block; font-weight:700; margin-bottom:6px; font-size:.9rem; color:var(--text2); }
.input-group input {
  width:100%; padding:14px 18px; border:2px solid var(--bg2); border-radius:var(--radius-sm);
  font-size:1rem; font-family:inherit; background:var(--bg); color:var(--text);
  transition:border-color .2s,box-shadow .2s; outline:none;
}
.input-group input:focus { border-color:var(--primary); box-shadow:0 0 0 4px rgba(124,58,237,.15); }
.btn-primary {
  display:inline-flex; align-items:center; gap:8px; padding:14px 32px;
  background:linear-gradient(135deg,var(--primary),var(--secondary));
  color:#fff; border:none; border-radius:50px; font-size:1.1rem; font-weight:700;
  font-family:inherit; cursor:pointer; transition:transform .15s,box-shadow .15s;
  box-shadow:0 4px 15px rgba(124,58,237,.3); margin-top:8px;
}
.btn-primary:hover { transform:translateY(-2px); box-shadow:0 6px 20px rgba(124,58,237,.4); }
.btn-primary:active { transform:translateY(0); }
.btn-icon { font-size:1.2rem; }

/* Category Screen */
#category-screen { background:var(--bg); }
.category-card {
  background:var(--card); padding:48px 36px; border-radius:var(--radius);
  box-shadow:var(--shadow-lg); text-align:center; max-width:500px; width:100%;
  animation:scaleIn .4s ease;
}
@keyframes scaleIn { from{transform:scale(.9);opacity:0} to{transform:scale(1);opacity:1} }
.category-icon { font-size:4.5rem; margin-bottom:12px; }
.category-card h2 { font-size:1.8rem; color:var(--primary); margin-bottom:8px; }
.category-card p { color:var(--text2); margin-bottom:20px; }
.category-progress { margin-bottom:20px; }
.category-progress span { background:var(--bg2); padding:6px 16px; border-radius:20px; font-size:.85rem; font-weight:700; }

/* Question Screen */
#question-screen { background:var(--bg); padding-top:0; }
.question-header {
  position:sticky; top:0; background:var(--card); padding:12px 20px;
  box-shadow:0 2px 12px rgba(0,0,0,.06); width:100%; z-index:10;
}
.progress-bar-container { height:6px; background:var(--bg2); border-radius:3px; margin-bottom:10px; overflow:hidden; }
.progress-bar { height:100%; background:linear-gradient(90deg,var(--primary),var(--secondary)); border-radius:3px; transition:width .4s ease; width:0%; }
.header-info { display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:6px; }
.q-category-badge {
  background:linear-gradient(135deg,var(--primary),var(--secondary)); color:#fff;
  padding:4px 14px; border-radius:20px; font-size:.8rem; font-weight:700;
}
.q-counter { font-weight:700; color:var(--text2); font-size:.9rem; }
.q-score { font-weight:700; color:var(--accent); font-size:.95rem; }
.q-timer { text-align:center; font-size:1.8rem; font-weight:800; color:var(--accent2); margin-top:6px; animation:pulse 1s ease infinite; }
.q-timer.hidden { display:none; }
.question-body {
  max-width:700px; width:100%; margin:20px auto; padding:0 16px;
  flex:1; display:flex; flex-direction:column; align-items:center;
}
.question-text { font-size:1.25rem; text-align:center; margin-bottom:20px; line-height:1.5; font-family:'Nunito',sans-serif; font-weight:700; }
.question-visual { margin-bottom:20px; display:flex; flex-wrap:wrap; gap:10px; justify-content:center; align-items:center; }
.options-grid { display:grid; grid-template-columns:1fr 1fr; gap:12px; width:100%; max-width:500px; }
.options-grid.single-col { grid-template-columns:1fr; }
.option-btn {
  padding:16px 20px; background:var(--card); border:2px solid var(--bg2);
  border-radius:var(--radius-sm); font-size:1rem; font-weight:600; font-family:inherit;
  cursor:pointer; transition:all .2s; text-align:center; color:var(--text); min-height:52px;
  display:flex; align-items:center; justify-content:center;
}
.option-btn:hover { border-color:var(--primary); background:rgba(124,58,237,.05); transform:translateY(-2px); }
.option-btn.selected { border-color:var(--primary); background:rgba(124,58,237,.1); }
.option-btn.correct { border-color:var(--success); background:rgba(16,185,129,.12); color:var(--success); animation:correctPop .3s ease; }
.option-btn.wrong { border-color:var(--error); background:rgba(239,68,68,.1); color:var(--error); }
@keyframes correctPop { 0%{transform:scale(1)} 50%{transform:scale(1.05)} 100%{transform:scale(1)} }

/* Feedback */
.feedback-overlay {
  position:fixed; top:0; left:0; width:100%; height:100%;
  background:rgba(0,0,0,.5); z-index:100; display:flex;
  align-items:center; justify-content:center; padding:20px;
  backdrop-filter:blur(4px);
}
.feedback-overlay.hidden { display:none; }
.feedback-card {
  background:var(--card); padding:36px; border-radius:var(--radius);
  text-align:center; max-width:400px; width:100%; box-shadow:var(--shadow-lg);
  animation:scaleIn .3s ease;
}
.feedback-icon { font-size:3.5rem; margin-bottom:8px; }
.feedback-card h3 { font-size:1.4rem; margin-bottom:8px; }
.feedback-card p { color:var(--text2); margin-bottom:16px; font-size:.95rem; line-height:1.5; }
.feedback-card.correct-fb { border-top:4px solid var(--success); }
.feedback-card.wrong-fb { border-top:4px solid var(--error); }

/* Memory Game */
#memory-screen { background:var(--bg); }
.memory-header { text-align:center; margin-bottom:24px; }
.memory-header h2 { color:var(--primary); margin-bottom:8px; }
.memory-display { display:flex; gap:12px; flex-wrap:wrap; justify-content:center; margin-bottom:24px; min-height:80px; }
.memory-cell {
  width:70px; height:70px; border-radius:var(--radius-sm);
  display:flex; align-items:center; justify-content:center;
  font-size:1.6rem; font-weight:800; transition:all .3s;
  background:var(--card); border:3px solid var(--bg2); box-shadow:var(--shadow);
}
.memory-cell.revealed { color:#fff; border-color:transparent; }
.memory-cell.c-red { background:#e74c3c; }
.memory-cell.c-blue { background:#3498db; }
.memory-cell.c-green { background:#2ecc71; }
.memory-cell.c-yellow { background:#f1c40f; }
.memory-cell.c-purple { background:#9b59b6; }
.memory-cell.c-orange { background:#e67e22; }
.memory-input { display:flex; gap:10px; flex-wrap:wrap; justify-content:center; margin-bottom:16px; }
.memory-input-btn {
  width:60px; height:60px; border-radius:var(--radius-sm); border:3px solid transparent;
  cursor:pointer; transition:transform .15s; color:#fff; font-size:1.2rem; font-weight:800;
}
.memory-input-btn:hover { transform:scale(1.1); }

/* Simon */
#simon-screen { background:var(--bg); }
.simon-header { text-align:center; margin-bottom:24px; }
.simon-header h2 { color:var(--primary); margin-bottom:4px; }
.badge { background:var(--primary); color:#fff; padding:4px 14px; border-radius:20px; font-size:.85rem; font-weight:700; display:inline-block; margin-top:4px; }
.simon-board {
  display:grid; grid-template-columns:1fr 1fr; gap:12px; max-width:280px; width:100%;
}
.simon-btn {
  width:100%; aspect-ratio:1; border-radius:var(--radius); background:var(--c);
  border:none; cursor:pointer; transition:all .15s; box-shadow:0 4px 12px rgba(0,0,0,.15);
}
.simon-btn.lit { background:var(--cl); transform:scale(1.05); box-shadow:0 0 30px var(--cl); }
.simon-btn:active { transform:scale(.95); }

/* Quick Math */
#quickmath-screen { background:var(--bg); }
.qm-header { text-align:center; margin-bottom:24px; }
.qm-header h2 { color:var(--primary); margin-bottom:8px; }
.qm-stats { display:flex; gap:12px; justify-content:center; }
.qm-problem { font-size:2.8rem; font-weight:800; text-align:center; margin-bottom:20px; font-family:'Fredoka One',cursive; color:var(--primary); }
.qm-input {
  width:160px; padding:16px; text-align:center; font-size:1.8rem; font-weight:700;
  border:3px solid var(--bg2); border-radius:var(--radius-sm); background:var(--card);
  color:var(--text); font-family:inherit; outline:none; display:block; margin:0 auto 16px;
}
.qm-input:focus { border-color:var(--primary); }

/* Results */
#results-screen { background:linear-gradient(135deg,#7c3aed,#06b6d4); position:relative; overflow:hidden; }
.results-card {
  background:var(--card); padding:40px 32px; border-radius:var(--radius);
  box-shadow:var(--shadow-lg); text-align:center; max-width:520px; width:100%;
  position:relative; z-index:1;
}
.results-card h2 { font-size:1.8rem; color:var(--primary); margin-bottom:12px; }
.results-rating { font-size:3rem; margin-bottom:8px; }
.results-score { font-size:1.4rem; font-weight:800; color:var(--accent); margin-bottom:20px; }
.results-breakdown { text-align:left; margin-bottom:20px; }
.breakdown-item { display:flex; align-items:center; gap:10px; margin-bottom:10px; }
.breakdown-label { flex:0 0 140px; font-weight:600; font-size:.9rem; }
.breakdown-bar-bg { flex:1; height:14px; background:var(--bg2); border-radius:7px; overflow:hidden; }
.breakdown-bar { height:100%; border-radius:7px; transition:width .8s ease; }
.breakdown-val { flex:0 0 40px; font-weight:700; font-size:.9rem; text-align:right; }
.results-message { color:var(--text2); margin-bottom:16px; font-size:1.05rem; line-height:1.5; }

/* Confetti */
#confetti-container { position:fixed; top:0; left:0; width:100%; height:100%; pointer-events:none; z-index:50; }
.confetti-piece {
  position:absolute; width:10px; height:10px; top:-20px;
  animation:confettiFall 3s linear forwards;
}
@keyframes confettiFall {
  0% { top:-20px; transform:rotate(0) scale(1); opacity:1; }
  100% { top:110vh; transform:rotate(720deg) scale(0); opacity:0; }
}

/* Theme Toggle */
.theme-toggle {
  position:fixed; top:16px; right:16px; width:44px; height:44px;
  border-radius:50%; border:none; background:var(--card); box-shadow:var(--shadow);
  font-size:1.3rem; cursor:pointer; z-index:200; transition:transform .2s;
}
.theme-toggle:hover { transform:scale(1.1); }

/* Visual shapes for puzzles */
.shape-box {
  width:60px; height:60px; display:flex; align-items:center; justify-content:center;
  border-radius:8px; font-size:2rem; background:var(--card); border:2px solid var(--bg2);
  box-shadow:0 2px 8px rgba(0,0,0,.05);
}
.shape-box.highlight { border-color:var(--accent); background:rgba(245,158,11,.08); }
.shape-box.large { width:80px; height:80px; font-size:2.5rem; }
.shape-row { display:flex; gap:8px; align-items:center; justify-content:center; }
.shape-grid { display:grid; gap:6px; justify-content:center; }
.shape-arrow { font-size:1.5rem; color:var(--text2); }
.seq-num {
  width:50px; height:50px; display:flex; align-items:center; justify-content:center;
  border-radius:50%; font-size:1.2rem; font-weight:800; background:var(--primary);
  color:#fff; box-shadow:0 3px 10px rgba(124,58,237,.25);
}
.seq-num.mystery { background:var(--accent); font-size:1.5rem; }

/* Responsive */
@media (max-width:600px) {
  .welcome-card { padding:28px 20px; }
  .welcome-card h1 { font-size:2rem; }
  .options-grid { grid-template-columns:1fr; }
  .question-text { font-size:1.1rem; }
  .shape-box { width:50px; height:50px; font-size:1.5rem; }
  .seq-num { width:42px; height:42px; font-size:1rem; }
  .results-card { padding:28px 20px; }
  .breakdown-label { flex:0 0 110px; font-size:.8rem; }
}
