/*!
 * Site typography -- loaded on every page (not only where a shortcode renders).
 *
 * Why this is in the plugin rather than the theme:
 *
 * 1. The site runs the free Kadence theme. Its content column is 1242px wide,
 *    which is roughly 140 characters per line at body size. The Customizer
 *    setting that would narrow it lives in wp-admin, and this project deploys
 *    over FTP, so a stylesheet rule is the available channel.
 * 2. It has to apply to articles that contain no sudoku shortcode, so it cannot
 *    ride on sudoku.css -- that file is only enqueued by the shortcodes.
 *
 * 46rem = 736px, about 70 characters per line: the classic comfortable measure
 * for long-form reading. Widening it again is one number.
 */

/* Article pages (no board): narrow and centre the whole column, so the hero,
 * headings, paragraphs and lists all share one left edge. */
.entry-content:not(:has(.sds)) {
	max-width: 46rem;
	margin-left: auto;
	margin-right: auto;
}

/* Everyone else: narrow the prose, leave the diagrams alone.
 *
 * Two details matter here:
 *
 * - Direct children only. The board, keypad and calendar are block-level
 *   children of .entry-content, and everything inside them must keep the width
 *   its own stylesheet gives it -- a descendant selector would reach into .sds
 *   and squeeze the info rows.
 * - margin-inline, not just max-width. Kadence ships `.entry-content h2` with a
 *   shorthand margin, and a max-width alone leaves the heading hugging the left
 *   edge of a 1152px column while the paragraphs beside it are centred. Same
 *   specificity (0,1,1), later in the cascade, so this wins on the margin and
 *   every text block lands on one centre line. */
.entry-content > :is(p, h1, h2, h3, h4, h5, h6, ul, ol, blockquote, figure, table) {
	max-width: 46rem;
	margin-inline: auto;
}

/* Long paragraphs with a hard measure look better with slightly looser leading
 * and no orphan words; both are no-ops on browsers without support. */
.entry-content.single-content {
	text-wrap: pretty;
}

.entry-content.single-content > p {
	line-height: 1.75;
}

/* Code-like blocks never reflow, at any width.
 *
 * Kadence ships `pre { white-space: pre-wrap }`, which silently wrapped the
 * 81-character puzzle string in the worked example across two lines -- and a
 * wrapped string cannot be copied into the solver. The diagram blocks are the
 * same story: reflowed, the columns stop lining up with the row labels. So: keep
 * the author's lines, and let the block scroll inside itself when it is wider
 * than the column (the page itself still never scrolls sideways). */
.entry-content > pre {
	white-space: pre;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
}

/* On a phone, a five-column table does not fit 326px. Reflowing the cells into
 * columns turns every row into a five-line sliver, and letting the table scroll
 * sideways makes the reader swipe three screens wide to read one row. Stack it
 * instead: one card per row, level first in bold, the rest underneath. The
 * header row is dropped -- the first cell of each row names itself.
 *
 * <pre> keeps its alignment and scrolls inside its own box: a nine-step ladder
 * reflowed is unreadable, and one short swipe is cheaper than five lines of
 * wrapped numbers. The page itself still never scrolls sideways. */
@media (max-width: 600px) {
	.entry-content > table {
		display: block;
		white-space: normal;
	}

	.entry-content > table thead {
		display: none;
	}

	.entry-content > table tr {
		display: block;
		padding: 10px 0;
	}

	.entry-content > table tr + tr {
		border-top: 1px solid rgba(128, 128, 128, 0.3);
	}

	.entry-content > table td {
		display: block;
		padding: 2px 0;
		border: 0;
	}

	.entry-content > table td:first-child {
		font-weight: 600;
	}
}

/* Footer information links (About us / Contact us / FAQ).
 *
 * The row prints inside the theme footer, after its own bottom line, so it has
 * to sit on the same background rather than punching a white band through it.
 * Kadence's footer bottom uses --global-palette8 on this install; the variable
 * with a literal fallback means a palette change in the Customizer carries the
 * row along instead of leaving it behind.
 *
 * One centred row, quiet type: this is a sign-off, not navigation anyone should
 * notice. Wrap on narrow screens rather than shrink, since three short labels
 * fit a phone in one line either way. */
.sds-footer-links {
	background: var(--global-palette8, #f7fafc);
	border-top: 1px solid rgba(128, 128, 128, 0.18);
	padding: 14px 1.5rem 18px;
}

.sds-footer-links-inner {
	max-width: 46rem;
	margin-left: auto;
	margin-right: auto;
}

.sds-footer-links ul {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 4px 24px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.sds-footer-links li {
	margin: 0;
	padding: 0;
}

.sds-footer-links a {
	color: var(--global-palette5, #4a5568);
	font-size: 0.9375rem;
	line-height: 1.5;
	text-decoration: none;
}

.sds-footer-links a:hover,
.sds-footer-links a:focus-visible {
	color: var(--global-palette3, #1a202c);
	text-decoration: underline;
	text-underline-offset: 3px;
}

@media (max-width: 480px) {
	.sds-footer-links {
		padding: 12px 1rem 16px;
	}

	.sds-footer-links ul {
		gap: 2px 18px;
	}
}

/* ---- print: the sheet, not the website ------------------------------------
 * Every tool page prints through the browser dialog, and by default that means
 * the theme's header (with its hamburger), the footer links and the page's intro
 * prose all land on paper. On a sheet that promises "one puzzle per page" that
 * costs a page and looks like a mistake. The rules below are scoped to pages that
 * actually contain a tool, so ordinary articles print unchanged.
 *
 * The grid lines are 1px background gaps rather than borders; browsers drop
 * backgrounds by default, which is why printed grids lost their lines and kept
 * only the thick 3x3 borders. print-color-adjust: exact keeps them.
 */
@media print {
	body:has(.sds) .site-header,
	body:has(.sds) #masthead,
	body:has(.sds) .site-footer,
	body:has(.sds) #colophon,
	body:has(.sds) .main-navigation,
	body:has(.sds) .site-navigation,
	body:has(.sds) .kadence-header,
	body:has(.sds) .kadence-footer,
	body:has(.sds) .sds-footer-links {
		display: none !important;
	}

	/* The printable sheet and the classroom pack are the page on paper: the intro
	   stays on screen, where it explains the picker, and not on the sheet. */
	body:has(.sds-printable) .entry-header,
	body:has(.sds-pack) .entry-header,
	body:has(.sds-printable) .entry-content > *:not(.sds):not(:has(.sds)),
	body:has(.sds-pack) .entry-content > *:not(.sds):not(:has(.sds)) {
		display: none !important;
	}

	/*
	 * The grid, drawn explicitly.
	 *
	 * On screen the cell lines are 1px background gaps. In print the board's own
	 * print rules take the gap away and the backgrounds are not painted, so the
	 * sheet came out with the thick box borders and nothing else. Borders on the
	 * cells do not depend on either, and 1px at print scale is a visible hairline.
	 */
	.sds-board,
	.sds-pack-mini {
		gap: 0 !important;
		background: #fff !important;
		border-radius: 0 !important;
		box-shadow: none !important;
		-webkit-print-color-adjust: exact;
		print-color-adjust: exact;
	}

	.sds-board .sds-cell,
	.sds-pack-mini-cell {
		background: #fff !important;
		color: #000 !important;
		border: 0 !important;
		border-right: 1px solid #000 !important;
		border-bottom: 1px solid #000 !important;
		-webkit-print-color-adjust: exact;
		print-color-adjust: exact;
	}

	.sds-board .sds-row .sds-cell:last-child,
	.sds-pack-mini .sds-pack-mini-cell:nth-child(4n) {
		border-right: 0 !important;
	}

	.sds-board .sds-row:last-child .sds-cell,
	.sds-pack-mini .sds-pack-mini-cell:nth-child(n + 13) {
		border-bottom: 0 !important;
	}

	.sds-board .sds-cell.sds-br,
	.sds-pack-mini .sds-pack-mini-cell.sds-pack-mini-br {
		border-right: 2px solid #000 !important;
	}

	.sds-board .sds-cell.sds-bb,
	.sds-pack-mini .sds-pack-mini-cell.sds-pack-mini-bb {
		border-bottom: 2px solid #000 !important;
	}

	/* One 9x9 sheet per page in the classroom pack. */
	body:has(.sds-pack) .sds-pack-sheet.sds-pack-full {
		page-break-before: always;
		break-before: page;
	}
}
