/* --------------------------------------------------------------------------
   Article layout (default posts, body.td-layout-article): design review item 6.
   Loaded on single posts only (inc/setup.php). Every rule is scoped to
   .td-layout-article, so Tutorial, Cover story and Quick note are untouched.
   Elements are Blocksy settings (tools/customizer.php); this file is the styling
   they cannot express. DOM: article > .hero-section > header.entry-header
   (a.td-back, ul.entry-meta chips, h1.page-title, p.td-standfirst, ul.entry-meta[data-id="second"] byline),
   .ct-share-box, .entry-content; related posts live in .ct-related-posts-container
   after the article. The table of contents (assets/js/techdigest.js) is
   .td-toc-rail > nav.td-toc inside .entry-content (sticky, >= 1024px); below that the server-rendered
   details.td-toc-mini (inc/layouts.php). The share box is lifted above .td-author by the same script.
   -------------------------------------------------------------------------- */

.td-layout-article {
	--td-article-col: 740px;
	--td-article-rail: 400px;
	--td-article-gap: 44px;
	--td-w: min(1290px, 90vw);
	--td-col: var(--td-article-col);
	--td-article-measure: 720px;
	--td-lead: calc(var(--td-w) - var(--td-col));
}

@media (min-width: 1024px) {
	/* Design mock: a 400px rail, a 44px gap, then the reading column, capped at 720px (owner, 1.5.8) so
	   lines stay readable; on wide screens the space right of the column stays empty. --td-lead is
	   the column's offset from the container's left edge (rail + gap). */
	.td-layout-article.td-has-toc {
		--td-col: min(var(--td-article-measure), calc(var(--td-w) - var(--td-article-rail) - var(--td-article-gap)));
		--td-lead: calc(var(--td-article-rail) + var(--td-article-gap));
	}

	/* The empty space right of the capped column: padding on the boxes that use --td-lead, so their
	   content box is exactly the column and WordPress' auto margins resolve to 0 (left-aligned text). */
	.td-layout-article.td-has-toc .entry-content,
	.td-layout-article.td-has-toc .entry-tags,
	.td-layout-article.td-has-toc .ct-share-box {
		padding-right: calc(var(--td-w) - var(--td-lead) - var(--td-col));
	}
}

@media (prefers-reduced-motion: reduce) {
	html {
		scroll-behavior: auto;
	}
}

/* ---- Title area -------------------------------------------------------- */

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

/* Words-first head (1.5.4). Blocksy prints: back link, chips list, h1, standfirst, byline list (data-id="second"): date and reading time.
   Flex order keeps that reading order whatever the source order is. */
.td-layout-article .td-back {
	order: 0;
	font-size: var(--td-text-sm);
	font-weight: 500;
	color: var(--td-ink);
	text-decoration: none;
	margin-bottom: 16px;
}

.td-layout-article .td-back:hover {
	text-decoration: underline;
}

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

/* Chips row. */
.td-layout-article .entry-header .entry-meta:not([data-id="second"]) {
	order: 1;
	margin-bottom: 18px;
}

/* Byline row. */
.td-layout-article .entry-header .entry-meta[data-id="second"] {
	order: 4;
	margin-top: 28px;
}

/* Blocksy's "slash" separators are drawn on li::after: drop them, the chips and the dots do the job. */
.td-layout-article .entry-header .entry-meta > li {
	margin: 0;
	padding: 0;
}

.td-layout-article .entry-header .entry-meta > li::before,
.td-layout-article .entry-header .entry-meta > li::after {
	content: none;
}

.td-layout-article .entry-header .entry-meta .meta-categories {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

/* Byline: "date · N min read" (no author: the author box ends the post). */
.td-layout-article .entry-header .entry-meta[data-id="second"] > li {
	font-weight: 500;
}

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

.td-layout-article .entry-header .page-title {
	order: 2;
	max-width: 880px;
	margin: 0 0 20px;
	font-family: var(--td-body);
	font-weight: 700;
	font-size: 68px;
	line-height: 1.02;
	letter-spacing: -0.035em;
	color: var(--td-ink);
	overflow-wrap: break-word;
	text-wrap: balance;
}

.td-layout-article .entry-header .td-standfirst {
	order: 3;
	max-width: 760px;
	margin: 0;
	font-family: var(--td-body);
	font-size: 22px;
	line-height: 1.5;
	color: #222;
}

.td-layout-article .hero-section {
	margin-bottom: 36px;
}

/* 120 x 2px ink rule closing the head, 36px below the byline; the content starts 36px below the rule. */
.td-layout-article .entry-header::after {
	content: "";
	order: 5;
	display: block;
	width: 120px;
	height: 2px;
	margin-top: 36px;
	background: var(--td-ink);
}

/* ---- Reading column + table of contents gutter ------------------------- */

.td-layout-article .entry-content {
	position: relative;
	max-width: var(--td-w);
	margin-inline: auto;
}

/* No table of contents: the column is centred by WordPress' auto margins on constrained children. */
.td-layout-article .entry-content.is-layout-constrained > * {
	max-width: var(--td-article-col);
}

.td-layout-article .entry-content.is-layout-constrained > .td-toc-rail {
	max-width: none;
}

.td-layout-article .entry-content img,
.td-layout-article .entry-content pre {
	max-width: 100%;
}

/* The author card (pattern, already in the content) now sits in the 740px column: keep the avatar beside the text. */
@media (min-width: 769px) {
	.td-layout-article .td-author {
		flex-wrap: nowrap;
	}

	.td-layout-article .td-author > :last-child {
		flex: 1 1 0;
		min-width: 0;
	}
}

/* ---- Share box: outline pills ------------------------------------------ */

.td-layout-article .ct-share-box {
	max-width: var(--td-article-col);
	margin: 0 auto 28px;
	padding: 0;
	border: 0;
}

/* Under the article (stored at the bottom); techdigest.js lifts it into the content just above the author box,
   where the content's own column rules apply. Spacing there: */
.td-layout-article .entry-content > .ct-share-box {
	margin-top: 40px;
	margin-bottom: 32px;
}

.td-layout-article .ct-share-box > div {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	border: 0;
}

.td-layout-article .ct-share-box a[data-network] {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-height: 40px;
	padding: 0 18px;
	border: var(--td-border);
	border-radius: var(--td-radius-pill);
	background: transparent;
	color: var(--td-ink);
	font-size: var(--td-text-sm);
	font-weight: 700;
	line-height: 1;
	text-decoration: none;
	box-sizing: border-box;
}

@media (hover: hover) {
	.td-layout-article .ct-share-box a[data-network]:hover {
		background: var(--td-lime);
	}
}

.td-layout-article .ct-share-box a[data-network]:focus-visible {
	background: var(--td-lime);
}

.td-layout-article .ct-share-box a[data-network]:focus-visible {
	outline: 3px solid var(--td-violet);
	outline-offset: 2px;
}

.td-layout-article .ct-share-box .ct-icon-container {
	display: inline-flex;
	min-height: 0;
	padding: 0;
	width: auto;
	height: auto;
}

.td-layout-article .ct-share-box svg {
	width: 16px;
	height: 16px;
	fill: currentColor;
}

/* Labels: Blocksy renders icon-only links with an aria-label; show it as text. */
.td-layout-article .ct-share-box a[data-network]::after {
	content: attr(data-td-label);
}

/* ---- Tags -------------------------------------------------------------- */

.td-layout-article .entry-tags {
	max-width: var(--td-w);
	margin: 40px auto 0;
	padding: 0;
}

.td-layout-article .entry-tags-items {
	width: min(100%, var(--td-article-col));
	margin-inline: auto;
	padding-top: 24px;
	border-top: 2px dashed var(--td-ink);
}

@media (min-width: 1024px) {
	.td-layout-article.td-has-toc .entry-tags {
		padding-left: var(--td-lead);
		box-sizing: border-box;
	}

	.td-layout-article.td-has-toc .entry-tags-items {
		width: 100%;
		margin-inline: 0;
	}
}

.td-layout-article .entry-tags .ct-module-title {
	display: none;
}

.td-layout-article .entry-tags a {
	display: inline-block;
	margin: 0 8px 8px 0;
	padding: 4px 14px;
	border: var(--td-border);
	border-radius: var(--td-radius-pill);
	background: var(--td-paper);
	color: var(--td-ink);
	font-size: var(--td-text-sm);
	font-weight: 500;
	text-decoration: none;
}

.td-layout-article .entry-tags a:hover {
	background: var(--td-lime);
}

/* ---- Related posts: "Keep reading" -------------------------------------- */

.td-layout-article .ct-related-posts-container {
	margin-top: 64px;
	padding: 40px 0 80px;
	border-top: 2px dashed var(--td-ink);
	background: transparent;
}

.td-layout-article .ct-related-posts-container .ct-container {
	max-width: min(1290px, 90vw);
}

.td-layout-article .ct-related-posts .ct-module-title {
	margin: 0 0 32px;
	font-family: var(--td-display);
	font-weight: 900;
	font-style: italic;
	font-size: clamp(36px, 5vw, 64px);
	line-height: 0.9;
	text-transform: uppercase;
	color: var(--td-violet);
	-webkit-text-stroke: 2.5px var(--td-ink);
	paint-order: stroke fill;
	text-shadow: var(--td-shadow-sm);
	transform: rotate(-2deg);
	transform-origin: left bottom;
	padding: 0.08em 0;
}

.td-layout-article .ct-related-posts-items {
	gap: 28px;
}

.td-layout-article .ct-related-posts-items article > div {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	height: 100%;
	padding: 22px 20px;
	overflow: hidden;
	box-sizing: border-box;
	background: var(--td-paper);
	border: var(--td-border);
	border-radius: var(--td-card-radius, var(--td-radius));
	box-shadow: var(--td-card-shadow, var(--td-shadow));
}

/* Cover image first: 16:9 (Blocksy sets the ratio inline), flush to the card edges, 2px ink rule under it. */
.td-layout-article .ct-related-posts-items article > div:has(> .ct-media-container) {
	padding-top: 0;
}

.td-layout-article .ct-related-posts-items .ct-media-container {
	display: block;
	align-self: stretch;
	width: auto;
	margin: 0 -20px 18px;
	border-bottom: 2px solid var(--td-ink);
	line-height: 0;
}

.td-layout-article .ct-related-posts-items .ct-media-container img {
	display: block;
	width: 100%;
	height: auto;
	object-fit: cover;
}

.td-layout-article .ct-related-posts-items .entry-meta {
	margin: 0;
	padding: 0;
	font-size: var(--td-text-sm);
}

.td-layout-article .ct-related-posts-items .entry-meta li::after {
	content: none;
}

/* One chip per card: the extra category links go (the ", " between them is stripped server side). */
.td-layout-article .ct-related-posts-items .meta-categories a {
	font-size: var(--td-text-xs);
}

.td-layout-article .ct-related-posts-items .meta-categories a:nth-of-type(n+2) {
	display: none;
}

.td-layout-article .ct-related-posts-items .related-entry-title {
	margin: 14px 0 12px;
	font-family: var(--td-body);
	font-weight: 700;
	font-size: 20px;
	line-height: 1.25;
}

.td-layout-article .ct-related-posts-items .related-entry-title a {
	color: var(--td-ink);
	text-decoration: none;
}

.td-layout-article .ct-related-posts-items .related-entry-title a:hover {
	text-decoration: underline;
}

.td-layout-article .ct-related-posts-items article > div > .entry-meta:last-child {
	margin-top: auto;
	color: var(--td-muted);
}

/* ---- Table of contents (wide screens only) ------------------------------ */

.td-toc-rail {
	display: none;
}

@media (min-width: 1024px) {
	/* The content box is exactly the column wide, so WordPress' auto margins resolve to 0 and the
	   rail's left edge meets the image's left edge, the column's right edge the image's right edge. */
	.td-layout-article.td-has-toc .entry-content {
		padding-left: var(--td-lead);
		box-sizing: border-box;
	}

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

	.td-layout-article.td-has-toc .entry-content.is-layout-constrained > .td-toc-rail {
		max-width: none;
	}

	.td-layout-article .td-toc-rail {
		display: block;
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		width: var(--td-article-rail);
		margin: 0;
	}

	/* No JS: the share box stays after the article; keep it in the text column beside the rail. */
	.td-layout-article.td-has-toc .ct-share-box {
		max-width: var(--td-w);
		margin: 0 auto 28px;
		padding-left: var(--td-lead);
		box-sizing: border-box;
	}

	.td-layout-article.td-has-toc .entry-content > .ct-share-box {
		max-width: var(--td-col);
		margin: 40px 0 32px;
		padding-left: 0;
		padding-right: 0;
	}

	.td-layout-article .td-toc-rail__inner {
		position: sticky;
		/* Sticky header (shrunk height, as Blocksy's own sticky sidebars use it) + 32px. The rail is as tall as the
		   content box, so it stops at the end of the article and never reaches the Keep reading band or the footer. */
		top: calc(var(--admin-bar, 0px) + var(--theme-frame-size, 0px) + var(--header-sticky-height, 64px) * var(--sticky-shrink, 100) / 100 + 32px);
		display: flex;
		flex-direction: column;
		gap: 16px;
	}

	.td-layout-article .td-toc {
		padding: 18px 20px;
		font-size: var(--td-text-sm);
	}

	.td-layout-article .td-toc__title {
		margin: 0 0 10px;
		font-family: var(--td-display);
		font-weight: 900;
		font-style: italic;
		font-size: 20px;
		line-height: 1;
		text-transform: uppercase;
		color: var(--td-lime);
		-webkit-text-stroke: 1.5px var(--td-ink);
		paint-order: stroke fill;
		text-shadow: 2px 2px 0 var(--td-ink);
	}

	.td-layout-article .td-toc ol {
		margin: 0;
		padding: 0;
		list-style: none;
	}

	.td-layout-article .td-toc li {
		margin: 0 0 8px;
		line-height: 1.35;
	}

	.td-layout-article .td-toc li:last-child {
		margin-bottom: 0;
	}

	.td-layout-article .td-toc a {
		color: var(--td-ink);
		text-decoration: underline;
		text-underline-offset: 3px;
	}

	.td-layout-article .td-toc a:hover,
	.td-layout-article .td-toc a[aria-current="location"] {
		background: var(--td-lime);
	}

	.td-layout-article .td-toc a:focus-visible {
		outline: 3px solid var(--td-violet);
		outline-offset: 2px;
	}
}

/* ---- Mini contents list (under 1024px; server-rendered in inc/layouts.php) ---- */

.td-toc-mini {
	margin: 0 0 24px;
	padding: 12px 18px;
	border: 2px dashed var(--td-ink);
	border-radius: 16px;
	font-family: var(--td-body);
	font-size: var(--td-text-sm);
}

.td-toc-mini summary {
	font-weight: 700;
	cursor: pointer;
	min-height: 24px;
}

.td-toc-mini summary:focus-visible,
.td-toc-mini a:focus-visible {
	outline: 3px solid var(--td-violet);
	outline-offset: 2px;
}

.td-toc-mini ol {
	margin: 8px 0 0;
	padding: 0;
	list-style: none;
}

.td-toc-mini a {
	display: block;
	padding: 7px 0;
	color: var(--td-ink);
	text-decoration: underline;
	text-underline-offset: 3px;
}

@media (min-width: 1024px) {
	.td-toc-mini {
		display: none;
	}
}

/* Headings jump clear of the sticky header. */
.td-layout-article .entry-content h2[id] {
	scroll-margin-top: 112px;
}

/* ---- Phone (the app UI: single column, no gutter) ----------------------- */

@media (max-width: 1023px) {
	.td-layout-article .entry-content {
		padding-left: 0;
	}

	.td-layout-article .entry-content.is-layout-constrained > * {
		max-width: 100%;
	}
}

@media (max-width: 768px) {
	.td-layout-article .td-back {
		margin-bottom: 12px;
	}

	.td-layout-article .entry-header .page-title {
		font-size: 36px;
	}

	.td-layout-article .entry-header .td-standfirst {
		font-size: 17px;
	}

	.td-layout-article .entry-header::after {
		margin-top: 22px;
	}

	.td-layout-article .entry-header .entry-meta[data-id="second"] {
		margin-top: 22px;
		font-size: 13px;
	}

	.td-layout-article .entry-header .entry-meta .meta-reading-time::before {
		margin-right: 6px;
	}

	.td-layout-article .ct-related-posts-container {
		margin-top: 40px;
		padding: 32px 0 56px;
	}

	.td-layout-article .ct-related-posts-items {
		gap: 22px;
	}
}
