/* 环绕布局：左 2×2 轮播 + 其余格位铺卡片（对齐 twigspike） */
.bili-feed.pb-cf,
.pb-cf {
  container-type: inline-size;
  container-name: pb-surround;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 20px 16px;
  margin-bottom: 28px;
  align-items: stretch;
  min-width: 0;
  max-width: 100%;
}

/* 槽位 / 块宿主 / 封面包裹层一律穿透，卡片与轮播直接参与 pb-cf 网格 */
.bili-feed.pb-cf > .pb-surround-slot:not(.pb-surround-empty),
.pb-cf > .pb-surround-slot:not(.pb-surround-empty),
.bili-feed.pb-cf > .pb-block-host,
.pb-cf > .pb-block-host,
.pb-cf .pb-surround-slot:not(.pb-surround-empty) > .pb-block-host,
.pb-cf .pb-cover {
  display: contents !important;
}

/* 轮播占左上 2 列 × 2 行（可穿透 slot / host） */
.pb-cf .bili-feed__carousel,
.pb-cf .pb-cf__carousel,
.pb-cf .pb-vc.pb-cf__carousel {
  grid-column: 1 / 3;
  grid-row: 1 / 3;
  height: 100%;
  min-height: 0;
  align-self: stretch;
}

.pb-cf .pb-vod-card {
  margin: 0;
  min-width: 0;
}

/* 5 列桌面：隐藏多出的最后一张，保持环绕整齐 */
@media (min-width: 1281px) {
  .pb-cf > .pb-vod-card:nth-last-child(1),
  .pb-cf .pb-cover > .pb-vod-card:nth-last-child(1),
  .pb-cf .pb-surround-slot--feed .pb-vod-card:nth-last-child(1) {
    display: none;
  }
}

@container pb-surround (max-width: 479px) {
  .bili-feed.pb-cf,
  .pb-cf {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px 10px !important;
  }

  .pb-cf .bili-feed__carousel,
  .pb-cf .pb-cf__carousel {
    grid-column: 1 / -1 !important;
    grid-row: auto !important;
    aspect-ratio: 16 / 9;
    min-height: 180px;
  }
}

@container pb-surround (min-width: 480px) and (max-width: 719px) {
  .bili-feed.pb-cf,
  .pb-cf {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 14px 12px !important;
  }

  .pb-cf .bili-feed__carousel,
  .pb-cf .pb-cf__carousel {
    grid-column: 1 / -1 !important;
    grid-row: auto !important;
    aspect-ratio: 16 / 9;
    min-height: 180px;
  }
}

@media (max-width: 1280px) {
  .bili-feed.pb-cf,
  .pb-cf {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 720px) {
  .bili-feed.pb-cf,
  .pb-cf {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 14px 12px !important;
  }

  .pb-cf .bili-feed__carousel,
  .pb-cf .pb-cf__carousel {
    grid-column: 1 / -1 !important;
    grid-row: auto !important;
    aspect-ratio: 16 / 9;
    min-height: 180px;
  }
}

@media (max-width: 560px) {
  .bili-feed.pb-cf,
  .pb-cf {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 12px 10px !important;
  }
}

/* Page Builder 预览：保留网格与空槽投放区；列数交给 @container / @media，勿强制 5 列（否则手机预览与真机 H5 不一致） */
body.pb-preview-mode .bili-feed.pb-cf[data-pb-surround-layout] {
  display: grid !important;
  align-items: stretch;
}

@media (max-width: 560px) {
  body.pb-preview-mode .bili-feed.pb-cf[data-pb-surround-layout] > .pb-surround-slot--banner.pb-surround-empty {
    grid-column: 1 / -1 !important;
    grid-row: auto !important;
    min-height: 120px;
  }

  body.pb-preview-mode .bili-feed.pb-cf[data-pb-surround-layout] > .pb-surround-slot--feed.pb-surround-empty {
    grid-column: 1 / -1 !important;
    grid-row: auto !important;
    min-height: 120px;
  }
}

body.pb-preview-mode .bili-feed.pb-cf[data-pb-surround-layout] > .pb-surround-slot--banner.pb-surround-empty {
  grid-column: 1 / 3;
  grid-row: 1 / 3;
  display: block !important;
  min-height: 160px;
  position: relative;
  box-sizing: border-box;
}

body.pb-preview-mode .bili-feed.pb-cf[data-pb-surround-layout] > .pb-surround-slot--feed.pb-surround-empty {
  grid-column: 3 / -1;
  grid-row: 1 / 3;
  display: block !important;
  min-height: 160px;
  position: relative;
  box-sizing: border-box;
}

body.pb-preview-mode .bili-feed.pb-cf[data-pb-surround-layout] .pb-surround-slot.pb-surround-empty {
  min-height: 140px;
  border: 1px dashed rgba(64, 204, 146, 0.45);
  border-radius: 8px;
  background: rgba(64, 204, 146, 0.06);
}

body.pb-preview-mode .bili-feed.pb-cf[data-pb-surround-layout] .pb-surround-slot.pb-surround-empty::after {
  content: attr(data-pb-surround-hint);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  text-align: center;
  font-size: 12px;
  line-height: 1.45;
  color: #64748b;
  font-family: system-ui, sans-serif;
  pointer-events: none;
}

/* 已填充槽位：子块宿主 display:contents 无法绘制 outline，改由槽位承担 hover/选中高亮 */
body.pb-preview-mode .pb-cf[data-pb-surround-layout] > .pb-surround-slot:not(.pb-surround-empty):hover {
  outline: 2px solid #40cc92;
  outline-offset: -2px;
  z-index: 50;
}

body.pb-preview-mode .pb-cf[data-pb-surround-layout] .pb-surround-slot.pb-surround-slot-selected {
  outline: 3px solid #2563eb;
  outline-offset: -3px;
  z-index: 9999;
}
