:root {
	--board-size: 6;
}

* {
	padding: 0;
	margin: 0;
	box-sizing: border-box;
}

html {
	font-size: 62.5%;
	overflow-x: hidden;
	scroll-behavior: smooth;
}

body {
	font-size: 1.6rem;
	font-family: "Inter", sans-serif;
	color: #0a0a0a;
	line-height: 1;
	font-weight: 400;
	padding: 1rem;

	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	height: 90vh;
}

h1 {
	text-align: center;
	font-size: 3.2rem;
	margin: 1rem 0 2rem;
	font-weight: 700;
}

.hide {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.2s ease, visibility 0.2s ease;
}

.game-container {
	width: 100%;
	max-width: 600px;
	margin: 0 auto;
	padding: 1rem;

	max-height: 100vh;
}

.game-status {
	width: 100%;
	padding: 1.6rem 1rem;
}

.moves-info {
	display: flex;
	justify-content: space-between;
	align-items: center;
	font-size: 2rem;
}

.move-display,
.optimal-display {
	font-weight: 500;
}

.game-controls {
	display: flex;
	justify-content: center;
	gap: 1rem;
}

.game-btn {
	border: 2px solid;
	padding: 0.75rem 1.5rem;
	border-radius: 5px;
	font-size: 1.8rem;
	font-weight: 500;
	cursor: pointer;
	transition: all 0.2s ease;
	display: flex;
	align-items: center;
}

.game-btn:hover {
	transform: translateY(-2px);
}

.game-btn:active {
	transform: translateY(0);
}

.game-btn:disabled {
	cursor: not-allowed;
	transform: translateY(0);
}

.chessboard {
	display: grid;
	grid-template-columns: repeat(var(--board-size), 1fr);
	grid-template-rows: repeat(var(--board-size), 1fr);
	gap: 0px;
	border: 3px solid #0a0a0a;
	border-radius: 13px;
	overflow: hidden;

	height: auto;
	aspect-ratio: 1;

	margin: 0 auto;
}

.square {
	position: relative;
	width: 100%;
	height: 100%;
	overflow: hidden;
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.square.light {
	background: #f0d9b5;
}

.square.dark {
	background: #b58863;
}

.square.valid {
	background: #22c55e !important;
	box-shadow: inset 0 0 0 3px #16a34a;
}

.square.valid:hover {
	opacity: 0.8;
}

.square::after {
	content: "";
	position: absolute;
	inset: 4px;
	border-radius: 5px;
	pointer-events: none;
	opacity: 0;
	transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.square.target::after {
	border: 4px dashed #ef4444;
	opacity: 1;
	pointer-events: none;
}

.square.visited::after {
	border: 4px solid #3b82f6;
	opacity: 1;
	pointer-events: none;
}

.square.visited.target::after {
	border: 4px solid #22c55e;
	opacity: 1;
	background: transparent;
}

.square.valid.visited::after {
	opacity: 0;
}

.square:has(.knight):hover {
	box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.15);
}

.knight {
	position: absolute;
	top: 50%;
	left: 50%;
	width: 90%;
	height: 90%;
	transform: translate(-50%, -50%);
	cursor: grab;
	user-select: none;
	z-index: 10;
	transition: filter 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
	will-change: transform;
}

.knight svg {
	width: 100%;
	height: 100%;
	object-fit: contain;
	overflow: visible;
}

.knight:active {
	cursor: grabbing;
	transform: scale(1.05);
}

.knight.dragging {
	position: fixed !important;
	transition: none;
	z-index: 1000;
	cursor: grabbing;
	filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.5));
}

.knight.game-over {
	pointer-events: none !important;
	cursor: default !important;
}

.copy-box {
	position: fixed;
	width: 40rem;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	background: white;
	border: 2px solid #000;
	border-radius: 9px;
	padding: 1.6rem;
	z-index: 1000;
}

.copy-text {
	width: 100%;
	height: 12rem;
	border: 1px solid #000;
	border-radius: 5px;
	padding: 0.8rem;
	font-family: inherit;
	font-size: 1.6rem;
	resize: none;
	background: #fafafa;
	margin-bottom: 1rem;
	box-sizing: border-box;
}

.copy-close-btn {
	background: transparent;
	border: 1px solid #000;
	border-radius: 6px;
	padding: 0.6rem 1.2rem;
	font-size: 1.6rem;
	font-family: inherit;
	cursor: pointer;
	color: #000;
	transition: background-color 0.2s ease, color 0.2s ease;
}

@media (max-width: 500px) {
	body {
		padding: 2rem;
	}

	h1 {
		font-size: 2.4rem;
	}

	.moves-info {
		font-size: 1.6rem;
	}

	.game-btn {
		padding: 0.5rem 1rem;
		font-size: 1.6rem;
	}

	.square::after {
		inset: 3px;
	}

	.square.target::after {
		border: 3px dashed #ef4444;
	}

	.square.visited::after {
		border: 3px solid #3b82f6;
	}

	.square.visited.target::after {
		border: 3px solid #22c55e;
	}
}
