/* Game modal overlay */
.game-modal {
	position: fixed;
	inset: 0;
	z-index: 2000;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(0, 0, 0, 0.5);
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
}

.game-modal-box {
	position: relative;
	width: 440px;
	max-width: calc(100vw - 1.5rem);
	background: var(--bg-surface);
	border-radius: var(--radius-large, 16px);
	box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3);
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.game-modal-header {
	display: grid;
	grid-template-columns: 1fr auto 1fr;
	align-items: center;
	padding: 0.6rem 0.75rem;
	border-bottom: 1px solid var(--border-light);
	flex-shrink: 0;
}

.game-modal-score {
	grid-column: 1;
	text-align: left;
	font-size: 0.75rem;
	color: var(--text-muted);
	font-weight: 500;
	min-width: 26px;
}

.game-modal-title {
	grid-column: 2;
	text-align: center;
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--text-primary);
}

.game-modal-close {
	grid-column: 3;
	justify-self: end;
	width: 26px;
	height: 26px;
	border: none;
	background: var(--bg-tertiary, var(--bg-secondary));
	border-radius: 50%;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--text-secondary);
	font-size: 0.75rem;
	transition: all 0.2s ease;
	flex-shrink: 0;
}

.game-modal-close:hover {
	background: var(--color-error);
	color: #fff;
}

.game-modal-body {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 0.75rem;
	width: 100%;
	box-sizing: border-box;
}

/* ===================== SNAKE ===================== */
.snake-canvas {
	border-radius: 8px;
	display: block;
}

/* Universal game settings bar */
.game-settings {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	padding: 0.5rem 0.75rem;
	border-top: 1px solid var(--border-light);
	font-size: 0.75rem;
	color: var(--text-muted);
	flex-shrink: 0;
}

.game-settings-row {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
}

.game-settings input[type="range"] {
	width: 90px;
	accent-color: var(--color-primary);
}

.game-setting-btn {
	padding: 0.25rem 0.6rem;
	font-size: 0.7rem;
	font-weight: 600;
	border: 1px solid var(--border-light);
	border-radius: 4px;
	background: var(--bg-secondary);
	color: var(--text-secondary);
	cursor: pointer;
	transition: all 0.15s ease;
}

.game-setting-btn:hover {
	border-color: var(--color-primary);
	color: var(--color-primary);
}

.game-setting-btn.active {
	background: var(--gradient-brand);
	color: #fff;
	border-color: transparent;
}

.game-settings-label {
	font-size: 0.7rem;
	color: var(--text-muted);
	margin-right: 0.25rem;
}

/* ===================== TIC TAC TOE ===================== */
.ttt-board {
	display: grid;
	gap: 5px;
}

.ttt-cell {
	width: 80px;
	height: 80px;
	background: var(--bg-secondary);
	border: 1px solid var(--border-light);
	border-radius: 6px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.8rem;
	font-weight: 700;
	color: var(--text-primary);
	transition: background 0.15s ease;
	user-select: none;
}

.ttt-cell:hover:not(.ttt-taken) {
	background: var(--bg-elevated, var(--bg-tertiary));
}

.ttt-cell.ttt-x { color: var(--color-primary); }
.ttt-cell.ttt-o { color: var(--color-error); }

.ttt-status {
	text-align: center;
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--text-primary);
	margin-top: 0.6rem;
	min-height: 1.2em;
}

.ttt-restart {
	display: block;
	margin: 0.4rem auto 0;
	padding: 0.35rem 1rem;
	font-size: 0.8rem;
	font-weight: 500;
	border: 1px solid var(--border-light);
	border-radius: var(--radius-button, 8px);
	background: var(--bg-surface);
	color: var(--text-secondary);
	cursor: pointer;
	transition: all 0.2s ease;
}

.ttt-restart:hover {
	border-color: var(--color-primary);
	color: var(--color-primary);
}

/* ===================== MEMORY ===================== */
.memory-board {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 5px;
	width: 240px;
	height: 240px;
}

.memory-card {
	background: var(--bg-secondary);
	border: 1px solid var(--border-light);
	border-radius: 6px;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.3rem;
	transition: all 0.2s ease;
	user-select: none;
}

.memory-card:hover:not(.memory-flipped):not(.memory-matched) {
	background: var(--bg-elevated, var(--bg-tertiary));
}

.memory-card.memory-flipped,
.memory-card.memory-matched {
	background: var(--bg-surface);
	border-color: rgba(var(--brand-blue-rgb), 0.3);
}

.memory-card.memory-matched {
	opacity: 0.5;
	cursor: default;
}

.memory-hidden {
	visibility: hidden;
}

/* ===================== 2048 ===================== */
.game-2048-wrapper {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.4rem;
}

.game-2048-board {
	display: grid;
	gap: 5px;
	background: #bbada0;
	border-radius: 8px;
	padding: 5px;
	user-select: none;
}

.tile-2048 {
	width: 60px;
	height: 60px;
	border-radius: 5px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.1rem;
	font-weight: 700;
	color: #776e65;
	background: #cdc1b4;
}

.tile-2048[data-val="0"] { background: #cdc1b4; color: transparent; }
.tile-2048[data-val="2"] { background: #eee4da; }
.tile-2048[data-val="4"] { background: #ede0c8; }
.tile-2048[data-val="8"] { background: #f2b179; color: #fff; }
.tile-2048[data-val="16"] { background: #f59563; color: #fff; }
.tile-2048[data-val="32"] { background: #f67c5f; color: #fff; }
.tile-2048[data-val="64"] { background: #f65e3b; color: #fff; }
.tile-2048[data-val="128"] { background: #edcf72; color: #fff; font-size: 1rem; }
.tile-2048[data-val="256"] { background: #edcc61; color: #fff; font-size: 1rem; }
.tile-2048[data-val="512"] { background: #edc850; color: #fff; font-size: 1rem; }
.tile-2048[data-val="1024"] { background: #edc53f; color: #fff; font-size: 0.85rem; }
.tile-2048[data-val="2048"] { background: #edc22e; color: #fff; font-size: 0.85rem; }

.game-2048-over {
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--color-error);
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 420px) {
	.game-modal-box {
		width: calc(100vw - 1.5rem);
	}

	.ttt-cell {
		width: 60px;
		height: 60px;
		font-size: 1.5rem;
	}

	.tile-2048 {
		width: 52px;
		height: 52px;
		font-size: 0.95rem;
	}

	.memory-card {
		font-size: 1.1rem;
	}
}

/* ===================== DARK THEME ===================== */
:root[data-theme="dark"] .game-modal-box {
	box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
}

:root[data-theme="dark"] .ttt-cell {
	background: var(--bg-elevated, var(--bg-secondary));
}

:root[data-theme="dark"] .memory-card {
	background: var(--bg-elevated, var(--bg-secondary));
}

:root[data-theme="dark"] .game-2048-board {
	background: #534b45;
}

:root[data-theme="dark"] .tile-2048 {
	background: #635b52;
	color: var(--text-muted);
}

:root[data-theme="dark"] .tile-2048[data-val="0"] { background: #635b52; color: transparent; }
:root[data-theme="dark"] .tile-2048[data-val="2"] { background: #504a42; color: var(--text-primary); }
:root[data-theme="dark"] .tile-2048[data-val="4"] { background: #5a5244; color: var(--text-primary); }
:root[data-theme="dark"] .tile-2048[data-val="8"] { background: #c2854a; color: #fff; }
:root[data-theme="dark"] .tile-2048[data-val="16"] { background: #c47040; color: #fff; }
:root[data-theme="dark"] .tile-2048[data-val="32"] { background: #c55a3c; color: #fff; }
:root[data-theme="dark"] .tile-2048[data-val="64"] { background: #c43a22; color: #fff; }
