/*
   Premium Editorial Design System for Mathematics
   Supports fully responsive layouts, smooth light/dark mode transitions,
   custom sidebar accordions, math scroll handling, and high-quality typography.
*/

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Lora:ital,wght@0,400..700;1,400..700&family=JetBrains+Mono:wght@400;500&display=swap");

:root {
    /* Light Theme Variables */
    --bg-color: #faf9f6; /* Cream/Warm paper white */
    --text-primary: #1a1c1e; /* Rich dark gray */
    --text-secondary: #4a4d52; /* Medium slate gray */
    --text-muted: #7a7e85;
    --sidebar-bg: #f4f3ee; /* Solid light stone */
    --sidebar-border: #e5e4dc;
    --border-color: #eae9e1;
    --accent-color: #4f46e5; /* Royal indigo */
    --accent-hover: #4338ca;
    --accent-light: #eef2ff;
    --code-bg: #eae8df;
    --pre-bg: #f4f3ee;
    --pre-border: #e5e4dc;
    --pre-text: #1a1c1e;

    /* Font Stacks */
    --font-serif: "Lora", Georgia, serif;
    --font-sans:
        "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        sans-serif;
    --font-mono: "JetBrains Mono", monospace;

    /* Layout Variables */
    --sidebar-width: 340px;
    --header-height: 64px;
    --transition-speed: 0.25s;
}

/* Dark Mode Overrides */
body.dark-mode {
    --bg-color: #0f111a; /* Midnight blue-gray */
    --text-primary: #f1f3f9; /* Off-white */
    --text-secondary: #939cae; /* Light grey-blue */
    --text-muted: #647087;
    --sidebar-bg: #151926; /* Dark slate */
    --sidebar-border: #23293d;
    --border-color: #21263a;
    --accent-color: #818cf8; /* Soft indigo */
    --accent-hover: #6366f1;
    --accent-light: #1e2238;
    --code-bg: #22273d;
    --pre-bg: #1b1e30;
    --pre-border: #272c46;
    --pre-text: #f1f3f9;
}

/* Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.625;
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
}

/* Left Sidebar Layout */
aside.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    padding: 1.5rem 1.25rem;
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    overflow-y: auto;
    scrollbar-gutter: stable;
    transition: transform 0.3s ease;
}

/* Scrollbar Customization */
aside.sidebar::-webkit-scrollbar {
    width: 6px;
}
aside.sidebar::-webkit-scrollbar-track {
    background: transparent;
}
aside.sidebar::-webkit-scrollbar-thumb {
    background: var(--sidebar-border);
    border-radius: 3px;
}
aside.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Brand styling */
.brand {
    margin-bottom: 1.5rem;
    padding-left: 0.25rem;
}

/* Theme Toggle Button */
.theme-switch-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding: 0.5rem;
    background-color: var(--border-color);
    border-radius: 10px;
    width: 100%;
}

.theme-switch-btn {
    background: none;
    border: 1px solid var(--sidebar-border);
    cursor: pointer;
    width: 44px;
    height: 24px;
    border-radius: 12px;
    position: relative;
    background-color: var(--code-bg);
    transition: background-color 0.2s ease;
}

.theme-switch-btn .mode-icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    line-height: 1;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-switch-btn .sun {
    left: 4px;
    opacity: 1;
}

.theme-switch-btn .moon {
    right: 4px;
    opacity: 0.3;
}

body.dark-mode .theme-switch-btn .sun {
    opacity: 0.3;
}

body.dark-mode .theme-switch-btn .moon {
    opacity: 1;
}

body.dark-mode .theme-switch-btn {
    background-color: var(--accent-light);
}

/* Search Box Container */
.search-container {
    position: relative;
    margin-bottom: 1.5rem;
}

.search-input {
    width: 100%;
    padding: 0.6rem 1rem 0.6rem 2.25rem;
    font-family: var(--font-sans);
    font-size: 0.875rem;
    background-color: var(--bg-color);
    border: 1px solid var(--sidebar-border);
    border-radius: 8px;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s ease;
}

.search-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    pointer-events: none;
}

/* Dropdown Search Results */
.search-results {
    position: absolute;
    top: 105%;
    left: 0;
    width: 100%;
    background-color: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: 8px;
    box-shadow:
        0 10px 25px -5px rgba(0, 0, 0, 0.1),
        0 8px 10px -6px rgba(0, 0, 0, 0.1);
    max-height: 320px;
    overflow-y: auto;
    z-index: 200;
    display: none;
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 0.75rem 1rem;
    display: block;
    text-decoration: none;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
    transition: background-color 0.15s ease;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background-color: var(--border-color);
}

.search-result-title {
    font-weight: 600;
    margin-bottom: 0.15rem;
}

.search-result-snippet {
    color: var(--text-secondary);
    font-size: 0.8rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Hierarchical Navigation Sidebar */
.sidebar-menu {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.menu-phase {
    display: flex;
    flex-direction: column;
}

.menu-phase-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    padding-left: 0.25rem;
}

.menu-chapters {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.menu-chapter {
    display: flex;
    flex-direction: column;
}

.chapter-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 6px;
    transition: background-color 0.15s ease;
}

.chapter-row:hover {
    background-color: var(--border-color);
}

.chapter-row a {
    display: block;
    padding: 0.4rem 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chapter-row a.active {
    color: var(--accent-color);
    font-weight: 600;
}

.toggle-icon {
    padding: 0.4rem 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.toggle-icon::after {
    content: "▼";
    font-size: 0.55rem;
    transition: transform 0.2s ease;
}

.menu-chapter.collapsed .toggle-icon::after {
    transform: rotate(-90deg);
}

/* Subtopics child list */
.subtopics-list {
    list-style: none;
    padding-left: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: 0.25rem;
}

.menu-chapter.collapsed .subtopics-list {
    display: none;
}

.subtopics-list a {
    display: block;
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.15s ease;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.subtopics-list a:hover {
    color: var(--text-primary);
    background-color: var(--border-color);
}

.subtopics-list li.active a {
    color: var(--accent-color);
    font-weight: 500;
    background-color: var(--accent-light);
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    padding-top: 1.25rem;
    border-top: 1px solid var(--sidebar-border);
}

.footer-nav {
    display: flex;
    gap: 1rem;
}

.footer-nav a {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s ease;
}

.footer-nav a:hover {
    color: var(--accent-color);
}

/* Main Content Area */
main.content-area {
    margin-left: var(--sidebar-width);
    flex-grow: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: margin-left 0.3s ease;
}

/* Top Navigation Header */
header.top-header {
    height: var(--header-height);
    padding: 0 3rem;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    position: sticky;
    top: 0;
    background-color: rgba(250, 249, 246, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    z-index: 90;
}

body.dark-mode header.top-header {
    background-color: rgba(15, 17, 26, 0.85);
}

.header-nav-links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: color 0.15s ease;
}

.nav-link:hover {
    color: var(--accent-color);
}

/* Mobile Toggle Hamburger */
.mobile-nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
}

.mobile-nav-toggle svg {
    width: 24px;
    height: 24px;
    color: var(--text-primary);
}

/* Article Styling */
.lecture-content {
    max-width: 820px;
    width: 100%;
    margin: 0 auto;
    padding: 3.5rem 2rem 5rem 2rem;
    flex-grow: 1;
}

.category-indicator {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-color);
    margin-bottom: 1rem;
}

/* Markdown prose rendering */
.markdown-body {
    font-family: var(--font-sans);
    color: var(--text-primary);
}

.markdown-body h1 {
    font-family: var(--font-serif);
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1.15;
    margin-bottom: 1.5rem;
    letter-spacing: -0.015em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
}

.markdown-body h2 {
    font-family: var(--font-serif);
    font-size: 1.625rem;
    font-weight: 600;
    margin-top: 2.25rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.4rem;
}

.markdown-body h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-top: 1.75rem;
    margin-bottom: 0.75rem;
}

.markdown-body p {
    margin-bottom: 1.25rem;
}

.markdown-body a,
.markdown-body a:visited {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.15s ease;
}

.markdown-body a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Table of Contents Card Styling */
.toc-card {
    background-color: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem 1.75rem;
    margin: 1.75rem 0;
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.01),
        0 2px 4px -1px rgba(0, 0, 0, 0.01);
    transition:
        box-shadow 0.2s ease,
        border-color 0.2s ease;
}

body.dark-mode .toc-card {
    box-shadow:
        0 4px 6px -1px rgba(0, 0, 0, 0.15),
        0 2px 4px -1px rgba(0, 0, 0, 0.1);
}

.toc-card h2,
.toc-card h3 {
    font-family: var(--font-sans) !important;
    font-size: 1.05rem !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.05em !important;
    color: var(--text-primary) !important;
    margin-top: 0 !important;
    margin-bottom: 0.85rem !important;
    padding-bottom: 0.4rem !important;
    border-bottom: 1px solid var(--border-color) !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.4rem !important;
}

.toc-card h2::before,
.toc-card h3::before {
    content: "📖";
    font-size: 1rem;
}

.toc-card ul,
.toc-card ol {
    list-style: none !important;
    padding-left: 0 !important;
    margin-bottom: 0 !important;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.toc-card ul li,
.toc-card ol li {
    position: relative;
    padding-left: 1rem;
    margin-bottom: 0 !important;
    font-size: 0.9rem;
}

.toc-card ul li::before,
.toc-card ol li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--accent-color);
    font-weight: bold;
}

.toc-card ul li a,
.toc-card ul li a:visited,
.toc-card ol li a,
.toc-card ol li a:visited {
    color: var(--text-secondary) !important;
    font-weight: 500;
    transition: color 0.15s ease;
}

.toc-card ul li a:hover,
.toc-card ol li a:hover {
    color: var(--accent-color) !important;
    text-decoration: underline;
}

.toc-card ul ul,
.toc-card ul ol,
.toc-card ol ul,
.toc-card ol ol {
    padding-left: 1rem !important;
    margin-top: 0.2rem;
    gap: 0.3rem;
}

.toc-card ul ul li,
.toc-card ul ol li,
.toc-card ol ul li,
.toc-card ol ol li {
    font-size: 0.85rem;
}

.toc-card ul ul li::before,
.toc-card ul ol li::before,
.toc-card ol ul li::before,
.toc-card ol ol li::before {
    content: "◦";
    position: absolute;
    left: 0;
    color: var(--accent-color);
}

/* Math block handling */
.mjx-container {
    max-width: 100%;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    padding: 0.5rem 0;
}

/* Bullet lists and blocks */
.markdown-body ul,
.markdown-body ol {
    margin-bottom: 1.25rem;
    padding-left: 1.5rem;
}

.markdown-body li {
    margin-bottom: 0.4rem;
}

.markdown-body blockquote {
    border-left: 4px solid var(--accent-color);
    padding: 0.75rem 1.25rem;
    background-color: var(--sidebar-bg);
    border-radius: 0 6px 6px 0;
    margin-bottom: 1.5rem;
    color: var(--text-secondary);
}

.markdown-body blockquote p {
    margin-bottom: 0;
    font-style: italic;
}

/* Tables styling */
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.markdown-body th,
.markdown-body td {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    text-align: left;
}

.markdown-body th {
    background-color: var(--sidebar-bg);
    font-weight: 600;
    color: var(--text-primary);
}

.markdown-body tr:nth-child(even) td {
    background-color: rgba(0, 0, 0, 0.01);
}

body.dark-mode .markdown-body tr:nth-child(even) td {
    background-color: rgba(255, 255, 255, 0.015);
}

/* Horizontal Rules */
.markdown-body hr {
    height: 1px;
    border: none;
    background-color: var(--border-color);
    margin: 2rem 0;
}

/* Code block wrapping and copying */
.markdown-body code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    padding: 0.2rem 0.4rem;
    background-color: var(--code-bg);
    border-radius: 4px;
    font-variant-ligatures: none;
    -webkit-font-variant-ligatures: none;
    font-feature-settings:
        "liga" 0,
        "clig" 0,
        "calt" 0;
}

.markdown-body pre {
    padding: 1rem;
    background-color: var(--pre-bg) !important;
    color: var(--pre-text) !important;
    border: 1px solid var(--pre-border);
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 1.5rem;
    font-variant-ligatures: none;
    -webkit-font-variant-ligatures: none;
    font-feature-settings:
        "liga" 0,
        "clig" 0,
        "calt" 0;
}

.markdown-body pre code {
    padding: 0;
    background-color: transparent !important;
    color: var(--pre-text) !important;
    text-shadow: none !important;
    font-size: 0.85rem;
    border-radius: 0;
    font-variant-ligatures: none;
    -webkit-font-variant-ligatures: none;
    font-feature-settings:
        "liga" 0,
        "clig" 0,
        "calt" 0;
}

.copy-code-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background-color: var(--bg-color);
    border: 1px solid var(--sidebar-border);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    opacity: 0;
    transition:
        opacity 0.2s ease,
        background-color 0.15s ease;
}

div:hover > .copy-code-btn {
    opacity: 1;
}

.copy-code-btn:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

.copy-code-btn.copied {
    background-color: #10b981;
    color: #fff;
    border-color: #10b981;
}

/* Prev / Next Pagination Layout */
.pagination-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 3.5rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

.pag-btn {
    display: flex;
    flex-direction: column;
    padding: 1rem 1.25rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-decoration: none !important;
    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease;
}

.pag-btn:hover {
    border-color: var(--accent-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.02);
}

body.dark-mode .pag-btn:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.pag-btn.prev {
    align-items: flex-start;
    text-align: left;
}

.pag-btn.next {
    align-items: flex-end;
    text-align: right;
    grid-column: 2;
}

.pag-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.pag-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Responsive Breakpoints */
@media (max-width: 1024px) {
    aside.sidebar {
        transform: translateX(-100%);
    }

    aside.sidebar.mobile-active {
        transform: translateX(0);
    }

    main.content-area {
        margin-left: 0;
    }

    header.top-header {
        justify-content: space-between;
        padding: 0 1.5rem;
    }

    .mobile-brand {
        display: flex !important;
    }

    .mobile-nav-toggle {
        display: block;
    }

    .header-nav-links {
        display: none;
    }
}

@media (max-width: 640px) {
    .pagination-container {
        grid-template-columns: 1fr;
    }

    .pag-btn.next {
        grid-column: 1;
    }

    .lecture-content {
        padding: 2rem 1rem 3rem 1rem;
    }

    .markdown-body h1 {
        font-size: 2rem;
    }
}

/* Prism Tomorrow light-mode overrides to blend with cream styling */
body:not(.dark-mode) .token.comment,
body:not(.dark-mode) .token.prolog,
body:not(.dark-mode) .token.doctype,
body:not(.dark-mode) .token.cdata {
    color: #8a8273;
    font-style: italic;
}

body:not(.dark-mode) .token.punctuation {
    color: #5c554a;
}

body:not(.dark-mode) .token.property,
body:not(.dark-mode) .token.tag,
body:not(.dark-mode) .token.boolean,
body:not(.dark-mode) .token.number,
body:not(.dark-mode) .token.constant,
body:not(.dark-mode) .token.symbol,
body:not(.dark-mode) .token.deleted {
    color: #b55a30;
}

body:not(.dark-mode) .token.selector,
body:not(.dark-mode) .token.attr-name,
body:not(.dark-mode) .token.string,
body:not(.dark-mode) .token.char,
body:not(.dark-mode) .token.builtin,
body:not(.dark-mode) .token.inserted {
    color: #3b6b4c;
}

body:not(.dark-mode) .token.operator,
body:not(.dark-mode) .token.entity,
body:not(.dark-mode) .token.url,
body:not(.dark-mode) .language-css .token.string,
body:not(.dark-mode) .style .token.string {
    color: #70583b;
}

body:not(.dark-mode) .token.atrule,
body:not(.dark-mode) .token.attr-value,
body:not(.dark-mode) .token.keyword {
    color: #2b558c;
    font-weight: bold;
}

body:not(.dark-mode) .token.function,
body:not(.dark-mode) .token.class-name {
    color: #8c2b75;
}

body:not(.dark-mode) .token.regex,
body:not(.dark-mode) .token.important,
body:not(.dark-mode) .token.variable {
    color: #c98200;
}

/* ═══════════════════════════════════════════════
   ENHANCED DESIGN SYSTEM
   ═══════════════════════════════════════════════ */

/* --- Article Typography Refinements --- */
.markdown-body {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
}

.markdown-body h1 {
    font-size: 2.75rem;
    letter-spacing: -0.03em;
    margin-bottom: 1.2rem;
}

.markdown-body h2 {
    position: relative;
    padding-bottom: 0.6rem;
    margin-bottom: 1.5rem;
}

.markdown-body h2::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 48px;
    height: 3px;
    background: var(--accent-color);
    border-radius: 2px;
    opacity: 0.6;
}

.markdown-body h3 {
    color: var(--text-primary);
    font-weight: 600;
}

.markdown-body p {
    margin-bottom: 1.5rem;
    line-height: 1.75;
}

/* --- Key Insight Box --- */
.markdown-body .insight-box {
    background: linear-gradient(
        135deg,
        rgba(79, 70, 229, 0.05),
        rgba(79, 70, 229, 0.02)
    );
    border: 1px solid rgba(79, 70, 229, 0.12);
    border-left: 4px solid var(--accent-color);
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
    margin: 2rem 0;
    font-size: 1rem;
}

.markdown-body .insight-box strong:first-child {
    display: block;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent-color);
    margin-bottom: 0.5rem;
}

body.dark-mode .markdown-body .insight-box {
    background: linear-gradient(
        135deg,
        rgba(129, 140, 248, 0.08),
        rgba(129, 140, 248, 0.02)
    );
    border-color: rgba(129, 140, 248, 0.2);
}

/* --- Better Blockquotes --- */
.markdown-body blockquote {
    border-left: 3px solid var(--accent-color);
    background: linear-gradient(90deg, rgba(79, 70, 229, 0.04), transparent);
    padding: 1rem 1.5rem;
    border-radius: 0 8px 8px 0;
    margin: 2rem 0;
}

body.dark-mode .markdown-body blockquote {
    background: linear-gradient(90deg, rgba(129, 140, 248, 0.06), transparent);
}

/* --- Enhanced Code Blocks --- */
.markdown-body pre {
    position: relative;
    border-radius: 10px;
    padding: 1.25rem;
    margin: 2rem 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.markdown-body pre::before {
    content: attr(data-lang);
    position: absolute;
    top: 0;
    right: 1rem;
    font-family: var(--font-sans);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 0.25rem 0.75rem;
    background: var(--sidebar-bg);
    border-radius: 0 0 6px 6px;
    border: 1px solid var(--border-color);
    border-top: none;
}

body.dark-mode .markdown-body pre::before {
    background: var(--pre-bg);
    border-color: var(--pre-border);
}

.markdown-body pre code {
    font-size: 0.875rem;
    line-height: 1.7;
}

/* --- Better Inline Code --- */
.markdown-body :not(pre) > code {
    background: rgba(79, 70, 229, 0.08);
    color: var(--accent-color);
    padding: 0.15em 0.45em;
    border-radius: 4px;
    font-weight: 500;
    font-size: 0.9em;
}

body.dark-mode .markdown-body :not(pre) > code {
    background: rgba(129, 140, 248, 0.12);
}

/* --- Tables --- */
.markdown-body table {
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

body.dark-mode .markdown-body table {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.markdown-body th {
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    padding: 0.85rem 1rem;
}

.markdown-body td {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
}

/* --- Images --- */
.markdown-body img {
    max-width: 100%;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    margin: 2rem 0;
}

/* --- Horizontal Rules --- */
.markdown-body hr {
    border: none;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent,
        var(--border-color),
        transparent
    );
    margin: 3rem 0;
}

/* --- Lists --- */
.markdown-body ul {
    list-style: none;
    padding-left: 0;
}

.markdown-body ul li {
    position: relative;
    padding-left: 1.5rem;
    margin-bottom: 0.5rem;
}

.markdown-body ul li::before {
    content: "";
    position: absolute;
    left: 0.25rem;
    top: 0.65em;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-color);
    opacity: 0.5;
}

.markdown-body ol li::marker {
    color: var(--accent-color);
    font-weight: 600;
    font-size: 0.9em;
}

/* --- Sidebar Polish --- */
.chapter-row a {
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    transition: all 0.15s ease;
}

.chapter-row:hover {
    background: var(--border-color);
}

.subtopics-list a {
    border-radius: 6px;
    padding: 0.35rem 0.5rem;
    margin-right: 0.25rem;
}

.subtopics-list li.active a {
    background: rgba(79, 70, 229, 0.08);
    color: var(--accent-color);
    font-weight: 600;
}

body.dark-mode .subtopics-list li.active a {
    background: rgba(129, 140, 248, 0.12);
}

/* --- Pagination --- */
.pag-btn {
    border-radius: 10px;
    transition: all 0.2s ease;
}

.pag-title {
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}

/* --- TOC Card --- */
.toc-card {
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

/* --- Math display polish --- */
.mjx-container {
    padding: 0.75rem 0;
}

/* --- Copy Button --- */
.copy-code-btn {
    border-radius: 6px;
    padding: 0.3rem 0.65rem;
}

/* --- Smooth scroll --- */
html {
    scroll-behavior: smooth;
}

/* --- Print optimizations --- */
@media print {
    .markdown-body h2::after {
        display: none;
    }

    .markdown-body blockquote {
        background: none;
        border-left: 3px solid #ccc;
    }
}
