/* ==========================================================================
   博客 UI：现代简约 · 扁平卡片 · 无 emoji
   纯色/渐变背景，CSS 变量驱动亮/暗双主题
   主题通过 <html data-theme="light|dark"> 切换
   ========================================================================== */

/* ---------- 主题变量 ---------- */
:root,
[data-theme="light"] {
  --page-bg-image: linear-gradient(160deg, #eef1f6 0%, #f7f8fb 100%);
  --text-strong: #111827;
  --text-body: #374151;
  --text-muted: #6b7280;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-soft: #eef2ff;
  --accent-soft-text: #4f46e5;
  --card-bg: #ffffff;
  --card-border: #eef0f3;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  --card-hover-shadow: 0 14px 32px rgba(0, 0, 0, 0.08);
  --sidebar-bg: #ffffff;
  --sidebar-border: #eef0f3;
  --widget-bg: #f8f9fb;
  --code-bg: #f6f8fa;
  --code-text: #24292f;
  --inline-code-bg: #eef2f7;
  --inline-code-text: #4338ca;
  --blockquote-bg: #f8f9fb;
  --divider: #eef0f3;
  --link-line: #c7d2fe;
  --btn-bg: #ffffff;
  --btn-border: #e5e7eb;
  --hover-bg: #f8f8ff;
}

[data-theme="dark"] {
  --page-bg-image: linear-gradient(160deg, #0d1117 0%, #161b22 100%);
  --text-strong: #f3f4f6;
  --text-body: #d1d5db;
  --text-muted: #9ca3af;
  --accent: #818cf8;
  --accent-strong: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, 0.16);
  --accent-soft-text: #a5b4fc;
  --card-bg: #161b22;
  --card-border: #21262d;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --card-hover-shadow: 0 14px 32px rgba(0, 0, 0, 0.5);
  --sidebar-bg: #161b22;
  --sidebar-border: #21262d;
  --widget-bg: #1f242c;
  --code-bg: #0d1117;
  --code-text: #e6edf3;
  --inline-code-bg: rgba(129, 140, 248, 0.16);
  --inline-code-text: #a5b4fc;
  --blockquote-bg: #1f242c;
  --divider: #21262d;
  --link-line: rgba(129, 140, 248, 0.5);
  --btn-bg: #1f242c;
  --btn-border: #30363d;
  --hover-bg: #21262d;
}

/* ---------- 基础 ---------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, "Helvetica Neue", Arial,
    sans-serif;
  color: var(--text-body);
  line-height: 1.75;
  min-height: 100vh;
  background-image: var(--page-bg-image);
  background-attachment: fixed;
  transition: background 0.3s ease, color 0.3s ease;
}

a {
  text-decoration: none;
  color: inherit;
}

/* ==========================================================================
   侧边栏
   ========================================================================== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 40px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  z-index: 100;
  transition: background 0.3s ease;
}

.avatar img {
  width: 116px;
  height: 116px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--card-border);
  margin-bottom: 18px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.user-name {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-strong);
  margin-bottom: 6px;
}

.user-sig {
  font-size: 13.5px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 26px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--divider);
  width: 100%;
}

/* 主题切换按钮（固定在页面右上角） */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 24px;
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  color: var(--text-body);
  border-radius: 30px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--card-shadow);
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.theme-toggle:hover {
  background: var(--hover-bg);
  border-color: var(--accent);
  color: var(--accent);
}

/* ==========================================================================
   主内容区
   ========================================================================== */
.main-content {
  margin-left: 280px;
  padding: 48px 56px 72px;
  max-width: 1080px;
}

/* 宽屏时主内容在剩余空间居中 */
@media (min-width: 1400px) {
  .main-content {
    margin-left: calc(280px + (100vw - 280px - 1080px) / 2);
  }
}

.page-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-strong);
  margin-bottom: 30px;
}

/* 筛选行：标签下拉框 + 清空 */
.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

/* 标签下拉框 */
.tag-select {
  position: relative;
  flex: 1;
  min-width: 0;
}

.tag-select-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  color: var(--text-body);
  background: var(--widget-bg);
  border: 1px solid var(--btn-border);
  border-radius: 9px;
  cursor: pointer;
  transition: border-color 0.18s, color 0.18s;
}

.tag-select-trigger:hover,
.tag-select.open .tag-select-trigger {
  border-color: var(--accent);
  color: var(--accent);
}

/* 触发器上的标签预览 */
.tag-select-preview {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.tag-preview-chip {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--widget-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 1px 10px;
  white-space: nowrap;
}

.tag-preview-more {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.tag-select-count {
  min-width: 20px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-soft-text);
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 1px 6px;
}

.tag-select-caret {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0.7;
  transition: transform 0.18s;
}

.tag-select.open .tag-select-caret {
  transform: rotate(180deg);
}

/* 下拉面板：与触发器同宽，内分「文章类型」「标签」两组平铺开关 */
.tag-select-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 100%;
  z-index: 60;
  max-height: 320px;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  box-shadow: var(--card-hover-shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  pointer-events: none;
}

.tag-select.open .tag-select-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.filter-group-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.filter-group-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-chip {
  padding: 6px 16px;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--widget-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  cursor: pointer;
  transition: color 0.18s, border-color 0.18s, background 0.18s;
}

.tag-chip:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.tag-chip.active {
  background: var(--accent-soft);
  color: var(--accent-soft-text);
  border-color: var(--accent);
  font-weight: 600;
}

/* 清空筛选按钮 */
.filter-clear {
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
  transition: color 0.18s, border-color 0.18s;
}

.filter-clear:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* 筛选器 */
.filter-bar {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 18px 20px;
  margin-bottom: 24px;
  box-shadow: var(--card-shadow);
}

.search-input {
  width: 100%;
  padding: 11px 16px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text-body);
  background: var(--widget-bg);
  border: 1px solid var(--btn-border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
}

/* 分页 */
.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 30px;
}

.pagination-info {
  flex: 0 0 100%;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.3px;
  margin-bottom: 6px;
}

.page-btn {
  min-width: 38px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-body);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
}

.page-btn:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
}

.page-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 600;
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-ellipsis {
  padding: 0 2px;
  color: var(--text-muted);
}

/* 文章卡片内联标签 */
.article-tags {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-inline {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--widget-bg);
  border: 1px solid var(--card-border);
  padding: 1px 9px;
  border-radius: 20px;
}

/* 文章卡片 */
.article-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  padding: 26px 30px;
  margin-bottom: 18px;
  border-radius: 14px;
  box-shadow: var(--card-shadow);
  transition: transform 0.18s, box-shadow 0.18s, background 0.3s ease;
  cursor: pointer;
}

.article-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--card-hover-shadow);
}

.article-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-strong);
}

.article-meta {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.article-meta .category {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-soft-text);
  padding: 1px 10px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 12px;
}

.article-excerpt {
  color: var(--text-body);
  font-size: 14.5px;
  line-height: 1.6;
}

/* 文章页布局：正文 + 右侧目录 */
.article-page {
  max-width: 1160px;
}

.article-wrap {
  display: flex;
  align-items: flex-start;
  gap: 36px;
}

.article-main {
  flex: 1;
  min-width: 0;
}

/* 右侧目录 */
.toc {
  position: sticky;
  top: 24px;
  flex-shrink: 0;
  width: 236px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 16px 14px;
  box-shadow: var(--card-shadow);
}

.toc-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-strong);
  padding: 0 6px 10px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--divider);
  letter-spacing: 0.5px;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
}

.toc-item {
  margin: 1px 0;
}

.toc-item a {
  display: block;
  padding: 5px 8px;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  border-radius: 0 6px 6px 0;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  overflow-wrap: break-word;
}

.toc-item a:hover {
  color: var(--accent);
  background: var(--hover-bg);
}

.toc-item.active > a {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

/* 目录层级缩进 */
.toc-item.level-h2 a { padding-left: 18px; }
.toc-item.level-h3 a { padding-left: 30px; font-size: 13px; }

/* 标题锚点定位时留出顶部空间 */
.article-body h1[id],
.article-body h2[id],
.article-body h3[id],
.article-body h4[id] {
  scroll-margin-top: 20px;
}

/* ==========================================================================
   文章阅读页
   ========================================================================== */
.back-home {
  display: inline-block;
  margin-bottom: 20px;
  color: var(--accent);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  padding: 6px 16px;
  border-radius: 30px;
  font-size: 13.5px;
  font-weight: 500;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.back-home:hover {
  background: var(--hover-bg);
  border-color: var(--link-line);
}

.article-header {
  margin-bottom: 28px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--divider);
}

.article-header h1 {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
  color: var(--text-strong);
}

.article-header .sub-info {
  color: var(--text-muted);
  font-size: 14px;
}

/* 正文卡片 */
.article-body {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 36px 40px;
  font-size: 16px;
  color: var(--text-body);
  line-height: 1.85;
  box-shadow: var(--card-shadow);
  overflow-wrap: break-word;
  transition: background 0.3s ease;
}

.article-body h1,
.article-body h2,
.article-body h3,
.article-body h4 {
  color: var(--text-strong);
  font-weight: 700;
  line-height: 1.4;
  margin: 28px 0 14px;
}

.article-body h1 { font-size: 26px; }
.article-body h2 { font-size: 22px; }
.article-body h3 { font-size: 18px; }
.article-body h4 { font-size: 16px; }

.article-body p {
  margin-bottom: 18px;
  color: var(--text-body);
}

.article-body a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--link-line);
  transition: color 0.15s;
}
.article-body a:hover {
  color: var(--accent-strong);
}

.article-body ul,
.article-body ol {
  padding-left: 26px;
  margin-bottom: 18px;
  color: var(--text-body);
}

.article-body li {
  margin-bottom: 4px;
}

.article-body blockquote {
  border-left: 4px solid var(--accent);
  padding: 12px 20px;
  margin: 0 0 18px;
  color: var(--text-body);
  background: var(--blockquote-bg);
  border-radius: 0 8px 8px 0;
}

/* 行内代码 */
.article-body code {
  font-family: "SF Mono", "Consolas", "Menlo", monospace;
  font-size: 0.9em;
  background: var(--inline-code-bg);
  color: var(--inline-code-text);
  padding: 2px 6px;
  border-radius: 4px;
}

/* 代码块（highlight.js 主题由 JS 按主题切换） */
.article-body pre {
  background: var(--code-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 18px 20px;
  overflow-x: auto;
  margin-bottom: 20px;
  line-height: 1.6;
  tab-size: 4;
  -moz-tab-size: 4;
}

.article-body pre code {
  background: transparent;
  color: var(--code-text);
  padding: 0;
  font-size: 13.5px;
  line-height: 1.6;
}

.article-body pre::-webkit-scrollbar { height: 6px; }
.article-body pre::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; opacity: 0.4; }
.article-body pre::-webkit-scrollbar-track { background: transparent; }

/* 图片 */
.article-body img {
  max-width: 100%;
  border-radius: 10px;
  display: block;
  margin: 20px auto;
}

.article-body hr {
  border: none;
  border-top: 1px solid var(--divider);
  margin: 26px 0;
}

.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 14.5px;
}
.article-body th,
.article-body td {
  border: 1px solid var(--card-border);
  padding: 8px 12px;
  text-align: left;
}
.article-body th {
  background: var(--blockquote-bg);
  color: var(--text-strong);
  font-weight: 600;
}

/* KaTeX 公式：跟随主题文字颜色 */
.article-body .katex {
  color: var(--text-strong);
}

/* ==========================================================================
   响应式
   ========================================================================== */
@media (max-width: 900px) {
  .main-content {
    margin-left: 0;
    padding: 28px 20px 56px;
  }
  .article-body {
    padding: 26px 22px;
  }
  .article-wrap {
    display: block;
  }
  .toc {
    display: none; /* 窄屏隐藏目录，避免挤压正文 */
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: relative;
    width: 100%;
    height: auto;
    padding: 24px;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    border-right: none;
    border-bottom: 1px solid var(--sidebar-border);
  }
  .avatar img {
    width: 72px;
    height: 72px;
    margin-bottom: 0;
  }
  .user-name {
    font-size: 19px;
    margin-bottom: 0;
  }
  .user-sig {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
    width: auto;
  }
  .article-header h1 {
    font-size: 24px;
  }
  .theme-toggle {
    top: 12px;
    right: 12px;
  }
}

/* ==========================================================================
   Live2D（侧边栏底部，原时钟/主题按钮位置）
   ========================================================================== */
#live2d-container {
  flex: 1 1 auto; /* 填满侧边栏剩余高度，角色尽量大且不产生滚动 */
  min-height: 0;
  width: 100%;
  pointer-events: auto;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

#live2d-container canvas {
  width: 100%;
  height: 100%;
  display: block;
}

@media (max-width: 768px) {
  #live2d-container {
    flex: 1 1 100%;
    height: 300px;
    margin-top: 12px;
  }
}
