/* October layer. Everything here is gated on body.season-halloween. */

body.season-halloween {
    --hw-ember: #f97316;
    --hw-soot: #140c09;
}

body.season-halloween::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 40;
    pointer-events: none;
    background: radial-gradient(ellipse at center, transparent 42%, rgba(0, 0, 0, 0.45) 100%);
}

body.hw-sanctuary::before {
    opacity: 0.35;
}

.hw-layer {
    position: fixed;
    inset: 0;
    z-index: 45;
    pointer-events: none;
    overflow: hidden;
}

.hw-fog {
    position: absolute;
    left: -12%;
    right: -12%;
    top: -8%;
    height: 46%;
    background:
        radial-gradient(ellipse at 18% 30%, rgba(190, 186, 178, 0.09), transparent 58%),
        radial-gradient(ellipse at 78% 20%, rgba(180, 90, 20, 0.07), transparent 52%);
    animation: hw-fog-drift 32s linear infinite;
}

.hw-embers {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

@keyframes hw-fog-drift {
    0% { transform: translate3d(0, 0, 0); }
    50% { transform: translate3d(3%, 2%, 0); }
    100% { transform: translate3d(0, 0, 0); }
}

body.season-halloween::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 41;
    pointer-events: none;
    opacity: 0.18;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
    mix-blend-mode: overlay;
}

/* Portrait frame. Hole centre is 49.9% / 47.4% of the art; the face is ~46% of the frame. */
.hw-portrait {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    overflow: visible;
}

.hw-portrait .avatar {
    position: relative;
    z-index: 1;
    width: 28px;
    height: 28px;
}

.hw-portrait-frame {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 61px;
    height: 61px;
    transform: translate(-49.9%, -47.4%);
    z-index: 2;
    pointer-events: none;
    object-fit: contain;
}

.hw-portrait--hero {
    width: 72px;
    height: 72px;
}

.hw-portrait--hero .avatar,
.hw-portrait--hero .dashboard-hero-avatar {
    width: 72px;
    height: 72px;
}

.hw-portrait--hero .hw-portrait-frame {
    width: 157px;
    height: 157px;
}

.dashboard-hero-avatar-wrap:has(.hw-portrait--hero) {
    margin-left: 1.4rem;
    margin-right: 2.6rem;
}

.hw-blink {
    position: absolute;
    z-index: 3;
    pointer-events: none;
    object-fit: cover;
    border-radius: 50%;
}

.hw-portrait .hw-blink {
    width: 28px;
    height: 28px;
}

.hw-portrait--hero .hw-blink {
    width: 72px;
    height: 72px;
}

.player-avatar-circle .hw-blink {
    inset: 0;
    width: 100%;
    height: 100%;
}

/* Bouncing pumpkin heads */
.hw-pumpkin {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 150;
    width: 156px;
    height: 156px;
    margin: 0;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    pointer-events: auto;
    will-change: transform;
}

.hw-pumpkin img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    pointer-events: none;
    filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.45));
}

.hw-pumpkin.is-burst {
    pointer-events: none;
}

.hw-pumpkin.is-burst img {
    animation: hw-burst 420ms ease-in forwards;
}

@keyframes hw-burst {
    35% { transform: scale(1.28) rotate(8deg); filter: brightness(1.6); }
    100% { transform: scale(1.7) rotate(-6deg); opacity: 0; }
}

.hw-spark {
    position: fixed;
    z-index: 170;
    width: 8px;
    height: 8px;
    margin-left: -4px;
    margin-top: -4px;
    border-radius: 2px;
    pointer-events: none;
    animation: hw-spark 640ms ease-out forwards;
}

@keyframes hw-spark {
    to {
        transform: translate(var(--dx), var(--dy)) scale(0.25);
        opacity: 0;
    }
}

body.hw-hold .hw-pumpkin {
    visibility: hidden;
}

/* Spiders on a silk thread */
.hw-spider {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 90;
    width: 0;
    height: 0;
    pointer-events: none;
}

.hw-spider-swing {
    transform-origin: top center;
    animation: hw-spider-bob var(--hw-bob, 2.6s) ease-in-out infinite;
}

.hw-silk {
    display: block;
    width: 2px;
    height: var(--hw-silk, 48px);
    margin-left: -1px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.25));
}

.hw-spider-body {
    width: 33px;
    margin-left: -16px;
    margin-top: -2px;
    filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.5));
}

.hw-spider-body img {
    display: block;
    width: 100%;
    height: auto;
}

/* Blood drop lands on the footer, then the pool rises. Clicks pass through. */
.hw-drop {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 80;
    width: 16px;
    height: 24px;
    margin-left: -8px;
    pointer-events: none;
    background: radial-gradient(circle at 38% 32%, #f87171, #b91c1c 42%, #450a0a 80%);
    border-radius: 50% 50% 50% 50% / 35% 35% 65% 65%;
    filter: drop-shadow(0 6px 5px rgba(0, 0, 0, 0.45));
}

.hw-blood {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 48;
    height: 0;
    pointer-events: none;
    background: linear-gradient(to top, rgba(48, 0, 0, 0.78) 0%, rgba(127, 10, 14, 0.55) 62%, rgba(185, 28, 28, 0.22) 100%);
    transition: height 0.65s ease-out;
}

.hw-blood::before {
    content: "";
    position: absolute;
    left: -8%;
    right: -8%;
    top: -16px;
    height: 32px;
    background: radial-gradient(ellipse at center, rgba(153, 12, 16, 0.9), rgba(90, 4, 6, 0.35) 68%, transparent 70%);
    animation: hw-blood-wave 5.5s ease-in-out infinite;
}

@keyframes hw-blood-wave {
    0%, 100% { transform: translateX(0) scaleY(1); }
    50% { transform: translateX(-1.5%) scaleY(1.2); }
}

@keyframes hw-spider-bob {
    0%, 100% { transform: rotate(-8deg) translateY(0); }
    50% { transform: rotate(9deg) translateY(8px); }
}

/* Footer season controls */
.hw-controls {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    margin-left: 0.75rem;
}

.hw-controls button {
    border: 0;
    background: none;
    color: var(--muted, #8b92a5);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0.1rem 0.35rem;
}

.hw-controls button:hover,
.hw-controls button:focus-visible {
    color: var(--accent, #f97316);
}

.hw-treat-badge {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0.05rem 0.4rem;
    border-radius: 999px;
    background: rgba(249, 115, 22, 0.18);
    color: #fdba74;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    vertical-align: 1px;
}

.hw-candle {
    position: fixed;
    right: 1.1rem;
    bottom: 4.6rem;
    z-index: 180;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid rgba(249, 115, 22, 0.45);
    background: #1a120e;
    color: #fdba74;
    cursor: pointer;
    box-shadow: 0 0 18px rgba(249, 115, 22, 0.28);
    display: grid;
    place-items: center;
    padding: 0;
}

.hw-candle:hover,
.hw-candle:focus-visible {
    box-shadow: 0 0 26px rgba(249, 115, 22, 0.5);
}

.hw-candle svg {
    width: 22px;
    height: 22px;
    display: block;
}

.hw-toast {
    position: fixed;
    left: 50%;
    bottom: 6.25rem;
    transform: translateX(-50%);
    z-index: 190;
    width: min(440px, calc(100vw - 2rem));
    padding: 0.85rem 1rem;
    border-radius: 12px;
    background: #16120f;
    border: 1px solid rgba(249, 115, 22, 0.4);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    color: #f0f2f7;
    font-size: 0.92rem;
}

.hw-toast p {
    margin: 0 0 0.7rem;
}

.hw-toast-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.hw-toast-actions button {
    border: 1px solid rgba(249, 115, 22, 0.35);
    background: rgba(249, 115, 22, 0.12);
    color: #fdba74;
    border-radius: 8px;
    padding: 0.3rem 0.65rem;
    font: inherit;
    font-size: 0.82rem;
    cursor: pointer;
}

.hw-toast-actions button:hover {
    background: rgba(249, 115, 22, 0.22);
}

.hw-ribbon {
    margin: 0 0 1rem;
    padding: 0.55rem 0.8rem;
    border-radius: 10px;
    border: 1px solid rgba(249, 115, 22, 0.35);
    background: rgba(249, 115, 22, 0.08);
    color: #fdba74;
    font-size: 0.9rem;
}

.hw-moon {
    position: absolute;
    top: 0.15rem;
    right: 0.3rem;
    color: #fbbf24;
    font-size: 0.8rem;
    line-height: 1;
    pointer-events: none;
}

body.season-halloween .rok-cal-day.hw-hallows {
    position: relative;
    box-shadow: inset 0 0 0 1px rgba(251, 191, 36, 0.45);
}

body.season-halloween .kd-top10-table__rank:has(.kd-top10-trophy--gold)::after,
body.season-halloween .fort-rank-gold::after,
body.season-halloween .player-best-card--rank-1 .player-best-card-rank::after {
    content: "";
    display: inline-block;
    width: 16px;
    height: 10px;
    margin-left: 0.25rem;
    vertical-align: super;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 10'%3E%3Cpath fill='%23e7e5e4' d='M1 8 L3 2 L5 6 L8 1 L11 6 L13 2 L15 8 Z'/%3E%3Crect x='1' y='8' width='14' height='2' fill='%23a8a29e'/%3E%3C/svg%3E") center / contain no-repeat;
}

.hw-dark-catch {
    position: fixed;
    inset: 0;
    z-index: 100002;
    border: 0;
    padding: 0;
    cursor: none;
    background: radial-gradient(
        circle 120px at var(--hw-x, 50%) var(--hw-y, 42%),
        rgba(90, 40, 0, 0.12) 0,
        rgba(0, 0, 0, 0.78) 78px,
        rgba(0, 0, 0, 0.94) 150px
    );
}

.hw-walker {
    position: fixed;
    top: 16vh;
    width: min(34vw, 280px);
    height: 62vh;
    z-index: 100001;
    pointer-events: none;
    background: center / cover no-repeat;
    filter: contrast(1.15);
    animation: hw-walk 1.45s ease-in-out forwards;
}

@keyframes hw-walk {
    0% { left: -32%; opacity: 0; }
    18% { opacity: 0.88; }
    72% { opacity: 0.88; }
    100% { left: 108%; opacity: 0; }
}

.hw-scare {
    position: fixed;
    inset: 0;
    z-index: 100003;
    margin: 0;
    padding: 0;
    border: 0;
    background: #000;
    cursor: pointer;
}

.hw-scare img,
.hw-scare svg {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.hw-scare--fake {
    background: #1a0d08;
    display: grid;
    place-items: center;
}

.hw-scare--fake svg {
    width: min(70vmin, 420px);
    height: min(70vmin, 420px);
}

.hw-version.is-glitch {
    color: #f97316;
}

@media (prefers-reduced-motion: reduce) {
    .hw-fog,
    .hw-embers,
    .hw-walker,
    .hw-drop { display: none !important; }

    .hw-spider-swing,
    .hw-blood::before { animation: none; }

    body.season-halloween::after { display: none; }
}

html.hw-reduce .hw-fog,
html.hw-reduce .hw-embers,
html.hw-reduce .hw-walker,
html.hw-reduce .hw-drop { display: none !important; }

html.hw-reduce .hw-spider-swing,
html.hw-reduce .hw-blood::before { animation: none; }

@media (max-width: 720px) {
    .hw-candle { bottom: 5.2rem; right: 0.75rem; }
    .hw-pumpkin { width: 112px; height: 112px; }
    .hw-spider-body { width: 24px; margin-left: -12px; }
    .hw-toast { bottom: 5.4rem; }
    .hw-portrait--hero .hw-portrait-frame { width: 120px; height: 120px; }
    .hw-portrait--hero .avatar,
    .hw-portrait--hero .dashboard-hero-avatar,
    .hw-portrait--hero .hw-blink { width: 55px; height: 55px; }
    .dashboard-hero-avatar-wrap:has(.hw-portrait--hero) {
        margin-left: 0.6rem;
        margin-right: 1.4rem;
    }
}

@media print {
    body.season-halloween::before,
    body.season-halloween::after,
    .hw-layer,
    .hw-pumpkin,
    .hw-spider,
    .hw-drop,
    .hw-blood,
    .hw-candle,
    .hw-toast,
    .hw-controls,
    .hw-ribbon { display: none !important; }
}
