* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "Comic Sans MS", "Chalkboard SE", "Segoe UI", sans-serif;
  min-height: 100vh;
  background: linear-gradient(160deg, #7bd5f5 0%, #a78bfa 50%, #f9a8d4 100%);
  overflow-x: hidden;
  user-select: none;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 24px 16px;
}
.screen.active { display: flex; }

/* ---------- Chapter picker ---------- */
.game-title {
  font-size: clamp(2rem, 6vw, 3.5rem);
  color: #fff;
  text-shadow: 3px 3px 0 #7c3aed;
  margin-top: 24px;
  animation: float 2.5s ease-in-out infinite;
}
.subtitle {
  color: #fff;
  font-size: 1.3rem;
  margin: 12px 0 32px;
  text-shadow: 1px 1px 0 rgba(0,0,0,.2);
}
.chapter-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  width: 100%;
  max-width: 720px;
}
.chapter-btn {
  border: none;
  border-radius: 24px;
  padding: 24px;
  font-family: inherit;
  font-size: 1.25rem;
  font-weight: bold;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0,0,0,.25);
  transition: transform .15s, box-shadow .15s;
  display: flex;
  align-items: center;
  gap: 14px;
}
.chapter-btn .chap-icon { font-size: 2.4rem; }
.chapter-btn:hover { transform: translateY(-4px) scale(1.03); }
.chapter-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.chapter-btn:nth-child(4n+1) { background: #f97316; }
.chapter-btn:nth-child(4n+2) { background: #10b981; }
.chapter-btn:nth-child(4n+3) { background: #3b82f6; }
.chapter-btn:nth-child(4n+4) { background: #ec4899; }

/* ---------- Mode toggle ---------- */
.mode-toggle {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
}
.mode-btn {
  border: 4px solid transparent;
  border-radius: 20px;
  background: rgba(255,255,255,.6);
  color: #4c1d95;
  font-family: inherit;
  font-size: 1.15rem;
  font-weight: bold;
  padding: 14px 22px;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0,0,0,.2);
  transition: transform .15s;
}
.mode-btn:hover { transform: scale(1.05); }
.mode-btn.selected {
  background: #fff;
  border-color: #fde047;
  transform: scale(1.08);
}

/* ---------- Lesson flow ---------- */
.stage-badge {
  background: rgba(255,255,255,.85);
  color: #7c3aed;
  font-weight: bold;
  font-size: 1.05rem;
  padding: 10px 16px;
  border-radius: 16px;
  box-shadow: 0 4px 0 rgba(0,0,0,.2);
}
.read-sentence {
  color: #fff;
  font-size: clamp(1.1rem, 4vw, 1.5rem);
  font-weight: bold;
  text-shadow: 2px 2px 0 rgba(0,0,0,.25);
  background: rgba(0,0,0,.15);
  padding: 12px 20px;
  border-radius: 16px;
  margin: 0 12px 20px;
  max-width: 560px;
  text-align: center;
  min-height: 1.4em;
}
.read-sentence:empty { display: none; }
.chap-stars {
  margin-left: auto;
  font-size: 1.05rem;
  letter-spacing: 2px;
  white-space: nowrap;
}

/* ---------- Reading screen ---------- */
.read-word {
  font-size: clamp(2.5rem, 12vw, 5rem);
  font-weight: bold;
  color: #fff;
  text-shadow: 3px 3px 0 #7c3aed;
  letter-spacing: .1em;
  margin: 12px 0 24px;
  animation: pop .5s cubic-bezier(.2, 2, .4, 1);
}
.read-word .speaking-letter {
  display: inline-block;
  color: #fde047;
  transform: scale(1.3);
  transition: transform .15s;
}
.read-controls {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
}
.speak-btn {
  border: none;
  border-radius: 22px;
  background: #f97316;
  color: #fff;
  font-family: inherit;
  font-size: 1.4rem;
  font-weight: bold;
  padding: 18px 28px;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0,0,0,.25);
  transition: transform .15s;
}
.speak-btn.alt { background: #3b82f6; }
.speak-btn:hover { transform: scale(1.07); }
.speak-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.speak-btn.speaking { animation: pulse .6s ease-in-out infinite; }
.read-nav {
  display: flex;
  gap: 18px;
  margin-top: 36px;
}
.nav-btn {
  border: none;
  border-radius: 18px;
  background: #fff;
  color: #7c3aed;
  font-family: inherit;
  font-size: 1.2rem;
  font-weight: bold;
  padding: 14px 24px;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0,0,0,.2);
}
.nav-btn:disabled { opacity: .4; cursor: default; }
.nav-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: none; }

/* ---------- Test screen ---------- */
.test-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 720px;
}
.small-btn {
  border: none;
  background: #fff;
  color: #7c3aed;
  font-family: inherit;
  font-weight: bold;
  font-size: 1rem;
  padding: 10px 16px;
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,.2);
}
.small-btn:active { transform: translateY(2px); box-shadow: none; }

.progress-stars { font-size: 1.3rem; letter-spacing: 4px; }
.score-badge {
  background: #fde047;
  color: #92400e;
  font-weight: bold;
  font-size: 1.1rem;
  padding: 10px 16px;
  border-radius: 16px;
  box-shadow: 0 4px 0 rgba(0,0,0,.2);
}

.hint-emoji {
  font-size: clamp(4rem, 14vw, 7rem);
  margin: 32px 0 8px;
  animation: float 2s ease-in-out infinite;
}

/* Word with slots */
.word-slots {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin: 20px 0 8px;
}
.slot {
  width: clamp(44px, 10vw, 64px);
  height: clamp(54px, 12vw, 76px);
  border-radius: 14px;
  background: #fff;
  color: #1e293b;
  font-size: clamp(1.6rem, 6vw, 2.6rem);
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 5px 0 rgba(0,0,0,.2);
}
.slot.missing {
  background: #fef9c3;
  border: 3px dashed #f59e0b;
  color: transparent;
  animation: pulse 1.2s ease-in-out infinite;
}
.slot.filled {
  background: #86efac;
  color: #14532d;
  animation: pop .45s cubic-bezier(.2, 2.2, .4, 1);
}

.cheer-msg {
  height: 2.2rem;
  font-size: 1.5rem;
  font-weight: bold;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0,0,0,.25);
}
.cheer-msg.show { animation: pop .4s ease; }

/* Letter choice buttons */
.letter-choices {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 28px;
}
.letter-btn {
  width: clamp(60px, 15vw, 84px);
  height: clamp(60px, 15vw, 84px);
  border: none;
  border-radius: 20px;
  background: #fff;
  color: #7c3aed;
  font-family: inherit;
  font-size: clamp(1.8rem, 6vw, 2.6rem);
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0,0,0,.25);
  transition: transform .15s;
  animation: bounceIn .5s backwards;
}
.letter-btn:nth-child(1) { animation-delay: .05s; }
.letter-btn:nth-child(2) { animation-delay: .15s; }
.letter-btn:nth-child(3) { animation-delay: .25s; }
.letter-btn:nth-child(4) { animation-delay: .35s; }
.letter-btn:hover { transform: scale(1.1) rotate(-3deg); }
.letter-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.letter-btn.wrong {
  background: #fca5a5;
  color: #7f1d1d;
  animation: shake .45s;
}
.letter-btn.correct-fly {
  background: #86efac;
  color: #14532d;
  animation: flyUp .5s forwards;
}
.letter-btn.used {
  visibility: hidden;
  pointer-events: none;
}

/* ---------- Slice mode ---------- */
#slice-screen { padding-bottom: 12px; }
.slice-top {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 14px 0 4px;
}
.slice-hint { font-size: clamp(2.2rem, 8vw, 3.4rem); animation: float 2s ease-in-out infinite; }
.slice-word-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}
.slice-word-row .slot {
  width: clamp(34px, 7vw, 48px);
  height: clamp(42px, 8vw, 58px);
  font-size: clamp(1.3rem, 4.5vw, 2rem);
}
.slice-word-row .slot.done {
  background: #86efac;
  color: #14532d;
  animation: pop .4s cubic-bezier(.2, 2, .4, 1);
}
.slice-word-row .slot.next {
  border: 3px dashed #f59e0b;
  background: #fef9c3;
  animation: pulse 1.1s ease-in-out infinite;
}
.slice-option {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,.85);
  color: #7c3aed;
  font-weight: bold;
  font-size: 1rem;
  padding: 8px 16px;
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(0,0,0,.2);
  cursor: pointer;
  margin-top: 8px;
  user-select: none;
}
.slice-option input {
  width: 20px;
  height: 20px;
  accent-color: #7c3aed;
  cursor: pointer;
}
.slice-area {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 900px;
  min-height: 320px;
  margin-top: 10px;
  border-radius: 24px;
  background: rgba(255,255,255,.18);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.35);
  touch-action: none;
  overflow: hidden;
  cursor: crosshair;
}
.slice-letter {
  position: absolute;
  width: clamp(46px, 9vw, 62px);
  height: clamp(46px, 9vw, 62px);
  border-radius: 50%;
  background: #fff;
  color: #7c3aed;
  font-weight: bold;
  font-size: clamp(1.3rem, 4.5vw, 1.9rem);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 0 rgba(0,0,0,.2);
  user-select: none;
  animation: floaty 3.2s ease-in-out infinite alternate;
}
.slice-letter.sliced {
  animation: sliceOut .55s forwards;
  pointer-events: none;
}
.slice-letter.bad {
  background: #fca5a5;
  color: #7f1d1d;
  animation: shake .4s;
}
.trail-dot {
  position: fixed;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, #fde047 60%, transparent 100%);
  pointer-events: none;
  z-index: 60;
  animation: trailFade .35s forwards;
}
@keyframes floaty {
  0% { transform: translate(0, 0) rotate(-4deg); }
  100% { transform: translate(6px, 14px) rotate(4deg); }
}
@keyframes sliceOut {
  30% { transform: scale(1.25) rotate(20deg); }
  100% { transform: scale(0) rotate(220deg) translateY(60px); opacity: 0; }
}
@keyframes trailFade {
  to { transform: scale(.2); opacity: 0; }
}

/* ---------- Snake mode ---------- */
.snake-area {
  position: relative;
  width: 100%;
  max-width: 620px;
  aspect-ratio: 15 / 11;
  margin-top: 10px;
  border-radius: 20px;
  background: rgba(0,0,0,.22);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.35);
  touch-action: none;
  overflow: hidden;
}
.snake-seg {
  position: absolute;
  background: #4ade80;
  border-radius: 30%;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.25);
  transition: left .25s linear, top .25s linear;
}
.snake-seg.head {
  background: #16a34a;
  border-radius: 45%;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .8em;
}
.snake-food {
  position: absolute;
  background: #fff;
  color: #7c3aed;
  border-radius: 50%;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 rgba(0,0,0,.25);
  animation: pulse 1.4s ease-in-out infinite;
}
.snake-food.bad-flash {
  background: #fca5a5;
  color: #7f1d1d;
  animation: shake .4s;
}
.dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.dpad-mid { display: flex; gap: 8px; }
.dpad-btn {
  width: 62px;
  height: 62px;
  border: none;
  border-radius: 18px;
  background: rgba(255,255,255,.9);
  font-size: 1.6rem;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0,0,0,.25);
}
.dpad-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
@media (min-width: 900px) and (hover: hover) {
  .dpad { display: none; } /* desktop has arrow keys */
}

/* ---------- Jumping monkey mode ---------- */
.monkey-area {
  position: relative;
  width: 100%;
  max-width: 700px;
  aspect-ratio: 16 / 9;
  margin-top: 10px;
  border-radius: 20px;
  background: linear-gradient(180deg, #38bdf8 0%, #7dd3fc 55%, #bae6fd 100%);
  overflow: hidden;
  touch-action: none;
  cursor: pointer;
}
.monkey-clouds {
  position: absolute;
  top: 8%;
  left: 0;
  width: 200%;
  font-size: 2rem;
  display: flex;
  justify-content: space-around;
  animation: cloudsDrift 14s linear infinite;
  opacity: .9;
  pointer-events: none;
}
.monkey-ground {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 13%;
  background: repeating-linear-gradient(90deg, #22c55e 0 40px, #16a34a 40px 80px);
  background-size: 80px 100%;
  animation: groundScroll .7s linear infinite;
  border-top: 4px solid #15803d;
}
.monkey-player {
  position: absolute;
  left: 12%;
  bottom: 13%;
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  z-index: 3;
  transition: none;
  filter: drop-shadow(0 4px 2px rgba(0,0,0,.25));
}
.monkey-fruit {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}
.monkey-fruit .fruit-emoji { font-size: clamp(1.8rem, 6vw, 2.6rem); }
.monkey-fruit .fruit-letter {
  margin-top: -6px;
  background: #fff;
  color: #7c3aed;
  font-weight: bold;
  font-size: clamp(1rem, 3.5vw, 1.3rem);
  width: 1.9em;
  height: 1.9em;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 rgba(0,0,0,.25);
}
.monkey-fruit.got { animation: sliceOut .5s forwards; }
.monkey-fruit.bad-flash .fruit-letter {
  background: #fca5a5;
  color: #7f1d1d;
  animation: shake .4s;
}
@keyframes cloudsDrift {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
@keyframes groundScroll {
  from { background-position-x: 0; }
  to { background-position-x: -80px; }
}

/* ---------- Result screen ---------- */
.result-card {
  background: #fff;
  border-radius: 32px;
  padding: 40px 32px;
  margin: auto;
  text-align: center;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 10px 0 rgba(0,0,0,.2);
  animation: pop .5s cubic-bezier(.2, 2, .4, 1);
}
.result-emoji { font-size: 5rem; animation: float 2s ease-in-out infinite; }
.result-card h2 { color: #7c3aed; font-size: 2rem; margin: 12px 0; }
.result-card p { color: #475569; font-size: 1.2rem; margin-bottom: 8px; }
.result-stars { font-size: 2.2rem; margin: 12px 0 24px; }
.big-btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 18px;
  background: #10b981;
  color: #fff;
  font-family: inherit;
  font-size: 1.3rem;
  font-weight: bold;
  padding: 14px;
  margin-top: 12px;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0,0,0,.2);
}
.big-btn.alt { background: #3b82f6; }
.big-btn:active { transform: translateY(3px); box-shadow: none; }

/* ---------- Confetti ---------- */
#confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}
.confetti {
  position: absolute;
  top: -20px;
  font-size: 1.5rem;
  animation: confettiFall linear forwards;
}

/* ---------- Animations ---------- */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}
@keyframes pop {
  0% { transform: scale(0); }
  70% { transform: scale(1.25); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px) rotate(-4deg); }
  40% { transform: translateX(8px) rotate(4deg); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}
@keyframes bounceIn {
  0% { transform: scale(0) rotate(180deg); opacity: 0; }
  70% { transform: scale(1.15) rotate(-8deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes flyUp {
  to { transform: translateY(-120px) scale(.4); opacity: 0; }
}
@keyframes confettiFall {
  to { transform: translateY(110vh) rotate(720deg); }
}
