/* Wild Rose Writers Platform - Main Stylesheet */

/* Default Theme Variables (Light) */
:root {
    --bg-body: linear-gradient(135deg, #f5f7fa 0%, #fafbfc 100%);
    --bg-page: #ffffff;
    --text-main: #333333;
    --text-muted: #666666;
    --border-color: #e1e8ed;
    --shadow-color: rgba(0,0,0,0.08);
    --primary-color: #667eea;
    --secondary-color: #764ba2;
    --code-bg: #f5f5f5;
    --quote-bg: linear-gradient(135deg, #f0f7ff 0%, #f5f9ff 100%);
    --quote-border: #2196F3;
    --quote-text: #2c3e50;
    --nav-icon-color: white;
}

/* Sepia Theme */
[data-theme="sepia"] {
    --bg-body: #f4ecd8;
    --bg-page: #fdf6e3;
    --text-main: #5b4636;
    --text-muted: #8f7e6d;
    --border-color: #d3c4b1;
    --shadow-color: rgba(91, 70, 54, 0.1);
    --primary-color: #a67c52;
    --secondary-color: #8c6b4a;
    --code-bg: #eee8d5;
    --quote-bg: #f5efdc;
    --quote-border: #a67c52;
    --quote-text: #5b4636;
    --nav-icon-color: #fdf6e3;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-body: #1a1a1a;
    --bg-page: #2d2d2d;
    --text-main: #e0e0e0;
    --text-muted: #a0a0a0;
    --border-color: #404040;
    --shadow-color: rgba(0,0,0,0.3);
    --primary-color: #8ba1f0;
    --secondary-color: #a478d6;
    --code-bg: #404040;
    --quote-bg: #383838;
    --quote-border: #8ba1f0;
    --quote-text: #d0d0d0;
    --nav-icon-color: white;
}

body {
    background: var(--bg-body);
    min-height: 100vh;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-main);
    transition: background 0.3s, color 0.3s;
}

.page-wrapper {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    
    padding-top: 80px;background: var(--bg-page);
    box-shadow: 0 0 20px var(--shadow-color);
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    min-height: 100vh;
    position: relative;
    transition: background 0.3s, border-color 0.3s;
}

/* =============================================
   Top-left Brand + Main Menu
   ============================================= */
.settings-dropdown {
    position: relative;
    display: inline-block;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Brand cluster (logo + title + menu container) */
.wr-top-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    position: fixed; /* stay at window top-left */
    top: 0;
    left: 0;
    z-index: 12000;
    padding: 10px 12px;
    background: var(--bg-page);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 6px 18px rgba(0,0,0,0.08);
    flex-wrap: wrap;
    max-width: calc(100vw - 260px);
}



.header-nav-icons {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 14000;
    padding: 10px 12px;
    display: flex;
    gap: 6px;
    align-items: center;
    background: var(--bg-page);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 6px 18px rgba(0,0,0,0.08);
}

.book-title {
    position: fixed;
    top: 50px;
    left: 0;
    right: 0;
    z-index: 13500;

    /* Artistic title style (default: Elegance) */
    font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    font-size: 24px;
    font-weight: 400;          /* unbold */
    font-style: italic;
    letter-spacing: 0.02em;
    text-rendering: optimizeLegibility;
    font-variant-ligatures: common-ligatures;

    color: var(--text-main);
    text-align: center;
    line-height: 1.2;
    padding: 6px 12px 0;

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Optional alternate artistic presets.
   To use: add one of these classes to <body>:
   - title-style-elegance
   - title-style-harmony
*/
body.title-style-elegance .book-title {
    font-family: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    font-style: italic;
    letter-spacing: 0.02em;
}

body.title-style-harmony .book-title {
    font-family: Garamond, "EB Garamond", "Times New Roman", Times, serif;
    font-style: normal;
    letter-spacing: 0.01em;
}


.wr-brand-text {
    
    font-size: 1.05rem;
    color: var(--text-main);
    white-space: nowrap;

  font-size: 10px;
  color: #1a9b2d;
  font-weight: 400;
}


#wrTranslateSlot {
    width: 300px;
    flex: 0 0 300px;   /* prevents shrinking */
    display: flex;
    align-items: center;
    gap: 0.4rem;
    position: relative;
    z-index: 12001;
}

/* Logo (acts as the menu toggle) */
.wr-logo-btn {
    display: block;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    transition: transform 0.2s;
    border-radius: 50%;
}

.wr-logo-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.wr-logo-btn:hover {
    transform: scale(1.1);
}

.wr-logo-btn:active {
    transform: scale(0.95);
}

/* Container where JS injects the dropdown */
#mainMenuContainer {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10001;
}

/* The Dropdown Panel */
.settings-dropdown-menu {
    position: fixed;               /* anchor to window */
    top: 64px;                     /* below the top-left header area */
    left: 5em;                     /* ~5em from window left edge */
    right: auto;
    max-width: calc(100vw - 5em - 20px); /* never overflow viewport */
    box-sizing: border-box;
    background: var(--bg-page);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    z-index: 10000;
    display: none;
    width: 260px;                  /* Fixed width */
    padding: 0;
    overflow: visible;
    text-align: left;
}

.settings-dropdown-menu.show {
    display: block;
    animation: dropdownFadeIn 0.2s ease;
}

@keyframes dropdownFadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Menu Sections */
.menu-section {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
}

.menu-section:last-child {
    border-bottom: none;
    background: var(--code-bg); /* Contrast for help section */
}

.menu-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
    display: block;
}

/* Theme Controls Row */
.visual-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.theme-controls {
    display: flex;
    gap: 8px;
}

.theme-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: transform 0.2s, border-color 0.2s;
    background: transparent;
    padding: 0;
}
.theme-btn:hover { transform: scale(1.1); }
.theme-btn.active { border-color: var(--primary-color); }
.theme-btn.light { background: #fff; border-color: #ddd; }
.theme-btn.sepia { background: #fdf6e3; border-color: #d3c4b1; }
.theme-btn.dark { background: #333; border-color: #555; }
.theme-btn.light.active { border-color: var(--primary-color); }
.theme-btn.sepia.active { border-color: #a67c52; }
.theme-btn.dark.active { border-color: #8ba1f0; }

/* Font Size Controls */
.font-size-controls {
    display: flex;
    gap: 5px;
}

.font-size-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-page);
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.2s;
}

.font-size-btn:hover {
    background: var(--code-bg);
    border-color: var(--primary-color);
}

.font-size-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Help Buttons */
.help-links {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.help-btn {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-page);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
}

.help-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: white;
}

.help-icon {
    margin-right: 8px;
    font-size: 16px;
}

/* Header & Navigation */
.page-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    padding: 12px 20px 12px 0;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 30px;
}

.page-header.library-header {
    justify-content: flex-start;
    gap: 10px;
    margin-bottom: 20px;
}

.header-center-title {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 12px;
}

.page-title-inline {
    font-weight: 700;
    color: var(--text-main);
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 40vw;
}

.header-back {
    text-decoration: none;
    font-size: 1.2em;
    line-height: 1;
}

.header-nav-icons, .footer-nav-icons {
    display: flex;
    gap: 15px;
    align-items: center;
    justify-content: center;
}


/* Footer navigation wrapper (page counter + icons) */
.footer-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 10px 16px;
}

.footer-nav .page-number-display {
    white-space: nowrap;
    flex: 0 0 auto;
    margin-right: 15px;
}

.footer-nav .footer-nav-icons {
    flex: 0 0 auto;
    justify-content: center;
}

.nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--nav-icon-color);
    text-decoration: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: bold;
    transition: all 0.3s;
    cursor: pointer;
    border: none;
    padding: 0;
}

.nav-icon:hover:not(.disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.nav-icon.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
    background: #ccc;
}


/* Ensure any disabled navigation item is truly non-interactive (even if it's not a .nav-icon) */
[data-role].disabled,
[data-role][aria-disabled="true"] {
    pointer-events: none;
    cursor: not-allowed;
}

.page-number-display {
    font-size: 14px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Reader UI helpers */
.header-page-counter {
    white-space: nowrap;
    font-weight: 700;
    font-size: 13px;
    opacity: 0.85;
    margin-right: 15px;
    margin-left: 0;
}

.wr-hidden {
    display: none !important;
}

/* Standard error message styling for content fetch failures */
.wr-error-message {
    color: #c62828;
    text-align: center;
    font-weight: 600;
    margin: 16px 0;
}

/* Main menu (dropdown) list reset */
.mainmenu-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Allow .help-btn to be used on <a> without underlines */
.help-btn {
    text-decoration: none;
}

/* Slight emphasis for important menu items */
.help-btn--strong {
    font-weight: 600;
}


/* Content Typography */
.content {
    max-width: 750px;
    margin: 0 auto;
    line-height: 1.8;
    color: var(--text-main);
}

.content h1 {
    color: var(--text-main);
    font-size: 2.2em;
    margin: 0 0 20px 0;
    padding-bottom: 15px;
    border-bottom: 3px solid var(--primary-color);
}

.content h2 {
    color: var(--primary-color);
    font-size: 1.6em;
    margin: 30px 0 15px 0;
    padding-left: 15px;
    border-left: 5px solid var(--secondary-color);
}

.content h3 {
    color: var(--secondary-color);
    font-size: 1.2em;
    margin: 20px 0 10px 0;
}

.content p { margin-bottom: 15px; }

.content strong { color: var(--primary-color); font-weight: 600; }

.content blockquote {
    background: var(--quote-bg);
    border-left: 5px solid var(--quote-border);
    margin: 25px 0;
    padding: 20px 25px;
    font-size: 1.1em;
    font-style: italic;
    color: var(--quote-text);
    border-radius: 5px;
}

.content img {
    max-width: 100%;
    height: auto;
    margin: 20px 0;
    border-radius: 6px;
    box-shadow: 0 2px 8px var(--shadow-color);
}

/* Code Blocks */
.content code {
    background: var(--code-bg);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    color: #d63384;
}

.content pre {
    background: var(--code-bg);
    padding: 15px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 15px 0;
    border-left: 4px solid var(--primary-color);
}

.content pre code {
    background: none;
    padding: 0;
    color: var(--text-main);
}

/* Loading State */
.loading {
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.2s;
}

/* Utilities */

/* =============================================
   Table of Contents (Auto-generated)
   ============================================= */
.toc-container {
    max-width: 100%;
}

.toc-container h1 {
    color: var(--text-main);
    font-size: 1.8em;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 3px solid var(--primary-color);
}

.toc-item {
    padding: 12px 15px;
    margin: 4px 0;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s;
    background: var(--bg-page);
}

.toc-item:hover {
    background: var(--code-bg);
    transform: translateX(5px);
}

.toc-item.toc-intro {
    font-weight: 500;
    color: var(--primary-color);
}

.toc-page-number {
    min-width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
}

.toc-title {
    flex: 1;
    color: var(--text-main);
}

.toc-section {
    margin: 20px 0;
}

.toc-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 18px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 1.1em;
    transition: all 0.2s;
}

.toc-section-header:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.toc-section-title {
    flex: 1;
}

.toc-arrow {
    font-size: 12px;
    transition: transform 0.3s;
}

.toc-section-header.expanded .toc-arrow {
    transform: rotate(90deg);
}

.toc-section-pages {
    display: none;
    padding: 10px 0 10px 20px;
    border-left: 3px solid var(--primary-color);
    margin-left: 15px;
    margin-top: 8px;
}

.toc-section-pages.show {
    display: block;
    animation: tocSlideDown 0.3s ease;
}

@keyframes tocSlideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .page-wrapper {
        padding: 15px;
        padding-top: 75px;
        box-shadow: none;
        border: none;
    }
    .content h1 { font-size: 1.8em; }
    .content h2 { font-size: 1.4em; }
    
    /* Keep the main menu working at all widths (avoid fixed positioning quirks). */
    .settings-dropdown-menu {
    position: fixed;               /* anchor to window */
    top: 64px;                     /* below the top-left header area */
    left: 5em;                     /* ~5em from window left edge */
    right: auto;
    max-width: calc(100vw - 5em - 20px); /* never overflow viewport */
    box-sizing: border-box;
    background: var(--bg-page);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    z-index: 10000;
    display: none;
    width: 260px;                  /* Fixed width */
    padding: 0;
    overflow: hidden;
    text-align: left;
}

/* -------------------------------------------------------------------------- */
/* Library page: book cards with covers                                        */
/* -------------------------------------------------------------------------- */

.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin-top: 18px;
    padding: 8px 0;
}

.book-card {
    display: flex;
    align-items: flex-start;
    gap: 16px;

    padding: 14px 14px;
    text-decoration: none;

    background: var(--bg-page);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 8px 24px var(--shadow-color);

    transition: transform 120ms ease, box-shadow 120ms ease;
}

.book-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px var(--shadow-color);
}

.book-cover-box {
    width: 100px;
    flex: 0 0 100px;

    display: flex;
    align-items: flex-start;
    justify-content: center;

    border-radius: 12px;
    overflow: hidden;
    background: var(--code-bg);
    border: 1px solid var(--border-color);
}

.book-cover {
    width: 100px;
    height: auto;              /* scale proportionally to width */
    max-height: 160px;         /* safety cap */
    object-fit: contain;       /* keep proportions, no cropping */
    display: block;
}

.book-cover-placeholder {
    width: 100px;
    height: 133px; /* ~3:4 default reserved space */
    display: flex;
    align-items: center;
    justify-content: center;

    font-size: 42px;
    line-height: 1;
    opacity: 0.85;
}

.book-meta {
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
}

.book-name {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.25;
    word-break: break-word;
}

/* Slightly tighter cards on small screens */
@media (max-width: 520px) {
    .book-card {
        gap: 12px;
        padding: 12px;
    }
    .book-cover-box {
        width: 90px;
        flex-basis: 90px;
    }


.book-cover {
    width: 90px;
    max-height: 144px;
}

.book-cover-placeholder {
    width: 90px;
    height: 120px;
}
}
