*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #FFF7EC;
  --text: #3D2C2E;
  --text-muted: #8B7E80;
  --card: #ffffff;
  --accent-red: #FF6B6B;
  --accent-teal: #4ECDC4;
  --accent-yellow: #FFD93D;
  --accent-purple: #6C5CE7;
  --accent-orange: #FF9F43;
  --accent-green: #2ECC71;
  --shadow-sm: 0 4px 12px rgba(61, 44, 46, 0.08);
  --shadow-md: 0 8px 28px rgba(61, 44, 46, 0.12);
  --radius: 20px;
}

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* blobs */
.blob { position: fixed; border-radius: 50%; filter: blur(90px); opacity: 0.22; z-index: 0; animation: blobFloat 14s ease-in-out infinite alternate; pointer-events: none; }
.blob-1 { width: 380px; height: 380px; background: var(--accent-purple); top: -140px; left: -80px; }
.blob-2 { width: 340px; height: 340px; background: var(--accent-yellow); bottom: -100px; right: -60px; animation-delay: -5s; }
.blob-3 { width: 280px; height: 280px; background: var(--accent-teal); top: 35%; left: 55%; animation-delay: -9s; }
@keyframes blobFloat {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(24px, -32px) scale(1.06); }
}

/* top bar */
.top-bar { position: relative; z-index: 10; padding: 12px 20px; }
.back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: 'Nunito', sans-serif; font-weight: 700; font-size: 0.95rem;
  color: var(--text-muted); text-decoration: none;
  padding: 8px 14px; border-radius: 14px;
  background: rgba(255,255,255,0.6); backdrop-filter: blur(8px);
  transition: background 0.2s, color 0.2s;
}
.back-btn:hover { background: rgba(255,255,255,0.9); color: var(--text); }

/* game wrapper */
.game-wrapper {
  position: relative; z-index: 1; flex: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: 0 16px 24px;
  max-width: 600px; margin: 0 auto; width: 100%;
}

/* header */
.game-header { text-align: center; margin-bottom: 10px; animation: fadeDown 0.5s ease both; }
.game-header h1 {
  font-family: 'Baloo 2', cursive; font-weight: 800;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-orange));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.emoji-bounce {
  display: inline-block; -webkit-text-fill-color: initial;
  animation: emojiBounce 2s ease-in-out infinite;
}
@keyframes emojiBounce {
  0%, 100% { transform: translateY(0) rotate(0); }
  25%  { transform: translateY(-6px) rotate(-8deg); }
  75%  { transform: translateY(-3px) rotate(6deg); }
}
.subtitle { font-size: 0.95rem; font-weight: 600; color: var(--text-muted); margin-top: 2px; }
@keyframes fadeDown {
  0% { opacity: 0; transform: translateY(-18px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ── Shape tray ── */
.shape-tray {
  display: flex; flex-wrap: wrap; gap: 10px;
  justify-content: center; align-items: center;
  min-height: 190px;
  padding: 14px 10px;
  margin-bottom: 14px;
  width: 100%;
  background: rgba(255,255,255,0.5);
  border-radius: var(--radius);
  animation: fadeDown 0.5s 0.15s ease both;
}
.tray-empty {
  font-family: 'Baloo 2', cursive; font-weight: 800;
  font-size: 1.35rem; color: var(--accent-green);
  animation: emptyPop 0.5s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes emptyPop {
  0% { opacity: 0; transform: scale(0.6); }
  100% { opacity: 1; transform: scale(1); }
}

.shape {
  width: 78px; height: 78px;
  cursor: grab;
  position: relative;
  touch-action: none;                 /* the shape owns the gesture, never the page */
  -webkit-user-select: none; user-select: none;
  -webkit-user-drag: none;
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), filter 0.25s;
  filter: drop-shadow(0 4px 8px rgba(61,44,46,0.16));
}
.shape:hover { transform: scale(1.09); filter: drop-shadow(0 7px 14px rgba(61,44,46,0.22)); }
.shape.dragging { opacity: 0.35; transform: scale(0.9); cursor: grabbing; }
.shape svg { width: 100%; height: 100%; display: block; pointer-events: none; }

.shape.pop-in { animation: shapePop 0.4s cubic-bezier(0.34,1.56,0.64,1) both; }
@keyframes shapePop {
  0% { opacity: 0; transform: scale(0) rotate(-20deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

.shape.rejected { animation: shapeReject 0.5s cubic-bezier(0.36,0.07,0.19,0.97); }
@keyframes shapeReject {
  0%, 100% { transform: translateX(0) rotate(0); }
  18% { transform: translateX(-9px) rotate(-7deg); }
  42% { transform: translateX(8px)  rotate(7deg); }
  66% { transform: translateX(-5px) rotate(-4deg); }
  85% { transform: translateX(3px)  rotate(2deg); }
}

/* ── Bins ── */
.bins {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  animation: fadeDown 0.5s 0.25s ease both;
}

.bin {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}

.bin-mouth {
  width: 100%; height: 92px;
  border-radius: 16px 16px 22px 22px;
  border: 3px dashed #D9CABC;
  background: rgba(255,255,255,0.72);
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.2s, background 0.2s, transform 0.2s, box-shadow 0.2s;
  position: relative;
}
.bin.over .bin-mouth {
  border-style: solid;
  transform: translateY(-4px) scale(1.04);
}
/* The count sits in the corner so the shapes inside stay readable */
.bin-count {
  position: absolute;
  top: 3px; right: 9px;
  font-family: 'Baloo 2', cursive; font-weight: 800;
  font-size: 1.3rem; color: #C9BDBE;
  transition: color 0.25s;
  z-index: 2;
}
.bin-count.pop { animation: countPop 0.35s cubic-bezier(0.34,1.56,0.64,1); }
@keyframes countPop {
  0% { transform: scale(1); } 45% { transform: scale(1.35); } 100% { transform: scale(1); }
}

.bin-label {
  font-size: 0.82rem; font-weight: 700; color: var(--text-muted);
  text-align: center; line-height: 1.2;
}
.bin-label strong {
  font-family: 'Baloo 2', cursive; font-size: 1.1rem;
  display: block;
}

/* per-bin colours */
#bin-3 .bin-mouth { border-color: var(--accent-red); }
#bin-3.over .bin-mouth { background: rgba(255,107,107,0.12); box-shadow: 0 8px 22px rgba(255,107,107,0.25); }
#bin-3 .bin-label strong, #bin-3 .bin-count.has { color: var(--accent-red); }

#bin-4 .bin-mouth { border-color: var(--accent-teal); }
#bin-4.over .bin-mouth { background: rgba(78,205,196,0.14); box-shadow: 0 8px 22px rgba(78,205,196,0.25); }
#bin-4 .bin-label strong, #bin-4 .bin-count.has { color: #2AA79E; }

#bin-5 .bin-mouth { border-color: var(--accent-purple); }
#bin-5.over .bin-mouth { background: rgba(108,92,231,0.12); box-shadow: 0 8px 22px rgba(108,92,231,0.25); }
#bin-5 .bin-label strong, #bin-5 .bin-count.has { color: var(--accent-purple); }

#bin-0 .bin-mouth { border-color: var(--accent-orange); }
#bin-0.over .bin-mouth { background: rgba(255,159,67,0.14); box-shadow: 0 8px 22px rgba(255,159,67,0.25); }
#bin-0 .bin-label strong, #bin-0 .bin-count.has { color: var(--accent-orange); }

/* mini shapes stacked inside a bin */
.bin-stack {
  position: absolute; inset: 6px;
  display: flex; flex-wrap: wrap; gap: 2px;
  align-items: flex-end; justify-content: center;
  pointer-events: none;
}
.bin-chip {
  width: 20px; height: 20px;
  animation: chipDrop 0.4s cubic-bezier(0.34,1.56,0.64,1) both;
}
.bin-chip svg { width: 100%; height: 100%; display: block; }
@keyframes chipDrop {
  0%   { opacity: 0; transform: translateY(-26px) scale(1.6) rotate(-16deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}

/* ── Feedback line ── */
.say-line {
  text-align: center; margin: 16px 0 2px;
  font-family: 'Baloo 2', cursive; font-weight: 700;
  font-size: 1.1rem; color: var(--text-muted);
  min-height: 30px;
  transition: color 0.2s;
  animation: fadeDown 0.5s 0.3s ease both;
}
.say-line.good  { color: var(--accent-green); }
.say-line.retry { color: var(--accent-orange); }

/* ── Drag ghost ── */
.drag-ghost {
  position: fixed; pointer-events: none; z-index: 9999;
  width: 78px; height: 78px;
  filter: drop-shadow(0 10px 18px rgba(0,0,0,0.28));
  transition: none;
}
.drag-ghost svg { width: 100%; height: 100%; display: block; }

/* ── Confetti ── */
.confetti {
  position: fixed; width: 9px; height: 14px;
  border-radius: 2px; pointer-events: none; z-index: 9998;
  animation: confettiFall 1.5s ease-in forwards;
}
@keyframes confettiFall {
  0%   { opacity: 1; transform: translate(0, 0) rotate(0deg); }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) rotate(var(--rot)); }
}

/* ── Actions ── */
.actions {
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center;
  animation: fadeDown 0.5s 0.4s ease both;
  margin-top: 12px;
}
.btn {
  font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 0.95rem;
  border: none; border-radius: 16px; padding: 12px 22px; cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.25s, opacity 0.3s;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.93); }
.btn:disabled { opacity: 0.35; pointer-events: none; }
.btn-icon { font-size: 1.1rem; display: inline-block; }
.btn-new {
  background: linear-gradient(135deg, var(--accent-purple), #A78BFA);
  color: #fff; box-shadow: 0 4px 14px rgba(108,92,231,0.32);
}
.btn-new:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(108,92,231,0.42); }
.btn-clear { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); }
.btn-clear:hover:not(:disabled) { box-shadow: var(--shadow-md); transform: translateY(-2px); }

@media (max-width: 480px) {
  .bins { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .shape { width: 66px; height: 66px; }
  .shape-tray { min-height: 160px; }
  .btn { padding: 11px 16px; font-size: 0.88rem; }
}

@media (prefers-reduced-motion: reduce) {
  .blob, .emoji-bounce { animation: none; }
  .shape.pop-in, .bin-chip { animation-duration: 0.01s; }
}
