/* =============================================================================
   ADVANCED ANIMATIONS - Round 22
   Sun/Moon, Battery Fill, Power Meter, Weather Backgrounds
   ============================================================================= */

/* -----------------------------------------------------------------------------
   Sun/Moon Day/Night Animation
   ----------------------------------------------------------------------------- */

.sky-container {
  position: relative;
  width: 100%;
  height: 200px;
  border-radius: 16px;
  overflow: hidden;
  transition: background 1s ease;
}

.sky-day {
  background: linear-gradient(180deg, #87CEEB 0%, #E0F6FF 50%, #FFF5E6 100%);
}

.sky-night {
  background: linear-gradient(180deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
}

.sky-sunrise {
  background: linear-gradient(180deg, #FF512F 0%, #F09819 30%, #FFECD2 100%);
}

.sky-sunset {
  background: linear-gradient(180deg, #642B73 0%, #C6426E 40%, #FF9966 100%);
}

/* Sun */
.celestial-sun {
  position: absolute;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(145deg, #FFD700 0%, #FFA500 100%);
  box-shadow: 
    0 0 40px rgba(255, 215, 0, 0.6),
    0 0 80px rgba(255, 165, 0, 0.4),
    0 0 120px rgba(255, 215, 0, 0.2);
  animation: sun-glow 3s ease-in-out infinite;
}

.celestial-sun::before {
  content: '';
  position: absolute;
  inset: -20px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 215, 0, 0.3) 0%, transparent 70%);
  animation: sun-rays 4s linear infinite;
}

@keyframes sun-glow {
  0%, 100% { 
    box-shadow: 
      0 0 40px rgba(255, 215, 0, 0.6),
      0 0 80px rgba(255, 165, 0, 0.4);
  }
  50% { 
    box-shadow: 
      0 0 60px rgba(255, 215, 0, 0.8),
      0 0 100px rgba(255, 165, 0, 0.5);
  }
}

@keyframes sun-rays {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Moon */
.celestial-moon {
  position: absolute;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(145deg, #F5F5F5 0%, #E0E0E0 100%);
  box-shadow: 
    0 0 20px rgba(255, 255, 255, 0.4),
    0 0 40px rgba(200, 200, 255, 0.2),
    inset -8px -5px 0 rgba(200, 200, 200, 0.3);
  animation: moon-glow 4s ease-in-out infinite;
}

.celestial-moon::before {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  background: rgba(180, 180, 180, 0.3);
  border-radius: 50%;
  top: 10px;
  left: 15px;
}

.celestial-moon::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  background: rgba(180, 180, 180, 0.25);
  border-radius: 50%;
  top: 25px;
  left: 28px;
}

@keyframes moon-glow {
  0%, 100% { 
    box-shadow: 
      0 0 20px rgba(255, 255, 255, 0.4),
      0 0 40px rgba(200, 200, 255, 0.2);
  }
  50% { 
    box-shadow: 
      0 0 30px rgba(255, 255, 255, 0.5),
      0 0 60px rgba(200, 200, 255, 0.3);
  }
}

/* Stars (night mode) */
.sky-stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.sky-star {
  position: absolute;
  width: 2px;
  height: 2px;
  background: #fff;
  border-radius: 50%;
  animation: star-twinkle 2s ease-in-out infinite;
}

@keyframes star-twinkle {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* -----------------------------------------------------------------------------
   Battery Fill Animation
   ----------------------------------------------------------------------------- */

.battery-container {
  position: relative;
  width: 120px;
  height: 60px;
}

.battery-body {
  position: absolute;
  width: 100px;
  height: 50px;
  background: #1a1a2e;
  border: 3px solid #4a4a6a;
  border-radius: 8px;
  overflow: hidden;
}

.battery-cap {
  position: absolute;
  right: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 8px;
  height: 20px;
  background: #4a4a6a;
  border-radius: 0 4px 4px 0;
}

.battery-fill {
  position: absolute;
  bottom: 3px;
  left: 3px;
  height: calc(100% - 6px);
  border-radius: 4px;
  transition: width 1s ease-out, background 0.5s ease;
}

.battery-fill.charging {
  animation: battery-charge-pulse 1.5s ease-in-out infinite;
}

@keyframes battery-charge-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.2); }
}

/* Battery colors based on level */
.battery-fill[data-level="critical"] {
  background: linear-gradient(180deg, #ff4444 0%, #cc0000 100%);
  box-shadow: 0 0 10px rgba(255, 68, 68, 0.5);
}

.battery-fill[data-level="low"] {
  background: linear-gradient(180deg, #ffaa00 0%, #ff8800 100%);
  box-shadow: 0 0 10px rgba(255, 170, 0, 0.5);
}

.battery-fill[data-level="medium"] {
  background: linear-gradient(180deg, #6bcb77 0%, #4caf50 100%);
  box-shadow: 0 0 10px rgba(107, 203, 119, 0.5);
}

.battery-fill[data-level="high"] {
  background: linear-gradient(180deg, #4dff4d 0%, #00cc00 100%);
  box-shadow: 0 0 15px rgba(0, 204, 0, 0.6);
}

/* Battery segments */
.battery-segments {
  position: absolute;
  inset: 0;
  display: flex;
  gap: 2px;
  padding: 3px;
}

.battery-segment {
  flex: 1;
  background: transparent;
  border-radius: 2px;
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.battery-segment.filled {
  background: linear-gradient(180deg, #6bcb77 0%, #4caf50 100%);
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.2);
}

.battery-segment.charging {
  animation: segment-fill 0.5s ease-out forwards;
}

@keyframes segment-fill {
  from {
    background: transparent;
    transform: scaleY(0);
  }
  to {
    background: linear-gradient(180deg, #6bcb77 0%, #4caf50 100%);
    transform: scaleY(1);
  }
}

/* Charging bolt */
.battery-bolt {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.5rem;
  color: #FFD700;
  text-shadow: 0 0 10px rgba(255, 215, 0, 0.8);
  animation: bolt-flash 0.8s ease-in-out infinite;
  z-index: 10;
}

@keyframes bolt-flash {
  0%, 100% { opacity: 0.7; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
}

/* Battery percentage */
.battery-percentage {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.875rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  z-index: 5;
}

/* -----------------------------------------------------------------------------
   Power Meter with Animated Needle
   ----------------------------------------------------------------------------- */

.power-meter {
  position: relative;
  width: 200px;
  height: 120px;
}

.power-meter-gauge {
  position: absolute;
  width: 100%;
  height: 200%;
  border-radius: 50%;
  background: conic-gradient(
    from 180deg,
    #e53935 0deg,
    #ff9800 45deg,
    #ffc107 90deg,
    #8bc34a 135deg,
    #4caf50 180deg,
    transparent 180deg
  );
  mask: radial-gradient(
    circle at center,
    transparent 60%,
    black 60%
  );
  -webkit-mask: radial-gradient(
    circle at center,
    transparent 60%,
    black 60%
  );
}

.power-meter-background {
  position: absolute;
  width: 100%;
  height: 200%;
  border-radius: 50%;
  background: #1a1a2e;
  mask: radial-gradient(
    circle at center,
    transparent 55%,
    black 55%,
    black 65%,
    transparent 65%
  );
  -webkit-mask: radial-gradient(
    circle at center,
    transparent 55%,
    black 55%,
    black 65%,
    transparent 65%
  );
}

.power-meter-needle {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 4px;
  height: 70px;
  background: linear-gradient(180deg, #fff 0%, #e53935 100%);
  border-radius: 2px;
  transform-origin: bottom center;
  transition: transform 1s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 0 10px rgba(229, 57, 53, 0.5);
}

.power-meter-needle::before {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

.power-meter-needle.animating {
  animation: needle-bounce 0.5s ease-out;
}

@keyframes needle-bounce {
  0% { transform: translateX(-50%) rotate(var(--from-angle, -90deg)); }
  60% { transform: translateX(-50%) rotate(calc(var(--to-angle, 0deg) + 5deg)); }
  80% { transform: translateX(-50%) rotate(calc(var(--to-angle, 0deg) - 2deg)); }
  100% { transform: translateX(-50%) rotate(var(--to-angle, 0deg)); }
}

.power-meter-labels {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 10px;
  font-size: 0.75rem;
  color: #888;
}

.power-meter-value {
  position: absolute;
  bottom: 25px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
}

.power-meter-unit {
  font-size: 0.875rem;
  font-weight: 400;
  color: #888;
  margin-left: 4px;
}

/* -----------------------------------------------------------------------------
   Weather-based Backgrounds
   ----------------------------------------------------------------------------- */

.weather-bg {
  position: relative;
  width: 100%;
  min-height: 300px;
  border-radius: 16px;
  overflow: hidden;
  transition: all 0.5s ease;
}

/* Sunny */
.weather-bg.sunny {
  background: linear-gradient(180deg, #87CEEB 0%, #E0F6FF 100%);
}

.weather-bg.sunny::before {
  content: '';
  position: absolute;
  top: 20px;
  right: 30px;
  width: 80px;
  height: 80px;
  background: radial-gradient(circle, #FFD700 30%, transparent 70%);
  border-radius: 50%;
  animation: sun-glow 3s ease-in-out infinite;
}

/* Cloudy */
.weather-bg.cloudy {
  background: linear-gradient(180deg, #8e9eab 0%, #bdc3c7 100%);
}

.weather-cloud {
  position: absolute;
  background: #fff;
  border-radius: 100px;
  opacity: 0.9;
  animation: cloud-drift 30s linear infinite;
}

.weather-cloud::before,
.weather-cloud::after {
  content: '';
  position: absolute;
  background: inherit;
  border-radius: 50%;
}

.weather-cloud-1 {
  width: 120px;
  height: 40px;
  top: 20%;
  left: -150px;
}

.weather-cloud-1::before {
  width: 50px;
  height: 50px;
  top: -25px;
  left: 20px;
}

.weather-cloud-1::after {
  width: 70px;
  height: 70px;
  top: -35px;
  left: 50px;
}

@keyframes cloud-drift {
  from { transform: translateX(0); }
  to { transform: translateX(calc(100vw + 200px)); }
}

/* Rainy */
.weather-bg.rainy {
  background: linear-gradient(180deg, #4a5568 0%, #2d3748 100%);
}

.rain-container {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.rain-drop {
  position: absolute;
  width: 2px;
  height: 20px;
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.6));
  animation: rain-fall 0.8s linear infinite;
}

@keyframes rain-fall {
  from {
    transform: translateY(-20px);
    opacity: 1;
  }
  to {
    transform: translateY(100vh);
    opacity: 0.3;
  }
}

/* Stormy */
.weather-bg.stormy {
  background: linear-gradient(180deg, #1a1a2e 0%, #2d2d44 100%);
}

.lightning {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.8);
  opacity: 0;
  pointer-events: none;
}

.lightning.flash {
  animation: lightning-flash 0.2s ease-out;
}

@keyframes lightning-flash {
  0% { opacity: 0; }
  10% { opacity: 0.8; }
  20% { opacity: 0.2; }
  30% { opacity: 0.9; }
  40% { opacity: 0; }
  100% { opacity: 0; }
}

/* Snowy */
.weather-bg.snowy {
  background: linear-gradient(180deg, #e0e5ec 0%, #ffffff 100%);
}

.snowflake {
  position: absolute;
  color: #fff;
  font-size: 1rem;
  opacity: 0.8;
  animation: snow-fall 8s linear infinite;
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
}

@keyframes snow-fall {
  0% {
    transform: translateY(-10px) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 0.8;
  }
  90% {
    opacity: 0.8;
  }
  100% {
    transform: translateY(100vh) rotate(360deg);
    opacity: 0;
  }
}

/* Foggy */
.weather-bg.foggy {
  background: linear-gradient(180deg, #d3d3d3 0%, #a9a9a9 100%);
}

.fog-layer {
  position: absolute;
  width: 200%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.4) 25%,
    rgba(255, 255, 255, 0.6) 50%,
    rgba(255, 255, 255, 0.4) 75%,
    transparent 100%
  );
  animation: fog-drift 20s linear infinite;
}

@keyframes fog-drift {
  from { transform: translateX(-50%); }
  to { transform: translateX(0%); }
}

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

@media (prefers-reduced-motion: reduce) {
  .celestial-sun,
  .celestial-sun::before,
  .celestial-moon,
  .sky-star,
  .battery-fill.charging,
  .battery-bolt,
  .battery-segment.charging,
  .power-meter-needle,
  .power-meter-needle.animating,
  .weather-cloud,
  .rain-drop,
  .lightning,
  .snowflake,
  .fog-layer {
    animation: none !important;
  }
  
  .power-meter-needle {
    transition: none !important;
  }
}
