:root {
  --bg: #0B1026;
  --bg-panel: #141a3d;
  --bg-panel-light: #1c2350;
  --text: #F4F1E8;
  --text-dim: #9aa3c9;
  --orange: #FF6B35;
  --green: #3DDC97;
  --yellow: #FFD23F;
  --red: #FF5266;
  --border: #2a3466;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Heebo', sans-serif;
  overflow-x: hidden;
}

h1, h2, .title, .profile-name, .question-eyebrow, .level-badge, .pilot-name {
  font-family: 'Rubik', sans-serif;
}

#stars {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.star {
  position: absolute;
  background: white;
  border-radius: 50%;
  animation: twinkle 3s ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

.screen {
  position: relative;
  z-index: 1;
  display: none;
  min-height: 100vh;
  min-height: 100dvh;
  flex-direction: column;
  align-items: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}

.screen.active { display: flex; }

/* --- Profile select --- */

.title {
  font-size: clamp(28px, 5vw, 44px);
  font-weight: 800;
  margin: 24px 0 4px;
  text-align: center;
}

.subtitle {
  color: var(--text-dim);
  margin: 0 0 40px;
  font-size: 18px;
}

.profile-cards {
  display: flex;
  gap: 28px;
  flex-wrap: wrap;
  justify-content: center;
}

.profile-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.reset-link {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  font-family: 'Heebo', sans-serif;
  padding: 4px;
}

.reset-link:hover { color: var(--red); }

.reset-link.reset-confirming {
  color: var(--red);
  font-weight: 700;
  text-decoration: none;
  animation: shake 0.4s ease;
}

.profile-card {
  width: 220px;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: 24px;
  padding: 28px 16px;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
  font-family: inherit;
}

.profile-card:hover, .profile-card:focus-visible {
  transform: translateY(-6px);
  border-color: var(--orange);
  outline: none;
}

.profile-avatar {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  height: 100px;
  margin-bottom: 8px;
}

.profile-avatar svg {
  width: 92px;
  height: auto;
  filter: drop-shadow(0 0 14px rgba(255,107,53,0.4));
}

.profile-avatar.avatar-green svg {
  filter: drop-shadow(0 0 14px rgba(61,220,151,0.4));
}

.profile-name {
  font-size: 26px;
  font-weight: 800;
}

.profile-grade {
  color: var(--text-dim);
  margin-top: 2px;
  font-size: 15px;
}

.profile-stats {
  margin-top: 14px;
  font-size: 14px;
  color: var(--yellow);
  font-weight: 500;
}

/* --- Mission screen --- */

.mission-bar {
  width: 100%;
  max-width: 780px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 12px;
  padding: 8px 14px;
  cursor: pointer;
  font-family: 'Heebo', sans-serif;
  font-size: 14px;
}

.btn-ghost:hover { border-color: var(--text-dim); color: var(--text); }

.mission-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pilot-name { font-weight: 700; font-size: 18px; }

.level-badge {
  background: var(--bg-panel-light);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  color: var(--yellow);
}

.mission-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-sound {
  font-size: 18px;
  padding: 8px 10px;
  line-height: 1;
}

.stars-count { font-weight: 700; color: var(--yellow); }

.track-wrap {
  width: 100%;
  max-width: 780px;
  margin: 16px 0 8px;
}

.track {
  position: relative;
  height: 46px;
  background: var(--bg-panel);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.planet {
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 30px;
}

.rocket-travel {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%) scaleX(-1);
  font-size: 26px;
  transition: right 0.5s cubic-bezier(.34,1.56,.64,1);
}

.fuel-label {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 6px;
}

.game-area {
  width: 100%;
  max-width: 780px;
  display: flex;
  align-items: center;
  gap: 24px;
  margin-top: 28px;
  flex-wrap: wrap;
  justify-content: center;
}

.mascot-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 130px;
  border-radius: 50%;
  padding: 10px;
  transition: background 0.3s ease;
}

.mascot { transition: transform 0.25s ease; }
.mascot.happy { animation: bounce 0.5s ease; }
.mascot.oops { animation: shake 0.4s ease; }

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-14px); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.mascot-bubble {
  margin-top: 10px;
  background: var(--bg-panel-light);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 14px;
  font-size: 14px;
  text-align: center;
  max-width: 160px;
}

.question-card {
  flex: 1;
  min-width: 280px;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: 24px;
  padding: 28px;
  text-align: center;
}

.question-eyebrow {
  color: var(--orange);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.question-text {
  font-family: 'Rubik', sans-serif;
  font-size: clamp(24px, 5vw, 34px);
  font-weight: 700;
  margin-bottom: 20px;
  direction: ltr;
  unicode-bidi: isolate;
}

.answer-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choice-btn {
  background: var(--bg-panel-light);
  border: 2px solid var(--border);
  color: var(--text);
  border-radius: 14px;
  padding: 14px;
  font-size: 18px;
  cursor: pointer;
  font-family: 'Heebo', sans-serif;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.choice-btn:hover { border-color: var(--orange); }
.choice-btn:active { transform: scale(0.98); }

/* While the answer is being shown, the choices stop responding to taps. */
.answer-choices.locked { pointer-events: none; }
.answer-choices.locked .choice-btn { opacity: 0.55; }

.answer-display {
  font-family: 'Rubik', sans-serif;
  font-size: 32px;
  font-weight: 800;
  min-height: 44px;
  margin-bottom: 14px;
  letter-spacing: 2px;
  direction: ltr;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 320px;
  margin: 0 auto;
  direction: ltr;
}

.key {
  background: var(--bg-panel-light);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 16px 0;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Rubik', sans-serif;
}

.key:hover { border-color: var(--orange); }
.key:active { transform: scale(0.96); }

.key-launch {
  grid-column: span 3;
  background: var(--orange);
  color: #1a1a1a;
  font-weight: 800;
  direction: rtl;
}

.feedback-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  opacity: 0;
}

.feedback-flash.correct {
  background: radial-gradient(circle, rgba(61,220,151,0.25), transparent 70%);
  animation: flash 0.5s ease;
}

.feedback-flash.wrong {
  background: radial-gradient(circle, rgba(255,82,102,0.2), transparent 70%);
  animation: flash 0.5s ease;
}

@keyframes flash {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* --- Next unlocks path --- */

.next-unlocks {
  width: 100%;
  max-width: 780px;
  margin-bottom: 8px;
}

.next-unlocks-label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
}

.next-unlocks-track {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 14px;
}

.unlock-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  opacity: 0.55;
  transform: scale(0.85);
}

.unlock-chip.next {
  opacity: 1;
  transform: scale(1);
}

.unlock-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.15);
}

.unlock-chip.next .unlock-swatch {
  width: 42px;
  height: 42px;
  border-color: var(--yellow);
  box-shadow: 0 0 10px rgba(255,210,63,0.4);
}

.unlock-swatch[data-rarity="rare"] { border-color: #B79CED; }
.unlock-swatch[data-rarity="epic"] { border-color: #FFD866; }

.unlock-progress {
  width: 42px;
  height: 5px;
  background: var(--bg-panel-light);
  border-radius: 999px;
  overflow: hidden;
}

.unlock-progress-fill {
  height: 100%;
  background: var(--yellow);
  transition: width 0.4s ease;
}

.unlock-cost {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 700;
}

.unlock-chip.next .unlock-cost { color: var(--yellow); }

.unlock-chip-done {
  font-size: 13px;
  color: var(--yellow);
  font-weight: 700;
}

/* --- Level up screen --- */

.levelup-card {
  position: relative;
  margin: auto;
  text-align: center;
  background: var(--bg-panel);
  border: 2px solid var(--yellow);
  border-radius: 28px;
  padding: 48px 36px;
  max-width: 420px;
  z-index: 1;
}

.levelup-planet {
  font-size: 72px;
  animation: bounce 1s ease infinite;
}

.levelup-mascot {
  display: flex;
  justify-content: center;
  margin-top: 8px;
  animation: dance 0.6s ease-in-out infinite;
}

@keyframes dance {
  0%, 100% { transform: rotate(-6deg) translateY(0); }
  50% { transform: rotate(6deg) translateY(-8px); }
}

.confetti-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 8px;
  height: 14px;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0.9; }
}

.levelup-card h2 {
  font-size: 26px;
  margin: 16px 0 4px;
}

.levelup-card p {
  color: var(--text-dim);
  margin-bottom: 24px;
}

.btn-primary {
  background: var(--orange);
  color: #1a1a1a;
  border: none;
  border-radius: 14px;
  padding: 14px 28px;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  font-family: 'Rubik', sans-serif;
}

.btn-primary:hover { filter: brightness(1.08); }

/* --- Closet screen --- */

.closet-layout {
  width: 100%;
  max-width: 780px;
  display: flex;
  gap: 28px;
  margin-top: 20px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.closet-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 160px;
  position: sticky;
  top: 20px;
}

.closet-preview .mascot-wrap {
  width: 160px;
  height: 160px;
  justify-content: center;
}

.closet-title {
  margin-top: 10px;
  font-family: 'Rubik', sans-serif;
  font-weight: 700;
  color: var(--text-dim);
}

.closet-shop {
  flex: 1;
  min-width: 280px;
}

.closet-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.closet-tab {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: 'Heebo', sans-serif;
  font-size: 14px;
  cursor: pointer;
}

.closet-tab.active {
  border-color: var(--orange);
  color: var(--text);
  background: var(--bg-panel-light);
}

.closet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.closet-item {
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-family: 'Heebo', sans-serif;
  color: var(--text);
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.closet-item:hover { transform: translateY(-3px); }

.closet-item.equipped {
  border-color: var(--green);
  box-shadow: 0 0 0 1px var(--green) inset;
}

.closet-item.locked {
  opacity: 0.75;
}

.closet-swatch {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.15);
}

.closet-swatch[data-rarity="rare"] { border-color: #B79CED; }
.closet-swatch[data-rarity="epic"] { border-color: #FFD866; box-shadow: 0 0 10px rgba(255,216,102,0.5); }

.closet-item-name {
  font-size: 13px;
  text-align: center;
  line-height: 1.3;
}

.tag {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}

.equipped-tag { background: rgba(61,220,151,0.18); color: var(--green); }
.owned-tag { background: rgba(255,210,63,0.18); color: var(--yellow); }
.cost-tag { background: rgba(255,107,53,0.15); color: var(--orange); }

.closet-item.shake-no {
  animation: shake 0.4s ease;
}

@media (prefers-reduced-motion: reduce) {
  .star { animation: none; }
  .mascot.happy, .mascot.oops, .levelup-planet, .levelup-mascot { animation: none; }
  .rocket-travel { transition: none; }
  .confetti-piece { display: none; }
}

@media (max-width: 480px) {
  .screen { padding: max(12px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom)); }
  .title { margin: 12px 0 4px; }
  .subtitle { margin-bottom: 24px; }
  .mission-bar { margin-bottom: 4px; flex-wrap: wrap; justify-content: center; row-gap: 6px; }
  .mission-right { gap: 8px; }
  .btn-ghost { padding: 7px 10px; font-size: 13px; }
  .btn-sound { padding: 7px 9px; font-size: 16px; }
  .track-wrap { margin: 8px 0 4px; }
  .track { height: 36px; }
  .fuel-label { margin-top: 4px; font-size: 12px; }
  .next-unlocks { margin-bottom: 4px; }
  .next-unlocks-label { margin-bottom: 5px; }
  .next-unlocks-track { gap: 10px; }
  .unlock-swatch { width: 22px; height: 22px; }
  .unlock-chip.next .unlock-swatch { width: 32px; height: 32px; }
  .unlock-progress { width: 32px; }
  .game-area { flex-direction: column; margin-top: 12px; gap: 10px; }
  .mascot-wrap { order: 2; min-width: auto; padding: 2px; }
  .mascot svg { width: 64px; height: auto; }
  .mascot-bubble { margin-top: 4px; padding: 5px 10px; font-size: 12px; max-width: 140px; }
  .question-card { padding: 16px; }
  .question-eyebrow { margin-bottom: 4px; font-size: 12px; }
  .question-text { margin-bottom: 12px; }
  .answer-display { min-height: 34px; margin-bottom: 8px; font-size: 26px; }
  .keypad-grid { gap: 7px; }
  .key { padding: 11px 0; font-size: 17px; }
  .answer-choices { gap: 7px; }
  .choice-btn { padding: 11px; font-size: 16px; }
}
