:root {
  --ink: #17171a;
  --muted: #6f7079;
  --paper: #fbfbfa;
  --card: #fff;
  --line: #deded9;
  --accent: #6755e7;
  --accent-soft: #e8e4ff;
  --max: 1240px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body::before { position: fixed; inset: 0; z-index: -1; background: radial-gradient(circle at 78% 4%, rgba(103,85,231,.11), transparent 25rem), radial-gradient(circle at 4% 35%, rgba(115,202,190,.1), transparent 22rem); content: ''; pointer-events: none; }
a { color: inherit; }
button, input { font: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.nav, footer, .reader-nav { max-width: var(--max); margin: auto; padding: 24px 32px; display: flex; align-items: center; justify-content: space-between; }
.nav { border-bottom: 1px solid rgba(222,222,217,.7); }
.brand { font-size: 1.3rem; font-weight: 800; letter-spacing: -.06em; text-decoration: none; }
.brand span { color: var(--accent); }
.nav nav { display: flex; gap: 28px; }
.nav nav a { color: var(--muted); font-size: .88rem; text-decoration: none; }
.nav nav a:hover { color: var(--ink); }

.hero { max-width: var(--max); margin: auto; padding: 72px 32px 50px; }
.eyebrow { margin: 0 0 18px; color: var(--accent); font-size: .68rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.hero-copy { display: flex; align-items: end; justify-content: space-between; gap: 40px; }
h1 { margin: 0; font-size: clamp(3rem, 6vw, 5.2rem); font-weight: 600; letter-spacing: -.065em; line-height: .96; }
h1 em { color: var(--muted); font-family: Georgia, serif; font-weight: 400; }
.intro { max-width: 410px; margin: 0 0 5px; color: var(--muted); font-size: .95rem; line-height: 1.6; }

.library { max-width: var(--max); margin: auto; padding: 0 32px 110px; }
.toolbar { padding: 22px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.search { min-width: min(420px, 75vw); display: flex; align-items: center; gap: 10px; }
.search span { color: var(--muted); font-size: 1.3rem; }
.search input { width: 100%; padding: 10px 0; color: var(--ink); background: transparent; border: 0; outline: 0; font-size: 1rem; }
.toolbar p { color: var(--muted); font-size: .8rem; }
.chips { display: flex; gap: 8px; padding: 22px 0 48px; overflow-x: auto; scrollbar-width: none; }
.chip { flex: none; padding: 8px 13px; color: var(--muted); background: rgba(255,255,255,.6); border: 1px solid var(--line); border-radius: 999px; cursor: pointer; font-size: .74rem; }
.chip:hover, .chip.active { color: #fff; background: var(--ink); border-color: var(--ink); }
.section-heading { margin-bottom: 20px; display: flex; align-items: end; justify-content: space-between; }
.section-heading h2 { margin: 0; font-size: 1.35rem; letter-spacing: -.04em; }
.section-heading span { color: var(--muted); font-size: .78rem; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.post { min-height: 245px; padding: 26px; overflow: hidden; position: relative; background: rgba(255,255,255,.84); border: 1px solid rgba(222,222,217,.85); border-radius: 18px; display: flex; flex-direction: column; cursor: pointer; transition: transform .2s, box-shadow .2s, border-color .2s; }
.post::after { position: absolute; right: -35px; bottom: -55px; width: 125px; height: 125px; background: var(--accent-soft); border-radius: 50%; content: ''; opacity: .65; transition: transform .3s; }
.post:hover { transform: translateY(-4px); border-color: #cbc5fa; box-shadow: 0 18px 45px rgba(29,25,68,.09); }
.post:hover::after { transform: scale(1.18); }
.post:first-child { grid-column: span 2; color: #fff; background: var(--ink); border-color: var(--ink); }
.post:first-child::after { width: 210px; height: 210px; right: -45px; bottom: -100px; background: var(--accent); opacity: .7; }
.post:first-child .category { color: #a99dff; }
.post:first-child h2 { max-width: 620px; color: #fff; font-size: clamp(1.8rem, 3vw, 2.65rem); }
.post:first-child .meta { color: #aaaab1; }
.post .category { margin: 0; color: var(--accent); font-size: .68rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.post h2 { position: relative; z-index: 1; max-width: 500px; margin: 18px 0; font-size: 1.35rem; font-weight: 580; line-height: 1.25; letter-spacing: -.035em; }
.post .meta { position: relative; z-index: 1; margin: auto 0 0; color: var(--muted); font-size: .75rem; }
.empty { padding: 70px 0; color: var(--muted); text-align: center; }

footer { padding-top: 42px; padding-bottom: 42px; border-top: 1px solid var(--line); }
footer p { color: var(--muted); font-size: .82rem; }

.reader { position: fixed; inset: 0; z-index: 5; overflow-y: auto; background: var(--paper); }
.reader-nav { position: sticky; top: 0; z-index: 2; max-width: none; background: rgba(247,247,245,.92); border-bottom: 1px solid var(--line); backdrop-filter: blur(14px); }
.reader-nav button { padding: 0; color: var(--muted); background: none; border: 0; cursor: pointer; }
.article-shell { max-width: 1080px; margin: auto; padding: 80px 32px 120px; display: grid; grid-template-columns: 190px minmax(0, 720px); gap: 65px; }
.toc { position: sticky; top: 110px; align-self: start; display: grid; gap: 10px; max-height: calc(100vh - 140px); overflow: auto; }
.toc a { color: var(--muted); font-size: .73rem; line-height: 1.4; text-decoration: none; }
.toc a:hover { color: var(--accent); }
.prose { min-width: 0; font-family: Georgia, serif; font-size: 1.06rem; line-height: 1.8; }
.prose h1, .prose h2, .prose h3 { color: var(--ink); font-family: Inter, sans-serif; letter-spacing: -.045em; line-height: 1.12; scroll-margin-top: 110px; }
.prose h1 { margin: 0 0 42px; font-size: clamp(2.8rem, 6vw, 5rem); }
.prose h2 { margin: 70px 0 20px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 2rem; }
.prose h3 { margin-top: 38px; font-size: 1.35rem; }
.prose p, .prose li { color: #38383d; }
.prose a { color: var(--accent); text-underline-offset: 3px; }
.prose blockquote { margin: 30px 0; padding: 3px 24px; color: var(--muted); border-left: 3px solid var(--accent); }
.prose pre { margin: 28px 0; padding: 22px; overflow-x: auto; color: #e9e9ef; background: #1d1d22; border-radius: 14px; font: .82rem/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; }
.prose code { padding: .15em .35em; background: var(--accent-soft); border-radius: 4px; font-size: .85em; }
.prose pre code { padding: 0; background: none; }
.prose table { width: 100%; margin: 28px 0; border-collapse: collapse; font-family: Inter, sans-serif; font-size: .85rem; }
.prose th, .prose td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.prose img, .prose svg { max-width: 100%; }
.prose .mermaid { margin: 32px 0; padding: 24px; overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 16px; text-align: center; }
.loader { min-height: 55vh; display: grid; place-content: center; justify-items: center; gap: 16px; color: var(--muted); font-family: Inter, sans-serif; font-size: .78rem; letter-spacing: .04em; }
.loader i { width: 30px; height: 30px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  .article-shell { display: block; }
  .toc { display: none; }
}
@media (max-width: 580px) {
  .nav, footer, .reader-nav { padding: 22px 20px; }
  .nav nav a:first-child { display: none; }
  .hero { padding: 52px 20px 38px; }
  .hero-copy { align-items: start; flex-direction: column; gap: 18px; }
  .intro { margin: 0; }
  .library { padding: 0 20px 75px; }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .grid { grid-template-columns: 1fr; }
  .post:first-child { grid-column: auto; }
  .post { min-height: 175px; }
  .section-heading span { display: none; }
  .article-shell { padding: 50px 20px 90px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
