/**
 * 广告位布局（与 site.css 业务样式分离）
 * 仅控制预留空位、响应式与占位展示；联盟代码样式由投放方控制，建议限制在 .ad-slot__inner 内。
 */

:root {
  --ad-rail-width: 148px;
  --ad-layout-max: 1280px;
  --ad-banner-pc-max-h: 120px;
  --ad-banner-mobile-max-h: 72px;
  --ad-rail-min-h: 280px;
  --ad-gap: 1rem;
}

/* ── 广告容器通用 ── */
.ad-region {
  width: 100%;
  max-width: var(--ad-layout-max);
  margin-left: auto;
  margin-right: auto;
  padding-left: max(0.75rem, env(safe-area-inset-left));
  padding-right: max(0.75rem, env(safe-area-inset-right));
  box-sizing: border-box;
}

.ad-region--top {
  padding-top: 0.65rem;
  padding-bottom: 0.35rem;
  flex-shrink: 0;
}

.ad-region--bottom {
  padding-top: 0.35rem;
  padding-bottom: 0.75rem;
  flex-shrink: 0;
}

.ad-region--mobile-mid {
  display: none;
  padding-top: 0.5rem;
  padding-bottom: 0.5rem;
}

.ad-slot {
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
  margin: 0 auto;
  text-align: center;
}

.ad-slot__inner {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 1px;
  overflow: hidden;
}

.ad-slot__inner:empty {
  min-height: 0;
}

.ad-slot__placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  color: rgba(196, 165, 116, 0.35);
  border: 1px dashed rgba(196, 165, 116, 0.22);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.18);
  box-sizing: border-box;
  pointer-events: none;
}

.ad-slot--filled .ad-slot__placeholder,
.ad-slot__inner:not(:empty) + .ad-slot__placeholder {
  display: none;
}

/* 未投放广告：有 wisdomKey 时展示格言，隐藏虚线「广告位」 */
.ad-slot--has-wisdom .ad-slot__placeholder {
  display: none !important;
}

.ad-slot__wisdom {
  display: none;
}

.ad-slot--has-wisdom:has(.ad-slot__inner:empty) .ad-slot__wisdom {
  display: block;
}

.ad-slot--has-wisdom:has(.ad-slot__inner:not(:empty)) .ad-slot__wisdom {
  display: none;
}

/* 无格言 key 的可选位：仍保持不展示 */
.ad-slot--optional:not(.ad-slot--has-wisdom):has(.ad-slot__inner:empty) {
  display: none;
}

.ad-region-collapsible:not(:has(.ad-slot--has-wisdom)):has(.ad-slot__inner:empty),
.ad-region-collapsible[hidden] {
  display: none;
}

/* 加载页弹窗：无广告时不遮罩（有格言时 overlay 可展示格言） */
.fortune-loading__ad-overlay:not(:has(.ad-slot__inner:not(:empty))):not(:has(.ad-slot--has-wisdom .ad-slot__inner:empty)) {
  display: none;
}

/* 顶部 / 底部通栏 */
.ad-slot--banner-top,
.ad-slot--banner-bottom {
  width: 100%;
  max-width: 728px;
}

.ad-slot--banner-top .ad-slot__placeholder,
.ad-slot--banner-bottom .ad-slot__placeholder {
  width: 100%;
  min-height: 64px;
  max-height: var(--ad-banner-pc-max-h);
}

.ad-slot--banner-top .ad-slot__inner,
.ad-slot--banner-bottom .ad-slot__inner {
  max-height: var(--ad-banner-pc-max-h);
}

.ad-slot--banner-top .ad-slot__inner img,
.ad-slot--banner-bottom .ad-slot__inner img,
.ad-slot--banner-mobile .ad-slot__inner img {
  max-width: 100%;
  max-height: var(--ad-banner-pc-max-h);
  height: auto;
  width: auto;
  object-fit: contain;
}

/* 两侧竖栏（仅 PC 布局显示） */
.ad-region--rail-start,
.ad-region--rail-end {
  flex-shrink: 0;
  width: var(--ad-rail-width);
  padding-top: 0.25rem;
}

.ad-slot--rail-side {
  width: var(--ad-rail-width);
  max-width: 100%;
}

.ad-slot--rail-side .ad-slot__placeholder {
  width: 100%;
  min-height: var(--ad-rail-min-h);
  max-height: 600px;
}

.ad-slot--rail-side .ad-slot__inner {
  max-width: var(--ad-rail-width);
}

.ad-slot--rail-side .ad-slot__inner img,
.ad-slot--rail-side .ad-slot__inner iframe {
  max-width: 100%;
  height: auto;
}

/* 正文段落间隙（可选，在业务模板中单独插入 contentGap 时使用） */
.ad-slot--inline-gap {
  width: 100%;
  max-width: 640px;
  margin: 1.25rem auto;
}

.ad-slot--inline-gap .ad-slot__placeholder {
  width: 100%;
  min-height: 48px;
  max-height: 90px;
}

/* ── 页面主布局：正文优先，广告不挤压 ── */
body.page-with-ads {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

body.page-with-ads .site-layout {
  display: flex;
  flex: 1 1 auto;
  align-items: flex-start;
  justify-content: center;
  gap: var(--ad-gap);
  width: 100%;
  max-width: var(--ad-layout-max);
  margin-left: auto;
  margin-right: auto;
  padding-left: max(0.5rem, env(safe-area-inset-left));
  padding-right: max(0.5rem, env(safe-area-inset-right));
  box-sizing: border-box;
}

body.page-with-ads .site-layout__main {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

body.page-with-ads .site-content {
  min-width: 0;
  width: 100%;
}

/* 业务 main.wrap 保持原有最大宽度与内边距，不被侧栏压缩 */
body.page-with-ads .site-content > .wrap,
body.page-with-ads .site-content > main.wrap {
  max-width: var(--wrap-max, 1180px);
  margin-left: auto;
  margin-right: auto;
  padding-top: 1.85rem;
  padding-bottom: 3rem;
  box-sizing: border-box;
}

body.page-with-ads.site-layout--no-rails .site-layout,
body.page-with-ads .site-layout--no-rails {
  max-width: var(--wrap-max, 1180px);
}

/* 无侧栏页（跳转页等） */
body.page-with-ads .site-layout--no-rails .site-layout__main {
  max-width: var(--wrap-max, 1180px);
}

/* ── 平板：收窄侧栏 ── */
@media (max-width: 1100px) {
  :root {
    --ad-rail-width: 120px;
  }
}

/* ── 手机：隐藏 PC 侧栏，启用移动专用位，限制广告高度 ── */
@media (max-width: 900px) {
  body.page-with-ads .site-layout {
    flex-direction: column;
    gap: 0;
    padding-left: max(0.65rem, env(safe-area-inset-left));
    padding-right: max(0.65rem, env(safe-area-inset-right));
  }

  .ad-region--rail-start,
  .ad-region--rail-end {
    display: none !important;
  }

  .ad-region--mobile-mid {
    display: block;
    order: 10;
  }

  .ad-slot--banner-top,
  .ad-slot--banner-bottom,
  .ad-slot--banner-mobile {
    max-width: 100%;
  }

  .ad-slot--banner-top .ad-slot__placeholder,
  .ad-slot--banner-bottom .ad-slot__placeholder,
  .ad-slot--banner-mobile .ad-slot__placeholder {
    min-height: 50px;
    max-height: var(--ad-banner-mobile-max-h);
  }

  .ad-slot--banner-top .ad-slot__inner,
  .ad-slot--banner-bottom .ad-slot__inner,
  .ad-slot--banner-mobile .ad-slot__inner {
    max-height: var(--ad-banner-mobile-max-h);
  }

  .ad-slot--banner-top .ad-slot__inner img,
  .ad-slot--banner-bottom .ad-slot__inner img,
  .ad-slot--banner-mobile .ad-slot__inner img {
    max-height: var(--ad-banner-mobile-max-h);
  }

  .ad-slot--inline-gap {
    margin: 0.85rem auto;
  }

  .ad-slot--inline-gap .ad-slot__placeholder {
    min-height: 40px;
    max-height: 60px;
  }

  body.page-with-ads .site-content > .wrap,
  body.page-with-ads .site-content > main.wrap {
    padding-top: 1.25rem;
    padding-bottom: 2rem;
  }
}

/* 联盟常见固定尺寸：容器内居中，禁止撑破视口 */
.ad-slot__inner iframe,
.ad-slot__inner ins,
.ad-slot__inner > * {
  max-width: 100%;
}

.ad-slot__inner iframe {
  max-height: var(--ad-banner-pc-max-h);
}

@media (max-width: 900px) {
  .ad-slot__inner iframe {
    max-height: var(--ad-banner-mobile-max-h);
  }
}

/* ── 测算加载等待页 ── */
body.fortune-loading-page .ad-region--top,
body.fortune-loading-page .ad-region--bottom {
  display: none;
}

.fortune-loading {
  position: relative;
  min-height: 52vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding-top: 2rem;
  padding-bottom: 3rem;
}

.fortune-loading__panel {
  max-width: 28rem;
}

.fortune-loading__spinner {
  width: 3rem;
  height: 3rem;
  margin: 0 auto 1.25rem;
  border: 3px solid rgba(196, 165, 116, 0.2);
  border-top-color: rgba(196, 165, 116, 0.85);
  border-radius: 50%;
  animation: fortune-loading-spin 0.9s linear infinite;
}

@keyframes fortune-loading-spin {
  to {
    transform: rotate(360deg);
  }
}

.fortune-loading__title {
  font-size: 1.35rem;
  margin: 0 0 0.5rem;
}

.fortune-loading__hint {
  margin: 0 0 0.35rem;
}

.fortune-loading__sub {
  font-size: 0.88rem;
  margin: 0;
}

.fortune-loading__ad-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  pointer-events: none;
  background: rgba(8, 6, 12, 0.45);
}

.fortune-loading__ad-overlay .ad-slot {
  pointer-events: auto;
  max-width: min(360px, 92vw);
}

.ad-slot--overlay-popup .ad-slot__placeholder {
  width: 100%;
  min-height: 200px;
  max-height: 320px;
}

.ad-slot--overlay-popup .ad-slot__inner {
  max-height: 320px;
}

/* ── 结果页末尾信息流（第三方广告，勿用业务标题包装） ── */
.jieguo-result-ad {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid rgba(196, 165, 116, 0.12);
}

.ad-slot--feed-native {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
}

.ad-slot--feed-native .ad-slot__placeholder {
  width: 100%;
  min-height: 120px;
  max-height: 280px;
}

.ad-slot--feed-native .ad-slot__inner {
  min-height: 80px;
}

/* ── 无广告时的道家格言 fallback ── */
.wisdom-fallback {
  margin: 0;
  padding: 0.85rem 1rem;
  text-align: center;
  border: none;
  background: transparent;
}

.wisdom-fallback__text {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  line-height: 1.65;
  color: rgba(232, 220, 198, 0.88);
  font-style: normal;
  letter-spacing: 0.04em;
}

.wisdom-fallback__src {
  margin: 0;
  font-size: 0.72rem;
  color: rgba(196, 165, 116, 0.42);
  font-style: normal;
}

.ad-slot--nav-mini .wisdom-fallback {
  padding: 0.35rem 0.5rem;
}

.ad-slot--nav-mini .wisdom-fallback__text {
  font-size: 0.68rem;
  line-height: 1.4;
  margin-bottom: 0.15rem;
}

.ad-slot--nav-mini .wisdom-fallback__src {
  font-size: 0.58rem;
}

.ad-slot--feed-native .wisdom-fallback {
  max-width: 36rem;
  margin-left: auto;
  margin-right: auto;
}

.ad-slot--overlay-popup .wisdom-fallback {
  padding: 1.25rem 1.5rem;
  background: rgba(12, 10, 16, 0.92);
  border-radius: 10px;
  border: 1px solid rgba(196, 165, 116, 0.15);
}

.ad-slot--rail-side .wisdom-fallback__text {
  font-size: 0.82rem;
  line-height: 1.55;
}

/* ── 页头导航旁小广告 ── */
.site-header__nav-ads {
  margin-top: 0.65rem;
  padding-top: 0.35rem;
  border-top: 1px solid rgba(196, 165, 116, 0.08);
}

.nav-feature-ads {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 0.75rem;
}

.nav-feature-ads__item {
  flex: 0 1 auto;
}

.ad-slot--nav-mini {
  max-width: 100px;
}

.ad-slot--nav-mini .ad-slot__placeholder {
  min-height: 28px;
  max-height: 40px;
  min-width: 72px;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
}

.ad-slot--nav-mini .ad-slot__inner {
  max-height: 40px;
}

.ad-slot--nav-mini .ad-slot__inner img {
  max-height: 36px;
  width: auto;
}

@media (max-width: 900px) {
  .site-header__nav-ads {
    margin-top: 0.5rem;
  }

  .nav-feature-ads {
    gap: 0.35rem;
  }

  .ad-slot--nav-mini {
    max-width: 88px;
  }

  .ad-slot--nav-mini .ad-slot__placeholder {
    min-height: 24px;
    max-height: 32px;
  }
}

/* ── 管理端广告说明页 ── */
.admin-ads-guide .admin-lead {
  max-width: 52rem;
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.admin-ads-guide .admin-card {
  margin-bottom: 1.75rem;
  padding: 1.25rem 1.35rem;
  border: 1px solid rgba(196, 165, 116, 0.18);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.12);
}

.admin-ads-guide .admin-card h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

.admin-ads-method {
  margin-bottom: 1.25rem;
}

.admin-ads-method:last-child {
  margin-bottom: 0;
}

.admin-ads-method h3 {
  font-size: 1rem;
  margin: 0 0 0.35rem;
}

.admin-ads-highlights {
  margin: 0;
  padding-left: 1.25rem;
  line-height: 1.65;
}

.admin-ads-highlights li + li {
  margin-top: 0.65rem;
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table--ads {
  font-size: 0.88rem;
}

.admin-table--ads code {
  font-size: 0.82em;
}

.admin-ads-guide .admin-back {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}
