/* Переменные */
.sam-stories {
    --story-item-size: 125px;
    --story-rotation-time: 3s;
    --theme-color: #DAA752;
    --swiper-theme-color: var(--theme-color);
    --swiper-navigation-size: 26px;
    --swiper-navigation-sides-offset: 24px;
    --swiper-pagination-color: #fff;
    --swiper-pagination-bullet-inactive-color: #fff;
}

.sam-stories__modal {
    --theme-color: #DAA752;
    --swiper-theme-color: var(--theme-color);
}

/* Анимация вращения через transform для 100% совместимости с Safari */
@keyframes rotate-bg {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* ========================================== */
/* Desktop Slider                             */
/* ========================================== */

.sam-stories__slider {
    overflow: hidden;
}

.sam-stories__slider:not(.swiper-initialized) {
    opacity: 0.66;
}

.sam-stories__slider .swiper-wrapper {
    display: flex;
    gap: 15px;
}

.sam-stories__slider .sam-stories__slide.swiper-slide {
    width: 150px;
    margin-right: 0 !important;
}

.sam-stories__slider .sam-stories__slide.swiper-slide button {
    position: relative;
    background: none;
    border: none;
    margin: 0;
    padding: 0px;
    cursor: pointer;
}

.sam-stories__slider .sam-stories__slide.swiper-slide button:hover {
    opacity: 0.9;
    transition: opacity 0.2s ease;
}

.sam-stories__slider .sam-stories__slide.swiper-slide button::before,
.sam-stories__slider .sam-stories__slide.swiper-slide button::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    border-radius: var(--story-item-size);
}

.sam-stories__slider .sam-stories__slide.swiper-slide button::before {
    background: none;
    z-index: 2;
}

.sam-stories__slider .sam-stories__slide.swiper-slide button::after {
    background: conic-gradient(from 0deg, var(--theme-color), #f3ce8a, var(--theme-color));
    background-size: cover;
    display: none; /* Замените на block, если включаете градиентную рамку */
    animation: rotate-bg var(--story-rotation-time) infinite linear;
}

.sam-stories__slider .sam-stories__slide.swiper-slide button img,
.sam-stories__slider .sam-stories__slide.swiper-slide button picture {
    position: relative;
    display: block;
    max-width: 100%;
    border: 0;
    aspect-ratio: 1 / 1;
    width: var(--story-item-size);
    height: var(--story-item-size);
    overflow: hidden;
    object-fit: cover;
    object-position: center center;
    border-radius: var(--story-item-size);
    z-index: 3;
    margin: 0 auto 15px;
}

.sam-stories__slider .swiper-button-prev,
.sam-stories__slider .swiper-button-next {
    background: #fff;
    box-sizing: border-box;
    box-shadow: 0 0 2px 0px var(--theme-color);
    width: var(--swiper-navigation-size);
    padding: 12px;
    border-radius: 24px;
    transition: opacity 0.2s ease;
}

.sam-stories__slider .swiper-button-prev.swiper-button-disabled,
.sam-stories__slider .swiper-button-next.swiper-button-disabled {
    opacity: 0;
}

.sam-stories__slider .swiper-button-prev::after,
.sam-stories__slider .swiper-button-next::after {
    font-size: calc(var(--swiper-navigation-size) / 2);
}

.sam-stories__slider .swiper-button-prev {
    padding-left: 8px;
}

.sam-stories__slider .swiper-button-next {
    padding-right: 8px;
}

/* ========================================== */
/* Modal Slider                               */
/* ========================================== */

.sam-stories__modal {
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    width: 0;
    height: 0;
    background: rgba(0, 0, 0, 0.9);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    opacity: 0;
    z-index: 2147483648;
    transition: opacity 0.2s ease, width 0.2s step-end, height 0.2s step-end;
    overflow: hidden; /* clip заменен на hidden для Safari */
}

.sam-stories__modal.opened {
    opacity: 1;
    width: 100%;
    height: 100%;
    transition: opacity 0.2s ease;
}

.sam-stories__modal .sam-stories__close {
    position: absolute;
    top: 6px;
    right: 6px;
    background: none;
    border: none;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

.sam-stories__modal .sam-stories__modal-slider {
    margin: auto 0;
    height: 90vh; /* dvh заменен на vh для поддержки старых iOS */
    height: 90dvh;
    width: 100%;
}

.sam-stories__modal .sam-stories__modal-slider .swiper-slide {
    display: flex;
    width: auto;
}

.sam-stories__modal .sam-stories__modal-slider .swiper-slide picture,
.sam-stories__modal .sam-stories__modal-slider .swiper-slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sam-stories__modal .swiper-button-next.sam-stories__modal-next,
.sam-stories__modal .swiper-button-prev.sam-stories__modal-prev {
    background: rgba(255, 255, 255, 0.3);
    color: #000;
    margin: 0;
    top: 0;
    left: 0;
    height: 100%;
    width: calc((100vw - 90vh / 16 * 9) / 2);
    opacity: 0;
}

.sam-stories__modal .swiper-button-next.sam-stories__modal-next {
    left: auto;
    right: 0;
}

/* ========================================== */
/* Story Item                                 */
/* ========================================== */

.sam-stories__item {
    position: relative;
    aspect-ratio: 9 / 16;
    height: 100%;
    width: auto;
    max-width: 100vw;
    margin: auto;
    border-radius: 5px;
    overflow: hidden;
    -webkit-transform: scale(0.75);
    transform: scale(0.75);
    transition: transform 0.4s ease;
}

.swiper-slide-active .sam-stories__item {
    -webkit-transform: scale(1);
    transform: scale(1);
}

.sam-stories__item .sam-stories__item-slider {
    height: 100%;
    width: 100%;
}

.sam-stories__item picture,
.sam-stories__item video {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    border: 0;
}

.sam-stories__item .swiper-progressbar {
    position: absolute;
    top: 8px;
    left: 8px;
    right: 8px;
    display: flex;
    gap: 2px;
    z-index: 20;
}

.sam-stories__item .swiper-progressbar span {
    position: relative;
    height: 2px;
    flex: 1 1 auto;
    background: #eee;
}

.sam-stories__item .swiper-progressbar span::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    max-width: 100%;
    background: var(--theme-color);
}

/* Упрощенная логика заполнения progressbar без ломающего :has() */
.sam-stories__item .swiper-progressbar.active span.passed::after {
    width: 100%;
}

.sam-stories__item .swiper-progressbar.active span.active::after {
    width: calc(100% * var(--progress, 0));
}

/* ========================================== */
/* Bottom Button                              */
/* ========================================== */

.sam-stories__btn {
    display: block;
    position: absolute;
}

.sam-stories__btn.--top {
    top: 24px;
    left: 8px;
}

.sam-stories__btn.--bottom {
    bottom: 24px;
    left: 8px;
    right: 8px;
}

.sam-stories__btn.--left {
    text-align: left;
}

.sam-stories__btn.--center {
    text-align: center;
}

.sam-stories__btn.--right {
    text-align: right;
}

.sam-stories__btn .sam-stories__link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    padding: 0 25px;
    border-radius: 20px;
    background: #DAA752;
    color: #fff;
    text-decoration: none;
    font-size: 16px;
    font-style: normal;
    line-height: 1.2;
    font-weight: 500;
}

/* ========================================== */
/* Controls                                   */
/* ========================================== */

.sam-stories__controls {
    position: absolute;
    top: 24px;
    right: 8px;
    max-width: calc(100% - 16px);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    opacity: 0;
}

.swiper-slide-active .sam-stories__item .sam-stories__controls {
    opacity: 1;
}

.sam-stories__controls svg {
    pointer-events: none;
}

.sam-stories__playpause {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: #fff;
    border-radius: 40px;
    border: none;
    z-index: 2;
}

.sam-stories__playpause::after,
.sam-stories__playpause::before {
    position: absolute;
    content: "";
    display: block;
    height: 14px;
    width: 4px;
    border-radius: 8px;
    background: var(--black, #1f1f1f);
    transition: transform 0.2s ease;
}

.sam-stories__playpause::before {
    left: 55%;
}

.sam-stories__playpause::after {
    right: 55%;
}

.sam-stories__playpause svg {
    transition: transform 0.2s ease;
    transform: scale(0);
}

.sam-stories__playpause.paused svg {
    transform: scale(1);
}

.sam-stories__playpause.paused::after,
.sam-stories__playpause.paused::before {
    transform: scale(0);
}

.sam-stories__mute {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: #fff;
    border-radius: 40px;
    border: none;
    z-index: 2;
}

.sam-stories__mute::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 10%;
    margin-top: -1px;
    width: 80%;
    height: 1px;
    background: currentColor;
    transform: rotate(-45deg) scale(0);
    transition: transform 0.2s ease;
}

.sam-stories__mute.muted::after {
    transform: rotate(-45deg) scale(1);
}