* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.container {
    max-width: 1200px;
    width: 100%;
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.header {
    text-align: center;
    margin-bottom: 40px;
}

h1 {
    color: #667eea;
    margin-bottom: 20px;
    font-size: 2.5em;
}

.mode-selector {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.mode-btn {
    padding: 12px 24px;
    font-size: 16px;
    border: 2px solid #667eea;
    background: white;
    color: #667eea;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.mode-btn:hover {
    background: #f0f0f0;
}

.mode-btn.active {
    background: #667eea;
    color: white;
}

.game-mode {
    display: none;
}

.game-mode.active {
    display: block;
}

.game-info {
    display: flex;
    gap: 30px;
    margin-bottom: 30px;
    justify-content: center;
    flex-wrap: wrap;
}

.info-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.label {
    color: #666;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.value {
    font-size: 28px;
    font-weight: bold;
    color: #667eea;
}

.endless-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 30px;
}

.game-board {
    display: grid;
    gap: 12px;
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 15px;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
}

.card {
    aspect-ratio: 1;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    user-select: none;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    position: relative;
    transform-style: preserve-3d;
    min-height: 80px;
}

.card:hover:not(.flipped):not(.matched) {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.card.flipped {
    background: white;
    color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.card.matched {
    background: #4caf50;
    color: white;
    cursor: not-allowed;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.card.matched::after {
    content: '✓';
    position: absolute;
    font-size: 50px;
}

.card.disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

/* Flashing animation for endless mode */
@keyframes flash {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(0.98);
    }
}

.card.flashing {
    animation: flash 0.5s ease-in-out 3;
}

/* Modal styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    max-width: 400px;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    color: #667eea;
    margin-bottom: 15px;
    font-size: 28px;
}

.modal-content p {
    color: #666;
    margin-bottom: 10px;
    font-size: 16px;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 25px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f0f0f0;
    color: #667eea;
    border: 2px solid #667eea;
}

.btn-secondary:hover {
    background: #667eea;
    color: white;
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 20px;
    }

    h1 {
        font-size: 1.8em;
    }

    .game-board {
        grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
        gap: 8px;
        padding: 15px;
    }

    .card {
        min-height: 60px;
        font-size: 32px;
    }

    .game-info {
        gap: 15px;
    }

    .value {
        font-size: 22px;
    }

    .modal-content {
        padding: 25px;
        max-width: 90%;
    }

    .modal-content h2 {
        font-size: 22px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 15px;
    }

    h1 {
        font-size: 1.5em;
    }

    .game-board {
        grid-template-columns: repeat(auto-fit, minmax(50px, 1fr));
        gap: 6px;
        padding: 10px;
    }

    .card {
        min-height: 50px;
        font-size: 24px;
    }

    .game-info {
        gap: 10px;
    }

    .info-item {
        gap: 4px;
    }

    .label {
        font-size: 12px;
    }

    .value {
        font-size: 18px;
    }
}
