/* =========================
   TEMA ESTACIONAL: HALLOWEEN
   Se carga solo en la ventana de fechas (ver core.context_processors.seasonal_theme).
   Todo es decorativo: sin cambios de layout ni de interacción.
========================= */

/* --- Escena al pie del header (core/_halloween_scene.html) --- */
.header__container > .hw-scene {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 38px;
    display: block;
    pointer-events: none;
    overflow: visible;
    z-index: 0;
}

/* Piezas (core/_halloween_zones.html): dentro de .header__inner, detrás de su
   contenido, con el pie alineado a la tierra (el container tiene 0.3rem de padding) */
.header__inner > .hw-zones {
    position: absolute;
    left: 0;
    bottom: -0.3rem;
    width: 100%;
    height: 38px;
    display: block;
    pointer-events: none;
    overflow: visible;
    z-index: -1;
}

/* Niebla baja, por delante de la escena y detrás del contenido */
.header__container::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 34px;
    pointer-events: none;
    z-index: 1;
    background: linear-gradient(to top, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0));
}

/* El contenido del header queda por encima de la escena y la niebla */
.header__inner {
    position: relative;
    z-index: 2;
}

/* Manos: suben y bajan lentamente, cada una a su ritmo */
.hw-hand {
    transform-box: fill-box;
    transform-origin: 50% 100%;
    animation: hw-reach 7s ease-in-out infinite;
}

.hw-hand--late {
    animation-duration: 8.5s;
    animation-delay: -3s;
}


@keyframes hw-reach {
    0%, 100% { transform: translateY(4px) rotate(-1.5deg); }
    50%      { transform: translateY(-1px) rotate(1.5deg); }
}

/* Cara de la calabaza: titileo de vela */
.hw-face {
    animation: hw-flicker 3.2s steps(1, end) infinite;
}

.hw-pumpkin .hw-face {
    animation-delay: -1.7s;
}

@keyframes hw-flicker {
    0%   { opacity: 1; }
    13%  { opacity: 0.82; }
    21%  { opacity: 0.96; }
    38%  { opacity: 0.78; }
    47%  { opacity: 1; }
    66%  { opacity: 0.88; }
    74%  { opacity: 1; }
    89%  { opacity: 0.84; }
}

/* Caldero: llamas que titilan, brebaje que respira y burbujas que suben */
.hw-fire {
    transform-box: fill-box;
    transform-origin: 50% 100%;
    animation: hw-fire 0.9s ease-in-out infinite alternate;
}

.hw-brew {
    animation: hw-brew 2.6s ease-in-out infinite;
}

.hw-bubble {
    transform-box: fill-box;
    transform-origin: 50% 50%;
    animation: hw-bubble 2.4s ease-out infinite;
}

.hw-bubble:nth-of-type(2) { animation-delay: -0.9s; animation-duration: 2.8s; }
.hw-bubble:nth-of-type(3) { animation-delay: -1.7s; animation-duration: 2.1s; }

@keyframes hw-fire {
    from { transform: scaleY(0.88) scaleX(1.04); opacity: 0.85; }
    to   { transform: scaleY(1.06) scaleX(0.96); opacity: 1; }
}

@keyframes hw-brew {
    0%, 100% { opacity: 0.85; }
    50%      { opacity: 1; }
}

@keyframes hw-bubble {
    0%   { transform: translateY(0) scale(0.6); opacity: 0; }
    15%  { opacity: 0.95; }
    100% { transform: translateY(-9px) scale(1.25); opacity: 0; }
}

/* --- Zombi que va y vuelve por el cementerio comiendo un cerebro --- */
.hw-zombie-walk {
    transform-box: fill-box;
    transform-origin: 50% 50%;
    animation: hw-walk 44s linear infinite;
}

.hw-zombie-body {
    transform-box: fill-box;
    transform-origin: 50% 100%;
    animation: hw-shamble 1.1s ease-in-out infinite;
}

.hw-zombie-leg {
    transform-box: fill-box;
    transform-origin: 50% 0;
    animation: hw-step 1.1s ease-in-out infinite;
}

.hw-zombie-leg--front {
    animation-delay: -0.55s;
}

.hw-zombie-arms {
    transform-box: fill-box;
    transform-origin: 0 50%;
    animation: hw-chew 1.1s ease-in-out infinite;
}

@keyframes hw-walk {
    0%   { transform: translateX(0) scaleX(1); }
    46%  { transform: translateX(var(--hw-walk, 170px)) scaleX(1); }
    50%  { transform: translateX(var(--hw-walk, 170px)) scaleX(-1); }
    96%  { transform: translateX(0) scaleX(-1); }
    100% { transform: translateX(0) scaleX(1); }
}

/* --- Bruja: vuela ida y vuelta sobre el rincón de la bruja, con un leve cabeceo --- */
.hw-witch-fly {
    transform-box: fill-box;
    transform-origin: 50% 50%;
    animation: hw-fly 18s ease-in-out infinite;
}

.hw-witch-bob {
    animation: hw-bob 1.8s ease-in-out infinite;
}

@keyframes hw-fly {
    0%   { transform: translateX(0) scaleX(1); }
    46%  { transform: translateX(160px) scaleX(1); }
    50%  { transform: translateX(160px) scaleX(-1); }
    96%  { transform: translateX(0) scaleX(-1); }
    100% { transform: translateX(0) scaleX(1); }
}

@keyframes hw-bob {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-2.5px); }
}

@keyframes hw-shamble {
    0%, 100% { transform: translateY(0) rotate(4deg); }
    50%      { transform: translateY(-1.2px) rotate(7deg); }
}

@keyframes hw-step {
    0%, 100% { transform: rotate(-14deg); }
    50%      { transform: rotate(12deg); }
}

@keyframes hw-chew {
    0%, 100% { transform: rotate(0deg); }
    50%      { transform: rotate(-5deg); }
}

/* --- Araña colgando de un hilo --- */
.hw-spider {
    position: absolute;
    width: var(--hw-spider-size, 22px);
    height: var(--hw-thread, 58px);
    pointer-events: none;
    transform-origin: 50% 0;
    animation: hw-sway 4.5s ease-in-out infinite;
    background:
        no-repeat center bottom / var(--hw-spider-size, 22px) var(--hw-spider-size, 22px)
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'><g stroke='%23120d1c' stroke-width='1.7' fill='none' stroke-linecap='round'><path d='M15 21 L6 13 L3 5'/><path d='M25 21 L34 13 L37 5'/><path d='M14 24 L3 21 L1 15'/><path d='M26 24 L37 21 L39 15'/><path d='M14 27 L4 30 L1 37'/><path d='M26 27 L36 30 L39 37'/><path d='M16 29 L10 36 L9 40'/><path d='M24 29 L30 36 L31 40'/></g><circle cx='20' cy='25' r='6.5' fill='%23120d1c'/><circle cx='20' cy='15.5' r='3.8' fill='%23120d1c'/><circle cx='18.6' cy='14.8' r='0.9' fill='%23e4722a'/><circle cx='21.4' cy='14.8' r='0.9' fill='%23e4722a'/></svg>"),
        no-repeat center top / 1px calc(100% - var(--hw-spider-size, 22px) + 2px)
        linear-gradient(var(--hw-thread-color, rgba(255, 255, 255, 0.55)), var(--hw-thread-color, rgba(255, 255, 255, 0.55)));
}

/* En pantallas anchas el logo es un ítem flex sin posición; en ≤1600px ya es
   absolute (styles.css) y no hay que tocarlo o pierde su anclaje a la izquierda. */
@media screen and (min-width: 1601px) {
    .header__logo {
        position: relative;
    }
}

.header__logo .hw-spider {
    /* Cuelga de la hoja de la "O" (el logo mide 80px): hilo corto, araña a la derecha de la O */
    --hw-thread: 48px;
    --hw-spider-size: 20px;
    left: 50px;
    top: 21px;
    z-index: 3;
}

@keyframes hw-sway {
    0%, 100% { transform: rotate(-3deg); }
    50%      { transform: rotate(3deg); }
}

/* --- Login: la araña cuelga del borde superior del panel --- */
.login-sidebar {
    position: relative;
}

.login-sidebar .hw-spider {
    --hw-thread: 170px;
    --hw-spider-size: 30px;
    --hw-thread-color: rgba(0, 0, 0, 0.35);
    left: 46px;
    top: 0;
    z-index: 1;
}

/* Móvil: solo araña, zombi y una calabaza; el resto es de escritorio.
   El rincón de la bruja necesita ancho: bajo 900px se oculta para no chocar con el cementerio. */
.hw-mobile-only {
    display: none;
}

@media (max-width: 900px) {
    .hw-wide-only {
        display: none;
    }
}

@media (max-width: 768px) {
    .hw-desktop-only {
        display: none;
    }
    .hw-mobile-only {
        display: inline;
    }
    .hw-zombie-walk {
        --hw-walk: 100px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .hw-hand,
    .hw-face,
    .hw-fire,
    .hw-brew,
    .hw-bubble,
    .hw-spider,
    .hw-zombie-body,
    .hw-zombie-leg,
    .hw-zombie-arms,
    .hw-witch-bob {
        animation: none;
    }
    .hw-zombie-walk {
        animation: none;
        transform: translateX(90px);
    }
    .hw-witch-fly {
        animation: none;
        transform: translateX(120px);
    }
}
