/* ==========================================================================
   أطلس الأنبياء والأمم السابقة — الهوية البصرية
   مستوحاة من المخطوطات والخرائط الكلاسيكية: رملي دافئ، ذهبي داكن، كحلي ليلي
   ========================================================================== */

:root {
    --gold: #B45309;
    --gold-bright: #D97706;
    --gold-soft: #F3D9A4;
    --navy: #0F172A;
    --navy-2: #1E293B;
    --sand-50: #FDF8EC;
    --sand-100: #F8EFD9;
    --sand-200: #EFE1C0;
    --sand-300: #DDC89B;
    --sand-400: #C4A873;
    --ink: #2A2118;
    --ink-soft: #5B4E3C;
    --ink-faint: #6B5D49;

    --c-certain: #166534;
    --c-certain-bg: #DCFCE7;
    --c-probable: #92400E;
    --c-probable-bg: #FEF3C7;
    --c-estimated: #5B21B6;
    --c-estimated-bg: #EDE9FE;

    --font-ui: "Tajawal", "Segoe UI", Tahoma, system-ui, sans-serif;
    --font-quran: "Amiri", "Traditional Arabic", "Scheherazade New", serif;

    --radius: 16px;
    --radius-sm: 10px;
    --gap: 16px;
    --sidebar-w: 372px;
    --card-w: 420px;
    --timeline-h: 104px;
    --shadow: 0 18px 44px -12px rgba(15, 23, 42, .45), 0 2px 8px rgba(15, 23, 42, .18);
    --ease: cubic-bezier(.22, .8, .24, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.7;
    color: var(--ink);
    background: var(--navy);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h1, h2, h3, p { margin: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--gold-bright); outline-offset: 2px; border-radius: 6px; }

.skip-link {
    position: fixed; top: -60px; right: 16px; z-index: 100;
    background: var(--navy); color: #fff; padding: 8px 16px; border-radius: 8px; text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* ---------- الخريطة ---------- */
#map { position: fixed; inset: 0; background: #E9DFC8; }
/* مسحة «رَقّ قديم» خفيفة على الخريطة العادية فقط */
body:not(.is-satellite) #map .maplibregl-canvas { filter: sepia(.28) saturate(.92) contrast(1.02); }

.maplibregl-map { font-family: var(--font-ui); }
.maplibregl-ctrl-top-left { top: 72px; left: 6px; transition: left .45s var(--ease); }
.maplibregl-ctrl-bottom-left { bottom: calc(var(--timeline-h) + var(--gap) + 6px); left: 6px; transition: left .45s var(--ease), bottom .3s var(--ease); }
body.timeline-collapsed .maplibregl-ctrl-bottom-left { bottom: 66px; }
.maplibregl-ctrl-group { border-radius: 12px !important; overflow: hidden; box-shadow: var(--shadow) !important; background: var(--sand-50) !important; }
.maplibregl-ctrl-group button + button { border-top-color: var(--sand-200) !important; }
.maplibregl-ctrl-attrib { font-size: 11px; direction: ltr; }

/* ---------- الألواح العائمة (ورق المخطوطات) ---------- */
.panel {
    position: fixed;
    z-index: 10;
    background:
        radial-gradient(120% 80% at 100% 0%, rgba(180, 83, 9, .07), transparent 60%),
        radial-gradient(90% 70% at 0% 100%, rgba(15, 23, 42, .05), transparent 60%),
        linear-gradient(180deg, var(--sand-50), var(--sand-100));
    border: 1px solid var(--sand-300);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.icon-btn {
    display: inline-grid; place-items: center;
    width: 38px; height: 38px; border-radius: 50%;
    transition: background .2s, transform .2s;
    flex: none;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn--light { color: var(--sand-100); background: rgba(255, 255, 255, .08); }
.icon-btn--light:hover { background: rgba(255, 255, 255, .18); }
.icon-btn--gold { color: var(--gold); background: rgba(180, 83, 9, .1); border: 1px solid rgba(180, 83, 9, .3); }
.icon-btn--gold:hover { background: rgba(180, 83, 9, .18); }
.icon-btn .ico-pause { display: none; }
.icon-btn[aria-pressed="true"] .ico-pause { display: block; }
.icon-btn[aria-pressed="true"] .ico-play { display: none; }
.icon-btn .ico-play { fill: currentColor; stroke: none; }

/* ---------- شريط الأدوات ---------- */
.toolbar {
    position: fixed; z-index: 11;
    top: var(--gap); left: var(--gap);
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
    transition: left .45s var(--ease);
}
body.card-open .toolbar { left: calc(var(--card-w) + var(--gap) * 2); }
body.card-open .maplibregl-ctrl-top-left,
body.card-open .maplibregl-ctrl-bottom-left { left: calc(var(--card-w) + var(--gap) + 6px); }

.tool-btn, .segmented {
    background: var(--navy);
    color: var(--sand-100);
    border: 1px solid rgba(243, 217, 164, .28);
    border-radius: 999px;
    box-shadow: var(--shadow);
}
.tool-btn {
    display: inline-flex; align-items: center; gap: 8px;
    height: 44px; padding: 0 16px;
    font-weight: 700; font-size: 14px;
    transition: background .2s, color .2s, border-color .2s;
}
.tool-btn:hover { background: var(--navy-2); }
.tool-btn[aria-pressed="true"] { background: var(--gold); border-color: var(--gold-soft); color: #fff; }
.segmented { display: inline-flex; padding: 4px; height: 44px; }
.seg-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 0 12px; border-radius: 999px;
    font-weight: 700; font-size: 13px; color: var(--sand-300);
    transition: background .2s, color .2s;
}
.seg-btn svg { width: 17px; height: 17px; }
.seg-btn.is-active { background: var(--sand-100); color: var(--navy); }

/* ---------- الشريط الجانبي ---------- */
.sidebar {
    top: var(--gap); right: var(--gap); bottom: var(--gap);
    width: var(--sidebar-w);
    display: flex; flex-direction: column;
    overflow: hidden;
    transition: transform .45s var(--ease), opacity .3s, visibility 0s linear 0s;
}
body.sidebar-collapsed .sidebar {
    transform: translateX(calc(100% + var(--gap) * 2));
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: transform .45s var(--ease), opacity .3s, visibility 0s linear .45s;
}

.brand {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 16px 16px 12px;
    color: var(--sand-100);
    background:
        radial-gradient(140% 120% at 100% 0%, rgba(217, 119, 6, .35), transparent 55%),
        linear-gradient(135deg, var(--navy), #172033);
    border-bottom: 3px double var(--gold);
}
.brand__mark { width: 46px; height: 46px; flex: none; color: var(--gold-soft); }
.brand__mark svg { width: 100%; height: 100%; stroke-width: 1.4; }
.brand__mark .needle { fill: var(--gold-bright); stroke: var(--gold-soft); }
.brand > div:nth-child(2) { flex: 1; min-width: 0; }
.brand__title { font-family: var(--font-quran); font-size: 22px; font-weight: 700; line-height: 1.35; color: #FFF7E3; }
.brand__sub { font-size: 12px; color: var(--sand-300); margin-top: 2px; }

.sidebar__controls { padding: 14px 14px 6px; display: grid; gap: 10px; }
.search {
    display: flex; align-items: center; gap: 8px;
    padding: 0 12px; height: 44px;
    background: #fff; border: 1.5px solid var(--sand-300); border-radius: 12px;
    color: var(--ink-faint);
    transition: border-color .2s, box-shadow .2s;
}
.search:focus-within { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(180, 83, 9, .16); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--ink); height: 100%; }
.search input::placeholder { color: var(--ink-faint); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 11px; border-radius: 999px;
    font-size: 12.5px; font-weight: 700; color: var(--ink-soft);
    background: rgba(255, 255, 255, .7); border: 1px solid var(--sand-300);
    transition: all .2s;
}
.chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--chip-color, var(--ink-faint)); }
.chip:hover { border-color: var(--gold); }
.chip[aria-pressed="true"] { background: var(--navy); color: #fff; border-color: var(--navy); }
.chip small { font-weight: 500; }

.sidebar__meta { padding: 2px 18px 6px; font-size: 12px; color: var(--ink-faint); min-height: 22px; }

.story-list { flex: 1; overflow-y: auto; padding: 2px 10px 10px; scrollbar-width: thin; scrollbar-color: var(--sand-400) transparent; }
.story-item {
    display: grid; grid-template-columns: auto 1fr; gap: 1px 12px; align-items: center;
    width: 100%; text-align: right;
    padding: 10px 12px; margin-bottom: 4px;
    border-radius: 12px; border: 1px solid transparent;
    transition: background .2s, border-color .2s;
}
.story-item:hover { background: rgba(255, 255, 255, .75); border-color: var(--sand-200); }
.story-item.is-active { background: #fff; border-color: var(--gold); box-shadow: 0 4px 14px -6px rgba(180, 83, 9, .5); }
.story-item__num {
    grid-row: span 2;
    width: 34px; height: 34px; border-radius: 50%;
    display: grid; place-items: center;
    font-weight: 800; font-size: 14px; color: #fff;
    background: var(--cat-color, var(--gold));
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .35);
}
.story-item__title { font-weight: 800; font-size: 15px; line-height: 1.45; color: var(--ink); }
.story-item__sub { grid-column: 2; font-size: 12.5px; color: var(--ink-faint); line-height: 1.5; }
.story-empty { padding: 28px 16px; text-align: center; color: var(--ink-faint); }

.sidebar__footer { border-top: 1px solid var(--sand-200); padding: 8px 14px 10px; background: rgba(255, 255, 255, .35); }
.legend summary { cursor: pointer; font-weight: 700; font-size: 13px; color: var(--ink-soft); padding: 4px 2px; }
.legend__list { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
.legend__list li { display: grid; gap: 2px; font-size: 12px; color: var(--ink-soft); }
.legend__note { font-size: 11.5px; color: var(--ink-faint); line-height: 1.7; }

/* ---------- شارة التوثيق ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 6px; width: fit-content;
    padding: 3px 11px 3px 12px; border-radius: 999px;
    font-size: 12.5px; font-weight: 800; line-height: 1.6;
    border: 1px solid currentColor;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge--certain { color: var(--c-certain); background: var(--c-certain-bg); }
.badge--probable { color: var(--c-probable); background: var(--c-probable-bg); }
.badge--estimated { color: var(--c-estimated); background: var(--c-estimated-bg); }
.badge--estimated::before { background: none; border: 2px dashed currentColor; width: 10px; height: 10px; }

/* ---------- بطاقة القصة ---------- */
.card {
    top: var(--gap); left: var(--gap);
    width: var(--card-w);
    max-height: calc(100% - var(--timeline-h) - var(--gap) * 3);
    display: flex; flex-direction: column;
    overflow: hidden;
    animation: card-in .5s var(--ease);
}
body.timeline-collapsed .card { max-height: calc(100% - 60px - var(--gap) * 3); }
@keyframes card-in { from { opacity: 0; transform: translateY(14px) scale(.98); } }

.card__head {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 14px 16px 12px 12px;
    color: var(--sand-100);
    background:
        radial-gradient(130% 140% at 0% 0%, rgba(217, 119, 6, .32), transparent 55%),
        linear-gradient(135deg, var(--navy), #172033);
    border-bottom: 3px double var(--gold);
}
.card__head-text { flex: 1; min-width: 0; }
.card__category {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 11.5px; font-weight: 700; color: var(--gold-soft); letter-spacing: .2px;
}
.card__category::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--cat-color, var(--gold)); box-shadow: 0 0 0 2px rgba(255, 255, 255, .3); }
.card__title { font-family: var(--font-quran); font-size: 23px; font-weight: 700; line-height: 1.4; color: #FFF7E3; }
.card__prophet { font-size: 13px; color: var(--sand-300); }

.card__steps {
    display: flex; gap: 6px; align-items: center;
    padding: 10px 14px; overflow-x: auto; scrollbar-width: none;
    border-bottom: 1px solid var(--sand-200);
    background: rgba(255, 255, 255, .4);
}
.card__steps::-webkit-scrollbar { display: none; }
.step-dot {
    flex: none; min-width: 30px; height: 30px; padding: 0 8px; border-radius: 999px;
    display: grid; place-items: center;
    font-size: 13px; font-weight: 800; color: var(--ink-soft);
    background: #fff; border: 1.5px solid var(--sand-300);
    transition: all .2s;
}
.step-dot:hover { border-color: var(--gold); color: var(--gold); }
.step-dot.is-active { background: var(--gold); border-color: var(--gold); color: #fff; transform: scale(1.08); }
.step-dot.is-done { background: var(--gold-soft); border-color: var(--sand-400); }
.step-dot--intro svg { width: 15px; height: 15px; }

.card__body { flex: 1; overflow-y: auto; padding: 16px 18px 18px; scrollbar-width: thin; scrollbar-color: var(--sand-400) transparent; outline: 0; }
.card__body > * { animation: fade-up .45s var(--ease) both; }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } }

.stop__count { font-size: 12px; font-weight: 700; color: var(--gold); letter-spacing: .3px; }
.stop__name { font-size: 20px; font-weight: 800; line-height: 1.45; color: var(--navy); margin-top: 2px; }
.stop__modern { display: flex; align-items: flex-start; gap: 6px; margin-top: 4px; font-size: 13.5px; color: var(--ink-soft); }
.stop__modern svg { width: 16px; height: 16px; margin-top: 4px; color: var(--gold); }
.stop__badge { margin-top: 10px; }

.verse {
    position: relative; margin: 16px 0 14px; padding: 18px 16px 12px;
    text-align: center;
    background: linear-gradient(180deg, #FFFDF6, #FBF3DD);
    border: 1px solid var(--sand-300); border-radius: 12px;
    box-shadow: inset 0 0 0 4px #FFFDF6, inset 0 0 0 5px var(--sand-300);
}
.verse::before {
    content: "۞"; position: absolute; top: -15px; right: 50%; transform: translateX(50%);
    font-family: var(--font-quran); font-size: 22px; line-height: 1; color: var(--gold);
    background: var(--sand-50); padding: 2px 10px; border-radius: 999px;
}
.verse__text { font-family: var(--font-quran); font-size: 22px; line-height: 2.15; color: #1F1710; }
.verse__ref { display: inline-block; margin-top: 6px; font-size: 12.5px; font-weight: 700; color: var(--gold); }
.verse__ref::before { content: "— "; }

.stop__desc { font-size: 14.5px; line-height: 1.95; color: var(--ink); text-align: justify; }
.stop__tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn-ghost {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 12px; border-radius: 10px;
    font-size: 13px; font-weight: 700; color: var(--ink-soft);
    background: rgba(255, 255, 255, .7); border: 1px solid var(--sand-300);
    transition: all .2s;
}
.btn-ghost svg { width: 16px; height: 16px; }
.btn-ghost:hover { border-color: var(--gold); color: var(--gold); }
.btn-ghost[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.coords { font-size: 12px; color: var(--ink-faint); direction: ltr; unicode-bidi: isolate; align-self: center; margin-inline-start: auto; }

/* مقدمة القصة */
.intro__era { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; color: var(--gold); }
.intro__era svg { width: 16px; height: 16px; }
.intro__summary { margin-top: 10px; font-size: 15.5px; line-height: 2; text-align: justify; }
.intro__facts { display: grid; gap: 8px; margin: 14px 0 0; padding: 12px 14px; background: rgba(255, 255, 255, .6); border: 1px solid var(--sand-200); border-radius: 12px; font-size: 13.5px; }
.intro__facts div { display: grid; grid-template-columns: 78px 1fr; gap: 8px; }
.intro__facts dt { color: var(--ink-faint); font-weight: 700; }
.intro__facts dd { margin: 0; color: var(--ink); }
.intro__stops { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 4px; }
.intro__stops button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: right; padding: 7px 8px; border-radius: 10px; font-size: 14px; transition: background .2s; }
.intro__stops button:hover { background: rgba(255, 255, 255, .8); }
.intro__stops .n { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--gold); color: #fff; font-size: 12px; font-weight: 800; flex: none; }
.intro__stops .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; margin-inline-start: auto; }
.dot--certain { background: var(--c-certain); }
.dot--probable { background: var(--gold-bright); }
.dot--estimated { border: 2px dashed var(--c-estimated); }

.card__foot {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px; border-top: 1px solid var(--sand-200);
    background: rgba(255, 255, 255, .45);
}
.btn {
    flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    height: 42px; padding: 0 12px; border-radius: 12px;
    font-weight: 800; font-size: 13.5px; color: var(--navy);
    background: #fff; border: 1.5px solid var(--sand-300);
    transition: all .2s;
}
.btn svg { width: 18px; height: 18px; }
.btn:hover:not(:disabled) { border-color: var(--gold); color: var(--gold); }
.btn--primary { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn--primary:hover:not(:disabled) { background: #9A4607; border-color: #9A4607; color: #fff; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- الشريط الزمني ---------- */
.timeline {
    left: var(--gap); bottom: var(--gap);
    right: calc(var(--sidebar-w) + var(--gap) * 2);
    height: var(--timeline-h);
    display: flex; align-items: stretch;
    overflow: hidden;
    transition: right .45s var(--ease), height .3s var(--ease), width .3s var(--ease);
}
body.sidebar-collapsed .timeline { right: var(--gap); }
.timeline__toggle {
    flex: none; width: 108px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--sand-100); font-weight: 800; font-size: 13px; line-height: 1.4;
    background: linear-gradient(160deg, var(--navy), #1b2740);
    border-inline-end: 3px double var(--gold);
}
.timeline__toggle small { font-weight: 500; font-size: 10.5px; color: var(--sand-300); }
.timeline__toggle svg { color: var(--gold-soft); }
.timeline__track {
    flex: 1; display: flex; align-items: center; gap: 0;
    overflow-x: auto; overflow-y: hidden; padding: 0 14px;
    scrollbar-width: thin; scrollbar-color: var(--sand-400) transparent;
    scroll-behavior: smooth;
}
.tl-item {
    position: relative; flex: none;
    display: grid; justify-items: center; gap: 3px;
    min-width: 96px; padding: 8px 10px 6px;
    border-radius: 12px;
    transition: background .2s;
}
/* الخط الواصل بين المحطات الزمنية */
.tl-item::before { content: ""; position: absolute; top: 22px; inset-inline: 0; height: 2px; background: repeating-linear-gradient(90deg, var(--sand-400) 0 6px, transparent 6px 10px); }
.tl-item:first-child::before { inset-inline-start: 50%; }
.tl-item:last-child::before { inset-inline-end: 50%; }
.tl-item__dot {
    position: relative; z-index: 1;
    width: 30px; height: 30px; border-radius: 50%;
    display: grid; place-items: center;
    font-size: 12.5px; font-weight: 800; color: #fff;
    background: var(--cat-color, var(--gold));
    border: 2px solid var(--sand-50);
    box-shadow: 0 0 0 1.5px var(--cat-color, var(--gold));
    transition: transform .25s var(--ease);
}
.tl-item__name { font-size: 13px; font-weight: 800; color: var(--ink); white-space: nowrap; line-height: 1.4; }
.tl-item__era { font-size: 10.5px; color: var(--ink-faint); white-space: nowrap; max-width: 130px; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; }
.tl-item:hover { background: rgba(255, 255, 255, .7); }
.tl-item:hover .tl-item__dot { transform: scale(1.12); }
.tl-item.is-active { background: #fff; box-shadow: inset 0 0 0 1.5px var(--gold); }
.tl-item.is-active .tl-item__dot { transform: scale(1.18); }
.tl-item.is-dimmed { opacity: .35; }

body.timeline-collapsed .timeline { height: 50px; width: 108px; right: auto; }
body.timeline-collapsed .timeline__track { display: none; }
body.timeline-collapsed .timeline__toggle { flex-direction: row; gap: 6px; border: 0; width: 100%; }
body.timeline-collapsed .timeline__toggle small { display: none; }
body.timeline-collapsed.card-open .timeline { left: var(--gap); }

/* ---------- دبابيس المحطات على الخريطة ---------- */
.stop-marker { width: 0; height: 0; cursor: pointer; }
/* الدبوس: مربع مُدار حول زاويته السفلية اليسرى، فتبقى قمته مثبتة على الإحداثية عند التكبير */
.stop-marker__pin {
    position: absolute; left: 0; bottom: 0;
    width: 34px; height: 34px; padding: 0;
    display: grid; place-items: center;
    border-radius: 50% 50% 50% 0;
    transform-origin: 0 100%; transform: rotate(-45deg);
    background: var(--navy); color: #fff;
    border: 2.5px solid var(--sand-50);
    box-shadow: 0 6px 14px rgba(15, 23, 42, .45);
    transition: transform .3s var(--ease), background .3s;
}
.stop-marker__pin span { transform: rotate(45deg); font-weight: 800; font-size: 14px; font-family: var(--font-ui); line-height: 1; }
.stop-marker:hover .stop-marker__pin { background: var(--navy-2); transform: rotate(-45deg) scale(1.1); }
.stop-marker.is-active { z-index: 5; }
.stop-marker.is-active .stop-marker__pin { background: var(--gold); transform: rotate(-45deg) scale(1.3); }
.stop-marker.is-active::after {
    content: ""; position: absolute; left: -7px; top: -7px; width: 14px; height: 14px;
    border-radius: 50%; border: 2px solid var(--gold);
    animation: pulse 1.8s ease-out infinite; pointer-events: none;
}
@keyframes pulse { from { transform: scale(.6); opacity: .9; } to { transform: scale(3.4); opacity: 0; } }
.stop-marker__label {
    position: absolute; top: 6px; left: 0; transform: translateX(-50%);
    padding: 1px 9px; border-radius: 999px; white-space: nowrap;
    font-size: 12px; font-weight: 800; color: var(--navy);
    background: rgba(253, 248, 236, .94); border: 1px solid var(--sand-300);
    box-shadow: 0 2px 6px rgba(15, 23, 42, .25);
    pointer-events: none;
}
.stop-marker:not(.is-active) .stop-marker__label { display: none; }

.maplibregl-popup-content {
    font-family: var(--font-ui); direction: rtl; text-align: right;
    background: var(--sand-50); border: 1px solid var(--sand-300); border-radius: 12px; padding: 8px 12px;
    box-shadow: var(--shadow); font-size: 13px; line-height: 1.6;
}
.maplibregl-popup-content strong { display: block; color: var(--navy); font-size: 14px; }
.maplibregl-popup-content span { color: var(--ink-faint); font-size: 12px; }
.maplibregl-popup-tip { border-top-color: var(--sand-50) !important; border-bottom-color: var(--sand-50) !important; }

/* ---------- التحميل والتنبيهات ---------- */
.loader {
    position: fixed; inset: 0; z-index: 50;
    display: grid; place-items: center;
    background: radial-gradient(90% 90% at 50% 40%, #1b2740, var(--navy));
    color: var(--sand-100); text-align: center;
    transition: opacity .6s, visibility 0s linear .6s;
}
body:not(.is-loading) .loader { opacity: 0; visibility: hidden; pointer-events: none; }
.loader__compass {
    width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 50%;
    border: 3px solid rgba(243, 217, 164, .25); border-top-color: var(--gold-bright);
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader__title { font-family: var(--font-quran); font-size: 28px; font-weight: 700; color: #FFF7E3; }
.loader__text { color: var(--sand-300); margin-top: 4px; }

.toast {
    position: fixed; z-index: 60; top: 76px; left: 50%; transform: translateX(-50%);
    max-width: min(92vw, 480px); padding: 10px 18px; border-radius: 12px;
    background: var(--navy); color: #fff; border: 1px solid var(--gold);
    box-shadow: var(--shadow); font-size: 14px; text-align: center;
}
.noscript { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; background: var(--navy); color: #fff; font-size: 18px; }

/* ==========================================================================
   التجاوب — الأجهزة اللوحية والهواتف
   ========================================================================== */
/* البطاقة والقائمة مفتوحتان معاً: يُحصر شريط الأدوات بينهما */
@media (min-width: 861px) {
    body.card-open:not(.sidebar-collapsed) .toolbar { right: calc(var(--sidebar-w) + var(--gap) * 2); }
}
@media (max-width: 1500px) {
    body.card-open:not(.sidebar-collapsed) .seg-btn span { display: none; }
}
@media (max-width: 1360px) {
    .tool-btn span { display: none; }
    .tool-btn { padding: 0; width: 44px; justify-content: center; }
}
@media (max-width: 1180px) {
    :root { --sidebar-w: 330px; --card-w: 380px; }
}

@media (max-width: 860px) {
    :root { --gap: 10px; --timeline-h: 92px; --sidebar-w: min(88vw, 380px); }
    body { font-size: 14.5px; }

    .toolbar, body.card-open .toolbar { top: calc(var(--gap) + env(safe-area-inset-top)); left: var(--gap); right: var(--gap); flex-wrap: nowrap; }
    .seg-btn span { display: none; }
    .segmented { margin-inline-start: auto; }

    .maplibregl-ctrl-top-left, body.card-open .maplibregl-ctrl-top-left { top: calc(64px + env(safe-area-inset-top)); left: 4px; }
    .maplibregl-ctrl-bottom-left, body.card-open .maplibregl-ctrl-bottom-left { left: 4px; }
    .maplibregl-ctrl-top-left .maplibregl-ctrl-group { display: none; } /* اللمس يغني عن أزرار التكبير */

    /* القائمة: درج جانبي فوق كل شيء */
    .sidebar { top: 0; right: 0; bottom: 0; z-index: 30; border-radius: var(--radius) 0 0 var(--radius); border-width: 0 0 0 1px; padding-top: env(safe-area-inset-top); }
    body:not(.sidebar-collapsed)::after { content: ""; position: fixed; inset: 0; z-index: 29; background: rgba(15, 23, 42, .55); backdrop-filter: blur(2px); }

    /* البطاقة: لوح سفلي */
    .card, body.timeline-collapsed .card {
        top: auto; left: 0; right: 0; bottom: 0; width: auto;
        max-height: 58dvh; z-index: 20;
        border-radius: 20px 20px 0 0; border-width: 1px 0 0;
        padding-bottom: env(safe-area-inset-bottom);
        animation-name: sheet-in;
    }
    @keyframes sheet-in { from { transform: translateY(40%); opacity: 0; } }
    .card__head { padding: 10px 14px 9px 10px; }
    .card__title { font-size: 19px; }
    .card__steps { padding: 7px 12px; }
    .card__body { padding: 12px 14px 14px; }
    .stop__name { font-size: 18px; }
    .verse { margin: 14px 0 10px; padding: 14px 12px 8px; }
    .verse__text { font-size: 20px; line-height: 2.05; }
    .btn span { font-size: 13px; }

    /* الشريط الزمني يختفي عند فتح البطاقة ليفسح المجال */
    .timeline, body.sidebar-collapsed .timeline { left: var(--gap); right: var(--gap); bottom: calc(var(--gap) + env(safe-area-inset-bottom)); }
    body.card-open .timeline { display: none; }
    .timeline__toggle { width: 74px; font-size: 11.5px; }
    .timeline__toggle small { display: none; }
    .tl-item { min-width: 84px; padding: 6px 8px 4px; }
    .tl-item::before { top: 20px; }
    body.timeline-collapsed .timeline { width: 150px; right: auto; }
    body.card-open .maplibregl-ctrl-bottom-left { bottom: calc(58dvh + 6px); }
}

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

@media (max-height: 520px) and (min-width: 861px) {
    :root { --timeline-h: 84px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

@media print {
    .toolbar, .sidebar, .timeline, .loader, .toast { display: none !important; }
}

/* ---------- إضافات: المواضع البديلة وقائمة اختيار القصص المتطابقة الموقع ---------- */
.stop__badge { display: flex; flex-wrap: wrap; gap: 6px; }
.badge--note { color: var(--ink-soft); background: rgba(255, 255, 255, .7); border-style: dashed; font-weight: 700; }
.badge--note::before { display: none; }
.stop-marker--alt .stop-marker__pin { border-style: dashed; background: var(--navy-2); }

.choice-popup .maplibregl-popup-content { padding: 10px; }
.choice { display: grid; gap: 4px; min-width: 210px; }
.choice__title { font-size: 12px; font-weight: 800; color: var(--gold); padding: 0 6px 4px; }
.choice__item {
    display: grid; gap: 0; text-align: right; width: 100%;
    padding: 6px 10px; border-radius: 8px;
    border-inline-start: 4px solid var(--cat-color, var(--gold));
    background: rgba(255, 255, 255, .6);
    transition: background .2s;
}
.choice__item:hover { background: #fff; }

/* اللوح overflow:hidden فيُقص إطار التركيز الخارجي؛ نرسمه داخل الزر */
.timeline__toggle:focus-visible { outline-offset: -6px; border-radius: 0; }
.story-list { scroll-padding-block: 6px; }


/* ==========================================================================
   إضافات المزايا الجديدة (التلاوة، التفسير، الشجرة، السور، الاختبار، الإنجاز، 3D)
   ========================================================================== */

/* أزرار رأس البطاقة والمفضلة */
.card__head-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn.is-bookmarked { color: #F59E0B; background: rgba(245, 158, 11, .15); }
.icon-btn.is-bookmarked svg { fill: currentColor; }

/* روابط المصحف والتفسير */
.verse__links {
    display: flex; justify-content: center; gap: 8px; margin-top: 10px;
    padding-top: 8px; border-top: 1px dashed var(--sand-300);
}
.verse__link {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 11.5px; font-weight: 700; color: var(--gold); text-decoration: none;
    padding: 3px 8px; border-radius: 6px; background: rgba(180, 83, 9, .08);
    transition: all .2s;
}
.verse__link:hover { background: rgba(180, 83, 9, .18); text-decoration: underline; }
.verse__link svg { width: 14px; height: 14px; }

/* شريط التلاوة الصوتية */
.audio-bar {
    display: flex; align-items: center; gap: 8px; margin: 10px 0;
    padding: 8px 12px; background: rgba(255, 255, 255, .7);
    border: 1px solid var(--sand-300); border-radius: 10px;
}
.btn-audio {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 14px; border-radius: 8px;
    font-size: 13px; font-weight: 800; color: #fff; background: var(--gold);
    transition: all .2s;
}
.btn-audio:hover { background: var(--gold-bright); }
.btn-audio.is-playing { background: #DC2626; }
.btn-audio svg { width: 16px; height: 16px; }
.select-reciter {
    flex: 1; padding: 6px 10px; border-radius: 8px; border: 1.5px solid var(--sand-300);
    background: #fff; font-size: 12.5px; font-weight: 700; color: var(--ink);
    cursor: pointer; outline: 0;
}
.select-reciter:focus { border-color: var(--gold); }

/* إجراءات مقدمة القصة وتتبع الإنجاز */
.intro__actions { display: flex; gap: 8px; margin-top: 12px; }
.btn-complete { font-weight: 800; }
.btn-complete.is-completed { color: #166534; background: #DCFCE7; border-color: #86EFAC; }
.sidebar__progress {
    padding: 10px 14px 6px; border-bottom: 1px solid var(--sand-200);
    background: rgba(255, 255, 255, .3);
}
.progress-bar-wrap {
    height: 7px; background: var(--sand-200); border-radius: 999px; overflow: hidden; margin-bottom: 4px;
}
.progress-bar { height: 100%; background: var(--gold); border-radius: 999px; transition: width .4s var(--ease); }
.progress-text { display: flex; justify-content: space-between; font-size: 11.5px; font-weight: 700; color: var(--ink-soft); }

/* تبويبات الشريط الجانبي */
.sidebar__tabs {
    display: flex; padding: 6px 12px 0; gap: 6px;
    border-bottom: 1px solid var(--sand-200);
}
.tab-btn {
    flex: 1; padding: 7px 10px; border-radius: 8px 8px 0 0;
    font-size: 12.5px; font-weight: 800; color: var(--ink-soft);
    border-bottom: 2.5px solid transparent; transition: all .2s;
}
.tab-btn:hover { background: rgba(255, 255, 255, .6); }
.tab-btn.is-active {
    background: #fff; color: var(--gold); border-bottom-color: var(--gold);
}

/* تصفح السور القرآنية */
.surah-group { margin-bottom: 6px; border-radius: 10px; border: 1px solid var(--sand-300); background: #fff; overflow: hidden; }
.surah-group__head {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer;
    font-size: 13.5px; font-weight: 700; background: var(--sand-50); user-select: none;
}
.surah-group__num {
    width: 22px; height: 22px; border-radius: 50%; background: var(--gold); color: #fff;
    display: grid; place-items: center; font-size: 11.5px; font-weight: 800;
}
.surah-group__title { flex: 1; color: var(--navy); }
.surah-group__badge { font-size: 11px; color: var(--ink-faint); }
.surah-group__list { list-style: none; margin: 0; padding: 4px 6px; display: grid; gap: 3px; }
.surah-stop-btn {
    width: 100%; text-align: right; padding: 6px 8px; border-radius: 6px;
    transition: background .2s;
}
.surah-stop-btn:hover { background: var(--sand-100); }
.surah-stop-btn__top { display: flex; justify-content: space-between; align-items: center; }
.surah-stop-btn__name { font-weight: 800; font-size: 13px; color: var(--ink); }
.surah-stop-btn__ref { font-size: 11.5px; font-weight: 700; color: var(--gold); }
.surah-stop-btn__story { font-size: 11.5px; color: var(--ink-faint); margin-top: 2px; }

/* لوح الممالك القديمة */
.history-panel {
    position: fixed; z-index: 12; top: 76px; left: var(--gap); width: 340px;
    max-height: calc(100% - 180px); overflow-y: auto; padding: 14px;
    scrollbar-width: thin; scrollbar-color: var(--sand-400) transparent;
}
.history-panel__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; border-bottom: 1px solid var(--sand-200); padding-bottom: 8px; }
.history-panel__head h3 { font-size: 15px; font-weight: 800; color: var(--navy); }
.history-panel__list { display: grid; gap: 8px; }
.history-card {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    padding: 8px 10px; border-radius: 10px; background: #fff;
    border: 1px solid var(--sand-300); border-inline-start: 4px solid var(--realm-color, var(--gold));
}
.history-card__body h4 { font-size: 13px; font-weight: 800; margin: 0; color: var(--navy); }
.history-card__era { font-size: 10.5px; font-weight: 700; color: var(--gold); display: block; }
.history-card__body p { font-size: 11.5px; color: var(--ink-soft); margin: 2px 0 0; line-height: 1.5; }
.btn-sm { font-size: 11.5px; padding: 4px 8px; }

/* صندوق التحدي الجغرافي (Quiz) */
.quiz-box {
    position: fixed; z-index: 25; top: 80px; left: 50%; transform: translateX(-50%);
    width: min(92vw, 440px); padding: 16px; text-align: center;
}
.quiz-card__header { display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; color: var(--gold); margin-bottom: 8px; }
.quiz-card__title { font-size: 18px; font-weight: 800; color: var(--navy); margin-bottom: 4px; }
.quiz-card__hint { font-size: 13px; color: var(--ink-soft); margin-bottom: 4px; }
.quiz-card__modern { font-size: 12.5px; font-weight: 700; color: var(--ink-faint); margin-bottom: 8px; }
.quiz-card__prompt { padding: 8px; border-radius: 8px; background: rgba(180, 83, 9, .1); color: var(--gold); font-size: 12.5px; font-weight: 800; margin-bottom: 10px; }
.quiz-res__dist { font-size: 16px; font-weight: 800; color: var(--navy); }
.quiz-res__points { font-size: 26px; font-weight: 900; color: var(--gold); margin: 6px 0; }
.quiz-res__comm { font-size: 13px; color: var(--ink-soft); margin-bottom: 12px; }
.quiz-final__score { font-size: 32px; font-weight: 900; color: var(--gold); margin: 10px 0; }
.quiz-final__actions { display: flex; gap: 8px; justify-content: center; }
.quiz-pin {
    padding: 3px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 800; color: #fff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, .4);
}
.quiz-pin--guess { background: #DC2626; border: 2px solid #fff; }
.quiz-pin--target { background: #166534; border: 2px solid #fff; }

/* نافذة شجرة نسب الأنبياء */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 60;
    display: grid; place-items: center; background: rgba(15, 23, 42, .65); backdrop-filter: blur(4px);
    padding: 16px;
}
.modal-card {
    position: relative; width: min(94vw, 920px); max-height: 86vh;
    background: var(--sand-50); border: 2px solid var(--sand-300); border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column;
}
.modal-close { position: absolute; top: 12px; left: 12px; z-index: 10; color: var(--ink); background: rgba(0, 0, 0, .06); }
.modal-close:hover { background: rgba(0, 0, 0, .14); }
.modal-body { flex: 1; overflow-y: auto; padding: 24px; scrollbar-width: thin; scrollbar-color: var(--sand-400) transparent; }

.tree-diagram-wrap { position: relative; display: flex; flex-direction: column; gap: 14px; }
.tree-header { text-align: center; border-bottom: 2px solid var(--sand-300); padding-bottom: 12px; }
.tree-header h3 { font-family: var(--font-quran); font-size: 26px; font-weight: 700; color: var(--navy); margin-bottom: 4px; }
.tree-header p { font-size: 13.5px; color: var(--ink-soft); max-width: 660px; margin: 0 auto; line-height: 1.6; }

.tree-controls {
    position: sticky; top: 0; z-index: 15;
    display: flex; gap: 6px; justify-content: flex-end; padding: 4px 0;
}
.tree-ctrl-btn {
    width: 34px; height: 34px; border-radius: 50%; background: #fff;
    border: 1.5px solid var(--sand-300); font-size: 16px; font-weight: 800; color: var(--navy);
    display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,.08); transition: all .2s;
}
.tree-ctrl-btn:hover { background: var(--sand-100); border-color: var(--gold); color: var(--gold); }

.tree-svg-viewport {
    width: 100%; overflow: auto; padding: 10px; background: radial-gradient(circle at 50% 30%, rgba(217, 119, 6, .05), transparent 70%), #FFFDF9;
    border: 1.5px solid var(--sand-300); border-radius: 14px; box-shadow: inset 0 2px 10px rgba(0,0,0,.03);
    min-height: 540px; max-height: 72vh;
}
.tree-svg-canvas {
    width: 100%; min-width: 900px; height: auto; display: block; margin: 0 auto;
    transition: transform .25s ease-out; transform-origin: top center;
}

/* فروع الشجرة */
.tree-branch-line {
    fill: none; stroke: #B45309; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round;
    opacity: 0.85; filter: drop-shadow(0 2px 3px rgba(180, 83, 9, 0.25));
}
.tree-branch-line--dashed {
    stroke: #64748B; stroke-width: 2.5; stroke-dasharray: 6 5;
}
.tree-branch-line--prophecy {
    stroke: #059669; stroke-width: 3; stroke-dasharray: 5 4;
}

/* عقد الشجرة (أوراق الأنبياء) */
.tree-leaf {
    width: 100%; height: 100%; box-sizing: border-box;
    display: flex; align-items: center; gap: 10px; padding: 6px 12px;
    background: #fff; border: 2px solid var(--node-color, var(--gold));
    border-radius: 12px; box-shadow: 0 4px 12px rgba(15, 23, 42, .08);
    cursor: pointer; transition: transform .2s, box-shadow .2s, border-color .2s;
    user-select: none;
}
.tree-leaf:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 8px 20px rgba(180, 83, 9, .25);
    border-color: #D97706; background: #FFFDF9;
}
.tree-leaf__num {
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--node-color, var(--gold)); color: #fff;
    display: grid; place-items: center; font-size: 11.5px; font-weight: 800; flex: none;
}
.tree-leaf__text { display: flex; flex-direction: column; min-width: 0; text-align: right; }
.tree-leaf__name { font-size: 13.5px; font-weight: 800; color: var(--navy); white-space: nowrap; }
.tree-leaf__title { font-size: 10.5px; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* عقدة آدم (الجذع الأول) */
.tree-leaf--root {
    background: linear-gradient(135deg, #FFFDF6, #F8EFD9);
    border-width: 2.5px; border-color: #4338CA;
    box-shadow: 0 6px 16px rgba(67, 56, 202, .18);
}
.tree-leaf--root .tree-leaf__name { font-size: 15px; color: #312E81; }

/* عقدة خاتم الأنبياء محمد ﷺ (التتويج في الأسفل) */
.tree-leaf--seal {
    background: radial-gradient(120% 120% at 50% 0%, #FFFDF6, #F9EDD2);
    border: 3px solid #B45309; border-radius: 16px; padding: 10px 18px;
    box-shadow: 0 10px 28px rgba(180, 83, 9, .35), 0 0 0 3px rgba(243, 217, 164, .5);
}
.tree-leaf--seal .tree-leaf__num {
    width: 30px; height: 30px; font-size: 13px; background: #9A4607;
}
.tree-leaf--seal .tree-leaf__name {
    font-family: var(--font-quran); font-size: 20px; font-weight: 700; color: #9A4607;
}
.tree-leaf--seal .tree-leaf__title {
    font-size: 12px; font-weight: 700; color: #B45309;
}

/* بطاقة حلقة الوصل للأجيال */
.tree-node-bridge {
    width: 100%; height: 100%; box-sizing: border-box;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: rgba(180, 83, 9, .06); border: 1.5px dashed var(--gold); border-radius: 10px;
    padding: 6px 10px; text-align: center; color: var(--gold);
}
.tree-node-bridge__arrow { font-size: 12px; font-weight: 800; }
.tree-node-bridge small { font-size: 10px; color: var(--ink-soft); line-height: 1.4; margin-top: 2px; }
