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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #475569;
    --card-flip-time: 0.4s;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
}

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

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

/* Header Styles */
header {
    text-align: center;
    padding: 1.5rem 0;
}

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.5rem;
}

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

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Panel Styles */
.panel {
    background: var(--bg-secondary);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.panel h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

/* Settings Grid */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.setting-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.setting-group select {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.setting-group select:hover {
    border-color: var(--primary-color);
}

.setting-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Button Styles */
.btn {
    padding: 0.875rem 2rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

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

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

#settings-panel .btn {
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
    display: block;
}

/* Stats Panel */
#stats-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
}

.stats-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    flex: 1;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 70px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

#stats-panel .btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Game Board */
#game-board {
    display: flex;
    justify-content: center;
    padding: 1rem 0;
}

#cards-container {
    display: grid;
    gap: 0.75rem;
    justify-content: center;
    max-width: 100%;
}

/* Card Styles */
.card {
    width: 80px;
    height: 80px;
    perspective: 1000px;
    cursor: pointer;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform var(--card-flip-time);
}

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

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
    box-shadow: var(--shadow);
}

.card-front {
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    color: white;
}

.card-front::after {
    content: '?';
    font-size: 2rem;
}

.card-back {
    background: var(--bg-card);
    transform: rotateY(180deg);
    border: 2px solid var(--border-color);
}

.card.matched .card-back {
    background: linear-gradient(135deg, var(--success-color), #16a34a);
    border-color: var(--success-color);
    animation: matchPulse 0.5s ease;
}

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

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

@keyframes shake {
    0%, 100% { transform: rotateY(180deg) translateX(0); }
    25% { transform: rotateY(180deg) translateX(-5px); }
    75% { transform: rotateY(180deg) translateX(5px); }
}

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

/* Color symbols */
.color-symbol {
    width: 50px;
    height: 50px;
    border-radius: 50%;
}

/* Shape symbols */
.shape-symbol {
    width: 40px;
    height: 40px;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 1rem;
    padding: 2rem;
    max-width: 400px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.3s ease;
}

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

.modal-content h2 {
    font-size: 1.75rem;
    margin-bottom: 1rem;
}

#modal-message {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.modal-stats {
    background: var(--bg-card);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.modal-stats p {
    margin: 0.5rem 0;
    color: var(--text-secondary);
}

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

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

.modal-buttons .btn {
    flex: 1;
    min-width: 120px;
}

/* High Scores */
#high-scores-panel {
    margin-top: auto;
}

#high-scores-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.no-scores {
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    padding: 1rem;
}

.score-entry {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-radius: 0.5rem;
}

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

.score-rank.gold {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
}

.score-rank.silver {
    background: linear-gradient(135deg, #94a3b8, #64748b);
}

.score-rank.bronze {
    background: linear-gradient(135deg, #d97706, #b45309);
}

.score-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

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

.score-value {
    font-weight: 700;
    color: var(--primary-color);
}

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

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

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

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

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Timer warning states */
.timer-warning {
    color: var(--warning-color) !important;
    animation: pulse 1s infinite;
}

.timer-danger {
    color: var(--danger-color) !important;
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Responsive Design */
@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }

    .card {
        width: 65px;
        height: 65px;
    }

    .card-front::after, .card-back {
        font-size: 1.5rem;
    }

    #cards-container {
        gap: 0.5rem;
    }

    .stats-grid {
        gap: 1rem;
    }

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

@media (max-width: 480px) {
    .container {
        padding: 0.75rem;
    }

    header {
        padding: 1rem 0;
    }

    header h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .panel {
        padding: 1rem;
    }

    .card {
        width: 55px;
        height: 55px;
    }

    .card-front::after {
        font-size: 1.25rem;
    }

    .card-back {
        font-size: 1.25rem;
    }

    .color-symbol {
        width: 35px;
        height: 35px;
    }

    .shape-symbol {
        width: 30px;
        height: 30px;
    }

    #stats-panel {
        flex-direction: column;
        text-align: center;
    }

    .stats-grid {
        width: 100%;
        justify-content: center;
    }

    .modal-buttons {
        flex-direction: column;
    }

    .modal-buttons .btn {
        width: 100%;
    }
}

/* Animation for card appearance */
.card {
    animation: cardAppear 0.3s ease backwards;
}

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

/* Stagger card animations */
.card:nth-child(1) { animation-delay: 0.02s; }
.card:nth-child(2) { animation-delay: 0.04s; }
.card:nth-child(3) { animation-delay: 0.06s; }
.card:nth-child(4) { animation-delay: 0.08s; }
.card:nth-child(5) { animation-delay: 0.10s; }
.card:nth-child(6) { animation-delay: 0.12s; }
.card:nth-child(7) { animation-delay: 0.14s; }
.card:nth-child(8) { animation-delay: 0.16s; }
.card:nth-child(9) { animation-delay: 0.18s; }
.card:nth-child(10) { animation-delay: 0.20s; }
.card:nth-child(11) { animation-delay: 0.22s; }
.card:nth-child(12) { animation-delay: 0.24s; }
.card:nth-child(13) { animation-delay: 0.26s; }
.card:nth-child(14) { animation-delay: 0.28s; }
.card:nth-child(15) { animation-delay: 0.30s; }
.card:nth-child(16) { animation-delay: 0.32s; }
.card:nth-child(17) { animation-delay: 0.34s; }
.card:nth-child(18) { animation-delay: 0.36s; }
.card:nth-child(19) { animation-delay: 0.38s; }
.card:nth-child(20) { animation-delay: 0.40s; }
.card:nth-child(21) { animation-delay: 0.42s; }
.card:nth-child(22) { animation-delay: 0.44s; }
.card:nth-child(23) { animation-delay: 0.46s; }
.card:nth-child(24) { animation-delay: 0.48s; }
