/**
 * Next Country Blocks — front end + editor.
 *
 * Every colour is a theme colour token (--wp--preset--color--*) or a color-mix() of tokens, so the blocks
 * follow the theme's light palette and Next Dark Mode Toggle's dark token values without extra settings.
 * Token choices made in the block sidebar are written as inline custom properties (--ncb-accent …).
 */

/* ------------------------------------------------------------------ tokens */

.ncb {
	--ncb-text: var(--wp--preset--color--contrast, var(--wp--preset--color--main, var(--wp--preset--color--foreground, #16171a)));
	--ncb-bg: var(--wp--preset--color--base, var(--wp--preset--color--background, #ffffff));
	--ncb-accent: var(--wp--preset--color--brand, var(--wp--preset--color--primary, var(--wp--preset--color--accent-1, var(--wp--preset--color--accent, var(--ncb-accent-fb)))));
	--ncb-alert: var(--ncb-alert-fb);
	--ncb-success: var(--ncb-success-fb);

	/* Fallback colours when no theme token is chosen (dark-mode values are added by PHP for Next Dark Mode Toggle). */
	--ncb-accent-fb: #f5b70a;
	--ncb-alert-fb: #e5674c;
	--ncb-success-fb: #2fae6b;

	/* Derived (all overridable from the sidebar). */
	--ncb-surface: color-mix(in srgb, var(--ncb-text) 5%, var(--ncb-bg));
	--ncb-surface-hover: color-mix(in srgb, var(--ncb-text) 8%, var(--ncb-bg));
	--ncb-border: color-mix(in srgb, var(--ncb-text) 14%, transparent);
	--ncb-muted: color-mix(in srgb, var(--ncb-text) 70%, var(--ncb-bg));
	--ncb-subtle: color-mix(in srgb, var(--ncb-text) 52%, var(--ncb-bg));
	--ncb-accent-2: color-mix(in srgb, var(--ncb-accent) 74%, var(--ncb-on-accent));
	--ncb-accent-text: color-mix(in srgb, var(--ncb-accent) 72%, var(--ncb-text));

	/* Text on the badge: dark in both modes (light mode: the text token, dark mode: the background token). */
	--ncb-on-accent: var(--ncb-on-accent-l, var(--ncb-text));

	--ncb-radius: 14px;
	--ncb-radius-sm: 10px;
	--ncb-gap: clamp(0.875rem, 1.6vw, 1.25rem);
	--ncb-mono: var(--wp--preset--font-family--monospace, var(--wp--preset--font-family--mono, ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace));
	--ncb-ease: cubic-bezier(0.2, 0.7, 0.2, 1);

	color: var(--ncb-text);
	container: ncb / inline-size;
	box-sizing: border-box;
}

/* Dark mode (Next Dark Mode Toggle, or a theme that sets data-theme="dark"). */
html.nxdm-dark .ncb,
html[data-nxdm-mode="dark"] .ncb,
[data-theme="dark"] .ncb {
	--ncb-on-accent: var(--ncb-on-accent-d, var(--ncb-bg));
}

.ncb *,
.ncb *::before,
.ncb *::after {
	box-sizing: border-box;
}

.ncb.has-ncb-fill {
	background: var(--ncb-bg);
	padding: clamp(1.25rem, 4vw, 3rem);
	border-radius: calc(var(--ncb-radius) + 6px);
}

/* ------------------------------------------------------------------ header */

.ncb-head {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: 1rem 3rem;
	margin: 0 0 clamp(1.5rem, 3vw, 2.25rem);
}

.ncb-head__main {
	flex: 1 1 22rem;
	min-width: 0;
}

.ncb .ncb-eyebrow {
	margin: 0 0 0.5rem;
	font-size: 0.78rem;
	font-weight: 700;
	letter-spacing: 0.14em;
	line-height: 1.3;
	text-transform: uppercase;
	color: var(--ncb-subtle);
}

.ncb .ncb-heading {
	margin: 0;
	font-size: clamp(1.9rem, 1.3rem + 2.4vw, 3rem);
	font-weight: 800;
	line-height: 1.06;
	letter-spacing: -0.025em;
	color: var(--ncb-text);
}

.ncb .ncb-intro {
	flex: 0 1 28rem;
	margin: 0;
	font-size: 1rem;
	line-height: 1.45;
	color: var(--ncb-muted);
}

.ncb-sections .ncb-intro {
	flex-basis: auto;
	max-width: 32rem;
	font-size: 0.95rem;
	align-self: flex-end;
}

.ncb code {
	font-family: var(--ncb-mono);
	font-size: 0.86em;
	font-weight: 600;
	padding: 0.14em 0.45em;
	border-radius: 5px;
	color: var(--ncb-accent-text);
	background: color-mix(in srgb, var(--ncb-accent) 14%, transparent);
	white-space: nowrap;
}

/* ------------------------------------------------------------------ grid */

.ncb-grid {
	display: grid;
	gap: var(--ncb-gap);
	grid-template-columns: repeat(var(--ncb-cols, 3), minmax(0, 1fr));
	margin: 0;
	padding: 0;
}

.ncb-cols-1 { --ncb-cols: 1; }
.ncb-cols-2 { --ncb-cols: 2; }
.ncb-cols-3 { --ncb-cols: 3; }
.ncb-cols-4 { --ncb-cols: 4; }
.ncb-cols-5 { --ncb-cols: 5; }
.ncb-cols-6 { --ncb-cols: 6; }

@container ncb (max-width: 1100px) {
	.ncb-cols-5, .ncb-cols-6 { --ncb-cols: 4; }
}

@container ncb (max-width: 960px) {
	.ncb-cols-4, .ncb-cols-5, .ncb-cols-6 { --ncb-cols: 3; }
}

@container ncb (max-width: 820px) {
	.ncb-cols-3, .ncb-cols-4, .ncb-cols-5, .ncb-cols-6 { --ncb-cols: 2; }
}

@container ncb (max-width: 540px) {
	.ncb-grid { --ncb-cols: 1; }
	.ncb-head { gap: 0.75rem; }
}

/* ------------------------------------------------------------------ card (shared) */

.ncb-card {
	--ncb-tone: var(--ncb-accent);
	position: relative;
	display: flex;
	flex-direction: column;
	min-width: 0;
	margin: 0;
	background: var(--ncb-surface);
	border: 1px solid var(--ncb-border);
	border-radius: var(--ncb-radius);
	color: var(--ncb-text);
	transition: border-color 0.25s var(--ncb-ease), background-color 0.25s var(--ncb-ease), transform 0.25s var(--ncb-ease), box-shadow 0.25s var(--ncb-ease);
}

.ncb-card.is-highlighted {
	border-color: color-mix(in srgb, var(--ncb-tone) 42%, var(--ncb-border));
}

.ncb-card.has-link:hover,
.ncb-card.has-link:focus-within {
	background: var(--ncb-surface-hover);
	border-color: color-mix(in srgb, var(--ncb-accent) 55%, var(--ncb-border));
	transform: translateY(-2px);
	box-shadow: 0 14px 34px -22px color-mix(in srgb, var(--ncb-text) 55%, transparent);
}

.ncb-card .ncb-card__name {
	margin: 0;
	font-weight: 800;
	line-height: 1.12;
	letter-spacing: -0.02em;
	color: var(--ncb-text);
	overflow-wrap: anywhere;
}

.ncb-card .ncb-card__desc {
	margin: 0;
	font-size: 0.95rem;
	line-height: 1.6;
	color: var(--ncb-muted);
}

.ncb-card .ncb-card__desc em,
.ncb-card .ncb-card__desc i {
	color: var(--ncb-subtle);
}

/* Link: the visible link text is small, ::after stretches it over the whole card. */
.ncb-card .ncb-link {
	color: inherit;
	text-decoration: none;
	box-shadow: none;
}

.ncb-card a.ncb-link::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 1;
	border-radius: inherit;
}

.ncb-card a.ncb-link:focus {
	outline: none;
}

.ncb-card a.ncb-link:focus-visible::after {
	outline: 2px solid var(--ncb-accent);
	outline-offset: 3px;
}

.ncb-arrow {
	display: inline-flex;
	flex: none;
	color: var(--ncb-accent-text);
	transition: transform 0.25s var(--ncb-ease);
}

.ncb-arrow svg {
	width: 1.35rem;
	height: 1.35rem;
	display: block;
}

.ncb-card.has-link:hover .ncb-arrow,
.ncb-card.has-link:focus-within .ncb-arrow {
	transform: translateX(4px);
}

/* ------------------------------------------------------------------ country card */

.ncb-country {
	padding: clamp(1.25rem, 2.4vw, 1.75rem);
}

.ncb-country .ncb-card__top {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 0.75rem;
	margin-bottom: 1.25rem;
}

.ncb-badge {
	display: inline-grid;
	place-items: center;
	flex: none;
	width: 4.5rem;
	height: 4.5rem;
	padding: 0 0.25rem;
	border-radius: var(--ncb-radius-sm);
	background: linear-gradient(140deg, var(--ncb-accent) 0%, var(--ncb-accent) 30%, var(--ncb-accent-2) 100%);
	box-shadow: 0 10px 24px -14px color-mix(in srgb, var(--ncb-accent) 85%, transparent);
	color: var(--ncb-on-accent);
	font-size: 1.6rem;
	font-weight: 800;
	line-height: 1;
	letter-spacing: -0.02em;
	text-transform: uppercase;
	white-space: nowrap;
}

.ncb-pill {
	display: inline-flex;
	align-items: center;
	gap: 0.55em;
	max-width: 100%;
	margin-top: 0.15rem;
	padding: 0.42em 0.9em;
	border: 1px solid transparent;
	border-radius: 999px;
	font-family: var(--ncb-mono);
	font-size: 0.7rem;
	font-weight: 700;
	line-height: 1.2;
	letter-spacing: 0.09em;
	text-transform: uppercase;
	color: color-mix(in srgb, var(--ncb-tone) 72%, var(--ncb-text));
	background: color-mix(in srgb, var(--ncb-tone) 17%, transparent);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.ncb-pill::before {
	content: "";
	flex: none;
	width: 0.6em;
	height: 0.6em;
	border-radius: 50%;
	background: var(--ncb-tone);
}

.ncb-pill.is-outline {
	background: color-mix(in srgb, var(--ncb-tone) 7%, transparent);
	border-color: color-mix(in srgb, var(--ncb-tone) 48%, transparent);
}

.ncb-tone-accent  { --ncb-tone: var(--ncb-accent); }
.ncb-tone-neutral { --ncb-tone: var(--ncb-subtle); }
.ncb-tone-alert   { --ncb-tone: var(--ncb-alert); }
.ncb-tone-success { --ncb-tone: var(--ncb-success); }

.ncb-country .ncb-card__name {
	font-size: clamp(1.5rem, 1.25rem + 0.8vw, 1.85rem);
	margin-bottom: 0.45rem;
}

.ncb-country .ncb-card__meta {
	margin: 0 0 1.15rem;
	font-family: var(--ncb-mono);
	font-size: 0.78rem;
	line-height: 1.4;
	letter-spacing: 0.02em;
	color: var(--ncb-subtle);
}

.ncb-country .ncb-card__desc {
	margin-bottom: 1.5rem;
}

.ncb-country .ncb-card__foot {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin-top: auto;
	padding-top: 1.1rem;
	border-top: 1px solid var(--ncb-border);
}

.ncb-path {
	font-family: var(--ncb-mono);
	font-size: 0.85rem;
	font-weight: 700;
	letter-spacing: 0.01em;
	color: var(--ncb-accent-text);
	overflow-wrap: anywhere;
}

/* ------------------------------------------------------------------ section card */

.ncb-section {
	padding: 1.5rem 1.5rem 1.75rem;
	min-height: 10.5rem;
}

.ncb-section .ncb-section__top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	margin-bottom: 1.1rem;
}

.ncb-section__path {
	font-family: var(--ncb-mono);
	font-size: 0.74rem;
	line-height: 1.35;
	color: var(--ncb-subtle);
	overflow-wrap: anywhere;
	min-width: 0;
}

.ncb-section .ncb-card__name {
	font-size: 1.3rem;
	margin-bottom: 0.65rem;
}

.ncb-section .ncb-card__desc {
	font-size: 0.92rem;
	line-height: 1.55;
}

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

@media (prefers-reduced-motion: reduce) {
	.ncb-card,
	.ncb-arrow {
		transition: none;
	}

	.ncb-card.has-link:hover,
	.ncb-card.has-link:focus-within {
		transform: none;
	}
}
