/* SyntVision Jigsaw — full-screen puzzle */
:root {
	--svp-bg0: #0b1220;
	--svp-bg1: #132033;
	--svp-panel: rgba(255, 255, 255, 0.06);
	--svp-panel-border: rgba(255, 255, 255, 0.1);
	--svp-text: #f8fafc;
	--svp-muted: #94a3b8;
	--svp-accent: #0a86bf;
	--svp-accent-2: #38bdf8;
	--svp-ok: #34d399;
	--svp-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
	--svp-radius: 16px;
	--svp-font: "DM Sans", system-ui, sans-serif;
	--svp-display: "Fraunces", Georgia, serif;
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	min-height: 100%;
	background:
		radial-gradient(1200px 600px at 10% -10%, rgba(10, 134, 191, 0.28), transparent 55%),
		radial-gradient(900px 500px at 90% 0%, rgba(56, 189, 248, 0.16), transparent 50%),
		linear-gradient(180deg, var(--svp-bg0), var(--svp-bg1) 55%, #0a101a);
	color: var(--svp-text);
	font-family: var(--svp-font);
	-webkit-font-smoothing: antialiased;
}

.sv-puzzle-body {
	overflow: hidden;
}

.sv-puzzle-app {
	--svp-tab: 0.2;
	height: calc(100vh - 48px);
	height: calc(100dvh - 48px);
	max-height: calc(100vh - 48px);
	max-height: calc(100dvh - 48px);
	display: flex;
	flex-direction: column;
	padding: 10px 12px 12px;
	gap: 10px;
	overflow: hidden;
}

.sv-puzzle-top {
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 10px 12px;
	background: var(--svp-panel);
	border: 1px solid var(--svp-panel-border);
	border-radius: var(--svp-radius);
	backdrop-filter: blur(14px);
	flex: 0 0 auto;
}

.sv-puzzle-top__main {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 14px;
	min-width: 0;
}

.sv-puzzle-brand {
	display: flex;
	align-items: center;
	gap: 14px;
	min-width: 0;
	flex: 1 1 auto;
}

.sv-puzzle-back {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	flex: 0 0 auto;
	color: var(--svp-muted);
	text-decoration: none;
	font-size: 13px;
	font-weight: 600;
	padding: 8px 10px;
	border-radius: 999px;
	border: 1px solid transparent;
	transition: color .15s ease, border-color .15s ease, background .15s ease;
}

.sv-puzzle-back:hover {
	color: var(--svp-text);
	background: rgba(255, 255, 255, 0.06);
	border-color: var(--svp-panel-border);
}

.sv-puzzle-heading {
	min-width: 0;
}

.sv-puzzle-kicker {
	margin: 0 0 2px;
	font-size: 11px;
	font-weight: 700;
	letter-spacing: .08em;
	text-transform: uppercase;
	color: var(--svp-fun, #14b8a6);
}

.sv-puzzle-heading h1 {
	margin: 0;
	font-family: var(--svp-display);
	font-size: clamp(14px, 1.5vw, 18px);
	font-weight: 700;
	line-height: 1.25;
	white-space: normal;
	overflow: hidden;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2;
	line-clamp: 2;
}

.sv-puzzle-stats {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	justify-content: flex-end;
	align-items: stretch;
	flex: 0 0 auto;
}

.sv-puzzle-stat {
	min-width: 68px;
	padding: 6px 10px;
	border-radius: 10px;
	background: rgba(0, 0, 0, 0.22);
	border: 1px solid var(--svp-panel-border);
	text-align: center;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.sv-puzzle-stat__label {
	display: block;
	font-size: 10px;
	font-weight: 700;
	letter-spacing: .06em;
	text-transform: uppercase;
	color: var(--svp-muted);
	margin-bottom: 2px;
}

.sv-puzzle-stat strong {
	font-size: 18px;
	font-variant-numeric: tabular-nums;
	letter-spacing: -.02em;
}

.sv-puzzle-controls {
	--sv-ctrl-h: 36px;
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	justify-content: flex-start;
	align-items: center;
	width: 100%;
	padding-top: 10px;
	border-top: 1px solid var(--svp-panel-border);
}

.sv-puzzle-diff {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	height: var(--sv-ctrl-h);
	font-size: 12px;
	font-weight: 600;
	color: var(--svp-muted);
}

.sv-puzzle-ctrl-label {
	white-space: nowrap;
}

.sv-puzzle-rotate-opt {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	height: var(--sv-ctrl-h);
	box-sizing: border-box;
	font-size: 12px;
	font-weight: 600;
	color: var(--svp-muted);
	cursor: pointer;
	user-select: none;
	padding: 0 12px;
	border-radius: 10px;
	border: 1px solid var(--svp-panel-border);
	background: rgba(0, 0, 0, 0.18);
	white-space: nowrap;
}

.sv-puzzle-rotate-opt input {
	margin: 0;
	accent-color: var(--svp-accent-2);
	width: 15px;
	height: 15px;
	flex: 0 0 auto;
}

.sv-puzzle-rotate-opt:hover {
	color: var(--svp-text);
	border-color: rgba(255, 255, 255, 0.2);
}

.sv-puzzle-diff select {
	appearance: none;
	height: var(--sv-ctrl-h);
	box-sizing: border-box;
	background: rgba(0, 0, 0, 0.28);
	color: var(--svp-text);
	border: 1px solid var(--svp-panel-border);
	border-radius: 10px;
	padding: 0 30px 0 12px;
	font: inherit;
	font-weight: 600;
	font-size: 12px;
	line-height: 1;
	cursor: pointer;
	background-image: linear-gradient(45deg, transparent 50%, #94a3b8 50%), linear-gradient(135deg, #94a3b8 50%, transparent 50%);
	background-position: calc(100% - 14px) calc(50% - 2px), calc(100% - 9px) calc(50% - 2px);
	background-size: 5px 5px, 5px 5px;
	background-repeat: no-repeat;
}

.sv-puzzle-btn {
	appearance: none;
	height: var(--sv-ctrl-h);
	box-sizing: border-box;
	border: 1px solid var(--svp-panel-border);
	background: rgba(255, 255, 255, 0.06);
	color: var(--svp-text);
	font: inherit;
	font-size: 12px;
	font-weight: 700;
	padding: 0 14px;
	border-radius: 10px;
	cursor: pointer;
	text-decoration: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
	white-space: nowrap;
	transition: transform .15s ease, background .15s ease, border-color .15s ease;
	user-select: none;
	-webkit-user-select: none;
}

.sv-puzzle-btn:hover {
	background: rgba(255, 255, 255, 0.12);
	border-color: rgba(255, 255, 255, 0.2);
}

.sv-puzzle-btn:active {
	transform: translateY(1px);
}

.sv-puzzle-btn--primary {
	background: linear-gradient(135deg, var(--svp-accent), #0673a5);
	border-color: transparent;
	box-shadow: 0 8px 24px rgba(10, 134, 191, 0.35);
}

.sv-puzzle-btn--primary:hover {
	background: linear-gradient(135deg, #0b94d4, var(--svp-accent));
}

.sv-puzzle-main {
	flex: 1 1 auto;
	min-height: 0;
	display: grid;
	grid-template-columns: minmax(0, 1.45fr) minmax(220px, 0.85fr);
	gap: 14px;
	overflow: hidden;
}

.sv-puzzle-board-wrap {
	position: relative;
	min-width: 0;
	min-height: 0;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 14px;
	background: var(--svp-panel);
	border: 1px solid var(--svp-panel-border);
	border-radius: var(--svp-radius);
	box-shadow: var(--svp-shadow);
	overflow: hidden;
}

.sv-puzzle-board {
	--svp-tab: 0.2;
	position: relative;
	/* width/height set by JS to fit wrap + preserve image aspect */
	width: auto;
	height: auto;
	max-width: 100%;
	max-height: 100%;
	display: grid;
	gap: 0;
	padding: 0;
	margin: 0 auto;
	background:
		linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 40%),
		rgba(0, 0, 0, 0.38);
	border-radius: 14px;
	border: 1px solid rgba(255, 255, 255, 0.08);
	touch-action: none;
	overflow: visible;
	box-sizing: border-box;
	flex: 0 0 auto;
}

.sv-puzzle-slot {
	position: relative;
	background:
		repeating-linear-gradient(
			-45deg,
			rgba(255, 255, 255, 0.03),
			rgba(255, 255, 255, 0.03) 4px,
			transparent 4px,
			transparent 8px
		);
	border: 0;
	outline: 1px dashed rgba(255, 255, 255, 0.07);
	outline-offset: -1px;
	overflow: visible;
	min-width: 0;
	min-height: 0;
	z-index: 1;
}

.sv-puzzle-slot.is-target {
	outline-color: rgba(56, 189, 248, 0.85);
	background: rgba(10, 134, 191, 0.2);
	z-index: 3;
}

.sv-puzzle-slot.is-filled {
	outline-color: transparent;
	background: transparent;
	z-index: 2;
}

.sv-puzzle-slot.is-filled:has(.is-locked) {
	z-index: 4;
}

.sv-puzzle-piece {
	display: block;
	position: absolute;
	/* Oversized so knobs stick out of the cell */
	width: calc(100% * (1 + 2 * var(--svp-tab)));
	height: calc(100% * (1 + 2 * var(--svp-tab)));
	left: calc(-100% * var(--svp-tab));
	top: calc(-100% * var(--svp-tab));
	overflow: visible;
	cursor: grab;
	touch-action: none;
	user-select: none;
	-webkit-user-select: none;
	filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.42));
	transition: transform .15s ease, filter .12s ease, opacity .12s ease;
	z-index: 2;
	transform-origin: center center;
}

.sv-puzzle-piece__edge-shadow,
.sv-puzzle-piece__edge-highlight,
.sv-puzzle-piece__edge {
	pointer-events: none;
}

.sv-puzzle-tray .sv-puzzle-piece {
	position: relative;
	left: auto;
	top: auto;
	width: 100%;
	height: auto;
}

.sv-puzzle-piece:active,
.sv-puzzle-piece.is-dragging {
	cursor: grabbing;
	z-index: 40;
	filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.55));
	transform: scale(1.05);
}

.sv-puzzle-piece.is-locked {
	cursor: default;
	filter: none;
	pointer-events: none;
	z-index: 1;
}

.sv-puzzle-piece.is-correct {
	animation: svp-snap .28s ease;
}

.sv-puzzle-piece.is-wrong-rot {
	animation: svp-wiggle .42s ease;
}

@keyframes svp-wiggle {
	0%, 100% { transform: rotate(var(--svp-rot, 0deg)); }
	20% { transform: rotate(calc(var(--svp-rot, 0deg) - 8deg)); }
	40% { transform: rotate(calc(var(--svp-rot, 0deg) + 8deg)); }
	60% { transform: rotate(calc(var(--svp-rot, 0deg) - 5deg)); }
	80% { transform: rotate(calc(var(--svp-rot, 0deg) + 5deg)); }
}

@keyframes svp-snap {
	0% { transform: scale(1.07); filter: drop-shadow(0 0 12px rgba(52, 211, 153, 0.55)); }
	100% { transform: scale(1); }
}

.sv-puzzle-piece.is-ghost {
	position: fixed;
	z-index: 80;
	pointer-events: none;
	margin: 0;
	left: 0;
	top: 0;
	max-width: none;
	filter: drop-shadow(0 18px 28px rgba(0, 0, 0, 0.55));
	opacity: .97;
	transition: width .12s ease, height .12s ease;
}

.sv-puzzle-tray-wrap {
	min-height: 0;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 14px;
	background: linear-gradient(180deg, #dce5f0 0%, #cfd9e6 100%);
	border: 1px solid rgba(255, 255, 255, 0.35);
	border-radius: var(--svp-radius);
	overflow: hidden;
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.sv-puzzle-tray-hint {
	margin: 0;
	font-size: 12px;
	font-weight: 700;
	color: #334155;
}

.sv-puzzle-tray {
	flex: 1;
	min-height: 0;
	overflow: auto;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
	gap: 14px;
	align-content: start;
	padding: 8px 4px 12px;
	touch-action: pan-y;
	background: rgba(255, 255, 255, 0.35);
	border-radius: 12px;
	border: 1px solid rgba(15, 23, 42, 0.06);
}

.sv-puzzle-board.is-complete {
	gap: 0;
	padding: 0;
	overflow: hidden;
	animation: svp-glow 1.2s ease;
}

.sv-puzzle-board.is-complete .sv-puzzle-slot {
	outline: none;
}

.sv-puzzle-board.is-complete .sv-puzzle-piece {
	filter: none;
}

.sv-puzzle-pause-veil {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 14px;
	background: rgba(8, 12, 20, 0.72);
	backdrop-filter: blur(6px);
	z-index: 20;
}

.sv-puzzle-pause-veil[hidden] {
	display: none !important;
}

.sv-puzzle-pause-veil p {
	margin: 0;
	font-family: var(--svp-display);
	font-size: 28px;
}

.sv-puzzle-loading {
	position: fixed;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	background: rgba(8, 12, 20, 0.72);
	z-index: 50;
	backdrop-filter: blur(4px);
}

.sv-puzzle-app[data-loading="0"] .sv-puzzle-loading {
	display: none;
}

.sv-puzzle-spinner {
	width: 36px;
	height: 36px;
	border-radius: 999px;
	border: 3px solid rgba(255, 255, 255, 0.15);
	border-top-color: var(--svp-accent-2);
	animation: svp-spin .8s linear infinite;
}

@keyframes svp-spin {
	to { transform: rotate(360deg); }
}

.sv-puzzle-peek {
	position: fixed;
	inset: 0;
	z-index: 60;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
	background: rgba(8, 12, 20, 0.78);
	backdrop-filter: blur(8px);
}

.sv-puzzle-peek[hidden] {
	display: none !important;
}

.sv-puzzle-peek img {
	max-width: min(920px, 100%);
	max-height: 85dvh;
	border-radius: 14px;
	box-shadow: var(--svp-shadow);
	object-fit: contain;
}

.sv-puzzle-win {
	position: fixed;
	inset: 0;
	z-index: 70;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20px;
	background: rgba(8, 12, 20, 0.78);
	backdrop-filter: blur(10px);
}

.sv-puzzle-win[hidden] {
	display: none !important;
}

.sv-puzzle-win__card {
	animation: svp-pop .35s ease;
}

@keyframes svp-pop {
	from { opacity: 0; transform: translateY(10px) scale(.98); }
	to { opacity: 1; transform: none; }
}

.sv-puzzle-win__card h2 {
	font-family: var(--svp-display);
}

.sv-puzzle-win__stats {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px;
	margin: 0 0 14px;
	text-align: center;
}

.sv-puzzle-win__stats div {
	padding: 12px;
	border-radius: 12px;
	background: rgba(255, 255, 255, 0.04);
	border: 1px solid var(--svp-panel-border);
}

.sv-puzzle-win__stats span {
	display: block;
	font-size: 11px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: .05em;
	color: var(--svp-muted);
	margin-bottom: 4px;
}

.sv-puzzle-win__stats strong {
	font-size: 22px;
	font-variant-numeric: tabular-nums;
}

@keyframes svp-glow {
	0%, 100% { box-shadow: 0 0 0 rgba(52, 211, 153, 0); }
	40% { box-shadow: 0 0 40px rgba(52, 211, 153, 0.35); }
}

@media (max-width: 960px) {
	.sv-puzzle-top__main {
		flex-direction: column;
		align-items: stretch;
		gap: 10px;
	}

	.sv-puzzle-stats {
		justify-content: flex-start;
	}

	.sv-puzzle-main {
		grid-template-columns: 1fr;
		grid-template-rows: minmax(0, 1.15fr) minmax(140px, 0.85fr);
	}

	.sv-puzzle-tray-wrap {
		max-height: none;
		min-height: 0;
	}

	.sv-puzzle-tray {
		grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
		gap: 8px;
	}

	.sv-puzzle-heading h1 {
		font-size: clamp(13px, 3.6vw, 16px);
	}
}

@media (max-width: 520px) {
	.sv-puzzle-app {
		padding: 10px;
		gap: 10px;
	}

	.sv-puzzle-stat {
		min-width: 58px;
		padding: 5px 8px;
	}

	.sv-puzzle-controls {
		--sv-ctrl-h: 34px;
		gap: 6px;
	}

	.sv-puzzle-ctrl-label {
		display: none;
	}

	.sv-puzzle-btn,
	.sv-puzzle-diff select,
	.sv-puzzle-rotate-opt {
		font-size: 11px;
		padding-left: 10px;
		padding-right: 10px;
	}
}
