/* Rabin Craft — Constellation. Needs core.css.
   Three layouts from one list of cards:
   - default (no script, reduced motion): a grid with every detail visible;
   - narrow columns (under 720px): a swipeable row that snaps card by card (data-narrow="grid": the grid);
   - .is-field (set by constellation.js on wide columns): the cards are absolutely placed in the stage;
     the script writes each card's transform and opacity only while something moves, and draws the
     lines in an SVG it adds. Drift is a CSS animation, paused off screen (.is-idle).
   Theme with --mkit-const-card (card width), --mkit-const-aspect / --mkit-const-height (field size),
   --mkit-const-gap / --mkit-const-group-gap / --mkit-const-pad (spacing, read by the script),
   --mkit-const-line / --mkit-const-line-w / --mkit-const-dot (lines) and --mkit-card-radius. */

.mkit-const {
	container: mkit-const / inline-size;
	width: 100%;
	color: var(--mkit-muted);
	--gap: clamp(.875rem, 1.6vw, 1.25rem);
	--r: var(--mkit-card-radius, 18px);
}

/* Process: the live counter and bar. It needs the field, so it shows only where the field is (or is about to be) */
.mkit-const__progress {
	display: flex;
	align-items: center;
	gap: 1rem;
	max-width: 26rem;
	margin: 0 auto clamp(1rem, 2.5vw, 1.75rem);
	font-family: var(--mkit-font-mono);
	font-size: .8125rem;
	letter-spacing: .12em;
	text-transform: uppercase;
	color: var(--mkit-muted);
}

.mkit-const__count {
	flex: none;
	white-space: nowrap;
}

.mkit-const__count b {
	color: var(--mkit-text);
	font-weight: 700;
}

.mkit-const__bar {
	position: relative;
	flex: 1;
	height: 2px;
	overflow: hidden;
	border-radius: 2px;
	background: var(--mkit-line);
}

.mkit-const__bar i {
	position: absolute;
	inset: 0;
	background: var(--mkit-accent);
	transform-origin: 0 50%;
}

html:not(.mkit-js) .mkit-const__progress,
.mkit-const.is-grid .mkit-const__progress {
	display: none;
}

@container mkit-const (max-width: 719px) {
	.mkit-const:not(.is-field) .mkit-const__progress {
		display: none;
	}
}

/* Step numbers on the cards */
.mkit-const__num {
	position: absolute;
	top: clamp(.75rem, 1.4vw, 1rem);
	right: clamp(.75rem, 1.4vw, 1rem);
	z-index: 1;
	padding: .3em .65em;
	border: 1px solid var(--mkit-line);
	border-radius: 999px;
	font-family: var(--mkit-font-mono);
	font-size: .6875rem;
	font-weight: 600;
	letter-spacing: .08em;
	line-height: 1.2;
	text-transform: uppercase;
	color: var(--mkit-muted);
	transition: color .35s var(--mkit-ease), background-color .35s var(--mkit-ease), border-color .35s var(--mkit-ease);
}

.mkit-const__card.is-current .mkit-const__num,
.mkit-const[data-mode="process"] .mkit-const__card.is-reached .mkit-const__num {
	border-color: var(--mkit-accent);
	background: var(--mkit-accent);
	color: #fff;
}

/* Steps not reached yet wait dimmed; the current one glows */
.mkit-const[data-mode="process"].is-field .mkit-const__card:not(.is-reached) .mkit-const__body::after {
	opacity: calc(var(--fog, 0) + .5);
}

.mkit-const[data-mode="process"].is-field .mkit-const__card.is-current .mkit-const__body {
	border-color: color-mix(in srgb, var(--mkit-accent-soft) 70%, transparent);
	box-shadow: 0 24px 50px -28px color-mix(in srgb, var(--mkit-accent) 85%, transparent);
}

/* Filters (they need the script, so they only show with it) */
html:not(.mkit-js) .mkit-const__filters {
	display: none;
}

.mkit-const__filters {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: .5rem;
	margin: 0 0 clamp(1.25rem, 3vw, 2rem);
}

.mkit-const__filter {
	padding: .55em 1.1em;
	border: 1px solid var(--mkit-line);
	border-radius: 999px;
	background: transparent;
	color: var(--mkit-text);
	font: inherit;
	font-size: .875rem;
	font-weight: 600;
	line-height: 1.2;
	cursor: pointer;
	transition: background-color .25s var(--mkit-ease), border-color .25s var(--mkit-ease), color .25s var(--mkit-ease);
}

.mkit-const__filter:hover {
	border-color: color-mix(in srgb, var(--mkit-accent-soft) 60%, transparent);
}

.mkit-const__filter[aria-pressed="true"] {
	border-color: var(--mkit-accent);
	background: var(--mkit-accent);
	color: #fff;
}

.mkit-const__filter:focus-visible {
	outline: 2px solid var(--mkit-accent-soft);
	outline-offset: 2px;
}

/* Cards */
.mkit-const__stage {
	position: relative;
	width: 100%; /* so the field's min-height can't widen it through aspect-ratio */
}

.mkit-const__list {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
	gap: var(--gap);
	margin: 0;
	padding: 0;
	list-style: none;
}

.mkit-const__card {
	position: relative;
	margin: 0;
	border-radius: var(--r);
}

.mkit-const:not(.is-field) .mkit-const__card.is-out {
	display: none;
}

.mkit-const__body {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: .5rem;
	height: 100%;
	padding: clamp(1rem, 1.8vw, 1.35rem);
	border: 1px solid var(--mkit-line);
	border-radius: inherit;
	background: linear-gradient(160deg, color-mix(in srgb, var(--mkit-accent) 18%, var(--mkit-chip-bg)), var(--mkit-chip-bg) 72%);
	transition: border-color .3s var(--mkit-ease), box-shadow .3s var(--mkit-ease), opacity .3s var(--mkit-ease);
}

/* Depth and "falling back" darken a card toward the section colour with a layer inside it, so the card stays
   opaque and hides the lines behind it. --fog is set per card by the script (0 = near). */
.mkit-const__card .mkit-const__body::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 2;
	border-radius: inherit;
	background: var(--mkit-surface);
	opacity: var(--fog, 0);
	pointer-events: none;
	transition: opacity .35s var(--mkit-ease);
}

.mkit-const.has-active .mkit-const__card:not(.is-active):not(.is-out) .mkit-const__body::after {
	opacity: calc(var(--fog, 0) + .28);
}

.mkit-const__card.is-active .mkit-const__body::after {
	opacity: 0;
}

.mkit-const__card.is-active .mkit-const__body {
	border-color: color-mix(in srgb, var(--mkit-accent-soft) 70%, transparent);
	box-shadow: 0 28px 60px -30px color-mix(in srgb, var(--mkit-accent) 85%, transparent), 0 0 0 1px color-mix(in srgb, var(--mkit-accent-soft) 25%, transparent);
}

.mkit-const__icon {
	display: grid;
	place-items: center;
	width: 2.75rem;
	height: 2.75rem;
	margin-bottom: .25rem;
	border-radius: 12px;
	background: color-mix(in srgb, var(--mkit-accent) 26%, transparent);
	color: var(--mkit-accent-soft);
}

.mkit-const__icon svg {
	width: 1.4rem;
	height: 1.4rem;
}

.mkit-const__icon :is(i, b) {
	font-size: 1.2rem;
	font-style: normal;
}

.mkit-const__media {
	position: relative;
	display: block;
	aspect-ratio: 16 / 10;
	margin-bottom: .25rem;
	overflow: hidden;
	border-radius: calc(var(--r) * .6);
	background: color-mix(in srgb, var(--mkit-accent) 20%, transparent);
}

.mkit-const__media img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.mkit-const__group {
	font-family: var(--mkit-font-mono);
	font-size: .6875rem;
	letter-spacing: .14em;
	text-transform: uppercase;
	color: var(--mkit-accent-soft);
}

.mkit-const__title {
	margin: 0;
	color: var(--mkit-text);
	font-size: clamp(1.05rem, .95rem + .4vw, 1.25rem);
	font-weight: 600;
	line-height: 1.25;
}

.mkit-const__text,
.mkit-const__detail p {
	margin: 0;
	font-size: .9375rem;
	line-height: 1.55;
}

.mkit-const__detail {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: .875rem;
	margin-top: .25rem;
}

/* With the script, details live in the panel */
.mkit-js .mkit-const[data-expand] .mkit-const__card .mkit-const__detail {
	display: none;
}

.mkit-const__more {
	position: relative;
	z-index: 1;
	display: inline-flex;
	align-items: center;
	gap: .45em;
	margin-top: auto;
	color: var(--mkit-text);
	font-size: .9375rem;
	font-weight: 600;
	text-decoration: none;
}

span.mkit-const__more {
	pointer-events: none;
}

a.mkit-const__more {
	padding: .65em 1.15em;
	border-radius: 999px;
	background: var(--mkit-accent);
	color: #fff;
}

a.mkit-const__more:focus-visible {
	outline: 2px solid var(--mkit-accent-soft);
	outline-offset: 3px;
}

.mkit-const__more .mkit-arrow {
	width: 1.1em;
	height: 1.1em;
}

/* The title is the card's control (a button the script adds, or a link): stretched over the card */
.mkit-const__open {
	all: unset;
	color: inherit;
	cursor: pointer;
}

.mkit-const__open::after {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: var(--r);
}

.mkit-const__open:focus-visible::after {
	outline: 2px solid var(--mkit-accent-soft);
	outline-offset: 3px;
}

/* Narrow columns: a swipeable row, unless data-narrow="grid" keeps the grid (the field starts at 720px by default) */
@container mkit-const (max-width: 719px) {
	.mkit-const:not(.is-field, [data-narrow="grid"]) .mkit-const__list {
		display: flex;
		gap: .875rem;
		margin-inline: -16px;
		padding: .5rem 16px 1rem;
		overflow-x: auto;
		overscroll-behavior-x: contain;
		scroll-snap-type: x mandatory;
		scroll-padding-inline: 16px;
		scrollbar-width: none;
	}
	.mkit-const:not(.is-field, [data-narrow="grid"]) .mkit-const__list::-webkit-scrollbar {
		display: none;
	}
	.mkit-const:not(.is-field, [data-narrow="grid"]) .mkit-const__card {
		flex: 0 0 min(80%, 300px);
		scroll-snap-align: center;
	}
	/* Cards off to the side sit back a little, like a stack, where scroll-driven animations exist */
	@supports (animation-timeline: view()) {
		@media (prefers-reduced-motion: no-preference) {
			.mkit-const:not(.is-field) .mkit-const__card {
				animation: mkit-const-swipe linear both;
				animation-timeline: view(inline);
			}
		}
	}
}

@keyframes mkit-const-swipe {
	0%, 100% { scale: .9; opacity: .55; }
	35%, 65% { scale: 1; opacity: 1; }
}

/* The field. Where the script will build it (wide column, motion allowed), its height is reserved from
   the first paint and the cards wait hidden, so the page doesn't shift when the script starts. The script
   sets .is-grid when it keeps the grid (many cards in a mid-width column); without the script, core's boot
   snippet drops .mkit-js and the grid comes back. */
@container mkit-const (min-width: 720px) {
	@media (prefers-reduced-motion: no-preference) {
		.mkit-js .mkit-const:not(.is-grid) .mkit-const__stage {
			aspect-ratio: var(--mkit-const-aspect, 16 / 10);
			height: var(--mkit-const-height, auto);
			min-height: var(--mkit-const-height, max(30rem, var(--mkit-n, 8) * 3.5rem + 10rem)); /* a set height wins; otherwise taller with more cards */
		}
		.mkit-js .mkit-const:not(.is-field, .is-grid) .mkit-const__list {
			visibility: hidden;
		}
	}
}

.mkit-const.is-field .mkit-const__stage {
	aspect-ratio: var(--mkit-const-aspect, 16 / 10);
	height: var(--mkit-const-height, auto);
	min-height: var(--mkit-const-height, max(30rem, var(--mkit-n, 8) * 3.5rem + 10rem));
	transform-origin: var(--ox, 50%) var(--oy, 50%);
	transition: scale .5s var(--mkit-ease), opacity .5s var(--mkit-ease);
}

.mkit-const.is-field .mkit-const__list {
	position: absolute;
	inset: 0;
	display: block;
}

.mkit-const.is-field .mkit-const__card {
	position: absolute;
	top: 50%;
	left: 50%;
	width: var(--mkit-const-card, clamp(180px, 19%, 250px));
	transform-origin: 50% 50%;
}

.mkit-const.is-field .mkit-const__card.is-out {
	pointer-events: none;
}

.mkit-const.is-field .mkit-const__card .mkit-const__text {
	display: -webkit-box;
	overflow: hidden;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
}

.mkit-const__lines {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	overflow: visible;
	pointer-events: none;
}

/* Lines: colour, width and dot size are CSS variables (Bricks controls set them per breakpoint);
   the script sets each line's opacity (its cards' fade times data-line-o) and .is-hot on the hovered card's lines */
.mkit-const__edge {
	--lc: var(--mkit-const-line, var(--mkit-accent-soft));
	--lw: var(--mkit-const-line-w, 1px);
	transition: opacity .3s var(--mkit-ease);
}

.mkit-const__edge path {
	fill: none;
	stroke: var(--lc);
	stroke-width: var(--lw);
	stroke-linecap: round;
}

.mkit-const[data-line-style="dashed"] .mkit-const__line {
	stroke-dasharray: 6 6;
}

.mkit-const[data-line-style="dotted"] .mkit-const__line {
	stroke-width: calc(var(--lw) * 1.6);
	stroke-dasharray: 0 calc(var(--lw) * 5 + 3px);
}

.mkit-const__edge circle {
	fill: var(--lc);
	r: var(--mkit-const-dot, 2.5px);
}

.mkit-const__edge.is-hot path {
	stroke-width: calc(var(--lw) + .75px);
}

.mkit-const__edge.is-hot circle {
	fill: var(--mkit-text);
}

/* Process: the reached part of each line, drawn over it in the accent (pathLength 1; the script sets the offset) */
.mkit-const__fill {
	stroke: var(--mkit-accent) !important;
	stroke-width: calc(var(--lw) + .75px) !important;
	stroke-dasharray: 1 1;
	stroke-dashoffset: 1;
}

/* Flow: a short bright dash travels along each line (off screen it pauses) */
.mkit-const__flow {
	stroke: var(--mkit-text) !important;
	stroke-width: calc(var(--lw) + .5px) !important;
	stroke-dasharray: 3 37;
	animation: mkit-const-flow 2.4s linear infinite;
}

.mkit-const.is-idle .mkit-const__flow {
	animation-play-state: paused;
}

@keyframes mkit-const-flow {
	to { stroke-dashoffset: -40; }
}

@media (prefers-reduced-motion: reduce) {
	.mkit-const__flow {
		display: none;
	}
}

@media (prefers-reduced-motion: no-preference) {
	.mkit-const.is-field[data-drift] .mkit-const__card .mkit-const__body {
		animation: mkit-const-drift calc(6s + var(--i, 0) * .7s) ease-in-out calc(var(--i, 0) * -1.9s) infinite alternate;
	}
	.mkit-const.is-field.is-idle .mkit-const__card .mkit-const__body {
		animation-play-state: paused;
	}
}

@keyframes mkit-const-drift {
	from { translate: 0 -5px; }
	to { translate: 0 5px; }
}

/* Opening: the field falls back while the panel flies out of the card */
.mkit-const.is-diving .mkit-const__stage {
	scale: 1.05;
	opacity: .3;
}

.mkit-const__card.is-opened .mkit-const__body {
	opacity: 0;
}

/* Equal heights: in the field every card takes the tallest card's height (the script measures it into
   --mkit-const-h); in the grid all rows share one height; the swipe row stretches its cards already */
.mkit-const.is-field[data-equal] .mkit-const__card .mkit-const__body {
	min-height: var(--mkit-const-h, 0);
}

.mkit-const[data-equal]:not(.is-field) .mkit-const__list {
	grid-auto-rows: 1fr;
}

/* Shapes: square tiles and circles are 1:1; their text is clamped so it stays inside */
.mkit-const:is([data-shape="square"], [data-shape="circle"]) .mkit-const__card .mkit-const__body {
	aspect-ratio: 1;
	overflow: hidden;
}

.mkit-const:is([data-shape="square"], [data-shape="circle"]) .mkit-const__card :is(.mkit-const__title, .mkit-const__text) {
	display: -webkit-box;
	overflow: hidden;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
}

.mkit-const[data-shape="square"] .mkit-const__card .mkit-const__text {
	-webkit-line-clamp: 3;
}

.mkit-const[data-shape="circle"] .mkit-const__card {
	border-radius: 50%;
}

.mkit-const[data-shape="circle"] .mkit-const__card .mkit-const__body {
	align-items: center;
	justify-content: center;
	gap: .4rem;
	padding: 15%; /* keeps the content inside the circle */
	border-radius: 50%;
	text-align: center;
	background: radial-gradient(circle at 50% 20%, color-mix(in srgb, var(--mkit-accent) 22%, var(--mkit-chip-bg)), var(--mkit-chip-bg) 70%);
	overflow: visible; /* the step number sits on the rim */
}

.mkit-const[data-shape="circle"] .mkit-const__card .mkit-const__body > * {
	max-width: 100%;
}

.mkit-const[data-shape="circle"] .mkit-const__card .mkit-const__media {
	flex: none;
	width: 32%;
	margin: 0;
	aspect-ratio: 1;
	border-radius: 50%;
}

.mkit-const[data-shape="circle"] .mkit-const__card .mkit-const__icon {
	margin: 0;
}

.mkit-const[data-shape="circle"] .mkit-const__card .mkit-const__title {
	font-size: clamp(1rem, .9rem + .35vw, 1.15rem);
}

.mkit-const[data-shape="circle"] .mkit-const__card .mkit-const__text {
	font-size: .875rem;
	line-height: 1.45;
}

.mkit-const[data-shape="circle"] .mkit-const__card .mkit-const__more {
	margin-top: .25rem;
}

.mkit-const[data-shape="circle"] .mkit-const__open::after {
	border-radius: 50%;
}

/* On a circle the number sits on the rim, at the top */
.mkit-const[data-shape="circle"] .mkit-const__card .mkit-const__num {
	top: 0;
	right: auto;
	left: 50%;
	z-index: 3;
	transform: translate(-50%, -50%);
	background: var(--mkit-chip-bg);
}

.mkit-const[data-shape="circle"] .mkit-const__card.is-current .mkit-const__num,
.mkit-const[data-shape="circle"][data-mode="process"] .mkit-const__card.is-reached .mkit-const__num {
	background: var(--mkit-accent);
}

/* Detail panel (a <dialog> the script adds to the root, so it keeps the theme's variables) */
.mkit-const__dialog {
	box-sizing: border-box;
	width: min(600px, calc(100% - 32px));
	max-width: none;
	max-height: calc(100% - 48px);
	margin: auto;
	padding: 0;
	overflow: hidden auto; /* long details scroll down; nothing scrolls sideways */
	overscroll-behavior: contain;
	scrollbar-width: thin;
	scrollbar-color: var(--mkit-line) transparent;
	border: 1px solid var(--mkit-line);
	border-radius: calc(var(--r) * 1.2);
	background: linear-gradient(160deg, color-mix(in srgb, var(--mkit-accent) 20%, var(--mkit-chip-bg)), var(--mkit-chip-bg) 70%) var(--mkit-chip-bg);
	color: var(--mkit-muted);
	box-shadow: 0 40px 120px -40px var(--mkit-shadow);
}

.mkit-const__dialog::-webkit-scrollbar {
	width: 8px;
	height: 0;
}

.mkit-const__dialog::-webkit-scrollbar-thumb {
	border: 2px solid transparent;
	border-radius: 8px;
	background: var(--mkit-line) padding-box;
}

.mkit-const__dialog::-webkit-scrollbar-track {
	background: transparent;
}

/* In the panel the step number sits in the flow, above the title, clear of the close button */
.mkit-const__dialog .mkit-const__num {
	position: static;
	align-self: flex-start;
	order: -1;
	transform: none;
}

.mkit-const__dialog::backdrop {
	background: rgba(6, 7, 20, .66);
}

.mkit--light .mkit-const__dialog::backdrop {
	background: rgba(20, 21, 43, .38);
}

.mkit-const__dialog .mkit-const__body {
	gap: .75rem;
	padding: clamp(1.5rem, 4vw, 2.5rem);
	border: 0;
	background: none;
	animation: none;
}

.mkit-const__dialog .mkit-const__detail {
	display: flex;
}

.mkit-const__dialog .mkit-const__media {
	aspect-ratio: 16 / 9;
	margin-right: 2.25rem;
}

.mkit-const__dialog .mkit-const__icon {
	width: 3.5rem;
	height: 3.5rem;
	border-radius: 16px;
}

.mkit-const__dialog .mkit-const__icon svg {
	width: 1.75rem;
	height: 1.75rem;
}

.mkit-const__dialog .mkit-const__title {
	padding-right: 2.5rem;
	font-size: clamp(1.4rem, 1.1rem + 1.2vw, 1.9rem);
}

.mkit-const__dialog :is(.mkit-const__text, .mkit-const__detail p) {
	font-size: 1rem;
	line-height: 1.65;
}

/* Pinned to the panel's top-right corner while a long detail scrolls; the negative bottom margin
   cancels its height, so the content still starts at the top */
.mkit-const__close {
	position: sticky;
	top: .875rem;
	z-index: 3;
	display: grid;
	margin: .875rem .875rem -3.375rem auto;
	place-items: center;
	width: 2.5rem;
	height: 2.5rem;
	padding: 0;
	border: 1px solid var(--mkit-line);
	border-radius: 50%;
	background: var(--mkit-chip-bg);
	color: var(--mkit-text);
	cursor: pointer;
}

.mkit-const__close:focus-visible {
	outline: 2px solid var(--mkit-accent-soft);
	outline-offset: 2px;
}

.mkit-const__close svg {
	width: 1.1rem;
	height: 1.1rem;
}
