* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #10b981;
    --accent-color: #f59e0b;
    --danger-color: #ef4444;
    --background: #0f0f23;
    --surface: #1a1b2e;
    --surface-light: #2d2e44;
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --border: #374151;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --game-card-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 15px;
    min-height: 100vh;
}

/* Header */
.header {
    background: var(--surface);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.logo h1 {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: clamp(1.5rem, 4vw, 2rem);
    margin-bottom: 5px;
}

.logo span {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.nav {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.nav-link {
    padding: 10px 15px;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 8px;
    transition: all 0.3s ease;
    border: 1px solid transparent;
    font-size: 0.9rem;
}

.nav-link:hover,
.nav-link.active {
    color: var(--primary-color);
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

/* Quick Stats */
.quick-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    padding: 15px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    text-align: center;
    border: 1px solid var(--border);
}

.stat-label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: bold;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Main Content */
.main-content {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
    min-height: 500px;
}

.section {
    display: none;
    padding: 20px;
    min-height: 500px;
}

.section.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.section-header h2 {
    color: var(--text-primary);
    font-size: 1.3rem;
}

.search-box input {
    padding: 10px 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-light);
    color: var(--text-primary);
    font-size: 0.9rem;
    width: 100%;
    max-width: 300px;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Games Grid */
.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
}

.game-card {
    background: var(--surface-light);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid transparent;
    position: relative;
    overflow: hidden;
}

.game-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--game-card-gradient);
}

.game-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary-color);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.3);
}

.game-icon {
    font-size: 2.5rem;
    margin-bottom: 15px;
    text-align: center;
}

.game-title {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.game-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 15px;
    line-height: 1.4;
}

.game-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.game-difficulty {
    display: flex;
    gap: 2px;
}

.difficulty-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
}

.difficulty-dot.active {
    background: var(--accent-color);
}

.featured-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--accent-color);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
}

/* Game Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 10px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: 12px;
    width: 100%;
    max-width: 800px;
    max-height: 95vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.game-modal {
    padding: 0;
}

.modal-header {
    background: var(--surface);
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0;
    font-size: 1.3rem;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    width: 35px;
    height: 35px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.close-btn:hover {
    color: var(--text-primary);
    background: var(--surface-light);
}

.modal-body {
    padding: 20px;
    max-height: calc(95vh - 80px);
    overflow-y: auto;
}

/* Game Specific Styles */
.game-container {
    text-align: center;
}

.game-board {
    background: var(--surface-light);
    border-radius: 12px;
    padding: 15px;
    margin: 15px auto;
    display: inline-block;
}

.game-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin: 15px 0;
    flex-wrap: wrap;
}

.game-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin: 15px 0;
    flex-wrap: wrap;
}

.game-stat {
    text-align: center;
    min-width: 80px;
}

.game-stat-value {
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--primary-color);
}

.game-stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* 2048 Game */
.grid-2048 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    background: var(--surface-light);
    padding: 10px;
    border-radius: 8px;
    margin: 0 auto;
    touch-action: none;
}

.tile {
    width: 65px;
    height: 65px;
    background: var(--background);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.1rem;
    transition: all 0.2s ease;
}

.tile-2 { background: #eee4da; color: #776e65; }
.tile-4 { background: #ede0c8; color: #776e65; }
.tile-8 { background: #f2b179; color: white; }
.tile-16 { background: #f59563; color: white; }
.tile-32 { background: #f67c5f; color: white; }
.tile-64 { background: #f65e3b; color: white; }
.tile-128 { background: #edcf72; color: white; font-size: 1rem; }
.tile-256 { background: #edcc61; color: white; font-size: 1rem; }
.tile-512 { background: #edc850; color: white; font-size: 1rem; }
.tile-1024 { background: #edc53f; color: white; font-size: 0.8rem; }
.tile-2048 { background: #edc22e; color: white; font-size: 0.8rem; }

/* Memory Game */
.grid-memory {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 0 auto;
    justify-content: center;
    max-width: 360px;
}

.memory-card {
    width: 75px;
    height: 75px;
    background: var(--primary-color);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    transform-style: preserve-3d;
    transition: transform 0.6s;
    position: relative;
    user-select: none;
}

.memory-card.flipped {
    transform: rotateY(180deg);
}

.memory-card .front,
.memory-card .back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.memory-card .front {
    background: var(--surface-light);
    transform: rotateY(180deg);
}

.memory-card .back {
    background: var(--primary-color);
    color: white;
}

/* Typing Game */
.typing-container {
    background: var(--surface-light);
    padding: 20px;
    border-radius: 12px;
    margin: 15px 0;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.typing-text {
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 15px;
    color: var(--text-primary);
    min-height: 80px;
    text-align: left;
    padding: 15px;
    background: var(--background);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.typing-input {
    width: 100%;
    padding: 12px;
    background: var(--background);
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    text-align: center;
}

.typing-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.current-char {
    background: var(--primary-color);
    color: white;
    padding: 2px 4px;
    border-radius: 4px;
}

.correct-char {
    color: var(--secondary-color);
}

.incorrect-char {
    color: var(--danger-color);
    text-decoration: underline;
}

/* Math Game */
.math-container {
    background: var(--surface-light);
    padding: 20px;
    border-radius: 12px;
    margin: 15px 0;
    text-align: center;
}

.math-problem {
    font-size: 2rem;
    margin: 15px 0;
    color: var(--text-primary);
    font-weight: bold;
}

.math-input-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 15px;
}

.math-input {
    padding: 12px;
    font-size: 1.1rem;
    width: 120px;
    text-align: center;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    background: var(--background);
    color: var(--text-primary);
}

.math-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

/* Aim Trainer */
.aim-container {
    position: relative;
    width: 100%;
    height: 300px;
    background: var(--surface-light);
    border-radius: 12px;
    margin: 15px 0;
    overflow: hidden;
    cursor: crosshair;
    border: 2px solid var(--border);
    touch-action: none;
}

.aim-target {
    position: absolute;
    width: 40px;
    height: 40px;
    background: var(--danger-color);
    border-radius: 50%;
    cursor: pointer;
    transform: translate(-50%, -50%);
    transition: all 0.1s ease;
    box-shadow: 0 2px 10px rgba(239, 68, 68, 0.5);
    border: 2px solid white;
}

.aim-target:hover {
    transform: translate(-50%, -50%) scale(1.1);
}

/* Achievements */
.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
}

.achievement-card {
    background: var(--surface-light);
    padding: 15px;
    border-radius: 12px;
    border-left: 4px solid var(--accent-color);
    display: flex;
    align-items: center;
    gap: 12px;
}

.achievement-icon {
    font-size: 1.5rem;
    width: 45px;
    height: 45px;
    background: var(--accent-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.achievement-info {
    flex: 1;
}

.achievement-info h4 {
    margin-bottom: 5px;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.achievement-info p {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-bottom: 5px;
}

.achievement-unlocked {
    color: var(--secondary-color) !important;
    font-size: 0.7rem !important;
}

.achievement-card.locked {
    opacity: 0.5;
    border-left-color: var(--border);
}

.achievement-card.locked .achievement-icon {
    background: var(--border);
}

/* Progress Bars */
.progress-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    margin: 10px 0;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--secondary-color);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Buttons */
.btn {
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
    user-select: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-sm {
    padding: 8px 12px;
    font-size: 0.8rem;
}

/* Stats */
.stats-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
}

.stat-item {
    background: var(--surface-light);
    padding: 15px;
    border-radius: 12px;
}

.stat-item h4 {
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 1rem;
}

/* Notification */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--secondary-color);
    color: white;
    padding: 12px 18px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    z-index: 10000;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    max-width: 300px;
    font-size: 0.9rem;
}

/* Touch Controls for Mobile */
.touch-controls {
    display: none;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 5px;
    margin: 15px auto;
    max-width: 200px;
    height: 200px;
}

.touch-control {
    background: rgba(99, 102, 241, 0.3);
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary);
    font-size: 1.5rem;
    user-select: none;
    cursor: pointer;
}

.touch-control:active {
    background: rgba(99, 102, 241, 0.6);
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .header {
        flex-direction: column;
        text-align: center;
        gap: 15px;
        padding: 15px;
    }
    
    .nav {
        justify-content: center;
    }
    
    .games-grid {
        grid-template-columns: 1fr;
    }
    
    .game-stats {
        flex-direction: column;
        gap: 12px;
    }
    
    .grid-2048,
    .grid-memory {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }
    
    .tile {
        width: 55px;
        height: 55px;
        font-size: 0.9rem;
    }
    
    .memory-card {
        width: 65px;
        height: 65px;
        font-size: 1.2rem;
    }
    
    .section-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-box input {
        width: 100%;
        max-width: none;
    }
    
    .modal {
        padding: 5px;
    }
    
    .math-problem {
        font-size: 1.7rem;
    }
    
    .math-input {
        width: 100px;
        font-size: 1rem;
    }
    
    .aim-container {
        height: 250px;
    }
    
    .touch-controls {
        display: grid;
    }
}

@media (max-width: 480px) {
    .quick-stats {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .stat-card {
        padding: 12px;
    }
    
    .stat-value {
        font-size: 1.3rem;
    }
    
    .game-icon {
        font-size: 2rem;
    }
    
    .game-title {
        font-size: 1.1rem;
    }
    
    .achievements-grid {
        grid-template-columns: 1fr;
    }
    
    .modal-body {
        padding: 15px;
    }
    
    .game-board {
        padding: 10px;
    }
    
    .typing-container {
        padding: 15px;
    }
    
    .typing-text {
        font-size: 1rem;
        padding: 12px;
    }
}

/* High DPI screens */
@media (min-resolution: 2dppx) {
    .tile,
    .memory-card,
    .aim-target {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
