@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

:root {
    --stranger-red: #e11d48;
    --stranger-glow: #ff0055;
    --neon-blue: #38bdf8;
    --synth-purple: #a855f7;
    --eggo-gold: #f59e0b;
    --bg-dark: #070913;
}

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

body {
    background-color: var(--bg-dark);
    color: #ffffff;
    font-family: 'Press Start 2P', monospace;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: hidden;
}

/* Game Container & Cabinet Frame */
#game-wrapper {
    position: relative;
    width: 800px;
    height: 500px;
    max-width: 100vw;
    max-height: 100vh;
    box-shadow: 0 0 40px rgba(225, 29, 72, 0.4), 0 0 100px rgba(168, 85, 247, 0.2);
    border: 4px solid #1e293b;
    border-radius: 8px;
    background: #000;
    overflow: hidden;
}

#game-wrapper:fullscreen,
#game-wrapper:-webkit-full-screen {
    width: 100vw;
    height: 100vh;
    max-width: none;
    max-height: none;
    border: none;
    border-radius: 0;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* CRT Overlay Shader Effect with TV Static Grain */
#crt-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: 
        linear-gradient(
            rgba(18, 16, 16, 0) 50%, 
            rgba(0, 0, 0, 0.32) 50%
        ),
        linear-gradient(
            90deg,
            rgba(255, 0, 0, 0.03),
            rgba(0, 255, 0, 0.01),
            rgba(0, 0, 255, 0.03)
        ),
        repeating-radial-gradient(
            rgba(255, 255, 255, 0.03) 0,
            rgba(0, 0, 0, 0.04) 1px,
            transparent 2px,
            transparent 4px
        );
    background-size: 100% 4px, 6px 100%, 8px 8px;
    z-index: 10;
    box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.85);
    animation: crtFlicker 0.15s infinite;
}

@keyframes crtFlicker {
    0% { opacity: 0.97; }
    50% { opacity: 1.0; }
    100% { opacity: 0.98; }
}

/* Mild Upside Down Glitch & Chromatic Aberration */
#game-wrapper.upsidedown-active #game-canvas {
    animation: udGlitchShift 4s infinite ease-in-out;
}

#game-wrapper.upsidedown-active #crt-overlay {
    background: 
        linear-gradient(
            rgba(225, 29, 72, 0.08) 50%, 
            rgba(0, 0, 0, 0.45) 50%
        ),
        linear-gradient(
            90deg,
            rgba(255, 0, 60, 0.08),
            rgba(0, 255, 200, 0.03),
            rgba(168, 85, 247, 0.08)
        ),
        repeating-radial-gradient(
            rgba(255, 100, 150, 0.05) 0,
            rgba(0, 0, 0, 0.08) 1px,
            transparent 2px,
            transparent 3px
        );
    background-size: 100% 4px, 4px 100%, 6px 6px;
    box-shadow: inset 0 0 100px rgba(225, 29, 72, 0.35), inset 0 0 50px rgba(0, 0, 0, 0.9);
}

@keyframes udGlitchShift {
    0%, 94%, 100% {
        transform: translate(0, 0);
        filter: none;
    }
    95% {
        transform: translate(-2px, 1px);
        filter: hue-rotate(-15deg) contrast(1.1);
    }
    96% {
        transform: translate(2px, -1px);
        filter: hue-rotate(15deg) brightness(1.15);
    }
    97% {
        transform: translate(-1px, -1px);
        filter: none;
    }
    98% {
        transform: translate(1px, 2px);
        filter: hue-rotate(-25deg);
    }
    99% {
        transform: translate(0, 0);
        filter: none;
    }
}

/* UI Overlay Screens */
.ui-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(7, 9, 19, 0.92);
    z-index: 20;
    padding: 24px;
    text-align: center;
}

/* Stranger Things Glowing Title */
.title-glow {
    font-size: 26px;
    color: #ff2255;
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow: 
        0 0 10px #ff0055,
        0 0 20px #ff0055,
        0 0 40px #e11d48,
        0 0 80px #b91c1c;
    margin-bottom: 8px;
    animation: titleFlicker 4s infinite alternate;
}

.subtitle {
    font-size: 11px;
    color: var(--neon-blue);
    letter-spacing: 2px;
    margin-bottom: 24px;
    text-shadow: 0 0 8px var(--neon-blue);
}

@keyframes titleFlicker {
    0%, 19%, 21%, 23%, 25%, 54%, 56%, 100% {
        opacity: 1;
        text-shadow: 0 0 10px #ff0055, 0 0 20px #ff0055, 0 0 40px #e11d48;
    }
    20%, 24%, 55% {
        opacity: 0.7;
        text-shadow: none;
    }
}

/* Retro Buttons */
.retro-btn {
    background: #1e1b4b;
    color: #ffffff;
    border: 2px solid var(--stranger-red);
    padding: 10px 18px;
    font-family: 'Press Start 2P', monospace;
    font-size: 11px;
    cursor: pointer;
    border-radius: 4px;
    margin: 6px;
    box-shadow: 0 0 10px rgba(225, 29, 72, 0.3);
    transition: all 0.15s ease;
}

.retro-btn:hover {
    background: var(--stranger-red);
    box-shadow: 0 0 20px var(--stranger-glow);
    transform: scale(1.05);
}

.controls-info {
    font-family: 'VT323', monospace;
    font-size: 18px;
    color: #cbd5e1;
    line-height: 1.6;
    margin-top: 14px;
    background: rgba(15, 23, 42, 0.7);
    padding: 12px 18px;
    border-radius: 6px;
    border-left: 3px solid var(--synth-purple);
}

/* Dialogue Box */
#dialogue-box {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: rgba(15, 23, 42, 0.95);
    border: 2px solid var(--neon-blue);
    border-radius: 6px;
    padding: 16px;
    display: none;
    align-items: center;
    gap: 16px;
    z-index: 25;
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.4);
}

.avatar-icon {
    width: 48px;
    height: 48px;
    border: 2px solid var(--eggo-gold);
    border-radius: 4px;
    background: #1e293b;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

#dialogue-text {
    font-family: 'VT323', monospace;
    font-size: 22px;
    color: #f8fafc;
    flex: 1;
    text-align: left;
    white-space: pre-line;
    line-height: 1.3;
}

.skip-hint {
    font-size: 8px;
    color: #94a3b8;
    align-self: flex-end;
}

/* Control Bar (Audio / CRT toggles) */
#top-bar {
    width: 800px;
    max-width: 100vw;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #0f172a;
    border-top: 2px solid #334155;
    border-left: 2px solid #334155;
    border-right: 2px solid #334155;
    font-size: 9px;
}

.top-btn {
    background: transparent;
    color: #94a3b8;
    border: 1px solid #475569;
    padding: 4px 8px;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    cursor: pointer;
    border-radius: 3px;
}

.top-btn:hover {
    color: #ffffff;
    border-color: var(--neon-blue);
}

/* Touch On-Screen Controls for Mobile / Tablets */
#touch-controls {
    display: none;
    position: absolute;
    bottom: 12px;
    left: 12px;
    right: 12px;
    justify-content: space-between;
    pointer-events: none;
    z-index: 30;
}

@media (max-width: 850px), (hover: none) and (pointer: coarse) {
    #touch-controls {
        display: flex;
    }
}

.touch-cluster {
    display: flex;
    gap: 8px;
    pointer-events: auto;
}

.touch-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(30, 41, 59, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: #ffffff;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

.touch-btn.active {
    background: var(--stranger-red);
    border-color: #ffffff;
    transform: scale(0.92);
}
