:root {
	--bg: #f7f5f0;
	--paper: #fffef9;
	--ink: #2a2520;
	--ink-light: #6b6460;
	--marked: #f4c842;
	--marked-stroke: #e0a800;
	--bingo-line: #e84545;
	--accent-blue: #4a90d9;
	--dot-color: #d0ccc5;
	--grid-gap: 7px;
	--border-radius: 6px;
}

html.dark {
	--bg: #1a1814;
	--paper: #23211c;
	--ink: #e8e4da;
	--ink-light: #9a9488;
	--marked: #c9960a;
	--marked-stroke: #f4c842;
	--bingo-line: #e84545;
	--accent-blue: #5ba3e8;
	--dot-color: #2e2b24;
}

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

body,
.cell,
.btn-reset,
.btn-close-win,
.bingo-letter,
#win-overlay,
.win-box {
	transition:
		background-color 0.3s ease,
		border-color 0.3s ease,
		color 0.3s ease,
		box-shadow 0.3s ease;
}

body {
	background-color: var(--bg);
	background-image: radial-gradient(
		circle,
		var(--dot-color) 1px,
		transparent 1px
	);
	background-size: 28px 28px;
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
	padding: 36px 16px 60px;
	font-family: "Caveat", cursive;
}

.doodle-bg {
	position: fixed;
	inset: 0;
	pointer-events: none;
	z-index: 0;
	overflow: hidden;
	width: 100%;
	height: 100%;
}

header {
	position: relative;
	z-index: 10;
	text-align: center;
	margin-bottom: 24px;
}

.title {
	font-family: "Caveat Brush", cursive;
	font-size: clamp(3rem, 9vw, 5.5rem);
	color: var(--ink);
	letter-spacing: 2px;
	line-height: 1;
	display: inline-block;
}

.title-wrap {
	position: relative;
	display: inline-block;
}

.title-underline {
	display: block;
	width: 110%;
	margin-left: -5%;
	margin-top: -8px;
}

.subtitle {
	color: var(--ink-light);
	font-size: 1.15rem;
	margin-top: 4px;
}

.btn-reset {
	margin-top: 14px;
	padding: 8px 24px;
	background: var(--paper);
	border: 2.5px solid var(--ink);
	border-radius: 100px;
	font-family: "Caveat", cursive;
	font-size: 1.05rem;
	font-weight: 600;
	color: var(--ink);
	cursor: pointer;
	box-shadow: 3px 3px 0 var(--ink);
	transition:
		transform 0.12s,
		box-shadow 0.12s;
}

.btn-reset:hover {
	transform: translate(-1px, -1px);
	box-shadow: 4px 4px 0 var(--ink);
}

.btn-reset:active {
	transform: translate(2px, 2px);
	box-shadow: 1px 1px 0 var(--ink);
}

.bingo-letters {
	display: grid;
	gap: var(--grid-gap);
	margin-bottom: 4px;
	position: relative;
	z-index: 10;
}

.bingo-letter {
	width: clamp(60px, 13.5vw, 108px);
	height: 38px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: "Caveat Brush", cursive;
	font-size: 1.5rem;
	color: var(--ink);
	border: 2.5px solid var(--ink);
	border-bottom: none;
	border-radius: 6px 6px 0 0;
	background: var(--paper);
}

.grid {
	display: grid;
	grid-template-columns: repeat(5, clamp(60px, 13.5vw, 108px));
	grid-template-rows: repeat(5, clamp(60px, 13.5vw, 108px));
	gap: var(--grid-gap);
	position: relative;
	z-index: 10;
	background: var(--ink);
	border: 2.5px solid var(--ink);
	border-radius: 10px;
	padding: var(--grid-gap);
}

.cell {
	background: var(--paper);
	border: 2px solid var(--ink);
	border-radius: var(--border-radius);
	display: flex;
	align-items: center;
	justify-content: center;
	text-align: center;
	padding: 6px;
	cursor: pointer;
	font-family: "Caveat", cursive;
	font-size: var(--fit-font-size, clamp(0.7rem, 1.5vw, 0.9rem));
	font-weight: 600;
	color: var(--ink);
	line-height: 1.25;
	overflow-wrap: anywhere;
	word-break: break-word;
	hyphens: auto;
	overflow: hidden;
	transition:
		transform 0.12s ease,
		background 0.12s;
	user-select: none;
	position: relative;
	touch-action: manipulation;
}

.cell.text-long {
	font-size: clamp(0.62rem, 1.2vw, 0.8rem);
	line-height: 1.18;
	padding: 4px;
}

.cell.text-very-long {
	font-size: clamp(0.54rem, 1vw, 0.72rem);
	line-height: 1.1;
	padding: 3px;
}

@media (hover: hover) and (pointer: fine) {
	.cell:hover {
		transform: scale(1.05) rotate(45deg);
		background: #aaa;
	}
}

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

.cell.marked {
	background: var(--marked);
	border-color: var(--marked-stroke);
	animation: markWobble 0.3s ease;
}

.cell.marked::after {
	content: "";
	position: absolute;
	inset: 5px;
	border: 2px solid var(--ink);
	border-radius: 3px;
	pointer-events: none;
}

@keyframes markWobble {
	0% {
		transform: rotate(-3deg) scale(0.88);
	}

	40% {
		transform: rotate(2deg) scale(1.08);
	}

	70% {
		transform: rotate(-1deg) scale(0.97);
	}

	100% {
		transform: rotate(0deg) scale(1);
	}
}

.cell.bingo-line {
	border-color: var(--bingo-line);
	border-width: 2.5px;
	box-shadow: 0 0 0 2px var(--bingo-line);
}

.cell.marked.bingo-line {
	background: #ffb347;
}

.cell.free-space {
	cursor: default;
	background: #e8f4fd;
	border-style: dashed;
	border-color: var(--accent-blue);
	color: var(--accent-blue);
	font-size: 0.75rem;
}

.cell.free-space::after {
	display: none;
}

.status-bar {
	position: relative;
	z-index: 10;
	margin-top: 18px;
	color: var(--ink-light);
	font-size: 1.05rem;
	display: flex;
	gap: 24px;
}

.status-count {
	color: var(--ink);
	font-weight: 700;
}

/* Win Overlay */
#win-overlay {
	position: fixed;
	inset: 0;
	z-index: 1000;
	display: none;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	background: rgba(247, 245, 240, 0.88);
	backdrop-filter: blur(3px);
}

#win-overlay.active {
	display: flex;
	animation: overlayIn 0.3s ease;
}

@keyframes overlayIn {
	from {
		opacity: 0;
	}

	to {
		opacity: 1;
	}
}

.win-box {
	background: var(--paper);
	border: 3px solid var(--ink);
	border-radius: 16px;
	padding: 44px 56px;
	text-align: center;
	box-shadow: 6px 6px 0 var(--ink);
	animation: winBoxPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes winBoxPop {
	0% {
		transform: scale(0.6) rotate(-4deg);
		opacity: 0;
	}

	100% {
		transform: scale(1) rotate(0deg);
		opacity: 1;
	}
}

.win-emoji {
	font-size: 4rem;
	display: block;
	margin-bottom: 12px;
	animation: emojiJump 0.6s ease 0.2s both;
}

@keyframes emojiJump {
	0% {
		transform: translateY(20px) scale(0);
		opacity: 0;
	}

	60% {
		transform: translateY(-10px) scale(1.15);
		opacity: 1;
	}

	100% {
		transform: translateY(0) scale(1);
	}
}

.win-title {
	font-family: "Caveat Brush", cursive;
	font-size: clamp(3rem, 8vw, 4.5rem);
	color: var(--ink);
	letter-spacing: 4px;
}

.win-squiggle {
	width: 90%;
	margin: 4px auto 0;
	display: block;
}

.win-sub {
	color: var(--ink-light);
	font-size: 1.2rem;
	margin-top: 10px;
}

.btn-close-win {
	margin-top: 28px;
	padding: 10px 32px;
	background: var(--marked);
	border: 2.5px solid var(--ink);
	border-radius: 100px;
	font-family: "Caveat", cursive;
	font-size: 1.1rem;
	font-weight: 700;
	color: var(--ink);
	cursor: pointer;
	box-shadow: 3px 3px 0 var(--ink);
	transition: all 0.12s;
}

.btn-close-win:hover {
	transform: translate(-1px, -1px);
	box-shadow: 4px 4px 0 var(--ink);
}

.btn-close-win:active {
	transform: translate(2px, 2px);
	box-shadow: 1px 1px 0 var(--ink);
}

.btn-theme {
	position: fixed;
	top: 18px;
	right: 20px;
	z-index: 200;
	width: 42px;
	height: 42px;
	border-radius: 50%;
	border: 2.5px solid var(--ink);
	background: var(--paper);
	font-size: 1.2rem;
	cursor: pointer;
	box-shadow: 2px 2px 0 var(--ink);
	transition:
		transform 0.15s,
		box-shadow 0.15s;
	display: flex;
	align-items: center;
	justify-content: center;
	line-height: 1;
}

.btn-theme:hover {
	transform: translate(-1px, -1px) rotate(20deg);
	box-shadow: 3px 3px 0 var(--ink);
}

.btn-theme:active {
	transform: translate(1px, 1px);
	box-shadow: 1px 1px 0 var(--ink);
}

.confetti-piece {
	position: fixed;
	top: -30px;
	z-index: 1100;
	pointer-events: none;
	animation: confettiFall linear forwards;
	font-size: 1.2rem;
	opacity: 0.85;
}

@keyframes confettiFall {
	0% {
		transform: translateY(0) rotate(0deg);
		opacity: 0.85;
	}

	100% {
		transform: translateY(110vh) rotate(540deg);
		opacity: 0;
	}
}

.cookie-popup {
	position: fixed;
	inset: 0;
	z-index: 1600;
	display: none;
	align-items: center;
	justify-content: center;
	background: rgba(18, 15, 12, 0.62);
	backdrop-filter: blur(4px);
	padding: 20px;
}

.cookie-popup.active {
	display: flex;
}

.cookie-box {
	width: min(580px, 100%);
	background: var(--paper);
	border: 3px solid var(--ink);
	border-radius: 14px;
	box-shadow: 8px 8px 0 var(--ink);
	padding: 24px 22px;
	position: relative;
	z-index: 2;
}

.cookie-box h2 {
	font-family: "Caveat Brush", cursive;
	font-size: clamp(2rem, 7vw, 2.8rem);
	line-height: 1;
	color: var(--ink);
	margin-bottom: 10px;
}

.cookie-box p {
	font-size: 1.12rem;
	line-height: 1.28;
	color: var(--ink);
	margin-bottom: 16px;
}

.btn-cookie-accept {
	padding: 10px 18px;
	background: var(--marked);
	border: 2.5px solid var(--ink);
	border-radius: 100px;
	font-family: "Caveat", cursive;
	font-size: 1.12rem;
	font-weight: 700;
	color: var(--ink);
	cursor: pointer;
	box-shadow: 3px 3px 0 var(--ink);
	transition:
		transform 0.12s,
		box-shadow 0.12s;
}

.btn-cookie-accept:hover {
	transform: translate(-1px, -1px);
	box-shadow: 4px 4px 0 var(--ink);
}

.btn-cookie-accept:active {
	transform: translate(2px, 2px);
	box-shadow: 1px 1px 0 var(--ink);
}
