/* Storybook Layout and Typography */
:root {
    --page-color: #fff8f3;
    --text-color: #2c1810;
    --border-color: #d4c5b9;
    --page-stack-color: #e4e0d9;
}

.storybook {
    max-width: 1200px;
    margin: 0.75rem auto;
    background: var(--page-color);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    position: relative;
    display: flex;
    min-height: 800px;
    perspective: 1500px;
    transform-style: preserve-3d;
    padding: 20px;
}

/* Book thickness effect */
.storybook::before,
.storybook::after {
    content: '';
    position: absolute;
    top: 0;
    width: 40px;
    height: 100%;
    background: var(--page-stack-color);
    border-radius: 4px;
    z-index: -1;
}

/* Left stack of pages */
.storybook::before {
    left: -20px;
    background: linear-gradient(to right,
        #d4d1cc,
        var(--page-stack-color) 4px,
        var(--page-stack-color) 6px,
        #ffffff 7px,
        var(--page-stack-color) 8px,
        var(--page-stack-color) 10px,
        #ffffff 11px,
        var(--page-stack-color) 12px,
        var(--page-stack-color) 14px,
        #ffffff 15px,
        var(--page-stack-color) 16px,
        var(--page-stack-color)
    );
    transform: rotateY(-20deg);
    box-shadow: inset -7px 0 8px -4px rgba(0,0,0,0.1);
}

/* Right stack of pages */
.storybook::after {
    right: -20px;
    background: linear-gradient(to left,
        #d4d1cc,
        var(--page-stack-color) 4px,
        var(--page-stack-color) 6px,
        #ffffff 7px,
        var(--page-stack-color) 8px,
        var(--page-stack-color) 10px,
        #ffffff 11px,
        var(--page-stack-color) 12px,
        var(--page-stack-color) 14px,
        #ffffff 15px,
        var(--page-stack-color) 16px,
        var(--page-stack-color)
    );
    transform: rotateY(20deg);
    box-shadow: inset 7px 0 8px -4px rgba(0,0,0,0.1);
}

/* Book spine shadow */
.storybook::before {
    box-shadow: 
        inset -7px 0 8px -4px rgba(0,0,0,0.1),
        -2px 0 3px rgba(0,0,0,0.1);
}

.storybook::after {
    box-shadow: 
        inset 7px 0 8px -4px rgba(0,0,0,0.1),
        2px 0 3px rgba(0,0,0,0.1);
}

/* Page styles */
.page {
    flex: 1;
    padding: 3rem 4rem 6rem 4rem;
    border: 1px solid var(--border-color);
    position: absolute;
    top: 0;
    bottom: 0;
    width: 50%;
    background: var(--page-color);
    transition: transform 1s ease-in-out;
    transform-style: preserve-3d;
    backface-visibility: visible;
    cursor: pointer;
    will-change: transform;
    overflow: hidden;
    text-align: left;
    height: 100%; /* Change from auto to 100% to fill the page */
    display: flex;
    flex-direction: column;
    justify-content: center; /* This centers content vertically */
}

#previous-page {
    left: 0;
    transform-origin: right center;
    border-radius: 8px 0 0 8px;
    border-right: none;
    z-index: 1;
}

#current-page {
    right: 0;
    transform: rotateY(0deg);
    transform-origin: left center;
    border-radius: 0 8px 8px 0;
    border-left: none;
    z-index: 2;
    box-shadow: inset 7px 0 10px -5px rgba(0, 0, 0, 0.15);
}

/* Story content */
.story-text {
    text-align: left;
    color: black;
    font-family: 'Jost', sans-serif;
}

.story-text p {
    font-size: 1.5rem;
    margin-bottom: 1em;
    line-height: 1.6;
    color: rgb(34, 29, 29);
    font-family: 'Jost', sans-serif;
}

/* Story title container */
.story-title-container {
    display: flex;
    align-items: center;
    margin-bottom: 1em;
}

.story-title {
    margin: 0;
    font-size: 2rem;
    line-height: 1.2;
    color: rgb(34, 29, 29);
    font-family: 'Jost', sans-serif;
}

/* Info button and popup styles */
.info-button {
    display: inline-block;
    margin-left: 15px;
    padding: 5px 12px;
    background: var(--hover-color, #FFC368); /* Flat main color background instead of gradient */
    border: none;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    color: #000; /* Black text for contrast */
    cursor: pointer;
    transition: background-color 0.3s ease; /* Simplified transition */
    vertical-align: middle;
}

.info-button:hover {
    background: rgba(255, 195, 104, 0.8); /* Slightly darker main color, same as other buttons */
}

.info-button:active {
    transform: translateY(1px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.info-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s;
}

.info-popup-overlay.active {
    opacity: 1;
    visibility: visible;
}

.info-popup {
    background-color: white;
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    min-width: 320px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    position: relative;
    margin: 20px;
}

.info-popup h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #333;
    font-size: 1.4rem;
}

.info-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
}

.info-table th,
.info-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.info-table th {
    width: 40%;
    font-weight: bold;
    color: #555;
}

.info-table td {
    color: #333;
}

.info-popup-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 25px;
    height: 25px;
    text-align: center;
    line-height: 23px;
    background-color: #f0f0f0;
    border-radius: 50%;
    cursor: pointer;
    font-weight: bold;
    font-size: 18px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}

.info-popup-close:hover {
    background-color: #e0e0e0;
}

/* Admin button styles */
.recreate-image-btn:hover {
    background: linear-gradient(135deg, #5a6fd8 0%, #6b41a8 100%) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.recreate-image-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.4);
}

.recreate-image-btn:disabled {
    background: #cccccc !important;
    cursor: not-allowed !important;
    transform: none !important;
    box-shadow: none !important;
}

/* Styles for Story Image */
.story-image-container {
    margin-bottom: 1.5rem;
    text-align: center;
}

.story-image {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    cursor: pointer; /* Add cursor pointer to indicate the image is clickable */
    transition: transform 0.2s ease; /* Add smooth transition for hover effect */
}

.story-image:hover {
    transform: scale(1.02); /* Slightly scale up on hover */
}

/* Full-screen image overlay */
.fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s;
}

.fullscreen-overlay.active {
    opacity: 1;
    visibility: visible;
}

.fullscreen-image {
    max-width: 90%;
    max-height: 90%;
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.close-fullscreen {
    position: absolute;
    top: 20px;
    right: 20px;
    color: white;
    font-size: 30px;
    cursor: pointer;
    z-index: 1001;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.close-fullscreen:hover {
    background-color: rgba(255, 0, 0, 0.7);
}

/* Page corner indicators */
.page-corner {
    position: absolute;
    width: 50px;
    height: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 2;
    transform: rotateY(0deg);
    backface-visibility: hidden;
}

#previous-page .page-corner {
    transform: rotateY(180deg);
}

/* Active page states */
.page.dragging, .page.turning {
    z-index: 3;
}

/* Page turn animations */
.page-turn-next {
    animation: turnNext 1s cubic-bezier(0.645, 0.045, 0.355, 1.000) forwards;
}

.page-turn-prev {
    animation: turnPrev 1s cubic-bezier(0.645, 0.045, 0.355, 1.000) forwards;
}

@keyframes turnNext {
    from { transform: rotateY(0deg); }
    to { transform: rotateY(-180deg); }
}

@keyframes turnPrev {
    from { transform: rotateY(-180deg); }
    to { transform: rotateY(0deg); }
}

/* Hide previous page when it's not needed */
#previous-page.hidden {
    display: none;
}

/* Decorative elements */
.page-number {
    position: absolute;
    bottom: 1.5rem;
    font-family: 'Quicksand', sans-serif;
    font-size: 0.9rem;
    color: var(--text-color);
    opacity: 0.7;
    z-index: 2;
    backface-visibility: hidden;
}

.page-number-left {
    left: 3rem;
}

.page-number-right {
    right: 3rem;
    transform: rotateY(0deg);
}

/* Responsive design */
@media (max-width: 768px) {
    .storybook {
        flex-direction: column;
        min-height: auto;
        padding: 15px;
        background-color: rgba(255, 248, 243, 0.25); /* Semi-transparent version of --page-color with more opacity */
        -webkit-backdrop-filter: blur(5px); /* For Safari */
        backdrop-filter: blur(5px);
        border-radius: 10px; /* Optional: softer edges for the blurred container */
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    }

    .storybook::before,
    .storybook::after {
        display: none;
    }

    .page {
        position: relative;
        width: 100%;
        padding: 1.5rem;
        border: none;
        box-shadow: none;
        background: white;
        transform: none !important;
    }

    #previous-page, #current-page {
        display: none;
        overflow-y: auto;
        top: auto;
        bottom: auto;
        left: auto;
        right: auto;
        border-radius: 5px;
    }
    
    #current-page {
        display: block;
    }

    .story-image-container {
        max-width: 100%;
        margin: 0 auto 1em auto;
    }
    
    .book-navigation, 
    .page-corner,
    .page-number {
        display: none !important; /* Hide navigation, corners and page numbers on mobile */
    }
    
    .story-text p {
        font-size: 1.2rem;
    }

    .story-title {
        font-size: 1.5rem;
    }
    
    /* Improve the title container and INFO button for mobile */
    .story-title-container {
        flex-wrap: wrap;
        margin-bottom: 0.5em;
        display: flex;
        align-items: center;
    }
    
    .info-button {
        margin-left: 10px;
        margin-top: 10px;
        padding: 8px 15px;
        font-size: 0.85rem;
        height: auto;
        line-height: normal;
        white-space: nowrap;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(0,0,0,0);
    }
    
    /* Hide print button on mobile devices */
    .print-button-рядом {
        display: none !important;
    }
    
    /* Make popup more touchable on mobile */
    .info-popup-close {
        padding: 0;
        width: 40px;
        height: 40px;
        font-size: 24px;
        line-height: 40px;
        background-color: rgba(0,0,0,0.1);
        color: #333;
        border: none;
        top: 5px;
        right: 5px;
    }
    
    /* Ensure popup is sized properly for mobile */
    .info-popup {
        width: 95%;
        max-width: 95vw;
        min-width: unset;
        padding: 20px 15px;
        margin: 10px;
        max-height: 90vh;
        border-radius: 16px;
    }
    
    .info-table th,
    .info-table td {
        padding: 6px 8px;
        font-size: 0.9rem;
    }
}

/* Tablet styles */
@media (min-width: 769px) and (max-width: 1024px) {
    .info-popup {
        width: 85%;
        max-width: 500px;
        padding: 20px;
    }
    
    .info-popup h3 {
        font-size: 1.3rem;
    }
}

/* Large screen optimization */
@media (min-width: 1200px) {
    .info-popup {
        width: 40%;
        max-width: 650px;
        padding: 30px;
    }
    
    .info-popup h3 {
        font-size: 1.5rem;
    }
    
    .info-table th,
    .info-table td {
        padding: 10px 15px;
        font-size: 1rem;
    }
}

/* Extra small devices (phones in portrait) */
@media (max-width: 480px) {
    .info-popup {
        width: 98%;
        margin: 5px;
        padding: 15px 12px;
        border-radius: 12px;
    }
    
    .info-popup h3 {
        font-size: 1.2rem;
        margin-bottom: 15px;
    }
    
    .info-popup-close {
        width: 35px;
        height: 35px;
        font-size: 20px;
        line-height: 35px;
        top: 8px;
        right: 8px;
    }
    
    .info-table th,
    .info-table td {
        padding: 8px 6px;
        font-size: 0.85rem;
    }
    
    .info-table th {
        width: 35%;
    }
    
    .story-preview-actions {
        margin-top: 15px !important;
    }
    
    .btn-primary {
        padding: 12px 20px;
        font-size: 0.9rem;
    }
}

/* Draggable page styles */
#draggable-page {
    cursor: grab;
    transform-origin: left center;
    will-change: transform;
}

#draggable-page:active {
    cursor: grabbing;
}

/* Enhance page turn animations */
.page-turn-next, .page-turn-prev {
    pointer-events: none;
}

/* Language Switcher Buttons */
.language-switcher {
    /* Use Flexbox for centering */
    display: flex;
    justify-content: center;
    align-items: center; /* Vertically align items if needed */
    /* Container has margin via my-4 */
    padding: 10px 0; 
}

/* Style for the moral of the story section */
.story-morale-page {
    margin-top: 10px;
    padding: 10px 0;
    font-family: 'Jost', sans-serif;
}

.story-morale-page h4 {
    margin-bottom: 10px;
    font-weight: bold;
    color: #333;
    font-family: 'Jost', sans-serif;
}

.lang-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-family: 'Jost', sans-serif;
    font-size: 1rem; /* Adjust size as needed */
    font-weight: 600;
    transition: all 0.3s ease;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
    backdrop-filter: blur(5px);
    margin: 0 5px; /* Add horizontal spacing between buttons */
}

.lang-btn:hover {
    background: var(--hover-color, #FFC368);
    color: #000;
    transform: scale(1.03);
}

.lang-btn.active {
    background-color: rgba(74, 107, 175, 0.7); /* Use theme accent color */
    color: #fff;
    border-color: rgba(74, 107, 175, 0.9);
    box-shadow: 0 0 10px rgba(74, 107, 175, 0.4),
                0 0 15px rgba(255, 255, 255, 0.6);
    transform: scale(1.05);
    font-weight: bold;
}

/* Optional: Style for the single language indicator */
.single-language-indicator .badge {
    padding: 8px 15px;
    font-size: 0.9rem;
    background-color: rgba(108, 117, 125, 0.7); /* Bootstrap secondary, but translucent */
    backdrop-filter: blur(5px);
}

/* Print-specific styles */
@media print {
    body > *:not(iframe), /* Hide everything in the main body except the print iframe */
    .book-navigation, 
    .breadcrumb-nav, 
    .star-rating-container, 
    .public-story-rating-widget,
    .info-button,
    .info-popup-overlay,
    .fullscreen-overlay,
    .language-switcher,
    header, /* Assuming your site header has a <header> tag or a common class */
    footer, /* Assuming your site footer has a <footer> tag or a common class */
    .navbar, /* Common class for navbars */
    .sidebar /* Common class for sidebars */
    {
        display: none !important;
        visibility: hidden !important;
    }

    /* Ensure the body itself has no margins or padding affecting the print */
    body {
        margin: 0 !important;
        padding: 0 !important;
        background-color: #fff !important; /* Ensure background is white for print */
    }
}

/* Story Preview Modal Image Styles */
.story-preview-image-container {
    text-align: center;
    margin: 15px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

#modal-story-image {
    max-width: 200px;
    max-height: 150px;
    border-radius: 8px;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: opacity 0.3s ease;
    display: block;
    margin: 0 auto;
}

#modal-story-image-placeholder {
    width: 150px;
    height: 150px;
    margin: 0 auto;
    background-color: #f0f0f0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #666;
    border: 2px dashed #ddd;
}

/* Responsive adjustments for modal image */
@media (max-width: 480px) {
    .story-preview-image-container {
        margin: 10px 0 !important;
    }
    
    #modal-story-image {
        max-width: 140px !important;
        max-height: 105px !important;
    }
    
    #modal-story-image-placeholder {
        width: 120px !important;
        height: 120px !important;
        font-size: 20px !important;
    }
}

@media (min-width: 1200px) {
    #modal-story-image {
        max-width: 250px;
        max-height: 190px;
    }
    
    #modal-story-image-placeholder {
        width: 180px;
        height: 180px;
        font-size: 28px;
    }
}