/* Echoes of Nyx - Ebook Reader Theme with Matrix Option */

/* === CSS Variables for Theming === */
:root {
    /* Light Theme (Default - Ebook Style) */
    --bg-primary: #faf9f6;
    --bg-secondary: #f5f4f0;
    --bg-card: #ffffff;
    --text-primary: #2c2c2c;
    --text-secondary: #555555;
    --text-muted: #888888;
    --accent: #8b4513;
    --accent-hover: #a0522d;
    --border-color: #d0d0d0;
    --link-color: #8b4513;
    --link-hover: #a0522d;
    --shadow: rgba(0, 0, 0, 0.08);
    --font-body: 'Georgia', 'Times New Roman', serif;
    --font-heading: 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'Courier New', monospace;
    --line-height: 1.8;
    --font-size-base: 18px;
    --content-max-width: 720px;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #252525;
    --bg-card: #2d2d2d;
    --text-primary: #e8e8e8;
    --text-secondary: #b0b0b0;
    --text-muted: #808080;
    --accent: #d4a574;
    --accent-hover: #e8c9a8;
    --border-color: #444444;
    --link-color: #d4a574;
    --link-hover: #e8c9a8;
    --shadow: rgba(0, 0, 0, 0.3);
}

/* Matrix Theme */
[data-theme="matrix"] {
    --bg-primary: #000000;
    --bg-secondary: #0a0a0a;
    --bg-card: #000000;
    --text-primary: #00ff00;
    --text-secondary: #00cc00;
    --text-muted: #008800;
    --accent: #00ff00;
    --accent-hover: #33ff33;
    --border-color: #00ff00;
    --link-color: #00ff00;
    --link-hover: #33ff33;
    --shadow: rgba(0, 255, 0, 0.1);
    --font-body: 'Courier New', Consolas, monospace;
    --font-heading: 'Courier New', monospace;
}

/* === Reset & Base === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    font-size: var(--font-size-base);
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    line-height: var(--line-height);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Matrix-specific effects */
[data-theme="matrix"] body {
    text-shadow: 0 0 5px var(--text-secondary);
}

[data-theme="matrix"] body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15),
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
    pointer-events: none;
    z-index: 999;
}

/* === Links === */
a {
    color: var(--link-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--link-hover);
    text-decoration: underline;
}

/* === Navigation === */
.main-nav {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background-color 0.3s ease;
}

.nav-logo {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 1px;
}

.nav-logo:hover {
    text-decoration: none;
    color: var(--accent);
}

.nav-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.nav-links a {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-family: var(--font-heading);
    padding: 0.4rem 0.8rem;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--accent);
    background: var(--bg-card);
    text-decoration: none;
}

/* === Theme Toggle === */
.theme-toggle {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    background: var(--bg-card);
    padding: 0.3rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
}

.theme-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.4rem 0.8rem;
    border-radius: 15px;
    font-size: 0.8rem;
    font-family: var(--font-heading);
    color: var(--text-muted);
    transition: all 0.2s ease;
}

.theme-btn:hover {
    color: var(--text-secondary);
}

.theme-btn.active {
    background: var(--accent);
    color: var(--bg-primary);
}

/* === Container === */
.container {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: 2rem;
    flex: 1;
    width: 100%;
}

/* === Hero Section === */
.hero {
    text-align: center;
    padding: 4rem 2rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

.hero-content {
    max-width: 600px;
    margin: 0 auto;
}

.title {
    font-family: var(--font-heading);
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-primary);
    letter-spacing: 2px;
}

.tagline {
    color: var(--text-secondary);
    font-size: 1.2rem;
    font-style: italic;
    font-weight: 300;
}

/* === Book Cards === */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin: 2rem 0;
}

.book-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 2rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px var(--shadow);
}

.book-card h3 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.book-card .subtitle {
    font-size: 0.9rem;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.book-card p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    flex: 1;
}

.book-meta {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.book-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.btn {
    display: inline-block;
    padding: 0.7rem 1.5rem;
    background: var(--accent);
    color: var(--bg-primary);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover {
    background: var(--accent-hover);
    text-decoration: none;
    transform: translateY(-1px);
}

.btn-secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
}

.btn-secondary:hover {
    background: var(--accent);
    color: var(--bg-primary);
}

/* === Section Headers === */
.section-header {
    text-align: center;
    margin: 3rem 0 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.section-header h2 {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.section-header p {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* === Author Section === */
.author-section {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 2rem;
    margin: 3rem 0;
    text-align: center;
}

.author-section h2 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.author-bio {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.author-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 3px solid var(--accent);
    object-fit: cover;
}

.author-info p {
    color: var(--text-secondary);
    max-width: 500px;
    margin: 0 auto 1rem;
}

.social-links {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.social-links a {
    color: var(--accent);
    font-weight: 600;
}

/* === Book Index Page === */
.book-header {
    text-align: center;
    padding: 2rem 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

.book-header h1 {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    margin-bottom: 0.5rem;
}

.book-header .book-subtitle {
    color: var(--text-secondary);
    font-style: italic;
    margin-bottom: 1rem;
}

.book-header .book-description {
    color: var(--text-secondary);
    max-width: 600px;
    margin: 0 auto;
}

/* Language Toggle */
.lang-toggle {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin: 2rem 0;
}

.lang-btn {
    padding: 0.6rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.lang-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.lang-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg-primary);
}

/* Progress Bar */
.progress-section {
    margin: 2rem 0;
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.progress-bar {
    height: 8px;
    background: var(--bg-card);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.3s ease;
}

/* Chapter List */
.chapters-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin: 2rem 0;
}

.chapter-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1.2rem;
    transition: all 0.2s ease;
    display: block;
    text-decoration: none;
}

.chapter-item:hover {
    border-color: var(--accent);
    transform: translateX(4px);
    text-decoration: none;
}

.chapter-item:hover .chapter-number {
    color: var(--accent);
}

.chapter-number {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.3rem;
}

.chapter-title {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    color: var(--text-primary);
    font-weight: 600;
}

/* === Chapter Reader === */
.reader-header {
    text-align: center;
    padding: 1.5rem 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

.reader-header h1 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 0.3rem;
}

.reader-header .chapter-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Chapter Navigation (Top) */
.chapter-nav-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding: 0.8rem 1rem;
    background: var(--bg-secondary);
    border-radius: 6px;
}

.chapter-nav-top a {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chapter-nav-top a:hover {
    text-decoration: none;
    color: var(--accent-hover);
}

.chapter-nav-top a.disabled {
    color: var(--text-muted);
    pointer-events: none;
}

.chapter-nav-top .toc-link {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Chapter Content - Ebook Style */
.chapter-content {
    font-size: 1.05rem;
    line-height: var(--line-height);
    text-align: justify;
    color: var(--text-primary);
}

.chapter-content p {
    margin-bottom: 1.5rem;
    text-indent: 2rem;
}

.chapter-content p:first-of-type {
    text-indent: 0;
}

.chapter-content p:first-of-type::first-letter {
    font-size: 3.5rem;
    font-weight: bold;
    float: left;
    line-height: 1;
    padding-right: 0.5rem;
    margin-top: -0.2rem;
    color: var(--accent);
    font-family: var(--font-heading);
}

.chapter-content em,
.chapter-content i {
    font-style: italic;
}

.chapter-content strong,
.chapter-content b {
    font-weight: 600;
}

.chapter-content blockquote {
    margin: 2rem 1.5rem;
    padding: 1rem 1.5rem;
    border-left: 3px solid var(--accent);
    background: var(--bg-secondary);
    font-style: italic;
    color: var(--text-secondary);
}

.chapter-content hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2rem 0;
}

/* Chapter Navigation (Bottom) */
.chapter-nav-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.8rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.nav-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg-primary);
    text-decoration: none;
}

.nav-btn.disabled {
    color: var(--text-muted);
    pointer-events: none;
    opacity: 0.5;
}

.nav-btn.next {
    flex-direction: row-reverse;
}

/* === Footer === */
footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: auto;
}

footer p {
    margin-bottom: 0.5rem;
}

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

footer a:hover {
    text-decoration: underline;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 1rem;
}

.footer-links a {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* === Matrix Background (Optional) === */
.matrix-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.5s ease;
}

[data-theme="matrix"] .matrix-bg {
    opacity: 0.05;
}

/* === Responsive Design === */
@media (max-width: 768px) {
    html {
        font-size: 16px;
    }

    .main-nav {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .nav-links {
        gap: 1rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .theme-toggle {
        order: -1;
    }

    .title {
        font-size: 2rem;
    }

    .container {
        padding: 1.5rem;
    }

    .hero {
        padding: 2rem 1rem;
    }

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

    .book-actions {
        flex-direction: column;
        justify-content: center;
    }

    .btn {
        text-align: center;
    }

    .chapters-list {
        grid-template-columns: 1fr;
    }

    .chapter-content {
        font-size: 1rem;
    }

    .chapter-content p:first-of-type::first-letter {
        font-size: 2.5rem;
    }

    .chapter-nav-top,
    .chapter-nav-bottom {
        flex-direction: column;
        gap: 1rem;
    }

    .nav-btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 15px;
    }

    .title {
        font-size: 1.6rem;
    }

    .container {
        padding: 1rem;
    }

    .chapter-content p {
        text-indent: 1.5rem;
    }

    .chapter-content p:first-of-type::first-letter {
        font-size: 2rem;
    }
}

/* === Print Styles === */
@media print {
    body {
        background: white;
        color: black;
    }

    .main-nav,
    .theme-toggle,
    .chapter-nav-top,
    .chapter-nav-bottom,
    .matrix-bg,
    footer {
        display: none;
    }

    .chapter-content {
        font-size: 12pt;
        line-height: 1.6;
    }

    .container {
        max-width: 100%;
        padding: 0;
    }
}

/* === Accessibility === */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }

    html {
        scroll-behavior: auto;
    }
}

/* Focus styles for keyboard navigation */
a:focus,
button:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000;
        --text-primary: #000;
        --bg-primary: #fff;
    }
}

/* === Book Cover Styles === */
.book-section {
    display: flex;
    flex-direction: column;
    align-items: center; /* Center everything */
    text-align: center;
    gap: 2rem;
    padding: 5rem 1.5rem 3rem; /* Extra padding on top (5rem), sides (1.5rem), bottom (3rem) */
}

.book-cover-container {
    max-width: 350px;
    width: 100%;
    margin: 0 auto; /* Center the container */
    display: flex;
    justify-content: center;
    /* Fix: Add aspect ratio to prevent cropping */
    aspect-ratio: 2/3;
}

.book-cover {
    width: 100%;
    max-width: 320px;
    aspect-ratio: 2/3;
    border-radius: 12px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.4);
}

.book-cover-container iframe {
    width: 100%;
    height: auto; /* Fix: Let height adjust to content */
    aspect-ratio: 2/3;
    border: none;
    display: block;
}

.book-info {
    flex: 1;
}

@media (min-width: 769px) {
    .book-section {
        flex-direction: row;
        align-items: center;
        text-align: left;
    }

    .book-cover-container {
        flex-shrink: 0;
    }
}

/* === Utility Classes === */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mt-2 { margin-top: 2rem; }
.mb-2 { margin-bottom: 2rem; }
.hidden { display: none; }
