/* Reset and base styles - Chromebook optimized */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Enable hardware acceleration for better performance - Space Theme */
body {
    font-family: 'Roboto', sans-serif;
    background: radial-gradient(ellipse at center, #1a1a2e 0%, #16213e 35%, #0f0f23 100%);
    background-attachment: fixed;
    min-height: 100vh;
    color: #e8e8ff;
    overflow-x: hidden;
    /* Chromebook optimizations */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transform: translateZ(0); /* Force hardware acceleration */
    will-change: scroll-position;
    /* Space atmosphere */
    position: relative;
}

/* Add subtle stars background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        radial-gradient(2px 2px at 20px 30px, #ffffff20, transparent),
        radial-gradient(2px 2px at 40px 70px, #ffffff15, transparent),
        radial-gradient(1px 1px at 90px 40px, #ffffff25, transparent),
        radial-gradient(1px 1px at 130px 80px, #ffffff20, transparent),
        radial-gradient(2px 2px at 160px 30px, #ffffff15, transparent);
    background-repeat: repeat;
    background-size: 200px 100px;
    pointer-events: none;
    z-index: -1;
    opacity: 0.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    position: relative;
    z-index: 1;
}

/* Hero Section */
.hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 60px 40px;
    background: linear-gradient(135deg, rgba(22, 33, 62, 0.3), rgba(15, 15, 35, 0.4));
    border-radius: 20px;
    margin-bottom: 40px;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(138, 119, 255, 0.2);
    box-shadow: 0 8px 32px rgba(138, 119, 255, 0.1);
    /* Chromebook optimizations */
    transform: translateZ(0);
}

.hero-content {
    text-align: center;
    flex: 1;
}

.hero-account {
    position: absolute;
    top: 20px;
    right: 20px;
}

.account-button {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(138, 119, 255, 0.1);
    border: 1px solid rgba(138, 119, 255, 0.2);
    border-radius: 20px;
    padding: 10px 16px;
    color: #e8e8ff;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Roboto', sans-serif;
    font-size: 0.9rem;
    transform: translateZ(0);
}

.account-button:hover {
    background: rgba(138, 119, 255, 0.2);
    border-color: rgba(138, 119, 255, 0.3);
    transform: translateY(-1px) translateZ(0);
}

.account-icon {
    font-size: 1.2rem;
}

.account-name {
    font-weight: 500;
}

.logo {
    font-family: 'Orbitron', monospace;
    font-size: 4rem;
    font-weight: 900;
    background: linear-gradient(45deg, #8a77ff, #4c9aff, #00d4ff, #7c4dff);
    background-size: 400% 400%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: galaxyShift 4s ease-in-out infinite;
    margin-bottom: 20px;
    text-shadow: 0 0 40px rgba(138, 119, 255, 0.4);
    filter: drop-shadow(0 0 20px rgba(76, 154, 255, 0.3));
}

.tagline {
    font-size: 1.2rem;
    font-weight: 300;
    opacity: 0.8;
    letter-spacing: 1px;
    color: #b8b8ff;
}

/* Space-themed animation for logo */
@keyframes galaxyShift {
    0%, 100% { background-position: 0% 50%; }
    25% { background-position: 100% 0%; }
    50% { background-position: 100% 100%; }
    75% { background-position: 0% 100%; }
}

/* Reduce animations on low-end devices */
@media (prefers-reduced-motion: reduce) {
    .logo {
        animation: none;
        background: linear-gradient(45deg, #8a77ff, #4c9aff);
        -webkit-background-clip: text;
        background-clip: text;
        -webkit-text-fill-color: transparent;
    }
}

/* Main Content */
.main-content {
    display: grid;
    gap: 40px;
}

.section-title {
    font-family: 'Orbitron', monospace;
    font-size: 2.5rem;
    text-align: center;
    margin-bottom: 30px;
    color: #e8e8ff;
    text-shadow: 0 0 25px rgba(138, 119, 255, 0.5);
    background: linear-gradient(45deg, #8a77ff, #4c9aff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Games Grid */
.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 30px;
    padding: 20px 0;
}

.game-card {
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.4), rgba(22, 33, 62, 0.3));
    border-radius: 15px;
    padding: 0;
    text-align: center;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(138, 119, 255, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    /* Chromebook optimizations */
    transform: translateZ(0);
    will-change: transform;
    box-shadow: 0 4px 20px rgba(15, 15, 35, 0.3);
    display: flex;
    flex-direction: column;
    min-height: 400px;
}

/* Space-themed hover effects for better Chromebook performance */
.game-card:hover {
    transform: translateY(-5px) translateZ(0);
    box-shadow: 0 15px 35px rgba(138, 119, 255, 0.2), 0 5px 15px rgba(76, 154, 255, 0.1);
    border-color: rgba(138, 119, 255, 0.3);
}

/* Space-themed shimmer effect for performance */
@media (hover: hover) and (pointer: fine) {
    .game-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg, transparent, rgba(138, 119, 255, 0.1), rgba(76, 154, 255, 0.05), transparent);
        transition: left 0.3s ease;
        pointer-events: none;
    }

    .game-card:hover::before {
        left: 100%;
    }
}

/* Game cover image */
.game-cover {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 15px 15px 0 0;
    display: block;
}

/* CSS-generated cover when no image */
.game-icon {
    width: 100%;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    background: linear-gradient(135deg, #8a77ff, #4c9aff);
    border-radius: 15px 15px 0 0;
    margin: 0;
    position: relative;
    overflow: hidden;
}

/* Add some visual flair to the icon covers */
.game-icon::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
    animation: rotate 20s linear infinite;
}

@keyframes rotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.fallback-icon {
    margin: 60px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.fallback-emoji {
    font-size: 4rem;
}

.fallback-title {
    font-family: 'Orbitron', monospace;
    font-size: 1.5rem;
    color: #e8e8ff;
    text-shadow: 0 0 10px rgba(138, 119, 255, 0.3);
    text-align: center;
}

/* Game info section */
.game-info {
    padding: 20px 30px 30px 30px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.game-title {
    font-family: 'Orbitron', monospace;
    font-size: 1.5rem;
    margin-bottom: 15px;
    color: #e8e8ff;
    text-shadow: 0 0 10px rgba(138, 119, 255, 0.3);
}

.game-description {
    font-size: 0.9rem;
    opacity: 0.7;
    line-height: 1.6;
    margin-bottom: 20px;
    color: #b8b8ff;
    flex: 1;
}

.play-button {
    background: linear-gradient(45deg, #8a77ff, #4c9aff);
    border: none;
    padding: 12px 30px;
    border-radius: 25px;
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    text-decoration: none;
    display: inline-block;
    font-family: 'Roboto', sans-serif;
    /* Chromebook optimizations */
    transform: translateZ(0);
    will-change: transform;
    box-shadow: 0 4px 15px rgba(138, 119, 255, 0.3);
    border: 1px solid rgba(138, 119, 255, 0.2);
}

.play-button:hover {
    transform: scale(1.03) translateZ(0);
    box-shadow: 0 8px 25px rgba(138, 119, 255, 0.4), 0 4px 10px rgba(76, 154, 255, 0.2);
    background: linear-gradient(45deg, #9d8aff, #5fa5ff);
}

.play-button:active {
    transform: scale(0.98) translateZ(0);
    transition: transform 0.1s ease;
}

/* Stats Section */
.stats-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 30px;
    margin: 40px 0;
}

.stat-card {
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.3), rgba(22, 33, 62, 0.2));
    border-radius: 15px;
    padding: 30px;
    text-align: center;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(138, 119, 255, 0.15);
    /* Chromebook optimizations */
    transform: translateZ(0);
    box-shadow: 0 4px 20px rgba(15, 15, 35, 0.2);
}

.stat-number {
    font-family: 'Orbitron', monospace;
    font-size: 3rem;
    font-weight: 700;
    color: #8a77ff;
    margin-bottom: 10px;
    text-shadow: 0 0 15px rgba(138, 119, 255, 0.4);
}

.stat-label {
    font-size: 1rem;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #b8b8ff;
}

/* Footer */
.footer {
    text-align: center;
    padding: 40px 0;
    margin-top: 60px;
    border-top: 1px solid rgba(138, 119, 255, 0.1);
    opacity: 0.6;
    color: #b8b8ff;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 15, 35, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(4px);
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(138, 119, 255, 0.2);
    border-top: 4px solid #8a77ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
    box-shadow: 0 0 20px rgba(138, 119, 255, 0.3);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* No Games Message */
.no-games {
    text-align: center;
    padding: 60px 20px;
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.4), rgba(22, 33, 62, 0.3));
    border-radius: 15px;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(138, 119, 255, 0.15);
    /* Chromebook optimizations */
    transform: translateZ(0);
    box-shadow: 0 4px 20px rgba(15, 15, 35, 0.3);
}

.no-games h3 {
    font-family: 'Orbitron', monospace;
    font-size: 1.5rem;
    margin-bottom: 15px;
    color: #8a77ff;
    text-shadow: 0 0 15px rgba(138, 119, 255, 0.4);
}

.no-games p {
    opacity: 0.7;
    line-height: 1.6;
    color: #b8b8ff;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .logo {
        font-size: 2.5rem;
    }
    
    .section-title {
        font-size: 2rem;
    }
    
    .games-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .game-card {
        padding: 20px;
    }
    
    .stats-section {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

@media (max-width: 480px) {
    .hero {
        padding: 40px 0;
    }
    
    .logo {
        font-size: 2rem;
    }
    
    .tagline {
        font-size: 1rem;
    }
    
    .section-title {
        font-size: 1.5rem;
    }
}

/* Chromebook-specific optimizations */
@media screen and (max-width: 1366px) and (max-height: 768px) {
    /* Optimize for typical Chromebook screen sizes */
    .container {
        padding: 15px;
    }
    
    .hero {
        padding: 40px 0;
        margin-bottom: 30px;
    }
    
    .logo {
        font-size: 3rem;
    }
    
    .games-grid {
        gap: 20px;
    }
    
    .game-card {
        padding: 20px;
    }
}

/* Performance optimizations for low-end devices */
@media (max-resolution: 150dpi) {
    /* Reduce visual complexity on low-DPI screens (typical Chromebooks) */
    .game-card, .stat-card, .hero, .no-games {
        backdrop-filter: blur(4px); /* Further reduced blur */
    }
    
    .logo {
        animation-duration: 4s; /* Slower animation for smoother performance */
    }
}

/* Touch-friendly optimizations */
@media (pointer: coarse) {
    .game-card {
        padding: 25px;
        min-height: 200px; /* Ensure touch targets are large enough */
    }
    
    .play-button {
        padding: 15px 35px;
        font-size: 1.1rem;
    }
    
    .color-button {
        min-width: 60px;
        min-height: 60px;
    }
}

/* Reduce motion for better performance and accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .loading-spinner {
        animation: none;
        border: 4px solid #8a77ff;
    }
    
    .game-icon::before {
        animation: none;
    }
}

/* Low-end device optimizations */
@supports not (backdrop-filter: blur(1px)) {
    /* Fallback for devices that don't support backdrop-filter */
    .hero, .game-card, .stat-card, .no-games {
        backdrop-filter: none;
        background: rgba(255, 255, 255, 0.15);
    }
}

/* Memory and CPU optimizations */
.games-grid {
    /* Use CSS Grid more efficiently */
    contain: layout style;
}

.game-card {
    /* Optimize repaints and reflows */
    contain: layout style paint;
}

/* Clicked state for better performance than inline styles */
.game-card.clicked {
    transform: scale(0.96) translateZ(0);
    transition: transform 0.1s ease;
}

/* Account Panel */
.account-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 15, 35, 0.9);
    backdrop-filter: blur(10px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.account-panel.active {
    opacity: 1;
    visibility: visible;
}

.account-panel-content {
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.9), rgba(22, 33, 62, 0.9));
    border: 1px solid rgba(138, 119, 255, 0.3);
    border-radius: 20px;
    padding: 0;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    backdrop-filter: blur(15px);
    box-shadow: 0 20px 60px rgba(138, 119, 255, 0.2);
}

.account-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 25px 30px;
    border-bottom: 1px solid rgba(138, 119, 255, 0.2);
    background: rgba(138, 119, 255, 0.1);
}

.account-header h3 {
    font-family: 'Orbitron', monospace;
    color: #8a77ff;
    margin: 0;
    text-shadow: 0 0 10px rgba(138, 119, 255, 0.3);
}

.close-btn {
    background: none;
    border: none;
    color: #8a77ff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: rgba(138, 119, 255, 0.2);
}

.account-body {
    padding: 30px;
    overflow-y: auto;
    max-height: 60vh;
}

.account-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-label {
    color: #e8e8ff;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-input {
    background: rgba(138, 119, 255, 0.1);
    border: 1px solid rgba(138, 119, 255, 0.2);
    border-radius: 10px;
    padding: 12px 15px;
    color: #e8e8ff;
    font-family: 'Roboto', sans-serif;
    font-size: 1rem;
}

.form-input::placeholder {
    color: #b8b8ff;
    opacity: 0.7;
}

.form-input:focus {
    outline: none;
    border-color: rgba(138, 119, 255, 0.4);
    box-shadow: 0 0 15px rgba(138, 119, 255, 0.2);
}

.account-actions {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.account-btn {
    background: linear-gradient(45deg, #8a77ff, #4c9aff);
    border: none;
    padding: 12px 20px;
    border-radius: 20px;
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Roboto', sans-serif;
    font-size: 0.9rem;
    transform: translateZ(0);
    flex: 1;
    min-width: 120px;
}

.account-btn:hover {
    transform: scale(1.02) translateZ(0);
    box-shadow: 0 6px 20px rgba(138, 119, 255, 0.4);
}

.account-btn.secondary {
    background: rgba(138, 119, 255, 0.2);
    border: 1px solid rgba(138, 119, 255, 0.3);
}

.account-btn.secondary:hover {
    background: rgba(138, 119, 255, 0.3);
}

.account-info {
    background: rgba(138, 119, 255, 0.1);
    border: 1px solid rgba(138, 119, 255, 0.2);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
}

.username-display {
    font-family: 'Orbitron', monospace;
    font-size: 1.2rem;
    color: #8a77ff;
    margin-bottom: 10px;
}

.save-stats {
    color: #b8b8ff;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Game Overlay for Inline Games */
.game-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 15, 35, 0.95);
    backdrop-filter: blur(10px);
    z-index: 10001;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.game-overlay.active {
    opacity: 1;
    visibility: visible;
}

.game-overlay-content {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: linear-gradient(135deg, rgba(26, 26, 46, 0.9), rgba(22, 33, 62, 0.9));
    border: 1px solid rgba(138, 119, 255, 0.3);
    backdrop-filter: blur(15px);
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    background: rgba(138, 119, 255, 0.1);
    border-bottom: 1px solid rgba(138, 119, 255, 0.2);
    flex-shrink: 0;
}

.back-to-hub-btn {
    background: linear-gradient(45deg, #8a77ff, #4c9aff);
    border: none;
    padding: 10px 16px;
    border-radius: 20px;
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Roboto', sans-serif;
    font-size: 0.9rem;
    transform: translateZ(0);
}

.back-to-hub-btn:hover {
    transform: scale(1.02) translateZ(0);
    box-shadow: 0 6px 20px rgba(138, 119, 255, 0.4);
}

#gameOverlayTitle {
    font-family: 'Orbitron', monospace;
    color: #8a77ff;
    margin: 0;
    text-shadow: 0 0 10px rgba(138, 119, 255, 0.3);
    font-size: 1.5rem;
}

.game-overlay-controls {
    display: flex;
    gap: 10px;
}

.game-overlay-btn {
    background: rgba(138, 119, 255, 0.2);
    border: 1px solid rgba(138, 119, 255, 0.3);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    color: #8a77ff;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transform: translateZ(0);
}

.game-overlay-btn:hover {
    background: rgba(138, 119, 255, 0.3);
    transform: scale(1.05) translateZ(0);
}

.game-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#gameFrame {
    width: 100%;
    height: 100%;
    border: none;
    background: #000;
    /* Ensure proper scaling */
    transform-origin: top left;
    /* Smooth loading */
    opacity: 0;
    transition: opacity 0.3s ease;
}

#gameFrame.loaded {
    opacity: 1;
}

/* Fullscreen mode */
.game-overlay.fullscreen .game-overlay-content {
    border: none;
    border-radius: 0;
}

.game-overlay.fullscreen .game-header {
    padding: 10px 20px;
}

/* Mobile optimizations for game overlay */
@media (max-width: 768px) {
    .game-header {
        padding: 10px 15px;
    }
    
    #gameOverlayTitle {
        font-size: 1.2rem;
    }
    
    .back-to-hub-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    
    .game-overlay-btn {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
    
    /* Ensure iframe scales properly on mobile */
    #gameFrame {
        min-height: calc(100vh - 60px);
    }
}

/* Ensure games scale properly within iframe */
#gameFrame {
    /* Prevent scrollbars */
    overflow: hidden;
    /* Ensure content fits */
    box-sizing: border-box;
}

@media (max-width: 480px) {
    .game-header {
        padding: 8px 12px;
    }
    
    #gameOverlayTitle {
        font-size: 1rem;
    }
    
    .back-to-hub-btn {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
}