/*!
 * Story Player Styles v2.2.0
 * License: MIT
 */

/* ==============================
   Stories Container
============================== */
#stories-container {
    width: 100%;
}

/* Keep wrapper LTR so nav buttons stay on left/right physically */
.stories-wrapper {
    position: relative;
    align-items: center;
    gap: 10px;
    direction: ltr;
}

/* Hide nav buttons when there is NO overflow (JS toggles .no-overflow) */
.stories-wrapper.no-overflow .stories-nav-btn {
    display: none;
}

/* Make the story items appear RTL (right side first) but keep scroll behaviour consistent */
.stories-scroll {
    display: flex;
    flex-direction: row-reverse; /* right-to-left order */
    direction: ltr; /* consistent scrollLeft across browsers */
    gap: 15px;
    overflow-x: auto;
    padding: 1px 0 10px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
}

.stories-scroll::-webkit-scrollbar {
    display: none;
}

/* Scroll Navigation Buttons */
.stories-nav-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10;
}

.stories-nav-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

@media (max-width: 768px) {
    .stories-nav-btn {
        display: none;
    }
}

/* ==============================
   Story Avatar Item
============================== */
.story {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    padding: 5px;
    transition: transform 0.2s ease;
    direction: rtl; /* text RTL */
}

.story:hover {
    transform: scale(1.05);
}

.story-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0264c5, #00b4d8);
    padding: 3px;
    transition: all 0.3s ease;
}

.story-avatar.viewed {
    background: linear-gradient(135deg, #666, #888);
}

.story-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid #1a1a2e;
    object-fit: cover;
}

.story-username {
    margin-top: 8px;
    font-size: 11px;
    color: #fff;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    max-width: 80px;
    direction: rtl;
}

@media (min-width: 768px) {
    .story-avatar {
        width: 100px;
        height: 100px;
    }

    .story-username {
        font-size: 12px;
        max-width: 100px;
    }
}

/* ==============================
   Story Modal
============================== */
.story-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.story-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
}

.story-modal-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* ==============================
   Story Content Wrapper
============================== */
.story-content-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 420px; /* 420 */
    max-height: 740px; /* 740 */
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

@media (min-width: 768px) {
    .story-content-wrapper {
        border-radius: 16px;
        height: 90vh;
        max-height: 740px;
    }
}

/* ==============================
   Progress Segments (Instagram-style)
============================== */
.story-progress-container {
    position: absolute;
    top: 8px;
    left: 10px;
    right: 10px;
    height: 4px; /* thicker */
    z-index: 10;
    display: flex;
    align-items: center;
}

/* Segments are ordered RTL: first story segment on the RIGHT */
.story-progress-segments {
    display: flex;
    flex-direction: row-reverse;
    gap: 4px;
    width: 100%;
    height: 100%;
}

.story-progress-segment {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

/* Fill grows from RIGHT -> LEFT */
.story-progress-segment-fill {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    width: 0%;
    background: #1e88e5;
    border-radius: 3px;
}

/* ==============================
   Header
============================== */
.story-header {
    position: absolute;
    top: 20px;
    left: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
}

.story-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.story-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.story-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.4);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.story-header-btn:hover {
    background: rgba(0, 0, 0, 0.6);
}

.story-user-info {
    text-align: right;
}

.story-username-text {
    display: block;
    color: white;
    font-size: 13px;
    font-weight: 600;
}

.story-time-text {
    display: block;
    color: rgba(255, 255, 255, 0.7);
    font-size: 11px;
}

.story-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #1e88e5;
}

/* ==============================
   Media Container
============================== */
.story-media-container {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #000; /* avoid showing empty side areas */
}

/* IMPORTANT: Use cover to avoid empty bars (740x420 is always filled; crop if needed) */
.story-media {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.story-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Tap Zones for Mobile Navigation */
.story-tap-zone {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30%;
    z-index: 5;
    cursor: pointer;
}

.story-tap-right {
    right: 0;
}

.story-tap-left {
    left: 0;
}

@media (min-width: 768px) {
    .story-tap-zone {
        display: none;
    }
}

/* ==============================
   Footer
============================== */
.story-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
    z-index: 10;
}

.story-footer-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.story-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 5px;
    transition: all 0.2s ease;
}

.story-action-btn:hover {
    transform: scale(1.1);
}

.story-like-btn.liked {
    color: #ff4757;
}

.like-count {
    font-size: 11px;
    font-weight: 600;
}

/* Widget Link */
.story-widget-link {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    padding: 8px 16px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
    max-width: 200px;
}

.story-widget-link:hover {
    background: #fff;
    transform: scale(1.02);
}

.widget-link-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==============================
   Navigation Buttons (Desktop)
============================== */
.story-nav-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
}

.story-nav-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.desktop-only {
    display: none;
}

@media (min-width: 768px) {
    .desktop-only {
        display: flex;
    }
}

/* ==============================
   Mobile Full Screen
============================== */
@media (max-width: 767px) {
    .story-modal-container {
        padding: 0;
    }

    .story-content-wrapper {
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .story-header {
        top: 15px;
    }

    .story-progress-container {
        top: 5px;
        left: 5px;
        right: 5px;
    }
}

/* ==============================
   Animations
============================== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.story-modal {
    animation: fadeIn 0.2s ease;
}

.story-content-wrapper {
    animation: scaleIn 0.2s ease;
}

/* ==============================
   Dark Mode Support
============================== */
.dark .story-username {
    color: #fff !important;
}

/* ==============================
   Accessibility
============================== */
.story-header-btn:focus,
.story-action-btn:focus,
.story-nav-btn:focus {
    outline: 2px solid #1e88e5;
    outline-offset: 2px;
}

/* Screen Reader Only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}


/* ==============================
   v2.2.0 Tweaks (RTL + UX)
============================== */

/* Keep physical layout (icons left, user info right), but keep text RTL */
.story-content-wrapper {
    direction: ltr;
}

/* Footer actions pinned to the LEFT (like then mute) */
.story-footer {
    justify-content: flex-start;
    direction: ltr;
}

.story-footer-left {
    margin-left: 0;
}

.story-user-info,
.story-widget-link,
.widget-link-text {
    direction: rtl;
}

/* Thicker progress bar (segments) */
.story-progress-container {
    height: 4px;
}

.story-progress-segment,
.story-progress-segment-fill {
    border-radius: 3px;
}

/* Center & bigger widget button (like Instagram) */
.story-widget-link {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 18px;
    font-size: 13px;
    border-radius: 22px;
    max-width: min(320px, calc(100% - 120px));
}

.story-widget-link:hover {
    transform: translateX(-50%) scale(1.02);
}

/* Instagram-like loading dots */
.story-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    z-index: 6;
    pointer-events: none;
}

.story-loading.is-visible {
    display: flex;
}

.story-loading span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    animation: storyDotBounce 0.9s infinite ease-in-out;
}

.story-loading span:nth-child(2) {
    animation-delay: 0.15s;
}

.story-loading span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes storyDotBounce {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    40% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* Center mute indicator (shown when video is muted) */
.story-mute-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 6;
    pointer-events: none;

    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.story-mute-indicator.is-visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* Remove focus ring / blue outline everywhere inside story player */
#stories-container button:focus,
#stories-container button:focus-visible,
#stories-container a:focus,
#stories-container a:focus-visible,
.story-modal button:focus,
.story-modal button:focus-visible,
.story-modal a:focus,
.story-modal a:focus-visible {
    outline: none !important;
    box-shadow: none !important;
}

/* Remove mobile tap highlight */
#stories-container button,
#stories-container a,
.story-modal button,
.story-modal a {
    -webkit-tap-highlight-color: transparent;
}
