:root {
  --bg: #1b1238;
  --ink: #fff8ec;
  --ink-dim: #cfc2f2;
  --panel: #2c1f57;
  --panel-2: #3a2a72;
  --gold: #ffd84a;
  --pink: #ff7fd1;
  --green: #43c35a;
  --purple: #6c5cff;
  --orange: #ff9a3c;
  --liquid: #2f7d6e;
  --liquid-light: #4fa595;
  --font: "Baloo 2", "Comic Sans MS", "Chalkboard SE", system-ui, sans-serif;
  color-scheme: dark;
}
/* The castle is always night-time; light and dark both use these colors. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #1b1238; }
}
:root[data-theme="dark"] { --bg: #1b1238; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Scene ---------- */
#scene {
  position: fixed;
  inset: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
.wall {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 50% 70%, rgba(255, 170, 80, .22), transparent 55%),
    linear-gradient(rgba(0,0,0,.12) 2px, transparent 2px) 0 0 / 120px 60px,
    linear-gradient(90deg, rgba(0,0,0,.12) 2px, transparent 2px) 0 0 / 120px 120px,
    linear-gradient(90deg, rgba(0,0,0,.1) 2px, transparent 2px) 60px 60px / 120px 120px,
    linear-gradient(#2a1d52, #3b2a6b 60%, #2b1f50);
}
.window {
  position: absolute; top: 12%; left: 50%; translate: -50% 0;
  width: min(26vw, 200px); aspect-ratio: 3 / 4;
  border-radius: 999px 999px 10px 10px;
  background: radial-gradient(circle at 70% 30%, #2d3f8a, #101640 70%);
  border: 10px solid #4c3a7e;
  box-shadow: inset 0 0 30px rgba(0,0,0,.6), 0 0 60px rgba(120,140,255,.18);
  overflow: hidden;
  opacity: .9;
}
.window::after { /* window bars */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent 47%, #4c3a7e 47%, #4c3a7e 53%, transparent 53%),
              linear-gradient(transparent 55%, #4c3a7e 55%, #4c3a7e 60%, transparent 60%);
}
.moon {
  position: absolute; top: 14%; right: 16%; width: 36%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fffbe0, #ffe69a);
  box-shadow: 0 0 30px #ffe69a;
}
.moon::after { content: ""; position: absolute; width: 22%; height: 22%; border-radius: 50%; background: rgba(200,170,90,.35); top: 45%; left: 25%; box-shadow: 18px -8px 0 -2px rgba(200,170,90,.3); }
.twinkles { position: absolute; inset: 0; background-image: radial-gradient(2px 2px at 20% 30%, #fff, transparent), radial-gradient(1.5px 1.5px at 40% 70%, #fff, transparent), radial-gradient(2px 2px at 70% 80%, #fff, transparent), radial-gradient(1.5px 1.5px at 15% 85%, #fff, transparent); animation: twinkle 3s ease-in-out infinite alternate; }
@keyframes twinkle { to { opacity: .4; } }
.torch { position: absolute; top: 30%; width: 14px; height: 54px; background: linear-gradient(#7a4a26, #4a2a12); border-radius: 4px; }
.torch.t1 { left: 8%; } .torch.t2 { right: 8%; }
.flame { position: absolute; bottom: 100%; left: 50%; width: 26px; height: 40px; translate: -50% 4px; border-radius: 50% 50% 40% 40% / 70% 70% 30% 30%; background: radial-gradient(circle at 50% 70%, #fff6a8, #ffb330 40%, #ff5a1f 75%, transparent 76%); filter: drop-shadow(0 0 18px #ff9a3c); animation: flicker .18s infinite alternate; transform-origin: 50% 100%; }
.torch::after { content: ""; position: absolute; left: 50%; top: -30px; width: 220px; height: 220px; translate: -50% -50%; background: radial-gradient(circle, rgba(255,160,60,.18), transparent 60%); pointer-events: none; }
@keyframes flicker { from { transform: scale(1, 1) rotate(-2deg); } to { transform: scale(.92, 1.08) rotate(2deg); } }
.shelf-deco { position: absolute; top: 52%; left: 3%; display: flex; align-items: flex-end; gap: 6px; padding: 0 10px 4px; border-bottom: 10px solid #5a3a20; opacity: .75; }
.deco-bottle { width: 22px; height: 30px; border-radius: 6px 6px 10px 10px; background: var(--c); box-shadow: inset -4px -4px 0 rgba(0,0,0,.25), inset 3px 3px 0 rgba(255,255,255,.3); }
.deco-bottle.tall { height: 44px; }
.deco-book { width: 14px; height: 40px; background: #b8452f; border-radius: 2px; box-shadow: 16px 4px 0 -2px #3c7bd1; margin-right: 14px; }
.floor { position: absolute; left: 0; right: 0; bottom: 0; height: 30%; background: linear-gradient(#3a2448, #24152f); box-shadow: 0 -8px 30px rgba(0,0,0,.4); }

/* ---------- Top bar ---------- */
.topbar {
  position: relative; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}
.mode-title { font-weight: 800; font-size: clamp(16px, 2.6vw, 22px); color: var(--gold); text-shadow: 0 2px 0 #6b3f1e; flex: 1; text-align: center; }
.toggles { display: flex; gap: 6px; }
.icon-btn {
  width: 46px; height: 46px; border-radius: 14px; border: 0;
  background: rgba(255,255,255,.12); font-size: 22px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.25);
  transition: transform .12s;
  display: grid; place-items: center;
}
.icon-btn:active { transform: scale(.9); }
.icon-btn.off { opacity: .35; filter: grayscale(1); }
body:not(.playing) .topbar, body:not(.playing) .hoot-area, body:not(.playing) .lesson-card { display: none; }

/* ---------- Professor Hoot ---------- */
.hoot-area {
  position: absolute; z-index: 6;
  top: calc(max(10px, env(safe-area-inset-top)) + 54px); left: max(12px, env(safe-area-inset-left));
  display: flex; align-items: flex-start; gap: 6px;
  max-width: min(560px, calc(100vw - 24px));
  pointer-events: none;
}
.owl { width: clamp(70px, 11vw, 110px); flex: none; pointer-events: auto; cursor: pointer; transform-origin: 50% 100%; animation: owl-idle 3s ease-in-out infinite; }
.owl-svg { width: 100%; display: block; overflow: visible; filter: drop-shadow(0 6px 8px rgba(0,0,0,.4)); }
.owl-lids rect { transform: scaleY(0); transform-origin: center top; transform-box: fill-box; transition: transform .08s; }
.owl.blink .owl-lids rect { transform: scaleY(1); }
.owl-pupils { transition: transform .15s; }
.owl.talking .owl-beak { animation: beak .18s infinite alternate; transform-origin: 50% 0; transform-box: fill-box; }
.owl.talking .owl-wing { animation: flap .35s ease-in-out infinite alternate; transform-box: fill-box; }
.owl-wl { transform-origin: 100% 0; } .owl-wr { transform-origin: 0 0; }
.owl.hop { animation: hop .5s; }
.owl.sooty .owl-svg { filter: brightness(.35) sepia(.5) drop-shadow(0 6px 8px rgba(0,0,0,.4)); }
.owl.sooty::after { content: "💫"; position: absolute; font-size: 26px; margin: -10px 0 0 -40px; animation: spin 1s linear infinite; }
.owl.pinch .owl-lids rect { transform: scaleY(.55); }
.owl.pinch::after { content: "🤢"; position: absolute; font-size: 28px; margin: 30px 0 0 -34px; }
@keyframes owl-idle { 50% { transform: translateY(-4px) rotate(-1.5deg); } }
@keyframes beak { to { transform: scaleY(1.35); } }
@keyframes flap { to { transform: rotate(-18deg); } }
@keyframes hop { 30% { transform: translateY(-18px) scale(1.05, .95); } 60% { transform: translateY(0) scale(1.08, .9); } }
@keyframes spin { to { transform: rotate(360deg); } }

.speech {
  position: relative; margin-top: 8px;
  background: #fff8ec; color: #2c1f57;
  border-radius: 20px; padding: 10px 16px;
  font-size: clamp(15px, 2.2vw, 20px); font-weight: 700; line-height: 1.25;
  box-shadow: 0 6px 0 rgba(0,0,0,.2), 0 10px 30px rgba(0,0,0,.25);
  min-height: 2.5em;
  pointer-events: auto;
}
.speech::before { content: ""; position: absolute; left: -12px; top: 18px; border: 10px solid transparent; border-right: 14px solid #fff8ec; border-left: 0; }
.speech.pop { animation: speech-pop .3s cubic-bezier(.3,1.6,.6,1); }
@keyframes speech-pop { from { transform: scale(.85); opacity: .3; } }

/* ---------- Lesson checklist ---------- */
.lesson-card {
  position: absolute; z-index: 5; right: max(12px, env(safe-area-inset-right)); top: calc(max(10px, env(safe-area-inset-top)) + 60px);
  background: rgba(255, 248, 236, .95); color: #2c1f57; border-radius: 18px; padding: 10px 14px 8px;
  width: min(260px, 40vw);
  box-shadow: 0 6px 0 rgba(0,0,0,.2);
  transform: rotate(1.5deg);
  font-size: 15px;
}
.lesson-card::before { content: "📜"; position: absolute; right: -6px; top: -14px; font-size: 26px; }
.lc-title { font-weight: 800; color: #5b3fd1; line-height: 1.1; margin-bottom: 4px; }
.lesson-card ol { margin: 0; padding-left: 22px; }
.lesson-card li { margin: 2px 0; font-weight: 600; opacity: .55; }
.lesson-card li.now { opacity: 1; color: #d1306b; font-weight: 800; }
.lesson-card li.done { opacity: .9; text-decoration: line-through; text-decoration-thickness: 2px; }
.lesson-card li.done::marker { content: "✅ "; }

/* ---------- Stage & cauldron ---------- */
#stage {
  position: relative; z-index: 2;
  grid-row: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding-bottom: 6px;
  min-height: 0;
}
.pot {
  --boil: 0;
  position: relative;
  width: min(44vh, 62vw, 380px);
  aspect-ratio: 300 / 270;
  cursor: grab;
  touch-action: none;
  transform-origin: 50% 90%;
  transition: filter .3s;
}
.pot-svg { width: 100%; height: 100%; display: block; overflow: visible; filter: drop-shadow(0 18px 18px rgba(0,0,0,.45)); }
.pot.drop-hover { filter: drop-shadow(0 0 24px var(--gold)); }
.pot.drop-hover .pot-svg { transform: scale(1.04); transition: transform .15s; }
#liquid { transition: fill .5s; }
.pot .liquid-g { transform-origin: 150px 96px; transform-box: view-box; }
.pot.has-stuff .liquid-g { filter: drop-shadow(0 0 calc(6px + var(--boil) * 5px) var(--liquid-light)); }
.pot .swirl { transform-origin: 150px 96px; transform-box: view-box; opacity: .2; }
.pot.has-stuff .swirl { opacity: 1; }
.surface-bubbles circle { fill: var(--liquid-light); opacity: 0; transform-box: fill-box; transform-origin: center; }
.pot.has-stuff .surface-bubbles circle { animation: surf 1.4s ease-in-out infinite; }
.surface-bubbles circle:nth-child(2) { animation-delay: .4s !important; }
.surface-bubbles circle:nth-child(3) { animation-delay: .8s !important; }
.surface-bubbles circle:nth-child(4) { animation-delay: 1.1s !important; }
@keyframes surf { 0% { opacity: 0; transform: scale(.2); } 50% { opacity: .9; transform: scale(1); } 100% { opacity: 0; transform: scale(1.4); } }
.fire .fl { transform-box: fill-box; transform-origin: 50% 100%; animation: fire .3s ease-in-out infinite alternate; }
.fire .f2 { animation-duration: .25s; } .fire .f3 { animation-duration: .35s; } .fire .f4 { animation-duration: .2s; }
@keyframes fire { to { transform: scale(.85, 1.12) skewX(4deg); } }
.pot.gulp .pot-svg { animation: gulp .5s cubic-bezier(.3,1.6,.5,1); }
@keyframes gulp { 30% { transform: scale(1.08, .92); } 60% { transform: scale(.96, 1.05); } }
.pot.slosh .liquid-g { animation: slosh .5s; }
@keyframes slosh { 30% { transform: skewX(6deg) translateY(-2px); } 60% { transform: skewX(-4deg); } }
.pot.trembling { animation: tremble .07s linear infinite; }
@keyframes tremble { 0% { transform: translate(-3px, 0) rotate(-1deg); } 50% { transform: translate(3px, -1px) rotate(1deg); } 100% { transform: translate(-2px, 1px); } }
.pot.sooty .pot-svg { filter: brightness(.5) drop-shadow(0 18px 18px rgba(0,0,0,.45)); }
.pot.tipping { animation: tip .7s ease-in-out; }
@keyframes tip { 40%, 60% { transform: rotate(-28deg) translateX(-20px); } }
.pot.floating-away { animation: float-away 3s cubic-bezier(.5,0,.7,.4) forwards; }
@keyframes float-away { 0% { transform: translateY(0); } 20% { transform: translateY(-20px) rotate(-3deg); } 100% { transform: translateY(-110vh) rotate(6deg); } }
.pot.rocket { animation: rocket 2.6s ease-in-out; }
@keyframes rocket { 20% { transform: translateY(8px) scale(1.05, .9); } 45% { transform: translateY(-40vh) rotate(-8deg); } 70% { transform: translateY(-40vh) rotate(8deg); } 100% { transform: translateY(0); } }
.pot.dancing { animation: dance .44s ease-in-out infinite alternate; }
@keyframes dance { from { transform: rotate(-8deg) translateY(0); } to { transform: rotate(8deg) translateY(-14px); } }

.balloons { position: absolute; left: 50%; bottom: 82%; width: 0; height: 0; }
.balloons span {
  position: absolute; left: calc((var(--i) - 2) * 34px - 20px); bottom: calc(40px + (var(--i) % 2) * 26px);
  width: 40px; height: 50px; border-radius: 50% 50% 46% 46%; background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.7), var(--c) 40%);
  animation: balloon-in .6s cubic-bezier(.3,1.6,.5,1) both, sway 1.4s ease-in-out infinite alternate; animation-delay: calc(var(--i) * .08s), 0s;
}
.balloons span::after { content: ""; position: absolute; left: 50%; top: 100%; width: 2px; height: calc(40px + (var(--i) % 2) * 26px); background: rgba(255,255,255,.6); }
@keyframes balloon-in { from { transform: scale(0); } }
@keyframes sway { to { rotate: 6deg; } }

/* Spoon */
.spoon {
  --sx: 0%; --sy: 0%; --tilt: 0deg;
  position: absolute; left: calc(50% + var(--sx)); top: calc(-12% + var(--sy));
  width: 7%; height: 48%;
  transform: translateX(-50%) rotate(var(--tilt));
  transform-origin: 50% 80%;
  pointer-events: none;
  transition: opacity .3s;
  outline: none;
}
.spoon-stick { position: absolute; inset: 0; border-radius: 10px 10px 50% 50% / 6% 6% 18% 18%; background: linear-gradient(90deg, #a46a3a, #d9a26a 45%, #8a5228); box-shadow: inset 0 -12px 0 rgba(0,0,0,.18); }
.spoon::after { content: ""; position: absolute; left: -40%; right: -40%; bottom: -6%; height: 22%; border-radius: 50%; background: var(--liquid); opacity: .9; }
.spoon:focus-visible .spoon-stick { box-shadow: 0 0 0 4px var(--gold); }
.spoon.hint .spoon-stick { animation: spoon-hint 1s ease-in-out infinite; box-shadow: 0 0 18px 4px var(--gold); }
@keyframes spoon-hint { 50% { filter: brightness(1.4); } }
.spoon.away { opacity: 0; }
.pot.has-stuff.spoon-hint-hand::after { content: "👆"; }

.pot-items { position: absolute; inset: 20% 15% 60%; pointer-events: none; }
.bob { position: absolute; top: 0; font-size: clamp(22px, 4vh, 34px); animation: bob 2.4s ease-in forwards; }
@keyframes bob { 0% { transform: translateY(-10px) scale(.6); } 20% { transform: translateY(0) scale(1) rotate(-10deg); } 50% { transform: translateY(4px) rotate(10deg); } 100% { transform: translateY(30px) scale(.4); opacity: 0; } }

.stir-meter { position: absolute; left: 50%; top: 2%; translate: -50% -100%; pointer-events: none; display: flex; gap: 4px; background: rgba(0,0,0,.45); padding: 2px 10px; border-radius: 99px; font-size: 18px; }
.stir-meter span { opacity: .3; filter: grayscale(1); transition: all .25s; }
.stir-meter span.on { opacity: 1; filter: none; transform: scale(1.2) rotate(180deg); }

.actions { display: flex; gap: 10px; min-height: 58px; align-items: center; margin-top: 6px; }
.pill-btn {
  border: 0; border-radius: 999px; padding: 10px 22px; font-weight: 800; font-size: clamp(17px, 2.4vw, 22px);
  box-shadow: inset 0 -5px 0 rgba(0,0,0,.22), 0 6px 14px rgba(0,0,0,.3);
  transition: transform .12s, opacity .2s;
}
.pill-btn:active { transform: scale(.94) translateY(2px); }
.pill-btn.brew { background: linear-gradient(#ffe36e, #ffb330); color: #5a2a00; }
.pill-btn.ghost { background: rgba(255,255,255,.16); color: var(--ink); }
.pill-btn:disabled { opacity: .4; }
.pill-btn.brew.ready { animation: ready 1s ease-in-out infinite; }
.pill-btn.brew.dim { filter: saturate(.4) brightness(.8); }
.pill-btn .wand { display: inline-block; }
.pill-btn.ready .wand { animation: wiggle .5s ease-in-out infinite alternate; }
@keyframes ready { 50% { transform: scale(1.08); box-shadow: inset 0 -5px 0 rgba(0,0,0,.22), 0 0 30px 6px rgba(255,216,74,.7); } }
@keyframes wiggle { from { transform: rotate(-15deg); } to { transform: rotate(15deg); } }

/* ---------- Shelf of jars ---------- */
.shelf {
  position: relative; z-index: 3;
  grid-row: 3;
  display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px;
  padding: 10px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: linear-gradient(#6b4423, #4a2d15);
  border-top: 8px solid #8a5a2e;
  box-shadow: 0 -10px 30px rgba(0,0,0,.4);
}
.jar {
  position: relative; border: 0; background: none; padding: 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  touch-action: none;
  transition: transform .15s;
  min-width: 0;
}
.jar-glass {
  position: relative; width: min(100%, 76px); aspect-ratio: 1 / 1.05;
  border-radius: 22% 22% 30% 30%;
  background: rgba(255,255,255,.14);
  border: 3px solid rgba(255,255,255,.45);
  overflow: hidden;
  display: grid; place-items: center;
  box-shadow: 0 6px 0 rgba(0,0,0,.25);
}
.jar-liquid { position: absolute; left: 0; right: 0; bottom: 0; height: 55%; background: linear-gradient(color-mix(in srgb, var(--c) 80%, #fff), var(--c)); opacity: .85; }
.jar-icon { position: relative; font-size: clamp(24px, 4.2vw, 38px); filter: drop-shadow(0 2px 2px rgba(0,0,0,.3)); }
.jar-shine { position: absolute; left: 12%; top: 12%; width: 14%; height: 45%; border-radius: 99px; background: rgba(255,255,255,.45); }
.jar-lid { position: absolute; top: -5px; width: min(60%, 46px); height: 10px; border-radius: 4px; background: linear-gradient(#c48a52, #7a4a26); }
.jar-label { font-size: clamp(10px, 1.4vw, 14px); font-weight: 700; line-height: 1; text-align: center; color: #ffe9c8; text-shadow: 0 1px 0 #000; max-width: 100%; }
.jar:hover { transform: translateY(-4px); }
.jar:active, .jar.lifted { transform: scale(.92); }
.jar.used .jar-glass { animation: used .4s; }
@keyframes used { 40% { transform: rotate(-20deg) translateY(-6px); } }
.jar.nope { animation: nope .4s; }
@keyframes nope { 20%, 60% { transform: translateX(-6px) rotate(-4deg); } 40%, 80% { transform: translateX(6px) rotate(4deg); } }
.shelf.guiding .jar:not(.glow) { opacity: .55; filter: saturate(.6); }
.jar.glow { z-index: 2; }
.jar.glow .jar-glass { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(255,216,74,.5), 0 0 28px 8px rgba(255,216,74,.65); animation: glow-bounce 1s ease-in-out infinite; }
.jar.glow::before { content: "👇"; position: absolute; top: -34px; font-size: 26px; animation: point .6s ease-in-out infinite alternate; }
@keyframes glow-bounce { 50% { transform: translateY(-6px) scale(1.05); } }
@keyframes point { to { transform: translateY(8px); } }
.jar:focus-visible .jar-glass { outline: 3px solid var(--gold); outline-offset: 2px; }

@media (max-aspect-ratio: 4/3) {
  .shelf { grid-template-columns: repeat(5, 1fr); row-gap: 10px; }
  .jar-glass { width: min(100%, 70px); }
  .jar-icon { font-size: clamp(26px, 7vw, 38px); }
  .jar-label { font-size: clamp(10px, 2.8vw, 14px); }
  .lesson-card { top: auto; bottom: calc(100% + 8px); }
}
@media (max-width: 640px) {
  .lesson-card { display: none; }
  .torch, .shelf-deco { display: none; }
  .icon-btn { width: 40px; height: 40px; font-size: 19px; }
}
@media (max-height: 520px) {
  .jar-label { display: none; }
  .shelf { padding-top: 6px; }
  .hoot-area { top: 8px; left: 64px; }
  .owl { width: 60px; }
  .speech { font-size: 14px; padding: 6px 12px; }
  .lesson-card { display: none; }
}

/* Drag + fly */
.drag-ghost, .flying {
  position: fixed; left: 0; top: 0; z-index: 50; font-size: 48px; pointer-events: none;
  filter: drop-shadow(0 8px 6px rgba(0,0,0,.4));
}
.drag-ghost { translate: -50% -50%; scale: 1.2; }

/* ---------- Effects layer ---------- */
.fx { position: fixed; inset: 0; z-index: 20; pointer-events: none; overflow: hidden; }
#particles { position: fixed; inset: 0; z-index: 21; pointer-events: none; }
.flash { position: absolute; inset: 0; animation: flash .7s ease-out forwards; }
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }
.comic {
  position: absolute; translate: -50% -50%;
  font-size: clamp(48px, 12vw, 120px); font-weight: 800; color: var(--c);
  -webkit-text-stroke: 4px #2c1f57; paint-order: stroke fill;
  text-shadow: 6px 6px 0 #2c1f57;
  animation: comic 2.2s cubic-bezier(.3,1.6,.5,1) forwards;
  white-space: nowrap; letter-spacing: 2px;
}
@keyframes comic { 0% { transform: scale(0) rotate(-20deg); } 15% { transform: scale(1.1) rotate(-6deg); } 25% { transform: scale(1) rotate(-6deg); } 80% { opacity: 1; transform: scale(1.05) rotate(-4deg); } 100% { opacity: 0; transform: scale(1.4) rotate(-4deg); } }
#scene.shake-big { animation: shake-big .8s; }
.shake-small { animation: shake-small .5s; }
@keyframes shake-big { 10%, 50% { transform: translate(-14px, 8px) rotate(-1deg); } 30%, 70% { transform: translate(14px, -8px) rotate(1deg); } 90% { transform: translate(-4px, 2px); } }
@keyframes shake-small { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.big-bubble {
  position: absolute; border-radius: 50%; pointer-events: auto; cursor: pointer;
  background: radial-gradient(circle at 30% 28%, rgba(255,255,255,.85) 0 8%, transparent 9%), radial-gradient(circle at 50% 50%, transparent 55%, color-mix(in srgb, var(--tint) 50%, transparent) 75%, rgba(255,255,255,.6) 100%);
  box-shadow: inset 0 0 20px rgba(255,255,255,.3);
  animation: bubble-up var(--dur) ease-in-out both;
}
@keyframes bubble-up { 0% { transform: translate(0, 0) scale(.1); } 10% { transform: translate(calc(var(--dx) * .1), -6vh) scale(1); } 100% { transform: translate(var(--dx), -110vh) scale(1.1); } }

.hatchling {
  position: absolute; width: clamp(150px, 26vh, 240px); translate: -50% -92%;
  animation: hatch 1s cubic-bezier(.3,1.6,.5,1) both;
  z-index: 3;
}
.hatchling.big { width: clamp(200px, 36vh, 320px); }
.hatchling .creature-svg { animation: creature-bounce .8s ease-in-out infinite alternate; }
@keyframes hatch { 0% { transform: translateY(80px) scale(.2); } 60% { transform: translateY(-40px) scale(1.1); } 100% { transform: translateY(0) scale(1); } }
.hatchling.sneeze { animation: sneeze .5s ease-in-out; }
@keyframes sneeze { 50% { transform: scale(.9, 1.1) rotate(-6deg); } }
.creature-svg { width: 100%; display: block; overflow: visible; filter: drop-shadow(0 8px 10px rgba(0,0,0,.4)); }
@keyframes creature-bounce { from { transform: translateY(0) scale(1.03, .97); } to { transform: translateY(-10px) scale(.98, 1.02); } }
.creature-svg .lid { transform: scaleY(0); transform-origin: center top; transform-box: fill-box; animation: c-blink 4s infinite; }
@keyframes c-blink { 0%, 92%, 100% { transform: scaleY(0); } 95% { transform: scaleY(1); } }
.creature-svg .pupil { transition: transform .15s; }
.creature-svg .wing { transform-box: fill-box; animation: c-flap .3s ease-in-out infinite alternate; }
.creature-svg .wl { transform-origin: 100% 60%; } .creature-svg .wr { transform-origin: 0 60%; }
@keyframes c-flap { to { transform: rotate(-16deg); } }
.creature-svg .wr { animation-name: c-flap-r; }
@keyframes c-flap-r { to { transform: rotate(16deg); } }
.creature-svg .tail { transform-box: fill-box; transform-origin: 0 50%; animation: c-tail .6s ease-in-out infinite alternate; }
@keyframes c-tail { to { transform: rotate(14deg); } }
.creature-svg .antenna { transform-box: fill-box; transform-origin: 80% 100%; animation: c-ant 1s ease-in-out infinite alternate; }
.creature-svg .a2 { transform-origin: 20% 100%; animation-delay: -.5s; }
@keyframes c-ant { to { transform: rotate(10deg); } }

.rainbow { position: absolute; left: -5%; right: -5%; top: 10%; height: 60%; }
.rainbow svg { width: 100%; height: 100%; }
.rainbow path { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.4s ease-out forwards; stroke-linecap: round; opacity: .9; }
.rainbow path:nth-child(2) { animation-delay: .06s; } .rainbow path:nth-child(3) { animation-delay: .12s; } .rainbow path:nth-child(4) { animation-delay: .18s; } .rainbow path:nth-child(5) { animation-delay: .24s; } .rainbow path:nth-child(6) { animation-delay: .3s; } .rainbow path:nth-child(7) { animation-delay: .36s; }
@keyframes draw { to { stroke-dashoffset: 0; } }

body.snow-mode .wall { filter: hue-rotate(-30deg) brightness(1.15) saturate(.7); transition: filter 1s; }
.frost { position: absolute; inset: 0; box-shadow: inset 0 0 120px 40px rgba(220, 245, 255, .55); animation: fade-in 1.5s; }
@keyframes fade-in { from { opacity: 0; } }

body.stink-mode .wall { filter: sepia(.6) hue-rotate(40deg) saturate(1.5); transition: filter .6s; }
.fly { position: absolute; font-size: 26px; animation: fly var(--d) linear infinite; }
@keyframes fly { from { transform: rotate(0) translateX(var(--r)) rotate(0); } to { transform: rotate(360deg) translateX(var(--r)) rotate(-360deg); } }

body.disco-mode .wall { animation: disco-hue 1.2s linear infinite; }
@keyframes disco-hue { to { filter: hue-rotate(360deg) saturate(1.6); } }
.disco-ball { position: absolute; left: 50%; top: 0; translate: -50% 0; animation: drop-in .8s cubic-bezier(.3,1.6,.5,1) both; }
.disco-ball::before { content: ""; display: block; width: 3px; height: 9vh; margin: auto; background: #ccc; }
.disco-ball span { display: block; width: 80px; height: 80px; border-radius: 50%; background: conic-gradient(#fff, #bbb, #fff, #999, #fff, #ccc, #fff); box-shadow: 0 0 40px #fff; animation: spin 2s linear infinite; background-size: 20px 20px; }
@keyframes drop-in { from { transform: translateY(-200px); } }
.spotlights i { position: absolute; top: 10vh; left: 50%; width: 60vw; height: 140vh; transform-origin: 50% 0; background: linear-gradient(rgba(255,255,255,.35), transparent 70%); clip-path: polygon(48% 0, 52% 0, 75% 100%, 25% 100%); mix-blend-mode: screen; animation: sweep 2s ease-in-out infinite alternate; translate: -50% 0; }
.spotlights i:nth-child(1) { background: linear-gradient(rgba(255,77,109,.5), transparent 70%); --a: -40deg; }
.spotlights i:nth-child(2) { background: linear-gradient(rgba(58,183,255,.5), transparent 70%); --a: 30deg; animation-delay: -.5s; }
.spotlights i:nth-child(3) { background: linear-gradient(rgba(255,216,74,.5), transparent 70%); --a: -10deg; animation-delay: -1s; }
.spotlights i:nth-child(4) { background: linear-gradient(rgba(198,107,255,.5), transparent 70%); --a: 50deg; animation-delay: -1.5s; }
@keyframes sweep { from { transform: rotate(var(--a)); } to { transform: rotate(calc(var(--a) * -1)); } }

.frog-drop { position: absolute; top: -60px; font-size: calc(40px * var(--s)); animation: frog-fall 2s cubic-bezier(.5,0,1,.5) forwards; }
@keyframes frog-fall { 0% { transform: translateY(0) rotate(0); } 70% { transform: translateY(85vh) rotate(260deg); } 80% { transform: translateY(78vh) rotate(360deg); } 100% { transform: translateY(86vh) rotate(360deg); } }

.wand-swish { position: absolute; font-size: 64px; translate: -50% -110%; animation: swish .8s ease-in-out; transform-origin: 80% 90%; }
@keyframes swish { 0% { transform: rotate(-60deg) scale(.5); opacity: 0; } 30% { opacity: 1; transform: rotate(-30deg) scale(1.1); } 70% { transform: rotate(40deg); } 100% { transform: rotate(10deg) scale(.8); opacity: 0; } }

/* ---------- Screens ---------- */
.screen { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; }
.title-screen {
  background: radial-gradient(ellipse at 50% 120%, rgba(255,160,60,.35), transparent 60%), radial-gradient(ellipse at 50% 30%, #3e2b80, #1b1238 75%);
  overflow: hidden;
}
.title-screen::before { content: ""; position: absolute; inset: 0; background-image: radial-gradient(2px 2px at 10% 20%, #fff, transparent), radial-gradient(2px 2px at 80% 15%, #fff, transparent), radial-gradient(1.5px 1.5px at 60% 40%, #fff, transparent), radial-gradient(2px 2px at 30% 60%, #fff, transparent), radial-gradient(1.5px 1.5px at 90% 70%, #fff, transparent), radial-gradient(2px 2px at 45% 10%, #fff, transparent); animation: twinkle 2.5s ease-in-out infinite alternate; }
.title-wrap { position: relative; text-align: center; display: flex; flex-direction: column; align-items: center; }
.logo-pot { width: 120px; height: 100px; position: relative; margin-bottom: -10px; }
.logo-pot::before { content: "🧪"; font-size: 96px; position: absolute; left: 50%; translate: -50% 0; animation: owl-idle 2s ease-in-out infinite; filter: drop-shadow(0 0 30px #43c35a); }
.logo { margin: 0; line-height: .85; display: flex; flex-direction: column; font-weight: 800; }
.logo span { font-size: clamp(56px, 13vw, 120px); color: var(--gold); -webkit-text-stroke: 5px #2c1f57; paint-order: stroke fill; text-shadow: 0 8px 0 #2c1f57, 0 12px 30px rgba(0,0,0,.5); }
.logo span:last-child { color: var(--pink); transform: rotate(-3deg); }
.logo span:first-child { transform: rotate(2deg); }
.tagline { font-size: clamp(18px, 3vw, 24px); font-weight: 700; color: var(--ink-dim); margin: 14px 0 22px; }
.menu { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
.big-btn {
  border: 0; border-radius: 26px; padding: 14px 26px; min-width: 200px;
  font-size: clamp(22px, 3.4vw, 28px); font-weight: 800; color: #fff;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  box-shadow: inset 0 -7px 0 rgba(0,0,0,.25), 0 10px 20px rgba(0,0,0,.35);
  transition: transform .12s;
  animation: menu-in .6s cubic-bezier(.3,1.6,.5,1) both;
}
.big-btn span { font-size: 1.3em; }
.big-btn:hover { transform: translateY(-3px) scale(1.03); }
.big-btn:active { transform: scale(.95); }
.b-purple { background: linear-gradient(#8a7bff, #5b3fd1); }
.b-green { background: linear-gradient(#5fe07a, #2e9a45); animation-delay: .08s; }
.b-orange { background: linear-gradient(#ffb766, #e8741a); animation-delay: .16s; }
@keyframes menu-in { from { transform: translateY(40px) scale(.8); opacity: 0; } }

.panel-screen { background: radial-gradient(ellipse at 50% 0, #3e2b80, #1b1238 70%); overflow-y: auto; place-items: start center; }
.panel { position: relative; width: min(900px, 100%); padding: 10px 0 40px; }
.panel h2 { text-align: center; font-size: clamp(28px, 5vw, 44px); margin: 6px 0 4px; color: var(--gold); text-shadow: 0 4px 0 #2c1f57; padding: 0 50px; line-height: 1.05; }
.panel h3 { font-size: 28px; color: var(--pink); margin: 30px 0 0; text-align: center; }
.panel .back { position: absolute; left: 0; top: 8px; }
.lesson-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-top: 18px; }
.lesson-tile, .book-tile {
  position: relative; border: 0; border-radius: 22px; padding: 14px 10px 12px;
  background: linear-gradient(var(--panel-2), var(--panel)); color: var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  box-shadow: inset 0 -5px 0 rgba(0,0,0,.25), 0 8px 18px rgba(0,0,0,.3);
  transition: transform .12s;
}
.lesson-tile:not(:disabled):hover { transform: translateY(-4px) rotate(-1deg); }
.lesson-tile:disabled { opacity: .5; cursor: not-allowed; }
.lesson-tile.done { background: linear-gradient(#4a3a8a, #33256a); }
.lt-num { position: absolute; top: 8px; left: 12px; font-size: 22px; font-weight: 800; color: var(--gold); }
.bottle-svg { width: 70px; height: 88px; filter: drop-shadow(0 4px 6px rgba(0,0,0,.4)); }
.lt-name, .bt-name { font-weight: 800; font-size: 19px; line-height: 1.1; text-align: center; }
.lt-ings, .bt-ings { font-size: 18px; color: var(--ink-dim); text-align: center; }
.lt-stars { color: var(--gold); font-size: 22px; letter-spacing: 2px; }
.book-count, .zoo-hint { text-align: center; color: var(--ink-dim); font-size: 18px; margin: 0 0 10px; }
.book-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.book-tile:not(.found) { opacity: .6; }
.book-tile:not(.found) .bt-name { color: var(--ink-dim); }
.zoo-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.zoo-tile { border: 0; background: rgba(255,255,255,.07); border-radius: 18px; padding: 8px; display: flex; flex-direction: column; align-items: center; font-weight: 700; font-size: 15px; }
.zoo-tile .creature-svg { width: 90px; }
.zoo-tile.hop { animation: hop .5s; }

.result-screen { background: radial-gradient(circle, rgba(27,18,56,.55), rgba(27,18,56,.85)); z-index: 40; }
.result-card {
  position: relative; width: min(460px, 100%);
  background: linear-gradient(#fff8ec, #ffe9c8); color: #2c1f57;
  border-radius: 32px; padding: 18px 22px 22px; text-align: center;
  border: 6px solid var(--gold);
  box-shadow: 0 12px 0 #b8862e, 0 30px 60px rgba(0,0,0,.5);
  max-height: calc(100vh - 32px); overflow-y: auto;
}
.result-screen.in .result-card { animation: card-in .6s cubic-bezier(.3,1.5,.5,1); }
@keyframes card-in { from { transform: scale(.3) rotate(-8deg); opacity: 0; } }
.new-badge { position: absolute; top: 10px; right: 10px; background: #ff4d6d; color: #fff; font-weight: 800; font-size: 22px; padding: 4px 14px; border-radius: 99px; transform: rotate(12deg); box-shadow: 0 4px 0 #a01d3a; animation: badge 1s ease-in-out infinite alternate; }
@keyframes badge { to { transform: rotate(6deg) scale(1.1); } }
.result-art { display: grid; place-items: center; min-height: 120px; }
.result-art .bottle-svg { width: 100px; height: 125px; animation: bottle-glow 1.6s ease-in-out infinite alternate; }
@keyframes bottle-glow { to { transform: translateY(-6px) rotate(4deg); filter: drop-shadow(0 0 16px rgba(255,216,74,.9)); } }
.art-pair { display: flex; align-items: flex-end; gap: 8px; }
.mini-creature { width: 130px; }
.mini-creature.solo { width: 170px; }
.mini-creature .creature-svg { animation: creature-bounce .8s ease-in-out infinite alternate; }
.you-made { margin: 4px 0 0; font-weight: 700; font-size: 19px; color: #6b5a9a; }
.result-name { margin: 0; font-size: clamp(30px, 7vw, 42px); line-height: 1; color: var(--c, #5b3fd1); -webkit-text-stroke: 2px #2c1f57; paint-order: stroke fill; filter: brightness(.9); }
.result-stars { font-size: 40px; margin: 4px 0; }
.result-stars:empty { display: none; }
.result-stars .star { display: inline-block; color: #d8cfe8; }
.result-stars .star.on { color: var(--gold); -webkit-text-stroke: 2px #b8862e; animation: star-in .5s cubic-bezier(.3,1.8,.5,1) both; animation-delay: calc(.4s + var(--i) * .2s); }
@keyframes star-in { from { transform: scale(0) rotate(-180deg); } }
.result-blurb { font-size: 19px; font-weight: 600; margin: 6px 0; }
.result-recipe { font-size: 30px; display: flex; justify-content: center; align-items: center; gap: 6px; margin: 4px 0 14px; }
.result-recipe b { font-size: 20px; color: #9a88c8; }
.result-btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.result-btns .ghost { background: #e7dcf7; color: #2c1f57; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .pot.floating-away { animation: none; opacity: .3; }
}

/* ---------- Round 2 polish ---------- */
.hand-guide {
  position: absolute; left: 50%; top: 22%; font-size: clamp(34px, 6vh, 48px); pointer-events: none; opacity: 0;
  filter: drop-shadow(0 4px 4px rgba(0,0,0,.5)); transition: opacity .3s;
}
.pot:has(.spoon.hint) .hand-guide { opacity: 1; animation: hand-circle 1.6s linear infinite; }
@keyframes hand-circle {
  0% { transform: translate(-50%, 0) translate(30%, 0); }
  12.5% { transform: translate(-50%, 0) translate(150%, 25%); }
  25% { transform: translate(-50%, 0) translate(210%, 60%); }
  37.5% { transform: translate(-50%, 0) translate(150%, 95%); }
  50% { transform: translate(-50%, 0) translate(-30%, 110%); }
  62.5% { transform: translate(-50%, 0) translate(-190%, 95%); }
  75% { transform: translate(-50%, 0) translate(-250%, 60%); }
  87.5% { transform: translate(-50%, 0) translate(-190%, 25%); }
  100% { transform: translate(-50%, 0) translate(30%, 0); }
}
.title-scene { position: relative; display: flex; align-items: flex-end; justify-content: center; gap: 4px; margin-bottom: -6px; cursor: pointer; }
.title-owl { width: clamp(80px, 13vh, 120px); animation: owl-idle 3s ease-in-out infinite; transform-origin: 50% 100%; }
.title-owl .owl-svg { width: 100%; display: block; overflow: visible; }
.title-pot { width: clamp(130px, 22vh, 200px); --liquid: #43c35a; --liquid-light: #8ff5a0; }
.title-pot .pot-svg { width: 100%; display: block; overflow: visible; filter: drop-shadow(0 0 30px rgba(95,224,122,.45)); }
.title-pot .surface-bubbles circle { fill: #8ff5a0; animation: surf 1.4s ease-in-out infinite; }
.title-pot .liquid-g { filter: drop-shadow(0 0 12px #8ff5a0); }
.mini-creature, .result-art .bottle-svg { cursor: pointer; }
.mini-creature.hop, .bottle-svg.hop { animation: hop .5s; }
.jar:nth-child(odd) .jar-icon { animation: jar-idle 3.2s ease-in-out infinite; }
.jar:nth-child(even) .jar-icon { animation: jar-idle 3.2s ease-in-out -1.6s infinite; }
@keyframes jar-idle { 50% { transform: translateY(-3px) rotate(-4deg); } }
@media (max-height: 520px) { .mode-title { visibility: hidden; } .title-scene { display: none; } }
.lesson-card.quest { cursor: pointer; transform: rotate(-1.5deg); }
.lesson-card.quest::before { content: "🔍"; }
.lesson-card.quest li { list-style: none; margin-left: -18px; }
.lesson-card .quest-clue { font-size: 24px; opacity: 1 !important; letter-spacing: 2px; }

/* Bottling */
.pot { transition: rotate .4s cubic-bezier(.3,1.4,.5,1), translate .4s; }
.pot.pour-right { rotate: 16deg; translate: 0 -8px; }
.pot.pour-left { rotate: -16deg; translate: 0 -8px; }
.bottle-fill { position: absolute; translate: -50% -100%; animation: bottle-in .4s cubic-bezier(.3,1.6,.5,1) both; z-index: 2; }
.bottle-fill .bottle-svg { width: 100%; height: auto; }
.bottle-fill .bl { clip-path: inset(100% 0 0 0); transition: clip-path 1.3s ease-in .25s; }
.bottle-fill.filling .bl { clip-path: inset(0 0 0 0); }
.bottle-fill .cork { opacity: 0; transform: translateY(-24px); transition: transform .25s cubic-bezier(.3,1.8,.5,1), opacity .1s; }
.bottle-fill.corked .cork { opacity: 1; transform: none; }
.bottle-fill.corked { animation: bottle-hop .5s; }
@keyframes bottle-in { from { transform: scale(0) rotate(-20deg); } }
@keyframes bottle-hop { 40% { transform: translateY(-14px) rotate(-6deg); } }
