:root {
  --sky-top: #6EC6E8;
  --sky-bottom: #D6F5FF;
  --sun: #FFD93D;
  --grass: #8CD867;
  --grass-dark: #6FBF52;
  --red: #FF6B6B;
  --yellow: #FFC93C;
  --green: #4ECB71;
  --purple: #A78BFA;
  --ink: #233156;
  --card: #FFFFFF;
  --shadow: rgba(35, 49, 86, 0.18);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'Nunito', sans-serif;
  color: var(--ink);
  overflow: hidden;
  background: linear-gradient(to bottom, var(--sky-top) 0%, var(--sky-bottom) 65%, var(--grass) 65%, var(--grass-dark) 100%);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.stage {
  position: relative;
  width: 100%;
  height: 100vh;
  min-height: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---- sun ---- */
.sun {
  position: absolute;
  top: 24px;
  left: 24px;
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #FFF1A8, var(--sun));
  box-shadow: 0 0 30px 6px rgba(255, 217, 61, 0.6);
}

/* ---- clouds ---- */
.cloud {
  position: absolute;
  background: #fff;
  border-radius: 50px;
  opacity: 0.9;
  filter: drop-shadow(0 4px 0 rgba(255, 255, 255, 0.4));
  animation: drift linear infinite;
}

.cloud:before, .cloud:after {
  content: "";
  position: absolute;
  background: #fff;
  border-radius: 50%;
}

.c1 { width: 90px; height: 34px; top: 70px; left: -120px; animation-duration: 38s; }
.c1:before { width: 50px; height: 50px; top: -24px; left: 12px; }
.c1:after { width: 34px; height: 34px; top: -14px; left: 52px; }

.c2 { width: 70px; height: 26px; top: 150px; left: -100px; animation-duration: 52s; animation-delay: -15s; }
.c2:before { width: 38px; height: 38px; top: -18px; left: 10px; }
.c2:after { width: 26px; height: 26px; top: -10px; left: 40px; }

.c3 { width: 60px; height: 22px; top: 40px; left: -90px; animation-duration: 46s; animation-delay: -30s; }
.c3:before { width: 32px; height: 32px; top: -15px; left: 8px; }
.c3:after { width: 22px; height: 22px; top: -8px; left: 34px; }

@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(120vw); }
}

/* ---- top bar ---- */
.topbar {
  position: relative;
  z-index: 5;
  width: 100%;
  max-width: 520px;
  padding: 16px 18px 0 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: 'Fredoka', sans-serif;
}

.pill {
  background: var(--card);
  border-radius: 999px;
  padding: 8px 16px;
  box-shadow: 0 4px 0 var(--shadow);
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill span.num { font-size: 20px; color: var(--red); }
.pill.level span.num { color: var(--purple); }

.progress-wrap {
  background: rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  height: 16px;
  width: 100%;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), #7EE39A);
  width: 0%;
  transition: width 0.4s ease;
}

.progress-label {
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
  margin-top: 2px;
  opacity: 0.75;
}

/* ---- main game area ---- */
.game-area {
  position: relative;
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 2;
}

.balloon-zone {
  position: relative;
  width: 230px;
  height: 290px;
  display: flex;
  align-items: center;
  justify-content: center;
}

svg.timer-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 230px;
  height: 230px;
  transform: rotate(-90deg);
}

.timer-ring circle.bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.55);
  stroke-width: 8;
}

.timer-ring circle.progress {
  fill: none;
  stroke: var(--purple);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset linear, stroke 0.3s ease;
}

.timer-ring circle.progress.urgent { stroke: var(--red); }

.balloon {
  position: relative;
  width: 150px;
  height: 180px;
  transform-origin: center bottom;
  transition: transform 0.25s ease-out;
  cursor: default;
}

.balloon .body {
  width: 100%;
  height: 100%;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.75), transparent 40%),
             linear-gradient(160deg, var(--balloon-color-1, #FF9AA2), var(--balloon-color-2, #FF6B6B));
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.balloon .knot {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 12px solid var(--balloon-color-2, #FF6B6B);
}

.balloon .string {
  position: absolute;
  bottom: -70px;
  left: 50%;
  width: 2px;
  height: 70px;
  background: rgba(80, 60, 40, 0.4);
  transform-origin: top center;
  animation: sway 2.4s ease-in-out infinite;
}

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

.balloon.urgent { animation: shake 0.35s ease-in-out infinite; }

@keyframes shake {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  25% { transform: translateX(-3px) rotate(-2deg); }
  75% { transform: translateX(3px) rotate(2deg); }
}

.balloon.pop-anim { animation: popScale 0.15s ease-out forwards; }

@keyframes popScale {
  to { transform: scale(1.3); opacity: 0; }
}

.balloon.correct-float { animation: floatAway 0.6s ease-in forwards; }

@keyframes floatAway {
  to { transform: translateY(-160px) scale(0.7); opacity: 0; }
}

.equation {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 34px;
  color: #fff;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.15);
}

/* ---- approaching storm cloud ---- */
.cloud-track {
  position: absolute;
  top: -30px;
  right: -40px;
  width: 130px;
  height: 95px;
  z-index: 6;
  transform: translateX(180px) scale(0.75);
  transition: none;
  pointer-events: none;
}
/* ---- storm cloud lunge animation ---- */
.cloud-track.lunge {
  transition: transform 0.25s ease-in !important;
  transform: translateX(-120px) translateY(20px) scale(1.15) !important;
}
.black-cloud {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.4));
}

.black-cloud.urgent { animation: cloudShake 0.28s ease-in-out infinite; }

@keyframes cloudShake {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  25% { transform: translateX(-3px) rotate(-2deg); }
  75% { transform: translateX(3px) rotate(2deg); }
}

.black-cloud .bolt { opacity: 0; }

.black-cloud.urgent .bolt { animation: boltFlicker 0.4s steps(2, jump-none) infinite; }

@keyframes boltFlicker {
  0%, 100% { opacity: 0; }
  50% { opacity: 0.95; }
}

.cloud-track.impact { animation: cloudLunge 0.25s ease-out forwards; }

@keyframes cloudLunge {
  to { transform: translateX(-14px) scale(0.85); }
}

/* burst particles */
.burst {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  pointer-events: none;
}

.burst span {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  opacity: 0;
}

.burst.show span {
  animation: fly 0.55s ease-out forwards;
}

@keyframes fly {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.3); }
}

/* ---- answer buttons ---- */
.answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: 100%;
  max-width: 340px;
  padding: 0 20px;
}

.answer-btn {
  font-family: 'Fredoka', sans-serif;
  font-size: 26px;
  font-weight: 700;
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 18px 0;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.15);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.answer-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}

.answer-btn:nth-child(1) { background: var(--red); }
.answer-btn:nth-child(2) { background: var(--purple); }
.answer-btn:nth-child(3) { background: var(--green); }
.answer-btn:nth-child(4) { background: #4FA9E0; }

.answer-btn.correct-flash { background: var(--green) !important; }
.answer-btn.wrong-flash { background: var(--red) !important; }
.answer-btn[disabled] { opacity: 0.55; cursor: default; }

/* ---- feedback banner ---- */
.feedback {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translate(-50%, -140%);
  background: var(--card);
  padding: 10px 22px;
  border-radius: 999px;
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 17px;
  box-shadow: 0 6px 0 var(--shadow);
  z-index: 10;
  opacity: 0;
  transition: transform 0.35s ease, opacity 0.35s ease;
  white-space: nowrap;
}

.feedback.show { transform: translate(-50%, 0%); opacity: 1; }
.feedback.good { color: var(--green); }
.feedback.bad { color: var(--red); }

/* ---- level up overlay ---- */
.levelup {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(35, 49, 86, 0.35);
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.levelup.show { opacity: 1; pointer-events: auto; }

.levelup-card {
  background: #fff;
  border-radius: 24px;
  padding: 28px 34px;
  text-align: center;
  font-family: 'Fredoka', sans-serif;
  box-shadow: 0 10px 0 var(--shadow);
  transform: scale(0.7);
  transition: transform 0.3s ease;
}

.levelup.show .levelup-card { transform: scale(1); }

.levelup-card h2 {
  margin: 0 0 6px 0;
  font-size: 28px;
  color: var(--purple);
}

.levelup-card p {
  margin: 0 0 16px 0;
  font-size: 15px;
  color: var(--ink);
  font-family: 'Nunito', sans-serif;
  font-weight: 600;
}

.levelup-card button {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 16px;
  background: var(--green);
  color: #fff;
  border: none;
  padding: 10px 26px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
}

.confetti {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  animation: fall linear forwards;
}

@keyframes fall {
  to { transform: translateY(110vh) rotate(360deg); opacity: 0.4; }
}

footer.hint {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  opacity: 0.55;
  padding: 8px 0 12px 0;
  text-align: center;
  z-index: 2;
}