:root {
  --ink: #2a1f3d;
  --sky: #bfe7ff;
  --grass: #b2f2bb;
  --green: #40c057;
  --card: #fff;
  --shadow: 0 6px 0 rgba(42, 31, 61, 0.14);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Fredoka', ui-rounded, system-ui, sans-serif;
  font-weight: 600;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 12%, #fff8 0 40px, transparent 41px),
    radial-gradient(circle at 80% 20%, #fff6 0 60px, transparent 61px),
    linear-gradient(var(--sky), #e7f6ff 62%, var(--grass) 62.2%, #8ce99a);
  background-attachment: fixed;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}
button:active { transform: scale(0.94); }

#app { height: 100dvh; }
.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

/* --- Buttons --- */
.icon-btn {
  width: 52px; height: 52px; flex: none;
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 26px;
  display: grid; place-items: center;
}
.big-btn {
  min-width: 140px; height: 84px;
  padding: 0 34px;
  border-radius: 30px;
  background: var(--pc, var(--green));
  color: #fff;
  font-size: 40px;
  box-shadow: 0 8px 0 rgba(42, 31, 61, 0.25);
  text-shadow: 0 2px 0 rgba(42, 31, 61, 0.25);
}
.big-btn:disabled { opacity: 0.35; }

/* --- Monster --- */
.monster-wrap { display: grid; place-items: center; }
.monster-wrap > svg { grid-area: 1 / 1; width: 100%; height: 100%; overflow: visible; }

.eye { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.1); } }
.pupil { animation: look 7s ease-in-out infinite; }
@keyframes look {
  0%, 20% { transform: translate(0, 0); } 30%, 45% { transform: translate(4px, 1px); }
  55%, 70% { transform: translate(-4px, -1px); } 80%, 100% { transform: translate(0, 0); }
}
.arm-l { animation: wave-l 1.6s ease-in-out infinite alternate; }
.arm-r { animation: wave-r 1.6s ease-in-out infinite alternate; }
@keyframes wave-l { from { transform: rotate(14deg); } to { transform: rotate(-16deg); } }
@keyframes wave-r { from { transform: rotate(-14deg); } to { transform: rotate(16deg); } }
.wig { transform-box: fill-box; transform-origin: top center; animation: wig 0.9s ease-in-out infinite alternate; }
@keyframes wig { from { transform: rotate(-7deg); } to { transform: rotate(7deg); } }
.wob { transform-box: fill-box; transform-origin: bottom center; animation: wig 1.3s ease-in-out infinite alternate; }
.spin { animation: spin 1.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.flame { animation: flicker 0.14s infinite alternate; }
@keyframes flicker { from { transform: scaleY(0.75); } to { transform: scaleY(1.1); } }
.boing { transform-box: fill-box; transform-origin: top center; animation: springy 0.5s ease-in-out infinite alternate; }
@keyframes springy { from { transform: scaleY(0.85); } to { transform: scaleY(1.04); } }

.chatter { animation: chatter 0.25s ease-in-out infinite alternate; }
@keyframes chatter { to { transform: translateY(4px); } }
.blinky { animation: blinky 0.9s steps(1) infinite; }
@keyframes blinky { 50% { opacity: 0.25; } }
.cape { transform-box: fill-box; transform-origin: top center; animation: cape 1.1s ease-in-out infinite alternate; }
@keyframes cape { from { transform: skewX(-5deg); } to { transform: skewX(5deg); } }
.float { animation: float 1.8s ease-in-out infinite alternate; }
@keyframes float { to { transform: translateY(-5px); } }

/* A part just picked drops into place. */
.slot.drop { animation: drop 0.55s cubic-bezier(0.3, 1.6, 0.5, 1) both; }
.slot-feet.drop { animation-name: rise; }
@keyframes drop { from { transform: translateY(-90px); opacity: 0; } }
@keyframes rise { from { transform: translateY(60px); opacity: 0; } }

/* Reveal: the monster assembles bottom-up, then dances. */
.assemble .slot-feet { animation: rise 0.5s 0.1s cubic-bezier(0.3, 1.6, 0.5, 1) both; }
.assemble .slot-body { animation: drop 0.5s 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) both; }
.assemble .slot-head { animation: drop 0.5s 0.8s cubic-bezier(0.3, 1.6, 0.5, 1) both; }
.dance > svg { animation: hop 0.62s ease-in-out infinite; transform-origin: 50% 100%; }
.dance .slot-head .part { animation: bob 0.62s ease-in-out infinite alternate; transform-origin: 100px 140px; }
.dance .slot-body .part { animation: sway 1.24s ease-in-out infinite alternate; transform-origin: 100px 245px; }
@keyframes hop {
  0%, 100% { transform: translateY(0) scale(1.04, 0.96); }
  50% { transform: translateY(-5%) scale(0.97, 1.03); }
}
@keyframes bob { from { transform: rotate(-7deg); } to { transform: rotate(7deg); } }
@keyframes sway { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
.happy > svg { animation: jumpy 0.5s ease-in-out 4; transform-origin: 50% 100%; }
@keyframes jumpy {
  0%, 100% { transform: translateY(0) scale(1.06, 0.94); }
  50% { transform: translateY(-14%) rotate(4deg) scale(0.96, 1.05); }
}
.flying { position: fixed; z-index: 50; pointer-events: none; overflow: visible; }

/* --- Home --- */
.home { align-items: center; justify-content: space-evenly; gap: 6px; position: relative; }
.corner { position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(14px, env(safe-area-inset-right)); }
.title {
  margin: 0;
  font-size: clamp(44px, 11vw, 84px);
  line-height: 0.9;
  font-weight: 700;
  text-align: center;
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
  transform: rotate(-3deg);
}
.title span { display: block; }
.title span:first-child { color: #ff6b6b; }
.title span:last-child { color: #ffd43b; }
.demo { height: min(32vh, 300px); aspect-ratio: 28 / 30; }
.who { margin: 0; font-size: 26px; }
.avatars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.avatar {
  position: relative;
  width: clamp(76px, 22vw, 104px); aspect-ratio: 1;
  border-radius: 28px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: clamp(42px, 12vw, 58px);
  display: grid; place-items: center;
  opacity: 0.6;
  transition: opacity 0.15s, transform 0.15s;
}
.avatar.on { opacity: 1; background: var(--pc); box-shadow: 0 0 0 5px #fff, 0 8px 0 5px rgba(42, 31, 61, 0.18); transform: scale(1.06); }
.badge, .order {
  position: absolute;
  font-style: normal;
  font-size: 17px;
  min-width: 30px; height: 30px; padding: 0 6px;
  border-radius: 15px;
  display: grid; place-items: center;
}
.badge { right: -6px; top: -6px; background: #ffd43b; border: 3px solid var(--ink); }
.order { left: -6px; top: -6px; background: #fff; border: 3px solid var(--ink); }

/* --- Top bar --- */
.topbar { display: flex; align-items: center; gap: 10px; }
.chips { flex: 1; display: flex; justify-content: center; gap: 8px; min-width: 0; }
.chip {
  display: flex; align-items: center; gap: 4px;
  height: 52px; padding: 0 12px 0 6px;
  border-radius: 26px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 30px;
  opacity: 0.55;
}
.chip b { font-size: 20px; min-width: 18px; }
.chip.now { opacity: 1; background: var(--pc); box-shadow: 0 0 0 4px #fff, var(--shadow); }
.chip.bump { animation: bump 0.4s; }
@keyframes bump { 50% { transform: scale(1.35); } }

/* --- Turn card --- */
.turn { align-items: center; justify-content: center; gap: 20px; background: color-mix(in srgb, var(--pc) 35%, transparent); }
.turn-emoji { font-size: min(40vw, 220px); line-height: 1; animation: hop 0.8s ease-in-out infinite; }
.turn h2 { margin: 0; font-size: clamp(40px, 10vw, 72px); text-align: center; }

/* --- Build --- */
.stage { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; padding: 8px 0; }
.stage .monster-wrap { width: 100%; height: 100%; min-height: 0; }
.ghost rect { fill: #ffffff55; stroke: #fff; stroke-width: 5; stroke-dasharray: 14 12; animation: pulse 1.2s ease-in-out infinite alternate; }
.ghost text { fill: #fff; font-size: 54px; font-weight: 700; text-anchor: middle; font-family: 'Fredoka', sans-serif; }
@keyframes pulse { from { opacity: 0.5; } to { opacity: 1; } }
.undo { position: absolute; left: 0; bottom: 8px; }
.prompt { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 26px; padding-bottom: 8px; }
.steps { display: flex; gap: 8px; }
.steps i { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--ink); opacity: 0.4; }
.steps i.done { background: var(--green); opacity: 1; }
.steps i.now { background: #ffd43b; opacity: 1; transform: scale(1.3); }
.options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.card {
  aspect-ratio: 1.1;
  min-height: 0;
  border-radius: 26px;
  background: var(--card);
  box-shadow: var(--shadow);
  padding: 8px;
  display: grid; place-items: center;
  animation: cardIn 0.4s cubic-bezier(0.3, 1.5, 0.5, 1) both;
}
.card svg { width: 100%; height: 100%; }
.card.chosen { animation: chosen 0.25s forwards; }
@keyframes cardIn { from { transform: translateY(40px) scale(0.6); opacity: 0; } }
@keyframes chosen { to { transform: scale(1.15); box-shadow: 0 0 0 6px #ffd43b, var(--shadow); } }

/* --- Reveal & name --- */
.name-area { min-height: 120px; display: grid; place-items: center; }
.name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; }
.syl {
  display: flex;
  padding: 2px 16px 6px;
  border-radius: 24px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.syl.heard { animation: heard 0.5s; }
@keyframes heard { 40% { transform: scale(1.12); background: #fff3bf; } }
.l, .hy { font-size: clamp(56px, 15vw, 116px); line-height: 1.1; font-weight: 700; }
.hy { opacity: 0.45; }
.l { display: inline-block; animation: popIn 0.35s cubic-bezier(0.3, 1.8, 0.5, 1) both; }
@keyframes popIn { from { transform: scale(0) rotate(-20deg); opacity: 0; } }
.name.jump .l { animation: letterJump 0.5s ease-in-out 3; }
.name.jump .l:nth-child(2n) { animation-delay: 0.1s; }
@keyframes letterJump { 50% { transform: translateY(-22px); color: #f03e3e; } }

.judge { min-height: 110px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; }
.hint { margin: 0; font-size: 14px; font-weight: 500; opacity: 0.6; text-align: center; }
.judge-row { display: flex; gap: 14px; align-items: center; animation: cardIn 0.4s both; }
.rename { width: 64px; height: 64px; font-size: 30px; }
.next { min-width: 200px; }

/* --- Confetti --- */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
.confetti i {
  position: absolute; top: -20px;
  width: 12px; height: 18px; border-radius: 3px;
  animation: fall 2.4s linear both;
}
.confetti i.star { width: auto; height: auto; font-size: 30px; font-style: normal; -webkit-text-stroke: 1.5px var(--ink); }
@keyframes fall {
  to { transform: translate(var(--x), 105vh) rotate(var(--r)); }
}

/* --- Modals --- */
.modal {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(42, 31, 61, 0.45);
  display: grid; place-items: center;
  padding: 16px;
  animation: fade 0.2s;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: min(680px, 100%);
  max-height: 100%;
  overflow: auto;
  background: #fff;
  border-radius: 30px;
  padding: 18px;
  animation: cardIn 0.3s both;
}
.sheet header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sheet h2 { flex: 1; margin: 0; font-size: 28px; }
.zoo { background: color-mix(in srgb, var(--pc) 22%, #fff); }
.zoo-emoji { font-size: 44px; }
.zoo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.zoo-item {
  background: #fff;
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 8px;
  display: flex; flex-direction: column; align-items: center;
  font-size: 22px;
}
.zoo-item .monster-wrap { width: 100%; aspect-ratio: 28 / 30; }
.empty { font-size: 22px; text-align: center; padding: 30px 0; }

.settings .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 2px solid #f1f3f5; font-size: 18px; }
.seg { display: flex; background: #f1f3f5; border-radius: 14px; padding: 4px; flex: none; }
.seg button { padding: 8px 14px; border-radius: 10px; font-size: 17px; }
.seg button.on { background: var(--green); color: #fff; }
.note { font-size: 14px; font-weight: 500; opacity: 0.7; }
.danger { margin-top: 10px; padding: 12px 16px; border-radius: 14px; background: #fff0f0; color: #c92a2a; font-size: 16px; }

/* Sideways phone or tablet: options go next to the stage. */
@media (min-aspect-ratio: 5/4) {
  .build, .reveal {
    display: grid;
    grid-template-columns: 1fr minmax(0, 1.1fr);
    grid-template-rows: auto 1fr auto auto 1fr;
    column-gap: 20px;
  }
  .build .topbar, .reveal .topbar { grid-column: 1 / -1; }
  .build .stage, .reveal .stage { grid-row: 2 / 6; }
  .build .prompt, .reveal .name-area { grid-column: 2; grid-row: 3; }
  .build .options, .reveal .judge { grid-column: 2; grid-row: 4; }
  .build .card { aspect-ratio: 0.9; }
  .home { flex-direction: row; flex-wrap: wrap; align-content: center; column-gap: 30px; }
  .home .demo { height: 50vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
