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

body {
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	color: #333;
	min-height: 100vh;
	line-height: 1.6;
	overflow-x: hidden; /* Prevent horizontal scrolling */
}

.container {
	max-width: 1400px;
	margin: 0 auto;
	padding: 20px;
	width: 100%;
}

header {
	text-align: center;
	margin-bottom: 30px;
	color: white;
}

header h1 {
	font-size: 2.5em;
	margin-bottom: 10px;
	text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
	font-weight: 700;
}

header p {
	font-size: 1.1em;
	opacity: 0.9;
	margin-bottom: 20px;
}

.links {
	display: flex;
	gap: 15px;
	justify-content: center;
	flex-wrap: wrap;
}

.links a {
	color: white;
	text-decoration: none;
	padding: 10px 20px;
	background: rgba(255, 255, 255, 0.1);
	border-radius: 25px;
	backdrop-filter: blur(10px);
	transition: all 0.3s ease;
	border: 1px solid rgba(255, 255, 255, 0.2);
}

.links a:hover {
	background: rgba(255, 255, 255, 0.2);
	transform: translateY(-2px);
	box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.game-container {
	display: grid;
	grid-template-columns: auto 1fr;
	gap: 30px;
	max-width: 100%;
	align-items: start;
	justify-content: center;
}

.board-container {
	background: rgba(45, 52, 66, 0.95);
	border-radius: 15px;
	padding: 25px;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
	backdrop-filter: blur(10px);
	border: 1px solid rgba(255, 255, 255, 0.1);
	color: #e0e6ed;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.chessboard {
	display: grid;
	grid-template-columns: repeat(8, 70px);
	grid-template-rows: repeat(8, 70px);
	border: 3px solid #8b4513;
	border-radius: 8px;
	overflow: hidden;
	box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
	margin: 0 auto;
	justify-self: center;
	align-self: center;
}

.square {
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 45px;
	cursor: pointer;
	transition: all 0.2s ease;
	position: relative;
	user-select: none;
	text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8),
		-1px -1px 2px rgba(255, 255, 255, 0.3);
}

.square.light {
	background-color: #f0d9b5;
}

.square.dark {
	background-color: #b58863;
}

/* Enhanced piece visibility with clear color distinction */
.square.has-piece {
	font-weight: 900;
	filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.7));
}

.square.piece-white {
	color: #ffffff;
	text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.9), -1px -1px 2px rgba(0, 0, 0, 0.8),
		0 0 8px rgba(255, 255, 255, 0.3);
}

.square.piece-black {
	color: #2c2c2c;
	text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.9),
		-1px -1px 1px rgba(255, 255, 255, 0.7), 0 0 6px rgba(0, 0, 0, 0.5);
}

/* Additional contrast on different square colors */
.square.dark.piece-white {
	color: #ffffff;
	text-shadow: 2px 2px 4px rgba(0, 0, 0, 1), -1px -1px 2px rgba(0, 0, 0, 0.8),
		0 0 10px rgba(255, 255, 255, 0.4);
}

.square.light.piece-black {
	color: #1a1a1a;
	text-shadow: 1px 1px 3px rgba(255, 255, 255, 1),
		-1px -1px 1px rgba(255, 255, 255, 0.8), 0 0 8px rgba(0, 0, 0, 0.3);
}

/* Hover effects for better visibility */
.square.has-piece:hover {
	transform: scale(1.05);
	filter: drop-shadow(3px 3px 6px rgba(0, 0, 0, 0.8));
}

/* Make selected pieces extra visible */
.square.selected.piece-white {
	color: #ffffff;
	text-shadow: 3px 3px 6px rgba(0, 0, 0, 1), -2px -2px 4px rgba(0, 0, 0, 0.9),
		0 0 15px rgba(255, 255, 255, 0.5);
}

.square.selected.piece-black {
	color: #000000;
	text-shadow: 2px 2px 4px rgba(255, 255, 255, 1),
		-1px -1px 2px rgba(255, 255, 255, 0.9), 0 0 15px rgba(255, 255, 255, 0.6);
}

.square.selected {
	background-color: #20a020 !important;
	box-shadow: inset 0 0 0 3px #006600, 0 0 15px rgba(32, 160, 32, 0.6);
	animation: pulse 1s infinite;
}

.square.selected.piece-white {
	color: #ffffff;
	text-shadow: 2px 2px 6px rgba(0, 0, 0, 1), 0 0 10px rgba(0, 0, 0, 0.8);
}

.square.selected.piece-black {
	color: #000000;
	text-shadow: 1px 1px 4px rgba(255, 255, 255, 1),
		0 0 10px rgba(255, 255, 255, 0.8);
}

@keyframes pulse {
	0%,
	100% {
		transform: scale(1);
	}
	50% {
		transform: scale(0.95);
	}
}

.square.valid-move {
	background-color: #90ee90 !important;
}

.square.valid-move::after {
	content: "";
	position: absolute;
	width: 20px;
	height: 20px;
	border-radius: 50%;
	background: #006600;
	opacity: 0.7;
}

.square.valid-move.has-piece::after {
	width: calc(100% - 6px);
	height: calc(100% - 6px);
	border-radius: 4px;
	border: 3px solid #006600;
	background: rgba(0, 102, 0, 0.2);
	box-sizing: border-box;
}

.square:hover {
	opacity: 0.8;
	transform: scale(0.98);
}

.board-controls {
	margin-top: 20px;
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
}

.turn-indicator {
	font-size: 1.3em;
	font-weight: bold;
	color: #e0e6ed;
	margin-bottom: 15px;
	text-align: center;
}

.control-buttons {
	display: flex;
	gap: 10px;
	justify-content: center;
	flex-wrap: wrap;
}

.btn {
	padding: 12px 20px;
	border: none;
	border-radius: 25px;
	background: linear-gradient(45deg, #667eea, #764ba2);
	color: white;
	cursor: pointer;
	font-size: 14px;
	font-weight: 500;
	transition: all 0.3s ease;
	text-decoration: none;
	display: inline-block;
}

.btn:hover {
	transform: translateY(-2px);
	box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
	background: linear-gradient(45deg, #5a6fd8, #6b4190);
}

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

.btn.btn-small {
	padding: 8px 16px;
	font-size: 12px;
}

.info-panel {
	background: rgba(45, 52, 66, 0.95);
	border-radius: 15px;
	padding: 25px;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
	backdrop-filter: blur(10px);
	border: 1px solid rgba(255, 255, 255, 0.1);
	max-height: fit-content;
	color: #e0e6ed;
}

.section {
	margin-bottom: 25px;
}

.section:last-child {
	margin-bottom: 0;
}

.section h3 {
	color: #9bb3ff;
	margin-bottom: 15px;
	font-size: 1.2em;
	font-weight: 600;
}

.section ul {
	list-style: none;
	padding-left: 0;
}

.section li {
	margin-bottom: 8px;
	padding-left: 20px;
	position: relative;
}

.section li::before {
	content: "▸";
	position: absolute;
	left: 0;
	color: #9bb3ff;
	font-weight: bold;
}

.status-display {
	padding: 15px;
	border-radius: 8px;
	background: rgba(30, 35, 45, 0.8);
	font-weight: bold;
	text-align: center;
	border: 2px solid rgba(255, 255, 255, 0.1);
	transition: all 0.3s ease;
	color: #e0e6ed;
}

.status-display.loading {
	background: rgba(21, 101, 192, 0.2);
	color: #64b5f6;
	border-color: rgba(100, 181, 246, 0.3);
}

.status-display.ready {
	background: rgba(46, 125, 50, 0.2);
	color: #81c784;
	border-color: rgba(129, 199, 132, 0.3);
}

.status-display.check {
	background: rgba(133, 100, 4, 0.2);
	color: #ffb74d;
	border-color: rgba(255, 183, 77, 0.3);
	animation: shake 0.5s ease-in-out;
}

.status-display.checkmate {
	background: rgba(114, 28, 36, 0.2);
	color: #e57373;
	border-color: rgba(229, 115, 115, 0.3);
	animation: flash 1s ease-in-out;
}

.status-display.stalemate {
	background: rgba(12, 84, 96, 0.2);
	color: #4db6ac;
	border-color: rgba(77, 182, 172, 0.3);
}

.status-display.error {
	background: rgba(114, 28, 36, 0.2);
	color: #e57373;
	border-color: rgba(229, 115, 115, 0.3);
}

@keyframes shake {
	0%,
	100% {
		transform: translateX(0);
	}
	25% {
		transform: translateX(-5px);
	}
	75% {
		transform: translateX(5px);
	}
}

@keyframes flash {
	0%,
	50%,
	100% {
		opacity: 1;
	}
	25%,
	75% {
		opacity: 0.5;
	}
}

#fen-display {
	width: 100%;
	height: 80px;
	border: 2px solid rgba(255, 255, 255, 0.2);
	border-radius: 8px;
	padding: 12px;
	font-family: "Courier New", monospace;
	font-size: 12px;
	resize: none;
	background: rgba(30, 35, 45, 0.8);
	color: #e0e6ed;
	transition: border-color 0.3s ease;
}

#fen-display:focus {
	border-color: #9bb3ff;
	outline: none;
	box-shadow: 0 0 0 3px rgba(155, 179, 255, 0.2);
}

.fen-controls {
	margin-top: 15px;
	display: flex;
	gap: 10px;
	flex-wrap: wrap;
}

#fen-input {
	flex: 1;
	min-width: 200px;
	padding: 10px;
	border: 2px solid rgba(255, 255, 255, 0.2);
	border-radius: 8px;
	font-family: "Courier New", monospace;
	font-size: 12px;
	background: rgba(30, 35, 45, 0.8);
	color: #e0e6ed;
	transition: border-color 0.3s ease;
}

#fen-input:focus {
	border-color: #9bb3ff;
	outline: none;
	box-shadow: 0 0 0 3px rgba(155, 179, 255, 0.2);
}

#fen-input::placeholder {
	color: rgba(224, 230, 237, 0.5);
}

.move-history {
	max-height: 200px;
	overflow-y: auto;
	background: rgba(30, 35, 45, 0.8);
	border-radius: 8px;
	padding: 15px;
	font-family: "Courier New", monospace;
	font-size: 14px;
	border: 2px solid rgba(255, 255, 255, 0.1);
	margin-bottom: 10px;
	color: #e0e6ed;
}

.move-history::-webkit-scrollbar {
	width: 8px;
}

.move-history::-webkit-scrollbar-track {
	background: rgba(30, 35, 45, 0.5);
	border-radius: 4px;
}

.move-history::-webkit-scrollbar-thumb {
	background: rgba(155, 179, 255, 0.3);
	border-radius: 4px;
}

.move-history::-webkit-scrollbar-thumb:hover {
	background: rgba(155, 179, 255, 0.5);
}

.move-entry {
	margin: 5px 0;
	padding: 2px 0;
}

.example-positions {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
	gap: 8px;
	margin-top: 10px;
}

.error-container {
	background: rgba(45, 52, 66, 0.95);
	border-radius: 15px;
	padding: 40px;
	box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
	text-align: center;
	color: #e0e6ed;
	border: 1px solid rgba(255, 255, 255, 0.1);
}

.error-container h2 {
	color: #d32f2f;
	margin-bottom: 20px;
}

.error-container h3 {
	color: #9bb3ff;
	margin: 25px 0 15px;
}

.error-container code {
	background: rgba(30, 35, 45, 0.8);
	color: #9bb3ff;
	padding: 4px 8px;
	border-radius: 4px;
	font-family: "Courier New", monospace;
}

.error-container ol,
.error-container ul {
	text-align: left;
	max-width: 600px;
	margin: 0 auto;
}

footer {
	text-align: center;
	margin-top: 40px;
	color: white;
	opacity: 0.8;
}

footer p {
	margin: 5px 0;
}

/* Tablet landscape and smaller desktops */
@media (max-width: 1200px) {
	.game-container {
		grid-template-columns: 1fr;
		gap: 20px;
		justify-items: center;
	}

	.board-container {
		order: 1;
		width: 100%;
		max-width: 600px;
		margin: 0 auto;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.info-panel {
		order: 2;
		width: 100%;
		max-width: 600px;
		margin: 0 auto;
	}
	
	.chessboard {
		margin: 0 auto;
		justify-self: center;
	}
}

/* Tablet portrait and large phones */
@media (max-width: 768px) {
	.container {
		padding: 15px 10px;
	}
	
	.board-container {
		width: 100%;
		padding: 20px 15px;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		max-width: 480px;
	}

	.chessboard {
		grid-template-columns: repeat(8, 45px);
		grid-template-rows: repeat(8, 45px);
		margin: 0 auto;
		justify-self: center;
		align-self: center;
	}

	.board-controls {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 15px;
		margin-top: 20px;
	}

	.turn-indicator {
		text-align: center;
		width: 100%;
		max-width: 300px;
	}

	.control-buttons {
		display: flex;
		justify-content: center;
		flex-wrap: wrap;
		gap: 10px;
		width: 100%;
	}

	.square {
		font-size: 30px;
		/* Better touch targets */
		min-height: 45px;
		min-width: 45px;
	}

	/* Enhanced touch interaction */
	.square:hover,
	.square:active {
		transform: scale(0.95);
		background-color: rgba(255, 255, 0, 0.3) !important;
	}

	.square.selected {
		background-color: rgba(255, 255, 0, 0.5) !important;
		transform: scale(1.05);
		box-shadow: inset 0 0 10px rgba(255, 255, 0, 0.8);
	}

	.square.valid-move {
		background-color: rgba(0, 255, 0, 0.4) !important;
		animation: pulse 1.5s infinite;
	}

	@keyframes pulse {
		0% {
			box-shadow: 0 0 0 0 rgba(0, 255, 0, 0.7);
		}
		70% {
			box-shadow: 0 0 0 10px rgba(0, 255, 0, 0);
		}
		100% {
			box-shadow: 0 0 0 0 rgba(0, 255, 0, 0);
		}
	}

	header h1 {
		font-size: 2em;
		text-align: center;
	}

	.info-panel {
		width: 100%;
		max-width: 500px;
		margin: 0 auto;
		padding: 15px;
	}

	.container {
		padding: 10px;
	}

	.board-container,
	.info-panel {
		padding: 15px;
		background: rgba(45, 52, 66, 0.95);
		border: 1px solid rgba(255, 255, 255, 0.1);
		border-radius: 10px;
	}

	.control-buttons {
		justify-content: center;
		flex-wrap: wrap;
		gap: 10px;
	}

	.btn {
		padding: 12px 20px;
		font-size: 14px;
		min-height: 44px; /* Better touch target */
		touch-action: manipulation; /* Prevent double-tap zoom */
	}

	.fen-controls {
		flex-direction: column;
		gap: 10px;
	}

	#fen-input {
		min-width: auto;
		padding: 12px;
		font-size: 16px; /* Prevent zoom on iOS */
	}

	.example-positions {
		grid-template-columns: repeat(2, 1fr);
		gap: 8px;
	}

	.example-btn {
		padding: 8px 12px;
		font-size: 12px;
		min-height: 40px;
	}
}

@media (max-width: 480px) {
	.container {
		padding: 8px;
		width: 100%;
		overflow-x: hidden;
	}
	
	.board-container {
		width: 100%;
		padding: 15px 10px;
		margin: 0 auto;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		max-width: 100%;
		box-sizing: border-box;
	}

	.chessboard {
		grid-template-columns: repeat(8, 35px);
		grid-template-rows: repeat(8, 35px);
		margin: 0 auto;
		justify-self: center;
		align-self: center;
		width: fit-content;
	}

	.square {
		font-size: 20px;
		min-height: 35px;
		min-width: 35px;
	}

	.board-container,
	.info-panel {
		padding: 12px;
		margin: 0 auto 15px auto;
		width: 100%;
		max-width: 400px;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	
	.board-controls {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 10px;
		margin-top: 15px;
	}

	header h1 {
		font-size: 1.6em;
	}

	header p {
		font-size: 0.95em;
	}

	.links {
		flex-direction: column;
		align-items: center;
		gap: 8px;
	}

	.links a {
		padding: 8px 16px;
		font-size: 14px;
		min-width: 120px;
		text-align: center;
	}

	.example-positions {
		grid-template-columns: 1fr;
	}

	.turn-indicator {
		font-size: 16px;
		padding: 8px;
		margin-bottom: 12px;
		text-align: center;
		background: rgba(255, 255, 255, 0.1);
		border-radius: 5px;
	}

	.status-display {
		font-size: 14px;
		padding: 10px;
	}

	#fen-display {
		font-size: 12px;
		min-height: 60px;
	}
}

/* Extra small screens */
@media (max-width: 360px) {
	.container {
		padding: 5px;
	}

	.chessboard {
		grid-template-columns: repeat(8, 30px);
		grid-template-rows: repeat(8, 30px);
		margin: 0 auto;
	}

	.square {
		font-size: 18px;
		min-height: 30px;
		min-width: 30px;
	}

	.board-container {
		padding: 10px 8px;
	}

	header h1 {
		font-size: 1.4em;
	}

	header p {
		font-size: 0.9em;
	}

	.btn {
		padding: 10px 16px;
		font-size: 13px;
		min-height: 42px;
	}
}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {
	.square:hover {
		/* Remove hover effects on touch devices */
		background-color: inherit;
		transform: none;
	}

	.square:active {
		/* Better active state for touch */
		background-color: rgba(255, 255, 0, 0.4) !important;
		transform: scale(0.95);
	}

	.btn:hover {
		background: inherit;
		transform: none;
	}

	.btn:active {
		transform: scale(0.95);
		background: rgba(255, 255, 255, 0.2);
	}
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
	.square {
		image-rendering: crisp-edges;
	}
}

/* Promotion Modal Styles */
.modal {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.8);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 1000;
	backdrop-filter: blur(5px);
}

.modal-content {
	background: linear-gradient(135deg, #2d3442, #394553);
	padding: 30px;
	border-radius: 15px;
	text-align: center;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
	border: 2px solid rgba(255, 255, 255, 0.1);
	max-width: 500px;
	width: 90%;
}

.modal-content h3 {
	color: #e0e6ed;
	font-size: 1.8em;
	margin-bottom: 10px;
	text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.modal-content p {
	color: #b0bdc8;
	font-size: 1.1em;
	margin-bottom: 25px;
}

.promotion-choices {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 15px;
	margin-top: 20px;
}

.promotion-btn {
	background: linear-gradient(135deg, #4a5568, #5a667a);
	border: 2px solid rgba(255, 255, 255, 0.2);
	border-radius: 12px;
	padding: 20px 15px;
	cursor: pointer;
	transition: all 0.3s ease;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	min-height: 100px;
}

.promotion-btn:hover {
	background: linear-gradient(135deg, #667eea, #764ba2);
	transform: translateY(-3px);
	box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
	border-color: rgba(255, 255, 255, 0.4);
}

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

.promotion-piece {
	font-size: 3em;
	color: #ffffff;
	text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
	filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.3));
}

.promotion-label {
	color: #e0e6ed;
	font-size: 1.1em;
	font-weight: bold;
	text-transform: capitalize;
}

@media (max-width: 600px) {
	.promotion-choices {
		grid-template-columns: repeat(2, 1fr);
		gap: 12px;
	}

	.promotion-btn {
		padding: 15px 10px;
		min-height: 85px;
	}

	.promotion-piece {
		font-size: 2.5em;
	}

	.promotion-label {
		font-size: 1em;
	}

	.modal-content {
		padding: 25px 20px;
	}
}
