:root {
  --bg: #fff8d6;
  --yellow: #ffe45c;
  --yellow-soft: #fff27a;
  --ink: #3a2e1f;
  --accent: #ff8a3b;
  --green: #5cb85c;
  --card: #ffffff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
/* no double-tap zoom while tapping the keypad fast; pinch zoom still works */
html, body, button { touch-action: manipulation; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: radial-gradient(circle at 20% 10%, #fffbe8, transparent 40%), radial-gradient(circle at 80% 90%, #fff0a8, transparent 45%), var(--bg);
  color: var(--ink);
  font-family: 'Fredoka', 'Arial Rounded MT Bold', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }

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

/* ---------- start ---------- */
#start { justify-content: center; gap: 12px; text-align: center; }
h1 { color: #16c8e8; font-size: clamp(2rem, 7vw, 3.6rem); margin: 0; text-shadow: 0 3px 0 #fff; }
.paint {
  width: min(70vw, 42dvh, 320px); aspect-ratio: 1;
  background: var(--yellow-soft);
  border-radius: 38% 44% 40% 46% / 44% 38% 46% 40%;
  box-shadow: 0 0 0 10px #fff58f, 0 0 40px 10px #fff27a;
  display: grid; place-items: center;
}
.title-svg { width: 85%; }
.lead { font-size: 1.3rem; margin: 8px 0; }
.subtitle { font-size: clamp(1.1rem, 3.5vw, 1.5rem); font-weight: 700; margin: -4px 0 4px; opacity: .75; }
#title-paint { cursor: pointer; }
.byline { margin: 0 0 4px; font-size: 1.05rem; font-weight: 700; color: var(--accent); }
.music-hint { background: #fff; border-radius: 99px; padding: 6px 16px; font-size: 1rem; box-shadow: 0 3px 0 #e6d38a; animation: nudge 1.4s ease-in-out infinite; }
@keyframes nudge { 50% { transform: scale(1.08); } }
.levels { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; width: min(100%, 420px); }
.levels button, .big {
  background: var(--yellow); border-radius: 18px; padding: 14px 18px; font-size: 1.5rem; font-weight: 700;
  box-shadow: 0 5px 0 #d9b400; transition: transform .1s;
}
.levels button:active, .big:active, .keypad button:active { transform: translateY(4px); box-shadow: 0 1px 0 #d9b400; }
.big { background: var(--accent); color: #fff; box-shadow: 0 5px 0 #c9621c; margin-top: 8px; }
.round {
  width: 48px; height: 48px; border-radius: 50%; background: #fff; font-size: 1.4rem;
  box-shadow: 0 3px 0 #e6d38a;
}
#mute { position: fixed; top: 12px; right: 12px; z-index: 5; }
#share { position: fixed; top: 12px; right: 70px; z-index: 5; display: grid; place-items: center; color: var(--ink); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 1.1rem; opacity: 0; transition: .25s; pointer-events: none; z-index: 10; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- game ---------- */
#game {
  display: grid; gap: 12px; width: 100%; max-width: 1200px; margin: 0 auto; align-content: start;
  grid-template-columns: 1fr; grid-template-areas: "head" "stage" "panel" "next";
}
header { grid-area: head; display: flex; align-items: center; gap: 12px; padding-right: 120px; }
header > div:first-of-type { flex: 1; }
#chapter { font-size: .95rem; opacity: .7; }
h2 { margin: 0; font-size: clamp(1.3rem, 4vw, 2rem); }
#dots { display: flex; gap: 8px; }
.dot { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid var(--yellow); }
.dot.done { background: var(--green); border-color: #3d913d; animation: pop .4s; }

.stage-wrap { grid-area: stage; }
.stage {
  width: 100%; display: block; background: #fff; border-radius: 22px;
  border: 10px solid var(--yellow-soft); box-shadow: 0 0 0 4px #fff, 0 8px 24px rgba(160, 120, 0, .25);
}
#story { font-size: 1.25rem; text-align: center; margin: 10px 0 0; min-height: 1.6em; }

#panel { grid-area: panel; display: flex; flex-direction: column; align-items: center; gap: 8px; }
#som {
  background: var(--card); border-radius: 20px; padding: 10px 26px; font-size: clamp(2.2rem, 8vw, 3.4rem); font-weight: 700;
  box-shadow: 0 5px 0 #eadca0; white-space: nowrap;
}
.answer { display: inline-block; min-width: 1.6em; padding: 0 .2em; border-bottom: 5px solid var(--accent); color: var(--accent); text-align: center; }
#hint { min-height: 1.5em; font-size: 1.2rem; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(100%, 330px); }
.keypad button {
  background: #fff; border-radius: 16px; font-size: 1.9rem; font-weight: 700; padding: 10px 0;
  box-shadow: 0 5px 0 #e6d38a;
}
.keypad .ok { background: var(--green); color: #fff; box-shadow: 0 5px 0 #3d913d; }
.keypad .del { background: #ffe0cc; }
#next { grid-area: next; justify-self: center; font-size: 1.8rem; }

/* phones: everything (scene, som, keypad) fits on one screen without scrolling */
@media (max-width: 600px) {
  .screen { padding: 8px 10px; }
  #start { gap: 8px; }
  .round { width: 40px; height: 40px; font-size: 1.15rem; }
  #mute { top: 8px; right: 8px; }
  #share { top: 8px; right: 54px; }
  #game { gap: 6px; }
  header { gap: 8px; padding-right: 94px; min-height: 40px; }
  header > div:first-of-type { min-width: 0; }
  #chapter { font-size: .75rem; white-space: nowrap; }
  h2 { font-size: 1.05rem; line-height: 1.15; }
  #dots { gap: 4px; }
  .dot { width: 14px; height: 14px; border-width: 2px; }
  .stage { border-width: 6px; border-radius: 16px; box-shadow: 0 0 0 3px #fff, 0 4px 12px rgba(160, 120, 0, .2); }
  #story { font-size: 1rem; margin-top: 6px; min-height: 2.4em; line-height: 1.2; }
  #panel { gap: 4px; }
  #som { font-size: 2rem; padding: 4px 20px; border-radius: 16px; box-shadow: 0 4px 0 #eadca0; }
  #hint { font-size: 1rem; min-height: 1.3em; }
  .keypad { gap: 6px; width: min(100%, 320px); }
  .keypad button { font-size: 1.5rem; padding: 0; height: clamp(40px, 7dvh, 54px); border-radius: 12px; }
  #next { font-size: 1.4rem; }
}

/* small phones (e.g. iPhone SE): a little tighter still */
@media (max-width: 600px) and (max-height: 620px) {
  .screen { padding: 6px 10px; }
  #game, #panel { gap: 4px; }
  #story { font-size: .9rem; margin-top: 4px; min-height: 2.3em; }
  #som { font-size: 1.7rem; padding: 2px 18px; }
  #hint { font-size: .9rem; min-height: 1.15em; }
  .keypad { gap: 4px; }
  .keypad button { height: clamp(34px, 6.5dvh, 48px); font-size: 1.35rem; }
}

@media (min-width: 900px) and (min-aspect-ratio: 4/3) {
  #game { grid-template-columns: 1fr 340px; grid-template-areas: "head head" "stage panel" "stage next"; align-items: start; }
  #panel { margin-top: 20px; }
}

/* ---------- finale ---------- */
#finale { justify-content: center; text-align: center; gap: 16px; overflow: hidden; position: relative; }
#finale-stage { max-width: 900px; }
#confetti { position: fixed; inset: 0; pointer-events: none; }
#confetti i { position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px; animation: fall linear infinite; }

/* ---------- animations ---------- */
.shake { animation: shake .45s; }
.panda .p-body { animation: breathe 3.2s ease-in-out infinite; }
.panda .p-eye { animation: blink 4.5s infinite; }
.panda.sleep .p-eye { animation: none; transform: scaleY(.12); }
.drift { animation: drift 18s ease-in-out infinite alternate; }
.flow { animation: flow .6s linear infinite; }
.foam { animation: foam 1s ease-in-out infinite alternate; }
.wheel.spin { animation: spin .4s linear infinite; }
.siren.flash { animation: flash .4s steps(2) infinite; }
.twinkle { animation: twinkle 2s ease-in-out infinite alternate; }
.ripple { animation: ripple 2s ease-out infinite; transform-box: fill-box; transform-origin: center; }
.pulse { animation: pulse 1.2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }

@keyframes breathe { 50% { transform: scale(1.015, .985); } }
@keyframes blink { 0%, 93%, 100% { transform: none; } 96% { transform: scaleY(.1); } }
@keyframes drift { to { transform: translateX(80px); } }
@keyframes flow { to { stroke-dashoffset: -54; } }
@keyframes foam { to { opacity: .4; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes flash { 50% { opacity: .3; } }
@keyframes twinkle { to { opacity: .3; } }
@keyframes ripple { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
@keyframes pulse { 50% { transform: scale(1.08); } }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
@keyframes pop { 50% { transform: scale(1.4); } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) {
  .drift, .flow, .twinkle, #confetti i { animation: none; }
}
