:root,
:root[data-theme="light"] {
	--bg: #fffdf8;
	--sky: #e8f4ff;
	--surface: #ffffff;
	--text: #1d2742;
	--muted: #56627f;
	--border: #dfe5f0;
	--key: #dfe5f0;
	--brand: #8a5a2b;
	--ink: #1d2742;
	--on-ink: #ffffff;
	--on-brand: #ffffff;
	--sun: #ffc93c;
	--red: #dc2626;
	--vermilion: #e03e1a;
	--orange: #ea580c;
	--lime: #4d7c0f;
	--green: #16a34a;
	--teal: #0d9488;
	--cyan: #0891b2;
	--blue: #2563eb;
	--indigo: #4f46e5;
	--violet: #7c3aed;
	--fuchsia: #c026d3;
	--pink: #db2777;
	--rose: #e11d48;
	--on-color: #ffffff;
	--ok: #16a34a;
	--near: #f2b200;
	--miss: #8d97ab;
	--bad: #e5484d;
	--shadow: 0 2px 10px rgba(29, 39, 66, 0.08);
	--radius: 16px;
	--game: var(--brand);
	color-scheme: light;
}

:root[data-theme="dark"] {
	--bg: #151d33;
	--sky: #1b2542;
	--surface: #212c4a;
	--text: #f3f5fb;
	--muted: #a8b2cc;
	--border: #34415f;
	--key: #3d4a6b;
	--brand: #d9a066;
	--ink: #5a3a1e;
	--on-ink: #fff6ea;
	--on-brand: #151d33;
	--sun: #ffd25c;
	--red: #f87171;
	--vermilion: #ff7f5c;
	--orange: #fb923c;
	--lime: #a3e635;
	--green: #4ade80;
	--teal: #2dd4bf;
	--cyan: #22d3ee;
	--blue: #60a5fa;
	--indigo: #818cf8;
	--violet: #a78bfa;
	--fuchsia: #e879f9;
	--pink: #f472b6;
	--rose: #fb7185;
	--on-color: #151d33;
	--ok: #2f9e4f;
	--near: #e0aa10;
	--miss: #2a3452;
	--bad: #ff6b6f;
	--shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
	color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
	:root[data-theme="auto"] {
		--bg: #151d33;
		--sky: #1b2542;
		--surface: #212c4a;
		--text: #f3f5fb;
		--muted: #a8b2cc;
		--border: #34415f;
		--key: #3d4a6b;
		--brand: #d9a066;
		--ink: #5a3a1e;
		--on-ink: #fff6ea;
		--on-brand: #151d33;
		--sun: #ffd25c;
		--red: #f87171;
		--vermilion: #ff7f5c;
		--orange: #fb923c;
		--lime: #a3e635;
		--green: #4ade80;
		--teal: #2dd4bf;
		--cyan: #22d3ee;
		--blue: #60a5fa;
		--indigo: #818cf8;
		--violet: #a78bfa;
		--fuchsia: #e879f9;
		--pink: #f472b6;
		--rose: #fb7185;
		--on-color: #151d33;
		--ok: #2f9e4f;
		--near: #e0aa10;
		--miss: #2a3452;
		--bad: #ff6b6f;
		--shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
		color-scheme: dark;
	}
}

* {
	box-sizing: border-box;
	min-width: 0;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font-family: ui-rounded, "SF Pro Rounded", Nunito, "Segoe UI", system-ui, sans-serif;
	font-size: 17px;
	line-height: 1.5;
}

button {
	font: inherit;
	color: inherit;
}

:focus-visible {
	outline: 3px solid var(--game);
	outline-offset: 2px;
}

main {
	max-width: 1000px;
	margin: 0 auto;
	padding: 0 16px 40px;
}

.button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 0 18px;
	border: 2px solid var(--game);
	border-radius: 14px;
	background: var(--game);
	color: var(--on-color);
	font-weight: 800;
	text-decoration: none;
	cursor: pointer;
}

.button.secondary {
	border-color: var(--border);
	background: transparent;
	color: var(--text);
}

.segmented {
	display: inline-flex;
	padding: 2px;
	border: 2px solid var(--border);
	border-radius: 999px;
	background: var(--surface);
}

.segmented button {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 36px;
	padding: 0 14px;
	border: 0;
	border-radius: 999px;
	background: transparent;
	color: var(--muted);
	font-weight: 800;
	cursor: pointer;
}

.segmented button[aria-pressed="true"] {
	background: var(--game);
	color: var(--on-color);
}

/* Start page */

.site-header {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr) auto;
	grid-template-areas: "logo name side" "logo tagline side";
	align-items: center;
	column-gap: 14px;
	max-width: 1000px;
	margin: 0 auto;
	padding: 16px;
}

.site-logo {
	grid-area: logo;
	width: 80px;
	height: 80px;
}

.site-title {
	grid-area: name;
	align-self: end;
	margin: 0;
	font-size: clamp(1.7rem, 6vw, 2.4rem);
	font-weight: 900;
	line-height: 1.05;
	letter-spacing: -0.01em;
}

.site-title a {
	color: var(--text);
	text-decoration: none;
}

.site-title .nut {
	color: var(--brand);
}

.tagline {
	grid-area: tagline;
	align-self: start;
	color: var(--muted);
	font-size: clamp(1rem, 3.5vw, 1.15rem);
	font-weight: 800;
	line-height: 1.25;
}

.header-side {
	display: flex;
	grid-area: side;
	flex-direction: column;
	align-items: flex-end;
	gap: 8px;
}

.header-side .segmented {
	--game: var(--brand);
	--on-color: var(--on-brand);
}

@media (max-width: 480px) {
	.site-header {
		grid-template-areas: "logo name side" "tagline tagline tagline";
		row-gap: 10px;
	}

	.site-logo {
		width: 60px;
		height: 60px;
	}

	.site-title {
		align-self: center;
	}
}

.streak {
	padding: 2px 12px;
	border: 2px solid var(--sun);
	border-radius: 999px;
	background: var(--sun);
	color: #1d2742;
	font-size: 0.85rem;
	font-weight: 800;
	white-space: nowrap;
}

.home {
	--game: var(--ink);
	--on-color: var(--on-ink);
	display: flex;
	flex-direction: column;
	min-height: 100svh;
}

.home > * {
	width: 100%;
}

.home main {
	flex: 1;
}

.continue {
	display: flex;
	align-items: center;
	gap: 14px;
	margin-bottom: 8px;
	padding: 14px 16px;
	border-radius: 20px;
	background: var(--ink);
	color: var(--on-ink);
	text-decoration: none;
}

.continue small {
	display: block;
	font-size: 0.8rem;
	font-weight: 700;
}

.continue strong {
	display: block;
	font-size: 1.15rem;
	line-height: 1.2;
}

.continue .go {
	margin-left: auto;
	padding: 6px 14px;
	border-radius: 12px;
	background: var(--sun);
	color: #1d2742;
	font-weight: 900;
	white-space: nowrap;
}

.group h2 {
	margin: 24px 0 10px;
	font-size: 1.25rem;
	font-weight: 900;
}

.game-row {
	position: relative;
}

.game-list {
	display: grid;
	grid-auto-columns: min(300px, 80%);
	grid-auto-flow: column;
	gap: 16px;
	margin: 0;
	padding: 4px 2px 10px;
	overflow-x: auto;
	overscroll-behavior-x: contain;
	scroll-snap-type: x mandatory;
	scrollbar-width: none;
	list-style: none;
}

.game-list::-webkit-scrollbar {
	display: none;
}

.game-list > li {
	scroll-snap-align: start;
}

.row-arrow {
	position: absolute;
	top: 50%;
	z-index: 2;
	display: none;
	place-items: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 2px solid var(--border);
	border-radius: 50%;
	background: var(--surface);
	box-shadow: var(--shadow);
	color: var(--text);
	cursor: pointer;
	transform: translateY(-50%);
}

.row-arrow.prev {
	left: -14px;
}

.row-arrow.next {
	right: -14px;
}

@media (hover: hover) and (pointer: fine) {
	.row-arrow:not([hidden]) {
		display: grid;
	}
}

.game-tile {
	position: relative;
	display: flex;
	flex-direction: column;
	height: 100%;
	overflow: hidden;
	border: 2px solid var(--border);
	border-radius: 22px;
	background: var(--surface);
	box-shadow: var(--shadow);
	color: inherit;
	text-decoration: none;
	transition: transform 0.15s, border-color 0.15s;
}

a.game-tile:hover,
a.game-tile:focus-visible {
	border-color: var(--game);
	transform: translateY(-2px);
}

.game-tile.soon {
	opacity: 0.55;
}

.game-preview {
	display: grid;
	place-items: center;
	height: 116px;
	background: color-mix(in srgb, var(--game) 12%, var(--surface));
}

.game-preview svg {
	width: 176px;
	height: 99px;
}

.game-preview .cell {
	fill: var(--surface);
	stroke: var(--border);
}

.game-preview .ink {
	fill: var(--text);
}

.game-preview .ok {
	fill: var(--ok);
}

.game-preview .near {
	fill: var(--near);
}

.game-preview .miss {
	fill: var(--miss);
}

.game-preview .mark {
	fill: var(--game);
	fill-opacity: 0.3;
}

.game-preview .line {
	fill: none;
	stroke: var(--game);
}

.game-preview .dot {
	fill: var(--text);
}

.game-preview .dot-text {
	fill: var(--bg);
}

.game-preview .block {
	fill: var(--ink);
}

.game-preview .block-text {
	fill: var(--on-ink);
}

.game-preview .frame {
	fill: none;
	stroke: var(--text);
}

.game-preview .on {
	fill: var(--game);
	stroke: var(--surface);
}

.game-preview .pick {
	fill: var(--game);
}

.game-body {
	display: flex;
	flex-direction: column;
	gap: 4px;
	padding: 14px 16px 18px;
}

.game-head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 4px 10px;
}

.game-icon {
	display: grid;
	place-items: center;
	flex: none;
	width: 52px;
	height: 52px;
	border-radius: 14px;
	background: var(--game);
}

.game-icon svg {
	width: 32px;
	height: 32px;
}

.game-head .game-icon {
	width: 32px;
	height: 32px;
	border-radius: 10px;
}

.game-head .game-icon svg {
	width: 20px;
	height: 20px;
}

.game-tile.soon .game-icon {
	background: var(--miss);
}

.level-icon {
	display: inline-flex;
	flex: none;
	gap: 1px;
}

.level-icon svg {
	width: 16px;
	height: 16px;
	fill: var(--border);
}

.level-icon .on {
	fill: var(--brand);
}

.level-icon .seam {
	fill: none;
	stroke: var(--surface);
	stroke-width: 1.4;
	stroke-linecap: round;
}

.game-head .level-icon {
	margin-left: auto;
}

.segmented .level-icon .on {
	fill: currentColor;
}

.level-line .segmented button {
	min-width: 56px;
	justify-content: center;
}

.level-line .level-icon svg {
	width: 18px;
	height: 18px;
}

.segmented .level-icon .seam {
	stroke: none;
}

.game-name {
	font-size: 1.15rem;
	font-weight: 900;
	line-height: 1.25;
	hyphens: auto;
}

.game-description {
	color: var(--muted);
	font-size: 0.9rem;
	line-height: 1.35;
}

.badge {
	position: absolute;
	top: 12px;
	right: 12px;
	padding: 2px 10px;
	border-radius: 999px;
	background: var(--border);
	font-size: 0.75rem;
	font-weight: 900;
}

.badge.new {
	background: var(--sun);
	color: #1d2742;
}

.badge.running {
	background: color-mix(in srgb, var(--brand) 25%, transparent);
}

.badge.solvedToday {
	display: grid;
	place-items: center;
	width: 28px;
	height: 28px;
	padding: 0;
	border-radius: 50%;
	background: var(--ink);
	color: var(--on-ink);
	font-size: 0.95rem;
}

.site-footer {
	padding: 16px;
	border-top: 1px solid var(--border);
	color: var(--muted);
	font-size: 0.85rem;
	text-align: center;
}

@media (max-width: 600px) {
	.game-list {
		grid-auto-columns: 42%;
		gap: 10px;
		margin-inline: -16px;
		padding-inline: 16px;
		scroll-padding-inline: 16px;
	}

	.game-tile .game-preview {
		height: 84px;
	}

	.game-tile .game-preview svg {
		width: 132px;
		height: 74px;
	}

	.game-body {
		padding: 10px 12px 12px;
	}

	.game-head {
		flex-wrap: wrap;
		gap: 4px 8px;
	}

	.game-head .game-icon,
	.game-description {
		display: none;
	}

	.game-name {
		font-size: 1rem;
	}

	.badge {
		top: 8px;
		right: 8px;
	}
}

/* Game frame */

.game-bar {
	display: flex;
	align-items: center;
	gap: 8px;
	max-width: 1000px;
	min-height: 64px;
	margin: 0 auto;
	padding: 10px 16px;
}

.game-bar .back {
	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	margin-left: -8px;
	border-radius: 50%;
	color: var(--game);
}

.stroke-icon {
	display: grid;
	place-items: center;
}

.stroke-icon svg {
	width: 22px;
	height: 22px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2.4;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.game-bar .back svg {
	width: 28px;
	height: 28px;
	stroke-width: 3;
}

.game-bar h1 {
	flex: 1;
	margin: 0;
	overflow: hidden;
	font-size: clamp(1.1rem, 4.5vw, 1.35rem);
	font-weight: 900;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.icon-button {
	display: grid;
	place-items: center;
	flex: none;
	width: 42px;
	height: 42px;
	padding: 0;
	border: 2px solid var(--border);
	border-radius: 50%;
	background: var(--surface);
	font-size: 1.1rem;
	font-weight: 900;
	cursor: pointer;
}

.game-bar.confirm {
	flex-wrap: wrap;
	margin-top: 6px;
	border: 2px solid var(--sun);
	border-radius: 16px;
	background: var(--surface);
	font-weight: 800;
}

.game-bar.confirm span {
	flex: 1;
}

.level-line {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 8px 12px;
	margin-bottom: 14px;
	color: var(--muted);
	font-weight: 800;
	font-variant-numeric: tabular-nums;
}

.level-group {
	display: inline-flex;
	align-items: center;
	gap: 10px;
}

.level-hint {
	color: var(--game);
	font-weight: 900;
	opacity: 0;
	transition: opacity 0.2s;
}

.level-hint.show {
	opacity: 1;
}

.level-line .status {
	display: flex;
	gap: 12px;
}

.play {
	position: relative;
	display: grid;
	justify-items: center;
	gap: 16px;
}

@media (min-width: 900px) {
	.play.with-side {
		grid-template-columns: minmax(0, 1fr) minmax(200px, 300px);
		align-items: start;
	}
}

.tools {
	display: flex;
	justify-content: center;
	gap: 8px;
	margin-top: 16px;
}

.tool {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 2px;
	min-width: 76px;
	min-height: 60px;
	padding: 8px 10px 6px;
	border: 2px solid transparent;
	border-radius: 14px;
	background: transparent;
	color: var(--text);
	font-size: 0.85rem;
	font-weight: 800;
	cursor: pointer;
}

.tool .stroke-icon svg {
	width: 26px;
	height: 26px;
}

.tool:hover:not(:disabled) {
	background: color-mix(in srgb, var(--game) 10%, transparent);
}

.tool:disabled {
	color: var(--muted);
	opacity: 0.35;
	cursor: default;
}

.tool[aria-pressed="true"] {
	border-color: var(--game);
	background: color-mix(in srgb, var(--game) 14%, transparent);
	color: var(--game);
}

.toast {
	position: absolute;
	top: 8px;
	left: 50%;
	z-index: 5;
	max-width: calc(100% - 16px);
	padding: 10px 16px;
	border-radius: 14px;
	background: var(--text);
	color: var(--bg);
	font-weight: 800;
	text-align: center;
	transform: translateX(-50%);
	pointer-events: none;
}

dialog {
	width: min(440px, calc(100% - 32px));
	max-height: calc(100% - 32px);
	padding: 22px;
	border: 2px solid var(--border);
	border-radius: 24px;
	background: var(--surface);
	color: var(--text);
	box-shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.45);
}

dialog::backdrop {
	background: rgba(21, 29, 51, 0.45);
}

dialog h2 {
	margin: 0 0 6px;
	font-size: 1.4rem;
	font-weight: 900;
	line-height: 1.2;
}

dialog h3 {
	margin: 16px 0 4px;
	color: var(--game);
	font-size: 0.9rem;
	font-weight: 900;
}

dialog p,
dialog ul {
	margin: 0 0 6px;
}

dialog ul {
	padding-left: 20px;
}

dialog .game-preview {
	margin: 8px 0 4px;
	border-radius: 16px;
}

dialog details {
	margin-top: 14px;
	border-top: 1px solid var(--border);
}

dialog summary {
	padding: 12px 0 2px;
	color: var(--game);
	font-weight: 900;
	cursor: pointer;
}

.level-list {
	padding: 0;
	list-style: none;
}

.level-list li {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-bottom: 4px;
}

.level-list .level-icon {
	width: 52px;
}

.dialog-actions {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px;
	margin-top: 18px;
}

.setting {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	min-height: 52px;
	border-bottom: 1px solid var(--border);
	font-weight: 700;
}

.setting select {
	min-height: 40px;
	padding: 0 10px;
	border: 2px solid var(--border);
	border-radius: 10px;
	background: var(--surface);
	color: var(--text);
	font: inherit;
}

.switch {
	width: 48px;
	height: 28px;
	margin: 0;
	border-radius: 999px;
	background: var(--border);
	appearance: none;
	cursor: pointer;
	transition: background 0.15s;
}

.switch::after {
	content: "";
	display: block;
	width: 22px;
	height: 22px;
	margin: 3px;
	border-radius: 50%;
	background: #ffffff;
	transition: transform 0.15s;
}

.switch:checked {
	background: var(--game);
}

.switch:checked::after {
	transform: translateX(20px);
}

.note {
	margin-top: 10px;
	color: var(--muted);
	font-size: 0.85rem;
}

.end-card {
	text-align: center;
}

.end-card::backdrop {
	background: rgba(21, 29, 51, 0.15);
}

.end-card h2 {
	font-size: 2rem;
}

.solution {
	margin: 10px 0 0;
	font-size: 1.4rem;
	font-weight: 900;
	letter-spacing: 0.12em;
}

.stats {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
	gap: 8px;
	margin-top: 16px;
}

.stats div {
	color: var(--muted);
	font-size: 0.8rem;
	font-weight: 700;
}

.stats strong {
	display: block;
	color: var(--text);
	font-size: 1.5rem;
	font-weight: 900;
	font-variant-numeric: tabular-nums;
}

.end-card[open] .stats div {
	animation: appear 0.3s both;
}

.end-card[open] .stats div:nth-child(2) {
	animation-delay: 0.15s;
}

.end-card[open] .stats div:nth-child(3) {
	animation-delay: 0.3s;
}

.confetti {
	position: fixed;
	inset: 0;
	z-index: 10;
	width: 100%;
	height: 100%;
	pointer-events: none;
}

.pop {
	animation: pop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}

@keyframes pop {
	40% {
		transform: scale(1.25) translateY(-4px);
	}
}

@keyframes appear {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
}

@media (prefers-reduced-motion: reduce) {
	.pop,
	.end-card[open] .stats div {
		animation: none;
	}
}
