/* Themes can restyle the game by overriding these custom properties on .cg-game. */
.cg-game {
	--cg-ink: #121212;
	--cg-tile-bg: #efefe6;
	--cg-tile-fg: #121212;
	--cg-selected-bg: #5a594e;
	--cg-selected-fg: #fff;
	--cg-yellow: #f9df6d;
	--cg-green: #a0c35a;
	--cg-blue: #b0c4ef;
	--cg-purple: #ba81c5;
	--cg-gap: 8px;
	--cg-radius: 8px;
	--cg-row: 80px;

	max-width: 624px;
	margin: 1.5em auto;
	font-family: inherit;
}

.cg-game *,
.cg-game *::before,
.cg-game *::after {
	box-sizing: border-box;
}

.cg-game__title {
	text-align: center;
	margin: 0 0 0.25em;
}

.cg-game__title[hidden] {
	display: none;
}

.cg-game__intro {
	text-align: center;
	margin: 0 0 1em;
}

.cg-board {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: var(--cg-gap);
}

.cg-solved {
	display: flex;
	flex-direction: column;
	gap: var(--cg-gap);
}

.cg-solved:empty {
	display: none;
}

.cg-grid {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: var(--cg-gap);
}

.cg-grid[hidden] {
	display: none;
}

/* Tiles */
.cg-game .cg-tile {
	appearance: none;
	border: 0;
	margin: 0;
	border-radius: var(--cg-radius);
	background: var(--cg-tile-bg);
	color: var(--cg-tile-fg);
	height: var(--cg-row);
	padding: 4px;
	font: inherit;
	font-weight: 700;
	font-size: clamp(0.75rem, 2.8vw, 1.15rem);
	line-height: 1.1;
	text-transform: uppercase;
	overflow-wrap: anywhere;
	cursor: pointer;
	user-select: none;
	-webkit-tap-highlight-color: transparent;
	transition: background-color 0.15s, color 0.15s, transform 0.1s;
}

.cg-game .cg-tile:hover {
	filter: brightness(0.97);
}

.cg-game .cg-tile:active {
	transform: scale(0.96);
}

.cg-game .cg-tile[aria-pressed="true"] {
	background: var(--cg-selected-bg);
	color: var(--cg-selected-fg);
}

.cg-game .cg-tile:focus-visible,
.cg-game .cg-btn:focus-visible {
	outline: 3px solid #2563eb;
	outline-offset: 2px;
}

.cg-game .cg-tile--long {
	font-size: clamp(0.65rem, 2.2vw, 0.95rem);
}

.cg-game .cg-tile--xlong {
	font-size: clamp(0.55rem, 1.8vw, 0.8rem);
}

.cg-tile--jump {
	animation: cg-jump 0.3s ease-in-out both;
}

.cg-tile--shake {
	animation: cg-shake 0.4s ease-in-out;
}

/* Solved group bars */
.cg-group {
	min-height: var(--cg-row);
	border-radius: var(--cg-radius);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 2px;
	padding: 8px 12px;
	text-align: center;
	color: #121212;
	text-transform: uppercase;
	animation: cg-pop 0.35s ease-out;
}

.cg-group--yellow { background: var(--cg-yellow); }
.cg-group--green  { background: var(--cg-green); }
.cg-group--blue   { background: var(--cg-blue); }
.cg-group--purple { background: var(--cg-purple); }

.cg-group__name {
	font-weight: 800;
	font-size: 1.05rem;
}

.cg-group__words {
	font-size: 0.95rem;
}

/* Toast */
.cg-toast {
	position: absolute;
	top: 12px;
	left: 50%;
	transform: translate(-50%, -6px);
	z-index: 2;
	padding: 0.6em 1em;
	border-radius: 6px;
	background: var(--cg-ink);
	color: #fff;
	font-weight: 600;
	white-space: nowrap;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.2s, transform 0.2s;
}

.cg-toast.is-visible {
	opacity: 1;
	transform: translate(-50%, 0);
}

/* Mistakes */
.cg-mistakes {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	margin: 1.25em 0;
	font-size: 0.95rem;
}

.cg-mistakes[hidden] {
	display: none;
}

.cg-dots {
	display: inline-flex;
	gap: 8px;
}

.cg-dot {
	width: 14px;
	height: 14px;
	border-radius: 50%;
	background: var(--cg-selected-bg);
	transition: transform 0.3s, opacity 0.3s;
}

.cg-dot--used {
	transform: scale(0);
	opacity: 0;
}

/* Buttons */
.cg-controls {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 10px;
}

.cg-controls[hidden] {
	display: none;
}

.cg-game .cg-btn {
	appearance: none;
	min-height: 44px;
	padding: 0.6em 1.3em;
	border: 1px solid currentColor;
	border-radius: 999px;
	background: transparent;
	color: inherit;
	font: inherit;
	font-weight: 600;
	font-size: 0.95rem;
	cursor: pointer;
}

.cg-game .cg-btn--primary:not(:disabled) {
	background: var(--cg-ink);
	border-color: var(--cg-ink);
	color: #fff;
}

.cg-game .cg-btn:disabled {
	opacity: 0.4;
	cursor: default;
}

/* Result */
.cg-result {
	margin-top: 1.5em;
	text-align: center;
}

.cg-result[hidden] {
	display: none;
}

.cg-result__title {
	margin: 0 0 0.5em;
}

.cg-game .cg-result__grid {
	display: inline-block;
	margin: 0 0 1em;
	padding: 0;
	background: none;
	border: 0;
	font-size: 1.5rem;
	line-height: 1.15;
	letter-spacing: 2px;
	font-family: inherit;
}

.cg-notice {
	padding: 0.75em 1em;
	border-left: 4px solid #d63638;
	background: #fcf0f1;
}

@keyframes cg-jump {
	0%, 100% { transform: translateY(0); }
	50% { transform: translateY(-8px); }
}

@keyframes cg-shake {
	0%, 100% { transform: translateX(0); }
	20%, 60% { transform: translateX(-5px); }
	40%, 80% { transform: translateX(5px); }
}

@keyframes cg-pop {
	from { transform: scale(0.92); opacity: 0.4; }
	to { transform: scale(1); opacity: 1; }
}

@media (max-width: 480px) {
	.cg-game {
		--cg-gap: 6px;
		--cg-row: 68px;
	}

	.cg-group__name,
	.cg-group__words {
		font-size: 0.85rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.cg-game *,
	.cg-game *::before,
	.cg-game *::after {
		animation: none !important;
		transition: none !important;
	}
}
