:root {
    --bg-color: #050505;
    --terminal-green: #00ff41;
    --danger-red: #ff3333;
}

body {
    background-color: var(--bg-color);
    color: var(--terminal-green);
    font-family: 'Share Tech Mono', monospace;
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    padding-bottom: 0px;
    /* Reset padding here, handle in containers */
    overflow: hidden;
}

.top-bar {
    padding: 15px;
    border-bottom: 1px solid var(--terminal-green);
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

.blink {
    animation: blinker 1.5s linear infinite;
    color: var(--danger-red);
}

@keyframes blinker {
    50% {
        opacity: 0;
    }
}

.terminal-container {
    flex: 1;
    padding: 20px;
    font-size: 1.1rem;
    padding-bottom: 120px;
    /* Prevent button overlap on mobile */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Smooth scroll iOS */
}

.control-panel {
    padding: 20px;
    border-top: 1px solid var(--terminal-green);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.choice-btn {
    background: transparent;
    border: 1px solid var(--terminal-green);
    color: var(--terminal-green);
    font-family: inherit;
    padding: 20px 25px;
    margin-bottom: 15px;
    /* Spacing between buttons */
    text-align: left;
    text-transform: uppercase;
    cursor: pointer;
}

.choice-btn:hover {
    background: var(--terminal-green);
    color: #000;
    font-weight: bold;
}

.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
    z-index: 10;
}

.agent-avatar {
    width: 50px;
    height: 50px;
    border: 1px solid var(--terminal-green);
    object-fit: cover;
    filter: grayscale(100%) sepia(50%) contrast(1.2);
}

/* Global Statistics Panel */
.stats-panel {
    border: 1px dashed var(--terminal-green);
    padding: 10px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-around;
    background: rgba(0, 20, 0, 0.5);
    font-size: 0.9rem;
}

.stat-item {
    text-align: center;
}

.stat-header {
    display: block;
    margin-bottom: 5px;
    opacity: 0.8;
    font-size: 0.8rem;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: bold;
    font-family: 'Share Tech Mono', monospace;
}

.stat-saved {
    color: #00ffff;
    text-shadow: 0 0 5px #00ffff;
}

/* Cyan */
.stat-casualties {
    color: #ff4444;
    text-shadow: 0 0 5px #ff4444;
}

/* DOOMSDAY MODE */
.doomsday-mode {
    --terminal-green: #ff0000;
    --bg-color: #1a0000;
    /* Subtle reddish tint */
}

.doomsday-mode .scanlines {
    background: linear-gradient(rgba(50, 0, 0, 0) 50%, rgba(50, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.1), rgba(255, 0, 0, 0.05), rgba(255, 0, 0, 0.1));
}

.doomsday-mode body {
    box-shadow: inset 0 0 50px #ff0000;
    animation: panic-pulse 2s infinite;
}

@keyframes panic-pulse {
    0% {
        box-shadow: inset 0 0 20px #550000;
    }

    50% {
        box-shadow: inset 0 0 60px #aa0000;
    }

    100% {
        box-shadow: inset 0 0 20px #550000;
    }
}

/* ========================================= */
/* PC / DESKTOP OPTIMIZATION (min-width: 768px) */
/* ========================================= */
@media (min-width: 768px) {
    /* PC Optimization overrides within the wrapper if needed, 
       but the main logic is now handled by the wrapper structure below */
}

/* ========================================= */
/* FORCED CENTERING LAYOUT (PC & MOBILE)     */
/* ========================================= */
body {
    background-color: #000;
    /* Force black background */
    margin: 0;
    display: flex;
    justify-content: center;
    /* Centers the game-wrapper horizontally */
    min-height: 100dvh;
}

.game-wrapper {
    width: 100%;
    max-width: 600px;
    /* ANCHO MÁXIMO: Nunca pasará de 600px */
    margin-top: 0px;
    margin-left: auto !important;
    margin-right: auto !important;
    border-left: 1px solid var(--terminal-green);
    border-right: 1px solid var(--terminal-green);
    padding: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    /* Full height of viewport */
    background-color: var(--bg-color);
    position: relative;
    box-shadow: 0 0 50px rgba(0, 255, 65, 0.1);
}

/* On mobile, remove borders and margins to use full screen */
@media (max-width: 768px) {
    .game-wrapper {
        border: none;
        max-width: 100%;
        box-shadow: none;
    }

    #terminal-output {
        margin-top: 100px;
        /* Prevent overlap with sticky HUD */
    }

    /* MINI-BARRA OPTIMIZATION */
    .top-bar .choice-btn {
        padding: 2px 4px !important;
        font-size: 0.75rem !important;
        margin-bottom: 0 !important;
        width: auto !important;
        border-width: 1px !important;
        line-height: normal !important;
    }
}

/* ========================================= */
/* HUD (PSYCHOLOGICAL STATE INTERFACE)       */
/* ========================================= */

/* BASE STYLE (MOBILE DEFAULT) */
#hud {
    position: sticky;
    /* Stays at top but pushes content down */
    top: 0;
    left: 0;
    width: 100%;
    background-color: #000000 !important;
    /* Force opaque black */
    border-bottom: 1px solid var(--terminal-green);
    display: flex;
    flex-wrap: wrap;
    /* Allow wrapping on very small screens */
    justify-content: space-between;
    padding: 5px 10px;
    box-sizing: border-box;
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.8rem;
    /* Smaller font for mobile */
    z-index: 1000 !important;
    /* Ensure on top */
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.5);
}

/* FLOATING STAT POPUP (AGGRESSIVE MOBILE FIX) */
@keyframes floatUp {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -150%) scale(1.5);
        opacity: 0;
    }
}

.stat-popup {
    position: fixed;
    /* FIXED over everything */
    top: 40%;
    /* Center screen vertically */
    left: 50%;
    /* Center screen horizontally */
    transform: translate(-50%, -50%);
    /* True centering */
    font-family: 'Courier New', monospace;
    font-weight: bold;
    font-size: 2rem;
    /* GIANT TEXT */
    text-shadow: 2px 2px 0px #000;
    pointer-events: none;
    animation: floatUp 2s ease-out forwards;
    z-index: 9999;
    /* Top layer */
}

/* Colores forzados */
.popup-bad {
    color: #ff0000 !important;
    text-shadow: 0 0 10px #ff0000;
}

.popup-good {
    color: #00ff00 !important;
    text-shadow: 0 0 10px #00ff00;
}

.hud-title {
    display: none;
    /* Hide title on mobile to save space */
    width: 100%;
    border-bottom: 1px solid var(--terminal-green);
    margin-bottom: 5px;
    text-align: center;
    font-weight: bold;
}

.hud-row {
    margin: 0 5px;
    white-space: nowrap;
    /* Prevent text breaking */
}

/* DESKTOP OVERRIDE (SIDEBAR MODE) */
@media (min-width: 1100px) {

    /* Trigger only on wide screens where sidebar fits */
    #hud {
        position: fixed;
        top: 20px;
        right: 20px;
        width: 260px;
        /* Fixed width sidebar */
        left: auto;
        /* Reset left */
        border: 1px solid var(--terminal-green);
        border-bottom: 1px solid var(--terminal-green);
        /* Reiterate border */
        display: block;
        /* Stack vertically */
        background: rgba(0, 5, 0, 0.9);
        /* Slight transparency on PC */
        font-size: 0.9rem;
        padding: 15px;
    }

    .hud-title {
        display: block;
        /* Show title on PC */
    }

    .hud-row {
        margin: 8px 0;
        /* Vertical spacing */
        white-space: normal;
    }
}

/* Critical Decision Indicator */
.waiting-indicator {
    color: #ff3737;
    /* Red Alert */
    font-family: 'Share Tech Mono', monospace;
    font-size: 1rem;
    font-weight: bold;
    margin-bottom: 20px;
    letter-spacing: 2px;
    text-align: center;
    width: 100%;
    animation: blink-panic 0.8s infinite;
}

@keyframes blink-panic {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}


/* Meta-Progression Terminal */
.meta-terminal {
    border: 1px dashed #00f3ff;
    /* Cyan brillante */
    color: #00f3ff;
    padding: 15px;
    margin-top: 20px;
    font-family: 'Share Tech Mono', monospace;
    background: rgba(0, 243, 255, 0.05);
    /* Fondo muy sutil */
    text-shadow: 0 0 5px #00f3ff;
    font-size: 0.85rem;
}


/* Missed Routes (FOMO) */
.missed-routes-container {
    border: 1px solid #444;
    color: #888;
    padding: 15px;
    margin-top: 15px;
    font-family: 'Share Tech Mono', monospace;
    background: rgba(20, 20, 20, 0.8);
    font-size: 0.8rem;
}

.missed-route-header {
    border-bottom: 1px dashed #444;
    padding-bottom: 5px;
    margin-bottom: 10px;
    font-weight: bold;
    color: #666;
}

.missed-route-item {
    margin: 5px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.missed-items-hint {
    margin-top: 15px;
    font-style: italic;
    opacity: 0.6;
    font-size: 0.7rem;
    border-top: 1px solid #333;
    padding-top: 5px;
}