.color-lines .body {
	padding: 0 10px;
}

.color-lines .game {
	display: grid;
	width: max-content;
	max-width: 100%;
	margin: 20px auto;
	border: 3px solid #7590AE;
	border-radius: 8px;
	box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
	overflow: hidden;
}

.color-lines .scores {
	display: grid;
	grid-template-columns: 1fr 1fr;
	background-color: #7590AE;
	padding: 6px;
	color: #fff;
}
.color-lines .scores span {
	font-weight: bold;
}
.color-lines .scores>div:last-child {
	text-align: right;
}
.color-lines #topScore.new {
	animation-name: newtopscore;
	animation-duration: 0.5s;
	animation-iteration-count: 5;
}

@keyframes newtopscore {
	0% {
		color: inherit;
	}

	25% {
		color: red;
	}

	50% {
		color: green;
	}

	75% {
		color: #3080D0;
	}
}

.color-lines #points {
	color: red;
	display: none;
	animation: flash 0.5s ease-in infinite;
}
@keyframes flash {
	0% { opacity: 0; }
	50% { opacity: 1; }
	100% { opacity: 0; }
}

.color-lines .table {
	display: inline-grid;
	grid-template-columns: repeat(9, 1fr);
	grid-template-rows: repeat(9, 1fr);
	background: #7590AE; /*#767676; */
	padding: 4px;
	max-width: calc(100vw - 20px);
	box-sizing: border-box;
}
.color-lines .cell {
	width: 36px;
	height: 36px;
	border: 1px solid #ddd;
	transition: all 0.2s ease;
	cursor: pointer;
}

/* No hover effects by default - only when a ball is selected */

/* Hover effects on empty cells only when a ball is selected */
.color-lines.ball-selected .cell:hover:not(:has(img)) {
	background: #f0f8ff;
	border-color: #90b0ff;
}

.color-lines .cell img {
	margin: 2px;
	width: 32px;
	height: 32px;
	transition: all 0.3s ease;
	cursor: pointer;
	border-radius: 50%;
}

/* Remove hover effects on ball images entirely */

.color-lines .cell img.selected {
	opacity: 1;
	animation: rotate 1.5s linear infinite;
	transform: scale(1.1);
	filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.8));
}

/* Stop selection animation when ball is moving */
.color-lines .cell img.moving {
	animation: ballMove 0.2s ease-in-out;
	z-index: 100;
	/* Override selected animation */
	transform: scale(1) !important;
	filter: none !important;
}

.color-lines .cell img.moving.selected {
	animation: ballMove 0.2s ease-in-out !important;
}
@keyframes rotate {
	0% { transform: rotate(0deg) scale(1.1); }
	100% { transform: rotate(360deg) scale(1.1); }
}

@keyframes ballMove {
	0% { transform: scale(1); }
	50% { transform: scale(1.2); }
	100% { transform: scale(1); }
}

@keyframes ballRemove {
	0% {
		transform: scale(1);
		opacity: 1;
	}
	50% {
		transform: scale(1.3);
		opacity: 0.8;
	}
	100% {
		transform: scale(0);
		opacity: 0;
	}
}

@keyframes ballAppear {
	0% {
		transform: scale(0);
		opacity: 0;
	}
	50% {
		transform: scale(1.2);
		opacity: 0.8;
	}
	100% {
		transform: scale(1);
		opacity: 1;
	}
}

.color-lines .cell img.moving {
	animation: ballMove 0.2s ease-in-out;
	z-index: 100;
}

.color-lines .cell img.removing {
	animation: ballRemove 0.4s ease-out forwards;
}

.color-lines .cell img.appearing {
	animation: ballAppear 0.3s ease-out forwards;
}


.color-lines #next img {
	width: 24px;
	margin-right: 8px;
}

.color-lines .controls {
	padding: 6px;
	background-color: #7590AE;
	color: #fff;
	display: grid;
	grid-template-columns: 1fr 1fr;
}
.color-lines .controls div:nth-child(2) {
	text-align: right;
	margin-top: 19px;
}

.color-lines .rules {
	margin-bottom: 3em;
}

.color-lines .rules p {
	margin-bottom: 1em;
}

.color-lines h2 {
	line-height: 2em;
	font-size: 130%;
	font-weight: normal;
}

/* Small mobile screens (320px and below) */
@media screen and (max-width: 320px) {
	.color-lines .body {
		padding: 0 5px;
	}

	.color-lines .game {
		margin: 10px auto;
		border-width: 2px;
	}

	.color-lines .table {
		padding: 2px;
		max-width: calc(100vw - 14px);
	}

	.color-lines .cell {
		width: 28px;
		height: 28px;
		border-width: 0.5px;
	}

	.color-lines .cell img {
		margin: 1px;
		width: 26px;
		height: 26px;
	}

	.color-lines .scores {
		padding: 4px;
		font-size: 14px;
	}

	.color-lines .controls {
		padding: 4px;
		font-size: 14px;
	}

	.color-lines .controls div:nth-child(2) {
		margin-top: 14px;
	}

	.color-lines #next img {
		width: 20px;
		margin-right: 4px;
	}
}

/* Medium mobile screens (360px and below) */
@media screen and (max-width: 360px) and (min-width: 321px) {
	.color-lines .body {
		padding: 0 8px;
	}

	.color-lines .game {
		margin: 15px auto;
	}

	.color-lines .table {
		padding: 3px;
		max-width: calc(100vw - 16px);
	}

	.color-lines .cell {
		width: 30px;
		height: 30px;
	}

	.color-lines .cell img {
		margin: 1px;
		width: 28px;
		height: 28px;
	}
}

/* Touch device improvements */
@media (hover: none) and (pointer: coarse) {
	.color-lines .cell {
		min-width: 32px;
		min-height: 32px;
		-webkit-tap-highlight-color: transparent;
		touch-action: manipulation;
	}

	.color-lines .cell img {
		min-width: 28px;
		min-height: 28px;
		-webkit-tap-highlight-color: transparent;
		touch-action: manipulation;
		-webkit-user-select: none;
		user-select: none;
	}

	/* Hover effects on empty cells only when a ball is selected on touch devices */
	.color-lines.ball-selected .cell:hover:not(:has(img)) {
		background: #fff;
		border-color: #ddd;
	}

	/* No hover effects on ball images */

	/* Immediate visual feedback on touch */
	.color-lines .cell:active {
		background: #90b0ff !important;
		border-color: #4169e1 !important;
		transform: scale(0.95);
	}

	.color-lines .cell img:active {
		transform: scale(1.05) !important;
		filter: brightness(1.1) !important;
	}
}

/* Touch + small screen combination */
@media (hover: none) and (pointer: coarse) and (max-width: 320px) {
	.color-lines .cell {
		min-width: 28px;
		min-height: 28px;
		width: 28px;
		height: 28px;
	}

	.color-lines .cell img {
		min-width: 26px;
		min-height: 26px;
		width: 26px;
		height: 26px;
	}
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
	.color-lines.ball-selected .cell:hover:not(:has(img)) {
		background: #90b0ff;
	}
}
.color-lines .game-over {
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background-color: rgba(0, 0, 0, 0.5);
	justify-content: center;
	align-items: center;
	z-index: 1001;
	padding: 10px;
	box-sizing: border-box;
}

.color-lines .game-over>div {
	background-color: white;
	padding: 20px;
	border-radius: 10px;
	text-align: center;
	color: black;
	max-width: 90%;
	max-height: 90%;
	overflow-y: auto;
}

/* Mobile game-over adjustments */
@media screen and (max-width: 360px) {
	.color-lines .game-over>div {
		padding: 15px;
		font-size: 14px;
	}
}
