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

:root {
	--bg-deep: #0f0f1a;
	--bg-panel: #1a1a2e;
	--bg-hover: #2a2a4a;
	--border: #2a2a4a;
	--border-hi: #4a4aff;
	--text: #e0e0ff;
	--text-dim: #a0a0cc;
	--accent: #5a5aff;
	--accent-lo: #3a3a80;
	--green: #40d080;
	--red: #ff6060;
}

body {
	background: var(--bg-deep);
	color: var(--text);
	font-family: "Segoe UI", system-ui, sans-serif;
	min-height: 100vh;
}

/* Remove 300 ms tap delay on mobile for all interactive elements */
button,
input,
select {
	touch-action: manipulation;
}

.landing {
	max-width: 560px;
	margin: 0 auto;
	padding: 48px 20px;
}

.landing h1 {
	text-align: center;
	font-size: 2.4rem;
	margin-bottom: 36px;
	color: #a0a0ff;
	letter-spacing: 1px;
}

.card {
	background: var(--bg-panel);
	border: 1px solid var(--border);
	border-radius: 14px;
	padding: 28px;
	margin-bottom: 22px;
}

.card h2 {
	margin-bottom: 22px;
	font-size: 1.15rem;
	color: #c0c0ff;
}

.form-group {
	margin-bottom: 18px;
}

.form-group label {
	display: block;
	margin-bottom: 6px;
	color: var(--text-dim);
	font-size: 0.88rem;
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

.form-group input,
.form-group select {
	width: 100%;
	padding: 10px 14px;
	background: var(--bg-deep);
	border: 1px solid var(--border);
	border-radius: 8px;
	color: var(--text);
	font-size: 1rem;
	transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
	outline: none;
	border-color: var(--border-hi);
}

.form-row {
	display: flex;
	gap: 16px;
}

.form-row .form-group {
	flex: 1;
}

.btn-primary,
.btn-secondary {
	display: block;
	width: 100%;
	padding: 12px;
	border: none;
	border-radius: 8px;
	font-size: 1rem;
	font-weight: 600;
	cursor: pointer;
	transition:
		opacity 0.15s,
		transform 0.1s;
}

.btn-primary {
	background: var(--accent);
	color: #fff;
}

.btn-secondary {
	background: transparent;
	color: #c0c0ff;
	border: 1px solid var(--border-hi);
}

.btn-primary:hover,
.btn-secondary:hover {
	opacity: 0.82;
}

.btn-primary:active,
.btn-secondary:active {
	transform: scale(0.98);
}

.btn-primary:disabled,
.btn-secondary:disabled {
	opacity: 0.45;
	cursor: not-allowed;
	transform: none;
}

.status {
	margin-top: 12px;
	font-size: 0.88rem;
	color: var(--text-dim);
	min-height: 18px;
}

.preset-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 10px;
	margin-bottom: 10px;
}

.preset-card {
	cursor: pointer;
	border-radius: 10px;
	border: 2px solid var(--border);
	overflow: hidden;
	transition:
		border-color 0.15s,
		transform 0.1s;
	user-select: none;
	-webkit-tap-highlight-color: transparent;
}

.preset-card:hover {
	border-color: var(--accent);
	transform: scale(1.02);
}

.preset-card.selected {
	border-color: #a0a0ff;
	box-shadow: 0 0 0 2px var(--accent);
}

.preset-card img,
.preset-thumb {
	width: 100%;
	aspect-ratio: 3 / 2;
	display: block;
	object-fit: cover;
}

.preset-thumb {
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--bg-deep);
	font-size: 2rem;
	color: var(--text-dim);
}

.preset-name {
	display: block;
	text-align: center;
	font-size: 0.8rem;
	color: var(--text-dim);
	padding: 5px 0 4px;
	background: var(--bg-deep);
}

.upload-section {
	margin-top: 6px;
}

.upload-section input[type="file"] {
	width: 100%;
	padding: 10px 14px;
	background: var(--bg-deep);
	border: 1px solid var(--border);
	border-radius: 8px;
	color: var(--text);
	font-size: 0.9rem;
	cursor: pointer;
}

.upload-section input[type="file"]:focus {
	outline: none;
	border-color: var(--border-hi);
}

#upload-preview {
	display: block;
	margin-top: 10px;
	width: 100%;
	max-height: 220px;
	object-fit: contain;
	border-radius: 8px;
	border: 1px solid var(--border);
	background: var(--bg-deep);
}

.hidden {
	display: none !important;
}

.game-body {
	overflow: hidden;
	height: 100vh;
	display: flex;
}

.game-ui {
	display: flex;
	width: 100%;
	height: 100%;
}

.sidebar {
	width: 200px;
	min-width: 200px;
	background: var(--bg-panel);
	border-right: 1px solid var(--border);
	padding: 18px 14px;
	display: flex;
	flex-direction: column;
	gap: 20px;
	overflow-y: auto;
}

.room-info {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.room-label {
	font-size: 0.75rem;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--text-dim);
}

.room-info code {
	font-size: 1.05rem;
	color: #c0c0ff;
	letter-spacing: 1px;
}

.btn-small {
	padding: 4px 10px;
	background: transparent;
	border: 1px solid var(--border-hi);
	border-radius: 6px;
	color: #c0c0ff;
	cursor: pointer;
	font-size: 0.78rem;
	transition: background 0.15s;
	width: fit-content;
}

.btn-small:hover {
	background: var(--bg-hover);
}

.progress-section {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.progress-label {
	font-size: 0.82rem;
	color: var(--text-dim);
}

.progress-bar {
	height: 7px;
	background: var(--bg-deep);
	border-radius: 4px;
	overflow: hidden;
	border: 1px solid var(--border);
}

.progress-fill {
	height: 100%;
	background: linear-gradient(90deg, var(--accent), #a0a0ff);
	transition: width 0.4s ease;
}

.players-section h4 {
	font-size: 0.82rem;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--text-dim);
	margin-bottom: 8px;
}

.players-section ul {
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.players-section li {
	font-size: 0.88rem;
	padding: 4px 6px;
	border-radius: 5px;
	color: #c0c0ff;
}

.players-section li.me {
	background: var(--accent-lo);
	color: #d0d0ff;
	font-weight: 600;
}

.view-section {
	margin-top: auto;
	padding-top: 0.75rem;
}

.view-section .btn-small {
	width: 100%;
}

.bg-section h4 {
	margin: 0 0 0.4rem;
	font-size: 0.75rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: #8888aa;
}

.bg-swatches {
	display: flex;
	gap: 6px;
	align-items: center;
	flex-wrap: wrap;
}

.bg-swatch {
	width: 24px;
	height: 24px;
	border-radius: 50%;
	border: 2px solid transparent;
	cursor: pointer;
	padding: 0;
	outline: none;
	transition:
		border-color 0.15s,
		transform 0.1s;
	flex-shrink: 0;
}

.bg-swatch:hover {
	transform: scale(1.18);
}

.bg-swatch.active {
	border-color: #a0a0ff;
}

#bg-color-picker {
	width: 28px;
	height: 28px;
	border: none;
	background: none;
	padding: 0;
	cursor: pointer;
	border-radius: 50%;
	overflow: hidden;
	flex-shrink: 0;
}

.canvas-wrap {
	flex: 1;
	overflow: hidden;
	background: var(--bg-deep);
	position: relative;
}

#game-canvas {
	display: block;
	cursor: default;
	touch-action: none;
	-webkit-user-select: none;
	user-select: none;
}

.modal {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.72);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 100;
}

.modal-content {
	background: var(--bg-panel);
	border: 1px solid var(--border);
	border-radius: 14px;
	padding: 36px;
	width: 320px;
	text-align: center;
	display: flex;
	flex-direction: column;
	gap: 14px;
}

.modal-content h2 {
	color: #c0c0ff;
	font-size: 1.3rem;
}

.modal-content input {
	width: 100%;
	padding: 10px 14px;
	background: var(--bg-deep);
	border: 1px solid var(--border);
	border-radius: 8px;
	color: var(--text);
	font-size: 1rem;
	text-align: center;
	transition: border-color 0.2s;
}

.modal-content input:focus {
	outline: none;
	border-color: var(--border-hi);
}

.ref-panel {
	position: fixed;
	bottom: 16px;
	left: 14px;
	z-index: 50;
	width: 220px;
	background: rgba(26, 26, 46, 0.92);
	border: 1px solid var(--border-hi);
	border-radius: 10px;
	overflow: hidden;
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
	box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
	animation: ref-pop 0.18s ease;
}

@keyframes ref-pop {
	from {
		opacity: 0;
		transform: scale(0.92) translateY(8px);
	}
	to {
		opacity: 1;
		transform: scale(1) translateY(0);
	}
}

.ref-panel-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 6px 10px;
	font-size: 0.78rem;
	text-transform: uppercase;
	letter-spacing: 0.5px;
	color: var(--text-dim);
	border-bottom: 1px solid var(--border);
}

.ref-close-btn {
	background: none;
	border: none;
	color: var(--text-dim);
	cursor: pointer;
	font-size: 0.9rem;
	line-height: 1;
	padding: 0 2px;
	transition: color 0.15s;
}

.ref-close-btn:hover {
	color: var(--text);
}

.ref-img {
	width: 100%;
	display: block;
	object-fit: contain;
}

.complete-overlay {
	position: fixed;
	inset: 0;
	padding: 18px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(8, 10, 22, 0.72);
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
	z-index: 200;
	animation: complete-fade-in 0.24s ease;
}

.complete-card {
	width: min(640px, 100%);
	background:
		radial-gradient(
			circle at top right,
			rgba(80, 220, 170, 0.2),
			transparent 46%
		),
		linear-gradient(165deg, #1c2241, #151c35 56%, #122730);
	border: 1px solid rgba(120, 170, 255, 0.28);
	border-radius: 18px;
	padding: 26px;
	box-shadow:
		0 16px 48px rgba(0, 0, 0, 0.5),
		inset 0 1px 0 rgba(255, 255, 255, 0.08);
	animation: complete-pop 0.42s cubic-bezier(0.22, 1.15, 0.3, 1);
}

.complete-kicker {
	font-size: 0.76rem;
	text-transform: uppercase;
	letter-spacing: 0.09em;
	font-weight: 700;
	color: #7ce4ba;
	margin-bottom: 6px;
}

.complete-card h2 {
	font-size: clamp(1.55rem, 4vw, 2.3rem);
	margin-bottom: 4px;
	color: #f5f9ff;
}

.complete-subtitle {
	color: #c9d8f6;
	font-size: 0.98rem;
	margin-bottom: 20px;
}

.complete-stats {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 10px;
	margin-bottom: 18px;
}

.complete-stat {
	padding: 12px;
	border: 1px solid rgba(126, 165, 255, 0.25);
	border-radius: 12px;
	background: rgba(11, 18, 40, 0.5);
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.complete-stat .label {
	font-size: 0.72rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: #8ba2cf;
}

.complete-stat strong {
	font-size: clamp(1rem, 2.8vw, 1.45rem);
	color: #f4f8ff;
	font-weight: 700;
}

.complete-actions {
	display: flex;
	gap: 10px;
}

.complete-actions .btn-primary,
.complete-actions .btn-secondary {
	width: 100%;
}

@keyframes complete-fade-in {
	from {
		opacity: 0;
	}
	to {
		opacity: 1;
	}
}

@keyframes complete-pop {
	from {
		transform: translateY(8px) scale(0.96);
		opacity: 0;
	}
	to {
		transform: translateY(0) scale(1);
		opacity: 1;
	}
}

@media (max-width: 640px) {
	.complete-card {
		padding: 20px 16px;
	}

	.complete-stats {
		grid-template-columns: 1fr;
	}

	.complete-actions {
		flex-direction: column;
	}
}

.hud-icon-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	background: rgba(26, 26, 46, 0.88);
	border: 1px solid var(--border-hi);
	border-radius: 10px;
	color: #c0c0ff;
	font-size: 1.15rem;
	cursor: pointer;
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
	transition: background 0.15s;
	flex-shrink: 0;
}

.hud-icon-btn:active {
	background: var(--accent-lo);
}

/* Top HUD bar - hidden on desktop, shown on mobile */
.canvas-hud {
	display: none;
	position: absolute;
	top: 10px;
	left: 10px;
	right: 10px;
	z-index: 20;
	align-items: center;
	gap: 8px;
	pointer-events: none;
}

.canvas-hud > * {
	pointer-events: auto;
}

.hud-room-id {
	font-size: 0.95rem;
	color: #c0c0ff;
	letter-spacing: 1px;
	white-space: nowrap;
}

.hud-progress {
	flex: 1;
	display: flex;
	align-items: center;
	gap: 6px;
	min-width: 0;
}

.hud-progress-bar {
	flex: 1;
	height: 6px;
	background: rgba(15, 15, 26, 0.7);
	border-radius: 3px;
	overflow: hidden;
	border: 1px solid var(--border);
}

.hud-progress-fill {
	height: 100%;
	background: linear-gradient(90deg, var(--accent), #a0a0ff);
	transition: width 0.4s ease;
}

.hud-progress-num {
	font-size: 0.78rem;
	color: var(--text-dim);
	white-space: nowrap;
}

.hud-players {
	font-size: 0.82rem;
	color: var(--text-dim);
	white-space: nowrap;
	background: rgba(26, 26, 46, 0.88);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 4px 8px;
	backdrop-filter: blur(6px);
	-webkit-backdrop-filter: blur(6px);
}

.canvas-controls {
	position: absolute;
	bottom: 16px;
	right: 14px;
	z-index: 20;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.sidebar-backdrop {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.55);
	z-index: 29;
}

.sidebar-close {
	display: none;
	align-self: flex-end;
	background: transparent;
	border: none;
	color: var(--text-dim);
	font-size: 1.1rem;
	cursor: pointer;
	padding: 2px 4px;
	margin-bottom: 4px;
}

@media (max-width: 640px) {
	.game-ui {
		position: relative;
	}

	.sidebar {
		position: fixed;
		top: 0;
		left: 0;
		bottom: 0;
		width: 260px;
		max-width: 80vw;
		z-index: 30;
		transform: translateX(-100%);
		transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
		border-right: 1px solid var(--border-hi);
		/* ensure it covers the full height on all mobile browsers */
		height: 100%;
	}
	.sidebar.open {
		transform: translateX(0);
	}

	.sidebar-backdrop.open {
		display: block;
	}

	.sidebar-close {
		display: block;
	}

	.canvas-wrap {
		width: 100%;
	}

	/* Show the HUD bar */
	.canvas-hud {
		display: flex;
	}

	.modal-content {
		width: calc(100vw - 40px);
		padding: 28px 20px;
	}

	.landing {
		padding-top: 28px;
	}
}

.hidden {
	display: none !important;
}
