/* =====================================================================
   Math Balance Game Styles (Ages 5-7)
   Professor Owl's Laboratory: Antique Scale Physics, Brass Weights
   ===================================================================== */

:root {
  --beam-angle: 0deg;
  --brass-dark: #8c6d23;
  --brass-mid: #d4af37;
  --brass-light: #fef08a;
  --pan-dish: #e2c068;
  --wood-tray: #5c3a21;
  --lab-bg-top: #fbf6ec;
  --lab-bg-bottom: #eddcc4;
}

body {
  background: linear-gradient(180deg, var(--lab-bg-top) 0%, var(--lab-bg-bottom) 100%);
  color: #2c1a0e;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}

.game-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  box-sizing: border-box;
}

/* ---------------------------------------------------------------------
   Workspace Layout
   --------------------------------------------------------------------- */

.balance-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 16px 14px;
  box-sizing: border-box;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ---------------------------------------------------------------------
   Top Info Bar: Professor Badge, Equation, Round
   --------------------------------------------------------------------- */

.top-info-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: 12px;
  margin-bottom: 4px;
}

.professor-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #ffffff;
  padding: 6px 14px;
  border-radius: 20px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
  font-weight: 800;
  font-size: 0.95rem;
  color: #452a12;
}

.badge-avatar {
  font-size: 1.5rem;
}

.equation-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  border: 3px solid #d4af37;
  border-radius: 24px;
  padding: 6px 20px;
  box-shadow: 0 4px 12px rgba(140, 109, 35, 0.15);
  font-weight: 900;
  font-size: 1.4rem;
  letter-spacing: 0.5px;
}

.eq-side {
  color: #2c1a0e;
  min-width: 32px;
  text-align: center;
}

.eq-operator {
  color: #d97706;
  font-size: 1.5rem;
  transition: transform 0.3s ease, color 0.3s ease;
}

.equation-card.is-equal {
  border-color: #10b981;
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.35);
}

.equation-card.is-equal .eq-operator {
  color: #10b981;
  transform: scale(1.2);
}

.round-indicator {
  background: rgba(255, 255, 255, 0.85);
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 800;
  font-size: 0.95rem;
  color: #5c3a21;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

/* ---------------------------------------------------------------------
   Central Scale Apparatus
   --------------------------------------------------------------------- */

.scale-section {
  position: relative;
  width: 100%;
  max-width: 580px;
  height: 290px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 6px 0;
}

.scale-apparatus {
  position: relative;
  width: 100%;
  height: 240px;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Central Stand & Base */
.scale-base {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 150px;
  height: 22px;
  background: linear-gradient(180deg, var(--brass-light) 0%, var(--brass-mid) 50%, var(--brass-dark) 100%);
  border-radius: 12px 12px 4px 4px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
  z-index: 1;
}

.scale-stand {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 165px;
  background: linear-gradient(90deg, var(--brass-mid) 0%, var(--brass-light) 50%, var(--brass-dark) 100%);
  border-radius: 4px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  z-index: 1;
}

/* Central Fulcrum with Dial & Pointer */
.scale-fulcrum {
  position: absolute;
  top: 45px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, var(--brass-light) 0%, var(--brass-mid) 70%, var(--brass-dark) 100%);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
}

.dial-arc {
  position: absolute;
  top: -24px;
  width: 68px;
  height: 32px;
  border: 3px solid rgba(140, 109, 35, 0.6);
  border-bottom: none;
  border-radius: 36px 36px 0 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.center-star {
  font-size: 0.85rem;
  margin-top: -2px;
  opacity: 0.45;
  transition: opacity 0.3s, transform 0.3s;
}

.scale-apparatus.balanced .center-star {
  opacity: 1;
  transform: scale(1.4);
  filter: drop-shadow(0 0 6px #10b981);
}

.scale-pointer {
  position: absolute;
  bottom: 30px;
  width: 4px;
  height: 48px;
  background: #dc2626;
  border-radius: 2px;
  transform-origin: bottom center;
  transform: rotate(calc(var(--beam-angle) * 1.5));
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.scale-apparatus.balanced .scale-pointer {
  background: #10b981;
}

/* The Tilting Balance Beam */
.scale-beam {
  position: absolute;
  top: 72px;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: 90%;
  max-width: 480px;
  height: 12px;
  background: linear-gradient(180deg, var(--brass-light) 0%, var(--brass-mid) 60%, var(--brass-dark) 100%);
  border-radius: 6px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  transform-origin: center center;
  transform: rotate(var(--beam-angle));
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  z-index: 5;
}

/* Pan Hangers (Counter-rotating to stay vertical) */
.pan-hanger {
  position: absolute;
  top: 6px;
  width: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: 50% 0;
  transform: rotate(calc(-1 * var(--beam-angle, 0deg)));
  transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.hanger-left {
  left: -20px;
}

.hanger-right {
  right: -20px;
}

.pan-chains {
  width: 100px;
  height: 60px;
  border-left: 2px dashed rgba(140, 109, 35, 0.7);
  border-right: 2px dashed rgba(140, 109, 35, 0.7);
  margin: 0 auto;
}

.scale-pan {
  position: relative;
  width: 126px;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  border-radius: 14px 14px 28px 28px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  cursor: pointer;
  outline: none;
}

.scale-pan:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 4px;
}

.pan-weights-area {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  align-items: flex-end;
  min-height: 48px;
  padding: 4px 6px;
  width: 100%;
  box-sizing: border-box;
  z-index: 2;
}

.pan-dish {
  width: 100%;
  height: 18px;
  background: linear-gradient(180deg, var(--brass-light) 0%, var(--pan-dish) 50%, var(--brass-dark) 100%);
  border-radius: 0 0 28px 28px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  margin-top: -6px;
}

.pan-right.highlight {
  transform: scale(1.08);
  filter: drop-shadow(0 0 14px rgba(245, 158, 11, 0.8));
}

.pan-right.awaiting-drop {
  animation: panPulse 1.2s infinite ease-in-out;
}

@keyframes panPulse {
  0%, 100% {
    filter: drop-shadow(0 0 4px rgba(245, 158, 11, 0.4));
  }
  50% {
    filter: drop-shadow(0 0 14px rgba(245, 158, 11, 0.85));
  }
}

.pan-sum-badge {
  background: #ffffff;
  border: 2px solid var(--brass-mid);
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: 800;
  font-size: 0.95rem;
  color: #5c3a21;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  margin-top: 6px;
}

.scale-apparatus.balanced .pan-sum-badge {
  border-color: #10b981;
  color: #065f46;
  background: #ecfdf5;
}

/* Status message */
.balance-status {
  min-height: 1.6em;
  font-weight: 800;
  font-size: 1.1rem;
  color: #5c3a21;
  text-align: center;
  margin-top: 8px;
  transition: color 0.3s;
}

.balance-status.balanced {
  color: #059669;
}

/* ---------------------------------------------------------------------
   Bottom Rack Shelf: Brass Weights
   --------------------------------------------------------------------- */

.rack-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.weights-shelf {
  background: linear-gradient(180deg, #7c4d29 0%, var(--wood-tray) 60%, #3e2411 100%);
  border-radius: 20px;
  padding: 10px 16px;
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: flex-end;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2), inset 0 2px 4px rgba(255, 255, 255, 0.3);
  max-width: 620px;
  width: 100%;
  box-sizing: border-box;
  flex-wrap: wrap;
}

.weight-slot {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: 64px;
}

.weight-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  outline: none;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
  touch-action: none;
}

.weight-btn:hover:not(:disabled) {
  transform: translateY(-4px) scale(1.08);
}

.weight-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.weight-btn.selected {
  transform: translateY(-8px) scale(1.15);
}

.weight-btn.selected .weight-bell {
  box-shadow: 0 0 14px #f59e0b, 0 6px 12px rgba(0, 0, 0, 0.3);
  border-color: #ffffff;
}

.weight-btn.dragging {
  cursor: grabbing !important;
  opacity: 0.95;
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.35);
  transform: scale(1.2) rotate(3deg);
  pointer-events: none;
  position: fixed;
  z-index: 1000;
}

/* Kettlebell Brass Visual */
.weight-ring {
  width: 14px;
  height: 8px;
  border: 3px solid var(--brass-dark);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  margin-bottom: -1px;
}

.weight-bell {
  background: radial-gradient(circle at 35% 30%, #fff9c4 0%, var(--brass-mid) 50%, var(--brass-dark) 100%);
  border: 2px solid #5a420f;
  border-radius: 8px 8px 14px 14px;
  color: #3b280a;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.25), inset 0 2px 4px rgba(255, 255, 255, 0.5);
}

/* Proportional weight dimensions */
.w-1 { width: 34px; height: 36px; font-size: 0.85rem; }
.w-2 { width: 38px; height: 40px; font-size: 0.95rem; }
.w-3 { width: 42px; height: 44px; font-size: 1.05rem; }
.w-4 { width: 46px; height: 48px; font-size: 1.15rem; }
.w-5 { width: 50px; height: 52px; font-size: 1.25rem; }
.w-6 { width: 54px; height: 55px; font-size: 1.3rem; }
.w-7 { width: 58px; height: 58px; font-size: 1.35rem; }
.w-8 { width: 62px; height: 60px; font-size: 1.4rem; }
.w-9 { width: 65px; height: 62px; font-size: 1.45rem; }
.w-10 { width: 68px; height: 64px; font-size: 1.45rem; }

/* In-Pan Nested Weights */
.pan-weight-token {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: transparent;
  border: none;
  padding: 0;
  outline: none;
  animation: weightDrop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.pan-weight-token.removable {
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.pan-weight-token.removable:hover {
  transform: translateY(-3px) scale(1.06);
  filter: drop-shadow(0 2px 6px rgba(220, 38, 38, 0.45));
}

.pan-weight-token.removable:active {
  transform: scale(0.92);
}

.pan-weight-token:focus-visible {
  outline: 3px solid var(--game-focus, #ffb300);
  outline-offset: 2px;
  border-radius: 6px;
}

.pan-weight-token .weight-ring {
  width: 10px;
  height: 6px;
  border-width: 2px;
}

.pan-weight-token .weight-bell {
  border-radius: 6px 6px 10px 10px;
}

/* Controls bar */
.controls-bar {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.action-btn {
  font-family: inherit;
  font-weight: 800;
  font-size: 1rem;
  padding: 10px 22px;
  border-radius: 28px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
  transition: transform 0.1s ease, filter 0.2s ease, opacity 0.2s ease;
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.action-btn:active {
  transform: scale(0.96);
}

.clear-btn {
  background: #f1f5f9;
  color: #475569;
}

.next-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}

.primary-btn {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #ffffff;
}

.hidden {
  display: none !important;
}

/* ---------------------------------------------------------------------
   Celebration Overlay
   --------------------------------------------------------------------- */

.celebration-overlay {
  position: absolute;
  inset: 0;
  background: rgba(44, 26, 14, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 16px;
}

.celebration-card {
  background: #ffffff;
  padding: 24px 32px;
  border-radius: 28px;
  text-align: center;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.25);
  max-width: 420px;
  width: 100%;
  animation: cardBounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.celebration-icon {
  font-size: 3.2rem;
  margin-bottom: 8px;
}

.celebration-text {
  font-size: 1.25rem;
  font-weight: 800;
  color: #2c1a0e;
  margin-bottom: 20px;
  line-height: 1.4;
}

/* Sparks layer */
.sparks-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}

.sparkle {
  position: absolute;
  font-size: 1.5rem;
  line-height: 1;
  animation: sparkBurst 0.8s ease-out forwards;
}

/* ---------------------------------------------------------------------
   Keyframes & Animations
   --------------------------------------------------------------------- */

@keyframes weightDrop {
  0% { transform: translateY(-16px) scale(0.8); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes cardBounce {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes sparkBurst {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.3); opacity: 0; }
}

/* ---------------------------------------------------------------------
   Mobile Responsive
   --------------------------------------------------------------------- */

@media (max-width: 600px) {
  .scale-section {
    height: 240px;
  }
  .scale-apparatus {
    height: 210px;
  }
  .scale-beam {
    max-width: 340px;
    height: 10px;
  }
  .pan-hanger {
    width: 110px;
  }
  .pan-chains {
    width: 76px;
    height: 48px;
  }
  .scale-pan {
    width: 96px;
  }
  .pan-weights-area {
    min-height: 38px;
  }
  .pan-sum-badge {
    font-size: 0.82rem;
    padding: 1px 6px;
  }
  .equation-card {
    font-size: 1.15rem;
    padding: 4px 14px;
  }
  .weights-shelf {
    gap: 6px;
    padding: 8px 10px;
  }
  .w-1 { width: 28px; height: 30px; font-size: 0.75rem; }
  .w-2 { width: 32px; height: 34px; font-size: 0.82rem; }
  .w-3 { width: 35px; height: 38px; font-size: 0.9rem; }
  .w-4 { width: 39px; height: 42px; font-size: 0.98rem; }
  .w-5 { width: 42px; height: 45px; font-size: 1.05rem; }
  .w-6 { width: 45px; height: 48px; font-size: 1.1rem; }
  .w-7 { width: 48px; height: 50px; font-size: 1.15rem; }
  .w-8 { width: 52px; height: 53px; font-size: 1.2rem; }
  .w-9 { width: 55px; height: 55px; font-size: 1.25rem; }
  .w-10 { width: 58px; height: 58px; font-size: 1.25rem; }
}

/* ---------------------------------------------------------------------
   Reduced Motion
   --------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .scale-beam,
  .pan-hanger,
  .scale-pointer,
  .pan-weight-token,
  .celebration-card {
    transition: none !important;
    animation: none !important;
  }
  .sparkle {
    display: none !important;
  }
}
