/* ═══════════════════════════════════════════════════════════
   RL Notes Series — Chapter Styles
   Extends: ../research-style.css
   ═══════════════════════════════════════════════════════════ */

/* ── Reading Progress Bar ── */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: linear-gradient(90deg, #6e46be, #b088f9);
    z-index: 1000;
    transition: width 0.15s ease-out;
}

/* ── Series Nav (breadcrumb + chapter meta) ── */
.series-breadcrumb {
    font-size: 0.8rem;
    color: #888;
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}

.series-breadcrumb a {
    color: #888;
    text-decoration: none;
    transition: color 0.2s;
}

.series-breadcrumb a:hover {
    color: #6e46be;
}

.series-breadcrumb .sep {
    margin: 0 6px;
    opacity: 0.5;
}

/* ── Chapter Header ── */
.chapter-header {
    text-align: center;
    margin-bottom: 48px;
    padding-bottom: 32px;
    border-bottom: 1px solid #eee;
}

.chapter-number {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #6e46be;
    background: rgba(110, 70, 190, 0.08);
    padding: 4px 14px;
    border-radius: 20px;
    margin-bottom: 16px;
}

.chapter-header h1 {
    font-size: 1.9rem;
    font-weight: 700;
    color: #111;
    margin: 12px 0 16px;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

.chapter-meta {
    color: #888;
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.chapter-meta .dot {
    font-size: 0.5rem;
    opacity: 0.4;
}

/* ── Content Layout (with sidebar TOC) ── */
.content-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    max-width: 100%;
    position: relative;
}

@media (min-width: 1100px) {
    .content-layout {
        grid-template-columns: 1fr 200px;
        gap: 40px;
    }
}

/* ── Sticky Table of Contents ── */
.toc-sidebar {
    display: none;
}

@media (min-width: 1100px) {
    .toc-sidebar {
        display: block;
        position: relative;
    }

    .toc-inner {
        position: sticky;
        top: 24px;
        max-height: calc(100vh - 48px);
        overflow-y: auto;
        padding-right: 8px;
    }

    .toc-inner::-webkit-scrollbar {
        width: 2px;
    }

    .toc-inner::-webkit-scrollbar-thumb {
        background: #ddd;
        border-radius: 4px;
    }
}

.toc-title {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #aaa;
    margin-bottom: 12px;
}

.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-list li {
    margin-bottom: 6px;
}

.toc-list a {
    font-size: 0.72rem;
    color: #999;
    text-decoration: none;
    display: block;
    padding: 3px 0 3px 10px;
    border-left: 2px solid transparent;
    transition: all 0.2s;
    line-height: 1.4;
}

.toc-list a:hover {
    color: #6e46be;
}

.toc-list a.active {
    color: #6e46be;
    border-left-color: #6e46be;
    font-weight: 500;
}

/* ── Article Content ── */
.chapter-content {
    max-width: 100%;
    overflow-x: hidden;
}

.chapter-content h2 {
    font-size: 1.3rem;
    font-weight: 700;
    color: #111;
    margin-top: 2.5em;
    margin-bottom: 0.8em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid #eee;
    scroll-margin-top: 20px;
}

.chapter-content h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: #222;
    margin-top: 1.8em;
    margin-bottom: 0.5em;
    scroll-margin-top: 20px;
}

.chapter-content h4 {
    font-size: 0.92rem;
    font-weight: 700;
    color: #333;
    margin-top: 1.5em;
    margin-bottom: 0.4em;
}

.chapter-content p {
    margin-bottom: 1.2em;
    text-align: justify;
    hyphens: auto;
}

.chapter-content ul,
.chapter-content ol {
    margin-bottom: 1.2em;
    padding-left: 1.5em;
}

.chapter-content li {
    margin-bottom: 0.4em;
    line-height: 1.6;
}

.chapter-content a {
    color: #6e46be;
    text-decoration: none;
    border-bottom: 1px dotted rgba(110, 70, 190, 0.3);
    transition: border-color 0.2s;
}

.chapter-content a:hover {
    border-bottom-color: #6e46be;
}

/* ── Blockquotes (callouts) ── */
.chapter-content blockquote {
    border-left: 3px solid #6e46be;
    margin: 1.5em 0;
    padding: 12px 20px;
    background: rgba(110, 70, 190, 0.04);
    border-radius: 0 6px 6px 0;
    font-style: italic;
    color: #555;
}

/* ── Code Blocks ── */
.chapter-content pre {
    background: #f6f8fa;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    padding: 16px 20px;
    overflow-x: auto;
    font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
    font-size: 0.82rem;
    line-height: 1.55;
    margin: 1.5em 0;
    position: relative;
}

.chapter-content code {
    font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
    font-size: 0.85em;
}

.chapter-content p code,
.chapter-content li code {
    background: rgba(110, 70, 190, 0.06);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.82em;
    color: #555;
}

/* Copy button for code blocks */
.code-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.68rem;
    color: #475569;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
    font-family: inherit;
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.chapter-content pre:hover .code-copy-btn {
    opacity: 1;
}

.code-copy-btn:hover {
    background: #6e46be;
    color: #ffffff;
    border-color: #6e46be;
}

.code-copy-btn.copied {
    background: #2e7d32;
    color: #fff;
    border-color: #2e7d32;
}

/* Chapter Cross-Links */
.chapter-link {
    color: #6e46be;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
    font-weight: 600;
    transition: color 0.15s ease;
}

.chapter-link:hover {
    color: #5a37a3;
    text-decoration-style: solid;
}

/* ── Tables ── */
.chapter-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
    font-size: 0.85rem;
    border: none;
    table-layout: auto;
}

.chapter-content thead th {
    text-align: left;
    font-weight: 600;
    font-size: 0.78rem;
    color: #555;
    padding: 10px 12px;
    border-bottom: 2px solid #e0e0e0;
    background: #fafafa;
}

.chapter-content tbody td {
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: top;
}

.chapter-content tbody tr:hover {
    background: rgba(110, 70, 190, 0.02);
}

/* ── Math (KaTeX overrides) ── */
.katex-display {
    text-align: center !important;
    margin: 1.2em 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 0;
}

.katex {
    font-size: 1.05em;
}

/* Boxed equations */
.katex-display .boxed {
    border: 2px solid #6e46be;
    border-radius: 6px;
    padding: 12px 16px;
    background: rgba(110, 70, 190, 0.03);
}

/* ── Figures / Diagrams ── */
.chapter-content figure {
    margin: 2em 0;
    text-align: center;
}

.chapter-content figure img,
.chapter-content figure svg {
    max-width: 100%;
    height: auto;
}

.chapter-content figcaption {
    font-size: 0.78rem;
    color: #888;
    margin-top: 8px;
    font-style: italic;
}

/* ── Definition / Theorem / Note Boxes ── */
.note-box {
    border-radius: 8px;
    padding: 16px 20px;
    margin: 1.5em 0;
    font-size: 0.9rem;
}

.note-box .note-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 6px;
}

.note-box.definition {
    background: rgba(59, 130, 246, 0.05);
    border-left: 3px solid #3b82f6;
}

.note-box.definition .note-label {
    color: #3b82f6;
}

.note-box.theorem {
    background: rgba(110, 70, 190, 0.05);
    border-left: 3px solid #6e46be;
}

.note-box.theorem .note-label {
    color: #6e46be;
}

.note-box.intuition {
    background: rgba(245, 158, 11, 0.06);
    border-left: 3px solid #f59e0b;
}

.note-box.intuition .note-label {
    color: #d97706;
}

.note-box.implementation {
    background: rgba(16, 185, 129, 0.05);
    border-left: 3px solid #10b981;
}

.note-box.implementation .note-label {
    color: #059669;
}

/* ── Collapsible Sections ── */
details.collapsible {
    margin: 1em 0;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    overflow: hidden;
}

details.collapsible summary {
    padding: 10px 16px;
    background: #fafafa;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
    user-select: none;
    transition: background 0.2s;
    list-style: none;
}

details.collapsible summary::-webkit-details-marker {
    display: none;
}

details.collapsible summary::before {
    content: "▸ ";
    color: #6e46be;
    transition: transform 0.2s;
    display: inline-block;
}

details.collapsible[open] summary::before {
    content: "▾ ";
}

details.collapsible summary:hover {
    background: #f0f0f0;
}

details.collapsible .details-content {
    padding: 16px 20px;
    border-top: 1px solid #e8e8e8;
}

/* ── Chapter Navigation (prev/next) ── */
.chapter-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 60px;
    padding-top: 32px;
    border-top: 1px solid #eee;
}

.chapter-nav a {
    display: block;
    padding: 16px 20px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

.chapter-nav a:hover {
    border-color: #6e46be;
    background: rgba(110, 70, 190, 0.04);
    transform: translateY(-3px);
    box-shadow: 0 10px 20px -5px rgba(110, 70, 190, 0.12), 0 8px 8px -6px rgba(110, 70, 190, 0.08);
}

.chapter-nav .nav-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #94a3b8;
    margin-bottom: 6px;
}

.chapter-nav .nav-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: #333;
}

.chapter-nav .nav-prev {
    text-align: left;
}

.chapter-nav .nav-next {
    text-align: right;
}

.chapter-nav .nav-placeholder {
    /* Empty placeholder when there's no prev/next */
}

/* ── Key Takeaways Section ── */
.key-takeaways {
    background: linear-gradient(135deg, rgba(110, 70, 190, 0.04), rgba(176, 136, 249, 0.04));
    border: 1px solid rgba(110, 70, 190, 0.12);
    border-radius: 12px;
    padding: 24px 28px;
    margin: 2em 0;
}

.key-takeaways h2 {
    font-size: 1rem !important;
    border: none !important;
    margin-top: 0 !important;
    padding-bottom: 0 !important;
    color: #6e46be !important;
}

.key-takeaways ol {
    padding-left: 1.3em;
}

.key-takeaways li {
    font-size: 0.88rem;
    margin-bottom: 0.5em;
}

/* ── Chapter Intro (italicized context paragraph) ── */
.chapter-intro {
    font-style: italic;
    color: #555;
    font-size: 0.92rem;
    line-height: 1.7;
    padding: 16px 20px;
    background: #fafafa;
    border-radius: 8px;
    margin-bottom: 2em;
    border-left: 3px solid #e0e0e0;
}

/* ── Bridge / Transition Paragraph ── */
.chapter-bridge {
    font-style: italic;
    color: #666;
    font-size: 0.9rem;
    padding: 16px 20px;
    background: linear-gradient(135deg, #fafafa, rgba(110, 70, 190, 0.03));
    border-radius: 8px;
    margin-top: 2em;
    border-left: 3px solid #6e46be;
}

/* ── Horizontal Rule ── */
.chapter-content hr {
    border: none;
    height: 1px;
    background: #eee;
    margin: 2.5em 0;
}

/* ── Interactive Diagram Containers ── */
.interactive-container {
    border: 1px solid #e8e8e8;
    border-radius: 12px;
    padding: 24px;
    margin: 2em 0;
    background: #fafafa;
}

.interactive-container .interactive-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #6e46be;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.interactive-container .interactive-title::before {
    content: "⚡";
    font-size: 0.85rem;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .chapter-header h1 {
        font-size: 1.5rem;
    }

    .chapter-content h2 {
        font-size: 1.15rem;
    }

    .chapter-nav {
        grid-template-columns: 1fr;
    }

    .chapter-content pre {
        font-size: 0.75rem;
        padding: 12px 14px;
    }

    .key-takeaways {
        padding: 16px 18px;
    }

    .chapter-intro,
    .chapter-bridge {
        padding: 12px 16px;
    }

    .katex-display {
        font-size: 0.9em;
    }

    .interactive-container {
        padding: 16px;
    }
}

/* ── Series Index Page ── */
.series-hero {
    text-align: center;
    margin-bottom: 48px;
    padding-bottom: 32px;
}

.series-hero h1 {
    font-size: 2rem;
    font-weight: 700;
    color: #111;
    margin-bottom: 12px;
}

.series-hero .series-subtitle {
    font-size: 1rem;
    color: #666;
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.6;
}

.series-hero .series-meta {
    margin-top: 16px;
    font-size: 0.8rem;
    color: #999;
}

/* Chapter cards on index */
.chapter-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin: 32px 0;
}

.chapter-card {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    padding: 20px 24px;
    border: 1px solid #e8e8e8;
    border-radius: 12px;
    text-decoration: none;
    color: inherit;
    transition: all 0.25s ease;
    background: #fff;
}

.chapter-card:hover {
    border-color: #6e46be;
    background: rgba(110, 70, 190, 0.02);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(110, 70, 190, 0.1);
    text-decoration: none;
}

.chapter-card .card-number {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(110, 70, 190, 0.08);
    color: #6e46be;
    font-size: 0.85rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
}

.chapter-card .card-content {
    flex: 1;
}

.chapter-card .card-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: #222;
    margin-bottom: 4px;
    line-height: 1.3;
}

.chapter-card .card-desc {
    font-size: 0.82rem;
    color: #666;
    line-height: 1.5;
    margin-bottom: 8px;
}

.chapter-card .card-meta {
    font-size: 0.7rem;
    color: #aaa;
}

.chapter-card .card-topics {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.chapter-card .topic-tag {
    font-size: 0.62rem;
    background: #f0f0f0;
    padding: 2px 8px;
    border-radius: 3px;
    color: #666;
    border: 1px solid #e0e0e0;
}

/* ── Learning Path Indicator ── */
.learning-path {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin: 32px 0;
}

.learning-path .path-connector {
    width: 2px;
    height: 16px;
    background: #e0e0e0;
    margin-left: 41px;
}

/* ── Print styles ── */
@media print {
    .reading-progress,
    .toc-sidebar,
    .chapter-nav,
    .code-copy-btn,
    .interactive-container {
        display: none !important;
    }

    .chapter-content {
        font-size: 10pt;
    }
}
