:root {
    --bg: #F7F6F2;
    --surface: #FFFFFF;
    --border: #E4E2D8;
    --border-md: #CCC9BD;

    --text-primary: #1A1916;
    --text-secondary: #5C5A52;
    --text-muted: #8C8A82;

    --accent: #4A3FBF;
    --accent-light: #EEEDFE;
    --accent-mid: #7F77DD;
    --accent-dark: #3C3489;

    --teal: #0F6E56;
    --teal-light: #E1F5EE;
    --teal-mid: #1D9E75;

    --amber: #854F0B;
    --amber-light: #FAEEDA;
    --amber-mid: #EF9F27;

    --coral: #993C1D;
    --coral-light: #FAECE7;

    --code-bg: #1E1C2E;
    --code-text: #CDD6F4;
    --code-kw: #CBA6F7;
    --code-str: #A6E3A1;
    --code-num: #FAB387;
    --code-cmt: #6C7086;
    --code-fn: #89B4FA;
    --code-type: #F38BA8;
    --code-macro: #89DCEB;
    --code-op: #F5C2E7;
    --code-ln: #45475A;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --shadow-card: 0 1px 3px rgba(0, 0, 0, .06), 0 4px 12px rgba(0, 0, 0, .06);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Noto Sans SC', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.75;
    -webkit-font-smoothing: antialiased;
}

/* ── Page Layout ── */
.page-wrap {
    max-width: 860px;
    margin: 0 auto;
    padding: 0 24px 80px;
}

/* ── Chapter Header ── */
.chapter-header {
    background: var(--surface);
    border-bottom: 2px solid var(--accent);
    padding: 48px 48px 36px;
    margin-bottom: 40px;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    position: relative;
    overflow: hidden;
}

.chapter-header::before {
    content: 'Ch.1';
    position: absolute;
    right: 36px;
    top: 24px;
    font-size: 72px;
    font-weight: 700;
    color: var(--accent-light);
    line-height: 1;
    pointer-events: none;
    letter-spacing: -2px;
}

.chapter-eyebrow {
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: var(--accent-mid);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chapter-eyebrow a {
    color: var(--accent-mid);
    text-decoration: none;
    transition: color .15s;
}

.chapter-eyebrow a:hover {
    color: var(--accent);
}

.eyebrow-sep {
    color: var(--text-muted);
    font-size: 10px;
}

.chapter-title {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -.5px;
    margin-bottom: 14px;
}

.chapter-desc {
    font-size: 15px;
    color: var(--text-secondary);
    max-width: 520px;
    line-height: 1.7;
}

/* ── TOC ── */
.toc {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px 24px;
    margin-bottom: 40px;
    box-shadow: var(--shadow-card);
}

.toc-title {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.toc-list {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px 24px;
}

.toc-list a {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 13.5px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color .15s;
}

.toc-list a:hover {
    color: var(--accent);
}

.toc-num {
    font-size: 11px;
    font-weight: 500;
    color: var(--accent-mid);
    min-width: 24px;
    font-family: 'JetBrains Mono', monospace;
}

/* ── Section ── */
.section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 36px 40px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-card);
}

.section-label {
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--accent-mid);
    margin-bottom: 6px;
}

.section-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.section-body p {
    margin-bottom: 14px;
    color: var(--text-secondary);
    font-size: 14.5px;
    line-height: 1.8;
}

.section-body p:last-child {
    margin-bottom: 0;
}

/* ── Code Block ── */
.code-block {
    background: var(--code-bg);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin: 20px 0;
    font-size: 13.5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}

.code-header {
    background: #16141F;
    padding: 9px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #2A2840;
}

.code-dots {
    display: flex;
    gap: 6px;
}

.code-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
}

.code-dot.red {
    background: #FF5F57;
}

.code-dot.amber {
    background: #FEBC2E;
}

.code-dot.green {
    background: #28C840;
}

.code-lang {
    font-size: 11px;
    font-family: 'JetBrains Mono', monospace;
    color: #6C7086;
    letter-spacing: .06em;
}

.code-body {
    padding: 18px 0;
    overflow-x: auto;
}

.code-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'JetBrains Mono', monospace;
    line-height: 1.65;
}

.code-table tr:hover {
    background: rgba(255, 255, 255, .03);
}

.ln {
    width: 40px;
    padding: 0 6px 0 18px;
    color: var(--code-ln);
    text-align: right;
    user-select: none;
    font-size: 12.5px;
    vertical-align: top;
}

.cd {
    padding: 0 18px 0 14px;
    color: var(--code-text);
    white-space: pre;
}

/* Syntax tokens */
.kw {
    color: var(--code-kw);
}

.str {
    color: var(--code-str);
}

.num {
    color: var(--code-num);
}

.cmt {
    color: var(--code-cmt);
    font-style: italic;
}

.fn {
    color: var(--code-fn);
}

.type {
    color: var(--code-type);
}

.mac {
    color: var(--code-macro);
}

.op {
    color: var(--code-op);
}

.punc {
    color: #BAC2DE;
}

/* ── Callout Boxes ── */
.callout {
    border-radius: var(--radius-md);
    padding: 14px 18px;
    margin: 18px 0;
    display: flex;
    gap: 12px;
    align-items: flex-start;
    font-size: 14px;
    line-height: 1.7;
}

.callout-icon {
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 2px;
}

.callout.tip {
    background: var(--teal-light);
    border-left: 3px solid var(--teal-mid);
    color: var(--teal);
}

.callout.warn {
    background: var(--amber-light);
    border-left: 3px solid var(--amber-mid);
    color: var(--amber);
}

.callout.danger {
    background: var(--coral-light);
    border-left: 3px solid #D85A30;
    color: var(--coral);
}

.callout.info {
    background: var(--accent-light);
    border-left: 3px solid var(--accent-mid);
    color: var(--accent-dark);
}

.callout b {
    font-weight: 700;
}

/* ── Code-inline (inline code in prose) ── */
code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12.5px;
    background: #EEEDFE;
    color: var(--accent-dark);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid #D3CFFA;
}

/* ── Explanation Table ── */
.explain-table {
    width: 100%;
    border-collapse: collapse;
    margin: 18px 0;
    font-size: 13.5px;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
}

.explain-table thead tr {
    background: var(--accent-light);
}

.explain-table th {
    padding: 10px 16px;
    text-align: left;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--accent-dark);
    border-bottom: 1px solid #D3CFFA;
}

.explain-table td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: top;
}

.explain-table tr:last-child td {
    border-bottom: none;
}

.explain-table tr:nth-child(even) td {
    background: #FAFAF7;
}

.explain-table td:first-child {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--accent-dark);
    white-space: nowrap;
    background: #F4F2FF;
}

.explain-table tr:nth-child(even) td:first-child {
    background: #EEEDFE;
}

/* ── Step List (execution flow) ── */
.step-list {
    list-style: none;
    margin: 18px 0;
}

.step-item {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    position: relative;
}

.step-item::before {
    content: '';
    position: absolute;
    left: 19px;
    top: 40px;
    width: 2px;
    height: calc(100% + 8px);
    background: var(--border);
}

.step-item:last-child::before {
    display: none;
}

.step-num {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(74, 63, 191, .35);
}

.step-content {
    padding-top: 6px;
}

.step-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.step-desc {
    font-size: 13.5px;
    color: var(--text-secondary);
    line-height: 1.7;
}

.step-badge {
    display: inline-block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: 6px;
    vertical-align: middle;
}

.badge-gray {
    background: #E4E2D8;
    color: #5C5A52;
}

.badge-purple {
    background: var(--accent-light);
    color: var(--accent-dark);
}

/* ── Flow Diagram (compilation steps) ── */
.flow-diagram {
    margin: 22px 0;
    overflow-x: auto;
}

.flow-row {
    display: flex;
    align-items: center;
    gap: 0;
    justify-content: center;
    flex-wrap: nowrap;
    min-width: max-content;
    padding: 4px 0;
}

.flow-node {
    padding: 10px 18px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    white-space: nowrap;
}

.flow-node.source {
    background: var(--accent-light);
    color: var(--accent-dark);
    border: 1.5px solid #AFA9EC;
}

.flow-node.process {
    background: var(--teal-light);
    color: var(--teal);
    border: 1.5px solid #9FE1CB;
}

.flow-node.file {
    background: var(--amber-light);
    color: var(--amber);
    border: 1.5px solid #FAC775;
}

.flow-node.output {
    background: #EAF3DE;
    color: #3B6D11;
    border: 1.5px solid #C0DD97;
}

.flow-arrow {
    font-size: 18px;
    color: var(--border-md);
    padding: 0 4px;
    flex-shrink: 0;
}

.flow-label {
    font-size: 10.5px;
    color: var(--text-muted);
    text-align: center;
    margin-top: 5px;
    font-family: 'JetBrains Mono', monospace;
}

.flow-col {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ── Sub-section heading ── */
.sub-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 28px 0 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sub-title::before {
    content: '';
    display: block;
    width: 3px;
    height: 16px;
    background: var(--accent);
    border-radius: 2px;
}

/* ── Comment highlight in prose ── */
.highlight-row {
    background: rgba(74, 63, 191, .06) !important;
}

/* ── Divider ── */
.divider {
    height: 1px;
    background: var(--border);
    margin: 28px 0;
}

/* ── Footer ── */
.doc-footer {
    text-align: center;
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    font-size: 12.5px;
    color: var(--text-muted);
}

.chapter-nav {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    padding: 8px 18px;
    border-radius: var(--radius-md);
    transition: background .15s;
}

.nav-btn:hover {
    background: var(--accent-dark);
}