.stories-bar {
    padding: 4px 0;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
    overflow: hidden;
    transition: padding 0.3s ease;
    flex-shrink: 0;
}

.stories-bar.expanded { padding: 10px 0; }

.stories-scroll {
    display: flex;
    gap: 8px;
    padding: 0 8px;
    overflow-x: auto;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.stories-scroll::-webkit-scrollbar { display: none; }

.story-bubble {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    transition: transform 0.3s ease;
}

.story-avatar-ring {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    padding: 2px;
    position: relative;
    transition: width 0.3s ease, height 0.3s ease;
}

.stories-bar.expanded .story-avatar-ring { width: 48px; height: 48px; }

.story-avatar-ring.has-story {
    background: conic-gradient(#a855f7 var(--story-progress, 0deg), #4a0e4e var(--story-progress, 0deg));
}

.story-avatar-ring.has-story.segment-2 {
    background: conic-gradient(#a855f7 0deg 180deg, #7b2d8e 180deg 360deg);
}

.story-avatar-ring.has-story.segment-3 {
    background: conic-gradient(#a855f7 0deg 120deg, #c084fc 120deg 240deg, #7b2d8e 240deg 360deg);
}

.story-avatar-ring.has-story.segment-4 {
    background: conic-gradient(#a855f7 0deg 90deg, #c084fc 90deg 180deg, #7b2d8e 180deg 270deg, #4a0e4e 270deg 360deg);
}

.story-avatar-ring.has-story.segment-more {
    background: conic-gradient(#a855f7 0deg 72deg, #c084fc 72deg 144deg, #7b2d8e 144deg 216deg, #4a0e4e 216deg 288deg, #9333ea 288deg 360deg);
}

.story-avatar-ring.has-unviewed { animation: story-pulse 2s infinite; }
.story-avatar-ring.viewed { background: var(--border-color); }
.story-avatar-ring.empty { background: var(--border-color); border: 2px dashed var(--text-muted); }

.story-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border: 2px solid var(--bg-primary);
}

.story-avatar img { width: 100%; height: 100%; object-fit: cover; }

.story-name {
    font-size: calc(10px * var(--text-scale, 1));
    color: var(--text-secondary);
    text-align: center;
    max-width: 50px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: opacity 0.3s ease, max-height 0.3s ease;
}

.story-plus {
    position: absolute;
    bottom: 16px;
    right: 1px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    border: 2px solid var(--bg-primary);
    transition: opacity 0.3s ease;
}

.story-viewer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: #000;
    z-index: 20000;
    display: none;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
}

.story-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
}

.story-progress-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}

.story-progress-segment {
    flex: 1;
    height: 2px;
    background: rgba(255,255,255,0.3);
    border-radius: 1px;
    position: relative;
    overflow: hidden;
}

.story-progress-segment.completed { background: #fff; }

.story-progress-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: #fff;
    width: 0%;
}

.story-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.story-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
}

.story-user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.story-user-name { color: #fff; font-weight: 500; font-size: 14px; }
.story-time { color: rgba(255,255,255,0.6); font-size: 12px; }

.story-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 11;
}

.story-delete-btn {
    position: absolute;
    top: 16px;
    right: 56px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 11;
}

.story-reactions {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 11;
    background: rgba(0,0,0,0.5);
    padding: 8px 16px;
    border-radius: 24px;
    backdrop-filter: blur(10px);
}

.story-reactions span {
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.story-reactions span:active { transform: scale(1.3); }

.story-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.story-image { max-width: 100%; max-height: 100%; object-fit: contain; }
.story-video { max-width: 100%; max-height: 100%; object-fit: contain; }

.story-navigation {
    position: absolute;
    top: 60px;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    z-index: 5;
}

.story-nav-left { flex: 1; }
.story-nav-right { flex: 1; }

.media-viewer {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.95);
    z-index: var(--z-media-viewer);
    display: none;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.close-media {
    position: absolute;
    top: 18px;
    right: 18px;
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius-full);
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    border: none;
    transition: background 0.2s ease;
    pointer-events: auto;
}

.close-media:hover { background: rgba(255,255,255,0.2); }

.media-container {
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.media-container img, .media-container video {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 11px;
    box-shadow: var(--shadow-xl);
    object-fit: contain;
    transition: transform 0.3s ease;
    cursor: zoom-in;
}

.media-container img.zoomed { cursor: zoom-out; }

.media-controls {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 14px;
    background: rgba(0,0,0,0.5);
    padding: 11px 18px;
    border-radius: 36px;
    backdrop-filter: blur(10px);
}

.media-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius-full);
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: none;
    transition: background 0.2s ease;
    pointer-events: auto;
}

.media-btn:hover { background: rgba(255,255,255,0.2); }

.circle-record-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.9);
    backdrop-filter: blur(10px);
}

.video-circle-message {
    position: relative;
}

.circle-msg-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(255,255,255,0.2);
    z-index: 2;
}

.circle-msg-progress > div {
    height: 100%;
    background: var(--accent);
    width: 100%;
    transition: width 0.1s linear;
}