/**
 * style.css
 *
 * Styles for the Story Viewer Webpage.
 * Uses CSS variables for easy theming.
 */

/* ------------------------- */
/* --- Variable Defaults (Light Theme) --- */
/* ------------------------- */
:root {
    --bg-color: #fdfdfd;
    --text-color: #333;
    --header-color: #000;
    --meta-color: #666;
    --accent-color: #0056b3;
    --accent-hover-color: #003d80;
    --border-color: #ddd;
    --subtle-bg-color: #e9ecef;
    --tag-bg-color: #f1f1f1;

    --font-body: 'Lora', serif;
    --font-heading: 'Montserrat', sans-serif;
    --base-font-size: 16px;

    --background-image: none;
}

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

/* ------------------------- */
/* --- General Styling --- */
/* ------------------------- */
body {
    font-family: var(--font-body);
    line-height: 1.7;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    padding: 2rem;
    background-image: var(--background-image);
    transition: background-color 0.3s ease, color 0.3s ease;
}

h1, h2, h3 {
    font-family: var(--font-heading);
    font-weight: 700;
    color: var(--header-color);
}

a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.2s ease-in-out;
}

a:hover {
    color: var(--accent-hover-color);
}

/* ------------------------- */
/* --- Layout --- */
/* ------------------------- */
.page-container {
    display: grid;
    grid-template-columns: 250px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "header header"
        "nav    main";
    gap: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

header {
    grid-area: header;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    position: relative;
}

#story-navigation {
    grid-area: nav;
}

#story-display {
    grid-area: main;
}

/* ------------------------- */
/* --- Components --- */
/* ------------------------- */

/* Wrapper for all header controls */
.controls-container {
    position: absolute;
    top: 50%;
    right: 1rem;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 1rem; /* Space between theme and font controls */
}

/* Common styles for all control buttons */
#theme-switcher button,
#font-size-switcher button {
    background: var(--subtle-bg-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.3rem 0.7rem;
    border-radius: 20px;
    cursor: pointer;
    font-family: var(--font-heading);
    margin: 0 0.1rem;
}

/* Specific styles for font size buttons */
#font-size-switcher button {
    font-size: 0.9rem;
    font-weight: bold;
    min-width: 32px;
    text-align: center;
}

/* Story Navigation */
#story-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

#story-list li {
    margin-bottom: 0.5rem;
}

#story-list a {
    display: block;
    padding: 0.5rem;
    border-radius: 4px;
}

#story-list a.active {
    background-color: var(--subtle-bg-color);
    font-weight: bold;
}
/* Story Content */
#story-container {
    max-width: 720px;
    margin: 0 auto;
}

#story-header {
    text-align: center;
    margin-bottom: 3rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1.5rem;
}

/* Language switcher styles */
#language-switcher {
    margin-top: 1.5rem;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    color: var(--meta-color);
}

/* Hide the container when it has no content */
#language-switcher:empty {
    display: none;
}

#language-switcher a {
    margin: 0 0.5rem;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
}
#language-switcher a:hover {
    background-color: var(--subtle-bg-color);
}

/* Style for the currently active language */
#language-switcher .active-lang {
    margin: 0 0.5rem;
    font-weight: bold;
    color: var(--header-color);
}

#story-title {
    /* Typographic Enhancements */
    font-family: var(--font-heading);
    font-size: 2.8rem;
    font-variant: small-caps;
    letter-spacing: 0.1em;

    /* Layout and Framing */
    position: relative; /* Anchor for pseudo-elements */
    margin-top: 1.5rem;
    margin-bottom: 2.5rem;
    padding: 1.5rem 0; /* Vertical padding for space */
}

/* Line above the title */
#story-title::before,
#story-title::after {
    content: ''; /* Necessary for pseudo-elements to render */
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 100px; /* Adjust width of the line */
    height: 1px;
    background-color: var(--border-color);
}

#story-title::before {
    top: 0; /* Position the top line */
}

#story-title::after {
    bottom: 0; /* Position the bottom line */
}

/* Genre-specific font overrides */
body.genre-fantasy #story-title {
    font-family: 'Cinzel Decorative', var(--font-heading);
}

body.genre-fantasy #story-content h1,
body.genre-fantasy #story-content h2,
body.genre-fantasy #story-content h3 {
    font-family: 'Cinzel Decorative', var(--font-heading);
}

body.genre-scifi #story-title {
    font-family: 'Share Tech Mono', var(--font-heading);
    font-variant: normal; /* Reset small-caps for monospaced font */
    letter-spacing: normal; /* Reset letter-spacing */
}

body.genre-scifi #story-content h1,
body.genre-scifi #story-content h2,
body.genre-scifi #story-content h3 {
    font-family: 'Share Tech Mono', var(--font-heading);
}

#story-meta {
    color: var(--meta-color);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.story-stats {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem 1.5rem;
    line-height: 1.5;
}

.story-genres {
    line-height: 1.5;
}

.genre-tag {
    display: inline-block;
    background-color: var(--tag-bg-color);
    padding: 0.1rem 0.6rem;
    border-radius: 12px;
    font-size: 0.8rem;
    margin: 0.2rem;
}

/* --- BOOK TYPOGRAPHY STYLES --- */

#story-content p {
    text-align: justify;
    margin-top: 0;
    margin-bottom: 0;
    text-indent: 2em;
}

/* Remove indent for the first paragraph of a section */
#story-content h1 + p,
#story-content h2 + p,
#story-content h3 + p,
#story-content hr + p {
    text-indent: 0;
}

/* Styles for content with 'poem' format */
#story-content.format-poem p {
    /* Override standard paragraph book styles for a poetic layout */
    text-indent: 0;
    text-align: center;
}

/* Remove indent for the first paragraph of a section */
#story-content h1 + p,
#story-content h2 + p,
#story-content h3 + p,
#story-content hr + p {
    text-indent: 0;
}

/* Chapter Title Header */
#story-content h1 {
    text-align: center;
    font-size: 1.8rem;
    margin-top: 2em;
    margin-bottom: 1.5em;
}

/* Sub-section Headers */
#story-content h2 {
    text-align: left;
    font-size: 1.3rem;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

/* Minor Headers */
#story-content h3 {
    text-align: left;
    font-size: 1.1rem;
    margin-top: 1.5em;
    margin-bottom: 0.5em;
}

/* Styled Scene Break */
#story-content hr {
    border: 0;
    border-top: 1px solid var(--meta-color);
    width: 50px; /* Adjust width as needed */
    margin: 3em auto; /* 'auto' centers it */
}

#story-content blockquote {
    border-left: 4px solid var(--border-color);
    padding-left: 1rem;
    margin-left: 1em; /* Add some left margin to indent it */
    font-style: italic;
    color: var(--meta-color);
}

#story-content code {
    background-color: var(--subtle-bg-color);
    padding: 0.2em 0.4em;
    border-radius: 3px;
    font-family: monospace;
}
#story-content pre code {
    display: block;
    padding: 1rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ------------------------- */
/* --- Themes --- */
/* ------------------------- */
body.dark-theme {
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --header-color: #ffffff;
    --meta-color: #999;
    --accent-color: #8ab4f8;
    --accent-hover-color: #a3c5fb;
    --border-color: #444;
    --subtle-bg-color: #2a2a2a;
    --tag-bg-color: #333;
}

body.sepia-theme {
    --bg-color: #fbf0d9;
    --text-color: #5b4636;
    --header-color: #433124;
    --meta-color: #7d6b5a;
    --accent-color: #8c6f5a;
    --accent-hover-color: #6d5543;
    --border-color: #e0d5c1;
    --subtle-bg-color: #e9e0cf;
    --tag-bg-color: #e0d5c1;
}

body.parchment-theme {
    --background-image: url(https://am-a.akamaihd.net/image?f=https://assets.toptal.io/media/CACHE/images/subtle_patterns/patterns/debut_light/494bf5535850.png);
    --bg-color: #f5f5dc;
    --text-color: #4a2c2a;
    --header-color: #3b1e1e;
    --meta-color: #7b5b59;
    --accent-color: #8c3838;
    --accent-hover-color: #6b2a2a;
    --border-color: #d2b48c;
    --subtle-bg-color: #eaddc0;
    --tag-bg-color: #d2b48c;
    --font-body: 'IM Fell English', 'Lora', serif;
}


/* ------------------------- */
/* --- Responsive Design --- */
/* ------------------------- */

@media (max-width: 1000px) {
    html {
        font-size: calc(var(--base-font-size) - 2px);
    }

    /* Adjust the main page grid for single-column layout */
    .page-container {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "nav"
            "main";
        padding: 1rem 0rem;
        gap: 1.5rem;
    }

    #story-navigation {
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 1rem;
    }

    #story-title {
        font-size: 2.5rem;
        margin-bottom: 1.5rem;
    }

    /* Stack the header's title and controls vertically */
    header {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1rem;
        padding-bottom: 1.5rem;
    }

    /* Position the controls container within the new header flow */
    .controls-container {
        position: static;
        transform: none;
        /* Stack the theme and font-size controls vertically for smaller screens */
        flex-direction: column;
        gap: 0.75rem;
    }

    /* Ensure control groups are centered */
    #theme-switcher, #font-size-switcher {
        text-align: center;
    }
}