/**
 * 广告预留位：留白、与内容区分、降低 CLS；填充后弱化占位框（:has + .is-leafs-ad-filled 双路径）.
 */

.leafs-ad-slot {
	/* 父级作 container：可按栏宽用 @container 调整内部 __frame 的 min-height */
	container-type: inline-size;
	container-name: leafs-ad;
	/* 占位框颜色随 leafs-tokens 的 --leafs-border / 深浅主题切换 */
	--leafs-ad-frame-bg: color-mix(in srgb, var(--leafs-border, #e2e8f0) 32%, transparent);
	--leafs-ad-frame-border: color-mix(in srgb, var(--leafs-border, #e2e8f0) 72%, transparent);
	--leafs-ad-slot-radius: var(--leafs-radius, 12px);
	margin: 0 auto;
	width: 100%;
	max-width: 100%;
	padding-block: 10px;
	clear: both;
	box-sizing: border-box;
}

/* 桌面栅格子项多为 min-width:0；保证广告槽占满列宽，避免延后 push 时 ins 实测宽度长期为 0 */
.leafs-layout__center > .leafs-ad-slot,
.leafs-layout__right > .leafs-ad-slot,
/* 详情页广告在 article / .leafs-entry-content 内，非 main 直接子元素，须用后代选择器 */
.leafs-inner-layout__main .leafs-ad-slot,
.leafs-inner-layout__aside .leafs-ad-slot {
	width: 100%;
	max-width: 100%;
	min-width: 0;
}

/*
 * 详情页右栏可窄至约 200px；全站广告槽的 min-width: max(250px, …) 会撑破侧栏并压盖主栏。
 * 在侧栏内改为不超出列宽，避免与正文或其它侧栏块重叠。
 */
.leafs-inner-layout__aside .leafs-ad-slot__frame {
	min-width: 0;
}

.leafs-inner-layout__aside .leafs-ad-slot__frame ins.adsbygoogle {
	min-width: min(250px, 100%) !important;
}

/* 阅读详情：正文流中的槽位避免被祖先 content-visibility 等跳过布局（与列表流内嵌位一致） */
.leafs-reading-detail .leafs-entry-content .leafs-ad-slot,
.leafs-reading-detail .leafs-single-article .leafs-ad-slot,
.leafs-reading-detail .leafs-tool-article .leafs-ad-slot {
	content-visibility: visible;
}

.leafs-ad-slot__label {
	display: table;
	margin: 0 auto 10px;
	padding: 5px 12px;
	font-size: 11px;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--leafs-muted2);
	text-align: center;
	border-radius: 999px;
	background: color-mix(in srgb, var(--leafs-muted2) 10%, transparent);
	border: 1px solid color-mix(in srgb, var(--leafs-border) 55%, transparent);
	box-sizing: border-box;
}

.leafs-ad-slot__frame {
	margin-inline: auto;
	max-width: 100%;
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	justify-content: flex-start;
	min-height: 0;
	/*
	 * 勿用 overflow:hidden：个别环境下 AdSense 量宽异常；圆角交由子元素裁切。
	 * min-width：父级链若在某一帧为 0 宽，max(250px, …) 保证仍有可用横向尺寸。
	 */
	overflow: visible;
	min-width: max(250px, min(100%, calc(100vw - 32px)));
	border-radius: var(--leafs-ad-slot-radius);
	background: var(--leafs-ad-frame-bg);
	border: 1px dashed var(--leafs-ad-frame-border);
	box-shadow:
		0 1px 0 color-mix(in srgb, var(--leafs-border) 35%, transparent),
		0 10px 28px color-mix(in srgb, var(--leafs-text) 4%, transparent);
	transition:
		border-color 0.25s ease,
		background-color 0.25s ease,
		border-style 0.25s ease,
		box-shadow 0.25s ease;
	/* 为 AdSense 异步填充预留最小高度，减少布局抖动 */
	box-sizing: border-box;
}

@media (max-width: 420px) {
	.leafs-ad-slot__frame {
		min-width: max(200px, min(100%, calc(100vw - 16px)));
	}

	.leafs-ad-slot {
		padding-block: 8px;
	}
}

html[data-leafs-theme="dark"] .leafs-ad-slot {
	/* 深色下略提高边框辨识度，避免占位框融进背景 */
	--leafs-ad-frame-bg: color-mix(in srgb, var(--leafs-surface2) 55%, transparent);
	--leafs-ad-frame-border: color-mix(in srgb, var(--leafs-border) 78%, var(--leafs-muted) 22%);
}

html[data-leafs-theme="dark"] .leafs-ad-slot__frame {
	box-shadow:
		0 1px 0 color-mix(in srgb, var(--leafs-border) 45%, transparent),
		0 12px 32px rgba(0, 0, 0, 0.22);
}

html[data-leafs-theme="dark"] .leafs-ad-slot__label {
	color: var(--leafs-muted);
	opacity: 0.92;
	background: color-mix(in srgb, var(--leafs-muted) 14%, transparent);
	border-color: color-mix(in srgb, var(--leafs-border) 70%, transparent);
}

/* 已请求到广告时弱化「虚线占位」观感（Google 会为 ins 写入 data-ad-status） */
.leafs-ad-slot__frame:has(ins.adsbygoogle[data-ad-status="filled"]),
.leafs-ad-slot__frame.is-leafs-ad-filled {
	background: transparent;
	border-style: solid;
	border-color: color-mix(in srgb, var(--leafs-border) 42%, transparent);
	box-shadow: none;
}

html[data-leafs-theme="dark"] .leafs-ad-slot__frame:has(ins.adsbygoogle[data-ad-status="filled"]),
html[data-leafs-theme="dark"] .leafs-ad-slot__frame.is-leafs-ad-filled {
	border-color: color-mix(in srgb, var(--leafs-border) 62%, transparent);
	box-shadow: none;
}

/* 与 script/style 并列的包裹层也要拉满宽，避免内层 ins 实测宽度为 0 */
.leafs-ad-slot__frame > *:not(script):not(style) {
	width: 100%;
	max-width: 100%;
	box-sizing: border-box;
}

/*
 * AdSense 占位 ins：须占满容器宽度。勿对 flex 子项使用 align-items:center +
 * 无尺寸的 ins，否则 push() 时 availableWidth=0 触发 TagError。
 */
.leafs-ad-slot__frame ins.adsbygoogle {
	display: block !important;
	width: 100% !important;
	max-width: 100% !important;
	min-width: max(250px, min(100%, calc(100vw - 48px))) !important;
	box-sizing: border-box !important;
	margin-left: auto !important;
	margin-right: auto !important;
	border-radius: var(--leafs-ad-slot-radius);
}

/* 极窄视口：略降 ins 最小宽度，减少横向溢出（与 leafs-adsense-slot-push wideEnough 阈值一致） */
@media (max-width: 420px) {
	.leafs-ad-slot__frame ins.adsbygoogle {
		min-width: max(200px, min(100%, calc(100vw - 20px))) !important;
	}
}

.leafs-ad-slot__frame iframe {
	max-width: 100%;
	vertical-align: bottom;
}

.leafs-ad-below-header {
	padding-block: 14px 10px;
	margin-block-end: 2px;
	background: linear-gradient(
		180deg,
		color-mix(in srgb, var(--leafs-bg) 92%, var(--leafs-border)) 0%,
		color-mix(in srgb, var(--leafs-bg) 100%, transparent) 100%
	);
	border-bottom: 1px solid color-mix(in srgb, var(--leafs-border) 45%, transparent);
}

html[data-leafs-theme="dark"] .leafs-ad-below-header {
	background: linear-gradient(
		180deg,
		color-mix(in srgb, var(--leafs-surface) 88%, var(--leafs-border)) 0%,
		color-mix(in srgb, var(--leafs-bg) 100%, transparent) 100%
	);
	border-bottom-color: color-mix(in srgb, var(--leafs-border) 58%, transparent);
}

.leafs-ad-slot--below-header {
	width: 100%;
	max-width: 100%;
	padding-inline: 0;
	padding-block: 0;
}

.leafs-ad-slot--below-header .leafs-ad-slot__frame {
	min-height: 90px;
	width: 100%;
}

.leafs-ad-slot--home-below-toolbar {
	margin-top: 4px;
	margin-bottom: 14px;
	width: 100%;
}

/* —— 首页信息流：与 .leafs-card 同宽、卡片式外框 —— */
.leafs-card-list__ad--home-toolbar,
.leafs-card-list__ad--stream {
	width: 100%;
	min-width: 0;
	box-sizing: border-box;
	content-visibility: visible;
}

.leafs-card-list__ad--home-toolbar .leafs-ad-slot--home-below-toolbar {
	margin-block: 0;
	padding-block: 0;
}

.leafs-card-list__ad--stream .leafs-ad-slot--home-below-toolbar .leafs-ad-slot__frame {
	border-radius: var(--leafs-radius, 12px);
	border-style: solid;
	border-color: color-mix(in srgb, var(--leafs-border) 72%, transparent);
	background: color-mix(in srgb, var(--leafs-card) 96%, var(--leafs-brand) 4%);
	box-shadow: var(--leafs-shadow-card, 0 4px 14px color-mix(in srgb, var(--leafs-text) 6%, transparent));
}

html[data-leafs-theme="dark"] .leafs-card-list__ad--stream .leafs-ad-slot--home-below-toolbar .leafs-ad-slot__frame {
	background: color-mix(in srgb, var(--leafs-card) 92%, var(--leafs-surface2) 8%);
	border-color: color-mix(in srgb, var(--leafs-border) 65%, transparent);
}

.leafs-card-list__ad--stream .leafs-ad-slot--home-below-toolbar .leafs-ad-slot__frame:has(ins.adsbygoogle[data-ad-status="filled"]),
.leafs-card-list__ad--stream .leafs-ad-slot--home-below-toolbar .leafs-ad-slot__frame.is-leafs-ad-filled {
	border-color: color-mix(in srgb, var(--leafs-border) 48%, transparent);
}

/* —— 文章归档列表内嵌广告（共用 home_below_toolbar 单元） —— */
.leafs-pca__list-ad {
	width: 100%;
	min-width: 0;
	box-sizing: border-box;
	content-visibility: visible;
}

.leafs-pca__list-ad .leafs-ad-slot--home-below-toolbar {
	margin-block: 0;
	padding-block: 0;
}

/* 默认 / 图文 media：与 .leafs-pca-post 行卡片一致 */
.leafs-pca__list--media > .leafs-pca__list-ad,
.leafs-pca__list-ad--media {
	margin-bottom: 32px;
}

.leafs-pca__list-ad--media .leafs-ad-slot--home-below-toolbar .leafs-ad-slot__frame,
.leafs-pca__list--media > .leafs-pca__list-ad .leafs-ad-slot--home-below-toolbar .leafs-ad-slot__frame {
	border-radius: 16px;
	border-style: solid;
	border-color: color-mix(in srgb, var(--leafs-border) 80%, transparent);
	background: color-mix(in srgb, var(--leafs-card) 90%, transparent);
	box-shadow: 0 8px 22px color-mix(in srgb, var(--leafs-brand) 4%, transparent);
}

/* 文字 text：更紧凑，弱化阴影 */
.leafs-pca__list-ad--text .leafs-ad-slot--home-below-toolbar .leafs-ad-slot__frame,
.leafs-pca__list--text > .leafs-pca__list-ad .leafs-ad-slot--home-below-toolbar .leafs-ad-slot__frame {
	border-radius: 14px;
	min-height: 96px;
	box-shadow: 0 4px 16px color-mix(in srgb, var(--leafs-text) 5%, transparent);
}

/* 卡片 card：与 .leafs-pca-card 同系圆角与渐变底 */
.leafs-pca__list-ad--card .leafs-ad-slot--home-below-toolbar .leafs-ad-slot__frame,
.leafs-pca__list--card > .leafs-pca__list-ad .leafs-ad-slot--home-below-toolbar .leafs-ad-slot__frame {
	border-radius: 18px;
	border-style: solid;
	border-color: color-mix(in srgb, var(--leafs-border) 82%, transparent);
	background:
		linear-gradient(180deg, color-mix(in srgb, var(--leafs-card) 98%, var(--leafs-brand) 2%), var(--leafs-card));
	box-shadow:
		0 1px 0 color-mix(in srgb, var(--leafs-on-primary) 6%, transparent) inset,
		0 10px 28px color-mix(in srgb, var(--leafs-brand) 6%, transparent);
}

/*
 * 网格 grid：占一格（与文章卡片同列宽），外框对齐 .leafs-pca-grid-item；
 * 广告区 4:3（与 __media 一致）+ 底栏放 label，避免整行横幅破坏 2/3/4 列对齐。
 */
.leafs-pca__list--grid > .leafs-pca__list-ad.leafs-pca-grid-item--ad,
.leafs-pca__list-ad--grid.leafs-pca-grid-item--ad {
	margin: 0;
	min-width: 0;
	height: 100%;
	align-self: stretch;
	overflow: hidden;
}

.leafs-pca-grid-item--ad .leafs-ad-slot--home-below-toolbar {
	display: flex;
	flex-direction: column;
	flex: 1;
	min-height: 0;
	margin: 0;
	padding: 0;
	width: 100%;
	height: 100%;
}

.leafs-pca-grid-item--ad .leafs-ad-slot__frame {
	order: 1;
	flex: 0 0 auto;
	width: 100%;
	min-width: 0 !important;
	min-height: 0 !important;
	aspect-ratio: 4 / 3;
	margin: 0;
	border-radius: 0;
	border-left: none;
	border-right: none;
	border-top: none;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
}

.leafs-pca-grid-item--ad .leafs-ad-slot__frame ins.adsbygoogle {
	min-width: 0 !important;
	width: 100% !important;
	max-width: 100% !important;
	height: auto !important;
	max-height: 100%;
}

.leafs-pca-grid-item--ad .leafs-ad-slot__label {
	order: 2;
	flex: 1 1 auto;
	display: flex;
	align-items: center;
	justify-content: center;
	margin: 0;
	padding: 12px 14px 14px;
	font-size: 10px;
	letter-spacing: 0.04em;
	text-transform: none;
	border: none;
	border-radius: 0;
	background: transparent;
	border-top: 1px solid color-mix(in srgb, var(--leafs-border) 55%, transparent);
}

html[data-leafs-theme="dark"] .leafs-pca-grid-item--ad .leafs-ad-slot__label {
	border-top-color: color-mix(in srgb, var(--leafs-border) 70%, transparent);
}

@media (max-width: 639px) {
	.leafs-pca-grid-item--ad .leafs-ad-slot__frame {
		aspect-ratio: 16 / 10;
	}
}

.leafs-pca__list-ad .leafs-ad-slot__label {
	margin-bottom: 8px;
}

/*
 * 分类/标签文章列表内嵌广告：避免祖先 content-visibility（或其它 containment）
 * 跳过布局导致 ins 宽长期为 0、延后 push 失败（现象与首页信息流类似）。
 */
.leafs-pca__list > .leafs-pca__list-ad {
	content-visibility: visible;
}

.leafs-pca__list-ad .leafs-ad-slot--home-below-toolbar {
	margin-block: 0;
}

.leafs-pca__list-ad .leafs-ad-slot__frame {
	min-height: 100px;
	width: 100%;
}

.leafs-ad-slot--home-below-toolbar .leafs-ad-slot__frame {
	min-height: 100px;
	width: 100%;
}

/* 每日分享列表内（第 8 位）+ AI 资源导航右侧主栏底部（主题设置中共用同一单元代码） */
.leafs-ad-slot--daily-share-tools-nav-sidebar {
	margin-block: 0;
	width: 100%;
	max-width: 100%;
}

.leafs-daily-share__list-ad {
	width: 100%;
	min-width: 0;
	margin-block: 12px 18px;
	box-sizing: border-box;
	content-visibility: visible;
}

.leafs-daily-share__list-ad .leafs-ad-slot--daily-share-tools-nav-sidebar {
	padding-block: 0;
}

.leafs-daily-share__list-ad .leafs-ad-slot--daily-share-tools-nav-sidebar .leafs-ad-slot__frame {
	min-height: 120px;
	width: 100%;
	content-visibility: visible;
	border-radius: 14px;
	border-style: solid;
	border-color: color-mix(in srgb, var(--leafs-border) 75%, transparent);
	background: color-mix(in srgb, var(--leafs-card) 92%, transparent);
	box-shadow: 0 6px 20px color-mix(in srgb, var(--leafs-text) 5%, transparent);
}

.leafs-tools-nav__ad-main-bottom {
	width: 100%;
	min-width: 0;
	margin-top: clamp(16px, 3vw, 28px);
	box-sizing: border-box;
	content-visibility: visible;
}

.leafs-tools-nav__ad-main-bottom .leafs-ad-slot--daily-share-tools-nav-sidebar {
	padding-block: 0;
}

.leafs-tools-nav__ad-main-bottom .leafs-ad-slot--daily-share-tools-nav-sidebar .leafs-ad-slot__frame {
	min-height: 100px;
	width: 100%;
	border-radius: 14px;
	border-style: solid;
	border-color: color-mix(in srgb, var(--leafs-border) 78%, transparent);
	background: color-mix(in srgb, var(--leafs-card) 92%, transparent);
	box-shadow: 0 8px 22px color-mix(in srgb, var(--leafs-brand) 5%, transparent);
}

/* 工具归档标题下：横幅区与列表首项留白 */
.leafs-archive .leafs-ad-slot--archive-tools-below-header {
	margin-bottom: clamp(12px, 2vw, 20px);
}

.leafs-archive .leafs-ad-slot--archive-tools-below-header .leafs-ad-slot__frame {
	border-radius: 14px;
}

/* 外观 → 小工具「Lumo：谷歌广告」：侧栏宽度下的竖版/自适应单元 */
.leafs-ad-slot--sidebar-widget,
.lumo-widget-google-ad .leafs-ad-slot {
	margin-block: 0 14px;
	width: 100%;
	max-width: 100%;
}

.leafs-ad-slot--sidebar-widget .leafs-ad-slot__frame,
.lumo-widget-google-ad .leafs-ad-slot__frame {
	min-height: 250px;
	width: 100%;
	border-radius: 12px;
}

/* 侧栏内紧跟 AI 资源网格小工具：统一上下间距，避免双模块贴太紧 */
.lumo-widget-ai-resources + .lumo-widget-google-ad .leafs-ad-slot,
.lumo-widget-google-ad + .lumo-widget-ai-resources {
	margin-top: 12px;
}

.leafs-widget-area .lumo-widget-google-ad {
	min-width: 0;
	width: 100%;
}

.leafs-ad-slot--archive-tools-below-header {
	margin-bottom: 20px;
	width: 100%;
}

.leafs-ad-slot--archive-tools-below-header .leafs-ad-slot__frame {
	min-height: 100px;
	width: 100%;
}

/* 详情正文段落内插入：与上下段落留白（文章与工具共用；旧 class 保留兼容） */
.leafs-ad-slot--single-content-mid,
.leafs-ad-slot--single-tool-content-mid,
.leafs-ad-slot--single-post-content-mid {
	margin-block: 20px;
	width: 100%;
}

.leafs-ad-slot--single-content-mid .leafs-ad-slot__frame,
.leafs-ad-slot--single-tool-content-mid .leafs-ad-slot__frame,
.leafs-ad-slot--single-post-content-mid .leafs-ad-slot__frame {
	min-height: 120px;
	width: 100%;
}

.leafs-ad-slot--single-after-main-content {
	margin-block: 22px 18px;
	width: 100%;
}

.leafs-ad-slot--single-after-main-content .leafs-ad-slot__frame {
	min-height: 120px;
	width: 100%;
}

.leafs-ad-footer-above {
	background: color-mix(in srgb, var(--leafs-bg) 94%, var(--leafs-border));
	border-top: 1px solid color-mix(in srgb, var(--leafs-border) 65%, transparent);
}

html[data-leafs-theme="dark"] .leafs-ad-footer-above {
	background: color-mix(in srgb, var(--leafs-bg) 88%, var(--leafs-surface2));
	border-top-color: color-mix(in srgb, var(--leafs-border) 78%, transparent);
}

.leafs-ad-slot--footer-above {
	width: 100%;
	max-width: 100%;
	padding-inline: 0;
	padding-block: 10px 0;
}

.leafs-ad-slot--footer-above .leafs-ad-slot__frame {
	min-height: 90px;
	width: 100%;
}

/* 槽位宽度较窄时略降预留高度，减轻侧栏/窄正文列的空白与 CLS 折中 */
@container leafs-ad (max-width: 360px) {
	.leafs-ad-slot--below-header .leafs-ad-slot__frame {
		min-height: 76px;
	}

	.leafs-ad-slot--home-below-toolbar .leafs-ad-slot__frame,
	.leafs-pca__list-ad .leafs-ad-slot__frame,
	.leafs-card-list__ad--stream .leafs-ad-slot__frame {
		min-height: 88px;
	}

	.leafs-pca-grid-item--ad .leafs-ad-slot__frame {
		min-height: 0 !important;
	}

	.leafs-daily-share__list-ad .leafs-ad-slot--daily-share-tools-nav-sidebar .leafs-ad-slot__frame {
		min-height: 100px;
	}

	.leafs-tools-nav__ad-main-bottom .leafs-ad-slot--daily-share-tools-nav-sidebar .leafs-ad-slot__frame {
		min-height: 90px;
	}

	.leafs-ad-slot--sidebar-widget .leafs-ad-slot__frame {
		min-height: 200px;
	}

	.leafs-ad-slot--archive-tools-below-header .leafs-ad-slot__frame {
		min-height: 88px;
	}

	.leafs-ad-slot--single-content-mid .leafs-ad-slot__frame,
	.leafs-ad-slot--single-tool-content-mid .leafs-ad-slot__frame,
	.leafs-ad-slot--single-post-content-mid .leafs-ad-slot__frame,
	.leafs-ad-slot--single-after-main-content .leafs-ad-slot__frame {
		min-height: 100px;
	}

	.leafs-ad-slot--footer-above .leafs-ad-slot__frame {
		min-height: 76px;
	}
}

@container leafs-ad (max-width: 300px) {
	.leafs-ad-slot--sidebar-widget .leafs-ad-slot__frame {
		min-height: 180px;
	}

	.leafs-ad-slot--single-content-mid .leafs-ad-slot__frame,
	.leafs-ad-slot--single-tool-content-mid .leafs-ad-slot__frame,
	.leafs-ad-slot--single-post-content-mid .leafs-ad-slot__frame,
	.leafs-ad-slot--single-after-main-content .leafs-ad-slot__frame {
		min-height: 90px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.leafs-ad-slot,
	.leafs-ad-slot__frame {
		transition: none;
	}
}
