@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Open+Sans:wght@400;700&display=swap');

:root {
    --primary-color: #4CAF50; /* Green */
    --secondary-color: #FFC107; /* Amber */
    --accent-color: #2196F3; /* Blue */
    --card-back-color: #673AB7; /* Deep Purple */
    --text-color: #333;
    --dialogue-bg-color: #FFF;
    --font-header: 'Fredoka One', cursive;
    --font-body: 'Open Sans', sans-serif;
}

body {
    margin: 0;
    font-family: var(--font-body);
    background: linear-gradient(135deg, #8BC34A, #C8E6C9); /* Light green gradient */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: var(--text-color);
    overflow: hidden;
}

.game-container {
    background-color: #f0f8ff; /* Alice Blue */
    border-radius: 25px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 90%;
    width: 900px;
    position: relative;
    overflow: hidden;
    margin: 20px 0;
}

h1 {
    font-family: var(--font-header);
    color: var(--primary-color);
    font-size: 3em;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.professor-area {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: flex-end; /* Professor on the right side */
    align-items: flex-start;
    margin-bottom: 20px;
    min-height: 150px; /* Ensure space for professor */
}

#professor-bubbles {
    width: 150px;
    height: auto;
    position: absolute;
    right: 0;
    bottom: 0; /* Position professor at the bottom of its area */
    transition: transform 0.3s ease-out;
}

#professor-bubbles.talking {
    transform: translateY(-10px) translateX(5px) rotate(5deg);
}


.professor-dialogue {
    background-color: var(--dialogue-bg-color);
    border: 3px solid var(--accent-color);
    border-radius: 20px;
    padding: 15px 20px;
    font-family: var(--font-body);
    font-size: 1.2em;
    color: var(--text-color);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    position: absolute;
    right: 160px; /* Position next to Professor Bubbles */
    top: 20px; /* Adjust vertical position */
    max-width: 250px;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease-out, transform 0.3s ease-out;
    pointer-events: none; /* Make it unclickable */
}

.professor-dialogue.active {
    opacity: 1;
    transform: translateY(0);
}

.professor-dialogue::after {
    content: '';
    position: absolute;
    right: -15px; /* Point towards professor */
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
    width: 20px;
    height: 20px;
    background-color: var(--dialogue-bg-color);
    border-right: 3px solid var(--accent-color);
    border-top: 3px solid var(--accent-color);
}


.game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* 4 columns for 8 pairs = 16 cards */
    gap: 15px;
    perspective: 1000px; /* For 3D flip effect */
    width: 100%;
    max-width: 700px; /* Max width for the card grid */
    margin: 0 auto;
}

.card {
    background-color: var(--card-back-color);
    height: 120px; /* Fixed height for cards */
    border-radius: 15px;
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s ease-in-out;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
}

.card.flip {
    transform: rotateY(180deg);
}

.card.match {
    pointer-events: none; /* Disable clicking matched cards */
}

.card-face, .card-back {
    width: 100%;
    height: 100%;
    position: absolute;
    backface-visibility: hidden;
    border-radius: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    border: 4px solid var(--secondary-color);
}

.card-back {
    background-color: var(--card-back-color);
    background-image: url('card_back.png');
    background-size: cover;
    background-position: center;
    transform: rotateY(0deg);
    border-color: var(--card-back-color);
}

.card-face {
    background-color: #f7f7f7; /* Light background for card face */
    transform: rotateY(180deg);
}

.card-face img {
    max-width: 70%;
    max-height: 70%;
    object-fit: contain;
}

/* Game Overlay */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.game-overlay.hidden {
    display: none;
}

.overlay-content {
    background-color: #FFF;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    transform: scale(0.8);
    opacity: 0;
    animation: popIn 0.5s forwards ease-out;
}

.overlay-content h2 {
    font-family: var(--font-header);
    color: var(--primary-color);
    font-size: 3.5em;
    margin-bottom: 15px;
    text-shadow: 3px 3px 6px rgba(0,0,0,0.1);
}

.overlay-content p {
    font-size: 1.5em;
    color: var(--text-color);
    margin-bottom: 25px;
}

.reward-sticker {
    width: 150px;
    height: auto;
    margin-bottom: 30px;
    animation: bounceIn 1s ease-out forwards;
}

#restart-button {
    background-color: var(--accent-color);
    color: white;
    font-family: var(--font-header);
    font-size: 1.8em;
    padding: 15px 30px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    transition: background-color 0.3s ease, transform 0.2s ease;
}

#restart-button:hover {
    background-color: #1976D2; /* Darker blue */
    transform: translateY(-3px);
}

#restart-button:active {
    transform: translateY(0);
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.5);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes bounceIn {
    0% { transform: scale(0.1); opacity: 0; }
    60% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    h1 {
        font-size: 2.5em;
    }
    .game-board {
        grid-template-columns: repeat(3, 1fr); /* 3 columns for smaller screens */
        gap: 10px;
        max-width: 500px;
    }
    .card {
        height: 100px;
    }
    #professor-bubbles {
        width: 120px;
        right: 0px;
    }
    .professor-dialogue {
        font-size: 1em;
        padding: 10px 15px;
        right: 125px;
        max-width: 200px;
        top: 10px;
    }
    .professor-dialogue::after {
        right: -10px;
        width: 15px;
        height: 15px;
    }
    .overlay-content h2 {
        font-size: 2.5em;
    }
    .overlay-content p {
        font-size: 1.2em;
    }
    .reward-sticker {
        width: 120px;
    }
    #restart-button {
        font-size: 1.5em;
        padding: 12px 25px;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 2em;
    }
    .game-container {
        padding: 20px;
        margin: 10px 0;
    }
    .game-board {
        grid-template-columns: repeat(3, 1fr); /* Still 3 columns, cards will be smaller */
        gap: 8px;
        max-width: 320px;
    }
    .card {
        height: 80px;
    }
    #professor-bubbles {
        width: 100px;
        right: 0px;
        bottom: -10px;
    }
    .professor-dialogue {
        font-size: 0.9em;
        padding: 8px 12px;
        right: 105px;
        max-width: 150px;
        top: 5px;
    }
    .overlay-content h2 {
        font-size: 2em;
    }
    .overlay-content p {
        font-size: 1em;
    }
    .reward-sticker {
        width: 100px;
    }
    #restart-button {
        font-size: 1.2em;
        padding: 10px 20px;
    }
}

