/* --------------------------------------------------------------------------
   Post layouts: Cover story (board 07), Tutorial (08) and Quick note (09).
   Loaded on those single posts only (inc/setup.php); every rule is scoped to
   .td-layout-cover|tutorial|til. Same technique as article.css: the reading
   column is a max-width on the constrained children, no !important, centred
   or placed by WordPress' own auto margins / by the grid.
   Phone rules are at the end (max-width: 768px).
   -------------------------------------------------------------------------- */

.td-layout-cover,
.td-layout-tutorial,
.td-layout-til {
	--td-col: 740px;
	--td-w: min(1290px, 90vw);
}

/* ---- Shared title area (tutorial, quick note): back link, chips, big title, meta ---- */

.td-layout-tutorial .hero-section .entry-header,
.td-layout-til .hero-section .entry-header {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
}

:is(.td-layout-tutorial, .td-layout-til) .entry-header .entry-meta {
	order: 1;
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px 10px;
	margin: 0 0 18px;
	padding: 0;
	font-size: var(--td-text-sm);
	color: var(--td-ink);
	text-transform: none;
	letter-spacing: 0;
}

:is(.td-layout-tutorial, .td-layout-til) .entry-header .entry-meta > li {
	margin: 0;
	padding: 0;
}

:is(.td-layout-tutorial, .td-layout-til) .entry-header .entry-meta > li::before,
:is(.td-layout-tutorial, .td-layout-til) .entry-header .entry-meta > li::after {
	content: none;
}

:is(.td-layout-tutorial, .td-layout-til) .entry-header .entry-meta .meta-categories {
	order: -1;
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

:is(.td-layout-tutorial, .td-layout-til) .entry-header .page-title {
	order: 2;
	margin: 0 0 18px;
	font-family: var(--td-body);
	font-weight: 700;
	line-height: 1.04;
	letter-spacing: -0.025em;
	color: var(--td-ink);
	overflow-wrap: break-word;
}

:is(.td-layout-tutorial, .td-layout-til) .entry-header .page-description {
	order: 3;
	max-width: 36em;
	margin: 0;
	font-size: var(--td-text-lg);
	line-height: 1.6;
	color: var(--td-muted);
}

:is(.td-layout-tutorial, .td-layout-til) .entry-header .page-description p {
	margin: 0;
}

/* ---- Tutorial ----------------------------------------------------------- */

.td-layout-tutorial .entry-header .page-title {
	max-width: 15em;
	font-size: clamp(32px, 6.4vw, 68px);
}

/* Chips: "Tutorial" filled violet, "N steps" and "N min read" outlined, date as plain text. */
.td-layout-tutorial .entry-header .entry-meta .meta-steps,
.td-layout-tutorial .entry-header .entry-meta .meta-reading-time {
	padding: 2px 12px;
	background: var(--td-paper);
	border: var(--td-border);
	border-radius: var(--td-radius-pill);
	font-weight: 600;
	line-height: 1.6;
}

.td-layout-tutorial .entry-header .entry-meta .meta-date {
	order: 1;
	font-weight: 500;
}

body.td-layout-tutorial .entry-header .entry-meta .meta-categories a[href*="/category/tutorial/"] {
	--td-chip-bg: var(--td-violet);
	--td-chip-fg: var(--td-paper);
}

/* Reading column: 740px children on phones. From 769px the content is a grid whose step column fills the content box
 * and is left-aligned with the title (WordPress's auto side margins have nothing to centre in a grid area). */
.td-layout-tutorial .entry-content {
	position: relative;
	max-width: var(--td-w);
	margin-inline: auto;
}

.td-layout-tutorial .entry-content.is-layout-constrained > * {
	max-width: var(--td-col);
}

.td-layout-tutorial .entry-content.is-layout-constrained > .td-step-rail {
	display: none;
}

/* Step card: numeral and title on one line, as the board has it. */
@media (min-width: 769px) {
	.td-layout-tutorial .is-style-td-step {
		display: grid;
		grid-template-columns: auto minmax(0, 1fr);
		column-gap: 18px;
		align-items: center;
	}

	.td-layout-tutorial .is-style-td-step > * {
		grid-column: 1 / -1;
	}

	.td-layout-tutorial .is-style-td-step::before {
		grid-column: 1;
		grid-row: 1;
		margin-bottom: 0;
	}

	.td-layout-tutorial .is-style-td-step > :first-child:is(h2, h3) {
		grid-column: 2;
		grid-row: 1;
		margin: 0 0 4px;
	}
}

/* Tutorial grid (every tutorial, with or without "You'll need"): one reading column, left-aligned.
 * Grid items do not collapse margins, so the block-end margin is dropped to keep the gaps single. */
@media (min-width: 769px) {
	.td-layout-tutorial .entry-content.is-layout-constrained {
		display: grid;
		/* The column fills the content box (board 08): step cards carry their own padding,
		   so the lines inside stay readable. */
		grid-template-columns: minmax(0, 1fr);
		column-gap: 32px;
		align-items: start;
	}

	.td-layout-tutorial .entry-content.is-layout-constrained > * {
		grid-column: 1;
		max-width: none;
		margin-block-end: 0;
	}

	/* Step cards carry a 32 px top margin; give the other blocks that sit between
	   grid rows (the "You'll need" box after the intro paragraph, Done! (lime), author box)
	   the same so they don't touch. (row-gap would multiply across the 999 implicit
	   rows the sticky rail spans.) */
	.td-layout-tutorial .entry-content.is-layout-constrained > :is(.td-callout, .td-author, .is-style-td-dashed, .is-style-td-lime) {
		margin-block-start: 32px;
	}

	/* Intro paragraphs before the steps: same gap as article paragraphs (24px), since the rule above drops it. */
	.td-layout-tutorial .entry-content.is-layout-constrained > p {
		margin-block-end: 24px;
	}
}

/* "You'll need" sits full width in the reading column, above the steps (it is the first block in the stored
 * content, so no reordering is needed). Its zine heading never splits inside a word; phones get a smaller size. */
.td-layout-tutorial .td-callout--need h2 {
	white-space: nowrap;
}

@media (max-width: 480px) {
	body.td-theme.td-layout-tutorial .td-callout--need h2.is-style-td-zine {
		font-size: clamp(26px, 8.2vw, 34px);
	}
}

/* Step rail in a left column; the steps take the rest of the content box. The rail starts at 1048px, where the
 * 90vw content box leaves at least 740px (942 / 0.9 = 1046.7px) for the steps.
 * Only tutorials that get a rail (body.td-tutorial-nav: steps, or at least two h2 sections). Keep in sync with assets/js/layouts.js. */
@media (min-width: 1048px) {
	body.td-tutorial-nav.td-layout-tutorial .entry-content.is-layout-constrained {
		grid-template-columns: 170px minmax(0, 1fr);
	}

	body.td-tutorial-nav.td-layout-tutorial .entry-content.is-layout-constrained > * {
		grid-column: 2;
	}

	body.td-tutorial-nav.td-layout-tutorial .entry-content.is-layout-constrained > .td-step-rail {
		display: block;
		grid-column: 1;
		grid-row: 1 / span 999;
		position: sticky;
		top: calc(var(--admin-bar, 0px) + 96px);
		margin: 0;
	}
}

.td-step-rail ol {
	list-style: none;
	margin: 0;
	padding: 0;
	counter-reset: tdrail;
	display: grid;
	gap: 18px;
}

.td-step-rail li {
	counter-increment: tdrail;
	margin: 0;
	padding: 0;
}

.td-step-rail a {
	display: flex;
	align-items: center;
	gap: 10px;
	font-size: var(--td-text-sm);
	font-weight: 700;
	line-height: 1.3;
	color: var(--td-ink);
	text-decoration: none;
}

.td-step-rail a::before {
	content: counter(tdrail, decimal-leading-zero);
	flex: none;
	display: grid;
	place-items: center;
	width: 36px;
	height: 36px;
	box-sizing: border-box;
	background: var(--td-paper);
	border: var(--td-border);
	border-radius: 50%;
	font-family: var(--td-display);
	font-weight: 900;
	font-style: italic;
	font-size: 13px;
}

.td-step-rail a.is-done::before {
	background: var(--td-lime);
}

.td-step-rail a.is-current::before {
	background: var(--td-violet);
	color: var(--td-paper);
}

.td-step-rail a:hover {
	text-decoration: underline;
}

.td-step-rail a:focus-visible {
	outline: 3px solid var(--td-violet);
	outline-offset: 2px;
	border-radius: 999px;
}

/* Long step headings: two lines at most in the 170 px rail (full text in title). */
.td-step-rail__label {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	overflow: hidden;
}

/* ---- Quick note (TIL): title area becomes the top of the dashed card ----- */

body.td-layout-til .hero-section {
	position: relative;
	box-sizing: border-box;
	width: 100%;
	max-width: 920px;
	margin: 72px auto 0;
	padding: clamp(56px, 7vw, 72px) clamp(20px, 5vw, 64px) 0;
	border: 2px dashed var(--td-ink);
	border-bottom: 0;
	border-radius: var(--td-radius-xl) var(--td-radius-xl) 0 0;
}

body.td-layout-til .hero-section::before {
	content: 'TIL';
	position: absolute;
	top: -0.5em;
	left: clamp(16px, 4vw, 40px);
	padding: 0 12px;
	background: var(--td-ground);
	font-family: var(--td-display);
	font-weight: 900;
	font-style: italic;
	font-size: clamp(64px, 9vw, 104px);
	line-height: 0.9;
	color: var(--td-lime);
	-webkit-text-stroke: 3px var(--td-ink);
	paint-order: stroke fill;
	text-shadow: var(--td-shadow-md);
	transform: rotate(-4deg);
}

body.td-layout-til .entry-content::before {
	content: none;
}

body.td-layout-til .entry-content.is-layout-constrained {
	max-width: 920px;
	margin-top: 0;
	padding: 8px clamp(20px, 5vw, 64px) clamp(28px, 5vw, 48px);
	border-top: 0;
	border-radius: 0 0 var(--td-radius-xl) var(--td-radius-xl);
}

.td-layout-til .entry-header .page-title {
	max-width: 16em;
	font-size: clamp(30px, 5.2vw, 52px);
}

.td-layout-til .entry-header .entry-meta .meta-reading-time::before {
	content: "\00b7";
	margin-right: 10px;
}

.td-layout-til .entry-header .entry-meta .meta-date + .meta-reading-time {
	margin-left: -4px;
}

/* Quick note: the card's first paragraph is the lead-in, set larger as on the board. */
.td-layout-til .entry-content > p:first-child {
	font-size: var(--td-text-lg);
	line-height: 1.65;
}

/* Quick note: author + share row at the foot of the card (techdigest_til_author_row()). */
.td-layout-til .td-til-meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 14px 20px;
	margin-top: 28px;
	padding-top: 20px;
	border-top: 2px dashed var(--td-ink);
}

.td-til-author {
	display: flex;
	align-items: center;
	gap: 12px;
	min-width: 0;
}

/* Same transparent cut-out as the author box (techdigest.css): no circle, border or fill of its own. Since 1.4.28. */
.td-til-avatar {
	flex: none;
	width: 48px;
	height: 48px;
	background: url("../brand/author-avatar-pop.webp") center / contain no-repeat;
}

.td-til-author__name {
	font-weight: 600;
	font-size: var(--td-text-md);
}

.td-til-actions {
	display: flex;
	align-items: center;
	gap: 10px;
}

.td-til-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	box-sizing: border-box;
	padding: 6px 20px;
	border: var(--td-border);
	border-radius: var(--td-radius-pill);
	background: var(--td-paper);
	color: var(--td-ink);
	font: 600 var(--td-text-md) / 1 var(--td-body);
	text-decoration: none;
	cursor: pointer;
}

.td-til-btn--copy {
	background: var(--td-lime);
	box-shadow: var(--td-shadow-sm);
}

@media (hover: hover) {
	.td-til-btn:hover {
		background: var(--td-ink);
		color: var(--td-lime);
	}
}

.td-til-btn:focus-visible {
	background: var(--td-ink);
	color: var(--td-lime);
}

.td-til-btn:focus-visible {
	outline: 3px solid var(--td-violet);
	outline-offset: 3px;
}

/* "More quick notes" strip under the card (blocksy:content:bottom). */
.td-til-more {
	box-sizing: border-box;
	width: var(--td-w);
	margin: 72px auto 0;
	padding-bottom: 72px;
}

body.td-theme .td-til-more__title {
	margin: 0 0 28px;
}

.td-til-more__title a {
	color: inherit;
	text-decoration: none;
	-webkit-text-stroke: inherit;
}

.td-til-more__list {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 24px;
	margin: 0;
	padding: 0 6px 8px 0;
	list-style: none;
}

.td-til-more__card {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin: 0;
	padding: 22px 24px;
	border: var(--td-border);
	border-radius: var(--td-radius-lg);
	background: var(--td-paper);
	box-shadow: var(--td-shadow-md);
}

.td-til-more__card:first-child {
	background: var(--td-lime);
}

/* No movement on hover: a hover transform moves the hit area, so a pointer at the edge made it pulse (1.5.15, see brand-motion.css). */
.td-til-more__card:hover,
.td-til-more__card:focus-within {
	box-shadow: 8px 8px 0 var(--td-ink);
}

.td-til-more__card {
	transition: box-shadow 0.15s ease;
}

.td-til-more__tag {
	font-family: var(--td-display);
	font-weight: 900;
	font-style: italic;
	font-size: var(--td-text-xl);
	line-height: 1;
}

.td-til-more__link {
	color: var(--td-ink);
	font-weight: 700;
	font-size: var(--td-text-lg);
	line-height: 1.35;
	text-decoration: none;
}

/* The whole card is the tap target. */
.td-til-more__link::after {
	content: '';
	position: absolute;
	inset: 0;
	border-radius: inherit;
}

.td-til-more__link:focus-visible {
	outline: none;
}

.td-til-more__card:has(.td-til-more__link:focus-visible) {
	outline: 3px solid var(--td-violet);
	outline-offset: 3px;
}

.td-til-more__meta {
	margin-top: auto;
	font-size: var(--td-text-sm);
}

@media (prefers-reduced-motion: reduce) {
	.td-til-more__card {
		transition: none;
	}
}

/* ---- Cover story --------------------------------------------------------- */

/* Reading column of 740px; the hero, wide/full blocks and the pull quote keep their own width. */
.td-layout-cover .entry-content.is-layout-constrained > :not(.td-cover-hero, .alignwide, .alignfull, .is-style-td-pull) {
	max-width: var(--td-col);
}

.td-layout-cover .entry-content.is-layout-constrained > .is-style-td-pull {
	max-width: min(900px, 100%);
}

/* Numbered section headings: lime "01" pill + title. */
.td-layout-cover .entry-content {
	counter-reset: tdsection;
}

.td-layout-cover .entry-content > h2:not(.is-style-td-zine, .is-style-td-zine-violet) {
	counter-increment: tdsection;
	display: flex;
	align-items: center;
	gap: 12px;
}

.td-layout-cover .entry-content > h2:not(.is-style-td-zine, .is-style-td-zine-violet)::before {
	content: counter(tdsection, decimal-leading-zero);
	content: counter(tdsection, decimal-leading-zero) / "";
	flex: none;
	padding: 3px 10px;
	background: var(--td-lime);
	border: var(--td-border);
	border-radius: var(--td-radius-pill);
	font-family: var(--td-mono, ui-monospace, monospace);
	font-size: 13px;
	font-weight: 700;
	line-height: 1.4;
	color: var(--td-ink);
}

/* Hero: title sized to two lines beside a smaller arch image, tighter vertical rhythm. */
body.td-theme .td-cover-hero h1.is-style-td-zine {
	margin-block: 16px 20px;
	font-size: clamp(40px, 6.2vw, 88px);
	line-height: 1;
}

@media (min-width: 769px) {
	.td-cover-hero .wp-block-post-featured-image {
		max-width: 380px;
		margin-left: auto;
	}
}

/* Hero chips: "Cover Story" is the lime pill; the topic categories read as plain text beside it. */
.td-cover-hero .taxonomy-category {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px 12px;
}

.td-cover-hero .taxonomy-category a {
	order: 1;
	--td-chip-bg: transparent;
	--td-chip-fg: var(--td-paper);
	--td-chip-border: 0;
	--td-chip-pad: 0;
	--td-chip-weight: 500;
}

body.td-theme .td-cover-hero .taxonomy-category a[href*="/category/cover-story/"] {
	order: 0;
	--td-chip-bg: var(--td-lime);
	--td-chip-fg: var(--td-ink);
	--td-chip-border: var(--td-border);
	--td-chip-pad: 2px 12px;
	--td-chip-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	font-size: 12px;
}

body.td-theme .td-cover-hero .taxonomy-category a:not([href*="/category/cover-story/"]) {
	color: var(--td-paper);
}

.td-cover-hero .td-cover-meta {
	align-items: center;
}

.td-cover-hero .td-cover-author {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	font-weight: 700;
}

.td-cover-hero .td-cover-avatar {
	flex: none;
	width: 28px;
	height: 28px;
	box-sizing: border-box;
	background: var(--td-lime);
	border: var(--td-border);
	border-radius: 50%;
}

.td-cover-hero .td-cover-meta .td-cover-read {
	margin: 0;
	font-weight: 500;
}

/* Previous / next issue cards (Blocksy post navigation, enabled for cover posts in inc/layouts.php). */
.td-layout-cover .post-navigation {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 20px;
	max-width: var(--td-w);
	margin: 56px auto 0;
	padding: 28px 0 0;
	border-top: 2px dashed var(--td-ink);
}

.td-layout-cover .post-navigation a,
.td-layout-cover .post-navigation .nav-item-prev:empty,
.td-layout-cover .post-navigation .nav-item-next:empty {
	box-sizing: border-box;
	min-width: 0;
}

.td-layout-cover .post-navigation::after {
	content: none;
}

.td-layout-cover .post-navigation a {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	justify-content: center;
	gap: 6px;
	padding: 18px 22px;
	background: var(--td-paper);
	color: var(--td-ink);
	border: 2px dashed var(--td-ink);
	border-radius: var(--td-radius);
	text-decoration: none;
	transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.td-layout-cover .post-navigation a.nav-item-next {
	background: var(--td-ink);
	color: var(--td-paper);
	border-style: solid;
	text-align: right;
	align-items: flex-end;
	grid-column: 2;
}

.td-layout-cover .post-navigation .nav-item-prev {
	grid-column: 1;
}

.td-layout-cover .post-navigation figure {
	display: none;
}

.td-layout-cover .post-navigation .item-content {
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 0;
	margin: 0;
}

.td-layout-cover .post-navigation .item-label {
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

.td-layout-cover .post-navigation .nav-item-prev .item-label::before {
	content: "\2190\00a0";
	content: "\2190\00a0" / "";
}

.td-layout-cover .post-navigation .nav-item-next .item-label {
	color: var(--td-lime);
}

.td-layout-cover .post-navigation .nav-item-next .item-label::after {
	content: "\00a0\2192";
	content: "\00a0\2192" / "";
}

.td-layout-cover .post-navigation .item-title {
	display: block;
	font-family: var(--td-body);
	font-size: var(--td-text-lg);
	font-weight: 700;
	line-height: 1.3;
	color: inherit;
}

/* Hover changes the shadow only: a hover transform moved the hit area, so a pointer at the edge made it pulse
   (1.5.15). Keyboard focus keeps the lift (no pointer involved). */
.td-layout-cover .post-navigation a:hover,
.td-layout-cover .post-navigation a:focus-visible {
	box-shadow: var(--td-shadow-sm);
}

.td-layout-cover .post-navigation a:focus-visible {
	transform: translate(-2px, -2px);
}

@media (prefers-reduced-motion: reduce) {
	.td-layout-cover .post-navigation a {
		transition: none;
	}

	.td-layout-cover .post-navigation a:hover,
	.td-layout-cover .post-navigation a:focus-visible {
		transform: none;
	}
}

/* ---- Phone ---------------------------------------------------------------- */

@media (max-width: 768px) {
	body.td-layout-til .hero-section {
		margin-top: 56px;
	}

	.td-layout-til .td-til-meta {
		flex-direction: column;
		align-items: flex-start;
	}

	/* "More quick notes" scrolls sideways like the TIL archive (techdigest-mobile.css). */
	.td-til-more {
		margin-top: 48px;
		padding-bottom: 40px;
	}

	.td-til-more__list {
		display: flex;
		flex-wrap: nowrap;
		gap: 14px;
		overflow-x: auto;
		scroll-snap-type: x mandatory;
		scrollbar-width: none;
		padding: 4px 16px 14px;
		margin-inline: calc(5vw * -1);
	}

	.td-til-more__list::-webkit-scrollbar {
		display: none;
	}

	.td-til-more__card {
		flex: 0 0 86%;
		scroll-snap-align: center;
		box-shadow: var(--td-shadow-sm);
	}

	.td-layout-cover .post-navigation {
		grid-template-columns: 1fr;
		margin-top: 40px;
		padding-top: 20px;
	}

	.td-layout-cover .post-navigation .nav-item-prev,
	.td-layout-cover .post-navigation a.nav-item-next {
		grid-column: 1;
	}

	.td-layout-cover .post-navigation .nav-item-prev:empty {
		display: none;
	}
}

/* Phones: the step title (35px from the h2 size) wrapped to 4 lines and outsized the 32px post title.
   The "01" numeral above it keeps its size. */
@media (max-width: 768px) {
	body.td-theme.td-layout-tutorial .is-style-td-step > :first-child:is(h2, h3) {
		font-size: 24px;
		line-height: 1.2;
	}
}
