* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  height: 100%;
  background: #F08A45;
  color: #2A2118;
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}
button { font-family: inherit; }
.app {
  position: relative;
  touch-action: manipulation;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background:
    radial-gradient(90% 32% at 50% 0%, rgba(255,255,255,.42), transparent 62%),
    linear-gradient(180deg, #FFE3C2 0%, #FFC48A 42%, #FF9A4A 100%);
}
.screen {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  padding-top: calc(env(safe-area-inset-top, 0px) + 48px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
}
.screen.on { display: flex; }

.deco { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.backsplash {
  position: absolute;
  left: 0; right: 0; top: 0; height: 48%;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.22) 0 2px, transparent 2px 26px),
    repeating-linear-gradient(0deg, rgba(255,255,255,.22) 0 2px, transparent 2px 26px),
    linear-gradient(180deg, #FFEBD2, #FFD2A4);
  -webkit-mask-image: linear-gradient(180deg, #000 62%, transparent);
  mask-image: linear-gradient(180deg, #000 62%, transparent);
}
.shelf {
  position: absolute;
  left: 8%; right: 8%; top: 18%;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(180deg, #E7B56A, #C4843C);
  box-shadow: 0 6px 0 rgba(140, 70, 20, .18);
}
.jar {
  position: absolute;
  top: 11%;
  width: 28px; height: 36px;
  border-radius: 8px 8px 10px 10px;
  background: linear-gradient(180deg, #FFF6E8, #F0C48A);
  box-shadow: inset -6px 0 0 rgba(180, 100, 30, .12), 0 4px 0 rgba(140, 70, 20, .12);
}
.jar:before {
  content: "";
  position: absolute;
  left: 6px; right: 6px; top: -6px; height: 8px;
  border-radius: 4px;
  background: #E07A3A;
}
.jar-a { left: 14%; }
.jar-b { right: 16%; background: linear-gradient(180deg, #E7F7F4, #9FD8CF); }
.jar-b:before { background: #3A9A90; }
.plant {
  position: absolute;
  left: 28%; top: 12%;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #7BC67A;
  box-shadow: 10px 4px 0 #5AAA62, -8px 6px 0 #8ED48A;
}
.plant i {
  position: absolute;
  left: 8px; top: 16px;
  width: 6px; height: 16px;
  background: #C4843C;
  border-radius: 3px;
}
.counter {
  position: absolute;
  left: 0; right: 0; bottom: 0; height: 22%;
  background: linear-gradient(180deg, #E7A15A 0%, #C4783A 28%, #A8642C 100%);
  box-shadow: inset 0 8px 0 rgba(255,255,255,.2);
}

.col {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
#screenStart.on { overflow: auto; }
#screenStart .col {
  flex: 0 0 auto;
  margin-top: auto;
  margin-bottom: auto;
  padding-bottom: 8px;
}
#screenEnd.on { overflow: auto; justify-content: flex-start; }
#screenEnd .col { flex: 0 0 auto; margin-top: auto; margin-bottom: auto; }

.sign {
  position: relative;
  width: min(300px, 86vw);
  margin-top: 36px;
  padding: 18px 16px 14px;
  text-align: center;
  border-radius: 18px;
  background: linear-gradient(180deg, #F6D2A0 0%, #E3A85E 46%, #D08A3C 100%);
  border: 1px solid rgba(255,255,255,.45);
  box-shadow: 0 7px 0 #A86A30, 0 14px 22px rgba(120, 60, 10, .22);
}
.hat {
  position: absolute;
  left: 50%; top: -28px;
  width: 78px; height: 42px;
  transform: translateX(-50%);
}
.hat:before {
  content: "";
  position: absolute;
  left: 12px; right: 12px; top: 0; height: 28px;
  background: #fff;
  border-radius: 18px 18px 8px 8px;
  box-shadow: -18px 8px 0 -4px #fff, 18px 8px 0 -4px #fff, 0 4px 8px rgba(120, 60, 10, .12);
}
.hat:after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0; height: 14px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 3px 0 #F3E4D4;
}
.kicker {
  margin: 6px 0 0;
  font-size: 12px;
  letter-spacing: 3px;
  color: #8A4E1C;
  font-weight: 700;
}
.sign h1 {
  margin: 2px 0 0;
  font-size: 34px;
  line-height: 1.15;
  font-weight: 900;
  letter-spacing: 1px;
  color: #FFF6D8;
  text-shadow: 0 2px 0 #E39A3A, 0 4px 0 #C25812, 0 6px 0 #8A3A0C;
}

.preview {
  width: min(248px, 72vw);
  margin: 16px auto 0;
  padding: 10px;
  border-radius: 20px;
  background: linear-gradient(180deg, #E8B36A, #C4843C);
  border: 1px solid rgba(255,255,255,.28);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.4), 0 8px 0 #9A5A22, 0 14px 18px rgba(120, 55, 10, .22);
}
.preview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding: 7px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,248,230,.72), rgba(255,214,160,.45));
}
.preview-grid .pcell {
  aspect-ratio: 1;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #FFFDF8, #FFE7C8);
  box-shadow: 0 3px 0 #E2C39A, 0 4px 8px rgba(120, 60, 10, .08);
  border: 1px solid rgba(255,255,255,.85);
}
.preview-grid svg { width: 72%; height: 72%; display: block; }

.play-wrap {
  position: relative;
  width: min(320px, 100%);
  margin-top: 16px;
}
.spark {
  position: absolute;
  width: 14px; height: 14px;
  background: #FFE38A;
  clip-path: polygon(50% 0, 64% 36%, 100% 50%, 64% 64%, 50% 100%, 36% 64%, 0 50%, 36% 36%);
  filter: drop-shadow(0 0 3px rgba(255,255,255,.9));
  animation: twinkle 1.5s ease-in-out infinite;
}
.sp1 { left: -4px; top: 8px; }
.sp2 { right: 6px; top: -8px; animation-delay: .4s; }
.sp3 { right: -2px; bottom: 6px; width: 10px; height: 10px; animation-delay: .8s; }
@keyframes twinkle {
  0%, 100% { transform: scale(.8) rotate(0deg); opacity: .75; }
  50% { transform: scale(1.15) rotate(15deg); opacity: 1; }
}

.btn-main {
  width: 100%;
  height: 58px;
  border: none;
  border-radius: 29px;
  cursor: pointer;
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(180deg, #FFB86A 0%, #FF8A3D 46%, #F26616 100%);
  box-shadow: 0 5px 0 #D2540C, 0 10px 16px rgba(210, 80, 10, .28);
}
.btn-main .mp-icon { width: 28px; height: 28px; }
.btn-main:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #D2540C, 0 6px 10px rgba(210, 80, 10, .22);
}
.btn-main.is-off { opacity: .48; }
.btn-ghost {
  margin-top: 12px;
  height: 44px;
  min-width: 120px;
  padding: 0 16px;
  border: none;
  background: rgba(255,252,247,.72);
  color: #8A4B22;
  font-size: 15px;
  font-weight: 800;
  border-radius: 22px;
  cursor: pointer;
}
.btn-ghost:active { transform: scale(.97); opacity: .85; }

.rule {
  margin: 12px 0 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255,252,247,.86);
  color: #6A4A32;
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  border: 1px solid rgba(255,255,255,.7);
}

.chips {
  width: 100%;
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.chip {
  flex: 1;
  background: #fff;
  border-radius: 16px;
  padding: 12px 4px 10px;
  text-align: center;
  border: 1px solid rgba(0,0,0,.04);
  box-shadow: 0 6px 0 rgba(180, 90, 20, .1), 0 8px 16px rgba(120, 50, 0, .08);
}
.chip .ic {
  width: 40px; height: 40px;
  margin: 0 auto 6px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(180deg, #FFB067, #FF8A3D);
  box-shadow: 0 3px 0 #E06A22;
}
.chip .mp-icon { width: 22px; height: 22px; }
.chip b { display: block; font-size: 14px; color: #2A2118; }
.chip span { display: block; margin-top: 2px; font-size: 12px; color: #8A7560; }

.hud {
  flex: none;
  margin: 0 16px;
  padding: 10px 12px 8px;
  border-radius: 18px;
  background: rgba(255,252,247,.96);
  border: 1px solid rgba(255,255,255,.8);
  box-shadow: 0 6px 0 rgba(160, 70, 10, .08), 0 8px 16px rgba(120, 50, 0, .1);
}
.hud-top { display: flex; align-items: center; justify-content: space-between; min-height: 36px; }
.hud h2 { margin: 0; font-size: 17px; font-weight: 800; color: #2A2118; }
.hud-gap { width: 72px; }
.exit {
  min-width: 72px;
  height: 44px;
  padding: 0 8px 0 4px;
  border: none;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: #FFF1E4;
  color: #C45A12;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}
.exit .mp-icon { width: 18px; height: 18px; }
.exit:active { transform: scale(.96); background: #FFE0C8; }
.meters { display: flex; margin-top: 6px; }
.meter { flex: 1; text-align: center; }
.meter span { display: block; font-size: 12px; color: #8A7560; }
.meter b {
  display: block;
  margin-top: 1px;
  font-size: 22px;
  line-height: 1.2;
  color: #FF8A3D;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.meter b.dark { color: #2A2118; }
.meter b.danger { color: #E23B2F; animation: pulse 1s ease-in-out infinite; }
.meter b.pop { animation: popnum .25s ease; }
@keyframes pulse { 50% { opacity: .55; } }
@keyframes popnum { 50% { transform: scale(1.18); } }
.leftpairs { margin: 4px 0 2px; text-align: center; font-size: 12px; color: #8A7560; }

.boardWrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
}
.tray {
  position: relative;
  display: inline-block;
  padding: 10px;
  border-radius: 20px;
  background: linear-gradient(180deg, #E8B36A, #C4843C);
  border: 1px solid rgba(255,255,255,.3);
  box-shadow: inset 0 2px 0 rgba(255,255,255,.4), 0 8px 0 #9A5A22, 0 14px 20px rgba(120, 55, 10, .24);
}
.stage { position: relative; display: inline-block; }
.board {
  display: grid;
  position: relative;
  z-index: 1;
  width: min(78vw, 336px);
  aspect-ratio: 1;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 4px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255,248,230,.78), rgba(255,214,160,.5));
}
.cell {
  border-radius: 10px;
  padding: 0;
  min-width: 0;
  min-height: 0;
}
.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.9);
  cursor: pointer;
  background: linear-gradient(180deg, #FFFDF8, #FFE7C8);
  box-shadow: 0 3px 0 #E2C39A, 0 4px 6px rgba(90, 40, 0, .1);
}
.tile svg { width: 74%; height: 74%; display: block; pointer-events: none; }
.tile:active { filter: brightness(.96); }
.tile.sel {
  z-index: 2;
  transform: translateY(-2px);
  border-color: #FF8A3D;
  box-shadow: 0 0 0 3px #FF8A3D, 0 3px 0 #E2C39A;
}
.tile.shake { animation: shake .28s ease; }
.tile.out { animation: pout .26s ease forwards; pointer-events: none; }
.cell.empty {
  background: transparent;
  box-shadow: none;
  border: none;
}
@keyframes shake {
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}
@keyframes pout {
  to { transform: scale(.25); opacity: 0; }
}
.wires {
  position: absolute;
  overflow: visible;
  pointer-events: none;
  z-index: 3;
}
#wireBg, #wire {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0;
}
#wireBg { stroke: #fff; stroke-width: 8; }
#wire { stroke: #FF8A3D; stroke-width: 4.5; }
.wires.show #wireBg, .wires.show #wire { opacity: 1; }

.floater {
  position: absolute;
  z-index: 4;
  font-size: 16px;
  font-weight: 900;
  color: #FF8A3D;
  text-shadow: 0 1px 0 #fff, 0 2px 0 rgba(255,255,255,.8);
  pointer-events: none;
  animation: floatup .7s ease forwards;
}
@keyframes floatup {
  to { transform: translateY(-26px); opacity: 0; }
}

.dock { flex: none; padding: 0 16px 2px; }
.toast {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translateX(-50%);
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(42, 33, 24, .9);
  color: #fff;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  z-index: 6;
  transition: opacity .2s ease;
}
.toast.show { opacity: 1; }

#screenEnd { justify-content: center; }
.end-col { position: relative; z-index: 1; }
.end-card {
  width: 100%;
  text-align: center;
  padding: 22px 16px 16px;
  border-radius: 24px;
  background: #fff;
  border: 1px solid rgba(255,255,255,.8);
  box-shadow: 0 10px 0 rgba(160, 70, 10, .1), 0 16px 28px rgba(120, 50, 0, .16);
}
.badge {
  width: 72px; height: 72px;
  margin: 0 auto 10px;
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(180deg, #FFB067, #FF8A3D);
  box-shadow: 0 6px 0 #E06A22;
}
.badge .mp-icon { width: 40px; height: 40px; }
.end-card h2 { margin: 0; font-size: 22px; font-weight: 900; color: #2A2118; }
.reason { margin: 6px 0 0; font-size: 14px; line-height: 1.45; color: #8A7560; }
.score-num {
  margin-top: 10px;
  font-size: 48px;
  line-height: 1;
  font-weight: 900;
  color: #FF8A3D;
  font-variant-numeric: tabular-nums;
}
.score-label { margin-top: 4px; font-size: 12px; letter-spacing: 2px; color: #8A7560; }
.stats { display: flex; gap: 8px; margin-top: 14px; }
.stat {
  flex: 1;
  padding: 8px 4px;
  border-radius: 12px;
  background: #F7F1E8;
}
.stat b { display: block; font-size: 16px; color: #2A2118; font-variant-numeric: tabular-nums; }
.stat span { display: block; margin-top: 2px; font-size: 12px; color: #8A7560; }
.end-again { margin-top: 16px; }

.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.confetti i {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  animation: fall 1.15s ease-in forwards;
}
@keyframes fall {
  to { top: 108%; opacity: .15; }
}

[hidden] { display: none !important; }
