* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
  overscroll-behavior: none;
  font-family: "Comic Sans MS", "Baloo 2", system-ui, sans-serif;
  background: linear-gradient(180deg, #fff6ec, #ffe9d6);
  color: #4a3728;
}
.hidden { display: none !important; }
#app { height: 100dvh; display: flex; flex-direction: column; }
#topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: rgba(255,255,255,.65); backdrop-filter: blur(6px);
}
#app-title { font-size: clamp(20px, 4vw, 32px); margin: 0; flex: 1; text-align: center; }
.toggles { display: flex; gap: 8px; }
.toggle {
  border: 3px solid #ffb26e; background: #fff; border-radius: 999px;
  font-size: clamp(13px, 2.4vw, 17px); padding: 8px 12px; cursor: pointer; font-weight: 700;
}
.toggle:active { transform: scale(.95); }
#parent-gate {
  position: relative; width: 52px; height: 52px; border: none; border-radius: 50%;
  background: #fff; cursor: pointer; flex: 0 0 auto; padding: 0;
}
.gate-ring { width: 52px; height: 52px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: #ffe0bd; stroke-width: 5; }
.ring-fg { fill: none; stroke: #ff8c42; stroke-width: 5; stroke-linecap: round;
  stroke-dasharray: 119.4; stroke-dashoffset: 119.4; }
.gate-icon { position: absolute; inset: 0; display: grid; place-items: center; font-size: 22px; }
.hint { text-align: center; font-size: clamp(16px, 3vw, 22px); margin: 14px 8px 4px; }
.menu {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px; padding: 18px; overflow-y: auto;
}
.card {
  border: none; border-radius: 28px; min-height: 170px; cursor: pointer;
  font-size: clamp(19px, 3.4vw, 26px); font-weight: 800; color: #4a3728;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  box-shadow: 0 6px 0 rgba(0,0,0,.08);
}
.card:active { transform: scale(.96); }
.card .emoji { font-size: 56px; }
#game-screen { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#game-title { text-align: center; margin: 10px 0 4px; font-size: clamp(20px, 4vw, 30px); }
#game-root { flex: 1; position: relative; overflow: hidden; padding: 10px; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; }

/* Farm */
.farm-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; height: 100%; }
.animal { border: none; background: #fff; border-radius: 24px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: clamp(15px, 2.6vw, 21px); font-weight: 700; }
.animal svg { width: 62%; max-height: 62%; }
.animal.bounce { animation: bounce .6s ease; }
@keyframes bounce { 0%{transform:scale(1)} 30%{transform:scale(1.15) translateY(-10px)} 60%{transform:scale(.95)} 100%{transform:scale(1)} }

/* Shapes */
.shapes-top, .shapes-holes { display: flex; justify-content: space-around; align-items: center; min-height: 38%; flex-wrap: wrap; gap: 8px; }
.shape, .hole { width: clamp(64px, 15vw, 110px); height: clamp(64px, 15vw, 110px); }
.shape { cursor: pointer; touch-action: none; }
.shape.flying { transition: transform .6s ease, opacity .6s ease; }
.hole { opacity: .35; }
.hole.filled { opacity: 1; }

/* Tracing */
.trace-wrap { display: flex; flex-direction: column; align-items: center; height: 100%; }
.trace-stage { position: relative; width: min(78vw, 420px); height: min(58vh, 420px); }
.trace-letter { position: absolute; inset: 0; display: grid; place-items: center; font-size: min(46vh, 320px); font-weight: 900; color: #ffd9a0; line-height: 1; }
#trace-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.trace-nav { display: flex; gap: 16px; margin-top: 10px; }
.trace-nav button, .big-btn { border: none; border-radius: 999px; background: #ffb26e; font-size: 24px; padding: 10px 22px; cursor: pointer; font-weight: 800; }
.checkpoint { position: absolute; width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 4px solid #ff8c42; transform: translate(-50%,-50%); pointer-events: none; }
.checkpoint.hit { background: #95d5b2; border-color: #2d9d63; }

/* Bubbles */
.bubble { position: absolute; border-radius: 50%; cursor: pointer; border: 3px solid rgba(255,255,255,.8);
  background: radial-gradient(circle at 32% 30%, rgba(255,255,255,.95), rgba(255,255,255,.15) 55%), var(--c); animation: rise linear forwards; }
@keyframes rise { from { transform: translateY(20px); } to { transform: translateY(-72vh); } }
.pop-particle { position: absolute; width: 12px; height: 12px; border-radius: 50%; pointer-events: none; animation: pop .5s ease-out forwards; }
@keyframes pop { to { transform: translate(var(--dx), var(--dy)) scale(.3); opacity: 0; } }

/* Xylophone */
.xylo { display: flex; gap: 8px; height: 100%; align-items: stretch; padding: 8px 2px 18px; }
.bar { flex: 1; border: none; border-radius: 22px; cursor: pointer; font-size: clamp(16px, 3vw, 24px); font-weight: 900; color: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 14px; touch-action: none; }
.bar.bounce { animation: bounce .35s ease; }
