/*
 * Dayah Babul 'Ilmi - Kitab Reader Stylesheet
 * Optimized for comfortable reading on all devices
 */

/* ===== CSS Variables for Reader ===== */
:root {
    --reader-bg: #fefefe;
    --reader-text: #2d2d2d;
    --reader-heading: #1a1a1a;
    --reader-border: #e0e0e0;
    --reader-accent: #1a5f2a;
    --reader-font-size: 18px;
    --reader-line-height: 2;
    --reader-max-width: 720px;
    --reader-padding: 1.5rem;
}

/* Night Mode Variables */
[data-theme="dark"] {
    --reader-bg: #1a1a2e;
    --reader-text: #e0e0e0;
    --reader-heading: #ffffff;
    --reader-border: #333355;
    --reader-accent: #4fd165;
}

/* ===== Reader Container ===== */
.reader-container {
    min-height: 100vh;
    background-color: var(--reader-bg);
    transition: background-color 0.3s ease;
}

/* ===== Reader Header ===== */
.reader-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--reader-bg);
    border-bottom: 1px solid var(--reader-border);
    padding: 0.75rem 0;
    transition: all 0.3s ease;
}

.reader-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.reader-book-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--reader-heading);
    margin: 0;
    flex: 1;
    min-width: 200px;
}

.reader-book-title a {
    color: var(--reader-accent);
    text-decoration: none;
}

.reader-book-title a:hover {
    text-decoration: underline;
}

/* ===== Reader Controls ===== */
.reader-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.reader-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
    border: 2px solid var(--reader-border);
    background: var(--reader-bg);
    color: var(--reader-text);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1rem;
    font-weight: 600;
    -webkit-tap-highlight-color: transparent;
}

.reader-btn:hover {
    border-color: var(--reader-accent);
    color: var(--reader-accent);
}

.reader-btn.active {
    background: var(--reader-accent);
    border-color: var(--reader-accent);
    color: white;
}

.reader-btn-group {
    display: flex;
    gap: 0;
}

.reader-btn-group .reader-btn {
    border-radius: 0;
}

.reader-btn-group .reader-btn:first-child {
    border-radius: 8px 0 0 8px;
}

.reader-btn-group .reader-btn:last-child {
    border-radius: 0 8px 8px 0;
    border-left: none;
}

/* ===== Progress Bar ===== */
.reader-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 4px;
    background: linear-gradient(90deg, var(--reader-accent), #4fd165);
    z-index: 1000;
    transition: width 0.1s ease;
}

/* ===== Chapter Content ===== */
.reader-content {
    max-width: var(--reader-max-width);
    margin: 0 auto;
    padding: var(--reader-padding);
    padding-top: 2rem;
    padding-bottom: 4rem;
}

.chapter-header {
    text-align: center;
    margin-bottom: 3rem;
    padding-bottom: 2rem;
    border-bottom: 2px solid var(--reader-border);
}

.chapter-number {
    display: inline-block;
    background: var(--reader-accent);
    color: white;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.25rem 1rem;
    border-radius: 20px;
    margin-bottom: 1rem;
}

.chapter-title {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--reader-heading);
    margin-bottom: 0;
    line-height: 1.4;
}

@media (min-width: 768px) {
    .chapter-title {
        font-size: 2.25rem;
    }
}

/* ===== Chapter Body - Reading Optimized ===== */
.chapter-body {
    font-size: var(--reader-font-size);
    line-height: var(--reader-line-height);
    color: var(--reader-text);
    transition: font-size 0.2s ease, color 0.3s ease;
}

.chapter-body p {
    margin-bottom: 1.5em;
    text-align: justify;
    text-justify: inter-word;
}

.chapter-body h2 {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--reader-heading);
    margin-top: 2em;
    margin-bottom: 1em;
}

.chapter-body h3 {
    font-size: 1.25em;
    font-weight: 700;
    color: var(--reader-heading);
    margin-top: 1.5em;
    margin-bottom: 0.75em;
}

.chapter-body blockquote {
    border-left: 4px solid var(--reader-accent);
    padding-left: 1.5rem;
    margin: 1.5em 0;
    font-style: italic;
    color: var(--reader-text);
    opacity: 0.9;
}

.chapter-body ul,
.chapter-body ol {
    margin-bottom: 1.5em;
    padding-left: 1.5em;
}

.chapter-body li {
    margin-bottom: 0.5em;
}

/* Arabic Text Support */
.chapter-body .arabic,
.chapter-body .arabic-text,
.chapter-body [dir="rtl"] {
    font-family: 'Amiri', 'Traditional Arabic', serif;
    font-size: 1.3em;
    line-height: 2.1;
    direction: rtl;
    text-align: right;
    background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
    padding: 1.25rem;
    border-radius: 12px;
    margin: 1.5rem 0;
    border-right: 4px solid #0d6b3d;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    word-spacing: 0.05em;
    letter-spacing: 0.01em;
}

/* Prevent double borders on nested Arabic elements */
.chapter-body .arabic .arabic,
.chapter-body .arabic .arabic-text,
.chapter-body .arabic-text .arabic,
.chapter-body .arabic-text .arabic-text,
.chapter-body [dir="rtl"] [dir="rtl"],
.chapter-body .arabic *,
.chapter-body .arabic-text *,
.chapter-body [dir="rtl"] * {
    border: none !important;
    background: none !important;
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
}

/* Night mode Arabic text */
[data-theme="dark"] .chapter-body .arabic,
[data-theme="dark"] .chapter-body .arabic-text,
[data-theme="dark"] .chapter-body [dir="rtl"] {
    background: linear-gradient(135deg, #1a3a2a, #0f2a1f);
    border-right-color: #4fd165;
}

/* Indonesian Text Support */
.chapter-body .indo-text {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 1em;
    line-height: 1.9;
    direction: ltr;
    text-align: justify;
    background: linear-gradient(135deg, #f8fafc, #f1f5f9);
    padding: 1.5rem;
    border-radius: 12px;
    margin: 1.5rem 0;
    border-left: 4px solid #3b82f6;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

/* Night mode Indonesian text */
[data-theme="dark"] .chapter-body .indo-text {
    background: linear-gradient(135deg, #1e293b, #0f172a);
    border-left-color: #60a5fa;
    color: #e2e8f0;
}

/* ===== Chapter Navigation ===== */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 2rem 0;
    margin-top: 3rem;
    border-top: 2px solid var(--reader-border);
}

.chapter-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--reader-bg);
    border: 2px solid var(--reader-border);
    color: var(--reader-text);
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.chapter-nav-btn:hover {
    border-color: var(--reader-accent);
    color: var(--reader-accent);
    text-decoration: none;
}

.chapter-nav-btn.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.chapter-nav-btn i {
    font-size: 1.25rem;
}

/* ===== Font Size States ===== */
.font-size-1 {
    --reader-font-size: 14px;
}

.font-size-2 {
    --reader-font-size: 16px;
}

.font-size-3 {
    --reader-font-size: 18px;
}

.font-size-4 {
    --reader-font-size: 20px;
}

.font-size-5 {
    --reader-font-size: 22px;
}

.font-size-6 {
    --reader-font-size: 24px;
}

/* ===== Reading Progress Toast ===== */
.reading-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--reader-accent);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 30px;
    font-weight: 600;
    font-size: 0.875rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.reading-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ===== Scroll to Top Button ===== */
.scroll-top-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 50px;
    height: 50px;
    background: var(--reader-accent);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.25rem;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 100;
}

.scroll-top-btn.visible {
    opacity: 1;
    visibility: visible;
}

.scroll-top-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

/* ===== Chapter List Modal ===== */
.chapter-list-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.chapter-list-modal.show {
    opacity: 1;
    visibility: visible;
}

.chapter-list-content {
    background: var(--reader-bg);
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.chapter-list-modal.show .chapter-list-content {
    transform: translateY(0);
}

.chapter-list-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--reader-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chapter-list-header h3 {
    margin: 0;
    color: var(--reader-heading);
    font-weight: 700;
}

.chapter-list-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--reader-text);
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

.chapter-list-body {
    overflow-y: auto;
    padding: 1rem;
}

.chapter-list-item {
    display: block;
    padding: 1rem;
    border-radius: 8px;
    color: var(--reader-text);
    text-decoration: none;
    transition: all 0.2s ease;
}

.chapter-list-item:hover {
    background: rgba(26, 95, 42, 0.1);
    color: var(--reader-accent);
}

.chapter-list-item.active {
    background: var(--reader-accent);
    color: white;
}

.chapter-list-item .chapter-num {
    font-weight: 700;
    margin-right: 0.5rem;
}

/* ===== Mobile Responsive ===== */
@media (max-width: 767.98px) {
    :root {
        --reader-padding: 1rem;
        --reader-font-size: 16px;
    }

    .reader-header .container {
        padding: 0 1rem;
    }

    .reader-book-title {
        font-size: 0.875rem;
        min-width: 100%;
        text-align: center;
    }

    .reader-controls {
        justify-content: center;
        width: 100%;
        gap: 0.75rem;
    }

    .reader-btn {
        min-width: 48px;
        min-height: 48px;
        width: 48px;
        height: 48px;
    }

    .chapter-title {
        font-size: 1.5rem;
    }

    .chapter-body .arabic,
    .chapter-body .arabic-text,
    .chapter-body [dir="rtl"] {
        font-size: 1.2em;
        line-height: 2;
        padding: 1rem;
        margin: 1.25rem -0.5rem;
        border-radius: 8px;
    }

    .chapter-body .indo-text {
        padding: 1.25rem;
        margin: 1.25rem -0.5rem;
        border-radius: 8px;
    }

    .chapter-nav {
        flex-direction: column;
        gap: 0.75rem;
    }

    .chapter-nav-btn {
        width: 100%;
        justify-content: center;
        min-height: 48px;
    }

    .scroll-top-btn {
        bottom: 1rem;
        right: 1rem;
        width: 52px;
        height: 52px;
        font-size: 1.5rem;
    }
}

/* Extra small devices */
@media (max-width: 374.98px) {
    :root {
        --reader-padding: 0.75rem;
        --reader-font-size: 15px;
    }

    .chapter-body .arabic,
    .chapter-body .arabic-text,
    .chapter-body [dir="rtl"] {
        font-size: 1.15em;
        padding: 1rem;
    }

    .chapter-body .indo-text {
        padding: 1rem;
    }
}

/* ===== Print Styles ===== */
@media print {

    .reader-header,
    .reader-controls,
    .reader-progress,
    .chapter-nav,
    .scroll-top-btn {
        display: none !important;
    }

    .chapter-body {
        font-size: 12pt;
        line-height: 1.6;
        color: black;
    }
}