/* --- MASTER CONTAINER --- */
.library-container { 
    width: 100%;
    max-width: 1600px;
    margin: 2rem auto 0 auto; /* <-- This adds the perfect gap back */
    padding: 20px;  
    box-sizing: border-box;
}

/* --- RESPONSIVE MEDIA GRID (Fluid Math) --- */
.media-grid {
    display: grid;
    /* Desktop: Fits as many ~140px posters as possible */
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 20px;
}

@media (max-width: 768px) {
    .media-grid {
        /* Mobile: Shrinks posters down to ~105px to comfortably fit 3 across */
        grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
        gap: 12px;
    }
}

/* --- TERMINAL STYLES (Desktop Sticky) --- */
.terminal-window {
    width: 100%; 
    box-sizing: border-box;
    margin: 0 auto;
    background: rgba(22, 22, 22, 0.7); 
    backdrop-filter: blur(10px);
    border-radius: 12px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.6); 
    border: 1px solid rgba(255, 121, 198, 0.2);
    position: sticky;
    top: 20px; 
    z-index: 100; 
}

.terminal-header {
    background: linear-gradient(180deg, rgba(45, 45, 50, 0.95) 0%, rgba(25, 25, 30, 0.95) 100%);
    border-bottom: 1px solid rgba(0, 0, 0, 0.8);
    border-radius: 12px 12px 0 0;
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.1);
    padding: 12px 16px;
    display: flex; 
    align-items: center; 
    gap: 8px;
}

.term-btn { 
    width: 12px; height: 12px; border-radius: 50%; 
    box-shadow: inset 0 1px 4px rgba(0,0,0,0.6), 0 1px 0 rgba(255,255,255,0.1);
}
.term-btn.close { background: #ff5f56; }
.term-btn.min { background: #ffbd2e; }
.term-btn.max { background: #27c93f; }

.term-title { 
    margin-left: auto; margin-right: auto; 
    font-family: 'Inter', sans-serif; 
    font-weight: 600;
    color: #94a3b8; 
    font-size: 0.85rem; 
    letter-spacing: 0.5px;
    padding-right: 48px; 
}
.terminal-body { padding: 25px; font-family: 'Courier New', Courier, monospace; }

/* Terminal Search Bar */
.terminal-search-row { display: flex; align-items: center; margin-bottom: 30px; font-size: 1.1rem; }
.prompt { color: #ff79c6; font-weight: bold; margin-right: 15px; white-space: nowrap; }
.terminal-input {
    background: transparent; border: none; color: #f8f8f2;
    font-family: 'Courier New', Courier, monospace; font-size: 1.1rem;
    flex-grow: 1; outline: none; caret-color: #50fa7b; width: 100%;
    font-size: 16px !important; /* CRITICAL: Stops iOS Zoom */
}
.terminal-input::placeholder { color: rgba(255,255,255,0.3); }
.terminal-random-btn {
    background: transparent;
    border: 1px solid rgba(80, 250, 123, 0.4); 
    color: #ff79c6;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    margin-left: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.terminal-random-btn:hover {
    background: rgba(80, 250, 123, 0.1);
    box-shadow: 0 0 15px rgba(80, 250, 123, 0.3);
    transform: translateY(-2px);
}
/* Terminal Stat Cards (Desktop: Horizontal Row) */
.stats-grid {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: 15px;
}

.stat-card {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 15px;
    display: flex;
    flex-direction: column; /* Keeps text centered inside the card */
    align-items: center;
    justify-content: center;
    text-align: center;
    flex: 1;
    min-width: 0; /* Prevents text blowout */
    cursor: pointer;
    transition: all 0.2s ease;
}

.stat-card:hover { transform: translateY(-3px); background: rgba(50, 50, 50, 0.6); }
.stat-card.active { border-color: #ff79c6; background: rgba(255, 121, 198, 0.05); box-shadow: 0 0 20px rgba(255, 121, 198, 0.25), inset 0 0 10px rgba(255, 121, 198, 0.1); }

.stat-card h3 { color: rgba(255, 255, 255, 0.7); font-size: 0.8rem; letter-spacing: 1px; margin: 0 0 10px 0; text-transform: uppercase; }
.stat-number { font-size: 2.2rem; font-weight: bold; margin: 0; }

.neon-pink { color: #ff79c6; text-shadow: 0 0 10px rgba(255, 121, 198, 0.4); }

/* --- POSTER CARDS --- */
.media-card { 
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); 
    cursor: pointer; 
    min-width: 0; /* CRITICAL: Stops text blowout */
}
.media-card:hover { transform: translateY(-8px) scale(1.02); }
.media-card:hover .poster-wrapper {
    box-shadow: 0 15px 30px rgba(255, 121, 198, 0.3), 0 5px 15px rgba(0,0,0,0.5);
    border-color: rgba(255, 121, 198, 0.5);
}
.poster-wrapper {
    aspect-ratio: 2/3; border-radius: 12px; overflow: hidden;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.1);
    transition: all 0.3s ease;
}
.poster-wrapper img { width: 100%; height: 100%; object-fit: cover; }

.media-info { 
    margin-top: 12px; 
    display: flex; 
    flex-direction: column; 
    min-width: 0; /* CRITICAL: Stops text blowout */
}
.media-title { font-weight: bold; font-size: 0.9em; color: #f8f8f2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-meta { font-size: 0.75em; color: rgba(255,255,255,0.5); }
.loading-state { grid-column: 1/-1; text-align: center; padding: 50px; color: #ff79c6; font-family: monospace; }


/* --- MEDIA MODAL CSS --- */
.modal-overlay {
    display: none; 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8); backdrop-filter: blur(10px);
    z-index: 1000; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.3s ease;
}
.modal-overlay.active { display: flex; opacity: 1; }

.modal-content {
    background: rgba(22, 22, 22, 0.95); border: 1px solid rgba(255, 121, 198, 0.3);
    border-radius: 15px; width: 90%; max-width: 800px; padding: 30px; position: relative;
    box-shadow: 0 20px 50px rgba(0,0,0,0.8), 0 0 20px rgba(189, 147, 249, 0.2);
    transform: translateY(20px); transition: transform 0.3s ease;
}
.modal-overlay.active .modal-content { transform: translateY(0); }

.close-btn {
    position: absolute; top: 15px; right: 20px; color: rgba(255,255,255,0.5); 
    font-size: 28px; font-weight: bold; cursor: pointer; transition: color 0.2s;
}
.close-btn:hover { color: #ff5555; }
.modal-layout { display: flex; gap: 30px; align-items: flex-start; }
.modal-poster-wrapper {
    flex-shrink: 0; width: 250px; border-radius: 10px; overflow: hidden;
    box-shadow: 0 10px 20px rgba(0,0,0,0.6); border: 1px solid rgba(255,255,255,0.1);
}
.modal-poster-wrapper img { 
    width: 100%; 
    display: block; 
    transition: opacity 0.3s ease; 
}
.modal-info { flex-grow: 1; }
.modal-info h2 { margin: 0 0 15px 0; font-size: 2rem; color: #f8f8f2; }
.modal-badges { display: flex; gap: 10px; margin-bottom: 20px; }
.badge { padding: 4px 10px; border-radius: 20px; font-size: 0.8rem; font-weight: bold; font-family: monospace; }
.badge.neon-blue { background: rgba(189, 147, 249, 0.2); color: #bd93f9; border: 1px solid #bd93f9; }
.badge.neon-pink { background: rgba(255, 121, 198, 0.2); color: #ff79c6; border: 1px solid #ff79c6; }
.modal-summary { line-height: 1.6; color: rgba(255,255,255,0.7); margin-bottom: 30px; font-size: 0.95rem; }

.plex-btn {
    display: inline-block; padding: 10px 20px; background: #e5a00d; 
    color: #111; font-weight: bold; text-decoration: none; border-radius: 8px; 
    transition: all 0.2s ease; text-transform: uppercase; letter-spacing: 1px; font-size: 0.9rem;
}
.plex-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 15px rgba(229, 160, 13, 0.4); }

@media (max-width: 768px) {
    .modal-layout { flex-direction: column; align-items: center; }
    .modal-poster-wrapper { width: 200px; margin-bottom: 20px; }
    .modal-info { text-align: center; }
    .modal-badges { justify-content: center; }
}

/* =========================================
   MOBILE TERMINAL FIX (Swipeable / Un-sticky)
   ========================================= */
/* 1. Disable the sticky trap */
    @media (max-width: 768px) {
    .terminal-window {
        position: relative !important; 
        top: 0 !important;
        margin-top: -15px !important; /* <--- Pulls the terminal up to match the binder */
        margin-bottom: 20px !important;
    }
    .terminal-body { padding: 15px; }
    .terminal-search-row { margin-bottom: 15px; }
    .prompt, .terminal-input { font-size: 0.9rem; }

    .stats-grid {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        padding-bottom: 5px;
        overflow-x: visible; /* Kills the horizontal scroll */
    }

    .stat-card {
        flex: none !important; /* Strips the desktop flex rules */
        min-width: 0; 
        padding: 12px 5px;
        margin: 0;
    }
    
    .stat-card h3 { font-size: 0.65rem; margin-bottom: 4px; letter-spacing: 0; }
    .stat-number { font-size: 1.4rem; }
}