/*
 * 落魄山 1.5.0 收敛层
 * 只处理子主题组件和少量 Zibll 9.0 兼容点；父主题文件保持只读。
 */

body.lps-child-active {
  --theme-color: var(--lps-brand);
  --focus-color: var(--lps-brand);
  --key-color: var(--lps-text);
  color: var(--lps-text);
  background: var(--lps-bg);
}

body.lps-child-active.dark-theme {
  --theme-color: var(--lps-brand-light);
  --focus-color: var(--lps-brand-light);
  --key-color: var(--lps-text);
}

body.lps-child-active *,
body.lps-child-active *::before,
body.lps-child-active *::after {
  box-sizing: border-box;
}

/* 内容媒体兜底：保留原图比例，表格和嵌入内容不撑破文章。 */
body.lps-child-active :is(.entry-content, .article-content, .post-content) {
  min-width: 0;
  overflow-wrap: anywhere;
}

body.lps-child-active :is(.entry-content, .article-content, .post-content, .wp-block-image, figure, .wp-caption) img {
  max-width: 100%;
  height: auto !important;
  object-fit: contain;
}

body.lps-child-active :is(.entry-content, .article-content, .post-content) :is(iframe, video),
body.lps-child-active :is(.wp-caption, figure, .wp-block-embed) {
  max-width: 100%;
}

body.lps-child-active .lps-fallback-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 统一容器，不再通过减 10px 等页面补丁手工对齐。 */
body.lps-child-active .lps-shell,
body.lps-child-active .lps-header-inner,
body.category.lps-child-active main.container {
  width: min(1240px, calc(100% - 32px));
  max-width: 1240px;
  margin-right: auto;
  margin-left: auto;
}

/* 页头：只使用 .lps-* 命名空间，避免覆盖 Zibll 自带导航组件。 */
body.lps-child-active .lps-site-header {
  position: sticky;
  z-index: 10000;
  top: 0;
  overflow: visible;
  border-bottom: 1px solid var(--lps-border);
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 4px 18px rgba(31, 55, 75, .05);
}

body.lps-child-active.dark-theme .lps-site-header {
  background: rgba(24, 34, 47, .97);
}

body.lps-child-active .lps-header-inner {
  display: flex;
  min-height: 64px;
  align-items: center;
  gap: 22px;
}

body.lps-child-active .lps-site-nav {
  min-width: 0;
  flex: 1;
}

body.lps-child-active .lps-site-nav > ul {
  gap: 5px;
}

body.lps-child-active .lps-site-nav > ul > li > a {
  padding: 11px 15px;
  font-size: 17px;
  font-weight: 400;
  letter-spacing: .01em;
}

body.lps-child-active .lps-site-nav li.menu-item-has-children::after {
  position: absolute;
  top: 100%;
  left: 0;
  width: max(100%, 160px);
  height: 8px;
  content: "";
}

body.lps-child-active .lps-site-nav .sub-menu {
  top: calc(100% + 5px);
  overflow: visible;
  border-radius: 8px;
}

body.lps-child-active .lps-site-nav a:focus-visible,
body.lps-child-active .lps-menu-toggle:focus-visible,
body.lps-child-active .lps-menu-close:focus-visible {
  outline: 2px solid var(--lps-brand);
  outline-offset: 2px;
}

/* 标签统一为偏方形的小圆角。 */
body.lps-child-active :is(.item-tags a, .item-tags .badg, .lps-tags a, .tag-cloud a, .tag-list a, .article-tags a, .lps-term, .lps-gallery-tag, .badg) {
  border-radius: 5px !important;
}

/* 父主题列表页只做视觉映射，不改内部尺寸和定位契约。 */
body.lps-child-active:is(.tag, .search, .author, .archive):not(.category) .posts-item {
  overflow: hidden;
  border: 1px solid var(--lps-border);
  border-radius: var(--lps-radius);
  background: var(--lps-card);
  box-shadow: var(--lps-shadow);
}

body.lps-child-active:is(.tag, .search, .author, .archive):not(.category) .item-heading a {
  color: var(--lps-text);
  font-size: 18px;
  line-height: 1.5;
}

body.lps-child-active:is(.tag, .search, .author, .archive):not(.category) .item-excerpt {
  color: var(--lps-text-2);
  font-size: 14px;
  line-height: 1.75;
}

/* 分类页：封面、排序条和文章区共享同一宽度。 */
body.category.lps-child-active main.container {
  padding-top: 32px;
  padding-bottom: 42px;
}

body.category.lps-child-active .content-wrap,
body.category.lps-child-active .content-layout,
body.category.lps-child-active .lps-category-cover,
body.category.lps-child-active .posts-row,
body.category.lps-child-active .lps-category-waterfall {
  width: 100% !important;
  max-width: none;
  margin-right: 0 !important;
  margin-left: 0 !important;
}

body.category.lps-child-active .lps-category-cover {
  min-height: 242px !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: var(--lps-radius) !important;
  background: #183654;
  box-shadow: none !important;
}

body.category.lps-child-active .lps-category-cover > .lps-category-cover-content {
  min-height: 0 !important;
  padding: 36px 40px !important;
}

body.category.lps-child-active .posts-row.lps-category-layout {
  display: grid;
  grid-template-columns: repeat(var(--lps-category-columns, 4), minmax(0, 1fr)) !important;
  gap: 16px !important;
  margin-top: 20px !important;
}

body.category.lps-child-active .posts-row.lps-category-layout > .lps-category-items:not(.lps-category-waterfall) {
  display: contents;
}

body.category.lps-child-active .posts-row.lps-category-layout > .lps-category-pager {
  grid-column: 1 / -1;
  width: 100%;
}

body.category.lps-child-active .posts-row.lps-category-layout-waterfall {
  display: grid;
}

body.category.lps-child-active .posts-row.lps-category-layout-waterfall .lps-category-waterfall {
  column-count: var(--lps-category-columns, 4);
  column-gap: 16px;
}

/*
 * JS 完成首轮测量后切换为稳定 Grid 瀑布流。CSS 多栏会在 AJAX
 * 追加文章时重新平衡全部列，导致已经看过的卡片换列；Grid 的既有卡片
 * 行跨度不变，新文章只从末尾继续排布。
 */
body.category.lps-child-active .posts-row.lps-category-layout-waterfall .lps-category-waterfall.lps-masonry-ready {
  display: grid !important;
  grid-column: 1 / -1;
  grid-template-columns: repeat(var(--lps-category-columns, 4), minmax(0, 1fr));
  grid-auto-flow: row;
  grid-auto-rows: 8px;
  align-items: start;
  gap: 16px;
  column-count: initial !important;
}

body.category.lps-child-active .lps-category-waterfall.lps-masonry-ready > .lps-category-card {
  min-width: 0;
  margin: 0 !important;
  align-self: start;
  break-inside: auto;
}

body.category.lps-child-active .lps-category-waterfall .lps-category-card {
  margin: 0 0 20px !important;
}

body.category.lps-child-active .lps-category-waterfall .lps-gallery-card img {
  width: 100%;
  height: auto !important;
  object-fit: contain;
}

/* 分类瀑布流标题与简介。桌面、平板、手机依次使用 15/14/13px，
   同时让勾选的简介成为卡片正文的一部分，由稳定瀑布流脚本重新测量高度。 */
body.category.lps-child-active .lps-category-waterfall {
  --lps-waterfall-title-size: 15px;
}

body.category.lps-child-active .lps-category-waterfall :is(.lps-gallery-label, .lps-waterfall-title) {
  font-size: var(--lps-waterfall-title-size) !important;
}

body.category.lps-child-active .lps-category-waterfall .lps-waterfall-copy {
  min-width: 0;
  padding: 11px 13px 13px;
  background: var(--lps-card);
}

body.category.lps-child-active .lps-category-waterfall .lps-waterfall-title {
  display: -webkit-box !important;
  overflow: hidden;
  max-height: 3em;
  margin: 0 !important;
  padding: 0 !important;
  background: transparent !important;
  line-height: 1.5;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

body.category.lps-child-active .lps-category-waterfall .lps-title-lines-1 .lps-waterfall-title {
  max-height: 1.5em;
  -webkit-line-clamp: 1;
}

body.category.lps-child-active .lps-category-waterfall .lps-waterfall-title--responsive {
  display: none !important;
}

body.category.lps-child-active .lps-category-waterfall .lps-waterfall-excerpt {
  display: -webkit-box !important;
  overflow: hidden;
  max-height: 4.95em;
  margin: 0 !important;
  padding: 0 !important;
  background: transparent !important;
  color: var(--lps-text-2);
  font-size: 13px;
  line-height: 1.65;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

body.category.lps-child-active .lps-category-waterfall .lps-waterfall-title + .lps-waterfall-excerpt {
  margin-top: 6px !important;
}

body.category.lps-child-active .lps-category-card {
  min-width: 0;
}

body.category.lps-child-active .lps-category-card .lps-card-title > a:hover {
  color: var(--lps-brand);
}

/* 首页布局器中的 1/2 模块不再被丢弃，并在窄屏自然改为整行。 */
body.home.lps-child-active .lps-widget-builder-grid > .lps-span-half {
  grid-column: span 6;
}

/* 随机推荐与上方内容模块使用同一标题层级，避免网格卡片标题显得过小。 */
body.home.lps-child-active .lps-module-random .lps-grid-card .lps-card-title {
  font-size: 18px;
  line-height: 1.45;
}

/* 文章、标签和搜索页保留 Zibll 模板，只统一阅读宽度与节奏。 */
body.single.lps-child-active main.container,
body.tag.lps-child-active main.container,
body.search.lps-child-active main.container,
body.author.lps-child-active main.container {
  padding-top: 28px;
  padding-bottom: 42px;
}

body.single.lps-child-active :is(.article-content, .entry-content, .post-content) {
  font-size: 16px;
  line-height: 1.9;
}

@media (max-width: 1080px) {
  body.lps-child-active .lps-header-inner {
    gap: 12px;
  }
  body.lps-child-active .lps-brand small {
    display: none;
  }
  body.lps-child-active .lps-site-nav > ul > li > a {
    padding-right: 11px;
    padding-left: 11px;
    font-size: 16px;
  }
  body.lps-child-active .lps-site-search {
    width: 160px;
  }
}

@media (max-width: 860px) {
  body.lps-child-active .lps-shell,
  body.lps-child-active .lps-header-inner,
  body.category.lps-child-active main.container {
    width: calc(100% - 24px);
  }

  body.lps-child-active .lps-header-inner {
    min-height: 58px;
  }

  body.lps-child-active .lps-site-nav {
    right: auto;
    left: 0;
    width: min(340px, 86vw);
    padding: 64px 18px 26px;
    border-right: 1px solid var(--lps-border);
    border-left: 0;
    background: var(--lps-card);
    box-shadow: 14px 0 34px rgba(27, 50, 70, .15);
    transform: translateX(-100%);
  }

  body.lps-child-active .lps-site-nav li.menu-item-has-children::after {
    display: none;
  }

  body.lps-child-active .lps-site-nav .sub-menu {
    overflow: visible;
  }

  body.lps-child-active .lps-menu-toggle {
    order: initial;
    margin-right: 0;
    margin-left: auto;
  }

  body.category.lps-child-active main.container {
    padding-top: 20px;
  }

  body.category.lps-child-active .lps-category-cover {
    min-height: 190px !important;
  }

  body.category.lps-child-active .lps-category-cover > .lps-category-cover-content {
    padding: 25px 20px !important;
  }

  body.category.lps-child-active .posts-row.lps-category-layout {
    --lps-category-columns: 2;
    gap: 12px !important;
  }

  body.category.lps-child-active .posts-row.lps-category-layout-waterfall .lps-category-waterfall {
    column-gap: 12px;
  }

  body.category.lps-child-active .posts-row.lps-category-layout-waterfall .lps-category-waterfall.lps-masonry-ready {
    gap: 12px;
  }

  body.category.lps-child-active .lps-category-waterfall .lps-category-card {
    margin-bottom: 12px !important;
  }

  body.category.lps-child-active .lps-category-waterfall {
    --lps-waterfall-title-size: 14px;
  }

  body.category.lps-child-active .lps-category-waterfall .lps-waterfall-copy {
    padding: 9px 11px 11px;
  }

  body.category.lps-child-active .lps-category-waterfall .lps-gallery-label {
    display: none !important;
  }

  body.category.lps-child-active .lps-category-waterfall .lps-waterfall-title--responsive {
    display: -webkit-box !important;
  }

  body.category.lps-child-active .lps-category-waterfall .lps-waterfall-excerpt {
    max-height: 3.3em;
    font-size: 12px;
    -webkit-line-clamp: 2;
  }

  body.home.lps-child-active .lps-widget-builder-grid > .lps-span-half {
    grid-column: span 12;
  }

  body.home.lps-child-active .lps-module-random .lps-grid-card .lps-card-title {
    font-size: 17px;
  }
}

/* 菜单在 860px 切换不再同时触发分类瀑布流换列：
   761–860px 保持三列，至 760px 再进入两列，降低整页高度突增。 */
@media (min-width: 761px) and (max-width: 860px) {
  body.category.lps-child-active .posts-row.lps-category-cols-3,
  body.category.lps-child-active .posts-row.lps-category-cols-4 {
    --lps-category-columns: 3;
  }
}

@media (hover: none), (pointer: coarse) {
  /* 触屏没有 hover：隐藏图片浮层，改用正文区标题，避免同一标题出现两次。 */
  body.category.lps-child-active .lps-category-waterfall .lps-gallery-label {
    display: none !important;
  }

  body.category.lps-child-active .lps-category-waterfall .lps-waterfall-title--responsive {
    display: -webkit-box !important;
  }
}

@media (max-width: 560px) {
  body.lps-child-active :is(.entry-content, .article-content, .post-content) {
    font-size: 16px;
    line-height: 1.85;
  }

  body.lps-child-active :is(.entry-content, .article-content, .post-content) :is(pre, table) {
    display: block;
    max-width: 100%;
    overflow-x: auto;
  }

  body.category.lps-child-active .posts-row.lps-category-layout-waterfall {
    --lps-category-columns: 2;
  }

  body.category.lps-child-active .lps-category-waterfall {
    --lps-waterfall-title-size: 13px;
  }

  body.home.lps-child-active .lps-module-random .lps-grid-card .lps-card-title {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  body.category.lps-child-active .posts-row.lps-category-layout:not(.lps-category-layout-waterfall) {
    --lps-category-columns: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.lps-child-active *,
  body.lps-child-active *::before,
  body.lps-child-active *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
