:root {
    --bg: #050508;
    --bg-elev: rgba(16, 16, 22, 0.72);
    --border: rgba(255, 255, 255, 0.09);
    --text: #eceaf2;
    --muted: #9b96a8;
    --accent: #a5b4fc;
    --accent-hot: #f472b6;
    --prose: #d8d4e4;
    --pre-bg: #0c0c12;
    --blockquote-bg: rgba(255, 255, 255, 0.03);
    --code-bg: rgba(255, 255, 255, 0.06);
    --card-hover-border: rgba(165, 180, 252, 0.28);
    --tag-border: rgba(165, 180, 252, 0.35);
    --filter-pill-border: rgba(165, 180, 252, 0.35);
    --filter-pill-bg: rgba(165, 180, 252, 0.08);
    --nav-hover-border: rgba(165, 180, 252, 0.35);
    --nav-pill-bg: rgba(255, 255, 255, 0.03);
    --card-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.55);
    --radius: 1.1rem;
    --font-sans: "Syne", system-ui, sans-serif;
    --font-serif: "Instrument Serif", Georgia, serif;
}

html[data-theme="light"] {
    --bg: #f3f0fb;
    --bg-elev: rgba(255, 255, 255, 0.82);
    --border: rgba(22, 18, 40, 0.1);
    --text: #161222;
    --muted: #5b5569;
    --accent: #4338ca;
    --accent-hot: #be185d;
    --prose: #3a3548;
    --pre-bg: #1e1b2e;
    --blockquote-bg: rgba(67, 56, 202, 0.06);
    --code-bg: rgba(22, 18, 40, 0.06);
    --card-hover-border: rgba(67, 56, 202, 0.28);
    --tag-border: rgba(67, 56, 202, 0.28);
    --filter-pill-border: rgba(67, 56, 202, 0.25);
    --filter-pill-bg: rgba(67, 56, 202, 0.08);
    --nav-hover-border: rgba(67, 56, 202, 0.35);
    --nav-pill-bg: rgba(255, 255, 255, 0.65);
    --card-shadow: 0 18px 44px -16px rgba(22, 18, 40, 0.12);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-sans);
    color: var(--text);
    background: var(--bg);
    line-height: 1.55;
}

a {
    color: inherit;
    text-decoration: none;
}

.mesh {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse 70% 45% at 15% -5%, rgba(99, 102, 241, 0.32), transparent 55%),
        radial-gradient(ellipse 55% 40% at 95% 5%, rgba(244, 114, 182, 0.18), transparent 48%),
        radial-gradient(ellipse 45% 55% at 45% 105%, rgba(45, 212, 191, 0.1), transparent 42%),
        var(--bg);
}

html[data-theme="light"] .mesh {
    background:
        radial-gradient(ellipse 72% 48% at 12% -8%, rgba(99, 102, 241, 0.14), transparent 58%),
        radial-gradient(ellipse 58% 42% at 96% 4%, rgba(236, 72, 153, 0.1), transparent 52%),
        radial-gradient(ellipse 48% 58% at 48% 102%, rgba(45, 212, 191, 0.08), transparent 46%),
        var(--bg);
}

.noise {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0.035;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

html[data-theme="light"] .noise {
    opacity: 0.022;
}

.shell {
    position: relative;
    z-index: 1;
    max-width: min(1580px, 94vw);
    margin: 0 auto;
    padding: clamp(1rem, 3vw, 1.75rem) clamp(1rem, 3vw, 1.75rem) 3rem;
}

/* Top bar */
.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem 1.5rem;
    margin-bottom: clamp(1.75rem, 4vw, 2.75rem);
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.topbar__nav-wrap {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: flex-end;
    gap: 0.75rem 1rem;
    flex: 1;
    min-width: min(100%, 12rem);
}

.brand {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.brand small {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--muted);
}

.brand a.main {
    font-family: var(--font-serif);
    font-size: clamp(1.35rem, 3.5vw, 1.85rem);
    font-weight: 400;
    letter-spacing: -0.02em;
    background: linear-gradient(120deg, var(--text), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

html[data-theme="light"] .brand a.main {
    background: linear-gradient(120deg, #120c24, #4f46e5);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.brand a.main:hover {
    opacity: 0.92;
}

/* Theme toggle */
.theme-toggle {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-family: var(--font-sans);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 0.45rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--nav-pill-bg);
    cursor: pointer;
    transition: border-color 0.25s, color 0.25s, background 0.25s, transform 0.2s;
}

.theme-toggle:hover {
    color: var(--text);
    border-color: var(--nav-hover-border);
    transform: translateY(-1px);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.theme-toggle__icon {
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--accent-hot), #fcd34d 55%, var(--accent));
    box-shadow: 0 0 0 2px var(--border);
}

html[data-theme="light"] .theme-toggle__icon {
    background: linear-gradient(145deg, #4338ca, #818cf8 50%, #fbbf24);
}

/* Topic nav */
.topic-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    justify-content: flex-end;
    flex: 1;
    min-width: 0;
}

.topic-nav a {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 0.45rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--nav-pill-bg);
    color: var(--muted);
    white-space: nowrap;
    transition: border-color 0.25s, color 0.25s, background 0.25s, transform 0.2s;
}

.topic-nav a:hover {
    color: var(--text);
    border-color: var(--nav-hover-border);
    transform: translateY(-1px);
}

.topic-nav a.is-active {
    color: #f8f7ff;
    background: linear-gradient(135deg, var(--accent), #c4b5fd);
    border-color: transparent;
}

html[data-theme="light"] .topic-nav a.is-active {
    color: #fff;
}

/* Hero (index) */
.hero {
    margin-bottom: 2rem;
    animation: rise 0.75s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes rise {
    from {
        opacity: 0;
        transform: translateY(18px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hero h1 {
    font-family: var(--font-serif);
    font-weight: 400;
    font-size: clamp(2rem, 5vw, 3rem);
    line-height: 1.1;
    margin: 0 0 0.65rem;
    letter-spacing: -0.02em;
}

.hero h1 em {
    font-style: italic;
    color: var(--accent-hot);
}

.hero p {
    margin: 0;
    max-width: 42rem;
    color: var(--muted);
    font-weight: 500;
    font-size: 1rem;
}

.filter-pill {
    display: inline-flex;
    margin-top: 1rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent);
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--filter-pill-border);
    background: var(--filter-pill-bg);
}

/* Post grid — wider shell + ~30% wider min column → often 4 across on desktop */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
    gap: 1.25rem;
}

@media (min-width: 1400px) {
    .grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

.card {
    display: flex;
    flex-direction: column;
    padding: 1.75rem 1.65rem 1.5rem;
    min-width: 0;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-elev);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    box-shadow: var(--card-shadow);
    transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1), border-color 0.3s;
    animation: card-in 0.65s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.card:nth-child(1) { animation-delay: 0.04s; }
.card:nth-child(2) { animation-delay: 0.08s; }
.card:nth-child(3) { animation-delay: 0.12s; }
.card:nth-child(4) { animation-delay: 0.16s; }
.card:nth-child(5) { animation-delay: 0.2s; }
.card:nth-child(6) { animation-delay: 0.24s; }
.card:nth-child(7) { animation-delay: 0.28s; }
.card:nth-child(8) { animation-delay: 0.32s; }
.card:nth-child(9) { animation-delay: 0.36s; }
.card:nth-child(10) { animation-delay: 0.4s; }
.card:nth-child(11) { animation-delay: 0.44s; }
.card:nth-child(12) { animation-delay: 0.48s; }

@keyframes card-in {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.99);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.card:hover {
    transform: translateY(-4px);
    border-color: var(--card-hover-border);
}

.card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    margin-bottom: 0.65rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.card-meta .tag {
    color: var(--accent);
    border: 1px solid var(--tag-border);
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    white-space: nowrap;
}

.card h2 {
    font-size: 1.12rem;
    font-weight: 700;
    margin: 0 0 0.5rem;
    letter-spacing: -0.02em;
    line-height: 1.25;
    min-width: 0;
}

.card h2 a {
    display: inline;
}

.card h2 a:hover {
    color: var(--accent);
}

.card .excerpt {
    margin: 0;
    flex: 1;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--muted);
    line-height: 1.55;
    min-width: 0;
}

.card .read {
    margin-top: 1rem;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text);
    opacity: 0.85;
}

.card:hover .read {
    color: var(--accent-hot);
}

/* Article — one centered column (readable line length, uses horizontal space evenly) */
.article-wrap {
    animation: rise 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
    max-width: min(52rem, 100%);
    margin-inline: auto;
}

.article-head {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.article-head .meta {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.75rem;
}

.article-head .meta .tag {
    color: var(--accent);
    margin-right: 0.5rem;
}

.article-head h1 {
    font-family: var(--font-serif);
    font-weight: 400;
    font-size: clamp(2rem, 5vw, 2.85rem);
    line-height: 1.08;
    margin: 0 0 1rem;
    letter-spacing: -0.02em;
}

.back-row {
    margin-bottom: 1.25rem;
}

.back-row a {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.back-row a:hover {
    color: var(--accent);
}

/* Prose (Parsedown output) — width comes from .article-wrap */
.prose {
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--prose);
    max-width: none;
}

.prose > * + * {
    margin-top: 1rem;
}

.prose h2 {
    font-family: var(--font-serif);
    font-weight: 400;
    font-size: 1.65rem;
    margin: 2rem 0 0.75rem;
    letter-spacing: -0.02em;
    color: var(--text);
}

.prose h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin: 1.5rem 0 0.5rem;
    letter-spacing: -0.01em;
}

.prose p {
    margin: 0;
    line-height: 1.7;
}

.prose a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.prose a:hover {
    color: var(--accent-hot);
}

.prose ul,
.prose ol {
    margin: 0.5rem 0 0;
    padding-left: 1.25rem;
}

.prose li {
    margin: 0.35rem 0;
}

.prose blockquote {
    margin: 1.25rem 0;
    padding: 0.85rem 1rem 0.85rem 1.1rem;
    border-left: 3px solid rgba(244, 114, 182, 0.65);
    background: var(--blockquote-bg);
    border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--muted);
    font-style: italic;
}

html[data-theme="light"] .prose blockquote {
    border-left-color: rgba(190, 24, 93, 0.45);
}

.prose code {
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: 0.88em;
    padding: 0.12rem 0.35rem;
    border-radius: 0.35rem;
    background: var(--code-bg);
    border: 1px solid var(--border);
}

.prose pre {
    margin: 1rem 0;
    padding: 1rem 1.1rem;
    overflow-x: auto;
    border-radius: var(--radius);
    background: var(--pre-bg);
    border: 1px solid var(--border);
    font-size: 0.88rem;
}

.prose pre code {
    border: 0;
    padding: 0;
    background: none;
}

.prose hr {
    border: 0;
    height: 1px;
    margin: 2rem 0;
    background: linear-gradient(90deg, transparent, var(--border), transparent);
}

.prose strong {
    color: var(--text);
    font-weight: 700;
}

/* Tables & figures (analytics-style posts) */
.prose .table-scroll {
    margin: 1.25rem 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.prose .table-scroll table {
    margin: 0;
}

.prose table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.25rem 0;
    font-size: 0.86rem;
    line-height: 1.45;
}

.prose th,
.prose td {
    border: 1px solid var(--border);
    padding: 0.5rem 0.6rem;
    text-align: left;
    vertical-align: top;
}

.prose th {
    background: var(--filter-pill-bg);
    color: var(--text);
    font-weight: 700;
    white-space: nowrap;
}

.prose td.num,
.prose th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.prose tr:nth-child(even) td {
    background: rgba(255, 255, 255, 0.02);
}

html[data-theme="light"] .prose tr:nth-child(even) td {
    background: rgba(0, 0, 0, 0.03);
}

.prose caption {
    caption-side: bottom;
    text-align: left;
    font-size: 0.82rem;
    color: var(--muted);
    padding: 0.5rem 0.25rem 0;
}

.prose img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1.15rem 0;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.prose figure {
    margin: 1.35rem 0;
}

.prose figcaption {
    font-size: 0.84rem;
    color: var(--muted);
    margin-top: 0.45rem;
    line-height: 1.45;
}

.prose .callout-tools {
    margin: 1.25rem 0;
    padding: 1rem 1.15rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--filter-pill-bg);
    font-size: 0.92rem;
}

.prose .callout-tools h3 {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
}

/* Empty state */
.empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--muted);
    font-weight: 600;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
}

.empty code {
    font-family: ui-monospace, "Cascadia Code", monospace;
    font-size: 0.88em;
    padding: 0.12rem 0.35rem;
    border-radius: 0.35rem;
    background: var(--code-bg);
    border: 1px solid var(--border);
}

footer.site {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
    .hero,
    .card,
    .article-wrap {
        animation: none;
    }
    .card:hover {
        transform: none;
    }
    html {
        scroll-behavior: auto;
    }
}
