/* ============================================
   THE HOLLOW ASYLUM - Horror Game Styles
   ============================================ */

:root {
    --bg-dark: #0a0a0a;
    --bg-darker: #050505;
    --text-primary: #c8c8c8;
    --text-dim: #666;
    --accent-red: #8b0000;
    --accent-blood: #6b0000;
    --accent-green: #1a3a1a;
    --accent-glow: #ff2200;
    --accent-key: #ffd700;
    --accent-exit: #00cc66;
    --accent-ghost: #aa44ff;
    --accent-sanity: #00aaff;
    --font-horror: 'Creepster', cursive;
    --font-typewriter: 'Special Elite', cursive;
    --font-ui: 'Inter', sans-serif;
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-darker);
    color: var(--text-primary);
    font-family: var(--font-ui);
}

/* ===== PRELOADER ===== */
#preloader {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: var(--bg-darker);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s ease;
}

#preloader.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loading-eye {
    margin-bottom: 20px;
}

.eye-outer {
    width: 60px;
    height: 60px;
    border: 2px solid var(--accent-red);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse-eye 1.5s ease-in-out infinite;
}

.eye-inner {
    width: 20px;
    height: 20px;
    background: var(--accent-glow);
    border-radius: 50%;
    box-shadow: 0 0 20px var(--accent-glow), 0 0 40px var(--accent-red);
    animation: look-around 3s ease-in-out infinite;
}

@keyframes pulse-eye {
    0%, 100% { transform: scale(1); border-color: var(--accent-red); }
    50% { transform: scale(1.1); border-color: var(--accent-glow); }
}

@keyframes look-around {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(8px); }
    75% { transform: translateX(-8px); }
}

.loading-text {
    font-family: var(--font-typewriter);
    color: var(--text-dim);
    letter-spacing: 4px;
    animation: flicker-text 2s infinite;
}

@keyframes flicker-text {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
    92% { opacity: 0.5; }
    94% { opacity: 0; }
    96% { opacity: 0.5; }
}

/* ===== SCREENS ===== */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.5s ease;
}

.screen.hidden {
    display: none;
}

/* ===== TITLE SCREEN ===== */
#title-screen {
    background: var(--bg-darker);
}

.title-bg {
    position: absolute;
    inset: 0;
    background: url('assets/title_bg.png') center/cover no-repeat;
    opacity: 0.3;
    filter: grayscale(0.5) brightness(0.4);
    animation: slow-zoom 20s ease-in-out infinite alternate;
}

@keyframes slow-zoom {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); }
}

.title-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        180deg,
        rgba(0,0,0,0.6) 0%,
        rgba(10,0,0,0.8) 50%,
        rgba(0,0,0,0.95) 100%
    );
}

.title-content {
    position: relative;
    z-index: 2;
    text-align: center;
}

/* Glitch effect */
.glitch {
    font-family: var(--font-horror);
    font-size: clamp(2.5rem, 8vw, 5rem);
    color: var(--text-primary);
    position: relative;
    animation: glitch-skew 4s infinite linear alternate-reverse;
}

.glitch::before,
.glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.glitch::before {
    color: var(--accent-glow);
    animation: glitch-1 3s infinite linear alternate-reverse;
    clip-path: polygon(0 0, 100% 0, 100% 35%, 0 35%);
}

.glitch::after {
    color: var(--accent-ghost);
    animation: glitch-2 2s infinite linear alternate-reverse;
    clip-path: polygon(0 65%, 100% 65%, 100% 100%, 0 100%);
}

@keyframes glitch-1 {
    0%, 94% { transform: translate(0); }
    95% { transform: translate(-3px, 1px); }
    96% { transform: translate(3px, -1px); }
    97% { transform: translate(-2px, 2px); }
    98% { transform: translate(2px, -2px); }
    99% { transform: translate(-1px, 1px); }
    100% { transform: translate(0); }
}

@keyframes glitch-2 {
    0%, 92% { transform: translate(0); }
    93% { transform: translate(2px, -1px); }
    95% { transform: translate(-2px, 1px); }
    97% { transform: translate(1px, 2px); }
    99% { transform: translate(-1px, -1px); }
    100% { transform: translate(0); }
}

@keyframes glitch-skew {
    0%, 95% { transform: skew(0deg); }
    96% { transform: skew(0.5deg); }
    98% { transform: skew(-0.3deg); }
    100% { transform: skew(0deg); }
}

.subtitle {
    font-family: var(--font-typewriter);
    font-size: clamp(0.9rem, 2vw, 1.2rem);
    color: var(--text-dim);
    margin-top: 10px;
    letter-spacing: 3px;
    animation: flicker-text 4s infinite;
}

.menu-buttons {
    margin-top: 40px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.menu-btn {
    background: rgba(139, 0, 0, 0.15);
    border: 1px solid rgba(139, 0, 0, 0.4);
    color: var(--text-primary);
    padding: 14px 40px;
    font-family: var(--font-typewriter);
    font-size: 1rem;
    cursor: pointer;
    letter-spacing: 2px;
    transition: all 0.3s ease;
    min-width: 240px;
    position: relative;
    overflow: hidden;
}

.menu-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(139, 0, 0, 0.2), transparent);
    transition: left 0.5s ease;
}

.menu-btn:hover {
    background: rgba(139, 0, 0, 0.3);
    border-color: var(--accent-glow);
    color: #fff;
    box-shadow: 0 0 20px rgba(139, 0, 0, 0.3), inset 0 0 20px rgba(139, 0, 0, 0.1);
    transform: scale(1.02);
}

.menu-btn:hover::before {
    left: 100%;
}

.menu-btn:active {
    transform: scale(0.98);
}

.warning-text {
    margin-top: 30px;
    font-size: 0.75rem;
    color: var(--accent-red);
    letter-spacing: 3px;
    animation: pulse-warn 2s infinite;
}

@keyframes pulse-warn {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ===== PARTICLES ===== */
.particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.particle {
    position: absolute;
    width: 2px;
    height: 2px;
    background: rgba(200, 200, 200, 0.3);
    border-radius: 50%;
    animation: float-particle linear infinite;
}

@keyframes float-particle {
    0% { transform: translateY(100vh) rotate(0deg); opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { transform: translateY(-10vh) rotate(720deg); opacity: 0; }
}

/* ===== HOW TO PLAY ===== */
#how-screen {
    background: rgba(5, 5, 5, 0.97);
}

.how-content {
    max-width: 500px;
    text-align: center;
}

.how-content h2 {
    font-family: var(--font-horror);
    font-size: 2rem;
    color: var(--accent-red);
    margin-bottom: 30px;
    letter-spacing: 4px;
}

.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.control-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: rgba(139, 0, 0, 0.2);
    border: 1px solid rgba(139, 0, 0, 0.5);
    border-radius: 6px;
    font-family: var(--font-ui);
    font-size: 0.8rem;
    font-weight: 600;
    color: #ddd;
}

.key.wide {
    width: auto;
    padding: 0 16px;
}

.key-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.key-row {
    display: flex;
    gap: 4px;
}

.icon-display {
    font-size: 2rem;
}

.control-item p {
    font-size: 0.8rem;
    color: var(--text-dim);
}

.objective-box {
    background: rgba(139, 0, 0, 0.08);
    border: 1px solid rgba(139, 0, 0, 0.2);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 25px;
    text-align: left;
}

.objective-box h3 {
    font-family: var(--font-typewriter);
    color: var(--accent-red);
    margin-bottom: 10px;
    letter-spacing: 2px;
    font-size: 0.9rem;
}

.objective-box p {
    font-size: 0.85rem;
    line-height: 1.8;
    color: var(--text-dim);
}

.highlight-key { color: var(--accent-key); font-weight: 600; }
.highlight-exit { color: var(--accent-exit); font-weight: 600; }
.highlight-ghost { color: var(--accent-ghost); font-weight: 600; }
.highlight-sanity { color: var(--accent-sanity); font-weight: 600; }

/* ===== INTRO SCREEN ===== */
#intro-screen {
    background: var(--bg-darker);
}

.intro-content {
    max-width: 600px;
    padding: 20px;
    position: relative;
}

.typewriter {
    font-family: var(--font-typewriter);
    font-size: clamp(0.9rem, 2vw, 1.1rem);
    line-height: 2;
    color: var(--text-dim);
    min-height: 200px;
}

.typewriter .cursor {
    display: inline-block;
    width: 2px;
    height: 1.1em;
    background: var(--accent-red);
    animation: blink-cursor 0.8s infinite;
    vertical-align: text-bottom;
    margin-left: 2px;
}

@keyframes blink-cursor {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.skip-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-dim);
    padding: 8px 20px;
    font-family: var(--font-ui);
    font-size: 0.8rem;
    cursor: pointer;
    letter-spacing: 2px;
    transition: all 0.3s ease;
}

.skip-btn:hover {
    border-color: var(--accent-red);
    color: var(--text-primary);
}

/* ===== STAGE INTRO ===== */
#stage-intro {
    background: var(--bg-darker);
}

.stage-intro-content {
    text-align: center;
    animation: stage-reveal 0.8s ease-out;
}

@keyframes stage-reveal {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.stage-number {
    font-family: var(--font-ui);
    font-size: 0.9rem;
    letter-spacing: 8px;
    color: var(--accent-red);
    margin-bottom: 10px;
}

.stage-name {
    font-family: var(--font-horror);
    font-size: clamp(2rem, 6vw, 4rem);
    color: var(--text-primary);
    margin-bottom: 15px;
    animation: flicker-text 3s infinite;
}

.stage-desc {
    font-family: var(--font-typewriter);
    font-size: 0.9rem;
    color: var(--text-dim);
    letter-spacing: 2px;
}

/* ===== GAME CANVAS ===== */
#game-screen {
    z-index: 50;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: var(--bg-darker);
    image-rendering: pixelated;
}

/* ===== HUD ===== */
#hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 200;
    background: linear-gradient(180deg, rgba(0,0,0,0.7) 0%, transparent 100%);
    pointer-events: none;
}

.hud-left, .hud-right {
    display: flex;
    gap: 20px;
}

.hud-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.hud-label {
    font-size: 0.6rem;
    letter-spacing: 2px;
    color: var(--text-dim);
    font-weight: 600;
}

.hud-value {
    font-family: var(--font-typewriter);
    font-size: 0.85rem;
    color: var(--text-primary);
}

#hud-key {
    color: var(--accent-key);
}

.sanity-bar, .stamina-bar {
    width: 120px;
    height: 6px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    overflow: hidden;
}

.sanity-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--accent-red), var(--accent-sanity));
    border-radius: 3px;
    transition: width 0.3s ease;
}

.stamina-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #666, #aaa);
    border-radius: 3px;
    transition: width 0.15s ease;
}

/* ===== MOBILE CONTROLS ===== */
#mobile-controls {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 0;
    right: 0;
    padding: 0 20px;
    z-index: 200;
    justify-content: space-between;
    align-items: flex-end;
    pointer-events: none;
}

.dpad {
    display: grid;
    grid-template-areas:
        ". up ."
        "left . right"
        ". down .";
    gap: 4px;
    pointer-events: auto;
}

.dpad-btn {
    width: 50px;
    height: 50px;
    background: rgba(139, 0, 0, 0.2);
    border: 1px solid rgba(139, 0, 0, 0.3);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.5);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active {
    background: rgba(139, 0, 0, 0.5);
    color: #fff;
}

.dpad-btn.up { grid-area: up; }
.dpad-btn.left { grid-area: left; }
.dpad-btn.right { grid-area: right; }
.dpad-btn.down { grid-area: down; }

.action-buttons {
    display: flex;
    gap: 10px;
    pointer-events: auto;
}

.action-btn {
    width: 56px;
    height: 56px;
    background: rgba(139, 0, 0, 0.2);
    border: 1px solid rgba(139, 0, 0, 0.3);
    border-radius: 50%;
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.4rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.action-btn:active {
    background: rgba(139, 0, 0, 0.5);
}

@media (max-width: 768px) {
    #mobile-controls {
        display: flex;
    }
}

/* ===== PAUSE OVERLAY ===== */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
}

.overlay-content h2 {
    font-family: var(--font-horror);
    font-size: 2.5rem;
    color: var(--text-primary);
    margin-bottom: 30px;
    letter-spacing: 6px;
}

.overlay-content .menu-btn {
    margin: 8px 0;
    display: block;
}

/* ===== JUMP SCARE ===== */
#jumpscare-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

#jumpscare-overlay.hidden {
    display: none;
}

#jumpscare-overlay.active {
    animation: scare-shake 0.3s infinite;
}

#jumpscare-img {
    width: 100vw;
    height: 100vh;
    object-fit: cover;
    animation: scare-zoom 0.5s ease-out forwards;
    filter: contrast(1.5) brightness(1.2);
}

@keyframes scare-shake {
    0% { transform: translate(0, 0); }
    25% { transform: translate(-5px, 3px); }
    50% { transform: translate(3px, -5px); }
    75% { transform: translate(-3px, -3px); }
    100% { transform: translate(5px, 5px); }
}

@keyframes scare-zoom {
    0% { transform: scale(3); opacity: 0; }
    20% { opacity: 1; }
    100% { transform: scale(1.1); }
}

/* ===== GAME OVER ===== */
#gameover-screen {
    background: var(--bg-darker);
}

.gameover-content {
    text-align: center;
    animation: fade-in 1s ease;
}

.gameover-title {
    color: var(--accent-red) !important;
    margin-bottom: 15px;
}

.gameover-msg {
    font-family: var(--font-typewriter);
    color: var(--text-dim);
    margin-bottom: 30px;
    letter-spacing: 2px;
}

.gameover-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

/* ===== STAGE CLEAR ===== */
#stageclear-screen {
    background: var(--bg-darker);
}

.stageclear-content {
    text-align: center;
    animation: fade-in 1s ease;
}

.stageclear-title {
    font-family: var(--font-horror);
    font-size: 3rem;
    color: var(--accent-exit);
    margin-bottom: 10px;
    letter-spacing: 4px;
}

.stageclear-msg {
    font-family: var(--font-typewriter);
    color: var(--text-dim);
    margin-bottom: 25px;
}

.stage-stats {
    display: flex;
    gap: 30px;
    justify-content: center;
    margin-bottom: 30px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 15px 25px;
}

.stat span:first-child {
    font-size: 0.7rem;
    color: var(--text-dim);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.stat span:last-child {
    font-family: var(--font-typewriter);
    font-size: 1.4rem;
    color: var(--text-primary);
}

/* ===== VICTORY ===== */
#victory-screen {
    background: var(--bg-darker);
}

.victory-content {
    text-align: center;
    animation: fade-in 1.5s ease;
}

.victory-title {
    font-family: var(--font-horror);
    font-size: 3.5rem;
    color: var(--accent-exit);
    margin-bottom: 10px;
    letter-spacing: 6px;
    text-shadow: 0 0 30px rgba(0, 204, 102, 0.3);
}

.victory-subtitle {
    font-family: var(--font-typewriter);
    color: var(--text-dim);
    margin-bottom: 30px;
    letter-spacing: 2px;
}

/* ===== VIGNETTE ===== */
#vignette {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 150;
    background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.7) 100%);
    display: none;
}

#vignette.active {
    display: block;
}

#vignette.danger {
    background: radial-gradient(ellipse at center, transparent 30%, rgba(80,0,0,0.6) 100%);
    animation: vignette-pulse 1s infinite;
}

@keyframes vignette-pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* ===== SCREEN FLASH ===== */
#screen-flash {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 8000;
    background: #fff;
    opacity: 0;
    transition: opacity 0.05s ease;
}

#screen-flash.flash {
    opacity: 0.8;
    animation: flash-fade 0.3s ease-out forwards;
}

@keyframes flash-fade {
    0% { opacity: 0.8; }
    100% { opacity: 0; }
}

/* ===== SCREEN SHAKE ===== */
.screen-shake {
    animation: shake 0.3s infinite !important;
}

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

/* ===== UTILITIES ===== */
.hidden {
    display: none !important;
}

@keyframes fade-in {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
    .glitch {
        font-size: 2rem !important;
    }

    .menu-btn {
        min-width: 200px;
        padding: 12px 30px;
        font-size: 0.85rem;
    }

    .controls-grid {
        grid-template-columns: 1fr;
    }

    .sanity-bar, .stamina-bar {
        width: 80px;
    }

    .stage-stats {
        flex-direction: column;
        gap: 10px;
    }

    #hud {
        padding: 8px 12px;
    }
}
