/* Featured story flip-card — shared component used on the home page and
   the stories listing page (templates/partials/featured_card.html).
   Keep this file as the single source of truth: fixing something here
   fixes it everywhere the card is used. */

.stories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 2rem;
    padding: 0 2rem;
}

.featured-card {
    position: relative;
    /* Don't let the grid stretch this to match a taller sibling row —
       height comes from the front face's content (the image) alone. */
    align-self: start;
}

/* Flip mechanism: tapping the card flips it via a scaleX + opacity
   crossfade (not a 3D rotateY/backface-visibility flip, which broke on
   Telegram's WebView). The front is a plain div — clicking it flips to
   the back. The back is a real <a> to the story, so once flipped,
   tapping it (or the Explore Story button inside it) navigates. Nothing
   here depends on the animation succeeding to reach the story.

   Height: at rest, .story-flip has no explicit height, so it's sized by
   its only in-flow child (the front face — the back face is positioned
   absolutely and doesn't count). When flipped, JS measures each face's
   real content height and animates .story-flip between those two exact
   pixel values, so the front stays snug to the image and the back always
   gets exactly the room its description/button need — on any screen
   size, since it's measured, not guessed. */
.story-flip {
    position: relative;
    transition: height 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

.story-face {
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    border-radius: 20px;
    overflow: hidden;
    background: #ffffff;
    border: 2px solid rgba(195, 135, 163, 0.1);
    box-shadow: 0 8px 32px rgba(195, 135, 163, 0.1);
    transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease, box-shadow 0.3s ease;
}

.story-face-front {
    transform: scaleX(1);
    opacity: 1;
    z-index: 2;
    cursor: pointer;
}

.story-face-front:hover {
    transform: scaleX(1) translateY(-6px);
    box-shadow: 0 16px 40px rgba(195, 135, 163, 0.2);
}

.story-flip.flipped .story-face-front {
    transform: scaleX(0);
    opacity: 0;
    pointer-events: none;
}

.story-face-back {
    position: absolute;
    inset: 0;
    transform: scaleX(0);
    opacity: 0;
    z-index: 1;
    pointer-events: none;
    text-align: center;
    cursor: pointer;
}

.story-face-back .featured-info {
    justify-content: center;
}

.story-flip.flipped .story-face-back {
    transform: scaleX(1);
    opacity: 1;
    z-index: 2;
    pointer-events: auto;
}

.story-flip.flipped .story-face-back:hover {
    transform: scaleX(1) translateY(-6px);
    box-shadow: 0 16px 40px rgba(195, 135, 163, 0.2);
}

.featured-cover {
    position: relative;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    flex-shrink: 0;
}

.featured-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.story-face-front:hover .featured-cover img {
    transform: scale(1.1);
}

.story-placeholder {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(195, 135, 163, 0.1), rgba(180, 49, 106, 0.1));
    display: flex;
    align-items: center;
    justify-content: center;
}

.placeholder-icon {
    font-size: 4rem;
    opacity: 0.6;
}

.cover-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.45) 0%, transparent 22%, transparent 70%, rgba(0, 0, 0, 0.6) 100%);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.cover-badges {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    padding: 0.6rem 0.75rem;
}

.episode-count {
    background: rgba(255, 255, 255, 0.92);
    padding: 0.1rem 0.3rem;
    border-radius: 12px;
    text-align: center;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 0.55rem;
    min-width: fit-content;
    max-width: 60px;
    margin-inline-start: auto;
}

.count-number {
    display: block;
    font-size: 0.6rem;
}

.count-text {
    display: block;
    font-size: 0.5rem;
    opacity: 0.8;
}

.featured-info {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    flex: 1;
    text-align: center;
}

.release-date, .story-category, .story-status {
    background: rgba(255, 255, 255, 0.92);
    color: var(--text-primary);
    padding: 0.2rem 0.6rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.story-status-ongoing {
    background: rgba(59, 130, 246, 0.92);
    color: #ffffff;
}

.story-status-completed {
    background: rgba(34, 197, 94, 0.92);
    color: #ffffff;
}

.story-description {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

/* Dhivehi descriptions (RTL) */
.story-description-dv,
.story-description-legacy {
    font-family: 'Faruma', 'Noto Sans Dhivehi', Arial, serif;
    direction: rtl;
    text-align: right;
    unicode-bidi: embed;
    text-rendering: optimizeLegibility;
}

/* English descriptions (LTR) */
.story-description-en {
    font-family: 'Georgia', 'Times New Roman', serif;
    direction: ltr;
    text-align: left;
    unicode-bidi: embed;
}

/* Explore Story button — ancient scroll with ribbon */
.episode-scroll-btn {
    display: inline-block;
    text-decoration: none;
    transition: all 0.4s ease;
    position: relative;
    margin-top: auto;
    align-self: center;
}

.episode-scroll-paper {
    position: relative;
    background: var(--gradient-soft);
    padding: 0.7rem 1.8rem 0.7rem 1.3rem;
    border-radius: 25px 0 0 25px;
    border-right: 5px solid #c287a3;
    box-shadow: 0 2px 6px rgba(252, 228, 236, 0.25);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid var(--accent-gold);
    overflow: hidden;
}

.episode-scroll-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    z-index: 2;
}

.episode-scroll-icon {
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.episode-scroll-text {
    font-size: 0.9rem;
    font-weight: 700;
    background: linear-gradient(135deg, #b4316a, #a52a5c);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.6);
}

.episode-scroll-ribbon {
    position: absolute;
    top: -2px;
    right: -8px;
    bottom: -2px;
    width: 20px;
    background: linear-gradient(135deg, #c287a3, #b4316a, #a52a5c);
    clip-path: polygon(0 0, 80% 0, 100% 50%, 80% 100%, 0 100%);
    box-shadow:
        0 3px 10px rgba(195, 135, 163, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.episode-scroll-ribbon::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 30%;
    transform: translateY(-50%);
    width: 2px;
    height: 60%;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 1px;
}

.story-face-back:hover .episode-scroll-paper {
    transform: translateX(-5px);
    background: var(--accent-gold);
    box-shadow: 0 4px 12px rgba(248, 187, 217, 0.5);
    border-color: var(--accent-rose);
}

.story-face-back:hover .episode-scroll-icon {
    transform: rotate(5deg) scale(1.1);
}

.story-face-back:hover .episode-scroll-ribbon {
    background: linear-gradient(135deg, #b4316a, #a52a5c, #8b2c4a);
    box-shadow:
        0 5px 15px rgba(195, 135, 163, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.episode-scroll-paper::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(255,255,255,0.2) 50%,
        transparent 100%
    );
    transition: left 0.6s ease;
}

.story-face-back:hover .episode-scroll-paper::before {
    left: 100%;
}

[data-theme="dark"] .story-face {
    background: #1f1f1f !important;
    border-color: #3a2535 !important;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4) !important;
}

[data-theme="dark"] .episode-count,
[data-theme="dark"] .release-date,
[data-theme="dark"] .story-category {
    background: rgba(31, 31, 31, 0.92) !important;
    color: #f0f0f0 !important;
}

@media (max-width: 768px) {
    .stories-grid {
        grid-template-columns: 1fr;
        padding: 0 1rem;
    }

    .featured-info {
        padding: 1.2rem !important;
    }

    .cover-badges {
        padding: 0.5rem 0.6rem !important;
    }

    .release-date, .story-category {
        font-size: 0.7rem !important;
        padding: 0.15rem 0.5rem !important;
        border-radius: 20px !important;
    }

    .episode-count {
        padding: 0.1rem 0.3rem !important;
        border-radius: 12px !important;
        font-size: 0.55rem !important;
        max-width: 60px !important;
    }

    .count-number {
        font-size: 0.6rem !important;
    }

    .count-text {
        font-size: 0.5rem !important;
    }
}

@media (max-width: 480px) {
    .featured-info {
        padding: 1rem !important;
    }

    .cover-badges {
        gap: 0.3rem !important;
        padding: 0.45rem 0.55rem !important;
    }

    .release-date, .story-category {
        font-size: 0.65rem !important;
        padding: 0.1rem 0.4rem !important;
        border-radius: 15px !important;
        margin-bottom: 0.2rem;
        min-width: 80px;
        text-align: center;
    }

    .episode-count {
        padding: 0.1rem 0.3rem !important;
        border-radius: 12px !important;
        font-size: 0.55rem !important;
        max-width: 60px !important;
    }

    .count-number {
        font-size: 0.6rem !important;
    }

    .count-text {
        font-size: 0.5rem !important;
    }
}
