/*
 * KDN Article Parts Phase 1.
 * Front end is scoped by .kdn-ap-article. The editor uses .editor-styles-wrapper.
 */

:is(.kdn-ap-article, .editor-styles-wrapper) {
	color: var(--kdn-ap-text);
	line-height: var(--kdn-ap-reading-line);
}

:is(.kdn-ap-article, .editor-styles-wrapper) :where(p, ul, ol) {
	line-height: var(--kdn-ap-reading-line);
}

/*
 * Key point marker: one concise answer immediately after an H2/H3.
 * The paragraph stays unboxed; only its strong sentence receives a soft mark.
 */
:is(.kdn-ap-article, .editor-styles-wrapper) p.is-style-kdn-key-point {
	margin-block: 0 0.85em;
	color: var(--kdn-ap-ink);
	font-size: 1.02em;
	line-height: 1.8;
}

:is(.kdn-ap-article, .editor-styles-wrapper) p.is-style-kdn-key-point > strong:only-child {
	padding-inline: 0.08em;
	background:
		linear-gradient(
			to bottom,
			transparent 56%,
			var(--kdn-ap-marker) 56%,
			var(--kdn-ap-marker) 91%,
			var(--kdn-ap-marker-edge) 91%,
			var(--kdn-ap-marker-edge) 96%,
			transparent 96%
		);
	color: inherit;
	font-weight: 700;
	-webkit-box-decoration-break: clone;
	box-decoration-break: clone;
}

/* H2: soft section band with a reliable teal anchor. */
:is(.kdn-ap-article, .editor-styles-wrapper) h2.wp-block-heading:is(.is-style-kdn-section, .is-style-kdn-section-numbered) {
	position: relative;
	margin-block: clamp(42px, 8vw, 68px) 24px;
	padding: 0.72em 1em 0.72em 1.15em;
	border: 0;
	border-left: 5px solid var(--kdn-ap-teal);
	border-radius: 0 var(--kdn-ap-radius-md) var(--kdn-ap-radius-md) 0;
	background: linear-gradient(100deg, var(--kdn-ap-teal-soft) 0%, rgba(234, 246, 243, 0.5) 76%, rgba(255, 255, 255, 0) 100%);
	color: var(--kdn-ap-ink);
	font-size: clamp(1.35rem, 1.08rem + 1.1vw, 1.8rem);
	font-weight: 700;
	letter-spacing: 0.025em;
	line-height: 1.55;
}

:is(.kdn-ap-article, .editor-styles-wrapper) {
	counter-reset: kdn-ap-section;
}

:is(.kdn-ap-article, .editor-styles-wrapper) h2.wp-block-heading.is-style-kdn-section-numbered {
	counter-increment: kdn-ap-section;
	display: flex;
	align-items: center;
	gap: 0.65em;
}

:is(.kdn-ap-article, .editor-styles-wrapper) h2.wp-block-heading.is-style-kdn-section-numbered::before {
	content: counter(kdn-ap-section);
	display: inline-grid;
	flex: 0 0 2rem;
	width: 2rem;
	height: 2rem;
	place-items: center;
	border-radius: 999px;
	background: var(--kdn-ap-teal);
	color: #fff;
	font-size: 0.82em;
	font-weight: 700;
	line-height: 1;
}

/* H3: lighter than H2, with both shape and line communicating hierarchy. */
:is(.kdn-ap-article, .editor-styles-wrapper) h3.wp-block-heading.is-style-kdn-subsection {
	position: relative;
	margin-block: clamp(32px, 6vw, 48px) 18px;
	padding: 0 0 0.55em 1.05em;
	border: 0;
	border-bottom: 2px dotted #9cc9c3;
	background: transparent;
	color: var(--kdn-ap-ink);
	font-size: clamp(1.18rem, 1.03rem + 0.55vw, 1.45rem);
	font-weight: 700;
	line-height: 1.55;
}

:is(.kdn-ap-article, .editor-styles-wrapper) h3.wp-block-heading.is-style-kdn-subsection::before {
	content: "";
	position: absolute;
	left: 0;
	top: 0.58em;
	width: 0;
	height: 0;
	border-block: 0.34em solid transparent;
	border-left: 0.48em solid var(--kdn-ap-teal);
}

/* Semantic boxes. Text labels remain in markup; color is never the only cue. */
:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap {
	position: relative;
	box-sizing: border-box;
	margin-block: var(--kdn-ap-space-block);
	padding: var(--kdn-ap-space-inner);
	border: 1px solid var(--kdn-ap-line);
	border-radius: var(--kdn-ap-radius-md);
	background: var(--kdn-ap-paper);
	box-shadow: var(--kdn-ap-shadow);
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap > :first-child {
	margin-top: 0;
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap > :last-child {
	margin-bottom: 0;
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap__label {
	display: flex;
	align-items: center;
	gap: 0.5em;
	margin-bottom: 0.55em;
	font-size: 0.96rem;
	font-weight: 700;
	letter-spacing: 0.025em;
	line-height: 1.5;
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap__label::before {
	content: "";
	width: 0.72em;
	height: 0.72em;
	border: 2px solid currentColor;
	border-radius: 999px;
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--answer {
	border-color: #f1c4c2;
	background: linear-gradient(135deg, var(--kdn-ap-pink-bg), #fffaf8);
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--answer .kdn-ap__label {
	color: var(--kdn-ap-pink-ink);
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--question {
	margin-left: clamp(10px, 4vw, 34px);
	border-color: #acd7d2;
	background: #fff;
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--question::after {
	content: "";
	position: absolute;
	left: 24px;
	bottom: -9px;
	width: 16px;
	height: 16px;
	border-right: 1px solid #acd7d2;
	border-bottom: 1px solid #acd7d2;
	background: #fff;
	transform: rotate(45deg);
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--question .kdn-ap__label {
	color: var(--kdn-ap-teal-strong);
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--point {
	border-color: #eed59e;
	background: linear-gradient(135deg, var(--kdn-ap-cream-bg), #fffdf6);
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--point .kdn-ap__label {
	color: var(--kdn-ap-cream-ink);
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--family {
	border-color: #b9dfe8;
	background: linear-gradient(135deg, var(--kdn-ap-blue-bg), #f9fdfe);
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--family .kdn-ap__label {
	color: var(--kdn-ap-blue-ink);
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--warning {
	border-color: #efb9b3;
	background: linear-gradient(135deg, var(--kdn-ap-alert-bg), #fff9f8);
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--warning .kdn-ap__label {
	color: #a9444d;
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--confirm {
	border-color: #b9d9ca;
	background: linear-gradient(135deg, var(--kdn-ap-mint-bg), #f9fdfb);
}

:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--confirm .kdn-ap__label {
	color: var(--kdn-ap-mint-ink);
}

/* Lists organize information vertically. */
:is(.kdn-ap-article, .editor-styles-wrapper) :is(ul.is-style-kdn-checklist, ul.is-style-kdn-icon-list, ol.is-style-kdn-steps) {
	box-sizing: border-box;
	margin-block: var(--kdn-ap-space-block);
	padding: var(--kdn-ap-space-inner);
	border-radius: var(--kdn-ap-radius-md);
	list-style: none;
}

:is(.kdn-ap-article, .editor-styles-wrapper) ul.is-style-kdn-checklist {
	border: 1px solid #c9ddc5;
	background: #f6faf2;
}

:is(.kdn-ap-article, .editor-styles-wrapper) ul.is-style-kdn-icon-list {
	border: 1px solid #c6dfe0;
	background: #f5fbfb;
}

:is(.kdn-ap-article, .editor-styles-wrapper) :is(ul.is-style-kdn-checklist, ul.is-style-kdn-icon-list) > li {
	position: relative;
	margin: 0;
	padding-left: 1.8em;
}

:is(.kdn-ap-article, .editor-styles-wrapper) :is(ul.is-style-kdn-checklist, ul.is-style-kdn-icon-list) > li + li {
	margin-top: 0.55em;
}

:is(.kdn-ap-article, .editor-styles-wrapper) ul.is-style-kdn-checklist > li::before {
	content: "✓";
	position: absolute;
	left: 0;
	top: 0.22em;
	display: grid;
	width: 1.25em;
	height: 1.25em;
	place-items: center;
	border: 1px solid #77a66e;
	border-radius: 4px;
	color: #3d7041;
	font-size: 0.78em;
	font-weight: 700;
	line-height: 1;
}

:is(.kdn-ap-article, .editor-styles-wrapper) ul.is-style-kdn-icon-list > li::before {
	content: "";
	position: absolute;
	left: 0.28em;
	top: 0.78em;
	width: 0.52em;
	height: 0.52em;
	border-radius: 999px;
	background: var(--kdn-ap-teal);
}

:is(.kdn-ap-article, .editor-styles-wrapper) ol.is-style-kdn-steps {
	counter-reset: kdn-ap-step;
	border: 1px solid #c9e1dc;
	background: #f8fcfb;
}

:is(.kdn-ap-article, .editor-styles-wrapper) ol.is-style-kdn-steps > li {
	counter-increment: kdn-ap-step;
	position: relative;
	min-height: 2rem;
	margin: 0;
	padding: 0.15em 0 0.15em 2.8em;
}

:is(.kdn-ap-article, .editor-styles-wrapper) ol.is-style-kdn-steps > li + li {
	margin-top: 0.85em;
}

:is(.kdn-ap-article, .editor-styles-wrapper) ol.is-style-kdn-steps > li::before {
	content: counter(kdn-ap-step);
	position: absolute;
	left: 0;
	top: 0;
	display: grid;
	width: 2rem;
	height: 2rem;
	place-items: center;
	border-radius: 999px;
	background: var(--kdn-ap-teal);
	color: #fff;
	font-weight: 700;
	line-height: 1;
}

/* Comparison tables show only a quick horizontal overview. */
:is(.kdn-ap-article, .editor-styles-wrapper) figure.wp-block-table.is-style-kdn-comparison {
	margin-block: var(--kdn-ap-space-block);
	overflow-x: auto;
	border: 1px solid var(--kdn-ap-line);
	border-radius: var(--kdn-ap-radius-md);
	background: #fff;
	box-shadow: var(--kdn-ap-shadow);
	-webkit-overflow-scrolling: touch;
}

:is(.kdn-ap-article, .editor-styles-wrapper) figure.wp-block-table.is-style-kdn-comparison table {
	min-width: 32rem;
	margin: 0;
	border: 0;
	border-collapse: collapse;
	font-size: 0.94rem;
	line-height: 1.65;
}

:is(.kdn-ap-article, .editor-styles-wrapper) figure.wp-block-table.is-style-kdn-comparison :is(th, td) {
	padding: 0.78em 0.72em;
	border: 1px solid var(--kdn-ap-line);
	vertical-align: middle;
	text-align: center;
}

:is(.kdn-ap-article, .editor-styles-wrapper) figure.wp-block-table.is-style-kdn-comparison thead th {
	background: var(--kdn-ap-teal-soft);
	color: var(--kdn-ap-ink);
	font-weight: 700;
}

:is(.kdn-ap-article, .editor-styles-wrapper) figure.wp-block-table.is-style-kdn-comparison tbody th {
	background: var(--kdn-ap-cream-bg);
	color: var(--kdn-ap-ink);
	font-weight: 700;
}

:is(.kdn-ap-article, .editor-styles-wrapper) figure.wp-block-table.is-style-kdn-comparison figcaption {
	margin: 0;
	padding: 0.7em 1em;
	color: var(--kdn-ap-muted);
	font-size: 0.82rem;
	line-height: 1.65;
	text-align: left;
}

/* Rendered automatically for comparison tables; hidden until a mobile viewport. */
:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap-comparison-scroll-hint {
	display: none;
}

@media (max-width: 599px) {
	:is(.kdn-ap-article, .editor-styles-wrapper) {
		--kdn-ap-space-block: clamp(18px, 5vw, 24px);
		--kdn-ap-space-inner: 14px;
	}

	:is(.kdn-ap-article, .editor-styles-wrapper) p,
	:is(.kdn-ap-article, .editor-styles-wrapper) li {
		font-size: 15px;
		line-height: 1.75;
	}

	:is(.kdn-ap-article, .editor-styles-wrapper) p {
		margin-block: 0 0.78em;
	}

	:is(.kdn-ap-article, .editor-styles-wrapper) p.is-style-kdn-key-point {
		margin-block: 0 0.7em;
		font-size: 15px;
		line-height: 1.75;
	}

	:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--answer {
		padding: 14px 15px;
	}

	:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--answer > .kdn-ap__label {
		position: static;
		inset: auto;
		display: flex;
		min-height: 1.5em;
		margin: 0 0 0.7em;
		padding: 0;
		opacity: 1;
		visibility: visible;
		transform: none;
		color: var(--kdn-ap-pink-ink);
		font-size: 0.9rem;
		line-height: 1.4;
	}

	:is(.kdn-ap-article, .editor-styles-wrapper) h2.wp-block-heading:is(.is-style-kdn-section, .is-style-kdn-section-numbered) {
		padding-inline: 0.82em;
	}

	:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap--question {
		margin-left: 8px;
	}

	:is(.kdn-ap-article, .editor-styles-wrapper) figure.wp-block-table.is-style-kdn-comparison table {
		width: max-content;
		max-width: none;
		min-width: 30rem;
		margin-inline: 0;
	}

	:is(.kdn-ap-article, .editor-styles-wrapper) figure.wp-block-table.is-style-kdn-comparison {
		width: 100%;
		max-width: 100%;
		margin-inline: 0;
		margin-bottom: 0.45rem;
		text-align: left;
	}

	:is(.kdn-ap-article, .editor-styles-wrapper) .kdn-ap-comparison-scroll-hint {
		display: block;
		margin: 0 0 var(--kdn-ap-space-block);
		padding-inline: 0.15rem;
		color: var(--kdn-ap-muted);
		font-size: 0.78rem;
		line-height: 1.5;
		text-align: left;
	}
}

@media (prefers-reduced-motion: reduce) {
	:is(.kdn-ap-article, .editor-styles-wrapper) * {
		scroll-behavior: auto;
	}
}
