/* ==========================================================================
   Homepage — Stack
   One statement, then the week's stories as panels that stick under the
   header and pile up as the reader scrolls. The hero's tabs are the top edges
   of those panels; after the stack everything goes quiet again.
   ========================================================================== */

.home--stack {
	--stk-wrap: min(100% - 2 * var(--gutter), 1440px);
	--stk-step: 14px;                                  /* how much of each covered panel stays visible */
	--stk-top: calc(var(--header-h) + 14px);           /* where the first panel sticks */
}

/* ── Hero ────────────────────────────────────────────────────────────── */
.stk-hero {
	padding-top: clamp(2.5rem, 1rem + 6vw, 6.5rem);
}
.stk-hero__inner { display: grid; gap: clamp(1.75rem, 1rem + 2.5vw, 3.25rem); }

.stk-hero__title {
	max-width: 15ch;
	font-size: clamp(2.9rem, 0.9rem + 7.6vw, 8.75rem);
	font-weight: 800;
	font-variation-settings: "opsz" 96;
	line-height: 0.94;
	letter-spacing: -0.042em;
	text-wrap: balance;
}

.stk-hero__intro {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	justify-content: space-between;
	gap: 1rem 3rem;
	padding-top: 1.25rem;
	border-top: 1px solid var(--line);
}
.stk-hero__text {
	max-width: 46ch;
	font-size: clamp(1.05rem, 1rem + 0.35vw, 1.25rem);
	color: var(--ink-2);
}
.stk-hero__updated {
	font-family: var(--font-mono);
	font-size: 0.75rem;
	color: var(--muted);
}

/* The chapters, drawn as the tabbed top edges of the panels below. */
.stk-tabs {
	width: var(--stk-wrap);
	margin: clamp(2.5rem, 1.5rem + 3vw, 4.5rem) auto 0;
}
.stk-tabs__list {
	list-style: none;
	display: grid;
	grid-template-columns: repeat(var(--stk-n, 5), minmax(0, 1fr));
	gap: 6px;
	align-items: end;
}
.stk-tab { display: flex; }
.stk-tab__link {
	position: relative;
	display: grid;
	grid-template-columns: auto minmax(0, 1fr);
	grid-template-rows: auto 1fr;
	gap: 0.35rem 0.8rem;
	width: 100%;
	min-height: 8.5rem;
	padding: 1.1rem 1.25rem 1.5rem;
	border: 1px solid color-mix(in srgb, var(--card-accent, var(--mint)) 22%, transparent);
	border-bottom: 0;
	border-radius: var(--r-lg) var(--r-lg) 0 0;
	background: linear-gradient(180deg, color-mix(in srgb, var(--card-accent, var(--mint)) 12%, var(--surface)), color-mix(in srgb, var(--card-accent, var(--mint)) 5%, var(--bg)));
	transition: transform 0.35s var(--ease), background-color 0.25s var(--ease);
}
.stk-tab__link::before {
	content: "";
	position: absolute;
	inset: -1px 1.25rem auto;
	height: 2px;
	border-radius: 0 0 2px 2px;
	background: var(--card-accent, var(--mint));
}
.stk-tab__num {
	grid-row: 1 / span 2;
	font-family: var(--font-display);
	font-size: 1.6rem;
	font-weight: 800;
	line-height: 1;
	color: var(--card-accent, var(--mint));
}
.stk-tab__title {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 3;
	overflow: hidden;
	font-family: var(--font-display);
	font-size: 1rem;
	font-weight: 700;
	line-height: 1.25;
	letter-spacing: -0.015em;
}
.stk-tab__time {
	grid-column: 2;
	align-self: end;
	font-family: var(--font-mono);
	font-size: 0.72rem;
	color: var(--muted);
}
.stk-tab__link:hover { transform: translateY(-6px); }
.stk-tab__link:hover .stk-tab__title { color: var(--card-accent, var(--mint)); }
.stk-tab__link:focus-visible { outline-offset: -3px; border-radius: var(--r-lg) var(--r-lg) 0 0; }

/* ── The stack ───────────────────────────────────────────────────────── */
.stk-stack {
	width: var(--stk-wrap);
	margin-inline: auto;
	padding-top: 1.25rem;
	border-top: 1px solid var(--line);
}

.stk-ch {
	position: sticky;
	top: calc(var(--stk-top) + var(--i, 0) * var(--stk-step));
	display: grid;
	grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
	/* Tall enough to fill the screen, short enough that every panel still
	   fits under the edges of the ones it covers. */
	height: calc(100svh - var(--stk-top) - (var(--stk-n, 5) - 1) * var(--stk-step) - 1rem);
	min-height: 30rem;
	max-height: 58rem;
	margin-bottom: clamp(1.5rem, 1rem + 2vw, 3rem);
	overflow: hidden;
	border: 1px solid color-mix(in srgb, var(--card-accent, var(--mint)) 20%, var(--line));
	border-radius: var(--r-lg);
	background:
		radial-gradient(80% 80% at 100% 0%, color-mix(in srgb, var(--card-accent, var(--mint)) 14%, transparent), transparent 70%),
		color-mix(in srgb, var(--card-accent, var(--mint)) 9%, var(--surface));
	box-shadow:
		inset 0 1px 0 color-mix(in srgb, var(--ink) 9%, transparent),
		0 -22px 50px -26px rgb(0 0 0 / 0.75);
	transform-origin: 50% 0;
	/* --stk-cover is set by home-stack.js: 0 while the panel is on top, rising
	   towards 1 (and past it) as later panels slide over. */
	transform: scale(calc(1 - min(var(--stk-cover, 0), 3) * 0.022));
	will-change: transform;
}
.stk-ch:last-child { margin-bottom: 0; }

/* Covered panels sink back into the dark. */
.stk-ch::after {
	content: "";
	position: absolute;
	inset: 0;
	z-index: 2;
	background: var(--bg);
	opacity: calc(min(var(--stk-cover, 0), 1.6) * 0.42);
	pointer-events: none;
}

.stk-ch__media {
	position: relative;
	display: block;
	overflow: hidden;
	background: var(--surface-2);
}
.stk-ch__img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	transition: transform 0.8s var(--ease);
}
.stk-ch:hover .stk-ch__img { transform: scale(1.025); }

/* No photo: the topic's mark on a field of its colour. */
.stk-ch--plain .stk-ch__media {
	display: grid;
	place-items: center;
	background:
		radial-gradient(60% 60% at 50% 50%, color-mix(in srgb, var(--card-accent, var(--mint)) 18%, transparent), transparent 70%),
		color-mix(in srgb, var(--card-accent, var(--mint)) 8%, var(--bg-2));
}
.stk-ch--plain .topicmark {
	width: clamp(6rem, 4rem + 6vw, 9.5rem);
	height: auto;
	aspect-ratio: 1;
	margin: 0;
	border-radius: 30%;
}
.stk-ch--plain .topicmark svg { width: 46%; height: 46%; }

.stk-ch--flip { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); }
.stk-ch--flip .stk-ch__media { order: 2; }

.stk-ch__body {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: flex-start;
	gap: clamp(0.9rem, 0.6rem + 0.8vh, 1.4rem);
	min-height: 0;
	padding: clamp(1.75rem, 0.75rem + 3.2vw, 4.5rem);
}
.stk-ch__meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem 1.1rem;
}
.stk-ch__count {
	font-family: var(--font-mono);
	font-size: 0.75rem;
	color: var(--muted);
}
.stk-ch__meta .topic-tag { font-size: var(--fs-sm); color: var(--ink); }

.stk-ch__title {
	max-width: 17ch;
	font-size: clamp(1.9rem, 0.6rem + 1.7vw + 2.2vh, 3.7rem);
	font-weight: 800;
	line-height: 1.02;
	letter-spacing: -0.042em;
	text-wrap: balance;
}
.stk-ch__title a { transition: color 0.2s var(--ease); }
.stk-ch__title a:hover { color: var(--card-accent, var(--mint)); }

.stk-ch__text {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 4;
	overflow: hidden;
	max-width: 46ch;
	font-size: clamp(1rem, 0.95rem + 0.25vw, 1.15rem);
	color: var(--ink-2);
}
.stk-ch__actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 1rem 1.4rem;
	margin-top: 0.4rem;
}

/* ── From the archive ────────────────────────────────────────────────── */
.stk-list { list-style: none; border-top: 1px solid var(--line-2); }
.stk-list--cols {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	column-gap: clamp(2rem, 1rem + 4vw, 5rem);
}
.stk-row {
	display: grid;
	grid-template-columns: 4.25rem minmax(0, 1fr);
	gap: 0.45rem 1rem;
	align-items: baseline;
	padding: 1.25rem 0;
	border-bottom: 1px solid var(--line);
}
.stk-row__date {
	grid-row: 1;
	font-family: var(--font-mono);
	font-size: 0.75rem;
	color: var(--muted);
}
.stk-row__title {
	font-family: var(--font-display);
	font-size: 1.15rem;
	font-weight: 700;
	line-height: 1.28;
	letter-spacing: -0.018em;
	text-wrap: pretty;
	transition: color 0.2s var(--ease);
}
.stk-row__title:hover { color: var(--card-accent, var(--mint)); }
.stk-row .topic-tag { grid-column: 2; font-size: 0.78rem; color: var(--muted); }
.stk-row .topic-tag:hover { color: var(--ink); }

/* ── Topics ──────────────────────────────────────────────────────────── */
.stk-topics__grid {
	display: grid;
	grid-template-columns: minmax(0, 16rem) minmax(0, 1fr);
	gap: 1.5rem clamp(2rem, 1rem + 4vw, 5rem);
	align-items: start;
}
.stk-topics__title {
	font-size: clamp(1.6rem, 1.3rem + 1vw, 2.2rem);
	font-weight: 800;
	line-height: 1.08;
	letter-spacing: -0.035em;
	text-wrap: balance;
}
.stk-topics__list {
	list-style: none;
	display: flex;
	flex-wrap: wrap;
	gap: 0.6rem;
}
.stk-topic {
	display: inline-flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.45rem 1.1rem 0.45rem 0.45rem;
	border: 1px solid var(--line-2);
	border-radius: var(--r-pill);
	transition: border-color 0.2s var(--ease), background-color 0.2s var(--ease);
}
.stk-topic .topicmark {
	width: 38px;
	height: 38px;
	margin: 0;
	border-radius: 50%;
}
.stk-topic .topicmark svg { width: 19px; height: 19px; }
.stk-topic__name { font-weight: 600; }
.stk-topic__count { font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); }
.stk-topic:hover {
	border-color: color-mix(in srgb, var(--card-accent, var(--mint)) 60%, transparent);
	background: color-mix(in srgb, var(--card-accent, var(--mint)) 7%, transparent);
}
.stk-topic:focus-visible { border-radius: var(--r-pill); }

/* ── Sign-up: the last card on the pile ──────────────────────────────── */
.stk-join { padding-bottom: var(--band); }
.stk-join__panel {
	display: grid;
	grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
	gap: clamp(2rem, 1rem + 4vw, 5rem);
	align-items: center;
	width: var(--stk-wrap);
	margin-inline: auto;
	padding: clamp(2rem, 1rem + 4vw, 5rem);
	border: 1px solid color-mix(in srgb, var(--mint) 22%, var(--line));
	border-radius: var(--r-lg);
	background:
		radial-gradient(70% 90% at 0% 100%, color-mix(in srgb, var(--mint) 12%, transparent), transparent 70%),
		color-mix(in srgb, var(--mint) 5%, var(--surface));
	box-shadow: inset 0 1px 0 color-mix(in srgb, var(--ink) 9%, transparent);
}
.stk-join__title {
	max-width: 15ch;
	font-size: clamp(2rem, 1.2rem + 2.8vw, 3.8rem);
	font-weight: 800;
	line-height: 1.02;
	letter-spacing: -0.045em;
	text-wrap: balance;
}
.stk-join__text { max-width: 44ch; margin-top: 1.25rem; color: var(--ink-2); }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
	.stk-tab__link { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr; }
	.stk-tab__num { grid-row: auto; font-size: 1.2rem; }
	.stk-tab__time { grid-column: 1; }
	.stk-topics__grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
	/* The tabs turn into the pile itself, seen edge-on: each row overlaps
	   the one above it like a card laid on top. */
	.stk-tabs__list { grid-template-columns: 1fr; gap: 0; }
	.stk-tab + .stk-tab { margin-top: -0.9rem; }
	.stk-tab__link {
		grid-template-columns: 1.6rem minmax(0, 1fr) auto;
		grid-template-rows: auto;
		align-items: baseline;
		min-height: 0;
		padding: 1rem 1.1rem 1.9rem;
		box-shadow: 0 -10px 24px -14px rgb(0 0 0 / 0.7);
	}
	.stk-tab__num { font-size: 1rem; }
	.stk-tab__title { -webkit-line-clamp: 2; font-size: 0.98rem; }
	.stk-tab__time { grid-column: 3; align-self: baseline; }
	.stk-tab__link:hover { transform: none; }
	.stk-stack { border-top: 0; padding-top: 0; }

	.stk-ch,
	.stk-ch--flip {
		grid-template-columns: minmax(0, 1fr);
		grid-template-rows: minmax(9rem, 1fr) auto;
		min-height: 0;
	}
	.stk-ch--flip .stk-ch__media { order: 0; }
	.stk-ch__body { justify-content: flex-start; padding: 1.4rem 1.4rem 1.6rem; gap: 0.8rem; }
	.stk-ch__title { max-width: none; font-size: clamp(1.5rem, 1rem + 2.6vw, 2.2rem); }
	.stk-ch__text { -webkit-line-clamp: 3; font-size: 0.98rem; }
	.stk-ch__actions { margin-top: 0.2rem; }
	.stk-ch--plain .topicmark { width: 6rem; }

	.stk-list--cols { grid-template-columns: 1fr; }
	.stk-join__panel { grid-template-columns: 1fr; }
}

@media (max-width: 900px) and (max-height: 760px) {
	.stk-ch__text { display: none; }
}

@media (max-width: 480px) {
	.home--stack { --stk-step: 10px; }
	.stk-tab__time { display: none; }
	.stk-tab__link { grid-template-columns: 1.4rem minmax(0, 1fr); }
	.stk-ch__actions .btn { flex: 1 1 auto; }
	.stk-row { grid-template-columns: 3.4rem minmax(0, 1fr); }
	.stk-join__panel { padding: 1.75rem 1.25rem; }
}

/* Too short a screen for a panel to fit under the header: a plain list. */
@media (max-height: 560px) {
	.stk-ch {
		position: relative;
		top: auto;
		height: auto;
		min-height: 0;
		max-height: none;
		transform: none;
	}
	.stk-ch::after { display: none; }
	.stk-ch:not(.stk-ch--plain) .stk-ch__media { min-height: 16rem; }
}

/* ── Motion ──────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
	/* The panels still stack and the covered ones still dim, but nothing
	   scales or lifts. */
	.stk-ch { transform: none; will-change: auto; }
	.stk-ch:hover .stk-ch__img { transform: none; }
	.stk-tab__link:hover { transform: none; }
}
