/* ========== 变量 ========== */
:root {
    --bg: #f7f5f1;
    --panel: #fffdf9;
    --fg: #37352f;
    --muted: #7d7668;
    --border: #e5dfd4;
    --code-bg: #f3efe7;
    --mark-bg: #fff3b3;
    --seal: #a12a35;
    --accent: var(--accent-l);
}

html[data-theme="dark"] {
    --bg: #191714;
    --panel: #211f1b;
    --fg: #e8e4dc;
    --muted: #a49d90;
    --border: #3a362e;
    --code-bg: #282520;
    --mark-bg: #6b5d1f;
    --seal: #c2504a;
    --accent: var(--accent-d);
}

/* 强调色：ink 墨蓝 / crimson 暗红 / pine 松绿 / mono 纯黑白 */
html[data-accent="ink"]     { --accent-l: #1a4f8b; --accent-d: #7fa8dc; }
html[data-accent="crimson"] { --accent-l: #a02c3c; --accent-d: #e08a95; }
html[data-accent="pine"]    { --accent-l: #2c6e5a; --accent-d: #86c7ae; }
html[data-accent="mono"]    { --accent-l: #111111; --accent-d: #e6e6e6; }

/* ========== 基础 ========== */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font: 16px/1.75 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 20px; }

/* ========== 页头 ========== */
.site-header { border-bottom: 1px solid var(--border); }

.header-inner {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
    align-items: center;
    justify-content: space-between;
    padding-top: 14px;
    padding-bottom: 14px;
}

.site-title {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 20px;
    font-weight: 700;
    color: var(--fg);
    text-decoration: none;
}
.site-title:hover { color: var(--accent); }

/* 印章：朱底白字楷体方印 */
.seal {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    background: var(--seal);
    color: #fffdf9;
    font-family: "Kaiti SC", "STKaiti", "KaiTi", "Songti SC", "SimSun", serif;
    font-size: 16px;
    font-weight: 400;
    line-height: 1;
}

.site-header nav { display: flex; flex-wrap: wrap; gap: 4px 20px; align-items: center; }
.site-header nav a { color: var(--fg); text-decoration: none; font-size: 15px; }
.site-header nav a:hover { color: var(--accent); }
.site-header nav a.active { color: var(--accent); text-decoration: underline; text-underline-offset: 6px; }

#theme-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
    padding: 1px 10px;
    cursor: pointer;
}
#theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

html[data-theme="dark"] .when-light { display: none; }
html[data-theme="light"] .when-dark { display: none; }

/* ========== 主体 ========== */
main.container {
    background: var(--panel);
    border: 1px solid var(--border);
    margin: 24px auto 40px;
    padding: 32px 40px 48px;
    min-height: calc(100vh - 220px);
}

.hero { border-left: 3px solid var(--accent); padding-left: 12px; margin: 0 0 28px; }
.hero p { margin: 0; color: var(--muted); }

.page-crumb { margin: 0 0 4px; color: var(--muted); font-size: 13px; }

.page-title {
    font-size: 22px;
    margin: 0 0 24px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

/* ========== 文章列表 ========== */
.post-list { list-style: none; margin: 0; padding: 0; max-width: 760px; }
.post-list > li { padding: 18px 0; border-bottom: 1px solid var(--border); }
.post-list > li:first-child { padding-top: 0; }

.post-title { margin: 0 0 4px; font-size: 19px; line-height: 1.4; }
.post-title a { color: var(--fg); text-decoration: none; }
.post-title a:hover { color: var(--accent); }

.post-summary {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.post-meta { font-size: 13px; color: var(--muted); }
.post-meta a { color: var(--muted); text-decoration: none; }
.post-meta a:hover { color: var(--accent); }
.sep { margin: 0 6px; }

/* ========== 分页 ========== */
.pagination { display: flex; gap: 12px; align-items: center; margin-top: 32px; max-width: 760px; }
.pagination a, .pagination .disabled {
    border: 1px solid var(--border);
    padding: 5px 14px;
    text-decoration: none;
    font-size: 14px;
}
.pagination a { color: var(--fg); }
.pagination a:hover { border-color: var(--accent); color: var(--accent); }
.pagination .disabled { color: var(--muted); opacity: .45; }
.page-info { font-size: 13px; color: var(--muted); }

/* ========== 文章页 ========== */
.post-header { margin-bottom: 28px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.post-header h1 { margin: 0 0 10px; font-size: 26px; line-height: 1.4; }

.post-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 230px;
    gap: 40px;
    align-items: start;
}

.post-content { max-width: 760px; min-width: 0; }
.post-content > :first-child { margin-top: 0; }

.post-content h2 { font-size: 21px; margin: 1.6em 0 .6em; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.post-content h3 { font-size: 18px; margin: 1.4em 0 .5em; }
.post-content h4, .post-content h5, .post-content h6 { font-size: 16px; margin: 1.2em 0 .4em; }

.post-content img { max-width: 100%; height: auto; }

.post-content blockquote {
    margin: 0 0 1em;
    padding: 2px 0 2px 14px;
    border-left: 3px solid var(--accent);
    color: var(--muted);
}

.post-content code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: .875em;
    background: var(--code-bg);
    padding: 2px 5px;
}

.post-content pre {
    background: var(--code-bg);
    border: 1px solid var(--border);
    padding: 14px 16px;
    overflow-x: auto;
    line-height: 1.6;
    margin: 0 0 1em;
}
.post-content pre code { background: none; padding: 0; font-size: 13px; }

.post-content table {
    border-collapse: collapse;
    display: block;
    max-width: 100%;
    overflow-x: auto;
    margin: 0 0 1em;
    font-size: 14px;
}
.post-content th, .post-content td { border: 1px solid var(--border); padding: 6px 12px; text-align: left; }
.post-content th { background: var(--code-bg); }

.post-content hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }

mark { background: var(--mark-bg); color: inherit; }

/* ========== 目录 ========== */
.toc {
    position: sticky;
    top: 24px;
    font-size: 13px;
    border-left: 1px solid var(--border);
    padding-left: 16px;
    min-width: 0;
}
.toc summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }
.toc nav {
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    scrollbar-width: thin;
}
.toc nav ul { list-style: none; margin: 0; padding-left: 14px; }
.toc nav > ul { padding-left: 0; }
.toc nav li { margin: 4px 0; overflow-wrap: break-word; }
.toc nav a { color: var(--muted); text-decoration: none; }
.toc nav a:hover { color: var(--accent); }
.toc nav a.active { color: var(--accent); font-weight: 600; }

/* ========== 上一篇 / 下一篇 ========== */
.post-nav {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 48px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
    font-size: 14px;
}
.post-nav a {
    color: var(--fg);
    text-decoration: none;
    max-width: 48%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.post-nav a:hover { color: var(--accent); }
.post-nav .next { margin-left: auto; }

/* ========== 归档 ========== */
.archive-year h2 { font-size: 18px; margin: 28px 0 8px; }
.archive-year:first-of-type h2 { margin-top: 0; }
.archive-list { list-style: none; margin: 0; padding: 0; max-width: 760px; }
.archive-list li {
    display: flex;
    gap: 16px;
    align-items: baseline;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
}
.archive-list time {
    color: var(--muted);
    font-size: 13px;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}
.archive-list a { color: var(--fg); text-decoration: none; }
.archive-list a:hover { color: var(--accent); }

/* ========== 分类 / 标签 ========== */
.term-list { list-style: none; margin: 0; padding: 0; max-width: 760px; }
.term-list li { display: inline-block; margin: 0 12px 12px 0; }
.term-list a {
    display: inline-block;
    border: 1px solid var(--border);
    padding: 4px 12px;
    text-decoration: none;
    color: var(--fg);
    font-size: 14px;
}
.term-list a:hover { border-color: var(--accent); color: var(--accent); }
.term-list .count { color: var(--muted); font-size: 12px; margin-left: 8px; }

/* ========== 搜索 ========== */
#search-input {
    width: 100%;
    max-width: 760px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--fg);
    font-size: 15px;
    outline: none;
}
#search-input:focus { border-color: var(--accent); }
.search-status { color: var(--muted); font-size: 13px; min-height: 1.5em; }

/* ========== 页脚 ========== */
.site-footer { border-top: 1px solid var(--border); padding: 20px 0 32px; font-size: 13px; color: var(--muted); }
.site-footer .container { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

/* ========== 404 ========== */
.not-found { padding: 60px 0; }
.not-found h1 { font-size: 48px; margin: 0 0 12px; }

/* ========== 移动端 ========== */
@media (max-width: 900px) {
    .post-layout { grid-template-columns: 1fr; gap: 24px; }
    .toc {
        position: static;
        order: -1;
        border-left: none;
        border: 1px solid var(--border);
        padding: 10px 16px;
    }
    .toc nav { max-height: 40vh; overflow-y: auto; }
}

@media (max-width: 600px) {
    body { font-size: 15px; }
    main.container { margin: 12px auto 24px; padding: 20px 16px 32px; }
    .post-header h1 { font-size: 22px; }
    .post-nav { flex-direction: column; gap: 8px; }
    .post-nav a { max-width: 100%; }
}
