:root {
  --bg: #58b8f7;
  --panel: #fff8e7;
  --text: #2a1a4a;
  --muted: #6b5c8a;
  --accent: #ffc928;
  --pink: #ff4f9a;
  --song: #ffd54f;
  --ink: #1a1f3d;
  --btn: clamp(42px, 7vmin, 60px);
  --pick: clamp(56px, 11vmin, 84px); /* a song's picture button */
  --top: calc(env(safe-area-inset-top, 0px) + 12px);
  --ctlw: calc(var(--btn) * 3 + 52px); /* room the corner buttons take on each side */
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 700;
}

body {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 8px 16px;
  font: 700 17px "Fredoka", "Nunito", system-ui, sans-serif;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 2px 3px 0 var(--ink);
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  transition: transform 0.08s ease;
}
.btn:active { transform: translate(2px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn:focus-visible { outline: 3px dashed var(--pink); outline-offset: 3px; }
.btn.primary { background: var(--accent); }
.btn.big { font-size: 20px; padding: 10px 34px; border-radius: 999px; }
.btn.giant { font-size: clamp(28px, 6vmin, 40px); padding: 12px 54px; border-radius: 999px; background: #5fd068; animation: beckon 1.1s ease-in-out infinite alternate; }
@keyframes beckon { from { transform: scale(1); } to { transform: scale(1.06); } }
.btn[aria-pressed="true"] { background: #5fd068; }
.btn.onoff { min-width: 76px; }
.btn.onoff[aria-pressed="false"] { background: #e6e1ee; color: var(--muted); }

/* ---------- stage ---------- */
.stage-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #58b8f7;
}
#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
#fx { position: absolute; inset: 0; pointer-events: none; }

.char { cursor: pointer; }
.char.dragging { cursor: grabbing; }
.prop-tap { cursor: pointer; }
.glow-flash, .pick-bubble { pointer-events: none; }

.tag { pointer-events: none; }
.tag rect { fill: rgba(255, 255, 255, 0.94); stroke: var(--ink); stroke-width: 2.5; }
.tag text { fill: var(--ink); font: 700 19px "Fredoka", "Nunito", system-ui, sans-serif; }
.tag-bass rect { fill: #cfe4ff; }
.tag-tenor rect { fill: #d3f5d6; }
.tag-alto rect { fill: #ffdcef; }
.tag-soprano rect { fill: #fff3bf; }

.pick-icon { font-size: 92px; }

.say text, .gang-say text { font: 700 22px "Fredoka", "Nunito", system-ui, sans-serif; fill: #c2185b; }
.gang-say rect, .gang-say path { fill: #fff; stroke: var(--ink); stroke-width: 2.5; }
.gang-say path { stroke-width: 0; }
.say { transition: opacity 0.15s ease; }
.jbox-q { font: 700 34px "Fredoka", system-ui, sans-serif; fill: #ec407a; }
.sign-txt { font: 700 11px "Fredoka", system-ui, sans-serif; fill: #fff; letter-spacing: 0.08em; }
.bag-txt { font-size: 20px; }
.emoji-txt { font-size: 34px; }
.tile-txt { font: 700 40px "Fredoka", system-ui, sans-serif; fill: #fff; paint-order: stroke; stroke: rgba(0, 0, 0, 0.25); stroke-width: 3px; }
.abc-txt { font: 700 28px "Fredoka", system-ui, sans-serif; fill: #fff; paint-order: stroke; stroke: rgba(0, 0, 0, 0.3); stroke-width: 3px; }
.coin-n { font: 800 12px "Nunito", system-ui, sans-serif; fill: #6d4c00; }
.num-txt { font: 700 34px "Fredoka", system-ui, sans-serif; fill: #5d4037; }
.tile rect { transition: fill 0.12s ease; }

/* ---------- the words: big dark letters on a white banner ---------- */
.lyrics {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(calc(100% - 2 * var(--ctlw)), 1000px); /* clear of the buttons on both sides */
  padding: 0.16em 0.7em 0.2em;
  text-align: center;
  pointer-events: none;
  font-family: "Fredoka", "Nunito", system-ui, sans-serif;
  font-weight: 700;
  font-size: clamp(20px, 4.8vmin, 42px);
  line-height: 1.4; /* room for the sung word to hop without touching the row above */
  color: var(--text);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 1em;
  box-shadow: 3px 4px 0 var(--ink);
}
.lyrics:empty { display: none; }
.lyrics span { display: inline-block; margin: 0 0.16em; transition: color 0.12s ease, transform 0.12s ease; }
.lyrics span.sung { color: #e0218a; }
.lyrics span.now { transform: translateY(-0.08em) scale(var(--pop, 1.14)); }
.lyrics.idle { font-size: clamp(18px, 3.8vmin, 32px); color: #5b2bb8; }

.hint {
  position: absolute;
  top: calc(30px + clamp(20px, 4.8vmin, 42px) * 2.6);
  left: 50%;
  transform: translate(-50%, -8px);
  width: max-content;
  max-width: min(92%, 560px);
  padding: 8px 18px;
  border-radius: 999px;
  background: #fff3bf;
  border: 2.5px solid var(--ink);
  font-size: 16px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.hint.show { opacity: 1; transform: translate(-50%, 0); }

/* Chunky hand-drawn corner buttons: help, stickers and grown-ups at the top left; play, sound and full screen at
   the top right. They sit above the panels so they work at any time. */
#controls, #tools {
  position: fixed;
  top: var(--top);
  display: flex;
  gap: 12px;
  z-index: 10;
}
#controls { right: calc(env(safe-area-inset-right, 0px) + 12px); }
#tools { left: calc(env(safe-area-inset-left, 0px) + 12px); }
#controls button, #tools button, #dice, .arrow {
  width: var(--btn);
  height: var(--btn);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--ink);
  border-radius: 50% 46% 52% 48%;
  box-shadow: 2px 3px 0 var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s;
}
#controls button:active, #tools button:active, #dice:active, .arrow:active { transform: translate(2px, 3px); box-shadow: 0 0 0 var(--ink); }
#controls button:focus-visible, #tools button:focus-visible, #dice:focus-visible, .arrow:focus-visible, .pick:focus-visible { outline: 3px dashed var(--pink); outline-offset: 3px; }
#controls button[hidden] { display: none; }
#btnPlay { background: #ffd166; transform: rotate(-4deg); }
#btnSound { background: #7fd0f0; transform: rotate(3deg); }
#btnFull { background: #9be08a; transform: rotate(-2deg); }
#controls svg { width: 58%; height: 58%; fill: none; stroke: var(--ink); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
#tools button { color: var(--ink); font: 700 calc(var(--btn) * 0.46) "Fredoka", "Nunito", system-ui, sans-serif; line-height: 1; }
#help-btn { background: #d7b8ff; transform: rotate(3deg); }
#book-btn { background: #fff3bf; transform: rotate(-3deg); }
#set-btn { background: #fff; transform: rotate(2deg); }

/* ---------- the songs: one row of big picture buttons ---------- */
.deck {
  flex: none;
  background: var(--panel);
  border-top: 3px solid var(--ink);
}
.prog { height: 7px; background: #e9dfc8; }
#prog-fill { height: 100%; width: 0; border-radius: 0 4px 4px 0; background: linear-gradient(90deg, #ff5a5f, #ff9f43, #ffd93d, #5fd068, #4dabf7, #b47cff); }
.deck-row { display: flex; align-items: center; gap: 8px; padding: 0 10px; }
#dice {
  flex: none;
  width: var(--pick);
  height: var(--pick);
  font-size: calc(var(--pick) * 0.56);
  line-height: 1;
  background: #ff8fc7;
  transform: rotate(-4deg);
}
#dice.spin { animation: spin 0.9s ease-out; }
@keyframes spin { to { transform: rotate(716deg); } }
.arrow { flex: none; width: 40px; height: 40px; background: #fff; color: var(--ink); font: 700 28px/1 "Fredoka", system-ui, sans-serif; padding-bottom: 4px; }
.arrow:disabled { opacity: 0.3; cursor: default; }
.ribbon {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  gap: 12px;
  padding: 12px 8px 13px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}
.ribbon::-webkit-scrollbar { display: none; }
.pick {
  --c: #ffd54f;
  position: relative;
  flex: none;
  width: var(--pick);
  height: var(--pick);
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--c);
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: 2px 3px 0 var(--ink);
  cursor: pointer;
  scroll-snap-align: center;
  touch-action: manipulation;
  transition: transform 0.15s ease;
}
.pick .ico { font-size: calc(var(--pick) * 0.54); line-height: 1; pointer-events: none; }
.pick .got { position: absolute; top: -8px; right: -7px; font-size: calc(var(--pick) * 0.28); display: none; pointer-events: none; }
.pick.earned .got { display: block; }
.pick:active { transform: translate(2px, 3px); box-shadow: 0 0 0 var(--ink); }
.pick.active { transform: scale(1.12); box-shadow: 0 0 0 4px #fff, 0 0 0 7px var(--ink); z-index: 1; }
body.playing .pick.active .ico { animation: hop 0.5s ease-in-out infinite alternate; }
@keyframes hop { from { transform: translateY(2px); } to { transform: translateY(-5px) rotate(-8deg); } }

/* ---------- panels ---------- */
.splash {
  position: fixed; inset: 0; z-index: 5; display: grid; place-items: center; padding: 14px; overflow-y: auto;
  background: rgba(40, 110, 190, 0.55);
}
.splash[hidden] { display: none; }
.splash-card {
  text-align: center; width: min(100%, 480px); margin: auto; padding: 20px 24px 18px; border-radius: 28px;
  background: #fff; border: 4px solid var(--ink); box-shadow: 5px 7px 0 var(--ink);
}
.splash-card h2 {
  margin: 0 0 10px; font-family: "Fredoka", system-ui, sans-serif; font-weight: 700; font-size: 38px; line-height: 1.05;
  color: #6a3de0; text-shadow: 2px 3px 0 #ffd93d;
}
.splash-card p { margin: 0 0 14px; color: var(--muted); font-size: 16px; }
.splash-card .small { margin: 12px 0 0; font-size: 13px; }
.splash-card .brand { margin: 6px 0 0; font-size: 12px; letter-spacing: 0.06em; opacity: 0.8; }
.splash-card .brand b { font-size: 15px; letter-spacing: 0.1em; color: #2d3a8c; }
.sky-brand { font: 700 40px "Fredoka", "Nunito", system-ui, sans-serif; fill: #2d3a8c; letter-spacing: 2px; }

/* Four monster faces peeking over the welcome card. */
.faces { display: flex; justify-content: center; gap: 10px; margin: -4px 0 8px; }
.faces .f { position: relative; width: 50px; height: 50px; border: 3px solid var(--ink); border-radius: 50%; animation: hop 0.6s ease-in-out infinite alternate; }
.faces .f::before, .faces .f::after { content: ""; position: absolute; top: 12px; width: 13px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 55% 55%, var(--ink) 0 3.2px, #fff 3.6px); border: 2px solid var(--ink); }
.faces .f::before { left: 6px; }
.faces .f::after { right: 6px; }
.faces .f0 { background: #3f8cff; }
.faces .f1 { background: #5fd068; border-radius: 22px 22px 16px 16px; height: 58px; margin-top: -8px; animation-delay: -0.15s; }
.faces .f1::before { left: 12px; top: 10px; width: 20px; height: 21px; background: radial-gradient(circle at 55% 55%, var(--ink) 0 5px, #fff 5.5px); }
.faces .f1::after { display: none; }
.faces .f2 { background: #ff8fc7; animation-delay: -0.3s; }
.faces .f3 { background: #ffd93d; width: 40px; height: 40px; margin-top: 4px; animation-delay: -0.45s; }
.faces .f3::before, .faces .f3::after { top: 9px; width: 11px; height: 12px; }
.faces .f3::before { left: 4px; }
.faces .f3::after { right: 4px; }

.tips { list-style: none; margin: 0 0 16px; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; font-size: 14.5px; line-height: 1.25; }
.tips li { display: grid; justify-items: center; gap: 6px; padding: 10px 4px; border-radius: 18px; background: #eef8ff; border: 2.5px solid #bfe3ff; }
.tips li:nth-child(2) { background: #fff3f9; border-color: #ffc9e3; }
.tips li:nth-child(3) { background: #f1fbe9; border-color: #c5ecab; }
.tips .pic { font-size: 40px; line-height: 1; }

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 9px; margin: 0 0 16px; }
.sticker {
  display: grid; justify-items: center; gap: 4px; padding: 9px 4px; border-radius: 16px;
  background: #f4f1f8; border: 2.5px dashed #cfc6e0;
  font: 600 12px/1.15 "Fredoka", system-ui, sans-serif; color: var(--muted);
}
.sticker .ico { font-size: 34px; filter: grayscale(1); opacity: 0.3; }
.sticker.got { background: #fff3bf; border: 2.5px solid #f0a800; color: var(--text); }
.sticker.got .ico { filter: none; opacity: 1; }

.set { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 14px; padding: 10px 12px; border-radius: 18px; background: #f6f2ff; text-align: left; flex-wrap: wrap; }
.set-name { flex: 1 1 150px; font: 700 18px "Fredoka", system-ui, sans-serif; }
.set-name small { display: block; margin-top: 2px; font: 600 12.5px/1.25 "Nunito", system-ui, sans-serif; color: var(--muted); }
.speeds { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; flex: 1 1 100%; }
.speeds .btn { flex-direction: column; gap: 0; padding: 6px 2px; font-size: 13px; min-height: 62px; }
.speeds .btn .ico { font-size: 26px; line-height: 1.1; }

/* phones */
@media (max-width: 640px) {
  #controls, #tools { gap: 9px; }
  #controls { right: calc(env(safe-area-inset-right, 0px) + 8px); }
  #tools { left: calc(env(safe-area-inset-left, 0px) + 8px); }
  .deck-row { gap: 6px; padding: 0 6px; }
  .arrow { display: none; }
  .ribbon { gap: 10px; padding: 10px 6px 11px; }
  .splash-card { padding: 16px 14px; border-radius: 22px; }
  .splash-card h2 { font-size: 30px; }
  .tips { gap: 6px; font-size: 12.5px; }
  .tips .pic { font-size: 32px; }
}
/* phones, upright or on their side: a finger on the sky slides the page up and down; the monsters still lift */
@media (max-width: 640px), (max-height: 560px) {
  #stage { touch-action: pan-y; }
  #stage .char, #stage .prop-tap { touch-action: none; }
}
/* phones: the stage is drawn small, so the monsters' names are made bigger */
.tag { transform-box: fill-box; transform-origin: 50% 0; }
@media (max-height: 560px) { .tag { transform: scale(1.35); } }
@media (max-width: 640px) { .tag { transform: scale(1.85); } }
/* tall phones: the stage fills the width at the bottom, so the words sit big in the sky just above the band */
@media (max-aspect-ratio: 4/5) {
  .lyrics { top: max(calc(var(--top) + var(--btn) + 12px), calc((100% - 60vw) / 2 - 1.6em)); max-width: calc(100% - 20px); font-size: clamp(22px, 7vw, 36px); }
  .lyrics.idle { font-size: clamp(18px, 5.4vw, 28px); }
  .hint { top: max(calc(var(--top) + var(--btn) + 76px), calc((100% - 60vw) / 2 + 2.6em)); }
}
/* short frames (a phone on its side, full screen on a phone): the stage keeps most of the height */
@media (max-height: 560px) {
  :root { --pick: 54px; }
  .ribbon { padding: 8px 6px 9px; }
  .prog { height: 5px; }
  .lyrics { font-size: clamp(18px, 6vmin, 30px); }
  .hint { top: calc(26px + clamp(18px, 6vmin, 30px) * 1.5); font-size: 14px; padding: 5px 14px; }
  .splash-card { padding: 10px 18px; width: min(100%, 560px); }
  .splash-card h2 { font-size: 26px; margin-bottom: 6px; }
  .faces { display: none; }
  .tips { margin-bottom: 10px; }
  .tips li { padding: 6px 4px; grid-template-columns: auto auto; align-items: center; justify-content: center; }
  .tips .pic { font-size: 28px; }
  .btn.giant { font-size: 24px; padding: 8px 44px; }
  .set { margin-bottom: 8px; padding: 6px 10px; }
  .speeds .btn { min-height: 48px; flex-direction: row; gap: 6px; }
  .splash-card .small { margin-top: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  body.playing .pick.active .ico, .btn.giant, .faces .f, #dice.spin { animation: none; }
}

/* Songs with their own sun, moon or rain cloud in the sky: the meadow's sun fades out for them. */
.sky-sun { transition: opacity 0.5s; }
#stage[data-prop="stars"] .sky-sun, #stage[data-prop="spider"] .sky-sun, #stage[data-prop="diddle"] .sky-sun, #stage[data-prop="bells"] .sky-sun,
#stage[data-prop="mulberry"] .sky-sun, #stage[data-prop="cradle"] .sky-sun, #stage[data-prop="clouds"] .sky-sun, #stage[data-prop="ants"] .sky-sun { opacity: 0; }
