:root {
    --primary-bg: #102A43; /* Indigo Blue */
    --accent-green: #0F5132; /* Emerald Green */
    --gold: #D4AF37; /* Glowing Gold */
    --text-light: #F8F9FA; /* Off-White */
    --card-bg: rgba(16, 42, 67, 0.85); /* Transparent Indigo for glass effect */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Cairo', sans-serif;
    background-color: var(--primary-bg);
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    /* خلفية بزخرفة إسلامية خفيفة */
    background-image: url('data:image/svg+xml,%3Csvg width="40" height="40" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg"%3E%3Cpath d="M20 20.5V18H0v-2h20v-2.5L22.5 11 25 13.5V16h20v2H25v2.5L22.5 23 20 20.5z" fill="%230F5132" fill-opacity="0.1" fill-rule="evenodd"/%3E%3C/svg%3E');
}

#appContent {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
}

/* الشعار ولوحة التحكم العلوية */
.app-header {
    background-color: var(--accent-green);
    border-bottom: 3px solid var(--gold);
    color: var(--text-light);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    z-index: 10;
}

.header-title {
    display: flex;
    flex-direction: column;
}

.header-title h1 {
    font-family: 'Amiri', serif;
    font-size: 2.2rem;
    color: var(--gold);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

.header-title p {
    font-size: 1rem;
    opacity: 0.9;
}

/* لوحة تحكم اللاعب (الطفل) */
.dashboard-stats {
    display: flex;
    gap: 2rem;
    align-items: center;
}

.stat-box {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--gold);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-light);
    opacity: 0.8;
}

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

/* حاوية المحتوى */
.container {
    display: flex;
    flex: 1;
    flex-direction: column;
}

/* شاشة أبراج الحصن (الشبكة) */
.surahs-grid-view {
    padding: 3rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.view-title {
    font-family: 'Amiri', serif;
    font-size: 2.5rem;
    color: var(--gold);
    margin-bottom: 2rem;
    text-shadow: 0 0 15px rgba(212, 175, 55, 0.2);
}

.surahs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    width: 100%;
    max-width: 1200px;
}

.surah-card {
    background-color: var(--card-bg);
    border: 2px solid var(--accent-green);
    border-radius: 12px;
    padding: 2rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    backdrop-filter: blur(10px);
}

.surah-card:hover {
    transform: translateY(-5px);
    border-color: var(--gold);
    box-shadow: 0 8px 25px rgba(0,0,0,0.4);
    background-color: rgba(15, 81, 50, 0.6);
}

.surah-card-title {
    font-family: 'Amiri', serif;
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--text-light);
}

.surah-card.completed {
    border-color: var(--gold);
    background-color: rgba(212, 175, 55, 0.1);
}

.lantern-icon {
    font-size: 2.5rem;
    opacity: 0.2;
    transition: all 0.3s ease;
    filter: grayscale(100%);
}

.surah-card.completed .lantern-icon {
    opacity: 1;
    filter: grayscale(0%);
    text-shadow: 0 0 20px var(--gold);
}

/* شاشة عرض السورة */
.content-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    width: 100%;
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

.surah-header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 900px;
    margin-bottom: 1.5rem;
}

.current-surah-title {
    font-family: 'Amiri', serif;
    font-size: 2rem;
    color: var(--gold);
}

.btn-back {
    background-color: var(--accent-green);
    color: var(--text-light);
    border: 1px solid var(--gold);
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-family: 'Cairo', sans-serif;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-back:hover {
    background-color: var(--gold);
    color: var(--primary-bg);
}

.back-icon {
    font-size: 1.2rem;
}

.surah-display {
    background-color: var(--card-bg);
    border: 2px solid var(--accent-green);
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5), inset 0 0 20px rgba(15, 81, 50, 0.5);
    width: 100%;
    max-width: 900px;
    min-height: 500px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 3rem;
    position: relative;
    margin-bottom: 2rem;
    backdrop-filter: blur(10px);
}

.surah-display::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    border: 1px solid var(--gold);
    border-radius: 15px;
    pointer-events: none;
    opacity: 0.5;
}

.quran-text {
    font-family: 'Amiri', serif;
    font-size: 2.2rem;
    line-height: 2.2;
    text-align: center;
    color: var(--text-light);
    padding: 1rem;
    direction: rtl;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

.basmalah {
    font-family: 'Amiri', serif;
    font-size: 2.5rem;
    text-align: center;
    color: var(--gold);
    margin-bottom: 2.5rem;
    text-shadow: 0 0 15px rgba(212, 175, 55, 0.3);
}

.ayah-number {
    display: inline-block;
    margin: 0 8px;
    color: var(--gold);
    font-size: 1.6rem;
}

.loading {
    font-size: 1.5rem;
    color: var(--gold);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 0.5; text-shadow: 0 0 5px var(--gold); }
    50% { opacity: 1; text-shadow: 0 0 20px var(--gold); }
    100% { opacity: 0.5; text-shadow: 0 0 5px var(--gold); }
}

/* الفوتر (تذييل الصفحة) */
.app-footer {
    text-align: center;
    padding: 15px;
    background-color: rgba(16, 42, 67, 0.95);
    border-top: 2px solid var(--gold);
    width: 100%;
    z-index: 10;
}

.app-footer a {
    color: var(--text-light);
    text-decoration: none;
    font-size: 1.1rem;
    font-family: 'Amiri', serif;
    transition: color 0.3s ease;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.5);
}

.app-footer a:hover {
    color: var(--gold);
    text-shadow: 0 0 10px rgba(212, 175, 55, 0.5);
}

/* شريط التمرير مخصص ليتماشى مع الثيم الملكي */
::-webkit-scrollbar {
    width: 10px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--accent-green);
    border-radius: 5px;
    border: 1px solid var(--gold);
}

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

/* Responsive */
@media (max-width: 768px) {
    .surah-header-actions {
        flex-direction: column-reverse;
        gap: 1rem;
    }

    .current-surah-title {
        font-size: 1.8rem;
    }

    .app-header h1 {
        font-size: 1.8rem;
    }

    .quran-text {
        font-size: 1.8rem;
        line-height: 2;
    }

    .basmalah {
        font-size: 2rem;
        margin-bottom: 1.5rem;
    }

    .ayah-number {
        font-size: 1.2rem;
    }

    .surah-display {
        padding: 2rem 1rem;
    }
}

/* تنسيقات الآيات التفاعلية والصوت */
.ayah-span {
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 8px;
    padding: 0 5px;
}

.ayah-span:hover {
    background-color: rgba(212, 175, 55, 0.2);
}

.ayah-span.active {
    background-color: rgba(212, 175, 55, 0.4);
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
}

.audio-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    width: 100%;
}

.btn-play, .btn-stop {
    background-color: var(--accent-green);
    color: var(--text-light);
    border: 1px solid var(--gold);
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-family: 'Cairo', sans-serif;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-play:hover, .btn-stop:hover {
    background-color: var(--gold);
    color: var(--primary-bg);
}

.audio-hint {
    text-align: center;
    font-size: 1.1rem;
    color: var(--gold);
    margin-bottom: 1.5rem;
    opacity: 0.9;
}

/* تنسيق زر الإكمال */
.btn-complete {
    background-color: var(--accent-green);
    color: var(--text-light);
    border: 1px solid var(--gold);
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-family: 'Cairo', sans-serif;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-complete:hover {
    background-color: var(--gold);
    color: var(--primary-bg);
}

.btn-undo {
    background-color: transparent;
    color: #e74c3c;
    border: 1px solid #e74c3c;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-family: 'Cairo', sans-serif;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-undo:hover {
    background-color: #e74c3c;
    color: #fff;
}

/* نافذة الرتب Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: var(--primary-bg);
    border: 3px solid var(--gold);
    border-radius: 15px;
    padding: 2rem;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 5px 30px rgba(0,0,0,0.6);
}

.close-btn {
    position: absolute;
    top: 15px;
    left: 20px;
    color: var(--text-light);
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
}

.close-btn:hover {
    color: var(--gold);
}

.modal-title {
    text-align: center;
    color: var(--gold);
    margin-bottom: 1.5rem;
    font-family: 'Amiri', serif;
}

.rank-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.2);
    background-color: rgba(0,0,0,0.2);
}

.rank-item.unlocked {
    border-color: var(--accent-green);
    background-color: rgba(15, 81, 50, 0.4);
    box-shadow: 0 0 10px rgba(15, 81, 50, 0.5);
}

.rank-item.current {
    border-color: var(--gold);
    background-color: rgba(212, 175, 55, 0.2);
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.5);
}

.rank-icon {
    font-size: 2.2rem;
}

.rank-details {
    flex: 1;
    margin: 0 1rem;
}

.rank-name {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-light);
}

.rank-req {
    font-size: 0.9rem;
    color: #bbb;
}

.rank-status {
    font-size: 1.5rem;
}

.btn-ranks {
    background-color: transparent;
    border: 1px solid var(--gold);
    color: var(--gold);
    padding: 0.3rem 0.8rem;
    border-radius: 5px;
    cursor: pointer;
    font-family: 'Cairo', sans-serif;
    font-weight: bold;
    margin-top: 10px;
    transition: 0.3s;
}

.btn-ranks:hover {
    background-color: var(--gold);
    color: var(--primary-bg);
}

/* قسم الألعاب */
.games-section {
    width: 100%;
    margin-top: 3rem;
    border-top: 2px dashed rgba(212, 175, 55, 0.5);
    padding-top: 2rem;
}

.games-title {
    text-align: center;
    color: var(--gold);
    font-family: 'Amiri', serif;
    font-size: 2rem;
    margin-bottom: 2rem;
}

.games-buttons {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.btn-game {
    background-color: rgba(212, 175, 55, 0.1);
    color: var(--text-light);
    border: 2px solid var(--gold);
    padding: 1.2rem 2.5rem;
    border-radius: 15px;
    font-family: 'Cairo', sans-serif;
    font-size: 1.3rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.btn-game:hover {
    background-color: var(--gold);
    color: var(--primary-bg);
    transform: translateY(-5px);
}

/* تنسيقات نافذة الألعاب */
.game-modal-content {
    max-width: 800px;
    background: linear-gradient(135deg, var(--primary-bg), #1a2a20);
}
.game-body {
    min-height: 250px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    padding: 1rem;
}
.game-feedback {
    text-align: center;
    font-size: 1.5rem;
    font-weight: bold;
    margin-top: 1rem;
    min-height: 2.5rem;
}

/* ستايلات حجر البناء */
.ayah-gap-text {
    font-size: 2.2rem;
    color: var(--text-light);
    line-height: 2.5;
    text-align: center;
    font-family: 'Amiri', serif;
}
.gap-slot {
    display: inline-block;
    min-width: 120px;
    height: 45px;
    border-bottom: 4px dashed var(--gold);
    margin: 0 10px;
    color: var(--accent-green);
    font-weight: bold;
    vertical-align: bottom;
}
.stone-options {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 2rem;
}
.stone-btn {
    background-color: #8c7355;
    color: white;
    border: 2px solid #5a4630;
    border-radius: 8px;
    padding: 1rem 2rem;
    font-size: 1.5rem;
    font-family: 'Amiri', serif;
    cursor: pointer;
    box-shadow: inset 0 -4px 0 rgba(0,0,0,0.3), 0 4px 10px rgba(0,0,0,0.5);
    transition: 0.2s;
}
.stone-btn:active {
    transform: translateY(4px);
    box-shadow: inset 0 -1px 0 rgba(0,0,0,0.3), 0 1px 5px rgba(0,0,0,0.5);
}
.stone-btn.correct {
    background-color: var(--accent-green);
    border-color: var(--gold);
}
.stone-btn.wrong {
    background-color: #e74c3c;
    border-color: #c0392b;
    animation: shake 0.4s;
}

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

/* ستايلات ممر القلاع */
.order-path-zone {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
.order-slot {
    background-color: rgba(255,255,255,0.05);
    border: 2px dashed rgba(212, 175, 55, 0.5);
    min-height: 80px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Amiri', serif;
    font-size: 1.8rem;
    padding: 1rem;
    text-align: center;
}
.order-piece {
    background-color: var(--card-bg);
    border: 2px solid var(--gold);
    color: var(--text-light);
    border-radius: 10px;
    padding: 1rem;
    font-family: 'Amiri', serif;
    font-size: 1.5rem;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    transition: 0.3s;
    margin-top: 1rem;
}
.order-piece:hover {
    background-color: rgba(212, 175, 55, 0.2);
}
.order-piece.locked {
    background-color: var(--accent-green);
    border-color: var(--gold);
    cursor: default;
}
.order-pieces-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* تنسيقات زر التكرار الذكي */
.ayah-repeat-btn {
    background: var(--accent-green);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 1rem;
    margin-right: 10px;
    vertical-align: middle;
    transition: 0.3s;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.ayah-repeat-btn:hover {
    transform: scale(1.1) rotate(180deg);
}
.ayah-repeat-btn.active-loop {
    background: var(--gold);
    color: var(--primary-bg);
    animation: pulse 1.5s infinite;
}
.ayah-span.active-loop-text {
    background-color: rgba(212, 175, 55, 0.4);
    border-bottom: 2px solid var(--gold);
}

/* شاشة تسجيل الدخول */
.login-screen {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}
.login-box {
    background: rgba(18, 25, 43, 0.9);
    padding: 3rem 2rem;
    border-radius: 20px;
    border: 2px solid var(--gold);
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5), 0 0 20px rgba(212, 175, 55, 0.2);
    max-width: 400px;
    width: 90%;
}
.login-title {
    color: var(--gold);
    font-family: 'Amiri', serif;
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}
.login-subtitle {
    color: var(--text-light);
    margin-bottom: 2rem;
    font-size: 1.1rem;
}
.login-input {
    width: 100%;
    padding: 15px;
    font-size: 1.2rem;
    border: 2px solid rgba(212, 175, 55, 0.5);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--gold);
    text-align: center;
    margin-bottom: 1.5rem;
    outline: none;
    transition: 0.3s;
}
.login-input:focus {
    border-color: var(--gold);
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
}
.login-btn {
    width: 100%;
    padding: 15px;
    background: linear-gradient(to bottom, var(--gold), #b8860b);
    color: var(--primary-bg);
    font-size: 1.3rem;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: 0.3s;
}
.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(212, 175, 55, 0.4);
}
.login-error-msg {
    color: #e74c3c;
    margin-top: 1rem;
    min-height: 20px;
    font-weight: bold;
}

/* ========================================================
   التصميم المتجاوب (Responsive Design)
   ======================================================== */

/* للشاشات المتوسطة واللوحيات (Tablets) */
@media (max-width: 992px) {
    .app-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .dashboard-stats {
        flex-wrap: wrap;
        justify-content: center;
        gap: 1rem;
    }

    .surahs-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }

    .quran-text {
        font-size: 2.2rem;
        padding: 2rem 1rem;
    }
}

/* للشاشات الصغيرة والجوالات (Mobiles) */
@media (max-width: 600px) {
    .header-title h1 {
        font-size: 1.8rem;
    }
    
    .header-title p {
        font-size: 0.9rem;
    }

    .stat-box {
        padding: 0.4rem 0.8rem;
    }
    
    .stat-value {
        font-size: 1rem;
    }

    .surahs-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 1rem;
    }
    
    .surah-card {
        padding: 1.5rem 0.5rem;
    }

    .surah-card-title {
        font-size: 1.3rem;
    }

    .surah-header-actions {
        flex-direction: column;
        gap: 1rem;
    }

    .quran-text {
        font-size: 1.8rem;
        line-height: 2.2;
    }
    
    .audio-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-play, .btn-stop, .btn-complete {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .modal-content, .game-modal-content, .login-box {
        width: 95%;
        padding: 1.5rem 1rem;
    }

    .modal-title, .login-title {
        font-size: 1.8rem;
    }

    .rank-card {
        flex-direction: column;
        text-align: center;
        padding: 1rem;
    }
    
    .rank-icon {
        font-size: 2.5rem;
        margin-bottom: 0.5rem;
    }

    .ayah-gap-text {
        font-size: 1.5rem;
    }
    
    .stone-options {
        flex-direction: column;
        align-items: stretch;
    }
    
    .stone-btn {
        width: 100%;
    }
}
