:root {
    --bg-color: #f0f0ed;
    --pencil-color: #2c2c2c;
    --light-color: rgba(255, 245, 200, 0.4);
    --door-width: 180px;
    --door-height: 280px;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    background-image: radial-gradient(#dcdcdc 0.5px, transparent 0.5px);
    background-size: 20px 20px; /* Subtle paper-like grain/grid */
    color: var(--pencil-color);
    font-family: 'Courier New', Courier, monospace;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    width: 100%;
    max-width: 600px;
    filter: url(#pencil-filter); /* Apply the pencil filter to the whole scene for a cohesive look */
}

.sketch-text {
    font-size: 2rem;
    font-weight: bold;
    letter-spacing: 2px;
    opacity: 0.8;
}

/* Base sketch styling for SVG elements */
.sketch-line {
    /* Slight irregularity to mimic pencil */
    stroke-dasharray: 1000;
    stroke-dashoffset: 0;
}

#door-frame, #door, #stickman svg {
    /* No individual filters here to avoid double-processing */
}

.scene-wrapper {
    position: relative;
    width: 100%;
    height: 400px;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    /* Adding perspective to the wrapper makes the door rotation look 3D */
    perspective: 800px; 
}

.scene {
    position: relative;
    width: var(--door-width);
    height: var(--door-height);
    transform-style: preserve-3d;
}

#door-frame {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10; /* Frame in front of stickman and light */
    pointer-events: none;
}

/* This is the area inside the door frame where light and stickman live */
.doorway-area {
    position: absolute;
    top: 5px;
    left: 5px;
    width: calc(100% - 10px);
    height: calc(100% - 10px);
    overflow: hidden; /* Hide stickman when he slides past the frame */
    z-index: 1;
}

#light-beam {
    position: absolute;
    top: 5px; /* Align with top of frame opening */
    left: 5px;
    width: 200%; /* Wider than the frame to allow spill */
    height: 180%; /* Taller to spill onto 'floor' */
    background: linear-gradient(to bottom, #fffde0 0%, rgba(255, 253, 224, 0.4) 60%, transparent 100%);
    z-index: 0; /* Behind frame and stickman */
    pointer-events: none;
    transform-origin: top left;
}

#stickman {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 120px;
    z-index: 5; /* In the doorway, behind the door but in front of light */
}

#door-container {
    position: absolute;
    bottom: 5px;
    left: 5px;
    width: calc(100% - 10px);
    height: calc(100% - 10px);
    transform-origin: left center;
    z-index: 20; /* Door is in front of everything */
}

/* Responsiveness for mobile */
@media (max-width: 400px) {
    :root {
        --door-width: 140px;
        --door-height: 220px;
    }
    .sketch-text {
        font-size: 1.5rem;
    }
}