* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #8fd3f4;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

/* 通用背景 */
.bg-sky {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #a9e4ff 0%, #d4f3ff 60%, #a8e6cf 100%);
  z-index: 0;
  overflow: hidden;
}

.cloud {
  position: absolute;
  background: rgba(255,255,255,0.85);
  border-radius: 999px;
}
.cloud::before, .cloud::after {
  content: '';
  position: absolute;
  background: rgba(255,255,255,0.85);
  border-radius: 999px;
}
.cloud-1 {
  width: 100px;
  height: 36px;
  top: 12%;
  left: -20px;
  animation: cloudMove 25s linear infinite;
}
.cloud-1::before { width: 50px; height: 50px; top: -22px; left: 14px; }
.cloud-1::after { width: 40px; height: 40px; top: -16px; right: 14px; }
.cloud-2 {
  width: 80px;
  height: 28px;
  top: 22%;
  right: -30px;
  animation: cloudMove 32s linear infinite reverse;
}
.cloud-2::before { width: 40px; height: 40px; top: -18px; left: 10px; }
.cloud-2::after { width: 34px; height: 34px; top: -14px; right: 10px; }

@keyframes cloudMove {
  0% { transform: translateX(0); }
  100% { transform: translateX(calc(100vw + 100px)); }
}

.mountain {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 22%;
  background: #5fc49a;
  border-radius: 50% 50% 0 0 / 40% 40% 0 0;
  z-index: 1;
}
.mountain-1 {
  left: -30%;
  width: 140%;
  height: 24%;
  background: #4db88d;
}
.mountain-2 {
  left: 20%;
  width: 120%;
  height: 18%;
  background: #6dd1a6;
  opacity: 0.85;
}

.leaf {
  position: absolute;
  width: 90px;
  height: 70px;
  background: #4a9c5d;
  border-radius: 0 80% 0 80%;
  z-index: 2;
}
.leaf-tl {
  top: -10px;
  left: -20px;
  transform: rotate(-15deg);
}
.leaf-tr {
  top: -10px;
  right: -20px;
  transform: rotate(105deg);
}

.btn-complaint {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 56px;
  height: 28px;
  border-radius: 14px;
  background: rgba(0,0,0,0.45);
  color: #fff;
  font-size: 12px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  z-index: 50;
  cursor: pointer;
}
.btn-complaint::before {
  content: '!';
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #b0b0b0;
  color: #fff;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 启动页 */
.home-content {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 420px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 6vh;
}

.title-board {
  position: relative;
  width: 76%;
  max-width: 300px;
  aspect-ratio: 16/9;
  background: #4a9c5d;
  border-radius: 18px;
  border: 6px solid #a8e6b8;
  box-shadow: 0 8px 0 rgba(0,0,0,0.15), inset 0 4px 0 rgba(255,255,255,0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 4vh;
}
.title-board::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px dashed rgba(255,255,255,0.35);
  border-radius: 12px;
  pointer-events: none;
}
.game-title {
  color: #fff;
  font-size: 42px;
  font-weight: 900;
  text-shadow: 0 3px 0 rgba(0,0,0,0.2);
  letter-spacing: 2px;
}
.game-subtitle {
  color: #e0ffe8;
  font-size: 13px;
  margin-top: 6px;
}

.main-zongzi {
  position: relative;
  width: 45%;
  max-width: 180px;
  aspect-ratio: 1/1.1;
  margin-top: 4vh;
  z-index: 5;
  animation: floatZongzi 3s ease-in-out infinite;
}
.small-zongzi {
  position: absolute;
  width: 22%;
  max-width: 90px;
  aspect-ratio: 1/1.2;
  top: 44%;
  z-index: 4;
  animation: floatZongzi 3s ease-in-out infinite 0.5s;
}
.small-zongzi.left { left: 8%; }

.claw-left, .claw-right {
  position: absolute;
  width: 22%;
  max-width: 100px;
  aspect-ratio: 1/1.1;
  z-index: 6;
}
.claw-left { top: 12%; left: 5%; transform: rotate(-12deg); }
.claw-right { top: 16%; right: 5%; transform: rotate(12deg); }

.hat {
  position: absolute;
  width: 18%;
  max-width: 75px;
  top: 38%;
  right: 14%;
  z-index: 7;
  animation: floatHat 4s ease-in-out infinite;
}

@keyframes floatZongzi {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes floatHat {
  0%, 100% { transform: translateY(0) rotate(8deg); }
  50% { transform: translateY(-12px) rotate(12deg); }
}

.home-buttons {
  margin-top: auto;
  margin-bottom: 10vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.btn-start {
  width: 66%;
  max-width: 260px;
  padding: 16px 0;
  border-radius: 14px;
  background: linear-gradient(180deg, #f9d27a 0%, #f4b43a 100%);
  border: none;
  border-bottom: 5px solid #c98d20;
  color: #7a4a1a;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 3px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(0,0,0,0.18);
  transition: transform 0.08s;
}
.btn-start:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
}
.btn-rules {
  background: transparent;
  border: none;
  color: #2d6a4f;
  font-size: 15px;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* 弹窗通用 */
.modal {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal.show { display: flex; }

.modal-content {
  width: 100%;
  max-width: 340px;
  background: #4a9c5d;
  border-radius: 22px;
  border: 5px solid #a8e6b8;
  padding: 22px;
  text-align: center;
  color: #fff;
  box-shadow: 0 12px 30px rgba(0,0,0,0.3);
}

.rules-content h2 {
  font-size: 24px;
  margin-bottom: 16px;
  text-shadow: 0 2px 0 rgba(0,0,0,0.2);
}
.rules-body {
  text-align: left;
  font-size: 14px;
  line-height: 1.7;
  margin-bottom: 18px;
}
.rules-body p { margin-bottom: 10px; }
.rules-body strong { color: #fff7a8; }

.btn-close-modal, .btn-result {
  width: 100%;
  padding: 12px 0;
  border-radius: 10px;
  border: none;
  background: linear-gradient(180deg, #f9d27a 0%, #f4b43a 100%);
  border-bottom: 4px solid #c98d20;
  color: #7a4a1a;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
}
.btn-result { width: 48%; }
.btn-result:active {
  transform: translateY(2px);
  border-bottom-width: 2px;
}

/* DIY 页 */
.diy-content {
  position: relative;
  z-index: 10;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4vh 5% 0;
}

.diy-preview {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.diy-frame {
  width: 72%;
  max-width: 280px;
  aspect-ratio: 1/1.1;
  background: rgba(255,255,255,0.35);
  border-radius: 22px;
  border: 4px solid rgba(255,255,255,0.6);
  padding: 10px;
  box-shadow: inset 0 0 20px rgba(255,255,255,0.4);
}
.diy-canvas {
  width: 100%;
  height: 100%;
  background: rgba(255,255,255,0.25);
  border-radius: 16px;
  position: relative;
  overflow: hidden;
}
.diy-hint {
  color: #2d6a4f;
  font-size: 14px;
  font-style: italic;
  text-align: center;
  margin-top: 12px;
  line-height: 1.5;
  text-shadow: 0 1px 0 rgba(255,255,255,0.5);
}

.diy-sticker-el {
  position: absolute;
  cursor: grab;
  width: 60px;
  height: 60px;
  z-index: 20;
}
.diy-sticker-el.dragging { cursor: grabbing; z-index: 30; }
.diy-sticker-el.invalid { opacity: 0.5; }

.diy-panel {
  width: 100%;
  margin-top: auto;
  margin-bottom: 8vh;
  background: #fff;
  border-radius: 24px 24px 0 0;
  padding: 14px 16px 22px;
  position: relative;
  box-shadow: 0 -6px 20px rgba(0,0,0,0.08);
}
.diy-tabs {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
}
.diy-tab {
  flex: 1;
  padding: 10px 0;
  border-radius: 10px;
  border: none;
  background: #e8f5ee;
  color: #4a9c5d;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.diy-tab.active {
  background: #4a9c5d;
  color: #fff;
}
.diy-start-btn {
  background: linear-gradient(180deg, #f9d27a 0%, #f4b43a 100%);
  border-bottom: 4px solid #c98d20;
  color: #7a4a1a;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.diy-start-btn:active {
  transform: translateY(2px);
  border-bottom-width: 2px;
}
.diy-items {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.diy-items.hidden { display: none; }
.diy-item {
  background: #f6fdf8;
  border: 2px solid #d4eddf;
  border-radius: 12px;
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}
.diy-item.selected {
  border-color: #4a9c5d;
  background: #e8f5ee;
}
.diy-item svg {
  width: 48px;
  height: 48px;
}
.diy-item span {
  font-size: 11px;
  color: #4a6b55;
}

/* 游戏 UI */
.game-ui {
  position: absolute;
  top: 3vh;
  left: 5%;
  right: 5%;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.score-board, .time-board {
  background: #4a9c5d;
  border: 3px solid #a8e6b8;
  border-radius: 14px;
  padding: 10px 14px;
  color: #fff;
  box-shadow: 0 4px 0 rgba(0,0,0,0.15);
}
.score-board {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 110px;
}
.score-item {
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.score-item strong { font-size: 16px; }
.time-board {
  font-size: 13px;
  min-width: 100px;
  text-align: center;
}
.time-board strong { font-size: 20px; margin-left: 4px; }

/* 游戏机台 */
.machine {
  position: relative;
  z-index: 10;
  width: 92%;
  max-width: 400px;
  margin-top: 10vh;
}
.machine-frame {
  width: 100%;
  aspect-ratio: 1/1.15;
  background: #4a9c5d;
  border-radius: 26px;
  border: 8px solid #a8e6b8;
  padding: 14px;
  box-shadow: 0 10px 0 rgba(0,0,0,0.18), inset 0 4px 0 rgba(255,255,255,0.15);
}
.machine-glass {
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #a9e4ff 0%, #d4f3ff 100%);
  border-radius: 16px;
  border: 4px solid #3d8550;
  position: relative;
  overflow: hidden;
}
.machine-glass::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.35) 0%, transparent 40%, transparent 60%, rgba(255,255,255,0.2) 100%);
  pointer-events: none;
  z-index: 5;
}

.countdown-number {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 120px;
  font-weight: 900;
  color: rgba(255,255,255,0.9);
  text-shadow: 0 6px 0 rgba(74,156,93,0.3);
  z-index: 10;
}

.claw-assembly {
  position: absolute;
  top: 0;
  left: 50%;
  width: 80px;
  height: 100%;
  transform: translateX(-50%);
  z-index: 8;
  pointer-events: none;
}
.claw-line {
  position: absolute;
  top: 0;
  left: 50%;
  width: 8px;
  height: 40px;
  background: #f4d19b;
  transform: translateX(-50%);
  border-radius: 4px;
}
.claw-hand {
  position: absolute;
  top: 32px;
  left: 50%;
  width: 70px;
  height: 80px;
  transform: translateX(-50%);
}
.claw-arm {
  transition: transform 0.18s ease;
}
.claw-arm-l { transform-origin: 26px 58px; }
.claw-arm-r { transform-origin: 54px 58px; }
.claw-hand.closed .claw-arm-l { transform: rotate(16deg); }
.claw-hand.closed .claw-arm-r { transform: rotate(-16deg); }

.zongzi-layer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 38%;
  z-index: 7;
  overflow: hidden;
}
.zongzi-item {
  position: absolute;
  bottom: 6%;
  width: 62px;
  height: 74px;
  transition: none;
  will-change: transform;
}
.zongzi-item.caught {
  z-index: 9;
}

.machine-lights {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
}
.light {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ff9e7a;
  box-shadow: 0 0 8px #ff9e7a;
  animation: blink 1.2s ease-in-out infinite;
}
.light:nth-child(2n) { animation-delay: 0.6s; background: #ffd27a; box-shadow: 0 0 8px #ffd27a; }
@keyframes blink {
  0%, 100% { opacity: 0.5; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.1); }
}

.machine-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding: 0 4px;
}
.score-slot {
  width: 36%;
  height: 44px;
  background: #3d8550;
  border-radius: 12px;
  border: 3px solid #a8e6b8;
  box-shadow: inset 0 3px 6px rgba(0,0,0,0.2);
}
.btn-grab {
  width: 58%;
  height: 52px;
  border-radius: 28px;
  background: linear-gradient(180deg, #ffdd5e 0%, #ffb41f 100%);
  border: none;
  border-bottom: 5px solid #d98f0a;
  color: #8a4a00;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(0,0,0,0.2);
  transition: transform 0.08s, filter 0.2s;
}
.btn-grab:disabled {
  filter: grayscale(0.25);
  cursor: not-allowed;
}
.btn-grab:active:not(:disabled) {
  transform: translateY(3px);
  border-bottom-width: 2px;
}

.score-pop {
  position: absolute;
  left: 50%;
  bottom: 30%;
  transform: translateX(-50%);
  font-size: 36px;
  font-weight: 900;
  color: #ffdd5e;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  opacity: 0;
  pointer-events: none;
  z-index: 12;
}
.score-pop.show {
  animation: popUp 0.8s ease-out forwards;
}
@keyframes popUp {
  0% { opacity: 0; transform: translateX(-50%) translateY(20px) scale(0.8); }
  30% { opacity: 1; transform: translateX(-50%) translateY(-10px) scale(1.1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-50px) scale(1); }
}

/* 结算弹窗 */
.result-content {
  background: #4a9c5d;
  border-radius: 24px;
  position: relative;
  overflow: hidden;
}
.result-content::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-conic-gradient(from 0deg, rgba(255,255,255,0.08) 0deg 15deg, transparent 15deg 30deg);
  pointer-events: none;
}
.result-content h2 {
  font-size: 22px;
  margin-bottom: 14px;
  text-shadow: 0 2px 0 rgba(0,0,0,0.2);
  position: relative;
}
.result-zongzi {
  width: 120px;
  height: 140px;
  margin: 0 auto 12px;
  position: relative;
}
.result-text {
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 16px;
  position: relative;
}
.result-stats {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-bottom: 18px;
  position: relative;
}
.result-stats div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.result-stats span { font-size: 12px; opacity: 0.9; }
.result-stats strong { font-size: 28px; }
.result-buttons {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  position: relative;
}

/* 海报 */
.poster-layer {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  flex-direction: column;
  padding: 20px;
}
.poster-layer.show { display: flex; }
.poster-card {
  position: relative;
  background: #fff;
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.35);
}
#poster-canvas {
  display: block;
  border-radius: 10px;
  width: 300px;
  height: 480px;
}
.btn-close-poster {
  position: absolute;
  bottom: -56px;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: 2px solid #fff;
  color: #fff;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.poster-tip {
  color: #fff;
  font-size: 13px;
  margin-top: 18px;
}

/* 排行榜 */
.leaderboard-content {
  position: relative;
  z-index: 10;
  width: 92%;
  max-width: 420px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5vh 0 3vh;
}
.lb-title {
  color: #2d6a4f;
  font-size: 32px;
  font-weight: 900;
  margin-bottom: 16px;
  text-shadow: 0 2px 0 rgba(255,255,255,0.5);
}
.lb-table-wrap {
  width: 100%;
  flex: 1;
  overflow-y: auto;
  background: rgba(255,255,255,0.85);
  border-radius: 18px;
  padding: 12px;
  margin-bottom: 12px;
}
.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.lb-table th {
  color: #4a9c5d;
  font-weight: 700;
  padding: 10px 4px;
  text-align: center;
}
.lb-table td {
  padding: 10px 4px;
  text-align: center;
  color: #3d5a4d;
  border-bottom: 1px solid rgba(74,156,93,0.15);
}
.lb-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #ddd;
  margin: 0 auto;
  overflow: hidden;
}
.lb-self {
  width: 100%;
  background: #4a9c5d;
  border-radius: 14px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  margin-bottom: 12px;
}
.lb-rank { font-size: 18px; font-weight: 900; width: 30px; }
.lb-name { flex: 1; text-align: left; font-size: 14px; }
.lb-score { font-size: 20px; font-weight: 900; }
.lb-buttons {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

/* 响应式微调 */
@media (max-height: 680px) {
  .home-content { padding-top: 4vh; }
  .title-board { margin-top: 2vh; }
  .main-zongzi { margin-top: 2vh; }
  .machine { margin-top: 8vh; }
  .diy-panel { margin-bottom: 4vh; }
}

@media (min-width: 420px) {
  .game-ui { left: 8%; right: 8%; }
}
