/* عارض الستوري — مطابق لبروفايل المستخدم، فوق الهيدر وشريط الجوال (z-index أعلى من mobile-bottom-nav) */

.story-viewer-overlay {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.95);
    z-index: 1200000000000 !important;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    box-sizing: border-box;
}

/*
 * الغلاف story-viewer-perspective يحمل perspective فقط — لا يُستخدم عليه overflow:hidden
 * لأن ذلك يُسطّح rotateY في Chrome/Safari ويلغي الإحساس ثلاثي الأبعاد.
 * القصّ والزوايا على .story-cube-face الذي يدور.
 */
.story-viewer-perspective {
    position: relative;
    width: 400px;
    height: 700px;
    max-height: 100dvh;
    flex-shrink: 0;
    perspective: 1100px;
    perspective-origin: 50% 45%;
    transform-style: preserve-3d;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.story-viewer-perspective.story-cube-animating {
    overflow: visible;
    z-index: 1;
}

.story-viewer-container {
    position: relative;
    width: 100%;
    height: 100%;
    background: #000;
    border-radius: 15px;
    overflow: visible;
}

/* مكعب ثلاثي الأبعاد — وجه البطاقة الذي يدور */
.story-cube-face {
    position: absolute;
    inset: 0;
    border-radius: 15px;
    overflow: hidden;
    opacity: 1;
    -webkit-transform: translate3d(0, 0, 0.1px);
    transform: translate3d(0, 0, 0.1px);
    transform-origin: 50% 50%;
    transform-style: preserve-3d;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transition:
        transform 0.48s cubic-bezier(0.32, 0.72, 0, 1),
        opacity 0.38s ease;
    -webkit-transition:
        -webkit-transform 0.48s cubic-bezier(0.32, 0.72, 0, 1),
        opacity 0.38s ease;
    will-change: transform;
}

.story-cube-face.cube-exit-next {
    -webkit-transform: rotateY(-88deg) translateZ(-48px);
    transform: rotateY(-88deg) translateZ(-48px);
    opacity: 0.78;
}

.story-cube-face.cube-exit-prev {
    -webkit-transform: rotateY(88deg) translateZ(-48px);
    transform: rotateY(88deg) translateZ(-48px);
    opacity: 0.78;
}

.story-cube-face.story-cube-enter-from-right {
    -webkit-transform: rotateY(88deg) translateZ(-48px);
    transform: rotateY(88deg) translateZ(-48px);
    opacity: 0.92;
}

.story-cube-face.story-cube-enter-from-left {
    -webkit-transform: rotateY(-88deg) translateZ(-48px);
    transform: rotateY(-88deg) translateZ(-48px);
    opacity: 0.92;
}

.story-cube-face.story-cube-ready {
    -webkit-transform: rotateY(0deg) translate3d(0, 0, 0.1px) !important;
    transform: rotateY(0deg) translate3d(0, 0, 0.1px) !important;
    opacity: 1 !important;
}

html[dir='rtl'] .story-cube-face.cube-exit-next {
    -webkit-transform: rotateY(88deg) translateZ(-48px);
    transform: rotateY(88deg) translateZ(-48px);
}

html[dir='rtl'] .story-cube-face.cube-exit-prev {
    -webkit-transform: rotateY(-88deg) translateZ(-48px);
    transform: rotateY(-88deg) translateZ(-48px);
}

html[dir='rtl'] .story-cube-face.story-cube-enter-from-right {
    -webkit-transform: rotateY(-88deg) translateZ(-48px);
    transform: rotateY(-88deg) translateZ(-48px);
}

html[dir='rtl'] .story-cube-face.story-cube-enter-from-left {
    -webkit-transform: rotateY(88deg) translateZ(-48px);
    transform: rotateY(88deg) translateZ(-48px);
}

.story-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 12;
    padding: 15px;
    padding-top: max(15px, env(safe-area-inset-top));
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.75), transparent);
}

.story-progress {
    display: flex;
    gap: 2px;
    margin-bottom: 20px;
}

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

.story-progress-segment.active {
    background: rgba(255, 255, 255, 0.3);
}

.story-progress-segment.active::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    background: #fff;
    width: var(--progress, 0%);
    transition: width 0.1s linear;
}

.story-progress-segment.completed {
    background: #fff;
}

.story-user-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
    width: 100%;
    gap: 8px;
}

a.story-user-details {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    border-radius: 10px;
    padding: 2px 4px;
    margin: -2px -4px;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

a.story-user-details:hover,
a.story-user-details:focus-visible {
    opacity: 0.95;
    background: rgba(255, 255, 255, 0.08);
}

.story-user-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.story-header-link {
    font-size: 11px;
    color: #fcd34d;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.story-header-link:hover {
    color: #fde68a;
    text-decoration: underline;
}

.story-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #fff;
    object-fit: cover;
    flex-shrink: 0;
}

.story-username {
    font-weight: bold;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.story-time {
    font-size: 12px;
    opacity: 0.8;
}

.story-close-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 50%;
    transition: background 0.3s ease;
    position: absolute;
    top: max(12px, env(safe-area-inset-top));
    inset-inline-start: 12px;
    z-index: 20;
}

.story-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.story-options-btn {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.3s ease;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.story-options-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.story-options-modal,
.story-confirm-modal {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 120010 !important;
    display: flex;
    justify-content: center;
    align-items: center;
}

.story-options-content,
.story-confirm-content {
    background: white;
    border-radius: 15px;
    padding: 20px;
    min-width: 300px;
    max-width: 400px;
    text-align: center;
}

.story-confirm-content h3 {
    margin: 0 0 15px 0;
    color: #333;
    font-size: 1.2rem;
}

.story-confirm-content p {
    margin: 0 0 20px 0;
    color: #666;
    line-height: 1.5;
}

.story-option-btn,
.confirm-btn {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 10px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 1rem;
}

.story-option-btn.delete-btn,
.confirm-btn.delete-btn {
    background: #ff4757;
    color: white;
}

.story-option-btn.delete-btn:hover,
.confirm-btn.delete-btn:hover {
    background: #ff3742;
}

.story-option-btn.cancel-btn,
.confirm-btn.cancel-btn {
    background: #f1f2f6;
    color: #333;
}

.story-option-btn.cancel-btn:hover,
.confirm-btn.cancel-btn:hover {
    background: #ddd;
}

.confirm-buttons {
    display: flex;
    gap: 10px;
}

.confirm-buttons .confirm-btn {
    margin-bottom: 0;
}

.story-content {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 0;
}

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

.story-text {
    color: white;
    font-size: 24px;
    text-align: center;
    padding: 20px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    white-space: pre-wrap;
    word-break: break-word;
}

.story-nav-area {
    position: absolute;
    top: 80px;
    bottom: 0;
    width: 50%;
    cursor: pointer;
    z-index: 11;
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

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

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

.story-cta-wrap {
    position: absolute;
    bottom: max(28px, env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    z-index: 15;
    pointer-events: none;
}

.story-cta-wrap .story-cta-btn {
    pointer-events: auto;
}

.story-cta-btn {
    display: inline-block;
    padding: 12px 22px;
    background: rgba(255, 255, 255, 0.95);
    color: #111;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.3);
    max-width: 88%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.story-cta-btn:hover {
    color: #000;
    background: #fff;
}

@media (max-width: 768px) {
    .story-viewer-perspective {
        width: 100%;
        height: 100%;
        max-height: none;
        border-radius: 0;
        box-shadow: none;
    }

    .story-viewer-container {
        border-radius: 0;
    }

    .story-cube-face {
        border-radius: 0;
    }
}
