/* ============================================
   CHAPTER PAGE STYLES — Shared across all chapters
   ============================================ */

/* Import base variables */
:root {
    --bg: #08090f;
    --bg-card: #0f1120;
    --bg-card2: #131629;
    --border: rgba(255,255,255,0.07);
    --border-hover: rgba(108,99,255,0.5);
    --accent: #6c63ff;
    --accent2: #3ecfda;
    --accent3: #f7666f;
    --green: #22c55e;
    --text: #e8eaf0;
    --text-muted: #7c8099;
    --text-dim: #4a4f6a;
    --font: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --font-display: 'Space Grotesk', sans-serif;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 0 40px rgba(108,99,255,0.15);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* === Layout === */
.page-layout {
    display: block;
    min-height: 100vh;
    width: 100%;
}

/* === Sidebar === */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    height: 100vh;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    z-index: 50;
    padding: 24px 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 24px 24px;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: var(--text);
}

.brand-icon { font-size: 1.3rem; color: var(--accent); }

.brand-text {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
}

.brand-accent { color: var(--accent); }

.sidebar-chapters {
    padding: 20px 16px;
}

.sidebar-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-dim);
    padding: 0 8px;
    margin-bottom: 8px;
}

.chapter-nav-item {
    display: flex;
    flex-direction: column;
    padding: 10px 8px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-muted);
    transition: all 0.2s;
    margin-bottom: 2px;
}

.chapter-nav-item:hover, .chapter-nav-item.active {
    background: rgba(108,99,255,0.1);
    color: var(--text);
}

.chapter-nav-item.active { border-left: 2px solid var(--accent); }

.chapter-nav-num {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.5px;
}

.chapter-nav-title {
    font-size: 0.85rem;
    font-weight: 500;
}

.sidebar-divider {
    height: 1px;
    background: var(--border);
    margin: 16px;
}

.sidebar-toc {
    padding: 0 16px;
}

.toc-link {
    display: block;
    padding: 6px 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s;
}

.toc-link:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.toc-link.active { color: var(--accent); }

/* === Main Content === */
.main-content {
    margin-left: 260px;
    min-height: 100vh;
    width: calc(100% - 260px);
    min-width: 0;
}

/* Chapter Header */
.chapter-header {
    padding: 80px 60px 60px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(108,99,255,0.05) 0%, transparent 100%);
}

.chapter-breadcrumb {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.chapter-breadcrumb a {
    color: var(--accent);
    text-decoration: none;
}

.chapter-label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 12px;
    display: block;
}

.chapter-title {
    font-family: var(--font-display);
    font-size: clamp(2rem, 3vw, 3.2rem);
    font-weight: 800;
    letter-spacing: -1px;
    margin-bottom: 16px;
    line-height: 1.1;
}

.chapter-desc {
    font-size: 1.05rem;
    color: var(--text-muted);
    max-width: 700px;
    line-height: 1.7;
}

.chapter-meta {
    display: flex;
    gap: 24px;
    margin-top: 24px;
}

.meta-item {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.meta-item strong { color: var(--text); }

/* === Article sections === */
.article { padding: 60px; }

.algorithm-section {
    margin-bottom: 80px;
    padding-bottom: 80px;
    border-bottom: 1px solid var(--border);
}

.algorithm-section:last-child {
    border-bottom: none;
}

.algo-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.algo-title {
    font-family: var(--font-display);
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    flex: 1 1 420px;
    min-width: 0;
}

.algo-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.algo-tag {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 100px;
    background: rgba(108,99,255,0.12);
    color: #9d98ff;
    border: 1px solid rgba(108,99,255,0.2);
}

.algo-intro {
    font-size: 1rem;
    color: var(--text-muted);
    max-width: 720px;
    line-height: 1.75;
    margin-bottom: 36px;
    width: min(100%, 720px);
}

/* === Visualization Card === */
.viz-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 32px;
}

.viz-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,0.02);
    gap: 14px;
    flex-wrap: wrap;
}

.viz-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    flex: 1 1 260px;
}

.viz-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.ctrl-btn {
    padding: 6px 14px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font);
}

.ctrl-btn:hover {
    background: rgba(108,99,255,0.2);
    border-color: var(--accent);
    color: var(--accent);
}

.ctrl-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.ctrl-slider {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.ctrl-slider input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 4px;
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
    outline: none;
}

.ctrl-slider input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.viz-canvas-wrap {
    position: relative;
    background: #060710;
    min-height: 350px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: auto;
}

.viz-canvas {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
}

.viz-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-dim);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.viz-status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
    animation: pulse 2s infinite;
}

/* === Math Block === */
.math-block {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 24px 28px;
    margin: 24px 0;
    overflow-x: auto;
}

.math-block .math-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 12px;
}

/* === Code Block === */
.code-block {
    background: #060812;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin: 20px 0;
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,0.02);
}

.code-lang {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
}

.code-copy {
    font-size: 0.72rem;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    font-family: var(--font);
    transition: color 0.2s;
}

.code-copy:hover { color: var(--accent); }

pre {
    padding: 20px;
    overflow-x: auto;
}

code {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    line-height: 1.7;
    color: #c9d1d9;
}

/* Syntax colors */
.kw { color: #ff7b72; }    /* keywords */
.fn { color: #d2a8ff; }    /* functions */
.st { color: #a5d6ff; }    /* strings */
.cm { color: #8b949e; }    /* comments */
.nu { color: #79c0ff; }    /* numbers */
.op { color: #ff7b72; }    /* operators */

/* === Insights Box === */
.insight-box {
    display: flex;
    gap: 16px;
    padding: 20px 24px;
    border-radius: var(--radius-sm);
    margin: 24px 0;
    background: rgba(108,99,255,0.07);
    border: 1px solid rgba(108,99,255,0.2);
    border-left: 3px solid var(--accent);
}

.insight-box.warning {
    background: rgba(247,102,111,0.07);
    border-color: rgba(247,102,111,0.2);
    border-left-color: var(--accent3);
}

.insight-box.tip {
    background: rgba(34,197,94,0.07);
    border-color: rgba(34,197,94,0.2);
    border-left-color: var(--green);
}

.insight-icon { font-size: 1.2rem; flex-shrink: 0; }

.insight-content h5 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.insight-content p {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.6;
}

/* === Comparison Table === */
.compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    margin: 24px 0;
}

.compare-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.compare-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
}

.compare-table tr:hover td { background: rgba(255,255,255,0.02); }

/* === Nav Buttons === */
.chapter-nav-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 40px 60px;
    border-top: 1px solid var(--border);
}

.nav-btn {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-decoration: none;
    color: var(--text-muted);
    transition: all 0.2s;
    padding: 16px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.nav-btn:hover { color: var(--text); border-color: var(--border-hover); }
.nav-btn span:first-child { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 1px; }
.nav-btn span:last-child { font-size: 0.95rem; font-weight: 600; }

/* === Responsive === */
@media (max-width: 1024px) {
    .page-layout { display: block; }
    .sidebar { display: none; }
    .main-content {
        margin-left: 0;
        width: 100%;
    }
    .article { padding: 40px 24px; }
    .chapter-header { padding: 60px 24px 40px; }
    .chapter-nav-buttons { padding: 30px 24px; }
    .algo-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .algo-title {
        flex: 1 1 auto;
        width: 100%;
    }
    .algo-tags {
        justify-content: flex-start;
    }
    .algo-intro {
        max-width: 100%;
    }
    .viz-header {
        align-items: flex-start;
        flex-direction: column;
    }
    .viz-canvas-wrap {
        min-height: 260px;
    }
    .viz-footer {
        flex-wrap: wrap;
        gap: 8px;
    }
}

@media (max-width: 520px) {
    .article,
    .chapter-header,
    .chapter-nav-buttons {
        padding-left: 14px;
        padding-right: 14px;
    }
    .algo-title {
        font-size: 1.45rem;
    }
    .viz-canvas-wrap {
        min-height: 210px;
    }
}

/* === Reading Progress Bar === */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    z-index: 200;
    transition: width 0.08s linear;
    border-radius: 0 2px 2px 0;
    pointer-events: none;
}

/* === Mobile Sidebar Toggle === */
.sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 28px;
    right: 24px;
    z-index: 100;
    background: var(--accent);
    border: none;
    border-radius: 12px;
    padding: 12px 20px;
    cursor: pointer;
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: var(--font);
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 24px rgba(108,99,255,0.45);
    transition: background 0.2s, box-shadow 0.2s;
}

.sidebar-toggle:hover {
    background: #7d75ff;
    box-shadow: 0 4px 32px rgba(108,99,255,0.6);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 49;
}

@media (max-width: 1024px) {
    .sidebar-toggle { display: flex; }
    .sidebar { transform: translateX(-100%); display: block !important; transition: transform 0.3s ease; }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.open { display: block; }
}
