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

:root {
	--primary-blue: #4299e1;
	--primary-blue-dark: #3182ce;
	--success-green: #38a169;
	--success-green-dark: #2f855a;
	--danger-red: #e53e3e;
	--kofi-red: #ff5e5b;
	--kofi-red-dark: #e53e3e;
	--text-primary: #1a202c;
	--text-secondary: #4a5568;
	--text-muted: #718096;
	--bg-light: #f7fafc;
	--bg-gray: #e2e8f0;
	--bg-gray-dark: #cbd5e0;
	--border-color: #e2e8f0;
	--shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
	--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
	--shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.1);
}

body {
	font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
	background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
	min-height: 100vh;
	padding: 12px;
	display: flex;
	align-items: flex-start;
	justify-content: center;
}

.container {
	background: white;
	border-radius: 16px;
	box-shadow: var(--shadow-lg);
	padding: 20px;
	width: 100%;
	/* Dynamic max-width based on grid size */
	max-width: min(95vw, max(420px, calc(var(--grid-cols, 10) * 32px + 120px)));
	margin-top: 20px;
}

/* Header */
header {
	text-align: center;
	margin-bottom: 20px;
}

h1 {
	font-size: 2rem;
	font-weight: 700;
	color: var(--text-primary);
	margin-bottom: 6px;
}

.subtitle {
	color: var(--text-muted);
	font-size: 0.95rem;
	margin-bottom: 16px;
}

.header-buttons {
	display: flex;
	gap: 8px;
	justify-content: center;
	flex-wrap: wrap;
}

.instructions-btn,
.kofi-btn,
.homepage-btn {
	border: none;
	padding: 8px 12px;
	border-radius: 8px;
	font-size: 0.8rem;
	cursor: pointer;
	transition: all 0.2s ease;
	text-decoration: none;
	display: inline-flex;
	align-items: center;
	gap: 4px;
	font-weight: 500;
	flex: 1;
	min-width: 0;
	justify-content: center;
}

.instructions-btn {
	background: var(--primary-blue);
	color: white;
}

.instructions-btn:hover {
	background: var(--primary-blue-dark);
	transform: translateY(-1px);
}

.kofi-btn {
	background: var(--kofi-red);
	color: white;
}

.kofi-btn:hover {
	background: var(--kofi-red-dark);
	transform: translateY(-1px);
}

.homepage-btn {
	background: var(--success-green);
	color: white;
}

.homepage-btn:hover {
	background: var(--success-green-dark);
	transform: translateY(-1px);
}

/* Mobile Stats Bar */
.mobile-stats-bar {
	display: flex;
	justify-content: space-around;
	background: var(--bg-light);
	border-radius: 12px;
	padding: 12px 8px;
	margin-bottom: 16px;
	border: 1px solid var(--border-color);
}

.stat-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	flex: 1;
}

.stat-icon {
	font-size: 1.2rem;
}

.stat-value {
	font-size: 0.9rem;
	font-weight: 600;
	color: var(--text-primary);
}

/* Desktop Game Info (hidden on mobile) */
.desktop-only {
	display: none;
}

/* Mobile Controls */
.mobile-controls {
	margin-bottom: 16px;
}

.control-buttons {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
}

.flag-toggle {
	background: var(--bg-gray);
	border: 2px solid var(--bg-gray-dark);
	border-radius: 12px;
	padding: 12px 24px;
	font-size: 1rem;
	font-weight: 600;
	cursor: pointer;
	transition: all 0.2s ease;
	display: flex;
	align-items: center;
	gap: 8px;
	min-width: 140px;
	justify-content: center;
	touch-action: manipulation;
}

.flag-toggle.active {
	background: #fed7d7;
	border-color: var(--danger-red);
	color: #c53030;
}

.flag-toggle:active {
	transform: scale(0.98);
}

.flag-icon {
	font-size: 1.2em;
}

.control-hint {
	text-align: center;
	font-size: 0.75rem;
	color: var(--text-muted);
	padding: 0 16px;
}

/* Game Container - Responsive Grid */
#game-container {
	display: flex;
	justify-content: center;
	align-items: center;
	margin-bottom: 16px;
	width: 100%;
}

#loading {
	text-align: center;
	padding: 40px 20px;
	color: var(--text-muted);
	font-size: 1rem;
}

#game-board {
	display: grid;
	gap: 2px;
	background: var(--bg-gray);
	padding: 8px;
	border-radius: 12px;
	touch-action: manipulation;
	/* Center the grid and make it fit properly */
	margin: 0 auto;
	justify-content: center;
	align-content: center;
}

/* Responsive cell sizing */
.cell {
	background: var(--bg-gray-dark);
	border: none;
	border-radius: 4px;
	cursor: pointer;
	font-weight: 600;
	transition: all 0.15s ease;
	display: flex;
	align-items: center;
	justify-content: center;
	position: relative;
	touch-action: manipulation;
	user-select: none;
	aspect-ratio: 1;
}

/* Base mobile sizing */
.cell {
	width: calc((100vw - 80px) / var(--grid-cols, 10));
	height: calc((100vw - 80px) / var(--grid-cols, 10));
	max-width: 36px;
	max-height: 36px;
	min-width: 22px;
	min-height: 22px;
	font-size: clamp(
		10px,
		calc((100vw - 80px) / var(--grid-cols, 10) * 0.4),
		16px
	);
}

.cell:active {
	transform: scale(0.95);
}

.cell.touch-active {
	background: #a0aec0;
	transform: scale(0.95);
}

.cell.revealed {
	background: var(--bg-light);
	cursor: default;
	border: 1px solid var(--border-color);
}

.cell.flagged {
	background: #fed7d7;
	color: var(--danger-red);
}

.cell.mine {
	background: #feb2b2;
	color: #c53030;
}

.cell.mine-hit {
	background: var(--danger-red);
	color: white;
	animation: mineHit 0.5s ease-out;
}

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

/* Number colors */
.cell.number-1 {
	color: #3182ce;
}
.cell.number-2 {
	color: #38a169;
}
.cell.number-3 {
	color: #e53e3e;
}
.cell.number-4 {
	color: #805ad5;
}
.cell.number-5 {
	color: #d69e2e;
}
.cell.number-6 {
	color: #dd6b20;
}
.cell.number-7 {
	color: #000;
}
.cell.number-8 {
	color: #718096;
}

/* Mobile Action Bar */
.mobile-action-bar {
	display: flex;
	justify-content: center;
	gap: 16px;
	margin-top: 16px;
}

.action-btn {
	background: var(--bg-light);
	border: 1px solid var(--border-color);
	border-radius: 12px;
	padding: 12px 16px;
	cursor: pointer;
	transition: all 0.2s ease;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
	min-width: 60px;
	touch-action: manipulation;
}

.action-btn:active {
	transform: scale(0.98);
	background: var(--bg-gray);
}

.action-icon {
	font-size: 1.2rem;
}

.action-text {
	font-size: 0.7rem;
	color: var(--text-muted);
	font-weight: 500;
}

.hidden {
	display: none !important;
}

/* Game Over Modal */
#game-over {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.8);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 1000;
	padding: 20px;
}

.game-over-content {
	background: white;
	border-radius: 16px;
	padding: 24px;
	text-align: center;
	max-width: 360px;
	width: 100%;
}

#result-title {
	font-size: 1.8rem;
	margin-bottom: 12px;
}

#result-title.won {
	color: var(--success-green);
}

#result-title.lost {
	color: var(--danger-red);
}

#result-message {
	color: var(--text-muted);
	margin-bottom: 20px;
	font-size: 1rem;
}

.stats {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 12px;
	margin-bottom: 20px;
	padding: 16px;
	background: var(--bg-light);
	border-radius: 8px;
}

.stat {
	display: flex;
	flex-direction: column;
	align-items: center;
}

.stat-label {
	font-size: 0.8rem;
	color: var(--text-muted);
	margin-bottom: 4px;
}

.stat span:last-child {
	font-size: 1.1rem;
	font-weight: 600;
	color: var(--text-primary);
}

.share-buttons {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
	margin-bottom: 20px;
}

.share-buttons .copy {
	grid-column: 1 / -1;
}

.share-btn {
	padding: 10px 16px;
	border: none;
	border-radius: 8px;
	font-weight: 600;
	cursor: pointer;
	transition: all 0.15s ease;
	font-size: 0.85rem;
	touch-action: manipulation;
}

.share-btn.twitter {
	background: #1da1f2;
	color: white;
}

.share-btn.instagram {
	background: linear-gradient(
		45deg,
		#f09433 0%,
		#e6683c 25%,
		#dc2743 50%,
		#cc2366 75%,
		#bc1888 100%
	);
	color: white;
}

.share-btn.copy {
	background: var(--bg-gray);
	color: var(--text-primary);
}

.share-btn:active {
	transform: scale(0.98);
}

.next-puzzle {
	color: var(--text-muted);
	font-size: 0.85rem;
}

#countdown {
	font-weight: 600;
	color: var(--text-primary);
}

/* Modal Styles */
.modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.8);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 2000;
	padding: 20px;
}

.modal-content {
	background: white;
	border-radius: 16px;
	max-width: 500px;
	width: 100%;
	max-height: 90vh;
	overflow-y: auto;
}

.modal-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 20px 24px 0;
	border-bottom: 1px solid var(--border-color);
	margin-bottom: 20px;
}

.modal-header h2 {
	color: var(--text-primary);
	font-size: 1.3rem;
}

.close-btn {
	background: none;
	border: none;
	font-size: 1.8rem;
	color: var(--text-muted);
	cursor: pointer;
	padding: 0;
	width: 32px;
	height: 32px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	transition: all 0.15s ease;
	touch-action: manipulation;
}

.close-btn:active {
	background: var(--bg-light);
	color: var(--text-primary);
}

.modal-body {
	padding: 0 24px;
}

.instruction-section {
	margin-bottom: 20px;
}

.instruction-section h3 {
	color: var(--text-primary);
	margin-bottom: 10px;
	font-size: 1rem;
}

.instruction-section p {
	color: var(--text-secondary);
	line-height: 1.5;
	margin-bottom: 10px;
	font-size: 0.9rem;
}

.instruction-section ul {
	color: var(--text-secondary);
	line-height: 1.5;
	padding-left: 18px;
	font-size: 0.9rem;
}

.instruction-section li {
	margin-bottom: 6px;
}

.controls-grid {
	display: grid;
	gap: 8px;
}

.control-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 10px;
	background: var(--bg-light);
	border-radius: 8px;
}

.control-key {
	font-weight: 600;
	color: var(--text-primary);
	background: var(--bg-gray);
	padding: 4px 8px;
	border-radius: 4px;
	font-size: 0.8rem;
}

.control-desc {
	color: var(--text-secondary);
	font-size: 0.85rem;
	text-align: right;
	flex: 1;
	margin-left: 12px;
}

.number-examples {
	display: flex;
	gap: 6px;
	margin-top: 10px;
	flex-wrap: wrap;
}

.number-example {
	width: 28px;
	height: 28px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--bg-light);
	border-radius: 4px;
	font-weight: 600;
	font-size: 12px;
}

.modal-footer {
	padding: 20px 24px;
	border-top: 1px solid var(--border-color);
	text-align: center;
}

.start-btn {
	background: var(--success-green);
	color: white;
	border: none;
	padding: 12px 24px;
	border-radius: 8px;
	font-weight: 600;
	font-size: 1rem;
	cursor: pointer;
	transition: all 0.15s ease;
	touch-action: manipulation;
}

.start-btn:active {
	background: var(--success-green-dark);
	transform: scale(0.98);
}

.mobile-only {
	display: block;
}

/* Tablet and Desktop Styles */
@media (min-width: 769px) {
	body {
		align-items: center;
		padding: 20px;
	}

	.container {
		/* Expand container for larger grids on desktop */
		max-width: min(
			90vw,
			max(600px, calc(var(--grid-cols, 10) * 40px + 160px))
		);
		padding: 32px;
		margin-top: 0;
	}

	h1 {
		font-size: 2.5rem;
		margin-bottom: 8px;
	}

	.subtitle {
		font-size: 1.1rem;
		margin-bottom: 16px;
	}

	.header-buttons {
		gap: 12px;
	}

	.instructions-btn,
	.kofi-btn,
	.homepage-btn {
		padding: 8px 16px;
		font-size: 0.9rem;
		flex: none;
	}

	/* Show desktop layout, hide mobile */
	.mobile-stats-bar,
	.mobile-controls,
	.mobile-action-bar {
		display: none;
	}

	.desktop-only {
		display: block;
	}

	.mobile-only {
		display: none;
	}

	.game-info {
		display: grid;
		grid-template-columns: repeat(3, 1fr);
		gap: 16px;
		background: var(--bg-light);
		border-radius: 12px;
		padding: 16px;
		margin-bottom: 24px;
	}

	.info-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		text-align: center;
	}

	.label {
		font-size: 0.875rem;
		color: var(--text-muted);
		font-weight: 500;
		margin-bottom: 4px;
	}

	.info-item span:last-child {
		font-size: 1.25rem;
		font-weight: 600;
		color: var(--text-primary);
	}

	/* Desktop cell sizing - better for larger grids */
	.cell {
		width: calc(min(600px, 90vw - 160px) / var(--grid-cols, 10));
		height: calc(min(600px, 90vw - 160px) / var(--grid-cols, 10));
		max-width: 40px;
		max-height: 40px;
		min-width: 24px;
		min-height: 24px;
		font-size: clamp(
			10px,
			calc(min(600px, 90vw - 160px) / var(--grid-cols, 10) * 0.4),
			18px
		);
	}

	.cell:hover:not(.revealed):not(.flagged) {
		background: #a0aec0;
		transform: translateY(-1px);
		box-shadow: var(--shadow-sm);
	}

	.cell.hovered {
		outline: 2px solid var(--primary-blue);
		outline-offset: 1px;
	}

	#game-container {
		margin-bottom: 24px;
	}

	.share-buttons {
		display: flex;
		gap: 12px;
		flex-wrap: wrap;
	}

	.share-btn {
		flex: 1;
		min-width: 120px;
		font-size: 0.9rem;
		padding: 12px 20px;
	}

	.share-btn:hover {
		transform: translateY(-2px);
		box-shadow: var(--shadow-md);
	}
}

/* Large screens - even more space for big grids */
@media (min-width: 1200px) {
	.container {
		max-width: min(
			95vw,
			max(800px, calc(var(--grid-cols, 10) * 45px + 200px))
		);
	}

	.cell {
		width: calc(min(800px, 95vw - 200px) / var(--grid-cols, 10));
		height: calc(min(800px, 95vw - 200px) / var(--grid-cols, 10));
		max-width: 45px;
		max-height: 45px;
		font-size: clamp(
			12px,
			calc(min(800px, 95vw - 200px) / var(--grid-cols, 10) * 0.4),
			20px
		);
	}
}

/* Very small screens */
@media (max-width: 360px) {
	.container {
		padding: 16px;
		margin: 8px;
		border-radius: 12px;
		max-width: calc(100vw - 16px);
	}

	h1 {
		font-size: 1.8rem;
	}

	.header-buttons {
		flex-direction: column;
		gap: 6px;
	}

	.instructions-btn,
	.kofi-btn,
	.homepage-btn {
		width: 100%;
		justify-content: center;
	}

	.mobile-stats-bar {
		padding: 10px 6px;
	}

	.stat-value {
		font-size: 0.8rem;
	}

	.cell {
		width: calc((100vw - 64px) / var(--grid-cols, 10));
		height: calc((100vw - 64px) / var(--grid-cols, 10));
		min-width: 18px;
		min-height: 18px;
		font-size: clamp(
			8px,
			calc((100vw - 64px) / var(--grid-cols, 10) * 0.35),
			14px
		);
	}
}
