/* ==========================================================================
   Stories Page Styles
   ========================================================================== */

/* Active nav link */
.active-link {
    color: var(--clr-accent) !important;
}

.active-link::after {
    width: 100% !important;
    background: var(--clr-accent) !important;
}

/* ==========================================================================
   Before & After Showcase Section
   ========================================================================== */
.before-after-section {
    padding: 4rem 0 3rem;
}

.showcase-area {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
    margin-top: 2rem;
}

.showcase-box {
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: relative;
}

.showcase-label {
    background: var(--clr-bg-card);
    padding: 0.8rem 1.5rem;
    border-radius: var(--radius-full);
    text-align: center;
    font-weight: 700;
    color: var(--clr-text-dark);
    box-shadow: var(--shadow-sm);
    border: 2px solid var(--clr-primary-soft);
}

.showcase-label-after {
    background: var(--clr-accent);
    color: var(--clr-primary);
    border-color: var(--clr-accent);
}

.showcase-img-wrapper {
    height: 350px;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    position: relative;
    background: var(--clr-beige);
}

.showcase-box-before {
    width: min(280px, 100%);
}

.showcase-before-wrapper {
    height: 315px;
}

.showcase-box-result {
    width: min(560px, 100%);
}

.showcase-result-wrapper {
    height: 315px;
}

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

.showcase-img-after-result {
    object-fit: cover;
    object-position: center;
    background: var(--clr-bg-light);
}

.showcase-img-wrapper:hover .showcase-img {
    transform: scale(1.05);
}

.showcase-glow {
    border: 3px solid var(--clr-accent);
    box-shadow: 0 0 25px rgba(228, 176, 85, 0.4);
}

.sparkle-icon {
    position: absolute;
    top: 15px;
    left: 15px;
    font-size: 2rem;
    animation: sparkleFloat 2s ease-in-out infinite alternate;
}

html[dir="rtl"] .sparkle-icon {
    left: auto;
    right: 15px;
}

.showcase-arrow {
    color: var(--clr-primary-light);
    flex-shrink: 0;
    animation: arrowPulse 1.5s ease-in-out infinite;
    margin-top: 3rem; /* Align with images, not labels */
}

html[dir="rtl"] .showcase-arrow {
    animation: arrowPulseRTL 1.5s ease-in-out infinite;
}

@keyframes sparkleFloat {
    0% { transform: translateY(0) scale(0.9); opacity: 0.8; }
    100% { transform: translateY(-10px) scale(1.1); opacity: 1; filter: drop-shadow(0 0 5px var(--clr-accent)); }
}

@keyframes arrowPulse {
    0%, 100% { transform: translateX(0); opacity: 0.6; }
    50% { transform: translateX(8px); opacity: 1; }
}

@keyframes arrowPulseRTL {
    0%, 100% { transform: scaleX(-1) translateX(0); opacity: 0.6; }
    50% { transform: scaleX(-1) translateX(8px); opacity: 1; }
}

/* ==========================================================================
   Stories Toolbar (Search + Filter)
   ========================================================================== */
.stories-browse {
    padding: 3rem 0 5rem;
}

.stories-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 2.5rem;
    flex-wrap: wrap;
}

.stories-search {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--clr-bg-card);
    border: 2px solid var(--clr-primary-soft);
    border-radius: var(--radius-full);
    padding: 0.6rem 1.2rem;
    flex: 1;
    max-width: 400px;
    transition: border-color var(--transition-fast);
    color: var(--clr-text-muted);
}

.stories-search-clear {
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 50%;
    background: var(--clr-primary-soft);
    color: var(--clr-primary);
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    line-height: 1;
    flex-shrink: 0;
    transition: background var(--transition-fast), transform var(--transition-fast);
}

.stories-search-clear.visible {
    display: inline-flex;
}

.stories-search-clear:hover {
    background: var(--clr-accent);
    transform: scale(1.05);
}

.stories-search:focus-within {
    border-color: var(--clr-primary);
}

.stories-search-input {
    border: none;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-size: 1rem;
    color: var(--clr-text-dark);
    width: 100%;
}

.stories-search-input::placeholder {
    color: var(--clr-text-muted);
}

.stories-search-status {
    min-height: 1.5rem;
    margin: -1.25rem 0 1.5rem;
    color: var(--clr-text-muted);
    font-size: 0.95rem;
    font-weight: 700;
    text-align: center;
}

.stories-search-status.is-empty {
    color: var(--clr-primary);
}

.filter-dropdown {
    position: relative;
    display: inline-block;
}

.stories-select {
    appearance: none; /* Hide default arrow */
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: var(--clr-bg-card);
    border: 2px solid var(--clr-primary-soft);
    border-radius: var(--radius-full);
    padding: 0.6rem 2.5rem 0.6rem 1.2rem;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--clr-text-dark);
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%234E4076%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem top 50%;
    background-size: 0.65rem auto;
}

html[dir="rtl"] .stories-select {
    padding: 0.6rem 1.2rem 0.6rem 2.5rem;
    background-position: left 1rem top 50%;
}

.stories-select:hover,
.stories-select:focus {
    border-color: var(--clr-primary);
    box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .stories-select {
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23FFF9F3%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
}

/* ==========================================================================
   Stories Grid
   ========================================================================== */
.stories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
}

.story-card {
    background: var(--clr-bg-card);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal), opacity var(--transition-normal);
}

.story-card.hidden {
    display: none;
}

.story-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
}

.story-card-img {
    height: 220px;
    overflow: hidden;
    position: relative;
}

.story-card-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.story-card:hover .story-card-img img {
    transform: scale(1.05);
}

.story-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 0.3rem 0.8rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 700;
}

html[dir="ltr"] .story-badge {
    right: auto;
    left: 12px;
}

.badge-boys {
    background: var(--clr-secondary);
    color: var(--clr-primary);
}

.badge-girls {
    background: var(--clr-primary-light);
    color: #FFF9F3;
}

.badge-all {
    background: var(--clr-accent);
    color: var(--clr-primary);
}

.story-card-body {
    padding: 1.5rem;
}

.story-card-body h3 {
    font-size: 1.2rem;
    color: var(--clr-primary);
    margin-bottom: 0.5rem;
}

.story-card-body p {
    color: var(--clr-text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.story-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.story-price {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--clr-accent);
    font-family: var(--font-en);
}

.btn-sm {
    padding: 0.5rem 1.2rem;
    font-size: 0.85rem;
}

/* ==========================================================================
   Stories Page Responsive
   ========================================================================== */
@media (max-width: 768px) {
    .merge-area {
        flex-direction: column;
    }

    .merge-box {
        width: 100%;
        max-width: 320px;
        height: 280px;
    }

    .merge-arrow {
        transform: rotate(90deg);
    }

    html[dir="rtl"] .merge-arrow {
        transform: rotate(90deg);
    }

    .stories-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .stories-search {
        max-width: 100%;
    }

    .filter-buttons {
        justify-content: center;
    }

    .stories-grid {
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
    }

    .story-card-img {
        height: 160px;
    }

    .story-card-body {
        padding: 1rem;
    }

    .story-card-body h3 {
        font-size: 1rem;
    }

    .story-card-body p {
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .photo-merge-section {
        padding: 2.5rem 0 2rem;
    }

    .merge-box {
        height: 240px;
    }

    .stories-grid {
        grid-template-columns: 1fr;
    }

    .story-card-img {
        height: 200px;
    }

    .filter-btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
}

/* ==========================================================================
   Story Preview Modal & Open Book Layout
   ========================================================================== */
.story-preview-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    visibility: hidden;
}

.story-preview-modal.open {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(18, 15, 26, 0.75);
    backdrop-filter: blur(8px);
    cursor: pointer;
}

.modal-content {
    position: relative;
    background: var(--clr-bg-card);
    width: 90%;
    max-width: 950px;
    border-radius: 24px;
    padding: 30px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    z-index: 2;
    transform: translateY(30px);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.story-preview-modal.open .modal-content {
    transform: translateY(0);
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--clr-primary-soft);
    border: none;
    font-size: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--clr-primary);
    transition: all 0.2s ease;
    z-index: 10;
}

html[dir="rtl"] .modal-close {
    right: auto;
    left: 20px;
}

.modal-close:hover {
    background: var(--clr-accent);
    color: var(--clr-primary);
    transform: rotate(90deg);
}

/* Preview Grid - responsive layout */
.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 0.5rem;
    padding: 0 0.5rem;
}

.preview-card {
    background: var(--clr-bg-card);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
    max-width: 100%;
}

.preview-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.preview-illustration {
    height: 140px; /* reduced height for better fit */
    display: flex;
    align-items: center;
    justify-content: center;
    background: #eae3d2;
    overflow: hidden;
}

.preview-card .book-page-image {
    width: 100%;
    max-height: 140px;
    object-fit: cover;
    display: block;
}
    width: 100%;
    height: 100%;
    object-fit: cover;
    max-height: 140px;
}

.preview-text {
    padding: 0.75rem;
    text-align: center;
    font-size: 0.9rem;
    line-height: 1.4;
}

    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-top: 15px;
}

/* Book Container and Layout */
.book-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    position: relative;
}

.book-wrapper {
    flex: 1;
    perspective: 1500px;
}

.book-pages {
    display: flex;
    background: #fdfaf2;
    border-radius: 12px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15), inset 0 0 40px rgba(0,0,0,0.05);
    overflow: hidden;
    position: relative;
    aspect-ratio: 1.6 / 1;
    border: 8px solid #3c3359;
}

.book-pages::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 30px;
    transform: translateX(-50%);
    background: linear-gradient(to right, rgba(0,0,0,0.12) 0%, rgba(0,0,0,0.0) 25%, rgba(0,0,0,0.25) 50%, rgba(0,0,0,0.0) 75%, rgba(0,0,0,0.12) 100%);
    z-index: 5;
    pointer-events: none;
}

.book-page-half {
    width: 50%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* Left side page: Illustration */
.book-page-left {
    background: #eae3d2;
    border-right: 1px solid rgba(0, 0, 0, 0.08);
}

html[dir="rtl"] .book-page-left {
    border-right: none;
    border-left: 1px solid rgba(0, 0, 0, 0.08);
}

.book-page-image-container {
    width: 100%;
    height: 100%;
    position: relative;
}

.book-page-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.book-page-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 4rem;
    background: linear-gradient(135deg, #4e4076, #9c8bb0);
}

.book-page-placeholder-text {
    font-size: 1.2rem;
    font-weight: 700;
    margin-top: 10px;
    color: rgba(255,255,255,0.9);
}

/* Right side page: Narrative text */
.book-page-right {
    background: #faf6eb;
    padding: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    position: relative;
    color: #332d40;
}

.book-page-text-content {
    font-size: 1.4rem;
    line-height: 2.0;
    font-weight: 600;
    color: #3c3359;
    max-width: 85%;
    margin: 0 auto;
    position: relative;
}

.book-page-right::before,
.book-page-right::after {
    content: '✨';
    position: absolute;
    font-size: 1.5rem;
    color: var(--clr-accent);
    opacity: 0.5;
}
.book-page-right::before {
    top: 25px;
    right: 25px;
}
.book-page-right::after {
    bottom: 25px;
    left: 25px;
}

html[dir="rtl"] .book-page-right::before {
    right: auto;
    left: 25px;
}
html[dir="rtl"] .book-page-right::after {
    left: auto;
    right: 25px;
}

/* Page Navigation Arrows */
.book-nav-btn {
    background: var(--clr-primary);
    border: none;
    color: #fff;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    transition: all 0.2s ease;
    z-index: 10;
}

.book-nav-btn:hover {
    background: var(--clr-accent);
    color: var(--clr-primary);
    transform: scale(1.1);
}

.book-nav-btn:disabled {
    background: var(--clr-primary-soft);
    color: var(--clr-text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    opacity: 0.5;
}

/* Bottom Controls */
.modal-bottom-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    flex-wrap: wrap;
    gap: 15px;
}

.page-indicators {
    display: flex;
    gap: 8px;
}

.indicator-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--clr-primary-soft);
    cursor: pointer;
    transition: all 0.2s ease;
}

.indicator-dot.active {
    background: var(--clr-accent);
    transform: scale(1.25);
    box-shadow: 0 0 8px var(--clr-accent);
}

/* Actions */
.modal-actions {
    display: flex;
    gap: 15px;
}

/* Cards footer styling to layout the preview buttons nicely */
.story-actions {
    display: flex;
    gap: 8px;
}

.btn-preview {
    border: 2px solid var(--clr-primary-soft);
    background: transparent;
    color: var(--clr-primary);
}

.btn-preview:hover {
    background: var(--clr-primary-soft);
    border-color: var(--clr-primary);
    transform: translateY(-2px);
}

/* RTL adaptations for Book orientation */
html[dir="rtl"] .book-pages {
    flex-direction: row-reverse;
}

html[dir="rtl"] .book-nav-btn.prev-btn svg,
html[dir="rtl"] .book-nav-btn.next-btn svg {
    transform: scaleX(-1);
}

/* Unified preview slider, matching the home page modal */
.story-preview-modal .modal-content {
    width: min(1040px, 92vw);
    max-width: 92vw;
    max-height: 90vh;
    overflow-y: auto;
    padding: 2rem;
}

.story-preview-modal .preview-grid {
    display: block;
    width: 100%;
    padding: 0;
    margin: 0 0 0.75rem;
}

.story-preview-modal .preview-title {
    color: var(--clr-primary);
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1.3;
    text-align: center;
    padding: 0 2rem 0.25rem;
}

.story-preview-modal .book-pages {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    background: var(--clr-bg-light);
    border: 0;
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    box-shadow: var(--shadow-sm);
    aspect-ratio: auto;
    overflow: visible;
}

.story-preview-modal .book-pages::after {
    display: none;
}

.story-preview-modal .preview-slide-image {
    width: 100%;
    max-height: 68vh;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    border-radius: calc(var(--radius-sm) - 2px);
    display: block;
}

.story-preview-modal .book-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    margin: 0;
    display: inline-flex;
    z-index: 5;
}

.story-preview-modal #prev-page-btn {
    left: 1rem;
}

.story-preview-modal #next-page-btn {
    right: 1rem;
}

.story-preview-modal .page-indicators {
    justify-content: center;
    margin: 0 0 1rem;
}

.story-preview-modal .indicator-dot {
    border: 0;
    padding: 0;
}

@media (max-width: 520px) {
    .story-preview-modal .modal-content {
        width: 94vw;
        padding: 1.25rem;
    }

    .story-preview-modal .preview-title {
        font-size: 1.35rem;
        padding-inline: 1.5rem;
    }

    .story-preview-modal .book-nav-btn {
        width: 38px;
        height: 38px;
    }
}


/* Added styles for template cards on index page */
.card-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

.card-footer .btn-preview {
    border: 2px solid var(--clr-primary-soft);
    background: transparent;
    color: var(--clr-primary);
    margin-left: 0.5rem;
}

.card-footer .btn-preview:hover {
    background: var(--clr-primary-soft);
    border-color: var(--clr-primary);
    transform: translateY(-2px);
}

@media (max-width: 768px) {
    .modal-content {
        padding: 20px 15px;
        border-radius: 16px;
    }
    
    .modal-close {
        top: 10px;
        right: 10px;
    }
    
    html[dir="rtl"] .modal-close {
        left: 10px;
    }

    .book-pages {
        flex-direction: column !important;
        aspect-ratio: auto;
        height: auto;
        border: 4px solid #3c3359;
    }
    
    .book-pages::after {
        display: none;
    }

    .book-page-half {
        width: 100%;
    }
    
    .book-page-left {
        height: 220px;
        border-right: none;
        border-left: none;
        border-bottom: 2px solid rgba(0,0,0,0.1);
    }
    
    .book-page-right {
        height: auto;
        padding: 25px 20px;
        border-left: none;
        border-right: none;
    }
    
    .book-page-text-content {
        font-size: 1.1rem;
        max-width: 100%;
    }
    
    .book-nav-btn {
        width: 40px;
        height: 40px;
    }
    
    .book-container {
        gap: 10px;
    }
    
    .modal-bottom-controls {
        flex-direction: column;
        align-items: center;
    }
    
    .modal-actions {
        width: 100%;
    }
    
    .modal-actions .btn {
        width: 100%;
    }
    
    .story-card-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .story-actions {
        width: 100%;
    }
    
    .story-actions .btn {
        flex: 1;
    }
}
