/* =============================================
   ThreadWeaver: Adaptive Threading for Efficient
   Parallel Reasoning in Language Models
   Interactive companion · stylesheet
   ============================================= */

:root {
    --bg: #fbfaf7;
    --bg-elevated: #ffffff;
    --ink: #15212e;
    --ink-soft: #3a4a5c;
    --ink-muted: #6b7785;
    --ink-faint: #a4adb8;
    --rule: #e3e0d8;
    --rule-strong: #c9c4b6;

    --upstream: #1f3a52;
    --upstream-soft: #2c537a;
    --midmarket: #4a7396;
    --downstream: #7aa6cc;
    --downstream-soft: #a4c2dc;
    --feedback: #16a085;
    --feedback-soft: #2bbfa1;

    --accent: #c8392c;
    --accent-soft: #e25646;
    --accent-glow: rgba(200, 57, 44, 0.12);
    --warn: #d18b1f;
    --good: #16a085;

    --serif: 'Newsreader', 'Source Serif Pro', Georgia, 'Times New Roman', serif;
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;

    --max-width: 920px;
    --shadow-sm: 0 1px 2px rgba(21, 33, 46, 0.04), 0 2px 6px rgba(21, 33, 46, 0.04);
    --shadow-md: 0 2px 4px rgba(21, 33, 46, 0.06), 0 8px 24px rgba(21, 33, 46, 0.06);
    --shadow-lg: 0 8px 16px rgba(21, 33, 46, 0.08), 0 24px 60px rgba(21, 33, 46, 0.10);
}

* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--serif);
    font-size: 18px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
body { overflow-x: hidden; }

h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
h2 { font-size: 2.6rem; margin: 0 0 0.8rem 0; }
h3 { font-size: 1.5rem; margin: 2.4rem 0 0.8rem 0; }
h4 { font-size: 1.15rem; margin: 0 0 0.6rem 0; font-weight: 600; }

p { margin: 0 0 1.2rem 0; }
.muted { color: var(--ink-muted); font-size: 0.92em; }
em { font-style: italic; color: inherit; }
b, strong { font-weight: 600; color: var(--ink); }

/* ========== NAV BAR ========== */
.nav-bar {
    position: fixed; top: 0; left: 0; right: 0;
    background: rgba(251, 250, 247, 0.92);
    backdrop-filter: saturate(1.4) blur(10px);
    -webkit-backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--rule);
    z-index: 100;
    height: 56px;
}
.nav-inner {
    max-width: 1280px; margin: 0 auto; padding: 0 28px;
    height: 100%;
    display: flex; align-items: center; justify-content: space-between;
    position: relative;
}
.nav-title {
    display: flex; flex-direction: column;
    line-height: 1.15;
}
.nav-paper { font-family: var(--serif); font-weight: 600; font-size: 0.96rem; color: var(--ink); }
.nav-sub { font-family: var(--sans); font-size: 0.72rem; color: var(--ink-muted); letter-spacing: 0.02em; text-transform: uppercase; }
.nav-progress {
    position: absolute; bottom: -1px; left: 0; right: 0;
    height: 2px; background: transparent;
}
.nav-progress-fill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--upstream), var(--accent));
    transition: width 0.15s linear;
}

/* ========== CHAPTER RAIL ========== */
.chapter-rail {
    position: fixed;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 50;
}
.chapter-rail ol {
    list-style: none; margin: 0; padding: 0;
}
.chapter-rail li {
    display: flex; align-items: center; gap: 0.7rem;
    padding: 0.4rem 0;
    cursor: pointer;
    color: var(--ink-faint);
    font-family: var(--sans);
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    transition: color 0.2s;
}
.chapter-rail li:hover { color: var(--ink); }
.chapter-rail li.active { color: var(--accent); font-weight: 600; }
.chapter-rail .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--ink-faint);
    transition: all 0.2s;
}
.chapter-rail li.active .dot {
    background: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
    transform: scale(1.2);
}
.chapter-rail .label {
    opacity: 0;
    transform: translateX(-8px);
    transition: opacity 0.18s, transform 0.18s;
    pointer-events: none;
    white-space: nowrap;
}
.chapter-rail:hover .label,
.chapter-rail li.active .label { opacity: 1; transform: translateX(0); }

@media (max-width: 1100px) {
    .chapter-rail { display: none; }
}

/* ========== CHAPTER LAYOUT ========== */
.chapter {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 7rem 32px 6rem 32px;
    border-bottom: 1px solid var(--rule);
}
.chapter:last-of-type { border-bottom: none; }

.chapter-head { margin-bottom: 3rem; }
.chapter-num {
    font-family: var(--sans);
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 0.6rem;
}
.lede {
    font-size: 1.18rem;
    line-height: 1.55;
    color: var(--ink-soft);
    max-width: 56ch;
    margin-top: 1rem;
}

.prose { max-width: 64ch; }
.prose ul, .prose ol {
    margin: 1.2rem 0;
    padding-left: 1.4rem;
}
.prose li { margin-bottom: 0.7rem; }

/* ========== COVER ========== */
.cover { padding-top: 10rem; text-align: center; border-bottom: 1px solid var(--rule); }
.cover-inner { max-width: 720px; margin: 0 auto; }

.cover-eyebrow {
    font-family: var(--sans);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 1.5rem;
}
.cover-title {
    font-size: 3.1rem;
    font-weight: 600;
    line-height: 1.15;
    margin: 0 0 0.6rem 0;
    color: var(--ink);
}
.cover-title em { color: var(--accent); }
.cover-subtitle {
    font-size: 1.15rem;
    color: var(--ink-soft);
    margin: 0.6rem 0 1.8rem 0;
    font-style: italic;
}
.cover-byline {
    font-size: 0.92rem;
    color: var(--ink-soft);
    margin-bottom: 3rem;
    line-height: 1.5;
}

/* Cover abstract */
.cover-abstract {
    text-align: left;
    background: var(--bg);
    border-left: 4px solid #d4a843;
    padding: 2rem 2.2rem;
    margin: 2rem 0;
    border-radius: 0 8px 8px 0;
    box-shadow: var(--shadow-sm);
}
.cover-abstract-label {
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #d4a843;
    margin-bottom: 1rem;
}
.cover-abstract p { margin-bottom: 1rem; }
.cover-abstract p:last-child { margin-bottom: 0; }

/* Pillar cards */
.cover-pillars {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.2rem;
    margin-top: 3rem;
    text-align: left;
}
.pillar {
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 10px;
    padding: 1.6rem 1.4rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
}
.pillar:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.pillar-num {
    font-family: var(--serif);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 0.4rem;
}
.pillar-title {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 0.92rem;
    margin-bottom: 0.5rem;
    color: var(--ink);
}
.pillar-text {
    font-size: 0.88rem;
    line-height: 1.55;
    color: var(--ink-soft);
}

@media (max-width: 680px) {
    .cover-pillars { grid-template-columns: 1fr; }
    .cover-title { font-size: 2.2rem; }
}

/* ========== PLAIN ENGLISH CARD ========== */
.plain-card {
    background: var(--bg);
    border-left: 4px solid #d4a843;
    padding: 1.8rem 2rem;
    margin: 2rem 0;
    border-radius: 0 8px 8px 0;
    box-shadow: var(--shadow-sm);
}
.plain-label {
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #d4a843;
    margin-bottom: 0.8rem;
}
.plain-card p { margin-bottom: 0.8rem; }
.plain-card p:last-child { margin-bottom: 0; }

/* ========== EQUATION BLOCK ========== */
.equation-block {
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 8px;
    padding: 1.6rem 2rem;
    margin: 1.8rem 0;
    overflow-x: auto;
}

/* ========== INTERACTIVE SECTION ========== */
.interactive-section {
    margin: 2.5rem 0;
}
.interactive-hint {
    font-family: var(--sans);
    font-size: 0.78rem;
    color: var(--ink-muted);
    font-style: italic;
    margin-bottom: 1rem;
}
.slider-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1.2rem;
    margin-bottom: 1.2rem;
}
.slider-group {
    flex: 1 1 200px;
    min-width: 180px;
}
.slider-group label {
    display: block;
    font-family: var(--sans);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--ink-soft);
    margin-bottom: 0.3rem;
}
.slider-group input[type="range"] {
    width: 100%;
    accent-color: var(--upstream);
}
.slider-val {
    font-family: var(--mono);
    font-size: 0.82rem;
    color: var(--upstream);
    font-weight: 500;
}

/* Chart grid */
.chart-grid {
    display: grid;
    gap: 1rem;
    margin-top: 1rem;
}
.chart-grid.g2 { grid-template-columns: 1fr 1fr; }
.chart-grid.g1 { grid-template-columns: 1fr; }
.chart-box {
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 8px;
    overflow: hidden;
    min-height: 300px;
}

/* Readout cards */
.readout-row {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}
.readout-card {
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 8px;
    padding: 0.9rem 1.2rem;
    flex: 1 1 140px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}
.readout-label {
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-muted);
    margin-bottom: 0.3rem;
}
.readout-value {
    font-family: var(--mono);
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--upstream);
}

/* ========== CALLOUT ========== */
.callout {
    background: linear-gradient(135deg, rgba(200, 57, 44, 0.06), rgba(200, 57, 44, 0.02));
    border-left: 4px solid var(--accent);
    padding: 1.6rem 2rem;
    margin: 2.5rem 0;
    border-radius: 0 8px 8px 0;
}
.callout p { margin: 0; font-style: italic; color: var(--ink-soft); }
.callout em { color: var(--accent); font-weight: 500; }

/* ========== CHAPTER FOOT LINK ========== */
.chapter-foot {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--sans);
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--upstream);
    text-decoration: none;
    margin-top: 2.5rem;
    transition: color 0.2s, gap 0.2s;
}
.chapter-foot:hover { color: var(--accent); gap: 0.9rem; }
.chapter-foot .arrow { transition: transform 0.2s; }
.chapter-foot:hover .arrow { transform: translateX(4px); }

/* ========== STRATEGY CARDS ========== */
.strategy-cards {
    display: flex;
    gap: 0.8rem;
    margin-bottom: 1.2rem;
    flex-wrap: wrap;
}
.strategy-card {
    background: var(--bg-elevated);
    border: 2px solid var(--rule);
    border-radius: 8px;
    padding: 0.8rem 1.2rem;
    cursor: pointer;
    font-family: var(--sans);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ink-soft);
    transition: all 0.2s;
    text-align: center;
}
.strategy-card:hover { border-color: var(--midmarket); color: var(--ink); }
.strategy-card.active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
    font-weight: 600;
}

/* ========== ACTION BUTTONS ========== */
.action-btn {
    font-family: var(--sans);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.6rem 1.4rem;
    border: 2px solid var(--accent);
    border-radius: 6px;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    transition: all 0.2s;
    margin-right: 0.8rem;
    margin-top: 0.5rem;
}
.action-btn:hover { background: var(--accent); color: white; }
.action-btn.active { background: var(--accent); color: white; }

/* ========== SVG DIAGRAM ========== */
.diagram-container {
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 8px;
    padding: 1.5rem;
    margin: 1rem 0;
    overflow-x: auto;
}

/* ========== TABLE ========== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    margin: 1.5rem 0;
}
.data-table th {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-muted);
    border-bottom: 2px solid var(--rule);
    padding: 0.6rem 0.8rem;
    text-align: left;
}
.data-table td {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--rule);
    font-family: var(--mono);
    font-size: 0.85rem;
}
.data-table tr:hover td { background: rgba(31, 58, 82, 0.03); }

/* ========== CODE BLOCK ========== */
.code-block {
    background: #1e293b;
    color: #e2e8f0;
    font-family: var(--mono);
    font-size: 0.82rem;
    padding: 1.4rem 1.6rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1.5rem 0;
    line-height: 1.55;
}
.code-block .tag { color: #7aa6cc; }
.code-block .attr { color: #c8392c; }
.code-block .comment { color: #6b7785; }
