:root {
    --bg-dark: #050505;
    --glass: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --neon-cyan: #00f2ff;
    --neon-pink: #ff0055;
    --neon-yellow: #ffcc00;
}

* { box-sizing: border-box; } /* Fix padding calculation issues */

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-dark);
    color: #fff;
    /* FIX 1: Use Dynamic Height for Mobile Browsers */
    height: 100dvh; 
    width: 100vw;
    overflow: hidden; 
}

/* --- THE GRID SYSTEM --- */
.app-grid {
    display: grid;
    /* FIX 2: Ensure Grid fits the dynamic screen size exactly */
    height: 100dvh; 
    width: 100vw;
    grid-template-columns: 180px 1fr 180px;
    grid-template-rows: 100px 1fr;
    grid-template-areas: 
        "top-ad top-ad top-ad"
        "left-ad center right-ad";
}

/* --- DESKTOP AD ZONES --- */
.area-top-ad { grid-area: top-ad; background: rgba(0,0,0,0.8); border-bottom: 1px solid var(--glass-border); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.area-left-ad { grid-area: left-ad; background: rgba(0,0,0,0.2); border-right: 1px solid var(--glass-border); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.area-right-ad { grid-area: right-ad; background: rgba(0,0,0,0.2); border-left: 1px solid var(--glass-border); display: flex; align-items: center; justify-content: center; overflow: hidden; }

/* --- APP CENTER --- */
.area-center {
    grid-area: center;
    background: radial-gradient(circle at 50% 10%, #1a1a2e 0%, var(--bg-dark) 60%);
    overflow-y: auto; 
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    width: 100%;
}

/* --- MOBILE AD CONTROL --- */
.mobile-only-ad { display: none; }

/* --- MOBILE BREAKPOINT --- */
@media (max-width: 850px) {
    .app-grid {
        display: flex;
        flex-direction: column;
        height: 100dvh; /* Dynamic Height for Mobile */
        width: 100%;
    }

    .area-top-ad, .area-left-ad, .area-right-ad { display: none !important; }

    .mobile-only-ad {
        display: flex !important;
        justify-content: center;
        align-items: center;
        width: 100%;
        padding: 5px 0;
        background: rgba(0,0,0,0.5);
        border-bottom: 1px solid var(--glass-border);
        flex-shrink: 0; /* Prevent ad from squashing */
    }

    .area-center { flex: 1; width: 100%; height: 100%; }
    .menu-card { width: 90%; padding: 20px; max-width: none; }
    .glitch-text { font-size: 2.5rem; }
}

/* --- UI ELEMENTS --- */
#home-screen {
    /* REMOVED: flex: 1 and justify-content: center */
    /* ADDED: margin: auto to safely center content */
    margin: auto; 
    
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px; /* More breathing room at the top */
    gap: 30px;
    width: 100%; /* Ensure it doesn't collapse */
}
.glitch-text {
    font-size: 3.5rem;
    font-weight: 900;
    text-transform: uppercase;
    text-shadow: 4px 4px 0px var(--neon-pink), -4px -4px 0px var(--neon-cyan);
    margin: 0;
    
    /* ADDED: Line height to prevent clipping of the shadow */
    line-height: 1.2;
    padding: 10px; /* Extra safe space around the text */
    text-align: center;
}
.menu-card {
    background: var(--glass); backdrop-filter: blur(20px); border: 1px solid var(--glass-border);
    padding: 35px; border-radius: 24px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 20px;
}

button { border: none; padding: 18px; border-radius: 16px; font-weight: bold; cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 1rem; }
.btn-cyan { background: linear-gradient(135deg, #00f2ff, #00c6ff); color: #000; }
.btn-pink { background: linear-gradient(135deg, #ff0055, #ff0099); color: #fff; animation: pulse 3s infinite; }
.btn-yellow { background: linear-gradient(135deg, #ffcc00, #ffaa00); color: #000; }
.btn-ghost { background: transparent; border: 1px solid #444; color: #888; }
.btn-support { background: transparent; border: 1px solid var(--neon-pink); color: var(--neon-pink); margin-top: 10px; border-radius: 50px; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,0,85,0.4); } 70% { box-shadow: 0 0 0 10px rgba(255,0,85,0); } 100% { box-shadow: 0 0 0 0 rgba(255,0,85,0); } }

.group-section { background: rgba(0,0,0,0.3); padding: 20px; border-radius: 16px; display: flex; flex-direction: column; gap: 12px; border: 1px solid var(--glass-border); }
input { background: #0a0a0f; border: 1px solid #333; color: #fff; padding: 16px; border-radius: 12px; text-align: center; outline: none; font-size: 1rem; width: 100%; box-sizing: border-box; }

/* --- CHAT INTERFACE --- */
#chat-interface { flex: 1; display: none; flex-direction: column; height: 100%; overflow: hidden; }

header { padding: 15px 20px; background: rgba(0,0,0,0.8); border-bottom: 1px solid var(--glass-border); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
#chat-feed { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }

/* --- INPUT AREA FIX --- */
.input-area { 
    padding: 15px; 
    background: #000; 
    display: flex; 
    gap: 12px; 
    border-top: 1px solid var(--glass-border);
    flex-shrink: 0; /* Don't let it squash */
    
    /* CRITICAL FIXES FOR MOBILE */
    padding-bottom: max(15px, env(safe-area-inset-bottom)); /* Support iPhone Notch/Home Bar */
    margin-bottom: 0; /* Ensure no external margin pushes it down */
}

.message { padding: 12px 18px; border-radius: 18px; max-width: 80%; line-height: 1.5; font-size: 0.95rem; word-wrap: break-word; }
.message.me { align-self: flex-end; background: linear-gradient(135deg, #00b4db, #0083b0); color: #fff; border-bottom-right-radius: 4px; }
.message.them { align-self: flex-start; background: #222; border: 1px solid var(--glass-border); color: #eee; border-bottom-left-radius: 4px; }
.user-label { font-size: 0.75rem; font-weight: 700; display: block; margin-bottom: 4px; opacity: 0.8; }
.system-msg { align-self: center; color: #666; font-size: 0.8rem; background: rgba(255,255,255,0.05); padding: 6px 16px; border-radius: 20px; text-align: center; }

.legal-footer { margin-top: 15px; padding-top: 15px; border-top: 1px solid rgba(255,255,255,0.1); text-align: center; }
.legal-link { color: #555; font-size: 0.75rem; text-decoration: none; text-transform: uppercase; letter-spacing: 1px; }

.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.95); justify-content: center; align-items: center; z-index: 1000; }
.close { position: absolute; top: 20px; right: 25px; font-size: 2rem; cursor: pointer; color: #666; }