/* General Styling */
:root {
    --primary-color: #29B6F6; /* Light Blue */
    --secondary-color: #FFCA28; /* Amber */
    --accent-color: #66BB6A; /* Green */
    --danger-color: #EF5350; /* Red */
    --bg-color: #F0F8FF; /* Alice Blue */
    --text-color: #333;
    --font-primary: 'Fredoka One', cursive;
    --font-secondary: 'Nunito', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-secondary);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 20px;
}

.main-container {
    width: 100%;
    max-width: 900px;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    padding: 20px 30px;
    overflow: hidden;
}

header {
    text-align: center;
    margin-bottom: 20px;
    border-bottom: 2px dashed var(--primary-color);
    padding-bottom: 20px;
}

header h1 {
    font-family: var(--font-primary);
    color: var(--primary-color);
    font-size: 2.5rem;
    text-shadow: 2px 2px #fff, 4px 4px var(--secondary-color);
}

nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}

.nav-button {
    font-family: var(--font-secondary);
    font-weight: 700;
    padding: 10px 15px;
    border: none;
    border-radius: 25px;
    background-color: #E3F2FD;
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.nav-button:hover {
    background-color: var(--secondary-color);
    color: #fff;
    transform: translateY(-3px);
}

.nav-button.active {
    background-color: var(--primary-color);
    color: #fff;
    box-shadow: 0 4px 10px rgba(41, 182, 246, 0.4);
}

main {
    padding-top: 20px;
}

.feature-page {
    display: none;
    animation: fadeIn 0.5s ease;
    text-align: center;
}

.feature-page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

h2 {
    font-family: var(--font-primary);
    color: var(--accent-color);
    margin-bottom: 15px;
}

p {
    margin-bottom: 20px;
    color: #555;
}

.input-group, .quiz-area, .arrange-digits-answers {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

input[type="number"], input[type="text"] {
    padding: 12px;
    border-radius: 10px;
    border: 2px solid #ddd;
    font-size: 1.2rem;
    text-align: center;
    width: 100%;
    max-width: 300px;
    transition: border-color 0.3s;
}

input:focus {
    outline: none;
    border-color: var(--primary-color);
}

button {
    padding: 12px 25px;
    border: none;
    border-radius: 10px;
    background-color: var(--accent-color);
    color: white;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
}

button:hover {
    background-color: #57a95b;
    transform: scale(1.05);
}

/* 1. Place Value */
.place-value-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
}

.place-value-box {
    padding: 20px;
    border-radius: 15px;
    color: white;
    text-align: center;
    min-width: 100px;
}

.place-value-box .label {
    font-size: 0.9rem;
    font-weight: 700;
    display: block;
    margin-bottom: 5px;
}

.place-value-box .digit {
    font-family: var(--font-primary);
    font-size: 2rem;
}

/* 2. Calculator */
.calculator {
    max-width: 320px;
    margin: 0 auto;
    border: 5px solid #ccc;
    border-radius: 15px;
    padding: 15px;
    background: #f9f9f9;
}

.calculator-display {
    background-color: #222;
    color: #fff;
    font-size: 2.5rem;
    padding: 20px;
    text-align: right;
    border-radius: 10px;
    margin-bottom: 15px;
    font-family: var(--font-primary);
}

.calculator-keys {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.calculator-keys button {
    padding: 20px;
    font-size: 1.5rem;
    border-radius: 10px;
    background: #e0e0e0;
    color: #333;
}

.calculator-keys button:hover {
    background: #d5d5d5;
}

.calculator-keys button[data-action] {
    background: var(--secondary-color);
    color: #fff;
}

.calculator-keys button.equal-sign {
    grid-column: span 2;
    background: var(--primary-color);
}

/* 3. Quiz */
.quiz-controls { margin-bottom: 20px; display: flex; gap: 10px; justify-content: center; align-items: center; }
.quiz-op-btn { min-width: 50px; }
#quizProblem { font-size: 2rem; font-family: var(--font-primary); margin: 20px 0; color: var(--text-color); }
#quizFeedback { font-size: 1.5rem; font-weight: 700; margin-top: 15px; height: 30px; }
.correct { color: var(--accent-color); animation: bounce 0.5s ease; }
.incorrect { color: var(--danger-color); animation: shake 0.5s ease; }

@keyframes bounce { 0%, 20%, 50%, 80%, 100% {transform: translateY(0);} 40% {transform: translateY(-20px);} 60% {transform: translateY(-10px);} }
@keyframes shake { 0%, 100% {transform: translateX(0);} 10%, 30%, 50%, 70%, 90% {transform: translateX(-10px);} 20%, 40%, 60%, 80% {transform: translateX(10px);} }

/* 4. AI Guru */
.chat-container { max-width: 600px; margin: auto; border: 2px solid #eee; border-radius: 15px; padding: 15px; }
.chat-box { height: 300px; overflow-y: auto; margin-bottom: 15px; padding: 10px; background: #f9f9f9; border-radius: 10px; }
.chat-message { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 15px; max-width: 80%; }
.chat-message .avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.chat-message p { padding: 12px; border-radius: 15px; margin: 0; }
.chat-message.user { margin-left: auto; flex-direction: row-reverse; }
.chat-message.user p { background-color: var(--primary-color); color: white; border-bottom-right-radius: 0; }
.chat-message.ai p { background-color: #e9e9eb; color: #333; border-bottom-left-radius: 0; }
.chat-input-area { display: flex; gap: 10px; }
#aiUserInput { flex-grow: 1; text-align: left; }
#aiSendBtn { flex-shrink: 0; }

/* 5 & 8. Number Display */
.number-display {
    font-size: 2.5rem;
    font-family: var(--font-primary);
    padding: 20px;
    background: var(--secondary-color);
    color: white;
    border-radius: 15px;
    display: inline-block;
    margin-bottom: 20px;
}

/* 6. Sort Numbers */
.number-container {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: center;
    min-height: 80px;
    padding: 15px;
    background: #eee;
    border-radius: 10px;
    margin-bottom: 15px;
}
.number-container.sorted { background: #d4edda; }
.sort-number-item {
    width: 60px;
    height: 60px;
    background: var(--primary-color);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    font-family: var(--font-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
}
.sort-number-item:hover { transform: scale(1.1); }
.sort-number-item.clicked { background-color: #aaa; cursor: not-allowed; }

/* 7. Balloon Game */
.game-area {
    position: relative;
    width: 100%;
    height: 400px;
    background: linear-gradient(to top, #87CEEB, #B0E0E6);
    border-radius: 15px;
    overflow: hidden;
    margin-top: 15px;
}
.game-stats { display: flex; justify-content: space-around; font-size: 1.2rem; font-weight: 700; }
.balloon {
    position: absolute;
    width: 80px;
    height: 100px;
    background-color: var(--danger-color);
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 1.5rem;
    font-family: var(--font-primary);
    cursor: pointer;
    animation: floatUp 10s linear infinite;
    bottom: -100px;
}
.balloon::after {
    content: '';
    position: absolute;
    bottom: -10px;
    width: 2px;
    height: 20px;
    background: #555;
}
@keyframes floatUp {
    to { transform: translateY(-550px); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-container {
        padding: 15px;
    }
    header h1 {
        font-size: 2rem;
    }
    nav {
        gap: 5px;
    }
    .nav-button {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    .input-group {
        flex-direction: column;
    }
}
