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

:root {
    --font-display: 'Space Mono', 'JetBrains Mono', monospace;
    --font-body: 'Source Serif 4', 'Georgia', serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --max-width: 780px;
    --radius: 8px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Dark theme (default) ────────────────────────────── */
[data-theme="dark"] {
    --bg: #08090a;
    --bg-subtle: #0d0f11;
    --bg-card: #111316;
    --bg-card-hover: #161a1e;
    --text: #c8cdd3;
    --text-muted: #6b7280;
    --text-heading: #eef1f5;
    --accent: #5eead4;
    --accent-dim: rgba(94, 234, 212, 0.08);
    --accent-glow: rgba(94, 234, 212, 0.15);
    --border: #1e2128;
    --border-hover: #2d333b;
    --tag-bg: #0d2d2a;
    --tag-text: #5eead4;
    --code-bg: #0f1117;
    --dot-color: rgba(255, 255, 255, 0.03);
}

/* ── Light theme ─────────────────────────────────────── */
[data-theme="light"] {
    --bg: #f8f9fa;
    --bg-subtle: #f0f1f3;
    --bg-card: #ffffff;
    --bg-card-hover: #f5f6f8;
    --text: #2d3748;
    --text-muted: #718096;
    --text-heading: #1a202c;
    --accent: #0d9488;
    --accent-dim: rgba(13, 148, 136, 0.06);
    --accent-glow: rgba(13, 148, 136, 0.12);
    --border: #e2e8f0;
    --border-hover: #cbd5e0;
    --tag-bg: #e6fffa;
    --tag-text: #0d9488;
    --code-bg: #edf2f7;
    --dot-color: rgba(0, 0, 0, 0.03);
}

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.75;
    transition: background var(--transition), color var(--transition);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Dot grid background for depth */
    background-image: radial-gradient(var(--dot-color) 1px, transparent 1px);
    background-size: 24px 24px;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition), opacity var(--transition); }
a:hover { opacity: 0.85; }

/* ── Header ──────────────────────────────────────────── */
.site-header {
    position: sticky; top: 0; z-index: 100;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(16px) saturate(1.2);
    -webkit-backdrop-filter: blur(16px) saturate(1.2);
}
.header-content {
    max-width: var(--max-width); margin: 0 auto; padding: 0.85rem 1.5rem;
    display: flex; align-items: center; justify-content: space-between;
}
.site-title { display: flex; align-items: center; }
.site-logo {
    height: 30px; width: 30px; border-radius: 50%;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.site-title:hover .site-logo { transform: rotate(20deg) scale(1.1); }
.site-nav { display: flex; align-items: center; gap: 1.25rem; }
.nav-link {
    color: var(--text-muted); font-size: 0.82rem; font-weight: 500;
    font-family: var(--font-display); letter-spacing: 0.02em;
    transition: color var(--transition);
}
.nav-link:hover { color: var(--accent); opacity: 1; }

/* ── Theme Toggle ────────────────────────────────────── */
.theme-toggle {
    background: none; border: 1px solid var(--border); border-radius: 50%;
    width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--text-muted);
    transition: all var(--transition);
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); transform: rotate(15deg); }
[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ── Container ───────────────────────────────────────── */
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 1.5rem 5rem; }

/* ── Hero ────────────────────────────────────────────── */
.hero {
    padding: 3.5rem 0 2rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2rem;
}
.hero-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
}
.hero-text { flex: 1; min-width: 0; }
.hero h1 {
    font-family: var(--font-display);
    font-size: 1.75rem; font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.02em;
    animation: fadeSlideIn 0.6s ease both;
}
.hero-subtitle {
    margin-top: 0.4rem;
    color: var(--text-muted);
    font-size: 0.95rem;
    animation: fadeSlideIn 0.6s 0.1s ease both;
}
.hero-logo {
    width: 72px; height: 72px;
    flex-shrink: 0;
    animation: fadeSlideIn 0.6s 0.15s ease both;
}

/* ── Search ──────────────────────────────────────────── */
.search-wrap {
    position: relative; margin-top: 1.5rem;
    animation: fadeSlideIn 0.6s 0.2s ease both;
}
.search-input {
    width: 100%; padding: 0.7rem 1rem 0.7rem 2.5rem;
    background: var(--bg-card); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius);
    font-family: var(--font-mono); font-size: 0.85rem;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.search-input::placeholder { color: var(--text-muted); opacity: 0.5; }
.search-input:focus {
    border-color: var(--accent);
    background: var(--accent-dim);
    box-shadow: 0 0 0 3px var(--accent-glow), 0 1px 3px rgba(0,0,0,0.1);
}
.search-icon {
    position: absolute; left: 0.85rem; top: 50%; transform: translateY(-50%);
    color: var(--text-muted); pointer-events: none;
    transition: color var(--transition);
}
.search-input:focus ~ .search-icon { color: var(--accent); }
.search-kbd {
    position: absolute; right: 0.75rem; top: 50%; transform: translateY(-50%);
    background: var(--bg); border: 1px solid var(--border); border-radius: 4px;
    padding: 0.05rem 0.45rem; font-family: var(--font-mono); font-size: 0.65rem;
    color: var(--text-muted); line-height: 1.6; pointer-events: none;
}
.search-input:focus ~ .search-kbd { display: none; }

.no-results {
    text-align: center; color: var(--text-muted); font-size: 0.9rem;
    padding: 2rem 0; font-style: italic;
}

/* ── Post Cards ──────────────────────────────────────── */
.posts { display: flex; flex-direction: column; gap: 0.75rem; }

.post-card {
    display: block; padding: 1.25rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border); border-radius: var(--radius);
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
    animation: fadeSlideIn 0.5s ease both;
}
.post-card::before {
    content: '';
    position: absolute; left: 0; top: 0; bottom: 0;
    width: 3px; background: var(--accent);
    transform: scaleY(0); transform-origin: bottom;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.post-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    transform: translateX(4px);
    box-shadow: -4px 0 0 var(--accent), 0 2px 12px rgba(0,0,0,0.08);
    opacity: 1;
}
.post-card:hover::before { transform: scaleY(1); }

/* Staggered entrance for cards */
.post-card:nth-child(1) { animation-delay: 0.05s; }
.post-card:nth-child(2) { animation-delay: 0.1s; }
.post-card:nth-child(3) { animation-delay: 0.15s; }
.post-card:nth-child(4) { animation-delay: 0.2s; }
.post-card:nth-child(5) { animation-delay: 0.25s; }
.post-card:nth-child(6) { animation-delay: 0.3s; }
.post-card:nth-child(7) { animation-delay: 0.35s; }
.post-card:nth-child(8) { animation-delay: 0.4s; }

.post-meta {
    display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.4rem;
    font-size: 0.75rem; color: var(--text-muted); font-family: var(--font-mono);
}
.post-date { white-space: nowrap; }
.post-tags { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.post-tag {
    background: var(--tag-bg); color: var(--tag-text);
    padding: 0.1rem 0.5rem; border-radius: 3px;
    font-size: 0.65rem; font-weight: 600;
    letter-spacing: 0.03em; text-transform: uppercase;
}
.post-title {
    font-family: var(--font-display);
    font-size: 1.05rem; font-weight: 700;
    color: var(--text-heading);
    margin-bottom: 0.3rem; line-height: 1.4;
    letter-spacing: -0.01em;
}
.post-summary {
    font-size: 0.88rem; color: var(--text-muted); line-height: 1.6;
}

/* ── Footer ──────────────────────────────────────────── */
.site-footer {
    border-top: 1px solid var(--border); padding: 2.5rem 0; text-align: center;
}
.footer-content {
    max-width: var(--max-width); margin: 0 auto; padding: 0 1.5rem;
    color: var(--text-muted); font-size: 0.8rem;
    font-family: var(--font-mono);
}

/* ── Blog Post Page ──────────────────────────────────── */
.post-header {
    padding: 3.5rem 0 1.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 2rem;
    animation: fadeSlideIn 0.6s ease both;
}
.post-header h1 {
    font-family: var(--font-display);
    font-size: 1.75rem; font-weight: 700;
    color: var(--text-heading);
    letter-spacing: -0.02em; line-height: 1.3;
}
.post-header .post-meta { margin-top: 0.75rem; margin-bottom: 0; }

.post-content {
    padding-bottom: 3rem;
    animation: fadeSlideIn 0.6s 0.15s ease both;
}
.post-content h2 {
    font-family: var(--font-display);
    font-size: 1.25rem; font-weight: 700;
    color: var(--text-heading);
    margin: 2.5rem 0 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
    letter-spacing: -0.01em;
}
.post-content h3 {
    font-family: var(--font-display);
    font-size: 1.05rem; font-weight: 700;
    color: var(--text-heading);
    margin: 1.75rem 0 0.5rem;
}
.post-content p { margin-bottom: 1.25rem; }
.post-content ul, .post-content ol { margin: 0 0 1.25rem 1.5rem; }
.post-content li { margin-bottom: 0.35rem; }
.post-content blockquote {
    border-left: 3px solid var(--accent); padding: 0.75rem 1.25rem; margin: 1.5rem 0;
    color: var(--text-muted); background: var(--accent-dim);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-style: italic;
}
.post-content code {
    font-family: var(--font-mono); font-size: 0.82em;
    background: var(--code-bg); padding: 0.15rem 0.4rem; border-radius: 4px;
    color: var(--accent);
}
.post-content pre {
    background: var(--code-bg); padding: 1.25rem; border-radius: var(--radius);
    overflow-x: auto; margin-bottom: 1.5rem;
    border: 1px solid var(--border);
    position: relative;
}
.post-content pre code { background: none; padding: 0; font-size: 0.82rem; color: var(--text); }
.post-content img { max-width: 100%; height: auto; border-radius: var(--radius); margin: 1.25rem 0; }
.post-content a { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--accent-glow); }
.post-content a:hover { text-decoration-color: var(--accent); }
.post-content figure { margin: 1.75rem 0; text-align: center; }
.post-content figure img { border: 1px solid var(--border); }
.post-content figcaption { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.5rem; font-style: italic; }

/* Tables in post content */
.post-content table {
    width: 100%; border-collapse: collapse; margin: 1.25rem 0;
    font-size: 0.85rem;
}
.post-content th {
    text-align: left; padding: 0.5rem 0.75rem;
    border-bottom: 2px solid var(--border);
    font-family: var(--font-mono); font-size: 0.78rem;
    color: var(--accent); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em;
}
.post-content td {
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
.post-content tr:hover td { background: var(--accent-dim); }

.back-link {
    display: inline-flex; align-items: center; gap: 0.35rem;
    margin-top: 2.5rem; font-size: 0.85rem;
    color: var(--text-muted); font-family: var(--font-mono);
    transition: color var(--transition), transform var(--transition);
}
.back-link:hover { color: var(--accent); opacity: 1; transform: translateX(-3px); }

/* ── Series Navigation ────────────────────────────────── */
.series-nav {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 2rem;
    animation: fadeSlideIn 0.5s 0.1s ease both;
}
.series-nav-title {
    font-size: 0.7rem; font-weight: 700;
    color: var(--accent); text-transform: uppercase;
    letter-spacing: 0.08em; margin-bottom: 0.5rem;
    font-family: var(--font-mono);
}
.series-nav ol { margin: 0; padding-left: 1.25rem; font-size: 0.85rem; line-height: 1.9; }
.series-nav li { color: var(--text-muted); }
.series-nav li.current { color: var(--text-heading); font-weight: 600; }
.series-nav li a { text-decoration: none; }
.series-nav li a:hover { color: var(--accent); }

/* ── Mermaid Diagrams ─────────────────────────────────── */
.mermaid { margin: 1.75rem 0; text-align: center; overflow-x: auto; }
.mermaid svg { max-width: 100%; height: auto; }

/* ── Animations ──────────────────────────────────────── */
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 600px) {
    .hero h1 { font-size: 1.35rem; }
    .hero-logo { width: 56px; height: 56px; }
    .post-header h1 { font-size: 1.35rem; }
    .post-card { padding: 1rem 1.15rem; }
    .post-title { font-size: 0.95rem; }
    .header-content { padding: 0.75rem 1rem; }
    .container { padding: 0 1rem 3rem; }
    .search-input { font-size: 0.82rem; }
}
