/* ===== 主题变量：浅色为默认值，深色由 [data-theme="dark"] 覆盖 ===== */
:root {
    color-scheme: light;
    --bg: #f5f6f7;
    --bg-card: #fff;
    --border: #e5e7eb;
    --text: #333;
    --text-strong: #1f2937;
    --text-body: #374151;
    --text-em: #111827;
    --text-nav: #4b5563;
    --text-muted: #6b7280;
    --text-faint: #9ca3af;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --link: #2563eb;
    --link-hover: #1d4ed8;
    --link-visited: #6d28d9;
    --link-underline: rgba(37, 99, 235, .35);
    --accent-soft: #eff6ff;
    --pre-bg: #f6f8fa;
    --btn-disabled: #93c5fd;
    --c-admin: #d97706;
    --c-success: #16a34a;
    --c-error: #dc2626;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #111827;
    --bg-card: #1f2937;
    --border: #374151;
    --text: #d1d5db;
    --text-strong: #f3f4f6;
    --text-body: #d1d5db;
    --text-em: #f3f4f6;
    --text-nav: #d1d5db;
    --text-muted: #d1d5db;
    --text-faint: #9ca3af;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --link: #60a5fa;
    --link-hover: #93c5fd;
    --link-visited: #a78bfa;
    --link-underline: rgba(96, 165, 250, .4);
    --accent-soft: rgba(96, 165, 250, .15);
    --pre-bg: #111827;
    --btn-disabled: #1e40af;
    --c-admin: #f59e0b;
    --c-success: #22c55e;
    --c-error: #f87171;
}

/* ===== 前台三段式布局（仿 bcxm.fun 结构） ===== */
* { box-sizing: border-box; }

html {
    -webkit-tap-highlight-color: transparent;
    /* 禁止移动端浏览器在横屏/字体放大时对文本二次缩放 */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
    color: var(--text);
    background: var(--bg);
    touch-action: manipulation;
}

/* 键盘导航焦点环：所有可交互元素统一可见焦点 */
:focus-visible {
    outline: 2px solid var(--link);
    outline-offset: 2px;
}

/* 无障碍：屏幕阅读器专用文本 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* 跳过导航链接：聚焦时浮现 */
.skip-link {
    position: absolute;
    top: -48px;
    left: 8px;
    z-index: 100;
    padding: 8px 14px;
    background: var(--accent);
    color: #fff;
    border-radius: 6px;
    text-decoration: none;
    transition: transform .2s ease, top .2s ease;
}
.skip-link:focus-visible { top: 8px; }

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
}

/* ---- 页头 ---- */
.site-header { position: relative; background: var(--bg-card); border-bottom: 1px solid var(--border); }
.header-inner { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; }
.header-actions { display: flex; align-items: center; }
.site-title { font-size: 20px; font-weight: 700; color: var(--text-strong); text-decoration: none; }
.main-nav a { margin-left: 18px; color: var(--text-nav); text-decoration: none; }
.main-nav a.active, .main-nav a:hover { color: var(--link); }

/* ---- 页头图标按钮：搜索与主题切换共用 ---- */
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; margin-left: 18px; padding: 0;
    background: transparent; border: 1px solid var(--border); border-radius: 6px;
    color: var(--text-nav); cursor: pointer;
}
.icon-btn:hover { color: var(--link); border-color: var(--link); }
.icon-btn svg { width: 16px; height: 16px; }
/* 主题按钮图标：浅色显示月亮（点按进入深色），深色显示太阳 */
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* ---- 移动导航切换按钮：默认隐藏，仅窄屏 + JS 可用时出现 ---- */
.nav-toggle { display: none; }
.nav-toggle .icon-close { display: none; }
.nav-toggle[aria-expanded="true"] .icon-menu { display: none; }
.nav-toggle[aria-expanded="true"] .icon-close { display: block; }

/* ---- 主体：内容区 + 侧栏 ---- */
.layout-main { display: flex; gap: 20px; padding: 20px 16px; }
.content-area { flex: 1; min-width: 0; }
.sidebar { width: 280px; flex-shrink: 0; }

/* ---- 文章卡片 ---- */
.post-card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
    padding: 16px 20px; margin-bottom: 16px;
    transition: transform .2s ease;
}
.post-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0, 0, 0, .08); }
.post-title { margin: 0 0 6px; font-size: 18px; text-wrap: balance; }
.post-title a { color: var(--text-strong); text-decoration: none; }
.post-title a:hover { color: var(--link); }
.post-meta { font-size: 12px; color: var(--text-faint); margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.post-meta a { color: var(--link); text-decoration: none; }
.post-meta a:hover { color: var(--link-hover); }
.post-meta .meta-sep { margin: 0 4px; }

/* ---- 链接系统：正文常显下划线；UI 链接悬停/聚焦浮现下划线；visited 仅文章标题类 ---- */

/* 正文（marked 渲染，文章/自定义页）：常显下划线作为不依赖颜色的可读性线索 */
.markdown-body a {
    color: var(--link);
    text-decoration: underline;
    text-decoration-color: var(--link-underline);
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
    transition: color .15s ease, text-decoration-color .15s ease;
}
.markdown-body a:hover,
.markdown-body a:focus-visible {
    color: var(--link-hover);
    text-decoration-color: currentColor;
}
.markdown-body a:visited { color: var(--link-visited); }

/* 侧栏分类统计链接 */
.stat-list a { color: var(--link); text-decoration: none; }
.stat-list a:hover, .stat-list a:focus-visible { color: var(--link-hover); }

/* 时间轴文章标题链接 */
.archive-list a { color: var(--text-body); text-decoration: none; }
.archive-list a:hover, .archive-list a:focus-visible { color: var(--link); }
.archive-list a:visited { color: var(--link-visited); }

/* 页脚备案链接（低调灰，悬停转链接色） */
.site-footer a { color: var(--text-faint); text-decoration: none; }
.site-footer a:hover, .site-footer a:focus-visible { color: var(--link); }

/* 评论作者主页链接 */
.c-head a { color: var(--link); text-decoration: none; }
.c-head a:hover, .c-head a:focus-visible { color: var(--link-hover); }

/* 文章卡片标题：visited 提示已读（隐私规则下仅颜色生效） */
.post-title a:visited { color: var(--link-visited); }

/* UI 链接统一手势：悬停/聚焦浮现下划线 */
.post-title a, .post-meta a, .stat-list a, .archive-list a,
.main-nav a, .search-results a, .site-footer a, .c-head a {
    transition: color .15s ease, text-decoration-color .15s ease;
}
.post-title a:hover, .post-title a:focus-visible,
.post-meta a:hover, .post-meta a:focus-visible,
.stat-list a:hover, .stat-list a:focus-visible,
.archive-list a:hover, .archive-list a:focus-visible,
.main-nav a:hover, .main-nav a:focus-visible,
.search-results a:hover, .search-results a:focus-visible,
.site-footer a:hover, .site-footer a:focus-visible,
.c-head a:hover, .c-head a:focus-visible {
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

/* ---- 动效偏好：减少动效时关闭过渡与位移动画 ---- */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
    .post-card:hover, .link-card:hover { transform: none; }
}
.post-summary {
    margin: 0; color: var(--text-muted); font-size: 14px; line-height: 1.7;
    display: -webkit-box; -webkit-box-orient: vertical;
    -webkit-line-clamp: 3; line-clamp: 3;
    overflow: hidden;
}

/* ---- 侧栏组件 ---- */
.widget { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 16px; }
.widget h3 { margin: 0 0 10px; font-size: 14px; color: var(--link); border-left: 3px solid var(--link); padding-left: 8px; }
.stat-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.stat-list li { display: flex; justify-content: space-between; padding: 4px 0; color: var(--text-muted); }
.stat-list em { font-style: normal; color: var(--text-em); font-variant-numeric: tabular-nums; }
.author-desc { margin: 0; font-size: 13px; color: var(--text-muted); }

/* ---- 页脚 ---- */
.site-footer { border-top: 1px solid var(--border); background: var(--bg-card); margin-top: 16px; padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px)); }
.site-footer p { margin: 0; text-align: center; color: var(--text-faint); font-size: 13px; line-height: 1.7; }

/* ---- 空状态提示（无文章/无分类/无友链共用） ---- */
.empty-tip { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 32px 16px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* ---- 响应式与触屏适配规则统一放在文件末尾，保证覆盖前面的基础样式 ---- */

/* ---- 错误页 ---- */
.error-page { text-align: center; padding: 64px 16px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; margin-top: 24px; }
.error-page h1 { font-size: 64px; margin: 0 0 8px; color: var(--link); }
.error-page p { color: var(--text-muted); }
.error-page .back-home { display: inline-block; margin-top: 12px; padding: 8px 20px; background: var(--accent); color: #fff; border-radius: 6px; text-decoration: none; }
.error-page .back-home:hover { background: var(--accent-hover); }

/* ---- 文章详情 ---- */
.article-detail { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 24px; }
.article-title { margin: 0 0 8px; text-wrap: balance; }
.article-tags .tag, .tag { display: inline-block; padding: 2px 10px; margin-right: 6px; font-size: 12px; color: var(--link); background: var(--accent-soft); border-radius: 10px; }
.like-btn {
    margin-left: 8px; padding: 4px 12px;
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px;
    color: var(--link); font-size: 12px; cursor: pointer;
}
.like-btn:hover { border-color: var(--link); }
.like-btn:disabled { color: var(--text-faint); border-color: var(--border); cursor: default; }
.markdown-body { line-height: 1.8; }
.markdown-body pre { background: var(--pre-bg); padding: 12px; border-radius: 6px; overflow-x: auto; }

/* ---- 正文防溢出：媒体约束到容器宽，大图等比缩放 ---- */
.markdown-body img,
.markdown-body video,
.markdown-body iframe,
.markdown-body embed {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}
.markdown-body img {
    display: block;
    margin: 12px auto;
}
.markdown-body { overflow-wrap: break-word; }
.markdown-body table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

/* ---- 评论区 ---- */
.comment-section { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 20px 24px; margin-top: 20px; }
.section-title { font-size: 18px; margin: 0 0 16px; text-wrap: balance; }
.comment-item { padding: 10px 0; border-bottom: 1px dashed var(--border); content-visibility: auto; contain-intrinsic-size: auto 72px; }
.comment-child { margin-left: 32px; border-left: 3px solid var(--accent-soft); padding-left: 12px; }
.c-head { font-size: 13px; color: var(--text-muted); display: flex; justify-content: space-between; gap: 12px; overflow-wrap: anywhere; }
.c-head strong, .c-head a, .c-head time { min-width: 0; }
.c-head time { flex-shrink: 0; }
.c-admin { color: var(--c-admin); }
.c-content { margin: 6px 0 0; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.c-empty { color: var(--text-faint); text-align: center; padding: 12px 0; }
.comment-form .form-row { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.form-field { flex: 1; min-width: 140px; }
.comment-form label { display: block; margin-bottom: 4px; font-size: 13px; color: var(--text-nav); }
/* 表单控件 font: inherit 继承正文字号（≥16px），避免 iOS 聚焦自动放大页面 */
.comment-form input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-card); color: var(--text); font: inherit; }
.comment-form textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-card); color: var(--text); font: inherit; }
.btn-submit { margin-top: 8px; padding: 8px 24px; background: var(--accent); color: #fff; border: none; border-radius: 6px; cursor: pointer; }
.btn-submit:hover { background: var(--accent-hover); }
.btn-submit:disabled { background: var(--btn-disabled); cursor: default; }
.comment-tip { margin-left: 10px; color: var(--c-success); font-size: 13px; }
.comment-tip.error { color: var(--c-error); }

/* ---- 首页分页 ---- */
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 16px 0; }
.pager-btn { padding: 6px 16px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; color: var(--link); text-decoration: none; }
.pager-btn:hover { border-color: var(--link); background: var(--accent-soft); }
.pager-info { color: var(--text-muted); font-size: 13px; }
.page-title { margin: 0 0 16px; text-wrap: balance; }
.archive-group { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; margin-bottom: 16px; content-visibility: auto; contain-intrinsic-size: auto 100px; }
.archive-month { font-size: 16px; color: var(--link); border-left: 3px solid var(--link); padding-left: 8px; text-wrap: balance; }
.archive-list { list-style: none; padding: 0; margin: 8px 0 0; }
.archive-list li { display: flex; gap: 12px; padding: 6px 0; }
.archive-list time { color: var(--text-faint); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---- 友链页 ---- */
.link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.link-card { display: flex; gap: 10px; align-items: center; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; text-decoration: none; transition: transform .2s ease; }
.link-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.08); }
.link-card > div { min-width: 0; }
.link-avatar { width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; }
.link-title { color: var(--text-strong); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-desc { color: var(--text-faint); font-size: 12px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- 关于页 ---- */
.about-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 20px 24px; }
.about-card p { margin: 0 0 12px; line-height: 1.8; color: var(--text-body); }
.about-card p:last-child { margin-bottom: 0; }

/* ---- 侧栏博主卡片：头像居中 + 昵称/签名 + 社交图标行 ---- */
.author-card { text-align: center; }
.author-avatar {
    display: block; width: 72px; height: 72px;
    margin: 0 auto 10px; border-radius: 50%;
    object-fit: cover;
}
.author-name { margin: 0 0 4px; font-size: 16px; font-weight: 700; color: var(--text-strong); }
.author-socials { display: flex; justify-content: center; gap: 14px; margin-top: 12px; }
.author-socials a { display: inline-flex; color: var(--text-muted); }
.author-socials a:hover { color: var(--link); }
.social-icon { width: 18px; height: 18px; }

/* ---- 搜索弹框 ---- */
/* Alpine 初始化前隐藏 x-cloak 元素，避免弹框闪出 */
[x-cloak] { display: none !important; }

.search-modal {
    position: fixed; inset: 0; z-index: 200;
    display: flex; align-items: flex-start; justify-content: center;
    padding: 12vh 16px 0;
    background: rgba(0, 0, 0, .5);
}
.search-panel {
    width: 100%; max-width: 560px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 10px; box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
    overflow: hidden;
}
.search-panel input {
    width: 100%; padding: 14px 16px;
    border: none; border-bottom: 1px solid var(--border);
    background: transparent; color: var(--text);
    /* 16px 是 iOS Safari 不再对聚焦输入框自动放大页面的阈值 */
    font-size: 16px; outline: none;
}
.search-results {
    list-style: none; margin: 0; padding: 8px;
    max-height: 50vh; overflow-y: auto;
}
.search-results li { padding: 10px 12px; border-radius: 8px; }
.search-results li:hover { background: var(--accent-soft); }
.search-results a { color: var(--text-strong); text-decoration: none; font-size: 15px; }
.search-results a:hover { color: var(--link); }
.search-result-meta { margin: 4px 0 0; color: var(--text-faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.search-result-summary {
    margin: 4px 0 0; color: var(--text-muted); font-size: 13px;
    display: -webkit-box; -webkit-box-orient: vertical;
    -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.search-empty { padding: 24px 16px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* ---- 动效减弱偏好：关闭位移过渡 ---- */
@media (prefers-reduced-motion: reduce) {
    .post-card, .link-card, .skip-link { transition: none; }
    .post-card:hover, .link-card:hover { transform: none; }
}

/* ---- 响应式：窄屏折叠导航、侧栏下移、触摸目标放大 ---- */
@media (max-width: 768px) {
    /* 布局：内容单列，侧栏整体移到内容下方 */
    .layout-main { flex-direction: column; gap: 12px; padding: 12px 12px 16px; }
    .sidebar { width: 100%; }

    /* 页头：标题略小，图标按钮放大为 40px 触摸目标 */
    .header-inner { padding: 10px 12px; }
    .site-title { font-size: 18px; }
    .icon-btn { width: 40px; height: 40px; margin-left: 8px; }

    /* 折叠导航：JS 可用时收起为纵向面板，从页头下方展开；无 JS 则保持横向链接可用 */
    .js .nav-toggle { display: inline-flex; }
    .js .main-nav {
        position: absolute; top: 100%; left: 0; right: 0;
        display: none;
        background: var(--bg-card);
        border-bottom: 1px solid var(--border);
        box-shadow: 0 12px 24px rgba(0, 0, 0, .12);
        padding: 4px 0;
        z-index: 60;
    }
    .js .main-nav.open { display: block; }
    .js .main-nav a {
        display: flex; align-items: center;
        min-height: 46px; margin: 0; padding: 12px 20px;
        font-size: 15px;
        border-bottom: 1px solid var(--border);
    }
    .js .main-nav a:last-child { border-bottom: none; }
    .js .main-nav a:active { background: var(--accent-soft); }
    .js .main-nav a.active { background: var(--accent-soft); }

    /* 文章卡片 */
    .post-card { padding: 14px 16px; margin-bottom: 12px; }
    .post-title { font-size: 17px; }
    .post-summary { line-height: 1.65; }

    /* 文章详情与评论区 */
    .article-detail { padding: 16px 14px; }
    .article-title { font-size: 22px; }
    .comment-section { padding: 16px 14px; margin-top: 12px; }
    .section-title { font-size: 17px; margin-bottom: 12px; }
    .comment-child { margin-left: 14px; padding-left: 10px; }
    .form-field { min-width: 100%; }
    .btn-submit { width: 100%; padding: 12px 24px; }
    .like-btn { padding: 6px 14px; }
    .tag { margin: 2px 4px 2px 0; }

    /* 代码块与表格：iOS 惯性滚动 + 更紧凑的间距 */
    .markdown-body pre { padding: 10px; font-size: 13px; -webkit-overflow-scrolling: touch; }
    .markdown-body table { -webkit-overflow-scrolling: touch; }

    /* 侧栏组件：博主卡改为头像居左的横向紧凑布局 */
    .widget { padding: 12px 14px; margin-bottom: 12px; }
    .author-card { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; text-align: left; }
    .author-avatar { width: 48px; height: 48px; margin: 0; }
    .author-info { flex: 1; min-width: 0; }
    .author-name { font-size: 15px; }
    .author-desc { font-size: 12px; }
    .author-socials { width: 100%; justify-content: center; margin-top: 2px; }
    .author-socials a { padding: 8px; }
    .social-icon { width: 20px; height: 20px; }

    /* 归档与分页：放大翻页按钮触摸区 */
    .archive-group { padding: 14px 16px; margin-bottom: 12px; }
    .archive-list li { gap: 8px; }
    .archive-list time { flex-shrink: 0; }
    .pager { gap: 10px; padding: 12px 0; }
    .pager-btn { padding: 10px 18px; }

    /* 关于页与错误页 */
    .about-card { padding: 16px; }
    .error-page { padding: 48px 16px; margin-top: 12px; }
    .error-page h1 { font-size: 48px; }

    /* 搜索弹框：贴近顶部、占满可用宽度 */
    .search-modal { padding: 8vh 12px 0; }
    .search-results { max-height: 62vh; }
}

/* ---- 触屏设备：无真实 hover，去掉卡片位移/阴影悬停态 ---- */
@media (hover: none) {
    .post-card:hover, .link-card:hover { transform: none; box-shadow: none; }
}
