/*!
 * KL Push — opt-in prompt.
 *
 * The prompt has to look right on themes it has never met, and free themes
 * style bare elements hard: button { background; padding; height: 56px;
 * text-transform: uppercase; box-shadow; float }, p { margin; text-indent;
 * font-style }, svg { fill: currentColor }, button::before { content: "★" },
 * * { transition: all }. Element selectors like those beat plain class
 * selectors on every property they set, which is how a close button turns
 * into a pink slab on top of the title.
 *
 * So this file works in two layers:
 *
 *  1. Tokens (--klp-*) under :where(.klp-prompt) — zero specificity on
 *     purpose. A theme's `.klp-prompt { --klp-accent: … }`, and the plugin's
 *     own theme colours (KLP_Style), always override the defaults.
 *  2. Everything else under #klp-prompt. Each element of the card first drops
 *     every inherited and theme-set property (`all: unset` — custom properties
 *     are not affected), then gets exactly what is declared here. An id beats
 *     any element or class rule a theme writes; only a theme's !important or
 *     its own id selectors could still reach in.
 *
 * A theme that wants different markup turns the default off
 * (klp_render_default_prompt) and is not affected by any of this.
 */

/* --- 1. tokens ---------------------------------------------------------- */

:where(.klp-prompt) {
	--klp-bg: #ffffff;
	--klp-fg: #11161d;
	--klp-muted: #5b6673;
	--klp-line: rgba(17, 22, 29, .1);
	--klp-accent: #1f6feb;
	--klp-accent-fg: #ffffff;
	--klp-accent-hover: #1a5fd0;
	--klp-radius: 14px;
	--klp-shadow: 0 1px 2px rgba(17, 22, 29, .06), 0 12px 32px -8px rgba(17, 22, 29, .22);
	--klp-gap: 14px;
	--klp-z: 99990;
	/* Set by prompt.js to the height of a cookie bar on the same edge. */
	--klp-lift: 0px;
	--klp-lift-top: 0px;
}

/* Only for the default look. A themed prompt (theme tokens or colours set in
   the admin) follows the site instead: the theme already decides light or
   dark, and following the OS would put a white card on a dark site. */
@media (prefers-color-scheme: dark) {
	:where(.klp-prompt:not(.klp-prompt--themed)) {
		--klp-bg: #161b22;
		--klp-fg: #e8edf4;
		--klp-muted: #9aa7b6;
		--klp-line: rgba(232, 237, 244, .12);
		--klp-accent: #4b8ef7;
		--klp-accent-hover: #6aa2f9;
		--klp-accent-fg: #0b1118;
		--klp-shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 16px 40px -10px rgba(0, 0, 0, .6);
	}
}

/* --- 2. isolation ------------------------------------------------------- */

#klp-prompt,
#klp-prompt .klp-prompt__card,
#klp-prompt .klp-prompt__icon,
#klp-prompt .klp-prompt__icon img,
#klp-prompt .klp-prompt__body,
#klp-prompt .klp-prompt__title,
#klp-prompt .klp-prompt__text,
#klp-prompt .klp-prompt__actions,
#klp-prompt .klp-prompt__btn,
#klp-prompt .klp-prompt__close {
	all: unset;
	box-sizing: border-box;
}

/* Theme decorations hung on pseudo-elements (icons, ripples, "★ "). */
#klp-prompt *::before,
#klp-prompt *::after {
	content: none;
	display: none;
}

/* SVG internals are left out of `all: unset` — it would reset `d` and wipe
   the paths — and only the properties themes typically set are pinned. */
#klp-prompt svg {
	display: block;
	flex: none;
	width: 22px;
	height: 22px;
	max-width: none;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	box-shadow: none;
	float: none;
	position: static;
	overflow: visible;
	transition: none;
	vertical-align: middle;
}

#klp-prompt svg,
#klp-prompt svg * {
	fill: none;
	stroke: currentColor;
}

/* --- the root ----------------------------------------------------------- */

#klp-prompt {
	position: fixed;
	z-index: var(--klp-z);
	display: block;
	max-width: 100%;

	/* Every inherited property is fixed here, so none of the theme's body
	   typography (italic, justified, uppercase, letter-spaced…) leaks in.
	   The font family is the one thing deliberately taken from the site. */
	font-family: var(--klp-font, inherit);
	font-size: 15px;
	font-style: normal;
	font-weight: 400;
	line-height: 1.5;
	letter-spacing: normal;
	word-spacing: normal;
	text-align: left;
	text-indent: 0;
	text-transform: none;
	text-decoration: none;
	text-shadow: none;
	white-space: normal;
	overflow-wrap: break-word;
	color: var(--klp-fg);
	cursor: auto;
	visibility: visible;
	-webkit-font-smoothing: antialiased;
	-webkit-tap-highlight-color: transparent;

	/* The entry is animated from these; the shown state resets them. */
	opacity: 0;
	transform: translateY(12px);
	transition: opacity .24s ease, transform .24s ease, bottom .24s ease, top .24s ease;
}

[dir="rtl"] #klp-prompt {
	text-align: right;
}

#klp-prompt[hidden] {
	display: none;
}

/* The ask and the confirmation states swap with the hidden attribute, which
   the reset above would otherwise turn back into display: block. */
#klp-prompt [hidden] {
	display: none !important;
}

#klp-prompt.klp-prompt--shown {
	opacity: 1;
	transform: translateY(0);
}

/* --- the card ----------------------------------------------------------- */

#klp-prompt .klp-prompt__card {
	position: relative;
	display: grid;
	grid-template-columns: auto 1fr;
	gap: var(--klp-gap);
	width: 100%;
	padding: 18px 20px;
	background: var(--klp-bg);
	color: var(--klp-fg);
	border: 1px solid var(--klp-line);
	border-radius: var(--klp-radius);
	box-shadow: var(--klp-shadow);
}

#klp-prompt .klp-prompt__icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border-radius: 11px;
	background: rgba(31, 111, 235, .12);
	background: color-mix(in srgb, var(--klp-accent) 12%, transparent);
	color: var(--klp-accent);
	overflow: hidden;
}

#klp-prompt .klp-prompt__icon img {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: cover;
	border-radius: inherit;
}

#klp-prompt .klp-prompt__body {
	display: block;
	min-width: 0;
}

#klp-prompt .klp-prompt__title {
	display: block;
	margin: 0 0 4px;
	padding-right: 26px;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.4;
	letter-spacing: -.01em;
	color: var(--klp-fg);
}

#klp-prompt .klp-prompt__text {
	display: block;
	margin: 0;
	font-size: 13.5px;
	line-height: 1.5;
	color: var(--klp-muted);
}

#klp-prompt .klp-prompt__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	grid-column: 2;
	margin-top: 14px;
}

/* --- buttons ------------------------------------------------------------ */

#klp-prompt .klp-prompt__btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 1 auto;
	min-height: 38px;
	padding: 9px 16px;
	font-size: 13.5px;
	font-weight: 600;
	line-height: 1.2;
	text-align: center;
	border: 1px solid transparent;
	border-radius: 9px;
	cursor: pointer;
	user-select: none;
	transition: background-color .16s ease, border-color .16s ease, color .16s ease;
}

#klp-prompt .klp-prompt__btn--allow {
	order: 2;
	background: var(--klp-accent);
	color: var(--klp-accent-fg);
}

#klp-prompt .klp-prompt__btn--allow:hover,
#klp-prompt .klp-prompt__btn--allow:active {
	background: var(--klp-accent-hover);
	color: var(--klp-accent-fg);
}

#klp-prompt .klp-prompt__btn--deny {
	order: 1;
	background: transparent;
	color: var(--klp-muted);
}

#klp-prompt .klp-prompt__btn--deny:hover,
#klp-prompt .klp-prompt__btn--deny:active {
	background: rgba(17, 22, 29, .06);
	background: color-mix(in srgb, var(--klp-fg) 6%, transparent);
	color: var(--klp-fg);
}

/* The close button: a quiet square in the corner, never a themed "button". */
#klp-prompt .klp-prompt__close {
	position: absolute;
	top: 10px;
	right: 10px;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	color: var(--klp-muted);
	background: transparent;
	border: 0;
	border-radius: 8px;
	cursor: pointer;
	transition: background-color .16s ease, color .16s ease;
}

#klp-prompt .klp-prompt__close svg {
	width: 16px;
	height: 16px;
}

#klp-prompt .klp-prompt__close:hover,
#klp-prompt .klp-prompt__close:active {
	background: rgba(17, 22, 29, .07);
	background: color-mix(in srgb, var(--klp-fg) 7%, transparent);
	color: var(--klp-fg);
}

/* A visible focus ring is not optional: the modal takes focus when it opens,
   so a keyboard user must be able to see where they are. */
#klp-prompt .klp-prompt__btn:focus-visible,
#klp-prompt .klp-prompt__close:focus-visible {
	outline: 2px solid var(--klp-accent);
	outline-offset: 2px;
}

/* --- positions ---------------------------------------------------------- */

#klp-prompt.klp-prompt--corner {
	right: 20px;
	bottom: calc(20px + var(--klp-lift));
	width: 380px;
}

#klp-prompt.klp-prompt--toast {
	top: calc(20px + var(--klp-lift-top));
	left: 50%;
	width: 420px;
	transform: translate(-50%, -12px);
}

#klp-prompt.klp-prompt--toast.klp-prompt--shown {
	transform: translate(-50%, 0);
}

#klp-prompt.klp-prompt--bar {
	right: 0;
	bottom: var(--klp-lift);
	left: 0;
	width: 100%;
}

#klp-prompt.klp-prompt--bar .klp-prompt__card {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	max-width: 1180px;
	margin: 0 auto 12px;
	/* The close button is absolutely positioned, while the actions are pushed
	   to the right edge — without a reserved gutter the two overlap. */
	padding-right: 56px;
}

/* In a single row the gutter already keeps the title clear of the button. */
#klp-prompt.klp-prompt--bar .klp-prompt__title {
	padding-right: 0;
}

#klp-prompt.klp-prompt--bar .klp-prompt__body {
	flex: 1 1 320px;
}

#klp-prompt.klp-prompt--bar .klp-prompt__actions {
	grid-column: auto;
	margin-top: 0;
	margin-left: auto;
}

/* The modal is the one variant that dims the page, so it gets a backdrop and a
   centred card. */
#klp-prompt.klp-prompt--modal {
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20px;
	background: rgba(9, 12, 17, .45);
	backdrop-filter: blur(2px);
	transform: none;
}

#klp-prompt.klp-prompt--modal[hidden] {
	display: none;
}

#klp-prompt.klp-prompt--modal.klp-prompt--shown {
	transform: none;
}

#klp-prompt.klp-prompt--modal .klp-prompt__card {
	width: 440px;
	max-width: 100%;
	transform: translateY(12px) scale(.98);
	transition: transform .24s ease;
}

#klp-prompt.klp-prompt--modal.klp-prompt--shown .klp-prompt__card {
	transform: translateY(0) scale(1);
}

/* --- mobile ------------------------------------------------------------- */

@media (max-width: 600px) {
	/* On a phone every variant becomes the same thing: a sheet pinned to the
	   bottom, within thumb reach and never covering the whole article. */
	#klp-prompt.klp-prompt--corner,
	#klp-prompt.klp-prompt--toast,
	#klp-prompt.klp-prompt--bar {
		top: auto;
		right: 10px;
		bottom: calc(10px + var(--klp-lift));
		left: 10px;
		width: auto;
		transform: translateY(14px);
	}

	#klp-prompt.klp-prompt--corner.klp-prompt--shown,
	#klp-prompt.klp-prompt--toast.klp-prompt--shown,
	#klp-prompt.klp-prompt--bar.klp-prompt--shown {
		transform: translateY(0);
	}

	#klp-prompt .klp-prompt__card,
	#klp-prompt.klp-prompt--bar .klp-prompt__card {
		display: grid;
		margin-bottom: 0;
		padding: 16px;
		/* Keep clear of the iOS home indicator and Android gesture bar. */
		padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
	}

	/* The title keeps room for the close button in every variant. */
	#klp-prompt.klp-prompt--bar .klp-prompt__title {
		padding-right: 26px;
	}

	#klp-prompt .klp-prompt__actions,
	#klp-prompt.klp-prompt--bar .klp-prompt__actions {
		grid-column: 1 / -1;
		margin-left: 0;
	}

	#klp-prompt .klp-prompt__btn {
		flex: 1 1 auto;
		min-height: 44px;
	}
}

/* --- reduced motion ----------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	#klp-prompt,
	#klp-prompt .klp-prompt__card,
	#klp-prompt .klp-prompt__btn,
	#klp-prompt .klp-prompt__close {
		transition: none;
	}

	#klp-prompt {
		transform: none;
	}

	#klp-prompt.klp-prompt--toast,
	#klp-prompt.klp-prompt--toast.klp-prompt--shown {
		transform: translateX(-50%);
	}
}

/* === "While you were away" (missed.js) ==================================

   A separate element with the same two layers as the prompt: the --klp-*
   tokens come from :where(.klp-prompt) above (the root carries that class, and
   the themed one when the theme sets the colours), everything else is pinned
   under #klp-missed so the theme's element rules cannot reach in. */

#klp-missed,
#klp-missed .klp-missed__card,
#klp-missed .klp-missed__head,
#klp-missed .klp-missed__icon,
#klp-missed .klp-missed__title,
#klp-missed .klp-missed__list,
#klp-missed .klp-missed__row,
#klp-missed .klp-missed__item,
#klp-missed .klp-missed__thumb,
#klp-missed .klp-missed__text,
#klp-missed .klp-missed__name,
#klp-missed .klp-missed__time,
#klp-missed .klp-missed__more,
#klp-missed .klp-missed__close {
	all: unset;
	box-sizing: border-box;
}

#klp-missed *::before,
#klp-missed *::after {
	content: none;
	display: none;
}

#klp-missed svg {
	display: block;
	flex: none;
	width: 16px;
	height: 16px;
	max-width: none;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	box-shadow: none;
	float: none;
	position: static;
	overflow: visible;
	transition: none;
}

#klp-missed svg,
#klp-missed svg * {
	fill: none;
	stroke: currentColor;
}

#klp-missed {
	position: fixed;
	right: 20px;
	bottom: calc(20px + var(--klp-lift));
	z-index: var(--klp-z);
	display: block;
	width: 360px;
	max-width: calc(100% - 40px);

	font-family: var(--klp-font, inherit);
	font-size: 15px;
	font-style: normal;
	font-weight: 400;
	line-height: 1.5;
	letter-spacing: normal;
	text-align: left;
	text-transform: none;
	text-decoration: none;
	white-space: normal;
	overflow-wrap: break-word;
	color: var(--klp-fg);
	visibility: visible;
	-webkit-font-smoothing: antialiased;
	-webkit-tap-highlight-color: transparent;

	opacity: 0;
	transform: translateY(12px);
	transition: opacity .24s ease, transform .24s ease, bottom .24s ease;
}

[dir="rtl"] #klp-missed {
	right: auto;
	left: 20px;
	text-align: right;
}

#klp-missed.klp-missed--shown {
	opacity: 1;
	transform: translateY(0);
}

#klp-missed .klp-missed__card {
	position: relative;
	display: block;
	width: 100%;
	padding: 16px 16px 12px;
	background: var(--klp-bg);
	color: var(--klp-fg);
	border: 1px solid var(--klp-line);
	border-radius: var(--klp-radius);
	box-shadow: var(--klp-shadow);
}

#klp-missed .klp-missed__head {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 0 0 8px;
	padding-right: 30px;
}

#klp-missed .klp-missed__icon {
	display: block;
	flex: none;
	width: 24px;
	height: 24px;
	border-radius: 6px;
	object-fit: cover;
}

#klp-missed .klp-missed__title {
	display: block;
	margin: 0;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.4;
	letter-spacing: -.01em;
	color: var(--klp-fg);
}

#klp-missed .klp-missed__list {
	display: block;
	margin: 0;
	padding: 0;
	list-style: none;
}

#klp-missed .klp-missed__row {
	display: block;
	margin: 0;
	padding: 0;
	list-style: none;
}

#klp-missed .klp-missed__row + .klp-missed__row {
	border-top: 1px solid var(--klp-line);
}

#klp-missed .klp-missed__item {
	display: flex;
	align-items: center;
	gap: 12px;
	margin: 0 -8px;
	padding: 8px;
	border-radius: 9px;
	color: var(--klp-fg);
	text-decoration: none;
	cursor: pointer;
	transition: background-color .16s ease;
}

#klp-missed .klp-missed__item:hover,
#klp-missed .klp-missed__item:active {
	background: rgba(17, 22, 29, .05);
	background: color-mix(in srgb, var(--klp-fg) 5%, transparent);
}

#klp-missed .klp-missed__thumb {
	display: block;
	flex: none;
	width: 44px;
	height: 44px;
	border-radius: 8px;
	object-fit: cover;
	background: var(--klp-line);
}

#klp-missed .klp-missed__text {
	display: block;
	flex: 1 1 auto;
	min-width: 0;
}

#klp-missed .klp-missed__name {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	overflow: hidden;
	font-size: 13.5px;
	font-weight: 500;
	line-height: 1.35;
	color: var(--klp-fg);
}

#klp-missed .klp-missed__time {
	display: block;
	margin-top: 2px;
	font-size: 12px;
	line-height: 1.3;
	color: var(--klp-muted);
}

#klp-missed .klp-missed__more {
	display: inline-block;
	margin: 6px 0 2px;
	font-size: 13.5px;
	font-weight: 600;
	color: var(--klp-accent);
	text-decoration: none;
	cursor: pointer;
}

#klp-missed .klp-missed__more:hover {
	text-decoration: underline;
}

#klp-missed .klp-missed__close {
	position: absolute;
	top: 10px;
	right: 10px;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	color: var(--klp-muted);
	background: transparent;
	border: 0;
	border-radius: 8px;
	cursor: pointer;
	transition: background-color .16s ease, color .16s ease;
}

[dir="rtl"] #klp-missed .klp-missed__close {
	right: auto;
	left: 10px;
}

#klp-missed .klp-missed__close:hover,
#klp-missed .klp-missed__close:active {
	background: rgba(17, 22, 29, .07);
	background: color-mix(in srgb, var(--klp-fg) 7%, transparent);
	color: var(--klp-fg);
}

#klp-missed .klp-missed__item:focus-visible,
#klp-missed .klp-missed__more:focus-visible,
#klp-missed .klp-missed__close:focus-visible {
	outline: 2px solid var(--klp-accent);
	outline-offset: 2px;
}

@media (max-width: 600px) {
	/* A sheet at the bottom, like the prompt on a phone. */
	#klp-missed {
		right: 10px;
		bottom: calc(10px + var(--klp-lift));
		left: 10px;
		width: auto;
		max-width: none;
	}

	#klp-missed .klp-missed__card {
		padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
	}
}

@media (prefers-reduced-motion: reduce) {
	#klp-missed,
	#klp-missed .klp-missed__item,
	#klp-missed .klp-missed__close {
		transition: none;
	}

	#klp-missed {
		transform: none;
	}
}
