@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

/* === CSS Variables === */
:root {
    /* Modern Dark Theme */
    --bg-dark: #0a0a12;
    --bg-light: #151525;
    --card-bg: rgba(30, 30, 45, 0.6);
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-highlight: rgba(255, 255, 255, 0.15);
    
    /* Text Colors */
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    /* Accents */
    --primary: #6c5ce7;
    --primary-gradient: linear-gradient(135deg, #6c5ce7, #a29bfe);
    --secondary: #00d2ff;
    --secondary-gradient: linear-gradient(135deg, #00d2ff, #3a7bd5);
    --success: #00b894;
    --warning: #fdcb6e;
    --danger: #ff7675;
    
    /* Effects */
    --shadow-sm: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
    --glow-primary: 0 0 20px rgba(108, 92, 231, 0.4);
    --glow-secondary: 0 0 20px rgba(0, 210, 255, 0.3);
    
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;
}

/* === Reset & Base === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(108, 92, 231, 0.08), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(0, 210, 255, 0.08), transparent 25%);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

a {
    text-decoration: none;
    color: inherit;
    transition: color 0.2s;
}

button {
    font-family: inherit;
    border: none;
    background: none;
}

/* === Layout & Container === */
.container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 24px;
}

/* === Header === */
header {
    background: rgba(10, 10, 18, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.5rem;
    margin-right: 20px;
}

header h1 a {
    display: flex;
    align-items: center;
    gap: 10px;
}

#site-title {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-stats {
    font-size: 0.9rem;
    color: var(--text-secondary);
    background: var(--glass-bg);
    padding: 6px 16px;
    border-radius: var(--radius-full);
    border: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 8px;
}

#game-count {
    color: var(--secondary);
    font-weight: 700;
}

/* === Language Switcher === */
.lang-switch {
    display: flex;
    background: var(--glass-bg);
    padding: 3px;
    border-radius: var(--radius-full);
    border: 1px solid var(--glass-border);
}

.lang-btn {
    padding: 6px 14px;
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.lang-btn:hover {
    color: var(--text-primary);
}

.lang-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 10px rgba(108, 92, 231, 0.3);
}

/* === Filters === */
.filters-wrapper {
    position: sticky;
    top: 73px; /* header height + offset */
    z-index: 90;
    background: rgba(10, 10, 18, 0.9);
    backdrop-filter: blur(10px);
    margin: 0 -24px 30px -24px; /* Extend to edges */
    padding: 15px 24px;
    border-bottom: 1px solid var(--glass-border);
}

.filters {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
}

.filters::-webkit-scrollbar {
    display: none;
}

.filter-btn {
    padding: 10px 20px;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-btn:hover {
    border-color: rgba(255,255,255,0.2);
    color: var(--text-primary);
    background: rgba(255,255,255,0.05);
}

.filter-btn.active {
    background: var(--text-primary);
    color: var(--bg-dark);
    border-color: var(--text-primary);
    font-weight: 700;
}

/* === Game Stats === */
.game-stats {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 20px;
    padding-left: 4px;
}

#showing-count {
    color: var(--text-primary);
    font-weight: 600;
}

/* === Game Grid === */
.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 24px;
}

/* === Game Card === */
.game-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    overflow: hidden;
    position: relative;
    border: 1px solid var(--glass-border);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.game-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: var(--shadow-lg), var(--glow-primary);
    border-color: rgba(108, 92, 231, 0.3);
    z-index: 10;
}

.game-thumb-container {
    position: relative;
    aspect-ratio: 16/11;
    overflow: hidden;
    background: #1a1a2e;
}

.game-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s ease;
}

.game-card:hover .game-thumb {
    transform: scale(1.1);
}

.game-overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 10, 18, 0.4);
    opacity: 0;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.game-card:hover .game-overlay {
    opacity: 1;
}

.play-icon {
    width: 50px;
    height: 50px;
    background: var(--text-primary);
    color: var(--bg-dark);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transform: scale(0.5);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 0 20px rgba(255,255,255,0.3);
}

.game-card:hover .play-icon {
    transform: scale(1);
}

.game-info {
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    background: linear-gradient(to bottom, rgba(30, 30, 45, 0), rgba(30, 30, 45, 0.8));
}

.game-tags {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.game-tag {
    font-size: 0.7rem;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: rgba(108, 92, 231, 0.15);
    color: var(--primary);
}

/* Category Colors */
.cat-puzzle { background: rgba(0, 184, 148, 0.15); color: #00b894; }
.cat-action { background: rgba(255, 118, 117, 0.15); color: #ff7675; }
.cat-racing { background: rgba(253, 203, 110, 0.15); color: #fdcb6e; }
.cat-shooting { background: rgba(162, 155, 254, 0.15); color: #a29bfe; }
.cat-arcade { background: rgba(116, 185, 255, 0.15); color: #74b9ff; }
.cat-adventure { background: rgba(85, 239, 196, 0.15); color: #55efc4; }
.cat-casual { background: rgba(250, 177, 160, 0.15); color: #fab1a0; }
.cat-sports { background: rgba(255, 159, 67, 0.15); color: #ff9f43; }

.game-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.game-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 8px;
}

/* === Load More === */
.load-more-container {
    text-align: center;
    margin: 60px 0;
}

.load-more-btn {
    padding: 14px 40px;
    background: transparent;
    border: 2px solid var(--glass-border);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.load-more-btn:hover {
    background: var(--text-primary);
    color: var(--bg-dark);
    border-color: var(--text-primary);
    box-shadow: 0 0 20px rgba(255,255,255,0.2);
}

/* === Ads === */
.ad-space {
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    margin: 30px auto;
    overflow: hidden;
}

.ad-banner {
    max-width: 728px;
    height: 90px;
}

.ad-sidebar {
    width: 100%;
    height: 250px;
}

/* === Footer === */
footer {
    border-top: 1px solid var(--glass-border);
    background: rgba(10, 10, 18, 0.5);
    padding: 60px 20px;
    text-align: center;
    margin-top: 60px;
}

footer p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 10px;
}

footer a {
    color: var(--text-secondary);
    margin: 0 10px;
    position: relative;
}

footer a:hover {
    color: var(--primary);
}

/* === Play Page === */
.game-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 30px;
    padding: 30px 0;
    max-width: 1440px;
    margin: 0 auto;
}

.game-main {
    background: var(--bg-light);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    position: relative;
    display: flex;
    flex-direction: column;
}

.game-controls {
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.3);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
}

.back-btn:hover {
    color: var(--text-primary);
}

.game-title-area {
    text-align: center;
    flex: 1;
}

#game-title-display {
    font-weight: 700;
    font-size: 1.1rem;
    display: block;
}

#game-controls-display {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.fullscreen-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 8px 16px;
    border-radius: var(--radius-full);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    font-size: 0.85rem;
}

.fullscreen-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: var(--glow-primary);
}

.game-frame {
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    border: none;
    display: block;
}

/* Click to play overlay */
.click-to-play {
    position: absolute;
    inset: 0;
    top: 60px; /* Approx header height */
    background: radial-gradient(circle at center, #1e1e2f 0%, #0a0a12 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
    cursor: pointer;
    transition: opacity 0.5s;
}

.click-to-play.hidden {
    opacity: 0;
    pointer-events: none;
}

.play-button-large {
    width: 80px;
    height: 80px;
    background: var(--primary-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: white;
    box-shadow: 0 0 0 0 rgba(108, 92, 231, 0.7);
    animation: pulse-purple 2s infinite;
    margin-bottom: 20px;
    transition: transform 0.3s;
}

.click-to-play:hover .play-button-large {
    transform: scale(1.1);
}

@keyframes pulse-purple {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(108, 92, 231, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 20px rgba(108, 92, 231, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(108, 92, 231, 0); }
}

.click-content p {
    font-size: 1.2rem;
    color: var(--text-secondary);
    letter-spacing: 1px;
}

/* Sidebar */
.game-sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.info-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 24px;
    border: 1px solid var(--glass-border);
}

.info-card h3 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.info-card h3::before {
    content: '';
    display: block;
    width: 4px;
    height: 18px;
    background: var(--primary);
    border-radius: 2px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--glass-border);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label { color: var(--text-muted); font-size: 0.9rem; }
.info-value { color: var(--text-primary); font-size: 0.9rem; text-align: right; }

.tips-text {
    white-space: pre-line;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
}

.source-link {
    display: inline-block;
    margin-top: 15px;
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 500;
}

.source-link:hover { text-decoration: underline; }

.more-games-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.more-game-item {
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
    aspect-ratio: 4/3;
    background: #000;
    display: block;
}

.more-game-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
    opacity: 0.8;
}

.more-game-item:hover img {
    transform: scale(1.1);
    opacity: 1;
}

/* Fullscreen Container (Real) */
.fullscreen-container {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #000;
}

.fullscreen-container.active {
    display: block;
}

.fullscreen-container iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.fullscreen-exit-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-full);
    color: white;
    font-size: 14px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    display: none;
}

.fullscreen-container.active .fullscreen-exit-btn {
    display: block;
}

.fullscreen-exit-btn:hover {
    background: var(--danger);
    border-color: var(--danger);
}

/* === Mobile Optimization === */
@media (max-width: 1024px) {
    .game-layout {
        grid-template-columns: 1fr;
        padding: 20px 24px;
    }
    
    .game-sidebar {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }

    .game-sidebar .ad-space {
        grid-column: 1 / -1;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 16px;
    }

    header {
        padding: 12px 16px;
    }

    header h1 {
        font-size: 1.2rem;
    }

    .header-stats {
        display: none;
    }

    .filters-wrapper {
        margin: 0 -16px 20px -16px;
        padding: 12px 16px;
        top: 61px;
    }

    .game-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .game-card {
        border-radius: 10px;
    }
    
    .game-thumb-container {
        aspect-ratio: 16/10; /* Slightly reduced height */
    }
    
    .game-info {
        padding: 10px;
    }

    .game-sidebar {
        display: flex;
        flex-direction: column;
        width: 100%;
    }

    .ad-sidebar {
        height: 100px; /* Smaller ad space for mobile */
        margin-bottom: 10px;
    }

    .info-card {
        width: 100%;
    }

    .game-layout {
        padding: 16px;
    }
    
    .fullscreen-exit-btn {
        top: auto;
        bottom: 30px;
        right: 50%;
        transform: translateX(50%);
        padding: 12px 30px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 12px;
    }

    .filters-wrapper {
        margin: 0 -12px 20px -12px;
        padding: 10px 12px;
    }

    /* Switch to 3 columns for a more "App Store" icon feel */
    .game-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px 8px;
    }
    
    /* Minimalist Card Style for Mobile */
    .game-card {
        background: transparent;
        border: none;
        box-shadow: none;
        border-radius: 0;
    }

    .game-card:hover {
        transform: none;
    }

    .game-thumb-container {
        aspect-ratio: 1; /* Square icons */
        border-radius: 16px; /* Soft rounded corners like iOS icons */
        box-shadow: 0 4px 10px rgba(0,0,0,0.3);
        margin-bottom: 8px;
        border: 1px solid var(--glass-border);
    }
    
    .game-info {
        padding: 0;
        background: none;
        align-items: center;
    }
    
    .game-tags {
        display: none; /* Cleaner look */
    }
    
    .game-title {
        font-size: 0.75rem;
        margin-bottom: 0;
        text-align: center;
        color: var(--text-secondary);
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        width: 100%;
    }

    .game-desc {
        display: none;
    }
    
    /* Hide play icon overlay on mobile for cleaner view */
    .game-overlay {
        display: none;
    }

    /* Refined Header & Filters for Mobile */
    header {
        padding: 10px 16px;
        background: rgba(10, 10, 18, 0.95);
    }

    header h1 {
        font-size: 1.2rem;
    }

    .filter-btn {
        padding: 6px 14px;
        font-size: 0.75rem;
        border: none;
        background: rgba(255, 255, 255, 0.08);
        border-radius: 20px;
    }

    .filter-btn.active {
        background: var(--text-primary);
        color: var(--bg-dark);
        box-shadow: 0 2px 10px rgba(255,255,255,0.2);
    }
}

/* === Advanced Fullscreen Logic (No Reload) === */
.game-main:fullscreen,
.game-main.fixed-fullscreen {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999;
    border-radius: 0 !important;
    border: none !important;
    margin: 0 !important;
    background: #000;
    /* Use Grid + Padding to ensure safe area (prevents corner clipping) */
    display: grid !important;
    place-items: center;
    box-sizing: border-box;
    padding: max(2px, env(safe-area-inset-top)) max(2px, env(safe-area-inset-right)) max(2px, env(safe-area-inset-bottom)) max(2px, env(safe-area-inset-left));
}

/* Hide header controls in fullscreen */
.game-main:fullscreen .game-controls,
.game-main.fixed-fullscreen .game-controls {
    display: none !important;
}

/* Ensure iframe takes full space (respecting padding) */
.game-main:fullscreen .game-frame,
.game-main.fixed-fullscreen .game-frame {
    position: static !important; /* Let grid handle sizing */
    width: 100% !important;
    height: 100% !important;
    border-radius: 2px !important; /* Soft edge */
    z-index: 1;
}

/* Exit Button Styling - Context aware */
.game-main .fullscreen-exit-btn {
    display: none; /* Hidden by default in normal mode */
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 10005;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
}

.game-main:fullscreen .fullscreen-exit-btn,
.game-main.fixed-fullscreen .fullscreen-exit-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

/* Mobile optimizations for fullscreen button */
@media (max-width: 768px) {
    .game-main .fullscreen-exit-btn {
        /* Move to TOP CENTER to avoid corner UI conflicts */
        top: max(0px, env(safe-area-inset-top)); /* Stick to top edge */
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        
        /* Design: Subtle Glass Pill */
        width: 60px;
        height: 24px;
        border-radius: 0 0 12px 12px; /* Rounded bottom corners */
        padding: 0;
        font-size: 0;
        
        /* Very subtle visual */
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-top: none;
        backdrop-filter: blur(2px);
        opacity: 0.5;
        transition: all 0.3s;
        z-index: 10005;
    }

    /* Make it more visible when touched/active */
    .game-main .fullscreen-exit-btn:active,
    .game-main .fullscreen-exit-btn:hover {
        opacity: 1;
        height: 34px; /* Expands when interacting */
        background: rgba(220, 50, 50, 0.8);
    }

    .game-main .fullscreen-exit-btn::before {
        content: '✕';
        font-size: 12px;
        color: rgba(255, 255, 255, 0.8);
        font-weight: bold;
    }
}

/* Hide the old container if it still exists */
#fullscreen-container {
    display: none !important;
}
