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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    position: relative;
}

.game-header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
    width: 100%;
    max-width: 800px;
}

.game-header h1 {
    font-size: clamp(2rem, 8vw, 3rem);
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    line-height: 1.2;
}

.game-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    color: white;
    font-size: clamp(0.9rem, 3vw, 1.2rem);
    flex-wrap: wrap;
    justify-content: center;
}

.stat {
    background: rgba(255,255,255,0.2);
    padding: clamp(8px, 2vw, 15px) clamp(15px, 3vw, 25px);
    border-radius: 25px;
    backdrop-filter: blur(10px);
    white-space: nowrap;
    text-align: center;
    min-width: fit-content;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: clamp(8px, 2vw, 15px);
    max-width: min(90vw, 800px);
    margin: 0 auto;
    width: 100%;
}

.card {
    width: clamp(80px, 20vw, 120px);
    height: clamp(80px, 20vw, 120px);
    perspective: 1000px;
    cursor: pointer;
    margin: 0 auto;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    border-radius: clamp(8px, 2vw, 10px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

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

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: clamp(8px, 2vw, 10px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.5rem, 6vw, 2.5rem);
    font-weight: bold;
}

.card-front {
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
    color: white;
    transform: rotateY(180deg);
}

.card-back {
    background: linear-gradient(45deg, #a8edea, #fed6e3);
    color: #333;
}

.card.matched {
    opacity: 0.7;
    transform: scale(0.95);
}

.card.matched .card-inner {
    animation: pulse 0.5s ease-in-out;
}

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

.controls {
    margin-top: clamp(20px, 5vw, 30px);
    margin-bottom: clamp(30px, 8vw, 50px);
    text-align: center;
    width: 100%;
    max-width: 600px;
}

.btn {
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
    color: white;
    border: none;
    padding: clamp(12px, 3vw, 18px) clamp(20px, 4vw, 30px);
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
    border-radius: 25px;
    cursor: pointer;
    margin: clamp(5px, 1vw, 10px);
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    white-space: nowrap;
}

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

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

.game-over {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.game-over.show {
    display: flex;
}

.game-over-content {
    background: white;
    padding: clamp(20px, 5vw, 40px);
    border-radius: 20px;
    text-align: center;
    max-width: min(90vw, 400px);
    width: 100%;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.game-over h2 {
    color: #333;
    margin-bottom: 20px;
    font-size: clamp(1.5rem, 5vw, 2rem);
}

.game-over p {
    color: #666;
    margin-bottom: 20px;
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
}

footer {
    margin-top: auto;
    padding: 20px;
    text-align: center;
    color: white;
    font-size: clamp(0.8rem, 2vw, 1rem);
    opacity: 0.8;
    width: 100%;
    max-width: 800px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    position: relative;
    z-index: 1;
}

footer p {
    margin: 0;
    line-height: 1.4;
    padding: 0 15px;
}

/* Large Desktop Screens */
@media (min-width: 1200px) {
    .game-board {
        grid-template-columns: repeat(4, 1fr);
        max-width: 800px;
        gap: 20px;
    }
    
    .card {
        width: 140px;
        height: 140px;
    }
    
    .game-header h1 {
        font-size: 3.5rem;
    }
    
    .game-stats {
        gap: 40px;
    }
}

/* Medium Desktop Screens */
@media (min-width: 768px) and (max-width: 1199px) {
    .game-board {
        grid-template-columns: repeat(4, 1fr);
        max-width: 700px;
        gap: 15px;
    }
    
    .card {
        width: 120px;
        height: 120px;
    }
}

/* Tablet Screens */
@media (min-width: 481px) and (max-width: 767px) {
    .game-board {
        grid-template-columns: repeat(4, 1fr);
        max-width: 500px;
        gap: 12px;
    }
    
    .card {
        width: 100px;
        height: 100px;
    }
    
    .game-header h1 {
        font-size: 2.5rem;
    }
    
    .game-stats {
        gap: 15px;
    }
    
    .controls {
        margin-top: 25px;
    }
}

/* Mobile Screens */
@media (max-width: 480px) {
    body {
        padding: 15px;
    }
    
    .game-board {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        max-width: 350px;
    }
    
    .card {
        width: 90px;
        height: 90px;
    }
    
    .game-header {
        margin-bottom: 20px;
    }
    
    .game-header h1 {
        font-size: 2rem;
        margin-bottom: 8px;
    }
    
    .game-stats {
        flex-direction: column;
        gap: 10px;
        margin-bottom: 15px;
    }
    
    .stat {
        padding: 8px 16px;
        font-size: 0.9rem;
    }
    
    .controls {
        margin-top: 20px;
        margin-bottom: 25px;
    }
    
    .btn {
        padding: 10px 20px;
        font-size: 0.9rem;
        margin: 5px;
    }
    
    .game-over-content {
        padding: 25px 20px;
        margin: 20px;
    }
    
    .game-over h2 {
        font-size: 1.8rem;
    }
    
    .game-over p {
        font-size: 1rem;
    }
    
    footer {
        padding: 15px;
        margin-top: 15px;
    }
    
    footer p {
        padding: 0 10px;
        font-size: 0.75rem;
    }
}

/* Extra Small Mobile Screens */
@media (max-width: 360px) {
    .game-board {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        max-width: 300px;
    }
    
    .card {
        width: 80px;
        height: 80px;
    }
    
    .game-header h1 {
        font-size: 1.8rem;
    }
    
    .game-stats {
        font-size: 0.8rem;
    }
    
    .stat {
        padding: 6px 12px;
    }
    
    .btn {
        padding: 8px 16px;
        font-size: 0.8rem;
    }
    
    footer {
        padding: 12px;
        margin-top: 10px;
    }
    
    footer p {
        padding: 0 8px;
        font-size: 0.7rem;
    }
}

/* Landscape Mobile Orientation */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        padding: 10px;
    }
    
    .game-header {
        margin-bottom: 15px;
    }
    
    .game-header h1 {
        font-size: 1.8rem;
        margin-bottom: 5px;
    }
    
    .game-stats {
        margin-bottom: 10px;
        gap: 15px;
    }
    
    .game-board {
        gap: 8px;
        max-width: 600px;
    }
    
    .card {
        width: 70px;
        height: 70px;
    }
    
    .controls {
        margin-top: 15px;
    }
    
    .btn {
        padding: 8px 16px;
        font-size: 0.8rem;
    }
    
    footer {
        padding: 10px;
        margin-top: 5px;
    }
    
    footer p {
        padding: 0 10px;
        font-size: 0.7rem;
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .card-inner {
        box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    }
    
    .btn {
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    }
    
    .btn:hover {
        box-shadow: 0 3px 10px rgba(0,0,0,0.3);
    }
}

/* Reduced Motion Preferences */
@media (prefers-reduced-motion: reduce) {
    .card-inner {
        transition: transform 0.3s;
    }
    
    .card.matched .card-inner {
        animation: none;
    }
    
    .btn {
        transition: none;
    }
    
    .btn:hover {
        transform: none;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .game-over-content {
        background: #2a2a2a;
        color: #ffffff;
    }
    
    .game-over h2 {
        color: #ffffff;
    }
    
    .game-over p {
        color: #cccccc;
    }
}
