/* =============================================
   Make Attention Sub-Quadratic Again
   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); }

a { color: var(--upstream); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--accent); }

/* ========== 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: 90;
}
.chapter-rail ol {
    list-style: none;
    margin: 0; padding: 0;
    display: flex; flex-direction: column; gap: 12px;
}
.chapter-rail li {
    display: flex; align-items: center; gap: 8px;
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.3s;
}
.chapter-rail li.active { opacity: 1; }
.chapter-rail .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--ink-muted);
    transition: background 0.3s, transform 0.3s;
    flex-shrink: 0;
}
.chapter-rail li.active .dot {
    background: var(--accent);
    transform: scale(1.4);
}
.chapter-rail .label {
    font-family: var(--sans);
    font-size: 0.68rem;
    color: var(--ink-muted);
    white-space: nowrap;
    transition: color 0.3s;
}
.chapter-rail li.active .label { color: var(--ink); font-weight: 500; }

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

/* ========== CHAPTERS ========== */
.chapter {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 7rem 28px 4rem;
}
.chapter-num {
    font-family: var(--sans);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 0.8rem;
}
.chapter h2 {
    margin-bottom: 1.2rem;
}

/* ========== COVER ========== */
.cover { padding-top: 10rem; text-align: center; }
.cover-inner { max-width: 720px; margin: 0 auto; }
.cover-eyebrow {
    font-family: var(--sans);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 1.6rem;
}
.cover-title {
    font-family: var(--serif);
    font-size: 3.4rem;
    font-weight: 700;
    line-height: 1.1;
    margin-bottom: 1.2rem;
    color: var(--ink);
}
.cover-title em { color: var(--accent); }
.cover-subtitle {
    font-family: var(--serif);
    font-size: 1.15rem;
    color: var(--ink-soft);
    margin-bottom: 1.2rem;
    font-style: italic;
}
.cover-byline {
    font-family: var(--sans);
    font-size: 0.88rem;
    color: var(--ink-soft);
    margin-bottom: 3rem;
    line-height: 1.6;
}

/* ========== COVER ABSTRACT ========== */
.cover-abstract {
    text-align: left;
    background: var(--bg);
    border: 1px solid var(--rule);
    border-left: 4px solid var(--warn);
    border-radius: 6px;
    padding: 1.8rem 2rem;
    margin-bottom: 3rem;
    box-shadow: var(--shadow-sm);
}
.cover-abstract-label {
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--warn);
    margin-bottom: 1rem;
}

/* ========== PILLAR CARDS ========== */
.cover-pillars {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.2rem;
    margin-bottom: 3rem;
}
.pillar {
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 8px;
    padding: 1.4rem 1.2rem;
    text-align: left;
    box-shadow: var(--shadow-sm);
}
.pillar-num {
    font-family: var(--serif);
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--upstream);
    margin-bottom: 0.4rem;
}
.pillar-title {
    font-family: var(--sans);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 0.5rem;
}
.pillar-text {
    font-family: var(--serif);
    font-size: 0.88rem;
    color: var(--ink-soft);
    line-height: 1.5;
}

/* ========== RESOURCE LINKS ========== */
.resources-bar {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 3rem;
}
.resource-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--sans);
    font-size: 0.82rem;
    font-weight: 500;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    text-decoration: none;
    transition: background 0.2s, transform 0.2s;
}
.resource-link:hover { transform: translateY(-1px); }
.resource-link.hf {
    background: #fff0e6;
    color: #d45500;
    border: 1px solid #ffd5b8;
}
.resource-link.hf:hover { background: #ffe4d1; }
.resource-link.gh {
    background: #f0f0f0;
    color: #24292e;
    border: 1px solid #d0d0d0;
}
.resource-link.gh:hover { background: #e6e6e6; }

/* ========== PLAIN ENGLISH CARD ========== */
.plain-card {
    background: var(--bg);
    border: 1px solid var(--rule);
    border-left: 4px solid var(--warn);
    border-radius: 6px;
    padding: 1.8rem 2rem;
    margin: 2rem 0;
    box-shadow: var(--shadow-sm);
}
.plain-label {
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--warn);
    margin-bottom: 0.8rem;
}
.plain-card p {
    font-size: 0.95rem;
    color: var(--ink-soft);
    line-height: 1.6;
    margin-bottom: 0.6rem;
}
.plain-card p:last-child { margin-bottom: 0; }

/* ========== EQUATION BLOCK ========== */
.equation-block {
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 6px;
    padding: 1.4rem 1.8rem;
    margin: 1.6rem 0;
    overflow-x: auto;
    text-align: center;
}
.equation-block .eq-label {
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.6rem;
}

/* ========== INTERACTIVE SECTION ========== */
.interactive-section {
    margin: 2.5rem 0;
}
.slider-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1.2rem 2rem;
    margin-bottom: 1.4rem;
    align-items: flex-end;
}
.slider-item {
    flex: 1;
    min-width: 180px;
}
.slider-item label {
    display: block;
    font-family: var(--sans);
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--ink-soft);
    margin-bottom: 0.3rem;
}
.slider-item input[type="range"] {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--rule);
    border-radius: 2px;
    outline: none;
}
.slider-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--upstream);
    cursor: pointer;
    border: 2px solid var(--bg-elevated);
    box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}
.slider-item input[type="range"]::-moz-range-thumb {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--upstream);
    cursor: pointer;
    border: 2px solid var(--bg-elevated);
}
.slider-value {
    font-family: var(--mono);
    font-size: 0.82rem;
    color: var(--ink);
    margin-top: 0.2rem;
}
.chart-grid {
    display: grid;
    gap: 1rem;
    margin-bottom: 1rem;
}
.chart-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.chart-grid.cols-1 { grid-template-columns: 1fr; }
.chart-wrap {
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 8px;
    overflow: hidden;
    min-height: 320px;
}
.live-hint {
    font-family: var(--sans);
    font-size: 0.72rem;
    color: var(--ink-muted);
    font-style: italic;
    margin-bottom: 0.8rem;
}

/* ========== READOUT CARDS ========== */
.readout-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}
.readout-card {
    background: var(--bg-elevated);
    border: 1px solid var(--rule);
    border-radius: 6px;
    padding: 0.8rem 1.2rem;
    flex: 1;
    min-width: 120px;
    text-align: center;
}
.readout-card .rc-label {
    font-family: var(--sans);
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.readout-card .rc-value {
    font-family: var(--mono);
    font-size: 1.4rem;
    font-weight: 500;
    color: var(--ink);
    margin-top: 0.2rem;
}

/* ========== CALLOUT ========== */
.callout {
    background: var(--accent-glow);
    border-left: 4px solid var(--accent);
    border-radius: 0 6px 6px 0;
    padding: 1.2rem 1.6rem;
    margin: 2.5rem 0;
}
.callout p {
    font-size: 0.95rem;
    color: var(--ink-soft);
    margin: 0;
    line-height: 1.6;
}
.callout em { color: var(--accent); font-style: italic; }

/* ========== CHAPTER FOOT LINK ========== */
.chapter-foot {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--sans);
    font-size: 0.88rem;
    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.8rem;
}
.chapter-foot .arrow {
    display: inline-block;
    transition: transform 0.2s;
}
.chapter-foot:hover .arrow { transform: translateX(4px); }

/* ========== TABLES ========== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--sans);
    font-size: 0.82rem;
    margin: 1.5rem 0;
}
.data-table th {
    background: var(--bg);
    font-weight: 600;
    color: var(--ink-soft);
    text-align: left;
    padding: 0.6rem 0.8rem;
    border-bottom: 2px solid var(--rule);
}
.data-table td {
    padding: 0.5rem 0.8rem;
    border-bottom: 1px solid var(--rule);
    color: var(--ink);
    font-family: var(--mono);
    font-size: 0.8rem;
}
.data-table tr:hover td { background: rgba(0,0,0,0.02); }

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

/* ========== STRATEGY CARDS ========== */
.strategy-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.8rem;
    margin-bottom: 1.4rem;
}
.strategy-card {
    background: var(--bg-elevated);
    border: 2px solid var(--rule);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    text-align: center;
}
.strategy-card:hover {
    border-color: var(--midmarket);
}
.strategy-card.selected {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
}
.strategy-card .sc-title {
    font-family: var(--sans);
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 0.3rem;
}
.strategy-card .sc-desc {
    font-family: var(--serif);
    font-size: 0.78rem;
    color: var(--ink-muted);
}

/* ========== BUTTON ========== */
.btn {
    font-family: var(--sans);
    font-size: 0.82rem;
    font-weight: 500;
    padding: 0.6rem 1.4rem;
    border: 1px solid var(--rule);
    border-radius: 6px;
    background: var(--bg-elevated);
    color: var(--ink);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}
.btn:hover {
    background: var(--bg);
    border-color: var(--ink-muted);
}
.btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* ========== FOOTER ========== */
.site-footer {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 4rem 28px 3rem;
    border-top: 2px solid var(--rule);
    margin-top: 2rem;
}
.footer-refs {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}
.footer-meta {
    font-family: var(--sans);
    font-size: 0.78rem;
    color: var(--ink-muted);
    line-height: 1.6;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .cover-title { font-size: 2.2rem; }
    .cover-pillars { grid-template-columns: 1fr; }
    .strategy-cards { grid-template-columns: 1fr; }
    .chart-grid.cols-2 { grid-template-columns: 1fr; }
    .chapter { padding: 5rem 16px 3rem; }
    .slider-group { flex-direction: column; }
    h2 { font-size: 1.8rem; }
}

/* ========== MISC ========== */
.prose-indent {
    text-indent: 2rem;
}
.hide { display: none; }
