/**
 * Cheat sheet styles.
 *
 * Loaded only on cheat sheet singles and the archive, so it stays out of the
 * critical path for the 134 tutorials. Uses the theme's existing tokens.
 */

/* ---------- hero ---------- */
.em-cs-hero {
	padding-top: 2.5rem;
	padding-bottom: 2.5rem;
}

.em-cs-badges {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin-bottom: 0.75rem;
}

.em-cs-lede {
	max-width: 60ch;
	margin-top: 0.75rem;
	color: var(--em-muted);
	font-size: 1.05rem;
}

.em-cs-meta {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin-top: 1rem;
}

.em-cs-chip {
	font-family: 'JetBrains Mono', ui-monospace, monospace;
	font-size: 0.72rem;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	padding: 0.25rem 0.6rem;
	border: 1px solid var(--em-border);
	border-radius: 3px;
	color: var(--em-muted);
	white-space: nowrap;
}

.em-cs-chip-ok {
	color: var(--em-success);
	border-color: color-mix(in srgb, var(--em-success) 40%, transparent);
}

.em-cs-tutorial-link {
	margin-top: 1.25rem;
	color: var(--em-muted);
	font-size: 0.95rem;
}

.em-cs-tutorial-link a {
	color: var(--em-primary);
	font-weight: 600;
}

/* ---------- layout: jump nav + content ---------- */
.em-cs-layout {
	display: grid;
	grid-template-columns: 220px minmax(0, 1fr);
	gap: 2.5rem;
	align-items: start;
}

.em-cs-nav {
	position: sticky;
	top: 90px;
	border-left: 2px solid var(--em-border);
	padding-left: 1rem;
}

.em-cs-nav-title {
	font-family: 'JetBrains Mono', ui-monospace, monospace;
	font-size: 0.7rem;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--em-muted);
	margin: 0 0 0.75rem;
}

.em-cs-nav ol {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.em-cs-nav a {
	color: var(--em-muted);
	font-size: 0.9rem;
	text-decoration: none;
	display: block;
	line-height: 1.4;
}

.em-cs-nav a:hover,
.em-cs-nav a:focus-visible {
	color: var(--em-primary);
}

.em-cs-print {
	margin-top: 1.25rem;
	background: none;
	border: 1px solid var(--em-border);
	border-radius: 4px;
	color: var(--em-muted);
	padding: 0.4rem 0.75rem;
	font-size: 0.82rem;
	cursor: pointer;
	width: 100%;
}

.em-cs-print:hover {
	color: var(--em-text);
	border-color: var(--em-primary);
}

/* ---------- content: denser than a tutorial ---------- */
.em-cs-content {
	max-width: none;
}

.em-cs-content .em-cs-purpose {
	font-size: 1.1rem;
	color: var(--em-text);
	border-left: 3px solid var(--em-primary);
	padding-left: 1rem;
	margin-bottom: 2rem;
}

.em-cs-content h2 {
	font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
	font-size: 1.3rem;
	margin-top: 2.5rem;
	margin-bottom: 0.75rem;
	padding-bottom: 0.4rem;
	border-bottom: 1px solid var(--em-border);
	scroll-margin-top: 90px;
}

.em-cs-content h3 {
	font-size: 1.05rem;
	margin-top: 1.75rem;
	margin-bottom: 0.5rem;
	scroll-margin-top: 90px;
}

/* Tables carry most of the value on a cheat sheet. */
.em-cs-content .wp-block-table {
	margin: 1rem 0 1.75rem;
	overflow-x: auto;
}

.em-cs-content .wp-block-table table {
	border-collapse: collapse;
	width: 100%;
	font-size: 0.93rem;
	min-width: 480px;
}

.em-cs-content .wp-block-table th,
.em-cs-content .wp-block-table td {
	text-align: start;
	vertical-align: top;
	padding-inline: 0 2rem;
}

.em-cs-content .wp-block-table th {
	font-family: 'JetBrains Mono', ui-monospace, monospace;
	font-size: 0.7rem;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--em-muted);
	font-weight: 500;
	border-bottom: 1px solid var(--em-text);
	padding-block: 0 0.55rem;
}

.em-cs-content .wp-block-table td {
	padding-block: 0.75rem;
	border-bottom: 1px solid var(--em-border);
	line-height: 1.55;
}

/* Every column after the first gets a rule and a matching inset, so a
   three-column error table reads as columns instead of a run-on line. */
.em-cs-content .wp-block-table th + th,
.em-cs-content .wp-block-table td + td {
	border-inline-start: 1px solid var(--em-border);
	padding-inline-start: 2rem;
}

.em-cs-content .wp-block-table th:last-child,
.em-cs-content .wp-block-table td:last-child {
	padding-inline-end: 0;
}

/* The first column is the thing you came for: give it room and keep the
   command on one line. */
.em-cs-content .wp-block-table td:first-child {
	width: 1%;
	white-space: nowrap;
}

.em-cs-content .wp-block-table code {
	font-family: 'JetBrains Mono', ui-monospace, monospace;
	font-size: 0.85em;
	background: var(--em-code-bg);
	color: var(--em-code-text);
	padding: 0.15rem 0.45rem;
	border-radius: 3px;
	white-space: nowrap;
}

.em-cs-content .wp-block-code {
	background: var(--em-code-bg);
	color: var(--em-code-text);
	border: 1px solid var(--em-border);
	border-radius: 6px;
	padding: 1rem 1.1rem;
	overflow-x: auto;
	font-size: 0.88rem;
	line-height: 1.6;
}

.em-cs-verified-note {
	margin-top: 2.5rem;
	padding-top: 1rem;
	border-top: 1px solid var(--em-border);
	color: var(--em-muted);
	font-size: 0.88rem;
}

/* ---------- archive ---------- */
.em-cs-archive-lede {
	max-width: 60ch;
}

.em-cs-archive-stats {
	display: flex;
	flex-wrap: wrap;
	gap: 1.25rem;
	margin-top: 0.75rem;
	font-family: 'JetBrains Mono', ui-monospace, monospace;
	font-size: 0.75rem;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--em-muted);
}

.em-cs-filter {
	margin-top: 1.5rem;
	max-width: 26rem;
}

.em-cs-filter input[type="search"] {
	width: 100%;
	padding: 0.65rem 0.9rem;
	border: 1px solid var(--em-border);
	border-radius: 0.5rem;
	background: var(--em-bg-card);
	color: var(--em-text);
	font-size: 0.95rem;
}

.em-cs-filter input[type="search"]:focus-visible {
	outline: 2px solid var(--em-primary);
	outline-offset: 1px;
}

.em-cs-filter-empty {
	margin: 0.75rem 0 0;
	color: var(--em-muted);
	font-size: 0.9rem;
}

.em-cs-group {
	margin-bottom: 3rem;
}

.em-cs-group-title {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	font-size: 1.05rem;
	margin: 0 0 1rem;
	padding-bottom: 0.6rem;
	border-bottom: 1px solid var(--em-border);
}

.em-cs-group-title a {
	color: var(--em-text);
	text-decoration: none;
}

.em-cs-group-title a:hover {
	color: var(--em-primary);
}

.em-cs-group-count {
	margin-inline-start: auto;
	font-family: 'JetBrains Mono', ui-monospace, monospace;
	font-size: 0.75rem;
	font-weight: 400;
	color: var(--em-muted);
}

.em-cs-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
	gap: 1rem;
}

/* A cheat sheet has no cover image, so the card is type and data --
   not a post card with an empty picture frame. */
.em-cs-card {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	padding: 1.1rem 1.2rem;
	border: 1px solid var(--em-border);
	border-radius: 0.5rem;
	background: var(--em-bg-card);
	text-decoration: none;
	color: inherit;
	transition: border-color 0.15s ease, transform 0.15s ease;
}

.em-cs-card:hover,
.em-cs-card:focus-visible {
	border-color: var(--em-primary);
	transform: translateY(-2px);
}

.em-cs-card-title {
	font-size: 1rem;
	line-height: 1.35;
	margin: 0;
	color: var(--em-text);
}

.em-cs-card-excerpt {
	font-size: 0.88rem;
	line-height: 1.55;
	margin: 0;
	color: var(--em-muted);
	flex: 1;
}

.em-cs-card-foot {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.4rem;
	margin-top: 0.35rem;
}

.em-cs-date {
	font-family: 'JetBrains Mono', ui-monospace, monospace;
	font-size: 0.7rem;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--em-muted);
	margin-inline-end: auto;
	white-space: nowrap;
}

.em-cs-empty {
	text-align: center;
	padding: 3rem 1rem;
	border: 1px dashed var(--em-border);
	border-radius: 0.5rem;
	color: var(--em-muted);
}

/* ---------- jump nav: current section ---------- */
.em-cs-nav ol {
	position: relative;
}

.em-cs-nav a {
	position: relative;
}

.em-cs-nav a.is-current {
	color: var(--em-primary);
	font-weight: 600;
}

/* A marker sitting on the nav's own rule, so the eye can find the current
   section without reading the list. */
.em-cs-nav a.is-current::before {
	content: "";
	position: absolute;
	left: calc(-1rem - 2px);
	top: 0;
	bottom: 0;
	width: 2px;
	background: var(--em-primary);
	border-radius: 1px;
}

/* ---------- heading anchors ---------- */
.em-cs-anchor {
	margin-inline-start: 0.5rem;
	color: var(--em-muted);
	text-decoration: none;
	font-weight: 400;
	opacity: 0;
	transition: opacity 0.15s ease;
}

.em-cs-content h2:hover .em-cs-anchor,
.em-cs-anchor:focus-visible {
	opacity: 1;
}

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
	.em-cs-layout {
		grid-template-columns: minmax(0, 1fr);
		gap: 1.25rem;
	}

	/* The jump nav belongs above the sheet on a phone. It used to be ordered
	   after the article, which put a section index below everything it
	   indexes -- reachable only by scrolling past the whole page. */
	.em-cs-nav {
		order: -1;
		position: static;
		border: 1px solid var(--em-border);
		border-radius: 0.5rem;
		padding: 0.85rem 0 0.85rem 0.85rem;
		display: flex;
		flex-direction: column;
		gap: 0.65rem;
	}

	.em-cs-nav-title {
		margin: 0;
	}

	/* One thumb-scrollable row. Wrapping six sections into a block would
	   push the sheet itself off the first screen. */
	.em-cs-nav ol {
		flex-direction: row;
		flex-wrap: nowrap;
		overflow-x: auto;
		gap: 0.45rem;
		padding-bottom: 0.2rem;
		padding-inline-end: 0.85rem;
		scrollbar-width: none;
		-webkit-overflow-scrolling: touch;
		scroll-snap-type: x proximity;
	}

	.em-cs-nav ol::-webkit-scrollbar {
		display: none;
	}

	.em-cs-nav li {
		flex: 0 0 auto;
		scroll-snap-align: start;
	}

	.em-cs-nav a {
		display: block;
		padding: 0.38rem 0.8rem;
		border: 1px solid var(--em-border);
		border-radius: 999px;
		background: var(--em-bg-card);
		color: var(--em-text);
		font-size: 0.85rem;
		white-space: nowrap;
	}

	.em-cs-nav a.is-current {
		border-color: var(--em-primary);
		color: var(--em-primary);
		background: var(--em-bg-2);
	}

	.em-cs-print {
		width: auto;
		align-self: flex-start;
		margin-top: 0;
		margin-inline-end: 0.85rem;
	}
}

@media (max-width: 640px) {
	.em-cs-content .wp-block-table th,
	.em-cs-content .wp-block-table td {
		padding-inline-end: 1rem;
	}

	.em-cs-content .wp-block-table th + th,
	.em-cs-content .wp-block-table td + td {
		padding-inline-start: 1rem;
	}
}

@media (max-width: 560px) {
	/* Anchors are a pointer affordance; on touch they are dead pixels next
	   to the heading. */
	.em-cs-anchor {
		display: none;
	}

	.em-cs-hero {
		padding-top: 1.75rem;
		padding-bottom: 1.75rem;
	}

	.em-cs-lede {
		font-size: 1rem;
	}

	.em-cs-content h2 {
		font-size: 1.18rem;
		margin-top: 2rem;
	}

	.em-cs-grid {
		grid-template-columns: minmax(0, 1fr);
	}
}

/* ---------- print: the sheet on paper ---------- */
@media print {
	.em-site-header,
	.em-site-footer,
	.em-cs-nav,
	.em-cs-filter,
	.em-cs-anchor,
	.em-share-bar,
	.em-post-nav,
	.em-single-sidebar,
	.em-hero-glow,
	.em-grid-3,
	#em-back-top {
		display: none !important;
	}

	.em-cs-layout {
		display: block;
	}

	body {
		background: #fff !important;
		color: #000 !important;
		font-size: 11pt;
	}

	.em-cs-content .wp-block-code,
	.em-cs-content .wp-block-table code {
		background: #f4f4f4 !important;
		color: #000 !important;
		border: 1px solid #ccc !important;
	}

	.em-cs-content h2 {
		break-after: avoid;
		page-break-after: avoid;
	}

	.em-cs-content .wp-block-table,
	.em-cs-content .wp-block-code {
		break-inside: avoid;
		page-break-inside: avoid;
	}

	/* On paper a link is useless unless the URL is visible. */
	.em-cs-content a[href^="http"]::after {
		content: " (" attr(href) ")";
		font-size: 9pt;
		color: #555;
	}
}

@media (prefers-reduced-motion: reduce) {
	.em-cs-nav a {
		transition: none;
	}
}



/* ---------- featured image ---------- */
.em-cs-featured img {
	display: block;
	width: 100%;
	height: auto;
}

.em-cs-card-thumb {
	display: block;
	margin: -1.1rem -1.2rem 0.85rem;
	aspect-ratio: 16 / 9;
	overflow: hidden;
	background: var(--em-bg-2);
	border-radius: 0.5rem 0.5rem 0 0;
}

.em-cs-card-thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

/* ---------- related sheets ---------- */
.em-cs-related {
	margin-top: 3.5rem;
	padding-top: 2rem;
	padding-bottom: 1rem;
	border-top: 1px solid var(--em-border);
}

.em-cs-related h2 {
	margin: 0 0 1.25rem;
}

/* ---------- archive hero ---------- */

/* The lede is held to a reading measure, which left the right of the hero
   empty. The filter moves up beside it instead of sitting underneath. */
@media (min-width: 900px) {
	.em-cs-archive-inner {
		display: grid;
		grid-template-columns: minmax(0, 1fr) minmax(0, 20rem);
		gap: 3rem;
		align-items: end;
	}

	.em-cs-filter {
		margin-top: 0;
		max-width: none;
	}
}

.em-cs-archive-copy {
	min-width: 0;
}

/* ---------- icon on the cheat sheet card ---------- */
.em-cs-card-title {
	display: flex;
	align-items: flex-start;
	gap: 0.5rem;
}

.em-cs-card-icon {
	color: var(--em-primary);
	margin-top: 0.12rem;
}
