/* =============================================
   Dynamic Chunking for Diffusion 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 {
    min-height: 100vh;
    max-width: none;
    padding: 0;
    border-bottom: 1px solid var(--rule);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.cover-inner {
    max-width: var(--max-width);
    padding: 6rem 32px;
    position: relative;
    z-index: 2;
}
.cover-bg {
    position: absolute; inset: 0;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(200, 57, 44, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 70%, rgba(31, 58, 82, 0.10) 0%, transparent 55%),
        radial-gradient(ellipse at 50% 100%, rgba(22, 160, 133, 0.06) 0%, transparent 50%);
    z-index: 1;
}
.cover-eyebrow {
    font-family: var(--sans);
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 1.2rem;
}
.cover-title {
    font-size: clamp(2.6rem, 6vw, 4.6rem);
    font-weight: 600;
    line-height: 1.05;
    margin: 0 0 1.2rem 0;
    letter-spacing: -0.025em;
}
.cover-title em { font-style: italic; color: var(--accent); }
.cover-subtitle {
    font-size: 1.4rem;
    color: var(--ink-soft);
    font-style: italic;
    margin-bottom: 2.4rem;
    max-width: 30ch;
}
.cover-byline {
    font-family: var(--sans);
    font-size: 0.95rem;
    color: var(--ink-soft);
    margin-bottom: 2.6rem;
}
.cover-abstract {
    margin: 0 0 3.6rem 0;
    padding-top: 1.6rem;
    border-top: 1px solid var(--rule);
}
.cover-abstract-label {
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 1.2rem;
}
.cover-abstract p {
    font-family: var(--serif);
    font-size: 1.02rem;
    line-height: 1.65;
    color: var(--ink-soft);
    margin: 0 0 1rem 0;
}
.cover-abstract p:last-child { margin-bottom: 0; }
.cover-abstract b, .cover-abstract strong {
    color: var(--ink);
    font-weight: 600;
}
.cover-abstract em {
    color: var(--accent);
    font-style: italic;
}
.cover-pillars {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.6rem;
    margin-bottom: 3rem;
}
.pillar {
    padding: 1.6rem;
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 6px;
    box-shadow: var(--shadow-sm);
    position: relative;
    transition: transform 0.25s, box-shadow 0.25s;
}
.pillar:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.pillar-num {
    position: absolute;
    top: -10px; right: 16px;
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.1rem;
    color: var(--accent);
    background: var(--bg-elevated);
    padding: 0 6px;
}
.pillar-title {
    font-family: var(--serif);
    font-weight: 600;
    font-size: 1.18rem;
    margin-bottom: 0.6rem;
    color: var(--ink);
}
.pillar-text {
    font-size: 0.95rem;
    line-height: 1.55;
    color: var(--ink-soft);
}

@media (max-width: 720px) {
    .cover-pillars { grid-template-columns: 1fr; }
}

/* ========== CALLOUTS ========== */
.callout {
    margin: 3rem 0;
    padding: 1.6rem 1.8rem;
    background: linear-gradient(180deg, rgba(200, 57, 44, 0.04), rgba(200, 57, 44, 0.02));
    border-left: 3px solid var(--accent);
    border-radius: 0 6px 6px 0;
}
.callout.subtle {
    background: rgba(31, 58, 82, 0.04);
    border-left-color: var(--upstream);
}
.callout-label {
    font-family: var(--sans);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 0.6rem;
}
.callout.subtle .callout-label { color: var(--upstream); }
.callout-body {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--ink-soft);
}

/* ========== PLAIN CARDS ========== */
.plain-card {
    margin: 2rem 0 2.4rem 0;
    padding: 1.6rem 1.8rem 1.4rem 1.8rem;
    background: linear-gradient(180deg, #fff8ec 0%, #fffaf0 100%);
    border: 1px solid #f0e4c9;
    border-left: 4px solid #d4a849;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(212, 168, 73, 0.08);
}
.plain-label {
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #a07719;
    margin-bottom: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.plain-label::before {
    content: "\2726";
    font-size: 0.95rem;
    color: #d4a849;
    letter-spacing: 0;
    transform: translateY(-1px);
}
.plain-card p {
    margin: 0 0 0.85rem 0;
    color: #2a2618;
    font-family: var(--serif);
    font-size: 1.04rem;
    line-height: 1.65;
}
.plain-card p:last-child { margin-bottom: 0; }
.plain-card b, .plain-card strong { color: #15212e; }
.plain-card em { color: #a07719; font-style: italic; }

/* ========== EQUATION BLOCKS ========== */
.equation-block {
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 6px;
    padding: 1.4rem;
    margin: 1.8rem 0;
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
    text-align: center;
}
.equation-block .katex { font-size: 1.05em; }

/* ========== INTERACTIVE SECTIONS ========== */
.interactive-section {
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 8px;
    padding: 2rem;
    margin: 3rem 0;
    box-shadow: var(--shadow-md);
}
.interactive-section h3 {
    margin-top: 0;
    color: var(--upstream);
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.interactive-section h3::before {
    content: "\25B6";
    font-size: 0.65em;
    color: var(--accent);
}

.viz-container {
    width: 100%;
    min-height: 280px;
    border-radius: 4px;
    background: var(--bg);
    border: 1px solid var(--rule);
    margin: 1.4rem 0;
    position: relative;
    overflow: hidden;
}
.viz-container.tall { min-height: 460px; }
.viz-container.short { min-height: 240px; }

/* ========== CONTROLS ========== */
.ctrl, .ctrl-row {
    margin-bottom: 1rem;
}
.ctrl-row {
    display: flex;
    gap: 1.4rem;
    flex-wrap: wrap;
}
.ctrl {
    flex: 1;
    min-width: 200px;
}
.ctrl-label {
    font-family: var(--sans);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--ink-soft);
    margin-bottom: 0.4rem;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}
.ctrl-val {
    font-family: var(--mono);
    font-size: 0.82rem;
    color: var(--upstream);
    font-weight: 500;
}
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 5px;
    background: var(--rule);
    border-radius: 3px;
    outline: none;
    margin: 0.3rem 0 0 0;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--upstream);
    cursor: pointer;
    border: 2px solid var(--bg-elevated);
    box-shadow: var(--shadow-sm);
    transition: background 0.15s;
}
input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--accent);
}
input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--upstream);
    cursor: pointer;
    border: 2px solid var(--bg-elevated);
}

/* ========== READOUT CARDS ========== */
.readout-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin: 1.2rem 0;
}
.readout-card {
    padding: 1rem 1.2rem;
    background: var(--bg);
    border: 1px solid var(--rule);
    border-radius: 6px;
    text-align: center;
}
.readout-label {
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-muted);
    margin-bottom: 0.4rem;
}
.readout-value {
    font-family: var(--mono);
    font-size: 1.6rem;
    font-weight: 500;
    color: var(--ink);
}

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

/* ========== CHART GRID ========== */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.4rem;
}
@media (max-width: 700px) {
    .chart-grid { grid-template-columns: 1fr; }
}

/* ========== STRATEGY CARDS ========== */
.strategy-cards {
    display: flex;
    gap: 0.8rem;
    margin: 1rem 0;
    flex-wrap: wrap;
}
.strategy-card {
    padding: 0.8rem 1.2rem;
    background: var(--bg);
    border: 2px solid var(--rule);
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--sans);
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--ink-soft);
    transition: all 0.2s;
}
.strategy-card:hover {
    border-color: var(--ink-muted);
    color: var(--ink);
}
.strategy-card.active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(200, 57, 44, 0.04);
}

/* ========== HINT ========== */
.hint {
    font-family: var(--sans);
    font-size: 0.78rem;
    color: var(--ink-muted);
    font-style: italic;
    margin-bottom: 0.5rem;
}

/* ========== TOGGLE ========== */
.toggle-row {
    display: flex;
    gap: 0.8rem;
    margin: 1rem 0;
    flex-wrap: wrap;
}
.toggle-btn {
    padding: 0.6rem 1.2rem;
    background: var(--bg);
    border: 2px solid var(--rule);
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--sans);
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--ink-soft);
    transition: all 0.2s;
}
.toggle-btn:hover {
    border-color: var(--ink-muted);
    color: var(--ink);
}
.toggle-btn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(200, 57, 44, 0.04);
}
.toggle-btn.state-active {
    border-color: var(--good);
    color: var(--good);
    background: rgba(22, 160, 133, 0.04);
}

/* ========== FOOTER ========== */
.site-footer {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 3rem 32px;
    text-align: center;
    font-family: var(--sans);
    font-size: 0.85rem;
    color: var(--ink-muted);
}
.site-footer a {
    color: var(--upstream);
    text-decoration: none;
}
.site-footer a:hover {
    color: var(--accent);
}

/* ========== DIAGRAM ========== */
.diagram-container {
    width: 100%;
    min-height: 300px;
    margin: 1.4rem 0;
    border-radius: 4px;
    background: var(--bg);
    border: 1px solid var(--rule);
}

/* ========== TOKEN DEMO ========== */
.token-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 1rem 0;
    font-family: var(--mono);
    font-size: 0.88rem;
}
.token-cell {
    padding: 0.3rem 0.5rem;
    border-radius: 3px;
    border: 1px solid var(--rule);
    background: var(--bg-elevated);
    transition: background 0.3s, border-color 0.3s;
}
.chunk-divider {
    width: 3px;
    background: var(--accent);
    border-radius: 2px;
    margin: 0 2px;
    align-self: stretch;
}
