/*
 * Single post article - hero header, prose measure, footer meta.
 * Enqueued on single posts only; see sok_enqueue_post_styles().
 *
 * The problem this file solves: GeneratePress prints the featured image as a
 * bare block above the title (generate_featured_page_header_inside_single).
 * Nearly every featured image on this site is a 378x250 topic tile, so at
 * native size it landed as a small orphaned graphic floating over a lowercase
 * H1 on a flat white page - no frame, no alignment, no relationship to the
 * heading it was introducing.
 *
 * sok_open_post_hero() wraps that image and the entry header in one grid, so
 * the tile becomes the right hand column of a proper article header instead of
 * a stray image. The tile is never rendered wider than its 378px source, so it
 * stays sharp - upscaling a 378px tile to the 1120px content width was the one
 * option not worth taking.
 *
 * Palette is the landing page's, restated here because those tokens are scoped
 * to .sok-landing.
 */

.sok-post {
	--sok-primary: #004aaa;
	--sok-primary-2: #1e73be;
	--sok-primary-dark: #00347a;
	--sok-cta: #1668d6;
	--sok-cta-hover: #1d6ede;
	--sok-tint: #eef4fc;
	--sok-band: #f5f8fc;
	--sok-text: #0f1c2e;
	--sok-muted: #5a6b80;
	--sok-border: #e2e8f0;
	--sok-radius: 12px;
	--sok-shadow: 0 1px 3px rgba(15, 28, 46, .06);
	--sok-shadow-lg: 0 12px 32px rgba(15, 28, 46, .10);

	/*
	 * GeneratePress sets 22px Poppins for body copy, which the 1120px content
	 * box turns into ~90 character lines - well past the 65-75 readability
	 * band. Prose is capped at this measure; code blocks, tables and images
	 * deliberately keep the full width (see "Prose" below).
	 *
	 * 60ch rather than a round 70: `ch` is the width of a "0", and Poppins'
	 * digits are wider than its average lowercase letter, so 60ch of Poppins
	 * holds roughly 75 real characters.
	 */
	--sok-measure: 60ch;
}

/* ------------------------------------------------------------------
   Article hero - featured tile + title + meta as one block
   ------------------------------------------------------------------ */

.sok-post .sok-post-hero {
	display: grid;
	/*
	 * 300px keeps the tile just under its 378px source width, so it is always
	 * downscaled and never soft.
	 */
	grid-template-columns: minmax(0, 1fr) 300px;
	gap: 36px;
	align-items: center;
	/*
	 * Bled out to the edges of .inside-article's 40px padding and given the
	 * same padding back, so the H1 sits on the same left edge as the body
	 * copy and code blocks below it. Inset with its own padding the header
	 * was offset from the article by 36px, which reads as a mistake.
	 */
	margin: -40px -40px 44px;
	/* 39 + the 1px border = the 40px of .inside-article padding it replaces. */
	padding: 39px;
	background-image: linear-gradient(135deg, #f7fafd 0%, var(--sok-tint) 100%);
	border: 1px solid var(--sok-border);
	border-radius: 16px;
}

/* No featured image: the title takes the whole width. */
.sok-post .sok-post-hero--no-image {
	grid-template-columns: minmax(0, 1fr);
}

/*
 * The image is printed before the header in the DOM (GeneratePress hooks it at
 * generate_before_content), so both are placed explicitly rather than left to
 * source order.
 */
.sok-post .sok-post-hero .entry-header {
	grid-column: 1;
	grid-row: 1;
	margin: 0;
	min-width: 0;
}

.sok-post .sok-post-hero .featured-image {
	grid-column: 2;
	grid-row: 1;
	/* .grid-container .grid-parent from GeneratePress bring a 1200px cap. */
	max-width: none;
	margin: 0;
	padding: 0;
}

.sok-post .sok-post-hero .featured-image img {
	display: block;
	width: 100%;
	height: auto;
	/*
	 * The tiles are 378x250 (1.512), so a 3/2 box trims well under 1% off the
	 * top and bottom while squaring off the screenshots that come in other
	 * ratios. Same reasoning as the card grid in style.css.
	 */
	aspect-ratio: 3 / 2;
	object-fit: cover;
	background-color: #ffffff;
	border: 1px solid var(--sok-border);
	border-radius: var(--sok-radius);
	box-shadow: 0 8px 24px rgba(15, 28, 46, .10);
}

/* --- Title + meta --------------------------------------------------- */

.sok-post .sok-post-hero .entry-title {
	margin: 0;
	color: var(--sok-text);
	font-size: clamp(30px, 3.2vw, 42px);
	font-weight: 700;
	letter-spacing: -.02em;
	line-height: 1.15;
	/* Post slugs like "traceroute" are fine, but some titles are one long command. */
	overflow-wrap: break-word;
}

.sok-post .sok-post-meta {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px 22px;
	margin-top: 18px;
	color: var(--sok-muted);
	font-size: 15px;
	line-height: 1.4;
}

.sok-post .sok-meta-item {
	display: inline-flex;
	align-items: center;
	gap: 7px;
}

.sok-post .sok-meta-item svg {
	flex: none;
	width: 16px;
	height: 16px;
	opacity: .7;
}

/* --- Responsive ----------------------------------------------------- */

@media (max-width: 900px) {
	.sok-post .sok-post-hero {
		grid-template-columns: 1fr;
		gap: 24px;
	}

	/* Title first once the columns collapse - the tile is decorative. */
	.sok-post .sok-post-hero .entry-header {
		grid-column: 1;
		grid-row: 1;
	}

	.sok-post .sok-post-hero .featured-image {
		grid-column: 1;
		grid-row: 2;
		/* Never past the 378px source. */
		max-width: 378px;
	}
}

/* GeneratePress drops .inside-article to 30px of padding here. */
@media (max-width: 768px) {
	.sok-post .sok-post-hero {
		margin: -30px -30px 32px;
		padding: 29px;
		border-radius: 14px;
	}
}

/* ------------------------------------------------------------------
   Prose

   Only the text blocks take the measure. <pre>, tables and images keep the
   full 1120px, which is the point: the traceroute and log dumps these posts
   are built from are 100+ characters wide and wrap badly in a narrow column.
   ------------------------------------------------------------------ */

.sok-post .entry-content {
	color: var(--sok-text);
}

.sok-post .entry-content > p,
.sok-post .entry-content > ul,
.sok-post .entry-content > ol,
.sok-post .entry-content > h2,
.sok-post .entry-content > h3,
.sok-post .entry-content > h4,
.sok-post .entry-content > h5,
.sok-post .entry-content > h6,
.sok-post .entry-content > blockquote,
.sok-post .entry-content > .wp-block-embed {
	max-width: var(--sok-measure);
}

.sok-post .entry-content > p {
	margin: 0 0 1.3em;
	line-height: 1.7;
}

.sok-post .entry-content h2,
.sok-post .entry-content h3,
.sok-post .entry-content h4 {
	color: var(--sok-text);
	font-weight: 700;
	letter-spacing: -.01em;
	overflow-wrap: break-word;
}

.sok-post .entry-content h2 {
	margin: 1.9em 0 .6em;
	font-size: clamp(26px, 2.4vw, 32px);
	line-height: 1.25;
}

.sok-post .entry-content h3 {
	margin: 1.7em 0 .5em;
	font-size: clamp(22px, 2vw, 25px);
	line-height: 1.3;
}

.sok-post .entry-content h4 {
	margin: 1.5em 0 .5em;
	font-size: 20px;
	line-height: 1.35;
}

/* First heading of the article should not add to the hero's bottom margin. */
.sok-post .entry-content > :first-child {
	margin-top: 0;
}

.sok-post .entry-content ul,
.sok-post .entry-content ol {
	margin: 0 0 1.3em;
	padding-left: 1.4em;
}

.sok-post .entry-content li {
	margin-bottom: .45em;
	line-height: 1.7;
}

.sok-post .entry-content li > ul,
.sok-post .entry-content li > ol {
	margin: .45em 0 0;
}

.sok-post .entry-content blockquote {
	margin: 1.8em 0;
	padding: 2px 0 2px 22px;
	border-left: 3px solid var(--sok-primary-2);
	color: var(--sok-muted);
	font-style: normal;
}

.sok-post .entry-content blockquote p:last-child {
	margin-bottom: 0;
}

/* --- Links ---------------------------------------------------------- */

/*
 * GeneratePress' Customizer CSS turns every link #222222 on hover, which reads
 * as the link going dead rather than responding.
 */
.sok-post .entry-content a {
	color: var(--sok-primary-2);
	text-decoration-thickness: 1px;
	text-underline-offset: 3px;
	transition: color .18s ease;
}

.sok-post .entry-content a:hover,
.sok-post .entry-content a:focus {
	color: var(--sok-primary-dark);
}

.sok-post .entry-content a:focus-visible {
	outline: 2px solid var(--sok-cta);
	outline-offset: 2px;
	border-radius: 3px;
}

/* --- Code ----------------------------------------------------------- */

/* Inline code only - the <code> inside <pre> is styled by the syntax block. */
.sok-post .entry-content :not(pre) > code {
	padding: .12em .4em;
	background-color: var(--sok-tint);
	border: 1px solid #dbe6f5;
	border-radius: 6px;
	color: #0b3a72;
	font-family: "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: .85em;
	overflow-wrap: break-word;
}

.sok-post .entry-content pre.wp-block-code {
	margin: 1.6em 0 1.9em;
	border-radius: var(--sok-radius);
	box-shadow: 0 6px 20px rgba(15, 28, 46, .12);
}

/* --- Media ---------------------------------------------------------- */

.sok-post .entry-content figure {
	margin: 1.9em 0;
}

.sok-post .entry-content img {
	height: auto;
	border-radius: 10px;
}

.sok-post .entry-content figcaption {
	margin-top: 10px;
	color: var(--sok-muted);
	font-size: 15px;
	line-height: 1.5;
}

/* --- Tables --------------------------------------------------------- */

/*
 * display:block so a wide table scrolls inside itself instead of pushing the
 * page sideways on a phone.
 */
.sok-post .entry-content table {
	display: block;
	width: 100%;
	margin: 1.7em 0;
	overflow-x: auto;
	border-collapse: collapse;
	font-size: 17px;
}

.sok-post .entry-content th,
.sok-post .entry-content td {
	padding: 11px 15px;
	border: 1px solid var(--sok-border);
	text-align: left;
	vertical-align: top;
}

.sok-post .entry-content thead th {
	background-color: var(--sok-band);
	font-weight: 600;
}

/* ------------------------------------------------------------------
   Footer meta - categories and the previous/next pair
   ------------------------------------------------------------------ */

.sok-post footer.entry-meta {
	margin-top: 48px;
	padding-top: 28px;
	border-top: 1px solid var(--sok-border);
}

.sok-post footer.entry-meta .cat-links {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	margin-bottom: 12px;
	color: var(--sok-muted);
	font-size: 15px;
}

.sok-post footer.entry-meta .cat-links .gp-icon {
	display: inline-flex;
	margin-right: 2px;
	color: var(--sok-muted);
	opacity: .7;
}

/*
 * 40px chips: comfortably past the 24px WCAG 2.2 AA target minimum, and short
 * enough that a row of several categories still reads as metadata rather than
 * as a second navigation bar.
 */
.sok-post footer.entry-meta .cat-links a {
	display: inline-flex;
	align-items: center;
	min-height: 40px;
	padding: 0 15px;
	background-color: var(--sok-band);
	border: 1px solid var(--sok-border);
	border-radius: 999px;
	color: var(--sok-primary);
	font-size: 15px;
	font-weight: 500;
	line-height: 1;
	text-decoration: none;
	transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}

.sok-post footer.entry-meta .cat-links a:hover,
.sok-post footer.entry-meta .cat-links a:focus {
	background-color: var(--sok-tint);
	border-color: var(--sok-primary-2);
	color: var(--sok-primary-dark);
	text-decoration: none;
}

.sok-post footer.entry-meta .cat-links a:focus-visible {
	outline: 2px solid var(--sok-cta);
	outline-offset: 2px;
}

/* --- Previous / next ------------------------------------------------ */

.sok-post .post-navigation {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 16px;
	margin-top: 20px;
}

/* A post at either end of the archive only gets one link - keep it in place. */
.sok-post .post-navigation .nav-next:only-child {
	grid-column: 2;
}

.sok-post .post-navigation .nav-previous,
.sok-post .post-navigation .nav-next {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 18px 20px;
	background-color: #ffffff;
	border: 1px solid var(--sok-border);
	border-radius: var(--sok-radius);
	box-shadow: var(--sok-shadow);
	transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.sok-post .post-navigation .nav-next {
	align-items: flex-end;
	text-align: right;
}

.sok-post .post-navigation .nav-previous:hover,
.sok-post .post-navigation .nav-next:hover,
.sok-post .post-navigation .nav-previous:focus-within,
.sok-post .post-navigation .nav-next:focus-within {
	background-color: var(--sok-band);
	border-color: var(--sok-primary-2);
	box-shadow: var(--sok-shadow-lg);
}

.sok-post .sok-nav-dir {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	color: var(--sok-muted);
	font-size: 13px;
	font-weight: 600;
	letter-spacing: .08em;
	line-height: 1;
	text-transform: uppercase;
}

.sok-post .sok-nav-dir .gp-icon {
	display: inline-flex;
	opacity: .8;
}

.sok-post .post-navigation .prev,
.sok-post .post-navigation .next {
	display: block;
}

.sok-post .post-navigation .prev a,
.sok-post .post-navigation .next a {
	color: var(--sok-text);
	font-size: 17px;
	font-weight: 600;
	line-height: 1.4;
	text-decoration: none;
	overflow-wrap: anywhere;
	transition: color .18s ease;
}

.sok-post .post-navigation .nav-previous:hover .prev a,
.sok-post .post-navigation .nav-next:hover .next a {
	color: var(--sok-primary);
}

/* Whole card is the target; the <a> keeps the accessible name. */
.sok-post .post-navigation .prev a::after,
.sok-post .post-navigation .next a::after {
	content: "";
	position: absolute;
	inset: 0;
}

.sok-post .post-navigation .prev a:focus-visible,
.sok-post .post-navigation .next a:focus-visible {
	outline: 2px solid var(--sok-cta);
	outline-offset: 4px;
	border-radius: 4px;
}

@media (max-width: 640px) {
	.sok-post .post-navigation {
		grid-template-columns: 1fr;
	}

	.sok-post .post-navigation .nav-next:only-child {
		grid-column: 1;
	}

	/* One column: both cards read left to right. */
	.sok-post .post-navigation .nav-next {
		align-items: flex-start;
		text-align: left;
	}
}

/* ------------------------------------------------------------------
   Comments

   GeneratePress leaves the form on its Customizer defaults: a grey #55555e
   submit button and square #f7f8f9 fields with no focus ring beyond the
   browser's own.
   ------------------------------------------------------------------ */

.sok-post .comment-respond .comment-reply-title,
.sok-post .comments-title {
	margin-bottom: 8px;
	color: var(--sok-text);
	font-size: clamp(24px, 2.2vw, 28px);
	font-weight: 700;
	letter-spacing: -.01em;
}

.sok-post .comment-form .comment-form-comment,
.sok-post .comment-form p {
	margin-bottom: 16px;
}

.sok-post .comment-form input[type="text"],
.sok-post .comment-form input[type="email"],
.sok-post .comment-form input[type="url"],
.sok-post .comment-form textarea {
	width: 100%;
	padding: 12px 15px;
	background-color: #ffffff;
	border: 1px solid var(--sok-border);
	border-radius: 10px;
	color: var(--sok-text);
	font-size: 17px;
	line-height: 1.5;
	transition: border-color .18s ease, box-shadow .18s ease;
}

.sok-post .comment-form input[type="text"]:focus,
.sok-post .comment-form input[type="email"]:focus,
.sok-post .comment-form input[type="url"]:focus,
.sok-post .comment-form textarea:focus {
	background-color: #ffffff;
	border-color: var(--sok-cta);
	box-shadow: 0 0 0 3px rgba(22, 104, 214, .15);
	outline: none;
}

.sok-post .comment-form input::placeholder,
.sok-post .comment-form textarea::placeholder {
	/* 4.77:1 on white - the default #b2b2be placeholder is 2.02:1. */
	color: #64748b;
}

.sok-post .comment-form .form-submit {
	margin-bottom: 0;
}

.sok-post .comment-form input[type="submit"] {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 48px;
	padding: 0 26px;
	background-color: var(--sok-cta);
	border: 0;
	border-radius: 10px;
	color: #ffffff;
	cursor: pointer;
	font-size: 17px;
	font-weight: 600;
	line-height: 1;
	transition: background-color .18s ease, box-shadow .18s ease;
}

.sok-post .comment-form input[type="submit"]:hover,
.sok-post .comment-form input[type="submit"]:focus {
	background-color: var(--sok-cta-hover);
	box-shadow: 0 6px 18px rgba(22, 104, 214, .32);
}

.sok-post .comment-form input[type="submit"]:focus-visible {
	outline: 2px solid var(--sok-primary-dark);
	outline-offset: 2px;
}

/* ------------------------------------------------------------------
   Motion
   ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
	.sok-post .entry-content a,
	.sok-post footer.entry-meta .cat-links a,
	.sok-post .post-navigation .nav-previous,
	.sok-post .post-navigation .nav-next,
	.sok-post .post-navigation .prev a,
	.sok-post .post-navigation .next a,
	.sok-post .comment-form input,
	.sok-post .comment-form textarea {
		transition: none;
	}
}
