:root {
  color-scheme: light;
  --ink: #6a3d52;
  --muted: #8d6174;
  --pink: #ffd3e4;
  --hot: #e56b9b;
  --cream: #fff8f2;
  --card: #fffdfb;
  --mint: #c9f3e4;
  --line: #f3b7cf;
  font-family: "PingFang HK", "PingFang TC", "Noto Sans TC", "Heiti TC", "Microsoft JhengHei", ui-rounded, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  background: #f6efe6;
  -webkit-text-size-adjust: 100%;
}

body {
  position: fixed;
  inset: 0;
  width: 100%;
  display: grid;
  place-items: center;
  color: var(--ink);
}

button, img, canvas { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

button, #pinata, #stage, #maze, canvas, .dpad {
  touch-action: manipulation;
}

button {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 10px 14px;
  box-shadow: 0 3px 0 var(--line);
  min-height: 44px;
}

button:active { transform: translateY(2px); box-shadow: none; }

button:focus-visible { outline: 3px solid #f08ab3; outline-offset: 2px; }

[hidden] { display: none !important; }

#app {
  position: relative;
  width: min(480px, 100%);
  height: 100%;
  overflow: hidden;
  background: var(--cream);
}

.screen, .overlay {
  position: absolute;
  inset: 0;
}

.screen {
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

#screen-start {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(#ffe4f1, #fff6ea 58%, #e7fff6);
}

.balloons,
.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.start-stack {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(420px, calc(100% - 28px));
  max-height: calc(100% - 8px);
}

.start-cake {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 52vh;
  margin: 0;
  object-fit: contain;
  object-position: center bottom;
  flex: 0 1 auto;
  min-height: 0;
}

.start-card, .modal-card {
  position: relative;
  z-index: 1;
  width: min(420px, calc(100% - 28px));
  margin: 0 auto;
  text-align: center;
  background: #fffdfb;
  border-radius: 28px;
  padding: 26px 18px 22px;
  box-shadow: 0 12px 40px rgba(180, 80, 120, 0.14);
}

.start-card {
  width: 100%;
  flex: 0 0 auto;
}

h1 {
  margin: 4px 0 8px;
  font-size: clamp(36px, 11vw, 54px);
  letter-spacing: 0.04em;
  color: var(--hot);
}

.eyebrow, .lede { margin: 0; color: var(--muted); }

.lede { margin-top: 4px; line-height: 1.45; }

#start-btn {
  margin-top: 18px;
  width: min(240px, 100%);
  min-height: 56px;
  border-radius: 999px;
  background: #ff9ec2;
  border-color: #fff;
  box-shadow: 0 4px 0 #f0a0c0;
  font-size: 22px;
}

.balloon {
  position: absolute;
  width: 36px;
  height: 46px;
  border-radius: 50%;
  animation: float 4.8s ease-in-out infinite;
}

.balloon::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  background: inherit;
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}

.balloon.pink { background: #ff8fb8; left: 12%; top: 12%; }
.balloon.mint { background: #8fe0c9; right: 14%; top: 16%; animation-delay: -1.2s; }
.balloon.gold { background: #ffd36e; left: 20%; bottom: 16%; animation-delay: -2s; width: 28px; height: 36px; }
.balloon.blue { background: #9fd4ff; right: 18%; bottom: 18%; animation-delay: -2.4s; width: 30px; height: 38px; }

.confetti i {
  position: absolute;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  opacity: 0.85;
  animation: drift 6s linear infinite;
}

.confetti i:nth-child(1) { left: 8%; top: 28%; background: #ff8fb8; }
.confetti i:nth-child(2) { left: 18%; top: 8%; background: #ffd36e; animation-delay: -1s; }
.confetti i:nth-child(3) { left: 78%; top: 10%; background: #8fe0c9; animation-delay: -2s; }
.confetti i:nth-child(4) { left: 88%; top: 36%; background: #b9a6f2; }
.confetti i:nth-child(5) { left: 70%; top: 78%; background: #ffb38a; animation-delay: -3s; }
.confetti i:nth-child(6) { left: 10%; top: 72%; background: #9fd4ff; animation-delay: -1.5s; }
.confetti i:nth-child(7) { left: 46%; top: 6%; background: #ff9ec2; width: 6px; }
.confetti i:nth-child(8) { left: 58%; top: 18%; background: #fff; animation-delay: -2.5s; }
.confetti i:nth-child(9) { left: 30%; top: 84%; background: #f6c453; }
.confetti i:nth-child(10) { left: 84%; top: 62%; background: #ffd3e4; animation-delay: -4s; }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

@keyframes drift {
  0% { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(28px) rotate(30deg); }
}

#screen-play {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff8f1;
}

.hud { flex: 0 0 auto; padding: 8px 10px 4px; }

.hud-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  margin: 0 0 6px;
  padding: 4px 12px 4px 6px;
  background: #fffdfb;
  border: 2px solid #f3c6d6;
  border-radius: 999px;
  box-shadow: 0 2px 0 #f3d5e2;
}

.mini-cake { width: 28px; height: 28px; flex: 0 0 auto; }

#progress {
  margin: 0;
  font-size: clamp(15px, 4.4vw, 18px);
  font-weight: 700;
}

.hud-actions { display: flex; gap: 6px; }

.hud-actions button {
  flex: 1;
  min-height: 40px;
  padding: 6px 8px;
  border-radius: 999px;
  box-shadow: 0 2px 0 var(--line);
}

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 120px;
  background: #e7f2cf;
  overflow: hidden;
}

#maze {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #173028;
}

.corner-balloons {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.corner-balloons img {
  position: absolute;
  width: 68px;
  height: auto;
  filter: drop-shadow(0 4px 0 rgba(90, 60, 40, 0.08));
}

.corner-balloons .tl { left: -4px; top: -6px; }
.corner-balloons .tr { right: 2px; top: 118px; width: 54px; transform: scaleX(-1); }
.corner-balloons .bl { left: -6px; bottom: -8px; transform: scaleX(-1); }
.corner-balloons .br { right: -4px; bottom: -6px; }

#minimap {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 4;
  width: 86px;
  height: 110px;
  border-radius: 14px;
  border: 2px solid #f3b4cc;
  background: #14241c;
  box-shadow: 0 4px 12px rgba(70, 40, 30, 0.22);
  pointer-events: none;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(106, 61, 82, 0.92);
  color: #fff;
  font-size: 14px;
  text-align: center;
  z-index: 3;
  pointer-events: none;
}

.dpad {
  flex: 0 0 auto;
  width: 188px;
  height: 188px;
  margin: 2px auto 8px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 42%, #fffdfb 0%, #fff4ea 68%, #f6e3d6 100%);
  border: 3px solid #f0d0c4;
  box-shadow: 0 6px 0 #e7cfc3, 0 12px 18px rgba(160, 100, 80, 0.12);
}

.dpad button {
  font-size: 22px;
  padding: 0;
  min-height: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
  color: #e28aa4;
}

#dpad-up { grid-area: 1 / 2; }
#dpad-left { grid-area: 2 / 1; }
#dpad-right { grid-area: 2 / 3; }
#dpad-down { grid-area: 3 / 2; }

.dpad-heart {
  grid-area: 2 / 2;
  display: grid;
  place-items: center;
}

.dpad-heart svg { width: 36px; height: 36px; }

.overlay {
  z-index: 30;
  display: grid;
  place-items: center;
  padding:
    calc(10px + env(safe-area-inset-top))
    calc(10px + env(safe-area-inset-right))
    calc(10px + env(safe-area-inset-bottom))
    calc(10px + env(safe-area-inset-left));
  background: rgba(40, 16, 28, 0.55);
}

.modal-card {
  width: min(420px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 14px 12px 16px;
}

#candy {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

.modal-card { position: relative; z-index: 2; }

#modal-title { margin: 0 0 6px; font-weight: 700; }

#pinata {
  width: min(72vw, 280px);
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
  min-height: 0;
}

#pinata.big { width: min(58vw, 240px); }

#pinata svg { width: 100%; height: auto; display: block; }
#pinata .art-pinata,
#pinata .unicorn-pinata { display: none; position: relative; }
#pinata:not(.unicorn)[data-kind="cat"] .art-pinata[data-pinata="cat"],
#pinata:not(.unicorn)[data-kind="hamster"] .art-pinata[data-pinata="hamster"],
#pinata:not(.unicorn)[data-kind="durian"] .art-pinata[data-pinata="durian"],
#pinata.unicorn .unicorn-pinata { display: block; }
#pinata .art-pinata img,
#pinata .unicorn-pinata img { width: 100%; height: auto; display: block; }
#pinata .crack-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#pinata.unicorn.is-hit .swing { animation: wobble-hard 0.45s ease; }

.swing {
  transform-origin: 50% 2%;
  animation: swing 1.1s ease-in-out infinite;
}

#pinata.is-hit .swing { animation: wobble 0.34s ease; }

#pinata .crack { opacity: 0; }
#pinata[data-hits="1"] .c1 { opacity: 1; }
#pinata[data-hits="2"] .c1,
#pinata[data-hits="2"] .c2 { opacity: 1; }
#pinata[data-hits="3"] .c1,
#pinata[data-hits="3"] .c2,
#pinata[data-hits="3"] .c3 { opacity: 1; }
#pinata[data-hits="4"] .c1,
#pinata[data-hits="4"] .c2,
#pinata[data-hits="4"] .c3,
#pinata[data-hits="4"] .c4 { opacity: 1; }
#pinata[data-hits="5"] .crack { opacity: 1; }

@keyframes swing {
  0%, 100% { transform: rotate(-10deg); }
  50% { transform: rotate(10deg); }
}

@keyframes wobble {
  0% { transform: rotate(-16deg) scale(1); }
  30% { transform: rotate(14deg) scale(1.06); }
  60% { transform: rotate(-8deg) scale(0.96); }
  100% { transform: rotate(0deg) scale(1); }
}

@keyframes wobble-hard {
  0% { transform: rotate(-24deg) scale(1); }
  25% { transform: rotate(22deg) scale(1.1); }
  50% { transform: rotate(-18deg) scale(0.92); }
  75% { transform: rotate(12deg) scale(1.06); }
  100% { transform: rotate(0deg) scale(1); }
}

#clip {
  display: none;
  width: 100%;
  max-height: min(36vh, 280px);
  background: #fff1f6;
  border-radius: 16px;
}

#photo-frame.showing-video #photo { display: none; }
#photo-frame.showing-video #clip { display: block; }

#clip-controls { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
#clip-controls button { min-height: 44px; border-radius: 999px; }

#hit-hint { margin: 4px 0 0; }

#joke-line {
  margin: 0 0 8px;
  color: #6d56b8;
  background: #f3edff;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 14px;
}

#carousel {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  gap: 6px;
  align-items: center;
}

#carousel.single { grid-template-columns: 1fr; }

#prev-photo, #next-photo {
  min-height: 64px;
  font-size: 32px;
  padding: 0;
  border-radius: 14px;
}

#photo {
  width: 100%;
  max-height: min(36vh, 280px);
  object-fit: contain;
  background: #fff1f6;
  border-radius: 16px;
}

#caption, #note-text { margin: 8px 0 0; font-size: 16px; line-height: 1.4; }

#note-text {
  font-size: clamp(22px, 6vw, 32px);
  color: var(--hot);
  font-weight: 700;
  padding: 18px 8px 8px;
}

#dots { display: flex; gap: 6px; justify-content: center; margin: 8px 0; }

#dots button {
  width: 8px;
  height: 8px;
  min-height: 8px;
  padding: 0;
  border: 0;
  border-radius: 99px;
  background: #f3c2d4;
  box-shadow: none;
}

#dots button.on { width: 16px; background: var(--hot); }

#keep-btn, #finale-replay {
  width: 100%;
  margin-top: 8px;
  border-radius: 999px;
  background: #ff9ec2;
  border-color: #fff;
  box-shadow: 0 3px 0 #f0a0c0;
  font-size: 18px;
}

.row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }

.row h2 { margin: 0; font-size: 22px; }

.photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
  text-align: left;
}

.photo-grid figure { margin: 0; }

.photo-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
  background: var(--pink);
}

.photo-grid figcaption { margin-top: 4px; font-size: 13px; color: var(--muted); }

#screen-finale {
  overflow: auto;
  background: linear-gradient(#ffe4f1, #fff8f2 40%, #e7fff6);
  touch-action: pan-y;
}

.finale-inner { padding: 12px 8px 24px; text-align: center; }

.can-scroll { overscroll-behavior: contain; touch-action: pan-y; }

@media (max-width: 360px), (max-height: 640px) {
  .start-card { padding: 18px 14px; }
  h1 { font-size: 36px; }
  .dpad { width: 156px; height: 156px; padding: 6px; }
  .hud-actions button { min-height: 36px; font-size: 14px; }
  #pinata { width: min(70vw, 240px); }
  #minimap { width: 72px; height: 92px; }
  .corner-balloons img { width: 52px; }
  .corner-balloons .tr { top: 96px; }
}

@media (prefers-reduced-motion: reduce) {
  .balloon, .confetti i { animation: none; }
}
