.jigsaw {
	position: relative; max-width: 1030px; margin: auto; isolation: isolate;
	border: 2px solid var(--wood-dark); border-radius: var(--radius); background: var(--paper);
	box-shadow: var(--shadow); color: var(--ink);
}
.jigsaw [hidden], #jg-sheet { display: none !important; }
.jg-tools {
	display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px;
	position: relative; z-index: 2; background: var(--wood); border-radius: var(--radius) var(--radius) 0 0;
}
.jigsaw :is(button, summary, select), #jg-ranking {
	display: inline-flex; align-items: center; justify-content: center; gap: .3em;
	min-height: 44px; padding: 5px 12px; margin: 0; border: 1px solid var(--wood-dark); border-radius: 12px;
	color: var(--ink); background: #fffaf0; font: 750 15px/1.15 var(--font); cursor: pointer;
}
.jg-settings summary { list-style: none; }
.jg-settings summary::-webkit-details-marker { display: none; }
.jigsaw :is(button, summary):hover, .jg-settings[open] summary { background: #fff; }
.jigsaw button[aria-pressed="true"], #jg-full { background: var(--sun); }
#jg-full::before {
	content: ""; width: 1em; height: 1em;
	background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%235a2e0c' stroke-width='3' d='M3 9V3h6m6 0h6v6m0 6v6h-6m-6 0H3v-6'/%3E%3C/svg%3E") center / contain no-repeat;
}
.jigsaw :disabled { opacity: .6; cursor: default; }
.jg-time { margin-inline-start: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.jg-menu {
	position: absolute; inset: 100% auto auto 0; width: min(270px, 100%); max-height: min(50dvh, 400px);
	overflow: auto; overscroll-behavior: contain; padding: 12px;
	display: grid; gap: 8px; background: var(--paper); border: 2px solid var(--wood-dark);
	border-radius: 0 0 14px 14px; box-shadow: var(--shadow);
}
.jg-menu p { margin: 0; font-size: 14px; }
.jg-menu label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 15px; }
.jg-menu .jg-check { justify-content: start; min-height: 44px; cursor: pointer; }
.jg-check input { width: 21px; height: 21px; accent-color: var(--green-dark); }
.jg-field {
	position: relative; height: clamp(280px, 61vh, 630px); height: clamp(280px, 61svh, 630px);
	min-height: 0; overflow: hidden; background-color: #f2ead9;
	background-image: radial-gradient(#ded2b9 1px, transparent 1px); background-size: 12px 12px;
}
#jg-board { display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
#jg-board:focus-visible { outline-offset: -4px; }
#jg-target { fill: #fffcf4; stroke: #cebc97; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; }
#jg-pieces path { cursor: grab; stroke: #614c3f; stroke-width: 1; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
#jg-pieces path:active { cursor: grabbing; }
#jg-pieces .jg-selected path { stroke: var(--green-dark); stroke-width: 2; }
#jg-pieces.jg-done path { stroke: none; cursor: default; }
#jg-thumbnail {
	position: absolute; right: 8px; top: 8px; width: min(22%, 140px); max-height: 25%; object-fit: contain;
	background: white; border: 3px solid white; border-radius: 6px; box-shadow: var(--shadow); pointer-events: none;
}
#jg-result, #jg-message {
	position: absolute; left: 50%; transform: translateX(-50%); padding: 10px 14px;
	width: max-content; max-width: 95%; text-align: center; background: var(--paper); border-radius: 14px;
	box-shadow: var(--shadow);
}
#jg-message { top: 35%; }
#jg-result { bottom: 8px; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; }
.jigsaw .game-hint { margin: 0; padding: 6px 8px; font-size: 14px; }
.jigsaw.jg-expanded {
	position: fixed; inset: 0; z-index: 2147483647; width: 100%; height: 100%; height: 100dvh; max-width: none;
	padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
	display: flex; flex-direction: column; border: 0; border-radius: 0;
}
.jg-expanded .jg-field { flex: 1; }
.jg-expanded .jg-tools { border-radius: 0; }
html.jg-full-page { overflow: hidden; }
@media (max-width: 550px) {
	.jg-tools { gap: 4px; padding: 5px; }
	.jigsaw :is(button, summary) { padding-inline: 8px; font-size: 14px; }
	.jg-time { order: 1; }
}
@media (orientation: landscape) and (max-height: 540px) {
	.jg-field { height: 69svh; }
	.jigsaw .game-hint { font-size: 12px; padding-block: 2px; }
}
@media print {
	@page { size: landscape; margin: 10mm; }
	html.jg-full-page { overflow: visible; }
	body.page-game { background: white; }
	body.page-game > :not(main), .page-game .page--game > :not(#jg-sheet) { display: none !important; }
	.page-game :is(.site-main, .page--game) { padding: 0; margin: 0; max-width: none; background: white; box-shadow: none; }
	#jg-sheet { display: block !important; color: #333; text-align: center; break-inside: avoid; }
	#jg-sheet h2, #jg-sheet p { margin: 0; font: 16pt/1.25 sans-serif; }
	#jg-print-board { display: block; width: 100%; height: 150mm; margin: 3mm auto; }
}
