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

:root {
    --font-body:    "Noto Serif SC", "Source Serif Pro", Georgia, "Times New Roman", serif;
    --font-heading: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-code:    "Source Code Pro", "Menlo", "Monaco", "Consolas", monospace;
    --font-bold:    "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-italic:  "Noto Serif SC", Georgia, "Times New Roman", serif;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    line-height: 1.7;
    color: #333;
    background: #fafaf8;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { color: #2a6496; text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ===== Header ===== */
.site-header {
    background: #222;
    color: #fff;
    padding: 0 20px;
}
.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}
.site-title {
    color: #fff;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.site-title:hover { color: #fff; text-decoration: none; }
.site-nav { display: flex; gap: 20px; }
.site-nav a { color: #ccc; font-size: 0.9rem; }
.site-nav a:hover { color: #fff; text-decoration: none; }

/* ===== Main Layout ===== */
.site-main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px 20px;
}

/* ===== Post Layout (sidebar + content) ===== */
.post-layout {
    display: flex;
    gap: 30px;
}
.post-sidebar {
    flex: 0 0 260px;
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    font-size: 0.85rem;
}
.post-content {
    flex: 1;
    min-width: 0;
    max-width: 960px;
}

/* ===== Sidebar Profile ===== */
.sidebar-profile {
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #eee;
}
.sidebar-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 8px;
}
.sidebar-author {
    font-size: 0.95rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}
.sidebar-motto {
    font-size: 0.8rem;
    color: #888;
    font-style: italic;
    line-height: 1.4;
    margin-bottom: 8px;
}
.sidebar-social {
    display: flex;
    justify-content: center;
    gap: 12px;
}
.sidebar-social a {
    color: #666;
    display: flex;
    align-items: center;
}
.sidebar-social a:hover {
    color: #333;
    text-decoration: none;
}

/* ===== TOC ===== */
.toc { margin-bottom: 20px; }
.toc h3 {
    font-size: 0.95rem;
    margin-bottom: 8px;
    color: #555;
}
.toc ul {
    list-style: none;
    padding-left: 0;
}
.toc ul ul { padding-left: 16px; }
.toc li {
    margin: 3px 0;
    position: relative;
    padding-left: 12px;
}
.toc li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 7px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-accent);
}
.toc ul ul li::before {
    width: 5px;
    height: 5px;
    top: 8px;
    background: #999;
}
.toc ul ul ul li::before {
    width: 4px;
    height: 4px;
    top: 8px;
    background: #bbb;
}
.toc a { color: #666; font-size: 0.85rem; }
.toc a:hover { color: #333; }

/* ===== Post ===== */
.post-header { margin-bottom: 24px; }
.post-title {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: #222;
}
.post-meta {
    font-size: 0.85rem;
    color: #999;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
}
.post-meta .badge, .post-item-meta .badge {
    font-size: 0.8rem;
}
.post-meta .tag, .post-item-meta .tag {
    color: var(--color-accent);
}
.post-meta .tag:hover, .post-item-meta .tag:hover {
    background: var(--color-accent);
    color: #fff;
    text-decoration: none;
}

.post-body {
    background: #fff;
    padding: 30px;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ===== Post Body Typography ===== */
/* Shared typography for both .post-body and .post-item-excerpt */
.prose h1, .prose h2, .prose h3,
.prose h4, .prose h5, .prose h6 {
    font-family: var(--font-heading);
    margin-top: 1.5em;
    margin-bottom: 0.6em;
    font-weight: 600;
    color: #222;
}
.prose h2 { font-size: 1.4rem; border-bottom: 1px solid #eee; padding-bottom: 6px; }
.prose h3 { font-size: 1.2rem; }
.prose h4 { font-size: 1.05rem; }

.prose strong, .prose b {
    font-family: var(--font-bold);
    font-weight: 700;
}
.prose em, .prose i {
    font-family: var(--font-italic);
    font-style: italic;
}

.prose p { margin-bottom: 1em; }

.prose .wechat-card {
    display: flex;
    align-items: stretch;
    gap: 12px;
    width: min(100%, 520px);
    min-height: 96px;
    margin: 1em auto;
    padding: 12px;
    border: 1px solid #e2e2e2;
    border-radius: 4px;
    background: #fff;
    color: #222;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.prose .wechat-card:hover {
    color: #222;
    text-decoration: none;
    border-color: #cfcfcf;
    background: #fbfbfb;
}
.prose .wechat-card.has-hero-cover {
    flex-direction: column;
    gap: 0;
    padding: 0;
    overflow: hidden;
}
.prose .wechat-card-hero {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 0;
    background-color: #f1f1f1;
}
.prose .wechat-card.has-hero-cover .wechat-card-body {
    padding: 12px;
}
.prose .wechat-card-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 10px;
}
.prose .wechat-card-title {
    display: -webkit-box;
    overflow: hidden;
    color: #222;
    font-family: var(--font-heading);
    font-size: 0.98rem;
    font-weight: 600;
    line-height: 1.45;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.prose .wechat-card-description {
    display: -webkit-box;
    overflow: hidden;
    color: #777;
    font-size: 0.82rem;
    line-height: 1.45;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.prose .wechat-card-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #8a8a8a;
    font-size: 0.78rem;
    line-height: 1;
}
.prose .wechat-card-avatar {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: #f0f0f0;
    background-position: center;
    background-size: cover;
}
.prose .wechat-card-badge {
    padding: 2px 5px;
    border-radius: 3px;
    background: #edf8f1;
    color: #07c160;
    font-family: var(--font-heading);
    font-weight: 600;
}
.prose .wechat-card-source {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.prose .wechat-card-cover {
    flex: 0 0 80px;
    width: 80px;
    height: auto;
    max-height: none;
    margin: auto 0;
    border-radius: 4px;
    background-color: #f1f1f1;
    object-fit: contain;
}
.prose .wechat-card-icon {
    position: relative;
    flex: 0 0 56px;
    width: 56px;
    height: 56px;
    margin: auto 0;
    border-radius: 4px;
    background: #07c160;
}
.prose .wechat-card-icon::before,
.prose .wechat-card-icon::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    background: #fff;
}
.prose .wechat-card-icon::before {
    left: 10px;
    top: 15px;
    width: 28px;
    height: 21px;
}
.prose .wechat-card-icon::after {
    right: 9px;
    bottom: 14px;
    width: 24px;
    height: 18px;
    background: #eafff3;
    box-shadow: -10px -3px 0 -7px #07c160;
}

.prose hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 2em 0;
}

.prose ul, .prose ol { margin-bottom: 1em; padding-left: 2em; }
.prose li { margin-bottom: 0.3em; }

.prose blockquote {
    border-left: 4px solid #ddd;
    margin: 0.5em 0;
    padding: 0.4em 1em;
    color: #666;
    background: #fafafa;
}
.prose blockquote p:last-child { margin-bottom: 0; }

.prose table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 1em;
}
.prose th, .prose td {
    border: 1px solid #ddd;
    padding: 8px 12px;
    text-align: left;
}
.prose th { background: #f5f5f5; font-weight: 600; }
.prose tr:nth-child(even) { background: #fafafa; }

.prose img { border-radius: 4px; }
.prose figure {
    margin: 1em 0;
    text-align: center;
}
.prose figcaption {
    font-size: 0.85rem;
    color: #888;
    margin-top: 6px;
}

/* Redacted strikethrough: black block, hover to reveal */
.prose del {
    background: #333;
    color: #333;
    text-decoration: none;
    border-radius: 3px;
    padding: 0 4px;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
}
.prose del:hover {
    background: transparent;
    color: inherit;
}
.prose del a {
    color: inherit;
    text-decoration: none;
}
.prose del:hover a {
    color: var(--color-accent);
    text-decoration: underline;
}

/* ===== Code Blocks ===== */
.code-block {
    margin: 0 0 1em 0;
    border-radius: 8px;
    overflow: hidden;
    background: #f6f8fa;
    border: 1px solid #e1e4e8;
}
.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 14px;
    background: #e8ecf0;
    border-bottom: 1px solid #e1e4e8;
    font-size: 0.8rem;
}
.code-title, .code-lang {
    font-family: var(--font-code);
    font-size: 0.8rem;
    color: #555;
    font-weight: 500;
}
.code-lang { text-transform: uppercase; letter-spacing: 0.5px; }
.code-actions { display: flex; gap: 6px; }
.code-copy, .code-wrap {
    background: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 2px 10px;
    font-size: 0.75rem;
    cursor: pointer;
    color: #555;
    font-family: inherit;
}
.code-copy:hover, .code-wrap:hover { background: #fff; border-color: #999; }
.code-copy.copied { color: #2da44e; border-color: #2da44e; }
.code-wrap.active { color: var(--color-accent); border-color: var(--color-accent); }
.code-block pre.highlight {
    margin: 0;
    padding: 14px 0;
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.6;
}
.code-block code {
    font-family: var(--font-code);
    display: block;
}
.code-block .cl {
    display: block;
    padding: 0 16px 0 4.5em;
    min-height: 1.6em;
    white-space: pre;
    position: relative;
}
.code-block.wrap .cl {
    white-space: pre-wrap;
    word-break: break-all;
}
.code-block .ln {
    position: absolute;
    left: 0;
    width: 3.5em;
    padding-right: 12px;
    text-align: right;
    user-select: none;
    color: #adb5bd;
    font-size: 0.8rem;
}

/* Inline code */
.prose code {
    background: #eff1f3;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.88em;
    font-family: var(--font-code);
    color: #24292e;
}
.prose pre code {
    background: none;
    padding: 0;
}

/* ===== Mermaid ===== */
.mermaid-container {
    margin: 1em 0;
    text-align: center;
    overflow-x: auto;
}
.mermaid-container pre.mermaid {
    display: inline-block;
    text-align: left;
    background: #fff;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid #e1e4e8;
    font-size: 0.85rem;
    line-height: 1.5;
    font-family: monospace;
}

/* ===== Post Copyright ===== */
.post-copyright {
    margin-top: 24px;
    padding: 12px 16px;
    border-left: 3px solid var(--color-accent);
    background: #f9f9f9;
    border-radius: 0 4px 4px 0;
    font-size: 0.85rem;
    line-height: 1.7;
}
.post-copyright ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.post-copyright li {
    padding: 2px 0;
    color: #555;
}
.post-copyright a { color: var(--color-accent); }

/* ===== Reward ===== */
.reward-container {
    text-align: center;
}
.reward-container button {
    width: 48px;
    height: 48px;
    border: 2px solid #f0ad4e;
    border-radius: 50%;
    background: none;
    color: #f0ad4e;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    line-height: 1;
}
.reward-container button:hover {
    background: #f0ad4e;
    color: #fff;
}
.post-reward {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 10;
}
.post-reward.active {
    display: flex;
    justify-content: center;
    gap: 24px;
}
.post-reward > div {
    text-align: center;
}
.post-reward img {
    width: 200px;
    height: 200px;
    object-fit: cover;
    border-radius: 4px;
}
.post-reward span {
    display: block;
    margin-top: 6px;
    font-size: 0.85rem;
    color: #999;
}

/* ===== Giscus Comments ===== */
.giscus {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #eee;
}

/* ===== Note Boxes ===== */
.note {
    margin: 1em 0;
    padding: 6px 16px;
    border-left: 4px solid #777;
    border-radius: 0 4px 4px 0;
    background: #fafafa;
}
.note p:first-child { margin-top: 0; }
.note p:last-child { margin-bottom: 0; }
.note h1, .note h2, .note h3,
.note h4, .note h5, .note h6 { margin-top: 0; }

.note-default { border-left-color: #777; background: #fafafa; }
.note-primary { border-left-color: #6f42c1; background: #f8f5fc; }
.note-info    { border-left-color: var(--color-accent); background: #f0f6fc; }
.note-success { border-left-color: #5cb85c; background: #f0faf0; }
.note-warning { border-left-color: #f0ad4e; background: #fdf8f0; }
.note-danger  { border-left-color: #d9534f; background: #fdf5f5; }

/* ===== Group Pictures ===== */
.group-picture {
    margin: 16px 0;
}
.group-picture .gp-row {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
}
.group-picture .gp-row:last-child {
    margin-bottom: 0;
}
.group-picture figure {
    flex: 1;
    margin: 0;
}
.group-picture img {
    width: 100%;
    border-radius: 4px;
    display: block;
}
.group-picture figcaption {
    text-align: center;
    font-size: 0.85rem;
    color: #666;
}

/* ===== Video ===== */
.video-container video {
    width: 100%;
    border-radius: 4px;
}

/* ===== PDF ===== */
.pdf-container {
    margin: 1em 0;
}

/* ===== Math Error Fallback ===== */
.math-error {
    background: #fde8e8;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.85em;
}

/* ===== Post List (Index) ===== */
.post-list { max-width: 860px; margin: 0 auto; }
.post-item {
    background: #fff;
    padding: 24px 28px;
    margin-bottom: 16px;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.post-item-title {
    font-size: 1.3rem;
    margin-bottom: 6px;
}
.post-item-title a { color: #222; }
.post-item-title a:hover { color: var(--color-accent); text-decoration: none; }
.sticky-badge {
    background: #d9534f;
    color: #fff;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
}
.post-item-meta {
    font-size: 0.85rem;
    color: #999;
    margin-bottom: 8px;
    display: flex;
    gap: 10px;
}
.badge {
    background: #f0f0f0;
    padding: 1px 6px;
    border-radius: 3px;
    color: #666;
    font-size: 0.8rem;
}
.archive-category {
    font-size: 0.8rem;
    background: #f0f0f0;
    padding: 1px 6px;
    border-radius: 3px;
    color: #666;
}
.post-item-excerpt {
    color: #555;
    font-size: 0.95rem;
    line-height: 1.6;
}
.read-more {
    display: inline-block;
    margin-top: 8px;
    font-size: 0.9rem;
}

/* ===== Pagination ===== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 24px;
    padding: 16px 0;
}
.page-info { color: #999; font-size: 0.9rem; }

/* ===== Archive ===== */
.archive { max-width: 860px; margin: 0 auto; }
.archive-title {
    font-size: 1.6rem;
    margin-bottom: 20px;
}
.archive-year h2 {
    font-size: 1.2rem;
    color: var(--color-accent);
    margin-bottom: 10px;
    border-bottom: 1px solid #eee;
    padding-bottom: 4px;
}
.archive-list {
    list-style: none;
    padding-left: 0;
    margin-bottom: 24px;
}
.archive-list li {
    padding: 6px 0;
    border-bottom: 1px solid #f5f5f5;
    display: flex;
    gap: 12px;
    align-items: baseline;
}
.archive-list time {
    color: #999;
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* ===== Tags & Categories Pages ===== */
.page-title {
    font-size: 1.6rem;
    margin-bottom: 20px;
}
.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.tag-cloud-item {
    display: inline-block;
    padding: 4px 12px;
    background: #fff;
    border-radius: 4px;
    border: 1px solid #ddd;
    font-size: 0.9rem;
    color: #333;
}
.tag-cloud-item:hover { background: #f5f5f5; text-decoration: none; }
.tag-count { color: #999; font-size: 0.8rem; }

.category-list {
    list-style: none;
    padding: 0;
}
.category-list li {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    font-size: 1rem;
}
.category-count { color: #999; font-size: 0.85rem; }

/* ===== Post Footer (prev/next nav) ===== */
.post-footer {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: start;
    position: relative;
    margin-top: 30px;
    padding-top: 16px;
    border-top: 1px solid #eee;
}
.post-nav {
    min-width: 0;
}
.post-nav.prev { grid-column: 1; }
.post-nav.next {
    grid-column: 3;
    text-align: right;
}
.reward-container { grid-column: 2; }
.post-nav span {
    display: block;
    font-size: 0.8rem;
    color: #999;
    margin-bottom: 2px;
}
.post-nav a { font-size: 0.9rem; }

/* ===== Footer ===== */
.site-footer {
    text-align: center;
    padding: 24px 20px;
    color: #999;
    font-size: 0.85rem;
    border-top: 1px solid #eee;
    margin-top: 40px;
}
.footer-beian {
    margin-bottom: 8px;
}
.footer-beian a {
    color: #999;
    margin: 0 6px;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}
.footer-beian a:hover { color: #666; }
.beian-icon {
    width: 14px;
    height: 14px;
    vertical-align: middle;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .post-layout {
        flex-direction: column-reverse;
    }
    .post-sidebar {
        position: static;
        flex: 1;
        max-height: none;
        border-bottom: 1px solid #eee;
        padding-bottom: 12px;
        margin-bottom: 12px;
    }
    .post-body {
        padding: 20px;
    }
    .header-inner {
        flex-direction: column;
        height: auto;
        padding: 12px 0;
    }
    .site-nav {
        flex-wrap: wrap;
        justify-content: center;
        gap: 12px;
    }
}

/* ===== Hot Posts ===== */
.hot-posts {
    margin-top: 20px;
}
.hot-posts h3 {
    font-size: 0.95rem;
    margin-bottom: 8px;
    color: #555;
}
.hot-posts ol {
    list-style: none;
    padding-left: 0;
    counter-reset: hot-rank;
}
.hot-posts li {
    counter-increment: hot-rank;
    margin-bottom: 6px;
    font-size: 0.85rem;
    display: flex;
    align-items: baseline;
    gap: 6px;
}
.hot-posts li::before {
    content: counter(hot-rank);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    background: var(--color-accent);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}
.hot-posts li:nth-child(n+4)::before {
    background: #aaa;
}
.hot-posts li a {
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.hot-posts li a:hover { color: var(--color-accent); text-decoration: none; }
.hot-count {
    color: #999;
    font-size: 0.78rem;
    flex-shrink: 0;
    margin-left: auto;
}

.post-views {
    color: #999;
    font-size: 0.8rem;
}

/* ===== Search ===== */
.search-page {
    max-width: 860px;
    margin: 0 auto;
}
.search-box {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
}
.search-box input {
    flex: 1;
    padding: 10px 14px;
    font-size: 1rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    outline: none;
    font-family: inherit;
    background: #fff;
}
.search-box button {
    padding: 10px 20px;
    font-size: 1rem;
    border: none;
    border-radius: 6px;
    background: var(--color-accent);
    color: #fff;
    cursor: pointer;
    font-family: inherit;
}
.search-box button:hover { background: #2a6496; }
.search-box input:focus {
    border-color: var(--color-accent);
}
.search-item {
    padding: 16px 0;
    border-bottom: 1px solid #eee;
}
.search-item-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: #222;
}
.search-item-title:hover { color: var(--color-accent); text-decoration: none; }
.search-item-meta {
    font-size: 0.85rem;
    color: #999;
    margin: 4px 0;
    display: flex;
    gap: 6px;
    align-items: center;
}
.search-item-excerpt {
    color: #555;
    font-size: 0.9rem;
    line-height: 1.5;
    margin: 4px 0 0;
}
.search-empty {
    color: #999;
    text-align: center;
    padding: 40px 0;
}
