:root {
  --bg: #0f1020;
  --surface: #16172a;
  --panel: #1d1f36;
  --text: #f6f7fb;
  --muted: #b5b9d6;
  --primary: #8f5bff;
  --primary-2: #ff7ce3;
  --success: #43d17c;
  --warning: #ffc857;
  --danger: #ff5d73;
  --shadow: rgba(3, 5, 22, 0.4);
  --card-radius: 16px;
  --chip-radius: 12px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --maxw: 1100px;
}

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(143, 91, 255, 0.25), transparent 60%),
    radial-gradient(1000px 500px at 120% -20%, rgba(255, 124, 227, 0.25), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(15, 16, 32, 0.7);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.header-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 800;
  letter-spacing: 0.3px;
}

.logo-badge {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px var(--shadow);
  font-size: 20px;
}

.grow { flex: 1; }

.progress-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.star {
  color: #ffd86b;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
}

.progress-bar {
  position: relative;
  width: 200px;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  position: absolute;
  inset: 0 100% 0 0;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  transition: inset 300ms ease;
}

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: var(--space-6) var(--space-5);
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
}

@media (min-width: 960px) {
  .layout {
    grid-template-columns: 1.2fr 0.8fr;
  }
}

.card {
  background: linear-gradient(180deg, rgba(31, 33, 60, 0.9), rgba(23, 25, 46, 0.9));
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--card-radius);
  box-shadow: 0 20px 50px var(--shadow);
  padding: var(--space-6);
}

.title {
  font-size: 28px;
  margin: 0 0 var(--space-3) 0;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 var(--space-5) 0;
}

.level-art {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: var(--card-radius);
  background: linear-gradient(135deg, rgba(143, 91, 255, 0.18), rgba(255, 124, 227, 0.18));
  border: 1px dashed rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.level-art img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.badge {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px 10px;
  border-radius: var(--chip-radius);
  font-size: 12px;
  color: var(--muted);
}

.answer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}
@media (min-width: 640px) {
  .answer-grid { grid-template-columns: 1fr 1fr; }
}

.answer {
  text-align: left;
  padding: var(--space-4);
  border-radius: var(--chip-radius);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #ffffff;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}
.answer:hover, .answer:focus-visible {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.18);
  outline: none;
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
}
.answer.correct { border-color: rgba(67, 209, 124, 0.8); background: rgba(67, 209, 124, 0.2); color: #0d351f; }
.answer.wrong { border-color: rgba(255, 93, 115, 0.8); background: rgba(255, 93, 115, 0.2); color: #3b0a12; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.btn {
  appearance: none;
  border: none;
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn:hover:not(:disabled) { transform: translateY(-1px); }

.btn-primary {
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  color: white;
  box-shadow: 0 10px 24px rgba(143, 91, 255, 0.35);
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.meta {
  color: var(--muted);
  font-size: 14px;
}

.footer {
  max-width: var(--maxw);
  margin: 0 auto var(--space-6);
  padding: 0 var(--space-5);
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, -2px); }

.confetti-piece {
  position: fixed;
  top: -10px;
  width: 10px;
  height: 14px;
  opacity: 0.9;
  transform: translateY(-50px) rotate(0deg);
  animation: fall 1600ms linear forwards;
}
@keyframes fall {
  0% { transform: translateY(-50px) rotate(0deg); }
  100% { transform: translateY(110vh) rotate(540deg); }
}

/* Celebration animations */
.celebrate-pulse {
  animation: celebrate-pulse 800ms ease-out;
}
@keyframes celebrate-pulse {
  0% { transform: scale(1); }
  30% { transform: scale(1.03); }
  60% { transform: scale(0.995); }
  100% { transform: scale(1); }
}

.celebrate-flash::after {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(800px 500px at 50% 30%, rgba(255,255,255,0.25), rgba(255,255,255,0) 70%);
  pointer-events: none;
  animation: celebrate-flash 550ms ease-out;
}
@keyframes celebrate-flash {
  0% { opacity: 0; }
  10% { opacity: 1; }
  100% { opacity: 0; }
}

.level-art .art-wow {
  animation: art-wow 1000ms ease-out;
  transform-origin: center;
  filter: drop-shadow(0 12px 24px rgba(0,0,0,0.4));
}
@keyframes art-wow {
  0% { transform: scale(0.96) rotate(-1deg); filter: drop-shadow(0 0 0 rgba(0,0,0,0)); }
  20% { transform: scale(1.06) rotate(1deg); }
  50% { transform: scale(1.02) rotate(-1deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* Sparkles emitted from the art image */
.sparkle {
  position: fixed;
  width: 10px;
  height: 10px;
  background: radial-gradient(circle, #fff 0%, #fff 50%, rgba(255,255,255,0) 70%);
  border-radius: 50%;
  pointer-events: none;
  filter: drop-shadow(0 0 10px rgba(255,255,255,0.8));
  animation: sparkle-fly 900ms ease-out forwards;
}
@keyframes sparkle-fly {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  10% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, -80px))) scale(0.6); }
}

/* Escalation tiers for confetti density and timings can be reflected via classes if needed */
.celebrate-tier-1 {}
.celebrate-tier-2 {}
.celebrate-tier-3 {}
.celebrate-tier-4 {}
.celebrate-tier-5 {}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Mini-game overlay */
.minigame-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 28, 0.98);
  z-index: 1000;
}
.minigame-overlay canvas {
  position: absolute;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
}
.minigame-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}
.minigame-hud .hud-left,
.minigame-hud .hud-center,
.minigame-hud .hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.minigame-hud .hud-right { pointer-events: auto; }
.hud-chip {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 14px;
}
.mini-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.minigame-instructions {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  color: #fff;
}
.minigame-instructions .headline {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 8px;
}
.minigame-instructions .sub {
  color: var(--muted);
}
.mini-actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
  justify-content: center;
}


