/* ================================================================
   نور من القرآن — تنسيق صفحة جميع القصص (إعادة هيكلة 2026)
   نسق: هيدر مكتبة + شبكة بطاقات مخطوطية + تفاعلات إنستغرام
   ملاحظة: كل أسماء الكلاسات والمعرّفات المستخدمة في الـ JS كما هي.
   ================================================================ */

:root {
    --st-purple: #9B59B6;
    --st-purple-deep: #6C3483;
    --st-purple-ink: #4A235A;
    --st-pink: #F8B4D9;
    --st-soft: #FAF6FD;
    --st-line: rgba(155, 89, 182, 0.16);
    --st-line-soft: rgba(155, 89, 182, 0.08);
    --st-text: #3D2C4E;
    --st-text-light: #7C6B8A;
    --st-font-body: 'Cairo', system-ui, sans-serif;
    --st-font-serif: 'Amiri', 'Cairo', serif;
    --st-shadow: 0 26px 60px rgba(108, 52, 131, 0.10);
    --st-shadow-sm: 0 12px 28px rgba(108, 52, 131, 0.08);
    --st-radius: 26px;
}

/* ---------- الأساس ---------- */
body.stories-page {
    background:
        radial-gradient(1100px 560px at 85% -8%, rgba(248, 180, 217, 0.26), transparent 62%),
        radial-gradient(900px 520px at 10% 6%, rgba(155, 89, 182, 0.14), transparent 60%),
        linear-gradient(180deg, #FFFFFF 0%, var(--st-soft) 45%, #FFFFFF 100%);
    font-family: var(--st-font-body);
    color: var(--st-text);
    overflow-x: hidden;
}

/* ================================================================
   الهيدر
   ================================================================ */
.stories-hero {
    position: relative;
    padding: clamp(6.5rem, 12vw, 9rem) 0 clamp(2rem, 5vw, 3.5rem);
    overflow: hidden;
    isolation: isolate;
}


.stories-hero-inner {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) minmax(260px, 0.9fr);
    align-items: center;
    gap: clamp(1.5rem, 3vw, 3rem);
}

.section-tag {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0.5rem 1.15rem;
    border-radius: 100px;
    background: linear-gradient(135deg, rgba(248,180,217,0.32), rgba(155,89,182,0.18));
    border: 1px solid var(--st-line);
    color: var(--st-purple-deep);
    font-size: 0.82rem;
    font-weight: 700;
}
.section-tag i { color: var(--st-purple); }

.sh-title {
    margin: 1rem 0 0.6rem;
    font-family: var(--st-font-serif);
    font-weight: 700;
    font-size: clamp(2.1rem, 5.4vw, 3.4rem);
    line-height: 1.3;
    color: var(--st-purple-ink);
}

.sh-lead {
    margin: 0;
    max-width: 52ch;
    font-size: clamp(0.95rem, 2vw, 1.05rem);
    line-height: 2;
    color: var(--st-text-light);
}

/* الفاصل النجمي */
.emblem-divider {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1.4rem;
    max-width: 400px;
}
.emblem-divider .divider-line {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--st-line), transparent);
}
.emblem-frame { position: relative; width: 32px; height: 32px; display: grid; place-items: center; }
.emblem-halo {
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(248,180,217,0.5), transparent 68%);
    animation: stPulse 4s ease-in-out infinite;
}
.emblem-star { width: 24px; height: 24px; position: relative; z-index: 1; }

@keyframes stPulse {
    0%, 100% { transform: scale(1); opacity: 0.7; }
    50%      { transform: scale(1.2); opacity: 1; }
}

/* إحصاءات الهيدر */
.sh-stats { display: grid; gap: 0.7rem; }
.stat-chip {
    display: grid;
    grid-template-columns: 44px auto 1fr;
    align-items: center;
    gap: 0.7rem;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid var(--st-line);
    border-radius: 18px;
    padding: 0.75rem 1rem;
    box-shadow: var(--st-shadow-sm);
    backdrop-filter: blur(14px);
}
.stat-chip i {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--st-pink), var(--st-purple));
    color: #fff;
    font-size: 1rem;
}
.stat-chip b { font-size: 1.15rem; color: var(--st-purple-ink); font-family: var(--st-font-serif); }
.stat-chip span { font-size: 0.8rem; color: var(--st-text-light); }

/* ================================================================
   شبكة القصص
   ================================================================ */
.stories-section { padding: clamp(1rem, 3vw, 2rem) 0 clamp(4rem, 8vw, 6rem); position: relative; z-index: 2; }

.stories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
    gap: clamp(1.1rem, 2.4vw, 1.8rem);
}

/* ---------- بطاقة القصة ---------- */
.story-card {
    position: relative;
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(14px);
    border: 1px solid var(--st-line);
    border-radius: var(--st-radius);
    padding: 1.4rem 1.4rem 0.9rem;
    box-shadow: var(--st-shadow-sm);
    overflow: hidden;
    isolation: isolate;
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.7s ease, transform 0.45s cubic-bezier(0.34, 1.3, 0.64, 1), box-shadow 0.35s ease;
}
.story-card.is-in { opacity: 1; transform: none; }

.story-card::before {
    content: '';
    position: absolute;
    top: 0;
    inset-inline: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--st-pink), var(--st-purple), var(--st-purple-deep));
    z-index: 1;
}

.story-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: url('data:image/svg+xml;utf8,<svg width="40" height="40" xmlns="http://www.w3.org/2000/svg"><path d="M20 0l20 20-20 20L0 20z" fill="%238E44AD" fill-opacity="0.025"/></svg>') repeat;
    pointer-events: none;
    z-index: 0;
}

.story-card > * { position: relative; z-index: 1; }

.story-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 32px 66px rgba(108, 52, 131, 0.16);
    border-color: rgba(155, 89, 182, 0.3);
}

/* رقم البطاقة */
.card-serial {
    position: absolute;
    top: 0.8rem;
    inset-inline-end: 1rem;
    font-family: var(--st-font-serif);
    font-size: 2.6rem;
    font-weight: 700;
    line-height: 1;
    color: rgba(155, 89, 182, 0.12);
    z-index: 0;
    pointer-events: none;
}

/* بطاقة مميزة (أول قصة) */
.story-card.is-featured {
    grid-column: span 2;
    background: linear-gradient(150deg, rgba(255,255,255,0.96), rgba(250, 240, 255, 0.9));
    border-color: rgba(155, 89, 182, 0.28);
    box-shadow: var(--st-shadow);
}
.story-card.is-featured .story-header h3 { font-size: 1.9rem; }
.story-card.is-featured .story-excerpt p { font-size: 1.02rem; }

/* رأس البطاقة */
.story-header {
    border-bottom: 1px dashed var(--st-line);
    padding-bottom: 0.9rem;
    margin-bottom: 1rem;
}

.sh-author-mini {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-bottom: 0.75rem;
}
.author-letter {
    width: 40px;
    height: 40px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--st-pink), var(--st-purple));
    color: #fff;
    font-family: var(--st-font-serif);
    font-size: 1.2rem;
    font-weight: 700;
    box-shadow: 0 8px 18px rgba(155, 89, 182, 0.25);
}
.story-author-top {
    display: block;
    font-size: 0.86rem;
    font-weight: 700;
    color: var(--st-purple-ink);
}
.story-date {
    display: block;
    font-size: 0.74rem;
    color: var(--st-text-light);
}
.story-date i { color: var(--st-purple); margin-inline-end: 3px; }

.story-card .story-header h3 {
    margin: 0;
    font-family: var(--st-font-serif);
    color: var(--st-purple-ink);
    font-size: 1.45rem;
    font-weight: 700;
    line-height: 1.5;
}

/* المقتطف */
.story-excerpt {
    flex-grow: 1;
}
.story-excerpt p {
    margin: 0;
    font-size: 0.94rem;
    line-height: 2;
    color: var(--st-text-light);
}

/* شريط الآية */
.story-verse {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    margin: 1.1rem 0 0;
    padding: 0.95rem 1rem;
    border-radius: 18px;
    background: linear-gradient(150deg, rgba(155, 89, 182, 0.95), rgba(74, 35, 90, 0.95));
    color: #fff;
    box-shadow: 0 16px 34px rgba(108, 52, 131, 0.22);
}
.verse-icon { font-size: 1rem; opacity: 0.9; }
.verse-text {
    font-family: var(--st-font-serif);
    font-size: 1rem;
    line-height: 1.95;
    color: #fff;
}

/* الصوت */
.story-audio {
    margin: 1rem 0 0;
    padding: 0;
}

.st-custom-audio-player {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(155, 89, 182, 0.08); /* Matches var(--st-soft) transparently */
    border: 1px solid rgba(155, 89, 182, 0.15);
    border-radius: 40px;
    padding: 8px 12px;
}
.st-audio-play-btn {
    background: linear-gradient(135deg, var(--sv-purple, #9B59B6), var(--sv-pink, #F8B4D9));
    color: #fff;
    border: none;
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.8rem;
    box-shadow: 0 3px 8px rgba(108, 52, 131, 0.25);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.st-audio-play-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 5px 12px rgba(108, 52, 131, 0.35);
}
.st-audio-play-btn:active {
    transform: scale(0.95);
}
.st-audio-progress-bg {
    flex-grow: 1;
    height: 6px;
    background: rgba(108, 52, 131, 0.1);
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.st-audio-progress-bar {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    background: linear-gradient(270deg, var(--sv-purple, #9B59B6), var(--sv-pink, #F8B4D9));
    width: 0%;
    border-radius: 10px;
    pointer-events: none;
    transition: width 0.1s linear;
}
.st-audio-time {
    font-size: 0.7rem;
    color: var(--st-text-muted);
    font-family: var(--st-font-sans, "Cairo", sans-serif);
    min-width: 30px;
    text-align: left;
    font-weight: 600;
}

/* ---------- شريط التفاعلات ---------- */
.story-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding: 0.6rem 0.4rem;
    gap: 0.6rem;
    border-top: 1px solid var(--st-line-soft);
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--st-purple-deep);
    padding: 6px 10px;
    border-radius: 12px;
    transition: background 0.2s ease, transform 0.2s ease;
}
.action-btn:hover { background: rgba(155, 89, 182, 0.08); transform: translateY(-2px); }

.action-btn svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.action-btn span {
    margin-right: 4px;
    font-weight: 700;
    font-size: 13px;
}

.like-active { color: #9B59B6 !important; }
.like-active svg { fill: #9B59B6; stroke: #9B59B6; animation: stPop 0.35s ease; }

@keyframes stPop {
    0% { transform: scale(1); }
    45% { transform: scale(1.35); }
    100% { transform: scale(1); }
}

/* ---------- معاينة التعليقات ---------- */
.comments-preview {
    padding: 0.5rem 0.2rem 0.2rem;
    font-family: var(--st-font-body);
}
.mini-comments-list { margin-bottom: 5px; display: grid; gap: 6px; }
.mini-comment {
    font-size: 13.5px;
    line-height: 1.7;
    background: var(--st-soft);
    border: 1px solid var(--st-line-soft);
    border-radius: 14px;
    padding: 8px 12px;
}
.mini-comment .user-name { font-weight: 800; margin-left: 8px; color: var(--st-purple-deep); }
.mini-comment .comment-text { color: var(--st-text); }

.view-all-comments {
    background: none;
    border: none;
    color: var(--st-text-light);
    font-size: 13px;
    font-weight: 700;
    padding: 4px 0 0;
    cursor: pointer;
    display: block;
}
.view-all-comments:hover { color: var(--st-purple); }

/* ---------- قسم التعليقات الموسّع ---------- */
.comments-section {
    margin-top: 0.6rem;
    padding: 0.8rem 0.9rem;
    border-radius: 18px;
    border: 1px solid var(--st-line);
    background: rgba(250, 246, 253, 0.85);
}

.comments-list { max-height: 220px; overflow-y: auto; margin-bottom: 10px; display: grid; gap: 8px; }
.comments-list::-webkit-scrollbar { width: 5px; }
.comments-list::-webkit-scrollbar-thumb { background: var(--st-line); border-radius: 10px; }

.comment-item {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--st-line-soft);
    border-radius: 14px;
    padding: 8px 12px;
}
.comment-content { font-size: 13.5px; line-height: 1.8; color: var(--st-text); }
.comment-user { font-weight: 800; margin-left: 8px; color: var(--st-purple-deep); }
.comment-meta { font-size: 11.5px; color: var(--st-text-light); margin-top: 2px; }

.comment-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--st-line);
    background: #fff;
    border-radius: 100px;
    padding: 6px 14px;
    margin-top: 6px;
}
.comment-input-wrapper textarea {
    flex: 1;
    border: none;
    background: none;
    resize: none;
    height: 26px;
    max-height: 80px;
    font-size: 13.5px;
    outline: none;
    padding: 2px 0;
    color: var(--st-text);
    font-family: var(--st-font-body);
}
.comment-send-btn {
    background: linear-gradient(135deg, var(--st-purple), var(--st-purple-deep));
    border: none;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    padding: 6px 16px;
    border-radius: 100px;
    transition: transform 0.2s ease;
}
.comment-send-btn:hover { transform: translateY(-2px); }
.comment-send-btn:disabled { opacity: 0.35; cursor: default; transform: none; }

/* ---------- تذييل البطاقة ---------- */
.story-footer {
    margin-top: auto;
    padding-top: 0.9rem;
    border-top: 1px dashed var(--st-line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    flex-wrap: wrap;
}
.story-author { font-size: 0.78rem; color: var(--st-text-light); }

.read-more {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.15rem;
    border-radius: 100px;
    background: linear-gradient(135deg, var(--st-purple), var(--st-purple-deep));
    color: #fff !important;
    font-size: 0.82rem;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 10px 22px rgba(108, 52, 131, 0.24);
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.read-more::after { content: '←'; transition: transform 0.25s ease; }
.read-more:hover { transform: translateY(-3px); box-shadow: 0 16px 32px rgba(108, 52, 131, 0.3); }
.read-more:hover::after { transform: translateX(-4px); }

/* ---------- حالة فارغة ---------- */
.stories-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 1rem;
    background: rgba(255, 255, 255, 0.75);
    border: 1px dashed var(--st-line);
    border-radius: var(--st-radius);
}
.stories-empty i { font-size: 2rem; color: var(--st-pink); margin-bottom: 0.8rem; display: block; }

/* ---------- الترقيم ---------- */
.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: clamp(2rem, 5vw, 3rem);
}
.page-link-custom {
    min-width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.6rem;
    border-radius: 14px;
    border: 1px solid var(--st-line);
    background: rgba(255, 255, 255, 0.85);
    color: var(--st-purple-deep) !important;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.25s ease;
}
.page-link-custom:hover { background: rgba(155, 89, 182, 0.1); transform: translateY(-2px); }
.page-link-custom.active {
    background: linear-gradient(135deg, var(--st-purple), var(--st-purple-deep));
    color: #fff !important;
    border-color: transparent;
    box-shadow: 0 12px 26px rgba(108, 52, 131, 0.26);
}
.page-info {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.82rem;
    color: var(--st-text-light);
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 24px;
    background: linear-gradient(135deg, var(--st-purple), var(--st-purple-deep));
    color: #fff;
    padding: 12px 22px;
    border-radius: 100px;
    font-size: 14px;
    font-family: var(--st-font-body);
    box-shadow: 0 18px 40px rgba(108, 52, 131, 0.3);
    z-index: 10000;
}

/* ================================================================
   الاستجابة
   ================================================================ */
@media (max-width: 991px) {
    .stories-hero-inner { grid-template-columns: 1fr; }
    .sh-stats { grid-template-columns: repeat(3, 1fr); }
    .stat-chip { grid-template-columns: 1fr; text-align: center; justify-items: center; gap: 0.35rem; padding: 0.9rem 0.5rem; }
    .story-card.is-featured { grid-column: span 1; }
}

@media (max-width: 575px) {
    .stories-hero { padding-top: 6rem; }
    .stories-grid { grid-template-columns: 1fr; }
    .story-card { padding: 1.15rem 1.05rem 0.8rem; border-radius: 22px; }
    .story-card .story-header h3,
    .story-card.is-featured .story-header h3 { font-size: 1.25rem; }
    .card-serial { font-size: 2rem; }
    .story-actions { justify-content: space-around; padding: 0.5rem 0; }
    .action-btn { padding: 6px; }
    .action-btn span { font-size: 12px; }
    .sh-stats { grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
    .stat-chip b { font-size: 1rem; }
    .stat-chip span { font-size: 0.68rem; }
    .story-footer { justify-content: space-between; }
    body.stories-page { padding-bottom: 75px; }
    .toast { left: 50%; transform: translateX(-50%); bottom: 90px; width: max-content; max-width: 90vw; }
}

@media (prefers-reduced-motion: reduce) {
    .stories-hero .geo-diamond,
    .emblem-halo { animation: none !important; }
    .story-card { opacity: 1 !important; transform: none !important; }
}
