:root {
    --bg: #f3efe6;
    --bg-gradient-start: #fff8ef;
    --panel: #fffdf8;
    --panel-alt: #fcf7ef;
    --ink: #1f2933;
    --accent: #b85c38;
    --line: #dbcdb9;
    --line-alt: #e4d8c7;
    --muted: #6b7280;
    --input-bg: #fff;
    --code-bg: #fff;
    --code-gutter-bg: #f8f9fa;
    --table-head-bg: #f6ecdd;
    --inline-code-bg: #efe5d6;
    --brand-icon-bg: #f4e7d6;
}

[data-theme="dark"] {
    --bg: #1a1612;
    --bg-gradient-start: #221d18;
    --panel: #231e18;
    --panel-alt: #2a2318;
    --ink: #f0e8dc;
    --accent: #d4784e;
    --line: #3d3228;
    --line-alt: #463b2e;
    --muted: #9ca3af;
    --input-bg: #2e2720;
    --code-bg: #1e1a15;
    --code-gutter-bg: #252019;
    --table-head-bg: #32291e;
    --inline-code-bg: #3a2f22;
    --brand-icon-bg: #3a2f22;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    background: radial-gradient(circle at top, var(--bg-gradient-start), var(--bg));
    color: var(--ink);
    transition: background .25s, color .25s;
}
a { color: inherit; }
.page-shell { max-width: 1080px; margin: 0 auto; padding: 24px; }
.navbar, .site-footer, .hero, .card, .auth-card, .sidebar-card, .post-row, .empty-state {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
}
.navbar, .site-footer { margin: 16px auto; max-width: 1080px; padding: 16px 24px; }
.navbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.nav-links, .hero-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.brand { font-weight: 700; text-decoration: none; }
.brand-with-mark { display: inline-flex; align-items: center; gap: 12px; font-size: 1.5rem; letter-spacing: -0.5px; }
.brand-logo { width: 52px; height: 52px; object-fit: contain; display: block; }
.brand-icon { width: 52px; height: 52px; display: inline-flex; align-items: center; justify-content: center; border-radius: 16px; background: var(--brand-icon-bg); color: var(--accent); font-size: 1.9rem; flex: 0 0 52px; }
.site-search-form { display: grid; grid-template-columns: minmax(220px, 340px) auto; gap: 8px; align-items: center; margin-left: auto; }
.site-search-form input { width: 100%; border: 1px solid var(--line); border-radius: 999px; padding: 10px 14px; background: var(--input-bg); color: var(--ink); }
.site-search-form .button { display: inline-flex; align-items: center; justify-content: center; }
.hero { padding: 32px; margin-bottom: 24px; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .8rem; color: var(--accent); }
.button, button {
    background: var(--accent);
    color: #fff;
    border: 0;
    padding: 10px 16px;
    border-radius: 999px;
    text-decoration: none;
    cursor: pointer;
}
.button-light { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.section-head { display: flex; justify-content: space-between; gap: 24px; align-items: start; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.card, .auth-card, .sidebar-card, .post-row, .empty-state, .article-page { padding: 24px; }
.stack { display: grid; gap: 14px; }
.stack input, .stack textarea, .stack select {
    width: 100%;
    margin-top: 6px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
    background: var(--input-bg);
    color: var(--ink);
}
.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 24px; }
.category-list { margin: 0; padding-left: 18px; }
.pager, .inline-form { display: inline-flex; gap: 12px; align-items: center; }
.newsletter-card { margin-bottom: 18px; padding: 18px; background: var(--panel-alt); border: 1px solid var(--line-alt); border-radius: 16px; }
.newsletter-card h3 { margin: 0 0 6px; font-size: 1.05rem; }
.newsletter-copy { margin: 0 0 12px; color: var(--muted); font-size: .94rem; }
.newsletter-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.newsletter-form input { width: 100%; border: 1px solid var(--line); border-radius: 999px; padding: 11px 14px; background: var(--input-bg); color: var(--ink); }
.newsletter-form .button { display: inline-flex; gap: 8px; align-items: center; justify-content: center; }
.newsletter-feedback { min-height: 1.5rem; margin-top: 10px; font-size: .94rem; color: var(--muted); }
.newsletter-feedback.is-success { color: #166534; }
.newsletter-feedback.is-error { color: #b42318; }
[data-theme="dark"] .newsletter-feedback.is-success { color: #4ade80; }
[data-theme="dark"] .newsletter-feedback.is-error { color: #f87171; }
.site-footer { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(280px, .8fr); gap: 20px; align-items: stretch; }
.site-footer-copy { display: flex; flex-direction: column; justify-content: center; min-height: 100%; padding: 18px; background: var(--panel-alt); border: 1px solid var(--line-alt); border-radius: 16px; }
.site-footer-copy .eyebrow { margin-top: 0; }
.site-footer-copy p:last-child { margin: 0; color: var(--muted); max-width: 48ch; }
.site-footer-newsletter,
.site-footer .newsletter-card { height: 100%; }
.site-footer .newsletter-card { margin-bottom: 0; display: flex; flex-direction: column; justify-content: center; }
.flash { margin-bottom: 16px; padding: 14px 16px; border-radius: 14px; }
.flash-success { background: #e4f4e7; border: 1px solid #9ec8a7; }
.flash-error { background: #fbe6e6; border: 1px solid #d59c9c; }
[data-theme="dark"] .flash-success { background: #14532d; border-color: #166534; color: #bbf7d0; }
[data-theme="dark"] .flash-error { background: #450a0a; border-color: #7f1d1d; color: #fecaca; }
.card-meta, .article-description { color: var(--muted); }
.article-content pre { position: relative; margin: 1.25rem 0; padding: 0; overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--code-bg); }
.article-content pre code.hljs,
.article-content pre code { display: block; margin-left: 3.5rem; padding: 1rem 1.1rem; border-radius: 14px; font-size: .92rem; line-height: 1.55; }
.article-content .code-line-numbers {
    position: absolute;
    top: 0;
    left: 0;
    width: 3.5rem;
    height: 100%;
    padding: 1rem .75rem;
    border-right: 1px solid var(--line);
    color: var(--muted);
    background: var(--code-gutter-bg);
    text-align: right;
    font-size: .92rem;
    line-height: 1.55;
    white-space: pre;
    user-select: none;
}
.article-content :not(pre) > code { padding: .15rem .4rem; border-radius: .45rem; background: var(--inline-code-bg); font-size: .92em; }
.article-content .table-wrap { overflow-x: auto; margin: 1.25rem 0; }
.article-content .table-wrap table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.article-content .table-wrap th,
.article-content .table-wrap td { padding: .8rem .9rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.article-content .table-wrap thead th { background: var(--table-head-bg); }

/* Dark mode toggle */
.theme-toggle {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--ink);
    padding: 8px 10px;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
    transition: background .2s, border-color .2s;
}
.theme-toggle:hover { background: var(--inline-code-bg); }
.theme-toggle .icon-dark { display: none; }
.theme-toggle .icon-light { display: inline; }
[data-theme="dark"] .theme-toggle .icon-dark { display: inline; }
[data-theme="dark"] .theme-toggle .icon-light { display: none; }

@media (max-width: 800px) {
    .content-grid { grid-template-columns: 1fr; }
    .navbar, .section-head { flex-direction: column; align-items: start; }
    .site-search-form { grid-template-columns: 1fr auto; width: 100%; margin-left: 0; }
    .newsletter-form { grid-template-columns: 1fr; }
    .site-footer { grid-template-columns: 1fr; }
}
