/*
 * Print and PDF styles.
 *
 * Loaded with media="print", and ALSO wrapped in @media print so the file is
 * safe to inline into a standalone export without leaking print rules onto the
 * screen view.
 *
 * Every choice here traces to something in private/research/02-typography-print-pdf.md.
 */

@page {
	/*
	 * Size is deliberately NOT set. `size: auto` lets the user's chosen sheet
	 * win and the content reflow, which is right for a browser print. The PDF
	 * exporter sets the sheet explicitly on its own side.
	 *
	 * 0.75in clears every consumer printer's unprintable margin (the worst
	 * measured is about 0.25in, on duplex) with roughly 3x headroom.
	 */
	margin: 0.75in;
}

@media print {
	body.ppres-resume-view {
		margin: 0;
		padding: 0;
		background: #fff;
		color: #000;

		/*
		 * 10.5pt, in a face whose x-height fraction is comfortably above 0.45.
		 * That puts the angular x-height above the 0.2-degree critical print
		 * size at normal reading distance, which is where reading speed stops
		 * improving. Larger buys nothing measurable; smaller starts costing.
		 *
		 * pt, not rem. A rem here would inherit the ROOT font size, which on
		 * screen is deliberately left at whatever the reader set in their
		 * browser — so a reader who chose 24px would silently get a print
		 * stylesheet scaled 1.5x and a repaginated resume.
		 *
		 * 10.5pt is the default. The author can choose 9-12pt in the editor's
		 * "Resume design" panel, which reaches this sheet as
		 * --ppres-text-scale (chosen size / 10.5pt, set in resume.css). Every
		 * pt size below is multiplied by it, so the scale stays one scale.
		 */
		font-size: calc(10.5pt * var(--ppres-text-scale, 1));
		line-height: 1.4;

		/* pt counterparts of resume.css' rem helpers. */
		--ppres-body-size: calc(10.5pt * var(--ppres-text-scale, 1));
	}

	/*
	 * Pin the content block to the SHARED Letter/A4 content width.
	 *
	 * A4 is 210mm wide, Letter 215.9mm. At 0.75in margins the narrower of the
	 * two leaves 6.768in of content. Holding the block to that on BOTH sheets
	 * means Letter and A4 prints break lines in exactly the same places and
	 * paginate identically — worth having on a document that might be sent to
	 * a US agency one week and a European one the next.
	 *
	 * The cost is about 0.23in of unused width when printing on Letter, which
	 * is invisible. The height difference is the one that actually bites:
	 * Letter is 0.69in SHORTER than A4, roughly four lines at this size, so a
	 * page laid out to fill A4 spills onto a second page on Letter. Always
	 * check pagination against Letter.
	 */
	.ppres-shell {
		max-width: 6.75in;
		margin: 0 auto;
	}

	/*
	 * Reset the screen measure. It is expressed in rem, and rem inside a print
	 * sheet resolves against the reader's own root font size — so leaving it
	 * would let a reader who raised their browser default silently repaginate
	 * the printed resume.
	 */
	.ppres-shell p,
	.ppres-shell li {
		max-width: none;
	}

	/* Screen-only furniture. */
	.ppres-actions,
	.ppres-skip-link,
	.no-print {
		display: none !important;
	}

	/*
	 * Heading sizes follow the heading scale too, floored at the body size for
	 * the same reason as on screen (resume.css).
	 */
	.ppres-name {
		font-size: max(var(--ppres-body-size), calc(20pt * var(--ppres-heading-factor, 1)));
	}

	.ppres-shell h2 {
		font-size: max(var(--ppres-body-size), calc(13pt * var(--ppres-heading-factor, 1)));
	}

	.ppres-shell h3 {
		font-size: max(var(--ppres-body-size), calc(11.5pt * var(--ppres-heading-factor, 1)));
	}

	.ppres-shell h4 {
		font-size: max(var(--ppres-body-size), calc(10.5pt * var(--ppres-heading-factor, 1)));
	}

	.ppres-dates {
		font-size: calc(9.5pt * var(--ppres-text-scale, 1));
		color: #000;
	}

	/*
	 * Fragmentation.
	 *
	 * `break-after: avoid` on a heading is RELIED ON here, and that is an
	 * evidence-backed change. It was originally declared but not trusted —
	 * whether Blink honoured it across PAGE boundaries was unconfirmed, so
	 * every entry was also an unbreakable block. Tested empirically
	 * 2026-08-27 (40-group comb document, per-page last-line extraction):
	 * the control stranded four headings at page bottoms; with the rule,
	 * zero. Current Chromium moves a bottom-of-page heading to the next
	 * page along with its content.
	 *
	 * So EMPLOYERS may now break internally. Keeping them atomic pushed any
	 * large entry to the next page whole, leaving a conspicuous gap above
	 * it (a real one: Lelander, following Freelance, stranded a third of a
	 * page of white). A long entry now fills the page and continues
	 * overleaf, which is ordinary resume typography; orphans/widows below
	 * keep the fragments respectable.
	 *
	 * PROJECTS stay unbreakable: they are short, an atomic project block
	 * almost never causes a visible gap, and a two-line block split across
	 * a page boundary looks worse than either page having one line less.
	 *
	 * Note `break-after: page`, never `break-after: always` — `always` is
	 * recorded as unsupported in Chrome, and it is exactly the value someone
	 * reaches for by default.
	 */
	.ppres-shell h2,
	.ppres-shell h3,
	.ppres-shell h4 {
		break-after: avoid;
	}

	.ppres-project {
		break-inside: avoid;
	}

	/*
	 * Structural belt-and-braces on top of break-after: a heading cannot end
	 * up last on a page if the thing after it refuses to start a new page
	 * without it.
	 */
	.ppres-section > h2 + *,
	.ppres-employer > h3 + * {
		break-before: avoid;
	}

	/*
	 * The heading-and-dates row (resume.css) is one line in the common case
	 * and must travel as one: never split, never left at a page bottom
	 * without the entry's first content. The h3/h4 inside it keep their own
	 * `break-after: avoid` above, but inside a flex row that only governs the
	 * row's interior — the row itself has to carry the rule outward.
	 */
	.ppres-entry-head {
		break-inside: avoid;
		break-after: avoid;
	}

	.ppres-employer > .ppres-entry-head + *,
	.ppres-project > .ppres-entry-head + * {
		break-before: avoid;
	}

	/*
	 * orphans/widows work in Blink and WebKit and do nothing in Firefox —
	 * that is a known engine gap, not an oversight, and an editor will flag it.
	 * Leave them: the PDF export path is Chromium, where they take effect, and
	 * a Firefox user printing directly just gets the browser default of 2.
	 */
	.ppres-shell p,
	.ppres-shell li {
		orphans: 2;
		widows: 2;
	}

	/*
	 * Links: one color on paper, another in the exported PDF.
	 *
	 * The exporter renders this same print view, so the only thing that tells
	 * the two apart is the `ppres-export-view` body class, which the exporter's
	 * URL flag switches on (PPRES_EXPORT_QUERY_ARG in includes/pdf.php). The
	 * class changes color and nothing else: layout stays shared, so a page
	 * break can never move between the PDF and the paper copy.
	 *
	 * - Browser print: black by default (--ppres-link-print). A paper reader
	 *   cannot click, so color would only say "this was a link".
	 * - Exported PDF: deep blue by default (--ppres-link-pdf, #16437e, about
	 *   9.8:1 on white), so a reader can see what is clickable by color.
	 *
	 * Both keep the underline, so a link is identifiable by shape alone. The
	 * author can change either color in the editor; anything under 4.5:1 on
	 * white is refused (includes/design.php).
	 *
	 * URLs are deliberately NOT expanded with a[href]::after: a full URL runs
	 * about 40 characters, which wrecks an already-tight measure, and Chromium
	 * keeps links as real clickable PDF annotations anyway. Self-describing link
	 * text does the job for the paper case without the noise.
	 */
	.ppres-shell a {
		color: var(--ppres-link-print, #000);
		text-decoration: underline;
	}

	body.ppres-export-view .ppres-shell a {
		color: var(--ppres-link-pdf, #16437e);
	}

	.ppres-notice {
		border-left: 2pt solid #000;
		background: transparent;
	}
}
