:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a25;
    --bg-card-hover: #222233;
    --accent: #6c5ce7;
    --accent-glow: #a29bfe;
    --text-primary: #f0f0f5;
    --text-secondary: #8888aa;
    --border-color: #333344;
    --success: #00d9a5;
    --warning: #ffd43b;
    --danger: #ff6b6b;
    --transition: 0.2s ease;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(ellipse at 20% 20%, rgba(108, 92, 231, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(162, 155, 254, 0.08) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.portal {
    position: relative;
    z-index: 1;
    width: 100%;
    min-height: 100vh;
}

.portal-inner {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    gap: 2rem;
    padding: 2rem;
}

.portal-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 900px;
}

.scores-panel {
    position: fixed;
    right: 2rem;
    top: 2rem;
    width: 300px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    height: fit-content;
}
}

.scores-panel h2 {
    font-size: 1.2rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
    text-align: center;
}

.change-username-btn {
    display: block;
    width: 100%;
    margin-bottom: 1rem;
    padding: 0.5rem;
    font-size: 0.85rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.change-username-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent);
    color: var(--text-primary);
}

.scores-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.score-tab {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.score-tab:hover {
    background: var(--bg-card-hover);
}

.score-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--text-primary);
}

.scores-list {
    max-height: 400px;
    overflow-y: auto;
}

.score-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    background: var(--bg-secondary);
}

.score-item.highlight {
    border: 1px solid var(--accent);
    background: rgba(108, 92, 231, 0.15);
}

.score-rank {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    border-radius: 50%;
    background: var(--border-color);
    color: var(--text-secondary);
}

.score-item:nth-child(1) .score-rank { background: #ffd43b; color: #000; }
.score-item:nth-child(2) .score-rank { background: #c0c0c0; color: #000; }
.score-item:nth-child(3) .score-rank { background: #cd7f32; color: #000; }

.score-info {
    flex: 1;
    min-width: 0;
}

.score-name {
    font-size: 0.9rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.score-game {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.score-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--success);
}

.no-scores {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 2rem 0;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-size: 3rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--accent-glow));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 40px rgba(108, 92, 231, 0.3);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.game-selector {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    flex: 1;
    align-content: center;
}

.game-card {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.game-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(108, 92, 231, 0.1), transparent);
    opacity: 0;
    transition: opacity var(--transition);
}

.game-card:hover,
.game-card:focus,
.game-card.selected {
    border-color: var(--accent);
    background: var(--bg-card-hover);
    transform: translateY(-4px);
    box-shadow: 
        0 8px 32px rgba(108, 92, 231, 0.2),
        0 0 0 1px var(--accent-glow);
    outline: none;
}

.game-card:hover::before,
.game-card.selected::before {
    opacity: 1;
}

.game-card.selected {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 8px 32px rgba(108, 92, 231, 0.2), 0 0 0 1px var(--accent-glow); }
    50% { box-shadow: 0 8px 32px rgba(108, 92, 231, 0.4), 0 0 0 2px var(--accent-glow); }
}

.game-icon {
    width: 200px;
    height: 100px;
    margin: 0 auto 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border-radius: 12px;
    position: relative;
    overflow: hidden;
}

.game-icon .custom-icon {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

.game-icon.has-custom-icon .custom-icon {
    display: block;
}

.game-icon.has-custom-icon > *:not(.custom-icon) {
    display: none;
}

.tetris-icon {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 12px;
}

.tetris-icon .block {
    width: 32px;
    height: 32px;
    background: var(--accent);
    border-radius: 4px;
}

.tetris-icon .block:nth-child(1) { background: #ff6b6b; }
.tetris-icon .block:nth-child(2) { background: #ffd43b; }
.tetris-icon .block:nth-child(3) { background: #00d9a5; }
.tetris-icon .block:nth-child(4) { background: #6c5ce7; }

.snake-icon {
    display: flex;
    gap: 8px;
    align-items: center;
}

.snake-segment {
    width: 28px;
    height: 28px;
    background: var(--success);
    border-radius: 50%;
}

.snake-segment:nth-child(2) { transform: scale(0.9); }
.snake-segment:nth-child(3) { transform: scale(0.8); background: var(--warning); }

.invaders-icon {
    display: flex;
    gap: 12px;
}

.invader {
    width: 28px;
    height: 28px;
    background: var(--danger);
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}

.invaders-icon .invader:nth-child(2) { transform: scale(1.2); }

.game-card h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.game-card p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 1rem;
}

.play-hint {
    display: inline-block;
    font-size: 0.8rem;
    color: var(--accent-glow);
    padding: 0.4rem 0.8rem;
    background: rgba(108, 92, 231, 0.15);
    border-radius: 20px;
    opacity: 0;
    transform: translateY(8px);
    transition: all var(--transition);
}

.game-card:hover .play-hint,
.game-card:focus .play-hint,
.game-card.selected .play-hint {
    opacity: 1;
    transform: translateY(0);
}

.controls-hint {
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.hint-item {
    color: var(--text-secondary);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

kbd {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    font-family: inherit;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 2px 0 var(--bg-primary);
}

.game-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.game-container[hidden] {
    display: none;
}

.game-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 2rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.game-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

#gameCanvas {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
}

.game-scores {
    width: 240px;
    border-radius: 0;
    border-left: 1px solid var(--border-color);
    border-top: none;
    border-right: none;
    border-bottom: none;
}

.game-scores .scores-list {
    max-height: none;
}

.back-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition);
}

.back-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent);
}

.game-title {
    font-size: 1.2rem;
    font-weight: 600;
}

#gameCanvas {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
}

.username-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.username-modal[hidden] {
    display: none;
}

.username-modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.username-modal-content h2 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.username-modal-content p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.username-modal-content input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    text-align: center;
}

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

.username-error {
    color: var(--danger);
    font-size: 0.9rem;
    margin-top: -1rem;
    margin-bottom: 1rem;
    text-align: center;
    display: none;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.modal-btn {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition);
    border: none;
}

.modal-btn.primary {
    background: var(--accent);
    color: var(--text-primary);
}

.modal-btn.primary:hover {
    background: var(--accent-glow);
}

.modal-btn.secondary {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.modal-btn.secondary:hover {
    background: var(--bg-card-hover);
}

@media (max-width: 1200px) {
    .scores-panel {
        position: static;
        width: 280px;
        flex-shrink: 0;
    }
    
    .portal-inner {
        justify-content: center;
    }
}

@media (max-width: 640px) {
    .portal {
        width: 100%;
    }
    
    .portal-inner {
        flex-direction: column;
        padding: 1rem;
    }
    
    .portal-main {
        width: 100%;
    }
    
    .scores-panel {
        width: 100%;
    }
    
    .game-content {
        flex-direction: column;
    }
    
    .game-scores {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border-color);
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .game-selector {
        grid-template-columns: 1fr;
    }
    
    .controls-hint {
        flex-direction: column;
        align-items: center;
        gap: 0.75rem;
    }
}
