/* ============================================
   FONT: Vazirmatn (Persian)
   ============================================ */
@import url('https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.0.3/Vazirmatn-font-face.css');

/* ============================================
   FONT: JetBrains Mono (Code + English)
   ============================================ */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&display=swap');

/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
    --bg: #faf8f3;
    --bg-warm: #f5f0e8;
    --text: #2c2416;
    --text-light: #6b5e4a;
    --text-muted: #9c8b72;
    --heading: #1a1208;
    --gold: #c4964c;
    --gold-light: #e0c87d;
    --gold-dark: #8b6520;
    --accent: #2c3e50;
    --card-bg: #fffdf9;
    --card-border: #e5dccf;
    --divider: #d4c8b0;
    --code-bg: #f0ebe0;
    --sidebar-bg: #1a1a2e;
    --sidebar-text: #aaa;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.06);
    --radius-sm: 6px;
    --radius-md: 10px;
    --font-fa: 'Vazirmatn', Tahoma, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    font-family: var(--font-fa);
    background: var(--bg);
    color: var(--text);
    line-height: 2.1;
    font-size: 17px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    direction: rtl;
    text-align: right;
    display: flex;
    min-height: 100vh;
}

/* ============================================
   TYPOGRAPHY
   ============================================ */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-fa);
    font-weight: 700;
    color: var(--heading);
}
h1 { font-size: 2.4em; line-height: 1.5; }
h2 { font-size: 1.8em; line-height: 1.5; margin-top: 45px; }
h3 { font-size: 1.25em; line-height: 1.6; color: var(--accent); margin-top: 28px; }
p { margin-bottom: 1.1em; }
a { color: var(--gold-dark); text-decoration: none; border-bottom: 1px solid transparent; transition: all 0.25s; }
a:hover { color: var(--gold); border-bottom-color: var(--gold-light); }
code {
    font-family: var(--font-mono);
    font-size: 0.88em;
    background: var(--code-bg);
    padding: 2px 7px;
    border-radius: 4px;
    color: var(--accent);
    direction: ltr;
    display: inline-block;
    unicode-bidi: embed;
}
.ltr { direction: ltr; display: inline-block; unicode-bidi: embed; }
blockquote {
    font-family: var(--font-fa);
    font-size: 1.1em;
    color: var(--text-light);
    border-right: 3px solid var(--gold);
    padding: 18px 25px;
    margin: 25px 0;
    background: rgba(196, 150, 76, 0.04);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
ul, ol { margin: 15px 22px 20px 0; }
li { margin-bottom: 8px; }

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 30px 20px;
    position: fixed;
    top: 0; right: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s ease;
}
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}
.sidebar h2 {
    color: var(--gold);
    font-size: 1.1em;
    text-align: center;
    flex: 1;
    margin-top: 0;
}
.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: #aaa;
    font-size: 1.5em;
    cursor: pointer;
}
.sidebar ul { list-style: none; padding: 0; margin: 0; }
.sidebar ul li { margin-bottom: 4px; }
.sidebar ul li a {
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.85em;
    display: block;
    padding: 7px 12px;
    border-radius: 4px;
    transition: all 0.2s;
    border-right: 2px solid transparent;
    border-bottom: none;
}
.sidebar ul li a:hover,
.sidebar ul li a.active {
    color: var(--gold);
    background: rgba(255,255,255,0.05);
    border-right-color: var(--gold);
}
.sidebar .part-title {
    color: var(--gold-light);
    font-weight: bold;
    margin-top: 22px;
    margin-bottom: 8px;
    font-size: 0.78em;
    letter-spacing: 1px;
    opacity: 0.8;
}

/* Sidebar overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

/* ============================================
   TOP BAR (mobile)
   ============================================ */
.topbar {
    display: none;
    position: sticky;
    top: 0;
    background: var(--bg);
    padding: 12px 15px;
    border-bottom: 1px solid var(--divider);
    z-index: 50;
    align-items: center;
    justify-content: space-between;
}
.hamburger {
    background: none; border: none;
    font-size: 1.5em; cursor: pointer;
    color: var(--text);
}
.topbar-title {
    font-weight: bold;
    color: var(--heading);
    font-size: 0.9em;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.theme-toggle {
    background: none; border: none;
    font-size: 1.3em; cursor: pointer;
    color: var(--text);
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
    margin-right: 280px;
    padding: 40px 50px;
    max-width: 900px;
    width: 100%;
    min-height: 100vh;
}

/* ============================================
   BOOK COVER
   ============================================ */
.book-cover {
    text-align: center;
    padding: 80px 20px 60px;
    border-bottom: 1px solid var(--divider);
    margin-bottom: 40px;
}
.book-cover h1 {
    font-size: 3em;
    margin-bottom: 10px;
}
.book-cover .subtitle {
    font-size: 1.2em;
    color: var(--text-light);
    font-style: italic;
    margin-bottom: 15px;
}
.book-cover .ornament {
    color: var(--gold);
    font-size: 0.6em;
    letter-spacing: 8px;
    margin: 15px 0;
}
.cover-btn {
    display: inline-block;
    padding: 14px 32px;
    background: var(--accent);
    color: #fff !important;
    border-radius: 50px;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.05em;
    border-bottom: none;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(44,62,80,0.2);
    margin-top: 20px;
}
.cover-btn:hover {
    background: #1a2d3d;
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(44,62,80,0.3);
}

/* ============================================
   CHAPTER CONTENT
   ============================================ */
.chapter-content {
    padding: 20px 0;
}
.chapter-header {
    text-align: center;
    margin-bottom: 40px;
}
.chapter-section {
    font-size: 0.82em;
    color: var(--text-muted);
    letter-spacing: 2px;
    margin-bottom: 10px;
}
.chapter-title {
    font-size: 2.2em;
    font-weight: 700;
    color: var(--heading);
    margin-bottom: 8px;
}
.chapter-subtitle {
    font-size: 1.1em;
    color: var(--text-light);
    font-style: italic;
}

/* Chapter content elements */
.chapter-content h2 {
    font-size: 1.7em;
    border-bottom: 2px solid var(--gold);
    padding-bottom: 8px;
    margin: 45px 0 20px;
}
.chapter-content h3 {
    font-size: 1.2em;
    color: var(--accent);
    margin: 30px 0 12px;
}
.chapter-content p { text-align: justify; }
.chapter-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 25px 0;
    font-size: 0.9em;
}
.chapter-content thead th {
    background: var(--accent);
    color: #fff;
    padding: 12px 15px;
    text-align: right;
    font-weight: 700;
    font-size: 0.85em;
    letter-spacing: 1px;
}
.chapter-content thead th:first-child { border-radius: 0 var(--radius-sm) 0 0; }
.chapter-content thead th:last-child { border-radius: var(--radius-sm) 0 0 0; }
.chapter-content tbody td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--card-border);
    vertical-align: top;
}
.chapter-content tbody tr:hover td { background: rgba(196,150,76,0.03); }
.chapter-content blockquote {
    font-size: 1.05em;
}

/* Insight box */
.insight-box {
    background: var(--bg-warm);
    border: 1px solid var(--divider);
    border-radius: var(--radius-md);
    padding: 25px 30px;
    margin: 30px 0;
}
.insight-box strong { color: var(--gold-dark); }

/* Core claim */
.core-claim {
    background: var(--accent);
    color: #fff;
    padding: 25px 30px;
    margin: 30px 0;
    border-radius: var(--radius-md);
}
.core-claim h2, .core-claim h3 { color: var(--gold) !important; }
.core-claim p, .core-claim li { color: #ddd; }

/* Question highlight */
.question {
    font-size: 1.15em;
    font-weight: 700;
    color: var(--accent);
    text-align: center;
    margin: 30px 0;
    padding: 15px;
    background: rgba(196,150,76,0.1);
    border-radius: var(--radius-sm);
}

/* Preview */
.preview {
    background: rgba(196,150,76,0.06);
    border: 1px dashed var(--gold);
    border-radius: var(--radius-md);
    padding: 20px 25px;
    margin: 40px 0 20px;
}
.preview h2 { color: var(--gold); border-bottom: none; margin-top: 0; }

/* Code block */
.code-block {
    margin: 20px 0;
    direction: ltr;
    text-align: left;
}
.code-block pre {
    background: #1e1e2e;
    color: #cdd6f4;
    padding: 18px 22px;
    border-radius: var(--radius-md);
    overflow-x: auto;
    font-size: 0.85em;
    line-height: 1.7;
    font-family: var(--font-mono);
}
.code-block code { background: none; padding: 0; color: inherit; }

/* Scene box */
.scene {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-md);
    padding: 25px 30px;
    margin: 30px 0;
    box-shadow: var(--shadow-sm);
}

/* ============================================
   CHAPTER NAVIGATION
   ============================================ */
.chapter-nav {
    display: none;
    justify-content: space-between;
    align-items: center;
    padding: 25px 0;
    margin-top: 50px;
    border-top: 1px solid var(--divider);
    gap: 15px;
}
.nav-btn {
    display: inline-block;
    padding: 14px 24px;
    border: 1px solid var(--divider);
    border-radius: var(--radius-md);
    color: var(--text);
    text-decoration: none;
    transition: all 0.3s;
    cursor: pointer;
    font-family: var(--font-fa);
    font-size: 0.9em;
    background: var(--card-bg);
    max-width: 45%;
    text-align: center;
    border-bottom: 1px solid var(--divider);
}
.nav-btn:hover {
    border-color: var(--gold);
    color: var(--gold);
    background: rgba(196,150,76,0.05);
}
.nav-btn.hidden { visibility: hidden; }
.progress-indicator {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85em;
}

/* ============================================
   FOOTER
   ============================================ */
.book-footer {
    text-align: center;
    padding: 40px 20px;
    margin-top: 60px;
    border-top: 1px solid var(--divider);
    color: var(--text-muted);
    font-size: 0.85em;
}
.book-footer a { color: var(--gold-dark); border-bottom: none; }

/* ============================================
   LOADING & ERROR
   ============================================ */
.loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 1.1em;
}
.error {
    text-align: center;
    padding: 60px 20px;
    color: #c0392b;
}
.error-detail {
    font-size: 0.85em;
    color: var(--text-muted);
    margin-top: 10px;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-close { display: block; }
    .sidebar-overlay.active { display: block; }
    .main-content {
        margin-right: 0;
        padding: 15px;
    }
    .topbar { display: flex; }
    .book-cover { padding: 50px 15px 40px; }
    .book-cover h1 { font-size: 2em; }
    .chapter-title { font-size: 1.6em; }
    .chapter-nav {
        flex-direction: column;
        gap: 10px;
    }
    .nav-btn {
        max-width: 100%;
        text-align: center;
    }
}