/* Global theme */
:root {
	color-scheme: dark;
	--bg-0: #06080f;
	--bg-1: #0d1320;
	--bg-2: #151d2c;
	--panel: rgba(18, 24, 36, 0.82);
	--panel-strong: rgba(11, 16, 27, 0.92);
	--panel-border: rgba(255, 255, 255, 0.09);
	--text: #eef2fb;
	--muted: #9ca8bb;
	--accent: #66d9ff;
	--accent-2: #ffb86b;
	--gold: #e2bf72;
	--board-light: #d6c0a3;
	--board-dark: #7e5741;
	--shadow-lg: 0 24px 80px rgba(0, 0, 0, 0.48);
	--shadow-md: 0 12px 30px rgba(0, 0, 0, 0.28);
	--radius-xl: 22px;
	--radius-lg: 16px;
	--radius-md: 12px;
	--radius-sm: 8px;
}

* {
	box-sizing: border-box;
}

html,
body {
	min-height: 100%;
}

body {
	margin: 0;
	color: var(--text);
	font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
	background:
		radial-gradient(circle at 20% 15%, rgba(102, 217, 255, 0.18), transparent 30%),
		radial-gradient(circle at 82% 22%, rgba(226, 191, 114, 0.13), transparent 22%),
		linear-gradient(145deg, var(--bg-0), var(--bg-1) 55%, #05070b 100%);
	overflow-x: hidden;
}

body::before {
	content: "";
	position: fixed;
	inset: 0;
	pointer-events: none;
	background-image:
		linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
		linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
	background-size: 84px 84px;
	mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent 92%);
	opacity: 0.18;
}

.app {
	position: relative;
	display: grid;
	grid-template-columns: minmax(0, 1.1fr) 320px;
	gap: 22px;
	min-height: 100vh;
	padding: 22px;
}

.board {
	align-self: center;
	justify-self: center;
	position: relative;
	display: grid;
	grid-template-columns: repeat(8, minmax(0, 1fr));
	grid-template-rows: repeat(8, minmax(0, 1fr));
	width: min(90vh, 90vw);
	aspect-ratio: 1 / 1;
	border-radius: 24px;
	overflow: hidden;
	box-shadow: var(--shadow-lg);
	border: 1px solid rgba(255, 255, 255, 0.08);
	background: #0b0f16;
	transform: translateZ(0);
	transform-origin: center center;
	transition: transform 200ms ease-out;
}

.board.flipped {
	transform: rotate(180deg);
}

.board.flipped .square {
	transform: rotate(180deg);
}

.square {
	position: relative;
	display: grid;
 	transform-origin: center center;
	transition: transform 200ms ease-out;
	width: 100%;
	height: 100%;
	border: 0;
	border-radius: 0;
	appearance: none;
	-webkit-appearance: none;
	padding: 0;
	margin: 0;
	color: inherit;
	font-size: clamp(1.8rem, 2.7vw, 3rem);
	line-height: 1;
	user-select: none;
	cursor: pointer;
	transition:
		transform 120ms ease,
		filter 120ms ease,
		box-shadow 120ms ease,
		background-color 120ms ease;
	z-index: 1;
}

.square.light {
	background:
		radial-gradient(circle at top left, rgba(255, 255, 255, 0.18), transparent 40%),
		linear-gradient(135deg, #e1cfb5, var(--board-light));
}

.square.dark {
	background:
		radial-gradient(circle at top left, rgba(255, 255, 255, 0.09), transparent 40%),
		linear-gradient(135deg, #8f6650, var(--board-dark));
}

.square:hover {
	filter: brightness(1.05) saturate(1.03);
}

.square.selected-piece {
	box-shadow: inset 0 0 0 4px rgba(255, 184, 107, 0.95);
}

.square.highlight {
	box-shadow: inset 0 0 0 4px rgba(102, 217, 255, 0.92);
}

.square.last-move-from {
	box-shadow: inset 0 0 0 4px rgba(226, 191, 114, 0.96);
}

.square.last-move-to {
	box-shadow: inset 0 0 0 4px rgba(255, 184, 107, 0.92);
}

.square.annotated-square {
	box-shadow: inset 0 0 0 4px rgba(168, 123, 255, 0.95);
}

.square.move-target {
	position: relative;
}

.square.move-target::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	background: rgba(102, 217, 255, 0.78);
	box-shadow: 0 0 0 8px rgba(102, 217, 255, 0.12);
	transform: translate(-50%, -50%);
}

.square.has-piece::before {
	content: "";
	position: absolute;
	inset: 12%;
	background-image: url("pieces.png");
	background-repeat: no-repeat;
	background-size: 600% 200%;
	background-position: 0 0;
	pointer-events: none;
	z-index: 2;
}

/* White pieces (top row of sprite sheet: KQBNRP) */
.square[data-piece="K"]::before { background-position: 0% 0%; }
.square[data-piece="Q"]::before { background-position: 20% 0%; }
.square[data-piece="B"]::before { background-position: 40% 0%; }
.square[data-piece="N"]::before { background-position: 60% 0%; }
.square[data-piece="R"]::before { background-position: 80% 0%; }
.square[data-piece="P"]::before { background-position: 100% 0%; }

/* Black pieces (bottom row of sprite sheet: KQBNRP) */
.square[data-piece="k"]::before { background-position: 0% 100%; }
.square[data-piece="q"]::before { background-position: 20% 100%; }
.square[data-piece="b"]::before { background-position: 40% 100%; }
.square[data-piece="n"]::before { background-position: 60% 100%; }
.square[data-piece="r"]::before { background-position: 80% 100%; }
.square[data-piece="p"]::before { background-position: 100% 100%; }

.annotation-layer {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	display: block;
	pointer-events: none;
	z-index: 3;
}


.side {
	align-self: center;
	display: flex;
	flex-direction: column;
	gap: 14px;
	min-width: 0;
}

.panel,
.modal-content {
	border: 1px solid var(--panel-border);
	background: var(--panel);
	box-shadow: var(--shadow-md);
	backdrop-filter: blur(16px);
}

.panel {
	border-radius: var(--radius-lg);
	padding: 16px;
}

.compact-panel {
	padding-bottom: 14px;
}

.running-games-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 10px 12px;
	border-radius: 12px;
	background: rgba(255, 255, 255, 0.04);
	border: 1px solid rgba(255, 255, 255, 0.08);
}

.running-games-label {
	color: var(--muted);
	font-size: 0.92rem;
	line-height: 1.2;
}

.running-games-count {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 42px;
	height: 28px;
	padding: 0 10px;
	border-radius: 999px;
	background: linear-gradient(135deg, #8be7ff, #5bbad8);
	color: #08111c;
	font-weight: 800;
	box-shadow: 0 10px 20px rgba(91, 186, 216, 0.18);
}

.panel h3,
.modal-content h3 {
	margin: 0 0 12px;
	font-family: "Georgia", serif;
	font-weight: 700;
	letter-spacing: 0.02em;
}

.panel h3 {
	font-size: 1.05rem;
}

.modal-content label {
	display: block;
	margin: 12px 0 6px;
	color: var(--muted);
	font-size: 0.92rem;
	letter-spacing: 0.01em;
}

input,
select,
button {
	font: inherit;
}

input,
select {
	width: 100%;
	border: 1px solid rgba(255, 255, 255, 0.12);
	border-radius: 10px;
	background: rgba(7, 11, 18, 0.76);
	color: var(--text);
	padding: 11px 12px;
	outline: none;
	transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

input:focus,
select:focus {
	border-color: rgba(102, 217, 255, 0.75);
	box-shadow: 0 0 0 3px rgba(102, 217, 255, 0.16);
}

button {
	width: 100%;
	margin-top: 10px;
	border: 0;
	border-radius: 999px;
	padding: 11px 14px;
	color: #08111c;
	background: linear-gradient(135deg, #8be7ff, #5bbad8);
	box-shadow: 0 10px 20px rgba(91, 186, 216, 0.2);
	cursor: pointer;
	transition:
		transform 120ms ease,
		filter 120ms ease,
		box-shadow 120ms ease;
}

button:hover {
	transform: translateY(-1px);
	filter: brightness(1.03);
	box-shadow: 0 14px 24px rgba(91, 186, 216, 0.26);
}

button:active {
	transform: translateY(0);
}

.button-secondary {
	background: linear-gradient(135deg, #f8cc8e, #e3a75b);
	color: #231507;
	box-shadow: 0 10px 20px rgba(227, 167, 91, 0.22);
}

.button-secondary:hover {
	box-shadow: 0 14px 24px rgba(227, 167, 91, 0.28);
}

#colorStack,
.color-stack,
#moveList {
	display: grid;
	gap: 8px;
}

#colorStack,
.color-stack {
	grid-template-columns: repeat(5, minmax(0, 1fr));
	align-content: start;
	max-height: 180px;
	overflow: auto;
}

#moveList {
	grid-template-columns: 1fr;
}

.color-item,
.move-entry,
.game-status {
	border-radius: 10px;
}

.color-item {
	position: relative;
	display: grid;
	place-items: center;
	aspect-ratio: 1 / 1;
	padding: 0;
	font-size: 0;
	border: 1px solid rgba(255, 255, 255, 0.08);
	overflow: hidden;
}

.color-item.white {
	color: #10202d;
	background: linear-gradient(135deg, #eff5fb, #d7e5f5);
}

.color-item.black {
	color: #eef2fb;
	background: linear-gradient(135deg, #293241, #171d29);
}

.color-item.white::before,
.color-item.black::before {
	content: "";
	width: 42%;
	height: 42%;
	border-radius: 50%;
	box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12) inset;
}

.color-item.white::before {
	background: linear-gradient(135deg, #ffffff, #d9e6f2);
}

.color-item.black::before {
	background: linear-gradient(135deg, #394353, #151c29);
}

.pointer {
	box-shadow: 0 0 0 5px rgba(255, 102, 0, 0.85) inset;
}

.game-status {
	margin-bottom: 12px;
	padding: 10px 12px;
	background: linear-gradient(135deg, rgba(102, 217, 255, 0.12), rgba(255, 184, 107, 0.08));
	border: 1px solid rgba(255, 255, 255, 0.08);
	color: var(--text);
	font-weight: 600;
}

.move-entry {
	padding: 8px 10px;
	background: rgba(6, 9, 15, 0.56);
	border: 1px solid rgba(255, 255, 255, 0.06);
	color: var(--text);
	font-size: 0.95rem;
}

.modal {
	position: fixed;
	inset: 0;
	z-index: 40;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 20px;
	background: rgba(3, 5, 10, 0.66);
	backdrop-filter: blur(8px);
}

.settings-modal {
	z-index: 50;
}

.modal.hidden {
	display: none;
}

.hidden {
	display: none !important;
}

.modal-content {
	width: min(360px, 100%);
	border-radius: 20px;
	padding: 20px;
}

.settings-modal .modal-content {
	width: min(420px, 100%);
}

.modal-text {
	margin: 2px 0 8px;
	color: var(--muted);
	font-size: 0.98rem;
}

.loading {
	margin-top: 12px;
	padding: 10px 12px;
	display: flex;
	align-items: center;
	gap: 10px;
	border-radius: 10px;
	background: rgba(102, 217, 255, 0.1);
	border: 1px solid rgba(102, 217, 255, 0.28);
	color: #d7f7ff;
	font-weight: 600;
}

.spinner {
	width: 16px;
	height: 16px;
	border-radius: 50%;
	border: 2px solid rgba(215, 247, 255, 0.32);
	border-top-color: rgba(215, 247, 255, 0.95);
	animation: spin 0.85s linear infinite;
}

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

.modal-content button + button {
	margin-top: 8px;
}

/* Simple panel spacing tweaks */
.panel h3 + * {
	margin-top: 4px;
}

/* Make the resign panel feel like a control strip. */
.side .panel:last-child h3 {
	text-transform: capitalize;
}

/* Responsive layout */
@media (max-width: 1080px) {
	.app {
		grid-template-columns: 1fr;
	}

	.board {
		width: min(94vw, 760px);
	}

	.side {
		width: min(100%, 760px);
		justify-self: center;
	}

}

@media (max-width: 720px) {
	.app {
		padding: 14px;
		gap: 16px;
	}

	.board {
		width: calc(100vw - 28px);
		border-radius: 18px;
	}

	.panel,
	.modal-content {
		border-radius: 16px;
	}

	.square {
		font-size: clamp(1.3rem, 5vw, 2.2rem);
	}

	.game-status,
	.move-entry,
	.color-item {
		font-size: 0.95rem;
	}
}

