/* TOC sheet button + bottom drawer */
#toc-sheet-button {
  display: none !important;
  bottom: 4.5rem;
}

body.has-toc-sheet-button #toc-sheet-button {
  display: block !important;
}

/* 宽屏右侧 #toc-auto 已显示时，隐藏右下角目录按钮，避免重复入口 */
@media only screen and (min-width: 1001px) {
  body.has-toc-sheet-button #toc-sheet-button {
    display: none !important;
  }

  body.has-toc-sheet-button #view-comments {
    bottom: 4.5rem;
  }
}

.toc-sheet {
  position: fixed;
  inset: 0;
  z-index: 220;
  pointer-events: none;
}

.toc-sheet.is-open {
  pointer-events: auto;
}

.toc-sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.toc-sheet.is-open .toc-sheet__backdrop {
  opacity: 1;
}

.toc-sheet__panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  background: #f8f8f8;
  border-radius: 1rem 1rem 0 0;
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.18);
  transform: translateY(105%);
  transition: transform 0.28s ease;
  overflow: hidden;
}

[theme="dark"] .toc-sheet__panel {
  background: #252627;
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.45);
}

.toc-sheet.is-open .toc-sheet__panel {
  transform: translateY(0);
}

.toc-sheet__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1rem 0.7rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}

[theme="dark"] .toc-sheet__header {
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.toc-sheet__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}

.toc-sheet__hint {
  margin-left: 0.15em;
  font-size: 0.875rem;
  font-weight: 400;
  color: #8f8f8f;
}

[theme="dark"] .toc-sheet__hint {
  color: #8f8f8f;
}

.toc-sheet__close {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  width: 2rem;
  height: 2rem;
  border-radius: 0.25rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.toc-sheet__close:hover {
  background: rgba(0, 0, 0, 0.06);
}

[theme="dark"] .toc-sheet__close:hover {
  background: rgba(255, 255, 255, 0.08);
}

.toc-sheet__body {
  padding: 0.75rem 1rem 1.25rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.toc-sheet__body nav > ul {
  margin: 0;
  padding-left: 0.25rem;
  list-style: none;
}

/* 一级标题之间约 0.5 行间距 */
.toc-sheet__body nav > ul > li:not(:last-child) {
  margin-bottom: 0.7em;
  margin-bottom: 0.5lh;
}

.toc-sheet__body ul {
  list-style: none;
  padding-left: 1rem;
  margin: 0.15rem 0;
}

.toc-sheet__body a {
  display: block;
  padding: 0.4rem 0.25rem;
  text-decoration: none;
  color: inherit;
  border-radius: 0.25rem;
  line-height: 1.4;
}

/* 一级目录加粗 */
.toc-sheet__body nav > ul > li > a {
  font-weight: 700;
}

/* 三级目录使用中性灰，不影响二级 */
.toc-sheet__body nav > ul > li > ul > li > ul > li > a {
  color: #8f8f8f;
}

[theme="dark"] .toc-sheet__body nav > ul > li > ul > li > ul > li > a {
  color: #8f8f8f;
}

.toc-sheet__body a:hover {
  background: rgba(0, 0, 0, 0.05);
}

[theme="dark"] .toc-sheet__body a:hover {
  background: rgba(255, 255, 255, 0.06);
}

body.toc-sheet-open {
  overflow: hidden;
}

/* 文内目录 + 右上角悬浮目录：一级标题加粗 */
.toc .toc-content nav > ul > li > a,
#toc-static .toc-content nav > ul > li > a,
#toc-auto .toc-content nav > ul > li > a {
  font-weight: 700;
}

/* 文内目录 + 右上角悬浮目录：一级标题之间约 0.5 行间距 */
.toc .toc-content nav > ul > li:not(:last-child),
#toc-static .toc-content nav > ul > li:not(:last-child),
#toc-auto .toc-content nav > ul > li:not(:last-child) {
  margin-bottom: 0.75em;
  margin-bottom: 0.5lh;
}
