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

:root {
    --primary-color: #FF9F1C; /* Vibrant Orange */
    --secondary-color: #2EC4B6; /* Teal */
    --accent-color: #FFBF69;
    --background-color: #CBF3F0; /* Soft pastel teal background */
    --card-bg: rgba(255, 255, 255, 0.85); /* Glassmorphism */
    --text-main: #2B2D42;
    --text-muted: #8D99AE;
    --success-color: #4CAF50;
    --error-color: #F44336;
    --border-radius: 20px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
}

* {
    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 top right, rgba(255,159,28,0.1), transparent 400px),
                      radial-gradient(circle at bottom left, rgba(46,196,182,0.1), transparent 400px);
    color: var(--text-main);
    direction: rtl;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header & Gamification */
header {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-area h1 {
    font-size: 1.8rem;
    color: var(--primary-color);
    font-weight: 800;
    letter-spacing: -0.5px;
}

.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: 0.8rem 1rem;
    background: #FFF;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 700;
    color: var(--text-muted);
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

.nav-lesson-item:hover {
    border-color: var(--accent-color);
    color: var(--primary-color);
    transform: translateX(-5px);
}

.nav-lesson-item.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    box-shadow: 0 4px 15px rgba(255, 159, 28, 0.4);
}
.nav-lesson-item.active i {
    color: #FFF;
}

.emoji-mascot {
    width: 150px;
    height: 150px;
    background: white;
    box-shadow: var(--shadow);
    border: 5px solid var(--secondary-color);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 5rem;
    animation: float 4s ease-in-out infinite;
}

.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: var(--primary-color);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 159, 28, 0.4);
}

.tab-btn:hover:not(.active) {
    background: rgba(255, 159, 28, 0.1);
    color: var(--primary-color);
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    transition: transform 0.3s ease;
    border: 1px solid rgba(255,255,255,0.5);
    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: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
    direction: ltr; /* Render LTR visually, but logical right-to-left in data */
    justify-content: center;
}

.pattern-item {
    padding: 1rem;
    background: #F8FAFC;
    border-radius: 10px;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--secondary-color);
    min-width: 100px;
    text-align: center;
    border: 2px solid #E2E8F0;
}

.pattern-input {
    width: 120px;
    padding: 1rem;
    font-size: 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: wrap;
    align-items: center;
    gap: 1rem;
    font-size: 1.2rem;
}
.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); }
}

/* 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;
}
