/* ========= Base reset + tokens ========= */
:root {
  --fg: #1a1a2e;
  --bg: #fefefe;
  --accent: #6ee7a0;
  --muted: #6b7280;
  --correct: #16a34a;
  --wrong: #dc2626;
  --focus: #fbbf24;
  --card-bg: rgba(255,255,255,0.08);
  --card-border: rgba(255,255,255,0.15);
  --text-on-dark: #e2e8f0;
  --text-accent: #6ee7a0;
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-round: 999px;
}

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow-x: hidden; }
body {
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  transition: background 0.6s ease;
}

/* ========= Theme kits (body classes) ========= */
body.kit-growth {
  background: linear-gradient(135deg, #0d3320 0%, #134e2e 30%, #0f4a3a 60%, #0c3d4a 100%);
  color: var(--text-on-dark);
  --accent: #6ee7a0;
  --text-accent: #6ee7a0;
}
body.kit-fill {
  background: linear-gradient(135deg, #0c1445 0%, #1e3a8a 30%, #0ea5e9 60%, #38bdf8 100%);
  color: var(--text-on-dark);
  --accent: #38bdf8;
  --text-accent: #7dd3fc;
}
body.kit-collect {
  background: linear-gradient(135deg, #451a03 0%, #78350f 30%, #b45309 60%, #d97706 100%);
  color: var(--text-on-dark);
  --accent: #fbbf24;
  --text-accent: #fde68a;
}
body.kit-level {
  background: linear-gradient(135deg, #2e1065 0%, #4c1d95 30%, #7c3aed 60%, #a855f7 100%);
  color: var(--text-on-dark);
  --accent: #c4b5fd;
  --text-accent: #ddd6fe;
}

/* ========= A11y fundamentals ========= */
.skip-link {
  position: absolute; top: -40px; left: 0;
  background: var(--accent); color: white;
  padding: 8px; text-decoration: none; z-index: 100;
}
.skip-link:focus { top: 0; }

*:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ========= Floating background particles ========= */
.particles {
  position: fixed; inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.particle {
  position: absolute;
  font-size: 1.4rem;
  opacity: 0.15;
  animation: particleFloat linear infinite;
}
@keyframes particleFloat {
  0% { transform: translateY(110vh) rotate(0deg); opacity: 0; }
  10% { opacity: 0.15; }
  90% { opacity: 0.15; }
  100% { transform: translateY(-20vh) rotate(360deg); opacity: 0; }
}

/* Celebration leaf layer */
.celebration { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 50; }
.leaf-particle { position: absolute; font-size: 1.6rem; animation: leafFall ease-in forwards; }
@keyframes leafFall {
  0% { transform: translateY(-50px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ========= Animations ========= */
@keyframes popIn {
  0% { transform: scale(0.4) rotate(-6deg); opacity: 0; }
  60% { transform: scale(1.08) rotate(2deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
.pop-in { animation: popIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }

@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.15); } }
.pulse { animation: pulse 0.5s ease; }

@keyframes shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
.shake { animation: shake 0.5s ease; }

@keyframes badgeSpin {
  0% { transform: scale(0) rotate(-180deg); opacity: 0; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
.badge-spin { animation: badgeSpin 0.9s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }

/* ========= Header ========= */
.app-header {
  position: relative;
  z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.5rem;
  background: rgba(0,0,0,0.15);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.brand {
  font-weight: 900; font-size: 1.5em;
  text-decoration: none;
  color: var(--text-accent);
  letter-spacing: -0.02em;
}
.pupil-info { display: flex; gap: 1rem; align-items: center; font-weight: 700; }
.pupil-info span { color: var(--text-accent); }
.xp-bar {
  display: inline-block; width: 140px; height: 10px;
  background: rgba(255,255,255,0.15);
  border-radius: var(--radius-round); overflow: hidden;
}
.xp-bar #xpFill {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--accent), #fbbf24);
  width: 0%;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========= Main + layout ========= */
main {
  position: relative;
  z-index: 5;
  padding: 2rem 1rem;
  max-width: 640px;
  margin: 0 auto;
}
h1 { font-size: 2.5rem; font-weight: 900; margin: 0 0 0.5rem; color: var(--text-accent); letter-spacing: -0.02em; }
h2 { font-size: 1.5rem; font-weight: 800; margin: 0 0 1rem; }

/* ========= Home tiles ========= */
.home-hero {
  text-align: center;
  margin-bottom: 2rem;
}
.home-hero .emoji-strip { font-size: 4rem; margin-bottom: 0.5rem; }
.stats-row {
  display: flex; gap: 0.75rem; justify-content: center;
  margin: 1rem 0;
  flex-wrap: wrap;
}
.stat-chip {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-round);
  font-weight: 700;
  backdrop-filter: blur(6px);
}
#quizList {
  list-style: none; padding: 0; margin: 1.5rem 0;
  display: grid; gap: 0.75rem;
}
#quizList li { margin: 0; }
#quizList a {
  display: block;
  padding: 1.25rem 1.5rem;
  background: rgba(255,255,255,0.1);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-md);
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.1rem;
  transition: transform 0.15s, background 0.15s, border-color 0.15s;
}
#quizList a:hover {
  transform: translateY(-3px);
  background: rgba(255,255,255,0.15);
  border-color: var(--accent);
}

/* ========= Buttons ========= */
button {
  font: inherit; font-weight: 700;
  min-height: 48px; min-width: 48px;
  padding: 0.85rem 1.5rem;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.15);
  transition: all 0.15s ease;
}
button:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.2); }
button:active:not(:disabled) { transform: translateY(0); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-secondary {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
}

/* ========= Login / PIN picker ========= */
.login-form fieldset {
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.05);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  backdrop-filter: blur(8px);
}
.login-form legend { font-weight: 800; padding: 0 0.5rem; }
.login-form label { font-weight: 700; margin-bottom: 0.5rem; display: block; }
.login-form select {
  font: inherit; font-weight: 700;
  padding: 0.75rem;
  background: rgba(255,255,255,0.15);
  color: inherit;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: var(--radius-sm);
  width: 100%;
  margin-bottom: 1rem;
}

.pin-picker { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.5rem 0; }
.pin-picker button {
  padding: 0.85rem 1.1rem;
  position: relative;
  border: 3px solid transparent;
  background: rgba(255,255,255,0.12);
  box-shadow: none;
  transition: transform 0.12s, box-shadow 0.15s, border-color 0.15s;
}
.pin-picker button.selected {
  border-color: #fff;
  box-shadow: 0 0 0 4px var(--correct), 0 6px 18px rgba(0,0,0,0.3);
  transform: scale(1.12);
}
.pin-picker button.selected::after {
  content: "✓";
  position: absolute;
  top: -8px; right: -8px;
  background: var(--correct);
  color: white;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 14px;
  border: 2px solid white;
}

/* ========= Quiz ========= */
.quiz-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem;
  font-weight: 800;
}
.quiz-header span { color: var(--text-accent); }
.growth-indicator { font-size: 1.75rem; transition: transform 0.3s; }

.progress-track {
  width: 100%; height: 12px;
  background: rgba(255,255,255,0.12);
  border-radius: var(--radius-round);
  overflow: hidden;
  margin-bottom: 1.5rem;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #fbbf24);
  width: 0%;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.question-card {
  background: var(--card-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.q-emoji { font-size: 3rem; text-align: center; margin-bottom: 0.5rem; }
.q-text {
  font-size: 1.35rem; font-weight: 800;
  text-align: center; margin: 0 0 1.5rem;
  line-height: 1.35;
}

.options { display: flex; flex-direction: column; gap: 0.65rem; }
.option-btn {
  display: block; width: 100%;
  text-align: left;
  background: rgba(255,255,255,0.08);
  color: inherit;
  border: 2px solid rgba(255,255,255,0.15);
  font-size: 1.05rem;
  padding: 1rem 1.2rem;
  box-shadow: none;
}
.option-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  background: rgba(255,255,255,0.15);
  border-color: var(--accent);
  box-shadow: 0 6px 18px rgba(0,0,0,0.15);
}
.option-btn.correct { background: rgba(22,163,74,0.35); border-color: #22c55e; }
.option-btn.wrong { background: rgba(220,38,38,0.35); border-color: #ef4444; }

.feedback {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  margin: 1rem 0;
  font-weight: 700;
  text-align: center;
  backdrop-filter: blur(8px);
}
.feedback.correct { background: rgba(22,163,74,0.25); border: 1px solid rgba(34,197,94,0.4); }
.feedback.wrong { background: rgba(220,38,38,0.25); border: 1px solid rgba(239,68,68,0.4); }

#nextBtn { display: block; width: 100%; margin-top: 0.5rem; }

/* ========= Result screen ========= */
.result-screen { text-align: center; padding: 2rem 1rem; }
.result-badge {
  width: 180px; height: 180px; margin: 0 auto 1.5rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border: 6px solid #fde68a;
  box-shadow: 0 0 40px rgba(251,191,36,0.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.result-badge .emoji { font-size: 3rem; margin-bottom: 0.25rem; }
.result-badge .label { font-size: 0.9rem; font-weight: 900; color: #78350f; }
.result-title { font-size: 2rem; font-weight: 900; margin: 0 0 0.5rem; color: var(--text-accent); }
.result-subtitle { font-size: 1.15rem; margin: 0 0 1rem; opacity: 0.9; }
.result-score { font-size: 3rem; font-weight: 900; color: #fbbf24; margin: 0.5rem 0 1.5rem; }
.rank-up-banner {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #78350f;
  padding: 1rem 1.5rem;
  border-radius: var(--radius-md);
  font-weight: 900;
  margin: 1rem 0;
  font-size: 1.1rem;
  box-shadow: 0 6px 20px rgba(251,191,36,0.4);
}

/* ========= Reduced motion ========= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
  .particle, .leaf-particle { display: none; }
}

/* ========= Small screens ========= */
@media (max-width: 540px) {
  h1 { font-size: 1.8rem; }
  .q-text { font-size: 1.15rem; }
  .result-badge { width: 150px; height: 150px; }
  .result-score { font-size: 2.4rem; }
  .pin-picker button { padding: 0.75rem 0.9rem; font-size: 0.95rem; }
}
