:root {
  --vh: 1vh;
  --cake-x: 11%;
  --orange: #f47734;
  --rose: #ef4d74;
  --cream: #fff1c6;
  --brown: #a95b27;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #5f5f5d;
  font-family: Arial, "Helvetica Neue", sans-serif;
  touch-action: none;
}

button {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
}

.dream-app {
  width: 100%;
  height: 100%;
}

.stage {
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(100vw, calc(var(--vh) * 100 * 1500 / 2667));
  aspect-ratio: 1500 / 2667;
  height: auto;
  overflow: hidden;
  background: #fff;
  transform: translate(-50%, -50%);
  transform-origin: center;
  container-type: inline-size;
}

.camera-video,
.camera-kit-canvas,
.white-wash,
.falling-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.camera-video {
  z-index: 0;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0;
}

.camera-video.is-ready {
  opacity: 0.32;
}

.camera-kit-canvas {
  z-index: 1;
  object-fit: cover;
  opacity: 0;
}

.camera-kit-lens-visible .camera-kit-canvas {
  opacity: 0.32;
}

.camera-kit-lens-visible .camera-video.is-ready {
  opacity: 0.015;
}

.white-wash {
  z-index: 2;
  background: rgba(255, 255, 255, 0.4);
}

.timer {
  position: absolute;
  left: 8.3333%;
  top: 4.4244%;
  z-index: 20;
  width: 68.2%;
  aspect-ratio: 1023 / 295;
  height: auto;
  container-type: inline-size;
}

.timer img,
.timer-bar-clip {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  pointer-events: none;
}

.timer-base,
.timer-top,
.timer-bar {
  width: 100%;
}

.timer-bar-clip {
  left: 0;
  width: 100%;
  overflow: hidden;
  clip-path: inset(0 var(--timer-trim, 0%) 0 0);
  transition: clip-path 180ms linear;
}

.timer-bar {
  transform: none;
}

.timer-cap {
  width: 13.1965%;
  height: auto !important;
  top: 11.5254% !important;
  transform: translateX(-50%);
  transition: left 180ms linear;
}

.timer-number {
  position: absolute;
  left: 5.4741%;
  top: 37.6271%;
  z-index: 6;
  width: 16.4223%;
  color: #f25a16;
  font-size: clamp(1.1rem, 7.6cqw, 5rem);
  font-weight: 950;
  line-height: 1;
  text-align: center;
  letter-spacing: 0;
  text-shadow: 0 3px 0 #fff2d5;
}

.icon-button {
  position: absolute;
  right: 2.3333%;
  z-index: 30;
  width: 11.8667%;
  aspect-ratio: 1;
  height: auto;
  cursor: pointer;
  filter: drop-shadow(0 10px 0 rgba(135, 68, 26, 0.18));
}

.icon-button img {
  width: 100%;
  height: 100%;
  display: block;
}

.info-button {
  top: 5.4244%;
  width: 16.5%;
}

.falling-layer {
  z-index: 10;
  pointer-events: none;
}

.falling-item {
  position: absolute;
  object-fit: contain;
  contain: layout paint style;
  filter: drop-shadow(0 10px 8px rgba(120, 70, 60, 0.16));
  will-change: transform;
}

.falling-item.is-caught {
  animation: caught-pop 520ms ease-out forwards;
}

.score-pop {
  position: absolute;
  z-index: 12;
  width: 8%;
  aspect-ratio: 4 / 3;
  height: auto;
  margin-left: -4%;
  margin-top: -3%;
  display: grid;
  place-items: center;
  color: #f25a16;
  font-size: clamp(1.2rem, 4.6vw, 4.5rem);
  font-weight: 950;
  text-shadow: 0 4px 0 #fff2b8, 0 0 18px rgba(244, 119, 52, 0.5);
  animation: score-pop 760ms ease-out forwards;
}

.cake-wrap {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 15;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.cake-stack {
  position: absolute;
  left: var(--cake-x);
  top: 51%;
  width: 78%;
  aspect-ratio: 1500 / 1169;
  height: auto;
  transform-origin: 50% 72%;
  will-change: left, transform;
  transition:
    top 900ms cubic-bezier(0.22, 1, 0.36, 1),
    width 900ms cubic-bezier(0.22, 1, 0.36, 1),
    height 900ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 900ms cubic-bezier(0.22, 1, 0.36, 1);
}

.cake-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.cake-layer-base {
  z-index: 1;
}

.cake-layer-strawberry {
  z-index: 20;
}

.cake-layer-cream {
  z-index: 90;
}

.cake-topping {
  position: absolute;
  z-index: var(--z, 60);
  width: 22%;
  aspect-ratio: 1;
  height: auto;
  object-fit: contain;
  transform: translate(-50%, -50%) rotate(var(--rotate)) scale(var(--scale));
  filter: drop-shadow(0 8px 6px rgba(120, 70, 60, 0.18));
  animation: topping-land 260ms ease-out both;
}

.cake-topping-chacolate {
  width: 22%;
  z-index: 40;
}

.cake-topping-stick {
  width: 22%;
}

.cake-topping-lemon {
  width: 22%;
}

.cake-topping-cherry,
.cake-topping-heart {
  width: 22%;
}

.finish-armed .cake-stack {
  transition:
    left 980ms cubic-bezier(0.22, 1, 0.36, 1),
    top 980ms cubic-bezier(0.22, 1, 0.36, 1),
    width 980ms cubic-bezier(0.22, 1, 0.36, 1),
    height 980ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 980ms cubic-bezier(0.22, 1, 0.36, 1);
}

.is-finished .cake-stack {
  left: 6%;
  top: 23%;
  width: 91%;
  height: auto;
  transform: scale(1);
}

.finish-panel {
  position: absolute;
  inset: 0;
  z-index: 35;
  display: none;
  align-items: end;
  justify-content: center;
  padding-bottom: 8%;
  pointer-events: none;
}

.finish-panel.is-visible {
  display: flex;
}

.finish-card {
  pointer-events: auto;
  width: 90%;
  padding: 4.5% 5.5% 5.5%;
  text-align: center;
  border: 0.55cqw solid rgba(244, 119, 52, 0.28);
  border-radius: 5cqw;
  color: #803d21;
  background:
    linear-gradient(rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0) 38%),
    #fff7dc;
  box-shadow:
    0 2.4cqw 0 rgba(169, 91, 39, 0.15),
    0 4cqw 8cqw rgba(104, 55, 24, 0.3);
  animation: finish-pop 300ms cubic-bezier(0.2, 1.2, 0.32, 1) both;
}

@keyframes finish-pop {
  0% {
    transform: translateY(4cqw) scale(0.94);
    opacity: 0;
  }
  100% {
    transform: none;
    opacity: 1;
  }
}

.finish-title {
  color: #f47734;
  font-size: 5cqw;
  font-weight: 950;
  line-height: 1.1;
  text-shadow: 0 0.3cqw 0 white;
}

.finish-steps {
  margin-top: 2.4cqw;
  text-align: left;
  font-size: 2.9cqw;
  font-weight: 800;
  line-height: 1.55;
  color: #8a5230;
}

.finish-steps p {
  margin: 0.5cqw 0;
}

.finish-actions {
  margin-top: 4cqw;
  display: flex;
  flex-direction: column;
  gap: 2.2cqw;
}

.finish-actions-row {
  display: flex;
  gap: 2.4cqw;
}

.finish-actions-row .finish-btn {
  flex: 1;
}

.finish-btn {
  padding: 3cqw 0;
  border-radius: 999px;
  color: #fff;
  font-size: 3.6cqw;
  font-weight: 950;
  letter-spacing: 0.06em;
  cursor: pointer;
  text-shadow: 0 0.35cqw 0 rgba(150, 50, 60, 0.4);
}

.finish-btn--share {
  font-size: 4.2cqw;
  background:
    linear-gradient(rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 52%),
    linear-gradient(#ff7fa2, #ef4d74);
  box-shadow:
    inset 0 0.4cqw 0 rgba(255, 255, 255, 0.4),
    0 1cqw 0 rgba(170, 40, 70, 0.32);
}

.finish-btn--share[disabled] {
  opacity: 0.6;
}

.finish-btn--replay {
  background:
    linear-gradient(rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0) 42%),
    linear-gradient(#ff943c, #ef5b21);
  box-shadow:
    inset 0 0.4cqw 0 rgba(255, 255, 255, 0.4),
    0 1cqw 0 rgba(150, 60, 20, 0.28);
}

.finish-btn--home {
  background:
    linear-gradient(rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 52%),
    linear-gradient(#ffa9c1, #f47196);
  box-shadow:
    inset 0 0.4cqw 0 rgba(255, 255, 255, 0.35),
    0 1cqw 0 rgba(170, 60, 90, 0.28);
}

.finish-btn:active {
  transform: translateY(0.4cqw);
}

/* 開始按鈕：沿用拼圖遊戲樣式，置於蛋糕下方 */
.cake-start {
  position: absolute;
  left: 50%;
  bottom: 3%;
  z-index: 34;
  width: 46%;
  aspect-ratio: 310 / 99;
  transform: translateX(-50%);
  transform-origin: 50% 50%;
  filter: drop-shadow(0 1.1cqw 0 rgba(90, 44, 20, 0.18));
  cursor: pointer;
  animation: cake-start-sway 1.3s ease-in-out infinite;
}

.cake-start img {
  width: 100%;
  height: 100%;
  display: block;
}

@keyframes cake-start-sway {
  0%,
  100% {
    transform: translateX(-50%) rotate(-1.6deg);
  }
  50% {
    transform: translateX(-50%) rotate(1.6deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cake-start {
    animation: none;
  }
}

.show-intro .cake-start,
.is-starting .cake-start,
.is-playing .cake-start,
.is-finished .cake-start {
  display: none;
}

/* 活動說明頁（進遊戲前） */
.intro-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 70;
  width: 76%;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 2.4cqw;
  padding: 8% 6.5% 7%;
  text-align: center;
  border: 0.55cqw solid rgba(244, 119, 52, 0.28);
  border-radius: 5cqw;
  color: #803d21;
  background:
    linear-gradient(rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0) 38%),
    #fff7dc;
  box-shadow:
    0 2.4cqw 0 rgba(169, 91, 39, 0.15),
    0 4cqw 8cqw rgba(104, 55, 24, 0.28);
  transform: translate(-50%, -50%);
}

.show-intro .intro-panel {
  display: flex;
}

.show-intro .stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 65;
  background: rgba(60, 34, 14, 0.36);
  backdrop-filter: blur(1.6px);
}

.intro-title {
  color: #f47734;
  font-size: 5.4cqw;
  font-weight: 950;
  line-height: 1.1;
  text-shadow: 0 0.3cqw 0 white;
}

.intro-body {
  font-size: 3cqw;
  font-weight: 800;
  line-height: 1.5;
  color: #8a5230;
}

.intro-body p {
  margin: 0;
}

.intro-actions {
  margin-top: 2cqw;
  display: flex;
  flex-direction: column;
  gap: 2.2cqw;
  width: 66%;
}

.intro-btn {
  padding: 3cqw 0;
  border-radius: 999px;
  color: #fff;
  font-size: 3.8cqw;
  font-weight: 950;
  letter-spacing: 0.08em;
  cursor: pointer;
  text-shadow: 0 0.35cqw 0 rgba(150, 50, 60, 0.4);
}

.intro-btn--play {
  background:
    linear-gradient(rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 52%),
    linear-gradient(#ff7fa2, #ef4d74);
  box-shadow:
    inset 0 0.4cqw 0 rgba(255, 255, 255, 0.4),
    0 1cqw 0 rgba(170, 40, 70, 0.32);
}

.intro-btn--home {
  background:
    linear-gradient(rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 52%),
    linear-gradient(#ffa9c1, #f47196);
  box-shadow:
    inset 0 0.4cqw 0 rgba(255, 255, 255, 0.35),
    0 1cqw 0 rgba(170, 60, 90, 0.28);
}

.intro-btn:active {
  transform: translateY(0.4cqw);
}

.help-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 60;
  width: 68%;
  min-height: auto;
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 1.6cqw;
  padding: 4.8% 5.4% 5.2%;
  border: 0.55cqw solid rgba(244, 119, 52, 0.28);
  border-radius: 4.5cqw;
  color: #803d21;
  background:
    linear-gradient(rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0) 38%),
    #fff7dc;
  box-shadow:
    0 2.4cqw 0 rgba(169, 91, 39, 0.15),
    0 4cqw 7cqw rgba(104, 55, 24, 0.24);
  transform: translate(-50%, -50%);
}

.show-help .stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 55;
  background: rgba(255, 255, 255, 0.42);
  backdrop-filter: blur(1.2px);
}

.show-help .help-panel {
  display: flex;
}

.help-title {
  color: #f47734;
  font-size: 4.1cqw;
  font-weight: 950;
  line-height: 1;
  text-align: center;
  text-shadow: 0 0.28cqw 0 white;
}

.help-steps {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 1.15cqw;
  list-style: none;
}

.help-steps li {
  min-height: 6.6cqw;
  display: flex;
  align-items: center;
  padding: 1.45cqw 1.8cqw;
  border-radius: 2.2cqw;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: inset 0 0 0 0.25cqw rgba(244, 119, 52, 0.12);
  font-size: 2.35cqw;
  font-weight: 850;
  line-height: 1.24;
}

.help-close {
  position: absolute;
  right: -2.8cqw;
  top: -2.8cqw;
  width: 7.2cqw;
  aspect-ratio: 1;
  height: auto;
  border-radius: 50%;
  color: white;
  background:
    linear-gradient(rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 45%),
    #f47734;
  box-shadow: 0 0.9cqw 0 rgba(174, 80, 30, 0.24);
  font-size: 4.4cqw;
  font-weight: 950;
  line-height: 1;
}

.status {
  position: absolute;
  left: 2.6667%;
  bottom: 1.3498%;
  z-index: 80;
  display: none;
  color: rgba(90, 60, 40, 0.7);
  font-size: clamp(0.75rem, 1.85vw, 1.75rem);
}

.is-starting .status,
.camera-booting .status {
  display: block;
}

@keyframes caught-pop {
  from {
    opacity: 1;
    transform: translate3d(var(--caught-x), var(--caught-y), 0) rotate(0deg) scale(1);
  }

  to {
    opacity: 0;
    transform: translate3d(var(--caught-x), var(--caught-y), 0) rotate(18deg) scale(1.2);
  }
}

@keyframes score-pop {
  to {
    opacity: 0;
    transform: translateY(-120px) scale(1.12);
  }
}

@keyframes topping-land {
  from {
    opacity: 0;
    transform: translate(-50%, -62%) rotate(var(--rotate)) scale(calc(var(--scale) * 1.3));
  }
}
