/* ==========================================================================
   Cake & Candle Physics Stylesheet - Enhanced Positioning & Controls
   ========================================================================== */

.cake-stage-container {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 1.5rem auto;
  width: 100%;
  max-width: 320px;
}

/* Cake Box Wrapper */
.cake-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  filter: drop-shadow(0 15px 25px rgba(0, 0, 0, 0.08));
}

.cake-wrapper:hover {
  transform: translateY(-4px) scale(1.02);
}

.cake-graphic {
  width: 190px;
  height: 190px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
  transition: all 0.35s ease;
  position: relative;
  z-index: 2;
}

/* Dynamic Candles Array - Planted directly on top of the cake tier */
.candles-row {
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  z-index: 10;
  pointer-events: auto;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.candles-row.hidden {
  display: none !important;
}

.candle-unit {
  position: relative;
  width: 12px;
  height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.candle-unit:hover {
  transform: scale(1.15);
}

/* Candle Body */
.candle-stem {
  width: 10px;
  height: 34px;
  border-radius: 4px 4px 2px 2px;
  background: repeating-linear-gradient(
    45deg,
    #ff4d6d,
    #ff4d6d 6px,
    #ffffff 6px,
    #ffffff 12px
  );
  box-shadow: 
    inset -2px 0 3px rgba(0,0,0,0.15),
    inset 2px 0 3px rgba(255,255,255,0.4),
    0 2px 4px rgba(0,0,0,0.1);
  position: relative;
}

/* Candle Stem Variants */
.candle-unit:nth-child(2n) .candle-stem {
  background: repeating-linear-gradient(45deg, #3b82f6, #3b82f6 6px, #ffffff 6px, #ffffff 12px);
}
.candle-unit:nth-child(3n) .candle-stem {
  background: repeating-linear-gradient(45deg, #10b981, #10b981 6px, #ffffff 6px, #ffffff 12px);
}
.candle-unit:nth-child(4n) .candle-stem {
  background: repeating-linear-gradient(45deg, #f59e0b, #f59e0b 6px, #ffffff 6px, #ffffff 12px);
}
.candle-unit:nth-child(5n) .candle-stem {
  background: repeating-linear-gradient(45deg, #ec4899, #ec4899 6px, #ffffff 6px, #ffffff 12px);
}

/* Candle Wick */
.candle-wick {
  width: 2px;
  height: 8px;
  background: #27272a;
  border-radius: 1px;
  position: relative;
  z-index: 3;
}

/* Realistic Candle Flame */
.candle-flame {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 22px;
  background: radial-gradient(circle at 50% 80%, #ffffff 0%, #ffea79 25%, #ff9800 60%, #ff3d00 100%);
  border-radius: 50% 50% 35% 35% / 60% 60% 40% 40%;
  box-shadow: 
    0 0 16px rgba(255, 170, 0, 0.9),
    0 0 35px rgba(255, 100, 0, 0.45);
  animation: realisticFlicker 1.4s infinite ease-in-out alternate;
  transform-origin: center bottom;
  z-index: 5;
}

.candle-flame::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 10px;
  background: radial-gradient(circle, #ffffff 0%, rgba(255, 245, 160, 0.8) 100%);
  border-radius: 50%;
  opacity: 0.9;
}

@keyframes realisticFlicker {
  0% { transform: translateX(-50%) scale(1) rotate(-2deg); opacity: 0.95; }
  25% { transform: translateX(-50%) scale(1.08) rotate(2deg); opacity: 1; }
  50% { transform: translateX(-50%) scale(0.94) rotate(-1deg); opacity: 0.9; }
  75% { transform: translateX(-50%) scale(1.05) rotate(1.5deg); opacity: 1; }
  100% { transform: translateX(-50%) scale(0.98) rotate(-2deg); opacity: 0.92; }
}

/* Blown Out Smoke Trail Animation */
.candle-smoke {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 24px;
  background: radial-gradient(circle, rgba(148, 163, 184, 0.6) 0%, rgba(148, 163, 184, 0.15) 60%, transparent 80%);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}

.candle-unit.blown .candle-flame {
  animation: none;
  opacity: 0;
  transform: translateX(-50%) scale(0.1);
  transition: all 0.3s ease-out;
}

.candle-unit.blown .candle-smoke {
  animation: smokeRise 1.6s ease-out forwards;
}

@keyframes smokeRise {
  0% { opacity: 0.6; transform: translateX(-50%) translateY(0) scale(0.6); }
  40% { opacity: 0.45; transform: translateX(-40%) translateY(-15px) scale(1.1); }
  80% { opacity: 0.2; transform: translateX(-60%) translateY(-30px) scale(1.5); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-45px) scale(1.9); }
}

/* Card Glow Effect */
.ambient-glow {
  position: absolute;
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 200, 80, 0.25) 0%, transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.5s ease;
}

.cake-stage-container.all-blown .ambient-glow {
  opacity: 0;
}

/* -------------------------------------------------------------
   Preview Canvas Specific Scaling & Alignment
   ------------------------------------------------------------- */
.preview-canvas-card .cake-graphic {
  width: 140px;
  height: 140px;
}

