/* Connections Word Game — all rules are scoped to .cg-game so they can't leak into your theme. */

@font-face {
	font-family: "CG Rubik";
	src: url("../fonts/Rubik-Regular.ttf") format("truetype");
	font-weight: 400;
	font-style: normal;
	font-display: swap;
}
@font-face {
	font-family: "CG Rubik";
	src: url("../fonts/Rubik-Bold.ttf") format("truetype");
	font-weight: 700;
	font-style: normal;
	font-display: swap;
}
@font-face {
	font-family: "CG Rubik";
	src: url("../fonts/Rubik-Italic.ttf") format("truetype");
	font-weight: 400;
	font-style: italic;
	font-display: swap;
}

.cg-game {
	--cg-bg: #e1e3ea;
	--cg-navy: #2a3358;
	--cg-navy-soft: #4f5d85;
	--cg-card: #ffffff;
	--cg-card-line: #c3c8d6;
	--cg-muted: #5b6482;
	--cg-ok: #2f7d4f;
	--cg-bad: #b3372f;
	--cg-g0: #f9df6d;
	--cg-g1: #a8cd6a;
	--cg-g2: #a9c3f0;
	--cg-g3: #c58fd0;

	box-sizing: border-box;
	container-type: inline-size;
	position: relative;
	margin: 1.5em auto;
	padding: 18px;
	background: var(--cg-bg);
	color: var(--cg-navy);
	border-radius: 18px;
	min-height: 480px;
	font-family: "CG Rubik", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	font-size: 16px;
	line-height: 1.35;
	text-align: center;
	-webkit-tap-highlight-color: transparent;
}
.cg-game *,
.cg-game *::before,
.cg-game *::after {
	box-sizing: border-box;
}
.cg-game h2,
.cg-game p {
	margin: 0;
	padding: 0;
}

/* ---------- Buttons ---------- */
.cg-game .cg-btn {
	appearance: none;
	-webkit-appearance: none;
	display: inline-block;
	border: 0;
	border-radius: 14px;
	background: var(--cg-navy);
	color: #fff;
	font: 700 1rem/1.2 inherit;
	font-family: inherit;
	padding: 12px 22px;
	cursor: pointer;
	text-transform: none;
	letter-spacing: normal;
	box-shadow: none;
	transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s ease;
}
.cg-game .cg-btn:hover:not(:disabled) {
	background: var(--cg-navy-soft);
}
.cg-game .cg-btn:active:not(:disabled) {
	transform: scale(0.97);
}
.cg-game .cg-btn:focus-visible,
.cg-game .cg-card:focus-visible {
	outline: 3px solid #5b8def;
	outline-offset: 2px;
}
.cg-game .cg-btn:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}
.cg-game .cg-btn--ghost {
	background: transparent;
	color: var(--cg-navy);
	box-shadow: inset 0 0 0 2px var(--cg-navy);
}
.cg-game .cg-btn--ghost:hover:not(:disabled) {
	background: rgba(42, 51, 88, 0.1);
}

/* ---------- Header ---------- */
.cg-game .cg-head {
	margin-bottom: 14px;
	padding-bottom: 12px;
	border-bottom: 2px solid rgba(42, 51, 88, 0.12);
}
.cg-game .cg-head-top {
	display: grid;
	grid-template-columns: 1fr auto 1fr;
	grid-template-areas: "name toggle icons";
	align-items: center;
	gap: 10px;
}
.cg-game .cg-namebox {
	grid-area: name;
	display: flex;
	align-items: center;
	gap: 4px;
	min-width: 0;
}
.cg-game .cg-spacer {
	grid-area: toggle;
}
.cg-game .cg-backbtn {
	margin-left: -8px;
	flex: 0 0 auto;
}
.cg-game .cg-name {
	text-align: left;
	font-size: clamp(1.05rem, 4.4cqi, 1.6rem);
	font-weight: 700;
	line-height: 1.1;
	color: var(--cg-navy);
}
.cg-game .cg-head-top > .cg-toggle {
	grid-area: toggle;
}
.cg-game .cg-icons {
	grid-area: icons;
	justify-self: end;
	display: flex;
	gap: 4px;
}
.cg-game .cg-head-sub {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	margin-top: 12px;
}
.cg-game .cg-date {
	font-style: italic;
	color: var(--cg-muted);
	font-size: 0.92rem;
	text-align: left;
}

/* Segmented toggle (Daily/Unlimited, Classic/Large) */
.cg-game .cg-toggle {
	display: inline-flex;
	padding: 3px;
	background: rgba(42, 51, 88, 0.12);
	border-radius: 999px;
}
.cg-game .cg-seg {
	appearance: none;
	-webkit-appearance: none;
	border: 0;
	margin: 0;
	padding: 6px 14px;
	border-radius: 999px;
	background: transparent;
	color: var(--cg-navy);
	font-family: inherit;
	font-size: 0.85rem;
	font-weight: 700;
	line-height: 1.2;
	text-transform: none;
	letter-spacing: normal;
	box-shadow: none;
	cursor: pointer;
	transition: background 0.15s, color 0.15s;
}
.cg-game .cg-seg:hover {
	background: rgba(42, 51, 88, 0.1);
}
.cg-game .cg-seg[aria-pressed="true"] {
	background: var(--cg-navy);
	color: #fff;
}
.cg-game .cg-seg:focus-visible,
.cg-game .cg-icon:focus-visible,
.cg-game .cg-x:focus-visible {
	outline: 3px solid #5b8def;
	outline-offset: 2px;
}

/* Icon buttons (? and stats) */
.cg-game .cg-icon {
	appearance: none;
	-webkit-appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 0;
	margin: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--cg-navy);
	box-shadow: none;
	cursor: pointer;
	transition: background 0.15s;
}
.cg-game .cg-icon:hover {
	background: rgba(42, 51, 88, 0.12);
}
.cg-game .cg-icon svg {
	display: block;
}

/* Narrow containers: name + icons on row 1, the mode toggle drops to its own row */
@container (max-width: 520px) {
	.cg-game .cg-head-top {
		grid-template-columns: 1fr auto;
		grid-template-areas:
			"name icons"
			"toggle toggle";
	}
	.cg-game .cg-head-top > .cg-toggle {
		justify-self: center;
	}
	.cg-game .cg-spacer {
		display: none;
	}
}

/* ---------- Game header ---------- */
.cg-game .cg-stat {
	font-style: italic;
	color: var(--cg-muted);
	font-size: 0.95rem;
}
.cg-game .cg-stat strong {
	color: var(--cg-navy);
	font-style: normal;
}
.cg-game .cg-lives {
	display: inline-flex;
	gap: 5px;
	vertical-align: middle;
	margin-left: 6px;
}
.cg-game .cg-dot {
	width: 11px;
	height: 11px;
	border-radius: 50%;
	background: var(--cg-navy);
	transition: background 0.2s, transform 0.2s;
}
.cg-game .cg-dot.is-lost {
	background: transparent;
	box-shadow: inset 0 0 0 2px var(--cg-navy-soft);
	transform: scale(0.8);
}
.cg-game .cg-message {
	min-height: 1.5em;
	margin: 2px 0 10px;
	font-weight: 700;
	font-size: 0.95rem;
}
.cg-game .cg-message.is-ok { color: var(--cg-ok); }
.cg-game .cg-message.is-bad { color: var(--cg-bad); }

/* ---------- Solved rows ---------- */
.cg-game .cg-solved {
	display: grid;
	gap: 8px;
	margin-bottom: 8px;
}
.cg-game .cg-row {
	padding: 10px 12px;
	border-radius: 12px;
	color: #1d2442;
	animation: cg-pop 0.35s ease both;
}
.cg-game .cg-row.is-missed {
	opacity: 0.75;
	box-shadow: inset 0 0 0 2px rgba(42, 51, 88, 0.35);
}
.cg-game .cg-row .cg-row-title {
	display: block;
	font-weight: 700;
	font-size: 1.05rem;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}
.cg-game .cg-row .cg-row-words {
	display: block;
	font-size: 0.9rem;
}
.cg-game .cg-c0 { background: var(--cg-g0); }
.cg-game .cg-c1 { background: var(--cg-g1); }
.cg-game .cg-c2 { background: var(--cg-g2); }
.cg-game .cg-c3 { background: var(--cg-g3); }

/* ---------- Card grid ---------- */
.cg-game .cg-grid {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 8px;
}
.cg-game .cg-card {
	appearance: none;
	-webkit-appearance: none;
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 64px;
	padding: 6px 4px;
	border: 0;
	border-radius: 12px;
	background: var(--cg-card);
	color: var(--cg-navy);
	box-shadow: inset 0 0 0 1px var(--cg-card-line);
	font-family: inherit;
	font-weight: 700;
	font-size: 14px;
	font-size: clamp(10px, 3.1cqi, 17px);
	line-height: 1.15;
	text-transform: none;
	letter-spacing: normal;
	overflow-wrap: anywhere;
	hyphens: auto;
	cursor: pointer;
	transition: background 0.15s, color 0.15s, transform 0.12s;
}
.cg-game .cg-card:hover {
	background: #f1f3f9;
}
.cg-game .cg-card[aria-pressed="true"] {
	background: var(--cg-navy);
	color: #fff;
	box-shadow: none;
	transform: scale(0.97);
}
.cg-game .cg-card.is-shake {
	animation: cg-shake 0.4s ease;
}
.cg-game .cg-grid.is-locked .cg-card {
	pointer-events: none;
}

/* ---------- Controls ---------- */
.cg-game .cg-controls {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 10px;
	margin-top: 14px;
}
.cg-game .cg-controls .cg-btn {
	padding: 11px 18px;
}

/* ---------- Overlays (confirm + game over) ---------- */
.cg-game .cg-overlay {
	position: absolute;
	inset: 0;
	z-index: 5;
	display: flex;
	align-items: flex-start;
	justify-content: center;
	padding: 16px;
	overflow-y: auto;
	background: rgba(225, 227, 234, 0.94);
	border-radius: inherit;
	animation: cg-fade 0.2s ease both;
}
.cg-game .cg-panel {
	position: relative;
	width: 100%;
	max-width: 340px;
	margin: auto;
	padding: 24px 20px;
	background: #fff;
	border-radius: 18px;
	box-shadow: 0 8px 30px rgba(42, 51, 88, 0.2);
}
.cg-game .cg-panel h2 {
	font-size: 1.6rem;
	font-weight: 700;
	margin-bottom: 10px;
}
.cg-game .cg-panel p {
	color: var(--cg-muted);
	margin-bottom: 4px;
}
.cg-game .cg-panel p strong {
	color: var(--cg-navy);
}
.cg-game .cg-panel .cg-newbest {
	color: var(--cg-ok);
	font-weight: 700;
}
.cg-game .cg-panel .cg-controls {
	margin-top: 18px;
}

.cg-game .cg-panel--wide {
	max-width: 460px;
	text-align: left;
}
.cg-game .cg-panel--wide h2 {
	padding-right: 36px;
}
.cg-game .cg-x {
	appearance: none;
	-webkit-appearance: none;
	position: absolute;
	top: 12px;
	right: 12px;
	width: 34px;
	height: 34px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(42, 51, 88, 0.1);
	color: var(--cg-navy);
	font-family: inherit;
	font-size: 1.4rem;
	line-height: 1;
	cursor: pointer;
}
.cg-game .cg-x:hover {
	background: rgba(42, 51, 88, 0.2);
}
.cg-game .cg-prose p {
	margin: 0 0 10px;
	color: var(--cg-navy);
	font-size: 0.95rem;
}
.cg-game .cg-scroll {
	overflow-x: auto;
}
.cg-game .cg-table {
	width: 100%;
	margin: 0;
	border-collapse: collapse;
	border: 0;
	font-size: 0.85rem;
}
.cg-game .cg-table th,
.cg-game .cg-table td {
	padding: 8px 6px;
	border: 0;
	border-bottom: 1px solid var(--cg-card-line);
	background: transparent;
	color: var(--cg-navy);
	text-align: center;
	white-space: nowrap;
}
.cg-game .cg-table th:first-child {
	text-align: left;
}
.cg-game .cg-table thead th {
	font-size: 0.75rem;
	color: var(--cg-muted);
}
.cg-game .cg-fine {
	margin-top: 10px;
	font-size: 0.8rem;
	font-style: italic;
}

/* Large mode + finished board */
.cg-game .cg-grid.is-large .cg-card {
	min-height: 54px;
}
.cg-game .cg-grid.is-over .cg-card {
	opacity: 0.6;
	cursor: default;
}
.cg-game .cg-caption {
	margin: 8px 0 0;
	font-size: 0.85rem;
	font-style: italic;
	color: var(--cg-muted);
}
.cg-game .cg-caption:empty {
	display: none;
}

/* ---------- Archive ---------- */
.cg-game .cg-head-top--archive {
	grid-template-columns: 1fr auto;
	grid-template-areas: "name date";
}
.cg-game .cg-head-top--archive .cg-name { grid-area: name; }
.cg-game .cg-head-top--archive .cg-date { grid-area: date; text-align: right; }

.cg-game .cg-cal {
	margin-bottom: 18px;
}
.cg-game .cg-cal-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 10px;
	margin-bottom: 10px;
}
.cg-game .cg-cal-nav {
	display: flex;
	align-items: center;
	gap: 4px;
}
.cg-game .cg-cal-nav .cg-icon {
	font-size: 1.7rem;
	line-height: 1;
	font-family: inherit;
}
.cg-game .cg-cal-nav .cg-icon:disabled {
	opacity: 0.3;
	cursor: default;
}
.cg-game .cg-cal-title {
	min-width: 9em;
	text-align: center;
	font-size: 1rem;
}
.cg-game .cg-cal-grid {
	display: grid;
	grid-template-columns: repeat(7, minmax(0, 1fr));
	gap: 6px;
}
.cg-game .cg-cal-dow {
	padding-bottom: 2px;
	font-size: 0.75rem;
	font-weight: 700;
	color: var(--cg-muted);
	text-transform: uppercase;
}
.cg-game .cg-day {
	appearance: none;
	-webkit-appearance: none;
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	aspect-ratio: 1 / 1;
	min-height: 40px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 12px;
	background: transparent;
	color: var(--cg-navy);
	font-family: inherit;
	font-size: 0.95rem;
	font-weight: 700;
	line-height: 1;
	box-shadow: none;
	text-transform: none;
	letter-spacing: normal;
}
.cg-game .cg-day.is-blank { visibility: hidden; }
.cg-game .cg-day.is-off {
	color: var(--cg-muted);
	opacity: 0.4;
	font-weight: 400;
}
.cg-game button.cg-day {
	background: var(--cg-card);
	box-shadow: inset 0 0 0 1px var(--cg-card-line);
	cursor: pointer;
	transition: background 0.15s, transform 0.12s;
}
.cg-game button.cg-day:hover { background: #f1f3f9; }
.cg-game button.cg-day:active { transform: scale(0.95); }
.cg-game button.cg-day:focus-visible,
.cg-game .cg-item:focus-visible,
.cg-game .cg-chip:focus-visible {
	outline: 3px solid #5b8def;
	outline-offset: 2px;
}
.cg-game .cg-day.is-today {
	box-shadow: inset 0 0 0 2px var(--cg-navy);
}
.cg-game .cg-day.is-won  { background: var(--cg-g1) !important; box-shadow: none; }
.cg-game .cg-day.is-lost { background: #e9b4ae !important; box-shadow: none; }
.cg-game .cg-day.is-progress { background: var(--cg-g0) !important; box-shadow: none; }
.cg-game .cg-day.is-won::after,
.cg-game .cg-day.is-lost::after,
.cg-game .cg-day.is-progress::after {
	position: absolute;
	top: 3px;
	right: 6px;
	font-size: 0.6rem;
	line-height: 1;
}
.cg-game .cg-day.is-won::after { content: "\2713"; }
.cg-game .cg-day.is-lost::after { content: "\2715"; }
.cg-game .cg-day.is-progress::after { content: "\2026"; }
.cg-game .cg-cal-key {
	margin: 8px 0 0;
	font-size: 0.78rem;
	font-style: italic;
	color: var(--cg-muted);
	white-space: pre-wrap;
}

.cg-game .cg-list-controls {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 10px;
	margin-bottom: 12px;
}
.cg-game .cg-chip {
	appearance: none;
	-webkit-appearance: none;
	margin: 0;
	padding: 7px 14px;
	border: 0;
	border-radius: 999px;
	background: transparent;
	box-shadow: inset 0 0 0 2px var(--cg-navy);
	color: var(--cg-navy);
	font-family: inherit;
	font-size: 0.85rem;
	font-weight: 700;
	line-height: 1.2;
	text-transform: none;
	letter-spacing: normal;
	cursor: pointer;
	transition: background 0.15s, color 0.15s;
}
.cg-game .cg-chip[aria-pressed="true"] {
	background: var(--cg-navy);
	color: #fff;
}
.cg-game .cg-list-head {
	display: grid;
	grid-template-columns: 1.3fr 1.2fr 7.5em;
	gap: 8px;
	padding: 0 14px 6px;
	text-align: left;
	font-size: 0.72rem;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--cg-muted);
}
.cg-game .cg-items {
	list-style: none;
	margin: 0;
	padding: 0;
	display: grid;
	gap: 8px;
}
.cg-game .cg-items li {
	margin: 0;
	padding: 0;
	list-style: none;
}
.cg-game .cg-item {
	appearance: none;
	-webkit-appearance: none;
	display: grid;
	grid-template-columns: 1.3fr 1.2fr 7.5em;
	align-items: center;
	gap: 8px;
	width: 100%;
	margin: 0;
	padding: 14px;
	border: 0;
	border-radius: 14px;
	background: var(--cg-card);
	box-shadow: inset 0 0 0 1px var(--cg-card-line);
	color: var(--cg-navy);
	font-family: inherit;
	font-size: 0.95rem;
	line-height: 1.25;
	text-align: left;
	text-transform: none;
	letter-spacing: normal;
	cursor: pointer;
	transition: background 0.15s, transform 0.12s;
}
.cg-game .cg-item:hover { background: #f1f3f9; }
.cg-game .cg-item:active { transform: scale(0.99); }
.cg-game .cg-item-name { font-weight: 700; }
.cg-game .cg-item-date { color: var(--cg-muted); }
.cg-game .cg-item-status {
	display: inline-flex;
	align-items: center;
	justify-content: flex-end;
	gap: 6px;
	font-size: 0.8rem;
	font-weight: 700;
}
.cg-game .cg-item-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background: var(--cg-navy);
	color: #fff;
	font-size: 0.68rem;
}
.cg-game .cg-item.is-won .cg-item-icon { background: var(--cg-ok); }
.cg-game .cg-item.is-lost .cg-item-icon { background: var(--cg-bad); }
.cg-game .cg-item.is-progress .cg-item-icon { background: #b58a00; }
.cg-game .cg-empty {
	padding: 20px;
	font-style: italic;
	color: var(--cg-muted);
}
.cg-game .cg-pager {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	margin-top: 14px;
}
.cg-game .cg-pager-info {
	font-size: 0.85rem;
	font-style: italic;
	color: var(--cg-muted);
}
.cg-game .cg-pager .cg-btn {
	padding: 10px 18px;
}

/* Narrow: stack name/date, shorten status */
@container (max-width: 480px) {
	.cg-game .cg-list-head { display: none; }
	.cg-game .cg-item {
		grid-template-columns: 1fr auto;
		grid-template-areas:
			"name status"
			"date status";
		row-gap: 2px;
	}
	.cg-game .cg-item-name { grid-area: name; }
	.cg-game .cg-item-date { grid-area: date; font-size: 0.85rem; }
	.cg-game .cg-item-status { grid-area: status; }
	.cg-game .cg-item-text { display: none; }
	.cg-game .cg-cal-title { min-width: 0; }
}

/* ---------- Animations ---------- */
@keyframes cg-pop {
	from { opacity: 0; transform: scale(0.94); }
	to   { opacity: 1; transform: scale(1); }
}
@keyframes cg-fade {
	from { opacity: 0; }
	to   { opacity: 1; }
}
@keyframes cg-shake {
	0%, 100% { transform: translateX(0); }
	20%      { transform: translateX(-6px); }
	40%      { transform: translateX(6px); }
	60%      { transform: translateX(-4px); }
	80%      { transform: translateX(4px); }
}
@media (prefers-reduced-motion: reduce) {
	.cg-game *,
	.cg-game *::before,
	.cg-game *::after {
		animation-duration: 0.01ms !important;
		transition-duration: 0.01ms !important;
	}
}
