/* ===== CSS Variables ===== */
:root {
    --bg: #0d1117;
    --bg-card: #161b22;
    --bg-hover: #1c2128;
    --border: #30363d;
    --text: #c9d1d9;
    --text-muted: #8b949e;
    --text-heading: #e6edf3;
    --primary: #58a6ff;
    --accent: #3fb950;
    --danger: #f85149;
    --warning: #d29922;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
    --transition: 0.25s ease;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --font-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", monospace;
    --nav-height: 60px;
    --content-width: 860px;
    --sidebar-width: 280px;
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--nav-height) + 20px); }

body {
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.7;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: #79c0ff; }

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

::selection { background: rgba(88,166,255,0.3); }

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

/* ===== Progress Bar ===== */
.progress-bar {
    position: fixed; top: 0; left: 0; height: 3px; width: 0;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    z-index: 1001; transition: width 0.1s linear;
}

/* ===== Navbar ===== */
.navbar {
    position: fixed; top: 0; left: 0; right: 0; height: var(--nav-height);
    background: rgba(13,17,23,0.85);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
}

.nav-container {
    max-width: 1200px; margin: 0 auto; padding: 0 20px;
    display: flex; align-items: center; height: 100%; gap: 24px;
}

.nav-brand {
    font-size: 20px; font-weight: 700; color: var(--text-heading);
    white-space: nowrap;
}
.nav-brand:hover { color: var(--primary); }

.nav-links {
    display: flex; align-items: center; gap: 20px; flex: 1;
}
.nav-links a {
    color: var(--text-muted); font-size: 14px; font-weight: 500;
    padding: 6px 0; position: relative; transition: color var(--transition);
}
.nav-links a::after {
    content: ''; position: absolute; bottom: 0; left: 0; width: 0; height: 2px;
    background: var(--primary); transition: width var(--transition);
}
.nav-links a:hover { color: var(--text); }
.nav-links a:hover::after { width: 100%; }

.nav-rss { display: flex; align-items: center; }

.nav-search {
    margin-left: auto;
}
.nav-search input {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 20px;
    padding: 6px 16px; color: var(--text); font-size: 13px; width: 180px;
    transition: all var(--transition); outline: none;
}
.nav-search input::placeholder { color: var(--text-muted); }
.nav-search input:focus { border-color: var(--primary); width: 240px; }

.nav-toggle {
    display: none; background: none; border: none; cursor: pointer;
    flex-direction: column; gap: 5px; padding: 4px;
}
.nav-toggle span {
    display: block; width: 22px; height: 2px; background: var(--text);
    transition: all var(--transition);
}

/* ===== Main Content ===== */
.main-content {
    min-height: calc(100vh - var(--nav-height) - 80px);
    padding-top: calc(var(--nav-height) + 30px);
    padding-bottom: 40px;
}

/* ===== Layout: Two Column ===== */
.layout-two-col {
    display: grid;
    grid-template-columns: 1fr var(--sidebar-width);
    gap: 30px;
    max-width: 1200px; margin: 0 auto; padding: 0 20px;
}

.layout-single {
    max-width: var(--content-width); margin: 0 auto; padding: 0 20px;
}

/* ===== Post Card ===== */
.post-card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg);
    overflow: hidden; transition: all var(--transition); margin-bottom: 20px;
}
.post-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.post-card-cover {
    width: 100%; height: 200px; object-fit: cover; display: block;
}

.post-card-body { padding: 20px; }

.post-card-pin {
    display: inline-block; font-size: 13px; color: var(--warning);
    margin-bottom: 8px;
}

.post-card-title {
    font-size: 20px; font-weight: 700; color: var(--text-heading);
    margin-bottom: 8px; line-height: 1.4;
}
.post-card-title a { color: inherit; }
.post-card-title a:hover { color: var(--primary); }

.post-card-excerpt {
    color: var(--text-muted); font-size: 14px; line-height: 1.6;
    margin-bottom: 12px;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

.post-card-meta {
    display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
    font-size: 13px; color: var(--text-muted);
}
.post-card-meta a { color: var(--text-muted); }
.post-card-meta a:hover { color: var(--primary); }

.post-card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

/* ===== Tags ===== */
.tag {
    display: inline-block; padding: 2px 10px; font-size: 12px;
    background: rgba(88,166,255,0.1); color: var(--primary);
    border-radius: 20px; border: 1px solid rgba(88,166,255,0.2);
    transition: all var(--transition);
}
.tag:hover {
    background: rgba(88,166,255,0.2); color: #79c0ff;
    border-color: rgba(88,166,255,0.4);
}

/* ===== Post Detail ===== */
.post-header { margin-bottom: 32px; }

.post-title {
    font-size: 32px; font-weight: 800; color: var(--text-heading);
    line-height: 1.3; margin-bottom: 16px;
}

.post-meta {
    display: flex; flex-wrap: wrap; gap: 16px; color: var(--text-muted);
    font-size: 14px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}

.post-cover {
    width: 100%; border-radius: var(--radius-lg); margin-bottom: 32px;
}

/* ===== Post Content (Rich Text) ===== */
.post-content { font-size: 16px; line-height: 1.8; }

.post-content h1, .post-content h2, .post-content h3,
.post-content h4, .post-content h5, .post-content h6 {
    color: var(--text-heading); font-weight: 700; margin: 1.8em 0 0.8em;
    line-height: 1.3;
}
.post-content h1 { font-size: 28px; }
.post-content h2 { font-size: 24px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.post-content h3 { font-size: 20px; }
.post-content h4 { font-size: 17px; }

.post-content p { margin-bottom: 1em; }

.post-content ul, .post-content ol { margin: 0.8em 0; padding-left: 1.8em; }
.post-content li { margin-bottom: 0.4em; }

.post-content blockquote {
    margin: 1.2em 0; padding: 12px 20px;
    border-left: 4px solid var(--primary);
    background: rgba(88,166,255,0.06); border-radius: 0 var(--radius) var(--radius) 0;
    color: var(--text-muted);
}

.post-content table {
    width: 100%; border-collapse: collapse; margin: 1.2em 0;
    font-size: 14px;
}
.post-content th, .post-content td {
    padding: 10px 14px; border: 1px solid var(--border); text-align: left;
}
.post-content th { background: var(--bg-card); font-weight: 600; color: var(--text-heading); }

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

.post-content img {
    border-radius: var(--radius); cursor: pointer;
    transition: transform var(--transition);
}
.post-content img:hover { transform: scale(1.01); }

.post-content a { color: var(--primary); border-bottom: 1px solid transparent; }
.post-content a:hover { border-bottom-color: var(--primary); }

/* ===== Code Blocks ===== */
.post-content code {
    font-family: var(--font-mono); font-size: 0.88em;
    background: rgba(110,118,129,0.15); padding: 2px 6px; border-radius: 4px;
}

.post-content pre {
    position: relative; margin: 1.2em 0; border-radius: var(--radius);
    background: #0d1117; border: 1px solid var(--border);
    overflow-x: auto;
}
.post-content pre code {
    display: block; padding: 16px 20px; background: none;
    font-size: 14px; line-height: 1.6;
}

.code-copy-btn {
    position: absolute; top: 8px; right: 8px;
    background: var(--bg-card); border: 1px solid var(--border);
    color: var(--text-muted); padding: 4px 10px; border-radius: 4px;
    font-size: 12px; cursor: pointer; opacity: 0; transition: opacity var(--transition);
}
pre:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { color: var(--text); border-color: var(--text-muted); }
.code-copy-btn.copied { color: var(--accent); border-color: var(--accent); }

/* ===== Comments ===== */
.comments-section { margin-top: 48px; padding-top: 32px; border-top: 1px solid var(--border); }
.comments-section h3 { color: var(--text-heading); margin-bottom: 24px; font-size: 20px; }

.comment {
    position: relative; padding-left: 20px; margin-bottom: 20px;
}
.comment::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0;
    width: 2px; background: var(--border); border-radius: 1px;
}

.comment-author { font-weight: 600; color: var(--text-heading); font-size: 14px; }
.comment-date { color: var(--text-muted); font-size: 12px; margin-left: 8px; }
.comment-body { margin: 6px 0 8px; font-size: 14px; line-height: 1.6; }
.comment-reply-btn {
    background: none; border: none; color: var(--primary); cursor: pointer;
    font-size: 13px; padding: 0;
}
.comment-reply-btn:hover { text-decoration: underline; }

.comment-children { margin-left: 20px; margin-top: 12px; }

.comment-form { margin-top: 24px; }
.comment-form textarea, .comment-form input[type="text"] {
    width: 100%; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 12px; color: var(--text);
    font-family: var(--font); font-size: 14px; resize: vertical;
    transition: border-color var(--transition); outline: none;
}
.comment-form textarea:focus, .comment-form input[type="text"]:focus {
    border-color: var(--primary);
}
.comment-form textarea { min-height: 100px; margin-bottom: 12px; }
.comment-form .form-row { display: flex; gap: 12px; margin-bottom: 12px; }
.comment-form .form-row input { flex: 1; }

.comment-form button {
    background: var(--primary); color: #fff; border: none;
    padding: 10px 24px; border-radius: var(--radius); font-size: 14px;
    cursor: pointer; font-weight: 600; transition: all var(--transition);
}
.comment-form button:hover { background: #79c0ff; }

.comment-form.inline-reply {
    margin-left: 20px; margin-top: 12px; padding: 16px;
    background: var(--bg); border-radius: var(--radius); border: 1px solid var(--border);
}

.comment-pending {
    padding: 10px 16px; background: rgba(63,185,80,0.1);
    border: 1px solid rgba(63,185,80,0.3); border-radius: var(--radius);
    color: var(--accent); font-size: 14px; margin-top: 12px;
}

/* ===== Pagination ===== */
.pagination {
    display: flex; justify-content: center; align-items: center; gap: 4px;
    margin: 32px 0;
}
.pagination a, .pagination span {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 36px; height: 36px; padding: 0 10px;
    border-radius: var(--radius); font-size: 14px; font-weight: 500;
    border: 1px solid var(--border); color: var(--text-muted);
    transition: all var(--transition);
}
.pagination a:hover { border-color: var(--primary); color: var(--primary); }
.pagination .active {
    background: var(--primary); color: #fff; border-color: var(--primary);
}
.pagination .disabled { opacity: 0.4; pointer-events: none; }

/* ===== Sidebar ===== */
.sidebar {}

.sidebar-widget {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 20px; margin-bottom: 20px;
}
.sidebar-widget h4 {
    color: var(--text-heading); font-size: 15px; font-weight: 700;
    margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.sidebar-widget ul { list-style: none; }
.sidebar-widget li { margin-bottom: 10px; }
.sidebar-widget li a {
    color: var(--text-muted); font-size: 14px;
    display: flex; justify-content: space-between;
}
.sidebar-widget li a:hover { color: var(--primary); }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; }

/* ===== TOC Sidebar ===== */
.toc-sidebar {
    position: sticky; top: calc(var(--nav-height) + 20px);
}
#toc { list-style: none; }
#toc li { margin-bottom: 6px; }
#toc a {
    color: var(--text-muted); font-size: 13px; display: block;
    padding: 4px 0 4px 12px; border-left: 2px solid transparent;
    transition: all var(--transition);
}
#toc a:hover { color: var(--text); }
#toc a.active { color: var(--primary); border-left-color: var(--primary); }
#toc .toc-h3 { padding-left: 24px; }

/* ===== Post Detail Layout ===== */
.post-layout {
    display: grid;
    grid-template-columns: 1fr 220px;
    gap: 40px;
    max-width: 1100px; margin: 0 auto; padding: 0 20px;
}

/* ===== Archives ===== */
.archive-year {
    margin-bottom: 32px;
}
.archive-year h2 {
    font-size: 24px; color: var(--text-heading); margin-bottom: 16px;
    padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.archive-list { list-style: none; }
.archive-list li {
    display: flex; gap: 16px; padding: 8px 0;
    border-bottom: 1px solid rgba(48,54,61,0.4);
}
.archive-list .archive-date { color: var(--text-muted); font-size: 14px; min-width: 80px; font-family: var(--font-mono); }
.archive-list a { font-size: 15px; }

/* ===== Search ===== */
.search-header { margin-bottom: 24px; }
.search-input-lg {
    width: 100%; padding: 14px 20px; font-size: 16px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); color: var(--text); outline: none;
    transition: border-color var(--transition);
}
.search-input-lg:focus { border-color: var(--primary); }

.search-result mark {
    background: rgba(88,166,255,0.25); color: var(--primary);
    padding: 1px 2px; border-radius: 2px;
}

.no-results {
    text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.no-results span { font-size: 48px; display: block; margin-bottom: 16px; }

/* ===== About ===== */
.about-page { max-width: 700px; margin: 0 auto; padding: 0 20px; }
.about-page h1 { font-size: 28px; color: var(--text-heading); margin-bottom: 24px; }
.about-page p { margin-bottom: 1em; color: var(--text-muted); }

/* ===== Back to Top ===== */
.back-to-top {
    position: fixed; bottom: 30px; right: 30px; width: 40px; height: 40px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 50%; color: var(--text); font-size: 18px;
    cursor: pointer; opacity: 0; visibility: hidden;
    transition: all var(--transition); z-index: 999;
    display: flex; align-items: center; justify-content: center;
}
.back-to-top.visible { opacity: 1; visibility: visible; }
.back-to-top:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-2px); }

/* ===== Image Modal ===== */
.image-modal {
    position: fixed; inset: 0; background: rgba(0,0,0,0.85);
    display: none; align-items: center; justify-content: center;
    z-index: 2000; cursor: zoom-out; padding: 20px;
}
.image-modal.show { display: flex; }
.image-modal img { max-width: 95%; max-height: 95vh; border-radius: var(--radius); }

/* ===== Footer ===== */
.footer {
    text-align: center; padding: 24px 0; color: var(--text-muted);
    font-size: 13px; border-top: 1px solid var(--border);
}

/* ===== Page Title ===== */
.page-title {
    font-size: 24px; color: var(--text-heading); margin-bottom: 24px;
    padding-bottom: 12px; border-bottom: 1px solid var(--border);
}

/* ===== Admin Styles ===== */
.admin-body { background: var(--bg); color: var(--text); font-family: var(--font); }
.admin-header {
    background: var(--bg-card); border-bottom: 1px solid var(--border);
    padding: 16px 24px; display: flex; justify-content: space-between; align-items: center;
}
.admin-header h2 { font-size: 18px; color: var(--text-heading); }
.admin-header button {
    background: transparent; color: var(--text-muted); border: 1px solid var(--border);
    padding: 6px 16px; border-radius: var(--radius); cursor: pointer;
    transition: all var(--transition);
}
.admin-header button:hover { color: var(--text); border-color: var(--text); }

.admin-sidebar-nav {
    width: 200px; background: var(--bg-card); border-right: 1px solid var(--border);
    padding-top: 16px; min-height: calc(100vh - 56px);
}
.admin-sidebar-nav a {
    display: block; padding: 12px 24px; color: var(--text-muted); font-size: 14px;
    transition: all var(--transition);
}
.admin-sidebar-nav a:hover, .admin-sidebar-nav a.active {
    color: #fff; background: var(--primary);
}

.admin-content { flex: 1; padding: 24px; }
.admin-content h3 { color: var(--text-heading); margin-bottom: 16px; }

.admin-table {
    width: 100%; border-collapse: collapse; background: var(--bg-card);
    border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border);
}
.admin-table th, .admin-table td {
    padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border);
}
.admin-table th { background: var(--bg-hover); font-weight: 600; color: var(--text-heading); font-size: 13px; }

.admin-btn {
    padding: 4px 12px; border: none; border-radius: 4px;
    cursor: pointer; font-size: 13px; margin-right: 4px; transition: opacity var(--transition);
}
.admin-btn:hover { opacity: 0.85; }
.admin-btn-primary { background: var(--primary); color: #fff; }
.admin-btn-danger { background: var(--danger); color: #fff; }
.admin-btn-success { background: var(--accent); color: #fff; }

/* ===== Responsive: 768px ===== */
@media (max-width: 768px) {
    .layout-two-col { grid-template-columns: 1fr; }
    .post-layout { grid-template-columns: 1fr; }
    .post-layout .toc-sidebar { display: none; }

    .nav-toggle { display: flex; }
    .nav-links {
        display: none; position: absolute; top: var(--nav-height);
        left: 0; right: 0; background: rgba(13,17,23,0.95);
        backdrop-filter: blur(12px); flex-direction: column;
        padding: 16px 20px; gap: 12px;
        border-bottom: 1px solid var(--border);
    }
    .nav-links.open { display: flex; }
    .nav-search { margin-left: 0; }
    .nav-search input { width: 100%; }

    .post-title { font-size: 24px; }
    .sidebar { margin-top: 20px; }
}

/* ===== Responsive: 480px ===== */
@media (max-width: 480px) {
    .post-card-body { padding: 14px; }
    .post-card-title { font-size: 17px; }
    .post-card-cover { height: 150px; }
    .comment-form .form-row { flex-direction: column; }
    .container { padding: 0 12px; }
    .back-to-top { bottom: 16px; right: 16px; }
}
