/* =========================================================
   Make Ten Adventure — Kid-friendly playful math
   ========================================================= */

:root {
  --bg-cream: #FFF6E0;
  --bg-sky: #E8F5FF;
  --sun: #FFD93D;
  --sun-deep: #F4B40B;
  --grass: #6BCB77;
  --grass-deep: #3FA85A;
  --coral: #FF6B9D;
  --coral-deep: #E04B7E;
  --sky: #4ECDC4;
  --sky-deep: #2BA8A0;
  --berry: #B084EE;
  --berry-deep: #8059D9;
  --ink: #2D3142;
  --ink-soft: #5C6378;
  --line: #E5D7B0;
  --paper: #FFFDF7;

  --font-display: "Lilita One", "Bubblegum Sans", "Fredoka", system-ui, sans-serif;
  --font-body: "Fredoka", "Baloo 2", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg-cream);
  overflow: hidden;
  height: 100%;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#root { height: 100vh; width: 100vw; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

/* =========================================================
   App shell — background sky with floating clouds
   ========================================================= */
.app {
  height: 100%;
  width: 100%;
  position: relative;
  background:
    radial-gradient(circle at 20% 10%, #FFE9A8 0%, transparent 40%),
    radial-gradient(circle at 80% 20%, #C8EBFF 0%, transparent 45%),
    linear-gradient(180deg, #FFF6E0 0%, #FFE9C5 100%);
  overflow: hidden;
}

.cloud {
  position: absolute;
  font-size: 60px;
  opacity: 0.55;
  animation: drift 25s linear infinite;
  pointer-events: none;
}
.cloud.c1 { top: 6%; left: -10%; animation-duration: 45s; }
.cloud.c2 { top: 18%; left: -10%; animation-duration: 60s; animation-delay: -15s; font-size: 48px; }
.cloud.c3 { top: 70%; left: -10%; animation-duration: 55s; animation-delay: -30s; font-size: 70px; opacity: 0.4;}

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

/* hill */
.hill {
  position: absolute;
  bottom: 0;
  left: -5%;
  right: -5%;
  height: 18%;
  background: radial-gradient(ellipse at center top, var(--grass) 0%, var(--grass-deep) 100%);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  z-index: 0;
}
.hill::before, .hill::after {
  content: '🌼'; position: absolute; bottom: 18%; font-size: 28px;
}
.hill::before { left: 12%; }
.hill::after { right: 15%; transform: rotate(8deg); }

/* =========================================================
   Header
   ========================================================= */
.header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
}

.stars-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: 3px solid var(--sun-deep);
  border-bottom-width: 5px;
  padding: 8px 18px 8px 14px;
  border-radius: 999px;
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--sun-deep);
  box-shadow: 0 4px 0 rgba(0,0,0,0.06);
}
.stars-pill .star { font-size: 26px; filter: drop-shadow(0 2px 0 var(--sun-deep)); }
.stars-pill .num { min-width: 24px; text-align: center; }

.icon-buttons { display: flex; gap: 10px; }
.icon-btn {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  background: white;
  border: 3px solid var(--ink);
  border-bottom-width: 6px;
  font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  transition: transform 80ms ease;
}
.icon-btn:hover { transform: translateY(-2px); }
.icon-btn:active { transform: translateY(2px); border-bottom-width: 3px; }
.icon-btn.on { background: var(--sun); }
.icon-btn.lang { font-size: 16px; line-height: 1.05; padding: 0 4px; }

/* =========================================================
   Welcome
   ========================================================= */
.welcome {
  position: relative;
  z-index: 5;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 40px;
}
.welcome-title {
  font-family: var(--font-display);
  font-size: clamp(64px, 9vw, 130px);
  line-height: 0.95;
  color: var(--coral);
  text-shadow:
    -2px -2px 0 white, 2px -2px 0 white, -2px 2px 0 white, 2px 2px 0 white,
    0 8px 0 var(--coral-deep);
  margin: 0 0 8px;
  transform: rotate(-2deg);
}
.welcome-title .word2 { color: var(--sky); text-shadow: -2px -2px 0 white, 2px -2px 0 white, -2px 2px 0 white, 2px 2px 0 white, 0 8px 0 var(--sky-deep); }
.welcome-sub {
  font-family: var(--font-display);
  font-size: clamp(28px, 3.2vw, 48px);
  color: var(--ink);
  margin: 0 0 50px;
  letter-spacing: 0.5px;
}
.welcome-sub .zh { color: var(--berry-deep); }

.welcome-animals {
  display: flex; gap: 20px; margin-bottom: 36px;
}
.welcome-animals span {
  font-size: clamp(60px, 8vw, 110px);
  display: inline-block;
  animation: bounce-y 1.2s ease-in-out infinite;
}
.welcome-animals span:nth-child(2) { animation-delay: 0.15s; }
.welcome-animals span:nth-child(3) { animation-delay: 0.30s; }
.welcome-animals span:nth-child(4) { animation-delay: 0.45s; }
.welcome-animals span:nth-child(5) { animation-delay: 0.60s; }

@keyframes bounce-y {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-20px) rotate(3deg); }
}

.big-btn {
  font-family: var(--font-display);
  font-size: clamp(32px, 4vw, 52px);
  padding: 18px 52px;
  background: var(--sun);
  color: var(--ink);
  border: 4px solid var(--ink);
  border-bottom-width: 10px;
  border-radius: 28px;
  letter-spacing: 1px;
  transition: transform 80ms ease, border-bottom-width 80ms ease;
  box-shadow: 0 6px 0 rgba(0,0,0,0.08);
}
.big-btn:hover { transform: translateY(-2px); }
.big-btn:active { transform: translateY(4px); border-bottom-width: 4px; }
.big-btn.coral { background: var(--coral); color: white; }
.big-btn.sky { background: var(--sky); color: white; }
.big-btn.grass { background: var(--grass); color: white; }

/* =========================================================
   Problem screen layout
   ========================================================= */
.scene {
  position: relative;
  z-index: 5;
  height: calc(100% - 88px);
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 18px;
  padding: 0 40px 40px;
  align-items: center;
}

/* Equation strip */
.equation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  font-family: var(--font-display);
  font-size: clamp(60px, 8vw, 110px);
  color: var(--ink);
  line-height: 1;
  filter: drop-shadow(0 6px 0 rgba(0,0,0,0.08));
}
.eq-num {
  display: inline-flex;
  min-width: 1.4em;
  justify-content: center;
  padding: 4px 18px;
  border-radius: 20px;
  background: white;
  border: 4px solid var(--ink);
  border-bottom-width: 8px;
  transition: all 350ms cubic-bezier(.34, 1.56, .64, 1);
}
.eq-num.left { color: var(--coral-deep); background: #FFE3EE; border-color: var(--coral-deep); }
.eq-num.right { color: var(--sky-deep); background: #DDF7F5; border-color: var(--sky-deep); }
.eq-num.left.zero, .eq-num.right.zero { opacity: 0.35; }
.eq-num.ten { color: white; background: var(--sun-deep); border-color: var(--sun-deep); animation: pop-in 400ms cubic-bezier(.34, 1.56, .64, 1); }
.eq-op {
  font-size: 0.9em;
  color: var(--ink-soft);
}
.eq-answer {
  color: white;
  background: var(--grass);
  border-color: var(--grass-deep);
  animation: pop-in 500ms cubic-bezier(.34, 1.56, .64, 1);
}
.eq-answer.hidden {
  color: var(--ink-soft);
  background: white;
  border-color: var(--line);
}
.eq-answer.hidden::after { content: "?"; }

@keyframes pop-in {
  0% { transform: scale(0.3) rotate(-10deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(5deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Ten-frame stage */
.stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(24px, 4vw, 80px);
  position: relative;
}

.group-label {
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(28px, 3vw, 40px);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}
.group-label.left { color: var(--coral-deep); }
.group-label.right { color: var(--sky-deep); }
.group-label.full { color: var(--sun-deep); animation: wiggle 600ms ease-in-out infinite; }

@keyframes wiggle {
  0%, 100% { transform: rotate(-3deg) scale(1); }
  50% { transform: rotate(3deg) scale(1.08); }
}

.frame-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Ten-frame */
.ten-frame {
  --cell: clamp(48px, 5.2vw, 78px);
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, var(--cell));
  grid-template-rows: repeat(2, var(--cell));
  background: white;
  border: 4px solid var(--ink);
  border-radius: 18px;
  padding: 6px;
  gap: 4px;
  box-shadow: 0 8px 0 rgba(0,0,0,0.08);
  transition: box-shadow 300ms ease, transform 300ms ease;
}
.ten-frame.highlight {
  box-shadow: 0 0 0 6px var(--sun), 0 8px 0 rgba(0,0,0,0.08);
  transform: scale(1.03);
}
.ten-frame.full {
  box-shadow: 0 0 0 6px var(--sun), 0 8px 0 rgba(0,0,0,0.08);
  animation: full-glow 1s ease-in-out infinite;
}
@keyframes full-glow {
  0%, 100% { box-shadow: 0 0 0 6px var(--sun), 0 8px 0 rgba(0,0,0,0.08); }
  50% { box-shadow: 0 0 0 10px var(--sun), 0 0 30px var(--sun-deep), 0 8px 0 rgba(0,0,0,0.08); }
}

.cell {
  border: 2px dashed #D8D2BD;
  border-radius: 10px;
  background: #FBF6E7;
  position: relative;
}
.cell.glow {
  border-style: solid;
  border-color: var(--sun-deep);
  background: #FFF4C8;
  animation: cell-pulse 0.9s ease-in-out infinite;
}
@keyframes cell-pulse {
  0%, 100% { background: #FFF4C8; transform: scale(1); }
  50% { background: var(--sun); transform: scale(1.05); }
}
.cell.filled { background: white; border-style: solid; border-color: #E8DEC5; }

/* Animals — absolutely positioned over the frames for smooth FLIP-style transitions */
.animals-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.animal {
  position: absolute;
  font-size: calc(var(--cell) * 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--cell);
  height: var(--cell);
  transition: transform 750ms cubic-bezier(.34, 1.56, .64, 1), opacity 300ms ease;
  transform-origin: center;
  filter: drop-shadow(0 3px 0 rgba(0,0,0,0.15));
  z-index: 2;
}
.animal.entering {
  animation: animal-pop-in 450ms cubic-bezier(.34, 1.56, .64, 1) both;
}
.animal.hopping {
  animation: hop 750ms cubic-bezier(.4, 0, .2, 1);
  z-index: 5;
}
@keyframes animal-pop-in {
  0% { transform: scale(0) rotate(-20deg); }
  60% { transform: scale(1.25) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}
@keyframes hop {
  0% { translate: 0 0; }
  50% { translate: 0 -80px; }
  100% { translate: 0 0; }
}
.animal.wiggle {
  animation: animal-wiggle 0.6s ease-in-out infinite;
}
@keyframes animal-wiggle {
  0%, 100% { transform: rotate(-6deg) scale(1); }
  50% { transform: rotate(6deg) scale(1.05); }
}

/* Plus sign between frames */
.plus-sign {
  font-family: var(--font-display);
  font-size: clamp(48px, 6vw, 80px);
  color: var(--ink-soft);
  margin-bottom: 16px;
}

/* =========================================================
   Speech bubble narration
   ========================================================= */
.narrator {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 20px;
  padding: 0 20px;
}
.narrator .mascot {
  font-size: clamp(60px, 7vw, 100px);
  animation: mascot-bounce 1.4s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes mascot-bounce {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-8px) rotate(2deg); }
}

.bubble {
  position: relative;
  background: white;
  border: 4px solid var(--ink);
  border-radius: 28px;
  padding: 16px 28px;
  max-width: 700px;
  box-shadow: 0 6px 0 rgba(0,0,0,0.08);
  font-family: var(--font-display);
  text-align: center;
  line-height: 1.15;
  animation: bubble-in 280ms cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes bubble-in {
  from { transform: translateY(10px) scale(0.9); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}
.bubble::after {
  content: '';
  position: absolute;
  left: -18px;
  bottom: 24px;
  width: 22px;
  height: 22px;
  background: white;
  border-left: 4px solid var(--ink);
  border-bottom: 4px solid var(--ink);
  transform: rotate(45deg);
}
.bubble .en {
  font-size: clamp(22px, 2.3vw, 32px);
  color: var(--ink);
  display: block;
  margin-bottom: 4px;
}
.bubble .zh {
  font-size: clamp(20px, 2.1vw, 28px);
  color: var(--berry-deep);
  display: block;
  font-family: var(--font-body);
  font-weight: 600;
}
.bubble .highlight { color: var(--coral); }
.bubble .highlight-sun { color: var(--sun-deep); }
.bubble .highlight-sky { color: var(--sky-deep); }
.bubble .highlight-grass { color: var(--grass-deep); }

/* Controls row */
.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.next-btn {
  font-family: var(--font-display);
  font-size: clamp(24px, 2.6vw, 36px);
  padding: 14px 36px;
  background: var(--coral);
  color: white;
  border: 4px solid var(--coral-deep);
  border-bottom-width: 10px;
  border-radius: 22px;
  letter-spacing: 1px;
  transition: transform 80ms ease, border-bottom-width 80ms ease;
  display: inline-flex; align-items: center; gap: 10px;
}
.next-btn:hover { transform: translateY(-2px); }
.next-btn:active { transform: translateY(4px); border-bottom-width: 4px; }
.next-btn.replay {
  background: white; color: var(--ink); border-color: var(--ink);
}

/* =========================================================
   Quiz
   ========================================================= */
.quiz-question {
  font-family: var(--font-display);
  font-size: clamp(32px, 3.6vw, 56px);
  color: var(--ink);
  text-align: center;
  margin: 8px 0;
}
.quiz-question .zh { display: block; font-size: 0.7em; color: var(--berry-deep); font-family: var(--font-body); font-weight: 600;}

.quiz-options {
  display: flex;
  gap: 22px;
  justify-content: center;
}
.quiz-opt {
  font-family: var(--font-display);
  font-size: clamp(48px, 6vw, 90px);
  width: clamp(120px, 14vw, 180px);
  height: clamp(120px, 14vw, 180px);
  border-radius: 28px;
  background: white;
  border: 4px solid var(--ink);
  border-bottom-width: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 100ms ease, background 200ms ease;
}
.quiz-opt:nth-child(1) { background: #FFE3EE; }
.quiz-opt:nth-child(2) { background: #FFF4C8; }
.quiz-opt:nth-child(3) { background: #DDF7F5; }
.quiz-opt:hover { transform: translateY(-3px) rotate(-2deg); }
.quiz-opt:active { transform: translateY(3px); border-bottom-width: 4px; }
.quiz-opt.correct { background: var(--grass) !important; color: white; animation: correct-pop 700ms cubic-bezier(.34, 1.56, .64, 1); border-color: var(--grass-deep); }
.quiz-opt.wrong { animation: shake 0.5s; background: #FFC9C9 !important; }
.quiz-opt.disabled { pointer-events: none; opacity: 0.5; }

@keyframes correct-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.25) rotate(8deg); }
  100% { transform: scale(1.1) rotate(0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-10px) rotate(-3deg); }
  40%, 80% { transform: translateX(10px) rotate(3deg); }
}

/* =========================================================
   Confetti
   ========================================================= */
.confetti-layer {
  position: fixed; inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 100;
}
.confetti-piece {
  position: absolute;
  top: -20px;
  font-size: 28px;
  animation: confetti-fall 2.5s linear forwards;
}
@keyframes confetti-fall {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 1; }
}

/* Star fly-up after correct */
.star-fly {
  position: fixed;
  font-size: 80px;
  z-index: 90;
  pointer-events: none;
  animation: star-fly 1.4s cubic-bezier(.34, 1.56, .64, 1) forwards;
}
@keyframes star-fly {
  0% { transform: scale(0) rotate(-30deg); opacity: 0; }
  30% { transform: scale(1.5) rotate(20deg); opacity: 1; }
  60% { transform: scale(1.2) rotate(0); opacity: 1; }
  100% { transform: scale(0.4) translate(50vw, -50vh) rotate(180deg); opacity: 0; }
}

/* =========================================================
   Complete screen
   ========================================================= */
.complete-overlay {
  position: fixed; inset: 0;
  background: rgba(255, 246, 224, 0.95);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  z-index: 200;
  animation: bubble-in 400ms ease;
  text-align: center;
  padding: 40px;
}
.complete-title {
  font-family: var(--font-display);
  font-size: clamp(60px, 8vw, 110px);
  color: var(--coral);
  text-shadow: -2px -2px 0 white, 2px -2px 0 white, -2px 2px 0 white, 2px 2px 0 white, 0 8px 0 var(--coral-deep);
  margin: 0;
}
.complete-sub {
  font-family: var(--font-display);
  font-size: clamp(28px, 3vw, 44px);
  margin: 16px 0 32px;
  color: var(--ink);
}
.complete-stars { font-size: 80px; margin: 20px 0 40px; letter-spacing: 6px; }
.complete-stars span { display: inline-block; animation: star-pop 600ms cubic-bezier(.34, 1.56, .64, 1) both; }

@keyframes star-pop {
  0% { transform: scale(0) rotate(-30deg); }
  60% { transform: scale(1.3) rotate(10deg); }
  100% { transform: scale(1) rotate(0); }
}

/* Joke ticker */
.joke {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink-soft);
  opacity: 0.7;
  z-index: 3;
  white-space: nowrap;
}

/* Progress dots */
.progress {
  display: flex; gap: 8px; align-items: center;
}
.dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: white;
  border: 3px solid var(--ink-soft);
}
.dot.done { background: var(--grass); border-color: var(--grass-deep); }
.dot.current { background: var(--sun); border-color: var(--sun-deep); transform: scale(1.3); }
