body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    font-family: Arial, sans-serif;
    background: linear-gradient(135deg, #89f7fe 0%, #66a6ff 100%);
    color: #222;
    min-height: 100vh;
    margin: 0;
    padding: 16px;
    box-sizing: border-box;
}

h1 {
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    text-align: center;
    font-size: clamp(1.8rem, 6vw, 2.8rem);
    margin: 0 0 10px 0;
}

#game-board {
    display: grid;
    grid-gap: 10px;
    margin: 20px auto;
    padding: 12px;
    background: rgba(255,255,255,0.2);
    border-radius: 16px;
    width: 100%;
    max-width: 600px;           /* Reduced from 900px to keep cards smaller on PC */
    box-sizing: border-box;
    justify-content: center;
}

.card {
    width: 100%;
    aspect-ratio: 1 / 1;
    background-color: #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.5rem, 5vw, 2.5rem);  /* Slightly reduced max font size */
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s, box-shadow 0.2s;
    border-radius: 12px;
    position: relative;
    transform-style: preserve-3d;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}


.card:hover {
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
}

.card.flipped {
    transform: rotateY(180deg);
}

.card .front,
.card .back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
}

.card .front {
    background-color: #fff;
    transform: rotateY(180deg);
    visibility: hidden;        /* hidden until flipped */
}

.card.flipped .front {
    visibility: visible;       /* shown when flipped */
}

.card .back {
    background-color: #ccc;
    transform: rotateY(0deg);
}

.card.matched .front {
    background-color: #8f8;
    box-shadow: 0 0 15px rgba(0,255,0,0.6);
}

.card.unmatched .front {
    background-color: #f88;
    box-shadow: 0 0 15px rgba(255,0,0,0.6);
}

#tries {
    margin-top: 20px;
    font-size: clamp(1.2rem, 4vw, 1.8rem);
    color: #fff;
    text-align: center;
}

#reset-button, #hint-button {
    margin-top: 20px;
    padding: 12px 24px;
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    background-color: #333;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.2s;
    width: auto;
    min-width: 160px;
    max-width: 90%;
}

#hint-button {
    background-color: #ff9800;
    margin-top: 10px;
}

#reset-button:hover {
    background-color: #555;
    transform: scale(1.05);
}

#hint-button:hover {
    background-color: #fb8c00;
    transform: scale(1.05);
}

/* Shake animation */
@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-5px); }
  100% { transform: translateX(0); }
}

#game-board.shake {
  animation: shake 0.4s;
}

/* Responsive adjustments */
@media (max-width: 700px) {
    #game-board {
        max-width: 100%;        /* On smaller screens, allow board to fill width */
        grid-gap: 8px;
        padding: 8px;
    }
    .card {
        font-size: clamp(1.2rem, 4vw, 2rem);
    }
}

@media (max-width: 480px) {
    #game-board {
        grid-gap: 6px;
        padding: 6px;
    }
    .card {
        font-size: 1.1rem;
    }
    #tries {
        font-size: 1.2rem;
    }
    button {
        padding: 10px 16px;
        font-size: 0.9rem;
    }
}