/* ردیف استوری */
.mg-stories {
    --mg-story-size: 84px;
    --mg-story-gap: 18px;
    --mg-story-ring-1: var(--mg-primary);
    --mg-story-ring-2: var(--mg-accent);
    --mg-story-seen: #d5dae1;
    padding: 18px 0;
}

.mg-stories__heading {
    margin: 0 0 14px;
    font-size: 20px;
    font-weight: 800;
    color: var(--mg-text);
}

.mg-stories__rail {
    display: flex;
    justify-content: safe center;
    gap: var(--mg-story-gap);
    padding: 4px 2px 8px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.mg-stories__rail::-webkit-scrollbar {
    display: none;
}

.mg-stories__item {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: calc(var(--mg-story-size) + 8px);
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
    scroll-snap-align: start;
}

.mg-stories__item:focus-visible {
    outline: 2px solid var(--mg-primary);
    outline-offset: 3px;
    border-radius: 12px;
}

.mg-stories__ring {
    position: relative;
    display: block;
    width: var(--mg-story-size);
    height: var(--mg-story-size);
    padding: 3px;
    border-radius: 50%;
    background: linear-gradient(45deg, var(--mg-story-ring-2), var(--mg-story-ring-1));
}

.mg-stories__item.is-seen .mg-stories__ring {
    background: var(--mg-story-seen);
}

.mg-stories__thumb {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border: 2.5px solid var(--mg-bg, #fff);
    border-radius: 50%;
    background: #eef1f5;
}

.mg-stories__thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mg-stories__play {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.55));
    pointer-events: none;
}

.mg-stories__title {
    display: -webkit-box;
    max-width: 100%;
    overflow: hidden;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.5;
    text-align: center;
    color: var(--mg-text);
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.mg-stories__item.is-seen .mg-stories__title {
    color: var(--mg-text-muted);
}

.mg-stories--rounded .mg-stories__ring {
    border-radius: 24px;
}

.mg-stories--rounded .mg-stories__thumb {
    border-radius: 21px;
}

.mg-stories--reel .mg-stories__item {
    position: relative;
    width: calc(var(--mg-story-size) * 1.6);
    gap: 0;
}

.mg-stories--reel .mg-stories__ring {
    width: 100%;
    height: auto;
    aspect-ratio: 9 / 16;
    padding: 2.5px;
    border-radius: 18px;
}

.mg-stories--reel .mg-stories__thumb {
    border-width: 2px;
    border-radius: 15px;
}

.mg-stories--reel .mg-stories__thumb::after {
    content: "";
    position: absolute;
    inset: 45% 0 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.72), transparent);
    pointer-events: none;
}

.mg-stories--reel .mg-stories__title,
.mg-stories--reel .mg-stories__item.is-seen .mg-stories__title {
    position: absolute;
    inset-inline: 12px;
    bottom: 12px;
    z-index: 1;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* نمایش تمام‌صفحه */
html.mg-story-open,
html.mg-story-open body {
    overflow: hidden;
}

.mg-story-viewer {
    position: fixed;
    inset: 0;
    z-index: 100200;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 22px;
    overflow: hidden;
    background: #0b0c0f;
    color: #fff;
    font-family: var(--mg-font-family, inherit);
    -webkit-tap-highlight-color: transparent;
}

.mg-story-viewer[hidden],
.mg-story-viewer [hidden] {
    display: none !important;
}

.mg-story-viewer .mg-story-backdrop {
    position: absolute;
    inset: -60px;
    background-position: center;
    background-size: cover;
    filter: blur(44px) brightness(0.42) saturate(1.2);
}

.mg-story-viewer .mg-story-stage {
    position: relative;
    flex: 0 0 auto;
    height: min(92dvh, 860px);
    aspect-ratio: 9 / 16;
    overflow: hidden;
    border-radius: 18px;
    background: #000;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
    transition: transform 0.2s ease;
}

.mg-story-viewer .mg-story-stage.is-in-next {
    animation: mg-story-next 0.3s cubic-bezier(0.22, 0.8, 0.3, 1);
}

.mg-story-viewer .mg-story-stage.is-in-prev {
    animation: mg-story-prev 0.3s cubic-bezier(0.22, 0.8, 0.3, 1);
}

@keyframes mg-story-next {
    from { opacity: 0.4; transform: perspective(1200px) translateX(-14%) rotateY(-26deg); }
    to { opacity: 1; transform: none; }
}

@keyframes mg-story-prev {
    from { opacity: 0.4; transform: perspective(1200px) translateX(14%) rotateY(26deg); }
    to { opacity: 1; transform: none; }
}

.mg-story-viewer.is-ltr .mg-story-stage.is-in-next {
    animation-name: mg-story-prev;
}

.mg-story-viewer.is-ltr .mg-story-stage.is-in-prev {
    animation-name: mg-story-next;
}

.mg-story-viewer .mg-story-media,
.mg-story-viewer .mg-story-shade,
.mg-story-viewer .mg-story-touch {
    position: absolute;
    inset: 0;
}

.mg-story-viewer .mg-story-blur {
    position: absolute;
    inset: -30px;
    width: calc(100% + 60px);
    height: calc(100% + 60px);
    max-width: none;
    object-fit: cover;
    filter: blur(26px) brightness(0.55);
}

.mg-story-viewer .mg-story-file {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: contain;
}

.mg-story-viewer .mg-story-file.is-fill {
    object-fit: cover;
}

.mg-story-viewer .mg-story-shade {
    background:
        linear-gradient(to bottom, rgba(0, 0, 0, 0.36), transparent 15%),
        linear-gradient(to top, rgba(0, 0, 0, 0.26), transparent 18%);
    pointer-events: none;
}

.mg-story-viewer .mg-story-touch {
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    cursor: pointer;
}

.mg-story-viewer .mg-story-top {
    position: absolute;
    inset-inline: 0;
    top: 0;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 12px 0;
    transition: opacity 0.18s ease;
    pointer-events: none;
}

.mg-story-viewer .mg-story-bars {
    display: flex;
    gap: 4px;
}

.mg-story-viewer .mg-story-bar {
    flex: 1 1 0;
    height: 3px;
    overflow: hidden;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.34);
}

.mg-story-viewer .mg-story-bar i {
    display: block;
    height: 100%;
    border-radius: 3px;
    background: #fff;
    transform: scaleX(0);
    transform-origin: right center;
}

.mg-story-viewer.is-ltr .mg-story-bar i {
    transform-origin: left center;
}

.mg-story-viewer .mg-story-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.mg-story-viewer .mg-story-avatar {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.2);
}

.mg-story-viewer .mg-story-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.5;
    white-space: nowrap;
    text-overflow: ellipsis;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.mg-story-viewer .mg-story-icon {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: #fff;
    cursor: pointer;
    pointer-events: auto;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.5));
}

.mg-story-viewer .mg-story-bottom {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 0 14px calc(16px + env(safe-area-inset-bottom, 0px));
    transition: opacity 0.18s ease;
    pointer-events: none;
}

.mg-story-viewer .mg-story-caption {
    display: -webkit-box;
    margin: 0;
    overflow: hidden;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.8;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
    white-space: pre-line;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
}

.mg-story-viewer .mg-story-product {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 68px;
    padding: 10px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.95);
    color: #111827;
    text-decoration: none;
    pointer-events: auto;
}

.mg-story-viewer .mg-story-product:hover,
.mg-story-viewer .mg-story-cta:hover {
    filter: brightness(0.94);
    color: #111827;
}

.mg-story-viewer .mg-story-product__image {
    flex: 0 0 auto;
    width: 48px;
    height: 48px;
    border-radius: 10px;
    object-fit: cover;
    background: #f1f5f9;
}

.mg-story-viewer .mg-story-product__text {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.mg-story-viewer .mg-story-product__name {
    overflow: hidden;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.5;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.mg-story-viewer .mg-story-product__price {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.5;
    color: var(--mg-primary);
}

.mg-story-viewer .mg-story-product__price:empty {
    display: none;
}

.mg-story-viewer .mg-story-product__go {
    flex: 0 0 auto;
    display: flex;
    color: #6b7280;
    transform: scaleX(-1);
}

.mg-story-viewer.is-ltr .mg-story-product__go {
    transform: none;
}

.mg-story-viewer .mg-story-cta {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 8px 20px;
    border-radius: 12px;
    background: #fff;
    color: #111827;
    font-size: 14.5px;
    font-weight: 700;
    line-height: 1.5;
    text-align: center;
    text-decoration: none;
    pointer-events: auto;
}

.mg-story-viewer .mg-story-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    display: none;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: mg-story-spin 0.8s linear infinite;
    pointer-events: none;
}

.mg-story-viewer .mg-story-loader.is-on {
    display: block;
}

@keyframes mg-story-spin {
    to { transform: rotate(360deg); }
}

.mg-story-viewer .mg-story-playbig {
    position: absolute;
    top: 50%;
    left: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    margin: -36px 0 0 -36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    cursor: pointer;
}

.mg-story-viewer .mg-story-playbig.is-on {
    display: flex;
}

.mg-story-viewer .mg-story-arrow {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    cursor: pointer;
}

.mg-story-viewer .mg-story-arrow:hover {
    background: rgba(255, 255, 255, 0.26);
}

.mg-story-viewer .mg-story-arrow.is-off {
    visibility: hidden;
}

.mg-story-viewer .mg-story-arrow--next svg,
.mg-story-viewer.is-ltr .mg-story-arrow--prev svg {
    transform: scaleX(-1);
}

.mg-story-viewer.is-ltr .mg-story-arrow--next svg {
    transform: none;
}

.mg-story-viewer .mg-story-arrow:focus-visible,
.mg-story-viewer .mg-story-icon:focus-visible,
.mg-story-viewer .mg-story-product:focus-visible,
.mg-story-viewer .mg-story-cta:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.mg-story-viewer.is-holding .mg-story-top,
.mg-story-viewer.is-holding .mg-story-bottom {
    opacity: 0;
}

@media (max-width: 767px) {
    .mg-stories {
        --mg-story-size: 72px;
        --mg-story-gap: 12px;
        padding: 12px 0;
    }

    .mg-story-viewer {
        background: #000;
    }

    .mg-story-viewer .mg-story-backdrop,
    .mg-story-viewer .mg-story-arrow {
        display: none !important;
    }

    .mg-story-viewer .mg-story-stage {
        width: 100%;
        height: 100%;
        aspect-ratio: auto;
        border-radius: 0;
        box-shadow: none;
    }
}

@media (min-width: 768px) and (max-height: 620px) {
    .mg-story-viewer .mg-story-stage {
        height: 96dvh;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mg-story-viewer .mg-story-stage {
        transition: none;
    }

    .mg-story-viewer .mg-story-loader {
        animation-duration: 2s;
    }
}
