:root {
    --primary: #10b981;
    --primary-dark: #059669;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text: #0f172a;
    --border: #e2e8f0;
    --sidebar-width: 280px;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f8fafc;
    --border: #334155;
}

@font-face { font-family: 'UthmanicHafs'; src: url('../fonts/uthmanic_hafs_v20.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'UthmanicWarsh'; src: url('../fonts/uthmanic_warsh_v21.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'UthmanicQaloun'; src: url('../fonts/uthmanic_qaloun_v21.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'UthmanicDuri'; src: url('../fonts/uthmanic_douri_v20.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'UthmanicShubah'; src: url('../fonts/uthmanic_shuba_v20.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'UthmanicSusi'; src: url('../fonts/uthmanic_sousi_v20.ttf') format('truetype'); font-display: swap; }

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

body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    overflow: hidden;
}

.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100dvh;
    overflow: hidden; /* يمنع التمرير الأفقي تماماً ويخفي القائمة تماماً بالجوال */
}

.sidebar {
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-header { padding: 15px; text-align: center; border-bottom: 1px solid var(--border); }
.app-logo { width: 50px; height: 50px; border-radius: 8px; margin-bottom: 5px; }
.sidebar-content { flex: 1; padding: 15px; overflow-y: auto; }
.sidebar-footer { padding: 10px; border-top: 1px solid var(--border); font-size: 0.75rem; text-align: center; }

.main-body {
    display: grid;
    grid-template-rows: 50px 1fr 45px 50px;
    height: 100dvh;
    overflow: hidden;
}

.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reading-container {
    padding: 20px 40px;
    overflow-y: auto;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 0;
}

.quran-text-block {
    width: 100%;
    max-width: 800px;
    direction: rtl;
    line-height: 2.1; /* زيادة طفيفة لدعم الحركات ومنع تداخل السطور */
    text-align: justify;
    text-align-last: center; /* توسيط السطر الأخير في السورة */
    word-spacing: 2px;
}

.ayah-container {
    display: inline;
    font-size: 2.1rem; /* تصغير طفيف لتناسب السطر */
    transition: background 0.3s;
    cursor: pointer;
}

.ayah-container.active { background: rgba(16, 185, 129, 0.15); border-radius: 4px; }

.ayah-text { padding: 0 2px; }

.bismillah, .istiazah {
    display: block;
    text-align: center;
    font-size: 2.2rem;
    color: var(--primary);
    margin: 10px 0; /* تقليل الفراغات العمودية */
}

.surah-header-inline {
    display: block;
    text-align: center;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary);
    padding: 8px;
    margin: 15px 0;
    border: 1px solid var(--primary);
    border-radius: 8px;
    background: var(--bg);
}

/* Page Navigation */
.page-navigation {
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.page-indicator input { width: 50px; text-align: center; border: 1px solid var(--border); border-radius: 4px; padding: 2px; }

.btn-nav { background: var(--bg); border: 1px solid var(--border); padding: 4px 12px; border-radius: 15px; cursor: pointer; font-size: 0.9rem; }

/* Player */
.player-container {
    background: var(--surface);
    border-top: 2px solid var(--primary);
    display: flex;
    flex-direction: column;
    padding: 5px 20px;
}

.player-controls { display: flex; align-items: center; justify-content: center; gap: 15px; flex: 1; }
.btn-play-pause { width: 45px; height: 45px; border-radius: 50%; background: var(--primary); color: white; border: none; font-size: 1.2rem; cursor: pointer; }

.progress-area input { width: 100%; cursor: pointer; accent-color: var(--primary); height: 4px; }

.btn-icon { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--text); padding: 5px; }

/* Forms */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; margin-bottom: 3px; font-weight: bold; font-size: 0.8rem; }
.form-control { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-size: 0.9rem; }

.btn-accent { background: #6366f1; color: white; border: none; padding: 8px; border-radius: 6px; cursor: pointer; }

/* Responsive */
@media (max-width: 768px) {
    .app-layout { grid-template-columns: 1fr; }
    .sidebar { 
        position: fixed; 
        right: 0; 
        width: 280px; 
        height: 100%; 
        transform: translateX(280px); 
        transition: transform 0.3s ease-in-out; 
        box-shadow: none;
    }
    .sidebar.open { 
        transform: translateX(0); 
        box-shadow: -5px 0 25px rgba(0, 0, 0, 0.15); 
    }
    .reading-container {
        padding: 15px 15px; /* تقليل الحواف الجانبية لزيادة وضوح النص ومساحة القراءة بالجوال */
    }
}

/* Premium Glassmorphic Buttons Styling */
.btn {
    border: 1px solid rgba(16, 185, 129, 0.15);
    border-radius: 12px;
    padding: 12px;
    font-weight: 500;
    font-size: 0.9rem;
    background: rgba(16, 185, 129, 0.04);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.02);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text);
    cursor: pointer;
    width: 100%;
}

.btn i {
    font-size: 1.05rem;
}

/* Amber / Warning button for testing mode inactive */
.btn-warning {
    border-color: rgba(245, 158, 11, 0.25);
    background: rgba(245, 158, 11, 0.06);
    color: #d97706;
}
[data-theme="dark"] .btn-warning {
    color: #fbbf24;
}
.btn-warning:hover {
    background: rgba(245, 158, 11, 0.12);
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.15);
}

/* Red / Danger button for testing mode active */
.btn-danger {
    border-color: rgba(239, 68, 68, 0.25);
    background: rgba(239, 68, 68, 0.06);
    color: #dc2626;
}
[data-theme="dark"] .btn-danger {
    color: #fca5a5;
}
.btn-danger:hover {
    background: rgba(239, 68, 68, 0.12);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.15);
}

/* Green / Success button for listen mode */
.btn-success {
    border-color: rgba(16, 185, 129, 0.25);
    background: rgba(16, 185, 129, 0.06);
    color: #059669;
}
[data-theme="dark"] .btn-success {
    color: #34d399;
}
.btn-success:hover {
    background: rgba(16, 185, 129, 0.12);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.15);
}

/* Blue / Info button for search */
.btn-info {
    border-color: rgba(59, 130, 246, 0.25);
    background: rgba(59, 130, 246, 0.06);
    color: #2563eb;
}
[data-theme="dark"] .btn-info {
    color: #60a5fa;
}
.btn-info:hover {
    background: rgba(59, 130, 246, 0.12);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.15);
}

/* Blue / Primary button */
.btn-primary {
    border-color: rgba(59, 130, 246, 0.25);
    background: rgba(59, 130, 246, 0.06);
    color: #2563eb;
}
[data-theme="dark"] .btn-primary {
    color: #60a5fa;
}
.btn-primary:hover {
    background: rgba(59, 130, 246, 0.12);
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.15);
}

/* Indigo / Secondary button for download */
.btn-secondary {
    border-color: rgba(99, 102, 241, 0.25);
    background: rgba(99, 102, 241, 0.06);
    color: #4f46e5;
}
[data-theme="dark"] .btn-secondary {
    color: #818cf8;
}
.btn-secondary:hover {
    background: rgba(99, 102, 241, 0.12);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.15);
}

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

/* Surah Section Container */
.surah-section {
    width: 100%;
    max-width: 800px;
    margin-bottom: 35px;
    padding: 25px;
    background: var(--bg);
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.02);
    transition: background 0.3s, border-color 0.3s;
}

[data-theme="dark"] .surah-section {
    background: rgba(30, 41, 59, 0.4);
    border-color: rgba(51, 65, 85, 0.5);
}

.input-row { display: flex; gap: 10px; }
.mt-10 { margin-top: 10px; }
.status-text { margin-top: 15px; font-size: 0.9rem; }

/* Modals */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); display: none; align-items: center; justify-content: center; z-index: 9999; }
.modal.active { display: flex; }
.modal-content { background: var(--surface); padding: 20px; border-radius: 12px; width: 90%; max-width: 450px; position: relative; box-shadow: 0 10px 25px rgba(0,0,0,0.3); }
.close-modal { position: absolute; top: 15px; left: 15px; cursor: pointer; font-size: 1.2rem; color: var(--text); }
.search-results-area { margin-top: 15px; max-height: 300px; overflow-y: auto; }
.search-item { padding: 10px; border-bottom: 1px solid var(--border); margin-bottom:5px; }
.search-item-meta { font-size: 0.85rem; color: var(--primary); display: flex; justify-content: space-between; margin-top: 5px; align-items: center; }

/* Fixed Inline Styles */
#downloadType { margin-bottom: 10px; }
#imageCaptureArea { position: absolute; left: -9999px; top: -9999px; z-index: -1; }

/* Custom Context Menu */
.custom-context-menu {
    display: none;
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 10001;
    min-width: 160px;
    overflow: hidden;
    animation: fadeIn 0.15s ease-out;
}
.context-item {
    padding: 10px 15px;
    font-size: 0.95rem;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s;
    text-align: right;
}
.context-item:hover {
    background: var(--border);
}
.context-item i {
    color: var(--primary);
    width: 16px;
}

/* Sidebar Tags */
.tags-sidebar-container {
    margin-top: 15px;
    direction: rtl;
}
.tags-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.sidebar-tags-list {
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding-right: 5px;
}
.no-tags-text {
    font-size: 0.85rem;
    color: var(--text);
    opacity: 0.6;
    text-align: center;
}
.tag-group {
    background: rgba(0, 0, 0, 0.03);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    margin-bottom: 5px;
}
[data-theme="dark"] .tag-group {
    background: rgba(255, 255, 255, 0.03);
}
.tag-group-header {
    padding: 8px 10px;
    font-size: 0.9rem;
    font-weight: 550;
    cursor: pointer;
    background: var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}
.tag-group-header:hover {
    background: var(--border);
    opacity: 0.9;
}
.tag-group-items {
    display: none;
    flex-direction: column;
    padding: 5px 0;
}
.tag-group-items.active {
    display: flex;
}
.tag-item-link {
    padding: 6px 15px;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}
.tag-item-link:hover {
    background: rgba(6, 78, 59, 0.1);
}
.tag-delete-btn {
    color: #ef4444;
    cursor: pointer;
    font-size: 0.8rem;
    padding: 2px 5px;
    transition: transform 0.2s;
}
.tag-delete-btn:hover {
    transform: scale(1.1);
}

/* Words wrappers inside Quran Text block */
.q_word {
    display: inline-block;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    border-radius: 4px;
    padding: 0 1px;
}
.q_word:hover {
    background: rgba(6, 78, 59, 0.15);
    color: var(--primary);
}

/* Mutashabihat and other styles */
.modal-sub {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-bottom: 15px;
}
.mutashabihat-meta {
    font-size: 0.95rem;
    padding: 8px;
    background: rgba(6, 78, 59, 0.08);
    border-radius: 6px;
    margin-bottom: 10px;
    font-weight: bold;
    color: var(--primary);
}
.gap-2 { gap: 10px; }
.d-flex { display: flex; }
.flex-column { flex-direction: column; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* API Tabs */
.api-tabs { display: flex; border-bottom: 2px solid rgba(0,0,0,0.1); margin-bottom: 15px; overflow-x: auto; scrollbar-width: none; }
.api-tabs::-webkit-scrollbar { display: none; }
.api-tab-btn { background: none; border: none; padding: 10px 15px; font-size: 1rem; color: var(--text); cursor: pointer; white-space: nowrap; font-family: inherit; transition: 0.3s; opacity: 0.6; font-weight: bold; }
.api-tab-btn.active { opacity: 1; color: var(--primary); border-bottom: 3px solid var(--primary); }
.api-tab-content { display: none; animation: fadeIn 0.3s ease; }
.api-tab-content.active { display: block; }


/* Prevent Selection */
#readingArea { user-select: none; -webkit-user-select: none; }


/* Sticky Modal Headers */
.modal-content { display: flex; flex-direction: column; overflow: hidden; max-height: 90vh; }
.modal-content h2, .modal-content h3 { flex-shrink: 0; }
.api-tabs { flex-shrink: 0; position: sticky; top: 0; background: #fff; z-index: 10; margin-bottom: 0; border-bottom: 2px solid #ddd; }
#apiInfoContent { flex-grow: 1; overflow-y: auto; }
/* Footnotes */
.footnote-section { margin-top: 20px; padding-top: 10px; border-top: 1px dashed #ccc; font-size: 0.9em; color: #666; }
/* Loaders */
.inline-loader { display: inline-block; width: 1.5rem; height: 1.5rem; border: 3px solid rgba(16, 185, 129, 0.3); border-radius: 50%; border-top-color: var(--primary); animation: spin 1s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

