/* ==========================================================================
   QuickMaths — playful, child-friendly stylesheet
   ========================================================================== */
/* 
@font-face {
	font-family: 'Playfair';
	src: url('assets/fonts/Playfair_Display/PlayfairDisplay-VariableFont_wght.ttf');
	font-display: swap;
} */

/* ---------- Design tokens ------------------------------------------------- */
:root {
	--qm-bg:        #A5D6A7;
	--qm-bg-soft:  #FFF8E1;
	--qm-primary:  #7E0000;          /* maroon  */
	--qm-accent:   #FFC45F;          /* honey   */
	--qm-pop:      #FF4500;          /* orange  */
	--qm-good:     #76D275;          /* green   */
	--qm-bad:      #FF6B6B;          /* coral   */
	--qm-blue:     #6FA8FF;          /* sky     */
	--qm-ink:      #2B2B2B;
	--qm-radius:   16px;
	--qm-radius-l: 24px;
	--qm-shadow:   0 4px 0 rgba(0, 0, 0, 0.18);
	--qm-shadow-s: 0 2px 0 rgba(0, 0, 0, 0.18);
	--qm-tap:      48px;             /* min touch target */
}

/* ---------- Base reset ---------------------------------------------------- */
*,
*::before,
*::after { box-sizing: border-box; }

html, body {
	margin: 0;
	padding: 0;
	width: 100%;
	height: 100dvh;
	font-family: 'Playfair', 'Helvetica', sans-serif;
	background-color: var(--qm-bg);
	color: var(--qm-ink);
	-webkit-font-smoothing: antialiased;
}

body {
	display: flex;
	flex-direction: column;
	align-items: center;
	overflow: hidden;
}

img#bg-img {
	position: fixed;
	inset: 0;
	width: 100vw;
	height: 100vh;
	object-fit: cover;
	opacity: 0.22;
	filter: saturate(1.6) brightness(1.4);
	z-index: -1;
	pointer-events: none;
}

main {
	width: 100%;
	max-width: 560px;
	margin: 0 auto;
	padding: 0;
	height: 100dvh;
}

/* ---------- Section layout ----------------------------------------------- */
main > section {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 1.25rem;
	height: 100dvh;
	padding: 1rem;
	text-align: center;
	
	opacity: 1;
	transition: opacity 0.3s ease-in-out;
}

body.loading > main > section { opacity: 0; }
#configScreen{
	gap:15px;
}
#configScreen,
#resultScreen { display: none; }

header img { max-width: 90%; height: auto; }

h2 {
	font-size: 1.8rem;
	color: var(--qm-primary);
	margin: 0.25rem 0;
}

h3 { color: var(--qm-primary); margin: 0.25rem 0; }

p, li { font-size: 1.05rem; line-height: 1.45; }

ul {
	list-style: square inside;
	padding: 0;
	text-align: left;
	max-width: 90%;
}

li + li { margin-top: 0.4rem; }

kbd {
	background: var(--qm-ink);
	color: #fff;
	padding: 0.2rem 0.45rem;
	border-radius: 6px;
	font-size: 0.9rem;
}

strong { color: var(--qm-primary); }

/* ---------- Form controls ------------------------------------------------ */
label {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.75rem;
	width: 100%;
	max-width: 480px;
	background: var(--qm-bg-soft);
	border-radius: var(--qm-radius);
	padding: 0.6rem 0.9rem;
	box-shadow: var(--qm-shadow-s);
	margin:auto;
}

label > strong { text-align: left; flex: 1; }

input[type="number"] {
	width: 80px;
	padding: 0.45rem;
	font-weight: 700;
	font-size: 1rem;
	text-align: center;
	color: var(--qm-primary);
	background: var(--qm-accent);
	border: 3px solid var(--qm-primary);
	border-radius: 12px;
	outline: none;
}

input[type="number"]:focus { background: #fff; }

input[type="checkbox"] {
	-webkit-appearance: none;
	appearance: none;
	width: 28px;
	height: 28px;
	border: 3px solid var(--qm-primary);
	border-radius: 8px;
	background: var(--qm-primary);
	cursor: pointer;
	transition: background 0.15s ease;
}

input[type="checkbox"]:checked {
	background: var(--qm-accent);
	box-shadow: inset 0 0 0 3px var(--qm-primary);
}

.fieldset {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 0.6rem;
	width: 100%;
	max-width: 480px;
	background: var(--qm-bg-soft);
	border-radius: var(--qm-radius);
	padding: 0.75rem;
	box-shadow: var(--qm-shadow-s);
}

.fieldset legend { width: 100%; }
.fieldset label {
	flex: 0 0 auto;
	width: auto;
	background: transparent;
	box-shadow: none;
	padding: 0.3rem;
	gap: 0.4rem;
}

span.operation {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	font-size: 1.6rem;
	font-weight: 700;
	color: var(--qm-primary);
	background: #fff;
	border-radius: 12px;
	box-shadow: var(--qm-shadow-s);
}

/* ---------- Buttons ------------------------------------------------------ */
button { cursor: pointer; }

.interactable-button {
	background: transparent;
	border: none;
	padding: 0;
	transition: transform 0.12s ease;
}

.interactable-button > img {
	width: 140px;
	height: 70px;
	object-fit: contain;
}

.interactable-button:hover,
.interactable-button:focus-visible { transform: scale(1.08); outline: none; }
.interactable-button:active { transform: scale(0.96); }

/* ---------- Game screen -------------------------------------------------- */
#gameScreen {
	display: none;
	flex-direction: column;
	gap: 1rem;
	font-family: 'Helvetica', sans-serif;
}

#gameScreenInfo {
	display: flex;
	justify-content: space-between;
	align-items: center;
	width: 100%;
	max-width: 480px;
	background: var(--qm-bg-soft);
	border-radius: var(--qm-radius);
	padding: 0.6rem 1rem;
	box-shadow: var(--qm-shadow-s);
}

#questionCounter { margin: 0; font-size: 1.1rem; }

#timer {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

#timeLeft {
	font-size: 2rem;
	font-weight: 900;
	color: var(--qm-pop);
}

#questionText {
	font-size: 3.4rem;
	font-weight: 900;
	color: var(--qm-pop);
	letter-spacing: 2px;
	text-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
	margin: 0.5rem 0;
}

#answerInput {
	width: 180px;
	padding: 0.6rem;
	font-size: 2rem;
	font-weight: 700;
	text-align: center;
	color: var(--qm-pop);
	background: #fff;
	border: 3px solid var(--qm-primary);
	border-radius: var(--qm-radius);
	outline: none;
}

#answerInput:focus { border-color: var(--qm-pop); }

#feedback {
	min-height: 1.6rem;
	font-size: 1.2rem;
	font-weight: 700;
	color: var(--qm-primary);
}

/* ---------- On-screen keypad -------------------------------------------- */
#keypad {
	display: none;
	width: 100%;
	max-width: 360px;
	margin-top: 0.5rem;
}

#keypad.touch { display: block; }

#keypad-keys {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.keypad-keys-row {
	display: flex;
	gap: 8px;
	justify-content: center;
}

.key {
	flex: 1;
	min-width: var(--qm-tap);
	min-height: 52px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.6rem;
	font-weight: 900;
	color: var(--qm-primary);
	background: #fff;
	border-radius: var(--qm-radius);
	box-shadow: var(--qm-shadow);
	cursor: pointer;
	user-select: none;
	-webkit-user-select: none;
	-webkit-tap-highlight-color: transparent;
	transition: transform 0.08s ease, background 0.1s ease;
}

.key:hover  { background: var(--qm-blue); color: #fff; }
.key:active,
.key.pressed {
	transform: translateY(2px);
	box-shadow: var(--qm-shadow-s);
	background: var(--qm-accent);
}

.key#enter      { background: var(--qm-good); color: #fff; }
.key#backspace  { background: var(--qm-bad);  color: #fff; }
.key#backspace img { width: 28px; height: 28px; background: transparent; }

/* ---------- Result screen ------------------------------------------------ */
#resultScreen {
	overflow-y: auto;
}

#summaryTable {
	width: 100%;
	max-width: 540px;
	border-collapse: collapse;
	background: var(--qm-bg-soft);
	border-radius: var(--qm-radius);
	overflow: hidden;
	box-shadow: var(--qm-shadow-s);
	font-size: 0.9rem;
}

#summaryTable th,
#summaryTable td {
	padding: 0.5rem;
	border: 1px solid rgba(0, 0, 0, 0.08);
	text-align: center;
}

#summaryTable th { background: var(--qm-primary); color: #fff; }
#summaryTable tr:nth-child(even) td { background: rgba(255, 255, 255, 0.5); }

/* ---------- Loading screen ----------------------------------------------- */
#loading-screen {
	position: fixed;
	inset: 0;
	background: var(--qm-bg);
	display: none;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	color: #fff;
	z-index: 999;
}

#loading-screen.loading { display: flex; }

#loading-screen .loader {
	width: 60px;
	height: 60px;
	border: 6px solid rgba(255, 255, 255, 0.4);
	border-top-color: var(--qm-primary);
	border-radius: 50%;
	animation: spin 1s linear infinite;
}

#loading-screen p {
	margin-top: 0.75rem;
	color: var(--qm-primary);
	font-weight: 700;
}

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

/* ---------- Listening indicator ----------------------------------------- */
.listening #answerInput {
	border-color: var(--qm-good);
	box-shadow: 0 0 0 4px rgba(118, 210, 117, 0.35);
	animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
	0%, 100% { box-shadow: 0 0 0 4px rgba(118, 210, 117, 0.35); }
	50%      { box-shadow: 0 0 0 10px rgba(118, 210, 117, 0.15); }
}

/* ---------- Responsive --------------------------------------------------- */
@media (max-width: 480px) {
	#questionText  { font-size: 2.6rem; }
	#answerInput   { width: 140px; font-size: 1.6rem; }
	.interactable-button > img { width: 120px; height: 60px; }
	label { padding: 0.5rem 0.7rem; }
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		transition-duration: 0.01ms !important;
	}
}
