:root { --image-story-duration: 5s; }
body {
    display: flex; justify-content: center; align-items: center;
    height: 100vh; margin: 0; background-color: #000; /* رنگ پس زمینه مشکی شد */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overflow: hidden;
}
.story-viewer {
    position: relative; width: 360px; height: 640px;
    background-color: #1a1a1a; border-radius: 16px;
    overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    /* برای جلوگیری از هایلایت آبی در تاچ */
    -webkit-tap-highlight-color: transparent;
}
.story-media {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover;
}
.story-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; flex-direction: column;
    background: linear-gradient(to bottom, rgba(0,0,0,0.45) 0%, transparent 25%, transparent 80%, rgba(0,0,0,0.55) 100%);
    color: white; z-index: 2;
}
.progress-bars {
    display: flex; gap: 5px; padding: 10px;
    transition: opacity 0.5s ease-in-out;
    flex-wrap: wrap; /* برای نمایش صحیح در موبایل */
}
.progress-bars.hidden { opacity: 0; }
.progress-bar {
    flex: 1; height: 4px; background-color: rgba(255, 255, 255, 0.4);
    border-radius: 4px; overflow: hidden;
    min-width: 10px; /* حداقل عرض برای نوارهای کوچک */
}
.progress-bar-fill {
    width: 0; height: 100%; border-radius: 4px;
    background: linear-gradient(90deg, #ff8a00, #e52e71);
    box-shadow: 0 0 5px rgba(229, 46, 113, 0.7);
    transition: width 0.2s linear;
}
.progress-bar-fill.animating {
    animation-name: fillProgress; animation-timing-function: linear;
    animation-fill-mode: forwards; animation-duration: var(--image-story-duration);
}
@keyframes fillProgress { from { width: 0; } to { width: 100%; } }
.paused { animation-play-state: paused; }

.story-header {
    display: flex; justify-content: flex-end; align-items: center;
    padding: 8px 12px; height: 40px; gap: 8px;
}
.story-controls {
    display: flex; gap: 8px;
    margin-left: auto; /* برای بردن دکمه‌ها به سمت چپ (rtl) */
}
.story-controls button {
    background: none; border: none; cursor: pointer;
    padding: 6px; color: white; transition: transform 0.2s ease; z-index: 11;
    outline: none; /* حذف outline در فوکوس */
    -webkit-tap-highlight-color: transparent; /* حذف هایلایت آبی در تاچ */
}
.story-controls button:hover { transform: scale(1.15); }
.story-controls svg { width: 24px; height: 24px; }

/* محفظه جدید برای پایین صفحه (لینک و کپشن) */
.story-bottom-container {
    margin-top: auto; /* این کل بلاک را به پایین هل می‌دهد */
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* استایل دکمه لینک */
.story-link-container {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 0 20px;
    margin-bottom: 8px; /* فاصله بین دکمه و کپشن */
    z-index: 10;
    min-height: 40px; /* رزرو فضا برای جلوگیری از پرش کپشن */
}

.story-link-button {
    background: rgba(255, 255, 255, 0.95);
    color: #111;
    border: none;
    border-radius: 25px; /* هماهنگ با کپشن */
    padding: 10px 24px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: transform 0.2s ease, background 0.2s ease;
    pointer-events: all; /* اطمینان از کلیک‌پذیری */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
}

.story-link-button:hover {
    background: #fff;
    transform: scale(1.03);
}

.story-caption-wrapper {
    /* margin-top: auto; <-- این حذف شد و به story-bottom-container منتقل شد */
    padding: 0 20px 12px;
    display: flex;
    justify-content: center;
    width: 100%; /* اطمینان از هم‌عرض بودن */
}
.story-caption-container {
    background: rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 25px;
    padding: 4px 4px 4px 16px;
    display: flex; align-items: center; gap: 12px;
    transition: all 0.4s ease-in-out;
    max-width: calc(100% - 40px); /* اطمینان از قرار گرفتن در صفحه */
}
.story-caption-container.caption-collapsed {
    padding: 4px;
    background: rgba(0, 0, 0, 0.4);
}
.story-caption-text {
    font-size: 15px; text-align: right; font-weight: 600;
    letter-spacing: 0.3px; text-shadow: 0 1px 3px rgba(0,0,0,0.5);
    transition: all 0.4s ease-in-out;
    max-width: 250px; /* حداکثر عرض برای نمایشگرهای بزرگ */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis; /* برای نمایش ... در صورت طولانی بودن متن */
    flex-grow: 1; /* اجازه رشد به متن */
}
.story-caption-text.hidden {
    opacity: 0; width: 0; margin-left: -12px;
    max-width: 0; /* برای پنهان کردن کامل در حالت جمع شده */
    flex-grow: 0;
}
.caption-toggle-arrow {
    background: rgba(255, 255, 255, 0.2);
    border: none; color: white; cursor: pointer;
    padding: 0; width: 32px; height: 32px;
    border-radius: 50%; z-index: 11;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.4s ease; flex-shrink: 0;
    outline: none; /* حذف outline در فوکوس */
    -webkit-tap-highlight-color: transparent; /* حذف هایلایت آبی در تاچ */
}
.caption-toggle-arrow.rotated { transform: rotate(180deg); }

.story-nav {
    position: absolute; top: 60px; bottom: 85px;
    width: 50%; z-index: 3; cursor: pointer;
    /* برای جلوگیری از هایلایت آبی در تاچ */
    -webkit-tap-highlight-color: transparent;
}
.story-nav-prev { left: 0; } .story-nav-next { right: 0; }

.settings-panel {
    position: absolute; bottom: 0; left: 0; right: 0;
    background: rgba(30, 30, 30, 0.8); backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px 20px 0 0; padding: 20px; color: white; z-index: 10;
    transform: translateY(100%); transition: transform 0.4s ease-in-out;
}
.settings-panel.visible { transform: translateY(0); }
.settings-panel h4 { margin-top: 0; text-align: center; }
.setting-item { display: flex; flex-direction: column; align-items: center; gap: 15px; }
.setting-item label { font-size: 14px; opacity: 0.9; }
.speed-controls { display: flex; gap: 10px; }
.speed-controls button {
    background: rgba(255, 255, 255, 0.2); border: 1px solid transparent;
    color: white; border-radius: 8px; padding: 8px 12px;
    cursor: pointer; transition: all 0.2s ease;
    outline: none; /* حذف outline در فوکوس */
    -webkit-tap-highlight-color: transparent; /* حذف هایلایت آبی در تاچ */
}
.speed-controls button:hover { background: rgba(255, 255, 255, 0.3); }
.speed-controls button.active {
    background: #fff; color: #000; font-weight: bold;
    border-color: #fff;
}

/* واکنش‌گرایی برای نمایشگرهای کوچکتر */
@media (max-width: 400px) {
    .story-viewer {
        width: 80vw;
        height: 80vh;
        border-radius: 10;
    }
    .progress-bars {
        padding: 8px;
        gap: 3px;
    }
    .progress-bar {
        height: 3px;
    }
    .story-link-container {
        margin-bottom: 4px;
        min-height: 36px;
    }
    .story-link-button {
        font-size: 14px;
        padding: 8px 18px;
    }
    .story-caption-wrapper {
        padding: 0 15px 10px;
    }
    .story-caption-container {
        padding: 4px 4px 4px 12px;
        max-width: calc(100% - 30px);
    }
    .story-caption-text {
        font-size: 14px;
        max-width: 200px; /* کاهش عرض در موبایل */
    }
    .caption-toggle-arrow {
        width: 28px;
        height: 28px;
    }
}
