/* =====================================================
   IndustryLLM — Failure-Driven LLM Training for
   Industrial Procurement · interactive companion
   ===================================================== */

: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;

    --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);
}

* { 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: clip; }
html { scroll-padding-top: 76px; }

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; }
p { margin: 0 0 1.2rem 0; }
.muted { color: var(--ink-muted); font-size: 0.92em; }
em { font-style: italic; }
b, strong { font-weight: 600; color: var(--ink); }
.mono { font-family: var(--mono); }

/* ========== NAV ========== */
.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; }
.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; }
.nav-progress-fill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--upstream), var(--accent));
    transition: width 0.15s linear;
}

/* ========== CHAPTER RAIL ========== */
.chapter-rail { width: 220px; 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 {
    padding: 0;
    color: var(--ink-faint); font-family: var(--sans);
    font-size: 0.78rem; font-weight: 500; 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%;
    border: 1.5px solid currentColor; background: transparent; flex-shrink: 0;
    transition: background 0.2s;
}
.chapter-rail li.active .dot { background: var(--accent); border-color: var(--accent); }
.chapter-rail .label { white-space: nowrap; opacity: 0; transform: translateX(-4px); transition: opacity 0.2s, transform 0.2s; }
.chapter-rail:hover .label, .chapter-rail li.active .label { opacity: 1; transform: translateX(0); }
@media (max-width: 1499px) { .chapter-rail { display: none; } }

/* ========== CHAPTERS ========== */
.chapter { padding: 7rem 1.5rem 3.5rem; }
.chapter > * { max-width: var(--max-width); margin-left: auto; margin-right: auto; }
.chapter-head { margin-bottom: 2.2rem; }
.chapter-num {
    font-family: var(--sans); font-size: 0.75rem; font-weight: 700;
    letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent);
    margin-bottom: 0.6rem;
}
.lede { font-size: 1.25rem; line-height: 1.55; color: var(--ink-soft); font-style: italic; margin-bottom: 2rem; }

.prose p { margin-bottom: 1.2rem; }

/* ========== COVER ========== */
.cover { padding-top: 9rem; padding-bottom: 5rem; position: relative; }
.cover-inner { max-width: 820px; margin: 0 auto; position: relative; z-index: 2; }
.cover-bg {
    position: absolute; inset: 0; z-index: 1; pointer-events: none;
    background:
        radial-gradient(ellipse 60% 40% at 85% 10%, rgba(74,115,150,0.10), transparent),
        radial-gradient(ellipse 50% 35% at 10% 80%, rgba(200,57,44,0.06), transparent);
}
.cover-eyebrow {
    font-family: var(--sans); font-size: 0.82rem; font-weight: 600;
    letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent);
    margin-bottom: 1.4rem;
}
.cover-title {
    font-size: 3.4rem; line-height: 1.12; margin: 0 0 1.6rem;
    font-weight: 500; letter-spacing: -0.015em;
}
.cover-title em { color: var(--upstream); font-weight: 500; }
.cover-byline { font-family: var(--sans); font-size: 0.95rem; color: var(--ink-soft); line-height: 1.6; margin-bottom: 2.6rem; }
.cover-abstract {
    background: #fdf8ec;
    border-left: 4px solid #d8a93c;
    border-radius: 0 10px 10px 0;
    padding: 1.8rem 2rem;
    margin-bottom: 2.6rem;
    box-shadow: var(--shadow-sm);
}
.cover-abstract-label {
    font-family: var(--sans); font-size: 0.74rem; font-weight: 700;
    letter-spacing: 0.14em; text-transform: uppercase; color: #9a7414;
    margin-bottom: 1rem;
}
.cover-abstract p { font-size: 1.02rem; line-height: 1.68; color: var(--ink-soft); margin-bottom: 1rem; }
.cover-abstract p:last-child { margin-bottom: 0; }
.cover-pillars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 2.6rem; }
.pillar {
    background: var(--bg-elevated); border: 1px solid var(--rule);
    border-top: 3px solid var(--upstream);
    border-radius: 10px; padding: 1.3rem 1.2rem;
    box-shadow: var(--shadow-sm);
}
.pillar-num { font-family: var(--serif); font-size: 1.5rem; color: var(--accent); font-style: italic; margin-bottom: 0.5rem; }
.pillar-title { font-family: var(--sans); font-weight: 600; font-size: 0.95rem; margin-bottom: 0.5rem; color: var(--upstream); }
.pillar-text { font-size: 0.86rem; line-height: 1.55; color: var(--ink-soft); }
.cover-cta { text-align: center; }
.cover-meta { margin-top: 0.8rem; font-family: var(--sans); }

.primary-btn {
    font-family: var(--sans); font-size: 0.95rem; font-weight: 600;
    background: var(--upstream); color: #fff; border: none;
    padding: 0.8rem 1.8rem; border-radius: 8px; cursor: pointer;
    transition: background 0.2s, transform 0.15s;
}
.primary-btn:hover { background: var(--upstream-soft); transform: translateY(-1px); }
.reset-btn {
    font-family: var(--sans); font-size: 0.82rem; font-weight: 500;
    background: transparent; color: var(--ink-muted);
    border: 1px solid var(--rule-strong); border-radius: 6px;
    padding: 0.45rem 1rem; cursor: pointer; transition: all 0.2s;
}
.reset-btn:hover { border-color: var(--ink-muted); color: var(--ink); }
.toggle-btn {
    font-family: var(--sans); font-size: 0.82rem; font-weight: 500;
    background: transparent; color: var(--upstream);
    border: 1px solid var(--midmarket); border-radius: 6px;
    padding: 0.5rem 0.9rem; cursor: pointer; transition: all 0.2s;
    width: 100%; text-align: left;
}
.toggle-btn:hover { background: rgba(74,115,150,0.08); }
.toggle-btn.active { background: var(--upstream); color: #fff; border-color: var(--upstream); }
.toggle-btn.seg { width: auto; }

/* ========== PLAIN CARD / CALLOUT ========== */
.plain-card {
    background: #fdf8ec;
    border-left: 4px solid #d8a93c;
    border-radius: 0 10px 10px 0;
    padding: 1.5rem 1.8rem;
    margin-block: 2.4rem;
    box-shadow: var(--shadow-sm);
}
.plain-label {
    font-family: var(--sans); font-size: 0.72rem; font-weight: 700;
    letter-spacing: 0.14em; text-transform: uppercase; color: #9a7414;
    margin-bottom: 0.9rem;
}
.plain-card p { font-size: 1rem; line-height: 1.65; color: var(--ink-soft); margin-bottom: 0.9rem; }
.plain-card p:last-child { margin-bottom: 0; }

.callout {
    background: linear-gradient(135deg, rgba(200,57,44,0.05), rgba(200,57,44,0.02));
    border: 1px solid rgba(200,57,44,0.18);
    border-left: 4px solid var(--accent);
    border-radius: 0 10px 10px 0;
    padding: 1.4rem 1.7rem;
    margin-block: 2.6rem 1rem;
}
.callout-label {
    font-family: var(--sans); font-size: 0.72rem; font-weight: 700;
    letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent);
    margin-bottom: 0.7rem;
}
.callout p { font-size: 1.02rem; line-height: 1.62; color: var(--ink-soft); margin: 0; }

/* ========== EQUATIONS ========== */
.equation-block {
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 10px;
    padding: 1.6rem 1.8rem 1.2rem;
    margin-block: 1.8rem;
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}
.equation-block .katex-display { margin: 0 0 0.8rem; }
.equation-caption {
    font-family: var(--sans); font-size: 0.8rem; line-height: 1.5;
    color: var(--ink-muted); border-top: 1px dashed var(--rule); padding-top: 0.7rem;
}

/* ========== INTERACTIVE ========== */
.interactive-section {
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 12px;
    padding: 1.8rem;
    margin-block: 2.6rem;
    box-shadow: var(--shadow-md);
}
.interactive-header h3 { margin: 0 0 0.4rem; font-size: 1.25rem; }
.hint { font-family: var(--sans); font-size: 0.82rem; color: var(--ink-muted); line-height: 1.55; margin-bottom: 1.4rem; }
.hint b { color: var(--ink-soft); }

.slider-row { display: grid; grid-template-columns: minmax(0, 1fr) 74px; align-items: center; gap: 0.8rem; margin-bottom: 0.9rem; }
.slider-row label { grid-column: 1 / -1; font-family: var(--sans); font-size: 0.85rem; color: var(--ink-soft); line-height: 1.3; }
.slider-row input[type="range"] { min-width: 0; width: 100%; accent-color: var(--upstream); cursor: pointer; }
.slider-val { font-size: 0.82rem; color: var(--upstream); font-weight: 500; text-align: right; }

.readout {
    background: var(--bg); border: 1px solid var(--rule); border-radius: 8px;
    padding: 0.9rem 1.1rem; margin-top: 0.9rem;
}
.readout-label { font-family: var(--sans); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-muted); margin-bottom: 0.35rem; }
.readout-value { font-family: var(--mono); font-size: 1.35rem; font-weight: 500; color: var(--upstream); line-height: 1.3; }
.readout-value.accent { color: var(--accent); }
.readout-value.feedback { color: var(--feedback); }
.readout-sub { font-family: var(--sans); font-size: 0.8rem; color: var(--ink-muted); line-height: 1.5; margin-top: 0.35rem; }

/* chart layout helpers */
.chart-tall { height: 430px; }
.chart-half { height: 300px; margin-bottom: 0.6rem; }
.chart-third { height: 340px; }
.bench-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.4rem; }
.bench-grid > :last-child { grid-column: 1 / -1; }
.bench-toggle-row { display: flex; gap: 0.6rem; margin-bottom: 0.8rem; }

/* ========== CH1 QUERY DEMO ========== */
.query-demo { display: flex; flex-direction: column; gap: 1.2rem; }
.query-raw {
    background: #f4f1ea; border: 1px solid var(--rule); border-radius: 10px; padding: 1.2rem 1.4rem;
}
.query-label { font-family: var(--sans); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-muted); margin-bottom: 0.6rem; }
.query-text { font-size: 1.35rem; line-height: 1.9; }
.query-translation { font-family: var(--sans); font-size: 0.85rem; color: var(--ink-muted); margin-top: 0.5rem; font-style: italic; }
.tok { padding: 0.08em 0.25em; border-radius: 5px; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.2s; }
.tok-typo { background: rgba(200,57,44,0.10); }
.tok-code { background: rgba(74,115,150,0.12); }
.tok-dim { background: rgba(22,160,133,0.10); }
.tok-conflict { background: rgba(209,139,31,0.14); }
.tok.active, .tok:hover { border-bottom-color: currentColor; }

.pathology-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.9rem; }
.pathology-card {
    border: 1px solid var(--rule); border-radius: 10px; padding: 1rem 1.1rem;
    cursor: pointer; transition: all 0.2s; background: var(--bg);
}
.pathology-card:hover { border-color: var(--midmarket); }
.pathology-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); background: #fff; }
.pc-tag { font-family: var(--sans); font-size: 0.65rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin-bottom: 0.3rem; }
.pc-name { font-family: var(--sans); font-weight: 600; font-size: 0.92rem; margin-bottom: 0.4rem; color: var(--upstream); }
.pc-desc { font-family: var(--sans); font-size: 0.8rem; line-height: 1.5; color: var(--ink-soft); }

.parse-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.parse-col { border-radius: 10px; overflow: hidden; border: 1px solid var(--rule); }
.parse-head { font-family: var(--sans); font-size: 0.8rem; font-weight: 700; padding: 0.6rem 1rem; letter-spacing: 0.02em; }
.parse-head.bad { background: rgba(200,57,44,0.08); color: var(--accent); }
.parse-head.good { background: rgba(22,160,133,0.08); color: var(--feedback); }
.parse-body { padding: 1rem 1.1rem; font-family: var(--mono); font-size: 0.78rem; line-height: 1.75; min-height: 200px; background: var(--bg); }
.parse-line { display: flex; gap: 0.6rem; align-items: baseline; padding: 0.15rem 0; border-bottom: 1px dashed var(--rule); }
.parse-line:last-child { border-bottom: none; }
.pk { color: var(--ink-muted); flex-shrink: 0; width: 92px; }
.pv { color: var(--ink); }
.pv .bad-val { color: var(--accent); font-weight: 500; }
.pv .good-val { color: var(--feedback); font-weight: 500; }
.pv .unk-val { color: var(--warn); font-weight: 500; }

/* ========== CH2 GATE ========== */
.gate-layout { display: grid; grid-template-columns: 1fr; gap: 1.4rem; }
.gate-controls { overflow-x: auto; padding-bottom: 0.4rem; }
.gate-controls > .gate-head-row, .gate-controls > #gate-rows, .gate-controls > .gate-verdict-row { min-width: 680px; }
.gate-row { display: grid; grid-template-columns: 190px repeat(4, minmax(100px, 1fr)); gap: 0.4rem; margin-bottom: 0.4rem; align-items: center; }
.gate-c1 { font-family: var(--sans); font-size: 0.8rem; color: var(--ink-soft); line-height: 1.3; padding-right: 0.4rem; }
.gate-c1 .cval { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-muted); display: block; }
.gate-head-row { border-bottom: 2px solid var(--rule-strong); padding-bottom: 0.5rem; display: flex; align-items: center; }
.gate-head-row .gate-c1 { width: 190px; flex-shrink: 0; }
.gate-head-row .gate-c2 { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; font-family: var(--sans); font-size: 0.78rem; font-weight: 700; color: var(--upstream); }
.gate-head-row .gate-c2 div { text-align: center; line-height: 1.25; }
.gate-prod-desc { font-family: var(--sans); font-size: 0.64rem; font-weight: 500; color: var(--ink-muted); display: block; }
.gate-verdict-row { border-top: 2px solid var(--rule-strong); padding-top: 0.5rem; margin-top: 0.5rem; display: flex; align-items: center; }
.gate-verdict-row .gate-c1 { width: 190px; flex-shrink: 0; }
.gate-verdict-row #gate-verdicts { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.4rem; }
.ev-chip {
    font-family: var(--sans); font-size: 0.68rem; font-weight: 600;
    border: 1.5px solid; border-radius: 6px; padding: 0.32rem 0.1rem;
    cursor: pointer; text-align: center; transition: all 0.15s; user-select: none;
    line-height: 1.25; background: var(--bg-elevated);
}
.ev-chip:hover { transform: translateY(-1px); }
.ev-verified { border-color: var(--feedback); color: var(--feedback); background: rgba(22,160,133,0.06); }
.ev-stale { border-color: var(--warn); color: var(--warn); background: rgba(209,139,31,0.06); }
.ev-missing { border-color: var(--ink-faint); color: var(--ink-muted); background: var(--bg); }
.ev-conflict { border-color: var(--accent); color: var(--accent); background: rgba(200,57,44,0.06); }
.chip-example { display: inline-block; font-family: var(--sans); font-size: 0.68rem; font-weight: 600; border: 1.5px solid; border-radius: 4px; padding: 0 0.35em; }
.verdict-cell { text-align: center; font-family: var(--sans); font-size: 0.72rem; font-weight: 700; border-radius: 6px; padding: 0.35rem 0; }
.verdict-satisfied { color: var(--feedback); background: rgba(22,160,133,0.10); }
.verdict-violated { color: #fff; background: var(--accent); }
.verdict-unknown { color: var(--warn); background: rgba(209,139,31,0.10); }
.gate-side { display: flex; flex-direction: column; gap: 0.2rem; }
.gate-side .readout { margin-top: 0.6rem; }
.reset-row { margin-top: 0.9rem; display: flex; gap: 0.6rem; }
.gate-note { font-family: var(--sans); font-size: 0.75rem; color: var(--ink-muted); line-height: 1.5; margin-top: 0.7rem; }

/* ========== CH3 CORPUS ========== */
.corpus-layout { display: grid; grid-template-columns: 1fr 1.2fr; gap: 1.6rem; }
.corpus-charts { display: flex; flex-direction: column; }
.corpus-readout .readout-value { font-size: 1.05rem; }

/* ========== CH4 REGISTER ========== */
.register-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 1.4rem; }
.picker-label { font-family: var(--sans); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-muted); }
.genre-grid { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.5rem; }
.genre-chip {
    font-family: var(--sans); font-size: 0.76rem; padding: 0.35rem 0.7rem;
    border: 1.5px solid var(--rule-strong); border-radius: 999px; cursor: pointer;
    color: var(--ink-soft); transition: all 0.15s; background: var(--bg);
}
.genre-chip:hover { border-color: var(--midmarket); }
.genre-chip.active { background: var(--upstream); border-color: var(--upstream); color: #fff; }
.genre-chip .share { font-family: var(--mono); font-size: 0.66rem; opacity: 0.75; margin-left: 0.3rem; }
.style-chip.active { background: var(--feedback); border-color: var(--feedback); }
.preview-card {
    background: #f4f1ea; border: 1px solid var(--rule); border-radius: 10px;
    padding: 1.2rem 1.4rem; min-height: 230px;
}
.preview-title { font-family: var(--sans); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-muted); margin-bottom: 0.7rem; }
.preview-text { font-size: 0.98rem; line-height: 1.65; color: var(--ink); font-style: italic; }
.preview-meta { font-family: var(--sans); font-size: 0.75rem; color: var(--ink-muted); margin-top: 0.8rem; border-top: 1px dashed var(--rule); padding-top: 0.6rem; }
.preview-note { font-family: var(--sans); font-size: 0.78rem; color: var(--ink-muted); line-height: 1.55; margin-top: 0.9rem; }
.register-proxy { margin-top: 0.4rem; }

/* ========== CH5 WEAKNESS ========== */
.weakness-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 1.6rem; }
.weakness-sliders .slider-row { grid-template-columns: 88px 1fr 52px; margin-bottom: 0.5rem; }
.weakness-verdict {
    font-family: var(--sans); font-size: 1rem; font-weight: 700;
    border-radius: 8px; padding: 0.8rem 1rem; text-align: center; margin-top: 0.9rem;
}
.wv-weak { background: rgba(200,57,44,0.09); color: var(--accent); border: 1.5px solid var(--accent); }
.wv-pass { background: rgba(22,160,133,0.09); color: var(--feedback); border: 1.5px solid var(--feedback); }
.trim-drop { opacity: 0.32; }

/* ========== CH6 SPEC GRID / TRAINING ========== */
.spec-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.7rem; margin-block: 1.8rem; }
.spec { background: var(--bg-elevated); border: 1px solid var(--rule); border-radius: 8px; padding: 0.8rem 0.9rem; }
.spec-k { font-family: var(--sans); font-size: 0.66rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); margin-bottom: 0.3rem; }
.spec-v { font-family: var(--mono); font-size: 0.78rem; line-height: 1.45; color: var(--ink); }
.training-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 1.6rem; }
.training-charts { display: flex; flex-direction: column; }

/* ========== CH8 A/B ========== */
.ab-layout { display: grid; grid-template-columns: 1fr; gap: 1.6rem; }
.ab-controls .primary-btn { width: 100%; margin-top: 0.3rem; }
.ab-controls .reset-btn { margin-top: 0.5rem; width: 100%; }
.ab-charts { display: flex; flex-direction: column; }

/* ========== CH9 BOUNDARY ========== */
.boundary-wrap { display: flex; flex-direction: column; gap: 1rem; }
#ch9-diagram { background: var(--bg); border: 1px solid var(--rule); border-radius: 10px; padding: 0.6rem; overflow-x: auto; }
.boundary-detail {
    background: #f4f1ea; border: 1px solid var(--rule); border-radius: 10px;
    padding: 1.1rem 1.4rem; min-height: 90px;
}
.detail-title { font-family: var(--sans); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--upstream); margin-bottom: 0.4rem; }
.detail-body { font-size: 0.95rem; line-height: 1.6; color: var(--ink-soft); }
.b-node { cursor: pointer; }
.b-node rect { transition: all 0.15s; }
.b-node:hover rect { stroke-width: 2.5; }
.b-node.selected rect { stroke-width: 3; }

/* ========== CHAPTER FOOT ========== */
.chapter-foot {
    display: flex; justify-content: space-between; align-items: baseline;
    font-family: var(--sans); font-size: 0.92rem; color: var(--ink-muted);
    text-decoration: none; border-top: 1px solid var(--rule);
    padding-top: 1.4rem; margin-top: 3rem;
    transition: color 0.2s;
}
.chapter-foot:hover { color: var(--accent); }
.chapter-foot span { transition: transform 0.25s; display: inline-block; }
.chapter-foot:hover span { transform: translateX(6px); color: var(--accent); }

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
    .cover-title { font-size: 2.4rem; }
    .cover-pillars { grid-template-columns: 1fr; }
    .pathology-cards, .parse-compare { grid-template-columns: 1fr; }
    .gate-layout, .corpus-layout, .register-layout, .weakness-layout, .training-layout, .ab-layout { grid-template-columns: 1fr; }
    .bench-grid { grid-template-columns: 1fr; }
    .spec-grid { grid-template-columns: repeat(2, 1fr); }
    .gate-row { grid-template-columns: 190px repeat(4, minmax(100px, 1fr)); }
    .chapter { padding-left: 1.1rem; padding-right: 1.1rem; }
    h2 { font-size: 2rem; }
    .chart-tall { height: 360px; }
}

/* Keep grid children, Plotly canvases, and long readouts within their tracks. */
.corpus-layout, .register-layout, .weakness-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.corpus-layout > *, .register-layout > *, .weakness-layout > *,
.training-layout > *, .ab-layout > *, .gate-layout > *, .bench-grid > *, .parse-compare > *, .spec-grid > * { min-width: 0; }
.chart-panel { min-width: 0; max-width: 100%; margin: 0; }
.chart-title { font-family: var(--sans); font-size: 0.78rem; line-height: 1.5; font-weight: 600; margin: 0.7rem 0 0.25rem; letter-spacing: 0; }
.chart-note { font-family: var(--sans); font-size: 0.72rem; line-height: 1.5; color: var(--ink-muted); margin: 0 0 1rem; }
.chart-tall, .chart-half, .chart-third { width: 100%; min-width: 0; }
.weakness-sliders .slider-row { grid-template-columns: 88px minmax(0, 1fr) 36px; }
.weakness-sliders .slider-row label { grid-column: auto; }
.readout-value, .spec-v, .pv { overflow-wrap: anywhere; }
.pv { min-width: 0; }
.gate-side { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem; margin-top: 0.5rem; }
.gate-side .toggle-btn, .gate-side .reset-row { grid-column: 1 / -1; }
.chapter-foot { gap: 1.2rem; }
.chapter-rail a { display: flex; align-items: center; gap: 0.7rem; padding: 0.4rem 0; color: inherit; text-decoration: none; }
.chapter-rail:focus-within .label { opacity: 1; transform: translateX(0); }
a:focus-visible, button:focus-visible, input:focus-visible, .b-node:focus-visible { outline: 3px solid var(--midmarket); outline-offset: 4px; }
#ch9-diagram svg { display: block; }
.nav-title { min-width: 0; }
.nav-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 900px) {
    .corpus-layout, .register-layout, .weakness-layout, .training-layout { grid-template-columns: 1fr; }
    .bench-grid { grid-template-columns: 1fr; }
    .bench-grid > :last-child { grid-column: auto; }
    .interactive-section { padding: 1.25rem; }
}
@media (max-width: 600px) {
    html, body { font-size: 17px; }
    .nav-inner { padding-inline: 18px; }
    .nav-sub { font-size: 0.6rem; }
    .chapter { padding: 5rem 1rem 2.5rem; }
    .cover { padding-top: 7rem; }
    .cover-title { font-size: clamp(1.9rem, 8vw, 2.4rem); }
    .cover-abstract, .plain-card, .callout, .equation-block { padding: 1.1rem; }
    .interactive-section { padding: 1rem; }
    .gate-side { grid-template-columns: 1fr; }
    .chapter-foot { flex-direction: column; gap: 0.5rem; }
    .chart-title { font-size: 0.8rem; }
    .bench-toggle-row { flex-wrap: wrap; }
    .spec-grid { grid-template-columns: 1fr; }
    .parse-line { flex-direction: column; gap: 0.15rem; }
    .chart-panel { overflow-x: auto; }
    /* Dense scientific plots retain readable axes and scroll inside their card. */
    .chart-panel .js-plotly-plot { min-width: 520px; }
    .chart-panel #corpus-donut, .chart-panel #ab-cum-chart, .chart-panel #wsd-schedule-chart { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
}

/* Use identical tracks for table headings, evidence rows, and verdicts. */
.gate-head-row, .gate-verdict-row { display: grid; grid-template-columns: 190px repeat(4, minmax(100px, 1fr)); gap: 0.4rem; }
.gate-head-row .gate-c1, .gate-verdict-row .gate-c1 { width: auto; }
.gate-head-row .gate-c2, .gate-verdict-row #gate-verdicts { grid-column: 2 / -1; min-width: 0; }
