/* 技术博客样式 - 参考优秀博客布局 */
:root {
  --bg: #0f1419;
  --bg-card: #1a2332;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --border: #30363d;
  --code-bg: #161b22;
  --content-max: 720px;
  --page-max: 1200px;
  --sidebar-width: 220px;
  --spacing-x: clamp(1.5rem, 5vw, 3rem);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
}

/* 页面容器 - 两侧留白 */
.container {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--spacing-x);
}

/* 内容区 - 首页/博客列表用较窄宽度 */
.content-narrow {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--spacing-x);
}

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
}

.site-header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.site-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

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

.site-nav a {
  margin-left: 1.5rem;
  color: var(--text-muted);
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--accent);
}

/* Home */
.home {
  padding: 4rem 0 5rem;
}

.home .container,
.blog-index .container {
  max-width: var(--content-max);
}

.hero {
  text-align: center;
  margin-bottom: 4rem;
}

.hero h1 {
  font-size: 2.25rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
}

.tagline {
  color: var(--text-muted);
  font-size: 1.15rem;
}

.recent-posts h2 {
  font-size: 1.25rem;
  margin-bottom: 1.5rem;
  font-weight: 600;
}

.post-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.post-list li {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1.5rem;
}

.post-list li a {
  color: var(--text);
  text-decoration: none;
  flex: 1;
}

.post-list li a:hover {
  color: var(--accent);
}

.post-date {
  color: var(--text-muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.view-all {
  display: inline-block;
  margin-top: 2rem;
  color: var(--accent);
  text-decoration: none;
}

.view-all:hover {
  color: var(--accent-hover);
}

/* Blog index */
.blog-index {
  padding: 4rem 0 5rem;
}

.blog-index .container {
  max-width: var(--content-max);
}

.blog-index h1 {
  font-size: 1.75rem;
  margin-bottom: 2.5rem;
  font-weight: 700;
}

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

.post-item a {
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
}

.post-item a:hover {
  color: var(--accent);
}

.post-item .post-meta {
  margin-top: 0.5rem;
}

.post-item .post-meta time {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.post-item .excerpt {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* ========== 文章页 - 带 TOC 侧边栏 ========== */
.post-with-sidebar {
  padding: 2rem 0 5rem;
}

.post-layout {
  display: flex;
  gap: 3rem;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--spacing-x);
  align-items: flex-start;
}

.post-toc-wrap {
  flex-shrink: 0;
  width: var(--sidebar-width);
  position: sticky;
  top: 2rem;
}

.post-toc {
  padding: 1rem 0;
  border-right: 1px solid var(--border);
  padding-right: 1.5rem;
}

.toc-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-item {
  margin-bottom: 0.25rem;
}

.toc-item.toc-level-3 {
  margin-left: 0.75rem;
}

.toc-link {
  display: block;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.2rem 0;
  border-left: 2px solid transparent;
  padding-left: 0.5rem;
  margin-left: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.toc-link:hover {
  color: var(--accent);
}

.toc-link.active {
  color: var(--accent);
  border-left-color: var(--accent);
}

.toc-sublist {
  list-style: none;
  padding: 0.25rem 0 0;
  margin: 0;
}

.post-main {
  flex: 1;
  min-width: 0;
  max-width: var(--content-max);
}

.post-header {
  margin-bottom: 2.5rem;
}

.post-title {
  font-size: 1.9rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
  line-height: 1.3;
}

.post-meta {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.post-tag, .post-category {
  color: var(--text-muted);
  text-decoration: none;
  margin-right: 0.25rem;
}

.post-tag:hover, .post-category:hover {
  color: var(--accent);
}

.post-tag::before {
  content: "#";
  opacity: 0.7;
}

.post-content {
  font-size: 1.05rem;
}

.post-content h2 {
  font-size: 1.4rem;
  margin: 2.5rem 0 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  scroll-margin-top: 1rem;
}

.post-content h2:first-child {
  margin-top: 0;
}

.post-content h3 {
  font-size: 1.15rem;
  margin: 1.75rem 0 0.75rem;
  font-weight: 600;
  scroll-margin-top: 1rem;
}

.post-content p {
  margin: 0 0 1.25rem;
}

.post-content ul, .post-content ol {
  margin: 0 0 1.25rem;
  padding-left: 1.5rem;
}

.post-content li {
  margin-bottom: 0.35rem;
}

.post-content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  overflow-x: auto;
  margin: 1.25rem 0;
}

.post-content code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9em;
}

.post-content pre code {
  background: none;
  padding: 0;
}

.post-content :not(pre) > code {
  background: var(--code-bg);
  padding: 0.2em 0.45em;
  border-radius: 4px;
}

.post-content blockquote {
  margin: 1.25rem 0;
  padding: 0.75rem 1.25rem;
  border-left: 4px solid var(--accent);
  background: var(--bg-card);
  color: var(--text-muted);
  border-radius: 0 6px 6px 0;
}

/* 正文图片：不超出栏宽、保持比例、不超过原图尺寸；点击放大 */
.post-content img.post-zoomable,
.post-content a.post-content-img-wrap img {
  max-width: 100%;
  width: auto;
  height: auto;
  vertical-align: middle;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--code-bg);
  cursor: zoom-in;
  display: block;
  margin: 1rem auto;
  box-sizing: border-box;
}

.post-content a.post-content-img-wrap {
  display: table;
  max-width: 100%;
  margin: 1rem auto;
  text-decoration: none;
  border-radius: 6px;
}

.post-content a.post-content-img-wrap:hover img {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

/* 图片灯箱 */
.img-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1rem 1rem;
  background: rgba(0, 0, 0, 0.88);
  cursor: zoom-out;
  animation: img-lightbox-in 0.2s ease-out;
}

@keyframes img-lightbox-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.img-lightbox[hidden] {
  display: none !important;
}

.img-lightbox .img-lightbox-img {
  max-width: 96vw;
  max-height: 92vh;
  width: auto;
  height: auto;
  object-fit: contain;
  cursor: default;
  border-radius: 4px;
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.5);
}

.img-lightbox-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
}

.img-lightbox-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

.img-lightbox-hint {
  position: absolute;
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.65);
  pointer-events: none;
}

.post-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
}

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

.post-content th {
  background: var(--bg-card);
  font-weight: 600;
}

.post-footer {
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.post-footer a {
  color: var(--accent);
  text-decoration: none;
}

.post-footer a:hover {
  color: var(--accent-hover);
}

/* 大屏适配 - 2K/4K 显示器拓宽内容区 */
@media (min-width: 1920px) {
  :root {
    --content-max: 900px;
    --page-max: 1600px;
    --sidebar-width: 280px;
  }
}

@media (min-width: 2560px) {
  :root {
    --content-max: 1100px;
    --page-max: 2000px;
    --sidebar-width: 320px;
  }
}

/* 响应式 - 小屏隐藏 TOC 侧边栏 */
@media (max-width: 1024px) {
  .post-layout {
    flex-direction: column;
    gap: 2rem;
  }

  .post-toc-wrap {
    width: 100%;
    position: static;
    order: -1;
  }

  .post-toc {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0;
    padding-bottom: 1.5rem;
  }

  .toc-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
  }

  .toc-item.toc-level-3 {
    margin-left: 0;
  }

  .toc-link {
    border-left: none;
    padding-left: 0;
    margin-left: 0;
  }

  .toc-sublist {
    display: contents;
  }

  .toc-sublist .toc-item {
    margin-left: 0;
  }
}

@media (max-width: 640px) {
  :root {
    --spacing-x: 1.25rem;
  }

  .hero h1 {
    font-size: 1.75rem;
  }

  .post-title {
    font-size: 1.5rem;
  }

  .post-list li {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
}

/* 标签 / 分类归档页 */
.archive-page .container,
.search-page .container {
  max-width: var(--content-max);
}

.archive-page, .search-page {
  padding: 4rem 0 5rem;
}

.archive-page h1, .search-page h1 {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
}

.page-desc {
  color: var(--text-muted);
  margin-bottom: 2.5rem;
}

.archive-section {
  margin-bottom: 2.5rem;
}

.archive-title {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  font-weight: 600;
}

.archive-name {
  color: var(--text);
}

.archive-count {
  color: var(--text-muted);
  font-weight: 400;
}

.empty-state {
  color: var(--text-muted);
}

/* 搜索页 */
.search-box-wrap {
  margin-bottom: 2rem;
}

.search-input {
  width: 100%;
  max-width: 480px;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

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

.search-result-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.search-result-item {
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
}

.search-result-item a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

.search-result-item a:hover {
  color: var(--accent);
}

.search-result-date {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-left: 0.5rem;
}

.search-result-excerpt {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.search-empty {
  color: var(--text-muted);
  padding: 2rem 0;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  margin-top: 3rem;
}

.site-footer p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

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

/* ========== Rouge 语法高亮 - 深色主题 ========== */
/* 基于 GitHub Dark / One Dark 配色，确保深色背景下关键字清晰可辨 */

.highlight { background: var(--code-bg); border-radius: 8px; }

/* 注释 - 灰绿色 */
.highlight .c,
.highlight .c1,
.highlight .cm,
.highlight .cs,
.highlight .cp  { color: #6a9955; font-style: italic; }

/* 关键字 - 蓝紫色 */
.highlight .k,
.highlight .kd,
.highlight .kn,
.highlight .kp,
.highlight .kr,
.highlight .kt,
.highlight .kc  { color: #c586c0; font-weight: 600; }

/* 字符串 - 橙黄色 */
.highlight .s,
.highlight .s1,
.highlight .s2,
.highlight .sb,
.highlight .sc,
.highlight .sd,
.highlight .sh,
.highlight .si,
.highlight .sx  { color: #ce9178; }

/* 数字 / 字面量 - 浅绿色 */
.highlight .m,
.highlight .mi,
.highlight .mf,
.highlight .mh,
.highlight .mo,
.highlight .il,
.highlight .mb  { color: #b5cea8; }

/* 函数名 / 方法名 - 黄色 */
.highlight .nf,
.highlight .fm  { color: #dcdcaa; }

/* 类名 / 类型名 - 青绿色 */
.highlight .nc,
.highlight .nn  { color: #4ec9b0; }

/* 变量名 / 普通标识符 */
.highlight .n,
.highlight .na,
.highlight .nb,
.highlight .nl  { color: #9cdcfe; }

/* 操作符 - 白色 */
.highlight .o,
.highlight .ow  { color: #d4d4d4; }

/* 内置 / 特殊名称 - 浅蓝 */
.highlight .bp  { color: #569cd6; }

/* 装饰器 / 注解 - 黄绿 */
.highlight .nd  { color: #c8c862; }

/* 错误 */
.highlight .err { color: #f44747; background: none; }

/* 通用文本 */
.highlight .p,
.highlight .nt,
.highlight .nv,
.highlight .nx  { color: #d4d4d4; }

/* 属性名 (HTML/XML/YAML) - 浅蓝 */
.highlight .na  { color: #9cdcfe; }

/* 标签 (HTML) - 蓝色 */
.highlight .nt  { color: #569cd6; }

/* 字符串插值符号 */
.highlight .se  { color: #d7ba7d; }

/* YAML key */
.highlight .l-Scalar-Plain { color: #9cdcfe; }
