/* ============================================================
   1. 核心变量与全局重置
   ============================================================ */
:root {
    --page-bg: #f5f5f7;
    --card-bg: #ffffff;
    --text-main: #1d1d1f;
    --text-meta: #86868b;
    --heading: #1d1d1f;
    --link-color: #007aff;
    --border-color: rgba(0, 0, 0, 0.08);
    --accent-orange: #ff9500;
    --header-height: 60px;
    --meta-height: 32px;
    /* 预设固定高度 */
}

@media (prefers-color-scheme: dark) {
    :root {
        --page-bg: #000000;
        --card-bg: #1c1c1e;
        --text-main: #f5f5f7;
        --heading: #ffffff;
        --border-color: rgba(255, 255, 255, 0.12);
    }
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    -webkit-font-smoothing: antialiased;
    background: var(--page-bg);
    color: var(--text-main);
    /* 针对中文优化的字体栈：优先系统默认，后备 PingFang/YaHei */
    font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

/* ============================================================
   2. 顶部导航栏 (Header)
   ============================================================ */
.header {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 800px;
    height: var(--header-height);
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    background: color-mix(in srgb, var(--page-bg) 85%, transparent);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.header.hide {
    transform: translate(-50%, -100%);
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.header-left h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.header-left h2 a {
    color: var(--heading);
    text-decoration: none;
}

.author-tag {
    font-size: 13px;
    color: var(--accent-orange);
    text-decoration: none;
    font-weight: 500;
}

.manage-btn {
    font-size: 12px;
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 6px 14px;
    border-radius: 8px;
    color: var(--text-meta);
    cursor: pointer;
    font-weight: 500;
    transition: 0.2s;
}

.manage-btn:hover {
    background: var(--border-color);
    color: var(--text-main);
}

.header-right {
    display: flex;
    align-items: center;
}

#viewBtns,
#editBtns {
    display: flex;
    gap: 10px;
    align-items: center;
}

#editor {
    width: 100%;
    min-height: 60vh;
    font-family: monospace;
    padding: 20px;
    background: var(--card-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    line-height: 1.5;
    resize: vertical;
    margin-top: 100px;
    margin-bottom: 50px;
    display: none;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

#editor.active {
    display: block;
}

/* ============================================================
   3. 首页列表 (彻底修复高度抖动)
   ============================================================ */
#list {
    max-width: 800px;
    margin: 0 auto;
    padding: 80px 20px 0;
}

.card {
    background: var(--card-bg);
    padding: 16px 20px;
    margin-bottom: 12px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    transition: transform 0.4s ease, opacity 0.4s ease;
}

.card a {
    font-size: 17px;
    font-weight: 600;
    text-decoration: none;
    color: var(--text-main);
    display: block;
    margin-bottom: 6px;
    line-height: 1.4;
}

/* 核心修复：固定高度并使用 flex 居中，确保占位一致 */
.meta {
    height: var(--meta-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-meta);
    overflow: hidden;
}

.del-btn {
    display: none !important;
    cursor: pointer;
    color: var(--text-meta);
    font-size: 13px;
    padding: 4px 12px;
    /* 减小上下内边距 */
    height: 28px;
    /* 强制按钮高度小于 meta 高度 */
    border-radius: 6px;
    user-select: none;
    align-items: center;
    justify-content: center;
    min-width: 70px;
    transition: all 0.2s;
    background: transparent;
}

body.admin-mode .del-btn {
    display: inline-flex !important;
}

.del-btn:hover {
    color: #ff3b30;
    background: rgba(255, 59, 48, 0.08);
}

.del-btn.confirming {
    color: #ff3b30;
    background: rgba(255, 59, 48, 0.12);
    font-weight: 500;
}

/* ============================================================
   4. 详情页排版
   ============================================================ */
/* 改进后的正文排版 */
article {
    max-width: 680px;
    /* 稍微收窄以提升阅读体验 */
    margin: 0 auto;
    padding: 100px 20px 120px;
    font-size: 17px;
    /* 稍微减小字号显得更精致 */
    line-height: 1.75;
    /* 1.75倍行高对于中文阅读最舒适 */
    color: var(--text-main);
}

article h1 {
    font-size: 28px;
    margin: 0 0 1.5em;
    line-height: 1.4;
    font-weight: 700;
    color: var(--heading);
    letter-spacing: -0.02em;
}

article h2 {
    font-size: 22px;
    margin: 2em 0 0.8em;
    font-weight: 600;
    color: var(--heading);
}

article h3 {
    font-size: 19px;
    margin: 1.6em 0 0.6em;
    font-weight: 600;
    color: var(--heading);
}

article p {
    margin: 1.4em 0;
    /* 稍微收紧段间距 */
    text-align: justify;
    text-justify: inter-ideograph;
    /* 优化中文两端对齐 */
    word-break: break-all;
    /* 防止长单词撑破 */
}

article ul,
article ol {
    margin: 1.5em 0;
    padding-left: 1.5em;
}

article li {
    margin-bottom: 0.5em;
}

article blockquote {
    margin: 2em 0;
    padding: 0.8em 1em 0.8em 1.2em;
    border-left: 4px solid var(--accent-orange);
    background: color-mix(in srgb, var(--accent-orange) 10%, transparent);
    border-radius: 4px;
    color: var(--text-main);
    font-style: italic;
}

article blockquote p {
    margin: 0;
}

article img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 2em auto;
    border-radius: 8px;
    /* 稍微减小圆角 */
    border: 1px solid var(--border-color);
    /* 增加微弱边框 */
}

/* 针对微信文章常见的强调样式适配 */
article strong {
    font-weight: 600;
    color: var(--heading);
}

/* ============================================================
   5. 弹窗与 Toast
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: 0.3s;
    z-index: 2000;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-box {
    background: var(--card-bg);
    width: 320px;
    padding: 32px 24px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    text-align: center;
    border: 1px solid var(--border-color);
}

.modal-box h3 {
    margin: 0 0 20px;
    font-size: 19px;
    font-weight: 600;
}

.modal-box input {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--page-bg);
    color: var(--text-main);
    margin-bottom: 24px;
    font-size: 16px;
}

.modal-footer {
    display: flex;
    gap: 12px;
}

.modal-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
}

.modal-btn.cancel {
    background: var(--page-bg);
    color: var(--text-meta);
}

.modal-btn.confirm {
    background: var(--link-color);
    color: white;
}

.toast-container {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translate(-50%, 100px);
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(20px);
    color: white;
    padding: 10px 24px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 3000;
    transition: 0.4s cubic-bezier(0.23, 1, 0.32, 1);
    opacity: 0;
    pointer-events: none;
}

.toast-container.active {
    transform: translate(-50%, 0);
    opacity: 1;
}

.load-status {
    text-align: center;
    max-width: 800px;
    margin: 0 auto;
    padding: 80px 20px;
    color: var(--text-meta);
    font-size: 13px;
    opacity: 0.6;
}

.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 59, 48, 0.2);
    border-top-color: #ff3b30;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.article-footer {
    margin-top: 80px;
    padding: 30px 0;
    text-align: center;
    border-top: 1px solid var(--border-color);
}

.article-footer a {
    color: var(--text-meta);
    font-size: 14px;
    text-decoration: none;
    opacity: 0.4;
    transition: opacity 0.3s;
}

.article-footer a:hover {
    opacity: 0.8;
}