/* Editorial theme — light + dark */
:root {
    --brand: #0066ff;
    --bg: #ffffff;
    --bg-elev: #f8fafc;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --link: var(--brand);
    --pill-bg: #eff6ff;
    --pill-text: var(--brand);
    --max-content: 1180px;
    --max-article: 720px;
}

[data-color-scheme="dark"] {
    --bg: #0b1220;
    --bg-elev: #111827;
    --text: #e5e7eb;
    --text-muted: #94a3b8;
    --border: #1f2937;
    --link: #60a5fa;
    --pill-bg: #1e3a8a;
    --pill-text: #93c5fd;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.65;
    font-size: 17px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: var(--max-content); margin: 0 auto; padding: 0 24px; }

/* Header */
.site-header { border-bottom: 1px solid var(--border); background: var(--bg); position: sticky; top: 0; z-index: 50; backdrop-filter: blur(8px); }
.site-header-inner { display: flex; align-items: center; gap: 24px; padding: 14px 24px; max-width: var(--max-content); margin: 0 auto; }
.site-logo {
    font-weight: 700;
    font-size: 19px;
    color: var(--text);
    letter-spacing: -0.01em;
    max-width: 150px;
    width: 100%;
}
.site-nav { display: flex; gap: 18px; flex: 1; flex-wrap: wrap; }
.site-nav a { color: var(--text-muted); font-size: 14px; font-weight: 500; }
.site-nav a:hover { color: var(--text); text-decoration: none; }
/* Header tools — search, theme toggle, lang toggle all share the SAME 36px height,
   same border, same radius. Don't break this by adding padding without box-sizing:border-box. */
.site-tools { display: flex; gap: 6px; align-items: center; }
.theme-toggle, .lang-toggle, .header-search input {
    box-sizing: border-box;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}
.header-search { margin: 0; }
.header-search input { font-weight: 400; min-width: 160px; cursor: text; }
.header-search input::placeholder { color: var(--text-muted); }
.theme-toggle:hover, .lang-toggle:hover, .header-search input:focus { border-color: var(--brand); color: var(--brand); outline: none; }
/* Theme toggle icons — show the ACTION, never the current state (which the user already sees).
   Light mode → show moon (= "click to go dark"). Dark mode → show sun (= "click to go light"). */
[data-color-scheme="light"] .theme-icon-sun { display: none; }
[data-color-scheme="dark"] .theme-icon-moon { display: none; }
.theme-icon-moon, .theme-icon-sun { display: block; }

/* Main */
.site-main { min-height: calc(100vh - 200px); padding: 40px 0 80px; }

/* Home — hero + grid */
.home-hero { padding-bottom: 48px; border-bottom: 1px solid var(--border); margin-bottom: 48px; }
.home-hero h1 { font-size: clamp(28px, 4vw, 44px); line-height: 1.15; margin: 0 0 12px; letter-spacing: -0.02em; }
.home-hero p { font-size: 18px; color: var(--text-muted); max-width: 640px; margin: 0; }

.article-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 32px; }
.article-card { display: flex; flex-direction: column; gap: 10px; }
.article-card-image { display: block; aspect-ratio: 16 / 10; background: var(--bg-elev); border-radius: 10px; overflow: hidden; }
.article-card-image img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.25s ease; }
.article-card-image:hover img { transform: scale(1.03); }
.article-card-category { color: var(--pill-text); background: var(--pill-bg); display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; align-self: flex-start; }
.article-card h2, .article-card h3 { font-size: 19px; line-height: 1.3; margin: 0; letter-spacing: -0.01em; font-weight: 700; }
.article-card h2 a, .article-card h3 a { color: var(--text); }
.article-card h2 a:hover, .article-card h3 a:hover { color: var(--brand); text-decoration: none; }
.article-card-excerpt { color: var(--text-muted); font-size: 15px; margin: 0; line-height: 1.5; }
.article-card-meta { color: var(--text-muted); font-size: 13px; margin: 0; }

/* Hero card (latest article on home) */
.home-hero-card {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 32px;
    margin: 32px auto 64px;
    align-items: center;
    padding-bottom: 48px;
    border-bottom: 1px solid var(--border);
}
.home-hero-card .hero-image {
    display: block;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    border-radius: 12px;
    background: var(--bg-elev);
}
.home-hero-card .hero-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.home-hero-card .hero-body h1 { font-size: clamp(28px, 3.5vw, 42px); line-height: 1.1; margin: 8px 0 12px; letter-spacing: -0.02em; }
.home-hero-card .hero-body h1 a { color: var(--text); }
.home-hero-card .hero-body h1 a:hover { color: var(--brand); text-decoration: none; }
.home-hero-card .hero-body p { font-size: 17px; color: var(--text-muted); margin: 0 0 12px; }
@media (max-width: 800px) { .home-hero-card { grid-template-columns: 1fr; gap: 16px; } }

/* Category section on home */
.category-section { margin-bottom: 64px; }
.category-section-header { display: flex; align-items: baseline; gap: 16px; margin-bottom: 24px; padding-bottom: 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.category-section-header h2 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.category-section-header h2 a { color: var(--text); }
.category-section-header h2 a:hover { color: var(--brand); text-decoration: none; }
.category-section-header p { margin: 0; color: var(--text-muted); font-size: 14px; flex: 1; }
.category-section-more { font-size: 13px; color: var(--brand); font-weight: 600; text-decoration: none; white-space: nowrap; }
.category-section-more:hover { text-decoration: underline; }

/* Article — Medium-style narrow column for header AND body, so breadcrumb/title/meta align
   with paragraphs below (no awkward empty gutter when there's no featured image). The hero
   IMAGE breaks out to full width inside the column for visual rhythm. */
.article-hero { max-width: var(--max-article); margin: 0 auto; padding: 0 24px 36px; }
.article-hero-image { aspect-ratio: 16 / 7; background: var(--bg-elev); border-radius: 12px; overflow: hidden; margin-bottom: 24px; }
.article-hero-image img { width: 100%; height: 100%; object-fit: cover; }
.article-breadcrumb { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }
.article-breadcrumb a { color: var(--text-muted); }
.article-title { font-size: clamp(28px, 4vw, 44px); line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 16px; }
.article-meta { color: var(--text-muted); font-size: 14px; margin-bottom: 8px; }

.article-body { max-width: var(--max-article); margin: 0 auto; padding: 0 24px; }
.article-body h2 { font-size: 26px; line-height: 1.25; letter-spacing: -0.01em; margin: 48px 0 16px; }
.article-body h3 { font-size: 20px; line-height: 1.35; margin: 36px 0 12px; }
.article-body p { margin: 0 0 18px; }
.article-body ul, .article-body ol { padding-left: 22px; margin: 0 0 18px; }
.article-body li { margin-bottom: 6px; }
.article-body table { width: 100%; border-collapse: collapse; margin: 24px 0; font-size: 15px; }
.article-body th, .article-body td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; vertical-align: top; }
.article-body th { background: var(--bg-elev); font-weight: 600; }
.article-body blockquote { border-left: 3px solid var(--brand); padding: 4px 16px; color: var(--text-muted); margin: 24px 0; }
.article-body code { background: var(--bg-elev); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
.article-body pre { background: var(--bg-elev); padding: 16px; border-radius: 8px; overflow: auto; }
.article-body pre code { background: transparent; padding: 0; }
.article-body a { color: var(--brand); text-decoration: underline; text-underline-offset: 3px; }
.article-body img { max-width: 100%; height: auto; border-radius: 8px; margin: 24px 0; }

/* Related */
.related { max-width: var(--max-content); margin: 80px auto 0; padding: 40px 24px 0; border-top: 1px solid var(--border); }
.related h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin: 0 0 24px; }

/* Footer */
.site-footer { border-top: 1px solid var(--border); padding: 32px 0; color: var(--text-muted); font-size: 14px; }
.site-footer p { margin: 0; text-align: center; }

/* Search field in header */
.header-search input { padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-elev); color: var(--text); font-size: 13px; min-width: 180px; }
.header-search input:focus { outline: none; border-color: var(--brand); }

/* Pagination */
.pagination { display: flex; justify-content: center; align-items: center; gap: 18px; margin: 48px auto 0; padding: 24px 0; border-top: 1px solid var(--border); }
.pagination a { color: var(--brand); font-weight: 500; text-decoration: none; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; }
.pagination a:hover { background: var(--bg-elev); }
.pagination .muted { color: var(--text-muted); font-size: 14px; }

/* Tags on article */
.article-tags { max-width: var(--max-article); margin: 32px auto 0; padding: 0 24px; display: flex; flex-wrap: wrap; gap: 8px; }
.article-tag { color: var(--pill-text); background: var(--pill-bg); padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 500; text-decoration: none; }
.article-tag:hover { filter: brightness(0.95); text-decoration: none; }

/* Search form on /search */
.search-form { display: flex; gap: 8px; margin-top: 12px; max-width: 480px; }
.search-form input { flex: 1; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-elev); color: var(--text); font-size: 16px; }
.search-form button { padding: 10px 18px; background: var(--brand); color: white; border: none; border-radius: 8px; font-weight: 600; cursor: pointer; }

/* Newsletter strip */
.newsletter-strip { background: var(--bg-elev); border-top: 1px solid var(--border); padding: 48px 0; margin-top: 80px; }
.newsletter-strip h3 { font-size: 24px; margin: 0 0 20px; text-align: center; letter-spacing: -0.01em; }
.newsletter-form { display: flex; gap: 8px; max-width: 480px; margin: 0 auto; }
.newsletter-form input[type="email"] { flex: 1; padding: 12px 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: 16px; font-family: inherit; }
.newsletter-form input[type="email"]:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.newsletter-form button { padding: 12px 20px; background: var(--brand); color: white; border: none; border-radius: 8px; font-weight: 600; font-size: 15px; cursor: pointer; white-space: nowrap; }
.newsletter-form button:hover { filter: brightness(1.05); }
.newsletter-feedback { text-align: center; margin: 16px 0 0; color: var(--text-muted); min-height: 1.4em; font-size: 14px; }
.hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
@media (max-width: 540px) { .newsletter-form { flex-direction: column; } .newsletter-form button { width: 100%; } }

/* Author hero on /author/{username} */
.author-hero { display: flex; gap: 24px; align-items: center; padding-top: 16px; }
.author-hero-avatar { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.author-hero h1 { margin: 0 0 8px; }

/* Author card */
.author-card { display: flex; gap: 16px; max-width: var(--max-article); margin: 40px auto 0; padding: 20px 24px; background: var(--bg-elev); border-radius: 12px; align-items: flex-start; }
.author-avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.author-meta { flex: 1; }
.author-name { font-weight: 700; margin: 0 0 4px; font-size: 15px; }
.author-bio { color: var(--text-muted); margin: 0 0 6px; font-size: 14px; line-height: 1.5; }
.author-meta a { color: var(--brand); font-size: 13px; font-weight: 500; }

/* Comments */
.comments { max-width: var(--max-article); margin: 60px auto 0; padding: 32px 24px 0; border-top: 1px solid var(--border); }
.comments h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin: 0 0 24px; }
.comment-flash { background: var(--pill-bg); color: var(--pill-text); padding: 10px 14px; border-radius: 6px; margin-bottom: 24px; font-size: 14px; }
.comment-list { list-style: none; padding: 0; margin: 0 0 32px; }
.comment { padding: 16px 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: none; }
.comment-meta { display: flex; gap: 12px; align-items: baseline; font-size: 13px; margin-bottom: 6px; }
.comment-meta strong { color: var(--text); }
.comment-meta time { color: var(--text-muted); }
.comment-body { margin: 0; color: var(--text); white-space: pre-wrap; }
.comment-form { display: flex; flex-direction: column; gap: 12px; background: var(--bg-elev); padding: 20px; border-radius: 8px; margin-top: 8px; }
.comment-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.comment-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.comment-form input, .comment-form textarea { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-family: inherit; font-size: 15px; }
.comment-form textarea { resize: vertical; min-height: 100px; }
.comment-form button { align-self: flex-start; padding: 10px 20px; background: var(--brand); color: white; border: none; border-radius: 6px; font-weight: 600; cursor: pointer; }
.comment-form .small { font-size: 12px; }
.hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
@@media (max-width: 600px) { .comment-row { grid-template-columns: 1fr; } }

/* Responsive */
@media (max-width: 720px) {
    /* Bumped top padding so the logo doesn't kiss the viewport edge on phones. */
    .site-header-inner { flex-wrap: wrap; gap: 12px; padding: 20px 16px 14px; }
    .site-nav { order: 3; width: 100%; gap: 12px; }
    .article-grid { gap: 24px; }
}

/* Article share buttons */
.article-share { max-width: var(--max-article); margin: 32px auto 0; padding: 16px 24px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.article-share a, .article-share .copy-link-btn { display: inline-flex; align-items: center; justify-content: center; min-width: 32px; height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px; color: var(--text-muted); font-weight: 700; text-decoration: none; font-size: 13px; background: var(--bg); cursor: pointer; font-family: inherit; }
.article-share a:hover, .article-share .copy-link-btn:hover { color: var(--brand); border-color: var(--brand); }
.article-share .muted { margin-right: 4px; }

/* Print-friendly */
@media print {
    .site-header, .site-footer, .newsletter-strip, .article-share, .related, .comments, .article-tags, .site-tools { display: none !important; }
    body { background: white; color: black; font-size: 12pt; }
    .article-body { max-width: 100%; }
    a { color: black; text-decoration: underline; }
}

/* Tag cloud */
.tag-cloud { margin: 32px auto; padding: 24px; background: var(--bg-elev); border-radius: 12px; }
.tag-cloud h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin: 0 0 14px; font-weight: 700; }
.tag-cloud-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-cloud-tag { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 999px; font-size: 13px; font-weight: 500; text-decoration: none; }
.tag-cloud-tag:hover { border-color: var(--brand); color: var(--brand); text-decoration: none; }
.tag-cloud-tag span { font-size: 11px; color: var(--text-muted); font-weight: 700; }

/* Comment threading */
.comment-list-nested { margin-left: 24px; margin-top: 16px; padding-left: 16px; border-left: 2px solid var(--border); }
.comment-reply-btn { display: inline-block; padding: 4px 10px; margin-top: 6px; background: transparent; border: 1px solid var(--border); border-radius: 999px; color: var(--text-muted); font-size: 12px; font-weight: 500; cursor: pointer; font-family: inherit; }
.comment-reply-btn:hover { color: var(--brand); border-color: var(--brand); }
.reply-indicator { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--pill-bg); border-radius: 6px; font-size: 13px; color: var(--pill-text); margin: 0 0 12px; }
.link-button { background: transparent; border: none; color: var(--brand); cursor: pointer; text-decoration: underline; font-family: inherit; font-size: 13px; padding: 0; }


/* Logo light/dark toggle — only show the matching variant for the active color scheme.
   The .site-logo container holds both <img>s; CSS hides the one that doesn't match. */
.site-logo-img { max-height: 40px; width: auto; display: block; }
.site-logo-light { display: block; }
.site-logo-dark { display: none; }
[data-color-scheme="dark"] .site-logo-light { display: none; }
[data-color-scheme="dark"] .site-logo-dark { display: block; }



/* Cards with no featured image — drop the image slot entirely and let text fill the card */
.article-card--no-image { display: flex; flex-direction: column; }
.article-card--no-image .article-card-category { margin-top: 0; }

/* Hero without image — text uses the full width, no empty image slot */
.home-hero-card--no-image { display: block; padding-top: 32px; }
.home-hero-card--no-image .hero-body { max-width: 720px; }


/* Reading progress bar — thin fixed strip at top of viewport, fills as user scrolls article body */
.reading-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; background: transparent; z-index: 50; pointer-events: none; }
.reading-progress span { display: block; height: 100%; background: var(--brand); width: 0; transition: width 0.1s linear; }

/* Auto-generated TOC at top of article — collapsed by default, expanded by admin/user */
.article-toc { max-width: var(--max-article); margin: 0 auto 28px; padding: 0 24px; }
.article-toc summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 8px 12px; background: var(--bg-elev); border-radius: 6px; }
.article-toc summary:hover { color: var(--brand); }
.article-toc ol { list-style: none; padding: 12px 0 0 12px; margin: 0; border-left: 2px solid var(--border); }
.article-toc li { padding: 4px 0; }
.article-toc li.toc-h3 { padding-left: 16px; font-size: 14px; }
.article-toc a { color: var(--text-muted); text-decoration: none; font-size: 15px; }
.article-toc a:hover { color: var(--brand); }

/* Search hit highlight */
mark { background: #fef3c7; color: #92400e; padding: 0 2px; border-radius: 3px; }
[data-color-scheme="dark"] mark { background: #92400e; color: #fef3c7; }

/* Archive page year/month grids */
.archive-year-list, .archive-month-list { list-style: none; padding: 0; margin: 24px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.archive-year-list a, .archive-month-list a { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 18px; background: var(--bg-elev); border-radius: 8px; text-decoration: none; color: inherit; font-weight: 600; }
.archive-year-list a:hover, .archive-month-list a:hover { background: var(--brand); color: white; }
.archive-year { font-size: 22px; }
.archive-count { font-size: 13px; font-weight: 500; }

/* Author RSS link */
.author-links { font-size: 14px; color: var(--text-muted); display: flex; gap: 8px; flex-wrap: wrap; }
.author-links a { color: var(--brand); }


/* ===================== MOBILE RESPONSIVE ===================== */

/* Hamburger button — hidden above 900px, shown below. 40×40 tap target, same height as
   the inline theme/lang toggles so the right side of the header stays visually aligned. */
.site-nav-toggle {
    display: none;
    box-sizing: border-box;
    width: 40px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}
.site-nav-toggle span { display: block; width: 18px; height: 2px; background: var(--text); border-radius: 2px; transition: transform 0.2s, opacity 0.2s; }
.site-nav-toggle.active span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.site-nav-toggle.active span:nth-child(2) { opacity: 0; }
.site-nav-toggle.active span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
.site-nav-toggle:hover { border-color: var(--brand); }

@media (max-width: 900px) {
    .site-header-inner {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "logo  tools"
            "nav   nav";
        align-items: center;
        gap: 8px 12px;
        padding: 10px 16px;
    }
    .site-logo { grid-area: logo; max-width: 100%; }
    .site-tools { grid-area: tools; display: flex; gap: 6px; align-items: center; }
    .site-nav-toggle { display: inline-flex; order: 10; }
    .site-nav {
        grid-area: nav;
        display: none;
        flex-direction: column;
        width: 100%;
        padding: 4px 0 8px;
        gap: 0;
        border-top: 1px solid var(--border);
    }
    .site-nav.open { display: flex; }
    .site-nav a {
        padding: 12px 4px;
        font-size: 16px;
        font-weight: 500;
        border-bottom: 1px solid var(--border);
        color: var(--text);
    }
    .site-nav a:last-child { border-bottom: none; }
    /* On narrow screens the search input would push tools off-screen; hide it from the
       header bar. (Desktop keeps it inline. To reach search on mobile, tap a category and
       use in-page browsing — or we'd need to add a search drawer, which is overkill.) */
    .header-search { display: none; }
}

@media (max-width: 640px) {
    .container { padding: 0 16px; }
    .site-main { padding: 24px 0 60px; }
    .home-hero h1 { font-size: 28px; }
    .article-hero, .article-body { padding-left: 16px; padding-right: 16px; }
    .article-title { font-size: 26px; }
    .article-body h2 { font-size: 22px; margin: 36px 0 12px; }
    .article-body h3 { font-size: 18px; margin: 28px 0 10px; }
    .article-grid { grid-template-columns: 1fr; gap: 24px; }
    .category-section-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .article-tags, .article-share, .author-card, .comments, .related { padding-left: 16px; padding-right: 16px; }
    body { font-size: 16px; }
}
