/* 防止横向滚动条 */
html,
body {
  overflow-x: hidden;
  overflow-x: clip;
}

/* 首页 Hero */
.hero {
  position: relative !important;
  isolation: isolate;

  width: 100vw !important;
  max-width: 100vw !important;
  margin-left: calc(50% - 50vw) !important;
  margin-right: calc(50% - 50vw) !important;

  min-height: calc(100vh - 64px) !important;

  padding-left: max(32px, calc((100vw - 1120px) / 2)) !important;
  padding-right: max(32px, calc((100vw - 1120px) / 2)) !important;

  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;

  box-sizing: border-box !important;
  overflow: hidden !important;

  --hero-bg-opacity: 1;
  --hero-bg-blur: 0px;
  --hero-text-opacity: 1;
  --hero-text-y: 0px;
}

/* 背景图层 */
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;

  background-image:
    linear-gradient(
      90deg,
      rgba(0, 12, 32, 0.58) 0%,
      rgba(0, 12, 32, 0.38) 32%,
      rgba(0, 12, 32, 0.08) 62%,
      rgba(0, 12, 32, 0.02) 100%
    ),
    linear-gradient(
      180deg,
      rgba(0, 12, 32, 0.05) 0%,
      rgba(255, 255, 255, 0.10) 65%,
      rgba(255, 255, 255, 0.88) 100%
    ),
    url("/img/index_bg.jpg");

  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;

  opacity: var(--hero-bg-opacity);
  filter: blur(var(--hero-bg-blur)) saturate(1.08) contrast(1.04);
  transform: scale(1.04);
  will-change: opacity, filter, transform;
}

/* Hero 文字 */
.hero .title,
.hero .description {
  position: relative;
  z-index: 1;

  opacity: var(--hero-text-opacity);
  transform: translateY(var(--hero-text-y));
  will-change: opacity, transform;
}

.hero .title {
  color: rgba(235, 248, 255, 0.95) !important;
  text-shadow:
    0 2px 8px rgba(0, 0, 0, 0.35),
    0 8px 32px rgba(0, 20, 60, 0.55);
}

.hero .description {
  color: #ffffff !important;
  text-shadow:
    0 2px 10px rgba(0, 0, 0, 0.42),
    0 10px 36px rgba(0, 20, 60, 0.68);
}

/* 默认情况下，所有文章列表都正常显示 */
.section-title,
.post-list {
  opacity: 1;
  transform: none;
}

/* 只在首页启用 Latest Posts 的滚动淡入效果 */
body:has(.hero) #main-content > .container > .section-title,
body:has(.hero) #main-content > .container > .post-list {
  opacity: var(--home-content-opacity, 1);
  transform: translateY(var(--home-content-y, 0px));
  transition: opacity 0.12s linear, transform 0.12s linear;
  will-change: opacity, transform;
}

/* Giscus comments layout fix */
.giscus-comments {
  width: min(100% - 48px, 860px);
  margin: 96px auto 72px auto;
  padding-top: 40px;
  border-top: 1px solid rgba(120, 150, 180, 0.22);
  box-sizing: border-box;
}

.giscus-comments h2 {
  font-size: 24px;
  font-weight: 650;
  color: var(--color-text-primary);
}

/* Giscus iframe */
.giscus-comments .giscus,
.giscus-comments iframe {
  width: 100% !important;
}

/* Prevent footer from sticking too close to comments */
footer {
  margin-top: 80px;
}

/* 文章右侧目录 */
.post > .post-toc {
  position: sticky;
  top: 80px;
  z-index: 10;
  width: clamp(168px, calc((100vw - 944px) / 2), 260px);
  height: 0;
  margin-left: calc(50% + 448px);
  overflow: visible;
}

.post-toc__title {
  margin: 0 0 10px;
  color: var(--color-text-primary);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.04em;
}

.post-toc__toggle {
  display: none;
}

.post > .post-toc > .toc {
  box-sizing: border-box;
  max-width: none;
  max-height: calc(100vh - 132px);
  margin: 0;
  padding: 2px 8px 2px 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--color-border-primary) transparent;
  scrollbar-width: thin;
}

.post > .post-toc > .toc::-webkit-scrollbar {
  width: 5px;
}

.post > .post-toc > .toc::-webkit-scrollbar-track {
  background: transparent;
}

.post > .post-toc > .toc::-webkit-scrollbar-thumb {
  background: var(--color-border-primary);
  border-radius: 999px;
}

.post-toc .toc > p > a {
  display: block;
  box-sizing: border-box;
  width: 100%;
  padding: 6px 10px 6px 12px;
  border-left: 2px solid var(--color-border-primary);
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  transition:
    color 0.2s ease,
    border-color 0.2s ease,
    background-color 0.2s ease;
}

.post-toc .toc > p[data-toc-level="2"] > a {
  font-weight: 550;
}

.post-toc .toc > p[data-toc-level="3"] > a {
  padding-left: 24px;
  font-size: 12px;
}

.post-toc .toc > p[data-toc-level="4"] > a,
.post-toc .toc > p[data-toc-level="5"] > a,
.post-toc .toc > p[data-toc-level="6"] > a {
  padding-left: 36px;
  font-size: 12px;
}

.post-toc .toc > p > a:hover,
.post-toc .toc > p > a:focus-visible {
  border-color: var(--color-text-secondary-hover);
  color: var(--color-text-secondary-hover);
  text-decoration: none;
}

.post-toc .toc > p > a.is-active {
  border-color: var(--color-text-accent);
  background-color: color-mix(in srgb, var(--color-background-accent) 9%, transparent);
  color: var(--color-text-accent);
  font-weight: 650;
}

.post > .content > h1,
.post > .content > h2,
.post > .content > h3,
.post > .content > h4,
.post > .content > h5,
.post > .content > h6 {
  scroll-margin-top: 80px;
}

/* 页脚使用不透明层盖住滚动到页面底部时仍在视口内的目录。 */
footer {
  position: relative;
  z-index: 20;
  background-color: var(--color-background-underlying);
}

/* 横向空间不足时不让目录覆盖正文，改为文章头部的折叠目录。 */
@media (max-width: 1279px) {
  .post > .post-toc {
    position: relative;
    top: auto;
    width: min(100% - 32px, 800px);
    height: auto;
    margin: 40px auto -24px;
  }

  .post-toc__title {
    display: none;
  }

  .post-toc__toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--color-border-primary);
    border-radius: 12px;
    background: var(--color-background-secondary);
    color: var(--color-text-primary);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
  }

  .post-toc__toggle::after {
    content: '';
    width: 7px;
    height: 7px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg) translateY(-2px);
    transition: transform 0.2s ease;
  }

  .post-toc.is-open .post-toc__toggle::after {
    transform: rotate(225deg) translate(-2px, -2px);
  }

  .post > .post-toc > .toc {
    max-height: 0;
    padding: 0 8px 0 0;
    opacity: 0;
    visibility: hidden;
    transition:
      max-height 0.25s ease,
      padding 0.25s ease,
      opacity 0.2s ease,
      visibility 0s linear 0.25s;
  }

  .post > .post-toc.is-open > .toc {
    max-height: min(50vh, 420px);
    padding-top: 10px;
    padding-bottom: 4px;
    opacity: 1;
    visibility: visible;
    transition:
      max-height 0.25s ease,
      padding 0.25s ease,
      opacity 0.2s ease,
      visibility 0s;
  }
}

@media (prefers-reduced-motion: reduce) {
  .post-toc *,
  .post-toc *::before,
  .post-toc *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
