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

:root {
    --primary-color: #4CAF50; /* Green for success */
    --secondary-color: #FFC107; /* Yellow for highlights */
    --accent-color: #2196F3; /* Blue for buttons */
    --text-color: #333;
    --background-light: #e0f7fa; /* Light blue sky */
    --background-dark: #81C784; /* Green grass */
    --card-background: #ffffff;
    --shadow-light: rgba(0, 0, 0, 0.1);
    --shadow-strong: rgba(0, 0, 0, 0.2);
}

body {
    font-family: 'Open Sans', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background: linear-gradient(to bottom, var(--background-light) 0%, var(--background-light) 60%, var(--background-dark) 100%);
    color: var(--text-color);
    overflow: hidden;
    position: relative;
}

.game-wrapper {
    display: flex;
    flex-direction: column;
    width: 95%;
    max-width: 1200px;
    min-height: 90vh;
    background-color: rgba(255, 255, 255, 0.8);
    border-radius: 25px;
    box-shadow: 0 15px 30px var(--shadow-strong);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    background-color: #81C784; /* A lighter green for header */
    border-radius: 15px;
    margin-bottom: 20px;
    box-shadow: 0 5px 15px var(--shadow-light);
    color: white;
}

.game-title {
    font-family: 'Fredoka One', cursive;
    font-size: 2.5em;
    color: #FFEB3B; /* Bright yellow */
    text-shadow: 2px 2px #F44336; /* Red shadow */
}

.player-info {
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 1.2em;
    font-weight: bold;
    color: #FFF;
    text-shadow: 1px 1px #333;
}

.knowledge-crystal-container {
    display: flex;
    gap: 2px;
    position: relative;
    padding: 5px;
    border-radius: 5px;
    background-color: rgba(0,0,0,0.1);
}

.crystal-shard {
    width: 15px;
    height: 25px;
    background-color: #B0BEC5; /* Grey for inactive */
    clip-path: polygon(50% 0%, 100% 30%, 100% 70%, 50% 100%, 0% 70%, 0% 30%);
    transition: background-color 0.5s ease-in-out;
}

.crystal-shard.restored {
    background-color: #00BCD4; /* Cyan for restored */
    box-shadow: 0 0 8px #00BCD4, 0 0 15px #00BCD4;
}

.crystal-core {
    width: 30px;
    height: 30px;
    background-color: #9E9E9E; /* Grey for inactive core */
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 1s ease-in-out, background-color 1s ease-in-out;
    box-shadow: 0 0 15px #00BCD4;
}

.crystal-core.restored {
    background-color: #00BCD4;
    opacity: 1;
}

.game-area {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Align content to the top */
    padding: 20px;
    position: relative;
}

.character-spark {
    position: absolute;
    top: 50px; /* Adjust as needed */
    left: 20px; /* Adjust as needed */
    width: 120px;
    height: 120px;
    background-color: #FFEB3B; /* Spark's body color */
    border-radius: 50%;
    border: 4px solid #FFC107;
    box-shadow: 0 0 15px rgba(255, 255, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Fredoka One', cursive;
    color: #333;
    font-size: 1.5em;
    animation: floatSpark 3s ease-in-out infinite alternate;
    z-index: 10;
}

.spark-bubble {
    position: absolute;
    top: -60px;
    left: 100%;
    background-color: white;
    border: 2px solid var(--accent-color);
    border-radius: 15px;
    padding: 10px 15px;
    width: 200px;
    text-align: left;
    font-size: 0.9em;
    font-family: 'Open Sans', sans-serif;
    color: var(--text-color);
    box-shadow: 0 5px 10px var(--shadow-light);
    opacity: 0;
    transform: translateY(10px);
    animation: fadeInBubble 0.5s forwards;
}

.spark-bubble::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 20px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid var(--accent-color);
}

@keyframes floatSpark {
    0% { transform: translateY(0); }
    100% { transform: translateY(-15px); }
}

@keyframes fadeInBubble {
    to { opacity: 1; transform: translateY(0); }
}

.game-section {
    display: none; /* Hide all game sections by default */
    width: 100%;
}

.game-section.active {
    display: block; /* Only show active game section */
}

.mission-card {
    background-color: var(--card-background);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 10px 20px var(--shadow-strong);
    text-align: center;
    max-width: 700px;
    width: 80%;
    margin: 50px auto;
    border: 5px solid var(--secondary-color);
    position: relative;
    z-index: 5;
}

h2 {
    font-family: 'Fredoka One', cursive;
    color: #FF7043; /* Orange-red */
    margin-bottom: 15px;
    font-size: 2.2em;
}

p.mission-text {
    font-size: 1.2em;
    margin-bottom: 25px;
    color: #4CAF50; /* Green text */
    line-height: 1.5;
}

/* Lost Apples Specific Styles */
.apples-container {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 30px;
    margin-bottom: 30px;
    min-height: 180px;
    perspective: 1000px; /* For 3D transformations */
}

.apple {
    width: 80px;
    height: 80px;
    background-color: #EF5350; /* Red apple */
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.8em;
    color: white;
    cursor: pointer;
    box-shadow: 0 5px 10px var(--shadow-strong) inset, 0 5px 10px var(--shadow-light);
    transition: transform 0.2s ease-in-out, background-color 0.2s;
    position: relative;
    border: 3px solid #C62828;
}

.apple::before { /* Stem */
    content: '';
    position: absolute;
    top: 5px;
    left: 50%;
    transform: translateX(-50%) rotate(15deg);
    width: 8px;
    height: 18px;
    background-color: #8BC34A; /* Green stem */
    border-radius: 0 0 5px 5px;
    z-index: 1;
}

.apple::after { /* Leaf */
    content: '';
    position: absolute;
    top: 10px;
    left: calc(50% + 5px);
    width: 15px;
    height: 10px;
    background-color: #689F38;
    border-radius: 50% 0;
    transform: rotate(30deg);
    z-index: 1;
}

.apple.tapped {
    background-color: #AED581; /* Lighter green when tapped */
    transform: scale(1.1) translateY(-15px) rotateY(15deg); /* Jump and slight rotate effect */
    box-shadow: 0 0 15px var(--primary-color) inset, 0 0 15px var(--shadow-strong);
}

/* Matching Game Specific Styles */
.matching-game-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* 4 columns for cards */
    gap: 15px;
    margin: 30px auto;
    max-width: 500px;
}

.matching-card {
    width: 100px;
    height: 100px;
    background-color: #B3E5FC; /* Light blue card back */
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5em; /* For animal emojis */
    cursor: pointer;
    box-shadow: 0 5px 10px var(--shadow-light);
    transition: transform 0.3s ease, background-color 0.3s;
    position: relative;
    transform-style: preserve-3d; /* For flip effect */
}

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

.matching-card.matched {
    background-color: var(--primary-color); /* Green for matched */
    cursor: default;
    pointer-events: none;
}

.matching-card.incorrect {
    background-color: #FFCDD2; /* Light red for incorrect guess */
}

.matching-card .card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
}

.matching-card .card-back {
    background-color: #B3E5FC;
    transform: rotateY(0deg);
    font-family: 'Fredoka One', cursive;
    font-size: 1.5em;
    color: var(--accent-color);
}

.matching-card .card-front {
    background-color: #FFF;
    transform: rotateY(180deg);
    color: var(--text-color);
    border: 2px solid var(--accent-color);
}


.feedback-area {
    margin-top: 20px;
}

input {
    padding: 12px 18px;
    font-size: 1.2em;
    border: 2px solid var(--accent-color);
    border-radius: 10px;
    width: 180px;
    text-align: center;
    margin-right: 15px;
    outline: none;
    transition: border-color 0.2s;
}

input:focus {
    border-color: #FFC107;
}

button {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 12px 25px;
    font-size: 1.2em;
    border-radius: 10px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s ease-out;
    box-shadow: 0 4px 8px var(--shadow-light);
}

button:hover {
    background-color: #1976D2;
    transform: translateY(-2px);
}

button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px var(--shadow-light);
}

button:disabled {
    background-color: #B0BEC5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

#message-apples, #message-match {
    margin-top: 15px;
    font-size: 1.4em;
    font-weight: bold;
    min-height: 30px;
    transition: color 0.3s ease-in-out;
}

.correct {
    color: var(--primary-color);
}

.incorrect {
    color: #F44336; /* Red for incorrect */
}

#next-challenge-button {
    margin-top: 30px;
    background-color: #FF9800; /* Orange for next level */
    position: relative;
    left: 50%;
    transform: translateX(-50%);
}

#next-challenge-button:hover {
    background-color: #FB8C00;
}

.hidden {
    display: none !important;
}

.game-footer {
    margin-top: 30px;
    text-align: center;
    font-size: 0.9em;
    color: #616161;
}

/* Firework styles */
@keyframes firework-burst {
    0% { transform: scale(0.1) translate(0, 0); opacity: 1; }
    100% { transform: scale(1) translate(var(--x-offset), var(--y-offset)); opacity: 0; }
}

.firework-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    background-color: var(--color);
    border-radius: 50%;
    animation: firework-burst 0.8s ease-out forwards;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
}

.firework-particle.active {
    opacity: 1;
}
