/* ------------------------------------
 * Default Theme - TOC / Reading Info / Progress
 * --------------------------------- */

/* ====================
 * 阅读信息（字数 + 阅读时间）
 * ================== */
.post-reading-info {
  margin: -0.5em 0 1.5em;
  padding: 0;
  color: #999;
  font-size: .92857em;
  list-style: none;
}
.post-reading-info li {
  display: inline-block;
  margin: 0 8px 0 0;
  padding-left: 12px;
  border-left: 1px solid #EEE;
}
.post-reading-info li:first-child {
  margin-left: 0;
  padding-left: 0;
  border: none;
}
.post-reading-info svg {
  width: 14px;
  height: 14px;
  margin-right: 4px;
  vertical-align: -2px;
  fill: currentColor;
}

/* ====================
 * 阅读进度条（顶部固定）
 * ================== */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.reading-progress.is-visible {
  opacity: 1;
}
.reading-progress-bar {
  height: 100%;
  width: 0%;
  background: #3354AA;
  border-radius: 0 2px 2px 0;
  transition: width 0.1s linear;
}

/* ====================
 * 文章目录 TOC（侧边栏模式）
 * ================== */
.widget-toc {
  margin-bottom: 30px;
}
.post-toc {
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  font-size: .92857em;
}
.post-toc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #EEE;
}
.post-toc-title {
  font-weight: bold;
  color: #444;
  font-size: 1em;
}
.post-toc-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: #999;
  cursor: pointer;
  border-radius: 2px;
  transition: transform 0.2s, background-color 0.2s;
}
.post-toc-toggle:hover {
  background: #EEE;
  color: #444;
}
.post-toc-toggle svg {
  width: 14px;
  height: 14px;
  transition: transform 0.3s ease;
}
.post-toc-toggle[aria-expanded="false"] svg {
  transform: rotate(-90deg);
}
.post-toc-toggle:focus {
  outline: 2px solid #3354AA;
  outline-offset: 1px;
}

/* TOC 列表：折叠/展开过渡动画 */
.post-toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 500px;
  overflow-y: auto;
  overflow-x: hidden;
  transition: max-height 0.35s ease, opacity 0.25s ease, margin 0.25s ease, padding 0.25s ease;
  opacity: 1;
}
.post-toc-list.is-collapsed {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  margin: 0;
  padding: 0;
}
.post-toc-list ol {
  list-style: none;
  margin: 0;
  padding-left: 14px;
}
.post-toc-item {
  margin: 2px 0;
  line-height: 1.5;
}
.post-toc-item a {
  display: block;
  overflow-wrap: anywhere;
  padding: 2px 6px;
  border: none !important;
  border-left: 2px solid transparent !important;
  color: #666;
  text-decoration: none;
  border-radius: 2px;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.post-toc-item a:hover {
  color: #3354AA;
  background: #F0F0F0;
}
.post-toc-item a:focus {
  outline: 2px solid #3354AA;
  outline-offset: 1px;
}
.post-toc-item a.is-active {
  color: #3354AA;
  font-weight: bold;
  border-left-color: #3354AA !important;
  background: #F0F4FF;
}
.post-toc-level-3 {
  padding-left: 14px;
}
.post-toc-level-4 {
  padding-left: 14px;
}

/* 无标题时的占位 */
.post-toc-empty {
  color: #999;
  font-size: .92857em;
  text-align: center;
  padding: 8px 0;
}

/* ====================
 * 桌面端：文章页 [TOC | 正文 | 侧栏] 三栏布局
 * ================== */
@media (min-width: 992px) {
  /* row 改为 flex 并等高拉伸，使 TOC 栏与正文栏等高，
     TOC 才能在整个文章高度范围内吸顶跟随 */
  .row:has(> #toc-column) {
    display: flex;
    align-items: stretch;
  }
  .row:has(> #toc-column)::before,
  .row:has(> #toc-column)::after {
    display: none;
  }
  #toc-column {
    flex: 0 0 auto;
    min-width: 260px;
    padding-top: 15px;
  }
  .row:has(> #toc-column) > #main {
    flex: 1 1 0;
    min-width: 0;
  }
  .row:has(> #toc-column) > #secondary {
    flex-shrink: 0;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  /* 吸顶模式（后台可切换为随页滚动） */
  #toc-column.toc-sticky .widget-toc {
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
  }
  #toc-column.toc-sticky .post-toc-list {
    max-height: calc(100vh - 120px);
  }
  #toc-column.toc-sticky .post-toc-list.is-collapsed {
    max-height: 0;
  }
}

/* ====================
 * 移动端 / 平板：单列堆叠，TOC 卡片位于文章上方
 * （DOM 顺序即 TOC 栏 → 正文 → 侧栏，无需 JS 搬移）
 * ================== */
@media (max-width: 991px) {
  #toc-column {
    margin-top: 20px;
  }
  #toc-column .widget-toc {
    margin-bottom: 20px;
    padding: 12px 16px;
    background: #F9F9F9;
    border: 1px solid #EEE;
    border-radius: 4px;
  }
  #toc-column .post-toc-list {
    max-height: 50vh;
  }
  #toc-column .post-toc-list.is-collapsed {
    max-height: 0;
  }
}

/* ====================
 * 暗色模式适配
 * ================== */
[data-theme="dark"] .post-reading-info {
  color: #888;
}
[data-theme="dark"] .post-reading-info li {
  border-left-color: #333;
}

[data-theme="dark"] .reading-progress-bar {
  background: #6e8de0;
}

[data-theme="dark"] .post-toc-header {
  border-bottom-color: #333;
}
[data-theme="dark"] .post-toc-title {
  color: #c9c9c9;
}
[data-theme="dark"] .post-toc-toggle {
  color: #888;
}
[data-theme="dark"] .post-toc-toggle:hover {
  background: #333;
  color: #c9c9c9;
}
[data-theme="dark"] .post-toc-item a {
  color: #999;
}
[data-theme="dark"] .post-toc-item a:hover {
  color: #6e8de0;
  background: #2a2a2a;
}
[data-theme="dark"] .post-toc-item a.is-active {
  color: #6e8de0;
  border-left-color: #6e8de0 !important;
  background: #1e2536;
}

@media (max-width: 991px) {
  [data-theme="dark"] #toc-column .widget-toc {
    background: #222;
    border-color: #333;
  }
}

/* 跟随系统暗色（未手动设置时） */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) .post-reading-info {
    color: #888;
  }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .post-reading-info li {
    border-left-color: #333;
  }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .reading-progress-bar {
    background: #6e8de0;
  }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .post-toc-header {
    border-bottom-color: #333;
  }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .post-toc-title {
    color: #c9c9c9;
  }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .post-toc-toggle {
    color: #888;
  }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .post-toc-toggle:hover {
    background: #333;
    color: #c9c9c9;
  }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .post-toc-item a {
    color: #999;
  }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .post-toc-item a:hover {
    color: #6e8de0;
    background: #2a2a2a;
  }
  :root:not([data-theme="light"]):not([data-theme="dark"]) .post-toc-item a.is-active {
    color: #6e8de0;
    border-left-color: #6e8de0 !important;
    background: #1e2536;
  }
  @media (max-width: 991px) {
    :root:not([data-theme="light"]):not([data-theme="dark"]) #toc-column .widget-toc {
      background: #222;
      border-color: #333;
    }
  }
}
