*, *::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;
  --beam-angle: 0deg;
}

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-green); top: -140px; left: -80px; }
.blob-2 { width: 340px; height: 340px; background: var(--accent-orange); bottom: -100px; right: -60px; animation-delay: -5s; }
.blob-3 { width: 280px; height: 280px; background: var(--accent-purple); 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: 540px; margin: 0 auto; width: 100%;
}

/* header */
.game-header { text-align: center; margin-bottom: 12px; 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-green), var(--accent-teal));
  -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); }
}

/* ── Item tray ── */
.item-tray {
  display: flex; gap: 12px; flex-wrap: wrap; justify-content: center;
  margin-bottom: 16px; padding: 0 8px;
  animation: fadeDown 0.5s 0.15s ease both;
}

.draggable-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  cursor: grab; padding: 10px 12px 8px;
  background: var(--card); border-radius: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s;
  position: relative;
  -webkit-user-drag: none;
}
.draggable-item:hover { transform: scale(1.08); box-shadow: var(--shadow-md); }
.draggable-item:active, .draggable-item.dragging { cursor: grabbing; transform: scale(0.95); opacity: 0.6; }
.draggable-item.pop-in { animation: itemPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
@keyframes itemPop {
  0% { opacity: 0; transform: scale(0) rotate(-10deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

/* ── Number block stacks (tray) ── */
.block-stack {
  display: flex; flex-direction: column-reverse;
  gap: 2px; align-items: center;
  pointer-events: none;
}

.mini-block {
  width: 28px; height: 16px;
  border-radius: 4px;
  box-shadow: inset 0 -2px 3px rgba(0,0,0,0.15), inset 0 1px 1px rgba(255,255,255,0.3);
}

.block-number {
  font-family: 'Baloo 2', cursive;
  font-weight: 800; font-size: 1.1rem;
  line-height: 1;
  pointer-events: none;
}

/* ── Number block stacks (on pans) ── */
.pan-block-stack {
  display: flex; flex-direction: column-reverse;
  gap: 1px; align-items: center;
}

.pan-mini-block {
  width: 20px; height: 11px;
  border-radius: 3px;
  box-shadow: inset 0 -2px 2px rgba(0,0,0,0.15), inset 0 1px 1px rgba(255,255,255,0.3);
}

.pan-item {
  animation: panItemDrop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes panItemDrop {
  0% { opacity: 0; transform: translateY(-20px) scale(0.5); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Scale ── */
.scale-stage {
  width: 100%; position: relative;
  animation: fadeDown 0.5s 0.25s ease both;
  margin-bottom: 10px;
}

.scale-container {
  position: relative;
  width: 100%;
  height: 260px;
}

/* Pillar */
.pillar {
  position: absolute;
  left: 50%; bottom: 0;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  z-index: 2;
}
.pillar-top {
  width: 18px; height: 18px;
  background: #B8860B;
  border-radius: 50%;
  border: 3px solid #DAA520;
  z-index: 3;
}
.pillar-body {
  width: 10px; height: 100px;
  background: linear-gradient(to right, #CD853F, #DAA520, #CD853F);
  border-radius: 4px;
}
.pillar-base {
  width: 80px; height: 14px;
  background: linear-gradient(to bottom, #DAA520, #B8860B);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

/* Beam */
.beam {
  position: absolute;
  left: 50%; top: 42px;
  width: 380px;
  transform: translateX(-50%) rotate(var(--beam-angle));
  transform-origin: center 9px;
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 1;
  height: 18px;
}

.beam-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 18px;
  background: linear-gradient(to bottom, #DAA520, #B8860B);
  border-radius: 9px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.10);
}

/* Pan assemblies */
.pan-assembly {
  position: absolute;
  top: 14px;
  display: flex; flex-direction: column; align-items: center;
}
.pan-left  { left: 10px; }
.pan-right { right: 10px; }

.chain {
  width: 2px; height: 50px;
  background: repeating-linear-gradient(
    to bottom,
    #B8860B 0px, #B8860B 4px,
    transparent 4px, transparent 8px
  );
}

.pan {
  width: 120px;
  min-height: 50px;
  background: linear-gradient(to bottom, #CD853F, #A0522D);
  border-radius: 8px 8px 50% 50%;
  box-shadow: inset 0 -4px 8px rgba(0,0,0,0.15), 0 4px 12px rgba(0,0,0,0.10);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 6px 6px 10px;
  transition: box-shadow 0.2s;
  position: relative;
}
.pan.drag-over {
  box-shadow: 0 0 0 3px var(--accent-purple), inset 0 -4px 8px rgba(0,0,0,0.15), 0 4px 16px rgba(108,92,231,0.2);
}

.pan-items {
  display: flex; flex-wrap: wrap; gap: 4px;
  justify-content: center; align-items: flex-end;
  transform: rotate(calc(var(--beam-angle) * -1));
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Balance badge ── */
.balance-badge {
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  padding: 4px 14px;
  border-radius: 20px;
  font-family: 'Baloo 2', cursive;
  font-weight: 700; font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 5;
  pointer-events: none;
  white-space: nowrap;
}
.balance-badge.balanced {
  opacity: 1;
  background: linear-gradient(135deg, var(--accent-green), var(--accent-teal));
  color: #fff;
  box-shadow: 0 4px 16px rgba(46,204,113,0.35);
  animation: badgePulse 1.5s ease-in-out infinite;
}
.balance-badge.unbalanced {
  opacity: 1;
  background: var(--card);
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
}
@keyframes badgePulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.06); }
}

/* ── Totals row ── */
.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 0 24px;
  margin-top: 8px;
}

.total-pill {
  background: var(--card);
  border-radius: 14px;
  padding: 6px 20px;
  box-shadow: var(--shadow-sm);
  min-width: 50px;
  text-align: center;
}

.total-num {
  font-family: 'Baloo 2', cursive;
  font-weight: 800;
  font-size: 1.5rem;
  color: var(--accent-purple);
  transition: transform 0.2s;
}
.total-num.pop { animation: counterPop 0.3s ease; }
@keyframes counterPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ── Buttons ── */
.actions {
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center;
  animation: fadeDown 0.5s 0.4s ease both;
  margin-top: 10px;
}
.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;
}
.btn:active { transform: scale(0.93); }
.btn:disabled { opacity: 0.35; pointer-events: none; }
.btn-icon { font-size: 1.1rem; display: inline-block; }

.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); }

/* ── Drag ghost ── */
.drag-ghost {
  position: fixed; pointer-events: none; z-index: 9999;
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Baloo 2', cursive; font-weight: 800;
  font-size: 1.4rem; color: #fff;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  transition: none;
}

@media (max-width: 420px) {
  .beam { width: 300px; }
  .pan { width: 95px; min-height: 42px; }
  .mini-block { width: 24px; height: 14px; }
  .pan-mini-block { width: 16px; height: 9px; }
  .scale-container { height: 240px; }
  .btn { padding: 10px 16px; font-size: 0.88rem; }
  .totals-row { padding: 0 16px; }
}
