* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #8ee4ff;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #243047;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(#9aebff, #fff4b8 70%, #ffe08a);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

header {
  text-align: center;
  padding: 10px 12px 4px;
}
h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1.1;
  letter-spacing: -0.03em;
}
.tagline {
  margin: 4px 0 0;
  font-size: 1rem;
  line-height: 1.25;
}
.score {
  margin: 6px 0 0;
  font-size: 1.35rem;
  font-weight: 800;
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 6px 10px;
  border-radius: 22px;
  overflow: hidden;
  background:
    linear-gradient(#fff7d6, #fff 28%, transparent 28%),
    repeating-linear-gradient(90deg, #d7f6ff 0 18px, #c8f1ff 18px 36px);
  box-shadow: inset 0 0 0 4px #fff;
}

#counter {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  height: 22px;
  border-radius: 10px;
  background: linear-gradient(#ffd27a, #f4a24a);
  box-shadow: 0 8px 0 #e07a32;
  z-index: 2;
}

#stage { touch-action: none; cursor: pointer; }

#stack {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 32px;
  height: 0;
  transform-origin: 50% 100%;
  z-index: 3;
}

#aim {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}
#aim .piece {
  top: 10px;
  bottom: auto;
  opacity: 0.92;
}
#aim .guide {
  position: absolute;
  top: calc(12px + var(--h));
  left: 50%;
  width: 4px;
  height: 26px;
  margin-left: -2px;
  border-radius: 4px;
  transform: translateX(var(--x));
  background: repeating-linear-gradient(#243047 0 8px, transparent 8px 14px);
  opacity: 0.4;
}

.piece {
  position: absolute;
  left: 50%;
  bottom: var(--bottom);
  width: var(--w);
  height: var(--h);
  margin-left: calc(var(--w) * -0.5);
  transform: translateX(var(--x));
  z-index: var(--z);
}

.piece.dropping {
  animation: drop 0.38s cubic-bezier(.2, .75, .3, 1) both;
}

@keyframes drop {
  from { transform: translateX(var(--x)) translateY(-46vh); }
  to { transform: translateX(var(--x)) translateY(0); }
}

.piece.plate {
  background: radial-gradient(ellipse at 50% 45%, #fffef9, #f3ecdc 62%, #e6dcc6);
  border-radius: 50%;
  box-shadow: 0 4px 0 #d9cdb4, inset 0 0 0 5px #fff, inset 0 0 0 8px #efe4cf;
}
.piece.cup {
  background: linear-gradient(#ff7b8d, #ff3358);
  border-radius: 6px 6px 14px 14px;
  box-shadow: inset 0 8px 0 rgba(255,255,255,.35), 0 3px 0 #d4143c;
}
.piece.cup::after {
  content: "";
  position: absolute;
  right: -11px;
  top: 12px;
  width: 14px;
  height: 18px;
  border: 4px solid #ff3358;
  border-left: none;
  border-radius: 0 12px 12px 0;
}
.piece.bowl {
  background: linear-gradient(#ffe566, #ffb703);
  border-radius: 8px 8px 40px 40px;
  box-shadow: inset 0 8px 0 #fff1a8, 0 3px 0 #e09a00;
}
.piece.pan {
  background: radial-gradient(circle at 35% 35%, #9aa3b2, #4b5563 55%, #1f2937);
  border-radius: 50%;
  box-shadow: inset 0 0 0 4px #d1d5db, 0 3px 0 #111827;
}
.piece.pan::after {
  content: "";
  position: absolute;
  left: 88%;
  top: 38%;
  width: 26px;
  height: 8px;
  background: #374151;
  border-radius: 6px;
}
.piece.pot {
  background: linear-gradient(#7fd4ff, #1c8fe6);
  border-radius: 8px 8px 16px 16px;
  box-shadow: inset 0 -8px 0 rgba(0,0,0,.08), 0 3px 0 #0b6cba;
}
.piece.pot::before {
  content: "";
  position: absolute;
  left: -6%;
  right: -6%;
  top: -7px;
  height: 12px;
  background: #e7f7ff;
  border-radius: 8px;
  box-shadow: 0 2px 0 #8ecff3;
}
.piece.pot::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -14px;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  background: #ff4d6d;
  border-radius: 50%;
}
.piece.mug {
  background: linear-gradient(#7d8cff, #3a46e0);
  border-radius: 6px 6px 16px 16px;
  box-shadow: inset 0 8px 0 rgba(255,255,255,.28), 0 3px 0 #241fa8;
}
.piece.mug::after {
  content: "";
  position: absolute;
  right: -12px;
  top: 10px;
  width: 16px;
  height: 18px;
  border: 4px solid #3a46e0;
  border-left: none;
  border-radius: 0 12px 12px 0;
}
.piece.glass {
  background: linear-gradient(90deg, rgba(255,255,255,.45), rgba(170,225,255,.7), rgba(255,255,255,.85));
  clip-path: polygon(14% 0, 86% 0, 100% 100%, 0 100%);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.9);
}
.piece.board {
  background: repeating-linear-gradient(90deg, #f0b44a 0 10px, #e39a2b 10px 12px);
  border-radius: 6px;
  box-shadow: inset 0 0 0 3px #ffe3a3, 0 3px 0 #c47d16;
}

#start-screen, #end-screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255, 250, 230, .55);
}
#start, #restart {
  min-width: 180px;
  min-height: 76px;
  padding: 16px 36px;
  border: none;
  border-radius: 20px;
  background: #ff4d6d;
  color: #fff;
  font-size: 2rem;
  font-weight: 800;
  box-shadow: 0 6px 0 #c81e45;
}
#start:active, #restart:active { transform: translateY(3px); box-shadow: 0 3px 0 #c81e45; }
.fell {
  margin: 0;
  font-size: 3rem;
  font-weight: 900;
  line-height: 1;
}
#final-score {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
}

#tray {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 8px 10px 12px;
}
.item {
  min-height: 76px;
  border: none;
  border-radius: 16px;
  background: #fffdf8;
  box-shadow: 0 4px 0 #f0c36a;
  padding: 6px 2px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.item:active { transform: translateY(2px); box-shadow: 0 2px 0 #f0c36a; }
.item.selected { outline: 4px solid #ff4d6d; background: #ffe4ea; }
.label { font-size: 0.95rem; font-weight: 800; }

.icon { display: block; position: relative; margin-bottom: 4px; }
.icon.plate { width: 46px; height: 14px; border-radius: 50%; background: radial-gradient(#fff, #e6dcc6); box-shadow: inset 0 0 0 3px #fff, 0 2px 0 #d9cdb4; }
.icon.cup { width: 26px; height: 28px; border-radius: 4px 4px 8px 8px; background: linear-gradient(#ff7b8d, #ff3358); }
.icon.cup::after { content: ""; position: absolute; right: -8px; top: 8px; width: 8px; height: 12px; border: 3px solid #ff3358; border-left: 0; border-radius: 0 8px 8px 0; }
.icon.bowl { width: 40px; height: 20px; border-radius: 4px 4px 18px 18px; background: linear-gradient(#ffe566, #ffb703); }
.icon.pan { width: 28px; height: 28px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #9aa3b2, #374151); }
.icon.pan::after { content: ""; position: absolute; left: 24px; top: 11px; width: 14px; height: 5px; background: #374151; border-radius: 4px; }
.icon.pot { width: 32px; height: 22px; margin-top: 6px; border-radius: 4px 4px 8px 8px; background: linear-gradient(#7fd4ff, #1c8fe6); }
.icon.pot::before { content: ""; position: absolute; left: -3px; right: -3px; top: -5px; height: 6px; background: #e7f7ff; border-radius: 4px; }
.icon.mug { width: 24px; height: 26px; border-radius: 4px 4px 8px 8px; background: linear-gradient(#7d8cff, #3a46e0); }
.icon.mug::after { content: ""; position: absolute; right: -8px; top: 6px; width: 8px; height: 12px; border: 3px solid #3a46e0; border-left: 0; border-radius: 0 8px 8px 0; }
.icon.glass { width: 22px; height: 30px; background: linear-gradient(90deg, rgba(255,255,255,.5), rgba(140,210,255,.8)); clip-path: polygon(18% 0, 82% 0, 100% 100%, 0 100%); }
.icon.board { width: 48px; height: 14px; border-radius: 4px; background: repeating-linear-gradient(90deg, #f0b44a 0 8px, #e39a2b 8px 10px); }
