/* ── Theme tokens ──────────────────────────────────────────── */
:root {
    --bg:           #f8fafc;
    --surface:      #ffffff;
    --surface-2:    #f1f5f9;
    --border:       #e2e8f0;
    --text:         #1e293b;
    --text-muted:   #64748b;
    --accent:       #4f46e5;
    --accent-dim:   rgba(79,70,229,0.08);
    --link:         #4f46e5;
    --code-bg:      #f1f5f9;
    --shadow:       0 1px 3px rgba(0,0,0,0.07);
    --shadow-md:    0 4px 8px rgba(0,0,0,0.08);
    --radius:       8px;
    --header-h:     60px;
    --sidebar-w:    240px;
    --font:         'Inter', system-ui, sans-serif;
    --mono:         'JetBrains Mono', monospace;
}
[data-theme="dark"] {
    --bg:           #0f172a;
    --surface:      #1e293b;
    --surface-2:    #263248;
    --border:       #334155;
    --text:         #e2e8f0;
    --text-muted:   #94a3b8;
    --accent:       #818cf8;
    --accent-dim:   rgba(129,140,248,0.1);
    --link:         #818cf8;
    --code-bg:      #1e293b;
    --shadow:       0 1px 3px rgba(0,0,0,0.4);
    --shadow-md:    0 4px 8px rgba(0,0,0,0.4);
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    font-size: 16px;
    transition: background 0.2s, color 0.2s;
}

/* ── Header ────────────────────────────────────────────────── */
.site-header {
    position: fixed; top: 0; left: 0; right: 0;
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    box-shadow: var(--shadow);
}
.header-inner {
    max-width: 1400px; margin: 0 auto; padding: 0 20px;
    height: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.header-badge {
    padding: 3px 10px; background: var(--accent-dim); color: var(--accent);
    border-radius: 999px; font-size: 11px; font-weight: 600;
    letter-spacing: 0.05em; text-transform: uppercase; white-space: nowrap; flex-shrink: 0;
}
.header-title {
    font-size: 14px; font-weight: 600; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.header-controls { display: flex; gap: 8px; flex-shrink: 0; }
.ctrl-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text);
    font-family: var(--font); font-size: 13px; font-weight: 500;
    cursor: pointer; transition: all 0.15s; white-space: nowrap;
    text-decoration: none;
}
.ctrl-btn:hover { background: var(--surface-2); border-color: var(--accent); color: var(--accent); }

/* ── Layout ────────────────────────────────────────────────── */
.layout {
    display: flex; max-width: 1400px; margin: 0 auto;
    padding-top: var(--header-h); min-height: 100vh;
}

/* ── Sidebar / TOC ─────────────────────────────────────────── */
.sidebar { width: var(--sidebar-w); flex-shrink: 0; padding: 28px 0 28px 20px; }
.toc {
    position: sticky; top: calc(var(--header-h) + 20px);
    max-height: calc(100vh - var(--header-h) - 40px); overflow-y: auto;
}
.toc-label {
    font-size: 11px; font-weight: 700; letter-spacing: 0.07em;
    text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; padding-left: 10px;
}
.toc-list { list-style: none; }
.toc-list li { margin-bottom: 2px; }
.toc-list a {
    display: block; padding: 4px 10px; border-radius: 6px;
    color: var(--text-muted); text-decoration: none; font-size: 13px;
    border-left: 2px solid transparent; transition: all 0.15s;
}
.toc-list a:hover { color: var(--text); background: var(--surface-2); }
.toc-list a.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-dim); }

/* ── Main content ──────────────────────────────────────────── */
.main-content { flex: 1; min-width: 0; padding: 40px 28px 80px 36px; max-width: 860px; }

/* ── Article typography ────────────────────────────────────── */
.article h1 { font-size: 2rem; font-weight: 700; line-height: 1.2; letter-spacing: -0.02em; margin-bottom: 16px; }
.article h2 {
    font-size: 1.35rem; font-weight: 700; line-height: 1.3; letter-spacing: -0.01em;
    margin-top: 48px; margin-bottom: 14px; padding-top: 16px; border-top: 1px solid var(--border);
}
.article h3 { font-size: 1.05rem; font-weight: 600; margin-top: 24px; margin-bottom: 10px; }
.article p  { margin-bottom: 14px; max-width: 72ch; }
.article ul, .article ol { padding-left: 22px; margin-bottom: 14px; max-width: 72ch; }
.article li { margin-bottom: 5px; }
.article a  { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
.article strong { font-weight: 600; }
.article em { font-style: italic; }
.article hr { border: none; border-top: 1px solid var(--border); margin: 36px 0; }

/* Code */
.article code {
    font-family: var(--mono); font-size: 0.85em;
    background: var(--code-bg); padding: 2px 5px; border-radius: 4px;
}
.article pre {
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px; overflow-x: auto; margin-bottom: 18px;
}
.article pre code { background: none; padding: 0; font-size: 0.875rem; line-height: 1.6; }

/* Tables */
.article table { width: 100%; border-collapse: collapse; margin-bottom: 22px; font-size: 0.875rem; box-shadow: var(--shadow); border-radius: var(--radius); overflow: hidden; }
.article th { background: var(--surface-2); font-weight: 600; text-align: left; padding: 9px 14px; border-bottom: 2px solid var(--border); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.article td { padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.article tr:last-child td { border-bottom: none; }
.article tr:nth-child(even) td { background: var(--surface-2); }
.article td[align="right"], .article th[align="right"] { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Timeline ──────────────────────────────────────────────── */
.timeline { position: relative; padding: 8px 0; margin: 24px 0; }
.tl-legend {
    display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 28px;
    padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.tl-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.tl-legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.tl-spine {
    position: absolute; left: 108px; top: 0; bottom: 0; width: 2px;
    background: linear-gradient(to bottom, transparent, var(--border) 4%, var(--border) 96%, transparent);
}
.tl-item { display: flex; align-items: flex-start; margin-bottom: 20px; position: relative; }
.tl-date-col { width: 108px; flex-shrink: 0; padding-right: 22px; padding-top: 13px; text-align: right; }
.tl-date { font-size: 11px; font-weight: 600; color: var(--text-muted); line-height: 1.3; display: block; }
.tl-dot-col { width: 2px; position: relative; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; }
.tl-dot {
    width: 13px; height: 13px; border-radius: 50%;
    background: var(--cat, #6366f1); border: 2px solid var(--surface);
    box-shadow: 0 0 0 2px var(--cat, #6366f1);
    margin-top: 13px; flex-shrink: 0; position: relative; z-index: 1;
}
.tl-body { flex: 1; min-width: 0; padding-left: 22px; padding-bottom: 4px; }
.tl-card {
    background: var(--surface); border: 1px solid var(--border);
    border-left: 3px solid var(--cat, #6366f1);
    border-radius: 0 var(--radius) var(--radius) 0;
    padding: 10px 14px; box-shadow: var(--shadow); transition: transform 0.15s, box-shadow 0.15s;
}
.tl-card:hover { transform: translateX(2px); box-shadow: var(--shadow-md); }
.tl-event { font-size: 13.5px; line-height: 1.5; }
.tl-year { position: relative; margin: 28px 0 16px; padding-left: 130px; }
.tl-year span {
    font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
    color: var(--accent); background: var(--bg); padding: 0 8px; position: relative; z-index: 1;
}
.tl-year::before { content: ''; position: absolute; left: 108px; top: 50%; width: 100%; height: 1px; background: var(--border); }

/* ── Glossary ──────────────────────────────────────────────── */
.glossary-list { margin: 0; }
.glossary-list dt { font-weight: 600; margin-top: 18px; padding-bottom: 3px; border-bottom: 1px solid var(--border); }
.glossary-list dd { margin: 6px 0 0 16px; color: var(--text-muted); font-size: 0.9rem; line-height: 1.6; }

/* ── Timeline Graph ─────────────────────────────────────────── */
.tl-graph-wrap { margin-bottom: 32px; }
.tl-graph-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.tl-graph-title { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); }
.tl-graph-nav { display: flex; gap: 6px; align-items: center; }
.tl-graph-btn {
    background: var(--surface); border: 1px solid var(--border); color: var(--text);
    width: 26px; height: 26px; border-radius: 6px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 13px;
    transition: background 0.15s, border-color 0.15s;
}
.tl-graph-btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--accent); }
.tl-graph-btn:disabled { opacity: 0.3; cursor: default; }
.tl-graph-counter { font-size: 11px; color: var(--text-muted); min-width: 52px; text-align: center; }
.tl-graph-rail {
    display: flex; align-items: center; justify-content: space-between; flex-wrap: nowrap;
    padding: 14px 16px; gap: 3px; position: relative; overflow: hidden;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.tl-graph-rail::before {
    content: ''; position: absolute; left: 16px; right: 16px; top: 50%;
    height: 1px; background: var(--border); pointer-events: none;
}
.tl-graph-dot {
    width: 11px; height: 11px; border-radius: 50%; flex-shrink: 0;
    background: currentColor; border: 2px solid var(--surface);
    box-shadow: 0 0 0 2px currentColor;
    cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; z-index: 1; position: relative;
}
.tl-graph-dot:hover { transform: scale(1.4); }
.tl-graph-dot.active {
    transform: scale(1.6);
    box-shadow: 0 0 0 3px currentColor, 0 0 0 7px color-mix(in srgb, currentColor 25%, transparent);
}
.tl-scroll-box {
    max-height: 520px; overflow-y: auto; scroll-behavior: smooth;
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 8px 0; margin-top: 12px; position: relative;
}
.tl-scroll-box::-webkit-scrollbar { width: 5px; }
.tl-scroll-box::-webkit-scrollbar-track { background: transparent; }
.tl-scroll-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.tl-item.tl-active .tl-card { animation: tl-flash 1.4s ease-out; }
@keyframes tl-flash {
    0%   { background: color-mix(in srgb, var(--accent) 22%, var(--surface)); }
    100% { background: var(--surface); }
}

/* ── Glossary tooltips ──────────────────────────────────────── */
.gloss-term {
    text-decoration-line: underline;
    text-decoration-style: wavy;
    text-decoration-color: rgba(234, 179, 8, 0.55);
    text-underline-offset: 3px;
    cursor: help;
}
.gloss-tooltip {
    position: fixed; z-index: 9999;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
    padding: 10px 14px; max-width: 300px;
    font-size: 12.5px; line-height: 1.5; color: var(--text);
    box-shadow: var(--shadow-md); pointer-events: none;
    opacity: 0; transition: opacity 0.12s;
}
.gloss-tooltip.visible { opacity: 1; }
.gloss-tooltip .gt-term { font-weight: 700; font-size: 12px; color: var(--accent); margin-bottom: 4px; }
.gloss-tooltip .gt-def { color: var(--text-muted); }

/* ── Landing page ───────────────────────────────────────────── */
.landing-content {
    max-width: 860px; margin: 0 auto;
    padding: calc(var(--header-h) + 48px) 28px 80px;
}
.landing-hero { margin-bottom: 48px; }
.landing-hero h1 {
    font-size: 2rem; font-weight: 700; letter-spacing: -0.02em;
    line-height: 1.2; margin-bottom: 10px;
}
.landing-hero p { color: var(--text-muted); font-size: 1rem; max-width: 60ch; }
.posts-label {
    font-size: 11px; font-weight: 700; letter-spacing: 0.07em;
    text-transform: uppercase; color: var(--text-muted); margin-bottom: 16px;
}
.post-list { display: flex; flex-direction: column; gap: 14px; }
.post-card {
    display: block; text-decoration: none; color: inherit;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px 24px;
    box-shadow: var(--shadow); transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.post-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--accent); }
.post-card-meta {
    display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.post-card-badge {
    padding: 2px 8px; background: var(--accent-dim); color: var(--accent);
    border-radius: 999px; font-size: 10px; font-weight: 600;
    letter-spacing: 0.05em; text-transform: uppercase;
}
.post-card-date { font-size: 12px; color: var(--text-muted); }
.post-card h2 {
    font-size: 1.1rem; font-weight: 600; line-height: 1.35;
    margin-bottom: 6px; color: var(--text);
}
.post-card p { font-size: 0.9rem; color: var(--text-muted); max-width: 68ch; line-height: 1.6; }
.post-card-langs { margin-top: 10px; font-size: 11px; color: var(--text-muted); }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar { display: none; }
    .main-content { padding: 28px 16px 60px; max-width: 100%; }
    .landing-content { padding: calc(var(--header-h) + 28px) 16px 60px; }
}
@media (max-width: 560px) {
    .header-title { display: none; }
    .tl-spine { left: 72px; }
    .tl-date-col { width: 72px; }
    .tl-year { padding-left: 94px; }
    .tl-year::before { left: 72px; }
}
