/* ============================================
   RETRO TETRIS GAME STYLES
   Authentic 80s-90s Arcade Aesthetic
   ============================================ */

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

/* === CSS VARIABLES FOR RETRO THEME === */
:root {
    --crt-bg: #0a0a0a;
    --crt-dark: #050505;
    --neon-cyan: #00ffff;
    --neon-magenta: #ff00ff;
    --neon-yellow: #ffff00;
    --neon-red: #ff0000;
    --neon-green: #00ff00;
    --grid-line: #1a1a1a;
    --border-glow: rgba(0, 255, 255, 0.4);
    --scanline-opacity: 0.03;
}

/* === BASE RESET === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* === CRT BODY EFFECT === */
body {
    font-family: 'Press Start 2P', 'Courier New', monospace;
    background-color: var(--crt-bg);
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    /* Subtle CRT vignette effect */
    background-image: 
        radial-gradient(ellipse at center, var(--crt-bg) 0%, #000 100%);
}

/* === SCANLINE OVERLAY (OPTIONAL - can be removed) === */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, var(--scanline-opacity)) 2px,
        rgba(0, 0, 0, var(--scanline-opacity)) 4px
    );
}

/* === MAIN GAME CONTAINER === */
.game-container {
    background-color: var(--crt-dark);
    border: 3px solid #222;
    border-radius: 4px;
    padding: 20px;
    /* Neon glow border */
    box-shadow: 
        0 0 10px var(--border-glow),
        inset 0 0 30px rgba(0, 0, 0, 0.8);
    position: relative;
    z-index: 1;
}

/* === GAME HEADER === */
.game-header {
    text-align: center;
    margin-bottom: 20px;
}

.game-header h1 {
    color: var(--neon-cyan);
    font-size: 1.5em;
    text-shadow: 
        0 0 5px var(--neon-cyan),
        0 0 10px var(--neon-cyan),
        0 0 20px var(--neon-cyan);
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* === GAME AREA LAYOUT === */
.game-area {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

/* === GAME BOARD === */
.game-board {
    border: 2px solid #333;
    background-color: #000;
    position: relative;
    /* Inner shadow for depth */
    box-shadow: 
        inset 0 0 20px rgba(0, 0, 0, 0.9),
        0 0 5px var(--border-glow);
}

#gameCanvas {
    display: block;
    background-color: #000;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* === GAME INFO PANEL === */
.game-info {
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 140px;
}

/* === NEXT PIECE PREVIEW === */
.next-piece {
    border: 2px solid #333;
    padding: 10px;
    text-align: center;
    background-color: var(--crt-dark);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.next-piece h3 {
    margin-bottom: 8px;
    color: var(--neon-cyan);
    font-size: 0.6em;
    text-shadow: 0 0 5px var(--neon-cyan);
    text-transform: uppercase;
    letter-spacing: 1px;
}

#nextCanvas {
    display: block;
    margin: 0 auto;
    background-color: #000;
    border: 1px solid #222;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* === GAME STATS === */
.game-stats {
    border: 2px solid #333;
    padding: 12px;
    background-color: var(--crt-dark);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.stat {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.5em;
}

.stat:last-child {
    margin-bottom: 0;
}

.stat label {
    color: #888;
    text-transform: uppercase;
}

.stat span {
    color: var(--neon-cyan);
    text-shadow: 0 0 5px var(--neon-cyan);
}

/* === CONTROLS INFO === */
.controls {
    border: 2px solid #333;
    padding: 12px;
    background-color: var(--crt-dark);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.controls h3 {
    margin-bottom: 8px;
    color: var(--neon-cyan);
    font-size: 0.5em;
    text-shadow: 0 0 5px var(--neon-cyan);
    text-transform: uppercase;
}

.controls p {
    margin-bottom: 4px;
    font-size: 0.4em;
    color: #666;
    line-height: 1.8;
}

/* === AI CONTROLS === */
.ai-controls {
    border: 2px solid #333;
    padding: 12px;
    background-color: var(--crt-dark);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
    transition: box-shadow 0.3s ease;
}

.ai-controls h3 {
    margin-bottom: 8px;
    color: var(--neon-cyan);
    font-size: 0.5em;
    text-shadow: 0 0 5px var(--neon-cyan);
    text-transform: uppercase;
}

.ai-controls label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    color: #888;
    cursor: pointer;
    font-size: 0.4em;
}

.ai-controls input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--neon-cyan);
    cursor: pointer;
}

.ai-controls input[type="checkbox"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-status p {
    font-size: 0.4em;
    color: #666;
}

.ai-status span {
    color: var(--neon-cyan);
    text-shadow: 0 0 3px var(--neon-cyan);
}

/* === GAME STATUS OVERLAY === */
.game-status {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
}

/* === GAME OVER SCREEN === */
.game-over, .pause {
    background-color: rgba(0, 0, 0, 0.95);
    border: 2px solid var(--neon-cyan);
    padding: 25px;
    text-align: center;
    pointer-events: all;
    box-shadow: 
        0 0 10px var(--neon-cyan),
        0 0 20px rgba(0, 255, 255, 0.3),
        inset 0 0 20px rgba(0, 0, 0, 0.8);
}

.game-over h2 {
    color: var(--neon-red);
    font-size: 0.9em;
    margin-bottom: 15px;
    text-shadow: 
        0 0 5px var(--neon-red),
        0 0 10px var(--neon-red);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.pause h2 {
    color: var(--neon-yellow);
    font-size: 0.9em;
    margin-bottom: 15px;
    text-shadow: 
        0 0 5px var(--neon-yellow),
        0 0 10px var(--neon-yellow);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.game-over p {
    font-size: 0.5em;
    margin-bottom: 20px;
    color: #888;
}

.pause p {
    font-size: 0.5em;
    color: #888;
}

/* === RESTART BUTTON === */
#restartBtn {
    background-color: transparent;
    color: var(--neon-cyan);
    border: 2px solid var(--neon-cyan);
    padding: 10px 20px;
    font-size: 0.5em;
    font-family: 'Press Start 2P', 'Courier New', monospace;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 0 5px var(--neon-cyan);
    transition: all 0.2s ease;
}

#restartBtn:hover {
    background-color: var(--neon-cyan);
    color: #000;
    box-shadow: 
        0 0 10px var(--neon-cyan),
        0 0 20px var(--neon-cyan);
}

#restartBtn:active {
    transform: scale(0.98);
}

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

/* ============================================
   RETRO ANIMATIONS (STATE-BASED ONLY)
   ============================================ */

/* === GAME OVER CRT GLITCH ANIMATION === */
@keyframes crt-glitch {
    0% {
        transform: translate(0);
        filter: none;
    }
    10% {
        transform: translate(-2px, 1px);
        filter: hue-rotate(90deg);
    }
    20% {
        transform: translate(2px, -1px);
        filter: hue-rotate(-90deg) saturate(2);
    }
    30% {
        transform: translate(-1px, 2px);
        filter: none;
    }
    40% {
        transform: translate(1px, -2px);
        filter: hue-rotate(180deg);
    }
    50% {
        transform: translate(-2px, 0);
        filter: saturate(0.5);
    }
    60% {
        transform: translate(2px, 1px);
        filter: hue-rotate(-45deg);
    }
    70% {
        transform: translate(0, -1px);
        filter: none;
    }
    80% {
        transform: translate(-1px, 0);
        filter: hue-rotate(45deg);
    }
    90% {
        transform: translate(1px, 1px);
        filter: saturate(1.5);
    }
    100% {
        transform: translate(0);
        filter: none;
    }
}

/* Game over glitch effect on game board */
.game-board.game-over-glitch {
    animation: crt-glitch 0.6s ease-out forwards;
}

/* Scanline distortion during game over (OPTIONAL) */
@keyframes scanline-distort {
    0%, 100% {
        background-position: 0 0;
    }
    25% {
        background-position: 0 2px;
    }
    50% {
        background-position: 0 -2px;
    }
    75% {
        background-position: 0 1px;
    }
}

.game-board.game-over-glitch::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 1px,
        rgba(255, 0, 0, 0.1) 1px,
        rgba(255, 0, 0, 0.1) 2px
    );
    animation: scanline-distort 0.15s linear 4;
    opacity: 0;
    animation-fill-mode: forwards;
}

/* === AI DIFFICULTY CHANGE PULSE ANIMATION === */
@keyframes difficulty-pulse {
    0% {
        box-shadow: 
            inset 0 0 10px rgba(0, 0, 0, 0.5),
            0 0 5px var(--neon-magenta);
    }
    50% {
        box-shadow: 
            inset 0 0 10px rgba(0, 0, 0, 0.5),
            0 0 15px var(--neon-magenta),
            0 0 25px rgba(255, 0, 255, 0.5);
    }
    100% {
        box-shadow: 
            inset 0 0 10px rgba(0, 0, 0, 0.5);
    }
}

/* AI difficulty increase indicator */
.ai-controls.difficulty-change {
    animation: difficulty-pulse 0.4s ease-out forwards;
}

/* Border pulse for difficulty change (OPTIONAL - alternative effect) */
@keyframes border-pulse {
    0% {
        border-color: #333;
    }
    50% {
        border-color: var(--neon-magenta);
    }
    100% {
        border-color: #333;
    }
}

.game-container.difficulty-change {
    animation: border-pulse 0.4s ease-out forwards;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .game-header h1 {
        font-size: 1em;
    }
    
    .game-area {
        flex-direction: column;
        align-items: center;
    }
    
    .game-info {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        min-width: auto;
        gap: 10px;
    }
    
    .next-piece, .game-stats, .controls, .ai-controls {
        flex: 1;
        min-width: 100px;
    }
    
    .stat {
        font-size: 0.4em;
    }
    
    .controls p {
        font-size: 0.35em;
    }
}

/* ============================================
   OPTIONAL EFFECTS (can be removed if needed)
   ============================================ */

/* OPTIONAL: Subtle screen flicker on game container */

@keyframes screen-flicker {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.98; }
}
.game-container {
    animation: screen-flicker 0.1s infinite;
}


/* OPTIONAL: Phosphor glow effect on text */

.game-header h1,
.stat span,
.ai-status span {
    animation: phosphor-glow 2s ease-in-out infinite alternate;
}
@keyframes phosphor-glow {
    from { text-shadow: 0 0 5px currentColor; }
    to { text-shadow: 0 0 10px currentColor, 0 0 15px currentColor; }
}


/* ============================================
   GAME OVER TEXT GLITCH EFFECT
   Added: Retro glitch appearance for "GAME OVER" text
   To revert: Remove this entire section
   ============================================ */

/* Glitch animation for GAME OVER h2 text */
@keyframes game-over-text-glitch {
    0% {
        opacity: 0;
        transform: translate(0);
        text-shadow: 
            0 0 5px var(--neon-red),
            0 0 10px var(--neon-red);
    }
    10% {
        opacity: 0.8;
        transform: translate(-3px, 0);
        text-shadow: 
            -2px 0 #00ffff,
            2px 0 #ff00ff,
            0 0 10px var(--neon-red);
    }
    20% {
        opacity: 0.6;
        transform: translate(3px, 0);
        text-shadow: 
            2px 0 #00ffff,
            -2px 0 #ff00ff,
            0 0 5px var(--neon-red);
    }
    30% {
        opacity: 1;
        transform: translate(-2px, 0);
        text-shadow: 
            -1px 0 #00ffff,
            1px 0 #ff00ff,
            0 0 10px var(--neon-red);
    }
    40% {
        opacity: 0.9;
        transform: translate(2px, 0);
        text-shadow: 
            1px 0 #00ffff,
            -1px 0 #ff00ff,
            0 0 8px var(--neon-red);
    }
    50% {
        opacity: 0.7;
        transform: translate(-1px, 0);
        text-shadow: 
            -2px 0 #00ffff,
            2px 0 #ff00ff,
            0 0 12px var(--neon-red);
    }
    60% {
        opacity: 1;
        transform: translate(1px, 0);
        text-shadow: 
            1px 0 #00ffff,
            -1px 0 #ff00ff,
            0 0 10px var(--neon-red);
    }
    70% {
        opacity: 0.95;
        transform: translate(-1px, 0);
        text-shadow: 
            0 0 5px var(--neon-red),
            0 0 10px var(--neon-red);
    }
    80% {
        opacity: 1;
        transform: translate(1px, 0);
        text-shadow: 
            -1px 0 #00ffff,
            1px 0 #ff00ff,
            0 0 8px var(--neon-red);
    }
    90% {
        opacity: 0.98;
        transform: translate(0);
        text-shadow: 
            0 0 5px var(--neon-red),
            0 0 10px var(--neon-red);
    }
    100% {
        opacity: 1;
        transform: translate(0);
        text-shadow: 
            0 0 5px var(--neon-red),
            0 0 10px var(--neon-red);
    }
}

/* Apply glitch animation when game-over-animate class is added */
.game-over.game-over-animate h2 {
    animation: game-over-text-glitch 0.8s ease-out forwards;
}
