/* 文章页宽屏——仅当 #body-wrap 内包含 #post 时生效 */
/* 双栏模式按视口自适应：外框上限 1380px，右侧目录栏 clamp(260px, 21vw, 336px) 弹性扩展，正文保持宽裕可读区 */

@media (min-width: 769px) {
  html:not(.hide-aside) #body-wrap:has(#post) > .layout {
    max-width: min(94vw, 1380px) !important;
  }

  html.hide-aside #body-wrap:has(#post) > .layout {
    max-width: min(92vw, 960px) !important;
  }
}

/* 移动端解除 94vw 缩进，释放横向阅读空间 */
@media (max-width: 768px) {
  #body-wrap:has(#post) > .layout {
    max-width: 100% !important;
  }

  #body-wrap:has(#post) > .layout > #post {
    padding: 28px 14px;
  }
}

/* 桌面端解除 Butterfly 默认 74%/26% 固定占比死锁，改为视口自适应侧栏 + 弹性高度分配 */
@media (min-width: 901px) {
  html:not(.hide-aside) #body-wrap:has(#post) > .layout > #post {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    padding: 44px 36px;
  }

  html.hide-aside #body-wrap:has(#post) > .layout > #post {
    width: 100%;
    padding: 44px 40px;
  }

  #body-wrap:has(#post) #aside-content {
    flex: 0 0 clamp(260px, 21vw, 336px);
    width: clamp(260px, 21vw, 336px);
    max-width: 336px;
  }

  /* 侧栏粘性容器按视口高度自适应分配给 TOC 与同系列卡片：短目录时系列卡片自由展开占满余量，长目录时按比例共存 */
  #body-wrap:has(#post) #aside-content > .sticky_layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: calc(100vh - 90px);
  }

  #body-wrap:has(#post) #aside-content > .sticky_layout > #card-toc {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    max-height: calc(100vh - 90px);
    margin-bottom: 0;
  }

  #body-wrap:has(#post) #aside-content > .sticky_layout > #card-toc:has(+ .card-post-series) {
    max-height: min(56vh, calc(100vh - 300px));
  }

  #body-wrap:has(#post) #aside-content > .sticky_layout > #card-toc .toc-content {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
  }

  #body-wrap:has(#post) #aside-content > .sticky_layout > .card-post-series {
    display: flex;
    flex-direction: column;
    flex: 0 1 auto;
    min-height: 0;
    margin-top: 0;
    margin-bottom: 0;
  }

  #body-wrap:has(#post) #aside-content > .sticky_layout > .card-post-series .aside-list {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
  }
}

/* 对齐宽屏下顶部文章标题区与正文容器左右边缘（Butterfly 的居中在 #post-info > * 上） */
@media (min-width: 769px) {
  html:not(.hide-aside) #body-wrap:has(#post) #page-header.post-bg #post-info > * {
    max-width: min(94vw, 1380px) !important;
    padding: 0 15px;
  }

  html.hide-aside #body-wrap:has(#post) #page-header.post-bg #post-info > * {
    max-width: min(92vw, 960px) !important;
    padding: 0 15px;
  }
}

#body-wrap:has(#post) #article-container {
  max-width: 100% !important;
}
