/*
Theme Name:  Mystic Pen
Theme URI:   https://mysticpen.com
Author:      Mystic Pen Development
Author URI:  https://mysticpen.com
Description: Custom theme for the Mystic Pen romance ebook publisher.
Version:     1.0.0
License:     GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags:        ebook, publisher, romance
Text Domain: mysticpen
*/

/*--------------------------------------------------------------
# Core Layout & Typography
--------------------------------------------------------------*/
:root {
    --primary-color: #4a148c; /* Deep Purple */
    --secondary-color: #fce4ec; /* Light Pink */
    --accent-color: #ff4081; /* Hot Pink */
    --text-color: #333333; /* Dark text for light background */
    --background-color: #fff;
    --site-background-color: rgb(0, 36, 81); /* Deep blue - default site background */
    --heading-font: 'Georgia', serif;
    --body-font: 'Helvetica Neue', Arial, sans-serif;
}

.dark-theme {
    --primary-color: #ce93d8; /* Light Purple */
    --secondary-color: #2c0b42; /* Dark Purple */
    --accent-color: #f48fb1; /* Light Pink */
    --text-color: #e0e0e0;
    --background-color: #121212;
    --site-background-color: #1a1a1a;
}

body {
    font-family: var(--body-font);
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--site-background-color);
    margin: 0;
    transition: background-color 0.3s, color 0.3s;
}

.site {
    max-width: 1200px;
    margin: 0 auto;
    background-color: var(--background-color);
    box-shadow: 0 0 20px rgba(0,0,0,0.05);
}

/*--------------------------------------------------------------
# Enhanced Book Content Formatting
--------------------------------------------------------------*/

/* Book paragraph styles with proper indentation and spacing */
.book-paragraph {
    margin: 0 0 1.2em 0;
    line-height: 1.8;
    font-size: 16px;
    color: var(--text-color);
    text-align: justify;
    hyphens: auto;
}

.book-paragraph-indent {
    text-indent: 0;
    margin-bottom: 1.5em;
    font-family: 'Courier New', Courier, monospace;
    white-space: pre-wrap;
    /* Five spaces at the start of each paragraph will be rendered literally */
}

.book-paragraph:first-of-type {
    text-indent: 0; /* No indent for first paragraph of chapter */
}

/* Enhanced Book image containers with responsive design */
.book-image-container {
    margin: 2.5em 0;
    text-align: center;
    padding: 1.5em;
    background: rgba(0,0,0,0.02);
    border-radius: 12px;
    border: 1px solid rgba(0,0,0,0.05);
    transition: all 0.3s ease;
    position: relative;
}

.book-image-container:hover {
    background: rgba(0,0,0,0.04);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}

.book-image-figure {
    margin: 0;
    position: relative;
    display: inline-block;
}

.book-image {
    max-width: 100%;
    max-height: 70vh;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
    transition: all 0.3s ease;
    cursor: pointer;
    display: block;
}

.book-image:hover {
    transform: scale(1.03);
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.book-image-inline {
    /* Specific styling for inline images within text */
    max-width: 100%;
    height: auto;
}

/* Image lightbox overlay */
.mysticpen-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.mysticpen-lightbox.active {
    opacity: 1;
    visibility: visible;
}

.mysticpen-lightbox-content {
    position: relative;
    max-width: 95%;
    max-height: 95%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mysticpen-lightbox-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.mysticpen-lightbox-close {
    position: absolute;
    top: -40px;
    right: -40px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

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

/* Loading state for images */
.book-image-container.loading {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 1.5s infinite;
}

.mysticpen-lightbox-content.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: spin 1s linear infinite;
}

@keyframes loading-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Age Gate Overlay */
.age-gate-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    padding: 20px;
    box-sizing: border-box;
}
.age-gate-overlay.active { display: flex; }
.age-gate-content {
    background: #ffffff;
    max-width: 480px;
    width: 100%;
    border-radius: 16px;
    padding: 32px 28px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    font-family: var(--body-font);
    color: #333333; /* Explicit dark text color for light background */
}
body.dark-theme .age-gate-content { background:#1e1a24; color:#e0d8ec; }
.age-gate-content h2 { margin-top:0; font-family: var(--heading-font); color: var(--primary-color); }
body.dark-theme .age-gate-content h2 { color: var(--accent-color); }
.age-gate-content p { line-height:1.5; margin: 1em 0 1.5em; color: inherit; }
.age-gate-help { margin-top: 12px !important; font-size: 0.85rem; opacity: 1 !important; }
.age-gate-content a { color: var(--primary-color); text-decoration: underline; }
.age-gate-content a:hover { color: var(--accent-color); }
body.dark-theme .age-gate-content a { color: var(--accent-color); }
body.dark-theme .age-gate-content a:hover { color: #ff5c9d; }
.age-gate-buttons { display:flex; gap:14px; flex-wrap:wrap; justify-content:center; }
.age-gate-button { cursor:pointer; border:none; border-radius:8px; padding:14px 22px; font-size:16px; font-weight:600; background:var(--primary-color); color:#fff; transition:background .25s, transform .2s; }
.age-gate-button:hover { background:var(--accent-color); transform:translateY(-2px); }
.age-gate-decline { background:#666; }
.age-gate-decline:hover { background:#444; }
body.dark-theme .age-gate-button { background: var(--accent-color); }
body.dark-theme .age-gate-button:hover { background:#ff5c9d; }
@media (max-width:600px){ .age-gate-content { padding:24px 20px; } .age-gate-button { flex:1 1 100%; } }


/* Responsive image sizing */
@media (max-width: 768px) {
    .book-image-container {
        margin: 1.5em 0;
        padding: 1em;
    }
    
    .book-image {
        max-height: 50vh;
    }
    
    .mysticpen-lightbox-close {
        top: 10px;
        right: 10px;
        width: 35px;
        height: 35px;
        font-size: 18px;
    }
}

/* Book table styles */
.book-table {
    width: 100%;
    margin: 2em 0;
    border-collapse: collapse;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.book-table-cell {
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    background: var(--background-color);
    vertical-align: top;
}

.book-table tr:nth-child(even) .book-table-cell {
    background: rgba(0,0,0,0.02);
}

.book-table tr:first-child .book-table-cell {
    font-weight: bold;
    background: var(--secondary-color);
}

/* Error states */
.image-error, .table-error {
    color: #999;
    font-style: italic;
    text-align: center;
    padding: 1em;
    background: rgba(255,0,0,0.05);
    border-radius: 4px;
    margin: 1em 0;
}

/* Enhanced reader content area */
.reader-content .prose {
    max-width: 800px;
    margin: 0 auto;
    padding: 2em;
    font-family: 'Georgia', 'Times New Roman', serif;
    font-size: 18px;
    line-height: 1.8;
}

.reader-content .prose h2 {
    font-family: var(--heading-font);
    font-size: 2em;
    margin: 2em 0 1em 0;
    color: var(--primary-color);
    text-align: center;
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 0.5em;
}

.reader-content .prose h2:first-of-type {
    margin-top: 0;
}

/* Table of Contents enhancement */
.reader-toc {
    background: var(--secondary-color);
    padding: 2em;
    margin: 2em 0;
    border-radius: 8px;
    border-left: 4px solid var(--accent-color);
}

.reader-toc h2 {
    color: var(--primary-color);
    margin-top: 0;
    text-align: center;
}

.reader-toc ul {
    list-style: none;
    padding: 0;
    columns: 2;
    column-gap: 2em;
}

.reader-toc li {
    margin: 0.5em 0;
    break-inside: avoid;
}

.reader-toc a {
    color: var(--text-color);
    text-decoration: none;
    padding: 0.5em 0;
    display: block;
    border-bottom: 1px dotted #ccc;
    transition: color 0.3s ease;
}

.reader-toc a:hover {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

/* Dark theme adjustments */
.dark-theme .book-table-cell {
    border-color: #444;
}

.dark-theme .book-image-container {
    background: rgba(255,255,255,0.05);
}

.dark-theme .book-table tr:nth-child(even) .book-table-cell {
    background: rgba(255,255,255,0.02);
}

@media (max-width: 768px) {
    .reader-content .prose {
        padding: 1em;
        font-size: 16px;
    }
    
    .book-paragraph {
        font-size: 15px;
        line-height: 1.7;
    }
    
    .book-paragraph-indent {
        text-indent: 1.5em;
    }
    
    .reader-toc ul {
        columns: 1;
    }
}


.site-content {
    padding: 2em;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--heading-font);
    color: var(--primary-color);
}

a {
    color: var(--accent-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/*--------------------------------------------------------------
# Header & Navigation
--------------------------------------------------------------*/
.site-header {
    /* The hero banner now acts as the header background. */
    /* Padding is removed to allow the hero image to fill the container. */
    padding: 0;
}

.site-branding {
    flex-shrink: 0;
    position: relative; /* Positioning context for the navigation */
}

.hero-banner img {
    /* Default mobile styles: Full width */
    width: 100%;
    height: auto;
    display: block;
}

/* Tablet styles */
@media (min-width: 768px) {
    .hero-banner img {
        width: 90%;
    }
}

/* Desktop styles */
@media (min-width: 1200px) {
    .hero-banner img {
        width: 80%;
    }
}

.site-title {
    margin: 0;
    font-size: 1.8em;
    font-family: var(--heading-font);
}


.site-description {
    margin: 0;
    font-size: 1em;
    opacity: 0.8;
}

.main-navigation {
    padding: 1em 0; /* Add some vertical spacing for mobile view */
}

.main-navigation ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap; /* Allow menu items to wrap on small screens */
    justify-content: center; /* Center items on mobile */
    gap: 1.5em;
}

.main-navigation li {
    margin-left: 0;
}

.main-navigation a {
    font-weight: bold;
    text-transform: uppercase;
    font-size: 0.9em;
}

.main-navigation a:hover {
    color: var(--accent-color);
    text-decoration: none;
}

/* Tablet and Desktop: Position menu over the hero image */
@media (min-width: 768px) {
    .main-navigation {
        position: absolute;
        bottom: 1em;
        left: 1em;
        z-index: 10;
        padding: 0; /* Reset padding */
    }

    .main-navigation ul {
        padding: 0.5em 1em;
        background-color: rgba(0, 0, 0, 0.5);
        border-radius: 4px;
        justify-content: flex-start; /* Re-align to left */
    }
}

/*--------------------------------------------------------------
# Theme Switcher
--------------------------------------------------------------*/
.theme-switcher {
    position: absolute;
    top: 1em;
    left: 1em;
    z-index: 11; /* Place above navigation */
}

.theme-toggle-button {
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid #fff;
    color: #fff;
    cursor: pointer;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background-color 0.2s;
}

.theme-toggle-button:hover {
    background-color: rgba(0, 0, 0, 0.5);
}

.theme-toggle-button .sun-icon {
    display: block;
}

.theme-toggle-button .moon-icon {
    display: none;
}

.dark-theme .theme-toggle-button .sun-icon {
    display: none;
}

.dark-theme .theme-toggle-button .moon-icon {
    display: block;
}


/*--------------------------------------------------------------
# Footer
--------------------------------------------------------------*/
.site-footer {
    padding: 2em;
    background-color: #f1f1f1;
    font-size: 0.9em;
    color: #555;
}

.dark-theme .site-footer {
    background-color: var(--secondary-color);
    color: var(--text-color);
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.site-info {
    text-align: left;
}

.footer-image img {
    max-height: 80px; /* Adjust as needed */
    width: auto;
}


/*--------------------------------------------------------------
# Single Book Styles
--------------------------------------------------------------*/
.book-single .book-content-wrapper {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2em;
    margin-top: 2em;
}

@media (min-width: 768px) {
    .book-single .book-content-wrapper {
        grid-template-columns: 300px 1fr;
    }
}

.book-single .book-cover img {
    width: 100%;
    height: auto;
    border: 1px solid #eee;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.book-single .book-meta {
    margin-bottom: 1.5em;
}

.book-single .book-meta div {
    margin-bottom: 0.5em;
}

.book-single .entry-content h2 {
    margin-top: 0;
    font-size: 1.5em;
}

.book-actions {
    margin-bottom: 1.5em;
}

.read-now-button {
    display: inline-block;
    background-color: var(--accent-color);
    color: #fff;
    padding: 0.8em 1.5em;
    border-radius: 4px;
    font-weight: bold;
    text-decoration: none;
    transition: background-color 0.2s;
}

.read-now-button:hover {
    background-color: #d81b60; /* Darker pink */
    color: #fff;
    text-decoration: none;
}


/*--------------------------------------------------------------
# Book Archive Styles
--------------------------------------------------------------*/
.book-archive-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5em;
    margin-top: 2em;
}

.book-archive-item {
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
    transition: box-shadow 0.2s ease-in-out;
}

.book-archive-item:hover {
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

.book-archive-link {
    text-decoration: none;
    color: inherit;
}

.book-archive-cover img {
    width: 100%;
    height: auto;
    display: block;
}

.book-archive-cover .placeholder-cover {
    width: 100%;
    height: 300px;
    background-color: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #aaa;
}

.book-archive-details {
    padding: 1em;
}

.book-archive-title {
    margin: 0 0 0.25em;
    font-size: 1.1em;
    line-height: 1.3;
}

.book-archive-author {
    font-size: 0.9em;
    color: #555;
}

/*--------------------------------------------------------------
# Age Gate
--------------------------------------------------------------*/
.age-gate-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.age-gate-content {
    background-color: var(--background-color);
    padding: 3em;
    border-radius: 8px;
    text-align: center;
    max-width: 500px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.age-gate-content h2 {
    margin-top: 0;
    color: var(--primary-color);
}

.age-gate-buttons {
    margin-top: 2em;
    display: flex;
    gap: 1em;
    justify-content: center;
}

.age-gate-button {
    padding: 0.8em 1.5em;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    font-weight: bold;
    transition: background-color 0.2s;
}

.age-gate-button#age-gate-confirm {
    background-color: var(--accent-color);
    color: #fff;
}

.age-gate-button#age-gate-confirm:hover {
    background-color: #d81b60; /* Darker pink */
}

.age-gate-button.age-gate-decline {
    background-color: #ccc;
    color: #333;
}

.dark-theme .age-gate-button.age-gate-decline {
    background-color: #555;
    color: #fff;
}

/*--------------------------------------------------------------
# Reader View Styles
--------------------------------------------------------------*/
.reader-sticky-home-link {
    position: fixed;
    top: 1em;
    left: 1em;
    z-index: 1001; /* Above reader controls */
    display: flex;
    align-items: center;
    gap: 0.5em;
    background-color: rgba(0, 0, 0, 0.3);
    padding: 0.5em;
    border-radius: 50px;
    text-decoration: none;
    transition: background-color 0.2s;
}

.reader-sticky-home-link:hover {
    background-color: rgba(0, 0, 0, 0.5);
}

.reader-sticky-home-image {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.back-arrow {
    font-size: 2em;
    color: #fff;
    line-height: 1;
    padding-right: 0.2em;
}

.reader-sticky-close-link {
    position: fixed;
    top: 1em;
    right: 1em;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    color: #fff;
    transition: background-color 0.2s;
}

.reader-sticky-close-link:hover {
    background-color: rgba(0, 0, 0, 0.5);
}

.reader-back-to-top {
    position: fixed;
    right: 1.5em;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1000;
    width: 40px;
    height: 40px;
    background-color: rgba(0, 0, 0, 0.3);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s, background-color 0.2s;
    pointer-events: none;
}

.reader-back-to-top.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.reader-back-to-top:hover {
    background-color: rgba(0, 0, 0, 0.5);
}

.reader-mode .reader-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2em;
    background-color: var(--background-color);
}

.reader-mode .reader-header {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #eee;
    padding-bottom: 1em;
    margin-bottom: 2em;
}

.reader-mode .reader-header h1 {
    margin: 0;
    font-size: 1.8em;
}

.dark-theme .reader-sticky-home-link {
    background-color: rgba(255, 255, 255, 0.2);
}

.dark-theme .reader-sticky-home-link:hover {
    background-color: rgba(255, 255, 255, 0.4);
}

.dark-theme .reader-back-to-top {
    background-color: rgba(255, 255, 255, 0.2);
}

.dark-theme .reader-back-to-top:hover {
    background-color: rgba(255, 255, 255, 0.4);
}

.dark-theme .reader-sticky-close-link {
    background-color: rgba(255, 255, 255, 0.2);
}
.dark-theme .reader-sticky-close-link:hover {
    background-color: rgba(255, 255, 255, 0.4);
}

.reader-mode .reader-content .prose {
    font-family: 'Georgia', serif;
    font-size: 1em; /* Default font size for mobile */
    line-height: 1.7;
}

.reader-mode .reader-content .prose h2 {
    font-size: 1.5em; /* Adjust heading size for mobile */
}

@media (min-width: 768px) {
    .reader-mode .reader-content .prose {
        font-size: 1.1em; /* Larger font size for tablets and desktops */
        line-height: 1.8;
    }
}

.reader-mode .reader-content .prose p {
    margin-bottom: 1.5em;
    text-align: justify;
}

.reader-mode .reader-content .prose .text-center {
    text-align: center;
    text-indent: 0; /* Override any other indentation rules */
}

.reader-mode .reader-content .prose p.indent-first-line {
    text-indent: 2em;
    margin-top: 0;
}

/* Do not indent the first paragraph right after a heading */
.reader-mode .reader-content .prose h1 + p,
.reader-mode .reader-content .prose h2 + p,
.reader-mode .reader-content .prose h3 + p {
    text-indent: 0;
}

.reader-mode .reader-content .prose img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 2em auto;
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.reader-toc {
    background-color: #f9f9f9;
    border: 1px solid #eee;
    padding: 1.5em;
    margin-bottom: 3em;
    border-radius: 4px;
}

.reader-toc h2 {
    margin-top: 0;
    margin-bottom: 1em;
    font-size: 1.4em;
    border-bottom: 1px solid #ddd;
    padding-bottom: 0.5em;
}

.reader-toc ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.reader-toc li a {
    text-decoration: none;
    display: block;
    padding: 0.4em 0;
    color: var(--primary-color);
    font-weight: bold;
}

.reader-toc li a:hover {
    text-decoration: underline;
}

.reader-toc .toc-level-2 {
    padding-left: 1.5em;
}

.reader-toc .toc-level-3 {
    padding-left: 3em;
}
