:root {
    --primary-bg: #0f172a;
    --accent-glow: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
    --card-bg: rgba(255, 255, 255, 0.08);
    --border-color: rgba(255, 255, 255, 0.15);
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --star-gold: #fbbf24;
    --radius-xl: 32px;
    --radius-lg: 20px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Tajawal', sans-serif;
    background-color: var(--primary-bg);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    direction: rtl;
    line-height: 1.6;
}

/* --- Animated Liquid Background --- */
.background-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: radial-gradient(circle at top right, #1e1b4b, #0f172a);
    overflow: hidden;
}

.glass-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.4;
    animation: liquidMove 25s infinite alternate ease-in-out;
}

.orb-1 { width: 60vw; height: 60vw; background: #4f46e5; top: -10vw; right: -10vw; }
.orb-2 { width: 50vw; height: 50vw; background: #7c3aed; bottom: -10vw; left: -10vw; animation-delay: -5s; }
.orb-3 { width: 40vw; height: 40vw; background: #db2777; top: 30%; left: 20%; animation-delay: -10s; }

@keyframes liquidMove {
    0% { transform: translate(0, 0) scale(1) rotate(0deg); }
    33% { transform: translate(5vw, 10vh) scale(1.1) rotate(120deg); }
    66% { transform: translate(-5vw, 5vh) scale(0.9) rotate(240deg); }
    100% { transform: translate(0, 0) scale(1) rotate(360deg); }
}

/* --- Layout --- */
.view {
    display: none;
    padding: 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.view.active-view {
    display: block;
    animation: viewEnter 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

@keyframes viewEnter {
    from { opacity: 0; transform: scale(0.98) translateY(20px); filter: blur(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); filter: blur(0); }
}

/* --- Header UI --- */
.main-header {
    text-align: center;
    padding: 4rem 1rem;
}

.header-content h1 {
    font-size: clamp(2.5rem, 8vw, 4.5rem);
    font-family: 'Changa', sans-serif;
    background: var(--accent-glow);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 1rem;
    filter: drop-shadow(0 0 30px rgba(99, 102, 241, 0.3));
    animation: glowTitle 3s infinite alternate;
}

@keyframes glowTitle {
    from { filter: drop-shadow(0 0 10px rgba(99, 102, 241, 0.3)); }
    to { filter: drop-shadow(0 0 30px rgba(236, 72, 153, 0.6)); }
}

.header-content p {
    color: var(--text-dim);
    font-size: 1.2rem;
    max-width: 600px;
    margin: 0 auto;
}

.user-stats {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    padding: 0.8rem 1.5rem;
    border-radius: 50px;
    border: 1px solid var(--border-color);
    margin-top: 2rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--star-gold);
}

/* --- Hero's Path Grid --- */
.lessons-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2.5rem;
    padding: 2rem 0;
}

.lesson-card {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 2.5rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: visible; /* To allow the lesson number to overflow */
    perspective: 1000px;
    border-top: 5px solid #6366f1;
}

/* Dynamic colors for lesson cards */
.card-style-0 { border-top-color: #ff4757; }
.card-style-1 { border-top-color: #2ecc71; }
.card-style-2 { border-top-color: #f1c40f; }
.card-style-3 { border-top-color: #9b59b6; }
.card-style-4 { border-top-color: #1e90ff; }

.lesson-number {
    position: absolute;
    top: -20px;
    right: -20px;
    width: 45px;
    height: 45px;
    background: var(--accent-glow);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 1.4rem;
    box-shadow: 0 5px 15px rgba(0,0,0,0.4);
    z-index: 2;
}

.lesson-card::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at center, rgba(255,255,255,0.1) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 0;
}

.lesson-card:hover {
    transform: translateY(-10px) scale(1.05) !important;
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.12);
    box-shadow: 0 25px 50px rgba(0,0,0,0.5);
}

.lesson-card:hover::before { opacity: 1; }

.lesson-card .icon {
    font-size: 4.5rem;
    margin-bottom: 1.5rem;
    display: block;
    filter: drop-shadow(0 10px 15px rgba(0,0,0,0.3));
    transition: transform 0.3s;
    position: relative;
    z-index: 1;
}

.lesson-card:hover .icon { transform: scale(1.15) rotate(5deg); }

.lesson-card h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-main);
    position: relative;
    z-index: 1;
}

.lesson-card .meta {
    color: var(--text-dim);
    font-size: 0.95rem;
    background: rgba(0,0,0,0.2);
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    position: relative;
    z-index: 1;
}

/* --- Lesson View Navigation --- */
.lesson-header-bar {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 2rem;
    background: rgba(255,255,255,0.03);
    padding: 1rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.back-btn {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    width: 50px;
    height: 50px;
    border-radius: 15px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: 0.3s;
}

.back-btn:hover { background: rgba(255,255,255,0.1); transform: translateX(5px); }

#lesson-title-display {
    flex-grow: 1;
    font-size: 1.5rem;
}

.lesson-tabs {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 2.5rem;
    flex-wrap: wrap;
}

.tab-trigger {
    padding: 0.8rem 1.8rem;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: rgba(255,255,255,0.05);
    color: var(--text-main);
    font-weight: 700;
    cursor: pointer;
    transition: 0.3s;
    font-size: 1rem;
}

.tab-trigger:hover { background: rgba(255,255,255,0.1); }

.tab-trigger.active {
    background: var(--accent-glow);
    border-color: transparent;
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

/* --- Tab Content Switching --- */
.lesson-body {
    position: relative;
}

.tab-content {
    display: none; /* All tabs hidden by default */
    animation: tabSlideIn 0.4s cubic-bezier(0.23, 1, 0.32, 1);
}

.tab-content.active {
    display: block;
}

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

.text-display {
    background: rgba(255, 255, 255, 0.95);
    color: #1e293b;
    padding: 3rem;
    border-radius: var(--radius-xl);
    font-size: 2.2rem;
    line-height: 2.5;
    box-shadow: 0 30px 60px rgba(0,0,0,0.5);
    text-align: center;
    border: 8px solid rgba(255,255,255,0.05);
}

.reading-line {
    display: inline-block;
    padding: 0 15px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    margin: 5px;
    border: 2px solid transparent;
}

.reading-line:hover { 
    background: #f1f5f9; 
    border-color: #cbd5e1;
}

.reading-line.playing { 
    background: #4f46e5; 
    color: white; 
    transform: scale(1.05);
    box-shadow: 0 10px 20px rgba(79, 70, 229, 0.3);
}

/* --- Vocabulary --- */
.vocab-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.vocab-item {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    padding: 2.5rem;
    border-radius: var(--radius-lg);
    text-align: center;
    transition: 0.4s;
    cursor: pointer;
}

.vocab-item:hover { 
    transform: rotateY(10deg); 
    border-color: #a855f7;
}

.vocab-word {
    font-size: 2.2rem;
    font-weight: 900;
    color: #a855f7;
    margin-bottom: 1rem;
}

.vocab-meaning {
    color: var(--text-dim);
    font-size: 1.3rem;
    opacity: 0;
    transform: translateY(10px);
    transition: 0.4s;
}

.vocab-item.flipped .vocab-meaning {
    opacity: 1;
    transform: translateY(0);
}

/* --- Game - Sentence Ordering & Memo --- */
.game-board, .memo-game {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    padding: 2rem;
    border-radius: var(--radius-xl);
    text-align: center;
}

.slots-container, .memo-lines {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-bottom: 2rem;
    min-height: 50px;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-lg);
}

.drop-slot {
    min-width: 80px;
    height: 45px;
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.3s;
}

.drop-slot.filled {
    border-style: solid;
    background: var(--accent-glow);
    border-color: transparent;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.words-bank, .memo-words {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    margin-top: 1rem;
}

.memo-word, .order-word {
    padding: 10px 20px;
    background: #f8fafc;
    color: #1e293b;
    border-radius: 15px;
    cursor: grab;
    user-select: none;
    font-weight: 800;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    transition: 0.3s;
    border: 2px solid transparent;
}

.memo-word:hover, .order-word:hover {
    transform: scale(1.1);
    background: #fff;
    border-color: #6366f1;
}

.memo-word.selected, .order-word.active {
    background: #6366f1;
    color: white;
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.5);
}

/* --- Writing Canvas --- */
.writing-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    min-width: 300px; /* Prevent collapsing to a line */
    background: rgba(255, 255, 255, 0.03);
    padding: 2rem;
    border-radius: var(--radius-xl);
}

#write-canvas {
    background: #fff;
    border-radius: var(--radius-lg);
    border: 4px solid #6366f1;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    cursor: crosshair;
    width: 100%; /* Responsive display */
    max-width: 900px;
    height: 400px;
    display: block;
}

.canvas-controls {
    display: flex;
    gap: 15px;
}

.check-btn {
    background: var(--accent-glow);
    color: white;
    padding: 1rem 3rem;
    font-size: 1.2rem;
    border-radius: 50px;
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(236, 72, 153, 0.4);
    margin-top: 2rem;
    transition: 0.3s;
}

.check-btn:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 35px rgba(236, 72, 153, 0.6);
}

.hidden { display: none !important; }

/* --- Success Modal --- */
.modal {
    display: none; /* Hidden by default */
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--primary-bg);
    border: 2px solid #a855f7;
    border-radius: var(--radius-xl);
    padding: 3rem;
    text-align: center;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 0 50px rgba(168, 85, 247, 0.4);
    animation: modalPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.celebration-icon {
    font-size: 5rem;
    margin-bottom: 1rem;
    animation: float 2s infinite ease-in-out;
}

.reward-stars {
    font-size: 2rem;
    letter-spacing: 5px;
    margin: 1.5rem 0;
}

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

.primary-btn {
    background: var(--accent-glow);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    border-radius: 50px;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    transition: 0.3s;
}

.primary-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(168, 85, 247, 0.4);
}

/* --- Checklist Styles --- */
.checklist-item {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    transition: 0.3s;
    cursor: pointer;
}

.checklist-item:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(-5px);
}

.checklist-item.completed {
    background: rgba(46, 204, 113, 0.15);
    border-color: #2ecc71;
}

.checklist-item.completed .checklist-title {
    color: #2ecc71;
    text-decoration: line-through;
    opacity: 0.8;
}

.checklist-checkbox {
    width: 25px;
    height: 25px;
    margin-left: 15px;
    cursor: pointer;
    accent-color: #2ecc71;
}

.checklist-title {
    font-size: 1.2rem;
    font-weight: bold;
    flex-grow: 1;
    transition: 0.3s;
}

.completed-badge {
    position: absolute;
    top: -15px;
    left: -15px;
    background: #2ecc71;
    color: white;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    z-index: 3;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    0% { transform: scale(0); }
    100% { transform: scale(1); }
}

.top-right-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 50;
    padding: 0.6rem 1.2rem;
    font-size: 1.1rem;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

/* --- Responsiveness Media Queries --- */

/* Tablets and small desktops */
@media (max-width: 1024px) {
    .view {
        padding: 1rem;
    }
    
    .main-header {
        padding: 3rem 1rem;
    }
    
    .text-display {
        font-size: 1.8rem;
        padding: 2rem;
    }
}

/* Mobile Devices */
@media (max-width: 768px) {
    .header-content h1 {
        font-size: 2.5rem;
    }
    
    .header-content p {
        font-size: 1rem;
    }
    
    .lessons-container {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
        gap: 1.5rem;
    }
    
    .lesson-card {
        padding: 1.5rem 1rem;
    }
    
    .lesson-card .icon {
        font-size: 3.5rem;
    }
    
    .text-display {
        font-size: 1.5rem;
        padding: 1.5rem;
        line-height: 2;
    }
    
    .lesson-tabs {
        gap: 8px;
    }
    
    .tab-trigger {
        padding: 0.6rem 1.2rem;
        font-size: 0.9rem;
    }
    
    .vocab-word {
        font-size: 1.8rem;
    }
    
    .vocab-meaning {
        font-size: 1.1rem;
    }
    
    #write-canvas {
        height: 300px;
    }
}

/* Very small screens (Phones) */
@media (max-width: 480px) {
    .main-header {
        padding: 2rem 0.5rem;
    }
    
    .header-content h1 {
        font-size: 2rem;
    }
    
    .user-stats {
        padding: 0.5rem 1rem;
    }
    
    .stat-item {
        font-size: 1.2rem;
    }
    
    .lesson-header-bar {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    .back-btn {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }
    
    .text-display {
        font-size: 1.3rem;
        padding: 1rem;
        border-width: 4px;
    }
    
    .reading-line {
        padding: 0 8px;
        margin: 3px;
    }
    
    .tab-trigger {
        flex-grow: 1;
        padding: 0.5rem;
        font-size: 0.85rem;
    }
    
    .modal-content {
        padding: 1.5rem;
    }
    
    .celebration-icon {
        font-size: 3.5rem;
    }
    
    #write-canvas {
        height: 250px;
    }
    
    .top-right-btn {
        position: static;
        margin-top: 10px;
        width: 100%;
    }
}
