/* ════════════════════════════════════════════════════════
   Balance — drag-and-drop equality game
   ════════════════════════════════════════════════════════ */

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

html, body {
  height: 100vh;
  min-height: 100vh;
  width: 100vw;
  overflow: hidden;
  font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none; /* prevent browser drag/scroll on touch during drag-and-drop */
  color: #2c1810;
}

body {
  position: relative;
  background: transparent;
  display: flex;
  flex-direction: column;
}

/* ─── Forest backdrop ──────────────────────────────────── */
.forest {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: -2;
  background: linear-gradient(
    180deg,
    #fef3d3 0%,
    #fce5b8 18%,
    #f4d29c 32%,
    #e6c896 44%,
    #d2c489 56%,
    #b3bf78 70%,
    #97b06b 84%,
    #7a9a5e 100%
  );
}
.sky-glow {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 50%;
  background: radial-gradient(ellipse 80% 60% at 70% 0%, rgba(255, 220, 140, 0.55) 0%, transparent 70%);
  pointer-events: none;
}
.sun {
  position: absolute;
  top: 6%;
  right: 14%;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff5d0 0%, #ffd96a 50%, #f5a700 100%);
  box-shadow: 0 0 60px 20px rgba(255, 217, 106, 0.45);
  animation: sunGlow 5s ease-in-out infinite;
}
@keyframes sunGlow {
  0%, 100% { box-shadow: 0 0 60px 20px rgba(255, 217, 106, 0.45); }
  50%      { box-shadow: 0 0 90px 30px rgba(255, 217, 106, 0.65); }
}

/* Distant trees */
.trees-far {
  position: absolute;
  bottom: 18%;
  left: 0; right: 0;
  height: 18%;
  background:
    radial-gradient(ellipse 120px 100px at 8%  100%, #6b8e5a 0 60%, transparent 65%),
    radial-gradient(ellipse 100px 80px  at 22% 100%, #7ba169 0 60%, transparent 65%),
    radial-gradient(ellipse 140px 110px at 38% 100%, #5e7d4f 0 60%, transparent 65%),
    radial-gradient(ellipse 110px 90px  at 55% 100%, #6b8e5a 0 60%, transparent 65%),
    radial-gradient(ellipse 130px 105px at 72% 100%, #7ba169 0 60%, transparent 65%),
    radial-gradient(ellipse 90px  75px  at 88% 100%, #5e7d4f 0 60%, transparent 65%);
  filter: blur(1px);
  opacity: 0.85;
}
/* Closer trees */
.trees-mid {
  position: absolute;
  bottom: 10%;
  left: 0; right: 0;
  height: 14%;
  background:
    radial-gradient(ellipse 80px 70px at 5%  100%, #4f6e44 0 60%, transparent 65%),
    radial-gradient(ellipse 70px 60px at 16% 100%, #5d7e52 0 60%, transparent 65%),
    radial-gradient(ellipse 90px 80px at 30% 100%, #4a6840 0 60%, transparent 65%),
    radial-gradient(ellipse 60px 55px at 44% 100%, #5d7e52 0 60%, transparent 65%),
    radial-gradient(ellipse 85px 75px at 60% 100%, #4f6e44 0 60%, transparent 65%),
    radial-gradient(ellipse 70px 65px at 76% 100%, #5d7e52 0 60%, transparent 65%),
    radial-gradient(ellipse 80px 70px at 92% 100%, #4a6840 0 60%, transparent 65%);
}
.ground {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 12%;
  background: linear-gradient(180deg, #7a9a5e 0%, #5d7e44 60%, #3e5a30 100%);
  box-shadow: inset 0 8px 16px rgba(50, 80, 30, 0.4);
}

.leaves {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.leaf {
  position: absolute;
  font-size: 22px;
  pointer-events: none;
  opacity: 0.85;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.2));
  animation: leafFall var(--dur, 14s) linear infinite;
  animation-delay: var(--delay, 0s);
}
@keyframes leafFall {
  0%   { transform: translate(0, -40px) rotate(0deg); opacity: 0; }
  10%  { opacity: 0.85; }
  90%  { opacity: 0.85; }
  100% { transform: translate(var(--dx, 80px), 105vh) rotate(var(--rot, 360deg)); opacity: 0; }
}

/* ─── HUD ──────────────────────────────────────────────── */
.hud {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  z-index: 10;
}
.hud-side { flex: 0 0 auto; min-width: 90px; }
.hud-side--right { display: flex; justify-content: flex-end; }
.hud-center { flex: 1 1 auto; display: flex; justify-content: center; }

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 250, 235, 0.95);
  padding: 8px 14px;
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(74, 54, 33, 0.25);
  font-size: 18px;
  font-weight: 700;
  color: #4a3621;
  font-variant-numeric: tabular-nums;
  min-width: 64px;
  justify-content: center;
}
.streak-pill { color: #c44820; }
.pill-icon { font-size: 18px; }
.pill-num--bump { animation: numBump 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes numBump {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.4); color: #d4a04e; }
  100% { transform: scale(1); }
}

.mode-tabs {
  display: inline-flex;
  background: rgba(255, 250, 235, 0.92);
  border: 3px solid #fff;
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
  box-shadow: 0 4px 12px rgba(74, 54, 33, 0.25);
}
.mode-btn {
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  color: #8a6d50;
  background: transparent;
  border: none;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.12s ease;
  white-space: nowrap;
}
.mode-btn:active { transform: scale(0.94); }
.mode-btn--active {
  background: linear-gradient(180deg, #d4a04e, #b27d2e);
  color: #fff;
  box-shadow: 0 2px 6px rgba(178, 125, 46, 0.5), inset 0 -2px 0 rgba(0,0,0,0.1);
  text-shadow: 0 1px 0 rgba(0,0,0,0.2);
}

/* ─── Prompt banner ────────────────────────────────────── */
.prompt-banner {
  position: relative;
  margin: 4px auto 12px;
  padding: 10px 28px 12px;
  background: linear-gradient(180deg, #fff8e5, #fbf0d4);
  border: 3px solid #d4a04e;
  border-radius: 22px;
  box-shadow: 0 6px 18px rgba(74, 54, 33, 0.28), inset 0 -3px 0 rgba(0,0,0,0.06);
  text-align: center;
  width: fit-content;
  max-width: 90vw;
  z-index: 5;
  animation: bannerPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes bannerPop {
  from { transform: scale(0.6) translateY(-8px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.prompt-label {
  font-size: 13px;
  font-weight: 600;
  color: #8a6d50;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.prompt-math {
  font-size: 30px;
  font-weight: 700;
  color: #2c1810;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  line-height: 1.1;
  margin-top: 2px;
}
.prompt-math .blank {
  display: inline-block;
  min-width: 1.2em;
  border-bottom: 4px dotted #d4a04e;
  margin: 0 0.1em;
  padding-bottom: 2px;
}

/* ─── Stage layout ─────────────────────────────────────── */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  min-height: 0;
}

/* ─── Scale ────────────────────────────────────────────── */
.scale-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.scale {
  position: relative;
  width: min(640px, 92vw);
  height: 360px;
}

/* Wooden post (vertical) */
.post {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 230px;
  background: linear-gradient(90deg, #6b5234 0%, #8b6f47 30%, #9d7e54 50%, #8b6f47 70%, #6b5234 100%);
  border-radius: 4px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.25), inset 0 0 12px rgba(0,0,0,0.18);
}
.post::before {
  /* wood grain */
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 8px, rgba(74, 54, 33, 0.2) 8px 9px),
    radial-gradient(ellipse 4px 12px at 30% 30%, rgba(74, 54, 33, 0.4), transparent 70%),
    radial-gradient(ellipse 3px 10px at 70% 70%, rgba(74, 54, 33, 0.4), transparent 70%);
  border-radius: 4px;
}

.post-base {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 100px;
  height: 18px;
  background: linear-gradient(180deg, #7a5a38 0%, #5a4128 100%);
  border-radius: 50% 50% 8px 8px / 60% 60% 8px 8px;
  box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}

.pivot {
  position: absolute;
  top: 130px;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #d4a04e, #8a5a1f 70%, #4a2812 100%);
  border: 2px solid #4a2812;
  box-shadow: 0 2px 6px rgba(0,0,0,0.45);
  z-index: 3;
}

/* Beam (rotates around pivot) */
.beam {
  position: absolute;
  top: 144px;
  left: 50%;
  transform: translateX(-50%) rotate(0deg);
  transform-origin: 50% 0;
  width: 580px;
  max-width: 90vw;
  height: 0;
  transition: transform 0.55s cubic-bezier(0.34, 1.06, 0.4, 1);
  z-index: 2;
}
.beam-bar {
  position: absolute;
  top: -8px;
  left: 0; right: 0;
  height: 14px;
  background: linear-gradient(180deg, #9d7e54 0%, #8b6f47 30%, #6b5234 100%);
  border-radius: 6px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.3), inset 0 -2px 4px rgba(0,0,0,0.25);
}
.beam-bar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    90deg, transparent 0 18px, rgba(74, 54, 33, 0.18) 18px 19px
  );
  border-radius: 6px;
}

.rope {
  position: absolute;
  top: 0;
  width: 4px;
  height: 90px;
  background: linear-gradient(180deg, #b8966a 0%, #8a6d4a 100%);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(74, 54, 33, 0.3);
}
.rope-left  { left: 50px;  }
.rope-right { right: 50px; }

.pan {
  position: absolute;
  top: 86px;
  width: 220px;
  height: 100px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.pan-left  { left: -60px;  }
.pan-right { right: -60px; }

.pan-surface {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 24px;
  background: linear-gradient(180deg, #c4a276 0%, #8b6f47 60%, #6b5234 100%);
  border-radius: 50% 50% 8px 8px / 80% 80% 8px 8px;
  box-shadow: 0 6px 12px rgba(0,0,0,0.3);
}
.pan-surface::before {
  /* top highlight */
  content: '';
  position: absolute;
  top: 2px; left: 8px; right: 8px;
  height: 4px;
  background: linear-gradient(90deg, transparent, rgba(255,240,200,0.6), transparent);
  border-radius: 50%;
}

.pan-tiles {
  position: absolute;
  bottom: 18px;
  left: 0; right: 0;
  display: flex;
  flex-wrap: wrap-reverse;
  justify-content: center;
  align-items: flex-end;
  gap: 2px;
  padding: 0 14px 4px;
  pointer-events: none; /* tiles inside intercept their own events */
}

/* When balanced — soft green glow on pans */
.scale--balanced .pan-surface {
  box-shadow: 0 0 0 3px #4cd964, 0 0 24px 6px rgba(76, 217, 100, 0.6),
              0 6px 12px rgba(0,0,0,0.3);
}
.scale--balanced .beam-bar {
  box-shadow: 0 0 0 2px rgba(76, 217, 100, 0.6), 0 4px 8px rgba(0,0,0,0.3);
}

/* ─── Balance indicator ────────────────────────────────── */
.balance-indicator {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 250, 235, 0.9);
  padding: 4px 12px;
  border-radius: 999px;
  border: 2px solid #d4a04e;
  font-size: 13px;
  font-weight: 600;
  color: #4a3621;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  pointer-events: none;
  z-index: 4;
}
.indicator-light {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #c44820;
  box-shadow: 0 0 6px #c44820;
  transition: background 0.3s ease, box-shadow 0.3s ease;
}
.balance-indicator--ok .indicator-light {
  background: #4cd964;
  box-shadow: 0 0 8px #4cd964;
}

/* ─── Tile tray ────────────────────────────────────────── */
.tray-wrap {
  flex: 0 0 auto;
  padding: 8px 16px 16px;
  display: flex;
  justify-content: center;
  z-index: 6;
}
.tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  background: linear-gradient(180deg, #6b5234 0%, #4a3621 100%);
  border: 4px solid #4a3621;
  border-radius: 16px;
  box-shadow: 0 6px 14px rgba(0,0,0,0.35), inset 0 4px 8px rgba(0,0,0,0.3);
  max-width: min(700px, 96vw);
  min-height: 76px;
}
.tray::before {
  content: 'TILES';
  position: absolute;
  /* (decorative label could go here, but keeping minimal) */
}

/* ─── Tile ─────────────────────────────────────────────── */
.tile {
  position: relative;
  width: 56px;
  height: 56px;
  border: none;
  background: transparent;
  padding: 0;
  cursor: grab;
  flex: 0 0 auto;
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: auto;
  z-index: 1;
}
.tile:active { cursor: grabbing; transform: scale(1.06); }
.tile:hover  { transform: translateY(-2px); }
.tile--dragging {
  z-index: 1000;
  transform: scale(1.18);
  filter: drop-shadow(0 12px 18px rgba(0,0,0,0.4));
  cursor: grabbing;
  transition: none;
}

/* The tile wood disc */
.tile-svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,0.35));
  pointer-events: none;
}

/* Tile when on a pan (rendered smaller) */
.pan-tiles .tile {
  width: 44px;
  height: 44px;
}
.pan-tiles .tile:hover { transform: none; }

/* Tile while returning home */
.tile--returning {
  transition: transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ─── Particles ────────────────────────────────────────── */
.drag-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
}
.particle-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 800;
}

.spark {
  position: absolute;
  font-size: 22px;
  pointer-events: none;
  animation: sparkFly var(--dur, 1s) ease-out forwards;
}
@keyframes sparkFly {
  0%   { transform: translate(0, 0) scale(0.4) rotate(0); opacity: 0; }
  20%  { opacity: 1; }
  100% { transform: translate(var(--dx, 0), var(--dy, -120px)) scale(1.1) rotate(var(--rot, 360deg)); opacity: 0; }
}

.glow-ring {
  position: absolute;
  width: 100px; height: 100px;
  border: 4px solid rgba(76, 217, 100, 0.85);
  border-radius: 50%;
  animation: ringExpand 0.8s ease-out forwards;
}
@keyframes ringExpand {
  0%   { transform: scale(0.3); opacity: 1; }
  100% { transform: scale(2.8); opacity: 0; }
}

.confetti {
  position: absolute;
  width: 10px;
  height: 14px;
  pointer-events: none;
  animation: confettiFall var(--dur, 2.4s) cubic-bezier(0.5, 0.05, 0.6, 1) forwards;
}
@keyframes confettiFall {
  0%   { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx, 0), var(--dy, 100vh)) rotate(var(--rot, 720deg)); opacity: 0.4; }
}

/* ─── Overlay ──────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(50, 35, 20, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: overlayFade 0.3s ease;
}
@keyframes overlayFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.overlay[hidden] { display: none; }

.overlay-card {
  background: linear-gradient(180deg, #fff8e0 0%, #fbf0d4 100%);
  color: #2c1810;
  border: 4px solid #d4a04e;
  border-radius: 26px;
  padding: 28px 32px;
  text-align: center;
  box-shadow: 0 14px 40px rgba(74, 54, 33, 0.5);
  max-width: 90vw;
  min-width: 280px;
  animation: cardPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes cardPop {
  from { transform: scale(0.5) translateY(30px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}
.overlay-emoji {
  font-size: 64px;
  line-height: 1;
  margin-bottom: 6px;
  animation: emojiSpin 1.6s ease-in-out infinite;
}
@keyframes emojiSpin {
  0%, 100% { transform: rotate(-12deg); }
  50%      { transform: rotate(12deg); }
}
.overlay-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 16px;
  color: #2c1810;
}
.overlay-stats {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-bottom: 14px;
}
.stat {
  background: #fff;
  border: 3px solid #e6c896;
  border-radius: 16px;
  padding: 10px 18px;
  min-width: 96px;
}
.stat-label {
  font-size: 12px;
  font-weight: 600;
  color: #8a6d50;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.stat-num {
  font-size: 36px;
  font-weight: 700;
  color: #2c1810;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.overlay-msg {
  font-size: 16px;
  color: #8a6d50;
  margin-bottom: 18px;
  min-height: 1.5em;
}
.overlay-msg--big {
  color: #c44820;
  font-weight: 700;
  font-size: 18px;
  animation: msgPulse 1s ease-in-out infinite;
}
@keyframes msgPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

.big-btn {
  font-family: 'Fredoka', sans-serif;
  font-weight: 700;
  font-size: 22px;
  color: #fff;
  background: linear-gradient(180deg, #d4a04e, #b27d2e);
  border: none;
  padding: 14px 36px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0,0,0,0.18), 0 8px 16px rgba(178, 125, 46, 0.5);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  text-shadow: 0 1px 0 rgba(0,0,0,0.2);
}
.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0,0,0,0.18), 0 4px 8px rgba(178, 125, 46, 0.5);
}

/* ─── Responsive ───────────────────────────────────────── */
@media (max-width: 600px) {
  .hud { padding: 8px 8px; gap: 6px; }
  .hud-side { min-width: 0; }
  .stat-pill { padding: 6px 12px; font-size: 16px; min-width: 56px; }
  .pill-icon { font-size: 16px; }
  .mode-btn { font-size: 13px; padding: 5px 10px; }
  .prompt-math { font-size: 26px; }
  .prompt-banner { padding: 8px 18px; }
  .sun { width: 60px; height: 60px; }
  .scale { height: 280px; }
  .post { height: 180px; }
  .pivot { top: 90px; }
  .beam { top: 104px; width: 96vw; }
  .pan { width: 160px; height: 80px; top: 70px; }
  .pan-left  { left: -40px; }
  .pan-right { right: -40px; }
  .rope { height: 70px; }
  .tile { width: 48px; height: 48px; }
  .pan-tiles .tile { width: 38px; height: 38px; }
  .tray { padding: 10px 12px; gap: 6px; }
  .overlay-card { padding: 22px 24px; min-width: 240px; }
  .overlay-emoji { font-size: 52px; }
  .overlay-title { font-size: 22px; }
  .stat-num { font-size: 28px; }
  .stat { padding: 8px 14px; min-width: 80px; }
  .big-btn { font-size: 18px; padding: 12px 28px; }
}

@media (max-width: 380px) {
  .scale { height: 240px; }
  .post { height: 150px; }
  .pivot { top: 70px; }
  .beam { top: 84px; }
  .pan { width: 140px; height: 70px; top: 60px; }
  .rope { height: 60px; }
  .tile { width: 42px; height: 42px; }
  .pan-tiles .tile { width: 34px; height: 34px; }
}
