:root {
  --cream: #fff8e7;
  --sky: #dff3ff;
  --ink: #4a3426;
  --ink-soft: #8a6e5a;
  --sun: #ffcc33;
  --coral: #ff7a59;
  --leaf: #6cc070;
  --card: #ffffff;
  --shadow: 0 8px 0 rgba(74, 52, 38, .12), 0 14px 30px rgba(74, 52, 38, .12);
  --tap: max(120px, 18vmin);
  font-family: 'Baloo 2', 'Nirmala UI', 'Mangal', system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: linear-gradient(180deg, var(--sky) 0%, var(--cream) 70%);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
img { -webkit-user-drag: none; user-select: none; }
[hidden] { display: none !important; }
.screen { position: fixed; inset: 0; }

/* ---------- parent screen ---------- */
#parent { overflow-y: auto; display: grid; place-items: center; padding: 16px; }
.parent-card {
  width: min(560px, 100%); background: var(--card); border-radius: 32px;
  padding: 24px 24px 20px; box-shadow: var(--shadow); text-align: center; position: relative;
}
.parent-chars { display: flex; justify-content: center; align-items: flex-end; gap: 6px; height: 120px; margin-top: -8px; }
.parent-chars img:first-child { height: 120px; }
.parent-chars img:last-child { height: 76px; }
h1 { margin: 4px 0 0; font-size: 44px; line-height: 1; font-weight: 800; color: var(--coral); letter-spacing: .5px; }
.sub { margin: 4px 0 14px; color: var(--ink-soft); font-size: 17px; }
.opt { border: 0; margin: 0 0 12px; padding: 0; display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.opt legend { width: 100%; font-weight: 700; font-size: 17px; margin-bottom: 4px; padding: 0; }
.opt button {
  flex: 1 1 0; min-width: 0; min-height: 60px; border-radius: 20px; font-size: 22px; font-weight: 700;
  background: #fff3d6; box-shadow: inset 0 -4px 0 rgba(74, 52, 38, .1);
  transition: transform .1s, background .15s;
}
.opt button.on { background: var(--sun); box-shadow: inset 0 -5px 0 rgba(160, 90, 0, .25); }
.opt button:active { transform: scale(.96); }
.start {
  margin-top: 8px; width: 100%; min-height: 84px; border-radius: 28px; font-size: 34px; font-weight: 800;
  background: var(--leaf); color: #fff; box-shadow: inset 0 -7px 0 rgba(0, 0, 0, .15), var(--shadow);
}
.start:active { transform: scale(.98); }
.fine { font-size: 14px; color: var(--ink-soft); margin: 12px 0 0; }
.warn { color: #b45309; }

/* ---------- play area ---------- */
#play { overflow: hidden; }
#stage { position: absolute; inset: 14px 0 0 0; display: grid; place-items: center; padding: 16px 16px 26vh; }
#timebar { position: absolute; top: 0; left: 0; right: 0; height: 8px; background: rgba(74, 52, 38, .08); z-index: 5; }
#timebar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--sun), var(--coral)); border-radius: 0 8px 8px 0; transition: width 1s linear; }

.char { position: absolute; bottom: 0; z-index: 3; pointer-events: auto; filter: drop-shadow(0 6px 8px rgba(74, 52, 38, .2)); }
.didi { left: 1.5vw; height: min(36vh, 300px); transform-origin: bottom center; }
.golu { right: 2vw; height: min(22vh, 180px); transform-origin: bottom center; }
.didi.talking { animation: talk .5s ease-in-out infinite alternate; }
.golu.jump { animation: jump .6s cubic-bezier(.3, 1.6, .5, 1); }
.golu.dance { animation: dance .7s ease-in-out infinite; }
@keyframes talk { from { transform: rotate(-1.2deg) translateY(0); } to { transform: rotate(1.2deg) translateY(-4px); } }
@keyframes jump { 0%, 100% { transform: translateY(0) scale(1); } 40% { transform: translateY(-60px) scale(1.06, .95); } 70% { transform: translateY(0) scale(1.08, .9); } }
@keyframes dance { 0%, 100% { transform: rotate(-8deg) translateY(0); } 50% { transform: rotate(8deg) translateY(-18px); } }

#lock {
  position: absolute; top: 14px; right: 14px; z-index: 10; width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; font-size: 22px; opacity: .45;
  background: conic-gradient(var(--coral) calc(var(--p, 0) * 360deg), rgba(255, 255, 255, .8) 0);
}
#lock span { width: 44px; height: 44px; border-radius: 50%; background: #fff; display: grid; place-items: center; }

#fx { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
.spark { position: absolute; width: 16px; height: 16px; border-radius: 50%; margin: -8px 0 0 -8px; animation: spark .75s ease-out forwards; }
@keyframes spark { to { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; } }

/* shared bits */
.pop-in { animation: popIn .45s cubic-bezier(.3, 1.6, .5, 1) both; }
@keyframes popIn { from { transform: scale(.3); opacity: 0; } }
.wiggle { animation: wiggle .5s ease-in-out; }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-9deg); } 40% { transform: rotate(8deg); } 60% { transform: rotate(-5deg); } 80% { transform: rotate(3deg); } }
.hint { animation: hint 1s ease-in-out infinite; }
@keyframes hint { 50% { transform: scale(1.12); box-shadow: 0 0 0 10px rgba(255, 204, 51, .7), var(--shadow); } }

/* colour placeholder */
.blob {
  display: block; width: 100%; height: 100%; background: var(--c);
  border-radius: 46% 54% 50% 50% / 52% 46% 54% 48%;
  box-shadow: inset -10px -14px 0 rgba(0, 0, 0, .12), inset 10px 10px 0 rgba(255, 255, 255, .35), 0 0 0 3px rgba(74, 52, 38, .16);
}

/* letter placeholder */
.glyph {
  display: grid; place-items: center; width: 100%; height: 100%; border-radius: 26px;
  background: #fff3d6; color: var(--coral); font-weight: 800; line-height: 1;
  font-size: calc(var(--tap, 200px) * .58);
}
.learn-pic .glyph { font-size: min(30vmin, 230px); border-radius: 40px; }

/* learn */
.learn { display: grid; justify-items: center; gap: 12px; }
.learn-pic { width: min(46vmin, 360px); aspect-ratio: 1; animation: breathe 2.4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.06); } }
.learn-words { display: flex; gap: 22px; font-size: clamp(28px, 6vmin, 56px); font-weight: 800; color: var(--ink); line-height: 1; }

/* find it */
.find-grid { display: grid; gap: clamp(16px, 4vmin, 40px); grid-template-columns: repeat(var(--cols, 2), var(--tap)); }
.find-grid.n3 { --cols: 3; }
.find-grid.n4 { --cols: 4; }
.find-grid.n5 { --cols: 5; }
.find-grid { --tap: clamp(120px, 24vmin, 220px); }
.find-grid.n4, .find-grid.n5 { --tap: clamp(120px, 19vmin, 190px); }
.choice {
  width: var(--tap); height: var(--tap); padding: 14px; border-radius: 34px; background: var(--card);
  box-shadow: var(--shadow); transition: transform .12s;
}
.choice:active { transform: scale(.94); }
.choice.yay { animation: yay .7s cubic-bezier(.3, 1.6, .5, 1); box-shadow: 0 0 0 8px var(--sun), var(--shadow); }
@keyframes yay { 40% { transform: scale(1.2) rotate(-4deg); } }

/* pop it + balloons */
.pop-field { position: absolute; inset: 0; overflow: hidden; }
.rise { position: absolute; bottom: -230px; }
.bubble {
  width: clamp(120px, 17vmin, 170px); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, rgba(255, 255, 255, .95) 0 12%, transparent 13%),
              radial-gradient(circle at 50% 50%, var(--c) 0 62%, color-mix(in srgb, var(--c) 70%, #000) 100%);
  box-shadow: 0 6px 16px rgba(74, 52, 38, .18), inset 0 0 0 3px rgba(255, 255, 255, .5), 0 0 0 2px rgba(74, 52, 38, .14);
  animation: sway 2.6s ease-in-out infinite;
}
.bubble.wiggle { animation: wiggle .5s ease-in-out; }
.bubble.hint { animation: hint 1s ease-in-out infinite; }
.gone { animation: burstOut .2s ease-out forwards !important; }
@keyframes burstOut { to { transform: scale(1.5); opacity: 0; } }
@keyframes sway { 50% { transform: translateX(18px); } }
.pop-progress {
  position: absolute; top: 22px; left: 50%; transform: translateX(-50%); z-index: 4;
  display: flex; gap: 10px; padding: 10px 14px; background: rgba(255, 255, 255, .85); border-radius: 999px; box-shadow: var(--shadow);
}
.pop-progress i { width: 34px; height: 34px; border-radius: 50%; border: 4px dashed var(--c); box-shadow: 0 0 0 2px rgba(74, 52, 38, .25); }
.pop-progress i.on { background: var(--c); border-style: solid; animation: popIn .35s cubic-bezier(.3, 1.6, .5, 1); }

.balloon {
  position: relative; width: clamp(120px, 16vmin, 160px); aspect-ratio: .82;
  border-radius: 50% 50% 48% 48% / 56% 56% 44% 44%;
  background: radial-gradient(circle at 30% 26%, rgba(255, 255, 255, .85) 0 9%, transparent 10%), var(--c);
  box-shadow: inset -12px -14px 0 rgba(0, 0, 0, .12);
  animation: sway 3s ease-in-out infinite;
}
.balloon::after {
  content: ''; position: absolute; left: 50%; top: 100%; width: 2px; height: 80px; background: rgba(74, 52, 38, .35);
  transform: translateX(-50%);
}

/* reward + bye */
.reward, .bye { display: grid; justify-items: center; gap: 16px; }
.sticker { font-size: 64px; line-height: 1; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .15)); }
.sticker.big { font-size: min(40vmin, 260px); animation: popIn .6s cubic-bezier(.3, 1.6, .5, 1) both, spinIn 1.4s ease-out; }
@keyframes spinIn { from { rotate: -30deg; } }
.sun { font-size: min(22vmin, 150px); line-height: 1; }
.sticker-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; max-width: 80vw; }

/* phone / small screens */
@media (max-width: 600px) {
  .didi { height: 22vh; }
  .golu { height: 13vh; }
  #stage { padding-bottom: 20vh; }
  .find-grid.n4, .find-grid.n5 { --cols: 2; }
  .find-grid.n3 { --cols: 2; }
  .find-grid.n3 .choice:last-child { grid-column: 1 / -1; justify-self: center; }
  .find-grid.n5 .choice:last-child { grid-column: 1 / -1; justify-self: center; }
  .find-grid, .find-grid.n4, .find-grid.n5 { --tap: clamp(120px, 38vw, 170px); }
}
@media (prefers-reduced-motion: reduce) {
  .didi.talking, .golu.dance, .learn-pic, .bubble, .balloon { animation: none; }
}

/* ?debug=1 only: key of the clip playing now */
#debug-key { position: fixed; right: 6px; bottom: 4px; z-index: 99; pointer-events: none; font: 600 12px/1.2 ui-monospace, Consolas, monospace;
  color: #fff; background: rgba(40, 30, 20, .7); padding: 2px 6px; border-radius: 6px; }
#debug-key:empty { display: none; }
