/**
 * lens.css - The Cold War Optic
 * 
 * Implements the "UI Rockstar" polish:
 * 1. Global Analog/CRT Lens (Grain, Vignette, Chromatic Aberration)
 * 2. Tactile Mechanical Interactions
 * 3. Cinematic "Paper Shuffle" Transitions
 * 4. Visual Decay System (Coffee, Ash, Smoke)
 */

/* ========================================
   1. MAP CRT LENS
   ======================================== */

/* Global overlay now stays subtle; dramatic treatment is scoped to the War Room map. */
#lens-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 10000;
    overflow: hidden;
    mix-blend-mode: normal;
}

#lens-overlay::before {
    content: "";
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.5'/%3E%3C/svg%3E");
    opacity: 0.03;
    animation: grain-shift 0.7s steps(3) infinite;
}

@keyframes grain-shift {
    0% { transform: translate(0, 0); }
    20% { transform: translate(-1.3%, 0.8%); }
    40% { transform: translate(0.7%, -0.9%); }
    60% { transform: translate(-0.9%, 1.1%); }
    80% { transform: translate(1.4%, -1.2%); }
    100% { transform: translate(0, 0); }
}

#lens-overlay::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0;
    background:
        radial-gradient(circle at 50% 24%, rgba(255, 255, 255, 0.75) 0%, rgba(229, 243, 255, 0.22) 30%, transparent 65%),
        radial-gradient(circle at 50% 80%, rgba(167, 198, 236, 0.18) 0%, transparent 62%);
}

@keyframes lamp-switch-flash {
    0% { opacity: 0.72; }
    100% { opacity: 0; }
}

body.lamp-switch-flash #lens-overlay::after {
    animation: lamp-switch-flash 0.22s ease-out;
}

/* War Room map receives scanlines, phosphor glow, and mild barrel distortion. */
#foreign-policy-view.active #map-area .game-map.ghost-map-container,
#foreign-policy-view.active #map-area .world-map-container.defcon-style .game-map {
    position: relative;
}

#foreign-policy-view.active #map-area .game-map.ghost-map-container::before,
#foreign-policy-view.active #map-area .world-map-container.defcon-style .game-map::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 14;
    background:
        repeating-linear-gradient(
            180deg,
            rgba(212, 244, 206, 0.11) 0px,
            rgba(212, 244, 206, 0.11) 1px,
            rgba(0, 0, 0, 0) 1px,
            rgba(0, 0, 0, 0) 4px
        );
    mix-blend-mode: screen;
    opacity: 0.26;
}

#foreign-policy-view.active #map-area .game-map.ghost-map-container::after,
#foreign-policy-view.active #map-area .world-map-container.defcon-style .game-map::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 15;
    background:
        radial-gradient(circle at 52% 44%, rgba(132, 215, 140, 0.15) 0%, transparent 52%),
        radial-gradient(circle at 53% 40%, transparent 52%, rgba(0, 0, 0, 0.32) 100%);
}

#foreign-policy-view.active #map-area .ghost-map-inner {
    transform: perspective(1300px) scale(1.01) rotateX(0.8deg);
    transform-origin: 50% 50%;
    filter: contrast(1.06) saturate(0.92);
    transition: transform 0.35s ease, filter 0.35s ease;
}

#foreign-policy-view.active #map-area .ghost-label .label-code {
    background: rgba(10, 18, 14, 0.72);
    color: #d3e5c2;
    border-color: rgba(145, 188, 112, 0.6);
    text-shadow:
        0 0 4px rgba(170, 224, 149, 0.55),
        0 0 8px rgba(255, 194, 104, 0.24);
}

#foreign-policy-view.active #map-area .ghost-label.us-aligned .label-code {
    color: #d9e8ff;
    border-color: rgba(126, 176, 241, 0.64);
    text-shadow: 0 0 6px rgba(116, 166, 242, 0.6);
}

#foreign-policy-view.active #map-area .ghost-label.ussr-aligned .label-code {
    color: #ffd7d7;
    border-color: rgba(240, 122, 122, 0.68);
    text-shadow: 0 0 6px rgba(242, 112, 112, 0.62);
}

body.clear-light #foreign-policy-view.active #map-area .ghost-map-inner {
    transform: none;
    filter: none;
}

body.clear-light #foreign-policy-view.active #map-area .game-map.ghost-map-container::before,
body.clear-light #foreign-policy-view.active #map-area .world-map-container.defcon-style .game-map::before {
    opacity: 0.08;
    mix-blend-mode: soft-light;
}

body.clear-light #foreign-policy-view.active #map-area .game-map.ghost-map-container::after,
body.clear-light #foreign-policy-view.active #map-area .world-map-container.defcon-style .game-map::after {
    background: radial-gradient(circle at 52% 40%, rgba(255, 255, 255, 0.18) 0%, transparent 58%);
}

body.clear-light #foreign-policy-view.active #map-area .ghost-label .label-code {
    background: rgba(255, 255, 255, 0.92);
    color: #1b334f;
    border-color: rgba(118, 150, 189, 0.68);
    text-shadow: none;
}

/* Intel Glitch Effect (Triggered via JS class on #desk or body) */
.intel-glitch {
    animation: glitch-anim 0.3s cubic-bezier(.25, .46, .45, .94) both infinite;
}

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

.intel-glitch::before {
    color: #ff00ff;
    z-index: -1;
    animation: glitch-anim-1 2s infinite linear alternate-reverse;
}

.intel-glitch::after {
    color: #00ffff;
    z-index: -2;
    animation: glitch-anim-2 3s infinite linear alternate-reverse;
}

@keyframes glitch-anim {
    0% { transform: translate(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) }
}

/* ========================================
   2. TACTILE INTERACTIONS
   ======================================== */

/* Buttons feeling "heavy" */
.execute-btn, .end-turn-btn, .crisis-btn, .faction-btn, .protocol-btn {
    transition: transform 0.05s ease-out, box-shadow 0.05s ease-out !important;
}

.execute-btn:active, .end-turn-btn:active, .crisis-btn:active, .faction-btn:active, .protocol-btn:active {
    transform: scale(0.97) translateY(2px) !important;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.4) !important;
    filter: brightness(0.9);
}

/* Hover "lift" for cards */
.telegram, .action-card {
    transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.2s ease;
}

.telegram:hover:not(.disabled), .action-card:hover:not(.disabled) {
    transform: translateY(-2px) rotate(0.5deg);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2) !important;
    z-index: 5;
}

/* ========================================
   3. CINEMATIC TRANSITIONS
   ======================================== */

/* Paper Slide-In */
@keyframes paper-slide-up {
    0% { 
        opacity: 0;
        transform: translateY(20px) rotate(-1deg);
    }
    100% { 
        opacity: 1; 
        transform: translateY(0) rotate(0deg);
    }
}

.telegram, .action-card, .notification {
    animation: paper-slide-up 0.4s cubic-bezier(0.19, 1, 0.22, 1) forwards;
}

/* Stagger animation for lists of items */
.action-list .telegram:nth-child(1) { animation-delay: 0.05s; }
.action-list .telegram:nth-child(2) { animation-delay: 0.1s; }
.action-list .telegram:nth-child(3) { animation-delay: 0.15s; }
.action-list .telegram:nth-child(4) { animation-delay: 0.2s; }

/* Stamp Impact */
@keyframes stamp-impact {
    0% {
        opacity: 0;
        transform: scale(3) rotate(-15deg);
    }
    70% {
        opacity: 1;
        transform: scale(0.9) rotate(-3deg);
    }
    100% {
        transform: scale(1) rotate(-5deg);
    }
}

.stamp {
    animation: stamp-impact 0.3s cubic-bezier(0.5, 0, 0.75, 0) forwards;
    display: inline-block; /* Ensure transform works */
}

/* ========================================
   4. VISUAL DECAY SYSTEM
   ======================================== */

/* Base Decay Layer on #desk */
#desk {
    position: relative;
    transition: filter 2s ease;
}

/* Stress Tier 1: Late Nights (Subtle Coffee Stains, dimmed light) */
.desk-stress-1 {
    filter: sepia(0.2) contrast(1.05);
}

.desk-stress-1::before {
    content: '';
    position: absolute;
    top: 15%;
    right: 10%;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    /* Coffee Ring */
    background: radial-gradient(transparent 60%, rgba(60, 40, 20, 0.1) 65%, rgba(60, 40, 20, 0.3) 70%, transparent 75%);
    transform: rotate(30deg) scale(1, 0.85);
    pointer-events: none;
    z-index: 1;
    opacity: 0.7;
    filter: blur(1px);
}

/* Stress Tier 2: The Crisis (More Stains, Smoke Haze, darker) */
.desk-stress-2 {
    filter: sepia(0.4) contrast(1.1) brightness(0.9);
}

.desk-stress-2::before {
    /* Two coffee rings now */
    content: '';
    position: absolute;
    top: 15%;
    right: 10%;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: 
        radial-gradient(transparent 60%, rgba(60, 40, 20, 0.15) 65%, rgba(60, 40, 20, 0.4) 70%, transparent 75%),
        radial-gradient(at 140% 40%, transparent 60%, rgba(60, 40, 20, 0.2) 65%, rgba(60, 40, 20, 0.5) 70%, transparent 75%);
    transform: rotate(45deg) scale(1, 0.85);
    pointer-events: none;
    z-index: 1;
    opacity: 0.8;
    filter: blur(1px);
}

.desk-stress-2::after {
    /* Smoke Haze */
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(circle at 20% 80%, rgba(255,255,255,0.05) 0%, transparent 40%);
    pointer-events: none;
    z-index: 999;
    animation: smoke-drift 10s ease-in-out infinite alternate;
}

/* Stress Tier 3: The Bunker (Red Tint, Heavy Grain, Ash) */
.desk-stress-3 {
    filter: sepia(0.6) contrast(1.3) brightness(0.8) hue-rotate(-10deg);
}

.desk-stress-3::after {
    /* Heavy Smoke & Ash */
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: 
        radial-gradient(circle at 20% 80%, rgba(200,200,200,0.1) 0%, transparent 50%),
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.1'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 999;
    mix-blend-mode: hard-light;
    animation: smoke-drift 8s ease-in-out infinite alternate;
}

@keyframes smoke-drift {
    0% { opacity: 0.3; transform: translateX(0); }
    100% { opacity: 0.6; transform: translateX(20px); }
}

/* Transition class for smooth stress updates */
.desk-stress-transition {
    transition: filter 4s ease-in-out;
}
