/* CSS Variables for easy theming */
:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --card-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --success-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    
    --text-primary: #2d3748;
    --text-secondary: #4a5568;
    --text-light: #ffffff;
    --card-bg: rgba(255, 255, 255, 0.95);
    --card-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    --card-shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.15);
    
    --border-radius: 16px;
    --border-radius-small: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.2s ease;
}

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

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

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 1rem;
}

.title {
    font-size: 3rem;
    font-weight: 700;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

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

/* Controls */
.controls {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.game-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 1.5rem;
}

.stat-item {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    font-weight: 500;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    background: var(--secondary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.game-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Difficulty Selector */
.difficulty-selector {
    display: flex;
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--border-radius-small);
    padding: 0.25rem;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.difficulty-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    background: transparent;
    border-radius: var(--border-radius-small);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    color: var(--text-primary);
    position: relative;
    overflow: hidden;
}

.difficulty-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: var(--primary-gradient);
    transition: var(--transition);
    z-index: -1;
}

.difficulty-btn.active::before,
.difficulty-btn:hover::before {
    left: 0;
}

.difficulty-btn.active,
.difficulty-btn:hover {
    color: var(--text-light);
    transform: translateY(-1px);
}

/* Control Buttons */
.control-btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius-small);
    background: var(--secondary-gradient);
    color: var(--text-light);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.control-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

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

/* Game Board */
.game-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.game-board {
    display: grid;
    gap: 1rem;
    padding: 2rem;
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    box-shadow: var(--card-shadow);
    border: 1px solid rgba(255, 255, 255, 0.3);
    transition: var(--transition);
}

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

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

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

/* Memory Cards */
.memory-card {
    aspect-ratio: 1;
    border-radius: var(--border-radius-small);
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    min-width: 60px;
    min-height: 60px;
}

.memory-card:hover {
    transform: scale(1.05);
}

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

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

.memory-card.matched {
    animation: matchPulse 0.6s ease-in-out;
    pointer-events: none;
}

@keyframes matchPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

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

.card-face.back {
    background: var(--card-gradient);
    color: var(--text-light);
}

.card-face.front {
    background: var(--card-bg);
    color: var(--text-primary);
    transform: rotateY(180deg);
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.memory-card:hover .card-face {
    box-shadow: var(--card-shadow-hover);
}

/* Best Scores */
.best-scores {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--card-shadow);
    border: 1px solid rgba(255, 255, 255, 0.3);
    text-align: center;
}

.best-scores h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
    font-size: 1.3rem;
}

.scores-grid {
    display: flex;
    justify-content: center;
    gap: 2rem;
}

.score-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.score-item span:first-child {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.score-item span:last-child {
    font-size: 1.2rem;
    font-weight: 700;
    background: var(--success-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: var(--border-radius);
    padding: 3rem;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.3);
    animation: modalSlideIn 0.3s ease-out;
}

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

.win-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: bounce 1s ease-in-out infinite alternate;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-10px); }
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

.final-stats {
    display: flex;
    justify-content: space-around;
    margin: 2rem 0;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--border-radius-small);
}

.final-stat {
    text-align: center;
}

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

.final-stat strong {
    color: var(--text-primary);
}

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

.modal-btn {
    padding: 0.75rem 2rem;
    border: none;
    border-radius: var(--border-radius-small);
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
}

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

.modal-btn.secondary {
    background: transparent;
    color: var(--text-primary);
    border: 2px solid var(--text-primary);
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

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

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
        gap: 1.5rem;
    }
    
    .title {
        font-size: 2.5rem;
    }
    
    .game-stats {
        gap: 1.5rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .game-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .difficulty-selector {
        justify-content: center;
    }
    
    .game-board {
        padding: 1rem;
    }
    
    .game-board.medium,
    .game-board.hard {
        grid-template-columns: repeat(4, 1fr);
        max-width: 320px;
    }
    
    .memory-card {
        min-width: 50px;
        min-height: 50px;
    }
    
    .card-face {
        font-size: 1.5rem;
    }
    
    .scores-grid {
        flex-direction: column;
        gap: 1rem;
    }
    
    .score-item {
        flex-direction: row;
        justify-content: space-between;
    }
    
    .modal-content {
        padding: 2rem 1rem;
    }
    
    .final-stats {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .modal-actions {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .title {
        font-size: 2rem;
    }
    
    .game-stats {
        gap: 1rem;
    }
    
    .stat-value {
        font-size: 1.2rem;
    }
    
    .difficulty-btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
    
    .game-board.easy {
        max-width: 280px;
    }
    
    .memory-card {
        min-width: 40px;
        min-height: 40px;
    }
    
    .card-face {
        font-size: 1.2rem;
    }
}

/* Animations for new cards */
.memory-card {
    animation: cardAppear 0.5s ease-out backwards;
}

@keyframes cardAppear {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Stagger animation for cards */
.memory-card:nth-child(1) { animation-delay: 0.1s; }
.memory-card:nth-child(2) { animation-delay: 0.15s; }
.memory-card:nth-child(3) { animation-delay: 0.2s; }
.memory-card:nth-child(4) { animation-delay: 0.25s; }
.memory-card:nth-child(5) { animation-delay: 0.3s; }
.memory-card:nth-child(6) { animation-delay: 0.35s; }
.memory-card:nth-child(7) { animation-delay: 0.4s; }
.memory-card:nth-child(8) { animation-delay: 0.45s; }
.memory-card:nth-child(9) { animation-delay: 0.5s; }
.memory-card:nth-child(10) { animation-delay: 0.55s; }
.memory-card:nth-child(11) { animation-delay: 0.6s; }
.memory-card:nth-child(12) { animation-delay: 0.65s; }
.memory-card:nth-child(13) { animation-delay: 0.7s; }
.memory-card:nth-child(14) { animation-delay: 0.75s; }
.memory-card:nth-child(15) { animation-delay: 0.8s; }
.memory-card:nth-child(16) { animation-delay: 0.85s; }