/* READER STYLES */

.reader-nav {
    background: rgba(10, 14, 23, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 1rem 0;
}

/* Grid layout for true centering */
.reader-nav-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
}

.reader-nav-left {
    justify-self: start;
}

.reader-nav-center {
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-self: center;
}

.reader-nav-center #current-ref {
    min-width: 150px;
    text-align: center;
}

.reader-nav-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-self: end;
}

.verse-display {
    text-align: center;
    margin-bottom: var(--space-lg);
    padding: var(--space-md);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, transparent 100%);
    border-radius: 8px;
    border: 1px solid var(--border-subtle);
    position: relative;
    overflow: visible;
    min-height: 100px;
}

/* Verse container elements */
#verse-box {
    text-align: center;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, transparent 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}

#arabic-verse {
    font-family: 'Amiri', serif;
    font-size: 1.8rem;
    line-height: 2;
    direction: rtl;
    color: #ffffff;
    margin-bottom: 1rem;
    word-spacing: 0.1em;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

#english-verse {
    font-family: 'Crimson Pro', serif;
    font-size: 1.2rem;
    font-style: italic;
    color: rgba(212, 168, 83, 0.85);
    line-height: 1.6;
}

/* Fix for Arabic Congestion - Balanced */
.quran-text {
    font-family: 'Amiri', serif;
    font-size: 1.8rem;
    /* Smaller, more compact */
    line-height: 1.8;
    /* Tighter but safe */
    padding: 0.5rem 0;
    word-spacing: 0.1em;
    margin-bottom: 1.5rem;
    direction: rtl;
    color: var(--text-primary);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    overflow-y: visible;
}

.translation-text {
    font-family: var(--font-body);
    font-size: 1.2rem;
    opacity: 0.9;
    font-style: italic;
    color: var(--text-secondary);
}

/* Layout Modes */
.tafsir-grid {
    display: none;
}

.tafsir-tabs-container {
    display: block;
}

.tabs-header {
    display: flex;
    gap: 1rem;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 1rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
}

.tab-btn {
    padding: 0.5rem 1rem;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    white-space: nowrap;
}

.tab-btn.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

.tafsir-card {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    padding: 1.25rem;
    border-radius: 8px;
    position: relative;
    transition: all var(--transition-fast);
}

.tafsir-card:hover {
    border-color: var(--border-active);
}

.tafsir-content {
    font-family: var(--font-body);
    font-size: 1.1rem;
    line-height: 1.7;
    color: var(--text-primary);
}

/* Typography Refinements */
.tafsir-content.lang-ar {
    font-family: 'Noto Naskh Arabic', serif;
    font-size: 1.3rem;
    line-height: 2.2;
    direction: rtl;
    font-weight: 400;
}

.tafsir-content.lang-en.tafsir-external {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.2rem;
    line-height: 1.6;
}

.tafsir-content.tafsir-custom {
    font-size: 1.25rem;
    /* Preserve original size as requested */
}

.tafsir-content.tafsir-external p {
    margin-bottom: 1rem;
}

.tafsir-content h2,
.tafsir-content h3 {
    font-family: var(--font-heading);
    color: var(--text-gold);
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

/* ========== Quill Formatting Classes ========== */
/* These are needed to render content created in the Studio */

/* Alignment */
.ql-align-center,
.tafsir-content .ql-align-center {
    text-align: center;
}

.ql-align-right,
.tafsir-content .ql-align-right {
    text-align: right;
}

.ql-align-justify,
.tafsir-content .ql-align-justify {
    text-align: justify;
}

/* Direction - only sets direction, does NOT override alignment */
.ql-direction-rtl,
.tafsir-content .ql-direction-rtl {
    direction: rtl;
    /* Do NOT set text-align here - let user's alignment choice take precedence */
}

/* Fonts - Arabic */
.ql-font-amiri {
    font-family: 'Amiri', serif;
}

.ql-font-noto-naskh {
    font-family: 'Noto Naskh Arabic', serif;
}

.ql-font-scheherazade {
    font-family: 'Scheherazade New', serif;
}

/* Fonts - English */
.ql-font-crimson {
    font-family: 'Crimson Pro', serif;
}

.ql-font-cormorant {
    font-family: 'Cormorant Garamond', serif;
}

.ql-font-georgia {
    font-family: 'Georgia', serif;
}

.ql-font-times {
    font-family: 'Times New Roman', serif;
}

.ql-font-merriweather {
    font-family: 'Merriweather', serif;
}

.ql-font-lora {
    font-family: 'Lora', serif;
}

.ql-font-gabriela {
    font-family: 'Gabriela', serif;
}

.ql-font-arial {
    font-family: 'Arial', sans-serif;
}

.ql-font-helvetica {
    font-family: 'Helvetica', sans-serif;
}

/* Size */
.ql-size-small {
    font-size: 0.75em;
}

.ql-size-large {
    font-size: 1.5em;
}

.ql-size-huge {
    font-size: 2em;
}

/* Indent */
.ql-indent-1 {
    padding-left: 3em;
}

.ql-indent-2 {
    padding-left: 6em;
}

.ql-indent-3 {
    padding-left: 9em;
}

/* Lists - Ordered and Unordered */
.tafsir-content ol,
.tafsir-content ul {
    padding-left: 2em;
    margin: 1em 0;
}

.tafsir-content li {
    margin-bottom: 0.5em;
    padding-left: 0.5em;
}

/* Blockquote */
.tafsir-content blockquote {
    border-left: 4px solid var(--accent-primary);
    padding-left: 1em;
    margin-left: 0;
    font-style: italic;
    color: var(--text-secondary);
}

/* Sidebar / Drawer for Options */
.options-drawer {
    position: fixed;
    top: 80px;
    right: -320px;
    width: 320px;
    height: calc(100vh - 80px);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-subtle);
    padding: 2rem;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 90;
    overflow-y: auto;
}

.options-drawer.open {
    right: 0;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(212, 168, 83, 0.1);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 2rem auto;
}

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

/* Inline Library Options */
.inline-library {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: var(--space-lg);
}

.library-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-top: 1rem;
}

.library-items-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

/* Coming Soon group should display horizontally */
.library-group.coming-soon-group {
    grid-column: 1 / -1;
}

.library-group.coming-soon-group .coming-soon-items {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.library-group.coming-soon-group .library-item {
    flex: 0 0 auto;
    min-width: 180px;
}

.library-group {
    margin-bottom: 1.5rem;
}

.library-group-title {
    color: var(--text-gold);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.library-group-arrow {
    transition: transform 0.2s;
    font-size: 0.8rem;
    opacity: 0.6;
}

.library-group-title.collapsed .library-group-arrow {
    transform: rotate(-90deg);
}

.library-items-container.collapsed {
    display: none !important;
}

.library-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 200px;
}

.library-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--border-subtle);
}

.library-item.selected {
    background: rgba(212, 168, 83, 0.1);
    border-color: var(--accent-primary);
}

.library-item span {
    font-size: 0.95rem;
}

/* Arabic text in library item names */
.library-item .tafsir-name-ar {
    font-family: 'Noto Naskh Arabic', serif;
    font-size: 0.9rem;
    font-weight: 500;
    opacity: 0.8;
    margin-right: 0.3rem;
}

/* Arabic text in tafsir card headers */
.tafsir-card h3 .tafsir-name-ar,
.tab-content h3 .tafsir-name-ar {
    font-family: 'Noto Naskh Arabic', serif;
    font-weight: 500;
    opacity: 0.85;
    margin-left: 0.4rem;
}

/* Coming Soon Badge */
.coming-soon-badge {
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    background: rgba(212, 168, 83, 0.2);
    color: var(--accent-primary);
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

.library-item.coming-soon:hover {
    background: rgba(255, 255, 255, 0.03);
    border-color: transparent;
}

/* Verse Navigation Dropdown */
.verse-select {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    /* Remove native arrow completely */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    /* Custom arrow */
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23888' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.2em 1.2em;
    padding-right: 2rem;
}

/* Hide IE arrow */
.verse-select::-ms-expand {
    display: none;
}

.verse-select:hover {
    border-color: var(--border-active);
}

.verse-select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Hide the select-wrapper arrow for verse dropdown since we use custom SVG */
.select-wrapper:has(.verse-select)::after {
    display: none;
}

/* ==================== MOBILE STYLES - COMPLETE REWRITE ==================== */

@media screen and (max-width: 768px) {

    /* ===== GLOBAL MOBILE RESETS ===== */
    body * {
        box-sizing: border-box !important;
    }

    /* ===== NAVIGATION ===== */
    .reader-nav {
        padding: 0.4rem 0 !important;
    }

    .reader-nav-grid {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 0.5rem !important;
        padding: 0.4rem 0.75rem !important;
    }

    .reader-nav-left {
        order: 1;
    }

    .reader-nav-left a {
        font-size: 0.75rem !important;
        padding: 0.4rem 0.6rem !important;
    }

    .reader-nav-center {
        order: 2;
        gap: 0.4rem !important;
    }

    .reader-nav-center #current-ref {
        font-size: 0.8rem !important;
        min-width: auto !important;
        padding: 0 0.25rem;
    }

    .btn-icon {
        width: 32px !important;
        height: 32px !important;
        font-size: 0.85rem !important;
        padding: 0 !important;
    }

    .reader-nav-right {
        order: 3;
        gap: 0.4rem !important;
    }

    .reader-nav-right .select-wrapper {
        display: none !important;
    }

    #btn-bookmark {
        display: none !important;
    }

    #auth-container {
        display: flex !important;
    }

    #auth-container .auth-buttons {
        gap: 0.25rem !important;
    }

    #auth-container .btn-sm {
        font-size: 0.7rem !important;
        padding: 0.3rem 0.5rem !important;
    }

    /* ===== VERSE DISPLAY ===== */
    #verse-container {
        width: 100% !important;
        margin-bottom: 1rem !important;
    }

    #verse-box {
        padding: 1rem !important;
        margin-bottom: 1rem !important;
    }

    #arabic-verse {
        font-size: 1.4rem !important;
        line-height: 1.8 !important;
        margin-bottom: 0.75rem !important;
    }

    #english-verse {
        font-size: 1rem !important;
    }

    /* ===== TAFSIR GRID/TABS ===== */
    /* Default: show grid */
    .tafsir-grid {
        display: none !important;
    }

    .tafsir-tabs-container {
        display: block !important;
    }

    /* ===== TAFSIR CARDS - ULTRA SPECIFIC ===== */
    .tafsir-card {
        padding: 0.6rem 0.75rem !important;
        margin-bottom: 0.75rem !important;
    }

    /* TARGET ALL TEXT INSIDE TAFSIR */
    .tafsir-card .tafsir-content,
    .tafsir-card .tafsir-content *,
    div[id^="content-"] *,
    .custom-tafsir-content,
    .custom-tafsir-content * {
        font-size: 0.85rem !important;
        line-height: 1.5 !important;
    }

    /* GOLDEN LEFT BORDER - TARGET INLINE STYLES */
    .tafsir-card .tafsir-content>div,
    div[id^="content-"]>div,
    .custom-tafsir-content,
    [style*="border-left"] {
        padding-left: 0.5rem !important;
        border-left-width: 2px !important;
        margin-left: 0 !important;
    }

    /* Paragraph spacing */
    .tafsir-card p,
    .tafsir-content p,
    .custom-tafsir-content p {
        margin-bottom: 0.5rem !important;
        margin-top: 0 !important;
    }

    /* Headers inside tafsir */
    .tafsir-card h3,
    .tafsir-card h4 {
        font-size: 0.9rem !important;
        margin-bottom: 0.4rem !important;
    }

    /* ===== LIBRARY ===== */
    .library-grid {
        display: block !important;
    }

    .library-items-container {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    .library-item {
        padding: 0.6rem 0.75rem !important;
        font-size: 0.85rem !important;
        width: 100% !important;
    }

    /* ===== TABS VIEW ===== */
    .tabs-header {
        gap: 0.3rem !important;
        flex-wrap: wrap !important;
    }

    .tab-btn {
        font-size: 0.75rem !important;
        padding: 0.4rem 0.6rem !important;
    }

    /* ===== BUTTONS ===== */
    .btn,
    .btn-outline {
        font-size: 0.75rem !important;
        padding: 0.35rem 0.5rem !important;
    }

}

/* ===== TAFSEER CONTENT FORMATTING ===== */
.tafsir-text {
    line-height: 1.8;
}

.tafsir-content.lang-ar .tafsir-text {
    font-family: 'Noto Naskh Arabic', serif;
}

.tafsir-content.lang-en:not(.tafsir-custom) .tafsir-text {
    font-family: 'Cormorant Garamond', serif;
    text-align: justify;
}

.tafsir-text strong {
    color: var(--text-gold);
    display: inline-block;
    margin-top: 0.5rem;
}

.quran-quote {
    display: inline;
    color: var(--accent-primary, #c8a96e);
    font-weight: 600;
}

.arabic-text {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

.verse-ref {
    color: var(--accent-primary, #c8a96e);
    font-size: 0.85em;
    font-weight: 500;
}

.tafsir-text br+br {
    display: block;
    content: "";
    margin-top: 1rem;
}

.arabic-tab-text {
    font-family: 'Noto Naskh Arabic', serif;
}