/* ==========================================================================
   Sticky affiliate ads — loaded only on posts that use a [sticky_ad_*]
   shortcode (see inc/affiliate-ads.php). Kept in its own file so it never
   adds weight to pages that don't need it.
   ========================================================================== */

.sticky-ad {
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 60;
	/* Shrinks to fit whatever image is pasted (no left+right, so the box
	   is shrink-to-fit sized); this is just a safety ceiling so an
	   unusually large banner can't take over the screen. */
	max-width: min(400px, calc(100vw - 40px));
	background: #fff;
	border: 1px solid var(--color-border);
	border-radius: var(--radius-md);
	box-shadow: 0 4px 16px rgba(17, 17, 17, 0.1);
	padding: 36px 8px 8px;
	opacity: 0;
	transform: translateY(12px);
	pointer-events: none;
	transition: opacity 0.3s ease, transform 0.3s ease;
}

.sticky-ad.is-visible {
	opacity: 1;
	transform: translateY(0);
	pointer-events: auto;
}

.sticky-ad-close {
	position: absolute;
	top: 2px;
	right: 4px;
	width: 32px;
	height: 32px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: none;
	border: none;
	border-radius: 50%;
	color: var(--color-text-muted);
	font-size: 24px;
	line-height: 1;
	cursor: pointer;
	transition: background-color 0.2s ease, color 0.2s ease;
}

.sticky-ad-close:hover {
	background: var(--color-bg-subtle);
	color: var(--color-accent);
}

.sticky-ad-body {
	max-width: 100%;
	overflow: hidden;
	text-align: center;
	line-height: 0;
}

.sticky-ad-body img {
	max-width: 100%;
	height: auto;
}

/* Generic mobile treatment for future sticky ads that opt into it:
   a compact bar pinned to the bottom edge instead of a floating box. */
@media (max-width: 767px) {
	.sticky-ad {
		left: 0;
		right: 0;
		bottom: 0;
		max-width: none;
		width: 100%;
		border-radius: 0;
		border-left: none;
		border-right: none;
		border-bottom: none;
		padding: 8px 40px 8px 12px;
		box-shadow: 0 -2px 10px rgba(17, 17, 17, 0.08);
	}

	.sticky-ad-body {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.sticky-ad-close {
		top: 50%;
		right: 8px;
		transform: translateY(-50%);
	}
}

/* --------------------------------------------------------------------------
   PC / スマホでバナーを出し分ける広告（chiikoto_render_sticky_ad() に
   ['desktop' => ..., 'mobile' => ...] を渡すと、それぞれ
   sticky-ad-{slug}--desktop / sticky-ad-{slug}--mobile というクラスの
   ラッパーが出力される）向けの汎用ルール。

   [class*="--desktop"] / [class*="--mobile"] という部分一致セレクタに
   しているので、広告(slug)ごとに個別CSSを書かなくても、この構造で
   実装すればどの広告にも自動的に適用される。画像サイズも決め打ちにせず、
   貼った画像の実寸に合わせて縮む（安全のため上限だけ設定）。
   -------------------------------------------------------------------------- */
.sticky-ad[class*="--desktop"],
.sticky-ad[class*="--mobile"] {
	display: none;
}

@media (min-width: 768px) {
	.sticky-ad[class*="--desktop"] {
		display: block;
	}
}

@media (max-width: 767px) {
	.sticky-ad[class*="--mobile"] {
		display: block;
		left: auto;
		right: 10px;
		bottom: 10px;
		width: auto;
		max-width: calc(100vw - 20px);
		border: 1px solid var(--color-border);
		border-radius: var(--radius-md);
		box-shadow: 0 4px 16px rgba(17, 17, 17, 0.1);
		padding: 32px 6px 6px;
	}

	.sticky-ad[class*="--mobile"] .sticky-ad-body {
		display: block;
	}

	.sticky-ad[class*="--mobile"] .sticky-ad-close {
		top: 2px;
		right: 2px;
		transform: none;
		width: 28px;
		height: 28px;
		font-size: 20px;
	}
}
