:root {
    --primary: #6C5CE7;
    --primary-light: #A29BFE;
    --secondary: #00CEC9;
    --accent: #FD79A8;
    --background: #1A1A2E;
    --card-bg: #FFFFFF;
    --text-main: #E8E4D9;
    --text-muted: #A0A0A0;
    --glass: rgba(255, 255, 255, 0.1);
    --shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
    --radius: 20px;
}

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

body {
    background-color: var(--background);
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(108, 92, 231, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(253, 121, 168, 0.15), transparent 25%),
        radial-gradient(circle at 50% 80%, rgba(0, 206, 201, 0.1), transparent 20%);
    color: var(--text-main);
    direction: rtl;
    min-height: 100vh;
    overflow-x: hidden;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

header p {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.home-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-align: right;
    background: white;
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 4rem;
    color: #1e293b;
}

.header-content h1 {
    font-size: 2.2rem;
    margin-bottom: 0.2rem;
}

.header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.portal-btn {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
    padding: 1rem 1.5rem;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}

.portal-btn:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-3px);
}

.achievements-btn {
    background: linear-gradient(135deg, #f59e0b, #fbbf24);
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 50px;
    font-size: 1.3rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(245, 158, 11, 0.3);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.achievements-btn:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 15px 30px rgba(245, 158, 11, 0.4);
}

/* Tabs / Switcher */
.lesson-tabs {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
    background: var(--glass);
    padding: 0.5rem;
    border-radius: 30px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
    box-shadow: var(--shadow);
}

.tab-btn {
    padding: 0.8rem 2rem;
    border: none;
    border-radius: 25px;
    background: transparent;
    color: var(--text-muted);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

/* Content Area */
.content-wrapper {
    position: relative;
    min-height: 500px;
}

.pane {
    display: none;
    animation: slideUp 0.5s ease-out;
}

.pane.active {
    display: block;
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 2.5rem;
    box-shadow: var(--shadow);
    border: 1px solid rgba(0, 0, 0, 0.05);
    color: #1e293b;
}

.explanation-section h2, .exercise-section h2 {
    color: var(--primary);
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-size: 1.8rem;
}

.explanation-section p {
    font-size: 1.3rem;
    line-height: 1.8;
    margin-bottom: 1.2rem;
}

.concept {
    background: #eff6ff;
    padding: 1.5rem;
    border-radius: 15px;
    border-right: 5px solid var(--primary);
    color: #1e40af;
}
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 1.5rem 0;
}

.cube {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #6366f1, #818cf8);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.95rem;
    font-weight: 800;
    box-shadow: 4px 4px 0px #4338ca;
    position: relative;
    transition: transform 0.3s;
}

.cube:hover {
    transform: translateY(-5px);
    box-shadow: 6px 6px 0px #4338ca;
}

.cube-stack {
    display: flex;
    flex-direction: column-reverse;
    gap: 2px;
}

/* Exercise Items */
.exercise-item {
    background: #f1f5f9;
    padding: 1.5rem;
    border-radius: 15px;
    margin-bottom: 1rem;
    border-right: 5px solid var(--primary);
    transition: all 0.3s;
}

.exercise-item:hover {
    transform: translateX(-5px);
    background: #e2e8f0;
}

.input-group {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

input[type="number"], input[type="text"] {
    width: 80px;
    padding: 0.5rem;
    border: 2px solid #cbd5e1;
    border-radius: 10px;
    text-align: center;
    font-size: 1.1rem;
    outline: none;
    transition: border-color 0.3s;
}

input:focus {
    border-color: var(--primary);
}

.check-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.5rem 1.2rem;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.2s;
}

.check-btn:active {
    transform: scale(0.95);
}

/* Animations */
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Lesson Selector */
.lesson-selector {
    margin-bottom: 1.5rem;
    background: var(--glass);
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.lesson-selector select {
    padding: 0.5rem;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    background: white;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
    outline: none;
}

/* Place Value Table */
.place-value-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    background: white;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

.place-value-table th {
    background: var(--primary);
    color: white;
    padding: 1rem;
    font-size: 1.1rem;
}

.place-value-table td {
    border: 1px solid #e2e8f0;
    padding: 1rem;
    text-align: center;
    vertical-align: top;
}

.visual-repr {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    min-height: 80px;
}

.mini-cube { width: 15px; height: 15px; background: #6366f1; border-radius: 2px; }
.mini-rod { width: 6px; height: 40px; background: #f43f5e; border-radius: 2px; }
.mini-square { width: 30px; height: 30px; background: #10b981; border-radius: 2px; border: 1px solid #059669; }
.mini-thousand { width: 40px; height: 40px; background: #8b5cf6; border-radius: 4px; box-shadow: 2px 2px 0 #6d28d9; }

/* Lesson 3 Specifics */
.underlined {
    text-decoration: underline;
    text-decoration-color: var(--secondary);
    text-decoration-thickness: 3px;
    font-weight: 800;
    color: var(--secondary);
}

.expanded-form {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.expanded-form input {
    width: 70px !important;
}

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

/* Responsive */
@media (max-width: 768px) {
    .app-container { padding: 1rem; }
    header h1 { font-size: 1.8rem; }
    .card { 
        padding: 1.5rem; 
        overflow-x: auto; 
    }
    
    #teacher-scene {
        flex-direction: column;
        padding: 15px;
        gap: 15px;
        text-align: center;
    }
    .teacher-emoji, .student-emoji { 
        font-size: 3rem; 
    }
    .speech-bubble {
        margin: 10px 0;
        font-size: 1.1rem;
        padding: 15px;
        width: 100%;
    }
    .speech-bubble::before, .speech-bubble::after {
        display: none; 
    }
    
    /* Target the correct wrappers for explanations and exercises on mobile */
    .interactive-explanation,
    .example-box,
    .exercise-item {
        padding: 15px !important;
    }
    
    /* Scale down large inline font sizes globally on mobile */
    .pane [style*="font-size: 4rem"] { font-size: 2.5rem !important; }
    .pane [style*="font-size: 3.5rem"] { font-size: 2.2rem !important; }
    .pane [style*="font-size: 3rem"] { font-size: 2rem !important; }
    .pane [style*="font-size: 2.5rem"] { font-size: 1.5rem !important; }
    .pane [style*="font-size: 2.2rem"] { font-size: 1.3rem !important; }
    
    /* Reduce huge paddings and gaps in inline styles */
    .pane [style*="padding: 25px"] { padding: 10px !important; }
    .pane [style*="padding: 20px"] { padding: 10px !important; }
    .pane [style*="padding: 15px 30px"] { padding: 10px 15px !important; }
    .pane [style*="padding: 15px 25px"] { padding: 10px 15px !important; }
    .pane [style*="gap: 40px"] { gap: 15px !important; }
    .pane [style*="gap: 20px"] { gap: 10px !important; }
    .pane [style*="gap: 15px"] { gap: 10px !important; }

    /* Fix Place Value Table overlapping on mobile */
    .pv-table-container {
        gap: 5px !important;
        padding: 10px !important;
    }
    .pv-col {
        padding: 5px !important;
        gap: 5px !important;
        border-width: 2px !important;
    }
    .pv-title {
        font-size: 0.85rem !important;
    }
    .pv-val {
        font-size: 1.2rem !important;
        padding: 2px 5px !important;
    }
    .pv-icon {
        width: 16px !important;
        height: 16px !important;
    }
}

/* Decorative Background */
.bg-blob {
    position: fixed;
    z-index: -1;
    filter: blur(80px);
    opacity: 0.4;
    border-radius: 50%;
}

.blob-1 {
    width: 400px;
    height: 400px;
    background: var(--primary-light);
    top: -100px;
    left: -100px;
}

.blob-2 {
    width: 300px;
    height: 300px;
    background: var(--secondary);
    bottom: -50px;
    right: -50px;
}

/* Curriculum Map & Views */
.view { animation: fadeIn 0.5s ease-out; position: relative; }
.view.hidden { display: none; }

.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 3rem;
    padding: 2rem;
    justify-items: center;
}

.book-btn {
    background: #4a2511;
    border-radius: 15px 5px 5px 15px; /* Spine on the right in RTL */
    width: 240px;
    height: 350px;
    position: relative;
    cursor: pointer;
    box-shadow: 
        15px 15px 25px rgba(0,0,0,0.4),
        inset -8px 0 15px rgba(0,0,0,0.5); /* spine shadow */
    border-right: 15px solid #2d1500; /* Dark spine */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    text-align: center;
    border: none;
    outline: none;
    color: white;
    transform-style: preserve-3d;
}

/* Page edges on the left (RTL) */
.book-btn::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 5px;
    bottom: 5px;
    width: 8px;
    background: #e3cfa4;
    border-radius: 5px 0 0 5px;
    box-shadow: inset 2px 0 5px rgba(0,0,0,0.1);
}

/* Bottom shadow/shelf */
.book-btn::after {
    content: '';
    position: absolute;
    bottom: -15px;
    left: -10px;
    right: -10px;
    height: 10px;
    background: #2d1500;
    border-radius: 5px;
    box-shadow: 0 5px 10px rgba(0,0,0,0.5);
    z-index: -1;
}

.book-btn:hover {
    transform: translateY(-10px) rotateY(-5deg);
    box-shadow: 
        20px 25px 35px rgba(0,0,0,0.5),
        inset -8px 0 15px rgba(0,0,0,0.5);
}

.book-icon {
    font-size: 4.5rem;
    margin-bottom: 2rem;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3));
}

.book-title {
    color: #ffd700;
    font-size: 1.8rem;
    font-weight: 800;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5), 0 2px 4px rgba(0,0,0,0.8);
    line-height: 1.4;
    font-family: 'Cairo', sans-serif;
}

.book-meta {
    position: absolute;
    bottom: 25px;
    color: #e8e4d9;
    font-size: 1.1rem;
    font-weight: 700;
    opacity: 0.9;
}

.book-check {
    position: absolute;
    top: -15px;
    left: -15px;
    width: 45px;
    height: 45px;
    background: #10b981;
    border: 4px solid #34d399;
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    z-index: 5;
}

/* Achievements Grid */
.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 2rem;
    padding: 2rem 0;
}

.badge-card {
    background: white;
    padding: 2rem;
    border-radius: 30px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: all 0.3s;
    opacity: 0.5;
    filter: grayscale(1);
}

.badge-card.unlocked {
    opacity: 1;
    filter: grayscale(0);
    transform: scale(1.05);
    border: 3px solid #fcd34d;
}

.badge-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    display: block;
}

.badge-card h3 {
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.badge-card p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.back-btn {
    background: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 50px;
    font-weight: 800;
    color: var(--primary);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Teacher Scene */
#teacher-scene {
    background: #1e293b;
    border-radius: 20px;
    padding: 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 5px solid #475569;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
    position: relative;
}

.teacher-emoji {
    font-size: 5rem;
    transition: transform 0.2s;
    filter: drop-shadow(0 5px 10px rgba(0,0,0,0.3));
}

.teacher-emoji.talking {
    animation: bounceTalk 0.4s infinite alternate;
}

.student-emoji {
    font-size: 4rem;
    transition: transform 0.3s;
    filter: drop-shadow(0 5px 10px rgba(0,0,0,0.3));
}

.student-emoji.happy {
    animation: jump 0.5s infinite alternate;
}

.speech-bubble {
    background: white;
    padding: 20px 30px;
    border-radius: 20px;
    font-size: 1.3rem;
    font-weight: bold;
    color: #1e293b;
    flex-grow: 1;
    margin: 0 30px;
    position: relative;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    text-align: center;
    border: 3px solid #fcd34d;
}

.speech-bubble::before {
    content: '';
    position: absolute;
    right: -20px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 15px 0 15px 20px;
    border-style: solid;
    border-color: transparent transparent transparent #fcd34d;
}
.speech-bubble::after {
    content: '';
    position: absolute;
    right: -15px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 12px 0 12px 16px;
    border-style: solid;
    border-color: transparent transparent transparent white;
}

@keyframes bounceTalk {
    0% { transform: translateY(0); }
    100% { transform: translateY(-10px); }
}

@keyframes jump {
    0% { transform: translateY(0); }
    100% { transform: translateY(-20px); }
}

.site-footer {
    text-align: center;
    padding: 2rem;
    margin-top: 2rem;
    font-size: 1.2rem;
    font-weight: bold;
    border-top: 2px dashed rgba(0,0,0,0.1);
}

.site-footer a {
    color: #4a2511;
    text-decoration: none;
    transition: color 0.3s;
}

.site-footer a:hover {
    color: #d946ef;
}

.highlight-part {
    animation: highlightPulse 1.5s infinite alternate !important;
    position: relative;
    z-index: 10;
}

@keyframes highlightPulse {
    0% { 
        box-shadow: 0 0 0px #fcd34d; 
        border-color: #cbd5e1; 
        transform: scale(1);
    }
    100% { 
        box-shadow: 0 0 25px #f59e0b, inset 0 0 15px rgba(245,158,11,0.2); 
        border-color: #f59e0b !important; 
        transform: scale(1.05);
    }
}

/* AI Bot Styles */
.ai-bot-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, #a855f7, #d946ef);
    border-radius: 50%;
    border: 4px solid white;
    font-size: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(217, 70, 239, 0.4);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
}

.ai-bot-btn:hover {
    transform: scale(1.1) rotate(10deg);
    box-shadow: 0 15px 35px rgba(217, 70, 239, 0.6);
}

.ai-bot-modal {
    position: fixed;
    bottom: 120px;
    right: 30px;
    width: 350px;
    max-width: calc(100vw - 60px);
    height: 500px;
    background: white;
    border-radius: 25px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-origin: bottom right;
    border: 3px solid #f3e8ff;
}

.ai-bot-modal.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.1);
}

.ai-bot-header {
    background: linear-gradient(135deg, #a855f7, #d946ef);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-bot-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 800;
}

.close-bot-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: transform 0.2s;
}

.close-bot-btn:hover {
    transform: scale(1.2);
}

.ai-bot-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: #faf5ff;
}

.bot-message, .user-message {
    max-width: 85%;
    padding: 12px 18px;
    border-radius: 20px;
    font-size: 1.05rem;
    line-height: 1.5;
    animation: fadeIn 0.3s ease-out;
}

.bot-message {
    background: white;
    color: #4b5563;
    align-self: flex-start;
    border-bottom-right-radius: 5px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    border: 1px solid #f3e8ff;
}

.user-message {
    background: #d946ef;
    color: white;
    align-self: flex-end;
    border-bottom-left-radius: 5px;
    box-shadow: 0 4px 10px rgba(217, 70, 239, 0.3);
}

.ai-bot-input-area {
    padding: 15px;
    background: white;
    border-top: 1px solid #f3e8ff;
    display: flex;
    gap: 10px;
}

.ai-bot-input-area input {
    flex-grow: 1;
    border: 2px solid #e5e7eb;
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
}

.ai-bot-input-area input:focus {
    border-color: #d946ef;
}

.send-bot-btn {
    background: #d946ef;
    color: white;
    border: none;
    padding: 0 20px;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
}

.send-bot-btn:hover {
    background: #c026d3;
}

@media (max-width: 768px) {
    .ai-bot-btn {
        bottom: 20px;
        right: 20px;
        width: 60px;
        height: 60px;
        font-size: 2rem;
    }
    
    .ai-bot-modal {
        bottom: 90px;
        right: 20px;
        width: calc(100vw - 40px);
        height: 60vh;
    }
}
