/* Anagram Challenge — all rules scoped to .ac-game. */
.ac-game {
	--ac-accent: #f5b301;
	--ac-accent-ink: #1b1b1b;
	--ac-ink: #1d1b26;
	--ac-muted: color-mix(in srgb, var(--ac-ink) 58%, transparent);
	--ac-line: color-mix(in srgb, var(--ac-ink) 12%, transparent);
	--ac-surface: #ffffff;
	--ac-tile: #eef0f6;
	--ac-good: #1f9d55;
	--ac-bad: #d64545;
	--ac-radius: 18px;

	box-sizing: border-box;
	max-width: 920px;
	margin: 1.5em auto;
	padding: clamp(16px, 3vw, 28px);
	border: 1px solid var(--ac-line);
	border-radius: 22px;
	background: var(--ac-surface);
	color: var(--ac-ink);
	font-family: inherit;
	box-shadow: 0 10px 40px -20px rgba(20, 20, 50, 0.35);
}
.ac-game *,
.ac-game *::before,
.ac-game *::after { box-sizing: border-box; }
.ac-game [hidden] { display: none !important; }

.ac-game .ac-title {
	margin: 0 0 14px;
	font-size: clamp(1.4rem, 3vw, 1.9rem);
	font-weight: 800;
	letter-spacing: -0.02em;
	text-align: center;
	color: inherit;
}
.ac-loading,
.ac-error { text-align: center; color: var(--ac-muted); padding: 40px 0; margin: 0; }
.ac-error { color: var(--ac-bad); }

/* ---------- Buttons ---------- */
.ac-game .ac-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 0 20px;
	border: 1px solid var(--ac-line);
	border-radius: 999px;
	background: var(--ac-surface);
	color: var(--ac-ink);
	font: inherit;
	font-size: 0.95rem;
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
	transition: scale 0.08s ease, background-color 0.15s ease, box-shadow 0.15s ease;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}
.ac-game .ac-btn:hover { background: var(--ac-tile); }
/* `scale` (not `transform`) so pressing a letter tile never overrides the transform that positions it. */
.ac-game .ac-btn:active { scale: 0.94; }
.ac-game .ac-btn:focus-visible { outline: 3px solid var(--ac-accent); outline-offset: 2px; }
.ac-game .ac-primary {
	border-color: var(--ac-ink);
	background: var(--ac-ink);
	color: #fff;
}
.ac-game .ac-primary:hover { background: color-mix(in srgb, var(--ac-ink) 85%, #fff); }
.ac-game .ac-link {
	min-height: 32px;
	padding: 0 12px;
	border: 0;
	background: transparent;
	color: var(--ac-muted);
	font-size: 0.85rem;
	text-decoration: underline;
}
.ac-game .ac-big { min-height: 52px; padding: 0 36px; font-size: 1.05rem; }

/* ---------- Top bar + rank ---------- */
.ac-top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 10px;
	font-variant-numeric: tabular-nums;
}
.ac-label { font-size: 0.8rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ac-muted); }
.ac-score { font-weight: 800; font-size: 1.05rem; }
.ac-timer {
	padding: 6px 14px;
	border-radius: 999px;
	background: var(--ac-tile);
	font-weight: 800;
	font-size: 1.05rem;
}
.ac-timer.is-low { background: var(--ac-bad); color: #fff; animation: ac-pulse 1s ease-in-out infinite; }
@keyframes ac-pulse { 50% { transform: scale(1.06); } }

.ac-rank { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.ac-rank-name { min-width: 92px; font-weight: 800; }
.ac-rank-bar { position: relative; flex: 1; height: 6px; border-radius: 999px; background: var(--ac-line); }
.ac-rank-fill {
	height: 100%;
	width: 0;
	border-radius: inherit;
	background: var(--ac-accent);
	transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.ac-rank-dot {
	position: absolute;
	top: 50%;
	width: 10px;
	height: 10px;
	margin: -5px 0 0 -5px;
	border-radius: 50%;
	background: var(--ac-surface);
	border: 2px solid var(--ac-line);
}

/* ---------- Layout ---------- */
.ac-layout {
	display: grid;
	grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
	gap: clamp(18px, 3vw, 36px);
	align-items: start;
}

/* ---------- Play area ---------- */
.ac-play {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 16px;
	padding-top: 8px;
}
.ac-toast {
	position: absolute;
	top: -6px;
	left: 50%;
	z-index: 3;
	padding: 8px 16px;
	border-radius: 999px;
	font-size: 0.9rem;
	font-weight: 700;
	white-space: nowrap;
	background: var(--ac-ink);
	color: #fff;
	opacity: 0;
	transform: translate(-50%, 6px);
	pointer-events: none;
	transition: opacity 0.2s ease, transform 0.2s ease;
}
.ac-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.ac-toast.is-good { background: var(--ac-good); }
.ac-toast.is-pangram { background: var(--ac-accent); color: var(--ac-accent-ink); }

.ac-current {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 56px;
	margin-top: 26px;
	font-size: clamp(1.8rem, 5vw, 2.4rem);
	font-weight: 800;
	letter-spacing: 0.08em;
}
.ac-cur-letter.is-new { animation: ac-pop 0.18s ease-out; }
.ac-caret {
	width: 3px;
	height: 1.1em;
	margin-left: 4px;
	background: var(--ac-accent);
	animation: ac-blink 1s steps(1) infinite;
}
@keyframes ac-blink { 50% { opacity: 0; } }
@keyframes ac-pop { from { transform: translateY(6px); opacity: 0; } }
.ac-current.is-shake,
.ac-game .is-shake { animation: ac-shake 0.35s ease; }
@keyframes ac-shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }

/* Flower of 7 letters: one in the middle, six around it */
.ac-wheel {
	--size: clamp(58px, 15vw, 76px);
	--ring: calc(var(--size) * 1.12);
	position: relative;
	width: calc(var(--size) + var(--ring) * 2);
	height: calc(var(--size) + var(--ring) * 2);
}
.ac-game .ac-tile {
	--a: 0deg;
	position: absolute;
	top: 50%;
	left: 50%;
	width: var(--size);
	height: var(--size);
	min-height: 0;
	margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2);
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--ac-tile);
	color: var(--ac-ink);
	font-size: calc(var(--size) * 0.44);
	font-weight: 800;
	text-transform: uppercase;
	transform: rotate(var(--a)) translateY(calc(var(--ring) * -1)) rotate(calc(var(--a) * -1));
	transition: transform 0.45s cubic-bezier(0.3, 1.4, 0.5, 1), scale 0.08s ease, background-color 0.15s ease, opacity 0.15s ease;
	box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.08);
	/* Fast repeated taps on phones: no double-tap zoom, no grey flash, no text selection. */
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
	user-select: none;
	-webkit-user-select: none;
}
.ac-game .ac-tile:hover { background: color-mix(in srgb, var(--ac-tile) 80%, var(--ac-ink)); }
/* The middle letter looks like the others: no letter is compulsory in this game. */
.ac-game .ac-tile.ac-pos-0 { transform: none; }
.ac-game .ac-pos-1 { --a: 0deg; }
.ac-game .ac-pos-2 { --a: 60deg; }
.ac-game .ac-pos-3 { --a: 120deg; }
.ac-game .ac-pos-4 { --a: 180deg; }
.ac-game .ac-pos-5 { --a: 240deg; }
.ac-game .ac-pos-6 { --a: 300deg; }
.ac-game .ac-tile.is-used { opacity: 0.28; }
.ac-wheel.is-shuffling .ac-tile { animation: ac-spin 0.45s ease; }
@keyframes ac-spin { 50% { opacity: 0.2; } }

.ac-controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.ac-game .ac-controls .ac-btn { padding: 0 16px; }

.ac-hint { margin: 0; font-size: 0.85rem; color: var(--ac-muted); text-align: center; }

/* ---------- "How to play" card (start of game, or from the ? button) ---------- */
/* While the card is open it takes the board's place, so the game box grows to fit it. */
.ac-reading .ac-rank,
.ac-reading .ac-layout,
.ac-reading .ac-end { display: none !important; }
.ac-start {
	display: flex;
	justify-content: center;
	padding: 6px 0 4px;
}
.ac-start-card {
	width: 100%;
	max-width: 540px;
	padding: clamp(18px, 3vw, 28px);
	border: 1px solid var(--ac-line);
	border-radius: var(--ac-radius);
	background: var(--ac-surface);
	box-shadow: 0 18px 44px -24px rgba(20, 20, 50, 0.45);
	font-size: 0.95rem;
	text-align: center;
}
.ac-game .ac-rules-title { margin: 0 0 12px; font-size: 1.3rem; font-weight: 800; color: inherit; }
.ac-game .ac-rules {
	margin: 0 0 14px;
	padding: 0;
	list-style: none;
	counter-reset: ac-rule;
	text-align: left;
}
.ac-game .ac-rules li {
	position: relative;
	margin: 0 0 10px;
	padding-left: 38px;
	font-size: 0.95rem;
	line-height: 1.5;
	counter-increment: ac-rule;
}
.ac-game .ac-rules li::before {
	content: counter(ac-rule);
	position: absolute;
	left: 0;
	top: 0;
	display: grid;
	place-items: center;
	width: 26px;
	height: 26px;
	border-radius: 50%;
	background: var(--ac-accent);
	color: var(--ac-accent-ink);
	font-size: 0.85rem;
	font-weight: 800;
}
.ac-scoring,
.ac-keys {
	margin: 0 0 8px;
	padding: 10px 12px;
	border-radius: 12px;
	background: var(--ac-tile);
	font-size: 0.88rem;
	line-height: 1.5;
}
.ac-keys { background: transparent; padding: 0; color: var(--ac-muted); font-size: 0.8rem; }
.ac-choose-label { margin: 16px 0 8px; font-weight: 800; }
.ac-time-options { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 18px; }
.ac-game .ac-time-option[aria-checked="true"] {
	border-color: var(--ac-accent);
	background: var(--ac-accent);
	color: var(--ac-accent-ink);
}
.ac-start-time { margin: 12px 0 16px; font-weight: 800; }
.ac-start-card .ac-big { margin-top: 6px; }

.ac-top-right { display: inline-flex; align-items: center; gap: 10px; }
.ac-game .ac-help {
	width: 32px;
	min-height: 32px;
	height: 32px;
	padding: 0;
	border-radius: 50%;
	font-weight: 800;
}

/* ---------- Found words ---------- */
.ac-found {
	padding: 18px;
	border-radius: var(--ac-radius);
	background: color-mix(in srgb, var(--ac-tile) 55%, var(--ac-surface));
	min-height: 100%;
}
.ac-found-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.ac-found-count { font-weight: 800; font-variant-numeric: tabular-nums; }
.ac-groups { display: grid; gap: 14px; }
.ac-group-title {
	display: flex;
	justify-content: space-between;
	margin-bottom: 6px;
	font-size: 0.75rem;
	font-weight: 700;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--ac-muted);
	font-variant-numeric: tabular-nums;
}
.ac-group.is-complete .ac-group-tally { color: var(--ac-good); }
.ac-game .ac-list {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	min-height: 30px;
	margin: 0;
	padding: 0;
	list-style: none;
}
.ac-game .ac-list li {
	margin: 0;
	padding: 5px 11px;
	border-radius: 999px;
	background: var(--ac-surface);
	border: 1px solid var(--ac-line);
	font-size: 0.9rem;
	font-weight: 600;
	text-transform: capitalize;
}
.ac-game .ac-list li.is-new { animation: ac-new 0.6s ease; border-color: var(--ac-good); }
@keyframes ac-new { from { transform: scale(1.3); background: var(--ac-good); color: #fff; } }
.ac-game .ac-list li.is-pangram { background: var(--ac-accent); border-color: var(--ac-accent); color: var(--ac-accent-ink); }
.ac-game .ac-list li.is-missed { background: transparent; border-style: dashed; color: var(--ac-muted); font-weight: 500; }

/* ---------- End panel ---------- */
.ac-end {
	margin-bottom: 20px;
	padding: 18px 20px;
	border-radius: var(--ac-radius);
	background: var(--ac-ink);
	color: #fff;
	text-align: center;
}
.ac-end p { margin: 0 0 8px; }
.ac-end-title { font-size: 1.3rem; font-weight: 800; }
.ac-end-note { opacity: 0.75; font-size: 0.9rem; }
.ac-end-actions { margin-top: 12px; }
.ac-game .ac-end .ac-primary { background: var(--ac-accent); border-color: var(--ac-accent); color: var(--ac-accent-ink); }
.ac-over .ac-wheel,
.ac-over .ac-controls,
.ac-over .ac-current { opacity: 0.35; pointer-events: none; }

/* Pangram celebration */
.ac-celebrate .ac-wheel { animation: ac-celebrate 0.7s ease; }
@keyframes ac-celebrate { 30% { transform: scale(1.08) rotate(6deg); } 60% { transform: scale(0.98) rotate(-3deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
	.ac-layout { grid-template-columns: 1fr; }
	.ac-rank-name { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) {
	.ac-game *,
	.ac-game *::before,
	.ac-game *::after { animation: none !important; transition: none !important; }
}
