:root {
    --color-bg: #050505;
    --color-surface: #0f0f0f;
    --color-blue: #3A86FF;
    --color-purple: #8B5CF6;
    --color-green: #10B981;
    --color-yellow: #FFB800;
    --color-red: #FF006E;
    --color-orange: #FF6B35;
    --color-border: rgba(255, 255, 255, 0.08);
    --font-main: 'Space Grotesk', sans-serif;
}

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

body {
    background: var(--color-bg);
    color: #fff;
    font-family: var(--font-main);
    line-height: 1.6;
    overflow-x: hidden;
}

header {
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--color-border);
    padding: 1.2rem 0;
    position: sticky; top: 0; z-index: 100;
}

.container { 
    max-width: 1100px; 
    margin: 0 auto; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 0 2rem; 
}

/* Logo Sync */
.logo-text { 
    font-size: 1.2rem; 
    font-weight: 700; 
    letter-spacing: 0.25em; 
}
.logo-text span:nth-child(1) { color: #FFB800; }
.logo-text span:nth-child(2) { color: #FF006E; }
.logo-text span:nth-child(3) { color: #FF6B35; }
.logo-text span:nth-child(4) { color: #FFB800; }
.logo-text span:nth-child(5) { color: var(--color-blue); }
.logo-text span:nth-child(6) { color: var(--color-purple); }

.back-link {
    text-decoration: none; 
    color: rgba(255,255,255,0.4);
    font-size: 0.75rem; 
    font-weight: 700; 
    display: flex; 
    align-items: center; 
    gap: 8px;
    transition: 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.back-link:hover { color: #fff; }

/* Main Layout */
main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 3.5rem 2rem;
}

.screen {
    animation: fadeIn 0.3s ease;
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === START SCREEN === */
.start-content {
    max-width: 600px;
    margin: 0 auto;
}

.game-title {
    text-align: center;
    margin-bottom: 3rem;
}

.icon-hero {
    width: 90px; 
    height: 90px; 
    margin: 0 auto 1.5rem;
    display: flex; 
    align-items: center; 
    justify-content: center;
    border-radius: 20px; 
    background: rgba(58, 134, 255, 0.1); 
    color: var(--color-blue);
    animation: floatIcon 3s ease-in-out infinite;
}

.icon-hero svg { 
    width: 50px; 
    height: 50px; 
}

@keyframes floatIcon {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.game-title h2 {
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--color-blue) 0%, var(--color-purple) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.game-title p {
    font-size: 1rem;
    color: rgba(255,255,255,0.5);
}

/* === LEVEL SELECTOR === */
.level-selector {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.level-btn {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    padding: 1.5rem 2rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s;
    font-family: inherit;
    text-align: left;
    position: relative;
    overflow: hidden;
}

.level-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 0%, rgba(255,255,255,0.03) 100%);
    opacity: 0;
    transition: opacity 0.3s;
}

.level-btn:hover::before {
    opacity: 1;
}

.level-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
}

.level-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.level-easy .level-icon {
    background: rgba(16, 185, 129, 0.15);
    color: var(--color-green);
}

.level-medium .level-icon {
    background: rgba(255, 184, 0, 0.15);
    color: var(--color-yellow);
}

.level-hard .level-icon {
    background: rgba(255, 0, 110, 0.15);
    color: var(--color-red);
}

.level-easy:hover {
    border-color: var(--color-green);
}

.level-medium:hover {
    border-color: var(--color-yellow);
}

.level-hard:hover {
    border-color: var(--color-red);
}

.level-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.level-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.02em;
}

.level-desc {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.4);
}

.level-info {
    font-size: 0.85rem;
    font-weight: 700;
    color: rgba(255,255,255,0.6);
    padding: 8px 16px;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    border: 1px solid var(--color-border);
}

/* === GAME SCREEN === */
.stats-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    max-width: 900px;
    margin: 0 auto 2.5rem;
}

.stat-item {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 16px;
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.2rem;
    transition: all 0.3s;
}

.stat-highlight {
    border-left: 4px solid var(--color-purple);
    background: linear-gradient(135deg, var(--color-surface) 0%, rgba(139, 92, 246, 0.05) 100%);
}

.stat-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon-blue {
    background: rgba(58, 134, 255, 0.15);
    color: var(--color-blue);
}

.stat-icon-purple {
    background: rgba(139, 92, 246, 0.15);
    color: var(--color-purple);
}

.stat-icon-green {
    background: rgba(16, 185, 129, 0.15);
    color: var(--color-green);
}

.stat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.3);
    font-weight: 600;
}

.stat-value {
    font-size: 2.2rem;
    font-weight: 700;
    line-height: 1;
    color: #fff;
}

/* === MEMORY GRID === */
.game-container {
    max-width: 900px;
    margin: 0 auto 2.5rem;
}

.memory-grid {
    display: grid;
    gap: 0.8rem;
    margin: 0 auto;
}

.memory-grid.grid-easy {
    grid-template-columns: repeat(2, 1fr);
    max-width: 300px;
}

.memory-grid.grid-medium {
    grid-template-columns: repeat(4, 1fr);
    max-width: 500px;
}

.memory-grid.grid-hard {
    grid-template-columns: repeat(6, 1fr);
    max-width: 700px;
}

/* === MEMORY CARD === */
.memory-card {
    aspect-ratio: 1;
    position: relative;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.5s ease;
}

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

.memory-card.matched {
    cursor: default;
}

.memory-card.disabled {
    pointer-events: none;
}

.card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    user-select: none;
}

.card-front {
    background: linear-gradient(135deg, var(--color-blue) 0%, var(--color-purple) 100%);
    color: white;
    font-size: 32px;
    font-weight: 700;
    box-shadow: 0 10px 30px rgba(58, 134, 255, 0.3);
    border: 1px solid rgba(255,255,255,0.1);
}

.card-back {
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    transform: rotateY(180deg);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.memory-card:hover:not(.flipped):not(.matched) {
    transform: translateY(-6px) scale(1.02);
}

.memory-card:hover:not(.flipped):not(.matched) .card-front {
    box-shadow: 0 15px 40px rgba(58, 134, 255, 0.5);
}

/* === ANIMATIONS === */
@keyframes cardAppear {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.memory-card {
    animation: cardAppear 0.3s ease backwards;
}

.memory-card:nth-child(n) { 
    animation-delay: calc(var(--i, 0) * 0.02s); 
}

@keyframes matchPulse {
    0%, 100% {
        transform: rotateY(180deg) scale(1);
    }
    50% {
        transform: rotateY(180deg) scale(1.08);
    }
}

.memory-card.matched {
    animation: matchPulse 0.5s ease;
}

.memory-card.matched .card-back {
    border-color: var(--color-green);
    background: linear-gradient(135deg, var(--color-surface) 0%, rgba(16, 185, 129, 0.1) 100%);
    box-shadow: 0 0 30px rgba(16, 185, 129, 0.3);
}

@keyframes shake {
    0%, 100% {
        transform: rotateY(180deg) translateX(0);
    }
    20%, 60% {
        transform: rotateY(180deg) translateX(-8px);
    }
    40%, 80% {
        transform: rotateY(180deg) translateX(8px);
    }
}

.memory-card.wrong {
    animation: shake 0.4s ease;
}

.memory-card.wrong .card-back {
    border-color: var(--color-red);
    box-shadow: 0 0 20px rgba(255, 0, 110, 0.4);
}

@keyframes counterBump {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
    }
}

.counter-update {
    animation: counterBump 0.3s ease;
}

/* === BUTTONS === */
.actions {
    display: flex;
    gap: 1rem;
    max-width: 600px;
    margin: 0 auto;
}

.btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 1rem 2rem;
    border-radius: 12px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-blue) 0%, var(--color-purple) 100%);
    color: white;
    box-shadow: 0 10px 25px rgba(58, 134, 255, 0.3);
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 35px rgba(58, 134, 255, 0.5);
}

.btn-secondary {
    background: transparent;
    color: #fff;
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: rgba(255,255,255,0.05);
    border-color: rgba(255,255,255,0.2);
}

.btn:active {
    transform: scale(0.97);
}

/* === WIN SCREEN === */
.win-content {
    max-width: 600px;
    margin: 0 auto;
}

.win-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.icon-success {
    margin-bottom: 1.5rem;
    display: inline-block;
    animation: successPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes successPop {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

.win-header h2 {
    font-size: 3rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--color-green) 0%, var(--color-blue) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.win-header p {
    font-size: 1rem;
    color: rgba(255,255,255,0.5);
}

.win-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.win-stat {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    transition: all 0.3s;
}

.win-stat:hover {
    border-color: var(--color-blue);
    transform: translateY(-4px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
}

.win-stat-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 1rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(58, 134, 255, 0.15);
    color: var(--color-blue);
}

.win-stat-value {
    display: block;
    font-size: 3.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: #fff;
}

.win-stat-label {
    display: block;
    font-size: 0.75rem;
    color: rgba(255,255,255,0.4);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
}

/* === RESPONSIVE === */
@media (max-width: 900px) {
    .stats-container {
        gap: 1rem;
    }
    
    .stat-item {
        padding: 1.2rem;
    }
    
    .memory-grid {
        gap: 0.6rem;
    }
}

@media (max-width: 768px) {
    main {
        padding: 2rem 1rem;
    }
    
    .game-title h2 {
        font-size: 2.2rem;
    }
    
    .icon-hero {
        width: 70px;
        height: 70px;
    }
    
    .icon-hero svg {
        width: 40px;
        height: 40px;
    }
    
    .stats-container {
        grid-template-columns: 1fr;
        gap: 0.8rem;
    }
    
    .stat-item {
        padding: 1rem;
        flex-direction: row;
    }
    
    .stat-icon {
        width: 40px;
        height: 40px;
    }
    
    .stat-value {
        font-size: 1.8rem;
    }
    
    .memory-grid {
        gap: 0.6rem;
    }
    
    .card-face {
        font-size: 32px;
    }
    
    .card-front {
        font-size: 26px;
    }
    
    .actions {
        flex-direction: column;
        gap: 0.8rem;
    }
    
    .btn {
        width: 100%;
    }
}

@media (max-width: 640px) {
    .container {
        padding: 0 1rem;
    }
    
    .logo-text {
        font-size: 1rem;
    }
    
    .game-title h2 {
        font-size: 1.8rem;
    }
    
    .game-title p {
        font-size: 0.9rem;
    }
    
    .icon-hero {
        width: 60px;
        height: 60px;
    }
    
    .icon-hero svg {
        width: 35px;
        height: 35px;
    }
    
    .level-btn {
        padding: 1rem 1.2rem;
        gap: 1rem;
    }
    
    .level-icon {
        width: 48px;
        height: 48px;
    }
    
    .level-name {
        font-size: 1rem;
    }
    
    .level-desc {
        font-size: 0.8rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .memory-grid.grid-easy {
        max-width: 250px;
    }
    
    .memory-grid.grid-medium {
        max-width: 100%;
        padding: 0 1rem;
    }
    
    .memory-grid.grid-hard {
        grid-template-columns: repeat(4, 1fr);
        max-width: 100%;
        padding: 0 1rem;
    }
    
    .card-face {
        font-size: 28px;
    }
    
    .card-front {
        font-size: 24px;
    }
    
    .win-header h2 {
        font-size: 2rem;
    }
    
    .win-stat-value {
        font-size: 2.5rem;
    }
    
    .btn {
        font-size: 0.8rem;
        padding: 0.9rem 1.5rem;
    }
}

@media (max-width: 380px) {
    .game-title h2 {
        font-size: 1.5rem;
    }
    
    .memory-grid.grid-easy {
        max-width: 200px;
    }
    
    .memory-grid.grid-medium {
        gap: 0.5rem;
    }
    
    .memory-grid.grid-hard {
        gap: 0.5rem;
    }
    
    .card-face {
        font-size: 24px;
    }
    
    .card-front {
        font-size: 20px;
    }
    
    .stat-label {
        font-size: 0.65rem;
    }
    
    .stat-value {
        font-size: 1.3rem;
    }
}