/* ============================================
   Community Feed Page
   Phase 2: Community Features
   ============================================ */

.community-page {
    min-height: 80vh;
    padding: 24px 16px 60px;
    padding-top: 110px;
}

.community-container {
    max-width: 1240px;
    margin: 0 auto;
}

/* Layout: sticky filter sidebar + feed (+ optional discovery rail on wide screens) */
.community-layout {
    display: grid;
    grid-template-columns: 220px minmax(0, 560px);
    gap: 32px;
    align-items: start;
    justify-content: center;
}

.community-sidebar {
    position: sticky;
    top: 84px;
    align-self: start;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    /* Hide the scrollbar — the rail still scrolls when content is tall */
    scrollbar-width: none;
}
.community-sidebar::-webkit-scrollbar {
    display: none;
}

.community-feed-main {
    min-width: 0;
}

/* ── Discovery rail (right column) ──
   Hidden by default; only revealed as a 3rd column on wide screens once JS has
   populated it (.has-discovery). Keeps phones / tablets at the clean 2-col view. */
.community-discovery {
    display: none;
}

@media (min-width: 1180px) {
    /* Equal flexible side columns keep the 560px feed centered on the page,
       with the filter sidebar and discovery rail hugging it on either side. */
    .community-layout.has-discovery {
        grid-template-columns: minmax(0, 1fr) minmax(0, 560px) minmax(0, 1fr);
    }
    .community-layout.has-discovery .community-sidebar {
        justify-self: end;
        width: 220px;
    }
    .community-layout.has-discovery .community-discovery {
        display: block;
        position: sticky;
        top: 84px;
        align-self: start;
        justify-self: start;
        width: 300px;
        max-height: calc(100vh - 100px);
        overflow-y: auto;
        scrollbar-width: none;
    }
    .community-layout.has-discovery .community-discovery::-webkit-scrollbar {
        display: none;
    }
}

/* ── Desktop app: show the rail and center the feed in the app window ──
   The desktop webview is typically ~1000–1180px wide (below the web 1180px
   breakpoint), so it gets its own fitted, group-centered 3-column layout with
   symmetric side columns — keeping the feed dead-centre. Hidden below 1000px
   to avoid horizontal overflow in a small window. Wider windows (≥1180px) fall
   through to the standard web rule above. */
@media (min-width: 1000px) and (max-width: 1179px) {
    body.desktop-app-mode .community-layout.has-discovery {
        grid-template-columns: 210px minmax(0, 540px) 210px;
        column-gap: 20px;
        justify-content: center;
    }
    body.desktop-app-mode .community-layout.has-discovery .community-discovery {
        display: block;
        position: sticky;
        top: 16px;
        align-self: start;
        justify-self: start;
        width: 210px;
        max-height: calc(100vh - 32px);
        overflow-y: auto;
        scrollbar-width: none;
    }
    body.desktop-app-mode .community-layout.has-discovery .community-discovery::-webkit-scrollbar {
        display: none;
    }
    /* Keep the left filter column symmetric with the rail in app mode */
    body.desktop-app-mode .community-layout.has-discovery .community-sidebar {
        top: 16px;
        max-height: calc(100vh - 32px);
    }
}

@media (max-width: 999px) {
    body.desktop-app-mode .community-discovery {
        display: none;
    }
}

/* Discovery widget card — shares the feed card's visual language */
.discovery-widget {
    background: var(--bg-secondary, rgba(255,255,255,0.04));
    border: 1px solid var(--border-color, rgba(255,255,255,0.08));
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 16px;
}

.discovery-widget-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0 0 12px;
}

/* Top-rated book row */
.discovery-book {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.discovery-book + .discovery-book {
    border-top: 1px solid var(--border-color, rgba(255,255,255,0.06));
}

.discovery-book-cover {
    width: 36px;
    height: 52px;
    flex-shrink: 0;
    object-fit: cover;
    border-radius: 5px;
    background: var(--bg-tertiary, rgba(255,255,255,0.06));
}

.discovery-book-info {
    min-width: 0;
    flex: 1;
}

.discovery-book-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary, #e8e6e1);
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.discovery-book-meta {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 3px;
    font-size: 0.72rem;
    color: var(--text-secondary, #94a3b8);
}

.discovery-book-rating {
    color: #f5b301;
    font-weight: 600;
    white-space: nowrap;
}

.discovery-book-count {
    color: var(--text-muted, #64748b);
    white-space: nowrap;
}

/* Suggested reader row */
.discovery-reader {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
}

.discovery-reader + .discovery-reader {
    border-top: 1px solid var(--border-color, rgba(255,255,255,0.06));
}

.discovery-reader-link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
    text-decoration: none;
    color: inherit;
}

.discovery-reader-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: rgba(99, 102, 241, 0.15);
}

.discovery-reader-avatar-initial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 600;
    color: #a5b4fc;
}

.discovery-reader-info {
    min-width: 0;
    flex: 1;
}

.discovery-reader-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary, #e8e6e1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.discovery-reader-followers {
    font-size: 0.72rem;
    color: var(--text-muted, #64748b);
    margin-top: 1px;
}

.discovery-reader-follow {
    flex-shrink: 0;
    padding: 5px 12px;
    border-radius: 999px;
    border: 1px solid rgba(99, 102, 241, 0.4);
    background: transparent;
    color: #a5b4fc;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.18s;
}

.discovery-reader-follow:hover {
    background: rgba(99, 102, 241, 0.12);
}

.discovery-reader-follow.following {
    border-color: var(--border-color, rgba(255,255,255,0.12));
    color: var(--text-secondary, #94a3b8);
}

.discovery-reader-follow:disabled {
    opacity: 0.6;
    cursor: default;
}

[dir="rtl"] .discovery-widget-title {
    letter-spacing: 0;
}


/* Header */
.community-header {
    text-align: center;
    margin-bottom: 28px;
    margin-top: 24px;
}

.community-title {
    font-size: clamp(1.75rem, 3.5vw, 2.25rem);
    font-weight: 700;
    color: var(--text-primary, #fff);
    margin-bottom: 6px;
}

.community-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary, #94a3b8);
}

/* Filter Tabs — vertical sidebar list */
.community-filters {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 0;
}

.community-filter {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 16px;
    background: var(--bg-secondary, rgba(255,255,255,0.04));
    border: 1px solid var(--border-color, rgba(255,255,255,0.1));
    border-radius: 12px;
    color: var(--text-secondary, #94a3b8);
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

[dir="rtl"] .community-filter {
    text-align: right;
}

.community-filter:hover {
    background: rgba(99, 102, 241, 0.08);
    border-color: rgba(99, 102, 241, 0.3);
}

.community-filter.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.4);
    color: #a5b4fc;
}

/* Feed Grid — single column for social feed UX */
.community-grid {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 560px;
    margin: 0 auto;
}

/* Feed Card */
.feed-card {
    background: var(--bg-secondary, #1a1a2e);
    border: 1px solid var(--border-color, rgba(255,255,255,0.08));
    border-radius: 14px;
    transition: transform 0.2s, box-shadow 0.2s;
}

/* Repost Indicator */
.feed-card-repost-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px 4px;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted, #64748b);
}

.feed-card-repost-indicator svg {
    width: 14px;
    height: 14px;
    color: #22c55e;
    flex-shrink: 0;
}

.feed-card-repost-indicator span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.feed-card-repost-avatar {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.feed-card-repost-avatars {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.feed-card-repost-avatar-stacked {
    margin-left: -6px;
    border: 1.5px solid var(--bg-card, #fff);
}

.feed-card-repost-avatar-stacked:first-child {
    margin-left: 0;
}

.feed-card-repost-avatar-initial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-size: 0.55rem;
    font-weight: 700;
}

.feed-card-repost-name {
    color: var(--text-secondary, #94a3b8);
    text-decoration: none;
    font-weight: 600;
    white-space: nowrap;
}

.feed-card-repost-name:hover {
    color: #a5b4fc;
    text-decoration: underline;
}

.feed-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.feed-card-thumbnail {
    width: 100%;
    aspect-ratio: 4/5;
    object-fit: cover;
    display: block;
    background: var(--bg-tertiary, #0f0f1a);
    /* Blur-up: start blurred, fade to sharp on load */
    filter: blur(8px);
    transform: scale(1.02);
    transition: filter 0.4s ease, transform 0.4s ease;
}
.feed-card-thumbnail.loaded {
    filter: blur(0);
    transform: scale(1);
}

/* Skeleton shimmer while image loads */
.feed-card-thumbnail-wrap {
    position: relative;
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
    border-radius: 14px 14px 0 0;
    background: linear-gradient(90deg,
        var(--bg-tertiary, #1a1a2e) 25%,
        var(--bg-secondary, #252540) 50%,
        var(--bg-tertiary, #1a1a2e) 75%
    );
    background-size: 200% 100%;
    animation: feed-skeleton-pulse 1.5s ease-in-out infinite;
}
.feed-card-thumbnail-wrap:has(.loaded) {
    animation: none;
    background: none;
}
@keyframes feed-skeleton-pulse {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.feed-card-thumbnail.presentation {
    aspect-ratio: 3/4;
}

.feed-card-thumbnail.portrait {
    aspect-ratio: 3/4;
    max-height: 300px;
}

.feed-card-body {
    padding: 14px 16px;
}

.feed-card-user {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.feed-card-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.feed-card-avatar-img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-secondary, #1e293b);
}

.feed-card-username {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary, #e2e8f0);
    text-decoration: none;
}

.feed-card-username:hover {
    color: #a5b4fc;
}

.feed-card-time {
    font-size: 0.7rem;
    color: var(--text-muted, #64748b);
    margin-left: auto;
}

[dir="rtl"] .feed-card-time {
    margin-left: 0;
    margin-right: auto;
}

/* Follow button */
.feed-card-follow {
    padding: 3px 10px;
    background: transparent;
    border: 1px solid rgba(99, 102, 241, 0.4);
    border-radius: 12px;
    color: #a5b4fc;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.feed-card-follow:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: #6366f1;
}

.feed-card-follow.following {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.4);
    color: #6ee7b7;
}

.feed-card-follow.following:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.4);
    color: #fca5a5;
}

.feed-card-follow:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.feed-card-caption {
    font-size: 0.82rem;
    color: var(--text-secondary, #94a3b8);
    line-height: 1.5;
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* For rating cards: show full review text without truncation */
.feed-card-rating + .feed-card-caption {
    -webkit-line-clamp: unset;
    display: block;
}

a.feed-card-caption-link {
    text-decoration: none;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

a.feed-card-caption-link:hover {
    color: #a5b4fc;
}

.feed-card-book {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted, #64748b);
    margin-bottom: 10px;
}

.feed-card-book a {
    color: #818cf8;
    text-decoration: none;
}

.feed-card-book a:hover {
    text-decoration: underline;
}

/* Book cover in rating cards */
.feed-card-book-cover-link {
    display: block;
    margin-bottom: 10px;
    border-radius: 8px;
    overflow: hidden;
}

.feed-card-book-cover {
    width: 100%;
    height: auto;
    max-height: 160px;
    object-fit: cover;
    display: block;
    border-radius: 8px;
    transition: transform 0.2s;
}

.feed-card-book-cover-link:hover .feed-card-book-cover {
    transform: scale(1.02);
}

/* Rating display in card */
.feed-card-rating {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.feed-card-stars {
    display: flex;
    gap: 1px;
}

.feed-card-stars svg {
    width: 14px;
    height: 14px;
    fill: #fbbf24;
}

.feed-card-stars svg.empty {
    fill: var(--text-muted, #4a5568);
}

.feed-card-reactions {
    display: flex;
    gap: 3px;
    font-size: 0.9rem;
}

/* Card Actions */
.feed-card-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color, rgba(255,255,255,0.06));
}

.feed-card-action {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: none;
    color: var(--text-muted, #64748b);
    font-size: 0.78rem;
    cursor: pointer;
    padding: 4px 0;
    transition: color 0.2s;
}

.feed-card-action:hover {
    color: var(--text-primary, #e2e8f0);
}

.feed-card-action.liked {
    color: #ef4444;
}

.feed-card-action svg {
    width: 16px;
    height: 16px;
}

.feed-card-remove {
    margin-left: auto;
    color: var(--text-muted, #64748b);
    opacity: 0.6;
    transition: color 0.2s, opacity 0.2s;
}
.feed-card-remove:hover {
    color: #ef4444;
    opacity: 1;
}

/* Share button */
.feed-card-share:hover {
    color: #3b82f6;
}

/* Repost button */
.feed-card-repost:hover {
    color: #22c55e;
}
.feed-card-repost.reposted {
    color: #22c55e;
}

/* Share Menu Dropdown */
.feed-share-menu {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: var(--bg-primary, #1e293b);
    border: 1px solid var(--border-color, rgba(255,255,255,0.12));
    border-radius: 12px;
    padding: 8px;
    display: flex;
    gap: 4px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 100;
    animation: shareMenuIn 0.2s ease;
    white-space: nowrap;
}

@keyframes shareMenuIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.feed-share-option {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary, #94a3b8);
    text-decoration: none;
    border: none;
    background: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.feed-share-option:hover {
    background: var(--bg-secondary, rgba(255,255,255,0.06));
    color: var(--text-primary, #e2e8f0);
}
.feed-share-option svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Type badge */
.feed-card-type {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 3px 8px;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    border-radius: 8px;
    font-size: 0.68rem;
    color: #e2e8f0;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

[dir="rtl"] .feed-card-type {
    right: auto;
    left: 10px;
}

/* feed-card-thumbnail-wrap moved up to loading optimization section */

.feed-card-thumbnail-wrap img {
    pointer-events: none;
}

/* Loading */
.community-loading {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    padding: 40px;
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color, rgba(255,255,255,0.1));
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Load More */
.community-load-more {
    text-align: center;
    margin-top: 24px;
}

/* Empty State */
.community-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
}

.community-empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.community-empty h3 {
    font-size: 1.1rem;
    color: var(--text-primary, #e2e8f0);
    margin-bottom: 8px;
}

.community-empty p {
    font-size: 0.85rem;
    color: var(--text-muted, #64748b);
}

/* Responsive */
@media (max-width: 860px) {
    /* Trim the large top spacing on mobile */
    .community-page {
        padding-top: 76px;
    }

    .community-header {
        margin-top: 4px;
        margin-bottom: 16px;
    }

    /* Collapse sidebar into a full-width sticky filter bar pinned to the top */
    .community-layout {
        display: block;
    }

    .community-sidebar {
        position: sticky;
        top: 0;
        z-index: 20;
        margin: 0 -16px 16px;
        padding: 10px 16px;
        /* Match the page background (body:has(.nav-transparent) uses --bg-secondary) */
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border-color, rgba(255,255,255,0.08));
    }

    .community-filters {
        flex-direction: row;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
    }

    .community-filter {
        width: auto;
        flex: 0 0 auto;
        border-radius: 20px;
        padding: 8px 16px;
    }
}

@media (max-width: 600px) {
    .community-title {
        font-size: 1.4rem;
    }

    .community-filters {
        gap: 6px;
    }

    .community-filter {
        padding: 6px 12px;
        font-size: 0.78rem;
    }
}


/* ============================================
   Lightbox — Full-screen image viewer
   ============================================ */

.community-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.community-lightbox.active {
    opacity: 1;
    pointer-events: all;
}

.community-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.community-lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    animation: lightbox-scale-in 0.2s ease;
}

@keyframes lightbox-scale-in {
    from { transform: scale(0.92); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.community-lightbox-img {
    max-width: 90vw;
    max-height: 80vh;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

.community-lightbox-close {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 1;
}

.community-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.community-lightbox-actions {
    display: flex;
    gap: 12px;
}

.community-lightbox-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s;
}

.community-lightbox-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}

.community-lightbox-read {
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    border-color: rgba(99, 102, 241, 0.5);
}

.community-lightbox-read:hover {
    background: linear-gradient(135deg, #4338ca, #4f46e5);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
}

@media (max-width: 600px) {
    .community-lightbox-img {
        max-width: 95vw;
        max-height: 75vh;
        border-radius: 8px;
    }

    .community-lightbox-close {
        top: -8px;
        right: -4px;
    }
}



/* Story/Audio Modal Overlay — Fullscreen Takeover */
.community-story-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.25s ease;
    /* Prevent ANY overscroll that could trigger browser chrome */
    overscroll-behavior: none;
    overflow: hidden;
    touch-action: manipulation;
}
.community-story-modal.active {
    opacity: 1;
}
.community-story-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
}
.community-story-modal-container {
    position: relative;
    width: 94vw;
    height: 92vh;
    height: 92dvh;
    max-width: 1100px;
    border-radius: 16px;
    overflow: hidden;
    background: #1a1a2e;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    /* Prevent internal overscroll from propagating */
    overscroll-behavior: contain;
}
.community-story-modal-header {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: rgba(15, 15, 26, 0.95);
    border-bottom: 1px solid rgba(99, 102, 241, 0.2);
    flex-shrink: 0;
}
.community-story-modal-close {
    background: none;
    border: none;
    color: #e2e8f0;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    margin-inline-start: auto; /* Right in LTR, left in RTL */
}
.community-story-modal-close:hover {
    background: rgba(255, 255, 255, 0.1);
}
.community-story-modal-external {
    color: #818cf8;
    padding: 6px;
    border-radius: 8px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
}
.community-story-modal-external:hover {
    background: rgba(99, 102, 241, 0.15);
}
.community-story-modal-iframe {
    flex: 1;
    width: 100%;
    border: none;
    /* Allow iframe content to scroll internally but not propagate */
    overscroll-behavior: contain;
}

@media (max-width: 600px) {
    .community-story-modal {
        /* On mobile: fill the entire viewport, sit OVER browser chrome */
        padding: 0;
        /* Use 100vh intentionally to extend behind browser nav bar */
        height: 100vh;
        height: 100dvh;
        height: -webkit-fill-available;
    }
    .community-story-modal-container {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        height: -webkit-fill-available;
        max-height: none;
        border-radius: 0;
        margin: 0;
        /* Ensure it covers everything — no gap under browser bar */
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    .community-story-modal-header {
        padding: 12px 16px;
        min-height: 48px;
        padding-top: calc(12px + env(safe-area-inset-top, 0));
        position: sticky;
        top: 0;
        z-index: 10;
    }
}

/* Body lock class applied when modal is open */
body.community-modal-open {
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: none;
}

/* Ensure html element also locks */
html.community-modal-open {
    overflow: hidden;
    overscroll-behavior: none;
}

/* ============================================
   Inline Presentation Embed (iframe in feed card)
   ============================================ */

.feed-card-presentation-embed {
    position: relative;
    width: 100%;
    aspect-ratio: 2/3;
    overflow: hidden;
    background: #0f172a;
    border-radius: 14px 14px 0 0;
}

.feed-card-presentation-iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    pointer-events: none;
}

.feed-card-presentation-overlay {
    position: absolute;
    inset: 0;
    z-index: 2;
}

.feed-card-presentation-overlay::after {
    content: '';
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='15 3 21 3 21 9'/%3E%3Cpolyline points='9 21 3 21 3 15'/%3E%3Cline x1='21' y1='3' x2='14' y2='10'/%3E%3Cline x1='3' y1='21' x2='10' y2='14'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 16px 16px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.feed-card-thumbnail-wrap:hover .feed-card-presentation-overlay::after {
    opacity: 1;
}

[dir="rtl"] .feed-card-presentation-overlay::after {
    right: auto;
    left: 12px;
}


/* ============================================
   Feed Comments — Phase 3
   ============================================ */

/* Comment button */
.feed-card-comment:hover {
    color: #6366f1;
}

/* Comments Section */
.feed-card-comments-section {
    padding: 0 16px 14px;
    border-top: 1px solid var(--border-color, rgba(255,255,255,0.06));
    margin-top: 8px;
}

.feed-card-comments-list {
    padding-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.feed-card-comments-empty {
    font-size: 0.78rem;
    color: var(--text-muted, #64748b);
    text-align: center;
    padding: 8px 0;
}

/* Individual Comment */
.feed-comment {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.feed-comment-header {
    display: flex;
    align-items: center;
    gap: 6px;
}

.feed-comment-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.feed-comment-avatar-initial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    flex-shrink: 0;
}

.feed-comment-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary, #e2e8f0);
    text-decoration: none;
}

.feed-comment-name:hover {
    color: #a5b4fc;
}

.feed-comment-time {
    font-size: 0.65rem;
    color: var(--text-muted, #64748b);
    margin-left: auto;
}

[dir="rtl"] .feed-comment-time {
    margin-left: 0;
    margin-right: auto;
}

.feed-comment-delete {
    background: none;
    border: none;
    color: var(--text-muted, #64748b);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
}

.feed-comment:hover > .feed-comment-header > .feed-comment-delete,
.feed-comment-reply:hover > .feed-comment-header > .feed-comment-delete {
    opacity: 1;
}

.feed-comment-delete:hover {
    color: #ef4444;
}

.feed-comment-content {
    font-size: 0.8rem;
    color: var(--text-secondary, #cbd5e1);
    line-height: 1.5;
    padding-left: 28px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

[dir="rtl"] .feed-comment-content {
    padding-left: 0;
    padding-right: 28px;
}

.feed-comment-footer {
    padding-left: 28px;
}

[dir="rtl"] .feed-comment-footer {
    padding-left: 0;
    padding-right: 28px;
}

.feed-comment-reply-btn {
    background: none;
    border: none;
    color: var(--text-muted, #64748b);
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    padding: 2px 0;
    transition: color 0.2s;
}

.feed-comment-reply-btn:hover {
    color: #a5b4fc;
}

/* Replies */
.feed-comment-replies {
    margin-left: 28px;
    padding-left: 12px;
    border-left: 2px solid var(--border-color, rgba(255,255,255,0.08));
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

[dir="rtl"] .feed-comment-replies {
    margin-left: 0;
    margin-right: 28px;
    padding-left: 0;
    padding-right: 12px;
    border-left: none;
    border-right: 2px solid var(--border-color, rgba(255,255,255,0.08));
}

.feed-comment-reply .feed-comment-avatar {
    width: 18px;
    height: 18px;
}

.feed-comment-reply .feed-comment-avatar-initial {
    width: 18px;
    height: 18px;
    font-size: 0.5rem;
}

.feed-comment-reply .feed-comment-content {
    padding-left: 24px;
    font-size: 0.78rem;
}

[dir="rtl"] .feed-comment-reply .feed-comment-content {
    padding-left: 0;
    padding-right: 24px;
}

/* Reply form (inline) */
.feed-comment-reply-form {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 28px;
    margin-top: 6px;
    padding-left: 12px;
}

[dir="rtl"] .feed-comment-reply-form {
    margin-left: 0;
    margin-right: 28px;
    padding-left: 0;
    padding-right: 12px;
}

/* Comment Form */
.feed-card-comment-form {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color, rgba(255,255,255,0.06));
}

.feed-card-comment-input {
    flex: 1;
    background: var(--bg-tertiary, rgba(255,255,255,0.04));
    border: 1px solid var(--border-color, rgba(255,255,255,0.1));
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 0.8rem;
    color: var(--text-primary, #e2e8f0);
    outline: none;
    transition: border-color 0.2s;
}

.feed-card-comment-input::placeholder {
    color: var(--text-muted, #64748b);
}

.feed-card-comment-input:focus {
    border-color: rgba(99, 102, 241, 0.4);
}

.feed-card-comment-submit {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.2s;
}

.feed-card-comment-submit:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: scale(0.9);
}

.feed-card-comment-submit:not(:disabled):hover {
    transform: scale(1.05);
}

.feed-card-comment-submit svg {
    width: 14px;
    height: 14px;
}

/* Load more comments button */
.feed-card-comments-more {
    text-align: center;
    padding-top: 8px;
}

.feed-card-comments-load-more {
    background: none;
    border: none;
    color: #818cf8;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.feed-card-comments-load-more:hover {
    background: rgba(99, 102, 241, 0.1);
}

/* Mobile responsive adjustments */
@media (max-width: 600px) {
    .feed-card-comments-section {
        padding: 0 12px 12px;
    }

    .feed-comment-content {
        font-size: 0.78rem;
    }

    .feed-comment-replies {
        margin-left: 20px;
        padding-left: 8px;
    }

    [dir="rtl"] .feed-comment-replies {
        margin-left: 0;
        margin-right: 20px;
        padding-left: 0;
        padding-right: 8px;
    }

    .feed-comment-reply-form {
        margin-left: 20px;
        padding-left: 8px;
    }

    [dir="rtl"] .feed-comment-reply-form {
        margin-left: 0;
        margin-right: 20px;
        padding-left: 0;
        padding-right: 8px;
    }
}

/* ============================================================
   COMMUNITY PAGE PRELOADER
   Full-page branded loader — the book logo "fills up" with the
   brand gradient — shown until the feed's first batch is ready,
   then fades out to reveal the fully populated page.
   ============================================================ */
.community-preloader {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: var(--bg-primary, #0f172a);
    opacity: 1;
    transition: opacity 0.5s ease;
}
.community-preloader.is-hidden {
    opacity: 0;
    pointer-events: none;
}

/* A book silhouette (inline SVG, guaranteed transparent) is used as a mask;
   the brand gradient fill rises inside it while the empty shape stays visible. */
.community-loader-logo {
    position: relative;
    width: 88px;
    height: 88px;
    /* Visible "empty" book so the shape always reads, even before the fill */
    background: rgba(148, 163, 184, 0.4);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M12 6.2C10.2 5 7.7 4.4 5.4 4.4c-1.2 0-2.4.2-3.4.5v13.9c1-.3 2.2-.5 3.4-.5 2.3 0 4.8.6 6.6 1.8V6.2zm0 0C13.8 5 16.3 4.4 18.6 4.4c1.2 0 2.4.2 3.4.5v13.9c-1-.3-2.2-.5-3.4-.5-2.3 0-4.8.6-6.6 1.8V6.2z'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M12 6.2C10.2 5 7.7 4.4 5.4 4.4c-1.2 0-2.4.2-3.4.5v13.9c1-.3 2.2-.5 3.4-.5 2.3 0 4.8.6 6.6 1.8V6.2zm0 0C13.8 5 16.3 4.4 18.6 4.4c1.2 0 2.4.2 3.4.5v13.9c-1-.3-2.2-.5-3.4-.5-2.3 0-4.8.6-6.6 1.8V6.2z'/%3E%3C/svg%3E") center / contain no-repeat;
    filter: drop-shadow(0 6px 22px rgba(99, 102, 241, 0.4));
    animation: communityLoaderPulse 1.6s ease-in-out infinite;
}
.community-loader-logo::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 0;
    background: linear-gradient(180deg, #8b5cf6 0%, #6366f1 100%);
    animation: communityLoaderFill 1.8s ease-in-out infinite;
}
@keyframes communityLoaderFill {
    0%, 100% { height: 0; }
    50%      { height: 100%; }
}
@keyframes communityLoaderPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.05); }
}

.community-loader-text {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: var(--text-secondary, #94a3b8);
}
.community-loader-dots::after {
    content: '';
    animation: communityLoaderDots 1.4s steps(4, end) infinite;
}
@keyframes communityLoaderDots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
    100% { content: ''; }
}

@media (prefers-reduced-motion: reduce) {
    .community-loader-logo,
    .community-loader-logo::after,
    .community-loader-dots::after {
        animation-duration: 0.001s;
    }
    .community-loader-logo::after { height: 100%; }
}
