:root {
  --ink: #5b2333;
  --pink: #ff7eb6;
  --pink-d: #ff4f98;
  --mint: #7fe3c4;
  --lemon: #fff07a;
  --lav: #c7a8ff;
  --sky: #8fd6ff;
  --cream: #fff7fb;
  --title: 'Mochiy Pop One', 'Baloo 2', system-ui, sans-serif;
  --body: 'Baloo 2', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--body);
  color: var(--ink);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(rgba(255, 255, 255, .55) 2px, transparent 2.6px) 0 0 / 20px 20px,
    linear-gradient(160deg, #ffd3ea 0%, #eadcff 55%, #d3f3ff 100%);
}
button { font-family: inherit; color: inherit; cursor: pointer; }
canvas { display: block; }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0;
  display: none; flex-direction: column; align-items: center;
  padding: 16px; overflow: hidden;
}
.screen.active { display: flex; animation: screen-in .35s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: scale(.97); } }

.screen-header {
  position: relative; z-index: 2;
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 14px;
  min-height: 64px; margin-bottom: 10px;
}
.back-btn { position: absolute; left: 0; top: 50%; transform: translateY(-50%); }

/* ---------- shared bits ---------- */
.round-btn {
  width: 54px; height: 54px; border-radius: 50%;
  border: 4px solid var(--ink); background: #fff; font-size: 24px;
  box-shadow: 0 5px 0 var(--ink);
  display: grid; place-items: center; padding: 0;
  transition: transform .1s, box-shadow .1s;
}
.round-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.back-btn:active { transform: translateY(calc(-50% + 4px)); }
#mute-btn { position: fixed; top: 16px; right: 16px; z-index: 50; }

.big-btn {
  font-family: var(--title);
  font-size: clamp(22px, 3vw, 34px);
  color: #fff;
  padding: 12px 34px;
  border: 4px solid var(--ink); border-radius: 26px;
  background: linear-gradient(180deg, #ff9cc9 0%, var(--pink-d) 100%);
  box-shadow: 0 7px 0 var(--ink), inset 0 4px 0 rgba(255, 255, 255, .5);
  text-shadow: 2px 2px 0 var(--ink);
  transition: transform .1s, box-shadow .1s;
}
.big-btn:active { transform: translateY(6px); box-shadow: 0 1px 0 var(--ink), inset 0 4px 0 rgba(255, 255, 255, .5); }
.big-btn:disabled { filter: grayscale(.8) opacity(.6); cursor: default; }
.big-btn.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.07); } }

.small-btn {
  font-family: var(--title); font-size: 18px;
  padding: 8px 16px; border-radius: 18px;
  border: 3px solid var(--ink); background: #fff;
  box-shadow: 0 4px 0 var(--ink);
}
.small-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

.bubble {
  font-family: var(--title);
  font-size: clamp(20px, 3vw, 32px);
  background: #fff; border: 4px solid var(--ink); border-radius: 999px;
  padding: 6px 28px; box-shadow: 6px 6px 0 var(--ink);
  position: relative; text-align: center;
}
.bubble::after {
  content: '★'; position: absolute; right: -14px; top: -16px;
  color: var(--lemon); font-size: 30px; -webkit-text-stroke: 2px var(--ink);
  animation: twinkle 1.6s ease-in-out infinite;
}
@keyframes twinkle { 50% { transform: scale(.7) rotate(30deg); } }

.manga-title {
  font-family: var(--title);
  font-size: clamp(48px, 9vw, 110px);
  line-height: .95; margin: 8px 0;
  color: #fff;
  -webkit-text-stroke: 10px var(--ink);
  paint-order: stroke fill;
  text-shadow: 7px 7px 0 var(--pink-d), 7px 7px 0 var(--ink);
  transform: rotate(-4deg);
}
.manga-title.small { font-size: clamp(36px, 6vw, 64px); }

.speed-lines {
  position: absolute; inset: -50%;
  background: repeating-conic-gradient(from 0deg at 50% 50%, rgba(255, 255, 255, .45) 0 3deg, transparent 3deg 11deg);
  animation: spin 60s linear infinite;
  pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.boing { animation: boing .45s ease; }
@keyframes boing {
  30% { transform: scale(1.08, .92); }
  60% { transform: scale(.95, 1.05); }
}

/* ---------- 1. intro ---------- */
#screen-intro { justify-content: center; }
.intro-card { position: relative; z-index: 1; text-align: center; display: flex; flex-direction: column; align-items: center; }
.kicker {
  font-family: var(--title); font-size: clamp(14px, 2vw, 20px);
  background: var(--lemon); border: 3px solid var(--ink); border-radius: 999px;
  padding: 4px 18px; box-shadow: 4px 4px 0 var(--ink); transform: rotate(3deg);
}
.intro-sub {
  font-size: clamp(18px, 2.4vw, 26px); font-weight: 800;
  background: rgba(255, 255, 255, .85); border: 3px solid var(--ink);
  border-radius: 20px; padding: 6px 18px; margin: 18px 0 26px;
}
.credit {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 1;
  white-space: nowrap; font-size: clamp(14px, 1.8vw, 20px); font-weight: 700;
  background: rgba(255, 255, 255, .85); border: 3px solid var(--ink); border-radius: 999px;
  padding: 4px 18px; box-shadow: 4px 4px 0 var(--ink);
}
.credit strong { font-family: var(--title); font-weight: 400; color: var(--pink-d); }
.floaties span {
  position: absolute; font-size: clamp(40px, 6vw, 72px);
  filter: drop-shadow(3px 3px 0 rgba(91, 35, 51, .35));
  animation: floaty 3.4s ease-in-out infinite;
}
.floaties span:nth-child(1) { left: 8%; top: 14%; }
.floaties span:nth-child(2) { left: 84%; top: 12%; animation-delay: -.6s; }
.floaties span:nth-child(3) { left: 12%; top: 70%; animation-delay: -1.2s; }
.floaties span:nth-child(4) { left: 80%; top: 72%; animation-delay: -1.8s; }
.floaties span:nth-child(5) { left: 26%; top: 84%; animation-delay: -2.2s; }
.floaties span:nth-child(6) { left: 66%; top: 86%; animation-delay: -.3s; }
.floaties span:nth-child(7) { left: 30%; top: 8%; animation-delay: -1.5s; }
.floaties span:nth-child(8) { left: 66%; top: 6%; animation-delay: -2.6s; }
@keyframes floaty { 50% { transform: translateY(-18px) rotate(12deg); } }

/* ---------- 2. choose candy ---------- */
.candy-grid {
  flex: 1; width: min(1100px, 100%);
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px;
  align-content: center;
}
.candy-card {
  background: #fff; border: 4px solid var(--ink); border-radius: 28px;
  box-shadow: 0 7px 0 var(--ink);
  padding: 10px 10px 6px; display: flex; flex-direction: column; align-items: center;
  animation: pop-in .4s backwards;
  transition: transform .15s;
}
.candy-card:nth-child(3n+1) { background: #ffe4f1; }
.candy-card:nth-child(3n+2) { background: #e2f8ff; }
.candy-card:nth-child(3n) { background: #fff8d6; }
.candy-card:hover { transform: translateY(-4px) rotate(-1.5deg); }
.candy-card:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.candy-card canvas { width: min(26vh, 22vw); height: auto; aspect-ratio: 1; }
.candy-card span { font-family: var(--title); font-size: clamp(18px, 2.4vw, 26px); }
@keyframes pop-in { from { transform: scale(.4); opacity: 0; } }

/* ---------- 3. decorate ---------- */
.decorate-layout {
  flex: 1; width: 100%; min-height: 0;
  display: grid; grid-template-columns: 160px 1fr 220px; gap: 16px; align-items: center;
}
.tools { display: flex; flex-direction: column; gap: 14px; }
.tool-btn {
  font-family: var(--title); font-size: 17px;
  display: flex; flex-direction: column; align-items: center;
  padding: 10px 6px; border-radius: 22px;
  border: 4px solid var(--ink); background: #fff; box-shadow: 0 5px 0 var(--ink);
  transition: transform .1s;
}
.tool-ico { font-size: 40px; line-height: 1.1; }
.tool-btn.selected { background: var(--lemon); transform: scale(1.06) rotate(-2deg); }
.tool-btn:nth-child(2).selected { background: var(--sky); }
.tool-btn:nth-child(3).selected { background: #f0c7a4; }

.stage { display: flex; flex-direction: column; align-items: center; gap: 10px; min-height: 0; }
.hint {
  font-weight: 800; font-size: clamp(16px, 2vw, 22px);
  background: #fff; border: 3px solid var(--ink); border-radius: 16px; padding: 4px 16px;
}
.canvas-wrap {
  position: relative;
  width: min(62vh, 44vw); aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, #fff 55%, rgba(255, 255, 255, 0) 70%);
}
#decor-canvas { width: 100%; height: 100%; touch-action: none; cursor: pointer; }
.fx-layer { position: absolute; inset: 0; pointer-events: none; }
.fx {
  position: absolute; font-size: 26px; transform: translate(-50%, -50%);
  animation: fx .8s ease-out forwards;
}
@keyframes fx {
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.3); opacity: 0; }
}

.side { display: flex; flex-direction: column; gap: 22px; align-items: center; }
.palette {
  display: grid; grid-template-columns: repeat(2, 64px); gap: 12px;
  background: #fff; border: 4px solid var(--ink); border-radius: 26px; padding: 14px;
  box-shadow: 5px 5px 0 var(--ink);
}
.swatch {
  width: 64px; height: 64px; border-radius: 50%;
  border: 4px solid var(--ink); padding: 0;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .15), inset 0 5px 0 rgba(255, 255, 255, .5);
  transition: transform .12s;
}
.swatch.selected { transform: scale(1.15); outline: 4px dashed var(--pink-d); outline-offset: 3px; }
.swatch.rainbow { background: conic-gradient(#ff5fa2, #ffd23f, #7be495, #5ec8ff, #c08bff, #ff5fa2); }
.swatch.gold { background: radial-gradient(circle at 35% 35%, #fff6b0, #ffd23f 45%, #e0a800); }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }

/* ---------- 4/5. people ---------- */
.people-layout {
  flex: 1; width: 100%; min-height: 0;
  display: grid; grid-template-columns: 260px 1fr; gap: 16px;
}
.preview-panel {
  background: #fff; border: 4px solid var(--ink); border-radius: 28px; box-shadow: 6px 6px 0 var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px;
}
.preview-stage { display: flex; align-items: flex-end; justify-content: center; gap: 4px; min-height: 230px; }
.preview-sprite canvas { width: 96px; height: auto; }
.preview-candy { width: 110px; height: 110px; display: none; }
.recipient-mode .preview-candy { display: block; animation: floaty 2.4s ease-in-out infinite; }
.preview-name { font-family: var(--title); font-size: 26px; text-align: center; }
.preview-panel .big-btn { font-size: 20px; padding: 10px 18px; }

.people-grid {
  overflow-y: auto; min-height: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 10px;
  padding: 6px 10px 20px 4px;
  -webkit-overflow-scrolling: touch;
}
.person-card {
  position: relative;
  border: 3px solid var(--ink); border-radius: 18px; background: #fff;
  box-shadow: 0 4px 0 var(--ink);
  display: flex; flex-direction: column; align-items: center; padding: 6px 2px 2px;
  transition: transform .12s;
}
.person-card:nth-child(4n+1) { background: #ffe9f4; }
.person-card:nth-child(4n+2) { background: #e9f8ff; }
.person-card:nth-child(4n+3) { background: #fffbe0; }
.person-card:nth-child(4n) { background: #efe6ff; }
.person-card canvas { width: 46px; height: auto; }
.person-name { font-weight: 800; font-size: 14px; }
.person-card:hover { transform: translateY(-3px); }
.person-card.selected { background: var(--lemon); transform: scale(1.08); outline: 4px dashed var(--pink-d); outline-offset: 2px; z-index: 1; }
.person-card.is-you { filter: grayscale(.9) opacity(.55); cursor: not-allowed; }
.you-tag {
  display: none; position: absolute; top: 4px; left: 50%; transform: translateX(-50%) rotate(-8deg);
  background: var(--pink-d); color: #fff; font-family: var(--title); font-size: 12px;
  border: 2px solid var(--ink); border-radius: 8px; padding: 0 6px; z-index: 1;
}
.is-you .you-tag { display: block; }

/* ---------- 6. map ---------- */
.map-header { margin-bottom: 8px; }
.hud-candy { width: 60px; height: 60px; animation: floaty 2.4s ease-in-out infinite; }
.map-outer { flex: 1; min-height: 0; width: 100%; display: grid; place-items: center; }
.map {
  position: relative;
  width: min(96vw, calc((100vh - 110px) * 4 / 3));
  aspect-ratio: 4 / 3;
  border: 6px solid var(--ink); border-radius: 26px; overflow: hidden;
  box-shadow: 8px 8px 0 var(--ink);
  container-type: inline-size;
}
.map-img { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }
.map-tint {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255, 200, 230, 0) 55%, rgba(255, 150, 200, .45) 100%);
  mix-blend-mode: screen;
}
.map-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.map-banner {
  position: absolute; left: -1%; top: -1%; width: 36%; height: 9%;
  display: grid; place-items: center;
  font-family: var(--title); font-size: 3cqw; color: #fff;
  -webkit-text-stroke: .5cqw var(--ink); paint-order: stroke fill;
  background: linear-gradient(180deg, #ffa6d1, var(--pink-d));
  border: .5cqw solid var(--ink); border-radius: 0 0 3cqw 0;
}
.map-layer { position: absolute; inset: 0; }

.stop {
  position: absolute; width: 6.4%; aspect-ratio: 1; transform: translate(-50%, -50%);
  border-radius: 50%; border: .5cqw solid var(--ink);
  background: radial-gradient(circle at 35% 30%, #fff, #ffe3f1 60%, #ffc2e0);
  font-family: var(--title); font-size: 2.6cqw; padding: 0;
  display: grid; place-items: center;
  box-shadow: 0 .5cqw 0 var(--ink);
}
.stop.locked { opacity: .8; }
.stop.done { background: radial-gradient(circle at 35% 30%, #fff, var(--mint) 70%); }
.stop.done .stop-num { font-size: 0; }
.stop.done .stop-num::after { content: '★'; font-size: 3cqw; color: #fff; -webkit-text-stroke: .25cqw var(--ink); }
.stop.next {
  background: radial-gradient(circle at 35% 30%, #fff, var(--lemon) 55%, #ffb000);
  animation: next-glow 1s ease-in-out infinite;
}
@keyframes next-glow {
  0%, 100% { transform: translate(-50%, -50%) scale(1); box-shadow: 0 .5cqw 0 var(--ink), 0 0 0 0 rgba(255, 95, 162, .8); }
  50% { transform: translate(-50%, -50%) scale(1.15); box-shadow: 0 .5cqw 0 var(--ink), 0 0 0 1.4cqw rgba(255, 95, 162, 0); }
}
.stop.boing { animation: shake .4s; }
@keyframes shake {
  25% { transform: translate(-60%, -50%); }
  75% { transform: translate(-40%, -50%); }
}
.tap-me {
  display: none; position: absolute; bottom: 115%; left: 50%; transform: translateX(-50%);
  white-space: nowrap; font-family: var(--title); font-size: 1.8cqw;
  background: #fff; border: .3cqw solid var(--ink); border-radius: 999px; padding: .1cqw 1.2cqw;
  animation: bob .8s ease-in-out infinite;
}
.next .tap-me { display: block; }
@keyframes bob { 50% { transform: translate(-50%, -25%); } }

.start-flag {
  position: absolute; transform: translate(-50%, -50%);
  font-family: var(--title); font-size: 1.7cqw; color: #fff;
  background: var(--pink-d); border: .3cqw solid var(--ink); border-radius: 1cqw; padding: 0 1cqw;
}
.house-btn { position: absolute; background: none; border: 0; padding: 0; border-radius: 2cqw; }
.house-btn .tap-me { bottom: 102%; }
.house-btn.next { animation: house-glow 1s ease-in-out infinite; }
@keyframes house-glow { 50% { box-shadow: 0 0 0 1cqw rgba(255, 210, 63, .7); } }
.house-btn.boing { animation: shake-plain .4s; }
@keyframes shake-plain { 25% { transform: translateX(-4%); } 75% { transform: translateX(4%); } }

.walker {
  position: absolute; width: 4.8%; transform: translate(-50%, -94%);
  pointer-events: none;
}
.walker > canvas.sprite { width: 100%; height: auto; filter: drop-shadow(0 .3cqw 0 rgba(0, 0, 0, .25)); }
.walker.avatar { transition: left .9s ease-in-out, top .9s ease-in-out; z-index: 3; }
.walker.avatar.flip > canvas.sprite { transform: scaleX(-1); }
.walker.walking > canvas.sprite { animation: walk-bob .22s ease-in-out infinite alternate; }
@keyframes walk-bob { to { translate: 0 -8%; rotate: 4deg; } }
.carry-candy { position: absolute; width: 110%; height: auto; left: 55%; top: 34%; }
.walker.recipient > canvas { animation: idle 1.6s ease-in-out infinite; }
@keyframes idle { 50% { translate: 0 -4%; } }
.heart {
  position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%);
  font-size: 2.6cqw; animation: bob .9s ease-in-out infinite;
}

/* ---------- 7. win ---------- */
#screen-win { justify-content: center; }
.confetti { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.win-card {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center;
  background: rgba(255, 255, 255, .92); border: 5px solid var(--ink); border-radius: 36px;
  box-shadow: 10px 10px 0 var(--ink); padding: 24px 40px 30px;
  animation: pop-in .5s;
}
.speech {
  font-family: var(--title); font-size: clamp(20px, 3vw, 32px);
  background: var(--lemon); border: 4px solid var(--ink); border-radius: 28px;
  padding: 8px 22px; position: relative; text-align: center;
}
.speech::after {
  content: ''; position: absolute; left: 30%; top: 100%;
  border: 14px solid transparent; border-top-color: var(--ink);
}
.win-row { display: flex; align-items: flex-end; gap: 10px; margin-top: 20px; }
.win-sprite canvas { width: min(130px, 18vh); height: auto; animation: idle 1s ease-in-out infinite; }
.win-candy { width: min(230px, 32vh); height: min(230px, 32vh); animation: floaty 2s ease-in-out infinite; }
.win-card .big-btn { margin-top: 10px; }
#done-btn { white-space: nowrap; padding: 12px 22px; }

/* ---------- smaller tablets ---------- */
@media (max-width: 900px) {
  .decorate-layout { grid-template-columns: 110px 1fr 160px; gap: 10px; }
  .tool-btn { font-size: 13px; }
  .tool-ico { font-size: 30px; }
  .palette { grid-template-columns: repeat(2, 48px); padding: 10px; }
  .swatch { width: 48px; height: 48px; }
  .canvas-wrap { width: min(58vh, 46vw); }
  .people-layout { grid-template-columns: 190px 1fr; }
  .candy-grid { gap: 12px; }
}
@media (max-height: 560px) {
  .screen-header { min-height: 54px; margin-bottom: 4px; }
  .preview-stage { min-height: 150px; }
  .preview-sprite canvas { width: 66px; }
}
