/* ================================================================
   styles.css - Nihongo Planet
   النسخة المُصلحة والمُنظمة
   ================================================================ */

/* ================================
   1. المتغيرات الجذرية
   ================================ */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@500;700;900&display=swap');

:root {
    --navy-bg: #090a1f;
    --deep-purple: #1e1145;
    --light-purple: #8b5cf6;
    --yellow-gold: #ffc107;
    --purple-glow: rgba(139, 92, 246, 0.3);
    --text-light: #f5f3ff;
    --glass: rgba(255, 255, 255, 0.05);

    /* خط مخصص للحروف اليابانية - أهم إضافة! */
    --font-jp: 'Noto Sans JP', 'Cairo', sans-serif;

    /* مقياس المسافات - استخدمه بدل أرقام عشوائية */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;

    /* مقياس الحواف الدائرية */
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 999px;

    /* منحنيات حركة احترافية موحدة */
    --ease-smooth: cubic-bezier(0.22, 1, 0.36, 1);
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ================================
   2. الإعدادات الأساسية (دمج التكرارات)
   ================================ */
* {
    box-sizing: border-box !important;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    font-family: 'Cairo', sans-serif !important;
}

body {
    background-color: var(--navy-bg);
    color: var(--text-light);
    font-family: 'Cairo', sans-serif;
    font-weight: 600;
    overflow-x: hidden;
    text-align: center;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;

    background:
        radial-gradient(circle at 20% 20%, rgba(139, 92, 246, .20), transparent 35%),
        radial-gradient(circle at 80% 70%, rgba(255, 193, 7, .10), transparent 35%),
        radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .03), transparent 50%);

    pointer-events: none;
    z-index: -2;
}

/* ================================
   3. شاشة التحميل
   ================================ */
#loader {
    position: fixed;
    inset: 0;
    background: var(--navy-bg);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.8s ease, visibility 0.8s;
}

.fade-out {
    opacity: 0;
    visibility: hidden;
}

/* ================================
   4. الخلفية والجماليات
   ================================ */
.bg-glow {
    position: fixed;
    top: -10%;
    left: -10%;
    width: 50%;
    height: 50%;
    background: radial-gradient(circle, var(--purple-glow) 0%, transparent 70%);
    z-index: -1;
    filter: blur(60px);
}

#starsCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

/* ================================
   5. تحريك المحمل (Loading Spinner)
   ================================ */
.purple-circle {
    width: 100px;
    height: 100px;
    border: 4px solid var(--light-purple);
    border-top: 4px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    box-shadow: 0 0 20px var(--light-purple);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ================================
   6. كوكب زحل
   ================================ */
.saturn-container {
    position: relative;
    width: 140px;
    height: 140px;
    margin: 40px auto 10px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.ring {
    position: absolute;
    width: 180px;
    height: 90px;
    border: 4px solid var(--yellow-gold);
    border-radius: 50%;
    transform: rotateX(75deg);
    animation: rotateRing 4s linear infinite;
}

.planet-img {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 3px solid var(--light-purple);
    z-index: 2;
}

@keyframes rotateRing {
    from {
        transform: rotateX(75deg) rotateZ(0deg);
    }

    to {
        transform: rotateX(75deg) rotateZ(360deg);
    }
}

/* ================================
   7. تبويبات الحروف — Segmented Control بخلفية منزلقة
   ================================ */
.tabs-container {
    position: relative;
    display: flex;
    gap: 6px;
    margin: 20px auto;
    max-width: 400px;
    padding: 6px;
    background: var(--deep-purple);
    border-radius: var(--radius-lg, 24px);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

/* الخلفية المتوهجة المنزلقة (المؤشر) */
.tabs-container::before {
    content: "";
    position: absolute;
    top: 6px;
    bottom: 6px;
    right: 6px;
    width: calc(50% - 9px);
    border-radius: 18px;
    background: linear-gradient(45deg, #8b5cf6, #a78bfa);
    box-shadow: 0 4px 15px var(--purple-glow), 0 0 15px #8b5cf6;
    transition: right 0.4s var(--ease-smooth, cubic-bezier(.22, 1, .36, 1));
    z-index: 0;
}

/* لو تاب Hiragana هو الفعّال، المؤشر يزحف لليسار (RTL) */
.tabs-container:has(#tab-Hira.active)::before {
    right: calc(50% + 3px);
}

.tab-btn {
    position: relative;
    z-index: 1;
    flex: 1;
    padding: 14px;
    border-radius: 18px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.6);
    font-weight: bold;
    font-size: 1.1rem;
    cursor: pointer;
    transition: color 0.3s ease, transform 0.2s ease;
}

.tab-btn.active {
    color: #fff;
}

.tab-btn:hover {
    transform: scale(1.03);
}

.tab-btn:active {
    transform: scale(0.96);
}

/* دعم للمتصفحات القديمة اللي مش فاهمة :has() — رجوع للتصميم الأصلي كـ fallback آمن */
@supports not selector(:has(a)) {
    .tabs-container::before {
        display: none;
    }

    .tab-btn.active {
        background: linear-gradient(45deg, #8b5cf6, #a78bfa);
        box-shadow: 0 4px 15px var(--purple-glow), 0 0 15px #8b5cf6;
    }
}

/* ================================
   8. لوحة الصدارة
   ================================ */
/* Container Box */
.leaderboard-container {
    width: min(100% - 24px, 1100px);
    max-width: 1100px;
    margin: 20px auto;
    padding: 30px 20px;
    background: rgba(18, 14, 38, 0.75);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(245, 186, 72, 0.4);
    box-shadow: 0 0 25px rgba(245, 186, 72, 0.15);
    border-radius: 20px;
    box-sizing: border-box;
}

.leaderboard-title {
    text-align: center;
    color: #f5ba48;
    font-size: 1.5rem;
    margin-bottom: 20px;
}

/* 2-Column Vertical Grid */
.leaderboard-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Individual User Card */
.leaderboard-item {
    position: relative; /* Ensure NO position: absolute on cards */
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 14px 18px;
    border-radius: 12px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    direction: rtl;
    gap: 12px;
    transition: background 0.2s, transform 0.2s, border-color 0.2s;
}

.leaderboard-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(245, 186, 72, 0.35);
    transform: translateY(-2px);
}

.leaderboard-item:focus-visible {
    outline: 2px solid #f5ba48;
    outline-offset: 2px;
}

/* Center Rank #15 across both columns */
.leaderboard-item:nth-child(15) {
    grid-column: 1 / -1;
    justify-self: stretch;
    width: 100%;
    max-width: none;
}

.leaderboard-rank {
    min-width: 32px;
    font-weight: bold;
    font-size: 1.1rem;
    color: #cbd5e1;
    text-align: center;
}

.leaderboard-rank-gold {
    color: #ffd700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
}

.leaderboard-rank-silver {
    color: #c0c7d1;
    text-shadow: 0 0 10px rgba(192, 199, 209, 0.5);
}

.leaderboard-rank-bronze {
    color: #cd7f32;
    text-shadow: 0 0 10px rgba(205, 127, 50, 0.55);
}

.leaderboard-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 1.5px solid rgba(245, 186, 72, 0.4);
    background: linear-gradient(135deg, var(--light-purple), #6d28d9);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    overflow: hidden;
    flex-shrink: 0;
}

.leaderboard-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.leaderboard-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0;
    flex: 1;
    text-align: center;
}

/* منع تجاوز النصوص لحدود البطاقة (اقتطاع بثلاث نقاط) */
.leaderboard-name,
.leaderboard-handle {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block;
}

.leaderboard-name {
    color: #fff;
    font-size: 1.05rem;
    font-weight: 600;
    text-align: center;
}

.leaderboard-handle {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.85rem;
    text-align: center;
}

.leaderboard-score {
    color: #f5ba48;
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
    text-shadow: 0 0 8px rgba(245, 186, 72, 0.35);
    direction: ltr;
}

.leaderboard-empty {
    color: rgba(203, 213, 225, 0.7);
    text-align: center;
    margin: 0;
    padding: 20px 0;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    /* منع لوحة الصدارة من تجاوز حدود الشاشة على الهواتف */
    #main-area {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow-x: hidden;
    }

    .leaderboard-container {
        width: calc(100% - 24px);
        max-width: 100%;
        margin: 20px auto;
        padding: 16px 10px;
        overflow: hidden;
    }

    .leaderboard-grid {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        width: 100%;
        max-width: 100%;
        min-width: 0;
        margin: 0;
        padding: 0;
        gap: 12px;
        overflow: hidden;
    }

    .leaderboard-item,
    .leaderboard-item:nth-child(15) {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding: 10px 12px;
        box-sizing: border-box;
        transform: none;
        display: grid;
        grid-template-columns: 38px 46px minmax(0, 1fr) auto;
        align-items: center;
        gap: 9px;
        overflow: hidden;
    }

    .leaderboard-rank {
        min-width: 0;
        width: 38px;
        text-align: center;
    }

    .leaderboard-avatar {
        width: 46px;
        height: 46px;
    }

    .leaderboard-info {
        min-width: 0;
        width: 100%;
        overflow: hidden;
        text-align: left;
    }

    .leaderboard-score {
        min-width: 0;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .leaderboard-container {
        width: calc(100% - 20px);
        padding-left: 8px;
        padding-right: 8px;
    }

    .leaderboard-item,
    .leaderboard-item:nth-child(15) {
        grid-template-columns: 34px 42px minmax(0, 1fr) auto;
        gap: 7px;
        padding: 9px 9px;
    }

    .leaderboard-rank {
        width: 34px;
        font-size: 1rem;
    }

    .leaderboard-avatar {
        width: 42px;
        height: 42px;
    }

    .leaderboard-score {
        max-width: 104px;
        font-size: 0.82rem;
    }
}

/* ================================
   9. القائمة الجانبية
   ================================ */
#sidebar {
    position: fixed;
    top: 0;
    right: -280px;
    width: 280px;
    height: 100%;
    background:
        linear-gradient(180deg,
            rgba(30, 17, 69, .96),
            rgba(9, 10, 31, .98));

    backdrop-filter: blur(25px);
    z-index: 10000;
    transition: 0.5s;
    padding: 80px 20px 20px 20px;
    border-left: 2px solid var(--light-purple);
    display: flex;
    flex-direction: column;
}

#sidebar.open {
    right: 0;
}

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

.menu-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--light-purple);
    color: #fff;
    padding: 12px 18px;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
    border: none;
}

.nav-item {
    width: 100%;
    padding: 15px;
    margin-bottom: 12px;
    background: var(--glass);
    border-radius: 12px;
    color: var(--text-light);
    font-weight: bold;
    text-align: right;
    cursor: pointer;
    border: none;
    transition: 0.2s;
}

.nav-item.active {
    background: var(--light-purple);
    color: #fff;
}

/* ================================
   10. شبكة المحتوى العامة
   ================================ */
.content-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    padding: 15px;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
}

/* ================================
   10.5. الحاوية الكبيرة الموحّدة (تضم الحروف / الكلمات)
   ================================ */
.mega-panel {
    background: var(--glass);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 25px;
    padding: 12px;
    margin: 10px auto 20px;
    width: 95%;
    max-width: 1000px;
    box-sizing: border-box;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}

@media (max-width: 480px) {
    .mega-panel {
        width: 100%;
        padding: 8px;
        border-radius: 18px;
    }
}

/* ================================
   11. شبكة الحروف مع Media Queries (الإصلاح)
   ================================ */
#letters-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    /* دائماً 5 حروف في كل صف */
    gap: 10px;
    padding: 12px;
    width: 100%;
    box-sizing: border-box;
    transition: all 0.4s ease;
}

/* الأجهزة اللوحية: 5 أعمدة */
@media (max-width: 768px) {
    #letters-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 7px;
        padding: 10px;
    }
}

/* الهواتف: 5 أعمدة دائماً */
@media (max-width: 480px) {
    #letters-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 5px;
        padding: 8px;
    }
}

/* ================================
   12. بطاقات الحروف (دمج التكرارات)
   ================================ */
/* ملاحظة أداء: تم حذف backdrop-filter من هنا (كان مطبقاً على ٧٥ بطاقة
   في نفس اللحظة وهو أثقل خاصية CSS من ناحية الأداء على الهواتف).
   تم تعويض المظهر الزجاجي بخلفية أغمق قليلاً بدلاً من التمويه الحي. */
.char-card {
    background: rgba(255, 255, 255, .055);

    border: 1px solid rgba(255, 255, 255, .08);

    border-radius: 22px;

    aspect-ratio: 1 / 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    box-shadow: 0 8px 25px rgba(0, 0, 0, .20);

    transition:
        transform .35s ease,
        box-shadow .35s ease,
        border-color .35s ease;
}

.char-card:hover {
    transform:
        translateY(-8px) scale(1.03);

    border-color:
        rgba(139, 92, 246, .5);

    box-shadow:
        0 15px 35px rgba(139, 92, 246, .25),
        0 0 20px rgba(139, 92, 246, .20);
}

/* دمج التكرارات الثلاثة لـ .char-card:active */
.char-card:active {
    transform: scale(0.9);
    background: var(--light-purple);
}

.char-jp {
    font-family: var(--font-jp) !important;
    font-size: 2.3rem;
    font-weight: 700;

    text-shadow:
        0 0 10px rgba(255, 255, 255, .3),
        0 0 20px rgba(139, 92, 246, .4);
}

.char-ro {
    font-size: 0.9rem;
    color: var(--yellow-gold);
    text-transform: lowercase;
    font-weight: bold;
}

/* تكبير الحروف للشاشات الكبيرة */
@media (min-width: 1200px) {
    .char-jp {
        font-size: 3rem;
    }

    .content-grid {
        gap: 25px;
    }
}

/* تصغير الحروف على الهواتف لتتسع 5 في الصف */
@media (max-width: 480px) {
    .char-card {
        border-radius: 12px;
        padding: 8px 3px;
    }

    .char-jp {
        font-size: 1.3rem !important;
    }

    .char-ro {
        font-size: 0.65rem;
    }
}

@media (max-width: 768px) and (min-width: 481px) {
    .char-card {
        border-radius: 16px;
        padding: 10px 5px;
    }

    .char-jp {
        font-size: 1.6rem !important;
    }

    .char-ro {
        font-size: 0.75rem;
    }
}

/* ================================
   13. العناصر الأخرى
   ================================ */
.item-box {
    background: var(--glass);
    margin: 12px;
    padding: 15px;
    border-radius: 18px;
    border-right: 5px solid var(--yellow-gold);
    display: flex;
    align-items: center;
    gap: 15px;
    text-align: right;
    cursor: pointer;
}

/* ================================
   13.4 بطاقة القناة الاحترافية (الدروس / القصص)
   ================================ */
.channel-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 16px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.08), var(--glass));
    border: 1px solid rgba(139, 92, 246, 0.28);
    border-radius: 18px;
    padding: 16px 18px;
    margin-bottom: 18px;
    cursor: pointer;
    text-decoration: none;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.3);
    transition: transform 0.25s var(--ease-smooth), box-shadow 0.25s var(--ease-smooth),
                border-color 0.25s var(--ease-smooth), background 0.25s var(--ease-smooth);
}

.channel-card::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    inset-inline-end: 0;
    width: 4px;
    border-radius: 18px 0 0 18px;
    background: linear-gradient(180deg, var(--yellow-gold), rgba(255, 193, 7, 0.12));
    opacity: 0.65;
    transition: opacity 0.25s ease;
}

.channel-card:hover,
.channel-card:focus-visible {
    transform: translateY(-3px);
    border-color: rgba(139, 92, 246, 0.6);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.14), var(--glass));
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35), 0 0 22px rgba(139, 92, 246, 0.22);
    outline: none;
}

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

.channel-logo-wrap {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(139, 92, 246, 0.18);
    border: 2px solid rgba(139, 92, 246, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--yellow-gold);
    box-shadow: 0 0 18px rgba(139, 92, 246, 0.4), 0 0 34px rgba(255, 193, 7, 0.14);
    transition: transform 0.25s var(--ease-smooth), box-shadow 0.25s var(--ease-smooth);
}

.channel-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.channel-info {
    flex: 1;
    min-width: 0;
}

.channel-name {
    margin: 0 0 4px 0;
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text-light);
}

.channel-stats {
    margin: 0 0 4px 0;
    font-size: 0.82rem;
    font-weight: 600;
    color: rgba(245, 243, 255, 0.65);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: right;
}

.channel-type {
    margin: 0;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--yellow-gold);
    opacity: 0.85;
}

.channel-cta {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, var(--yellow-gold), #ffd54f);
    color: var(--navy-bg);
    font-size: 0.82rem;
    font-weight: 800;
    padding: 9px 16px;
    border-radius: var(--radius-full);
    white-space: nowrap;
    box-shadow: 0 0 14px rgba(255, 193, 7, 0.25);
    transition: transform 0.25s var(--ease-smooth), box-shadow 0.25s var(--ease-smooth), filter 0.25s ease;
}

.channel-card:hover .channel-logo-wrap {
    transform: scale(1.05);
    box-shadow: 0 0 22px rgba(139, 92, 246, 0.55), 0 0 40px rgba(255, 193, 7, 0.18);
}

.channel-card:hover .channel-cta,
.channel-card:focus-visible .channel-cta {
    filter: brightness(1.1);
    box-shadow: 0 0 18px rgba(255, 193, 7, 0.4);
}

@media (max-width: 480px) {
    .channel-card {
        flex-wrap: wrap;
        gap: 12px;
        padding: 14px;
    }

    .channel-logo-wrap {
        width: 54px;
        height: 54px;
    }

    .channel-cta {
        width: 100%;
        justify-content: center;
        padding: 10px 16px;
    }
}

/* ================================
   13.5 شبكة بطاقات مربعة (الدروس / القصص)
   ================================ */
.square-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px;
    padding: 15px;
    width: 100%;
    box-sizing: border-box;
}

.square-card {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 18px;
    overflow: hidden;
    background: var(--glass);
    border: 1px solid rgba(255, 255, 255, 0.08);
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.square-card:hover {
    transform: translateY(-6px) scale(1.03);
    border-color: rgba(139, 92, 246, 0.5);
    box-shadow: 0 15px 35px rgba(139, 92, 246, 0.25), 0 0 20px rgba(139, 92, 246, 0.2);
}

.square-card:active {
    transform: scale(0.95);
}

.square-card-thumb {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
}

.square-card-overlay {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 10px;
    background: linear-gradient(to top, rgba(9, 10, 31, 0.92) 20%, rgba(9, 10, 31, 0.15) 70%, rgba(9, 10, 31, 0) 100%);
}

.square-card-title {
    font-size: 0.85rem;
    font-weight: bold;
    color: #fff;
    margin: 0 0 4px 0;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.square-card-play {
    align-self: flex-start;
    color: var(--yellow-gold);
    font-size: 1.3rem;
}

@media (min-width: 1024px) {
    .square-card-grid {
        grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
        gap: 20px;
        padding: 20px;
    }

    .square-card-title {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .square-card-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        padding: 10px;
    }

    .square-card-title {
        font-size: 0.7rem;
    }

    .square-card-play {
        font-size: 1rem;
    }
}

/* ================================
   14. النوافذ المنبثقة
   ================================ */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 50000;
}

.modal-content {
    background:
        linear-gradient(145deg,
            rgba(30, 17, 69, .95),
            rgba(9, 10, 31, .95));

    backdrop-filter: blur(25px);

    border: 1px solid rgba(255, 255, 255, .08);

    box-shadow:
        0 20px 60px rgba(0, 0, 0, .45);

    border-radius: 30px;
}

.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

/* ================================
   15. أنيميشنات النوافذ (إصلاح popInModal)
   ================================ */

/* تعريف @keyframes الصحيح لـ modalFadeIn */
@keyframes modalFadeIn {
    0% {
        opacity: 0;
        transform: scale(0.92) translateY(15px);
    }

    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes modalFadeOut {
    0% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }

    100% {
        opacity: 0;
        transform: scale(0.92) translateY(15px);
    }
}

/* دمج التكرارين لـ .modal-anim-active — يستخدم modalFadeIn */
.modal-anim-active {
    animation: modalFadeIn 0.35s ease-out forwards;
}

.modal-anim-closing {
    animation: modalFadeOut 0.3s ease-in forwards;
}

@keyframes fadeInBg {
    from {
        background-color: rgba(9, 10, 31, 0);
    }

    to {
        background-color: rgba(9, 10, 31, 0.95);
    }
}

@keyframes fadeOutBg {
    from {
        background-color: rgba(9, 10, 31, 0.95);
    }

    to {
        background-color: rgba(9, 10, 31, 0);
    }
}

.modal-bg-enter {
    animation: fadeInBg 0.4s forwards;
}

.modal-bg-leave {
    animation: fadeOutBg 0.4s forwards;
}

/* ================================
   16. صفحة تسجيل الدخول والتسجيل
   ================================ */
#login-modal .modal-content,
#signup-modal .modal-content {
    background: linear-gradient(-45deg, #1e1145, #090a1f, #2a1b54, #1e1145);
    background-size: 400% 400%;
    animation: loginGradient 8s ease infinite, loginFloat 6s infinite ease-in-out;
    border: 2px solid var(--light-purple);
    box-shadow: 0 10px 30px rgba(139, 92, 246, 0.3);
    border-radius: 20px;
}

@keyframes loginGradient {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

@keyframes loginFloat {
    0% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-10px);
    }

    100% {
        transform: translateY(0px);
    }
}

#regBtn {
    background: #222 !important;
    border: 1px solid #444;
    color: #ccc;
    transition: 0.3s;
    border-radius: 5px;
}

#regBtn:hover {
    background: #333 !important;
    color: #fff;
}

/* ================================
   17. الملف الشخصي في الشريط الجانبي
   ================================ */
.bottom-profile-btn {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: transparent;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: 0.3s;
    border: none;
    width: 100%;
}

.bottom-profile-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.bottom-profile-btn img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.bottom-profile-btn span {
    color: white;
    font-weight: bold;
    font-size: 1.1rem;
}

/* ================================
   18. زر Google
   ================================ */
.google-btn-modern {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 15px;
    background: rgba(255, 255, 255, 0.05);
    color: white;
    padding: 12px;
    border-radius: 12px;
    width: 100%;
    border: 1px solid rgba(139, 92, 246, 0.5);
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
}

.google-btn-modern:hover {
    background: var(--light-purple);
    box-shadow: 0 0 20px var(--purple-glow);
    transform: translateY(-2px);
    border-color: white;
}

.google-btn-modern svg {
    background: white;
    padding: 3px;
    border-radius: 5px;
}

.google-btn-modern:active {
    transform: scale(0.98);
}

#signup-trigger-btn {
    margin-top: 25px !important;
    background: rgba(139, 92, 246, 0.1) !important;
    border: 1px dashed var(--light-purple) !important;
}

/* ================================
   19. حقول الإدخال
   ================================ */
.transparent-input {
    background: transparent !important;
    border: 1px solid rgba(139, 92, 246, 0.4);
    color: #ffffff;
    padding: 15px;
    border-radius: 12px;
    width: 100%;
    margin-bottom: 15px;
    font-size: 1rem;
    transition: all 0.4s ease;
    text-align: right;
    box-sizing: border-box;
}

.transparent-input:focus {
    outline: none;
    border-color: #fff;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.8), 0 0 12px rgba(128, 128, 128, 0.6);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.02) !important;
}

/* ================================
   20. تتبع الوقت — زر صغير تحت القائمة
   ================================ */
#time-tracker {
    position: fixed;
    top: 72px;
    /* تحت زر القائمة مباشرة (20px top + ~40px height + 12px gap) */
    right: 20px;
    background: var(--light-purple);
    color: #fff;
    padding: 10px 14px;
    border-radius: 12px;
    font-weight: bold;
    font-size: 0.85rem;
    z-index: 1001;
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 14px rgba(139, 92, 246, 0.4);
    transition: 0.2s;
    white-space: nowrap;
    backdrop-filter: blur(10px);
}

#time-tracker:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.6);
}

#time-tracker:active {
    transform: scale(0.95);
}

/* ================================
   20ب. تتبع السلسلة اليومية (Streak)
   ================================ */
#streak-tracker {
    position: fixed;
    top: 126px;
    /* أسفل عداد الوقت مباشرة */
    right: 20px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--yellow-gold, #ffc107);
    padding: 10px 14px;
    border-radius: 12px;
    font-weight: bold;
    font-size: 0.85rem;
    z-index: 1001;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    transition: 0.2s;
    white-space: nowrap;
    backdrop-filter: blur(10px);
}

#streak-tracker:hover {
    transform: scale(1.05);
    border-color: var(--yellow-gold, #ffc107);
    box-shadow: 0 0 12px rgba(255, 193, 7, 0.4);
}

#streak-tracker:active {
    transform: scale(0.95);
}

/* شارات الإنجازات داخل الملف الشخصي */
.badge-chip {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    cursor: default;
}

.badge-chip.badge-unlocked {
    background: rgba(255, 193, 7, 0.15);
    border: 1.5px solid var(--yellow-gold, #ffc107);
    box-shadow: 0 0 10px rgba(255, 193, 7, 0.3);
}

.badge-chip.badge-locked {
    background: rgba(255, 255, 255, 0.04);
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    filter: grayscale(1);
    opacity: 0.4;
}


/* ================================
   20b. صور مصغرة لفيديوهات الدروس
   ================================ */
.lesson-video-card {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.lesson-video-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(139, 92, 246, 0.35);
}

.video-thumbnail {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    display: block;
    border-radius: 12px;
    background: var(--deep-purple);
}

/* صورة مصغرة يوتيوب من الرابط */
.video-thumb-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    margin-top: 8px;
}

.video-thumb-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.video-thumb-wrapper:hover img {
    transform: scale(1.05);
}

/* زر التشغيل فوق الصورة */
.video-thumb-wrapper .play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 52px;
    height: 52px;
    background: rgba(255, 0, 0, 0.85);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    transition: background 0.2s;
}

.video-thumb-wrapper:hover .play-icon {
    background: rgba(255, 0, 0, 1);
}

.video-thumb-wrapper .play-icon::after {
    content: "";
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-left: 18px solid #fff;
    margin-left: 4px;
}

/* تسمية الفيديو */
.video-label {
    font-size: 0.9rem;
    color: var(--text-light);
    padding: 6px 4px 4px;
    text-align: right;
    font-weight: 600;
}

/* ================================
   21. حاوية الرسم (دمج التكرارين)
   ================================ */
.drawing-container {
    position: relative;
    width: 100%;
    min-height: 260px;
    max-width: 420px;
    background: #14101f;
    border: 2px solid var(--light-purple);
    box-shadow: 0 0 25px rgba(139, 92, 246, 0.25), inset 0 0 30px rgba(0, 0, 0, 0.5);
    margin: 20px auto;
    border-radius: 16px;
    overflow: hidden;
}

/* ================================
   22. علامة مائية الحرف (دمج التكرارين)
   ================================ */
#watermark-char {
    font-family: var(--font-jp) !important;
    font-size: 180px;
    color: rgba(255, 255, 255, 0.08);
    z-index: 1;
    position: absolute;
    user-select: none;
    pointer-events: none;
}

/* ================================
   23. أزرار التنقل داخل النافذة
   ================================ */
.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: white;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    border-radius: 50%;
    cursor: pointer;
    transition: 0.3s;
    border: none;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-50%) scale(1.1);
}

.nav-btn:active {
    transform: translateY(-50%) scale(0.95);
}

.nav-btn.prev {
    left: 15px;
}

.nav-btn.next {
    right: 15px;
}

/* ================================
   24. لوحة الرسم
   ================================ */
#practice-canvas {
    background: transparent;
    /* شفاف عشان تبان شبكة الإرشاد اللي وراه (drawing-container) */
    border-radius: 12px;
    cursor: crosshair;
    touch-action: none;
}

/* ================================
   25. حزمة الأنيميشنات
   ================================ */
.fade-in {
    opacity: 0;
    transform: translateY(20px);
    animation: fadeInUp 0.8s ease forwards;
}

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.glow-hover {
    transition: 0.3s;
}

.glow-hover:hover {
    box-shadow: 0 0 20px #8b5cf6, 0 0 40px #8b5cf6;
    transform: scale(1.05);
}

.ripple {
    position: relative;
    overflow: hidden;
}

.ripple:active::after {
    content: "";
    position: absolute;
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: scale(0);
    animation: rippleEffect 0.6s linear;
}

@keyframes rippleEffect {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

.float {
    animation: floatAnim 4s ease-in-out infinite;
}

@keyframes floatAnim {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-15px);
    }
}

.pulse {
    animation: pulseAnim 1.5s infinite;
}

@keyframes pulseAnim {
    0% {
        box-shadow: 0 0 0 0 rgba(139, 92, 246, 0.7);
    }

    70% {
        box-shadow: 0 0 0 20px rgba(139, 92, 246, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(139, 92, 246, 0);
    }
}

.card-3d {
    transition: transform 0.3s;
}

.card-3d:hover {
    transform: rotateY(10deg) rotateX(10deg) scale(1.05);
}

.animated-bg {
    background: linear-gradient(-45deg, #1e1145, #090a1f, #8b5cf6, #1e1145);
    background-size: 400% 400%;
    animation: gradientMove 10s ease infinite;
}

@keyframes gradientMove {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

@keyframes sparkle {
    0% {
        opacity: 1;
        transform: scale(1);
    }

    100% {
        opacity: 0;
        transform: scale(2) translateY(-20px);
    }
}

/* ================================
   26. أنيميشنات التبديل بين الحروف
   ================================ */
@keyframes slideInRight {
    0% {
        opacity: 0;
        transform: translateX(30px);
    }

    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInLeft {
    0% {
        opacity: 0;
        transform: translateX(-30px);
    }

    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

.slide-right-anim {
    animation: slideInRight 1s ease-out forwards;
}

.slide-left-anim {
    animation: slideInLeft 1s ease-out forwards;
}

/* ================================
   27. أزرار المصادقة
   ================================ */
.auth-btn {
    background: linear-gradient(45deg, #8b5cf6, #a78bfa);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 14px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
    width: 100%;
}

.auth-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(139, 92, 246, 0.4);
}

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

/* ================================
   28. زر التنزيل
   ================================ */
.download-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    background: var(--light-purple);
    color: #fff;
    padding: 10px 16px;
    border-radius: 12px;
    font-weight: bold;
    text-decoration: none;
    z-index: 1001;
    box-shadow: 0 0 12px var(--purple-glow);
    transition: 0.2s;
}

.download-btn:active {
    transform: scale(0.9);
}

/* ================================
   29. مؤشر التحديث
   ================================ */
#refresh-indicator {
    position: fixed;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    width: 45px;
    height: 45px;
    background: var(--deep-purple);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border: 2px solid var(--light-purple);
    transition: top 0.3s;
}

.rotating {
    animation: spin 0.8s linear infinite;
}

/* ================================
   30. خيارات الاختبار (يُعاد استخدامها في نظام الدرس الجديد)
   ================================ */
.quiz-option {
    width: 100%;
    padding: 15px;
    margin: 8px 0;
    background: var(--deep-purple);
    color: white;
    border: 1px solid var(--light-purple);
    border-radius: 15px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.15s var(--ease-bounce), background 0.2s, border-color 0.2s, box-shadow 0.2s;
    animation: optionFadeIn 0.35s var(--ease-smooth) backwards;
}

.quiz-option:hover:not(:disabled) {
    border-color: var(--yellow-gold);
    box-shadow: 0 4px 14px rgba(139, 92, 246, 0.25);
}

.quiz-option:active:not(:disabled) {
    background: var(--light-purple);
    color: #fff;
    transform: scale(0.97);
}

.quiz-option:disabled {
    cursor: default;
    opacity: 0.9;
}

.quiz-option-correct {
    background: #1e824c !important;
    border-color: #2ecc71 !important;
    color: #fff !important;
    animation: optionCorrectPulse 0.5s var(--ease-bounce) !important;
}

.quiz-option-wrong {
    background: #7a1f1f !important;
    border-color: #ff4d4d !important;
    color: #fff !important;
    animation: optionShake 0.4s var(--ease-smooth) !important;
}

@keyframes optionFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes optionCorrectPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.55);
    }

    50% {
        transform: scale(1.03);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 14px rgba(46, 204, 113, 0);
    }
}

@keyframes optionShake {

    10%,
    90% {
        transform: translateX(-3px);
    }

    20%,
    80% {
        transform: translateX(5px);
    }

    30%,
    50%,
    70% {
        transform: translateX(-7px);
    }

    40%,
    60% {
        transform: translateX(7px);
    }
}

/* ================================
   30أ. نافذة الدرس نفسها — انتقال دخول/خروج ناعم بدل الظهور الفجائي
   ================================ */
#quiz-overlay {
    opacity: 0;
    transform: scale(0.96);
    transition: opacity 0.3s var(--ease-smooth), transform 0.3s var(--ease-smooth);
}

#quiz-overlay.quiz-open {
    opacity: 1;
    transform: scale(1);
}

/* ================================
   30ب. نظام الدرس (Lesson) — رأس الدرس: إغلاق + تقدّم + قلوب
   ================================ */
.lesson-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    max-width: 420px;
    margin-bottom: var(--space-4);
}

.lesson-close-btn {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    transition: transform 0.15s var(--ease-bounce), color 0.15s;
}

.lesson-close-btn:active {
    transform: scale(0.85) rotate(90deg);
    color: var(--yellow-gold);
}

.lesson-progress-track {
    flex: 1;
    height: 10px;
    background: var(--glass);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.lesson-progress-fill {
    position: relative;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--yellow-gold), #ffe08a, var(--yellow-gold));
    border-radius: var(--radius-full);
    box-shadow: 0 0 8px rgba(255, 193, 7, 0.6);
    transition: width 0.4s var(--ease-smooth);
    overflow: hidden;
}

.lesson-progress-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
    animation: progressShimmer 1.8s ease-in-out infinite;
}

@keyframes progressShimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

.lesson-hearts {
    font-size: 1.2rem;
    letter-spacing: 3px;
    white-space: nowrap;
}

.lesson-heart {
    display: inline-block;
    transition: transform 0.2s var(--ease-bounce);
}

.lesson-heart-lost {
    animation: heartBreak 0.55s var(--ease-smooth);
}

@keyframes heartBreak {
    0% {
        transform: scale(1.3) rotate(0deg);
    }

    30% {
        transform: scale(0.75) rotate(-18deg);
    }

    60% {
        transform: scale(1.2) rotate(12deg);
    }

    100% {
        transform: scale(1) rotate(0deg);
    }
}

.lesson-combo {
    color: var(--yellow-gold);
    font-weight: bold;
    font-size: 1rem;
    margin-bottom: var(--space-3);
    animation: comboPop 0.3s var(--ease-bounce);
    text-shadow: 0 0 10px rgba(255, 193, 7, 0.5);
}

@keyframes comboPop {
    0% {
        transform: scale(0.7);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ================================
   30ج. منطقة السؤال
   ================================ */
.lesson-question-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 420px;
    flex: 1;
    text-align: center;
}

.lesson-type-badge {
    color: var(--light-purple);
    font-size: 0.85rem;
    font-weight: bold;
    opacity: 0.9;
    margin-bottom: var(--space-3);
}

.lesson-prompt {
    font-size: 2.4rem;
    margin: var(--space-4) 0;
    color: var(--text-light);
    word-break: break-word;
    animation: promptIn 0.4s var(--ease-smooth);
}

@keyframes promptIn {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.lesson-interaction {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lesson-play-btn {
    background: var(--deep-purple);
    border: 2px solid var(--light-purple);
    color: var(--text-light);
    font-size: 2.4rem;
    padding: 18px 26px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s;
}

.lesson-play-btn:active {
    transform: scale(0.9);
}

/* اكتب النطق */
.lesson-text-input {
    width: 100%;
    padding: 14px;
    margin: var(--space-4) 0;
    border-radius: var(--radius-md);
    border: 1px solid var(--light-purple);
    background: var(--deep-purple);
    color: white;
    font-size: 1.2rem;
    text-align: center;
}

.lesson-text-input:focus {
    outline: none;
    border-color: var(--yellow-gold);
}

.lesson-input-correct {
    border-color: #2ecc71 !important;
    box-shadow: 0 0 0 2px rgba(46, 204, 113, 0.4);
    animation: answerCorrectPulse 0.5s var(--ease-bounce);
}

.lesson-input-wrong {
    border-color: #ff4d4d !important;
    box-shadow: 0 0 0 2px rgba(255, 77, 77, 0.4);
    animation: answerShake 0.4s var(--ease-smooth);
}

/* رتّب الحروف */
/* مهم: direction: ltr إجباري هنا لأن حروف الروماجي لاتينية (LTR) بينما
   الصفحة كلها RTL. بدون هذا، ترتيب الشرائح المرئي ينعكس داخل حاوية flex
   RTL حتى لو كان ترتيب الضغط الفعلي من المستخدم صحيحاً 100% -- وهذا بالضبط
   سبب ظهور الكلمة "مبعثرة" رغم أن المستخدم رتّبها صح. */
.lesson-order-answer {
    direction: ltr;
    min-height: 58px;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: var(--space-3);
    margin-bottom: var(--space-4);
    border-radius: var(--radius-md);
    background: var(--glass);
    border: 2px dashed var(--light-purple);
    transition: border-color 0.25s, background 0.25s, box-shadow 0.25s;
}

.lesson-order-chips {
    direction: ltr;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    justify-content: center;
    width: 100%;
}

.lesson-order-chip {
    background: var(--deep-purple);
    border: 1px solid var(--light-purple);
    color: white;
    font-size: 1.25rem;
    font-weight: bold;
    padding: 10px 16px;
    min-width: 44px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform 0.15s var(--ease-bounce), background 0.2s, box-shadow 0.2s, opacity 0.25s;
    animation: chipPopIn 0.35s var(--ease-bounce) backwards;
}

.lesson-order-chip:hover:not(.lesson-chip-used) {
    border-color: var(--yellow-gold);
    box-shadow: 0 3px 10px rgba(139, 92, 246, 0.3);
}

.lesson-order-chip:active:not(.lesson-chip-used) {
    transform: scale(0.88);
}

@keyframes chipPopIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.6);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.lesson-order-placed {
    background: var(--light-purple);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.4);
}

.lesson-chip-used {
    opacity: 0.2;
    pointer-events: none;
    transform: scale(0.9);
}

.lesson-order-answer.lesson-input-correct {
    border-style: solid;
    border-color: #2ecc71;
    background: rgba(46, 204, 113, 0.12);
    animation: answerCorrectPulse 0.5s var(--ease-bounce);
}

.lesson-order-answer.lesson-input-wrong {
    border-style: solid;
    border-color: #ff4d4d;
    background: rgba(255, 77, 77, 0.1);
    animation: answerShake 0.4s var(--ease-smooth);
}

@keyframes answerCorrectPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.5);
    }

    100% {
        box-shadow: 0 0 0 14px rgba(46, 204, 113, 0);
    }
}

@keyframes answerShake {

    10%,
    90% {
        transform: translateX(-4px);
    }

    20%,
    80% {
        transform: translateX(6px);
    }

    30%,
    50%,
    70% {
        transform: translateX(-8px);
    }

    40%,
    60% {
        transform: translateX(8px);
    }
}

.lesson-primary-btn {
    background: var(--light-purple);
    color: white;
    border: none;
    padding: 14px 40px;
    border-radius: var(--radius-md);
    font-weight: bold;
    font-size: 1.05rem;
    margin-top: var(--space-5);
    cursor: pointer;
    transition: transform 0.15s var(--ease-bounce), box-shadow 0.2s, background 0.2s;
}

.lesson-primary-btn:hover:not(:disabled) {
    box-shadow: 0 6px 18px rgba(139, 92, 246, 0.4);
}

.lesson-primary-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.lesson-primary-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

/* ================================
   30د. شريط التغذية الراجعة السريعة
   ================================ */
.lesson-feedback {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    padding: 18px 20px;
    text-align: center;
    font-weight: bold;
    font-size: 1.05rem;
    color: white;
    transform: translateY(100%);
    transition: transform 0.3s var(--ease-bounce), box-shadow 0.3s;
    z-index: 60010;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

.lesson-feedback-show {
    transform: translateY(0);
}

.lesson-feedback-correct {
    background: linear-gradient(135deg, #1e824c, #27ae60);
}

.lesson-feedback-wrong {
    background: linear-gradient(135deg, #7a1f1f, #a63232);
}

/* ================================
   30هـ. شاشة ملخص الدرس
   ================================ */
.lesson-summary {
    position: fixed;
    inset: 0;
    background: var(--navy-bg);
    z-index: 60005;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.lesson-summary-card {
    background: var(--deep-purple);
    border-radius: var(--radius-lg);
    padding: 40px 30px;
    max-width: 400px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    animation: summaryPopIn 0.45s var(--ease-bounce);
}

@keyframes summaryPopIn {
    from {
        opacity: 0;
        transform: scale(0.85) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* ================================
   30و. [درس اليوم] قفل 24 ساعة + عقوبة XP
   ================================ */
/* عدّاد القفل التنازلي بجانب زر درس الكلمات */
.lesson-cooldown {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin: 8px 14px 12px;
    padding: 8px 12px;
    background: rgba(255, 193, 7, 0.08);
    border: 1px solid rgba(255, 193, 7, 0.35);
    border-radius: 12px;
    font-size: 0.78rem;
    color: var(--yellow-gold);
    text-align: center;
    animation: cooldownIn 0.35s var(--ease-bounce);
}

.lesson-cooldown-label {
    opacity: 0.85;
}

.lesson-cooldown-time {
    font-variant-numeric: tabular-nums;
    font-weight: bold;
    letter-spacing: 1px;
    direction: ltr;
}

@keyframes cooldownIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* زر درس الكلمات عند القفل */
.nav-item[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
    filter: saturate(0.4);
}

/* نافذة خصم XP العائمة (-5 / -20 / -50) */
.lesson-xp-penalty {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.35rem;
    font-weight: bold;
    color: #ff6b6b;
    text-shadow: 0 0 14px rgba(255, 107, 107, 0.7);
    opacity: 0;
    pointer-events: none;
    z-index: 60011;
}

.lesson-xp-penalty-show {
    animation: xpPenaltyPop 1.4s ease-out forwards;
}

@keyframes xpPenaltyPop {
    0% {
        opacity: 0;
        transform: translateX(-50%) translateY(0) scale(0.7);
    }

    20% {
        opacity: 1;
        transform: translateX(-50%) translateY(-10px) scale(1.15);
    }

    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-50px) scale(1);
    }
}

/* رسالة اكتمال جميع الأسئلة في شاشة الملخص */
.lesson-summary-completion {
    margin-top: 10px;
    padding: 12px 14px;
    background: rgba(76, 175, 80, 0.12);
    border: 1px solid rgba(76, 175, 80, 0.4);
    border-radius: 12px;
    color: #9ce6a1;
    font-size: 0.9rem;
    line-height: 1.7;
    text-align: center;
    animation: summaryPopIn 0.45s var(--ease-bounce);
}

.lesson-stat-value {
    display: inline-block;
    animation: comboPop 0.4s var(--ease-bounce) 0.1s backwards;
}

.lesson-summary-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin: 25px 0;
}

.lesson-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lesson-stat-value {
    font-size: 2.2rem;
    font-weight: bold;
    color: var(--yellow-gold);
}

.lesson-stat-label {
    font-size: 0.85rem;
    color: var(--light-purple);
    margin-top: 4px;
}

.lesson-summary-mistakes {
    text-align: right;
    max-height: 150px;
    overflow-y: auto;
    margin: var(--space-4) 0;
    background: var(--glass);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    font-size: 0.9rem;
    line-height: 1.9;
    color: var(--text-light);
}

/* ================================
   31. رسائل الخطأ للمستخدم
   ================================ */
.error-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #c0392b;
    color: white;
    padding: 12px 24px;
    border-radius: 10px;
    z-index: 99999;
    font-weight: bold;
    animation: fadeInUp 0.3s ease;
    max-width: 90%;
    text-align: center;
}

.success-toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #27ae60;
    color: white;
    padding: 12px 24px;
    border-radius: 10px;
    z-index: 99999;
    font-weight: bold;
    animation: fadeInUp 0.3s ease;
    max-width: 90%;
    text-align: center;
}

/* ================================
   32. دعم تقليل الحركة (Accessibility)
   ================================ */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ================================
   33. تحسين Focus للوصول (Accessibility)
   ================================ */
button:focus-visible,
a:focus-visible,
input:focus-visible {
    outline: 3px solid var(--light-purple);
    outline-offset: 2px;
}

.nav-item {
    position: relative;
    overflow: hidden;
}

.nav-item::before {
    content: "";
    position: absolute;

    top: 0;
    left: -100%;

    width: 100%;
    height: 100%;

    background:
        linear-gradient(90deg,
            transparent,
            rgba(255, 255, 255, .08),
            transparent);

    transition: .6s;
}

.nav-item:hover::before {
    left: 100%;
}

/* ملاحظة أداء: تم حذف تعريف smoothAppear المكرر هنا — كان يُشغّل
   أنيميشن دخول مطابق تماماً لـ .fade-in على كل بطاقة حرف مرتين في
   نفس الوقت (٧٥ بطاقة × أنيميشنين). .fade-in وحدها تكفي وتحافظ
   على نفس تأثير الدخول تماماً. */

@media (hover:none) {

    .char-card:hover {
        transform: none;
        box-shadow: none;
    }

    .nav-item:hover {
        transform: none;
    }

}

/* ==========================================
   تطوير عداد الوقت الحالي (#time-tracker) ليكون زراً ممتداً
   ========================================== */
#time-tracker {
    display: flex !important;
    align-items: center;
    justify-content: flex-start;
    width: 44px;
    /* العرض الابتدائي الصغير (يحتوي الأيقونة فقط) */
    height: 44px;
    padding: 10px !important;
    border-radius: 50px !important;
    /* حواف دائرية بالكامل */
    overflow: hidden !important;
    /* إخفاء النص عندما يكون الزر منكمشاً */
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
    /* حركة تمدد ناعمة جداً */
    background: rgba(255, 255, 255, 0.06) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
    user-select: none;
    white-space: nowrap;
}

/* تأثير جميل عند تمرير الماوس (تحويم) */
#time-tracker:hover {
    background: rgba(255, 255, 255, 0.12) !important;
    border-color: var(--light-purple, #8b5cf6) !important;
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.4);
}

/* قلب الساعة الرملية بشكل خفيف عند حوم الماوس لإعطاء حيوية للموقع */
#time-tracker:hover .hourglass-svg {
    transform: rotate(180deg);
}

/* حاوية الأيقونة الثابتة لعدم تشوهها عند الحركة */
.time-tracker-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    min-width: 24px;
}

.hourglass-svg {
    width: 20px;
    height: 20px;
    color: var(--yellow-gold, #ffc107);
    transition: transform 0.6s ease;
}

/* حاوية النص والوقت المخفية مؤقتاً */
.time-tracker-content {
    display: flex;
    align-items: center;
    margin-right: 10px;
    /* مسافة تفصل النص عن الأيقونة في الوضع العربي RTL */
    opacity: 0;
    transform: translateX(15px);
    /* إزاحة خفيفة تندفع مع الحركة */
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#time-display {
    font-weight: 700;
    color: var(--text-light, #f5f3ff) !important;
}

/* ==========================================
   الحالة الممتدة للزر عند الضغط عليه (Expanded)
   ========================================== */
#time-tracker.expanded {
    width: 140px;
    /* يتسع العرض ليظهر الوقت بوضوح */
    background: rgba(139, 92, 246, 0.2) !important;
    /* إضاءة بنفسجية خفيفة عند الفتح */
    border-color: var(--light-purple, #8b5cf6) !important;
}

#time-tracker.expanded .time-tracker-content {
    opacity: 1;
    transform: translateX(0);
    /* عودة النص لمكانه الطبيعي بظهور سلس */
}

/* ================================
   24. محرك التدريب على الكتابة (Ringotan-Style White Screen Tracing)
   ================================ */

#writing-modal.writing-white-modal {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background: #ffffff !important;
    z-index: 70000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 16px 20px;
    overflow: hidden;
}

.writing-modal-content {
    width: 100%;
    max-width: 500px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* 1. إعادة تنسيق رأس الدرس لسياق الخلفية البيضاء */
.writing-lesson-header {
    width: 100%;
    max-width: 440px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.writing-lesson-header .lesson-close-btn {
    color: #64748b;
    font-size: 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    transition: color 0.15s ease, transform 0.15s ease;
}

.writing-lesson-header .lesson-close-btn:hover {
    color: #0f172a;
    transform: scale(1.1);
}

.writing-lesson-header .lesson-progress-track {
    flex: 1;
    height: 6px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
    box-shadow: none;
    border: none;
}

.writing-lesson-header .lesson-progress-fill {
    height: 100%;
    width: 0%;
    background: #22c55e;
    border-radius: 999px;
    box-shadow: none;
    transition: width 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 2. عنوان التتبع: Trace the character [char] ([ROMAJI]) */
.writing-title-area {
    text-align: center;
    margin-bottom: 16px;
    user-select: none;
}

.writing-instruction-title {
    font-family: 'Fredoka', 'Nunito', 'Cairo', sans-serif !important;
    font-weight: 700;
    font-size: 1.35rem;
    color: #1e293b;
    margin: 0;
    direction: ltr;
    display: inline-block;
}

.writing-instruction-title #writing-char-title {
    font-size: 1.55rem;
    font-weight: 800;
    color: #0f172a;
}

.writing-instruction-title #writing-romaji-title {
    font-weight: 800;
    text-transform: uppercase;
    color: #0f172a;
}

/* 3. منطقة التتبع المركزية العملاقة */
.writing-tracing-container {
    flex: 1;
    width: 100%;
    max-width: 440px;
    max-height: 520px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    touch-action: none;
    user-select: none;
    margin: auto 0;
}

#writing-svg {
    width: 100%;
    height: 100%;
    max-height: 480px;
    touch-action: none;
    user-select: none;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#writing-svg.success-pulse {
    animation: charSuccessPulse 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

    50% {
        transform: scale(1.08);
    }

    100% {
        transform: scale(1);
    }
}

/* مسارات الـ SVG */
.stroke-guide {
    stroke: #e2e8f0;
    stroke-width: 12;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.stroke-ink {
    stroke: #0f172a;
    stroke-width: 12;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
    transition: stroke-dashoffset 0.05s linear;
}

@media (max-width: 480px) {
    #writing-modal.writing-white-modal {
        padding: 12px 16px;
    }

    .writing-instruction-title {
        font-size: 1.15rem;
    }

    .writing-instruction-title #writing-char-title {
        font-size: 1.35rem;
    }
}

/* ================================================================
   34. نظام الأزرار الموحد (Button System)
   استخدمه بدل ما تكتب style="" في كل زرار جديد
   الاستخدام: <button class="btn btn-primary">نص</button>
   ================================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 22px;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 700;
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    transition:
        transform 0.25s var(--ease-smooth),
        box-shadow 0.25s var(--ease-smooth),
        background 0.25s var(--ease-smooth),
        filter 0.2s ease;
}

.btn:active {
    transform: scale(0.96);
}

/* الزرار الأساسي - للأفعال المهمة (حفظ، تأكيد، بدء) */
.btn-primary {
    background: linear-gradient(135deg, var(--light-purple), #6d28d9);
    color: #fff;
    box-shadow: 0 4px 18px rgba(139, 92, 246, 0.45);
}

.btn-primary:hover {
    filter: brightness(1.12);
    transform: translateY(-2px);
    box-shadow: 0 8px 26px rgba(139, 92, 246, 0.55);
}

/* زرار محدد - لأفعال ثانوية */
.btn-outline {
    background: transparent;
    color: var(--light-purple);
    border: 2px solid var(--light-purple);
}

.btn-outline:hover {
    background: rgba(139, 92, 246, 0.12);
    transform: translateY(-2px);
}

/* زرار شفاف خفيف - لأفعال أقل أهمية (إلغاء، تم) */
.btn-ghost {
    background: var(--glass);
    color: var(--text-light);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* أحجام اختيارية */
.btn-sm {
    padding: 10px 16px;
    font-size: 0.85rem;
}

.btn-lg {
    padding: 17px 28px;
    font-size: 1.05rem;
}

.btn-block {
    width: 100%;
}


/* ================================================================
   35. Skeleton Loading — بدل الفراغ وقت تحميل البيانات
   الاستخدام: حط دي بدل الكارت الحقيقي مؤقتاً أثناء انتظار Firestore:
   <div class="skeleton skeleton-card"></div>
   ================================================================ */
.skeleton {
    position: relative;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-md);
}

.skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.09), transparent);
    transform: translateX(-100%);
    animation: skeletonShimmer 1.6s infinite;
}

@keyframes skeletonShimmer {
    to {
        transform: translateX(100%);
    }
}

.skeleton-card {
    height: 90px;
    margin-bottom: 10px;
}

.skeleton-text {
    height: 14px;
    width: 70%;
    margin: 8px auto;
}

.skeleton-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}


/* ================================================================
   36. الاحتفال — Confetti Burst
   الاستخدام: ضيف الـ HTML التالي مرة واحدة قبل إغلاق </body>:

   <div class="confetti-burst" id="confettiBurst">
     <span class="confetti-piece"></span> ... (كرر 16 مرة، أو خليها زي ما هي تحت)
   </div>

   وفي app.js وقت النجاح (نتيجة عالية، خلاص اختبار) نادي:
     const c = document.getElementById('confettiBurst');
     c.classList.add('show');
     setTimeout(() => c.classList.remove('show'), 2500);
   ================================================================ */
.confetti-burst {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 99998;
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    top: -20px;
    width: 8px;
    height: 14px;
    opacity: 0;
    border-radius: 2px;
}

.confetti-burst.show .confetti-piece {
    animation: confettiFall 2.2s ease-in forwards;
}

@keyframes confettiFall {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg);
    }

    100% {
        opacity: 0;
        transform: translateY(105vh) rotate(540deg);
    }
}

/* 16 قطعة بمواقع وألوان وتأخيرات مختلفة */
.confetti-piece:nth-child(1) {
    left: 4%;
    background: #8b5cf6;
    animation-delay: 0s;
}

.confetti-piece:nth-child(2) {
    left: 11%;
    background: #ffc107;
    animation-delay: 0.15s;
}

.confetti-piece:nth-child(3) {
    left: 19%;
    background: #22c55e;
    animation-delay: 0.05s;
}

.confetti-piece:nth-child(4) {
    left: 27%;
    background: #a78bfa;
    animation-delay: 0.25s;
}

.confetti-piece:nth-child(5) {
    left: 35%;
    background: #ffffff;
    animation-delay: 0.1s;
}

.confetti-piece:nth-child(6) {
    left: 43%;
    background: #ffc107;
    animation-delay: 0.3s;
}

.confetti-piece:nth-child(7) {
    left: 51%;
    background: #8b5cf6;
    animation-delay: 0.02s;
}

.confetti-piece:nth-child(8) {
    left: 59%;
    background: #22c55e;
    animation-delay: 0.2s;
}

.confetti-piece:nth-child(9) {
    left: 67%;
    background: #a78bfa;
    animation-delay: 0.12s;
}

.confetti-piece:nth-child(10) {
    left: 75%;
    background: #ffffff;
    animation-delay: 0.28s;
}

.confetti-piece:nth-child(11) {
    left: 83%;
    background: #ffc107;
    animation-delay: 0.08s;
}

.confetti-piece:nth-child(12) {
    left: 91%;
    background: #8b5cf6;
    animation-delay: 0.18s;
}

.confetti-piece:nth-child(13) {
    left: 8%;
    background: #22c55e;
    animation-delay: 0.35s;
}

.confetti-piece:nth-child(14) {
    left: 47%;
    background: #a78bfa;
    animation-delay: 0.4s;
}

.confetti-piece:nth-child(15) {
    left: 63%;
    background: #ffffff;
    animation-delay: 0.22s;
}

.confetti-piece:nth-child(16) {
    left: 96%;
    background: #ffc107;
    animation-delay: 0.32s;
}


/* ================================================================
   37. شريط تقدم فضائي — صاروخ بيسافر مع التقدم
   الاستخدام: نفس .redirect-bar الموجودة أصلاً في صفحة تسجيل الدخول،
   بس ضيف سطر HTML واحد بس (اتشرح تحت في الرسالة)
   ================================================================ */
.redirect-bar {
    position: relative;
    overflow: visible !important;
    /* عشان الصاروخ يبان برا حدود الشريط */
}

.redirect-rocket {
    position: absolute;
    top: 50%;
    right: 0;
    transform: translate(50%, -50%) rotate(-90deg);
    font-size: 16px;
    filter: drop-shadow(0 0 6px rgba(255, 193, 7, 0.9));
    animation: rocketTravel 2s linear forwards;
}

@keyframes rocketTravel {
    from {
        right: 0%;
    }

    to {
        right: 100%;
    }
}


/* ================================================================
   38. تحسين عام للـ scrollbar بما يتماشى مع الثيم
   ================================================================ */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--navy-bg);
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(var(--light-purple), var(--deep-purple));
    border-radius: var(--radius-full);
    border: 2px solid var(--navy-bg);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--light-purple);
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--light-purple) var(--navy-bg);
}

/* ================================================================
   39. خريطة الرحلة التعليمية الفضائية (Journey Map)
   ================================================================ */
.journey-title {
    text-align: center;
    color: var(--text-light);
    font-size: 1.15rem;
    margin: 30px 0 5px;
    letter-spacing: 0.5px;
}

.journey-map {
    position: relative;
    width: 92%;
    max-width: 420px;
    aspect-ratio: 400 / 560;
    margin: 10px auto 40px;
}

.route-path {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

/* الصاروخ المسافر بيتحرك فوق نفس شكل المسار باستمرار */
.rocket-ship {
    position: absolute;
    top: 0;
    left: 0;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transform: translate(-50%, -50%);
    offset-path: path("M 320,40 C 220,70 160,90 100,130 C 200,160 260,190 300,230 C 200,260 140,290 90,330 C 190,360 250,390 300,430 C 250,460 190,490 150,520");
    offset-rotate: 0deg;
    animation: flyRoute 14s linear infinite;
    filter: drop-shadow(0 0 8px rgba(255, 193, 7, 0.85));
    z-index: 1;
    pointer-events: none;
}

@keyframes flyRoute {
    0% {
        offset-distance: 0%;
    }

    100% {
        offset-distance: 100%;
    }
}

/* المحطات */
.map-station {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 62px;
    height: 62px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 35% 30%, rgba(139, 92, 246, 0.35), rgba(30, 17, 69, 0.92));
    border: 2px solid var(--light-purple);
    box-shadow: 0 0 18px rgba(139, 92, 246, 0.4), inset 0 0 12px rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: transform 0.3s var(--ease-bounce), box-shadow 0.3s ease, border-color 0.3s ease;
    z-index: 2;
}

.map-station:hover {
    transform: translate(-50%, -50%) scale(1.12);
    box-shadow: 0 0 26px rgba(139, 92, 246, 0.6);
}

.map-station:active {
    transform: translate(-50%, -50%) scale(0.94);
}

.map-station.active {
    border-color: var(--yellow-gold);
    box-shadow: 0 0 26px rgba(255, 193, 7, 0.55), 0 0 40px rgba(139, 92, 246, 0.35);
    transform: translate(-50%, -50%) scale(1.15);
}

.map-icon {
    font-size: 1.6rem;
    filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.4));
    line-height: 1;
}

.map-label {
    position: absolute;
    top: 100%;
    margin-top: 6px;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-light);
    white-space: nowrap;
    text-shadow: 0 0 6px rgba(0, 0, 0, 0.7);
}

.map-station-sm {
    width: 46px;
    height: 46px;
}

.map-station-sm .map-icon {
    font-size: 1.15rem;
}

.map-station-gold {
    border-color: var(--yellow-gold);
    background: radial-gradient(circle at 35% 30%, rgba(255, 193, 7, 0.35), rgba(30, 17, 69, 0.92));
    box-shadow: 0 0 18px rgba(255, 193, 7, 0.4);
}

@media (max-width: 420px) {
    .map-station {
        width: 52px;
        height: 52px;
    }

    .map-icon {
        font-size: 1.3rem;
    }

    .map-label {
        font-size: 0.6rem;
    }
}

/* دعم للمتصفحات اللي مش فاهمة offset-path — الصاروخ يفضل ثابت وسط الخريطة بدل ما يختفي */
@supports not (offset-path: path("M0,0")) {
    .rocket-ship {
        position: absolute;
        top: 50%;
        left: 50%;
        opacity: 0.7;
        animation: none;
    }
}

/* ================================
   شاشة التدرب على الكتابة — صفحة كاملة الشاشة (بدون مودال)
   ================================ */
#writing-screen {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background-color: #0b0a1a;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
    overflow: hidden;
}

.writing-full-container,
.writing-modal-content {
    width: 100%;
    max-width: 600px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    position: relative;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}

.writing-modal-header {
    width: 100% !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 16px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    margin-bottom: 6px;
    position: relative;
}

.writing-close-btn {
    position: relative;
    top: auto;
    right: auto;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: var(--text-light);
    font-size: 1.2rem;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
    flex-shrink: 0;
}

.writing-close-btn:hover {
    background: #ef4444;
    border-color: #ef4444;
    color: #ffffff;
    transform: scale(1.08);
}

.writing-title-group {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.writing-title-group h1,
.writing-title-group h2 {
    font-size: 1.05rem;
    font-weight: 800;
    margin: 0;
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 6px;
}

.writing-title-group .jp-char {
    font-family: var(--font-jp);
    font-weight: 700;
    color: var(--yellow-gold);
    font-size: 1.35rem;
}

.progress-label {
    font-size: 0.8rem;
    color: rgba(245, 243, 255, 0.8);
    font-weight: 700;
    letter-spacing: 0.5px;
}

.level-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 800;
    padding: 2px 10px;
    border-radius: 999px;
    border: 1.5px solid var(--light-purple);
    color: var(--text-light);
    background: rgba(139, 92, 246, 0.2);
    transition: all 0.25s ease;
}

.level-badge.blind {
    background: linear-gradient(135deg, var(--light-purple), #6d28d9);
    color: #ffffff;
    border-color: transparent;
}

.writing-hint-btn {
    background: rgba(255, 193, 7, 0.15);
    border: 1.5px solid rgba(255, 193, 7, 0.4);
    color: var(--yellow-gold);
    padding: 7px 12px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.82rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.writing-hint-btn:hover {
    background: rgba(255, 193, 7, 0.3);
    border-color: var(--yellow-gold);
    transform: translateY(-1px);
    box-shadow: 0 0 12px rgba(255, 193, 7, 0.35);
}

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

.stroke-dots {
    display: flex;
    gap: 8px;
    margin: 4px 0 8px 0;
    height: 14px;
    align-items: center;
    justify-content: center;
}

.stroke-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transition: transform 0.25s ease, background 0.25s ease;
}

.stroke-dot.done {
    background: var(--light-purple);
}

.stroke-dot.current {
    background: var(--yellow-gold);
    transform: scale(1.4);
    box-shadow: 0 0 8px var(--yellow-gold);
}

.canvas-wrap {
    position: relative;
    /* سطح الرسم: أبيض نقي + زوايا دائرية كبيرة (24px) — مقاس متجاوب كبير:
       width: min(90vw, 550px) و height: min(55vh, 550px) */
    width: min(90vw, 550px);
    height: min(55vh, 550px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 24px;
    touch-action: none;
    overflow: hidden;
    background: #ffffff !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
    margin: 0 auto;
    flex-shrink: 0;
}

.canvas-wrap canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

#interact {
    z-index: 5;
    cursor: crosshair;
}

.msg {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 5rem;
    font-weight: 900;
    font-family: 'Cairo', 'Arial', sans-serif;
    font-variant-emoji: text;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    transform: scale(0.6);
    z-index: 10;
    color: #6d28d9;
}

.msg.show {
    opacity: 1;
    transform: scale(1);
}

.msg.err {
    color: #e11d48;
}

.controls {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    width: 100%;
    max-width: 500px;
    justify-content: center;
}

.controls button,
.controls .writing-btn {
    padding: 12px 20px;
    border-radius: 14px;
    font-weight: 700;
    font-size: 0.92rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.18s ease;
    flex: 1;
    max-width: 150px;
    /* أزرار عائمة فوق الكانفاس الأبيض: زجاجية + ظل لقراءة واضحة */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.controls button.ghost,
.controls .writing-btn.ghost {
    border: 1.5px solid rgba(139, 92, 246, 0.4);
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-light);
}

.controls button.ghost:hover,
.controls .writing-btn.ghost:hover {
    background: rgba(139, 92, 246, 0.25);
    border-color: var(--light-purple);
}

.controls #nextBtn,
.controls .writing-btn.primary {
    background: linear-gradient(135deg, var(--light-purple), #6d28d9);
    color: #ffffff;
    border: none;
    box-shadow: 0 4px 16px rgba(139, 92, 246, 0.4);
}

.controls #nextBtn:hover,
.controls .writing-btn.primary:hover {
    filter: brightness(1.12);
    transform: translateY(-1px);
}

.controls button:active,
.controls .writing-btn:active {
    transform: scale(0.95);
}

/* ================================
   إشعار Toast لرسالة اكتمال التلميح (بديل المودال الثقيل)
   ================================ */
.writing-toast {
    position: fixed;
    top: calc(18px + env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translate(-50%, -24px);
    background: rgba(15, 23, 42, 0.9);
    color: #ffffff;
    padding: 12px 22px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.6;
    max-width: min(92vw, 480px);
    border: 1px solid rgba(139, 92, 246, 0.55);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.35), 0 8px 24px rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    z-index: 100000;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.writing-toast-show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ================================
   نافذة تأكيد تسجيل الخروج الاحترافية
   ================================ */

.logout-confirm-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100000;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease, visibility .22s ease;
}

.logout-confirm-modal.is-open {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
}

.logout-confirm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(4, 3, 14, .76);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.logout-confirm-card {
    position: relative;
    width: min(100%, 370px);
    padding: 28px 22px 22px;
    border-radius: 26px;
    text-align: center;
    direction: rtl;
    background:
        radial-gradient(circle at 50% 0%, rgba(123, 63, 255, .18), transparent 45%),
        linear-gradient(145deg, rgba(31, 18, 68, .98), rgba(8, 9, 27, .99));
    border: 1px solid rgba(167, 112, 255, .32);
    box-shadow:
        0 24px 80px rgba(0, 0, 0, .65),
        0 0 45px rgba(111, 55, 220, .16);
    transform: translateY(14px) scale(.94);
    opacity: 0;
    transition: transform .24s cubic-bezier(.2,.8,.2,1), opacity .2s ease;
}

.logout-confirm-modal.is-open .logout-confirm-card {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.logout-confirm-close {
    position: absolute;
    top: 10px;
    left: 12px;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .06);
    color: rgba(255, 255, 255, .72);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: background .18s ease, transform .18s ease;
}

.logout-confirm-close:hover {
    background: rgba(255, 255, 255, .11);
}

.logout-confirm-close:active {
    transform: scale(.92);
}

.logout-confirm-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(139, 92, 246, .13);
    border: 1px solid rgba(167, 112, 255, .28);
    box-shadow: 0 0 30px rgba(111, 55, 220, .14);
}

.logout-confirm-icon span {
    display: block;
    color: var(--light-purple, #a970ff);
    font-size: 31px;
    font-weight: 700;
    transform: translateX(-1px);
}

.logout-confirm-card h2 {
    margin: 0 0 10px;
    color: #fff;
    font-size: 22px;
    font-weight: 800;
}

.logout-confirm-card p {
    margin: 0 auto 24px;
    max-width: 300px;
    color: rgba(255, 255, 255, .66);
    font-size: 14px;
    line-height: 1.8;
}

.logout-confirm-actions {
    display: flex;
    gap: 10px;
    direction: rtl;
}

.logout-confirm-actions button {
    flex: 1;
    min-height: 46px;
    border: 0;
    border-radius: 14px;
    padding: 11px 14px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    transition: transform .16s ease, filter .16s ease, background .16s ease;
}

.logout-confirm-actions button:active {
    transform: scale(.97);
}

.logout-cancel-btn {
    background: rgba(255, 255, 255, .07);
    color: rgba(255, 255, 255, .78);
    border: 1px solid rgba(255, 255, 255, .08) !important;
}

.logout-cancel-btn:hover {
    background: rgba(255, 255, 255, .11);
}

.logout-ok-btn {
    color: #fff;
    background: linear-gradient(135deg, #7d4cff, #5424c7);
    box-shadow: 0 8px 24px rgba(102, 50, 220, .28);
}

.logout-ok-btn:hover {
    filter: brightness(1.08);
}

body.logout-modal-open {
    overflow: hidden;
}

@media (max-width: 420px) {
    .logout-confirm-modal {
        padding: 16px;
    }

    .logout-confirm-card {
        padding: 26px 18px 18px;
        border-radius: 23px;
    }

    .logout-confirm-actions button {
        min-height: 44px;
        font-size: 13px;
    }
}


/* ==========================================
   أنميشن شاشة التدريب على الكتابة
   دخول ناعم + خروج سريع مع عمق بسيط
   ========================================== */

#writing-screen {
    opacity: 1;
    transform: translateY(0) scale(1);
    will-change: opacity, transform;
}

#writing-screen.writing-modal-opening {
    animation: writingScreenEnter .38s cubic-bezier(.22, 1, .36, 1) both;
}

#writing-screen.writing-modal-closing {
    pointer-events: none;
    animation: writingScreenExit .34s cubic-bezier(.4, 0, 1, 1) both;
}

#writing-screen.writing-modal-opening .writing-full-container {
    animation: writingContentEnter .42s cubic-bezier(.22, 1, .36, 1) both;
}

#writing-screen.writing-modal-closing .writing-full-container {
    animation: writingContentExit .30s ease-in both;
}

@keyframes writingScreenEnter {
    from {
        opacity: 0;
        transform: scale(1.035);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes writingScreenExit {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(.985);
    }
}

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

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

/* احترام إعداد تقليل الحركة في الجهاز */
@media (prefers-reduced-motion: reduce) {
    #writing-screen.writing-modal-opening,
    #writing-screen.writing-modal-closing,
    #writing-screen.writing-modal-opening .writing-full-container,
    #writing-screen.writing-modal-closing .writing-full-container {
        animation: none !important;
    }

    .writing-toast {
        transition: none !important;
    }
}

/* ================================================================
   الملف الشخصي — شبكة الإحصائيات + قسم إتقان الكانا
   ================================================================ */

/* شبكة 2×2 للإحصائيات الأربع */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 6px;
    border-radius: 10px;
    background: var(--glass);
    border: 1px solid rgba(139, 92, 246, 0.25);
    min-height: 64px;
}

.stat-label {
    font-size: 0.72rem;
    color: rgba(245, 243, 255, 0.7);
    font-weight: 700;
    text-align: center;
}

.stat-value {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--light-purple);
}

/* شريط تقدم إتقان الكانا */
.kana-mastery-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.kana-mastery-title {
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 800;
}

.kana-mastery-count {
    color: var(--light-purple);
    font-size: 0.85rem;
    font-weight: 800;
    background: rgba(139, 92, 246, 0.15);
    border: 1px solid rgba(139, 92, 246, 0.35);
    padding: 2px 10px;
    border-radius: 999px;
}

.kana-mastery-track {
    height: 14px;
    margin-top: 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(139, 92, 246, 0.3);
    overflow: hidden;
}

/* التعبئة تتحرك بنعومة حسب نسبة الإتقان */
.kana-mastery-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--light-purple), #a78bfa);
    box-shadow: 0 0 14px rgba(139, 92, 246, 0.65);
    transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.kana-mastery-footer {
    margin-top: 6px;
    display: flex;
    justify-content: flex-end;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--light-purple);
}

/* التجاوب على الشاشات الضيقة جداً */
@media (max-width: 380px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}
