/* ============================================
   INSTAGRAM-STYLE STORIES - MODERN DESIGN
   FIXED: 3 items on mobile, 5 items on desktop
   NO OVERFLOW - all items fully visible
   ============================================ */

/* Контейнер секции сторис */
.stories-section {
    position: relative;
    padding: 15px 0;
}

.stories-section.container {
    padding-left: 16px;
    padding-right: 16px;
    max-width: 100%;
}

@media (min-width: 768px) {
    .stories-section {
        padding: 30px 0;
    }
    
    .stories-section.container {
        padding-left: var(--tablet-padding, 24px);
        padding-right: var(--tablet-padding, 24px);
        max-width: var(--container-width, 1200px);
    }
}

@media (min-width: 1024px) {
    .stories-section.container {
        padding-left: 32px;
        padding-right: 32px;
    }
}

/* Превью сторис на главной - СО СКРОЛЛОМ И SNAP */
.stories-preview {
    --stories-count: 3;
    --stories-gap: 10px;
    
    display: flex;
    gap: var(--stories-gap);
    padding: 10px 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    /* Snap к началу каждой карточки */
    scroll-snap-type: x mandatory;
    scroll-padding-left: 0;
    margin: 0;
}

.stories-preview::-webkit-scrollbar {
    display: none;
}

@media (min-width: 768px) {
    .stories-preview {
        --stories-count: 5;
        --stories-gap: 16px;
    }
}

/* ============================================
   КАРТОЧКА СТОРИС - ТОЧНАЯ ШИРИНА
   Mobile: ровно 3 штуки видно
   Desktop: ровно 5 штук видно
   Скролл для остальных
   ============================================ */

.story-item {
    /* 
       Ширина = (100% - (кол-во гэпов * размер гэпа)) / кол-во элементов
       Гэпов всегда на 1 меньше чем элементов
    */
    --total-gaps: calc((var(--stories-count, 3) - 1) * var(--stories-gap, 10px));
    flex: 0 0 calc((100% - var(--total-gaps)) / var(--stories-count, 3));
    width: calc((100% - var(--total-gaps)) / var(--stories-count, 3));
    min-width: calc((100% - var(--total-gaps)) / var(--stories-count, 3));
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    /* Snap к началу каждой карточки */
    scroll-snap-align: start;
}

/* Планшеты - 4 элемента видны */
@media (min-width: 600px) {
    .stories-preview {
        --stories-count: 4;
        --stories-gap: 12px;
    }
}

/* Десктоп - переменные уже заданы выше */

.story-item:hover {
    transform: translateY(-4px);
}

.story-item:active {
    transform: scale(0.98);
}

/* Превью картинка - соотношение 3:4 */
.story-thumb {
    width: 100%;
    aspect-ratio: 3 / 4;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.3s ease;
}

/* Skeleton shimmer animation */
.story-thumb::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.5) 50%,
        transparent 100%
    );
    animation: skeleton-shimmer 1.5s infinite;
    z-index: 1;
    pointer-events: none;
}

.story-thumb.loaded::before {
    display: none;
}

@keyframes skeleton-shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.story-item:hover .story-thumb {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

@media (min-width: 360px) {
    .story-thumb {
        border-radius: 11px;
    }
}

@media (min-width: 400px) {
    .story-thumb {
        border-radius: 12px;
    }
}

@media (min-width: 480px) {
    .story-thumb {
        border-radius: 14px;
    }
}

@media (min-width: 768px) {
    .story-thumb {
        border-radius: 16px;
    }
}

@media (min-width: 1024px) {
    .story-thumb {
        border-radius: 18px;
    }
}

.story-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease;
    opacity: 0;
}

.story-thumb img.loaded {
    opacity: 1;
}

.story-item:hover .story-thumb img.loaded {
    transform: scale(1.05);
}

/* Градиентный оверлей - УБРАН */
.story-thumb-overlay {
    position: absolute;
    inset: 0;
    background: transparent;
    display: flex;
    align-items: flex-end;
    padding: 8px;
}

@media (min-width: 400px) {
    .story-thumb-overlay {
        padding: 10px;
    }
}

@media (min-width: 768px) {
    .story-thumb-overlay {
        padding: 14px;
    }
}

.story-item:hover .story-thumb-overlay {
    background: transparent;
}

/* Заголовок - скрыт */
.story-thumb-title {
    display: none;
}

/* Просмотренные сторис */
.story-item.viewed .story-thumb {
    opacity: 0.7;
}

.story-item.viewed .story-thumb-overlay {
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, 0.5) 0%,
        rgba(0, 0, 0, 0.2) 30%,
        transparent 60%
    );
}

/* Индикатор непросмотренной сторис */
.story-item:not(.viewed) .story-thumb::before {
    content: '';
    position: absolute;
    top: 5px;
    right: 5px;
    width: 6px;
    height: 6px;
    background: linear-gradient(135deg, #C8102E, #FF6B35);
    border-radius: 50%;
    z-index: 5;
    box-shadow: 0 0 0 2px white, 0 2px 8px rgba(200, 16, 46, 0.4);
}

@media (min-width: 480px) {
    .story-item:not(.viewed) .story-thumb::before {
        top: 8px;
        right: 8px;
        width: 7px;
        height: 7px;
    }
}

@media (min-width: 768px) {
    .story-item:not(.viewed) .story-thumb::before {
        top: 10px;
        right: 10px;
        width: 8px;
        height: 8px;
    }
}

/* Кнопки навигации превью */
.stories-preview-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    background: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    visibility: hidden;
}

.stories-section:hover .stories-preview-nav:not(.hidden) {
    opacity: 1;
    visibility: visible;
}

.stories-preview-nav:hover {
    background: #fafafa;
    transform: translateY(-50%) scale(1.08);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.stories-preview-nav:active {
    transform: translateY(-50%) scale(0.95);
}

.stories-preview-nav.prev {
    left: 8px;
}

.stories-preview-nav.next {
    right: 8px;
}

.stories-preview-nav svg {
    width: 18px;
    height: 18px;
    stroke: #333;
    stroke-width: 2.5;
    fill: none;
}

.stories-preview-nav.hidden {
    display: none !important;
}

/* На мобильных скрываем кнопки - используем свайп */
@media (max-width: 768px) {
    .stories-preview-nav {
        display: none !important;
    }
}

/* ============================================
   ПОЛНОЭКРАННЫЙ ПРОСМОТР СТОРИС
   Instagram-style с превью соседних сторис
   ============================================ */

.stories-viewer {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    gap: 20px;
}

.stories-viewer.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.stories-backdrop {
    position: absolute;
    inset: 0;
    z-index: 1;
}

/* Контейнер сторис */
.stories-container {
    position: relative;
    width: 100%;
    max-width: 380px;
    height: auto;
    max-height: 85vh;
    aspect-ratio: 9 / 16;
    border-radius: 16px;
    overflow: hidden;
    background: #000;
    z-index: 2;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.6);
    animation: scaleIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

/* ============================================
   ПРЕВЬЮ СОСЕДНИХ СТОРИС (Instagram-style)
   ============================================ */

.story-neighbor {
    position: relative;
    width: 260px;
    max-height: 70vh;
    aspect-ratio: 9 / 16;
    border-radius: 12px;
    overflow: hidden;
    background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
    cursor: pointer;
    flex-shrink: 0;
    opacity: 0.6;
    transform: scale(0.9);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
}

/* Skeleton для соседних превью */
.story-neighbor::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.1) 50%,
        transparent 100%
    );
    animation: skeleton-shimmer 1.5s infinite;
    z-index: 1;
    pointer-events: none;
}

.story-neighbor.loaded::before {
    display: none;
}

.story-neighbor:hover {
    opacity: 0.8;
    transform: scale(0.92);
}

.story-neighbor.hidden {
    display: none !important;
}

.story-neighbor img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.story-neighbor img.loaded {
    opacity: 1;
}

.story-neighbor-overlay {
    position: absolute;
    inset: 0;
    background: transparent;
    display: flex;
    align-items: flex-end;
    padding: 16px;
    pointer-events: none;
}

.story-neighbor-title {
    color: white;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.3;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    display: none; /* Скрываем заголовок тоже */
}

/* Скрываем превью на экранах меньше 1100px */
@media (max-width: 1100px) {
    .story-neighbor {
        display: none;
    }
    
    .stories-viewer {
        gap: 0;
    }
}

/* На средних экранах делаем превью меньше */
@media (min-width: 1100px) and (max-width: 1400px) {
    .story-neighbor {
        width: 200px;
        max-height: 60vh;
    }
}

@keyframes scaleIn {
    from { 
        opacity: 0;
        transform: scale(0.9);
    }
    to { 
        opacity: 1;
        transform: scale(1);
    }
}

/* Мобильные устройства */
@media (max-width: 480px) {
    .stories-viewer {
        padding: 10px;
    }
    
    .stories-container {
        max-width: 100%;
        max-height: 90vh;
        border-radius: 12px;
    }
}

/* Очень маленькие экраны */
@media (max-height: 700px) {
    .stories-container {
        max-height: 88vh;
    }
}

/* Прогресс-бары */
.stories-progress {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 3px;
    padding: 8px 10px 6px;
    z-index: 10;
    background: linear-gradient(to bottom, rgba(0,0,0,0.4), transparent);
}

@media (min-width: 480px) {
    .stories-progress {
        gap: 4px;
        padding: 10px 12px 8px;
    }
}

.progress-bar {
    flex: 1;
    height: 2px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    overflow: hidden;
}

@media (min-width: 480px) {
    .progress-bar {
        height: 2.5px;
    }
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: white;
    border-radius: 2px;
}

.progress-bar.viewed .progress-bar-fill {
    width: 100%;
}

.progress-bar.active .progress-bar-fill {
    animation: progressFill var(--story-duration, 5s) linear forwards;
}

@keyframes progressFill {
    from { width: 0%; }
    to { width: 100%; }
}

/* Хедер */
.stories-header {
    position: absolute;
    top: 16px;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    z-index: 10;
}

@media (min-width: 480px) {
    .stories-header {
        top: 20px;
        padding: 8px 12px;
    }
}

.story-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

@media (min-width: 480px) {
    .story-info {
        gap: 10px;
    }
}

.story-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #C8102E, #FF6B35);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 11px;
}

@media (min-width: 480px) {
    .story-avatar {
        width: 32px;
        height: 32px;
        font-size: 13px;
    }
}

.story-author {
    color: white;
    font-size: 12px;
    font-weight: 600;
}

@media (min-width: 480px) {
    .story-author {
        font-size: 13px;
    }
}

/* Кнопка закрытия */
.stories-close {
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

@media (min-width: 480px) {
    .stories-close {
        width: 32px;
        height: 32px;
    }
}

.stories-close:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.1);
}

.stories-close svg {
    width: 16px;
    height: 16px;
    stroke: white;
    stroke-width: 2;
}

@media (min-width: 480px) {
    .stories-close svg {
        width: 18px;
        height: 18px;
    }
}

/* Слайды */
.stories-slides {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.story-slide {
    position: absolute;
    inset: 0;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
    display: flex;
    flex-direction: column;
}

.story-slide.active {
    opacity: 1;
    visibility: visible;
}

.story-slide-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.story-slide-image.loaded {
    opacity: 1;
}

/* Контент слайда - БЕЗ ГРАДИЕНТА */
.story-slide-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 40px 16px 20px;
    background: transparent;
}

@media (min-width: 480px) {
    .story-slide-content {
        padding: 50px 20px 25px;
    }
}

@media (min-width: 768px) {
    .story-slide-content {
        padding: 60px 20px 30px;
    }
}

.story-slide-title {
    color: white;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 6px;
    line-height: 1.2;
}

@media (min-width: 480px) {
    .story-slide-title {
        font-size: 20px;
        margin-bottom: 8px;
    }
}

@media (min-width: 768px) {
    .story-slide-title {
        font-size: 24px;
    }
}

.story-slide-subtitle {
    color: rgba(255,255,255,0.85);
    font-size: 13px;
    margin-bottom: 12px;
    line-height: 1.4;
}

@media (min-width: 480px) {
    .story-slide-subtitle {
        font-size: 14px;
        margin-bottom: 16px;
    }
}

.story-slide-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: white;
    color: #1a1a1a;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
    transition: all 0.2s ease;
}

@media (min-width: 480px) {
    .story-slide-btn {
        padding: 12px 24px;
        font-size: 14px;
    }
}

.story-slide-btn:hover {
    background: #f5f5f5;
    transform: translateY(-2px);
}

.story-slide-btn svg {
    width: 14px;
    height: 14px;
}

@media (min-width: 480px) {
    .story-slide-btn svg {
        width: 16px;
        height: 16px;
    }
}

/* Зоны навигации */
.story-nav-area {
    position: absolute;
    top: 60px;
    bottom: 80px;
    width: 35%;
    z-index: 5;
    cursor: pointer;
}

@media (min-width: 480px) {
    .story-nav-area {
        top: 70px;
        bottom: 100px;
    }
}

.story-nav-area.prev { left: 0; }
.story-nav-area.next { right: 0; }

/* Кнопки навигации между сторис */
.stories-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    background: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    transition: all 0.2s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.stories-nav:hover {
    transform: translateY(-50%) scale(1.08);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.25);
}

.stories-nav.prev-story { left: -70px; }
.stories-nav.next-story { right: -70px; }

.stories-nav svg {
    width: 22px;
    height: 22px;
    stroke: #333;
    stroke-width: 2;
}

/* Скрываем круглые кнопки на мобильных */
@media (max-width: 600px) {
    .stories-nav { display: none; }
}

/* Скрываем круглые кнопки когда видны превью соседей */
@media (min-width: 1100px) {
    .stories-nav { display: none; }
}

/* Пауза */
.stories-viewer.paused .progress-bar.active .progress-bar-fill {
    animation-play-state: paused;
}