body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    overflow: hidden;
    font-family: 'Rye', serif;
    /* Vintage/Creepy font */
    color: #8b0000;
    /* Blood red */
}

#container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    /* Above video */
    pointer-events: none;
    /* Let clicks pass through if needed */
    opacity: 0;
    /* Hidden by default */
    transition: opacity 0.1s ease-in;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    /* Ensure UI is above fog/grain/scanlines */
    text-align: center;
    color: #fff;
    font-family: 'Courier New', Courier, monospace;
    /* Changed for monitor look */
}

/* Monitor Overlay */
.monitor-overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    pointer-events: none;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 10px;
    font-size: 1.2rem;
    text-shadow: 0 0 5px #00ff00;
    /* Green CRT glow */
    color: #00ff00;
}

.rec-dot {
    display: inline-block;
    width: 15px;
    height: 15px;
    background-color: red;
    border-radius: 50%;
    margin-right: 5px;
    animation: blink 1s infinite;
}

.timestamp {
    position: absolute;
    bottom: 10px;
    right: 10px;
}

.cam-name {
    position: absolute;
    top: 10px;
    right: 10px;
}

/* Landing Page */
#landing-page {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    padding: 40px;
    border: 2px solid #8b0000;
    box-shadow: 0 0 50px #000;
}

#landing-page h1 {
    font-family: 'Rye', serif;
    color: #8b0000;
    font-size: 3rem;
    margin-bottom: 10px;
    text-shadow: 0 0 10px #ff0000;
}

#landing-page p {
    color: #ccc;
    font-size: 1.2rem;
    margin: 10px 0;
}

/* Loading Screen */
#loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 4;
}

.loader {
    border: 5px solid #333;
    border-top: 5px solid #00ff00;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

button {
    background: transparent;
    border: 2px solid #8b0000;
    color: #8b0000;
    padding: 15px 40px;
    font-size: 1.5rem;
    font-family: 'Creepster', cursive;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
}

button:hover {
    background: #8b0000;
    color: #000;
    box-shadow: 0 0 20px #8b0000;
}

.hidden {
    opacity: 0 !important;
    pointer-events: none;
    display: none !important;
}

.visible {
    opacity: 1 !important;
}

/* Glitch effect utility */
.glitch {
    animation: glitch 0.2s infinite;
}

@keyframes glitch {
    0% {
        transform: translate(0);
        text-shadow: 2px 0 #f00, -2px 0 #0ff;
    }

    20% {
        transform: translate(-2px, 2px);
        text-shadow: -2px 0 #f00, 2px 0 #0ff;
    }

    40% {
        transform: translate(-2px, -2px);
        text-shadow: 2px 0 #f00, -2px 0 #0ff;
    }

    60% {
        transform: translate(2px, 2px);
        text-shadow: -2px 0 #f00, 2px 0 #0ff;
    }

    80% {
        transform: translate(2px, -2px);
        text-shadow: 2px 0 #f00, -2px 0 #0ff;
    }

    100% {
        transform: translate(0);
        text-shadow: none;
    }
}

/* Film Grain & CRT Overlay */
.grain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    opacity: 0.12;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='1'/%3E%3C/svg%3E");
    animation: grainFlicker 0.1s infinite;
}

@keyframes grainFlicker {
    0% {
        transform: translate(0, 0);
    }

    10% {
        transform: translate(-5%, -5%);
    }

    20% {
        transform: translate(-10%, 5%);
    }

    30% {
        transform: translate(5%, -10%);
    }

    40% {
        transform: translate(-5%, 15%);
    }

    50% {
        transform: translate(-10%, 5%);
    }

    60% {
        transform: translate(15%, 0);
    }

    70% {
        transform: translate(0, 10%);
    }

    80% {
        transform: translate(-15%, 0);
    }

    90% {
        transform: translate(10%, 5%);
    }

    100% {
        transform: translate(5%, 0);
    }
}

/* CRT Scanlines */
body::before {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    z-index: 9;
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
}

/* Vignette & Curvature */
body::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: radial-gradient(circle, rgba(0, 0, 0, 0) 60%, rgba(0, 0, 0, 0.8) 100%);
    z-index: 9;
    pointer-events: none;
    box-shadow: inset 0 0 100px rgba(0, 0, 0, 0.9);
}

.strobe {
    animation: strobe 0.1s infinite;
}

@keyframes strobe {
    0% {
        background-color: #000;
    }

    50% {
        background-color: #fff;
    }

    100% {
        background-color: #000;
    }
}

/* Fog Effect */
.fog-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 1;
    pointer-events: none;
}

.fog-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 200%;
    height: 100%;
    background: url('data:image/svg+xml;utf8,%3Csvg xmlns="http://www.w3.org/2000/svg" width="800" height="600"%3E%3Cfilter id="f"%3E%3CfeTurbulence type="fractalNoise" baseFrequency="0.01" numOctaves="3"/%3E%3C/filter%3E%3Crect width="100%25" height="100%25" filter="url(%23f)" opacity="0.4"/%3E%3C/svg%3E');
    opacity: 0.3;
    animation: fogDrift 30s linear infinite;
}

.fog-layer:nth-child(2) {
    animation-direction: reverse;
    animation-duration: 40s;
    opacity: 0.2;
}

@keyframes fogDrift {
    0% {
        transform: translateX(0);
    }

    100% {
        transform: translateX(-50%);
    }
}

/* Glowing Eyes */
.eyes-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100px;
    height: 40px;
    z-index: 2;
    pointer-events: none;
    transition: opacity 2s;
}

.eye {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #ff0000;
    border-radius: 50%;
    box-shadow: 0 0 10px #ff0000, 0 0 20px #8b0000;
    animation: blink 4s infinite;
}

.eye.left {
    left: 20px;
}

.eye.right {
    right: 20px;
}

@keyframes blink {

    0%,
    96%,
    100% {
        transform: scaleY(1);
        opacity: 1;
    }

    98% {
        transform: scaleY(0.1);
        opacity: 0.5;
    }
}

/* Enhanced Title Flicker */
h1 {
    font-size: 4rem;
    text-shadow: 0 0 10px #ff0000;
    letter-spacing: 5px;
    margin-bottom: 20px;
    animation: textFlicker 3s infinite;
}

@keyframes textFlicker {

    0%,
    19%,
    21%,
    23%,
    25%,
    54%,
    56%,
    100% {
        opacity: 1;
        text-shadow: 0 0 10px #ff0000;
    }

    20%,
    24%,
    55% {
        opacity: 0.3;
        text-shadow: none;
    }
}

/* Spirit Box UI */
#spirit-box-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Creepster', cursive;
    font-size: 3rem;
    color: rgba(255, 255, 255, 0.8);
    text-shadow: 0 0 20px #fff, 0 0 40px #00ff00;
    /* Ectoplasm Green */
    pointer-events: none;
    z-index: 5;
    text-align: center;
    opacity: 0;
    transition: opacity 2s ease-in-out;
}

#subtitles {
    position: absolute;
    bottom: 10%;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.5rem;
    color: #ffff00;
    /* Yellow standard subtitle */
    background: rgba(0, 0, 0, 0.7);
    padding: 5px 10px;
    text-shadow: 1px 1px 2px black;
    z-index: 6;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

#subtitles.visible {
    opacity: 1;
}

#spirit-box-display.active {
    opacity: 1;
    animation: spiritFloat 3s ease-in-out infinite;
}

@keyframes spiritFloat {

    0%,
    100% {
        transform: translate(-50%, -50%) scale(1);
    }

    50% {
        transform: translate(-50%, -55%) scale(1.05);
    }
}

/* --- CHARACTER ANIMATIONS --- */

.breathing {
    animation: breathe 4s ease-in-out infinite;
}

@keyframes breathe {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.03);
    }
}

.talking-child {
    animation: talkChild 0.1s infinite;
    filter: brightness(1.2);
}

@keyframes talkChild {
    0% {
        transform: translate(1px, 1px) scale(1.03);
    }

    50% {
        transform: translate(-1px, -1px) scale(1.03);
    }

    100% {
        transform: translate(0, 0) scale(1.03);
    }
}

.talking-demon {
    animation: talkDemon 0.05s infinite;
    filter: sepia(1) hue-rotate(-50deg) contrast(1.5) blur(0.5px);
    box-shadow: inset 0 0 50px #f00;
}

@keyframes talkDemon {
    0% {
        transform: translate(-2px, 0) scale(1.1);
    }

    25% {
        transform: translate(2px, 0) scale(1.1);
    }

    50% {
        transform: translate(-2px, 2px) scale(1.1);
    }

    75% {
        transform: translate(2px, -2px) scale(1.1);
    }

    100% {
        transform: translate(0, 0) scale(1.1);
    }
}

/* --- PARANORMAL EVENTS --- */
.invert {
    filter: invert(1) contrast(1.2);
}

.farmhouse-filter {
    filter: sepia(0.8) hue-rotate(180deg) contrast(1.2) brightness(0.7);
    box-shadow: inset 0 0 150px 50px rgba(0, 0, 0, 0.9);
    transform: scale(1.05);
    transition: all 2s ease;
}

.bloody {
    box-shadow: inset 0 0 100px 50px rgba(139, 0, 0, 0.8);
    background-color: rgba(255, 0, 0, 0.1);
    filter: sepia(1) saturate(5) hue-rotate(-50deg);
}

.glitch-heavy {
    animation: glitchHeavy 0.2s infinite;
    filter: hue-rotate(90deg) contrast(1.5);
}

@keyframes glitchHeavy {
    0% {
        transform: translate(0) scale(1);
        opacity: 1;
    }

    20% {
        transform: translate(-10px, 5px) scale(1.02);
        opacity: 0.8;
    }

    40% {
        transform: translate(10px, -5px) scale(0.98);
        opacity: 1;
    }

    60% {
        transform: translate(-5px, 10px) scale(1.05);
        opacity: 0.4;
    }

    80% {
        transform: translate(5px, -10px) scale(0.95);
        opacity: 1;
    }

    100% {
        transform: translate(0) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(0) scale(1);
        opacity: 1;
    }
}

/* ATMOSPHERIC BACKGROUNDS (Real Images Restored) */
.bg-farmhouse {
    background: url('assets/farmhouse_ext.png') no-repeat center center/cover;
    position: relative;
    overflow: hidden;
}

.bg-farmhouse::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 20, 0.4);
    /* Dark blue tint */
    animation: panRight 20s linear infinite alternate;
}

.bg-hallway {
    background: url('assets/farmhouse_int.png') no-repeat center center/cover;
    box-shadow: inset 0 0 100px #000;
}

.bg-hallway::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: repeating-linear-gradient(90deg, transparent 0, transparent 50px, rgba(0, 0, 0, 0.5) 50px, rgba(0, 0, 0, 0.5) 55px);
    transform: rotate(15deg);
    opacity: 0.3;
}

/* KEN BURNS EFFECT */
@keyframes panRight {
    0% {
        transform: scale(1.1) translate(-2%, -2%);
    }

    100% {
        transform: scale(1.2) translate(2%, 2%);
    }
}

@keyframes slowZoom {
    0% {
        transform: scale(1.0);
    }

    100% {
        transform: scale(1.15);
    }
}

.ken-burns {
    animation: slowZoom 15s ease-in-out infinite alternate;
}

.shake-slow {
    animation: shakeSlow 5s ease-in-out infinite;
}

@keyframes shakeSlow {

    0%,
    100% {
        transform: translate(0, 0) rotate(0deg);
    }

    25% {
        transform: translate(1px, 1px) rotate(0.1deg);
    }

    50% {
        transform: translate(-1px, -1px) rotate(-0.1deg);
    }

    75% {
        transform: translate(-1px, 1px) rotate(0.1deg);
    }
}

/* CINEMATIC FILM GRAIN (Global Overlay) */
.film-grain {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9998;
    /* Below jumpscare but above content */
    opacity: 0.12;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    animation: grainShift 0.2s steps(4) infinite;
}

@keyframes grainShift {
    0% {
        transform: translate(0, 0);
    }

    25% {
        transform: translate(-2%, -2%);
    }

    50% {
        transform: translate(2%, 2%);
    }

    75% {
        transform: translate(-2%, 2%);
    }

    100% {
        transform: translate(2%, -2%);
    }
}

/* VIGNETTE */
.vignette {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    background: radial-gradient(circle, transparent 40%, rgba(0, 0, 0, 0.8) 100%);
}

/* CINEMATIC TITLES */
#episode-title,
#final-message {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 2s ease;
}

#episode-title.visible,
#final-message.visible {
    opacity: 1;
}

.blood-drip {
    font-size: 5rem;
    color: #8b0000;
    text-shadow:
        1px 1px 0px #500,
        2px 2px 0px #300,
        3px 3px 0px #100,
        0 0 10px #f00,
        0 0 20px #8b0000;
    position: relative;
    filter: drop-shadow(0 5px 5px rgba(0, 0, 0, 0.8));
    z-index: 1;
}

.blood-drip::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    color: transparent;
    background: linear-gradient(180deg, transparent 55%, #8b0000 75%, #500 100%);
    background-size: 100% 250%;
    -webkit-background-clip: text;
    background-clip: text;
    animation: drip 5s infinite ease-in;
    opacity: 0.9;
    z-index: 2;
}

@keyframes pulse-blood {

    0%,
    100% {
        text-shadow: 0 0 10px #f00, 0 0 30px #500;
        transform: scale(1);
    }

    50% {
        text-shadow: 0 0 20px #f00, 0 0 50px #800;
        transform: scale(1.05);
    }
}

@keyframes drip {
    0% {
        background-position: 0% 0%;
        opacity: 0.8;
    }

    40% {
        background-position: 0% 80%;
        opacity: 1;
    }

    100% {
        background-position: 0% 120%;
        opacity: 0;
    }
}

.fade-in-delayed {
    font-size: 2rem;
    color: #666;
    animation: fade-in 4s ease-in forwards;
    opacity: 0;
    animation-delay: 1.5s;
}

@keyframes fade-in {
    to {
        opacity: 1;
    }
}

.horror-text {
    font-family: 'Creepster', cursive;
    font-size: 3rem;
    color: #cc0000;
    letter-spacing: 5px;
    text-shadow:
        2px 2px 0px #500,
        4px 4px 0px #000,
        0 0 20px rgba(255, 0, 0, 0.5);
    transform: perspective(500px) rotateX(10deg);
}