/* Core Typography and Variable setup */
:root {
    --bg-color: #050508;
    --text-color: #f0f0f5;
    --primary-red: #d32f2f;
    --accent-purple: #7b1fa2;
    --accent-green: #388e3c;
    --neon-glow: 0 0 10px rgba(211, 47, 47, 0.7);
    --glass-bg: rgba(10, 10, 15, 0.75);
    --glass-border: rgba(255, 255, 255, 0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-drag: none;
}

body {
    background-color: #000;
    color: var(--text-color);
    font-family: 'Outfit', sans-serif;
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Master Game Container */
#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    max-width: 1280px;
    max-height: 720px;
    background-color: var(--bg-color);
    border: 1px solid #111;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.9);
}

/* Vignette Screen Effect Removed */

/* Scanline / CRT overlay */
#game-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%);
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 11;
    opacity: 0.8;
}

/* Screen Management */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    z-index: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

/* --- START SCREEN --- */
#start-screen {
    background: radial-gradient(circle, #0c0a12 0%, #030205 100%);
    gap: 20px;
}

.glitch-text {
    font-family: 'Creepster', cursive;
    font-size: 5rem;
    letter-spacing: 5px;
    color: var(--primary-red);
    text-shadow: var(--neon-glow);
    position: relative;
    animation: text-pulse 2s infinite alternate;
}

.subtitle {
    font-size: 1.2rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.instructions-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.instructions-card h3 {
    color: var(--primary-red);
    margin-bottom: 12px;
    font-size: 1.1rem;
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(211,47,47,0.3);
    padding-bottom: 6px;
}

.instructions-card ul {
    list-style: none;
}

.instructions-card li {
    font-size: 0.9rem;
    color: #bbb;
    margin-bottom: 10px;
    line-height: 1.4;
}

.key {
    background: #222;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: monospace;
    color: #fff;
    font-size: 0.8rem;
}

.horror-btn {
    background: transparent;
    border: 1px solid var(--primary-red);
    color: var(--text-color);
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    padding: 12px 36px;
    cursor: pointer;
    letter-spacing: 2px;
    text-transform: uppercase;
    transition: all 0.3s ease;
    border-radius: 4px;
    margin-top: 10px;
    box-shadow: 0 0 10px rgba(211,47,47,0.2);
}

.horror-btn:hover {
    background: var(--primary-red);
    box-shadow: var(--neon-glow);
    transform: scale(1.05);
}

/* --- PLAY SCREEN --- */
#play-screen {
    background: #020202;
    display: block; /* Direct positioning for viewport layout */
}

/* HUD System */
#hud {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 15;
    pointer-events: none;
}

.hud-item {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 8px 16px;
    border-radius: 6px;
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    pointer-events: auto;
}

.hud-item .label {
    font-size: 0.7rem;
    color: #666;
    letter-spacing: 1.5px;
    font-weight: 700;
    margin-bottom: 2px;
}

.hud-item .value {
    font-size: 1.4rem;
    font-weight: 900;
    color: #fff;
    letter-spacing: 1px;
}

.health-container {
    width: 200px;
}

.health-bar-bg {
    width: 100%;
    height: 8px;
    background: #1a1a24;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 4px;
}

#health-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-red), #ff5252);
    width: 100%;
    transition: width 0.3s ease;
}

.key-indicator {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    opacity: 0.3;
    transition: all 0.3s ease;
}

.key-indicator.has-key {
    opacity: 1;
    border-color: rgba(255, 235, 59, 0.4);
    box-shadow: 0 0 10px rgba(255, 235, 59, 0.2);
}

.key-icon {
    font-size: 1.2rem;
}

.key-label {
    font-size: 0.8rem;
    font-weight: bold;
    color: #ffeb3b;
}

/* Room Viewport */
#room-viewport {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.4s ease, filter 0.3s ease;
}

#room-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(15, 15, 25, 0.8) 0%, rgba(5, 5, 8, 1) 100%);
    z-index: 1;
}

/* Positioning Room Elements */
#door-container {
    position: absolute;
    bottom: 10%;
    left: 85%;
    z-index: 3;
}

/* Door Styling */
#door {
    position: relative;
    width: 120px;
    height: 220px;
    background: #1c1410;
    border: 6px solid #2e1f18;
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    box-shadow: 0 0 15px rgba(0,0,0,0.8);
    transition: transform 0.3s ease, background 0.3s ease;
}

#door-number {
    position: absolute;
    top: 25px;
    left: 50%;
    transform: translateX(-50%);
    font-family: monospace;
    font-size: 1.2rem;
    font-weight: 700;
    color: #e0d0b0;
    opacity: 0.7;
    letter-spacing: 1px;
}

.door-handle {
    position: absolute;
    top: 110px;
    left: 10px;
    width: 14px;
    height: 14px;
    background: #d4af37;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.door-open {
    transform: skewY(-5deg) scaleX(0.2) translate(-60px, -5px) !important;
    background: #000 !important;
    box-shadow: -15px 0 30px rgba(0,0,0,0.9);
}

/* Dynamic Lockers and Tables Hiding Spots */
.locker-spot {
    position: absolute;
    width: 65px;
    height: 170px;
    background: #2a2e35;
    border: 3px solid #000;
    bottom: 10%;
    z-index: 3;
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.7);
}

.locker-spot::after {
    content: '|||';
    color: #000;
    font-size: 1.4rem;
    font-weight: bold;
    letter-spacing: 2px;
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0.8;
}

.table-spot {
    position: absolute;
    width: 100px;
    height: 75px;
    background: #5c4033;
    border: 3px solid #000;
    bottom: 10%;
    z-index: 3;
    border-radius: 2px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.7);
}

.table-spot::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 12px;
    right: 12px;
    bottom: 0;
    border-left: 8px solid #2f1d14;
    border-right: 8px solid #2f1d14;
    pointer-events: none;
}

/* Player Character */
#player-character {
    position: absolute;
    width: 35px;
    height: 55px;
    background: #ffffff;
    border: 3px solid #000000;
    bottom: 10%;
    left: 10%;
    z-index: 5;
    transition: left 0.08s linear;
}

#player-character.hiding-active {
    opacity: 0.1;
    pointer-events: none;
}

/* Glowing Key Item */
#interactive-item {
    position: absolute;
    bottom: 10%;
    width: 45px;
    height: 45px;
    z-index: 4;
    display: flex;
    justify-content: center;
    align-items: center;
}

.glowing-key {
    font-size: 1.8rem;
    animation: key-bob 0.8s infinite alternate;
    filter: drop-shadow(0 0 10px #ffeb3b);
}

@keyframes key-bob {
    0% { transform: translateY(0); }
    100% { transform: translateY(-6px); }
}

/* Interaction Prompt */
#interaction-prompt {
    position: absolute;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 12px 28px;
    border-radius: 6px;
    backdrop-filter: blur(10px);
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6), 0 0 15px rgba(255,255,255,0.05);
    z-index: 20;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    text-align: center;
    border-bottom: 2px solid var(--primary-red);
}

#interaction-prompt.hiding-active {
    border-color: var(--accent-green);
    animation: pulse-border 1.5s infinite alternate;
}

@keyframes pulse-border {
    0% { box-shadow: 0 0 10px rgba(56, 142, 60, 0.2); }
    100% { box-shadow: 0 0 20px rgba(56, 142, 60, 0.6); }
}

/* Room Lighting Modes */
.normal-lighting {
    background-color: #030306;
}

.dark-lighting {
    background-color: #000000;
}

.dark-lighting #room-background {
    /* Shadow circle follows flashlight center */
    background: radial-gradient(circle at var(--flashlight-x, 50%) var(--flashlight-y, 50%), rgba(20, 20, 30, 0.4) 0%, rgba(0, 0, 0, 0.99) 150px) !important;
}

.flickering-lighting {
    animation: flicker-lighting-anim 1.5s infinite;
}

.blood-lighting {
    background-color: #0b0202;
}
.blood-lighting #room-background {
    background: radial-gradient(circle at center, rgba(139, 0, 0, 0.2) 0%, rgba(5, 2, 2, 1) 100%) !important;
}

/* Interactive Item (Key / Runes) */
#interactive-item {
    position: absolute;
    width: 60px;
    height: 60px;
    z-index: 5;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

#interactive-item:hover {
    transform: scale(1.1);
}

/* Entity Sprites */
#entity-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 8;
}

#entity-sprite {
    position: absolute;
    bottom: 15%;
    width: 260px;
    height: 260px;
    object-fit: contain;
    transform: translate(-50%, -50%);
    filter: drop-shadow(0 0 15px rgba(255, 0, 0, 0.5));
}

#entity-sprite.a16-active {
    animation: a16-rush 1.8s linear forwards, entity-twitch 0.05s infinite linear;
}

#entity-sprite.a45-active {
    animation: a45-rush-back-forth 4.5s linear forwards, entity-twitch 0.05s infinite linear;
}

#entity-sprite.a87-active {
    animation: a87-rush 2.2s linear forwards, entity-twitch 0.05s infinite linear;
}

#entity-sprite.blt87-active {
    animation: blt87-rush 1.4s linear forwards, entity-twitch 0.05s infinite linear;
}

#entity-sprite.lk87-active {
    animation: lk87-rush-back-forth 3.8s linear forwards, entity-twitch 0.05s infinite linear;
}

#entity-sprite.tb87-active {
    animation: tb87-rush 5.0s linear forwards, entity-twitch 0.05s infinite linear;
}

/* --- SCREEN OVERLAYS --- */
#game-over-screen {
    background: radial-gradient(circle, #150202 0%, #030000 100%);
    gap: 20px;
}

.death-title {
    font-family: 'Creepster', cursive;
    font-size: 6rem;
    color: var(--primary-red);
    text-shadow: var(--neon-glow);
    letter-spacing: 4px;
    animation: text-shake 0.3s infinite;
}

.death-cause {
    font-size: 1.1rem;
    color: #aaa;
    max-width: 400px;
    text-align: center;
    line-height: 1.5;
}

.stats-card {
    background: rgba(20, 5, 5, 0.6);
    border: 1px solid rgba(211, 47, 47, 0.15);
    border-radius: 6px;
    padding: 20px;
    width: 350px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: #888;
    letter-spacing: 1px;
}

.stat-row .highlight {
    color: #fff;
    font-weight: 700;
}

/* --- KEYFRAME ANIMATIONS --- */

@keyframes text-pulse {
    0% { transform: scale(1); filter: brightness(1); }
    100% { transform: scale(1.03); filter: brightness(1.2); }
}

@keyframes orb-glow {
    0% { transform: scale(1); box-shadow: 0 0 10px #ffeb3b, 0 0 20px #ffeb3b; }
    100% { transform: scale(1.15); box-shadow: 0 0 18px #ffeb3b, 0 0 35px #ffeb3b; }
}

@keyframes rune-pulse {
    0% { transform: scale(1); box-shadow: 0 0 6px rgba(156,39,176,0.3); }
    100% { transform: scale(1.08); box-shadow: 0 0 15px rgba(156,39,176,0.7); }
}

@keyframes flicker-lighting-anim {
    0%, 19.999%, 22%, 62.999%, 64%, 64.999%, 70%, 100% { opacity: 0.99; }
    20%, 21.999%, 63%, 63.999%, 65%, 69.999% { opacity: 0.15; }
}

@keyframes border-pulse {
    0% { border-color: rgba(211, 47, 47, 0.25); }
    100% { border-color: rgba(211, 47, 47, 0.55); }
}

@keyframes static-flicker {
    0% { transform: translate(0, 0); }
    10% { transform: translate(-1px, 1px); }
    20% { transform: translate(1px, -1px); }
    30% { transform: translate(-2px, -1px); }
    40% { transform: translate(2px, 2px); }
    50% { transform: translate(-1px, 2px); }
    60% { transform: translate(1px, 1px); }
    70% { transform: translate(-1px, -1px); }
    80% { transform: translate(2px, -2px); }
    90% { transform: translate(-2px, 1px); }
    100% { transform: translate(0, 0); }
}

/* Entity Motion Keyframes */
@keyframes a16-rush {
    0% { left: 110%; filter: blur(8px) drop-shadow(0 0 15px red); opacity: 0; }
    15% { opacity: 0.9; }
    50% { filter: blur(1px) drop-shadow(0 0 25px red); }
    85% { opacity: 0.9; }
    100% { left: -20%; filter: blur(12px) drop-shadow(0 0 35px red); opacity: 0; }
}

@keyframes a45-rush-back-forth {
    0% { left: 110%; filter: blur(6px) drop-shadow(0 0 15px purple); opacity: 0; }
    5% { opacity: 0.95; }
    30% { left: -20%; opacity: 0.95; }
    60% { left: 110%; opacity: 0.95; }
    95% { opacity: 0.95; }
    100% { left: -20%; filter: blur(10px) drop-shadow(0 0 35px purple); opacity: 0; }
}

@keyframes a87-rush {
    0% { left: -20%; filter: blur(8px) drop-shadow(0 0 15px yellow); opacity: 0; }
    15% { opacity: 0.9; }
    100% { left: 110%; filter: blur(12px) drop-shadow(0 0 35px yellow); opacity: 0; }
}

@keyframes blt87-rush {
    0% { left: 110%; filter: blur(8px) drop-shadow(0 0 15px green); opacity: 0; }
    10% { opacity: 0.95; }
    100% { left: -20%; filter: blur(15px) drop-shadow(0 0 35px green); opacity: 0; }
}

@keyframes lk87-rush-back-forth {
    0% { left: 110%; filter: blur(6px) drop-shadow(0 0 15px blue); opacity: 0; }
    5% { opacity: 0.95; }
    45% { left: -20%; opacity: 0.95; }
    55% { left: -20%; }
    95% { opacity: 0.95; }
    100% { left: 110%; filter: blur(10px) drop-shadow(0 0 35px blue); opacity: 0; }
}

@keyframes tb87-rush {
    0% { left: 110%; filter: blur(4px) drop-shadow(0 0 15px cyan); opacity: 0; }
    15% { opacity: 0.9; }
    100% { left: -20%; filter: blur(8px) drop-shadow(0 0 20px cyan); opacity: 0; }
}

/* Rapid Twitching Animation */
@keyframes entity-twitch {
    0% { transform: translate(-50%, -50%) translate(-4px, -3px) rotate(-2deg); }
    20% { transform: translate(-50%, -50%) translate(4px, 3px) rotate(2deg); }
    40% { transform: translate(-50%, -50%) translate(-3px, 4px) rotate(-1deg); }
    60% { transform: translate(-50%, -50%) translate(3px, -4px) rotate(1deg); }
    80% { transform: translate(-50%, -50%) translate(-4px, 2px) rotate(-3deg); }
    100% { transform: translate(-50%, -50%) translate(-4px, -3px) rotate(-2deg); }
}

/* Camera Shake Effects */
.camera-shake {
    animation: shake-mild 0.2s infinite;
}
.camera-shake-heavy {
    animation: shake-violent 0.15s infinite;
}

@keyframes shake-mild {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(0px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(2px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(2px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

@keyframes shake-violent {
    0% { transform: translate(4px, 4px) rotate(0deg); }
    10% { transform: translate(-2px, -4px) rotate(-2deg); }
    20% { transform: translate(-8px, 0px) rotate(3deg); }
    30% { transform: translate(0px, 8px) rotate(0deg); }
    40% { transform: translate(4px, -2px) rotate(2deg); }
    50% { transform: translate(-2px, 7px) rotate(-3deg); }
    60% { transform: translate(-7px, 3px) rotate(0deg); }
    70% { transform: translate(6px, 2px) rotate(-2deg); }
    80% { transform: translate(-3px, -3px) rotate(3deg); }
    90% { transform: translate(5px, 5px) rotate(0deg); }
    100% { transform: translate(3px, -4px) rotate(-2deg); }
}

@keyframes text-shake {
    0% { transform: translate(0, 0); }
    20% { transform: translate(-2px, 2px); }
    40% { transform: translate(-2px, -2px); }
    60% { transform: translate(2px, 2px); }
    80% { transform: translate(2px, -2px); }
    100% { transform: translate(0, 0); }
}
