/* ================================================================
   Halloween Weather Atmosphere Engine — Visual Styles
   z-index: 500 (weather layer is below encounters at 900)
   ================================================================ */

/* ── Fixed weather container ─────────────────────────────────── */
#halloween-weather-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 500;
}

/* ── Rain canvas (created by JS, positioned inside the layer) ─── */
.hw-rain-canvas {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 1;
}

/* ── Lightning overlay ───────────────────────────────────────── */
.hw-lightning-overlay {
    position: fixed;
    inset: 0;
    pointer-events: none;
    /* z-index is inherited from #halloween-weather-layer */
    background: radial-gradient(
        circle at var(--lx, 50%) var(--ly, 20%),
        rgba(230, 235, 255, 0.80),
        rgba(170, 185, 230, 0.30) 32%,
        rgba(100, 110, 160, 0)    70%
    );
    opacity: 0;
    mix-blend-mode: screen;
    transition: opacity 0.02s linear;
    will-change: opacity;
}

/* Page brightens during peak flash */
body.lightning-peak .world-shell {
    filter: brightness(1.18) contrast(1.04);
    transition: filter 0.02s linear;
}
body:not(.lightning-peak) .world-shell {
    transition: filter 0.08s linear;
}

/* ── Lightning bolt canvas (created by JS) ───────────────────── */
.hw-lightning-bolt {
    position: fixed;
    top: 0;
    pointer-events: none;
    z-index: 501;
    transform: translateX(-50%);
    opacity: 0.85;
}

/* ── Leaf particles ──────────────────────────────────────────── */
.hw-leaf {
    position: fixed;
    width: var(--lsize, 10px);
    height: var(--lsize, 10px);
    background: var(--lc, #C86422);
    clip-path: polygon(50% 0%, 90% 30%, 100% 60%, 70% 90%, 30% 100%, 0% 70%, 10% 30%);
    pointer-events: none;
    animation: hw-leaf-fly var(--ldur, 3s) ease-out forwards;
    will-change: transform, opacity;
}

@keyframes hw-leaf-fly {
    0%   { opacity: 0;    transform: translate(0, 0) rotate(0deg); }
    15%  { opacity: 0.85; }
    100% { opacity: 0;    transform: translate(var(--ldx, 300px), var(--ldy, 40px)) rotate(var(--lrot, 360deg)); }
}

/* ── Wind CSS custom properties (JS updates these) ───────────── */
:root {
    --wind-x: 0px;
    --wind-rotation: 0deg;
    --wind-strength: 0;
}

/* Wind-reactive elements: opt-in via class.
   JS applies --wind-x and --wind-rotation to :root.
   Each element multiplies by its own --wind-factor for variation. */
.wind-reactive {
    transform: translate3d(
        calc(var(--wind-x) * var(--wind-factor, 1)),
        0,
        0
    ) rotate(calc(var(--wind-rotation) * var(--wind-factor, 1)));
    transition: transform 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
}

/* Decorative elements get a stronger wind reaction */
.wind-reactive-strong {
    transform: translate3d(
        calc(var(--wind-x) * var(--wind-factor, 1.6)),
        0,
        0
    ) rotate(calc(var(--wind-rotation) * var(--wind-factor, 1.6)));
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    will-change: transform;
}

/* Never animate these regardless of parent's wind-reactive */
input:focus,
textarea:focus,
select:focus,
[role="dialog"] .wind-reactive,
[role="dialog"] .wind-reactive-strong {
    transform: none !important;
}

/* ── Dev control panel ───────────────────────────────────────── */
.weather-dev-panel {
    position: fixed;
    bottom: 50px;   /* above the cat trigger button */
    left: 12px;
    z-index: 902;
    display: flex;
    flex-direction: column;
    gap: 4px;
    pointer-events: auto;
}

.weather-dev-panel button {
    width: 34px;
    height: 34px;
    border: 1px dashed rgba(100, 180, 255, 0.45);
    background: rgba(8, 12, 22, 0.88);
    border-radius: 50%;
    font-size: 15px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
    display: grid;
    place-items: center;
}

.weather-dev-panel button:hover { opacity: 1; }

/* ── Accessibility: reduced motion ───────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .hw-leaf           { animation: none !important; opacity: 0 !important; }
    .hw-rain-canvas    { display: none; }
    .hw-lightning-bolt { display: none; }
    .wind-reactive,
    .wind-reactive-strong { transform: none !important; transition: none !important; }
    body.lightning-peak .world-shell { filter: brightness(1.06); }
}

/* ── Mobile adjustments ──────────────────────────────────────── */
@media (max-width: 700px) {
    .wind-reactive        { --wind-factor: 0.6; }
    .wind-reactive-strong { --wind-factor: 1.0; }
    .weather-dev-panel    { display: none; } /* dev panel too crowded on mobile */
}
