/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* === CSS Custom Properties === */
:root {
    --bg: #fafaf9;
    --bg-secondary: #f0efed;
    --text: #1c1917;
    --text-muted: #78716c;
    --accent: #7c3aed;
    --border: #e7e5e4;
    --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
    --neutral-bar: #d6d3d1;
    --header-height: 58px;
    --max-width: 720px;
    --max-width-wide: 940px;
    --font: 'JetBrains Mono', 'Courier New', monospace;
}

[data-theme="dark"] {
    --bg: #111010;
    --bg-secondary: #1a1918;
    --text: #e7e5e4;
    --text-muted: #a8a29e;
    --accent: #34d399;
    --border: #282524;
    --neutral-bar: #3a3735;
}

/* === Base === */
html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background-color: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.75;
    transition: background-color 0.2s ease, color 0.2s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: opacity 0.15s;
}

a:hover {
    opacity: 0.7;
}

/* === Header === */
header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--header-height);
    border-bottom: 1px solid var(--border);
    background-color: color-mix(in srgb, var(--bg) 80%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: background-color 0.2s, border-color 0.2s;
}

header nav {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.logo {
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--text);
    letter-spacing: -0.03em;
    white-space: nowrap;
    flex-shrink: 0;
}

.logo:hover {
    color: var(--accent);
    opacity: 1;
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 1.75rem;
    flex: 1;
    justify-content: center;
}

.nav-links a {
    color: var(--text-muted);
    font-size: 0.82rem;
    transition: color 0.15s;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--accent);
    opacity: 1;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* === Theme Toggle === */
#theme-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.35rem;
    border-radius: 6px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, color 0.15s;
    font-family: var(--font);
}

#theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* === Mobile Menu Button === */
.menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.35rem;
    border-radius: 6px;
    cursor: pointer;
}

.menu-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* === Mobile Menu Overlay === */
#mobile-menu {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background-color: var(--bg);
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#mobile-menu.open {
    display: flex;
}

#mobile-menu ul {
    list-style: none;
    text-align: center;
}

#mobile-menu li {
    margin: 1.1rem 0;
}

#mobile-menu a {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
    transition: color 0.15s;
}

#mobile-menu a:hover {
    color: var(--accent);
    opacity: 1;
}

#close-menu {
    position: absolute;
    top: 1rem;
    right: 1.25rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-family: var(--font);
    line-height: 1;
    padding: 0.5rem;
    display: flex;
}

#close-menu .ico {
    width: 22px;
    height: 22px;
}

#close-menu:hover {
    color: var(--text);
}

/* === Main Content === */
main {
    flex: 1;
    margin-top: var(--header-height);
}

section {
    border-bottom: 1px solid var(--border);
}

.section-content {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 4rem 1.5rem;
}

/* === Loader === */
.loader {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 3rem auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Markdown Rendered Content === */
.md h1 {
    font-size: 1.65rem;
    font-weight: 800;
    margin-bottom: 0.4rem;
    letter-spacing: -0.04em;
    line-height: 1.2;
}

.md h2 {
    font-size: 0.78rem;
    font-weight: 700;
    margin-top: 2.75rem;
    margin-bottom: 1rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.md h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-top: 1.5rem;
    margin-bottom: 0.4rem;
}

.md p {
    margin-bottom: 1rem;
}

.md ul,
.md ol {
    margin: 0.5rem 0 1rem 1.5rem;
}

.md li {
    margin-bottom: 0.2rem;
}

.md strong {
    font-weight: 700;
}

.md em {
    font-style: italic;
}

.md code {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 0.1em 0.4em;
    border-radius: 4px;
    font-size: 0.88em;
    font-family: var(--font);
}

.md pre {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    overflow-x: auto;
    margin: 1rem 0 1.25rem;
}

.md pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.85rem;
    line-height: 1.6;
}

.md blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 1rem;
    color: var(--text-muted);
    margin: 1rem 0;
    font-style: italic;
}

.md hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2rem 0;
}

.md a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.md a:hover {
    opacity: 0.8;
    text-decoration-color: var(--accent);
}

/* === Tags === */
.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.6rem;
}

.tag {
    font-size: 0.72rem;
    padding: 0.2em 0.55em;
    border-radius: 4px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-family: var(--font);
}

/* === Blog Index === */
.blog-header {
    margin-bottom: 2rem;
}

.blog-header h1 {
    font-size: 1.65rem;
    font-weight: 800;
    letter-spacing: -0.04em;
}

.post-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.post-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.post-item:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 16px color-mix(in srgb, var(--accent) 10%, transparent);
}

.post-link {
    display: flex;
    align-items: baseline;
    gap: 1.25rem;
    padding: 1rem 1.25rem;
    color: var(--text);
    text-decoration: none;
    transition: none;
}

.post-link:hover {
    opacity: 1;
}

.post-date {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}

.post-info {
    flex: 1;
    min-width: 0;
}

.post-title {
    font-weight: 600;
    font-size: 0.92rem;
    display: block;
    margin-bottom: 0.15rem;
}

.post-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

.post-item-tags {
    display: flex;
    gap: 0.3rem;
    flex-shrink: 0;
    align-items: center;
}

.empty-state {
    color: var(--text-muted);
    font-size: 0.88rem;
    padding: 2rem 0;
}

/* === Blog Post View === */
.post-back {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 2.5rem;
    transition: color 0.15s;
    cursor: pointer;
    background: none;
    border: none;
    font-family: var(--font);
    padding: 0;
}

.post-back:hover {
    color: var(--accent);
}

.post-meta {
    margin-bottom: 2.5rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border);
}

.post-meta h1 {
    font-size: 1.65rem;
    font-weight: 800;
    margin-bottom: 0.6rem;
    letter-spacing: -0.04em;
    line-height: 1.25;
}

.post-meta-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.post-meta-date {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* === Footer === */
footer {
    padding: 1.75rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: var(--max-width);
    margin: 0 auto;
    width: 100%;
    font-size: 0.78rem;
    color: var(--text-muted);
}

footer a {
    color: var(--text-muted);
    text-decoration: none;
}

footer a:hover {
    color: var(--accent);
    opacity: 1;
}

.footer-links {
    display: flex;
    gap: 1.25rem;
}

/* === Responsive === */
@media (max-width: 640px) {
    .nav-links {
        display: none;
    }

    .menu-btn {
        display: flex;
    }

    .section-content {
        padding: 2.5rem 1.25rem;
    }

    .post-link {
        flex-direction: column;
        gap: 0.4rem;
        align-items: flex-start;
    }

    .post-item-tags {
        display: none;
    }

    footer {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
    }
}

/* === Accessibility === */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 4px;
}

/* === Icons === */
.ico {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    display: inline-block;
    vertical-align: -0.18em;
}

.ico-lg {
    width: 22px;
    height: 22px;
}

.logo-dim {
    color: var(--text-muted);
    font-weight: 500;
}

/* === Hero === */
#hero {
    border-bottom: 1px solid var(--border);
}

.hero-inner {
    max-width: var(--max-width-wide);
    margin: 0 auto;
    padding: 5.5rem 1.5rem 4rem;
}

.hero-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.hero-eyebrow .ico {
    width: 13px;
    height: 13px;
    color: var(--accent);
}

.hero-name {
    font-size: clamp(2rem, 6vw, 3.1rem);
    font-weight: 800;
    letter-spacing: -0.055em;
    line-height: 1.05;
    margin-bottom: 1.1rem;
}

.hero-thesis {
    font-size: clamp(1.05rem, 2.8vw, 1.45rem);
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: -0.025em;
    color: var(--accent);
    max-width: 22ch;
    margin-bottom: 1.25rem;
}

.hero-sub {
    font-size: 0.88rem;
    color: var(--text-muted);
    max-width: 58ch;
    line-height: 1.8;
    margin-bottom: 2rem;
}

.hero-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 3.5rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    padding: 0.5rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    background-color: var(--bg-secondary);
    transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}

.btn:hover {
    opacity: 1;
    border-color: var(--accent);
    color: var(--accent);
}

.btn-primary {
    border-color: color-mix(in srgb, var(--accent) 45%, transparent);
    color: var(--accent);
    background-color: var(--accent-soft);
}

/* === Metric tiles === */
.metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1px;
    background-color: var(--border);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.metric {
    background-color: var(--bg);
    padding: 1.4rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.metric-val {
    font-size: 1.85rem;
    font-weight: 800;
    letter-spacing: -0.05em;
    line-height: 1;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.metric-label {
    font-size: 0.79rem;
    font-weight: 600;
    line-height: 1.45;
}

.metric-note {
    font-size: 0.72rem;
    color: var(--text-muted);
}

/* === Visualization blocks === */
.viz-block {
    max-width: var(--max-width-wide);
    margin: 0 auto;
    padding: 3.5rem 1.5rem 0;
}

.viz-block:first-child {
    padding-top: 4rem;
}

.viz-kicker {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.9rem;
}

.viz-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    max-width: 62ch;
    margin-bottom: 1.75rem;
    line-height: 1.75;
}

.viz-foot {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 1.1rem;
    line-height: 1.7;
    max-width: 68ch;
}

/* === Pillars === */
.pillars {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.pillar {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem 1.1rem;
    background-color: var(--bg-secondary);
    transition: border-color 0.2s;
}

.pillar:hover {
    border-color: color-mix(in srgb, var(--accent) 50%, transparent);
}

.pillar .ico-lg {
    color: var(--accent);
    margin-bottom: 0.7rem;
}

.pillar h3 {
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    margin-bottom: 0.4rem;
}

.pillar p {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.65;
}

/* === Bar chart === */
.bars {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.bar-row {
    display: grid;
    grid-template-columns: 190px 1fr;
    align-items: center;
    gap: 1rem;
}

.bar-label {
    font-size: 0.76rem;
    color: var(--text-muted);
    text-align: right;
}

.bar-label em {
    font-style: normal;
    color: var(--text);
    font-weight: 600;
}

.bar-track {
    background-color: color-mix(in srgb, var(--border) 55%, transparent);
    border-radius: 5px;
    height: 30px;
    overflow: hidden;
}

/* Bars are drawn at full value by default, so the chart is correct with no JS,
   with a broken observer, or in a throttled tab. The animation is added on top:
   .js-anim is set by script.js only at the moment it registers the element. */
.bar-fill {
    height: 100%;
    width: var(--w);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 0.65rem;
    transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1);
    min-width: fit-content;
}

.bars.js-anim:not(.in-view) .bar-fill {
    width: 0;
}

.bar-fill span {
    font-size: 0.73rem;
    font-weight: 700;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.bar-before {
    background-color: var(--neutral-bar);
}

.bar-before span {
    color: var(--text);
}

.bar-after {
    background-color: var(--accent);
}

.bar-after span {
    color: var(--bg);
}

/* === Flow diagram === */
.flow-scroll {
    overflow-x: auto;
    padding-bottom: 0.5rem;
}

.flow {
    display: flex;
    align-items: stretch;
    gap: 0.5rem;
    min-width: max-content;
}

.flow-node {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 0.9rem 1rem;
    background-color: var(--bg-secondary);
    min-width: 150px;
}

.flow-node .ico {
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.flow-node strong {
    font-size: 0.78rem;
    font-weight: 700;
}

.flow-node span {
    font-size: 0.69rem;
    color: var(--text-muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.flow-node-key {
    border-color: color-mix(in srgb, var(--accent) 55%, transparent);
    background-color: var(--accent-soft);
}

.flow-node-key .ico {
    color: var(--accent);
}

.flow-arrow {
    align-self: center;
    color: var(--text-muted);
    opacity: 0.5;
    width: 15px;
    height: 15px;
}

/* === Timeline === */
.timeline {
    list-style: none;
    position: relative;
    padding-left: 1.75rem;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 6px;
    bottom: 6px;
    width: 1px;
    background-color: var(--border);
}

.timeline li {
    position: relative;
    display: grid;
    grid-template-columns: 60px 1fr;
    gap: 1.25rem;
    padding-bottom: 1.5rem;
}

.timeline li:last-child {
    padding-bottom: 0;
}

.timeline li::before {
    content: '';
    position: absolute;
    left: -1.75rem;
    top: 7px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background-color: var(--bg);
    border: 1px solid var(--text-muted);
}

.timeline li.tl-now::before {
    background-color: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

.tl-year {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.tl-now .tl-year {
    color: var(--accent);
}

.tl-body {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.tl-body strong {
    font-size: 0.85rem;
    font-weight: 700;
}

.tl-body span {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.7;
}

/* === Footer icon links === */
.footer-links a {
    display: inline-flex;
    align-items: center;
}

/* === Count-up animation === */
.metric-val {
    transition: opacity 0.3s;
}

/* === Responsive (visualizations) === */
@media (max-width: 900px) {
    .pillars {
        grid-template-columns: repeat(2, 1fr);
    }

    .metrics {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .hero-inner {
        padding: 3.5rem 1.25rem 3rem;
    }

    .viz-block {
        padding: 2.5rem 1.25rem 0;
    }

    .viz-block:first-child {
        padding-top: 3rem;
    }

    .metrics,
    .pillars {
        grid-template-columns: 1fr;
    }

    .bar-row {
        grid-template-columns: 1fr;
        gap: 0.3rem;
    }

    .bar-label {
        text-align: left;
    }

    .timeline li {
        grid-template-columns: 1fr;
        gap: 0.25rem;
    }
}
