:root {
	--bg: #0f0e17;
	--surface: #1a1826;
	--panel: #221f35;
	--accent1: #ff8906;
	--accent2: #f25f4c;
	--accent3: #e53170;
	--accent4: #3da9fc;
	--accent5: #72d18f;
	--text: #fffffe;
	--muted: #a7a9be;
	--radius: 20px;
	--timer-color: #72d18f;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
	height: 100%;
	background: var(--bg);
	color: var(--text);
	font-family: 'Nunito', sans-serif;
	overflow: hidden;
	-webkit-tap-highlight-color: transparent;
	user-select: none;
}

/* skip link */
.skip-link {
	position: absolute;
	top: -999px;
	left: 8px;
	z-index: 9999;
	background: var(--accent4);
	color: #000;
	padding: 6px 14px;
	border-radius: 8px;
	font-weight: 700;
	font-size: 0.9rem;
}
.skip-link:focus { top: 8px; }

/* layout */
#app {
	display: flex;
	flex-direction: column;
	height: 100dvh;
	max-width: 480px;
	margin: 0 auto;
	padding: 0;
	position: relative;
}

/* screens */
.screen {
	display: none;
	flex-direction: column;
	flex: 1;
	align-items: center;
	justify-content: center;
	padding: 24px 20px;
	gap: 20px;
	animation: fadeIn 0.35s ease;
}
.screen.active { display: flex; }

@keyframes fadeIn { from { opacity:0; transform: translateY(12px); } to { opacity:1; transform: none; } }

/* start screen */
#start-screen {
	justify-content: flex-start;
	overflow-y: auto;
	padding-block: 20px 28px;
}

.logo-mark {
	font-family: 'Space Mono', monospace;
	font-size: 4.5rem;
	font-weight: 700;
	line-height: 1;
	letter-spacing: -3px;
	background: linear-gradient(135deg, var(--accent1), var(--accent3), var(--accent4));
	-webkit-background-clip: text;
	-webkit-text-fill-color: transparent;
	background-clip: text;
}

.game-title {
	font-size: 1.6rem;
	font-weight: 900;
	color: var(--text);
	text-align: center;
	line-height: 1.2;
}

.game-desc {
	font-size: 0.95rem;
	color: var(--muted);
	text-align: center;
	line-height: 1.6;
	max-width: 300px;
}

.instructions-heading {
	color: var(--text);
	font-size: 1.05rem;
	font-weight: 900;
	line-height: 1.25;
	text-align: center;
}

.instructions-list {
	width: min(100%, 340px);
	color: var(--text);
	font-size: 0.95rem;
	line-height: 1.45;
	list-style-position: outside;
	padding-inline-start: 1.35rem;
}

.instructions-list li {
	padding-inline-start: 0.2rem;
}

.instructions-list li + li {
	margin-top: 0.45rem;
}

.instructions-list li::marker {
	color: var(--accent5);
	font-size: 1.1em;
}

#best-game {
	width: min(100%, 340px);
	background: var(--surface);
	border: 1px solid rgba(255,255,255,0.07);
	border-radius: 16px;
	padding: 14px;
}

#best-game-heading {
	color: var(--text);
	font-size: 1rem;
	font-weight: 900;
	line-height: 1.25;
	margin-bottom: 10px;
	text-align: center;
}

#best-game-stats {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 10px;
}

.best-game-stat {
	min-width: 0;
}

.best-game-label,
.best-game-value {
	display: block;
}

.best-game-label {
	color: var(--muted);
	font-size: 0.68rem;
	font-weight: 700;
	line-height: 1.2;
}

.best-game-value {
	color: var(--text);
	font-family: 'Space Mono', monospace;
	font-size: 0.95rem;
	font-weight: 700;
	line-height: 1.25;
	overflow-wrap: anywhere;
}

.footer-panel {
	width: min(100%, 480px);
	margin: 0 auto;
	padding: 12px 20px calc(14px + env(safe-area-inset-bottom));
	background: var(--surface);
	border-top: 1px solid rgba(255,255,255,0.07);
}

.footer-links {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px 12px;
	list-style: none;
	padding: 0;
}

.footer-links a {
	color: var(--accent4);
	font-size: 0.8rem;
	font-weight: 700;
	line-height: 1.3;
	text-decoration-thickness: 2px;
	text-underline-offset: 3px;
}

.footer-links a:hover {
	color: var(--accent5);
}

.footer-links a:focus-visible {
	outline: 3px solid var(--accent4);
	outline-offset: 3px;
	border-radius: 6px;
}

.footer-copy {
	margin-top: 10px;
	text-align: center;
	line-height: 1.4;
}

.small {
	font-size: 0.75rem;
}

.muted {
	color: var(--muted);
}

.demo-bubbles {
	display: flex;
	gap: 10px;
	flex-wrap: wrap;
	justify-content: center;
	padding: 8px 0;
}

.demo-bubble {
	width: 52px;
	height: 52px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: 'Space Mono', monospace;
	font-size: 1.3rem;
	font-weight: 700;
	animation: float 3s ease-in-out infinite;
	text-transform: uppercase;
}

.demo-bubble:nth-child(1) { background: var(--accent1); color: #000; animation-delay: 0s; }
.demo-bubble:nth-child(2) { background: var(--accent4); color: #000; animation-delay: 0.4s; }
.demo-bubble:nth-child(3) { background: var(--accent3); color: #fff; animation-delay: 0.8s; }
.demo-bubble:nth-child(4) { background: var(--accent5); color: #000; animation-delay: 1.2s; }
.demo-bubble:nth-child(5) { background: var(--accent2); color: #fff; animation-delay: 0.6s; }

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

/* buttons */
.btn {
	border: none;
	border-radius: 50px;
	font-family: 'Nunito', sans-serif;
	font-weight: 900;
	cursor: pointer;
	transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
	-webkit-tap-highlight-color: transparent;
	touch-action: manipulation;
}
.btn:active { transform: scale(0.94); }
.btn:focus-visible {
	outline: 3px solid var(--accent4);
	outline-offset: 4px;
}

.btn-primary {
	background: linear-gradient(135deg, var(--accent1) 0%, var(--accent2) 100%);
	color: #000;
	font-size: 1.2rem;
	padding: 16px 48px;
	box-shadow: 0 6px 24px rgba(255,137,6,0.35);
	letter-spacing: 0.5px;
}
.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
	background: var(--panel);
	color: var(--muted);
	font-size: 0.9rem;
	padding: 10px 24px;
	border: 1px solid rgba(255,255,255,0.08);
}

/* game screen */
#game-screen {
	height: 100dvh;
	overflow: hidden;
	padding: 0;
	justify-content: flex-start;
	gap: 0;
}

#gameplayHeading {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0,0,0,0);
	white-space: nowrap;
}

/* Header bar */
#game-header {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 16px 10px;
	background: var(--surface);
	border-bottom: 1px solid rgba(255,255,255,0.06);
	flex-shrink: 0;
	gap: 10px;
}

/* Timer */
#timer-wrap {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 2px;
	min-width: 90px;
}

#timer-label {
	font-size: 0.65rem;
	font-weight: 700;
	letter-spacing: 1px;
	color: var(--muted);
}

#timer-display {
	font-family: 'Space Mono', monospace;
	font-size: 1.6rem;
	font-weight: 700;
	color: var(--timer-color);
	line-height: 1;
	transition: color 0.3s;
}

#timer-display.warning { color: var(--accent2); animation: pulse 0.7s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.5} }

/* Score */
#score-wrap {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 2px;
}

#score-label {
	font-size: 0.65rem;
	font-weight: 700;
	letter-spacing: 1px;
	color: var(--muted);
}

#score-display {
	font-family: 'Space Mono', monospace;
	font-size: 1.6rem;
	font-weight: 700;
	color: var(--accent1);
	line-height: 1;
}

/* Word count */
#words-wrap {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 2px;
	min-width: 60px;
}
#words-label {
	font-size: 0.65rem;
	font-weight: 700;
	letter-spacing: 1px;
	color: var(--muted);
	text-align: right;
}
#words-display {
	font-family: 'Space Mono', monospace;
	font-size: 1.6rem;
	font-weight: 700;
	color: var(--accent4);
	line-height: 1;
}

#chain-meter-wrap {
	width: 100%;
	display: grid;
	grid-template-columns: auto 1fr auto;
	align-items: center;
	gap: 8px;
	flex-shrink: 0;
	padding: 6px 16px;
	background: var(--surface);
	border-bottom: 1px solid rgba(255,255,255,0.06);
}

#chain-meter-label,
#chain-meter-text {
	color: var(--muted);
	font-size: 0.7rem;
	font-weight: 700;
	line-height: 1;
}

#chain-meter-text {
	color: var(--accent5);
	font-family: 'Space Mono', monospace;
	min-width: 2.5rem;
	text-align: right;
}

#chain-meter {
	width: 100%;
	height: 8px;
	border: 0;
	border-radius: 999px;
	background: var(--panel);
}

#chain-meter::-webkit-meter-bar {
	height: 8px;
	border: 0;
	border-radius: 999px;
	background: var(--panel);
}

#chain-meter::-webkit-meter-optimum-value {
	border-radius: 999px;
	background: linear-gradient(90deg, var(--accent5), var(--accent4));
}

#chain-meter::-moz-meter-bar {
	border-radius: 999px;
	background: linear-gradient(90deg, var(--accent5), var(--accent4));
}

#chain-meter-wrap.powered #chain-meter::-webkit-meter-optimum-value {
	background: linear-gradient(90deg, var(--accent1), var(--accent5), var(--accent4));
}

#chain-meter-wrap.powered #chain-meter::-moz-meter-bar {
	background: linear-gradient(90deg, var(--accent1), var(--accent5), var(--accent4));
}

/* Current word tray */
#word-tray-wrap {
	width: 100%;
	flex-shrink: 0;
	background: var(--surface);
	padding: 6px 16px 8px;
	border-bottom: 1px solid rgba(255,255,255,0.06);
}

#word-tray-label {
	color: var(--muted);
	font-size: 0.65rem;
	font-weight: 700;
	line-height: 1;
	margin-bottom: 5px;
}

#word-tray {
	display: flex;
	gap: 6px;
	align-items: center;
	height: 40px;
	overflow-x: auto;
	overflow-y: hidden;
	flex-wrap: nowrap;
	scrollbar-width: none;
}

#word-tray::-webkit-scrollbar {
	display: none;
}

#word-tray-empty {
	color: var(--muted);
	font-size: 0.85rem;
	line-height: 1.2;
	white-space: nowrap;
}

.tray-letter {
	width: 36px;
	height: 36px;
	flex: 0 0 36px;
	border-radius: 10px;
	background: var(--accent4);
	color: #000;
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: 'Space Mono', monospace;
	font-size: 1.1rem;
	font-weight: 700;
	animation: popIn 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
	text-transform: uppercase;
}
@keyframes popIn { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Bubble field */
#bubble-table {
	flex: 1;
	width: 100%;
	min-height: 0;
	padding: 10px 8px;
	border-collapse: separate;
	border-spacing: 6px;
	table-layout: fixed;
	overflow: hidden;
}

#bubble-table caption {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0,0,0,0);
	white-space: nowrap;
}

#bubble-field tr {
	height: 20%;
}

#bubble-field td {
	padding: 0;
	width: 20%;
}

/* Individual bubble */
.bubble {
	width: 100%;
	height: 100%;
	aspect-ratio: 1;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: 'Space Mono', monospace;
	font-size: 1.45rem;
	font-weight: 700;
	cursor: pointer;
	border: none;
	transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.12s, opacity 0.12s, background 0.2s, color 0.2s;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
	position: relative;
	box-shadow: 0 4px 14px rgba(0,0,0,0.3);
	animation: bubbleIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes bubbleIn {
	from { transform: scale(0) rotate(-20deg); opacity: 0; }
	to { transform: scale(1) rotate(0deg); opacity: 1; }
}

.bubble:hover { transform: scale(1.08); }
.bubble:active { transform: scale(0.9); }
.bubble:focus-visible {
	outline: 3px solid #fff;
	outline-offset: 3px;
	transform: scale(1.08);
}

.bubble.selected {
	transform: scale(0.88);
	background: #3a3a4a !important;
	color: #6b6b80 !important;
	box-shadow: none;
	cursor: default;
}

.bubble.popping {
	animation: pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes pop {
	0% { transform: scale(0.88); opacity: 0.55; }
	50% { transform: scale(1.4); opacity: 1; }
	100% { transform: scale(0); opacity: 0; }
}

/* Bubble colors — 8 palette entries */
.bubble[data-color="0"] { background: var(--accent1); color: #000; }
.bubble[data-color="1"] { background: var(--accent2); color: #fff; }
.bubble[data-color="2"] { background: var(--accent3); color: #fff; }
.bubble[data-color="3"] { background: var(--accent4); color: #000; }
.bubble[data-color="4"] { background: var(--accent5); color: #000; }
.bubble[data-color="5"] { background: #b8c0ff; color: #000; }
.bubble[data-color="6"] { background: #ffd166; color: #000; }
.bubble[data-color="7"] { background: #ef85a8; color: #000; }

/* Bottom action bar */
#action-bar {
	width: 100%;
	flex-shrink: 0;
	display: flex;
	gap: 10px;
	min-height: 80px;
	padding: 10px 12px calc(18px + env(safe-area-inset-bottom));
	background: var(--surface);
	border-top: 1px solid rgba(255,255,255,0.07);
}

#btn-clear {
	background: var(--panel);
	color: var(--muted);
	font-size: 0.85rem;
	padding: 0 14px;
	height: 52px;
	border-radius: 14px;
	border: 1px solid rgba(255,255,255,0.08);
	flex-shrink: 0;
}
#btn-clear:focus-visible { outline: 3px solid var(--accent4); outline-offset: 4px; }

#btn-make-word {
	flex: 1;
	height: 52px;
	border-radius: 14px;
	background: linear-gradient(135deg, var(--accent5) 0%, var(--accent4) 100%);
	color: #000;
	font-size: 1.05rem;
	font-weight: 900;
	border: none;
	cursor: pointer;
	touch-action: manipulation;
	font-family: 'Nunito', sans-serif;
	letter-spacing: 0.3px;
	box-shadow: 0 4px 18px rgba(61,169,252,0.3);
	transition: transform 0.12s, filter 0.12s, box-shadow 0.12s;
}
#btn-make-word:disabled {
	background: var(--panel);
	color: var(--muted);
	box-shadow: none;
	cursor: not-allowed;
}
#btn-make-word:not(:disabled):active { transform: scale(0.95); }
#btn-make-word:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }

#btn-end-game {
	background: rgba(242,95,76,0.15);
	color: var(--accent2);
	font-size: 0.85rem;
	padding: 0 14px;
	height: 52px;
	border-radius: 14px;
	border: 1px solid rgba(242,95,76,0.25);
	flex-shrink: 0;
	font-family: 'Nunito', sans-serif;
	font-weight: 700;
	cursor: pointer;
	touch-action: manipulation;
	transition: background 0.15s;
}
#btn-end-game:hover { background: rgba(242,95,76,0.25); }
#btn-end-game:active { transform: scale(0.95); }
#btn-end-game:focus-visible { outline: 3px solid var(--accent2); outline-offset: 4px; }

/* Word success toast */
#toast {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%) scale(0.8);
	background: var(--accent5);
	color: #000;
	font-family: 'Space Mono', monospace;
	font-size: 1.4rem;
	font-weight: 700;
	padding: 14px 28px;
	border-radius: 16px;
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.2s, transform 0.2s;
	z-index: 100;
	white-space: nowrap;
	max-width: 90vw;
	text-align: center;
	word-break: break-word;
	white-space: normal;
}
#toast.show {
	opacity: 1;
	transform: translate(-50%, -50%) scale(1);
}

/* result screen */
#result-screen {
	gap: 16px;
	padding: 24px 20px 32px;
}

.result-header {
	font-family: 'Space Mono', monospace;
	font-size: 1rem;
	font-weight: 700;
	color: var(--muted);
	letter-spacing: 2px;
	text-align: center;
}

.result-score {
	font-family: 'Space Mono', monospace;
	font-size: 4rem;
	font-weight: 700;
	background: linear-gradient(135deg, var(--accent1), var(--accent3));
	-webkit-background-clip: text;
	-webkit-text-fill-color: transparent;
	background-clip: text;
	line-height: 1;
}

.result-sub {
	font-size: 1rem;
	color: var(--muted);
}

#words-list-wrap {
	width: 100%;
	background: var(--surface);
	border-radius: var(--radius);
	padding: 16px;
	max-height: 240px;
	overflow-y: auto;
	border: 1px solid rgba(255,255,255,0.07);
}

#words-list-title {
	color: var(--text);
	font-size: 1rem;
	font-weight: 900;
	line-height: 1.25;
	margin-bottom: 10px;
}

#words-list {
	display: grid;
	gap: 8px;
	list-style: decimal;
	padding-inline-start: 1.7rem;
}

.word-chip {
	background: var(--panel);
	color: var(--text);
	font-family: 'Space Mono', monospace;
	font-size: 0.85rem;
	line-height: 1.4;
	padding: 5px 12px;
	border-radius: 12px;
	border: 1px solid rgba(255,255,255,0.08);
}

.word-chip::marker {
	color: var(--accent5);
	font-family: 'Space Mono', monospace;
	font-weight: 700;
}

/* primary game announcer */
#game-announcer {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0,0,0,0);
	white-space: nowrap;
}

/* Bonus time flash on the timer */
@keyframes bonusFlash {
	0%   { color: var(--accent5); transform: scale(1.25); }
	40%  { color: var(--accent5); transform: scale(1.15); }
	100% { color: var(--timer-color); transform: scale(1); }
}
.timer-bonus {
	animation: bonusFlash 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* +15s badge that pops up briefly */
#bonus-badge {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%) scale(0.5);
	background: var(--accent5);
	color: #000;
	font-family: 'Space Mono', monospace;
	font-size: 1.6rem;
	font-weight: 700;
	padding: 12px 28px;
	border-radius: 50px;
	pointer-events: none;
	opacity: 0;
	z-index: 200;
	transition: none;
	white-space: nowrap;
}
#bonus-badge.show {
	animation: badgePop 1.1s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes badgePop {
	0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
	20%  { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
	60%  { opacity: 1; transform: translate(-50%, -50%) scale(1.0); }
	100% { opacity: 0; transform: translate(-50%, -50%) scale(0.85); }
}

.start-desc {
	font-size: 0.8rem;
	margin-top: -8px;
}

#result-stats {
	display: flex;
	gap: 24px;
	justify-content: center;
	width: 100%;
}

.result-stat {
	text-align: center;
}

.result-stat-value {
	font-family: 'Space Mono', monospace;
	font-size: 2rem;
	font-weight: 700;
}

.result-stat-word-count { color: var(--accent4); }
.result-stat-letters-used { color: var(--accent5); }
.result-stat-average { color: var(--accent1); }

.result-stat-label {
	font-size: 0.7rem;
	letter-spacing: 1px;
	color: var(--muted);
	font-weight: 700;
	margin-top: 2px;
}
