:root {
	--bg: #0b1020;
	--surface: #131a2e;
	--surface-2: #1a2240;
	--border: #283057;
	--text: #e6e9f5;
	--muted: #8b93b8;
	--accent: #6366f1;
	--accent-hover: #818cf8;
	--danger: #ef4444;
	--success: #22c55e;
	--shadow: 0 1px 2px rgba(0,0,0,0.4), 0 12px 32px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
	background: radial-gradient(circle at 20% 0%, #1a2547 0%, var(--bg) 55%);
	min-height: 100vh;
	color: var(--text);
	font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	-webkit-font-smoothing: antialiased;
	font-size: 15px;
	line-height: 1.5;
}

.topbar {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 1.25rem 2rem;
	border-bottom: 1px solid var(--border);
	background: rgba(11, 16, 32, 0.6);
	backdrop-filter: blur(6px);
}

.logo {
	display: inline-flex;
	align-items: center;
	gap: 0.55rem;
	user-select: none;
}

/* A raised minesweeper tile holding a bomb — the brand mark. */
.logo-tile {
	display: inline-grid;
	place-items: center;
	width: 2rem;
	height: 2rem;
	border-radius: 9px;
	background: linear-gradient(160deg, #4f93f7, #2563eb);
	box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.32),
		inset 0 -3px 0 rgba(0, 0, 0, 0.28),
		0 3px 8px rgba(2, 6, 23, 0.5);
	transform: rotate(-5deg);
	transition: transform 0.18s cubic-bezier(.34,1.56,.64,1);
}

.logo:hover .logo-tile { transform: rotate(0deg) scale(1.06); }

.logo-mine {
	width: 0.95rem;
	height: 0.95rem;
	border-radius: 50%;
	background: radial-gradient(circle at 34% 30%, #fff 0 14%, #0f172a 15% 100%);
	box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.35);
}

.logo-name {
	font-size: 1.3rem;
	font-weight: 800;
	letter-spacing: -0.01em;
	background: linear-gradient(90deg, #e6e9f5 0%, #a5b4fc 60%, #818cf8 100%);
	-webkit-background-clip: text;
	background-clip: text;
	color: transparent;
}

.topbar-right {
	display: flex;
	align-items: center;
	gap: 1rem;
}

.audio-control {
	display: flex;
	align-items: center;
	gap: 0.4rem;
}

.audio-control #mute_button {
	font-size: 1rem;
	padding: 0.3rem 0.45rem;
	line-height: 1;
}

#volume_slider {
	width: 84px;
	accent-color: var(--accent);
	cursor: pointer;
}

.user-badge {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	font-size: 0.9rem;
	color: var(--muted);
}

.user-badge strong { color: var(--text); font-weight: 600; }

input[type="text"] {
	background: var(--surface);
	border: 1px solid var(--border);
	color: var(--text);
	border-radius: 8px;
	padding: 0.6rem 0.85rem;
	font-size: 0.95rem;
	font-family: inherit;
}

input[type="text"]:focus {
	outline: none;
	border-color: var(--accent);
	box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

select {
	background: var(--surface);
	border: 1px solid var(--border);
	color: var(--text);
	border-radius: 8px;
	padding: 0.4rem 0.6rem;
	font-size: 0.9rem;
	font-family: inherit;
	cursor: pointer;
}
select:disabled { opacity: 0.6; cursor: not-allowed; }

main {
	max-width: 1200px;
	margin: 0 auto;
	padding: 2rem;
}

.view { animation: fade 180ms ease; }

@keyframes fade {
	from { opacity: 0; transform: translateY(4px); }
	to { opacity: 1; transform: translateY(0); }
}

/* Name view */
.name-view {
	display: flex;
	justify-content: center;
	align-items: flex-start;
	padding-top: 4rem;
}

.name-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 14px;
	padding: 2rem 2.25rem;
	box-shadow: var(--shadow);
	width: 100%;
	max-width: 420px;
}

.name-card h2 { margin: 0 0 0.4rem; font-size: 1.4rem; }
.name-subtitle { color: var(--muted); margin: 0 0 1.25rem; }

.signin-options {
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
	margin: 0.5rem 0 1.25rem;
}

.signin-note { color: var(--muted); font-size: 0.85rem; margin: 0.1rem 0 0; }

.signin-divider {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	color: var(--muted);
	font-size: 0.8rem;
	margin-top: 0.4rem;
}

.signin-divider::before, .signin-divider::after {
	content: "";
	flex: 1;
	height: 1px;
	background: var(--border);
}

.rating-chip {
	background: var(--accent);
	color: #fff;
	font-weight: 700;
	font-size: 0.8rem;
	padding: 0.1rem 0.5rem;
	border-radius: 999px;
	font-variant-numeric: tabular-nums;
}

.leaderboard-card { margin-bottom: 1.5rem; }

.leaderboard-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.3rem;
}

.lb-row {
	display: grid;
	grid-template-columns: 1.75rem 1fr auto auto;
	align-items: center;
	gap: 0.6rem;
	padding: 0.45rem 0.7rem;
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.02);
	border: 1px solid transparent;
}

.lb-row-me { background: rgba(99, 102, 241, 0.12); border-color: rgba(99, 102, 241, 0.3); }
.lb-rank { color: var(--muted); font-size: 0.85rem; text-align: right; }
.lb-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-tier { font-size: 0.8rem; font-weight: 700; }
.lb-rating { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 3.5ch; text-align: right; }

.rating-chip-bump {
	animation: rating-bump 0.6s ease-out;
}

@keyframes rating-bump {
	0% { transform: scale(1); }
	35% { transform: scale(1.35); }
	100% { transform: scale(1); }
}

.ranked-panel {
	background: linear-gradient(135deg, rgba(99,102,241,0.18), rgba(99,102,241,0.06));
	border: 1px solid rgba(99,102,241,0.4);
	border-radius: 12px;
	padding: 1rem 1.25rem;
	margin-bottom: 1.5rem;
}

.ranked-cta {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
}

.ranked-title { margin: 0; font-size: 1.2rem; }
.ranked-sub { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.85rem; }

.ranked-searching {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	margin-top: 0.85rem;
	color: var(--text);
	font-size: 0.9rem;
}

.ranked-spinner {
	width: 16px;
	height: 16px;
	border: 2px solid rgba(255,255,255,0.25);
	border-top-color: var(--accent-hover);
	border-radius: 50%;
	animation: ranked-spin 0.8s linear infinite;
	flex: 0 0 auto;
}

@keyframes ranked-spin { to { transform: rotate(360deg); } }

.ranked-tag {
	background: var(--accent);
	color: #fff;
	font-weight: 700;
	font-size: 0.7rem;
	letter-spacing: 0.06em;
	padding: 0.15rem 0.45rem;
	border-radius: 6px;
}

.name-form {
	display: flex;
	gap: 0.6rem;
}

.name-form input { flex: 1; }

.name-error {
	margin-top: 0.85rem;
	padding: 0.6rem 0.85rem;
	background: rgba(239, 68, 68, 0.1);
	border: 1px solid rgba(239, 68, 68, 0.3);
	border-radius: 8px;
	color: #fecaca;
	font-size: 0.9rem;
}

/* Lobby */
.lobby-actions {
	display: flex;
	gap: 0.75rem;
	margin-bottom: 1.5rem;
}

.section-title {
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--muted);
	text-transform: uppercase;
	letter-spacing: 0.08em;
	margin: 0 0 0.75rem;
}

.section-title-spaced { margin-top: 1.75rem; }

.room-list {
	list-style: none;
	padding: 0;
	margin: 0;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.room-row, .room-empty {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 0.9rem 1.1rem;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	box-shadow: var(--shadow);
}

.room-empty {
	color: var(--muted);
	justify-content: center;
	font-style: italic;
}

.room-info { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.room-title { font-weight: 600; font-size: 1rem; }
.room-meta { color: var(--muted); font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.room-badge {
	font-size: 0.8rem;
	font-weight: 500;
	padding: 0.3rem 0.7rem;
	border-radius: 999px;
	background: rgba(99, 102, 241, 0.15);
	border: 1px solid rgba(99, 102, 241, 0.35);
	color: var(--accent-hover);
}

.lobby-message {
	margin-top: 1rem;
	padding: 0.75rem 1rem;
	background: rgba(239, 68, 68, 0.1);
	border: 1px solid rgba(239, 68, 68, 0.3);
	border-radius: 8px;
	color: #fecaca;
	font-size: 0.9rem;
}

/* Buttons */
.btn {
	font: inherit;
	font-weight: 500;
	border: 1px solid transparent;
	border-radius: 8px;
	padding: 0.55rem 1rem;
	cursor: pointer;
	transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
	color: var(--text);
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary { background: var(--surface-2); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface); border-color: var(--accent); }

.btn-ghost {
	background: transparent;
	border-color: transparent;
	color: var(--muted);
	padding: 0.35rem 0.7rem;
}
.btn-ghost:hover { color: var(--text); background: var(--surface); }

/* Game view */
.game-view { animation: fade 180ms ease; }

.game-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 1rem;
}

.game-progress {
	display: flex;
	align-items: center;
	gap: 1.5rem;
}

#game_progress_text {
	color: var(--muted);
	font-size: 0.95rem;
}

.round-timer {
	font-size: 1.2rem;
	font-weight: 600;
	font-variant-numeric: tabular-nums;
	color: var(--text);
	min-width: 5ch;
	text-align: right;
}

.round-timer-warning {
	color: #fbbf24;
}

.round-timer-urgent {
	color: var(--danger);
	animation: pulse 0.7s ease-in-out infinite alternate;
}

@keyframes pulse {
	from { opacity: 1; }
	to { opacity: 0.55; }
}

.game-grid {
	display: grid;
	grid-template-columns: minmax(0, 1fr) 280px;
	gap: 1.25rem;
	align-items: start;
}

.game-left { min-width: 0; }

.player-board {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 1.25rem;
	box-shadow: var(--shadow);
	display: inline-block;
	max-width: 100%;
	position: relative;
}

.board-wrap {
	position: relative;
	display: inline-block;
}

.board-wrap.shake {
	animation: board-shake 0.42s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes board-shake {
	10%, 90% { transform: translateX(-2px); }
	20%, 80% { transform: translateX(3px); }
	30%, 50%, 70% { transform: translateX(-5px); }
	40%, 60% { transform: translateX(5px); }
}

.player-board.idle #game0 { opacity: 0.35; }

.player-board.idle::after {
	content: "Waiting for series to start";
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	color: var(--muted);
	font-size: 0.95rem;
	pointer-events: none;
	z-index: 2;
}

.board-overlay {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	font-weight: 700;
	font-size: 4rem;
	letter-spacing: 0.04em;
	text-shadow: 0 4px 24px rgba(0,0,0,0.6);
	pointer-events: none;
	border-radius: 4px;
	background: rgba(11, 16, 32, 0.45);
	color: #94a3b8;
	z-index: 3;
}

.board-overlay-count { font-size: 6rem; background: rgba(11, 16, 32, 0.3); }
.board-overlay-go { color: var(--success); font-size: 5rem; background: rgba(34, 197, 94, 0.15); }
.board-overlay-frozen { color: #fde68a; font-size: 4.5rem; background: rgba(239, 68, 68, 0.25); }
.board-overlay-win { color: var(--success); font-size: 2rem; background: rgba(34, 197, 94, 0.2); padding: 1rem; }
.board-overlay-lose { color: var(--danger); font-size: 2rem; background: rgba(239, 68, 68, 0.18); padding: 1rem; }

/* Round / series results panel */
.board-overlay-panel {
	font-size: 1rem;
	background: rgba(8, 12, 24, 0.86);
	backdrop-filter: blur(4px);
	padding: 1rem;
}

.result-panel {
	width: min(94%, 360px);
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
	text-shadow: none;
	color: var(--text);
}

.result-header {
	text-align: center;
	font-size: 1.2rem;
	font-weight: 700;
	letter-spacing: 0;
	color: var(--text);
}

.board-overlay-win .result-header { color: var(--success); }
.board-overlay-lose .result-header { color: var(--text); }
.result-header-series { font-size: 1.35rem; }

.result-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.3rem;
}

.result-row {
	display: grid;
	grid-template-columns: 2rem 1fr auto auto;
	align-items: center;
	gap: 0.6rem;
	padding: 0.4rem 0.65rem;
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.05);
	font-size: 0.95rem;
	font-weight: 500;
	opacity: 0;
	animation: result-row-in 0.32s ease-out forwards;
}

.result-row-me { background: rgba(99, 102, 241, 0.28); font-weight: 700; }
.result-row-top { box-shadow: inset 0 0 0 1px rgba(250, 204, 21, 0.55); }

.result-place { font-size: 1.05rem; text-align: center; }
.result-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-detail { color: var(--muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.result-points { color: var(--success); font-weight: 700; font-variant-numeric: tabular-nums; min-width: 2.5ch; text-align: right; }

.result-foot { text-align: center; color: var(--muted); font-size: 0.8rem; }

@keyframes result-row-in {
	from { opacity: 0; transform: translateY(8px) scale(0.97); }
	to { opacity: 1; transform: none; }
}

.player-name {
	margin: 0 0 0.6rem;
	font-weight: 600;
}

#game0, #game1, #game2, #game3, #game4, #game5 {
	display: block;
	border-radius: 4px;
	background: var(--bg);
}

.player-controls {
	display: flex;
	gap: 0.75rem;
	align-items: center;
	margin-top: 0.85rem;
}

.ready-status {
	color: var(--muted);
	font-size: 0.9rem;
}

.hotkey-hint {
	margin: 0.6rem 0 0;
	color: var(--muted);
	font-size: 0.8rem;
	letter-spacing: 0.01em;
}

.opponents {
	margin-top: 1.25rem;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
	gap: 0.75rem;
}

.opponent_div {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 0.75rem;
	box-shadow: var(--shadow);
}

.opponent_div .player-name { font-size: 0.9rem; color: var(--muted); }

/* Sidebar */
.game-side {
	display: flex;
	flex-direction: column;
	gap: 1rem;
	position: sticky;
	top: 1rem;
}

.side-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 1.1rem 1.2rem;
	box-shadow: var(--shadow);
}

.side-title {
	margin: 0 0 0.85rem;
	font-size: 0.8rem;
	font-weight: 600;
	color: var(--muted);
	text-transform: uppercase;
	letter-spacing: 0.08em;
}

.series-config {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	margin-bottom: 0.85rem;
}

.series-config-label {
	color: var(--muted);
	font-size: 0.85rem;
}

.series-config-readonly {
	font-weight: 600;
}

.series-status {
	color: var(--muted);
	font-size: 0.9rem;
}

.scoreboard {
	list-style: none;
	padding: 0;
	margin: 0;
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
}

.score-row {
	display: grid;
	grid-template-columns: 1.5rem 1fr auto 2rem;
	align-items: center;
	gap: 0.5rem;
	padding: 0.5rem 0.6rem;
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.02);
	border: 1px solid transparent;
}

.score-row-me {
	background: rgba(99, 102, 241, 0.1);
	border-color: rgba(99, 102, 241, 0.3);
}

.score-rank {
	color: var(--muted);
	font-size: 0.85rem;
	text-align: right;
}

.score-name {
	font-weight: 500;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.score-meta {
	font-size: 0.8rem;
	color: var(--muted);
}

.score-meta-ready { color: var(--success); }
.score-meta-waiting { color: var(--muted); }

.score-points {
	font-weight: 700;
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.score-points-bumped {
	animation: score-bump 0.7s ease-out;
}

@keyframes score-bump {
	0% { transform: scale(1); color: var(--text); }
	30% { transform: scale(1.45); color: var(--success); }
	100% { transform: scale(1); color: var(--text); }
}

.score-bot-tag {
	display: inline-block;
	font-size: 0.65rem;
	font-weight: 700;
	letter-spacing: 0.08em;
	padding: 0.1rem 0.35rem;
	border-radius: 4px;
	background: rgba(99, 102, 241, 0.18);
	border: 1px solid rgba(99, 102, 241, 0.4);
	color: var(--accent-hover);
	vertical-align: middle;
}

.bot-actions {
	display: flex;
	gap: 0.5rem;
	margin-top: 0.5rem;
	flex-wrap: wrap;
}

.bot-list {
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
	margin-top: 0.5rem;
}

.bot-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
}

.bot-row-name {
	font-size: 0.9rem;
	color: var(--text);
}

.bot-row-difficulty {
	font-size: 0.85rem;
	color: var(--muted);
}

.bot-difficulty-select {
	padding: 0.25rem 0.4rem;
	font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 900px) {
	.game-grid { grid-template-columns: 1fr; }
	.game-side { position: static; }
}

@media (max-width: 640px) {
	.topbar { flex-direction: column; align-items: flex-start; gap: 0.5rem; padding: 0.85rem 1rem; }
	.topbar h1 { font-size: 1rem; }
	.user-badge { font-size: 0.85rem; gap: 0.4rem; }
	main { padding: 1rem; }

	.name-view { padding-top: 2rem; }
	.name-card { padding: 1.5rem 1.25rem; }
	.name-form { flex-wrap: wrap; }
	.name-form input { min-width: 0; }
	.name-form .btn { flex: 0 0 auto; }

	.lobby-actions { flex-wrap: wrap; }

	.room-row, .room-empty { padding: 0.8rem 0.9rem; }

	.game-header { flex-wrap: wrap; gap: 0.6rem; }
	.game-progress { width: 100%; justify-content: space-between; gap: 0.75rem; }

	.player-board { padding: 0.85rem; display: block; }
	#game0 { width: 100%; height: auto; max-width: 100%; }

	.opponents { grid-template-columns: 1fr; }
	.opponent_div #game1,
	.opponent_div #game2,
	.opponent_div #game3,
	.opponent_div #game4,
	.opponent_div #game5 { width: 100%; height: auto; max-width: 100%; }

	.side-card { padding: 0.9rem 1rem; }
	.series-config { flex-wrap: wrap; gap: 0.5rem; }
	.score-row { grid-template-columns: 1.25rem 1fr auto 1.75rem; padding: 0.45rem 0.55rem; }
	.score-meta { font-size: 0.75rem; }
}
