:root {
    --bg-color: #0b0b0b;
    --card-bg: #141414;
    --text-color: #f0f0f0;
    --accent-color: #c5a059;
    --accent-hover: #e0bc7a;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 60px;
    --header-height: 60px;
    --font-serif: 'Cinzel', serif;
    --font-text: 'EB Garamond', serif;
    --font-sans: 'Inter', sans-serif;
    --transition: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Hide Sidebar on Library Page */
body.library-page .sidebar,
body.library-page .sidebar-overlay {
    display: none !important;
}

body.library-page .main-content {
    margin-left: 0 !important;
    width: 100% !important;
}

body.library-page .mobile-header {
    display: none !important;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-sans);
    line-height: 1.7;
    overflow-x: hidden;
    display: flex;
    min-height: 100vh;
}

@media (max-width: 1024px) {
    body {
        display: block !important;
        height: auto !important;
    }
}

/* Toggle switch languages */
body:not(.lang-es) .es,
body:not(.lang-en) .en,
body:not(.lang-it) .it,
body:not(.lang-zh) .zh,
body:not(.lang-ar) .ar,
body:not(.lang-ru) .ru,
body:not(.lang-de) .de,
body:not(.lang-fr) .fr,
body:not(.lang-ja) .ja,
body:not(.lang-pt) .pt,
body:not(.lang-vi) .vi {
    display: none !important;
}

body.lang-ar {
    direction: rtl;
}

/* Sidebar Navigation */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: #0f0f0f;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    z-index: 3000;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    pointer-events: auto !important;
}

body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.sidebar-logo {
    font-family: var(--font-serif);
    color: var(--accent-color);
    font-size: 1rem;
    letter-spacing: 2px;
    white-space: nowrap;
    overflow: hidden;
}

body.sidebar-collapsed .sidebar .sidebar-logo {
    display: none;
}

body.sidebar-collapsed .logo-link {
    display: none;
}

body.sidebar-collapsed .sidebar-header {
    justify-content: center;
}

.toggle-btn {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.3s;
    padding: 5px;
}

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

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0 0 20px 0;
    list-style: none;
    margin: 0;
}

.nav-item {
    margin-bottom: 2px;
}

.sidebar-nav .nav-item:first-child {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #0f0f0f;
    padding-top: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(197, 160, 89, 0.2);
    margin-bottom: 10px;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: #888;
    text-decoration: none;
    font-size: 0.9rem;
    transition: 0.2s;
    white-space: nowrap;
}

.nav-link i {
    min-width: 20px;
    font-style: normal;
    font-weight: bold;
    margin-right: 15px;
    text-align: center;
}

.nav-link span {
    transition: opacity 0.2s;
}

body.sidebar-collapsed .nav-link span {
    display: none;
}

body.sidebar-collapsed .nav-link i {
    margin-right: 0;
    font-size: 1.2rem;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.03);
    color: #fff;
}

.nav-link.active {
    color: var(--accent-color);
    background: rgba(197, 160, 89, 0.08);
    border-left: 3px solid var(--accent-color);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.03);
    font-size: 0.7rem;
    color: #444;
    text-align: center;
    white-space: nowrap;
}

/* Top-Right Controls Overlay (Glassmorphism + Golden Aura) */
.top-header-controls {
    position: fixed;
    top: 25px;
    right: 25px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 5000;
    /* Highest priority */
}

.library-quick-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 18px;
    height: 38px;
    border-radius: 40px;
    background: transparent !important;
    border: 1px solid rgba(197, 160, 89, 0.4);
    color: #fff;
    text-decoration: none;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    box-shadow: 0 0 15px rgba(197, 160, 89, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.library-quick-link:hover {
    border-color: var(--accent-color);
    box-shadow: 0 0 25px rgba(197, 160, 89, 0.5);
    background: rgba(197, 160, 89, 0.05) !important;
    transform: translateY(-1px);
}

.library-quick-link::before {
    content: '📚';
    font-size: 1rem;
}

.library-quick-link::after {
    content: 'BIBLIOTECA';
}

.lang-selector-elegant .lang-current-trigger {
    height: 38px;
    background: transparent !important;
    border: 1px solid rgba(197, 160, 89, 0.4);
    border-radius: 40px;
    color: #fff;
    padding: 0 15px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 0 15px rgba(197, 160, 89, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all 0.4s ease;
}

.lang-selector-elegant .lang-current-trigger:hover {
    border-color: var(--accent-color);
    box-shadow: 0 0 25px rgba(197, 160, 89, 0.5);
    background: rgba(197, 160, 89, 0.05) !important;
    transform: translateY(-1px);
}

@media (max-width: 768px) {
    .top-header-controls {
        top: 15px;
        right: 15px;
        gap: 8px;
    }
}

@media (max-width: 600px) {
    .library-quick-link::after {
        content: 'BIBLIO';
    }
}

@media (max-width: 420px) {
    .library-quick-link::after {
        display: none;
    }

    .library-quick-link {
        padding: 0 10px;
    }
}

@media (max-width: 380px) {
    .library-quick-link::after {
        display: none;
    }
}

.linktree-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    border: 1px solid rgba(197, 160, 89, 0.3);
    color: var(--accent-color);
    text-decoration: none;
    transition: 0.3s;
    background: rgba(197, 160, 89, 0.05);
}

.linktree-link:hover {
    background: var(--accent-color);
    color: #000;
    box-shadow: 0 0 15px rgba(197, 160, 89, 0.4);
}

.linktree-link svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.lang-selector-elegant {
    position: relative;
}

.lang-current-trigger {
    background: none;
    border: 1px solid rgba(197, 160, 89, 0.2);
    color: #bbb;
    padding: 8px 15px;
    border-radius: 4px;
    font-size: 0.75rem;
    letter-spacing: 1px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: 0.3s;
}

.lang-current-trigger:hover {
    border-color: var(--accent-color);
    color: #fff;
}

.lang-current-trigger .flag {
    font-size: 1.1rem;
}

.lang-dropdown-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: #181818;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 5px 0;
    min-width: 140px;
    display: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease-out;
}

.lang-dropdown-menu.show {
    display: block;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.lang-opt {
    padding: 10px 20px;
    color: #888;
    text-decoration: none;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: 0.2s;
}

.lang-opt:hover {
    background: #222;
    color: #fff;
}

.lang-opt.active {
    color: var(--accent-color);
    font-weight: 600;
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: var(--transition);
    min-width: 0;
}

body.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

/* Mobile Adjustments */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px !important;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        position: relative;
    }

    .chapter-card img {
        height: 100%;
        object-fit: cover;
    }

    .mobile-header {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 50px;
        background: #0b0b0b;
        display: flex;
        align-items: center;
        padding: 0 15px;
        z-index: 2000;
        border-bottom: 1px solid rgba(197, 160, 89, 0.3);
        direction: ltr !important;
        /* Force LTR at the bar level */
    }

    .mobile-header .toggle-btn {
        margin: 0 !important;
        padding: 5px !important;
        font-size: 1.5rem !important;
        color: var(--accent-color) !important;
        background: none !important;
        border: none !important;
        cursor: pointer !important;
    }

    .mobile-header .sidebar-logo {
        display: block !important;
        margin-left: 10px !important;
        font-size: 1rem !important;
        color: var(--accent-color) !important;
        font-family: var(--font-serif) !important;
        letter-spacing: 2px !important;
        opacity: 1 !important;
        visibility: visible !important;
        width: auto !important;
        height: auto !important;
    }

    .top-header-controls {
        position: absolute !important;
        right: 15px !important;
        top: 0 !important;
        height: 50px !important;
        display: flex !important;
        align-items: center !important;
        margin: 0 !important;
        z-index: 2010 !important;
    }

    .lang-selector-elegant {
        margin: 0 !important;
    }

    .lang-current-trigger {
        padding: 4px 8px !important;
        font-size: 0.8rem !important;
        background: rgba(255, 255, 255, 0.05) !important;
        border: 1px solid rgba(197, 160, 89, 0.3) !important;
    }

    .lang-current-trigger span:not(.flag) {
        display: none !important;
    }

    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.7);
        z-index: 1500;
        display: none;
    }

    body.sidebar-open .sidebar-overlay {
        display: block;
    }

    /* Mobile Text Alignment & Layout Fixes */
    .story-block,
    .connection-info,
    .moralina-text,
    .story-block p,
    .connection-info p {
        text-align: left !important;
    }

    .moral {
        font-size: 1.6rem !important;
        margin: 4rem 0 !important;
    }

    .story-block p:first-of-type::first-letter {
        font-size: 3.5rem;
    }

    /* Netflix-like Grid for Library on Mobile */
    .library-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
        padding: 0 !important;
    }

    .library-container {
        padding: 70px 15px !important;
    }

    .card-title {
        font-size: 0.8rem !important;
        margin-top: 5px !important;
    }

    .card-num {
        font-size: 0.6rem !important;
        letter-spacing: 1px !important;
    }

    .chapter-card {
        border-radius: 4px !important;
    }
}

/* --- Base Library Styles (Desktop & General) --- */
.library-container {
    padding: 100px 40px;
    max-width: 1400px;
    margin: 0 auto;
    text-align: center;
}

.library-title {
    text-align: center !important;
    width: 100%;
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    justify-content: center;
}

@media (min-width: 768px) {
    .library-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1025px) {
    .library-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        max-width: 1200px;
        margin: 0 auto;
    }
}

.chapter-card {
    position: relative;
    aspect-ratio: 16/9;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid rgba(197, 160, 89, 0.15); /* Subtle gold border */
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.4s;
    background: #101010;
    text-decoration: none;
    display: flex;
    flex-direction: column;
}

.chapter-card:hover {
    transform: translateY(-8px) scale(1.02);
    z-index: 10;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8), 0 0 30px rgba(197, 160, 89, 0.15); /* Deeper shadow with subtle gold glow */
    border-color: rgba(197, 160, 89, 0.4);
}

.chapter-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: brightness(0.6) saturate(0.85);
    transition: transform 0.7s cubic-bezier(0.2, 0.8, 0.2, 1), filter 0.4s ease;
}

.chapter-card:hover img {
    filter: brightness(0.9) saturate(1.1);
    transform: scale(1.05); /* Slight zoom on image hover */
}

.card-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 35px 20px 25px; /* Cover a bit more space vertically */
    background: linear-gradient(to top, rgba(10, 10, 10, 0.95) 0%, rgba(10, 10, 10, 0.85) 45%, transparent 100%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center; /* Center horizontally */
    text-align: center;
}

.card-num {
    font-family: var(--font-serif);
    font-size: 0.9rem; /* Larger chapter number */
    color: var(--accent-color);
    letter-spacing: 3px; /* Wider tracking */
    margin-bottom: 8px;
    display: block;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    opacity: 0.95;
}

.card-title {
    font-family: var(--font-serif);
    font-size: 1.4rem; /* Slightly larger title */
    margin: 0;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
    line-height: 1.2;
    width: 100%; /* Occupy full width */
}

/* Hero Section Refinement */
.hero-section {
    position: relative;
    height: 100vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#hero-img {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: brightness(0.4) saturate(0.8);
    transform-origin: center;
    transition: 1s ease-out;
}

.hero-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, transparent 40%, var(--bg-color) 95%);
}

.hero-content {
    z-index: 10;
    text-align: center;
    max-width: 900px;
    padding: 0 40px;
}

.chapter-num {
    font-family: var(--font-serif);
    font-size: 0.9rem;
    letter-spacing: 12px;
    color: var(--accent-color);
    margin-bottom: 30px;
}

.chapter-title {
    font-family: var(--font-serif);
    font-size: clamp(2.5rem, 8vw, 4.5rem);
    margin: 0;
    line-height: 1;
    text-transform: uppercase;
}

/* Story Content Refinement (Premium) */
.story-container {
    max-width: 750px;
    margin: 0 auto;
    padding: 6rem 2.5rem 10rem;
}

.story-block {
    font-family: var(--font-text);
    font-size: 1.7rem;
    color: #d0d0d0;
    margin-bottom: 6rem;
    line-height: 1.6;
}

/* Drop Cap (for premium feel) */
.story-block p:first-of-type::first-letter,
.story-block p.active-dropcap::first-letter {
    float: left;
    font-family: var(--font-serif);
    font-size: 5rem;
    line-height: 1;
    margin: 10px 15px 5px 0;
    color: var(--accent-color);
}

.story-block blockquote {
    border-left: 1px solid var(--accent-color);
    padding: 10px 0 10px 40px;
    margin: 5rem 0;
    font-style: italic;
    color: #fff;
    font-size: 2rem;
}

.connection-info {
    background: var(--card-bg);
    padding: 4rem;
    border-radius: 2px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    margin: 8rem 0;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.4);
}

.connection-info h3 {
    font-family: var(--font-serif);
    font-size: 1rem;
    color: var(--accent-color);
    letter-spacing: 3px;
    margin-bottom: 30px;
}

.connection-info p {
    font-size: 1.35rem;
    opacity: 0.9;
}

.moral {
    font-family: var(--font-text);
    font-size: 2.5rem;
    text-align: center;
    color: #fff;
    margin-top: 10rem;
    opacity: 0.9;
}

.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background: var(--accent-color);
    z-index: 2000;
}

.fade-in {
    opacity: 0;
    transform: translateY(40px);
    transition: 1s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Story Illustration Blocks (Introduction & Chapters) */
.story-block+.connection-info {
    margin: 2rem 0;
}

@media (max-width: 768px) {
    .story-container [style*="display: flex"] {
        flex-direction: column !important;
        gap: 20px !important;
    }

    .story-container [style*="flex: 0 0 200px"] {
        flex: none !important;
        width: 100% !important;
        max-width: 300px !important;
        margin: 0 auto !important;
    }
}

/* Story Section Titles */
.section-title {
    font-family: 'Cinzel', serif;
    font-size: 1.8rem;
    color: var(--accent-color);
    margin: 3rem 0 1.5rem 0;
    letter-spacing: 2px;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(197, 160, 89, 0.2);
    padding-bottom: 0.5rem;
    display: block;
}

.fade-in.is-visible {
    opacity: 1;
    transform: translateY(0);
}