/* Variables: colors, sizes and fonts, used everywhere with var() */
:root {
	/* Page and cards */
	--bg: #fbfaf6;
	--surface: #ffffff;
	--line: #e2ded2;
	--footer-bg: #eef5ea;

	/* Pond scene */
	--pond: #cfe8e6;
	--pond-deep: #afd6d3;
	--lily: #7dba6a;

	/* Characters */
	--frog: #58ae4a;
	--frog-dark: #2f7a35;
	--fly: #2a2926;
	--tongue: #e8607a;

	/* Text */
	--fg: #23211c;
	--muted: #6b675c;

	/* Sizes: the frog is always this many flies wide */
	--fly-size: 6vw;
	--frog-to-fly: 2.75;

	/* Fonts */
	--display: "Baloo 2", system-ui, sans-serif;
	--body: "Nunito Sans", system-ui, sans-serif;
}

@keyframes fly-across {
	0% {
		left: -5%;
		top: var(--start-y);
	}

	25% {
		left: 25%;
		top: var(--middle-y);
	}

	50% {
		left: 50%;
		top: var(--centre-y);
	}

	75% {
		left: 75%;
		top: var(--near-end-y);
	}

	100% {
		left: 105%;
		top: var(--end-y);
	}
}

.fly {
	position: absolute;
	height: var(--fly-size);
	animation-name: fly-across;
	animation-duration: var(--duration);
	animation-delay: var(--delay);
	animation-iteration-count: infinite;
	animation-timing-function: linear;
}

/* ==========================================
   Base styles that use the variables
   ========================================== */
/* Page intro: title and rules */
.intro {
	max-width: 520px;
	margin: 0 auto;
	padding: 48px 16px 24px;
	text-align: center;
}

.intro h1 {
	margin: 0 0 8px;
	font-family: var(--display);
	font-weight: 700;
	font-size: clamp(36px, 6vw, 56px);
	line-height: 1.1;
}

.lede {
	margin: 0;
	color: var(--muted);
	font-size: 18px;
	line-height: 1.6;
}

html {
	height: 100%;
}

body {
	background: var(--bg);
	color: var(--fg);
	font-family: var(--body);
	margin: 0;
	display: flex;
	flex-direction: column;
	height: auto;
	min-height: 100vh;
	min-height: 100dvh;
}

/* Game container: stats bar and pond */
#game-container {
	margin: 0 auto 16px;
	padding: 20px;
	background-color: var(--surface);
	border: 1px solid var(--line);
	border-radius: 22px;
}

#stats {
	display: flex;
	justify-content: space-between;
	color: var(--muted);
}

#stats span {
	font-weight: bold;
	color: var(--fg);
}

#pond {
	position: relative;
	overflow: hidden;
	background-color: var(--pond);
	border-radius: 16px;
	user-select: none;
	-webkit-user-select: none;
	/* The frog's lily:pond background, bottom center */
	background-image: url("images/lily-pad.svg");
	background-repeat: no-repeat;
	background-position: left 50% bottom -25px;
	background-size: 25%;
}

/* Lilies: shared property */
.lily {
	position: absolute;
}

/* Each lily's own position */
#lily-left {
	width: 15%;
	left: 3%;
	bottom: 18%;
}

#lily-right {
	width: 12%;
	right: 5%;
	bottom: 40%;
}

/* Ripples */
.ripple {
	position: absolute;
	border: 2px solid var(--pond-deep);
	border-radius: 50%;
}

#ripple-1 {
	left: 21%;
	bottom: 66%;
	width: 18%;
	height: 11%;
}

#ripple-2 {
	left: 61%;
	bottom: 55%;
	width: 14%;
	height: 8%;
}

#ripple-3 {
	left: 30%;
	bottom: 29%;
	width: 23%;
	height: 14%;
}

#frog {
	position: absolute;
	bottom: 0;
	/* Center horizontally at any screen size.
	   (margin auto keeps offsetLeft accurate for the tongue in script.js) */
	left: 0;
	right: 0;
	margin: 0 auto;
	/* Soft white edge, so every frog color stands out from the lily */
	filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 0 1.5px #fff);
	/* Grow with the pond, but never too tiny or too huge */
	width: calc(var(--fly-size) * var(--frog-to-fly) + 2px);
}

#tongue {
	position: absolute;
	height: 8px;
	width: 0;
	background-color: var(--tongue);
	border-radius: 999px;
	transform-origin: left center;
	transform: translateY(-50%) rotate(var(--angle, 0rad)) scaleX(0);
	transition: transform 0.3s ease-in-out;
	z-index: 3;
	pointer-events: none;
}

#tongue.tongue-out {
	transform: translateY(-50%) rotate(var(--angle, 0rad)) scaleX(1);
}

/* ==========================================
   Accessibility
   ========================================== */

/* Hidden on screen but still read by screen readers */
.visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* Clear focus ring for keyboard users */
#pond:focus-visible,
#start-button:focus-visible,
#play-again:focus-visible {
	outline: 3px solid var(--frog-dark);
	outline-offset: 3px;
}

/* Aim marker: a ring that keyboard players move with the arrow keys */
#aim {
	display: none;
	position: absolute;
	width: 28px;
	height: 28px;
	transform: translate(-50%, -50%);
	border: 3px solid var(--frog-dark);
	border-radius: 50%;
	box-shadow: 0 0 0 2px var(--surface);
	pointer-events: none;
	z-index: 3;
}

/* Only show it while the pond has keyboard focus */
#pond:focus-visible #aim {
	display: block;
}

/* Less motion if the device asks for it */
@media (prefers-reduced-motion: reduce) {
	#tongue {
		transition-duration: 0.1s;
	}
}

/* Welcome screen: covers the whole pond */
#welcome-screen {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
	z-index: 1;
	cursor: pointer;
}

/* Hidden welcome screen, class added by JavaScript on click */
#welcome-screen.hidden {
	display: none;
}

/* The white box in the middle */
.panel {
	padding: 24px 48px;
	background-color: var(--surface);
	border-radius: 16px;
	text-align: center;
}

.panel h2 {
	font-family: var(--display);
	margin: 0;
}

/* Start & play again buttons */
#start-button,
#play-again {
	margin-top: 12px;
	min-height: 44px; /* big enough to tap easily */
	padding: 10px 28px;
	border: none;
	border-radius: 12px;
	background-color: var(--fg);
	color: var(--surface);
	font-family: var(--body);
	font-size: 16px;
	font-weight: 700;
	cursor: pointer;
}

/* Footer: team names */
.site-footer {
	margin-top: auto;
	padding: 24px 16px 32px;
	border-top: 1px solid var(--line);
	background-color: var(--footer-bg);
	text-align: center;
	color: var(--muted);
}

.footer-title {
	margin: 0 0 8px;
	font-family: var(--display);
	font-weight: 700;
	font-size: 18px;
	color: var(--fg);
}

.team {
	list-style: none;
	padding: 0;
	margin: 0;
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 4px 16px;
	font-size: 14px;
}

.footer-note {
	margin: 12px 0 0;
	font-size: 13px;
}

/* End screen: covers the whole pond, same idea as the welcome screen */
#end-screen {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
	z-index: 1;
}

/* Hidden end screen, class added or removed by JavaScript */
#end-screen.hidden {
	display: none;
}

/* ==========================================
   Responsive
   ========================================== */

/* Phones: 520px wide or less */
@media (max-width: 520px) {
	#game-container {
		width: auto; /* fill the phone's width */
		margin: auto 16px 16px; /* 16px from the edges; "auto" on top centers the game vertically */
	}

	#pond {
		height: 240px; /* a fixed, shorter pond */
		background-position: left 50% bottom -8px; /* smaller lily, so push it down less */
	}
	.intro {
		padding-top: 80px; /* more space above the title */
	}
	.lede {
		font-size: 16px; /* slightly smaller directions text */
	}

	.panel {
		padding: 24px 32px; /* less side padding than desktop, so it fits the small pond */
	}
}

/* Tablets and desktops: wider than 520px */
@media (min-width: 521px) {
	:root {
		--fly-size: 2vw; /* flies (and the frog) are 2% of the window width */
	}
	#game-container {
		width: 40vw; /* the game is 40% of the window width */
	}
	#pond {
		height: 20vw; /* half as tall as it is wide */
	}
}

/* Big screens: 2000px wide or more */
@media (min-width: 2000px) {
	:root {
		--fly-size: 1.5vw; /* a bit smaller, so flies don't get huge */
	}
	#game-container {
		width: 50vw; /* a bit wider */
	}
	#pond {
		height: 700px; /* a fixed height, so it doesn't get too tall */
	}
}
