:root {
		--primary-color: #3498db;
		--secondary-color: #2c3e50;
		--background-color: #f0f2f5;
		--container-bg: #ffffff;
		--text-color: #333;
		--correct-color: rgba(46, 204, 113, 0.7);
		--incorrect-color: rgba(231, 76, 60, 0.7);
		--shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
	}

	body {
		font-family: 'Poppins', sans-serif;
		background-color: var(--background-color);
		color: var(--text-color);
		margin: 0;
		padding: 20px;
		display: flex;
		justify-content: center;
		align-items: flex-start;
		min-height: 100vh;
	}

	.container {
		background-color: var(--container-bg);
		padding: 30px;
		border-radius: 12px;
		box-shadow: var(--shadow);
		width: 100%;
		max-width: 900px;
		text-align: center;
		box-sizing: border-box; /* Añadido para un mejor manejo del padding */
	}

	h1 {
		color: var(--secondary-color);
		margin-bottom: 10px;
		font-size: 2.2rem; /* Tamaño base */
	}

	.description {
		color: #666;
		margin-bottom: 30px;
		max-width: 600px;
		margin-left: auto;
		margin-right: auto;
	}

	/* --- Settings Form --- */
	#settings {
		display: flex;
		flex-direction: column;
		gap: 20px;
		margin-bottom: 30px;
	}

	.form-group {
		text-align: left;
	}

	.form-group label {
		font-weight: 600;
		display: block;
		margin-bottom: 8px;
		color: var(--secondary-color);
	}

	input[type="text"], select {
		width: 100%;
		padding: 12px;
		border-radius: 8px;
		border: 1px solid #ccc;
		font-size: 1rem;
		box-sizing: border-box;
		transition: border-color 0.3s, box-shadow 0.3s;
	}

	input[type="text"]:focus, select:focus {
		outline: none;
		border-color: var(--primary-color);
		box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
	}

	button {
		background-color: var(--primary-color);
		color: white;
		border: none;
		padding: 15px 20px;
		border-radius: 8px;
		font-size: 1.1rem;
		font-weight: 600;
		cursor: pointer;
		transition: background-color 0.3s, transform 0.2s;
	}

	button:hover {
		background-color: #2980b9;
		transform: translateY(-2px);
	}

	button:disabled {
		background-color: #bdc3c7;
		cursor: not-allowed;
		transform: none;
	}

	/* --- Game Area --- */
	#targetWordContainer {
		margin-bottom: 25px;
	}

	#targetWordContainer p {
		margin: 0;
		color: #555;
	}

	#targetWord {
		font-size: 2rem;
		font-weight: 700;
		color: var(--primary-color);
		margin: 5px 0;
		min-height: 48px; /* Evita que la página salte al cambiar de palabra */
	}

	/* --- CAMBIO RESPONSIVE 1: Grilla de imágenes fluida --- */
	#imageGrid {
		display: grid;
		/*
		  auto-fit: Crea tantas columnas como quepan.
		  minmax(200px, 1fr): Cada columna tendrá un mínimo de 200px y se expandirá para ocupar el espacio disponible.
		  Esto crea una grilla que se ajusta sola: 1 columna en móviles, 2 en tabletas y 3 en escritorio.
		*/
		grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
		gap: 20px;
	}

	/* --- CAMBIO RESPONSIVE 2: Contenedor de imagen flexible --- */
	.image-container {
		position: relative;
		display: flex;
		flex-direction: column;
		gap: 8px;
		align-items: center;
	}
	
	/* --- CAMBIO RESPONSIVE 3: Estilos de la imagen para que sea flexible --- */
	.grid-image {
		width: 100%; /* La imagen ocupa todo el ancho de su celda en la grilla */
		aspect-ratio: 1 / 1; /* Mantiene la proporción cuadrada */
		object-fit: cover; /* Asegura que la imagen cubra el área sin deformarse */
		border-radius: 8px;
		cursor: pointer;
		transition: transform 0.3s, box-shadow 0.3s;
		border: 3px solid transparent;
	}


	.grid-image:hover:not(.used) {
		transform: scale(1.05);
		box-shadow: 0 8px 20px rgba(0,0,0,0.2);
	}

	/* --- Image States --- */
	.grid-image.selected {
		border-color: var(--primary-color);
	}
	.grid-image.correct {
		box-shadow: 0 0 20px 7px var(--correct-color);
	}
	.grid-image.incorrect {
		box-shadow: 0 0 20px 7px var(--incorrect-color);
	}
	.grid-image.used {
		opacity: 0.5;
		cursor: not-allowed;
		filter: grayscale(80%);
	}

	/* --- Loader --- */
	#loader {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		gap: 20px;
	}

	#loader p {
		font-size: 1.1rem;
		font-weight: 600;
		color: var(--secondary-color);
	}

	.spinner {
		border: 8px solid #f3f3f3;
		border-top: 8px solid var(--primary-color);
		border-radius: 50%;
		width: 60px;
		height: 60px;
		animation: spin 1.5s linear infinite;
	}

	@keyframes spin {
		0% { transform: rotate(0deg); }
		100% { transform: rotate(360deg); }
	}

	/* --- Results Area --- */
	#resultsArea {
		padding: 40px;
	}
	#resultsArea h2 {
		font-size: 2.5rem;
		color: var(--secondary-color);
	}
	#resultsArea p {
		font-size: 1.5rem;
	}
	#resultsArea button {
		margin-top: 20px;
	}

	/* Helper Class */
	.hidden {
		display: none !important;
	}

	.regenerate-button {
		background-color: #7f8c8d;
		color: white;
		border: none;
		padding: 6px 12px;
		border-radius: 6px;
		font-size: 0.8rem;
		font-weight: 500;
		cursor: pointer;
		transition: background-color 0.3s, transform 0.2s;
		width: 80%;
		box-sizing: border-box;
	}

	.regenerate-button:hover {
		background-color: #2c3e50;
		transform: translateY(-1px);
	}

	.image-container.used .regenerate-button { display: none; }

	/* --- Estilos para la fase de edición --- */
	.edit-instructions {
		margin-bottom: 15px;
		color: #555;
		background-color: #f0f2f5;
		padding: 10px;
		border-radius: 8px;
	}

	#approveContainer { margin-bottom: 20px; }
	#approveButton { background-color: #27ae60; font-size: 1.2rem; }
	#approveButton:hover { background-color: #229954; }

	.edit-word-input {
		width: 100%;
		box-sizing: border-box;
		text-align: center;
		font-family: 'Poppins', sans-serif;
		font-size: 0.9rem;
		padding: 8px;
		border: 1px solid #ccc;
		border-radius: 6px;
		transition: all 0.3s;
	}

	.edit-word-input:focus {
		border-color: var(--primary-color);
		box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
		outline: none;
	}

	/* --- Control de estado (Edición vs. Juego) --- */
	.game-active .edit-word-input,
	.game-active .regenerate-button {
		pointer-events: none;
		background-color: #f8f9f9;
		color: #aab7b8;
		opacity: 0.7;
	}

	.image-container.editing .regenerate-button { display: none; }

	/* --- Estilos para los botones y cabecera del juego --- */
	.game-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 25px;
		padding: 0 10px; /* Padding reducido para móviles */
		flex-wrap: wrap; /* Permite que los elementos pasen a la siguiente línea si no caben */
		gap: 15px;
	}

	.game-header div { text-align: left; }
	.game-buttons { display: flex; gap: 10px; }
	#newThemeButton { background-color: #e67e22; font-size: 0.9rem; padding: 10px 15px; }
	#newThemeButton:hover { background-color: #d35400; }
	#downloadButton { background-color: #9b59b6; font-size: 0.9rem; padding: 10px 15px; }
	#downloadButton:hover { background-color: #8e44ad; }

	/* --- Footer --- */
	footer {
		width: 100%;
		max-width: 900px;
		margin: 40px auto 20px auto;
		text-align: center;
		padding: 20px;
		border-top: 1px solid #e0e0e0;
		box-sizing: border-box;
	}
	footer p { margin: 0; font-size: 0.9rem; color: #777; line-height: 1.5; }
	footer strong { color: #555; font-weight: 600; }

	/* --- CAMBIO RESPONSIVE 4: Media Query para pantallas pequeñas (móviles) --- */
	@media (max-width: 600px) {
		body {
			padding: 10px; /* Menos padding en el body */
		}
		
		.container {
			padding: 15px; /* Menos padding en el contenedor principal */
		}

		h1 {
			font-size: 1.8rem; /* Título más pequeño */
		}
		
		#targetWord {
			font-size: 1.5rem; /* Palabra a buscar más pequeña */
		}
		
		/* Apila la cabecera del juego en vertical */
		.game-header {
			flex-direction: column;
			align-items: center;
			gap: 15px;
		}
		
		.game-header div {
			text-align: center; /* Centra el texto "Encuentra la imagen para:" */
		}

		.game-buttons {
			justify-content: center; /* Centra los botones */
			width: 100%;
		}

		button, #approveButton {
			font-size: 1rem; /* Botones un poco más pequeños */
		}
		
		#resultsArea h2 { font-size: 2rem; }
		#resultsArea p { font-size: 1.2rem; }
	}