/**
 * Woon Blog Theme
 *
 * 黑白灰极简博客主题: 衬线、留白、圆角
 * 默认浅色, 支持深色模式切换 (☾ / ☀)
 *
 * @package Woon Blog Theme
 * @author woon
 * @version 1.4.0
 * @link https://woon.top
 */

/* ========== 变量 ========== */
:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --text: #111111;
    --text-secondary: #666666;
    --text-tertiary: #999999;
    --border: #e5e5e5;
    --accent: #111111;
    --code-bg: #111111;
    --code-text: #ffffff;
    --nav-bg: rgba(255, 255, 255, 0.92);
    --radius: 12px;
    --maxw: 780px;
    --serif: Georgia, "Times New Roman", "Songti SC", "SimSun", serif;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    --mono: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
    --ease: cubic-bezier(0.19, 1, 0.22, 1);
}

[data-theme="dark"] {
    --bg: #0f0f0f;
    --surface: #171717;
    --text: #e8e8e8;
    --text-secondary: #a3a3a3;
    --text-tertiary: #6b6b6b;
    --border: #2a2a2a;
    --accent: #e8e8e8;
    --code-bg: #1c1c1c;
    --code-text: #e8e8e8;
    --nav-bg: rgba(15, 15, 15, 0.92);
}

/* ========== 重置 ========== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 76px; }

body {
    font-family: var(--serif);
    background: var(--bg);
    color: var(--text);
    line-height: 1.8;
    font-size: 17px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background 0.3s ease, color 0.3s ease;
}

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

a {
    color: var(--text);
    text-decoration: none;
    transition: color 0.2s ease;
}

/* ========== 顶部 ========== */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--nav-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.site-header .wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 18px;
    padding-bottom: 18px;
}

.site-title {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.site-title:hover { color: var(--text); }

.site-nav ul {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

.site-nav a {
    font-size: 0.82rem;
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 20px;
    transition: all 0.2s ease;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.site-nav a:hover {
    color: var(--text);
    background: var(--surface);
}

/* 主题切换按钮 */
.theme-toggle {
    width: 36px;
    height: 36px;
    margin-left: 10px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    border: 1px solid var(--border);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.theme-toggle:hover { transform: scale(1.08); }

/* 主题切换图标 (SVG) */
.theme-toggle .icon {
    width: 18px;
    height: 18px;
    display: block;        /* 去掉 inline 基线间隙，这是居中不稳的另一个常见源头 */
}

.theme-toggle .icon-sun { display: none; }

[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }

/* 顶栏 登录/后台 入口 */
.header-login {
    font-family: var(--sans);
    font-size: 0.78rem;
    color: var(--text-secondary);
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.header-login:hover {
    color: var(--text);
    border-color: var(--text);
}

/* 顶栏 退出按钮 (比登录按钮更淡) */
.header-logout {
    font-family: var(--sans);
    font-size: 0.78rem;
    color: var(--text-tertiary);
    padding: 6px 12px;
    border-radius: 20px;
    transition: color 0.2s ease;
    flex-shrink: 0;
}

.header-logout:hover {
    color: var(--text);
}

/* ========== 主体 ========== */
.site-main {
    padding: 56px 0 88px;
    min-height: calc(100vh - 180px);
}

/* ========== 文章列表 ========== */
.post-list { list-style: none; }

.post-item {
    padding: 48px 0;
    border-bottom: 1px solid var(--border);
}

.post-item:first-child { padding-top: 8px; }

.post-item .post-date {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    letter-spacing: 0.06em;
    display: block;
    margin-bottom: 10px;
}

.post-item h2 {
    font-size: 1.85rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.35;
    margin-bottom: 12px;
}

.post-item h2 a { color: var(--text); }
.post-item h2 a:hover { color: var(--text-secondary); }

.post-item .post-excerpt {
    font-size: 0.96rem;
    color: var(--text-secondary);
    line-height: 1.85;
    margin-bottom: 14px;
}

.post-item .post-meta {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.post-item .post-meta a { color: var(--text-tertiary); }
.post-item .post-meta a:hover { color: var(--text); }

/* ========== 分页 ========== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 32px 0 8px;
    font-size: 0.82rem;
    color: var(--text-tertiary);
}

.pagination a {
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 18px;
    transition: all 0.25s ease;
}

.pagination a:hover {
    color: var(--text);
    border-color: var(--text);
}

/* ========== 文章页 ========== */
.post-header {
    margin-bottom: 8px;
    text-align: center;
    padding: 24px 0 8px;
}

.post-header h1 {
    font-size: clamp(1.7rem, 4.5vw, 2.3rem);
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.35;
    margin-bottom: 14px;
}

.post-header .post-date {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    letter-spacing: 0.08em;
}

.post-divider {
    width: 100%;
    height: 1px;
    margin: 28px 0 44px;
    background: var(--border);
}

/* ========== 正文排版 ========== */
.post-content {
    font-size: 1rem;
    line-height: 1.9;
}

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

.post-content h1, .post-content h2, .post-content h3, .post-content h4 {
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1.4;
    margin: 2em 0 0.8em;
}

.post-content h2 { font-size: 1.45rem; }
.post-content h3 { font-size: 1.25rem; }
.post-content h4 { font-size: 1.1rem; }

.post-content a {
    color: var(--text);
    border-bottom: 1px solid var(--border);
    padding-bottom: 1px;
    transition: border-color 0.25s ease, color 0.25s ease;
}

.post-content a:hover {
    border-color: var(--text);
}

.post-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 2em auto;
    border-radius: var(--radius);
}

.post-content blockquote {
    margin: 2em 0;
    padding: 4px 0 4px 20px;
    border-left: 2px solid var(--text);
    color: var(--text-secondary);
    font-style: italic;
}

.post-content blockquote p:last-child { margin-bottom: 0; }

.post-content ul, .post-content ol {
    margin: 0 0 1.5em 1.5em;
}

.post-content li { margin-bottom: 0.4em; }

.post-content code {
    font-family: var(--mono);
    font-size: 0.85em;
    background: var(--code-bg);
    color: var(--code-text);
    padding: 2px 7px;
    border-radius: 6px;
}

.post-content pre {
    margin: 2em 0;
    padding: 18px 20px;
    background: var(--code-bg);
    color: var(--code-text);
    border-radius: 10px;
    overflow-x: auto;
}

.post-content pre code {
    background: none;
    padding: 0;
    font-size: 0.82rem;
    line-height: 1.7;
}

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

.post-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 2em 0;
    font-size: 0.92rem;
}

.post-content th, .post-content td {
    border: 1px solid var(--border);
    padding: 10px 14px;
    text-align: left;
}

.post-content th { color: var(--text-secondary); font-weight: 600; }

/* ========== 标签 ========== */
.post-tags {
    margin-top: 48px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
}

.post-tags a {
    display: inline-block;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 14px;
    margin: 0 8px 8px 0;
    transition: all 0.2s ease;
}

.post-tags a:hover {
    color: var(--text);
    border-color: var(--text);
}

/* ========== 归档 ========== */
.archive-title {
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: 8px;
}

.archive-title .keyword { color: var(--text-secondary); }

.archive-desc {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    letter-spacing: 0.04em;
    margin-bottom: 32px;
}

/* ========== 搜索 ========== */
.search-form {
    display: flex;
    align-items: center;
    gap: 0;
    margin: 8px 0 36px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0 16px;
    transition: border-color 0.25s ease;
}

.search-form:focus-within { border-color: var(--text); }

.search-form input[type="text"] {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-family: var(--serif);
    font-size: 1rem;
    padding: 12px 4px;
}

.search-form input[type="text"]::placeholder { color: var(--text-tertiary); }

.search-form button {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: var(--sans);
    font-size: 0.78rem;
    cursor: pointer;
    padding: 8px 6px;
}

.search-form button:hover { color: var(--text); }

/* ========== 404 ========== */
.notfound {
    min-height: 60vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.notfound .code {
    font-size: clamp(4rem, 12vw, 6.5rem);
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--text);
    line-height: 1;
}

.notfound p {
    color: var(--text-secondary);
    margin: 16px 0 32px;
}

.notfound a {
    font-family: var(--sans);
    font-size: 0.8rem;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 26px;
    transition: all 0.25s ease;
}

.notfound a:hover {
    color: var(--text);
    border-color: var(--text);
}

/* ========== 评论 ========== */
.comments {
    margin-top: 56px;
    padding-top: 36px;
    border-top: 1px solid var(--border);
}

.comments-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 24px;
}

.comment-list { list-style: none; }

.comment-list .comment {
    padding: 20px 0;
    border-bottom: 1px solid var(--border);
}

.comment-list .comment-meta {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    margin-bottom: 10px;
}

.comment-list .comment-meta .author {
    color: var(--text);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.comment-list .comment-content {
    color: var(--text-secondary);
    font-size: 0.92rem;
    line-height: 1.85;
}

.comment-list .comment-children {
    list-style: none;
    margin: 18px 0 0 32px;
    border-left: 1px solid var(--border);
    padding-left: 24px;
}

/* 评论表单 */
.comment-form { margin-top: 32px; }

.comment-form .form-row {
    display: flex;
    gap: 14px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.comment-form input[type="text"],
.comment-form input[type="email"],
.comment-form textarea {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-family: var(--serif);
    font-size: 0.92rem;
    padding: 10px 14px;
    outline: none;
    transition: border-color 0.25s ease;
}

.comment-form input[type="text"] { flex: 1; min-width: 200px; }
.comment-form textarea { min-height: 120px; resize: vertical; }

.comment-form input:focus,
.comment-form textarea:focus { border-color: var(--text); }

.comment-form input[type="submit"] {
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 10px;
    color: var(--bg);
    font-family: var(--sans);
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    padding: 10px 32px;
    cursor: pointer;
    transition: all 0.25s ease;
}

.comment-form input[type="submit"]:hover { opacity: 0.8; }

.comment-cancel a {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.comment-cancel a:hover { color: var(--text); }

/* ========== 页脚 ========== */
.site-footer {
    text-align: center;
    padding: 36px 24px 48px;
    border-top: 1px solid var(--border);
}

.site-footer span {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    letter-spacing: 0.04em;
}

.site-footer a { color: var(--text-tertiary); }
.site-footer a:hover { color: var(--text); }

/* ========== 双列布局 (主列 + 侧栏) ========== */
.layout-with-sidebar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 240px;
    gap: 56px;
    align-items: start;
    max-width: 960px;
}

.content-main { min-width: 0; }

/* ========== 侧栏 ========== */
.sidebar { font-size: 0.85rem; }

.sidebar .widget { margin-bottom: 32px; }

.sidebar .widget-title {
    font-family: var(--serif);
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text);
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.sidebar .widget-list {
    list-style: none;
}

.sidebar .widget-list li {
    padding: 7px 0;
    color: var(--text-secondary);
    line-height: 1.55;
}

.sidebar .widget-list a { color: var(--text-secondary); }
.sidebar .widget-list a:hover { color: var(--text); }

/* 空 widget 占位文字 */
.sidebar .widget-empty {
    color: var(--text-tertiary);
    font-size: 0.82rem;
    letter-spacing: 0.02em;
    padding: 2px 0;
}

/* 分类列表的缩进 */
.sidebar .widget-list .category-level-1 { padding-left: 16px; }
.sidebar .widget-list .category-level-2 { padding-left: 32px; }

/* 上一篇 / 下一篇 */
.post-near {
    display: flex;
    justify-content: space-between;
    list-style: none;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.post-near a { color: var(--text-secondary); }
.post-near a:hover { color: var(--text); }

/* ========== 回到顶部 ========== */
.to-top {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    border: none;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
    z-index: 200;
}

.to-top.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.to-top:hover { background: var(--text-secondary); }

/* ========== 响应式 ========== */
@media (max-width: 900px) {
    .layout-with-sidebar {
        grid-template-columns: minmax(0, 1fr);
        gap: 40px;
    }

    .sidebar {
        border-top: 1px solid var(--border);
        padding-top: 16px;
    }
}

@media (max-width: 600px) {
    body { font-size: 16px; }

    .wrap { padding: 0 16px; }

    .site-header .wrap {
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 14px;
        padding-bottom: 14px;
    }

    /* 顶栏两行: 第一行站点名, 第二行菜单+按钮 */
    .site-title {
        flex-basis: 100%;
        font-size: 1.2rem;
    }

    .site-nav ul { gap: 2px; }
    .site-nav a { font-size: 0.76rem; padding: 5px 10px; }

    .header-login { font-size: 0.72rem; padding: 5px 12px; }
    .header-logout { font-size: 0.72rem; padding: 5px 8px; }

    .theme-toggle { width: 32px; height: 32px; }

    .site-main { padding: 36px 0 64px; }

    .post-item h2 { font-size: 1.45rem; }

    .post-header h1 { font-size: 1.5rem; }

    /* 正文表格窄屏横向滚动, 不撑破页面 */
    .post-content table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .comment-list .comment-children {
        margin-left: 14px;
        padding-left: 14px;
    }

    .to-top { right: 16px; bottom: 16px; width: 38px; height: 38px; font-size: 1rem; }
}

/* ========== 减少动画 ========== */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * { transition: none !important; }
}

/* ========== 主题切换过渡 ==========
   仅在切换瞬间由 JS 挂上 .theme-transition，
   保证顶栏 / 正文 / 卡片同时缓动，不分两段。
   包在 no-preference 里，尊重系统的"减少动态效果"设置 */
@media (prefers-reduced-motion: no-preference) {
    html.theme-transition,
    html.theme-transition *:not(.theme-toggle),
    html.theme-transition *:not(.theme-toggle)::before,
    html.theme-transition *:not(.theme-toggle)::after {
        transition-property: background-color, border-color, color, fill, stroke, box-shadow !important;
        transition-duration: 0.35s !important;
        transition-timing-function: ease !important;
        transition-delay: 0s !important;
    }
}

/* 让根元素也带上背景色，转场时视口边缘不会闪白 */
html { background-color: var(--bg); }
