:root {
  --bg-deep: #0b132b;
  --bg-mid: #111d3d;
  --panel-bg: #162447;
  --card-bg: #1e325c;
  --stage-bg: #233a6b;
  --well-bg: #0d1733;

  --text-main: #fffdf7;
  --text-muted: #a9badb;

  --cyan: #38bdf8;
  --mint: #2ec4b6;
  --gold: #ffb703;
  --pink: #ff5d73;
  --orange: #fb8500;
  --purple: #6366f1;

  --font-display: 'Baloo 2', system-ui, sans-serif;
  --font-body: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;

  --radius-lg: 24px;
  --radius-md: 16px;
}

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

body {
  font-family: var(--font-body);
  background: radial-gradient(circle at 50% 0%, #192b56 0%, var(--bg-mid) 45%, var(--bg-deep) 100%);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  padding: 10px 14px 20px;
}

/* Twinkling Starfield (GPU-composited drift) */
.stars-bg {
  position: fixed;
  top: -420px;
  left: -420px;
  width: calc(100% + 420px);
  height: calc(100% + 420px);
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(2px 2px at 10% 15%, rgba(255, 255, 255, 0.85), transparent),
    radial-gradient(2.5px 2.5px at 28% 72%, rgba(255, 209, 102, 0.8), transparent),
    radial-gradient(2px 2px at 48% 22%, rgba(76, 201, 240, 0.85), transparent),
    radial-gradient(3px 3px at 72% 40%, rgba(255, 255, 255, 0.75), transparent),
    radial-gradient(2px 2px at 88% 18%, rgba(255, 89, 131, 0.8), transparent),
    radial-gradient(2.5px 2.5px at 82% 82%, rgba(6, 214, 160, 0.8), transparent),
    radial-gradient(2px 2px at 18% 88%, rgba(255, 255, 255, 0.7), transparent);
  background-size: 420px 420px;
  will-change: transform;
  animation: driftStarsGpu 85s linear infinite;
}

@keyframes driftStarsGpu {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(420px, 420px, 0); }
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Header */
.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.brand-icon {
  font-size: 1.8rem;
  filter: drop-shadow(0 4px 10px rgba(255, 209, 102, 0.45));
  animation: hoverBob 2.6s ease-in-out infinite;
}

@keyframes hoverBob {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-4px) rotate(4deg); }
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2.6vw, 1.65rem);
  letter-spacing: 0.4px;
  color: var(--gold);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.pill-btn {
  font-family: inherit;
  font-weight: 800;
  font-size: 0.92rem;
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  background: var(--card-bg);
  color: var(--text-main);
  box-shadow: 0 4px 0 #091024;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
}

.pill-btn:hover {
  background: #274073;
}

.pill-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #091024;
}

.danger-btn {
  background: linear-gradient(180deg, #ff6b8b, #e63963);
  box-shadow: 0 4px 0 #9e1b3c;
}

.danger-btn:hover {
  background: linear-gradient(180deg, #ff7e9a, #f0446e);
}

.danger-btn:active {
  box-shadow: 0 1px 0 #9e1b3c;
}

/* Settings Panel */
.settings-panel {
  background: var(--panel-bg);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  align-items: start;
}

button {
  touch-action: manipulation;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.setting-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 800;
  min-height: 24px;
  display: flex;
  align-items: center;
  line-height: 1.2;
}

.segmented {
  display: flex;
  background: var(--well-bg);
  padding: 4px;
  border-radius: 14px;
  gap: 4px;
}

.seg-btn,
.timer-btn {
  flex: 1;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.88rem;
  border: none;
  border-radius: 10px;
  padding: 8px 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.seg-btn.active,
.timer-btn.active {
  background: linear-gradient(180deg, var(--cyan), #2a9fd6);
  color: #0e0829;
  box-shadow: 0 3px 0 #18648a;
}

.focus-select {
  font-family: inherit;
  font-weight: 800;
  font-size: 0.9rem;
  background: var(--well-bg);
  color: var(--text-main);
  border: none;
  border-radius: 14px;
  padding: 10px 12px;
  cursor: pointer;
  outline: none;
  width: 100%;
}

.focus-select:focus-visible {
  box-shadow: 0 0 0 2px var(--cyan);
}

/* Slider */
.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  min-height: 24px;
}

.slider-badge {
  background: rgba(255, 183, 3, 0.16);
  color: var(--gold);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
}

.slider-bound {
  font-weight: 900;
  font-size: 0.9rem;
  color: var(--text-muted);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: var(--well-bg);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid #ffffff;
  box-shadow: 0 3px 0 #b38314;
  cursor: pointer;
  transition: transform 0.1s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.12);
}

input[type="range"]::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--gold);
  border: 3px solid #ffffff;
  box-shadow: 0 3px 0 #b38314;
  cursor: pointer;
}

/* HUD */
.hud-grid {
  position: sticky;
  top: 6px;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.hud-card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 6px 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1px;
  box-shadow: 0 6px 16px rgba(6, 10, 26, 0.45);
}

.hud-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 800;
}

.hud-value {
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 2.5vw, 1.6rem);
  font-weight: 800;
}

.hud-timer .hud-value { color: var(--cyan); }
.hud-score .hud-value { color: var(--mint); }
.hud-streak .hud-value { color: var(--gold); }
.hud-errors .hud-value { color: var(--pink); }

.hud-timer.warning .hud-value {
  color: var(--pink);
  animation: pulseWarn 0.7s ease-in-out infinite;
}

@keyframes pulseWarn {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Main Arena */
.arena {
  background: var(--panel-bg);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 12px 30px rgba(8, 4, 24, 0.45);
}

/* Mascot Bar */
.mascot-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mascot {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.mascot.cheer {
  animation: mascotJump 0.45s ease;
}

.mascot.oops {
  animation: mascotWobble 0.4s ease;
}

@keyframes mascotJump {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-14px) scale(1.12) rotate(-6deg); }
  75% { transform: translateY(2px) scale(0.96) rotate(4deg); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes mascotWobble {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-10deg); }
  75% { transform: rotate(10deg); }
}

.speech-bubble {
  background: #ffffff;
  color: #1d1145;
  font-weight: 800;
  font-size: 0.94rem;
  padding: 9px 14px;
  border-radius: 14px;
  position: relative;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
  flex: 1;
}

.speech-bubble::before {
  content: '';
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  border-width: 9px 11px 9px 0;
  border-style: solid;
  border-color: transparent #ffffff transparent transparent;
}

/* Rocket Progress Track */
.rocket-track {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.track-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 800;
}

.rank-badge {
  color: var(--gold);
}

.next-rank-text {
  color: var(--text-muted);
}

.progress-rail {
  height: 16px;
  background: var(--well-bg);
  border-radius: 999px;
  overflow: visible;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--orange), var(--gold), var(--mint));
  border-radius: 999px;
  position: relative;
  transition: width 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  min-width: 14px;
}

.rail-rocket {
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-54%) rotate(45deg);
  font-size: 1.25rem;
  z-index: 2;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.rocket-exhaust {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 16px;
  pointer-events: none;
  z-index: 1;
}

.engine-flame {
  position: absolute;
  right: 0;
  top: 50%;
  width: 16px;
  height: 7px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--orange), var(--gold));
  transform-origin: right center;
  will-change: transform, opacity;
  animation: flameFlicker 0.22s ease-in-out infinite alternate;
}

.rocket-spark {
  position: absolute;
  right: 4px;
  top: 50%;
  width: 3.5px;
  height: 3.5px;
  border-radius: 50%;
  background: var(--gold);
  will-change: transform, opacity;
}

.spark-1 {
  animation: sparkTrailA 0.55s linear infinite;
}

.spark-2 {
  background: var(--orange);
  animation: sparkTrailB 0.7s linear infinite 0.2s;
}

.spark-3 {
  background: #fffdf7;
  animation: sparkTrailC 0.6s linear infinite 0.35s;
}

@keyframes flameFlicker {
  from { transform: translateY(-50%) scaleX(0.82) scaleY(0.9); opacity: 0.75; }
  to { transform: translateY(-50%) scaleX(1.15) scaleY(1.08); opacity: 1; }
}

@keyframes sparkTrailA {
  0% { transform: translate3d(0, -50%, 0) scale(1); opacity: 0.9; }
  100% { transform: translate3d(-22px, -8px, 0) scale(0.2); opacity: 0; }
}

@keyframes sparkTrailB {
  0% { transform: translate3d(0, -50%, 0) scale(1); opacity: 0.85; }
  100% { transform: translate3d(-26px, 5px, 0) scale(0.2); opacity: 0; }
}

@keyframes sparkTrailC {
  0% { transform: translate3d(0, -50%, 0) scale(0.9); opacity: 0.8; }
  100% { transform: translate3d(-18px, -1px, 0) scale(0.15); opacity: 0; }
}

/* Question Card */
.question-card {
  position: relative;
  background: linear-gradient(180deg, var(--stage-bg), var(--card-bg));
  border-radius: var(--radius-md);
  padding: 14px 16px 10px;
  text-align: center;
  box-shadow: inset 0 2px 12px rgba(255, 255, 255, 0.06);
}

.question-card.correct-flash {
  box-shadow: 0 0 28px rgba(46, 196, 182, 0.55);
}

.question-card.error-shake {
  box-shadow: 0 0 24px rgba(255, 93, 115, 0.55);
  animation: cardShake 0.38s ease;
}

@keyframes cardShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-7px); }
  80% { transform: translateX(7px); }
}

.feedback-pop {
  position: absolute;
  top: 10px;
  right: 18px;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
}

.feedback-pop.show {
  animation: popFloat 0.85s ease forwards;
}

@keyframes popFloat {
  0% { opacity: 0; transform: translateY(8px) scale(0.8); }
  25% { opacity: 1; transform: translateY(0) scale(1.15); }
  100% { opacity: 0; transform: translateY(-22px) scale(1); }
}

.question-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
}

.question-text {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  font-family: var(--font-display);
  font-size: clamp(2.3rem, 6vw, 3.6rem);
  font-weight: 800;
  letter-spacing: 1px;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.q-part {
  display: inline-block;
  will-change: transform;
}

.q-num-a {
  animation: floatNumA 2.8s ease-in-out infinite;
}

.q-op {
  color: var(--cyan);
  animation: floatOp 2.3s ease-in-out infinite;
}

.q-num-b {
  animation: floatNumB 3.1s ease-in-out infinite;
}

@keyframes floatNumA {
  0%, 100% { transform: translate(0, 0) rotate(-2deg); }
  50% { transform: translate(-2px, -6px) rotate(2.5deg); }
}

@keyframes floatOp {
  0%, 100% { transform: translateY(2px) scale(1); }
  50% { transform: translateY(-5px) scale(1.08); }
}

@keyframes floatNumB {
  0%, 100% { transform: translate(0, -3px) rotate(2deg); }
  50% { transform: translate(2px, 5px) rotate(-2.5deg); }
}

.equals-sign {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3rem);
  color: var(--gold);
}

.answer-box {
  min-width: 112px;
  height: 64px;
  padding: 0 14px;
  background: var(--well-bg);
  border: 3px solid var(--cyan);
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.45), 0 0 18px rgba(56, 189, 248, 0.25);
}

.answer-value {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 800;
  color: var(--text-main);
}

.answer-value.placeholder {
  color: rgba(200, 194, 255, 0.45);
}

.input-hint {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 700;
}

/* Keypad */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 400px;
  width: 100%;
  margin: 0 auto;
}

.key-btn {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  padding: 10px 8px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, #274073, #1c3059);
  color: var(--text-main);
  cursor: pointer;
  box-shadow: 0 4px 0 #091024;
  transition: transform 0.04s ease, box-shadow 0.04s ease;
  user-select: none;
}

.key-btn:hover {
  filter: brightness(1.1);
}

.key-btn:active,
.key-btn.pressed {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #091024;
}

.key-clear {
  background: linear-gradient(180deg, #ff9f1c, #e07a00);
  box-shadow: 0 5px 0 #8a4b00;
}

.key-clear:active,
.key-clear.pressed {
  box-shadow: 0 1px 0 #8a4b00;
}

.key-go {
  background: linear-gradient(180deg, #06d6a0, #04a67b);
  color: #09261d;
  font-size: 1.25rem;
  box-shadow: 0 5px 0 #026349;
}

.key-go:active,
.key-go.pressed {
  box-shadow: 0 1px 0 #026349;
}

/* Tricky Facts Log */
.mistakes-section {
  background: var(--panel-bg);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mistakes-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.mistakes-header h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--pink);
}

.mistakes-tip {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 700;
}

.mistakes-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mistake-chip {
  background: rgba(255, 89, 131, 0.16);
  border: 1.5px solid rgba(255, 89, 131, 0.45);
  color: #ffd6e0;
  border-radius: 12px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 0.92rem;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 6, 30, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 50;
}

.modal-card {
  background: linear-gradient(180deg, var(--stage-bg), var(--panel-bg));
  border-radius: 28px;
  max-width: 480px;
  width: 100%;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(4, 8, 22, 0.75);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: modalPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

.modal-trophy {
  font-size: 3.6rem;
  line-height: 1;
}

.modal-card h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--gold);
}

.modal-subtitle {
  color: var(--text-muted);
  font-weight: 700;
  line-height: 1.45;
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-pill {
  background: var(--well-bg);
  border-radius: 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

.stat-num {
  font-family: var(--font-display);
  font-size: 1.7rem;
  color: var(--cyan);
}

.stat-lbl {
  font-size: 0.78rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 800;
}

.modal-mistakes-wrap {
  text-align: left;
  background: var(--well-bg);
  border-radius: 16px;
  padding: 12px;
}

.modal-mistakes-wrap h3 {
  font-size: 0.9rem;
  color: var(--pink);
  margin-bottom: 8px;
}

.animal-fact-box {
  background: var(--well-bg);
  border-radius: 18px;
  padding: 16px 18px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fact-tag {
  display: inline-block;
  align-self: flex-start;
  background: rgba(46, 196, 182, 0.18);
  color: var(--mint);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 999px;
}

.animal-fact-text {
  font-size: 1.02rem;
  font-weight: 700;
  line-height: 1.5;
  color: var(--text-main);
}

.play-again-btn {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 800;
  border: none;
  border-radius: 18px;
  padding: 14px 20px;
  background: linear-gradient(180deg, var(--gold), #e59f00);
  color: #0b132b;
  cursor: pointer;
  box-shadow: 0 5px 0 #996900;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.play-again-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #996900;
}

.hidden {
  display: none !important;
}

@media (max-width: 560px) {
  .hud-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .mascot {
    width: 54px;
    height: 54px;
  }

  .speech-bubble {
    font-size: 0.9rem;
    padding: 10px 12px;
  }

  .key-btn {
    padding: 12px 8px;
    font-size: 1.45rem;
  }
}
