/* --- TOP TALES (Redesign V2 - Bubbles) --- */
.popular-tales-card {
    /* Main card container override */
    padding: 20px !important;
    overflow: hidden;
    background: rgba(10, 10, 15, 0.7);
    border: 1px solid rgba(255, 46, 99, 0.2);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
}

.pt-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.pt-title {
    font-family: 'Cinzel', serif;
    font-size: 1.1rem;
    color: #fff;
    letter-spacing: 1px;
    margin: 0;
    text-shadow: 0 0 10px rgba(255, 46, 99, 0.4);
}

#top-night-tales-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    /* 2 columns */
    gap: 12px;
    width: 100%;
}

/* Make the 5th item span full width to create a 2-2-1 layout */
#top-night-tales-list .tale-bubble:nth-child(5) {
    grid-column: span 2;
}

/* Bubble Item */
.tale-bubble {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 140px;
    /* Fixed height for uniformity */
    border-radius: 20px;
    overflow: hidden;
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.05);
    /* Subtle border initially */
    background: #000;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);

    /* Animation entry */
    opacity: 0;
    animation: fadeInUp 0.5s forwards;
    animation-delay: var(--delay, 0s);
    cursor: pointer;
}

.tale-bubble:hover {
    transform: translateY(-4px);
    border-color: var(--primary-neon, #ff2e63);
    box-shadow: 0 8px 25px rgba(255, 46, 99, 0.25);
    z-index: 2;
}

/* Image Container */
.bubble-img-container {
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
}

.bubble-img-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s ease;
}

.tale-bubble:hover .bubble-img-container img {
    transform: scale(1.1);
}

.bubble-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom,
            rgba(0, 0, 0, 0) 0%,
            rgba(0, 0, 0, 0.3) 50%,
            rgba(0, 0, 0, 0.95) 100%);
    z-index: 1;
}

/* Content */
.bubble-content {
    position: relative;
    z-index: 2;
    margin-top: auto;
    /* Push to bottom */
    padding: 12px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.bubble-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.bubble-tag {
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid var(--tag-color);
    color: var(--tag-color);
    padding: 2px 6px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.bubble-views {
    color: #ffd700;
    font-weight: 600;
    font-size: 0.7rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 1);
}

.bubble-title {
    color: #fff;
    margin: 0;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.2;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 1);

    /* Truncate if too long */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Loading Spinner */
.loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary-neon, #ff2e63);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 40px auto;
}

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

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile Optimization */
@media (max-width: 600px) {
    #top-night-tales-list {
        display: flex;
        /* Horizontal Scroll */
        overflow-x: auto;
        padding-bottom: 20px;
        scroll-snap-type: x mandatory;
        grid-template-columns: none;
        /* Reset grid */
        margin-left: -20px;
        /* Bleed out slightly */
        width: calc(100% + 40px);
        padding-left: 20px;
        padding-right: 20px;
    }

    .tale-bubble {
        min-width: 130px;
        width: 130px;
        height: 170px;
        /* Taller on mobile */
        scroll-snap-align: start;
        flex-shrink: 0;
    }

    /* Hide 5th item special span on mobile */
    #top-night-tales-list .tale-bubble:nth-child(5) {
        grid-column: auto;
    }

    /* Scrollbar styling */
    #top-night-tales-list::-webkit-scrollbar {
        height: 4px;
    }

    #top-night-tales-list::-webkit-scrollbar-thumb {
        background: var(--primary-neon, #ff2e63);
        border-radius: 4px;
    }

    .popular-tales-card {
        padding: 15px !important;
    }
}

/* =========================================
   TOP 5 BANNER RELOCATION STYLES
   ========================================= */

/* The Section Container */
.top5-banner-section {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: 60px;
    padding: 0 20px;
    position: relative;
    z-index: 10;
}

/* Override Card for Banner Mode */
.top5-banner-section .popular-tales-card {
    width: 100%;
    max-width: 1200px;
    /* Banner Width */
    height: auto;
    min-height: 250px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    /* Enhanced shadow for banner */
}

/* CTA Adjustment */
.top5-banner-section .feature-cta {
    margin-top: 25px !important;
    width: 100%;
    text-align: center;
    display: block;
}

/* DESKTOP LAYOUT (5 Columns) */
@media (min-width: 1024px) {
    .top5-banner-section #top-night-tales-list {
        display: grid;
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 20px;
        width: 100%;
    }

    /* Reset the span for the 5th item */
    .top5-banner-section #top-night-tales-list .tale-bubble:nth-child(5) {
        grid-column: auto !important;
    }

    /* Adjust bubble height for banner look if needed */
    .top5-banner-section .tale-bubble {
        height: 160px;
        /* Slightly taller for impact */
    }
}

/* MOBILE ADJUSTMENTS */
@media (max-width: 768px) {
    .top5-banner-section {
        margin-top: 40px;
        padding: 0 15px;
    }

    .top5-banner-section .popular-tales-card {
        max-width: 100%;
    }
}

/* =========================================
   P0 HOTFIX: STRICT RESTORATION STYLES
   Scoped by data-section="top5-night-tales-banner"
   ========================================= */

/* Desktop Grid: 5 Columns, Compact */
[data-section="top5-night-tales-banner"] .top5-cards {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
    width: 100%;
    padding: 10px 0;
}

/* Card Styling */
[data-section="top5-night-tales-banner"] .top5-card {
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    overflow: hidden;
    text-decoration: none;
    transition: transform 0.2s, border-color 0.2s;
    height: 100%;
    min-height: 200px;
}

[data-section="top5-night-tales-banner"] .top5-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary-neon, #ff2e63);
}

/* Thumbnail */
[data-section="top5-night-tales-banner"] .top5-thumb {
    width: 100%;
    height: 132px;
    object-fit: cover;
    display: block;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* Meta Data */
[data-section="top5-night-tales-banner"] .top5-meta {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

[data-section="top5-night-tales-banner"] .top5-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.7rem;
}

[data-section="top5-night-tales-banner"] .top5-tag {
    color: var(--tag-color, #ff2e63);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

[data-section="top5-night-tales-banner"] .top5-views {
    color: #ffd700;
    font-weight: 600;
}

[data-section="top5-night-tales-banner"] .top5-name {
    color: #fff;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.3;
    margin-top: 2px;
    /* Limit to 2 lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Mobile: Horizontal Scroller (No Vertical Stack) */
@media (max-width: 900px) {
    [data-section="top5-night-tales-banner"] .top5-cards {
        display: flex;
        grid-template-columns: none;
        overflow-x: auto;
        gap: 12px;
        scroll-snap-type: x mandatory;
        padding-bottom: 15px;
        /* Scrollbar space */
    }

    [data-section="top5-night-tales-banner"] .top5-card {
        min-width: 220px;
        width: 220px;
        scroll-snap-align: start;
        flex-shrink: 0;
    }
}