/* CoolBrainrotGames Stylesheet - Ultra Widescreen Edition */
:root {
    --cmg-dark: #050b14;
    --cmg-card: #0c1524;
    --cmg-blue: #00d2ff;
    --cmg-purple: #9d50bb;
    --cmg-yellow: #f9d423;
    --cmg-green: #00ff87;
    --cmg-text: #e0e0e0;
}

body {
    background-color: var(--cmg-dark);
    color: var(--cmg-text);
    font-family: 'Comic Sans MS', 'Comic Sans', 'Outfit', sans-serif;
    margin: 0;
    overflow-x: hidden; /* Strict: NO horizontal scrollbar */
}

/* Nav */
.top-nav {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    gap: 15px; /* Added gap replacement */
    background: rgba(12, 21, 36, 0.8);
    backdrop-filter: blur(12px); /* Glassmorphism */
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 2px solid rgba(0, 210, 255, 0.4);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.logo {
    width: clamp(200px, 25vw, 380px);
    aspect-ratio: 8/1;
    height: auto;
    background: url('../assets/banner_logo_wide.png') no-repeat center;
    background-size: contain;
    text-indent: -9999px;
    margin-right: 20px;
    cursor: pointer;
    transition: transform 0.3s;
}

.logo:hover {
    transform: scale(1.05);
}

.nav-links { display: flex; gap: 10px; align-items: center; }
.nav-links a {
    text-decoration: none;
    color: var(--cmg-blue);
    font-size: 0.75rem;
    font-weight: 800;
    padding: 4px 10px;
    border: 1px solid rgba(0, 210, 255, 0.2);
    border-radius: 15px;
    transition: all 0.3s;
    background: rgba(0, 210, 255, 0.05);
}
.nav-links a:hover {
    background: rgba(0, 210, 255, 0.2);
    border-color: var(--cmg-blue);
    transform: translateY(-1px);
    box-shadow: 0 0 8px rgba(0, 210, 255, 0.3);
}

.search-bar { margin: 0; flex-grow: 1; min-width: 150px; }
.search-bar input {
    width: 100%;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 6px 15px;
    border-radius: 20px;
    font-size: 0.85rem;
    outline: none;
    transition: all 0.3s;
}
.search-bar input:focus {
    border-color: var(--cmg-blue);
    box-shadow: 0 0 10px rgba(0, 210, 255, 0.2);
    background: rgba(0, 0, 0, 0.6);
}

.auth-section { margin-left: auto; display: flex; gap: 15px; align-items: center; }
.login-btn, .logout-btn {
    background: transparent;
    border: 2px solid var(--cmg-blue);
    color: var(--cmg-blue);
    padding: 6px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 900;
    text-transform: uppercase;
    font-size: 0.8rem;
    transition: all 0.3s;
}
.login-btn:hover {
    background: var(--cmg-blue);
    color: var(--cmg-dark);
    box-shadow: 0 0 15px var(--cmg-blue);
}
.logout-btn { border-color: #ff4d4d; color: #ff4d4d; }
.logout-btn:hover { background: #ff4d4d; color: white; box-shadow: 0 0 15px #ff4d4d; }

/* Main Layout */
.main-container {
    width: 100%;
    margin: 0 auto;
    padding: 10px;
    transform-origin: top center; /* Critical for JS scaling */
}

/* Strict 5-Column Pro Layout - Unified & Compact */
.game-hero {
    display: grid;
    grid-template-columns: 
        minmax(140px, 200px)  /* Instructions */
        minmax(140px, 200px)  /* Rizz Clicks */
        minmax(300px, 2.5fr)  /* Game Viewport (Flexible middle) */
        minmax(140px, 200px)  /* Meme Upgrades */
        minmax(140px, 200px); /* Brainrot Items */
    gap: 12px;
    align-items: start;
}

/* Responsive: Hide instructions when screen is tight to keep shops visible */
@media (max-width: 1200px) {
    .game-hero {
        grid-template-columns: 
            0px                   /* Hide Instructions */
            minmax(140px, 1fr) 
            minmax(300px, 2.5fr) 
            minmax(140px, 1fr) 
            minmax(140px, 1fr);
    }
    .instructions-panel { display: none; }
}

.centered-leaderboard {
    width: 66%;
    margin: 30px auto 0 auto;
    border-color: var(--cmg-blue);
    box-shadow: 0 0 20px rgba(0, 210, 255, 0.1);
}

.centered-leaderboard .leaderboard-list {
    max-height: 250px; /* Reduced vertical size as requested */
}

/* Panel Containers */
.instructions-panel, .click-upgrades, .featured-upgrades, .brainrot-items, .leaderboard-panel {
    background: var(--cmg-card);
    border-radius: 16px;
    border: 2px solid #1a2a44;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.card-header {
    background: rgba(0,0,0,0.3);
    padding: 12px;
    font-weight: 900;
    text-transform: uppercase;
    font-size: 0.85rem;
    border-bottom: 3px solid var(--cmg-blue);
    text-align: center;
    letter-spacing: 1.5px;
}

/* Lists */
.upgrade-list {
    max-height: 850px; /* Increased to fit all items comfortably */
    overflow-y: auto;
    padding: 15px 15px 40px 15px; /* Balanced padding */
    scrollbar-width: none;
    -ms-overflow-style: none;  /* Hide scrollbar for IE/Edge */
}
.upgrade-list::-webkit-scrollbar {
    display: none; /* Hide scrollbar for Chrome/Safari */
}

.upgrade-card {
    display: flex;
    align-items: center;
    background: #16243d;
    padding: 10px;
    border-radius: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.upgrade-card:hover { transform: translateY(-3px) scale(1.02); border-color: var(--cmg-blue); box-shadow: 0 5px 15px rgba(0, 210, 255, 0.3); }

.upgrade-card img { width: 32px; height: 32px; margin-right: 10px; border-radius: 6px; }
.upgrade-info h3 { margin: 0; font-size: 0.75rem; font-weight: 800; }
.upgrade-info p { margin: 1px 0; font-size: 0.65rem; color: #aaa; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cost { font-weight: bold; color: var(--cmg-green); font-size: 0.75rem; }

.legendary-glow {
    border-color: var(--cmg-yellow) !important;
    box-shadow: 0 0 20px rgba(249, 212, 35, 0.5);
    animation: legendaryPulse 2s infinite;
}

@keyframes legendaryPulse {
    0% { box-shadow: 0 0 10px rgba(249, 212, 35, 0.4); }
    50% { box-shadow: 0 0 25px rgba(249, 212, 35, 0.8); }
    100% { box-shadow: 0 0 10px rgba(249, 212, 35, 0.4); }
}

.god-glow {
    border-color: var(--cmg-purple) !important;
    box-shadow: 0 0 30px rgba(157, 80, 187, 0.6);
    background: linear-gradient(145deg, rgba(5, 11, 20, 0.9), rgba(157, 80, 187, 0.1)) !important;
    animation: godPulse 1.5s infinite alternate;
}

@keyframes godPulse {
    0% { 
        box-shadow: 0 0 20px rgba(157, 80, 187, 0.4), 0 0 10px var(--cmg-blue); 
        transform: scale(1);
    }
    100% { 
        box-shadow: 0 0 40px rgba(157, 80, 187, 0.9), 0 0 20px var(--cmg-blue); 
        transform: scale(1.02);
    }
}

/* Game Viewport */
.game-viewport {
    flex-grow: 1;
    min-width: 280px;
    position: relative;
    /* No span - fits into 3rd column of 6-col grid */
}

#game-box {
    background: #000;
    border-radius: 20px;
    border: 5px solid var(--cmg-blue);
    position: relative;
    overflow: hidden;
    width: 100%;
    aspect-ratio: 16 / 9; /* Cinematic 16:9 Ratio */
    box-shadow: 0 0 50px rgba(0, 210, 255, 0.2);
}

#game-canvas {
    width: 100%; height: 100%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}

#summon-container { position: absolute; inset: 0; z-index: 5; pointer-events: none; }

.score-container h1 { 
    font-size: 2.8rem; 
    margin-bottom: 40px; 
    font-weight: 900;
    background: linear-gradient(to right, var(--cmg-blue), var(--cmg-green), var(--cmg-yellow), #ff00ff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 10px rgba(0, 210, 255, 0.2);
}

.meme-container button { background: none; border: none; cursor: pointer; transition: transform 0.1s; }
.meme-container img { 
    width: 500px; 
    border: 5px solid white; 
    border-radius: 20px; 
    box-shadow: 0 0 40px rgba(255,255,255,0.2);
    transition: transform 0.1s ease;
}

.meme-container button:active img {
    transform: scale(0.95);
}

.game-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    font-size: 0.8rem;
    font-weight: 800;
    color: #4a5568;
}

.game-meta { display: flex; gap: 15px; }
.game-meta .tag { color: var(--cmg-blue); opacity: 0.6; text-transform: uppercase; letter-spacing: 1px; }

/* Modals */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.9); display: flex; align-items: center; justify-content: center; z-index: 2000; }
.modal-content { background: var(--cmg-card); padding: 40px; border-radius: 20px; text-align: center; border: 4px solid var(--cmg-blue); width: 400px; }
.modal-content input { display: block; width: 100%; margin-bottom: 15px; padding: 12px; background: #16243d; border: 1px solid #333; color: white; border-radius: 8px; }
.modal-content button { background: var(--cmg-blue); border: none; padding: 12px 40px; font-weight: 900; cursor: pointer; border-radius: 8px; font-size: 1.1rem; }

/* Trending */
.trending-section {
    margin-top: 60px; /* Moved line up slightly for better visibility */
    padding: 20px 40px;
    border-top: 1px solid rgba(255, 215, 0, 0.2);
}
.trending-grid {
    display: flex;
    gap: 12px;
    justify-content: flex-start;
    margin-top: 15px;
}
.trend-card {
    width: 160px; /* Small and compact */
    background: #0d1b2a;
    border-radius: 6px;
    border: 1px solid #1a2a44;
    transition: all 0.3s;
    overflow: hidden;
    cursor: pointer;
}
.trend-card:hover { transform: scale(1.05); border-color: var(--cmg-blue); }
.trend-card img {
    width: 100%;
    height: 110px; /* Scaled down height */
    object-fit: cover;
    border-radius: 6px 6px 0 0;
}
.trend-info {
    padding: 8px;
}
.trend-info h3 { margin: 0; font-size: 0.75rem; color: var(--cmg-yellow); font-weight: 800; }
.trend-info p { margin: 1px 0 0 0; font-size: 0.6rem; color: #8892b0; }

/* Physics */
.bouncing-meme { 
    position: absolute; 
    width: 35px; /* Base size: Rizz Clicks (Small) */
    height: 35px; 
    pointer-events: none; 
    z-index: 10; 
    filter: drop-shadow(0 0 10px rgba(0, 210, 255, 0.4)); 
}

.meme-upgrade-medium {
    width: 70px; /* Double the size of Rizz Clicks */
    height: 70px;
}

.brainrot-item-large {
    width: 85px; /* Triple the size (Premium items) */
    height: 85px;
}

/* New: Cool Spawn Animation */
.spawn-anim {
    animation: spawnPop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes spawnPop {
    0% { transform: scale(0) rotate(-45deg); opacity: 0; filter: brightness(5) blur(10px); }
    70% { transform: scale(1.2) rotate(10deg); opacity: 1; filter: brightness(2) blur(0px); }
    100% { transform: scale(1) rotate(0deg); opacity: 1; filter: brightness(1) blur(0px); }
}

/* Leaderboard */
.leaderboard-item { display: flex; justify-content: space-between; padding: 15px; border-bottom: 1px solid #1a2a44; font-size: 1rem; font-weight: 600; }
.leaderboard-list {
    max-height: 850px;
    overflow-y: auto;
    padding-bottom: 40px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.leaderboard-list::-webkit-scrollbar {
    display: none;
}
.top-user { background: rgba(0, 210, 255, 0.15); color: var(--cmg-yellow); }

.floating-text {
    position: fixed; font-weight: 900; font-size: 1.5rem; pointer-events: none; animation: floatUp 1s forwards; z-index: 3000;
}

@keyframes floatUp {
    0% { transform: translateY(0) scale(1); opacity: 1; }
    100% { transform: translateY(-120px) scale(1.2); opacity: 0; }
}

/* --- Responsive Mobile Stacking --- */

/* 1. Prevent ANY image from overflowing its container */
img {
    max-width: 100%;
    height: auto;
    object-fit: contain;
}

/* Fix for mobile screens */
@media screen and (max-width: 768px) {
    /* Target the main body and layout wrapper to prevent black screen collapse */
    html, body {
        height: auto !important;
        min-height: 100%;
        width: 100%;
        overflow-x: hidden; /* Hard block on horizontal scrolling */
        position: relative;
        background-color: var(--cmg-dark);
    }

    /* Force the FX container to behave on mobile */
    #fx-container {
        width: 100vw !important;
        height: 100vh !important;
        position: fixed;
    }

    /* Fix the Top Nav from stretching the screen */
    .top-nav {
        flex-direction: column;
        padding: 15px 10px;
        gap: 15px;
        height: auto;
    }
    
    .logo {
        width: 80%;
        margin-right: 0;
    }

    .nav-links {
        display: flex;
        flex-wrap: wrap; /* This stops the links from stretching the screen */
        justify-content: center;
        gap: 8px;
    }

    .search-bar {
        width: 100%;
        margin-top: 5px;
    }

    .auth-section {
        width: 100%;
        justify-content: center;
    }

    .main-container {
        padding: 10px;
        box-sizing: border-box;
        width: 100%;
        overflow-x: hidden;
        transform: none !important; /* Force override of JS scaling */
        background-color: transparent;
    }

    .top-nav {
        flex-wrap: wrap;
        justify-content: center;
        padding: 5px;
        gap: 5px;
    }

    .logo {
        width: 160px;
        margin-right: 0;
        margin-bottom: 5px;
    }

    .nav-links {
        justify-content: center;
        width: 100%;
        margin-bottom: 5px;
        gap: 5px;
    }

    .search-bar { width: 100%; order: 3; margin: 5px 0; }
    .auth-section { margin-left: 0; width: 100%; justify-content: center; order: 4; }

    .game-hero {
        display: flex;
        flex-direction: column;
        align-items: center;
        width: 100%;
        gap: 15px;
    }

    /* Force the game window to stay visible */
    #game-box {
        width: 100%;
        max-width: 100%;
        min-height: 380px; 
        aspect-ratio: 16/9; /* Set back briefly and check */
        margin: 10px 0;
        border-width: 3px;
    }

    /* Ensure the brain image scales down so it doesn't push the window out */
    .meme-container img {
        width: 90%;
        max-width: 340px;
        height: auto;
    }

    .score-container h1 {
        font-size: 1.8rem;
        margin-bottom: 20px;
    }

    /* Ensure panels don't disappear */
    .click-upgrades, .featured-upgrades, .brainrot-items, .leaderboard-panel {
        width: 100%;
        min-width: 100%;
        margin-bottom: 20px;
        display: block !important; /* Ensure they are visible if hidden earlier */
    }

    .instructions-panel {
        display: none !important; /* Prioritize game on mobile */
    }

    /* Stack upgrades vertically for maximum mobile stability */
    .upgrade-list {
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 10px;
        max-height: none;
    }

    .upgrade-card {
        margin-bottom: 5px;
        flex-direction: row; 
        text-align: left;
        padding: 10px;
    }

    .upgrade-card img {
        width: 40px;
        height: 40px;
    }

    .centered-leaderboard {
        width: 95%;
        margin: 20px auto;
        display: block !important;
    }

    .leaderboard-item {
        padding: 10px;
        font-size: 0.9rem;
    }

    .leaderboard-item .user-name {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Fix Trending section to wrap correctly */
    .trending-grid {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 15px;
    }

    .trend-card {
        width: 45%; /* Two cards a row roughly */
        min-width: 140px;
    }

    /* Scaling fix for floating text on mobile */
    .floating-text {
        font-size: 1.1rem;
    }
}
