/* tv.css — CRT/TV effects, animations */

/* === TV UNIT === */
#tv-unit {
    perspective: 800px;
}

#tv-bezel {
    background: var(--tv-woodgrain);
    border-radius: 20px;
    padding: 30px 35px 20px;
    position: relative;
    box-shadow:
        0 8px 24px rgba(0,0,0,0.5),
        inset 0 2px 0 rgba(255,255,255,0.1),
        inset 0 -2px 0 rgba(0,0,0,0.3);
}

#tv-brand {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    letter-spacing: 4px;
    color: rgba(255,255,255,0.15);
    text-transform: uppercase;
}

/* Screen container */
#screen-container {
    background: #000;
    border-radius: 12px;
    padding: 4px;
    box-shadow:
        inset 0 0 30px rgba(0,0,0,0.8),
        0 0 2px rgba(0,0,0,0.5);
}

#screen {
    width: 512px;
    height: 448px;
    background: var(--screen-bg);
    border-radius: 10px;
    position: relative;
    overflow: hidden;
}

/* Game canvas */
#game-canvas {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
    position: relative;
    z-index: 1;
}

/* CRT overlay (curvature + vignette) */
#crt-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
    border-radius: 10px;
    background: radial-gradient(
        ellipse at center,
        transparent 60%,
        rgba(0,0,0,0.3) 85%,
        rgba(0,0,0,0.7) 100%
    );
    box-shadow: inset 0 0 80px rgba(0,0,0,0.4);
}

/* Scanlines */
#scanlines {
    position: absolute;
    inset: 0;
    z-index: 11;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 1px,
        rgba(0,0,0,var(--scanline-opacity)) 1px,
        rgba(0,0,0,var(--scanline-opacity)) 2px
    );
    mix-blend-mode: multiply;
}

/* Screen glare */
#screen-glare {
    position: absolute;
    inset: 0;
    z-index: 12;
    pointer-events: none;
    background: linear-gradient(
        135deg,
        rgba(255,255,255,0.06) 0%,
        rgba(255,255,255,0.02) 30%,
        transparent 50%,
        transparent 100%
    );
    border-radius: 10px;
}

/* Static overlay */
#static-overlay {
    position: absolute;
    inset: 0;
    z-index: 13;
    pointer-events: none;
    opacity: 0;
    background:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(255,255,255,0.015) 2px,
            rgba(255,255,255,0.015) 4px
        );
    animation: staticFlicker 0.1s steps(4) infinite;
}

#static-overlay.active {
    opacity: 1;
}

/* Power off screen */
#power-off-screen {
    position: absolute;
    inset: 0;
    z-index: 15;
    background: #0a0a0a;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s;
}

#power-off-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.no-signal {
    color: rgba(255,255,255,0.3);
    font-size: 14px;
    letter-spacing: 4px;
    animation: noSignalBlink 2s ease-in-out infinite;
}

/* TV controls (knobs) */
#tv-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    margin-top: 12px;
}

.tv-knob {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.tv-knob .knob-indicator {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, #888 0%, #555 100%);
    border: 2px solid #444;
    position: relative;
    transition: transform 0.2s;
}

.tv-knob .knob-indicator::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 6px;
    background: #ddd;
    border-radius: 1px;
}

.knob-label {
    font-size: 7px;
    color: rgba(255,255,255,0.2);
    letter-spacing: 2px;
}

.tv-led {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--led-off);
    transition: all 0.3s;
}

.tv-led.on {
    background: var(--led-green);
    box-shadow: 0 0 6px var(--led-green);
}

/* === CRT EFFECTS === */

/* Phosphor glow */
#screen.phosphor-glow {
    filter: brightness(1.05) contrast(1.1);
}

/* Chromatic aberration */
#screen.chromatic-aberration #game-canvas {
    text-shadow:
        -1px 0 rgba(255,0,0,0.2),
        1px 0 rgba(0,0,255,0.2);
}

/* Flicker effect */
#screen.flicker {
    animation: crtFlicker 0.05s steps(2) infinite;
}

/* Horizontal tear */
.h-tear {
    position: absolute;
    left: 0;
    width: 100%;
    height: 3px;
    z-index: 14;
    pointer-events: none;
    background: rgba(255,255,255,0.1);
    box-shadow: 0 0 6px rgba(255,255,255,0.1);
    animation: hTear 4s linear infinite;
}

/* VHS tracking line */
.vhs-tracking {
    position: absolute;
    left: 0;
    width: 100%;
    height: 20px;
    z-index: 14;
    pointer-events: none;
    background: linear-gradient(
        180deg,
        transparent 0%,
        rgba(255,255,255,0.05) 30%,
        rgba(255,255,255,0.1) 50%,
        rgba(255,255,255,0.05) 70%,
        transparent 100%
    );
    animation: vhsTracking 3s linear infinite;
}

/* Color bleed (VHS) */
#screen.color-bleed #game-canvas {
    filter: blur(0.5px) saturate(1.3);
}

/* Screen power on/off animations */
@keyframes powerOn {
    0% {
        clip-path: inset(50% 0);
        filter: brightness(5) contrast(0);
    }
    30% {
        clip-path: inset(48% 0);
        filter: brightness(3) contrast(0.5);
    }
    60% {
        clip-path: inset(0);
        filter: brightness(2) contrast(0.8);
    }
    100% {
        clip-path: inset(0);
        filter: brightness(1) contrast(1);
    }
}

@keyframes powerOff {
    0% {
        filter: brightness(1);
        clip-path: inset(0);
    }
    40% {
        filter: brightness(2);
        clip-path: inset(0);
    }
    70% {
        filter: brightness(5);
        clip-path: inset(48% 0);
    }
    100% {
        filter: brightness(0);
        clip-path: inset(50% 0);
    }
}

#screen.power-on {
    animation: powerOn 0.8s ease-out forwards;
}

#screen.power-off {
    animation: powerOff 0.5s ease-in forwards;
}

/* CRT flicker */
@keyframes crtFlicker {
    0% { opacity: 0.97; }
    50% { opacity: 1; }
}

/* No signal blink */
@keyframes noSignalBlink {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.6; }
}

/* Static flicker */
@keyframes staticFlicker {
    0% { background-position: 0 0; }
    25% { background-position: 2px 1px; }
    50% { background-position: -1px 2px; }
    75% { background-position: 1px -1px; }
}

/* Horizontal tear movement */
@keyframes hTear {
    0% { top: -3px; }
    100% { top: 100%; }
}

/* VHS tracking */
@keyframes vhsTracking {
    0% { top: -20px; }
    100% { top: 100%; }
}

/* Corruption color shift */
#screen.hue-shift {
    filter: hue-rotate(var(--corruption-hue));
}

/* Glitch horizontal offset */
#screen.glitch-offset #game-canvas {
    transform: translateX(var(--glitch-offset));
}

/* Screen shake */
#screen.screen-shake {
    animation: screenShake 0.3s ease-in-out;
}

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

/* Bloom effect */
#screen.bloom #game-canvas {
    filter: brightness(1.1) contrast(1.1);
    mix-blend-mode: screen;
}

/* === RESPONSIVE TV === */
@media (max-width: 768px) {
    #tv-bezel {
        padding: 20px 22px 14px;
        border-radius: 14px;
    }

    #screen {
        width: 384px;
        height: 336px;
    }

    #screen-container {
        border-radius: 8px;
    }
}

@media (max-width: 480px) {
    #tv-bezel {
        padding: 14px 16px 10px;
        border-radius: 10px;
    }

    #screen {
        width: 288px;
        height: 252px;
    }

    #tv-controls {
        gap: 16px;
    }

    .tv-knob .knob-indicator {
        width: 20px;
        height: 20px;
    }
}
