:root {
	--bg: #0b0f14;
	--panel: #131a22;
	--border: #24303d;
	--text: #d7e0ea;
	--muted: #7a8a99;
	--green: #22c55e;
	--cyan: #06b6d4;
	--amber: #f59e0b;
	--fuchsia: #d946ef;
	--purple: #873bf6;
	--food: #ef4444;
}

* {
	box-sizing: border-box;
}

html,
body {
	/* No pull-to-refresh or scroll-bounce while swiping to steer. */
	overscroll-behavior: none;
}

body {
	margin: 0;
	min-height: 100vh;
	background: var(--bg);
	color: var(--text);
	font-family: "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
	display: flex;
	align-items: center;
	justify-content: center;
}

.hidden {
	display: none !important;
}

/* ---- Screens ---- */

.screen {
	display: none;
	flex-direction: column;
	align-items: center;
	gap: 24px;
	padding: 24px;
	border:1px solid var(--border);
	border-radius:32px;
}

.screen.active {
	display: flex;
}

.title {
	font-size: 44px;
	letter-spacing: 4px;
	margin: 0;
	color: var(--green);
	text-shadow: 0 0 6px currentColor, 0 0 18px currentColor;
}

.panel {
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 24px;
	display: flex;
	flex-direction: column;
	gap: 12px;
	min-width: 300px;
	align-items: stretch;
}

label,
.lobby-label {
	color: var(--muted);
	font-size: 13px;
	margin: 0;
}

input {
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: 6px;
	color: var(--text);
	font: inherit;
	padding: 10px 12px;
	outline: none;
}

input:focus {
	border-color: var(--muted);
}

#code-input {
	text-transform: uppercase;
	letter-spacing: 3px;
	width: 110px;
}

button {
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 6px;
	color: var(--text);
	font: inherit;
	padding: 10px 16px;
	cursor: pointer;
}

button:hover {
	border-color: var(--muted);
}

button.primary {
	background: #16321f;
	border-color: var(--green);
	color: var(--green);
}

button.primary:hover {
	box-shadow: 0 0 10px rgba(34, 197, 94, 0.4);
}

button.primary.armed {
	background: var(--green);
	color: var(--bg);
}

button:disabled {
	opacity: 0.45;
	cursor: default;
	box-shadow: none;
}

button.linkish {
	background: none;
	border: none;
	color: var(--muted);
	text-decoration: underline;
	padding: 4px;
}

.home-actions {
	display: flex;
	flex-direction: column;
	gap: 12px;
	margin-top: 8px;
}

.join-row {
	display: flex;
	gap: 8px;
	justify-content: center;
}

.join-row button {
	flex: 1;
}

.error {
	color: var(--food);
	font-size: 13px;
	margin: 0;
	text-align: center;
}

.hint {
	color: var(--muted);
	font-size: 13px;
	margin: 0;
	text-align: center;
	min-height: 1.2em;
}

/* ---- Color swatches ---- */

.swatches {
	display: flex;
	gap: 10px;
	justify-content: center;
}

.swatch {
	width: 34px;
	height: 34px;
	border-radius: 50%;
	border: 2px solid transparent;
	padding: 0;
	background: currentColor;
}

.swatch.selected {
	border-color: var(--text);
	box-shadow: 0 0 10px currentColor;
}

.swatch:disabled {
	opacity: 0.25;
}

/* ---- Lobby ---- */

.room-code {
	font-size: 34px;
	letter-spacing: 8px;
	text-align: center;
	color: var(--cyan);
	text-shadow: 0 0 8px currentColor;
	background: none;
	border: 1px dashed var(--border);
	padding: 12px;
}

.player-list {
	list-style: none;
	margin: 8px 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.player-list li {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 10px;
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: 6px;
}

.dot {
	width: 12px;
	height: 12px;
	border-radius: 50%;
	background: currentColor;
	box-shadow: 0 0 8px currentColor;
	flex: none;
}

.player-list .status {
	margin-left: auto;
	color: var(--muted);
	font-size: 13px;
}

.player-list .status.ready {
	color: var(--green);
}

/* ---- Game grid ---- */

.game-layout {
	display: flex;
	gap: 24px;
	align-items: flex-start;
}

#grid {
	/* Cells shrink with the viewport so 20 columns always fit on a phone;
	   70px ≈ screen + grid padding and borders. */
	--cell: min(22px, calc((100vw - 70px) / 20));
	margin: 0;
	line-height: 0;
	background: #070a0e;
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 10px;
	user-select: none;
}

/* The glyphs (■ ● 　) are ambiguous-width, so don't trust the font for
   alignment — fixed inline-block cells guarantee the grid. */
.cell {
	display: inline-block;
	width: var(--cell);
	height: var(--cell);
	line-height: var(--cell);
	font-size: calc(var(--cell) * 0.72);
	text-align: center;
	vertical-align: top;
}

.c-green { color: var(--green); text-shadow: 0 0 4px currentColor, 0 0 10px currentColor; }
.c-cyan { color: var(--cyan); text-shadow: 0 0 4px currentColor, 0 0 10px currentColor; }
.c-amber { color: var(--amber); text-shadow: 0 0 4px currentColor, 0 0 10px currentColor; }
.c-fuchsia { color: var(--fuchsia); text-shadow: 0 0 4px currentColor, 0 0 10px currentColor; }
.c-purple { color: var(--purple); text-shadow: 0 0 4px currentColor, 0 0 10px currentColor; }
.food { color: var(--food); text-shadow: 0 0 4px currentColor, 0 0 10px currentColor; }

/* ---- Scoreboard ---- */

.scoreboard {
	display: flex;
	flex-direction: column;
	gap: 10px;
	min-width: 180px;
}

.score-row {
	display: flex;
	align-items: center;
	gap: 10px;
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 8px 12px;
}

.score-row .len {
	margin-left: auto;
}

.score-row.dead {
	opacity: 0.45;
}

.score-row .tag {
	font-size: 12px;
	color: var(--muted);
}

/* ---- Overlays & modals ---- */

.overlay {
	position: fixed;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 10;
}

.overlay.dim {
	background: rgba(4, 6, 9, 0.75);
}

.countdown-number {
	font-size: 140px;
	color: var(--amber);
	text-shadow: 0 0 12px currentColor, 0 0 40px currentColor;
	animation: pop 0.9s ease-out;
}

@keyframes pop {
	from { transform: scale(1.6); opacity: 0.3; }
	to { transform: scale(1); opacity: 1; }
}

.modal {
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 28px 36px;
	text-align: center;
	min-width: 300px;
}

.modal h2 {
	margin: 0 0 12px;
	font-size: 30px;
}

#modal-winner h2 {
	color: var(--amber);
	text-shadow: 0 0 10px currentColor;
}

#modal-died h2 {
	color: var(--food);
	text-shadow: 0 0 10px currentColor;
}

.modal p {
	color: var(--muted);
	margin: 0 0 16px;
}

.stats-table {
	border-collapse: collapse;
	margin: 0 auto 18px;
}

.stats-table th,
.stats-table td {
	padding: 6px 12px;
	text-align: left;
	font-size: 14px;
}

.stats-table th {
	color: var(--muted);
	font-weight: normal;
	border-bottom: 1px solid var(--border);
}

/* ---- Mobile ---- */

@media (max-width: 760px) {
	.screen {
		padding: 12px;
		border-radius: 16px;
	}

	/* Scoreboard collapses from sidebar to a wrapping strip under the grid. */
	.game-layout {
		flex-direction: column;
		align-items: center;
		gap: 12px;
	}

	.scoreboard {
		flex-direction: row;
		flex-wrap: wrap;
		width: 100%;
		min-width: 0;
	}

	.score-row {
		flex: 1 1 40%;
	}

	.modal {
		min-width: 0;
		max-width: 90vw;
	}
}

/* Swipes on the game screen steer the snake instead of scrolling. */
#screen-game {
	touch-action: none;
}

/* ---- RTT readout ---- */

.rtt {
	position: fixed;
	bottom: 8px;
	right: 12px;
	font-size: 12px;
	color: var(--muted);
	z-index: 5;
}

/* ---- Disconnect banner ---- */

.banner {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	background: #3a1114;
	border-bottom: 1px solid var(--food);
	color: var(--text);
	padding: 10px 16px;
	display: flex;
	gap: 16px;
	align-items: center;
	justify-content: center;
	z-index: 20;
}
