/* =============================================================================
   Technical Analysis for Futures Traders
   Editorial design system, single stylesheet
   ============================================================================= */

/* Design tokens
   --------------------------------------------------------------------------- */
:root {
    /* Typography */
    --font-serif: "Source Serif 4", "Charter", Cambria, Georgia, serif;
    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;

    /* Reading scale, fluid responsive */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1.0625rem;
    --text-md: 1.125rem;
    --text-lg: 1.25rem;
    --text-xl: 1.5rem;
    --text-2xl: 1.875rem;
    --text-3xl: 2.5rem;
    --text-4xl: 3.5rem;
    --text-5xl: clamp(3.5rem, 8vw, 6rem);

    /* Color palette, calibrated to the book's diagram conventions */
    --ink: #1A1D24;
    --ink-soft: #2C313D;
    --paper: #FAF8F4;
    --paper-warm: #F5F1EA;
    --rule: #D8D2C5;
    --rule-soft: #E8E3D6;

    --muted: #6E7682;
    --muted-soft: #9AA0A8;

    --bull: #1F7A4D;
    --bear: #B8362E;
    --highlight: #C68A1F;
    --institutional: #1A4F8A;
    --liquidity: #6B4F92;

    --bg-code: #F0EBE0;
    --bg-quote: #F5F1EA;
    --bg-panel: #F7F2E8;

    /* Spacing */
    --gap-1: 0.25rem;
    --gap-2: 0.5rem;
    --gap-3: 0.75rem;
    --gap-4: 1rem;
    --gap-5: 1.5rem;
    --gap-6: 2rem;
    --gap-8: 3rem;
    --gap-10: 4rem;
    --gap-12: 6rem;

    /* Reading width */
    --reading-width: 38rem;
    --content-width: 44rem;
    --wide-width: 64rem;

    /* Effects */
    --shadow-soft: 0 1px 2px rgba(26, 29, 36, 0.04), 0 4px 16px rgba(26, 29, 36, 0.04);
    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode tokens */
@media (prefers-color-scheme: dark) {
    :root {
        --ink: #E8E5DD;
        --ink-soft: #C8C4BA;
        --paper: #15171C;
        --paper-warm: #1B1E25;
        --rule: #2E3340;
        --rule-soft: #232730;

        --muted: #8A8F99;
        --muted-soft: #6A6F78;

        --bull: #4ABE89;
        --bear: #E5705F;
        --highlight: #E5A044;
        --institutional: #5C8AC2;
        --liquidity: #9F7CC4;

        --bg-code: #1F2228;
        --bg-quote: #1B1E25;
        --bg-panel: #1F232A;
    }
}

[data-theme="dark"] {
    --ink: #E8E5DD;
    --ink-soft: #C8C4BA;
    --paper: #15171C;
    --paper-warm: #1B1E25;
    --rule: #2E3340;
    --rule-soft: #232730;

    --muted: #8A8F99;
    --muted-soft: #6A6F78;

    --bull: #4ABE89;
    --bear: #E5705F;
    --highlight: #E5A044;
    --institutional: #5C8AC2;
    --liquidity: #9F7CC4;

    --bg-code: #1F2228;
    --bg-quote: #1B1E25;
    --bg-panel: #1F232A;
}

[data-theme="light"] {
    --ink: #1A1D24;
    --paper: #FAF8F4;
    /* keep light defaults explicitly */
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-serif);
    font-size: var(--text-base);
    line-height: 1.65;
    color: var(--ink);
    background: var(--paper);
    font-feature-settings: "kern" 1, "liga" 1, "onum" 1;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color var(--transition), color var(--transition);
}

/* Subtle paper texture for depth */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
    background-image:
        radial-gradient(circle at 25% 30%, rgba(26, 79, 138, 0.02) 0%, transparent 60%),
        radial-gradient(circle at 75% 70%, rgba(198, 138, 31, 0.015) 0%, transparent 50%);
}

/* Selection */
::selection {
    background: var(--highlight);
    color: var(--paper);
}

/* Focus */
:focus-visible {
    outline: 2px solid var(--institutional);
    outline-offset: 3px;
    border-radius: 2px;
}

/* Site header
   --------------------------------------------------------------------------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(250, 248, 244, 0.85);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--rule-soft);
    transition: background-color var(--transition), border-color var(--transition);
}

[data-theme="dark"] .site-header {
    background: rgba(21, 23, 28, 0.85);
}

.site-header .container {
    max-width: var(--wide-width);
    margin: 0 auto;
    padding: var(--gap-3) var(--gap-5);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--gap-5);
}

.brand {
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--ink);
    text-decoration: none;
    transition: color var(--transition);
}

.brand:hover {
    color: var(--institutional);
}

.brand-mark {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    margin-right: var(--gap-2);
    vertical-align: -3px;
    background: var(--institutional);
    border-radius: 2px;
    position: relative;
}

.brand-mark::after {
    content: "";
    position: absolute;
    inset: 4px 3px 4px 3px;
    border-left: 2px solid var(--paper);
    border-bottom: 2px solid var(--paper);
}

.nav-actions {
    display: flex;
    gap: var(--gap-4);
    align-items: center;
}

.nav-actions a {
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--muted);
    text-decoration: none;
    transition: color var(--transition);
}

.nav-actions a:hover {
    color: var(--ink);
}

.theme-toggle {
    background: none;
    border: 1px solid var(--rule);
    border-radius: 50%;
    width: 2rem;
    height: 2rem;
    color: var(--muted);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    color: var(--ink);
    border-color: var(--ink);
}

/* Reading progress bar */
.progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 2px;
    background: var(--institutional);
    width: 0;
    z-index: 100;
    transition: width 100ms linear;
}

/* Main layouts
   --------------------------------------------------------------------------- */
.layout {
    max-width: var(--wide-width);
    margin: 0 auto;
    padding: var(--gap-8) var(--gap-5) var(--gap-12);
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--gap-8);
}

@media (min-width: 1024px) {
    .layout-with-toc {
        grid-template-columns: 14rem minmax(0, 1fr);
        gap: var(--gap-10);
    }
}

/* Sidebar TOC for chapters */
.toc-sidebar {
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    line-height: 1.45;
}

@media (min-width: 1024px) {
    .toc-sidebar {
        position: sticky;
        top: 5rem;
        align-self: start;
        max-height: calc(100vh - 6rem);
        overflow-y: auto;
        padding-right: var(--gap-3);
        scrollbar-width: thin;
    }
}

.toc-sidebar h3 {
    font-size: var(--text-xs);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: var(--gap-3);
}

.toc-sidebar ol {
    list-style: none;
    border-left: 1px solid var(--rule-soft);
    padding-left: var(--gap-4);
}

.toc-sidebar ol li {
    margin-bottom: var(--gap-2);
}

.toc-sidebar a {
    color: var(--muted);
    text-decoration: none;
    transition: color var(--transition);
    display: block;
    padding: 2px 0;
    border-left: 2px solid transparent;
    margin-left: calc(-1 * var(--gap-4) - 2px);
    padding-left: calc(var(--gap-4));
}

.toc-sidebar a:hover {
    color: var(--ink);
}

.toc-sidebar a.active {
    color: var(--institutional);
    font-weight: 600;
    border-left-color: var(--institutional);
}

/* Chapter article
   --------------------------------------------------------------------------- */
.chapter {
    max-width: var(--content-width);
}

.chapter-header {
    margin-bottom: var(--gap-10);
    padding-bottom: var(--gap-6);
    border-bottom: 1px solid var(--rule);
}

.chapter-meta {
    display: flex;
    align-items: baseline;
    gap: var(--gap-4);
    margin-bottom: var(--gap-4);
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 600;
}

.part-label {
    color: var(--muted);
}

.chapter-num {
    color: var(--institutional);
}

.chapter-num-display {
    font-family: var(--font-serif);
    font-weight: 300;
    font-size: var(--text-5xl);
    line-height: 1;
    color: var(--rule);
    letter-spacing: -0.02em;
    margin-bottom: var(--gap-4);
    font-feature-settings: "lnum" 1;
}

.chapter h1.chapter-title {
    font-family: var(--font-serif);
    font-size: clamp(1.875rem, 4.5vw, var(--text-3xl));
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.015em;
    color: var(--ink);
    margin-bottom: var(--gap-5);
    text-wrap: balance;
}

.chapter-subtitle {
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--muted);
    font-style: italic;
}

/* Epigraph */
.epigraph {
    margin: var(--gap-6) 0 0 0;
    padding: var(--gap-4) var(--gap-5);
    border-left: 3px solid var(--highlight);
    background: var(--bg-quote);
    font-style: italic;
    font-size: var(--text-md);
    color: var(--ink-soft);
    line-height: 1.55;
}

.epigraph p {
    margin: 0;
}

.epigraph cite {
    display: block;
    margin-top: var(--gap-2);
    font-style: normal;
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--muted);
}

/* Body content
   --------------------------------------------------------------------------- */
.chapter-body {
    font-size: var(--text-base);
    line-height: 1.75;
    hyphens: auto;
    -webkit-hyphens: auto;
    hyphenate-limit-chars: 8 4 4;
}

.chapter-body p {
    margin-bottom: var(--gap-5);
    text-wrap: pretty;
    orphans: 2;
    widows: 2;
}

/* Drop cap on the first paragraph of each chapter body */
.chapter-body > p:first-of-type::first-letter,
.chapter-body > h2:first-of-type + p::first-letter {
    font-family: var(--font-serif);
    font-weight: 700;
    font-size: 4.2em;
    line-height: 0.85;
    float: left;
    padding: 0.05em 0.12em 0 0;
    margin-top: 0.05em;
    color: var(--institutional);
    font-feature-settings: "lnum" 1;
}

[data-theme="dark"] .chapter-body > p:first-of-type::first-letter,
[data-theme="dark"] .chapter-body > h2:first-of-type + p::first-letter {
    color: var(--institutional);
}

/* Headings hierarchy */
.chapter-body h2 {
    font-family: var(--font-serif);
    font-size: var(--text-2xl);
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.01em;
    margin-top: var(--gap-10);
    margin-bottom: var(--gap-5);
    padding-top: var(--gap-3);
    color: var(--ink);
    text-wrap: balance;
}

.chapter-body h2:first-child {
    margin-top: 0;
}

.chapter-body h2 .section-num {
    font-family: var(--font-sans);
    font-size: 0.6em;
    color: var(--muted);
    margin-right: var(--gap-3);
    letter-spacing: 0.05em;
    font-weight: 500;
    vertical-align: 0.1em;
}

.chapter-body h3 {
    font-family: var(--font-serif);
    font-size: var(--text-xl);
    font-weight: 600;
    line-height: 1.3;
    margin-top: var(--gap-8);
    margin-bottom: var(--gap-4);
    color: var(--ink);
}

.chapter-body h4 {
    font-family: var(--font-sans);
    font-size: var(--text-md);
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.005em;
    margin-top: var(--gap-6);
    margin-bottom: var(--gap-3);
    color: var(--ink);
}

.chapter-body h5 {
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: var(--gap-5);
    margin-bottom: var(--gap-2);
    color: var(--muted);
}

/* Inline elements */
.chapter-body strong {
    font-weight: 600;
    color: var(--ink);
}

.chapter-body em {
    font-style: italic;
    color: var(--ink-soft);
}

.chapter-body code {
    font-family: var(--font-mono);
    font-size: 0.92em;
    padding: 0.1em 0.4em;
    background: var(--bg-code);
    border-radius: 3px;
    color: var(--institutional);
    font-feature-settings: "liga" 0;
}

.chapter-body a {
    color: var(--institutional);
    text-decoration: underline;
    text-decoration-color: rgba(26, 79, 138, 0.3);
    text-underline-offset: 0.18em;
    transition: text-decoration-color var(--transition);
}

.chapter-body a:hover {
    text-decoration-color: var(--institutional);
}

/* Lists */
.chapter-body ul,
.chapter-body ol {
    margin: 0 0 var(--gap-5) var(--gap-5);
    padding-left: var(--gap-2);
}

.chapter-body li {
    margin-bottom: var(--gap-3);
    padding-left: var(--gap-2);
    line-height: 1.65;
}

.chapter-body li::marker {
    color: var(--muted);
}

.chapter-body ul li::marker {
    content: "• ";
    color: var(--institutional);
}

.chapter-body ol {
    list-style: decimal;
}

.chapter-body ol li::marker {
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 0.9em;
}

/* Nested lists */
.chapter-body li ul,
.chapter-body li ol {
    margin-top: var(--gap-3);
    margin-bottom: 0;
}

/* Blockquotes */
.chapter-body blockquote {
    margin: var(--gap-6) 0;
    padding: var(--gap-3) var(--gap-5);
    border-left: 3px solid var(--institutional);
    color: var(--ink-soft);
    font-style: italic;
    background: var(--bg-quote);
}

.chapter-body blockquote p {
    margin-bottom: var(--gap-3);
}

.chapter-body blockquote p:last-child {
    margin-bottom: 0;
}

/* Code blocks */
.chapter-body pre {
    background: var(--bg-code);
    border-radius: 6px;
    padding: var(--gap-5);
    overflow-x: auto;
    margin-bottom: var(--gap-5);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: 1.6;
    border: 1px solid var(--rule-soft);
}

.chapter-body pre code {
    background: transparent;
    padding: 0;
    border-radius: 0;
    color: var(--ink);
    font-feature-settings: "liga" 0;
}

/* Tables */
.chapter-body table {
    width: 100%;
    border-collapse: collapse;
    margin: var(--gap-6) 0;
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    line-height: 1.5;
}

.chapter-body thead {
    background: var(--bg-panel);
    border-bottom: 2px solid var(--ink);
}

.chapter-body th {
    text-align: left;
    padding: var(--gap-3) var(--gap-4);
    font-weight: 600;
    color: var(--ink);
    font-size: var(--text-xs);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.chapter-body td {
    padding: var(--gap-3) var(--gap-4);
    border-bottom: 1px solid var(--rule-soft);
    color: var(--ink-soft);
    vertical-align: top;
}

.chapter-body tbody tr:hover {
    background: var(--bg-panel);
}

/* Horizontal rules with rotating ornamental glyphs */
.chapter-body hr {
    border: none;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--rule) 20%, var(--rule) 80%, transparent);
    margin: var(--gap-8) auto;
    max-width: 12rem;
    position: relative;
}

.chapter-body hr::before {
    content: "◆";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: var(--paper);
    color: var(--muted-soft);
    font-family: var(--font-serif);
    font-size: 0.7rem;
    padding: 0 var(--gap-3);
    letter-spacing: 0.5em;
}

.chapter-body hr:nth-of-type(2n)::before { content: "❦"; }
.chapter-body hr:nth-of-type(3n)::before { content: "✦"; }
.chapter-body hr:nth-of-type(5n)::before { content: "§"; }

/* Insight callout (★ Insight ─── ... ─── pattern) */
.callout-insight {
    margin: var(--gap-6) 0;
    padding: var(--gap-5);
    background: var(--bg-panel);
    border-radius: 8px;
    border-left: 3px solid var(--highlight);
    font-size: var(--text-sm);
    line-height: 1.6;
    position: relative;
}

.callout-insight::before {
    content: "★";
    position: absolute;
    top: var(--gap-4);
    right: var(--gap-4);
    color: var(--highlight);
    font-size: var(--text-lg);
    line-height: 1;
}

.callout-insight h6 {
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--highlight);
    margin-bottom: var(--gap-2);
}

/* Figure / Diagram blocks */
.figure {
    margin: var(--gap-6) 0;
    padding: var(--gap-5);
    background: var(--paper-warm);
    border-radius: 6px;
    border: 1px solid var(--rule-soft);
}

.figure svg {
    display: block;
    width: 100%;
    height: auto;
    margin: 0 auto;
}

.figure figcaption {
    margin-top: var(--gap-4);
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    line-height: 1.5;
    color: var(--muted);
    text-align: center;
}

.figure figcaption .figure-num {
    font-weight: 700;
    color: var(--ink);
    margin-right: var(--gap-2);
    letter-spacing: 0.04em;
}

/* Key takeaways block */
.takeaways {
    margin: var(--gap-8) 0;
    padding: var(--gap-5);
    background: var(--bg-panel);
    border-radius: 8px;
    border-top: 3px solid var(--institutional);
}

.takeaways h3 {
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--institutional);
    margin: 0 0 var(--gap-3) 0;
    font-weight: 700;
}

.takeaways ul li {
    font-size: var(--text-sm);
    line-height: 1.6;
}

/* Chapter navigation */
.chapter-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--gap-4);
    margin-top: var(--gap-12);
    padding-top: var(--gap-6);
    border-top: 1px solid var(--rule);
}

.chapter-nav a {
    display: block;
    padding: var(--gap-4);
    text-decoration: none;
    color: var(--ink);
    border: 1px solid var(--rule);
    border-radius: 6px;
    transition: all var(--transition);
    font-family: var(--font-sans);
    font-size: var(--text-sm);
}

.chapter-nav a:hover {
    border-color: var(--institutional);
    color: var(--institutional);
    transform: translateY(-1px);
    box-shadow: var(--shadow-soft);
}

.chapter-nav .nav-direction {
    display: block;
    font-size: var(--text-xs);
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: var(--gap-1);
}

.chapter-nav .nav-title {
    font-weight: 600;
    line-height: 1.3;
    text-wrap: balance;
}

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

.chapter-nav .prev:only-child {
    grid-column: 1;
}

.chapter-nav .next:only-child {
    grid-column: 2;
}

/* Footer
   --------------------------------------------------------------------------- */
.site-footer {
    margin-top: var(--gap-12);
    padding: var(--gap-8) var(--gap-5);
    border-top: 1px solid var(--rule);
    background: var(--paper-warm);
}

.site-footer .container {
    max-width: var(--wide-width);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: var(--gap-5);
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--muted);
}

.site-footer a {
    color: var(--muted);
    text-decoration: none;
    transition: color var(--transition);
}

.site-footer a:hover {
    color: var(--ink);
}

.site-footer .footer-meta {
    font-size: var(--text-xs);
}

/* =========================================================================
   Index page (landing / table of contents)
   ========================================================================= */
.cover {
    max-width: var(--wide-width);
    margin: 0 auto;
    padding: var(--gap-10) var(--gap-5) var(--gap-12);
}

.cover-hero {
    text-align: center;
    padding: var(--gap-12) 0 var(--gap-10);
    border-bottom: 1px solid var(--rule);
    margin-bottom: var(--gap-10);
}

.cover-tag {
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--institutional);
    font-weight: 600;
    margin-bottom: var(--gap-5);
}

.cover h1 {
    font-family: var(--font-serif);
    font-size: clamp(2.5rem, 6vw, 4.5rem);
    font-weight: 600;
    line-height: 1.05;
    letter-spacing: -0.02em;
    color: var(--ink);
    margin-bottom: var(--gap-4);
    text-wrap: balance;
    max-width: 18ch;
    margin-left: auto;
    margin-right: auto;
}

.cover-subtitle {
    font-family: var(--font-serif);
    font-size: var(--text-lg);
    font-style: italic;
    color: var(--ink-soft);
    max-width: 36rem;
    margin: 0 auto;
    text-wrap: balance;
}

.cover-author {
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--muted);
    margin-top: var(--gap-6);
    letter-spacing: 0.04em;
}

.cover-author strong {
    color: var(--ink);
    font-weight: 600;
}

/* Cover stats row */
.cover-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
    gap: var(--gap-5);
    max-width: 36rem;
    margin: var(--gap-8) auto 0;
    padding-top: var(--gap-6);
    border-top: 1px solid var(--rule-soft);
}

.cover-stat {
    text-align: center;
}

.cover-stat-num {
    font-family: var(--font-serif);
    font-size: var(--text-3xl);
    font-weight: 600;
    color: var(--ink);
    line-height: 1;
    letter-spacing: -0.01em;
}

.cover-stat-label {
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: var(--gap-1);
}

/* Table of contents */
.toc-section {
    margin-bottom: var(--gap-10);
}

.toc-section-header {
    display: flex;
    align-items: baseline;
    gap: var(--gap-4);
    margin-bottom: var(--gap-5);
    padding-bottom: var(--gap-3);
    border-bottom: 1px solid var(--rule);
}

.toc-part {
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--institutional);
    font-weight: 700;
    flex-shrink: 0;
}

.toc-section-title {
    font-family: var(--font-serif);
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--ink);
    flex: 1;
    text-wrap: balance;
}

.toc-section-difficulty {
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    color: var(--muted);
    font-style: italic;
    flex-shrink: 0;
}

.toc-list {
    list-style: none;
}

.toc-item {
    border-bottom: 1px solid var(--rule-soft);
}

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

.toc-item a {
    display: grid;
    grid-template-columns: 3rem 1fr auto;
    align-items: baseline;
    gap: var(--gap-4);
    padding: var(--gap-4) var(--gap-2);
    text-decoration: none;
    color: var(--ink);
    transition: all var(--transition);
}

.toc-item a:hover {
    background: var(--paper-warm);
    color: var(--institutional);
}

.toc-item-num {
    font-family: var(--font-serif);
    font-size: var(--text-xl);
    font-weight: 300;
    color: var(--rule);
    line-height: 1;
    text-align: right;
    transition: color var(--transition);
}

.toc-item a:hover .toc-item-num {
    color: var(--institutional);
}

.toc-item-title {
    font-family: var(--font-serif);
    font-size: var(--text-md);
    font-weight: 500;
    line-height: 1.35;
    text-wrap: balance;
}

.toc-item-meta {
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    color: var(--muted);
    text-align: right;
    white-space: nowrap;
}

/* Companion / appendix sections */
.companion-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    gap: var(--gap-5);
    margin-bottom: var(--gap-10);
}

.companion-card {
    padding: var(--gap-5);
    border: 1px solid var(--rule);
    border-radius: 8px;
    background: var(--paper);
    transition: all var(--transition);
    text-decoration: none;
    color: var(--ink);
    display: block;
}

.companion-card:hover {
    border-color: var(--institutional);
    transform: translateY(-2px);
    box-shadow: var(--shadow-soft);
}

.companion-card-meta {
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--institutional);
    font-weight: 600;
    margin-bottom: var(--gap-3);
}

.companion-card h3 {
    font-family: var(--font-serif);
    font-size: var(--text-lg);
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: var(--gap-2);
    color: var(--ink);
    text-wrap: balance;
}

.companion-card p {
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--muted);
    line-height: 1.5;
    margin: 0;
}

/* Methodology block on cover */
.methodology {
    background: var(--paper-warm);
    border-radius: 8px;
    padding: var(--gap-6);
    margin: var(--gap-10) 0;
}

.methodology h3 {
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--institutional);
    font-weight: 700;
    margin-bottom: var(--gap-3);
}

.methodology h2 {
    font-family: var(--font-serif);
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--ink);
    margin-bottom: var(--gap-4);
    text-wrap: balance;
}

.methodology ul {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    gap: var(--gap-4);
}

.methodology li {
    padding-left: var(--gap-5);
    position: relative;
    font-size: var(--text-sm);
    line-height: 1.5;
}

.methodology li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: var(--institutional);
    font-weight: 700;
}

/* Print
   --------------------------------------------------------------------------- */
@media print {
    .site-header,
    .progress-bar,
    .toc-sidebar,
    .chapter-nav,
    .site-footer .nav-actions,
    .theme-toggle {
        display: none;
    }

    body {
        font-size: 11pt;
        background: white;
        color: black;
    }

    .chapter-body {
        font-size: 11pt;
    }

    .chapter h1 {
        page-break-after: avoid;
    }

    .chapter-body h2,
    .chapter-body h3 {
        page-break-after: avoid;
    }

    .figure,
    .takeaways,
    .callout-insight {
        page-break-inside: avoid;
    }

    a {
        color: black;
        text-decoration: none;
    }
}

/* Mobile refinements
   --------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .layout {
        padding: var(--gap-5) var(--gap-4) var(--gap-8);
    }

    .chapter-header {
        margin-bottom: var(--gap-6);
    }

    .chapter-num-display {
        font-size: 4rem;
    }

    .chapter-body h2 {
        margin-top: var(--gap-6);
    }

    .chapter-body pre {
        margin-left: calc(var(--gap-4) * -1);
        margin-right: calc(var(--gap-4) * -1);
        border-radius: 0;
    }

    .chapter-body table {
        font-size: var(--text-xs);
    }

    .chapter-body th,
    .chapter-body td {
        padding: var(--gap-2);
    }

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

/* =========================================================================
   Editorial enhancements
   ========================================================================= */

/* Oversized pull quote, full-width breakout */
.chapter-body .pullquote {
    margin: var(--gap-10) 0;
    padding: var(--gap-6) 0;
    font-family: var(--font-serif);
    font-size: clamp(1.375rem, 3.5vw, 1.875rem);
    line-height: 1.3;
    letter-spacing: -0.01em;
    font-weight: 500;
    color: var(--ink);
    text-align: center;
    text-wrap: balance;
    border-top: 1px solid var(--rule);
    border-bottom: 1px solid var(--rule);
    position: relative;
}

.chapter-body .pullquote::before,
.chapter-body .pullquote::after {
    content: "";
    display: block;
    width: 2.5rem;
    height: 1px;
    background: var(--highlight);
    margin: 0 auto;
}

.chapter-body .pullquote::before { margin-bottom: var(--gap-5); }
.chapter-body .pullquote::after  { margin-top: var(--gap-5); }

.chapter-body .pullquote cite {
    display: block;
    margin-top: var(--gap-3);
    font-size: var(--text-sm);
    font-style: normal;
    font-family: var(--font-sans);
    color: var(--muted);
    letter-spacing: 0.04em;
}

/* Marginalia, visible on wide screens; collapses to inline on narrow */
.margin-note {
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    line-height: 1.5;
    color: var(--muted);
    background: var(--bg-quote);
    border-left: 2px solid var(--highlight);
    padding: var(--gap-3) var(--gap-4);
    margin: var(--gap-5) 0;
    border-radius: 0 4px 4px 0;
}

.margin-note strong {
    color: var(--ink-soft);
    font-weight: 600;
}

@media (min-width: 1280px) {
    /* Push margin notes into the right margin on desktop */
    .chapter-body {
        position: relative;
    }
    .margin-note {
        position: absolute;
        right: -16rem;
        width: 14rem;
        margin: 0;
        background: transparent;
        border-left: 2px solid var(--rule);
        padding-left: var(--gap-3);
        font-size: 0.78rem;
    }
    .margin-note:hover {
        border-left-color: var(--highlight);
    }
}

/* Desk note, a tactical aside in the form of trader commentary */
.desk-note {
    margin: var(--gap-6) 0;
    padding: var(--gap-4) var(--gap-5);
    background: var(--bg-panel);
    border-left: 3px solid var(--liquidity);
    border-radius: 0 4px 4px 0;
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    line-height: 1.6;
    color: var(--ink-soft);
    position: relative;
}

.desk-note::before {
    content: "From the desk";
    position: absolute;
    top: -0.6em;
    left: var(--gap-4);
    background: var(--paper);
    padding: 0 var(--gap-2);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--liquidity);
    font-weight: 700;
}

/* Highlight box, for critical thresholds and rules */
.highlight-box {
    margin: var(--gap-6) 0;
    padding: var(--gap-5);
    background: var(--paper-warm);
    border: 1px solid var(--highlight);
    border-radius: 6px;
    font-size: var(--text-sm);
    line-height: 1.65;
    color: var(--ink-soft);
}

.highlight-box h4,
.highlight-box strong:first-child {
    color: var(--highlight);
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: var(--gap-2);
    display: block;
}

/* Warning box, for failure mode callouts */
.warning-box {
    margin: var(--gap-6) 0;
    padding: var(--gap-4) var(--gap-5);
    background: rgba(184, 54, 46, 0.06);
    border-left: 3px solid var(--bear);
    border-radius: 0 4px 4px 0;
    font-size: var(--text-sm);
    line-height: 1.6;
}

[data-theme="dark"] .warning-box {
    background: rgba(229, 112, 95, 0.08);
}

.warning-box::before {
    content: "Failure mode";
    display: block;
    font-family: var(--font-sans);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--bear);
    font-weight: 700;
    margin-bottom: var(--gap-2);
}

/* Side-by-side figure layouts */
.figure-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--gap-4);
    margin: var(--gap-6) 0;
}

.figure-grid .figure {
    margin: 0;
}

/* Definition list styling, for inline glossary */
.chapter-body dl {
    margin: var(--gap-5) 0;
    padding-left: var(--gap-3);
    border-left: 1px solid var(--rule-soft);
}

.chapter-body dt {
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--institutional);
    margin-top: var(--gap-3);
    margin-bottom: var(--gap-1);
    letter-spacing: 0.01em;
}

.chapter-body dt:first-child {
    margin-top: 0;
}

.chapter-body dd {
    margin-left: 0;
    margin-bottom: var(--gap-3);
    font-size: var(--text-sm);
    color: var(--ink-soft);
    line-height: 1.6;
}

/* Improved table styling, editorial rather than spreadsheet */
.chapter-body table {
    border-collapse: separate;
    border-spacing: 0;
    border-top: 2px solid var(--ink);
    border-bottom: 2px solid var(--ink);
}

.chapter-body thead {
    background: transparent;
    border-bottom: 1px solid var(--ink);
}

.chapter-body th {
    border-bottom: 1px solid var(--ink);
    color: var(--ink);
    font-size: 0.7rem;
    letter-spacing: 0.1em;
    padding: var(--gap-3) var(--gap-4) var(--gap-3) 0;
}

.chapter-body th:not(:last-child) {
    padding-right: var(--gap-5);
}

.chapter-body td {
    padding: var(--gap-3) var(--gap-4) var(--gap-3) 0;
    border-bottom: 1px solid var(--rule-soft);
}

.chapter-body tbody tr:last-child td {
    border-bottom: none;
}

.chapter-body tbody tr:hover {
    background: var(--paper-warm);
}

.chapter-body td:first-child {
    color: var(--ink);
    font-weight: 500;
}

/* Footnote-style references */
.chapter-body sup,
.chapter-body .footnote-ref {
    font-family: var(--font-sans);
    font-size: 0.7em;
    color: var(--institutional);
    text-decoration: none;
    margin-left: 0.05em;
    vertical-align: super;
    line-height: 0;
}

/* First-paragraph lead-in styling for chapter intros */
.chapter-body > p:first-of-type {
    font-size: 1.0625rem;
    line-height: 1.7;
    color: var(--ink);
}

/* Numeric figures use oldstyle except in tables/code */
.chapter-body p,
.chapter-body li,
.chapter-body dd,
.chapter-body blockquote {
    font-feature-settings: "kern" 1, "liga" 1, "onum" 1;
}

.chapter-body table,
.chapter-body code,
.chapter-body pre {
    font-feature-settings: "kern" 1, "lnum" 1;
}

/* Subtle accent on bold inside body */
.chapter-body strong {
    color: var(--ink);
    font-weight: 600;
    background-image: linear-gradient(to right, transparent, transparent);
}

/* Section anchors, hover-revealed link icons */
.chapter-body h2,
.chapter-body h3 {
    position: relative;
}

.chapter-body h2:hover::before,
.chapter-body h3:hover::before {
    content: "§";
    position: absolute;
    left: -1.2em;
    color: var(--muted-soft);
    font-weight: 400;
    opacity: 0.6;
}

/* Hidden helper */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Fade in on load */
@media (prefers-reduced-motion: no-preference) {
    .chapter,
    .cover {
        animation: fadeIn 400ms cubic-bezier(0.4, 0, 0.2, 1);
    }

    @keyframes fadeIn {
        from {
            opacity: 0;
            transform: translateY(8px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}


/* Back-to-portfolio link, only present when deployed under dhawal.org */
.back-to-portfolio {
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    color: var(--muted);
    text-decoration: none;
    letter-spacing: 0.04em;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: color var(--transition), background var(--transition);
}
.back-to-portfolio:hover {
    color: var(--ink);
    background: var(--paper-warm);
}
