@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800&display=swap');

:root {
    --primary-color: #f72585; /* Vibrant Fuchsia */
    --secondary-color: #7209b7; /* Deep Purple */
    --accent-color: #4cc9f0; /* Glowing Cyan */
    --gold-accent: #fee440; /* Stardust Gold */
    --background-color: #10002b; /* Dark Magic Night */
    --card-bg: rgba(255, 255, 255, 0.95); /* Bright frosted glass for text readability */
    --text-main: #240046; /* Very Dark Purple for contrast inside cards */
    --text-muted: #5a189a;
    --success-color: #4cc9f0;
    --error-color: #f72585;
    --border-radius: 30px; 
    --shadow: 0 15px 35px rgba(114, 9, 183, 0.4);
    --fairy-glow: 0 0 20px rgba(247, 37, 133, 0.8), 0 0 40px rgba(76, 201, 240, 0.4);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Cairo', sans-serif;
}

body {
    background-color: var(--background-color);
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(114, 9, 183, 0.6), transparent 600px),
        radial-gradient(circle at 85% 30%, rgba(247, 37, 133, 0.5), transparent 600px),
        url("data:image/svg+xml,%3Csvg width='200' height='200' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='10' cy='10' r='1.5' fill='%23fee440' opacity='0.7'/%3E%3Ccircle cx='90' cy='60' r='2' fill='%234cc9f0' opacity='0.5'/%3E%3Ccircle cx='150' cy='130' r='1.5' fill='%23f72585' opacity='0.8'/%3E%3C/svg%3E");
    background-size: auto, auto, 300px 300px;
    background-attachment: fixed;
    animation: breathingBackground 15s ease-in-out infinite alternate;
    color: var(--text-main);
    direction: rtl;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

@keyframes breathingBackground {
    0% { background-position: 0% 0%, 0% 0%, 0 0; }
    100% { background-position: 5% 5%, -5% 5%, 0 50px; }
}

/* Header & Gamification */
.fairy-header {
    background: linear-gradient(135deg, rgba(74, 20, 140, 0.8), rgba(247, 37, 133, 0.4));
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 0 40px rgba(247, 37, 133, 0.2);
    backdrop-filter: blur(20px);
    border-bottom: 2px solid rgba(255, 182, 193, 0.3);
    border-bottom-left-radius: 30px;
    border-bottom-right-radius: 30px;
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 15px;
}
.fairy-header .header-actions { order: 1; }
.fairy-header .fairy-title { order: 2; flex: 1; justify-content: center; text-align: center; }
.fairy-header .user-profile { order: 3; }

.logo-area {
    display: flex;
    align-items: center;
    gap: 15px;
}

.fairy-icon {
    font-size: 9rem;
    filter: drop-shadow(0 0 15px rgba(255, 255, 255, 0.8));
    animation: floatIcon 3s ease-in-out infinite;
}

@keyframes floatIcon {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-10px) rotate(10deg); }
}

.magical-title {
    font-size: clamp(1.5rem, 4vw, 2.2rem); /* Responsive font size */
    margin: 0;
    background: linear-gradient(to right, #ff9a9e 0%, #fecfef 99%, #fecfef 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 2px 15px rgba(255, 154, 158, 0.4);
    font-weight: 900;
}

.user-avatar-wrapper {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #f72585, #4cc9f0);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 15px rgba(247, 37, 133, 0.6);
    border: 3px solid #fff;
    cursor: pointer;
    transition: transform 0.3s;
}
.user-avatar-wrapper i {
    font-size: 2rem;
    color: #fff;
}
.user-avatar-wrapper:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 0 25px rgba(76, 201, 240, 0.8);
}

.btn-magical-back {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 25px;
    background: linear-gradient(135deg, #f72585, #7209b7);
    color: white !important;
    text-decoration: none !important;
    border-radius: 50px;
    font-weight: 800;
    font-size: 1.1rem;
    box-shadow: 0 4px 15px rgba(247, 37, 133, 0.5);
    border: 2px solid rgba(255,255,255,0.2);
    transition: all 0.3s ease;
}
.btn-magical-back:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 25px rgba(247, 37, 133, 0.8);
    background: linear-gradient(135deg, #7209b7, #f72585);
}
.btn-magical-back i {
    font-size: 1.3rem;
}

.gamification {
    display: flex;
    align-items: center;
    gap: 15px;
    background: #FFF;
    padding: 0.5rem 1rem;
    border-radius: 30px;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.05);
    border: 2px solid var(--accent-color);
}

.star-icon {
    color: #FFD700;
    font-size: 1.5rem;
    animation: pulse 2s infinite;
}

.score-text {
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--text-main);
}

/* Main Layout */
.container {
    display: flex;
    flex: 1;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    padding: 2rem;
    gap: 2rem;
}

/* Sidebar */
.sidebar-panel {
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.mascot-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Curriculum Nav */
.curriculum-nav {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid rgba(255,255,255,0.5);
    backdrop-filter: blur(10px);
}

.nav-title {
    color: var(--secondary-color);
    font-size: 1.3rem;
    margin-bottom: 1rem;
    border-bottom: 2px dashed rgba(46,196,182,0.3);
    padding-bottom: 0.8rem;
}

.nav-chapter {
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 1rem;
    margin-top: 1.5rem; /* Space between chapters */
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.nav-chapter:first-child {
    margin-top: 0;
}

.nav-lessons-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.nav-lesson-item {
    padding: 1rem 1.5rem;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 20px; /* Rounded box feel */
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 700;
    color: var(--text-main);
    border: 2px solid rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    gap: 0.8rem;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

.nav-lesson-item::before {
    content: '';
    position: absolute;
    top: -50%; left: -50%; right: -50%; bottom: -50%;
    background: linear-gradient(135deg, rgba(255,255,255,0.4), transparent);
    opacity: 0;
    transition: opacity 0.4s;
    transform: rotate(45deg);
}

.nav-lesson-item:hover {
    border-color: var(--accent-color);
    color: var(--primary-color);
    transform: translateX(-5px) scale(1.02);
    box-shadow: var(--fairy-glow);
}
.nav-lesson-item:hover::before {
    opacity: 1;
}

.nav-lesson-item.active {
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
    color: white;
    border-color: transparent;
    box-shadow: var(--fairy-glow);
}
.nav-lesson-item.active i {
    color: #FFF;
}

.emoji-mascot {
    width: 150px;
    height: 150px;
    background: linear-gradient(135deg, rgba(255,255,255,0.9), rgba(255,255,255,0.5));
    box-shadow: var(--fairy-glow);
    border: 5px solid var(--accent-color);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 5rem;
    animation: floatMascot 4s ease-in-out infinite, magicGlow 2s infinite alternate;
    backdrop-filter: blur(10px);
}

@keyframes floatMascot {
    0% { transform: translateY(0px) rotate(0deg); }
    50% { transform: translateY(-15px) rotate(5deg); }
    100% { transform: translateY(0px) rotate(0deg); }
}
@keyframes magicGlow {
    0% { box-shadow: 0 0 20px rgba(247, 37, 133, 0.4); }
    100% { box-shadow: 0 0 40px rgba(76, 201, 240, 0.8); }
}

.mascot-message {
    background: white;
    padding: 1rem;
    border-radius: var(--border-radius);
    margin-top: 1rem;
    text-align: center;
    box-shadow: var(--shadow);
    position: relative;
    font-weight: 600;
    color: var(--secondary-color);
}
.mascot-message::before {
    content: '';
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 0 10px 10px 10px;
    border-style: solid;
    border-color: transparent transparent white transparent;
}

/* Content Area */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Navigation Tabs */
.tabs {
    display: flex;
    gap: 1rem;
    background: var(--card-bg);
    padding: 0.5rem;
    border-radius: 50px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.tab-btn {
    flex: 1;
    padding: 1rem;
    border: none;
    border-radius: 50px;
    background: transparent;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.3s ease;
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
    color: white;
    box-shadow: var(--fairy-glow);
}

.tab-btn:hover:not(.active) {
    background: rgba(206, 147, 216, 0.15);
    color: var(--text-main);
}

/* Cards */
.card {
    background: var(--card-bg);
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10 10 Q 25 25 10 40' stroke='%23ce93d8' stroke-width='1' fill='none' opacity='0.3'/%3E%3Ccircle cx='50' cy='50' r='2' fill='%23f48fb1' opacity='0.3'/%3E%3C/svg%3E");
    border-radius: var(--border-radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    transition: transform 0.3s ease;
    border: 2px solid rgba(244, 143, 177, 0.3);
    display: none;
    animation: fadeIn 0.5s ease forwards;
}

.card.active {
    display: block;
}

.card-title {
    color: var(--secondary-color);
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
    border-bottom: 3px dashed rgba(46,196,182,0.3);
    padding-bottom: 0.5rem;
    display: inline-block;
}

/* Explanation Section */
.explanation-block {
    background: white;
    padding: 1.5rem;
    border-radius: 15px;
    margin-bottom: 1rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.02);
    border-right: 5px solid var(--primary-color);
    font-size: 1.2rem;
    line-height: 1.8;
}
.highlight-block {
    background: #FFF9E6;
    border-right-color: #FFD700;
    font-weight: bold;
}

/* Vocabulary */
.vocab-container {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-top: 1rem;
}
.vocab-tag {
    background: var(--secondary-color);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 50px;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(46,196,182,0.3);
}

/* Exercises */
.exercise {
    background: white;
    border-radius: 15px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 2px solid #E2E8F0;
    transition: border-color 0.3s;
}
.exercise:hover {
    border-color: var(--primary-color);
}

.exercise-prompt {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 1rem;
}

/* Pattern Sequence */
.pattern-sequence {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    direction: ltr; /* Render LTR visually, but logical right-to-left in data */
    justify-content: center;
}

.pattern-item {
    padding: clamp(0.5rem, 1.5vw, 1rem);
    background: #F8FAFC;
    border-radius: 10px;
    font-size: clamp(1rem, 3vw, 1.5rem);
    font-weight: bold;
    color: var(--secondary-color);
    min-width: 0;
    flex: 1 1 0;
    text-align: center;
    border: 2px solid #E2E8F0;
    white-space: nowrap;
}

.pattern-input {
    width: 100%;
    max-width: 120px;
    min-width: 60px;
    padding: clamp(0.5rem, 1.5vw, 1rem);
    font-size: clamp(1rem, 3vw, 1.5rem);
    text-align: center;
    border: 3px dashed var(--primary-color);
    border-radius: 10px;
    outline: none;
    transition: all 0.3s;
    background: #FFF;
    color: var(--primary-color);
    font-weight: bold;
}

.pattern-input:focus {
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 4px rgba(46,196,182,0.2);
}

.pattern-input.correct {
    border-color: var(--success-color);
    border-style: solid;
    color: var(--success-color);
    background: #F0FDF4;
}

.pattern-input.incorrect {
    border-color: var(--error-color);
    background: #FEF2F2;
    animation: shake 0.5s;
}

.rule-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.2rem;
    background: #F8FAFC;
    padding: 1rem;
    border-radius: 10px;
}
.rule-input {
    width: 100px;
    padding: 0.5rem;
    font-size: 1.2rem;
    text-align: center;
    border: 2px solid #CBD5E1;
    border-radius: 8px;
    outline: none;
}

/* Fill Blanks & Word Problems */
.fill-blanks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}
.fill-item {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.5rem;
    font-size: clamp(0.9rem, 2vw, 1.2rem);
    white-space: nowrap;
}
.fill-input {
    flex: 1;
    padding: 0.8rem;
    font-size: 1.2rem;
    border: 2px solid #CBD5E1;
    border-radius: 8px;
    text-align: center;
    outline: none;
    transition: all 0.3s;
}

/* Vertical Math Layout */
.vertical-math {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-end;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.5rem;
    font-weight: bold;
    line-height: 1.2;
    margin: 0 1rem;
    direction: ltr; /* Numbers should align right/LTR */
}

.math-row {
    display: flex;
    justify-content: flex-end;
    gap: 0.2rem;
}

.math-row span {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 1.5rem;
    height: 1.5rem;
}

.carry-row {
    font-size: 1rem;
    min-height: 1.5rem;
    margin-bottom: 0.2rem;
    align-items: center;
}

.carry-digit {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 1.5rem;
    height: 1.5rem;
    background-color: #3B82F6; /* Blue circle */
    color: white;
    border-radius: 50%;
    font-size: 0.9rem;
    margin: 0;
}

/* Long Division Layout */
.long-division {
    display: inline-table;
    vertical-align: middle;
    text-align: center;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.5rem;
    font-weight: bold;
    direction: ltr; /* Math is LTR */
    margin: 0 10px;
}
.ld-row {
    display: table-row;
}
.ld-quotient {
    display: table-cell;
    padding-bottom: 2px;
}
.ld-dividend {
    display: table-cell;
    border-top: 2px solid var(--text-main);
    border-right: 2px solid var(--text-main);
    padding: 2px 8px 0 8px;
    letter-spacing: 2px;
}
.ld-divisor {
    display: table-cell;
    vertical-align: top;
    padding: 2px 8px 0 8px;
}

/* Fraction Layout */
.fraction {
    display: inline-flex;
    flex-direction: column;
    vertical-align: middle;
    text-align: center;
    font-size: 1.2em;
    font-weight: bold;
    margin: 0 5px;
    line-height: 1.2;
}
.fraction .num {
    border-bottom: 2px solid var(--text-main);
    padding: 0 5px;
}
.fraction .den {
    padding: 0 5px;
}

/* Mixed Number Layout */
.mixed-number {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    direction: rtl;
    vertical-align: middle;
    margin: 0 5px;
}
.mixed-number .whole {
    font-size: 1.4em;
    font-weight: bold;
    color: var(--secondary-color);
}

.op-row {
    position: relative;
}

.op-row .op {
    position: absolute;
    left: -2rem; /* Place operator to the left */
    color: var(--primary-color);
}

.math-divider {
    width: 100%;
    height: 3px;
    background-color: var(--text-main);
    margin: 0.5rem 0;
}

.fill-input.vertical-input {
    width: 100%;
    margin-top: 0;
}

.btn-check {
    background: var(--secondary-color);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(46,196,182,0.3);
    transition: all 0.3s;
    display: block;
    margin: 2rem auto 0;
    width: fit-content;
}
.btn-check:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(46,196,182,0.4);
}

/* Animations */
@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-15px); }
    100% { transform: translateY(0px); }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Fairy Garden Custom Elements */
.lesson-fairy-btn {
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200'%3E%3Cdefs%3E%3CradialGradient id='g2' cx='50%25' cy='50%25' r='50%25'%3E%3Cstop offset='0%25' stop-color='%23ffffff' /%3E%3Cstop offset='40%25' stop-color='%2380deea' /%3E%3Cstop offset='100%25' stop-color='%23b39ddb' /%3E%3C/radialGradient%3E%3CradialGradient id='c1' cx='50%25' cy='50%25' r='50%25'%3E%3Cstop offset='0%25' stop-color='%23fff59d' /%3E%3Cstop offset='100%25' stop-color='%23ffb300' /%3E%3C/radialGradient%3E%3C/defs%3E%3Cg fill='url(%23g2)'%3E%3Ccircle cx='100' cy='55' r='45' /%3E%3Ccircle cx='142.7' cy='86' r='45' /%3E%3Ccircle cx='126.1' cy='136.4' r='45' /%3E%3Ccircle cx='73.9' cy='136.4' r='45' /%3E%3Ccircle cx='57.3' cy='86' r='45' /%3E%3C/g%3E%3Ccircle cx='100' cy='100' r='30' fill='url(%23c1)' /%3E%3C/svg%3E") center/contain no-repeat;
    border: none;
    border-radius: 0; 
    width: 150px;
    height: 150px;
    min-width: unset;
    padding: 0;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
    font-family: var(--font-main);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    position: relative;
    overflow: visible;
    filter: drop-shadow(0 0 15px rgba(76, 201, 240, 0.6));
    margin: 15px;
}
.lesson-fairy-btn::before {
    display: none;
}
.lesson-fairy-btn:hover {
    transform: scale(1.15) translateY(-5px) rotate(-10deg);
    filter: drop-shadow(0 0 35px rgba(76, 201, 240, 0.9));
}
.lesson-fairy-btn:hover::before {
    display: none;
}
.lesson-icon {
    font-size: 2.2rem;
    position: relative;
    color: var(--primary-color);
    filter: drop-shadow(0 4px 5px rgba(0,0,0,0.3));
    transition: transform 0.3s;
}
.lesson-fairy-btn:hover .lesson-icon {
    transform: rotate(10deg) scale(1.1);
}
.lesson-icon .audio-icon {
    position: absolute;
    bottom: -5px;
    right: -10px;
    font-size: 1.5rem;
    color: #fff;
    background: var(--primary-color);
    border-radius: 50%;
    padding: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.lesson-info {
    text-align: right;
    z-index: 1;
}
.lesson-num {
    font-size: 1.2rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.lesson-title {
    font-size: 1rem;
    color: #fff;
    font-weight: bold;
    opacity: 0.95;
    text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.stardust-trail {
    position: absolute;
    top: 50px;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    width: 15px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 100' preserveAspectRatio='none'%3E%3Cpath d='M10,0 C20,25 0,75 10,100' stroke='%23fee440' stroke-width='4' fill='none' stroke-dasharray='10 5'/%3E%3C/svg%3E");
    background-size: 100% 200px;
    filter: drop-shadow(0 0 10px var(--gold-accent));
    z-index: 1;
    opacity: 0.9;
    animation: stardustFlow 3s linear infinite;
}
@keyframes stardustFlow {
    from { background-position: 0 0; }
    to { background-position: 0 200px; }
}

/* Chapter fairy gate */
.chapter-fairy-btn {
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 200'%3E%3Cdefs%3E%3CradialGradient id='g1' cx='50%25' cy='50%25' r='50%25'%3E%3Cstop offset='0%25' stop-color='%23ffffff' /%3E%3Cstop offset='40%25' stop-color='%23f48fb1' /%3E%3Cstop offset='100%25' stop-color='%23ce93d8' /%3E%3C/radialGradient%3E%3CradialGradient id='c1' cx='50%25' cy='50%25' r='50%25'%3E%3Cstop offset='0%25' stop-color='%23fff59d' /%3E%3Cstop offset='100%25' stop-color='%23ffb300' /%3E%3C/radialGradient%3E%3C/defs%3E%3Cg fill='url(%23g1)'%3E%3Ccircle cx='100' cy='55' r='45' /%3E%3Ccircle cx='142.7' cy='86' r='45' /%3E%3Ccircle cx='126.1' cy='136.4' r='45' /%3E%3Ccircle cx='73.9' cy='136.4' r='45' /%3E%3Ccircle cx='57.3' cy='86' r='45' /%3E%3C/g%3E%3Ccircle cx='100' cy='100' r='30' fill='url(%23c1)' /%3E%3C/svg%3E") center/contain no-repeat;
    border: none;
    border-radius: 0;
    width: 160px;
    height: 160px;
    min-width: unset;
    padding: 0;
    cursor: pointer;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
    position: relative;
    overflow: visible;
    filter: drop-shadow(0 0 20px rgba(247, 37, 133, 0.6));
    margin: 15px;
}
.chapter-fairy-btn::before {
    display: none;
}
.chapter-fairy-btn:hover {
    transform: translateY(-15px) scale(1.1) rotate(15deg);
    filter: drop-shadow(0 0 40px rgba(254, 228, 64, 0.9));
}
.chapter-fairy-btn:hover .fairy-gate-icon {
    transform: scale(1.1) rotate(-15deg);
}
.fairy-gate-icon {
    font-size: 3.5rem;
    filter: drop-shadow(0 5px 10px rgba(0,0,0,0.3));
    z-index: 1;
    transition: all 0.4s;
}
.fairy-gate-title {
    font-size: 1.2rem;
    font-weight: 900;
    color: #fff;
    text-shadow: 0 2px 5px rgba(0,0,0,0.8);
    z-index: 1;
    max-width: 180px;
    text-align: center;
    line-height: 1.3;
}

/* Confetti */
.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    background-color: var(--primary-color);
    z-index: 1000;
    pointer-events: none;
    animation: fall 3s linear forwards;
}

@keyframes fall {
    to { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* Responsive */
@media (max-width: 1100px) {
    .container {
        gap: 1.5rem;
        padding: 1.5rem;
    }
    .sidebar-panel {
        width: 280px;
    }
}

@media (max-width: 850px) {
    .container {
        flex-direction: column;
    }
    .sidebar-panel {
        width: 100%;
    }
    .mascot-section {
        flex-direction: row;
        gap: 1.5rem;
        align-items: center;
        background: var(--card-bg);
        padding: 1rem;
        border-radius: var(--border-radius);
        box-shadow: var(--shadow);
    }
    .emoji-mascot {
        width: 90px;
        height: 90px;
        font-size: 3rem;
        flex-shrink: 0;
    }
    .mascot-message {
        margin-top: 0;
        text-align: right;
        flex: 1;
    }
    .mascot-message::before {
        display: none;
    }
    .curriculum-nav {
        margin-top: 0;
    }
    .nav-lessons-list {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 0.5rem;
    }
    .nav-lesson-item {
        padding: 0.6rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }


    .tabs {
        flex-direction: column;
        border-radius: 20px;
    }
    .tab-btn {
        padding: 0.8rem;
        font-size: 1rem;
    }
    .card-title {
        font-size: 1.4rem;
    }
    .nav-lessons-list {
        grid-template-columns: 1fr;
    }
}

/* Visual Fraction Models Container Fix */
div[style*="justify-content:center"] {
    flex-wrap: wrap !important;
    gap: 10px !important;
}

/* Visual Fraction Models */
.fraction-model {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    border: 2px solid var(--text-main);
    height: 40px;
    margin: 10px 5px;
    background-color: white;
    direction: ltr;
    width: fit-content;
    min-width: 100px;
    max-width: 100%;
}
.fraction-model .part {
    border-right: 1px solid var(--text-main);
    height: 100%;
}
.fraction-model .part:last-child {
    border-right: none;
}
.fraction-model .part.shaded {
    background-color: var(--primary-color);
    opacity: 0.8;
}

.models-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 15px;
    width: 100%;
    margin-bottom: 10px;
}

/* 100-Grid Model for Decimals */
.grid-100 {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    width: 180px;
    height: 180px;
    border: 2px solid var(--text-main);
    background-color: var(--text-main);
    gap: 1px;
    margin: 10px auto;
    direction: ltr;
}
.grid-100 .cell {
    background-color: white;
}
.grid-100 .cell.shaded {
    background-color: var(--primary-color);
    opacity: 0.8;
}
.grid-100 .cell.shaded-secondary {
    background-color: var(--secondary-color);
    opacity: 0.8;
}

/* Number Line */
.number-line-container {
    padding: 20px 40px;
    margin: 10px 0;
    position: relative;
    direction: ltr;
}
.number-line {
    height: 4px;
    background-color: var(--text-main);
    position: relative;
    display: flex;
    justify-content: space-between;
}
.number-line::before, .number-line::after {
    content: '';
    position: absolute;
    top: -4px;
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
}
.number-line::before {
    left: -10px;
    border-right: 10px solid var(--text-main);
}
.number-line::after {
    right: -10px;
    border-left: 10px solid var(--text-main);
}
.tick {
    position: relative;
    width: 2px;
    height: 15px;
    background-color: var(--text-main);
    top: -5px;
}
.tick.point::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -6px;
    width: 14px;
    height: 14px;
    background-color: var(--secondary-color);
    border-radius: 50%;
    z-index: 2;
}
.tick-label {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1rem;
    font-weight: bold;
    white-space: nowrap;
}
.tick-letter {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--secondary-color);
    font-weight: bold;
    font-size: 1.2rem;
}

/* Place Value Table for Comparison */
.place-value-table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
    font-size: 1rem;
}
.place-value-table th {
    background-color: var(--primary-color);
    color: white;
    padding: 10px;
    border: 1px solid var(--text-main);
}
.place-value-table td {
    padding: 10px;
    border: 1px solid var(--text-main);
    text-align: center;
    font-weight: bold;
}
.place-value-table .comma-col {
    background-color: #f8f9fa;
    color: var(--secondary-color);
    font-size: 1.4rem;
}

/* Grid Map for Location and Direction */
.grid-map-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin: 15px 0;
}
.grid-map {
    display: grid;
    grid-template-columns: repeat(11, 30px);
    grid-template-rows: repeat(11, 30px);
    border: 2px solid #64748b;
    background-image: 
        linear-gradient(#cbd5e1 1px, transparent 1px),
        linear-gradient(90deg, #cbd5e1 1px, transparent 1px);
    background-size: 30px 30px;
    background-color: white;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    border-radius: 4px;
    direction: ltr;
}
.grid-map .item {
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;
}
.grid-map .label {
    font-size: 10px;
    color: #64748b;
    z-index: 2;
    display: flex;
    justify-content: center;
    align-items: center;
}
.grid-map .path-h {
    border-bottom: 3px solid #ef4444;
    z-index: 1;
}
.grid-map .path-v {
    border-left: 3px solid #ef4444;
    z-index: 1;
}
.grid-map .point-marker {
    width: 10px;
    height: 10px;
    background-color: #ef4444;
    border: 2px solid white;
    border-radius: 50%;
    z-index: 3;
    margin: auto;
}

/* Fractions and Mixed Numbers Styling */
.fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 5px;
    direction: ltr; /* Ensure numbers and fractions are always LTR */
}
.fraction .num {
    padding: 2px 5px;
    line-height: 1.2;
    font-weight: bold;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 25px;
    border-bottom: none !important;
}
.fraction .den {
    padding: 2px 5px;
    border-top: 2px solid var(--text-main);
    line-height: 1.2;
    font-weight: bold;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 25px;
}
.mixed-number {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    direction: ltr;
}
.mixed-number .whole {
    margin-right: 5px; /* LTR margin */
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--text-main);
}
/* Ensure input boxes inside fractions are properly sized and aligned */
.fraction input {
    width: 40px !important;
    height: 30px !important;
    font-size: 1.2rem !important;
    text-align: center !important;
    padding: 0 !important;
    margin: 2px 0 !important;
    border: 2px solid #2EC4B6 !important; /* Secondary color for input borders */
    border-radius: 4px !important;
    color: var(--secondary-color) !important;
}

/* Chapters View (Cakes) Styles */
.chapters-grid {
    padding: 3rem;
    gap: 3rem;
}

.chapter-cake-btn {
    background: #FDF1E7; /* Sponge cake color */
    border: none;
    border-radius: 15px; /* Base of the cake */
    padding: 3.5rem 1.5rem 1.5rem 1.5rem;
    min-width: 200px;
    height: 220px;
    cursor: pointer;
    box-shadow: 0 8px 0 #DABBA6, 0 15px 35px rgba(255, 133, 161, 0.2); /* Cake 3D base */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
}

/* The main frosting at the top */
.chapter-cake-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: var(--primary-color); /* Strawberry frosting */
    border-radius: 15px 15px 0 0;
}

/* Frosting drips using box-shadows on pseudo-element */
.chapter-cake-btn::after {
    content: '';
    position: absolute;
    top: 30px;
    left: 15px;
    width: 30px;
    height: 30px;
    background: var(--primary-color);
    border-radius: 50%;
    box-shadow: 
        45px 5px 0 5px var(--primary-color), 
        90px -5px 0 5px var(--primary-color), 
        135px 10px 0 5px var(--primary-color);
}

.chapter-cake-btn:hover {
    transform: translateY(-10px) scale(1.05);
    box-shadow: 0 12px 0 #DABBA6, 0 25px 45px rgba(255, 133, 161, 0.3);
}

.chapter-cake-btn .cake-icon {
    font-size: 4.5rem;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 5px 5px rgba(0,0,0,0.1));
    z-index: 2; /* To appear above frosting drips if overlapping */
}

.chapter-cake-btn .cake-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-main);
    text-align: center;
    z-index: 2;
}

.btn-back-chapters {
    background: white;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
    padding: 0.8rem 1.5rem;
    border-radius: 50px;
    font-weight: bold;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-back-chapters:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

/* ===================================================================== */
/* BOT UI STYLES                                                         */
/* ===================================================================== */
.bot-floating-btn {
    position: fixed;
    bottom: 30px;
    left: 30px;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--secondary-color), #20c997);
    color: white;
    border: 4px solid white;
    box-shadow: 0 10px 25px rgba(32, 201, 151, 0.4);
    cursor: pointer;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.bot-floating-btn:hover {
    transform: scale(1.1) rotate(10deg);
}
.bot-emoji {
    font-size: 2.5rem;
}
.bot-tooltip {
    position: absolute;
    left: 80px;
    background: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--secondary-color);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    white-space: nowrap;
}
.bot-floating-btn:hover .bot-tooltip {
    opacity: 1;
    visibility: visible;
    left: 90px;
}
.bot-chat-window {
    position: fixed;
    bottom: 110px;
    left: 30px;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 25px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.15);
    z-index: 999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-origin: bottom left;
}
.bot-chat-window.hidden {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}
.bot-chat-header {
    background: linear-gradient(135deg, var(--secondary-color), #20c997);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: white;
}
.bot-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
.bot-header-emoji {
    font-size: 1.8rem;
}
.bot-chat-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 800;
}
#bot-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    transition: transform 0.2s;
}
#bot-close-btn:hover {
    transform: scale(1.2);
}
.bot-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: #f8f9fa;
}
.bot-message, .user-message {
    max-width: 85%;
    padding: 12px 18px;
    border-radius: 20px;
    font-size: 1rem;
    line-height: 1.5;
    animation: fadeIn 0.3s ease;
}
.bot-message {
    align-self: flex-start;
    background: white;
    color: var(--text-main);
    border-bottom-right-radius: 5px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}
.user-message {
    align-self: flex-end;
    background: var(--primary-color);
    color: white;
    border-bottom-left-radius: 5px;
    box-shadow: 0 4px 10px rgba(255, 133, 161, 0.2);
}
.bot-quick-prompts {
    display: flex;
    gap: 8px;
    padding: 10px 15px;
    overflow-x: auto;
    background: #fdfdfd;
    border-top: 1px solid #f1f5f9;
}
.bot-quick-prompts::-webkit-scrollbar {
    height: 6px;
}
.bot-quick-prompts::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}
.quick-prompt-btn {
    background: white;
    border: 1px solid var(--secondary-color);
    color: var(--secondary-color);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}
.quick-prompt-btn:hover {
    background: var(--secondary-color);
    color: white;
}
.bot-chat-input-area {
    padding: 15px;
    background: white;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
}
#bot-input-field {
    flex: 1;
    padding: 12px 20px;
    border: 2px solid #e2e8f0;
    border-radius: 30px;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.3s;
}
#bot-input-field:focus {
    border-color: var(--secondary-color);
}
#bot-send-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: var(--secondary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    transition: transform 0.2s, background 0.3s;
}
#bot-send-btn:hover {
    transform: scale(1.1);
    background: #20c997;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.bot-typing {
    align-self: flex-start;
    background: white;
    padding: 10px 15px;
    border-radius: 20px;
    border-bottom-right-radius: 5px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    display: flex;
    gap: 5px;
}
.typing-dot {
    width: 8px;
    height: 8px;
    background: #cbd5e1;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Force Flex Row Layout for Chapters */
.chapters-grid {
    display: flex;
    flex-wrap: wrap !important;
    flex-direction: row !important;
    justify-content: center !important;
    align-items: center !important;
    align-content: center !important;
    gap: 30px !important;
    width: 100% !important;
}
