:root {
	color-scheme: dark;
	--bg: #ffffff;
	--line: #5a5a5a;
	--text: #000000;
	--muted: #747474;
	--letter: #efefe7;
	--blue: #52c7ff;
	--green: #8fd16a;
	--red: #ff6f61;
	--yellow: #f3c969;
}

* {
	box-sizing: border-box;
}

html,
body {
	min-height: 100%;
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font-family:
		Inter,
		ui-sans-serif,
		system-ui,
		-apple-system,
		BlinkMacSystemFont,
		"Segoe UI",
		sans-serif;
}
.top-nav {
	font-family: Arial, sans-serif;
	font-size: 14px;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px 20px;
	border-bottom: 1px solid #e0e0e0;
	position: sticky;
	top: 0;
	background: #fff;
	width: 100%;
	box-sizing: border-box;
	justify-content: flex-start;
}
.top-nav a {
	color: #111;
	text-decoration: none;
}
.top-nav a:hover {
	text-decoration: underline;
}
.header-actions {
	margin-left: auto;
	display: flex;
	gap: 8px;
}
.help-btn {
	width: 30px;
	height: 30px;
	display: grid;
	place-items: center;
	padding: 0;
	color: #111;
	background: #fff;
	border: 1px solid #c8c8c8;
	border-radius: 999px;
	font-size: 16px;
	font-weight: 700;
	line-height: 1;
	cursor: pointer;
}
.help-btn:hover {
	background: #f2f2f2;
}

.puzzle-label {
	color: var(--muted);
	font-size: 13px;
	font-weight: 700;
}
button {
	font: inherit;
}

/* Visible keyboard focus indicators (mouse clicks stay ring-free). */
.letter:focus-visible,
.btn:focus-visible,
.icon-btn:focus-visible {
	outline: 3px solid var(--blue);
	outline-offset: 2px;
}

.top-nav a:focus-visible {
	outline: 2px solid var(--blue);
	outline-offset: 2px;
	border-radius: 2px;
}

.app {
	width: 1120px;
	max-width: 100%;
	margin: 0 auto;
	padding: 20px;
	display: flex;
	flex-direction: row;
	gap: 18px;
	justify-content: center;
	align-items: flex-start;
}

.app > aside {
	width: 320px;
	flex-shrink: 0;
}

.play {
	width: 640px;
	flex-shrink: 0;
	display: grid;
	gap: 14px;
}
#puzzle-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
}
.topbar {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 16px;
	align-items: center;
	padding: 16px;
}

h1 {
	margin: 0;
	font-size: 28px;
	line-height: 1.05;
	letter-spacing: 0;
}

.statbar {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: 10px;
}

.stat {
	padding: 8px 10px;
	background: var(--bg);
	border: 1px solid var(--line);
	border-radius: 6px;
	text-align: center;
}

.stat-value {
	display: block;
	font-size: 24px;
	font-weight: 700;
	line-height: 1;
	font-variant-numeric: tabular-nums;
}

/* Undo counter turns red as it runs low. */
.stat-value.danger {
	color: var(--red);
}

.stat-label {
	display: block;
	margin-top: 4px;
	color: var(--muted);
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.board {
	padding: 16px;
}

.word-rack {
	display: grid;
	grid-template-columns: repeat(5, minmax(52px, 1fr));
	gap: 10px;
	margin-bottom: 16px;
}

.slot {
	height: clamp(60px, 12vw, 80px);
	display: grid;
	place-items: center;
	background: var(--letter);
	border: 1px solid var(--line);
	border-radius: 6px;
	color: var(--muted);
	font-size: 30px;
	font-weight: 700;
	text-transform: uppercase;
}

.slot.filled {
	color: var(--text);
	border-color: var(--line);
}

.slot.bad {
	animation: shake 0.28s ease;
	border-color: var(--red);
	color: var(--red);
}

@keyframes shake {
	0%,
	100% {
		transform: translateX(0);
	}
	30% {
		transform: translateX(-5px);
	}
	70% {
		transform: translateX(5px);
	}
}

.controls {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin-bottom: 16px;
	width: 100%;
	align-items: center;
	justify-content: center;
}

.btn {
	min-height: 42px;
	padding: 0 15px;
	color: var(--text);
	background: var(--bg);
	border: 1px solid var(--line);
	border-radius: 21px;
	width: fit-content;
	cursor: pointer;
}
.btn:active {
	transform: translateY(1px);
}

.btn.primary {
	color: #06181f;
	background: var(--blue);
	border-color: var(--blue);
	font-weight: 700;
}

.btn:disabled {
	opacity: 0.42;
	cursor: default;
	transform: none;
}

.message {
	min-height: 22px;
	margin-left: auto;
	align-self: center;
	color: var(--muted);
	font-size: 14px;
}

.message.good {
	color: var(--green);
}

.message.bad {
	color: var(--red);
}

.letter-grid {
	display: grid;
	grid-template-columns: repeat(5, minmax(52px, 1fr));
	gap: 10px;
}
.letter-grid:empty::before {
	content: "Loading board...";
	color: var(--muted);
	font-size: 14px;
}

.letter {
	position: relative;
	height: clamp(60px, 12vw, 80px);
	display: grid;
	place-items: center;
	color: var(--text);
	background: var(--letter);
	border: 1px solid var(--line);
	border-radius: 6px;
	font-size: 32px;
	font-weight: 700;
	line-height: 0.8;
	cursor: pointer;
	text-transform: uppercase;
	transition:
		transform 0.3s ease,
		background 0.3s ease,
		color 0.3s ease;
}

.letter:active {
	transform: scale(0.9);
	background: rgb(90, 89, 79);
	color: rgb(248, 248, 248);
}

.letter.selected {
	background: rgb(90, 89, 79);
	color: rgb(248, 248, 248);
}

.letter.used {
	visibility: hidden;
	pointer-events: none;
}

.badge {
	position: absolute;
	top: 6px;
	right: 6px;
	width: 24px;
	height: 24px;
	display: none;
	place-items: center;
	border-radius: 999px;
	background: var(--yellow);
	color: #17120a;
	font-size: 13px;
	font-weight: 900;
}

.letter.selected .badge {
	display: grid;
}
#vl {
	width: 2px;
	height: 100%;
	background: var(--line);
}

.side {
	height: 100%;
	display: flex;
	flex-direction: column;
	gap: 14px;
}

.found-list {
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin: 0;
	padding: 0;
	list-style: none;
	color: var(--text);
}

.found-list:empty::before {
	content: "No words yet";
	color: var(--muted);
	font-size: 14px;
}

.found-item {
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	width: 50%;
	align-items: center;
	gap: 8px;
	padding: 9px 10px;
	background: var(--bg);
}

.found-word {
	font-weight: 700;
}

.icon-btn {
	width: 32px;
	height: 32px;
	display: grid;
	place-items: center;
	color: var(--muted);
	background: transparent;
	border: 1px solid transparent;
	border-radius: 6px;
	cursor: pointer;
}

.icon-btn:disabled {
	opacity: 0.35;
	cursor: default;
}

.win {
	display: none;
	padding: 12px;
	border: 1px solid #476a36;
	border-radius: 6px;
	background: var(--green);
	color: var(--text);
	font-weight: 700;
	width: 50%;
}

.win.show {
	display: block;
}

@media (max-width: 820px) {
	body {
		padding: 12px;
	}

	.app {
		flex-direction: column;
		align-items: stretch;
		padding: 12px;
	}

	.play,
	.app > aside {
		width: 100%;
	}

	.topbar {
		grid-template-columns: 1fr;
	}

	.stats {
		justify-content: stretch;
	}

	.stat {
		flex: 1;
		text-align: left;
	}

	.letter {
		font-size: 34px;
	}

	.message {
		width: 100%;
		margin-left: 0;
	}
}

/* --- How-to-play modal --------------------------------------------------- */
.modal {
	position: fixed;
	inset: 0;
	z-index: 100;
	display: none;
	place-items: center;
	padding: 20px;
	background: rgba(20, 20, 20, 0.55);
}

.modal.show {
	display: grid;
}

.modal-card {
	position: relative;
	width: 100%;
	max-width: 440px;
	max-height: 90vh;
	overflow: auto;
	padding: 28px 28px 24px;
	background: #fff;
	color: #000;
	border-radius: 12px;
	animation: modal-pop 0.18s ease;
}

@keyframes modal-pop {
	from {
		transform: translateY(8px) scale(0.98);
		opacity: 0;
	}
}

.modal-close {
	position: absolute;
	top: 12px;
	right: 14px;
	width: 34px;
	height: 34px;
	display: grid;
	place-items: center;
	padding: 0;
	color: #444;
	background: transparent;
	border: none;
	border-radius: 8px;
	font-size: 26px;
	line-height: 1;
	cursor: pointer;
}

.modal-close:hover {
	background: #f0f0f0;
}

.modal-title {
	margin: 0;
	font-size: 30px;
	font-weight: 700;
	letter-spacing: -0.01em;
}

.modal-sub {
	margin: 6px 0 18px;
	color: #333;
	font-size: 16px;
}

.modal-rules {
	margin: 0 0 18px;
	padding-left: 22px;
	display: grid;
	gap: 10px;
	color: #222;
	font-size: 15px;
	line-height: 1.4;
}

.modal-foot {
	margin: 0 0 20px;
	padding-top: 16px;
	border-top: 1px solid #e6e6e6;
	color: #555;
	font-size: 14px;
}

.modal-play {
	width: 100%;
	min-height: 48px;
	font-size: 16px;
}

/* --- Past boards (archive) modal ----------------------------------------- */
.archive-controls {
	display: flex;
	flex-direction: column;
	gap: 14px;
	margin: 0 0 12px;
}

.archive-field {
	display: flex;
	flex-direction: column;
	gap: 6px;
	color: #333;
	font-size: 14px;
	font-weight: 700;
}

.archive-field input[type="date"] {
	padding: 10px 12px;
	font: inherit;
	color: #111;
	background: #fff;
	border: 1px solid var(--line);
	border-radius: 8px;
}

.archive-play {
	min-height: 46px;
}

.archive-error {
	min-height: 18px;
	margin: 0 0 12px;
	color: var(--red);
	font-size: 14px;
}

.archive-error:empty {
	min-height: 0;
	margin: 0;
}

.archive-today {
	width: 100%;
	min-height: 46px;
}

.archive-today[hidden] {
	display: none;
}

/* --- Solution links + list ----------------------------------------------- */
/* Inline text button used in the win/lose footer to open the solution lists. */
.link-btn {
	padding: 0;
	border: none;
	background: none;
	color: #2563eb;
	font: inherit;
	text-decoration: underline;
	cursor: pointer;
}

.link-btn:hover {
	color: #1d4ed8;
}

.link-btn:disabled {
	color: inherit;
	text-decoration: none;
	cursor: default;
}

.solution-list {
	margin: 0;
	padding-left: 26px;
	/* One page's worth of rows; pagination (not scrolling) moves through them. */
	min-height: 230px;
	display: grid;
	grid-auto-rows: min-content;
	gap: 6px;
	color: #111;
	font-size: 15px;
	font-variant-numeric: tabular-nums;
}

.solution-list:empty::before {
	content: "No solutions to show.";
	color: #777;
	font-size: 14px;
}

.solution-row {
	letter-spacing: 0.02em;
}

/* --- Google-style page navigator ----------------------------------------- */
.solution-pager {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 4px;
	margin-top: 16px;
}

.solution-pager:empty {
	display: none;
}

.pager-btn {
	min-width: 30px;
	height: 30px;
	padding: 0 8px;
	display: grid;
	place-items: center;
	color: #2563eb;
	background: transparent;
	border: 1px solid transparent;
	border-radius: 6px;
	font: inherit;
	font-variant-numeric: tabular-nums;
	cursor: pointer;
}

.pager-btn:hover:not(:disabled):not(.current) {
	background: #eef2ff;
}

.pager-btn.current {
	color: #111;
	font-weight: 700;
	border-color: #d4d4d4;
	cursor: default;
}

.pager-btn:disabled {
	color: #bbb;
	cursor: default;
}

.pager-gap {
	min-width: 18px;
	text-align: center;
	color: #999;
}

/* --- Win screen ---------------------------------------------------------- */
.win-stats {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 12px;
	margin: 0 0 20px;
}

.win-stat {
	padding: 14px 10px;
	background: #f6f6f4;
	border: 1px solid #e4e4dd;
	border-radius: 10px;
	text-align: center;
}

.win-stat-value {
	display: block;
	font-size: 30px;
	font-weight: 800;
	line-height: 1;
	color: #111;
	font-variant-numeric: tabular-nums;
}

.win-stat-label {
	display: block;
	margin-top: 6px;
	color: #666;
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}
