/* CSS Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --success-color: #22c55e;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --card-back: #3b82f6;
    --card-front: #1e293b;
    --border-radius: 12px;
    --transition-speed: 0.3s;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
}

.container {
    flex: 1;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Header Styles */
header {
    text-align: center;
    margin-bottom: 1.5rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.25rem;
}

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

/* Game Controls */
.game-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.difficulty-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.difficulty-selector label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.difficulty-selector select {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--surface-light);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color var(--transition-speed);
}

.difficulty-selector select:hover,
.difficulty-selector select:focus {
    border-color: var(--primary-color);
    outline: none;
}

/* Button Styles */
.btn {
    padding: 0.6rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed);
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Stats Bar */
.stats-bar {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--surface);
    border-radius: var(--border-radius);
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Game Board */
.game-board {
    display: grid;
    gap: 0.75rem;
    justify-content: center;
    margin: 0 auto;
    perspective: 1000px;
}

.game-board.easy {
    grid-template-columns: repeat(4, 1fr);
    max-width: 400px;
}

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

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

.game-board.expert {
    grid-template-columns: repeat(6, 1fr);
    max-width: 540px;
}

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

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

.card.matched {
    cursor: default;
}

.card.matched .card-front {
    background: var(--success-color);
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.4);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    transition: box-shadow var(--transition-speed);
}

.card-back {
    background: linear-gradient(135deg, var(--card-back), #8b5cf6);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.card-back::before {
    content: '?';
    font-size: 2rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.8);
}

.card:hover .card-back {
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.card-front {
    background: var(--card-front);
    transform: rotateY(180deg);
    border: 2px solid var(--surface-light);
}

.card-front .emoji {
    font-size: 2.5rem;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    padding: 2.5rem;
    border-radius: var(--border-radius);
    text-align: center;
    max-width: 400px;
    width: 90%;
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--success-color), #4ade80);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-content > p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.final-stats {
    background: var(--background);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.final-stats p {
    font-size: 1.1rem;
    margin: 0.5rem 0;
}

.final-stats span {
    color: var(--primary-color);
    font-weight: 700;
}

/* Footer Styles */
footer {
    padding: 1.5rem;
    text-align: center;
    background: var(--surface);
    border-top: 1px solid var(--surface-light);
}

footer p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition-speed);
}

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

/* Responsive Design */
@media (max-width: 600px) {
    .container {
        padding: 1rem;
    }

    header h1 {
        font-size: 2rem;
    }

    .stats-bar {
        gap: 1rem;
        padding: 0.75rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .game-board {
        gap: 0.5rem;
    }

    .game-board.hard,
    .game-board.expert {
        max-width: 100%;
    }

    .card-front .emoji {
        font-size: 1.8rem;
    }

    .card-back::before {
        font-size: 1.5rem;
    }

    .modal-content {
        padding: 1.5rem;
    }
}

@media (max-width: 400px) {
    .game-controls {
        flex-direction: column;
    }

    .stats-bar {
        gap: 0.75rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    .card-front .emoji {
        font-size: 1.5rem;
    }
}

/* Animation for card matching */
@keyframes matchPulse {
    0% {
        transform: rotateY(180deg) scale(1);
    }
    50% {
        transform: rotateY(180deg) scale(1.1);
    }
    100% {
        transform: rotateY(180deg) scale(1);
    }
}

.card.matched {
    animation: matchPulse 0.4s ease;
}

/* Loading state */
.card.disabled {
    pointer-events: none;
}
