/* ─── Reset & base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

body {
  position: relative;
  display: flex;
  flex-direction: column;
  background: #ffd96e;
  color: #1a3a52;
}

/* ─── Sky background ─────────────────────────────────────── */
.sky {
  position: fixed;
  inset: 0;
  background: linear-gradient(
    to bottom,
    #ffd96e 0%,
    #ffb978 12%,
    #ffa191 22%,
    #f59ac4 32%,
    #c4b8f0 40%,
    /* horizon */
    #88c5e0 45%,
    #5fa8c9 50%,
    #4a93b8 58%,
    #357fa3 70%,
    #1f5d83 88%,
    #143f5c 100%
  );
  z-index: -2;
}
.sky::after {
  /* horizon glow line */
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 45%;
  height: 2px;
  background: linear-gradient(to right, transparent, rgba(255, 217, 110, 0.6), transparent);
  filter: blur(1px);
}

.clouds {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}
.cloud {
  position: absolute;
  font-size: 48px;
  opacity: 0.85;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.08));
  animation: drift 60s linear infinite;
}
.cloud-a { top: 8%;  left: -10%; animation-duration: 80s; }
.cloud-b { top: 18%; left: -10%; animation-delay: -30s; animation-duration: 100s; font-size: 64px; }
.cloud-c { top: 4%;  left: -10%; animation-delay: -60s; animation-duration: 90s; font-size: 36px; }
@keyframes drift {
  from { transform: translateX(-10vw); }
  to   { transform: translateX(120vw); }
}

/* ─── HUD ────────────────────────────────────────────────── */
.hud {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  z-index: 10;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.92);
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  font-weight: 700;
  font-size: 18px;
  color: #1a3a52;
  min-width: 64px;
  justify-content: center;
}
.pill-icon { font-size: 18px; line-height: 1; }
.pill-num { font-variant-numeric: tabular-nums; }

.streak-pill { color: #d63031; }
.best-pill   { color: #f39c12; }

.level-tabs {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.85);
  border: 3px solid #fff;
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
.level-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  color: #5a7a8a;
  background: transparent;
  border: none;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.12s ease;
}
.level-btn:active { transform: scale(0.94); }
.level-btn--active {
  background: linear-gradient(180deg, #4cd964, #2ecc71);
  color: #fff;
  box-shadow: 0 2px 6px rgba(46, 204, 113, 0.5), inset 0 -2px 0 rgba(0,0,0,0.1);
}

/* ─── Stage layout ──────────────────────────────────────── */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* ─── Problem card ──────────────────────────────────────── */
.problem-card {
  margin: 8px auto 16px;
  padding: 16px 32px;
  background: #fff;
  border: 4px solid #ffd96e;
  border-radius: 28px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18), inset 0 -4px 0 rgba(0,0,0,0.06);
  text-align: center;
  min-width: 260px;
  position: relative;
  z-index: 5;
  animation: cardPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.problem-card::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border: 10px solid transparent;
  border-top-color: #ffd96e;
}
@keyframes cardPop {
  from { transform: scale(0.5) translateY(-10px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.problem-label {
  font-size: 15px;
  font-weight: 600;
  color: #5a7a8a;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}
.problem-math {
  font-size: 42px;
  font-weight: 700;
  color: #1a3a52;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

/* ─── Pond ──────────────────────────────────────────────── */
.pond {
  flex: 1;
  position: relative;
  margin-top: auto;
  min-height: 50vh;
}
.water {
  position: absolute;
  inset: 0;
  overflow: hidden;
  /* subtle shimmer over the body's pond gradient */
  background: linear-gradient(180deg, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0) 50%);
}
.ripple {
  position: absolute;
  border: 2px solid rgba(255,255,255,0.5);
  border-radius: 50%;
  opacity: 0;
  animation: rippleAnim 4s ease-out infinite;
}
.ripple-a { left: 15%; top: 75%; width: 30px; height: 12px; }
.ripple-b { left: 70%; top: 60%; width: 40px; height: 14px; animation-delay: 1.5s; }
.ripple-c { left: 45%; top: 85%; width: 50px; height: 18px; animation-delay: 2.8s; }
@keyframes rippleAnim {
  0%   { transform: scale(0.4); opacity: 0; }
  20%  { opacity: 0.6; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* ─── Number line ───────────────────────────────────────── */
.numberline-wrap {
  position: absolute;
  left: 0; right: 0;
  bottom: 18%;
  padding: 0 8px;
  z-index: 2;
  overflow: hidden;
}

.numberline {
  display: flex;
  align-items: end;
  gap: 6px;
  width: 100%;
  justify-content: center;
}

.lily {
  position: relative;
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 0 4px;
  flex: 1 1 0;
  min-width: 36px;
  max-width: 80px;
  transition: transform 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.lily:active { transform: translateY(2px); }
.lily-shape {
  width: 100%;
  max-width: 70px;
  aspect-ratio: 16 / 9;
  border-radius: 50%;
  background: radial-gradient(ellipse at 35% 35%, #6dbe3a 0%, #4caf50 60%, #2e7d32 100%);
  box-shadow:
    inset 0 -3px 0 rgba(0,0,0,0.18),
    inset 0 3px 6px rgba(255,255,255,0.4),
    0 4px 8px rgba(0,0,0,0.25);
  position: relative;
  animation: lilyBob 3s ease-in-out infinite;
}
.lily-shape::before {
  content: '';
  position: absolute;
  top: 8%; left: 22%;
  width: 30%; height: 22%;
  border-radius: 50%;
  background: rgba(255,255,255,0.55);
  filter: blur(1px);
}
.lily-num {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 0 #1a3a52, 0 2px 4px rgba(0,0,0,0.4);
  font-variant-numeric: tabular-nums;
}
@keyframes lilyBob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}
.lily:nth-child(odd) .lily-shape  { animation-delay: -1.5s; }
.lily:nth-child(3n) .lily-shape   { animation-delay: -0.8s; }

.lily--landing .lily-shape {
  animation: lilyLand 0.4s ease-out;
}
@keyframes lilyLand {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18, 0.7); }
  70%  { transform: scale(0.94, 1.08); }
  100% { transform: scale(1); }
}
.lily--right .lily-shape {
  background: radial-gradient(ellipse at 35% 35%, #ffe066 0%, #f5b800 60%, #c98e00 100%);
  box-shadow: 0 0 0 3px #fff, 0 0 24px 4px rgba(255, 215, 64, 0.7),
              inset 0 -3px 0 rgba(0,0,0,0.18);
}
.lily--wrong .lily-shape {
  background: radial-gradient(ellipse at 35% 35%, #ff8a80 0%, #ef5350 60%, #c62828 100%);
  animation: lilyWrong 0.45s ease-out;
}
@keyframes lilyWrong {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

/* ─── Decade markers (every 10) ─────────────────────────── */
.lily--decade .lily-num {
  color: #ffeb3b;
  text-shadow: 0 1px 0 #1a3a52, 0 0 8px rgba(255, 235, 59, 0.7);
  font-size: 20px;
}
.lily--decade .lily-shape {
  box-shadow:
    inset 0 -3px 0 rgba(0,0,0,0.18),
    inset 0 3px 6px rgba(255,255,255,0.4),
    0 4px 10px rgba(0,0,0,0.3),
    0 0 0 2px rgba(255, 235, 59, 0.5);
}

/* ─── Frog ──────────────────────────────────────────────── */
.frog-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}
.frog {
  position: absolute;
  font-size: 60px;
  line-height: 1;
  top: 0;
  left: 0;
  transform: translate(0, 0);
  filter: drop-shadow(0 6px 6px rgba(0,0,0,0.35));
  will-change: transform;
}

/* ─── Splash ────────────────────────────────────────────── */
.splash {
  position: absolute;
  pointer-events: none;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 30px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0) 70%);
  animation: splashAnim 0.5s ease-out forwards;
}
@keyframes splashAnim {
  0%   { transform: translateX(-50%) scale(0.3); opacity: 1; }
  100% { transform: translateX(-50%) scale(2.2); opacity: 0; }
}

/* ─── Confetti / sparkles ───────────────────────────────── */
.spark {
  position: absolute;
  font-size: 22px;
  pointer-events: none;
  animation: sparkRise 1.1s ease-out forwards;
  z-index: 6;
}
@keyframes sparkRise {
  0%   { transform: translate(0, 0) scale(0.3) rotate(0deg); opacity: 0; }
  20%  { opacity: 1; }
  100% { transform: translate(var(--dx, 0), var(--dy, -160px)) scale(1.1) rotate(var(--rot, 360deg)); opacity: 0; }
}

/* ─── Message ───────────────────────────────────────────── */
.message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  padding: 12px 28px;
  border-radius: 999px;
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
  z-index: 20;
  white-space: nowrap;
  box-shadow: 0 8px 28px rgba(0,0,0,0.25);
}
.message--good {
  background: linear-gradient(180deg, #4cd964, #2ecc71);
  text-shadow: 0 2px 0 rgba(0,0,0,0.15);
}
.message--bad {
  background: linear-gradient(180deg, #ff7878, #e74c3c);
  text-shadow: 0 2px 0 rgba(0,0,0,0.15);
}
.message--show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ─── Responsive ────────────────────────────────────────── */
@media (max-width: 480px) {
  .problem-math { font-size: 36px; }
  .problem-card { padding: 12px 22px; min-width: 200px; }
  .level-btn { font-size: 13px; padding: 6px 10px; }
  .pill { font-size: 16px; padding: 6px 12px; min-width: 52px; }
  .lily { min-width: 24px; padding: 4px 0 2px; }
  .lily-num { font-size: 14px; }
  .frog { font-size: 48px; }
  .message { font-size: 26px; padding: 10px 22px; }
  .numberline { gap: 3px; }
  .numberline-wrap { padding: 0 4px; }
}

@media (max-height: 600px) {
  .problem-card { margin: 4px auto 8px; padding: 10px 24px; }
  .problem-math { font-size: 32px; }
  .numberline-wrap { bottom: 22%; }
}
