/* ==========================================================================
   1. CORE VARIABLES (THE PALETTE)
   ========================================================================== */

:root {
    /* Backgrounds: Deep High-Contrast Obsidian & Rich Velvet Black */
    --bg-main: #0c0a08; /* Darker, deep true-black ink base */
    --bg-card: #18130f; /* Rich leather charcoal with clear definition */
    --border-color: #42352b; /* Sharper, structural warm-bronze border line */
    /* Typography: Crisp Pure Alabaster & Warm Lit Cream */
    --text-primary: #ffffff; /* Pure stark white for flawless readability */
    --text-muted: #dcd0b9; /* Brightened parchment cream—no longer muddy */
    /* Accents: Radiant Royal Gold & Brilliant Sunfire Amber */
    --accent-color: #ffd700; /* High-saturation vivid golden-yellow glow */
    --accent-hover: #ffea70; /* Ultra-bright light gold shimmer on hover */
    /* Typography Hierarchy: Traditional Serif for Literary Feel */
    --font-main: 'Georgia', 'Times New Roman', serif;
    --main-header-height: 40px;
    --subheader-height: 40px;
    --footer-height: 40px;
}

/* ========================================================================== 
   2. GLOBAL RESETS & NAVIGATION LAYOUT 
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    overflow: hidden !important; /* Locks window canvas scrollbars completely */
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-main);
    line-height: 1.7;
}

html {
    font-size: 14px;
    scroll-behavior: auto;
}

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }
}

/* --- FIXED HEADERS ENGINE --- */

/* Fixed Header Base Configuration */
.main-fixed-header {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: var(--main-header-height);
    background-color: #333;
    z-index: 2000 !important;
    box-sizing: border-box;
}

.nav-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1.5rem;
    position: relative;
}

header-spacer
/* 1. HIDE IT EVERYWHERE BY DEFAULT */
.secondary-header {
    display: none !important;
}

/* 2. FORCE IT TO VISIBLE ONLY INSIDE SUBPAGE CONTEXT */
body.subpage-layout .secondary-header {
    display: flex !important;
    position: fixed !important;
    top: var(--main-header-height) !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: var(--subheader-height) !important;
    background-color: var(--bg-main) !important;
    border-bottom: 1px solid var(--border-color);
    z-index: 1900 !important;
    box-sizing: border-box;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
}

.header-stack-wrapper {
    flex-shrink: 0;
    width: 100%;
    z-index: 1000;
}



/* By default, hide the secondary header entirely */
.secondary-header {
    display: none !important;
}

/* Only show the secondary header when inside a subpage layout layout context */
body.subpage-layout .secondary-header {
    display: flex !important; /* Restores the header alignment styles perfectly */
    position: fixed !important;
    top: var(--main-header-height) !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: var(--subheader-height);
    background-color: var(--bg-main) !important;
    border-bottom: 1px solid #e0e0e0;
    z-index: 1900 !important;
    box-sizing: border-box;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
}


body:has(.secondary-header) .main-content-container {
    padding-top: calc(var(--main-header-height) + var(--subheader-height));
}

/* --- ISOLATED VIEWPORT BODY SCROLL --- */
/* Create a flex column that takes up exactly 100% of the screen height */
.app-viewport {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
}

.main-scroll-content {
    height: calc(100vh - var(--main-header-height));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    position: absolute !important;
    left: 0;
    right: 0;
    -ms-overflow-style: none;
    flex-grow: 1;
    overflow-y: auto; /* Content scrolls inside here, NOT the browser */
    width: 100%;
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 20px;
    padding-right: 20px;
    box-sizing: border-box;
    scroll-behavior: auto !important;
}

/* Homepage dynamic padding offset */
body.layout-container .main-scroll-content {
    top: var(--main-header-height) !important;
    height: calc(100vh - var(--main-header-height) - var(--footer-height)) !important;
}

/* Subpage dynamic padding offset */
body.subpage-layout .main-scroll-content {
    top: calc(var(--main-header-height) + var(--subheader-height)) !important;
    height: calc(100vh - var(--main-header-height) - var(--subheader-height) - var(--footer-height)) !important;
}

.main-content-container {
    height: calc(100vh - var(--main-header-height));
    overflow-y: auto; /* Only this specific region scrolls */
    box-sizing: border-box;
}

/* Optional: WebKit scrollbar styling (Chrome, Edge, Safari) */ 
.main-scroll-webkit-scrollbar {
    width: 12px;
}

.main-scroll-webkit-scrollbar-track {
    background: transparent;
}

.main-scroll::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.4);
    border-radius: 6px;
    border: 3px solid transparent;
    background-clip: padding-box;
}


/* Fixed Footer Configuration */
.app-footer {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: var(--footer-height);
    line-height: calc(var(--footer-height) - 5px);
    background-color: #333;
    z-index: 2000 !important;
}

/* Brand, typography, and focus resets */
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}


.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
    color: var(--bs-secondary-color);
    text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
    text-align: start;
}




h1, h2, h3, h4 {
    color: var(--text-primary);
    font-weight: normal; /* Classic literary styling uses lighter font weights */
    letter-spacing: 0.02em;
    margin-top: 0;
}

a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--accent-hover);
}

/* Perfect centering trick for the brand title */
#brand-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-weight: bold;
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-right: 40px;
    text-decoration: none;
    z-index: 1001;
}


#header-text {
    display: inline-block;
    padding-top: 8px;
    padding-left: 20px;
}



#footer-text {
    display: inline-block;
    padding-left: 20px;
}

#privacy-link {
    display: inline-block;
    padding-right: 20px;
}


/* Fixed Footer Configuration */
.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: var(--footer-height); /* Control footer height */
    background-color: #333;
    color: #333;
    z-index: 1000;
}


.section-wrapper {
    scroll-margin-top: var(--main-header-height); /* Match your sticky header height */
}

/* Keep section headings closer to their content */
.section-wrapper h2 {
    margin-bottom: 0.5rem;
}

/* Control spacing around horizontal dividers */
hr {
    margin: 1rem 0;
}

.newsletter-section {
    scroll-margin-top: var(--main-header-height); /* Match your sticky header height */
}

.section-subtitle {
    text-indent: 2ch;
}

/* ==========================================================================
   3. RESPONSIVE TWO-COLUMN SIDEBAR LAYOUT
   ========================================================================== */
.layout-container {
    display: grid;
    grid-template-rows: auto 1fr auto; /* Header (auto), Content (fills remaining), Footer (auto) */
    flex-direction: column; /* Default vertical stack for mobile phones */
    height: auto;
    gap: 1rem;
    max-width: 1100px;
    margin: 1rem auto;
    padding-left: 1.5rem
}

.sidebar {
    width: 100%;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1.5rem;
}

.sidebar h3 {
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar li {
    margin-bottom: 0.75rem;
}

.sidebar a {
    color: var(--text-muted);
    cursor: pointer;
}

.sidebar a:hover {
    color: var(--accent-color);
}

.content-area {
    width: 100%;
    max-width: 65ch; /* Locks reading text width to prevent eye tracking fatigue */
    margin: 0 auto;
}


/* ==========================================================================
   4. PURE CSS RESPONSIVE BOOK GRID
   ========================================================================== */

/* 1. Main Container: Enforces a strict, centered single-column layout */
#live-book-grid.book-grid {
    display: grid !important;
    grid-template-columns: 1fr;
    gap: 2.5rem;
    max-width: 650px; /* Kept narrow so text doesn't stretch out too wide */
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

/* 2. Individual Cards: Stacked vertically by default (Mobile Layout) */
#live-book-grid .book-card {
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background-color: #ffffff;
    box-sizing: border-box;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    text-decoration: none; /* Clears default underline styles if wrapped in an anchor */
    color: inherit; /* Keeps your standard text colors intact */
}

/* Adds a clean interactive hover feedback effect */
#live-book-grid .book-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

/* 3. Hide the Amazon Buy Button entirely */
#live-book-grid .buy-button {
    display: none !important;
}

/* 4. Element Reordering: Forces specific items below the picture */
#live-book-grid .book-cover {
    order: 1; /* First element: Image */
    width: 100%;
    max-width: 220px; /* Keeps the book cover crisp and uniformly sized */
    height: auto;
    margin: 0 auto 1.25rem auto; /* Centers the cover and adds spacing below */
    border-radius: 4px;
}

#live-book-grid .book-title {
    order: 3; /* Third element: Main book title */
    text-align: center;
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.5rem;
}

#live-book-grid small {
    order: 2; /* Second element: Series title */
    display: block;
    text-align: center;
    margin-bottom: 0.25rem;
}

#live-book-grid .book-description {
    order: 4; /* Fourth element: Summary description text */
    text-align: left; /* Kept left-aligned for easier reading */
    margin: 0;
    line-height: 1.6;
}

/* 5. Wide Screen Switch (Desktop Layout) */
@media (min-width: 600px) {
    /* If you want the summary text to shift to the right side on wide viewports, 
       while leaving the image and titles neatly stacked on the left: */
    #live-book-grid .book-card {
        display: grid;
        grid-template-columns: 220px 1fr; /* 220px left column, remaining space right */
        gap: 2rem;
    }

    #live-book-grid .book-cover {
        grid-column: 1;
        grid-row: 1;
        margin-bottom: 0.5rem;
    }

    #live-book-grid small {
        grid-column: 1;
        grid-row: 2;
        text-align: center;
    }

    #live-book-grid .book-title {
        grid-column: 1;
        grid-row: 3;
        text-align: center;
        margin-bottom: 0;
    }

    #live-book-grid .book-description {
        grid-column: 2;
        grid-row: 1 / span 3; /* Stretches the text to occupy the full right height */
        align-self: start;
    }
}

.book-card:hover {
    transform: translateY(-4px);
    border-color: var(--accent-color);
}

.book-cover {
    width: 100%;
    aspect-ratio: 2 / 3; /* Matches physical book dimensions */
    background-color: var(--bg-main);
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}

.book-title {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
}

.book-description {
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 1.5rem;
    flex-grow: 1; /* Aligns all buy buttons perfectly along the bottom row */
}

.buy-button {
    display: inline-block;
    text-align: center;
    border: 1px solid var(--accent-color);
    padding: 0.6rem 1rem;
    border-radius: 4px;
    font-weight: 600;
}

.buy-button:hover {
    background-color: var(--accent-color);
    color: var(--bg-main); /* Flips typography text color against the golden background */
}


/* ========================================================
   BOOK CATALOG RENDERING FIX
   ======================================================== */
.book-card, a.book-card {
    /* Changes background from browser default white to dark obsidian */
    background-color: var(--bg-card, #18130f) !important;
    /* Applies a solid 2-pixel wide leather/bronze themed border outline */
    border: 2px solid var(--border-color, #42352b) !important;
    /* Text color and decoration resets */
    color: var(--text-primary, #ffffff) !important;
    text-decoration: none !important;
}

/* ========================================================
   STRICT FORCED LAYOUT SPACING OVERRIDES
   ======================================================== */

/* Media Column Container */
.book-media-column, a.book-media-column {
    display: block;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* Enforce physical stacking order regardless of HTML string positions */
.book-cover, a.book-cover {
    display: block !important;
    margin: 0 auto 12px auto !important;
    order: 1;
}

.book-title, a.book-title {
    display: block !important;
    margin: 0 auto 4px auto !important;
    order: 2;
    margin: 12px 0 4px 0;
    font-size: 1.1rem;
    max-width: 100%;
    word-wrap: break-word;
    text-align: center;
}

.book-series, a.book-series {
    display: block !important;
    margin: 0 auto !important;
    order: 3;
    font-style: italic;
    color: #666666;
    text-align: center;
}


/* ========================================================
DYNAMIC CARD INTERACTION: BRIGHTEN BORDER ON MOUSE OVER
======================================================== */
.book-card:hover, a.book-card:hover {
    /* Muted gold with built-in transparency to blend into the black background */
    border-color: #8c7355aa !important;
    /* Adds a soft, smoky lighting transition speed change */
    transition: border-color 0.1s ease-in-out !important;
}


/* ==========================================================================
   FREE CONTENT STORY GRID
   ========================================================================== */

#live-free-content-grid.free-content-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    max-width: 850px;
    width: 100%;
    margin: 1.5rem auto;
    box-sizing: border-box;
}

#live-free-content-grid .free-content-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1.5rem;
    background-color: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    text-decoration: none;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

    #live-free-content-grid .free-content-card:hover {
        border-color: var(--accent-color);
        transform: translateY(-2px);
    }

.free-content-title {
    font-size: 1.5rem;
    margin: 0 0 0.25rem;
    color: var(--accent-color);
}

.free-content-summary {
    margin: 0 0 0.75rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.free-content-latest-heading {
    margin: 0.5rem 0 0;
    font-size: 0.95rem;
    color: var(--accent-color);
}

.free-content-chapter-title {
    margin: 0;
    font-size: 1.05rem;
}

.free-content-chapter-blurb {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.6;
}

.free-content-date {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
}

.free-content-read-link {
    display: inline-block;
    align-self: flex-start;
    margin-top: 0.5rem;
    color: var(--accent-color);
}

.free-content-card:hover .free-content-read-link {
    color: var(--accent-hover);
}

@media (min-width: 600px) {
    #live-free-content-grid.free-content-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}



/* ==========================================================================
   5. SEMANTIC NEWSLETTER SIGN-UP CARD
   ========================================================================== */

.newsletter-section {
    margin: 5rem auto;
    max-width: 65ch;
}

.newsletter-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 2.5rem;
    text-align: center;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1.5rem;
}

#subscriber-email {
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    font-family: var(--font-main);
    font-size: 1rem;
    flex-grow: 1;
}

#subscriber-email:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.15); /* Soft gold halo focus effect */
}

#submit-btn {
    background-color: var(--accent-color);
    color: var(--bg-main);
    border: none;
    border-radius: 4px;
    padding: 0.75rem 1.5rem;
    font-family: var(--font-main);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

#submit-btn:hover {
    background-color: var(--accent-hover);
}

.hidden-field {
    display: none;
}

.form-message {
    font-size: 0.95rem;
    margin-top: 1rem;
    display: none;
}

.form-message.success {
    color: #27ae60;
    display: block;
}

.form-message.error {
    color: #eb5757;
    display: block;
}


/* ==========================================================================
   6. LARGESCREEN / DESKTOP WIDESCREEN ENHANCEMENTS
   ========================================================================== */

@media (min-width: 769px) {
    body {
        padding: 3rem;
    }

    .layout-container {
        flex-direction: row; /* Shifts serial text and menu sidebar side-by-side */
        gap: 4rem;
    }

    .sidebar {
        width: 250px;
        flex-shrink: 0;
        border-bottom: none;
        border-right: 1px solid var(--border-color);
        padding-bottom: 0;
        padding-right: 2rem;
        position: sticky; /* Keeps the table of contents floating as the user scrolls text */
        top: 3rem;
    }

    .form-group {
        flex-direction: row; /* Email input and button snap horizontal on desktop */
    }
}


/* ==========================================
   Pure CSS Checkbox Engine & Animations
   ========================================== */
.menu-toggle {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

/* Three line icon building block */
.hamburger {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 28px;
    height: 18px;
    cursor: pointer;
    z-index: 1002;
}

.hamburger .bar {
    display: block;
    width: 100%;
    height: 3px;
    background-color: #ffffff;
    border-radius: 2px;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Mobile Dropdown Styling Configuration */
.menu-links {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    background-color: #1a1a1a;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out;
}

.menu-links a {
    color: #ffffff;
    text-decoration: none;
    padding: 1rem 2rem;
    border-bottom: 1px solid #2a2a2a;
    transition: background 0.2s ease;
}

.menu-links a:hover {
    background-color: #2a2a2a;
}

/* ==========================================
   Interactive Interaction State (Checked)
   ========================================== */

/* Toggle menu slide down visibility */
.menu-toggle:checked ~ .menu-links {
    max-height: 400px; /* Safe bounds to display your links */
}

/* Transform icon to dynamic close dynamic visual */
.menu-toggle:checked ~ .hamburger .bar:nth-child(1) {
    transform: translateY(7.5px) rotate(45deg);
}

.menu-toggle:checked ~ .hamburger .bar:nth-child(2) {
    opacity: 0;
}

.menu-toggle:checked ~ .hamburger .bar:nth-child(3) {
    transform: translateY(-7.5px) rotate(-45deg);
}

/* ==========================================
   Responsive Viewport Scaling Framework
   ========================================== */
@media (min-width: 768px) {
    /* Hide structural visual helpers built for standard narrow viewports */
    .hamburger, .header-spacer {
        display: none;
    }

    /* Standard layout configuration swap back to typical wide format */
    #brand-title {
        position: static;
        transform: none;
    }

    .menu-links {
        display: flex;
        flex-direction: row;
        position: static;
        width: auto;
        max-height: none !important;
        overflow: visible;
        background-color: transparent;
    }

    .menu-links a {
        padding: 0 0.75rem;
        border-bottom: none;
    }

    .menu-links a:hover {
        background-color: transparent;
        text-decoration: underline;
    }




}


.subpage-content .markdown-viewer {
    scroll-margin-top: calc( var(--main-header-height) + var(--sub-header-height) + 16px );
}

/* Book-style paragraph formatting */
.subpage-content .markdown-viewer p {
    text-indent: 2em;
    margin-top: 0;
    margin-bottom: 0;
    line-height: 1.6;
}


/* ==========================================================
   GLOBAL FIX: Navigation links should only be as wide as text
   ========================================================== */

a.subpage-navigation-link {
    display: inline-block !important;
    width: fit-content !important;
    max-width: 100%;
    flex: 0 0 auto !important;
    justify-self: start;
    align-self: start;
    box-sizing: border-box;
}

/* Keep navigation links compact inside all content sections */
.layout-container > a.subpage-navigation-link {
    width: fit-content !important;
    justify-self: start;
    align-self: start;
}


.chapter-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

    .chapter-navigation a {
        font-size: 0.9rem;
        text-decoration: none;
    }

        .chapter-navigation a:hover {
            text-decoration: underline;
        }

.free-content-chapter {
    scroll-margin-top: calc( var(--main-header-height) + var(--subheader-height) + 20px );
}

/* Mobile pull-to-refresh indicator */
#pull-refresh-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999999;
    opacity: 0;
    transform: translate(-50%, -60px);
    pointer-events: none;
    transition: opacity 0.15s ease;
}

    #pull-refresh-indicator.visible {
        opacity: 1;
    }

    #pull-refresh-indicator .refresh-circle {
        width: 23px;
        height: 23px;
        border: 3px solid #d8d8d8;
        border-top-color: #1877f2;
        border-radius: 50%;
    }

    #pull-refresh-indicator.refreshing .refresh-circle {
        animation: pull-refresh-spin 0.7s linear infinite;
    }

@keyframes pull-refresh-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    #pull-refresh-indicator.refreshing .refresh-circle {
        animation-duration: 1.5s;
    }
}