/* =========================================================
   Rawi — واجهة القراءة (single-chapter)
   ========================================================= */

/* ---------- الشريط العلوي: زر العودة فقط ---------- */
.ch-topbar {
    position: fixed;
    top: 0;
    inset-inline: 0;
    z-index: 120;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    height: 56px;
    padding: 0 14px;
    background: rgba(8, 9, 11, 0.9);
    background: linear-gradient(to bottom, color-mix(in srgb, var(--bg-deep) 94%, transparent), color-mix(in srgb, var(--bg-deep) 60%, transparent) 70%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 0;
    transition: transform 0.3s var(--ease), opacity 0.3s var(--ease);
}

.ch-topbar.ch-hidden { transform: translateY(-100%); opacity: 0; }

.ch-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    max-width: 100%;
    padding: 8px 16px 8px 12px;
    border: 1px solid var(--tint-1);
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    color: var(--text);
    transition: all var(--t-fast);
}

.ch-back-btn:hover {
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--surface2) 95%, transparent);
    transform: translateX(-2px);
}

.ch-back-btn svg { flex-shrink: 0; color: var(--primary-400); }

.ch-back-meta {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.ch-back-title {
    max-width: 46vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.25;
}

.ch-back-sub {
    color: var(--text3);
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.2;
}

/* ---------- الشريط السفلي ---------- */
.ch-bottombar {
    position: fixed;
    bottom: 0;
    inset-inline: 0;
    z-index: 120;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: rgba(8, 9, 11, 0.92);
    background: linear-gradient(to top, color-mix(in srgb, var(--bg-deep) 96%, transparent), color-mix(in srgb, var(--bg-deep) 75%, transparent) 65%, transparent);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transition: transform 0.3s var(--ease), opacity 0.3s var(--ease);
}

.ch-bottombar.ch-hidden { transform: translateY(110%); opacity: 0; }

.ch-bar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ch-bar-tools,
.ch-bar-nav {
    padding: 4px;
    border: 1px solid var(--tint-08);
    border-radius: var(--radius-pill);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
}

/* الصفحة RTL: العنصر ذو order الأصغر يظهر على اليمين.
   إذاً: التنقّل (order:1) يميناً، والأدوات (order:2) يساراً.
   لعكس الجهتين أضف الكلاس ch-bottombar--flip على #ch-bottombar. */
.ch-bar-nav   { order: 1; }
.ch-bar-tools { order: 2; }

.ch-bottombar--flip .ch-bar-nav   { order: 2; }
.ch-bottombar--flip .ch-bar-tools { order: 1; }

.ch-icon-btn,
.ch-nav-arrow,
.ch-chapters-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 14px;
    border: 0;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--text2);
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--t-fast);
}

.ch-icon-btn:hover,
.ch-nav-arrow:hover:not(:disabled) {
    color: var(--text);
    background: var(--tint-08);
}

.ch-icon-btn--report:hover { color: #ff6b6b; background: rgba(239, 68, 68, 0.12); }

.ch-chapters-btn {
    background: var(--grad-primary);
    color: #fff;
    box-shadow: 0 4px 14px rgba(198, 45, 45, 0.32);
}

.ch-chapters-btn:hover { filter: brightness(1.08); }

.ch-nav-arrow:disabled { opacity: 0.28; cursor: not-allowed; }
.ch-nav-arrow svg { flex-shrink: 0; }

/* ---------- شريط التقدّم ---------- */
.ch-progress-container {
    position: fixed;
    bottom: calc(64px + env(safe-area-inset-bottom));
    inset-inline: 0;
    z-index: 115;
    padding: 0 20px;
    transition: opacity 0.3s var(--ease);
}

.ch-bottombar.ch-hidden ~ .ch-progress-container { opacity: 0; pointer-events: none; }

/* ---------- نوافذ القارئ ---------- */
.ch-modal-sheet {
    background: var(--surface);
    border: 1px solid var(--border2);
    border-bottom: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.ch-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 20px 14px;
    border-bottom: 1px solid var(--border);
}

.ch-modal-title { margin: 0; font-size: 17px; font-weight: 800; color: var(--text); }

.ch-modal-close {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: var(--surface3);
    color: var(--text2);
    cursor: pointer;
    transition: all var(--t-fast);
}

.ch-modal-close:hover { color: var(--text); background: var(--border3); }

/* ---------- عناصر الإعدادات ---------- */
.ch-setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 4px;
    border-bottom: 1px solid var(--border);
}

.ch-setting-item:last-child { border-bottom: 0; }

.ch-setting-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.ch-setting-label { color: var(--text); font-size: 14.5px; font-weight: 700; }
.ch-setting-desc { color: var(--text3); font-size: 12px; line-height: 1.5; }

.ch-setting-control { display: flex; align-items: center; gap: 12px; flex: 1; justify-content: flex-end; }

/* تُظهر/تُخفى عبر JS بـ display */
.ch-setting-subgroup {
    display: none;
    padding-inline-start: 12px;
    margin-inline-start: 2px;
    border-inline-start: 2px solid var(--primary-soft);
}

.ch-setting-subgroup .ch-setting-item { border-bottom: 0; padding-block: 10px; }

.ch-slider {
    flex: 1;
    min-width: 100px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    border-radius: 999px;
    background: var(--surface3);
    outline: 0;
    cursor: pointer;
}

.ch-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary-color);
    box-shadow: 0 0 0 4px var(--primary-soft);
    cursor: pointer;
}

.ch-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border: 0;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
}

.ch-slider-val {
    min-width: 44px;
    color: var(--text2);
    font-size: 12.5px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

/* مفتاح التبديل */
.ch-toggle { position: relative; flex-shrink: 0; cursor: pointer; }
.ch-toggle input { position: absolute; opacity: 0; width: 0; height: 0; }

.ch-toggle-track {
    display: block;
    width: 46px;
    height: 26px;
    border-radius: 999px;
    background: var(--surface3);
    border: 1px solid var(--border2);
    transition: all var(--t-fast);
}

.ch-toggle-track::after {
    content: '';
    position: absolute;
    top: 4px;
    inset-inline-start: 4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text3);
    transition: all var(--t-fast);
}

.ch-toggle input:checked + .ch-toggle-track {
    background: var(--primary-soft);
    border-color: var(--primary-color);
}

.ch-toggle input:checked + .ch-toggle-track::after {
    background: var(--primary-400);
    transform: translateX(-20px);
}

html[dir="ltr"] .ch-toggle input:checked + .ch-toggle-track::after { transform: translateX(20px); }

/* ---------- قائمة الفصول داخل القارئ ---------- */
.ch-chapters-list { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }

.ch-chapters-list li a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface2);
    color: var(--text2);
    font-size: 14px;
    font-weight: 600;
    transition: all var(--t-fast);
}

.ch-chapters-list li a:hover { color: var(--text); border-color: var(--border3); background: var(--surface3); }

.ch-chapters-list li.is-current a,
.ch-chapters-list li a.current {
    color: #fff;
    background: var(--primary-soft);
    border-color: var(--primary-color);
}

/* ---------- استجابة ---------- */
@media (max-width: 640px) {
    .ch-btn-label { display: none; }
    .ch-icon-btn { padding: 10px 12px; }
    .ch-nav-text { display: none; }
    .ch-nav-arrow { padding: 10px 12px; }
    .ch-chapters-btn { padding: 9px 14px; }
    .ch-back-title { max-width: 40vw; }
    .ch-bottombar { padding-inline: 10px; }
}

@media (max-width: 380px) {
    .ch-chapters-btn span { display: none; }
}
