#sky { position: fixed; inset: 0; z-index: 0;
  background: linear-gradient(180deg, var(--sky-a, #8ecbf0), var(--sky-b, #dff2fd));
  transition: background 2s linear; }

#celestials { position: fixed; inset: 0; z-index: 1; pointer-events: none; }
#sunEl, #moonEl { position: absolute; width: 64px; height: 64px; border-radius: 50%;
  transition: opacity 1.5s; }
#sunEl { background: var(--sun); box-shadow: 0 0 60px 12px rgba(255, 217, 77, 0.65); }
#moonEl { background: #e8ecff; box-shadow: 0 0 40px 6px rgba(170, 180, 255, 0.45); }

#stars { position: fixed; inset: 0 0 40% 0; opacity: 0; transition: opacity 2s;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff, transparent),
    radial-gradient(1px 1px at 34% 42%, #fff9, transparent),
    radial-gradient(2px 2px at 58% 12%, #fff, transparent),
    radial-gradient(1px 1px at 72% 30%, #fffb, transparent),
    radial-gradient(1.5px 1.5px at 88% 22%, #fff, transparent),
    radial-gradient(1px 1px at 45% 25%, #fff8, transparent); }

#wxLayers { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
/* Overlapping puffs, dense enough that at full opacity (storm) the sun/moon
   never peek through the gaps, still soft and cloud-like when faded in. */
#clouds { position: absolute; inset: 0 0 45% 0; opacity: 0; transition: opacity 2.5s;
  background:
    radial-gradient(44% 58% at 15% 28%, rgba(255,255,255,.92) 46%, transparent 72%),
    radial-gradient(50% 64% at 40% 18%, rgba(255,255,255,.9) 46%, transparent 74%),
    radial-gradient(48% 62% at 62% 26%, rgba(255,255,255,.9) 46%, transparent 73%),
    radial-gradient(46% 60% at 86% 20%, rgba(255,255,255,.92) 46%, transparent 72%),
    radial-gradient(40% 52% at 27% 42%, rgba(255,255,255,.85) 46%, transparent 72%),
    radial-gradient(40% 52% at 74% 44%, rgba(255,255,255,.85) 46%, transparent 72%);
  animation: drift 60s linear infinite alternate; }
.lightning-on #clouds { filter: brightness(0.72); }   /* storm day: grey, heavy */
.is-night #clouds { filter: brightness(0.45); }        /* wins for storm night (later rule) */
@keyframes drift { from { transform: translateX(-3%); } to { transform: translateX(3%); } }

/* Ground: the town stands on a grass band that sits clear above the dock. */
#ground { position: fixed; left: 0; right: 0; bottom: 0; height: 224px; z-index: 2;
  pointer-events: none; transition: filter 2s;
  background: linear-gradient(180deg, #7cc24a 0 8px, #66b23c 8px, #4a8f2f 100%); }
.is-night #ground { filter: brightness(0.42) saturate(0.85); }

#rain { position: absolute; inset: 0; opacity: 0; transition: opacity 1.5s;
  background: repeating-linear-gradient(78deg, transparent 0 6px,
    rgba(180, 205, 235, 0.55) 6px 7px);
  animation: rainfall 0.5s linear infinite; }
@keyframes rainfall { from { background-position: 0 0; } to { background-position: -14px 26px; } }

#lightning { position: absolute; inset: 0; background: #fff; opacity: 0; }
.lightning-on #lightning { animation: flash 7s infinite; }
@keyframes flash { 0%, 93%, 100% { opacity: 0; } 94% { opacity: 0.5; } 95% { opacity: 0; } 96.5% { opacity: 0.7; } 97.5% { opacity: 0; } }

#vignette { position: fixed; inset: 0; z-index: 5; pointer-events: none; opacity: 0;
  transition: opacity 0.8s;
  background: radial-gradient(120% 95% at 50% 50%, transparent 22%,
    rgba(214, 30, 30, 0.5) 62%, rgba(150, 12, 12, 0.92) 100%); }
/* Unmissable but calm: a slow breathing pulse held bright, never a strobe. Fades on recovery. */
body.blackout #vignette { opacity: 1; animation: blackoutPulse 1.8s ease-in-out infinite; }
@keyframes blackoutPulse { 0%, 100% { opacity: 0.82; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { body.blackout #vignette { animation: none; } }

#town { position: fixed; left: 0; right: 0; bottom: 220px; z-index: 3;
  display: flex; align-items: flex-end; justify-content: center; gap: 10px;
  padding: 0 24px; pointer-events: none; }
.bldg { position: relative; border-radius: 6px 6px 0 0; }
.bldg.pop-in { animation: pop 0.45s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: translateY(24px) scale(0.6); opacity: 0; } }

.house { width: 52px; height: 62px; background: #e8734a; }
.house .roof { position: absolute; top: -16px; left: -4px; right: -4px; height: 18px;
  background: #b8502e; clip-path: polygon(0 100%, 50% 0, 100% 100%); }
.wins { position: absolute; inset: 12px 8px auto 8px; display: grid;
  grid-template-columns: 1fr 1fr; gap: 5px; }
.wins i { height: 9px; border-radius: 2px; background: #5c2814; }
#town .wins i { background: color-mix(in srgb, #ffe9a8 calc(var(--lit, 1) * 100%), #402010); }
#town.dark .wins i { background: #2a1508; animation: flicker 0.6s steps(2) 3; }
@keyframes flicker { 50% { background: #ffe9a8; } }

.farm { width: 84px; height: 30px; background: #eef3f8; border: 2px solid #c8d6e4; display: flex; gap: 4px; padding: 4px; }
.farm .panel, .solar .panel { flex: 1; background: #2d4a73; border-radius: 3px; }
#town.night .panel { background: #1a2c48; }
.solar { width: 40px; height: 26px; background: #eef3f8; border: 2px solid #c8d6e4; padding: 3px; display: flex; }

.wind { width: 10px; height: 96px; display: flex; flex-direction: column; align-items: center; }
.wind .mast { width: 5px; flex: 1; background: #f4f7fa; border-radius: 2px; }
.wind .blades { font-size: 30px; line-height: 1; animation: spin var(--spin-s, 4s) linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.battery { width: 34px; height: 56px; background: #3d4d73; overflow: hidden; }
.battery .fill { position: absolute; bottom: 0; left: 0; right: 0;
  height: var(--batt-fill, 0%); background: rgba(84, 198, 232, 0.75); transition: height 1s; }
.battery .ico, .ev .ico, .school .ico { position: relative; z-index: 1; font-size: 15px;
  display: block; text-align: center; padding-top: 6px; }
.ev { width: 40px; height: 34px; background: #3d6d8c; overflow: hidden; }
.ev .fill { position: absolute; bottom: 0; left: 0; right: 0;
  height: var(--batt-fill, 0%); background: rgba(84, 198, 232, 0.55); transition: height 1s; }

.school { width: 56px; height: 48px; background: #5aa876; }
.hospital { width: 52px; height: 58px; background: #c94f4f; }
.hospital .cross { position: absolute; top: 4px; left: 50%; transform: translateX(-50%);
  color: #fff; font-weight: 900; font-size: 18px;
  opacity: calc(0.25 + var(--lit, 1) * 0.75); }
.data { width: 44px; height: 66px; background: #35415f; display: flex;
  flex-direction: column; gap: 5px; padding: 7px 6px; }
.data .rack { height: 8px; border-radius: 2px; background: #202a42; position: relative; }
.data .rack::after { content: ''; position: absolute; right: 3px; top: 2.5px;
  width: 3px; height: 3px; border-radius: 50%; background: #46d08a;
  opacity: var(--lit, 1); animation: blinkr 1.4s steps(2) infinite; }
#town.dark .data .rack::after { background: #666; animation: none; }
@keyframes blinkr { 50% { opacity: 0.25; } }
