/* ========== 文章页面专属样式 ========== */

.article-transition-wrapper {
  min-height: calc(100vh - 80px);
  padding-top: 100px; /* 留出 navbar 的空间 */
  padding-bottom: 50px;
}

.article-page-container {
  display: flex;
  max-width: 1800px; 
  width: 95%;
  margin: 0 auto;
  padding: 0 1rem;
  gap: 3rem;
  align-items: flex-start;
  /* 防止子元素撑出页面 */
  max-width: 100%;
  box-sizing: border-box;
}

/* 左侧主要文章内容区 */
.article-content-wrapper {
  flex: 1;
  min-width: 0; /* 防止子元素溢出撑破 flex */
  max-width: 100%; /* 防止在移动端溢出 */
  padding: 3rem;
  overflow: hidden; /* 兜底裁切任何可能溢出的子元素 */
}

.article-header {
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--glass-border);
}

.article-headline {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.3;
  margin-top: 1rem;
  background: linear-gradient(135deg, var(--text-main), var(--primary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  width: fit-content;
  max-width: 100%;
  /* View Transition 性能优化：布局隔离 + GPU 合成提示 */
  contain: layout style;
  will-change: transform;
}

.article-meta {
  display: flex;
  gap: 1.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.article-meta span {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.article-meta .icon-svg {
  width: 1.1rem;
  height: 1.1rem;
}

.article-cover-wrap {
  position: absolute !important;
  top: 0;
  left: 0;
  width: 100%;
  height: 550px;
  z-index: 0 !important;
  overflow: hidden;
  margin-bottom: 0;
  box-shadow: none;
  pointer-events: none;
  border-radius: 24px 24px 0 0;
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,0.8) 40%, rgba(0,0,0,0) 100%);
  mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,0.8) 40%, rgba(0,0,0,0) 100%);
  /* View Transition 性能优化 */
  contain: strict;
  will-change: transform;
}

.article-hero-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0.55;
  transition: transform 0.8s ease-out;
}

.article-hero-image:hover {
  transform: scale(1.02);
}

.article-body {
  font-size: var(--article-font-size, 1.1rem);
  font-weight: var(--article-font-weight, 400);
  line-height: 1.8;
  color: var(--text-main);
  transition: font-size 0.3s, font-weight 0.3s;
  /* 防止长链接/长单词撑出容器（手机端溢出的元凶） */
  overflow-wrap: break-word;
  word-break: break-word;
  /* 确保不会超出父容器 */
  max-width: 100%;
  overflow-x: hidden;
}

.article-body p {
  margin-bottom: 1.5rem;
  font-weight: inherit;
}

.article-body h2 {
  font-size: 1.8rem;
  font-weight: 700;
  margin: 2.5rem 0 1.5rem;
  color: var(--text-main);
  position: relative;
  padding-left: 1rem;
}

.article-body h2::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 70%;
  background: var(--primary);
  border-radius: 2px;
  box-shadow: 0 0 10px var(--primary-glow);
}

/* 代码块 (pre) - 跟随主题模式，语法高亮由 highlight.js 负责 */
.article-body pre {
  padding: 1.5rem !important;
  border-radius: 12px !important;
  overflow-x: auto !important;
  margin: 1.5rem 0 !important;
  font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace !important;
  transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease !important;
  /* 防止代码块撑出容器 */
  max-width: 100% !important;
  box-sizing: border-box !important;
}

.article-body pre code {
  background: transparent !important;
  padding: 0 !important;
  border-radius: 0 !important;
  font-size: 0.95em !important;
  word-break: normal !important;
  text-shadow: none !important;
  font-weight: normal !important;
}

/* highlight.js 的 .hljs 类会附带背景色，保持圆角和间距一致 */
.article-body pre code.hljs {
  padding: 1.5rem !important;
  border-radius: 12px !important;
}

/* 行内代码 (code) */
.article-body p code,
.article-body li code,
.article-body table code {
  color: var(--primary);
  background: rgba(236, 72, 153, 0.1);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
  word-break: break-word;
}

/* 标题 (h1, h3-h6) */
.article-body h1, .article-body h3, 
.article-body h4, .article-body h5, .article-body h6 {
  color: var(--text-main);
  font-weight: 700;
  line-height: 1.4;
  margin: 2rem 0 1rem;
}
.article-body h1 { font-size: 2.2rem; }
.article-body h3 { font-size: 1.5rem; position: relative; padding-left: 0.8rem; }
.article-body h3::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--secondary);
  border-radius: 2px;
}
.article-body h4 { font-size: 1.3rem; }
.article-body h5 { font-size: 1.1rem; }
.article-body h6 { font-size: 1rem; color: var(--text-muted); }

/* 引用 (blockquote) */
.article-body blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.5rem;
  border-left: 4px solid var(--secondary);
  background: rgba(14, 165, 233, 0.08);
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
  font-style: italic;
  position: relative;
  box-shadow: inset 0 0 20px rgba(14, 165, 233, 0.02);
}
.article-body blockquote p:last-child {
  margin-bottom: 0;
}

/* 强调与加粗 (strong, em) */
.article-body strong, .article-body b, .article-body code {
  font-weight: 700;
}
.article-body strong, .article-body b {
  color: var(--primary);
}
.article-body em, .article-body i {
  font-style: italic;
  color: var(--secondary);
}
.article-body del, .article-body s {
  text-decoration: line-through;
  opacity: 0.6;
}

/* 链接 (a) */
.article-body a {
  color: var(--primary);
  text-decoration: none;
  border-bottom: 1px dashed var(--primary);
  transition: all 0.3s ease;
  padding-bottom: 1px;
}
.article-body a:hover {
  color: var(--secondary);
  border-bottom-color: var(--secondary);
  text-shadow: 0 0 8px var(--secondary-glow);
}

/* 图片 (img) */
.article-body img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  display: block;
  margin: 1.5rem auto;
  box-shadow: var(--glass-shadow);
  border: 1px solid var(--glass-border);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.article-body img:hover {
  transform: scale(1.02);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

/* 表格 (table) - 使用滚动容器防移动端溢出 */
.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  overflow-x: auto;
  display: block;
  max-width: 100%;
  -webkit-overflow-scrolling: touch; /* iOS 滚动优化 */
}
.article-body th, .article-body td {
  padding: 0.8rem 1.2rem;
  border: 1px solid var(--glass-border);
}
.article-body th {
  background: rgba(255, 255, 255, 0.08);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.9rem;
  color: var(--text-main);
}
.light-mode .article-body th {
  background: rgba(0, 0, 0, 0.05);
}
.article-body tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}
.light-mode .article-body tr:nth-child(even) {
  background: rgba(0, 0, 0, 0.02);
}
.article-body tr:hover {
  background: rgba(255, 255, 255, 0.05);
}
.light-mode .article-body tr:hover {
  background: rgba(0, 0, 0, 0.04);
}

/* 分割线 (hr) */
.article-body hr {
  border: none;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--glass-border), transparent);
  margin: 2.5rem 0;
}

/* 列表 (ul, ol) */
.article-body ul {
  padding-left: 0;
  margin-bottom: 1.5rem;
  list-style: none;
}
.article-body ul li {
  margin-bottom: 0.8rem;
  position: relative;
  padding-left: 1.5rem;
}
.article-body ul li::before {
  content: '';
  position: absolute;
  left: 0.3rem;
  top: 0.6rem;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--secondary);
  box-shadow: 0 0 8px var(--secondary-glow);
}

.article-body ol {
  padding-left: 1.5rem;
  margin-bottom: 1.5rem;
}
.article-body ol li {
  margin-bottom: 0.8rem;
  padding-left: 0.5rem;
}
.article-body ol li::marker {
  color: var(--primary);
  font-weight: 600;
}

/* 键盘和标记 (kbd, mark) */
.article-body kbd {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.85em;
  font-family: monospace;
  border: 1px solid var(--glass-border);
  box-shadow: 0 2px 0 var(--glass-border);
}
.light-mode .article-body kbd {
  background: rgba(0, 0, 0, 0.05);
  box-shadow: 0 2px 0 rgba(0,0,0,0.1);
}
.article-body mark {
  background: rgba(236, 72, 153, 0.3);
  color: var(--text-main);
  padding: 0.1rem 0.3rem;
  border-radius: 2px;
}

/* 右侧目录栏 */
.article-sidebar {
  width: 280px;
  flex-shrink: 0;
  position: sticky;
  top: 100px; /* 吸顶距离 */
}

.article-toc {
  padding: 1.5rem;
}

.toc-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
}

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

.toc-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.95rem;
  transition: all 0.3s;
  display: block;
  padding-left: 10px;
  border-left: 2px solid transparent;
}

.toc-link:hover, .toc-link.active {
  color: var(--primary);
  border-left-color: var(--primary);
  text-shadow: 0 0 10px var(--primary-glow);
  transform: scale(1.05); /* 选中的文字放大效果 */
  transform-origin: left center;
}

.toc-sublist {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding-left: 1.2rem;
  margin-top: 0;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.4s ease, opacity 0.4s ease, margin-top 0.4s ease;
}

.toc-sublist .toc-link {
  font-size: 0.88rem;
}

/* JS 添加的类，立即展开 */
.toc-sublist.expanded {
  max-height: 1000px;
  opacity: 1;
  margin-top: 0.8rem;
  transition-delay: 0s;
}

/* 鼠标悬停对应的父节点时，延迟 0.5 秒自动展开次级目录 */
.toc-list li:hover > .toc-sublist:not(.expanded) {
  max-height: 1000px;
  opacity: 1;
  margin-top: 0.8rem;
  transition-delay: 0.5s;
}

/* ========== 上一篇/下一篇 导航 ========== */
.article-nav-links {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--glass-border);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap; /* 手机端允许换行 */
}

.article-nav-prev,
.article-nav-next {
  padding: 8px 16px;
  font-size: 0.9rem;
  max-width: 48%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0; /* 防止flex子项溢出 */
}

.article-nav-next {
  text-align: right;
  margin-left: auto; /* 没有上一篇时靠右 */
}

@media (max-width: 480px) {
  .article-nav-prev,
  .article-nav-next {
    max-width: 100%;
    flex: 1 1 100%; /* 手机上各占一行 */
    text-align: center;
  }
  .article-nav-next {
    margin-left: 0;
  }
}

/* 响应式调整 */
@media (max-width: 992px) {
  .article-page-container {
    flex-direction: column;
    padding: 0 0.8rem;
    width: 100%;
    max-width: 100%;
  }
  .article-sidebar {
    width: 100%;
    position: static;
    order: -1; /* 将目录放到前面方便移动端查看 */
    margin-bottom: 2rem;
  }
  .article-content-wrapper {
    max-width: 100%;
    box-sizing: border-box;
  }
}

@media (max-width: 768px) {
  .article-transition-wrapper {
    padding-top: 70px; /* 手机端 navbar 更矮 */
    padding-bottom: 30px;
  }
  .article-page-container {
    padding: 0 0.5rem;
    gap: 1.5rem;
  }
  .article-content-wrapper {
    padding: 1.2rem;
    border-radius: 18px; /* 缩小圆角适配小屏 */
  }
  .article-headline {
    font-size: 1.6rem;
    line-height: 1.35;
  }
  .article-meta {
    flex-wrap: wrap; /* 元信息自动换行 */
    gap: 0.8rem;
    font-size: 0.85rem;
  }
  .article-body {
    font-size: var(--article-font-size, 1rem);
    line-height: 1.75;
  }
  .article-body h2 {
    font-size: 1.4rem;
    margin: 2rem 0 1rem;
  }
  .article-body h3 {
    font-size: 1.2rem;
  }
  .article-body pre {
    padding: 1rem !important;
    border-radius: 8px !important;
    font-size: 0.85em !important;
  }
  .article-body pre code.hljs {
    padding: 1rem !important;
    border-radius: 8px !important;
  }
  .article-body img {
    border-radius: 8px;
    margin: 1rem auto;
  }
  .article-body blockquote {
    padding: 0.8rem 1rem;
    margin: 1rem 0;
  }
  /* 封面图适配 */
  .article-cover-wrap {
    height: 300px;
    border-radius: 18px 18px 0 0;
  }
  /* 目录在手机上更紧凑 */
  .article-toc {
    padding: 1rem;
  }
  .toc-title {
    font-size: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
  }
  .toc-link {
    font-size: 0.88rem;
  }
  .toc-list {
    gap: 0.5rem;
  }
}

/* 超小屏幕 (竖屏手机等) */
@media (max-width: 480px) {
  .article-page-container {
    padding: 0 0.3rem;
  }
  .article-content-wrapper {
    padding: 1rem 0.8rem;
    border-radius: 14px;
  }
  .article-headline {
    font-size: 1.35rem;
  }
  .article-body {
    font-size: var(--article-font-size, 0.95rem);
  }
  .article-body pre {
    padding: 0.8rem !important;
    font-size: 0.8em !important;
  }
  .article-cover-wrap {
    height: 220px;
  }
  /* 推荐文章网格在超小屏单列 */
  .recommend-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* ========== 猜你想看 (推荐文章) ========== */
.recommend-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

.recommend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.5rem;
}

.recommend-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  border-radius: 16px;
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  /* 允许卡片独立转场 */
  contain: layout style;
  /* 生成动画效果默认起始隐藏 */
  opacity: 0;
  animation: recommend-card-enter 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

@keyframes recommend-card-enter {
  0% {
    opacity: 0;
    transform: translateY(30px) scale(0.98);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* 使用 View Transition 的自定义属性，使得转场不被截断 (在 JS 中触发点击时赋值) */
.recommend-card:active,
.recommend-card:focus {
  outline: none;
}

.recommend-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  border-color: var(--primary);
}

.recommend-cover {
  width: 100%;
  height: 140px;
  overflow: hidden;
}

.recommend-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}

.recommend-card:hover .recommend-cover img {
  transform: scale(1.08); /* 悬停图片放大微动效 */
}

.recommend-info {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  flex: 1;
}

.recommend-info h4 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.4;
  /* 多行截断 */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.3s ease;
}

.recommend-card:hover .recommend-info h4 {
  color: var(--primary);
}

.recommend-meta {
  margin-top: auto;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.recommend-generating {
  animation: recommend-pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes recommend-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: .4;
  }
}

/* ========== 文章设置面板与全局护眼(暖色)模式 ========== */
/* 重载全局 CSS 变量，使得整个页面的主基调全方位平滑变暖 */
:root.article-warm-mode {
  --bg-color: #2b211a;
  --text-main: #e8d0b3;
  --text-muted: #dcc2a3;
  --primary: #d18f40;
  --secondary: #e8a86c;
  --primary-glow: rgba(209, 143, 64, 0.6);
  --secondary-glow: rgba(232, 168, 108, 0.6);
  
  --glass-bg: rgba(43, 33, 27, 0.6);
  --glass-bg-hover: rgba(43, 33, 27, 0.85);
  --glass-border: rgba(184, 134, 11, 0.3);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  
  --nav-bg: rgba(43, 33, 27, 0.85);
  --footer-bg: rgba(43, 33, 27, 0.9);
  
  --orb-1: rgba(184, 134, 11, 0.15);
  --orb-2: rgba(209, 143, 64, 0.15);
}

/* 取消文章标题特殊的花里胡哨线性渐变色填充，改用纯护眼暖色 */
:root.article-warm-mode .article-headline {
  background: none;
  -webkit-text-fill-color: var(--text-main);
  color: var(--text-main);
}

/* 强制指定阅读区域的链接与激活项高加亮显示 */
.article-warm-mode .article-body a {
  color: var(--secondary);
  border-bottom-color: var(--secondary);
}

.article-warm-mode .toc-link.active,
.article-warm-mode .toc-link:hover {
  color: var(--secondary) !important;
  border-left-color: var(--secondary) !important;
}

/* 暖色模式切换开关状态 */
#warm-mode-toggle:checked + .slider {
  background-color: var(--primary) !important;
}
#warm-mode-toggle:checked + .slider .slider-knob {
  transform: translateX(20px);
}
