/* Custom styles for the memory game */
body {
    margin: 0;
    padding: 0;
    font-family: 'Gochi Hand', cursive; /* Fun, kid-friendly font for general text */
    background: linear-gradient(135deg, #A8DCEC 0%, #E0F2F7 50%, #FFE0B2 100%); /* Softer sky, light, and sand colors */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh; /* Ensure it takes full viewport height */
    color: #333;
    text-align: center;
}

/* --- Back to Homepage Icon Button Styling --- */
.back-to-home-icon {
    position: absolute;
    top: 20px;
    left: 20px;
    color: #777; /* Soft grey color for the icon */
    padding: 10px; /* Padding around the icon */
    border-radius: 50%; /* Make it circular */
    text-decoration: none;
    display: flex; /* Use flex to center the SVG inside */
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease-in-out;
    z-index: 101; /* Ensure it's above the game container and overlay */
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); /* Very subtle shadow */
    background-color: rgba(255, 255, 255, 0.7); /* Slightly transparent white background */
}

.back-to-home-icon:hover {
    color: #555; /* Darker grey on hover */
    transform: translateY(-2px); /* Slight lift */
    box-shadow: 0 4px 8px rgba(0,0,0,0.15); /* Slightly more prominent shadow on hover */
}

.back-to-home-icon:active {
    transform: translateY(1px); /* Press down effect */
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.back-to-home-icon svg {
    width: 28px; /* Size of the SVG icon */
    height: 28px;
    fill: currentColor; /* Make SVG fill color inherit from parent 'color' property */
}
/* --- End Back to Homepage Icon Button Styling --- */

.game-container {
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 25px;
    padding: 2rem; /* Reduced padding slightly to save space */
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2); /* More prominent shadow */
    text-align: center;
    max-width: 900px; /* Increased max-width */
    width: 95%; /* Make it take 95% of screen width */
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    border: 8px solid #FF8A80; /* Softer red border */
    box-sizing: border-box; /* Include padding and border in element's total width and height */
    /* Added min-height to ensure it takes up enough space, but allows growth */
    min-height: 85vh; /* Adjusted to fit content better on smaller screens */
    justify-content: space-between; /* Distribute space vertically */
}

h1 {
    font-family: 'Chewy', cursive; /* Fun, kid-friendly font for title */
    color: #FF8A80; /* Matching the border */
    font-size: clamp(2.5em, 5vw, 3.5em); /* More responsive for title */
    margin-bottom: 1rem; /* Reduced margin */
    font-weight: 700;
    text-shadow: 3px 3px 0 #FFF, 5px 5px 0 #FFECB3; /* Softer gold outline */
    letter-spacing: 2px;
}

.game-info {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 600px;
    margin-bottom: 1rem; /* Reduced margin */
    font-size: clamp(1.2em, 2vw, 1.6em); /* Responsive font size */
    color: #81C784; /* Softer green for info */
    font-weight: 700;
    padding: 8px 15px;
    background-color: rgba(255, 255, 255, 0.85);
    border-radius: 15px;
    border: 2px dashed #81C784;
}

.game-board {
    display: grid;
    gap: 0.8rem; /* Slightly reduced gap between cards */
    padding: 0.8rem; /* Slightly reduced padding */
    background-color: #f0f8ff; /* Light background for board */
    border-radius: 15px;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.05);
    max-width: 100%;
    margin-bottom: 1rem; /* Reduced margin */
    transition: all 0.3s ease-in-out; /* Smooth transition for board changes */
    flex-grow: 1; /* Allows the board to take up available space */
    display: flex; /* Use flexbox for dynamic card sizing within the grid */
    flex-wrap: wrap; /* Allow cards to wrap */
    justify-content: center; /* Center cards in the board */
    align-content: center; /* Center rows of cards */
    overflow-y: auto; /* Add scroll if content exceeds height */
    max-height: 60vh; /* Set a max height for the board to prevent it from pushing the button off-screen */
}

/* Card styling */
.card {
    width: 90px; /* Slightly reduced base card size */
    height: 90px;
    background-color: #FFC0CB; /* Soft pink back */
    border-radius: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3rem; /* Slightly reduced emoji size */
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 0.6s, background-color 0.3s;
    position: relative;
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.15);
    border: 4px solid #FF8A80; /* Matching softer red border */
    flex-shrink: 0; /* Prevent cards from shrinking below their size */
}

.card.flipped {
    transform: rotateY(180deg);
    background-color: #D4EDDA; /* Soft green when flipped */
    border-color: #4CAF50; /* Green border when flipped */
}

.card.matched {
    background-color: #B2EBF2; /* Soft blue when matched */
    border-color: #1E90FF; /* Blue border when matched */
    pointer-events: none; /* Disable clicks on matched cards */
    animation: pulse 1s infinite alternate; /* Subtle pulse for matched cards */
}

.card .front-face,
.card .back-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 15px;
}

.card .front-face {
    transform: rotateY(180deg);
    background-color: #D4EDDA; /* Front face color */
    color: #333; /* Emoji color */
}

.card .back-face {
    background-color: #FFC0CB; /* Back face color */
    border: 4px solid #FF8A80; /* Matching softer red border */
    font-size: 2rem; /* Question mark size */
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
}

/* Responsive card sizing */
@media (max-width: 768px) {
    .card {
        width: 75px; /* Further reduced for tablets */
        height: 75px;
        font-size: 2.5rem;
    }
    h1 {
        font-size: 2rem;
    }
    .game-info {
        font-size: 1.1rem;
    }
    .game-container {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .card {
        width: 60px; /* Further reduced for mobile */
        height: 60px;
        font-size: 1.8rem;
    }
    h1 {
        font-size: 1.6rem;
        margin-bottom: 0.8rem;
    }
    .game-info {
        font-size: 0.9rem;
        margin-bottom: 0.8rem;
    }
    .game-container {
        padding: 0.8rem;
    }
}

/* Button styling (adapted from addition game for consistency) */
.game-button {
    background-color: #81C780; /* Soft green */
    color: white;
    padding: clamp(12px, 3vw, 20px) clamp(25px, 7vw, 40px); /* Adjusted padding */
    font-size: clamp(1.6em, 3.5vw, 2.2em); /* Adjusted font size */
    border: none;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 10px 0 #5CB85C; /* Darker green shadow */
    transition: all 0.2s ease-in-out;
    font-family: 'Chewy', cursive;
    margin-top: 1.5rem; /* Ensure consistent margin from elements above */
    flex-shrink: 0; /* Prevent button from shrinking */
}

.game-button:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 0 #5CB85C;
}

.game-button:active {
    transform: translateY(5px);
    box-shadow: 0 5px 0 #5CB85C;
}

/* Message box styling */
.message-box {
    background-color: #FFECB3; /* Soft yellow */
    color: #6A5ACD; /* Deep purple text */
    border: 2px solid #FFDDAA;
    border-radius: 15px;
    padding: 0.8rem 1.5rem; /* Adjusted padding */
    margin-top: 1rem; /* Adjusted margin */
    font-size: clamp(1em, 1.8vw, 1.4em); /* Adjusted font size */
    font-weight: 700;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
    position: absolute;
    bottom: 10px; /* Position at the bottom, adjusted */
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 10;
    min-width: 200px; /* Adjusted min-width */
    max-width: 70%; /* Adjusted max-width */
    font-family: 'Gochi Hand', cursive;
}

.message-box.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Modal styling (adapted from addition game for consistency) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(173, 216, 230, 0.95); /* Soft blue transparent background */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: linear-gradient(135deg, #FFECB3 0%, #FFDDAA 100%); /* Soft yellow/orange gradient */
    border-radius: 20px;
    padding: 2.5rem; /* Adjusted padding */
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
    text-align: center;
    transform: scale(0.8);
    transition: transform 0.3s ease;
    max-width: 90%;
    border: 8px solid #FF8A80; /* Matching border */
}

.modal-overlay.show .modal-content {
    transform: scale(1);
}

.modal-content h2 {
    font-family: 'Chewy', cursive;
    font-size: clamp(2em, 4vw, 3em); /* Adjusted font size */
    color: #FF8A80;
    margin-bottom: 1rem; /* Adjusted margin */
    text-shadow: 3px 3px 0 #FFF, 5px 5px 0 #FFECB3;
}

.modal-content p {
    font-family: 'Gochi Hand', cursive;
    font-size: clamp(1.2em, 2vw, 1.6em); /* Adjusted font size */
    color: #555;
    margin-bottom: 1.5rem; /* Adjusted margin */
    font-weight: 700;
}

.modal-button {
    background-color: #FFAB91; /* Soft orange/red */
    color: white;
    padding: clamp(12px, 3vw, 20px) clamp(25px, 7vw, 40px); /* Adjusted padding */
    font-size: clamp(1.6em, 3.5vw, 2.2em); /* Adjusted font size */
    border: none;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 0 10px 0 #FF8A65; /* Darker orange/red shadow */
    transition: all 0.2s ease-in-out;
    font-family: 'Chewy', cursive;
}

.modal-button:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 0 #FF8A65;
}

.modal-button:active {
    transform: translateY(5px);
    box-shadow: 0 5px 0 #FF8A65;
}

/* Keyframe animations */
@keyframes pulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.03); }
}
