/* ===========================
   MisaLala Game - Modern CSS
   =========================== */

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

html {
	height: 100%;
	margin: 0;
	padding: 0;
	overflow-x: hidden;
	overflow-y: auto;
}

body {
	min-height: 100svh;
	margin: 0;
	padding: 0;
	overflow-x: hidden;
	overflow-y: auto;
	background-color: #eef3fb;
	background-image: url(../background.jpg);
	background-repeat: no-repeat;
	background-position: center;
	background-size: cover;
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
	color: #1f2d4d;
}

body.home-page {
	padding-top: 0;
	/* Keep content above the fixed footer on small screens (and iOS safe areas). */
	padding-bottom: calc(3.25rem + env(safe-area-inset-bottom));
}

body.game-page {
	display: flex;
	flex-direction: column;
	/* The app scrolls inside containers (e.g. game grid) instead of the whole page. */
	overflow-y: hidden;
}

button, input, select {
	font: inherit;
}

.game-header {
	flex-shrink: 0;
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 1rem;
	align-items: center;
	padding: 1rem 1.25rem;
	background: rgba(255, 255, 255, 0.96);
	backdrop-filter: blur(14px);
	border-bottom: 1px solid rgba(31, 45, 77, 0.08);
	z-index: 50;
}

.header-brand {
	display: flex;
	align-items: center;
	gap: 0.85rem;
}

.header-credit {
	font-size: 0.9rem;
	font-weight: 600;
	color: #5a6b8e;
	letter-spacing: 0.02em;
	white-space: nowrap;
	text-shadow: 0 0 8px rgba(90, 107, 142, 0.35);
	filter: blur(0.2px);
	opacity: 0.9;
}

.misalala-logo-text {
	display: inline-flex;
	align-items: center;
	gap: 0.75rem;
	font-size: 1.25rem;
	font-weight: 800;
	letter-spacing: 0.08em;
	text-decoration: none;
	color: #1f2d4d;
}

.favicon-logo {
	width: 2rem;
	height: 2rem;
	vertical-align: middle;
}

.level-badge {
	padding: 0.7rem 1rem;
	border-radius: 16px;
	background: #eef3ff;
	border: 1px solid rgba(24, 53, 104, 0.12);
}

.level-badge span {
	font-weight: 700;
	color: #183568;
}

.header-stats {
	display: grid;
	grid-template-columns: repeat(2, minmax(110px, 1fr));
	gap: 0.75rem;
}

.header-stats .stat {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	padding: 0.95rem 1rem;
	border-radius: 18px;
	background: #f6f8ff;
	border: 1px solid rgba(31, 45, 77, 0.08);
}

.header-stats .stat span {
	font-size: 0.8rem;
	color: #5a6b8e;
}

.header-stats .stat strong {
	font-size: 1.1rem;
	color: #183568;
}

.game-main {
	flex: 1;
	min-height: 0;
	width: 100%;
	display: flex;
	justify-content: center;
	align-items: stretch;
	padding: 0;
	overflow: hidden;
}

.game-container {
	position: relative;
	width: 100%;
	max-width: 980px;
	margin: 0 auto;
	padding: 1rem;
	display: flex;
	flex-direction: column;
	gap: 1rem;
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	justify-content: center;
	align-items: center;
}

.game-area {
	background: rgba(0, 0, 0, 0.2);
	border-radius: 28px;
	box-shadow: 0 28px 70px rgba(37, 57, 91, 0.08);
	padding: clamp(0.6rem, 2.2vw, 1rem);
	display: flex;
	justify-content: center;
	align-items: center;
	width: 100%;
	flex: 1;
	min-height: 0;
	overflow: auto;
}

.game-grid {
	width: 100%;
	max-width: 760px;
	display: grid;
	/* Smaller gaps on mobile so cards stay tappable. */
	gap: clamp(6px, 1.7vw, 13px);
	auto-rows: 1fr;
}

.game-card {
	width: 100%;
	aspect-ratio: 1 / 1;
	border-radius: 22px;
	background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
	overflow: hidden;
	box-shadow:
		0 18px 32px rgba(19, 38, 80, 0.05),
		0 10px 18px rgba(35, 59, 92, 0.08);
	cursor: pointer;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
	user-select: none;
	transition: transform 0.25s ease, box-shadow 0.25s ease;
	display: grid;
	place-items: center;
}

.game-card:hover:not(.matched):not(.flipped) {
	transform: translateY(-3px);
}

.game-card.flipped {
	transform: translateY(0);
}

.game-card.matched {
	opacity: 0.78;
	cursor: default;
}

.card-image {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.game-controls {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	padding: 0.75rem 1rem 1rem;
	background: #ffffff;
	border-radius: 24px;
	box-shadow: 0 18px 40px rgba(37, 57, 91, 0.08);
}

.game-status {
	min-height: 4.5rem;
	display: grid;
	place-items: center;
	text-align: center;
	font-size: 1.25rem;
	font-weight: 700;
	color: #1f2d4d;
}

.btn-play-again {
	display: none;
	width: 100%;
	padding: 0.95rem 1rem;
	border: none;
	border-radius: 16px;
	background-color: #1f2d4d;
	color: #ffffff;
	font-weight: 700;
	font-size: 1rem;
	cursor: pointer;
	transition: transform 0.2s ease, background-color 0.2s ease;
}

.btn-play-again:hover {
	background-color: #15213b;
	transform: translateY(-1px);
}

/* Game Controls Modal Styles
   =========================== */

.game-controls-overlay {
	display: none;
	position: absolute;
	inset: 0;
	padding: calc(1.5rem + env(safe-area-inset-top)) 1rem
		calc(1.5rem + env(safe-area-inset-bottom)) 1rem;
	background: rgba(0, 0, 0, 0.55);
	backdrop-filter: blur(3px);
	z-index: 1000;
	justify-content: center;
	align-items: center;
}

.game-controls-overlay.active {
	display: flex;
}

.game-controls-modal {
	background: white;
	border-radius: 16px;
	padding: 2rem;
	max-width: 400px;
	width: 90%;
	text-align: center;
	box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
	animation: modal-appear 0.3s ease-out;
	display: flex;
	flex-direction: column;
	gap: 1rem;
	align-items: center;
}

.game-footer {
	flex-shrink: 0;
	background: rgba(255, 255, 255, 0.98);
	border-top: 1px solid rgba(31, 45, 77, 0.08);
	padding: 0.9rem 1rem;
	text-align: center;
	font-size: 0.85rem;
	color: #5a6b8e;
	z-index: 40;
}

/* Keep header fixed on desktop screens. */
@media (min-width: 721px) {
	body.game-page {
		padding-top: 82px;
	}

	.game-header {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		width: 100%;
	}
}

.score-popup {
	position: fixed;
	bottom: 2rem;
	left: 50%;
	transform: translateX(-50%);
	background: rgba(24, 53, 104, 0.94);
	color: white;
	padding: 0.85rem 1.25rem;
	border-radius: 999px;
	font-size: 1.1rem;
	font-weight: 700;
	z-index: 1000;
	animation: slideUp 0.4s ease-out;
	pointer-events: none;
}

@keyframes slideUp {
	from {
		opacity: 0;
		transform: translate(-50%, 16px);
	}
	to {
		opacity: 1;
		transform: translate(-50%, 0);
	}
}

@media (max-width: 720px) {
	.game-header {
		/* Compact single-row header on mobile */
		grid-template-columns: 1fr auto;
		gap: 0.5rem;
		padding: 0.55rem 0.75rem;
		justify-items: start;
	}

	.header-brand {
		gap: 0.5rem;
		min-width: 0;
		justify-self: start;
	}

	.misalala-logo-text {
		font-size: 0.95rem;
		gap: 0.5rem;
		letter-spacing: 0.06em;
		white-space: nowrap;
	}

	.favicon-logo {
		width: 1.5rem;
		height: 1.5rem;
	}

	.level-badge {
		padding: 0.4rem 0.6rem;
		border-radius: 12px;
	}

	.header-stats {
		/* Tight horizontal chips */
		display: flex;
		gap: 0.5rem;
		justify-content: flex-end;
	}

	.header-stats .stat {
		flex-direction: row;
		align-items: baseline;
		gap: 0.4rem;
		padding: 0.45rem 0.6rem;
		border-radius: 14px;
	}

	.header-stats .stat span {
		font-size: 0.75rem;
	}

	.header-stats .stat strong {
		font-size: 0.95rem;
	}

	.game-container {
		padding: 0.85rem 0.9rem;
	}
	.game-status {
		font-size: 1.05rem;
	}

	/* Keep centered-header grid mapping valid on mobile layout. */
	.header-brand {
		grid-column: 1;
		justify-content: flex-start;
		width: 100%;
	}

	.header-stats {
		grid-column: 2;
		justify-self: end;
	}

	.header-credit {
		display: none;
	}
}

@media (max-width: 520px) {
	.text-panel {
		width: 90%;
	}

	.game-header {
		gap: 0.45rem;
		padding: 0.5rem 0.65rem;
	}
	.header-stats {
		gap: 0.4rem;
	}
	.header-stats .stat {
		padding: 0.4rem 0.55rem;
	}
	/* Hide labels to save horizontal/vertical space */
	.header-stats .stat span {
		display: none;
	}
	.game-container {
		padding: 0.75rem 0.85rem;
	}
	.game-grid {
		gap: clamp(6px, 2.1vw, 10px);
	}
	.game-card {
		border-radius: 18px;
	}
	.btn-play-again {
		padding: 0.85rem 0.9rem;
		font-size: 0.95rem;
	}
}

/* Disable hover-only affordances on touch devices. */
@media (hover: none) {
	.game-card:hover:not(.matched):not(.flipped) {
		transform: none;
	}
}

/* Respect reduced motion preferences. */
@media (prefers-reduced-motion: reduce) {
	* {
		animation-duration: 0.001ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.001ms !important;
		scroll-behavior: auto !important;
	}
}

/* ===========================
   Home Page Styles
   =========================== */

.home-header {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 50;
	width: 100%;
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 1rem;
	align-items: center;
	padding: 1rem 1.25rem;
	background: rgba(255, 255, 255, 0.96);
	backdrop-filter: blur(14px);
	border-bottom: 1px solid rgba(31, 45, 77, 0.08);
}

.home-container {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	min-height: calc(100vh - 12rem);
	padding: 2rem 1rem 1rem;
}

.text-panel {
	width: min(100%, 560px);
	background-color: rgba(255, 255, 255, 0.95);
	padding: 2rem 2rem 2.5rem;
	border-radius: 20px;
	box-shadow: 0 24px 50px rgba(0, 0, 0, 0.08);
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 1.5rem;
}

.home-content {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0;
}

.play-button-link {
	display: inline-block;
	text-decoration: none;
}

.play-button-text {
	padding: 15px 40px;
	font-size: 18px;
	font-weight: bold;
	color: #fff;
	background-color: #183568;
	border: none;
	border-radius: 8px;
	cursor: pointer;
	transition: background-color 0.2s, transform 0.2s;
	font-family: Baskerville, "Palatino Linotype", Palatino, "Century Schoolbook L", "Times New Roman", serif;
}

.play-button-text:hover {
	background-color: #0f1f3d;
	transform: scale(1.05);
}

.play-button-text:active {
	transform: scale(0.98);
}

.level-selector {
	display: flex;
	flex-direction: column;
	gap: 12px;
	justify-content: center;
	width: 100%;
}

.level-link {
	display: flex;
	flex-direction: row;
	align-items: center;
	gap: 20px;
	padding: 15px 20px;
	border: 1px solid #183568;
	border-radius: 8px;
	text-decoration: none;
	transition: all 0.3s ease;
	background-color: #f9fafc;
}

.level-link:hover {
	border-color: #0f1f3d;
	background-color: #fff;
	box-shadow: 0 4px 12px rgba(24, 53, 104, 0.15);
	transform: translateY(-2px);
}

.level-link img {
	width: 80px;
	height: 80px;
	border-radius: 6px;
	object-fit: cover;
	transition: transform 0.3s ease;
	flex-shrink: 0;
}

.level-link:hover img {
	transform: scale(1.08);
}

.level-link span {
	font-weight: 600;
	color: #183568;
	font-size: 16px;
	white-space: nowrap;
	flex-grow: 1;
}

.home-footer {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	z-index: 40;
	width: 100%;
	background: rgba(255, 255, 255, 0.98);
	border-top: 1px solid rgba(31, 45, 77, 0.08);
	padding: 0.9rem 1rem;
	padding-bottom: calc(0.9rem + env(safe-area-inset-bottom));
	text-align: center;
	font-size: 0.85rem;
	color: #5a6b8e;
}

.level-link.disabled {
	opacity: 0.3;
	pointer-events: none;
}

/* ===========================
   End Screen Styles
   =========================== */

.end-screen-overlay {
	display: none;
	position: fixed;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.7);
	backdrop-filter: blur(4px);
	z-index: 1000;
	justify-content: center;
	align-items: center;
}

.end-screen-overlay.active {
	display: flex;
}

.end-screen-modal {
	background: white;
	border-radius: 16px;
	padding: 2rem;
	max-width: 400px;
	width: 90%;
	text-align: center;
	box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
	animation: modal-appear 0.3s ease-out;
}

@keyframes modal-appear {
	from {
		opacity: 0;
		transform: scale(0.9) translateY(-20px);
	}
	to {
		opacity: 1;
		transform: scale(1) translateY(0);
	}
}

.end-screen-modal h1 {
	font-size: 2.5rem;
	margin-bottom: 1rem;
	color: #183568;
}

.end-screen-modal p {
	font-size: 1.2rem;
	color: #5a6b8e;
	margin: 0.5rem 0;
}

/* ===========================
   HUD colors & centered header
   =========================== */
#timer {
	color: #e53935;
}

#score {
	color: #0000FF;
}

@media (min-width: 721px) {
	/* Center title + level badge within the 3-col header */
	.game-header {
		grid-template-columns: 1fr auto 1fr;
	}

	.header-brand {
		grid-column: 2;
		justify-content: center;
		width: 100%;
	}

	.header-stats {
		grid-column: 3;
		justify-self: end;
	}

	.header-credit {
		grid-column: 1;
		justify-self: start;
	}
}
