/* Gambrell Bingo — print stylesheet.
   When a card's Download/Print button is used, JS adds
   .gambrell-bingo-print-mode to <body> and .gambrell-bingo--printing to
   that card; everything else on the page is hidden. */

@media print {
	/* Hide everything that is not the card, its contents, or an ancestor of
	   it (JS tags the ancestor chain). display, not visibility, so hidden
	   content collapses instead of leaving blank space and extra pages. */
	body.gambrell-bingo-print-mode :not(.gambrell-bingo-print-ancestor):not(.gambrell-bingo--printing):not(.gambrell-bingo--printing *) {
		display: none !important;
	}

	/* Flatten the wrappers the card sits in so it starts at the top of page 1. */
	body.gambrell-bingo-print-mode,
	body.gambrell-bingo-print-mode .gambrell-bingo-print-ancestor {
		display: block !important;
		position: static !important;
		margin: 0 !important;
		padding: 0 !important;
		width: auto !important;
		max-width: none !important;
		min-height: 0 !important;
		overflow: visible !important;
		background: none !important;
	}

	body.gambrell-bingo-print-mode .gambrell-bingo--printing {
		display: block;
		width: auto;
		max-width: 100%;
		margin: 0;
		padding: 0;
		background: none;
		/* No break-inside: avoid here — the card is deliberately split, intro
		   text on the first sheet and board on the next. The board keeps its
		   own avoid rule below. */
	}

	/* Cells keep their aspect ratio, so at full page width the grid alone
	   overflows a sheet. Capping the card width keeps title + grid on one page. */
	body.gambrell-bingo-print-mode .gambrell-bingo--printing .gambrell-bingo__inner {
		display: block;
		max-width: 6.2in;
		margin: 0 auto;
	}

	/* On a narrow screen the board carries inline styles for the viewport it
	   was measured against: negative margins bleeding it to the screen edges,
	   and a row height for that cell width. Paper is neither, so drop both and
	   let the cells' aspect ratio size the rows — at 6.2in there is ample room
	   for even the longest phrase. */
	.gambrell-bingo__grid {
		margin-left: 0 !important;
		margin-right: 0 !important;
		grid-auto-rows: auto !important;
		/* Never split the board across sheets. */
		break-inside: avoid;
		page-break-inside: avoid;
	}

	/* Interactive chrome has no place on paper. */
	.gambrell-bingo__toolbar,
	.gambrell-bingo__popover,
	.gambrell-bingo__banner,
	.gambrell-bingo__generate {
		display: none !important;
	}

	/* No forced break: the board follows the intro text when there is room for
	   it, and the avoid rules below move it whole to the next sheet when there
	   isn't. Avoid sits on this block as well as the grid — a plain block is
	   honoured more reliably than a grid container. */
	.gambrell-bingo--printing .gambrell-bingo__play {
		margin-top: 24px;
		break-inside: avoid;
		page-break-inside: avoid;
	}

	.gambrell-bingo__cell,
	.gambrell-bingo__cell[aria-pressed="true"] {
		-webkit-print-color-adjust: exact;
		print-color-adjust: exact;
	}
}
