/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif; line-height: 1.6; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ── CSS Custom Properties — Light (default) ─────────────────────── */
html, html.light {
    --bg: #ffffff;
    --bg-secondary: #f8f9fa;
    --text: #1a1a2e;
    --text-secondary: #6c757d;
    --link: #0d6efd;
    --link-hover: #0a58ca;
    --border: #dee2e6;
    --accent: #0d6efd;
    --card-bg: #ffffff;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.08);
    --code-bg: #f1f3f5;
    --tag-bg: #e9ecef;
    --tag-text: #495057;
    --mark-bg: #fff3cd;
}

/* ── Dark theme ──────────────────────────────────────────────────── */
html.dark {
    --bg: #0d1117;
    --bg-secondary: #161b22;
    --text: #e6edf3;
    --text-secondary: #8b949e;
    --link: #58a6ff;
    --link-hover: #79c0ff;
    --border: #30363d;
    --accent: #58a6ff;
    --card-bg: #161b22;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.3);
    --code-bg: #1c2128;
    --tag-bg: #21262d;
    --tag-text: #c9d1d9;
    --mark-bg: #3b2e00;
}

body {
    background-color: var(--bg);
    color: var(--text);
}

/* ── Site Layout ─────────────────────────────────────────────────── */
.site-wrapper {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.main-content {
    flex: 1;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* ── Splash / loading screen ─────────────────────────────────────── */
.splash {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    background: var(--bg);
    color: var(--text-secondary);
    z-index: 9999;
}
.splash-spinner { opacity: 0.6; }
.splash p { font-size: 0.95rem; }

/* ── Scroll offset for sticky header ─────────────────────────────── */
#posts-list { scroll-margin-top: 4rem; }

/* ── Header & Nav ────────────────────────────────────────────────── */
.site-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}
.site-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}
.site-title:hover { text-decoration: none; }
.nav-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text);
}
.nav-links {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 1.25rem;
}
.nav-links a { color: var(--text-secondary); font-size: 0.9rem; }
.nav-links a:hover { color: var(--text); }
.nav-icon { display: flex; align-items: center; }

/* ── Theme Toggle ────────────────────────────────────────────────── */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
}
.theme-toggle:hover { background: var(--bg); }

/* ── Featured Section ────────────────────────────────────────────── */
.featured-section {
    margin-bottom: 2.5rem;
    padding-bottom: 2rem;
    border-bottom: 2px solid var(--border);
}
.section-title {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}
.featured-grid .article-card {
    border-left: 3px solid var(--accent);
}

/* ── Page Titles ─────────────────────────────────────────────────── */
.page-title {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    color: var(--text);
}

/* ── Article Card ────────────────────────────────────────────────── */
.article-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1.5rem;
    box-shadow: var(--card-shadow);
    transition: box-shadow 200ms;
}
.article-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.article-card { contain: content; }
.article-card-cover img { width: 100%; height: 200px; object-fit: cover; aspect-ratio: 16/5; }
.article-card-body { padding: 1.25rem; }
.article-card-title { font-size: 1.25rem; margin-bottom: 0.5rem; }
.article-card-title a { color: var(--text); }
.article-card-title a:hover { color: var(--accent); text-decoration: none; }
.article-card-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}
.icon-calendar { vertical-align: -2px; margin-right: 0.25rem; }
.reading-time { color: var(--text-secondary); }
.article-card-excerpt {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
}
.article-card-tags { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ── Tags ────────────────────────────────────────────────────────── */
.tag {
    display: inline-block;
    background: var(--tag-bg);
    color: var(--tag-text);
    padding: 0.15rem 0.6rem;
    border-radius: 12px;
    font-size: 0.8rem;
}
.tag:hover { text-decoration: none; background: var(--accent); color: #fff; }
.tag-count { font-size: 0.75rem; opacity: 0.7; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.tag-size-1 { font-size: 0.85rem; }
.tag-size-2 { font-size: 1rem; }
.tag-size-3 { font-size: 1.2rem; }
.tag-size-4 { font-size: 1.4rem; font-weight: 600; }

/* ── Pagination ──────────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 2rem;
    padding: 1rem 0;
}
.pagination a {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--accent);
}
.pagination a:hover { background: var(--accent); color: #fff; text-decoration: none; }
.pagination-info { color: var(--text-secondary); font-size: 0.9rem; }

/* ── Post Detail ─────────────────────────────────────────────────── */
.post-header { margin-bottom: 2rem; }
.post-header h1 { font-size: 2rem; line-height: 1.3; margin-bottom: 0.75rem; }
.post-meta { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.75rem; }
.post-tags { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.post-layout { display: flex; gap: 2rem; }
.post-content { flex: 1; min-width: 0; }

/* ── Table of Contents ───────────────────────────────────────────── */
.toc {
    position: sticky;
    top: 5rem;
    width: 220px;
    flex-shrink: 0;
    align-self: flex-start;
    font-size: 0.85rem;
    order: 1;
}
.toc h3 { font-size: 0.9rem; margin-bottom: 0.75rem; color: var(--text-secondary); }
.toc ul { list-style: none; }
.toc li { margin-bottom: 0.4rem; }
.toc a { color: var(--text-secondary); }
.toc a:hover { color: var(--accent); }
.toc-3 { padding-left: 1rem; }

/* ── Prose (article content) ─────────────────────────────────────── */
.prose h2 { font-size: 1.5rem; margin: 2rem 0 1rem; padding-bottom: 0.3rem; border-bottom: 1px solid var(--border); }
.prose h3 { font-size: 1.25rem; margin: 1.5rem 0 0.75rem; }
.prose p { margin-bottom: 1rem; }
.prose ul, .prose ol { margin-bottom: 1rem; padding-left: 1.5rem; }
.prose li { margin-bottom: 0.25rem; }
.prose blockquote {
    border-left: 4px solid var(--accent);
    padding: 0.5rem 1rem;
    margin: 1rem 0;
    background: var(--bg-secondary);
    color: var(--text-secondary);
}
/* Inline code (not inside pre) */
.prose code:not([class*="language-"]) {
    background: var(--code-bg);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
}
/* Code blocks — base styles, Prism theme overrides colors */
.prose pre {
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 0;
}
.prose pre:not([class*="language-"]) {
    background: var(--code-bg);
    border: 1px solid var(--border);
    padding: 1rem;
    margin-bottom: 1rem;
}
.prose pre code { background: none; padding: 0; font-size: 0.85rem; }
.prose img { border-radius: 8px; margin: 1rem 0; }
.prose a { color: var(--accent); }
.prose a:hover { text-decoration: underline; }
.prose table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.prose th, .prose td { padding: 0.5rem 0.75rem; border: 1px solid var(--border); text-align: left; }
.prose th { background: var(--bg-secondary); font-weight: 600; }

/* ── Archives ────────────────────────────────────────────────────── */
.archive-year { margin-bottom: 2rem; }
.archive-year h2 { font-size: 1.5rem; margin-bottom: 0.75rem; color: var(--text); }
.archive-year .count { font-size: 0.9rem; color: var(--text-secondary); font-weight: 400; }
.archive-list { list-style: none; }
.archive-list li {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--border);
}
.archive-list time { color: var(--text-secondary); font-size: 0.85rem; min-width: 60px; }

/* ── Search ──────────────────────────────────────────────────────── */
.search-input-wrapper { margin-bottom: 1.5rem; }
.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 200ms;
}
.search-input:focus { border-color: var(--accent); }
.search-count { color: var(--text-secondary); margin-bottom: 1rem; }
.search-results { list-style: none; }
.search-result-item {
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
}
.search-result-item h3 { font-size: 1.1rem; margin-bottom: 0.4rem; }
.search-result-item p { color: var(--text-secondary); font-size: 0.9rem; margin-bottom: 0.5rem; }
.search-result-tags { display: flex; gap: 0.5rem; flex-wrap: wrap; }
mark { background: var(--mark-bg); padding: 0 0.15rem; border-radius: 2px; }

/* ── Skills Page ─────────────────────────────────────────────────── */
.skills-page .page-title { text-align: center; margin-bottom: 2rem; }
.skill-grid-flat {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}
.skill-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem 0.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-align: center;
    transition: transform 200ms, box-shadow 200ms;
}
.skill-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.skill-card-icon { width: 48px; height: 48px; object-fit: contain; }
.skill-card-name { font-size: 0.85rem; color: var(--text); font-weight: 500; }

@media (min-width: 600px) {
    .skill-grid-flat { grid-template-columns: repeat(8, 1fr); }
}
@media (min-width: 900px) {
    .skill-grid-flat { grid-template-columns: repeat(12, 1fr); }
}

/* ── Custom Page ─────────────────────────────────────────────────── */
.custom-page .prose { max-width: 100%; }

/* ── Footer ──────────────────────────────────────────────────────── */
.site-footer {
    text-align: center;
    padding: 1.5rem 1rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
}
.social-links {
    display: flex;
    justify-content: center;
    gap: 1.25rem;
}
.social-links a {
    color: var(--text-secondary);
    transition: color 200ms;
}
.social-links a:hover { color: var(--accent); }

/* ── Loading ─────────────────────────────────────────────────────── */
.loading { color: var(--text-secondary); font-style: italic; }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .nav-toggle { display: block; }
    .nav-links {
        display: none;
        flex-direction: column;
        width: 100%;
        padding-top: 0.75rem;
        gap: 0.75rem;
    }
    .nav-links.open { display: flex; }
    .post-layout { flex-direction: column; }
    .toc { position: static; width: 100%; order: -1; margin-bottom: 1.5rem; }
    .post-header h1 { font-size: 1.5rem; }
    .skill-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
}
