: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;
	text-decoration: none;
	cursor: pointer;
}

/* The brand mark — the same minesweeper-tile SVG used for the favicon. */
.logo-tile {
	display: block;
	width: 2rem;
	height: 2rem;
	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-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;
}

/* Main site nav between the logo and the user badge. Kept light-touch so the
   home page is still where the action is. */
.site-nav {
	display: flex;
	gap: 0.25rem;
	flex: 1;
	justify-content: center;
}

.site-nav-link {
	color: var(--muted);
	text-decoration: none;
	font-weight: 600;
	font-size: 0.92rem;
	padding: 0.45rem 0.85rem;
	border-radius: 8px;
	transition: color 120ms ease, background 120ms ease;
}

.site-nav-link:hover { color: var(--text); background: var(--surface); }
.site-nav-link.active { color: #fff; background: rgba(99, 102, 241, 0.22); }

@media (max-width: 800px) {
	.site-nav { flex-wrap: wrap; justify-content: flex-start; gap: 0.1rem; }
	.site-nav-link { padding: 0.35rem 0.55rem; font-size: 0.85rem; }
}

/* Layouts for the Learn / Practice / Leaderboard / Profile pages. */
.section-view { animation: fade 180ms ease; }

.section-page-title {
	font-size: 1.5rem;
	font-weight: 800;
	margin: 0 0 0.35rem;
}

.section-page-sub {
	color: var(--muted);
	margin: 0 0 1.4rem;
}

.section-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 1.25rem 1.4rem;
	box-shadow: var(--shadow);
	margin-bottom: 1rem;
}

.section-card h2 { margin: 0 0 0.55rem; font-size: 1.1rem; }
.section-card p { margin: 0 0 0.6rem; color: var(--muted); line-height: 1.55; }
.section-card p:last-child { margin-bottom: 0; }

.section-card-stub { opacity: 0.85; }
.section-card-stub h2::after {
	content: "·  preview";
	font-size: 0.65rem;
	letter-spacing: 0.12em;
	margin-left: 0.5rem;
	padding: 0.1rem 0.4rem;
	border-radius: 4px;
	background: rgba(99, 102, 241, 0.18);
	color: var(--accent-hover);
	font-weight: 700;
	vertical-align: middle;
}

.section-stub-note {
	font-size: 0.85rem;
	color: var(--muted);
	font-style: italic;
}

.section-link-inline { color: var(--accent-hover); text-decoration: none; font-weight: 600; }
.section-link-inline:hover { text-decoration: underline; }

.section-grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 1rem;
}

@media (max-width: 700px) {
	.section-grid { grid-template-columns: 1fr; }
}

.section-rules {
	margin: 0;
	padding-left: 1.2rem;
	color: var(--muted);
	line-height: 1.6;
}

.section-rules li { margin-bottom: 0.35rem; }
.section-rules strong { color: var(--text); }

/* Profile-specific small bits */
.profile-summary {
	display: flex;
	align-items: center;
	gap: 1.25rem;
}

.profile-summary-text { display: flex; flex-direction: column; gap: 0.15rem; }
.profile-summary-name { font-size: 1.25rem; font-weight: 800; }
.profile-summary-rating { color: var(--muted); font-variant-numeric: tabular-nums; }

.solo-stats {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 0.5rem;
	margin-bottom: 0.85rem;
}

.solo-stat {
	background: rgba(255, 255, 255, 0.04);
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 0.55rem 0.7rem;
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
}

.solo-stat-label {
	font-size: 0.65rem;
	letter-spacing: 0.14em;
	color: var(--muted);
	text-transform: uppercase;
	font-weight: 700;
}

.solo-stat-value {
	font-size: 1.15rem;
	font-weight: 800;
	font-variant-numeric: tabular-nums;
}

.solo-picker-label {
	display: block;
	font-size: 0.65rem;
	letter-spacing: 0.14em;
	color: var(--muted);
	text-transform: uppercase;
	font-weight: 700;
	margin-bottom: 0.3rem;
}

.solo-size-picker,
.solo-density-picker {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 0.4rem;
	margin-bottom: 0.6rem;
}

.solo-size-btn,
.solo-density-btn { padding: 0.4rem 0.4rem; font-size: 0.85rem; }
.solo-size-btn.active,
.solo-density-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.solo-size-btn.active:hover,
.solo-density-btn.active:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

#solo_restart { width: 100%; }

.profile-stats {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 1rem;
	margin-top: 1rem;
}

@media (max-width: 600px) {
	.profile-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Controls / keybindings section (Profile page) */
.controls-title { font-size: 1.2rem; font-weight: 800; margin: 0 0 0.4rem; }
.keybind-list {
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
	margin: 0.9rem 0;
}
.keybind-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.45rem 0.7rem;
	border: 1px solid var(--border);
	border-radius: 0.5rem;
}
.keybind-label { font-size: 0.95rem; }
.keybind-key {
	min-width: 5.5rem;
	padding: 0.35rem 0.7rem;
	border: 1px solid var(--border);
	border-radius: 0.45rem;
	background: var(--bg);
	color: inherit;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	cursor: pointer;
}
.keybind-key:hover { border-color: var(--accent); }
.keybind-key.capturing {
	border-color: var(--accent);
	background: var(--accent);
	color: #fff;
	font-weight: 600;
}
.keybind-reset { margin-top: 0.3rem; }

.profile-stat {
	background: rgba(255, 255, 255, 0.03);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 0.8rem 0.9rem;
}

.profile-stat-label {
	font-size: 0.7rem;
	letter-spacing: 0.12em;
	color: var(--muted);
	text-transform: uppercase;
	font-weight: 700;
}

.profile-stat-value {
	font-size: 1.4rem;
	font-weight: 800;
	font-variant-numeric: tabular-nums;
	margin-top: 0.25rem;
}

.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-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); }
}

/* Floating "+15"/"-15" that drifts up from the rating chip after a ranked match. */
.rating-delta {
	position: fixed;
	font-weight: 800;
	font-size: 1.1rem;
	z-index: 999;
	pointer-events: none;
	white-space: nowrap;
	text-shadow: 0 2px 8px rgba(0,0,0,0.6);
	animation: rating-delta-float 1.8s cubic-bezier(.22,1,.36,1) forwards;
}

.rating-delta-gain { color: #4ade80; }
.rating-delta-loss { color: #f87171; }

@keyframes rating-delta-float {
	0%   { opacity: 0; transform: translateY(4px) scale(0.7); }
	10%  { opacity: 1; transform: translateY(-4px) scale(1.25); }
	25%  { opacity: 1; transform: translateY(-14px) scale(1); }
	85%  { opacity: 1; transform: translateY(-44px) scale(1); }
	100% { opacity: 0; transform: translateY(-58px) scale(0.9); }
}

/* Centered rank-change banner: shows when crossing a sub-tier boundary. */
.rank-banner {
	position: fixed;
	top: 38%;
	left: 50%;
	transform: translate(-50%, -50%);
	padding: 1.5rem 2.5rem;
	border-radius: 18px;
	text-align: center;
	z-index: 1000;
	pointer-events: none;
	opacity: 0;
	color: #fff;
	min-width: 260px;
	text-shadow: 0 2px 12px rgba(0,0,0,0.5);
	animation: rank-banner-show 2.8s ease forwards;
}

.rank-banner.promoted {
	background: linear-gradient(135deg, rgba(34,197,94,0.96), rgba(16,150,80,0.96));
	box-shadow: 0 0 60px rgba(34,197,94,0.55), 0 14px 36px rgba(0,0,0,0.55);
	border: 1px solid rgba(134,239,172,0.6);
}

.rank-banner.demoted {
	background: linear-gradient(135deg, rgba(239,68,68,0.94), rgba(190,30,30,0.94));
	box-shadow: 0 0 50px rgba(239,68,68,0.45), 0 14px 36px rgba(0,0,0,0.55);
	border: 1px solid rgba(252,165,165,0.55);
}

.rank-banner-label {
	font-size: 0.82rem;
	font-weight: 800;
	letter-spacing: 0.22em;
	opacity: 0.9;
	margin-bottom: 0.4rem;
}

.rank-banner-tier {
	font-size: 2.6rem;
	font-weight: 800;
	letter-spacing: 0.02em;
}

@keyframes rank-banner-show {
	0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5) rotate(-4deg); }
	14%  { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(1deg); }
	22%  { transform: translate(-50%, -50%) scale(1) rotate(0); }
	82%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
	100% { opacity: 0; transform: translate(-50%, -50%) scale(1.06); }
}

.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-mode-buttons {
	display: flex;
	gap: 0.55rem;
}

.ranked-mode-buttons .btn { min-width: 96px; }

/* Home page cards: 1v1, 6-player, Tournament, Custom. */
.home-cards {
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	gap: 1rem;
	margin-bottom: 1.5rem;
}

@media (max-width: 1100px) { .home-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.home-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 14px;
	padding: 1.4rem 1.3rem 1.3rem;
	display: flex;
	flex-direction: column;
	gap: 0.7rem;
	box-shadow: var(--shadow);
	min-height: 220px;
}

.home-card-ranked {
	background: linear-gradient(160deg, rgba(99, 102, 241, 0.22), rgba(99, 102, 241, 0.05) 70%);
	border-color: rgba(99, 102, 241, 0.45);
}

.home-card-custom {
	background: linear-gradient(160deg, rgba(94, 234, 212, 0.10), rgba(94, 234, 212, 0.02) 70%);
	border-color: rgba(148, 163, 184, 0.35);
}

.home-card-puzzles {
	background: linear-gradient(160deg, rgba(192, 132, 252, 0.18), rgba(192, 132, 252, 0.04) 70%);
	border-color: rgba(192, 132, 252, 0.45);
}
.home-card-tag-puzzles {
	background: rgba(192, 132, 252, 0.22);
	color: #c084fc;
	border-color: rgba(192, 132, 252, 0.5);
}
.home-card-streak {
	background: linear-gradient(160deg, rgba(251, 146, 60, 0.16), rgba(251, 146, 60, 0.04) 70%);
	border-color: rgba(251, 146, 60, 0.45);
}
.home-card-tag-streak {
	background: rgba(251, 146, 60, 0.22);
	color: #fb923c;
	border-color: rgba(251, 146, 60, 0.5);
}
.home-card-storm {
	background: linear-gradient(160deg, rgba(248, 113, 113, 0.16), rgba(248, 113, 113, 0.04) 70%);
	border-color: rgba(248, 113, 113, 0.45);
}
.home-card-tag-storm {
	background: rgba(248, 113, 113, 0.22);
	color: #f87171;
	border-color: rgba(248, 113, 113, 0.5);
}
.home-card-daily {
	background: linear-gradient(160deg, rgba(250, 204, 21, 0.16), rgba(250, 204, 21, 0.04) 70%);
	border-color: rgba(250, 204, 21, 0.45);
}
.home-card-tag-daily {
	background: rgba(250, 204, 21, 0.22);
	color: #facc15;
	border-color: rgba(250, 204, 21, 0.5);
}

.puzzle-run-row { display: flex; gap: 1.4rem; margin: 0.4rem 0; }
.puzzle-run-stat { display: flex; flex-direction: column; gap: 0.2rem; }
.puzzle-run-stat-label {
	font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase;
	color: var(--muted);
}
.puzzle-run-stat-value {
	font-size: 2.4rem; font-weight: 800; line-height: 1;
	color: var(--text);
	display: inline-block;
	transform-origin: left center;
}

/* Solve-counter pop on increment — overshoots to 1.6x with a green flash
   and a soft glow, then springs back. Felt-tuned to feel snappy but
   readable: ~550ms total, bulk of the punch in the first 200ms. */
.puzzle-run-stat-value.bump {
	animation: solvesBump 550ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes solvesBump {
	0%   { transform: scale(1);   color: var(--text); text-shadow: none; }
	20%  { transform: scale(1.65); color: #4ade80; text-shadow: 0 0 28px rgba(74, 222, 128, 0.85), 0 0 6px rgba(74, 222, 128, 0.6); }
	50%  { transform: scale(1.15); color: #4ade80; text-shadow: 0 0 14px rgba(74, 222, 128, 0.45); }
	100% { transform: scale(1);   color: var(--text); text-shadow: none; }
}
.puzzle-run-foot {
	display: flex; gap: 0.4rem; align-items: baseline;
	margin-top: auto; padding-top: 0.6rem;
	border-top: 1px solid var(--border);
}
.puzzle-run-foot-label {
	font-size: 0.78rem; color: var(--muted);
	letter-spacing: 0.04em; text-transform: uppercase;
}
.puzzle-run-foot-value { font-size: 0.95rem; font-weight: 700; color: var(--text); }

.home-card-head { display: flex; align-items: center; gap: 0.5rem; }

.home-card-tag {
	font-size: 0.65rem;
	font-weight: 700;
	letter-spacing: 0.1em;
	padding: 0.18rem 0.45rem;
	border-radius: 5px;
	background: rgba(99, 102, 241, 0.25);
	color: var(--accent-hover);
	border: 1px solid rgba(99, 102, 241, 0.45);
}

.home-card-tag-casual {
	background: rgba(94, 234, 212, 0.15);
	color: #5eead4;
	border-color: rgba(94, 234, 212, 0.45);
}

.home-card-tournament {
	background: linear-gradient(160deg, rgba(251, 191, 36, 0.16), rgba(192, 132, 252, 0.06) 70%);
	border-color: rgba(251, 191, 36, 0.45);
}

.home-card-tag-tournament {
	background: rgba(251, 191, 36, 0.18);
	color: #fbbf24;
	border-color: rgba(251, 191, 36, 0.5);
}

.home-card-title {
	margin: 0;
	font-size: 1.6rem;
	font-weight: 800;
}

.home-card-sub {
	color: var(--muted);
	font-size: 0.9rem;
	margin: 0;
	flex: 1;
	line-height: 1.45;
}

.home-card-rank {
	display: flex;
	align-items: baseline;
	gap: 0.45rem;
	padding: 0.55rem 0.7rem;
	background: rgba(11, 16, 32, 0.45);
	border: 1px solid rgba(255, 255, 255, 0.08);
	border-radius: 8px;
}

.home-card-rank-label {
	font-size: 0.7rem;
	font-weight: 700;
	letter-spacing: 0.08em;
	color: var(--muted);
	text-transform: uppercase;
	margin-right: 0.15rem;
}

.home-card-rank-tier {
	font-size: 1rem;
	font-weight: 700;
}

.home-card-rank-rating {
	font-size: 0.85rem;
	color: var(--muted);
	font-variant-numeric: tabular-nums;
}

.home-card-action { align-self: stretch; padding: 0.65rem 1rem; font-weight: 600; }

.home-card-actions {
	display: flex;
	gap: 0.5rem;
	flex-wrap: wrap;
}

.home-card-actions .home-card-action { flex: 1 1 auto; }
.home-card-actions .btn-secondary { flex: 0 0 auto; }

.custom-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin: 0 0 1.4rem; }

.puzzles-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin: 0 0 0.6rem; }
.puzzles-toolbar { display: flex; gap: 1.4rem; flex-wrap: wrap; align-items: center; margin: 0 0 0.6rem; }
.puzzles-sort-wrap { display: flex; align-items: center; gap: 0.45rem; }
.puzzles-sort-select {
	background: var(--surface);
	color: var(--text);
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 0.32rem 0.6rem;
	font-weight: 600;
	font-size: 0.85rem;
	cursor: pointer;
}
.puzzles-list-footer { margin-top: 1.2rem; font-size: 0.85rem; }
.puzzles-list-footer a { color: var(--accent); text-decoration: none; }
.puzzles-list-footer a:hover { text-decoration: underline; }
.puzzles-list-empty { color: var(--muted); font-style: italic; margin: 1rem 0; }

.puzzles-pager {
	display: flex; gap: 0.4rem; align-items: center; justify-content: center;
	flex-wrap: wrap;
	margin: 1.2rem 0;
}
.puzzles-pager-btn {
	background: var(--surface);
	color: var(--text);
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 0.32rem 0.7rem;
	font-weight: 600;
	font-size: 0.85rem;
	cursor: pointer;
	min-width: 2.2rem;
}
.puzzles-pager-btn:hover:not(:disabled) { border-color: var(--accent); }
.puzzles-pager-btn.current {
	background: var(--accent); border-color: var(--accent); color: #fff;
}
.puzzles-pager-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.puzzles-pager-dots { color: var(--muted); padding: 0 0.3rem; }

.admin-cards {
	display: grid; gap: 1.2rem; margin-top: 1.2rem;
	grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.admin-card {
	display: block;
	padding: 1.4rem 1.2rem;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 12px;
	color: var(--text);
	text-decoration: none;
	transition: border-color 120ms ease;
}
.admin-card:hover { border-color: var(--accent); }
.admin-card-title { font-size: 1.2rem; font-weight: 800; margin: 0 0 0.4rem; }
.admin-card-sub   { color: var(--muted); margin: 0 0 0.9rem; font-size: 0.92rem; }
.admin-card-action { color: var(--accent); font-weight: 700; }

.puzzle-play-header {
	display: flex; gap: 1.2rem; align-items: center; margin: 0.6rem 0 1rem;
	font-size: 0.95rem;
}
.puzzle-play-rating { font-weight: 700; color: var(--text); }
.puzzle-play-streak {
	background: rgba(74, 222, 128, 0.18); color: #4ade80;
	padding: 0.2rem 0.6rem; border-radius: 999px; font-weight: 700;
	font-size: 0.85rem;
}
.puzzle-play-board {
	display: flex; justify-content: center; align-items: center;
	min-height: 240px; padding: 1.2rem; background: var(--surface);
	border: 1px solid var(--border); border-radius: 10px;
}
.puzzle-play-loading, .puzzle-play-empty {
	color: var(--muted); font-style: italic; margin: 0;
}
.puzzle-play-result {
	margin-top: 1.2rem; padding: 1rem 1.2rem;
	background: var(--surface); border: 1px solid var(--border);
	border-radius: 10px;
}
.puzzle-play-result.puzzle-play-result-ok { border-color: rgba(74, 222, 128, 0.6); }
.puzzle-play-result.puzzle-play-result-fail { border-color: rgba(248, 113, 113, 0.6); }
.puzzle-play-result-headline {
	font-size: 1.4rem; font-weight: 800; margin-bottom: 0.3rem;
}
.puzzle-play-result-ok .puzzle-play-result-headline { color: #4ade80; }
.puzzle-play-result-fail .puzzle-play-result-headline { color: #f87171; }
.puzzle-play-result-detail { color: var(--muted); margin: 0 0 0.9rem; font-size: 0.9rem; }
.puzzle-play-result-actions { display: flex; gap: 0.6rem; }

/* Floating overlay shown briefly after a puzzle resolves. Positioned inside
   .board-wrap so it sits centered over the board. */
.puzzle-flash {
	position: absolute;
	top: 50%; left: 50%;
	transform: translate(-50%, -50%);
	padding: 1rem 1.6rem;
	border-radius: 14px;
	background: rgba(15, 23, 42, 0.92);
	border: 2px solid var(--border);
	text-align: center;
	pointer-events: none;
	z-index: 50;
	opacity: 0;
}
.puzzle-flash.playing { animation: puzzleFlashPop 1.4s ease-out forwards; }
.puzzle-flash-solved { border-color: rgba(74, 222, 128, 0.7); }
.puzzle-flash-fail   { border-color: rgba(248, 113, 113, 0.7); }
.puzzle-flash-icon   { font-size: 2.4rem; line-height: 1; margin-bottom: 0.3rem; }
.puzzle-flash-solved .puzzle-flash-icon { color: #4ade80; }
.puzzle-flash-fail   .puzzle-flash-icon { color: #f87171; }
.puzzle-flash-label  { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.puzzle-flash-solved .puzzle-flash-label { color: #4ade80; }
.puzzle-flash-fail   .puzzle-flash-label { color: #f87171; }
@keyframes puzzleFlashPop {
	0%   { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
	14%  { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
	28%  { transform: translate(-50%, -50%) scale(1.00); opacity: 1; }
	72%  { transform: translate(-50%, -50%) scale(1.00); opacity: 1; }
	100% { transform: translate(-50%, -50%) scale(0.92); opacity: 0; }
}

/* Tier progress bar in the side card. */
.puzzle-rank { margin-bottom: 1rem; }
.puzzle-rank-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.4rem; }
.puzzle-rank-tier { font-weight: 700; font-size: 0.95rem; letter-spacing: 0.03em; }
.puzzle-rank-rating { font-weight: 800; font-size: 1.4rem; color: var(--text); }
.puzzle-rank-rating-wrap { position: relative; display: inline-flex; align-items: baseline; gap: 0.4rem; }
.puzzle-rank-delta {
	position: absolute;
	left: 100%; top: 50%;
	transform: translate(0.5rem, -50%);
	font-weight: 800; font-size: 1rem;
	opacity: 0;
	pointer-events: none;
	white-space: nowrap;
}
.puzzle-rank-delta.gain { color: #4ade80; }
.puzzle-rank-delta.loss { color: #f87171; }
.puzzle-rank-delta.flat { color: var(--muted); }
.puzzle-rank-delta.playing { animation: puzzleRankDelta 1.4s ease-out forwards; }
@keyframes puzzleRankDelta {
	0%   { opacity: 0; transform: translate(0.5rem, -10%); }
	15%  { opacity: 1; transform: translate(0.5rem, -50%); }
	75%  { opacity: 1; transform: translate(0.5rem, -90%); }
	100% { opacity: 0; transform: translate(0.5rem, -130%); }
}
.puzzle-rank-bar {
	height: 8px; border-radius: 999px; background: rgba(148, 163, 184, 0.18);
	overflow: hidden; position: relative;
}
.puzzle-rank-fill {
	height: 100%; width: 0%; border-radius: 999px;
	background: var(--accent);
	transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.puzzle-rank-foot {
	display: flex; justify-content: space-between;
	margin-top: 0.3rem;
	font-size: 0.78rem; color: var(--muted);
}
.puzzle-stats-secondary { margin-top: 0.4rem; }

/* Puzzle view layout: the board and the side card sit together as a fixed,
   centered block so nothing reflows when the puzzle dimensions change.
   The board area is always 480×480 (cells scale to fit), the side card
   matches that height, both share a tight gap to read as one component. */
.game-view.puzzle .game-grid {
	display: flex;
	justify-content: center;
	align-items: stretch;
	gap: 0.6rem;
	max-width: none;
}
.game-view.puzzle .game-left {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
}
.game-view.puzzle .player-board {
	padding: 0;
	background: transparent;
	border: none;
	box-shadow: none;
}
.game-view.puzzle #player_name0 { display: none; }
.game-view.puzzle .board-scroll {
	width: 480px;
	height: 480px;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 12px;
	box-shadow: var(--shadow);
}
.game-view.puzzle .board-wrap {
	display: block;
	width: 480px;
}
.game-view.puzzle .game-side {
	position: static;
	flex: 0 0 320px;
	gap: 0;
}
.game-view.puzzle #puzzle_card {
	height: 480px;
	display: flex;
	flex-direction: column;
}
.game-view.puzzle #puzzle_card .puzzle-mode-panel {
	flex: 1;
	display: flex;
	flex-direction: column;
}
.game-view.puzzle #puzzle_card .puzzle-hint-btn {
	margin-top: auto;
}
@media (max-width: 900px) {
	.game-view.puzzle .game-grid {
		flex-direction: column;
		align-items: center;
	}
	.game-view.puzzle .game-side { flex: 0 0 auto; }
	.game-view.puzzle #puzzle_card { height: auto; width: 480px; }
}
@media (max-width: 600px) {
	.game-view.puzzle .board-scroll,
	.game-view.puzzle .board-wrap,
	.game-view.puzzle #puzzle_card {
		width: 320px;
	}
	.game-view.puzzle .board-scroll { height: 320px; }
}

/* Puzzle side card — chess.com-style: title at top, big rating + streak
   chip, tier name, progress bar, hint button anchored at the bottom. */
.puzzle-side-card {
	display: flex;
	flex-direction: column;
	gap: 0.8rem;
}
.puzzle-side-head { display: flex; align-items: center; gap: 0.8rem; }
.puzzle-side-back {
	cursor: pointer; user-select: none;
	font-size: 1.4rem; color: var(--muted);
	width: 1.8rem; text-align: center;
}
.puzzle-side-back:hover { color: var(--text); }
.puzzle-side-title { font-size: 1.1rem; font-weight: 700; }
.puzzle-side-rating-row {
	display: flex; align-items: baseline; gap: 0.7rem;
	position: relative;
}
.puzzle-side-rating-wrap { position: relative; display: inline-flex; align-items: baseline; }
.puzzle-side-rating { font-size: 2.4rem; font-weight: 800; line-height: 1; }
.puzzle-streak-chip {
	background: rgba(251, 146, 60, 0.18); color: #fb923c;
	font-weight: 700; font-size: 0.9rem;
	padding: 0.2rem 0.55rem; border-radius: 999px;
	border: 1px solid rgba(251, 146, 60, 0.45);
}
.puzzle-side-tier {
	font-weight: 700; font-size: 0.95rem;
	letter-spacing: 0.04em; text-transform: uppercase;
	color: var(--muted);
	margin-top: -0.3rem;
}
.puzzle-side-card .puzzle-rank-bar { margin-top: 0.1rem; }
.puzzle-hint-btn {
	margin-top: auto;
	display: flex; align-items: center; justify-content: center; gap: 0.5rem;
	padding: 0.8rem 1rem;
	font-size: 1rem; font-weight: 700;
}
.puzzle-hint-btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}
.puzzle-hint-btn.used {
	/* Still clickable, but visually marked so the Elo penalty is obvious. */
	opacity: 0.75;
}
.puzzle-fail-actions {
	margin-top: auto;
	display: flex; flex-direction: column; gap: 0.5rem;
}
.puzzle-fail-actions .btn {
	padding: 0.8rem 1rem;
	font-size: 1rem; font-weight: 700;
}
.puzzle-hint-icon { font-size: 1.2rem; line-height: 1; }
.puzzles-filter { display: flex; gap: 0.45rem; flex-wrap: wrap; align-items: center; margin: 0 0 0.6rem; }
.puzzles-filter-label { color: var(--muted); font-size: 0.8rem; letter-spacing: 0.05em; text-transform: uppercase; margin-right: 0.25rem; }
.puzzles-filter-chip {
	background: var(--surface);
	color: var(--text);
	border: 1px solid var(--border);
	border-radius: 6px;
	padding: 0.32rem 0.7rem;
	font-weight: 700;
	font-size: 0.85rem;
	cursor: pointer;
	min-width: 36px;
}
.puzzles-filter-chip:hover { border-color: var(--accent); }
.puzzles-filter-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.puzzle-lab-status { color: var(--muted); font-size: 0.85rem; margin: 0 0 1.2rem; }
.puzzles-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
	gap: 1rem;
}

/* Admin bot browser */
.bots-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
	gap: 1rem;
}
.bot-card {
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 0.9rem;
	background: var(--surface);
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
}
.bot-card-head { display: flex; align-items: center; gap: 0.5rem; }
.bot-rating-badge {
	font-weight: 800;
	background: var(--accent);
	color: #fff;
	padding: 0.2rem 0.55rem;
	border-radius: 0.5rem;
	font-size: 0.95rem;
}
.bot-card-id { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.bot-vars {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 0.35rem;
}
.bot-var { display: flex; flex-direction: column; gap: 0.05rem; }
.bot-var-key { font-size: 0.6rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.bot-var-val { font-size: 0.85rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.bot-mode-row {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	padding-top: 0.45rem;
	border-top: 1px solid var(--border);
}
.bot-mode-name { font-size: 0.85rem; font-weight: 600; flex: 1 1 auto; }
.bot-mode-elo { font-size: 0.85rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.bot-watch-btn {
	border: 1px solid var(--accent);
	background: transparent;
	color: var(--accent);
	border-radius: 0.45rem;
	padding: 0.25rem 0.55rem;
	font-size: 0.8rem;
	font-weight: 700;
	cursor: pointer;
}
.bot-watch-btn:hover { background: var(--accent); color: #fff; }
.bots-elo-input {
	width: 64px;
	padding: 0.3rem 0.4rem;
	border: 1px solid var(--border);
	border-radius: 0.4rem;
	background: var(--bg);
	color: inherit;
}
.bots-elo-dash { color: var(--muted); }
.bot-demo-body { justify-content: center; }
.bot-demo-board { display: flex; align-items: center; justify-content: center; }
.bot-demo-title { font-weight: 800; }
.bot-demo-status { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 0.8rem; }
.bot-demo-new { margin-left: auto; }
.starting-positions-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
	gap: 0.8rem;
}
.starting-pos-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 0.7rem;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.5rem;
}
.starting-pos-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	gap: 0.6rem;
}
.starting-pos-rating {
	font-weight: 900;
	font-size: 1.15rem;
	padding: 0.18rem 0.6rem;
	border-radius: 6px;
	background: rgba(99, 102, 241, 0.18);
	color: var(--accent-hover);
}
.starting-pos-rating.sp-rating-tier-trivial       { background: rgba(74, 222, 128, 0.18); color: #4ade80; }
.starting-pos-rating.sp-rating-tier-subset        { background: rgba(34, 211, 238, 0.18); color: #22d3ee; }
.starting-pos-rating.sp-rating-tier-intersect     { background: rgba(251, 191, 36, 0.18); color: #fbbf24; }
.starting-pos-rating.sp-rating-tier-intersect-hard{ background: rgba(248, 113, 113, 0.18); color: #f87171; }
.starting-pos-rating.sp-rating-tier-case          { background: rgba(192, 132, 252, 0.22); color: #c084fc; }
.starting-pos-action {
	font-size: 0.65rem;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	font-weight: 800;
	padding: 0.18rem 0.45rem;
	border-radius: 4px;
}
.starting-pos-action-reveal { background: rgba(74, 222, 128, 0.16); color: #4ade80; }
.starting-pos-action-flag   { background: rgba(248, 113, 113, 0.16); color: #f87171; }
.starting-pos-action-mixed  { background: rgba(251, 191, 36, 0.16); color: #fbbf24; }
.starting-pos-action-case   { background: rgba(192, 132, 252, 0.20); color: #c084fc; }
.starting-pos-canvas {
	display: block;
	border-radius: 4px;
}
.patterns-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
	gap: 1rem;
}
.start-pattern-tags {
	display: flex;
	flex-wrap: wrap;
	gap: 0.3rem;
	margin-top: 0.5rem;
}
.start-pattern-tag {
	font-size: 0.7rem;
	font-weight: 700;
	padding: 0.15rem 0.45rem;
	border-radius: 0.4rem;
	background: rgba(99, 102, 241, 0.15);
	color: var(--accent);
	font-variant-numeric: tabular-nums;
}
.pattern-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 0.85rem;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.6rem;
}
.pattern-card-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	width: 100%;
	gap: 0.6rem;
}
.pattern-card-rating {
	font-weight: 900;
	font-size: 1.15rem;
	padding: 0.18rem 0.6rem;
	border-radius: 6px;
	background: rgba(99, 102, 241, 0.18);
	color: var(--accent-hover);
}
.pattern-card-rating.sp-rating-tier-trivial       { background: rgba(74, 222, 128, 0.18); color: #4ade80; }
.pattern-card-rating.sp-rating-tier-subset        { background: rgba(34, 211, 238, 0.18); color: #22d3ee; }
.pattern-card-rating.sp-rating-tier-intersect     { background: rgba(251, 191, 36, 0.18); color: #fbbf24; }
.pattern-card-rating.sp-rating-tier-intersect-hard{ background: rgba(248, 113, 113, 0.18); color: #f87171; }
.pattern-card-rating.sp-rating-tier-case          { background: rgba(192, 132, 252, 0.22); color: #c084fc; }
.pattern-card-canvas {
	display: block;
}
/* Tournament elimination — pulse on every DOM node tagged with the
 * cut player's id (board slots + scoreboard rows), plus a centered
 * banner with names and final places. Pure CSS animation, removed
 * after ~2.4s so the survivors' board view returns to normal. */
@keyframes elimFlash {
	0%   { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.0); background: transparent; }
	15%  { box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.85); background: rgba(248, 113, 113, 0.22); }
	60%  { box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.65); background: rgba(248, 113, 113, 0.18); }
	100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.0); background: transparent; opacity: 0.55; }
}
.elim-flash { animation: elimFlash 2.4s ease-out forwards; position: relative; }
.elim-flash::after {
	content: "ELIMINATED";
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #fecaca;
	font-weight: 900;
	letter-spacing: 0.18em;
	font-size: 0.9rem;
	text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
	pointer-events: none;
	animation: elimFlashLabel 2.4s ease-out forwards;
}
@keyframes elimFlashLabel {
	0%   { opacity: 0; transform: scale(0.85); }
	20%  { opacity: 1; transform: scale(1.05); }
	80%  { opacity: 1; transform: scale(1); }
	100% { opacity: 0; transform: scale(1); }
}
.elim-banner {
	position: fixed;
	left: 50%;
	top: 28%;
	transform: translate(-50%, -50%);
	background: rgba(248, 113, 113, 0.92);
	color: #1f2937;
	padding: 0.9rem 1.6rem;
	border-radius: 12px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
	z-index: 9999;
	text-align: center;
	font-family: var(--ui-font, system-ui, sans-serif);
	animation: elimBanner 2.6s ease-out forwards;
}
.elim-banner-label { font-size: 0.85rem; font-weight: 900; letter-spacing: 0.2em; text-transform: uppercase; opacity: 0.85; }
.elim-banner-names { font-size: 1.2rem; font-weight: 800; margin-top: 0.3rem; }
@keyframes elimBanner {
	0%   { opacity: 0; transform: translate(-50%, -60%) scale(0.85); }
	15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
	30%  { transform: translate(-50%, -50%) scale(1); }
	80%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
	100% { opacity: 0; transform: translate(-50%, -45%) scale(0.95); }
}

/* === Tournament round-end sequence ====================================
   COTD-style overlay: scrim fades in, full standings list materialises,
   eliminated rows flash red on a stagger, a glowing cutline divider
   draws between survivors and cuts, then the local player gets a
   "SURVIVED" / "ELIMINATED" verdict badge.  The board behind it stays
   visible but dimmed so the next round still feels in-context. */
.tournament-round-overlay {
	position: fixed; inset: 0; z-index: 9000;
	display: flex; align-items: center; justify-content: center;
	background: rgba(8, 12, 24, 0); /* animated to dark */
	pointer-events: none;
	opacity: 0;
	transition: opacity 0.28s ease, background-color 0.28s ease;
}
.tournament-round-overlay[hidden] { display: none; }
.tournament-round-overlay.visible {
	opacity: 1;
	background: rgba(8, 12, 24, 0.78);
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
}
.tournament-round-overlay .tro-frame {
	width: min(560px, 88vw);
	max-height: 86vh;
	display: flex; flex-direction: column; gap: 0.7rem;
	padding: 1.1rem 1.4rem 1.3rem;
	border-radius: 0.9rem;
	background: linear-gradient(180deg, rgba(30, 41, 65, 0.95), rgba(15, 23, 42, 0.95));
	border: 1px solid rgba(148, 163, 184, 0.18);
	box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
	transform: translateY(14px);
	transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.25, 1);
}
.tournament-round-overlay.visible .tro-frame { transform: translateY(0); }

.tro-header { display: flex; align-items: baseline; gap: 0.7rem; justify-content: space-between; }
.tro-round {
	font-size: 0.72rem; font-weight: 800; letter-spacing: 0.16em;
	text-transform: uppercase; color: #cbd5e1;
}
.tro-sub { font-size: 0.7rem; font-weight: 700; color: #94a3b8; letter-spacing: 0.06em; }

.tro-rows {
	display: flex; flex-direction: column; gap: 0.25rem;
	max-height: 60vh; overflow: hidden;
	position: relative;
}
.tro-row {
	display: grid;
	grid-template-columns: 2.1rem 1fr auto;
	align-items: center;
	padding: 0.42rem 0.65rem;
	border-radius: 0.45rem;
	background: rgba(30, 41, 59, 0.65);
	border: 1px solid transparent;
	font-size: 0.92rem;
	opacity: 0;
	transform: translateX(-12px);
	animation: troRowIn 0.32s ease forwards;
	transition: background-color 0.25s ease, border-color 0.25s ease, transform 0.45s cubic-bezier(0.2, 0.8, 0.25, 1);
	position: relative;
}
@keyframes troRowIn {
	to { opacity: 1; transform: translateX(0); }
}
.tro-row .tro-rank { font-weight: 800; color: #94a3b8; }
.tro-row .tro-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tro-row .tro-detail { font-size: 0.78rem; color: #94a3b8; font-variant-numeric: tabular-nums; }

/* The "you" row: stays subtly highlighted at neutral state so the eye
   tracks your card through the reorder without it screaming. */
.tro-row.tro-row-me {
	background: rgba(99, 102, 241, 0.18);
	border-color: rgba(129, 140, 248, 0.45);
}

/* Cut rows: triggered ~150ms apart from bottom up. Flash, then settle
   to a muted red so the eye can still parse who was eliminated. */
.tro-row.tro-cut {
	animation: troRowIn 0.32s ease forwards, troCutFlash 0.6s ease forwards;
}
@keyframes troCutFlash {
	0%   { background: rgba(248, 113, 113, 0.0); border-color: transparent; }
	18%  { background: rgba(248, 113, 113, 0.55); border-color: rgba(252, 165, 165, 0.9); transform: translateX(2px); }
	36%  { transform: translateX(-2px); }
	60%  { transform: translateX(0); }
	100% { background: rgba(127, 29, 29, 0.30); border-color: rgba(248, 113, 113, 0.35); }
}
.tro-row.tro-cut .tro-rank,
.tro-row.tro-cut .tro-name,
.tro-row.tro-cut .tro-detail { color: #fca5a5; }
.tro-row.tro-cut .tro-name { text-decoration: line-through; text-decoration-color: rgba(252, 165, 165, 0.55); }

/* Survivor highlight: fires once all cuts are flashed, single green
   pulse on every surviving row. */
.tro-row.tro-survive {
	animation: troRowIn 0.32s ease forwards, troSurviveGlow 0.9s ease forwards;
}
@keyframes troSurviveGlow {
	0%   { background: rgba(34, 197, 94, 0.0); }
	35%  { background: rgba(34, 197, 94, 0.32); border-color: rgba(134, 239, 172, 0.7); }
	100% { background: rgba(22, 101, 52, 0.22); border-color: rgba(74, 222, 128, 0.35); }
}

/* Cutline divider — animated horizontal rule between the last survivor
   and the first cut. Glows briefly when drawn. */
.tro-cutline {
	position: relative;
	height: 0; margin: 0;
	border: 0;
	border-top: 1px dashed rgba(248, 113, 113, 0.65);
	opacity: 0;
	transform: scaleX(0.5);
	transition: opacity 0.3s ease, transform 0.4s ease;
}
.tro-cutline.visible { opacity: 1; transform: scaleX(1); }
.tro-cutline::after {
	content: "CUT"; position: absolute; right: 0; top: -0.6rem;
	font-size: 0.6rem; font-weight: 900; letter-spacing: 0.18em;
	color: #fca5a5; background: rgba(127, 29, 29, 0.7);
	padding: 0.15rem 0.4rem; border-radius: 0.3rem;
}

/* Verdict badge: SURVIVED / ELIMINATED, slides in after the row work
   is done.  The .close variant grows + shakes a little — used when the
   player squeaked through within 1 rank of the cut. */
.tro-verdict {
	margin-top: 0.4rem;
	text-align: center;
	font-size: 1.4rem; font-weight: 900; letter-spacing: 0.18em;
	text-transform: uppercase;
	opacity: 0;
	transform: translateY(8px);
	transition: opacity 0.3s ease, transform 0.45s cubic-bezier(0.2, 0.8, 0.25, 1);
}
.tro-verdict.show { opacity: 1; transform: translateY(0); }
.tro-verdict.survived { color: #4ade80; text-shadow: 0 0 24px rgba(34, 197, 94, 0.6); }
.tro-verdict.eliminated { color: #f87171; text-shadow: 0 0 22px rgba(239, 68, 68, 0.55); }
.tro-verdict.close { animation: troClose 0.7s ease; font-size: 1.6rem; }
.tro-verdict-sub {
	display: block; font-size: 0.7rem; font-weight: 700;
	letter-spacing: 0.08em; opacity: 0.8; margin-top: 0.3rem;
	color: #cbd5e1;
}
@keyframes troClose {
	0%   { transform: translateY(8px) scale(0.9); }
	30%  { transform: translateY(0)   scale(1.08); }
	60%  { transform: translateY(0)   scale(0.98); }
	100% { transform: translateY(0)   scale(1); }
}

/* Escalation: later rounds (when the field is small) get a tighter,
   redder frame so the stakes read visually. Driven by data-round on
   the overlay element. */
.tournament-round-overlay[data-stage="late"].visible {
	background: rgba(20, 8, 12, 0.82);
}
.tournament-round-overlay[data-stage="late"] .tro-frame {
	border-color: rgba(248, 113, 113, 0.35);
	box-shadow: 0 30px 80px rgba(127, 29, 29, 0.45);
}
.tournament-round-overlay[data-stage="final"].visible {
	background: rgba(28, 6, 10, 0.86);
}
.tournament-round-overlay[data-stage="final"] .tro-frame {
	border-color: rgba(248, 113, 113, 0.55);
	box-shadow: 0 30px 90px rgba(127, 29, 29, 0.55), 0 0 0 1px rgba(248, 113, 113, 0.25) inset;
}

/* Pre-round preview: "N eliminations this round" — a quiet label that
   floats above the countdown digits.  Muted by design; the round overlay
   sequence already does the loud talking. */
.round-cut-preview {
	position: absolute;
	left: 50%; top: 12%;
	transform: translate(-50%, 0);
	padding: 0.3rem 0.7rem;
	color: rgba(203, 213, 225, 0.7);
	font-size: 0.78rem; font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	white-space: nowrap;
	animation: roundCutIn 0.45s cubic-bezier(0.2, 0.8, 0.25, 1);
	z-index: 5;
	pointer-events: none;
}
@keyframes roundCutIn {
	0%   { opacity: 0; transform: translate(-50%, -6px); }
	100% { opacity: 1; transform: translate(-50%, 0); }
}
.pattern-card-method {
	font-size: 0.65rem;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	font-weight: 800;
	padding: 0.18rem 0.5rem;
	border-radius: 4px;
}
.pattern-method-trivial   { background: rgba(74, 222, 128, 0.18); color: #4ade80; }
.pattern-method-subset    { background: rgba(34, 211, 238, 0.18); color: #22d3ee; }
.pattern-method-intersect { background: rgba(251, 191, 36, 0.18); color: #fbbf24; }
.pattern-method-union     { background: rgba(251, 146, 60, 0.18); color: #fb923c; }
.pattern-method-case      { background: rgba(192, 132, 252, 0.22); color: #c084fc; }
.pattern-method-enum      { background: rgba(248, 113, 113, 0.20); color: #f87171; }
.pattern-card-details { color: var(--text); font-size: 0.85rem; font-weight: 700; }
.pattern-card-uses { color: var(--muted); font-size: 0.75rem; }
.starting-pos-details { color: var(--muted); font-size: 0.72rem; }
.starting-pos-pattern { color: rgba(148, 163, 184, 0.7); font-size: 0.66rem; font-family: monospace; letter-spacing: 0.04em; }
.puzzle-card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 0.7rem 0.8rem 0.6rem;
	display: flex;
	flex-direction: column;
	gap: 0.45rem;
}
.puzzle-card-head { display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; }
.puzzle-diff-badge {
	font-size: 0.7rem;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	font-weight: 800;
	padding: 0.18rem 0.5rem;
	border-radius: 4px;
	background: rgba(99, 102, 241, 0.18);
	color: var(--accent-hover);
}
/* 1 trivial · 2 subset · 3 subset chain · 4–6 case analysis by frontier size */
.puzzle-card.puzzle-diff-1 .puzzle-diff-badge { background: rgba(74, 222, 128, 0.18); color: #4ade80; }
.puzzle-card.puzzle-diff-2 .puzzle-diff-badge { background: rgba(34, 211, 238, 0.18); color: #22d3ee; }
.puzzle-card.puzzle-diff-3 .puzzle-diff-badge { background: rgba(251, 191, 36, 0.18); color: #fbbf24; }
.puzzle-card.puzzle-diff-4 .puzzle-diff-badge { background: rgba(251, 146, 60, 0.18); color: #fb923c; }
.puzzle-card.puzzle-diff-5 .puzzle-diff-badge { background: rgba(248, 113, 113, 0.18); color: #f87171; }
.puzzle-card.puzzle-diff-6 .puzzle-diff-badge { background: rgba(192, 132, 252, 0.22); color: #c084fc; }
.puzzle-card-meta { font-size: 0.75rem; color: var(--muted); }
.puzzle-card-label { font-size: 0.8rem; font-weight: 600; margin: 0.45rem 0 0.1rem; }
.puzzle-card .learn-puzzle { padding: 0; }
/* Wide combined boards (up to ~11 cols) are rendered at a fixed cell size; scale the canvas
   down to fit its card / modal column instead of overflowing. `width: fit-content` keeps the
   board tray hugging the canvas (so narrow boards don't leave a dark gap) while `max-width:100%`
   caps it to the container; the canvas carries an inline width+height (px), so height:auto needs
   !important to win and keep the cells square as the width scales. */
.puzzle-card .learn-board { display: block; width: fit-content; max-width: 100%; margin: 0 auto; box-sizing: border-box; }
.puzzle-card .learn-board canvas { display: block; max-width: 100%; height: auto !important; }
.analyze-modal-board .learn-board { width: fit-content; max-width: 100%; margin: 0 auto; box-sizing: border-box; }
.analyze-modal-board .learn-board canvas { display: block; max-width: 100%; height: auto !important; }

/* Combined-puzzles page: group headings + the seam-conflict note. */
.section-page-subtitle { font-size: 1rem; margin: 1.6rem 0 0.7rem; color: var(--text); }
.combined-section-blurb { color: var(--muted); font-size: 0.82rem; margin: -0.3rem 0 0.9rem; max-width: 60ch; }

/* Territory (versus) mode — plays on the shared game board, with racing chrome hidden. */
/* Territory breaks out of the 1200px content column to use the full viewport width below the nav. */
body.territory-fullscreen main { max-width: none; padding: 0.6rem; }
/* Territory uses the whole width below the nav: drop the racing side column and chrome, and
   let the board card hug and centre the (fit-to-space) board. */
.game-view.territory .game-side { display: none; }
.game-view.territory .player-controls { display: none; }
.game-view.territory #player_name0 { display: none; }
.game-view.territory .hotkey-hint { display: none; }
.game-view.territory .game-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
.game-view.territory .game-left { text-align: center; }
.game-view.territory .player-board { display: inline-block; text-align: center; padding: 0.6rem; max-width: 100%; }
.game-view.territory #territory_hud { max-width: none; }
.game-view.territory .board-wrap { display: inline-block; }
#territory_hud { margin: 0 0 0.7rem; }
.tv-result-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(11,18,32,0.62); border-radius: 8px; z-index: 6; }
.tv-elo { color: var(--muted); font-size: 0.85rem; }
.tv-hud { display: flex; align-items: center; gap: 0.8rem; width: 100%; max-width: 560px; }
.tv-hud-multi { flex-direction: column; align-items: stretch; gap: 0.4rem; }
.tv-hud-multi .tv-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem 1.2rem; }
.tv-chip { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; white-space: nowrap; }
.tv-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.tv-name { color: var(--text); }
.tv-score { font-weight: 700; color: var(--text); }
.tv-energy { font-weight: 700; font-variant-numeric: tabular-nums; }
.tv-bomb-btn { margin-left: auto; padding: 0.3rem 0.7rem; font-size: 0.82rem; font-weight: 600; white-space: nowrap;
	border: 1px solid rgba(120, 150, 200, 0.35); background: rgba(30, 41, 66, 0.6); color: var(--text); }
.tv-bomb-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.tv-bomb-btn.aiming { background: #b91c1c; border-color: #fca5a5; color: #fff; animation: tv-bomb-pulse 1s ease-in-out infinite; }
@keyframes tv-bomb-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.5); } 50% { box-shadow: 0 0 0 6px rgba(248, 113, 113, 0); } }
body.tv-aiming #game0, body.tv-aiming .board-wrap canvas { cursor: crosshair; }
.tv-bar { flex: 1; height: 10px; background: #1b2742; border-radius: 6px; display: flex; justify-content: space-between; overflow: hidden; }
.tv-bar-fill { height: 100%; transition: width 0.2s ease; }
.tv-board-wrap { position: relative; line-height: 0; }
#tv_canvas { border-radius: 8px; background: #0b1220; cursor: pointer; }
.tv-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(11,18,32,0.55); border-radius: 8px; }
.tv-count { font-size: 4rem; font-weight: 800; color: var(--text); text-shadow: 0 2px 12px rgba(0,0,0,0.6); }
.tv-result { text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.4rem 1.8rem; }
.tv-result h2 { margin: 0 0 0.5rem; }
.tv-result p { margin: 0 0 1rem; color: var(--muted); }
.tv-result-actions { display: flex; gap: 0.6rem; justify-content: center; flex-wrap: wrap; }
.tv-result-pill { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 6; }
.tv-status { color: var(--muted); font-size: 0.8rem; margin: 0; }
.combined-unsat-note { margin-top: 1.8rem; }
.combined-unsat-list { color: var(--muted); font-size: 0.85rem; line-height: 1.6; margin: 0; padding-left: 1.2rem; }
.puzzle-card .learn-puzzle-title { display: none; }
.puzzle-card .learn-controls { margin-top: 0.4rem; }

@media (max-width: 900px) {
	.home-cards { grid-template-columns: 1fr; }
}

.result-actions {
	display: flex;
	gap: 0.55rem;
	justify-content: center;
	margin-top: 0.8rem;
}

.result-actions .btn { flex: 0 0 auto; }

.ranked-searching {
	margin-top: 1rem;
	color: var(--text);
	font-size: 0.95rem;
}

.ranked-search-header {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	font-weight: 600;
	font-size: 1.05rem;
	margin-bottom: 1.1rem;
}

.ranked-search-header > span:not(.ranked-spinner) { flex: 1; }

.search-progress-wrap {
	position: relative;
	width: 200px;
	height: 200px;
	margin: 0.5rem auto 0.4rem;
}

.search-progress-ring {
	width: 100%;
	height: 100%;
	transform: rotate(-90deg);
}

.search-progress-bg, .search-progress-fill {
	fill: none;
	stroke-width: 9;
}

.search-progress-bg { stroke: rgba(255, 255, 255, 0.08); }

.search-progress-fill {
	stroke: url(#search-progress-gradient);
	stroke-linecap: round;
	/* Circumference of r=52 is 2*pi*52 ≈ 326.73. JS sets dashoffset based on progress. */
	stroke-dasharray: 326.73;
	stroke-dashoffset: 326.73;
	stroke: var(--accent-hover);
	transition: stroke-dashoffset 0.45s cubic-bezier(.22,1,.36,1);
	filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.45));
}

.search-progress-text {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	pointer-events: none;
}

.search-progress-count {
	font-size: 3.4rem;
	font-weight: 800;
	line-height: 1;
	font-variant-numeric: tabular-nums;
}

.search-progress-of {
	color: var(--muted);
	font-size: 0.9rem;
	letter-spacing: 0.05em;
	margin-top: 0.2rem;
}

.ranked-slots {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
	gap: 0.6rem;
}

.ranked-slot {
	background: rgba(255, 255, 255, 0.04);
	border: 1px solid rgba(99, 102, 241, 0.18);
	border-radius: 10px;
	padding: 0.75rem 0.9rem;
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	min-height: 76px;
	justify-content: center;
	animation: ranked-slot-in 280ms ease both;
}

.ranked-slot-empty {
	color: var(--muted);
	font-style: italic;
	background: rgba(255, 255, 255, 0.015);
	border-style: dashed;
	border-color: rgba(255, 255, 255, 0.1);
	animation: ranked-slot-pulse 1.6s ease-in-out infinite;
}

.ranked-slot-you {
	background: rgba(99, 102, 241, 0.18);
	border-color: rgba(99, 102, 241, 0.55);
}

.ranked-slot-name {
	font-weight: 700;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.ranked-slot-meta {
	color: var(--muted);
	font-size: 0.85rem;
	display: flex;
	align-items: baseline;
	gap: 0.4rem;
}

.ranked-slot-tier { font-weight: 700; }
.ranked-slot-rating { font-variant-numeric: tabular-nums; }
.ranked-slot-you-tag {
	background: var(--accent);
	color: #fff;
	font-size: 0.65rem;
	font-weight: 700;
	letter-spacing: 0.06em;
	padding: 0.05rem 0.4rem;
	border-radius: 4px;
}

@keyframes ranked-slot-in {
	from { opacity: 0; transform: translateY(6px) scale(0.97); }
	to   { opacity: 1; transform: none; }
}

@keyframes ranked-slot-pulse {
	0%, 100% { opacity: 0.55; }
	50%      { opacity: 0.85; }
}

.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-danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #ef4444; border-color: #ef4444; }

.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; position: relative; }

/* Subtle red glow around the player's own board when they're currently below
   the elimination cut. Hugs the board frame instead of the whole viewport. */
.player-board.danger {
	border-color: rgba(239, 68, 68, 0.55);
	animation: danger-board-pulse 1.6s ease-in-out infinite alternate;
}

@keyframes danger-board-pulse {
	from {
		box-shadow: var(--shadow), 0 0 12px 1px rgba(239, 68, 68, 0.25), inset 0 0 0 1px rgba(239, 68, 68, 0.25);
	}
	to {
		box-shadow: var(--shadow), 0 0 28px 4px rgba(239, 68, 68, 0.55), inset 0 0 0 1px rgba(239, 68, 68, 0.5);
	}
}

.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) 320px;
	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;
}

/* Quick board-border pulse for run-mode solve / miss confirmation. Fast
   (~280ms) so the next puzzle can land while the eye still registers the
   green/red feedback. */
.board-wrap.flash-solved { animation: boardFlashSolved 280ms ease-out forwards; }
.board-wrap.flash-fail   { animation: boardFlashFail   280ms ease-out forwards; }
@keyframes boardFlashSolved {
	0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
	35%  { box-shadow: 0 0 0 10px rgba(74, 222, 128, 0.55); }
	100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}
@keyframes boardFlashFail {
	0%   { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0); }
	35%  { box-shadow: 0 0 0 10px rgba(248, 113, 113, 0.55); }
	100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0); }
}

@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. Lifted out of the board-wrap to a fixed
   centered modal so big lobbies (16-player tournament final) can list every
   player without bleeding past the board edges. */
.board-overlay-panel {
	/* Positioned within .board-wrap (which is position: relative) so the
	   panel is centered on the player's board rather than the whole viewport
	   — keeps it visually aligned with the game area instead of drifting
	   towards the sidebar. */
	position: absolute;
	inset: auto;
	top: 50%;
	left: 50%;
	right: auto;
	bottom: auto;
	transform: translate(-50%, -50%);
	width: min(94vw, 480px);
	max-height: 90vh;
	font-size: 1rem;
	background: rgba(11, 16, 32, 0.98);
	backdrop-filter: blur(8px);
	border: 1px solid rgba(99, 102, 241, 0.32);
	border-radius: 16px;
	box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
	padding: 1.4rem 1.5rem;
	pointer-events: auto;
	display: flex;
	align-items: stretch;
	justify-content: center;
	z-index: 200;
}

.result-panel {
	width: 100%;
	max-width: none;
	display: flex;
	flex-direction: column;
	gap: 0.55rem;
	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; }

/* === Tournament champion panel ====================================
   Single-subject celebration shown after the final round.  No ladder,
   just the winner, their tier, and the rating bump.  Trophy gets a
   gentle bounce-in + slow rotation; the champion's name uses a gold
   gradient so it pops without needing confetti effects. */
.champion-panel {
	align-items: center;
	gap: 0.45rem;
	padding: 1.4rem 1.4rem 1.1rem;
	text-align: center;
	position: relative;
	overflow: hidden;
}
.champion-panel::before {
	content: "";
	position: absolute; inset: 0;
	background: radial-gradient(ellipse at top, rgba(251, 191, 36, 0.22), transparent 65%);
	pointer-events: none;
	z-index: 0;
}
.champion-panel > * { position: relative; z-index: 1; }
.champion-trophy {
	font-size: 5rem;
	line-height: 1;
	animation: championTrophyIn 0.8s cubic-bezier(0.2, 0.8, 0.25, 1.4);
	filter: drop-shadow(0 6px 18px rgba(251, 191, 36, 0.55));
}
@keyframes championTrophyIn {
	0%   { opacity: 0; transform: scale(0.4) rotate(-18deg); }
	60%  { opacity: 1; transform: scale(1.15) rotate(4deg); }
	100% { opacity: 1; transform: scale(1)   rotate(0); }
}
.champion-tagline {
	font-size: 0.78rem;
	font-weight: 800;
	letter-spacing: 0.22em;
	text-transform: uppercase;
	color: #fbbf24;
	opacity: 0;
	animation: championFadeUp 0.45s ease 0.35s forwards;
}
.champion-name {
	font-size: 2.2rem;
	font-weight: 900;
	line-height: 1;
	letter-spacing: -0.01em;
	background: linear-gradient(135deg, #fde68a, #f59e0b 55%, #fbbf24);
	-webkit-background-clip: text;
	background-clip: text;
	color: transparent;
	opacity: 0;
	animation: championFadeUp 0.55s ease 0.5s forwards;
	text-shadow: 0 0 32px rgba(251, 191, 36, 0.35);
}
.champion-rating {
	font-size: 0.95rem;
	font-weight: 600;
	color: var(--text);
	opacity: 0;
	animation: championFadeUp 0.45s ease 0.75s forwards;
}
.champion-tier { font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.champion-delta.up   { color: #4ade80; font-weight: 800; }
.champion-delta.down { color: #f87171; font-weight: 800; }
.champion-yours {
	margin-top: 0.4rem;
	font-size: 0.82rem;
	color: var(--muted);
	letter-spacing: 0.04em;
	opacity: 0;
	animation: championFadeUp 0.45s ease 0.9s forwards;
}
.champion-actions {
	margin-top: 0.7rem;
	display: flex; gap: 0.6rem; justify-content: center;
	opacity: 0;
	animation: championFadeUp 0.4s ease 1.05s forwards;
}
@keyframes championFadeUp {
	from { opacity: 0; transform: translateY(8px); }
	to   { opacity: 1; transform: translateY(0); }
}

.result-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	/* The modal panel already caps at 90vh; let the list grow so 16-row
	   tournament finals fit without scrolling on a normal-sized screen. */
	max-height: 70vh;
	overflow-y: auto;
}

.result-row {
	padding: 0.32rem 0.55rem;
}

.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; }

.match-reveal-counter {
	margin-top: 0.4rem;
	color: var(--accent-hover);
	font-size: 0.95rem;
	font-weight: 700;
	letter-spacing: 0.04em;
}

/* ---- Ranked 1v1 pre-match: big VS card --------------------------------- */
.vs-display {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 1.2rem;
	margin: 1.2rem 0 0.4rem;
}
.vs-card {
	flex: 1 1 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.7rem;
	padding: 1.2rem 0.9rem 1rem;
	background: rgba(15, 23, 42, 0.55);
	border: 1px solid rgba(148, 163, 184, 0.18);
	border-radius: 14px;
	min-width: 0;
}
.vs-card-me { background: rgba(99, 102, 241, 0.18); border-color: rgba(99, 102, 241, 0.5); }
.vs-card .rank-badge { width: 110px; height: 110px; }
.vs-card .rank-badge-numeral { font-size: 2rem; }
.vs-card .rank-badge-tier { font-size: 0.65rem; }
.vs-card .rank-badge-icon { font-size: 2.1rem; }
.vs-name {
	font-size: 1.25rem;
	font-weight: 800;
	color: var(--text);
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.vs-rating {
	font-size: 0.95rem;
	font-weight: 600;
	letter-spacing: 0.02em;
}
.vs-divider {
	font-size: 2.2rem;
	font-weight: 900;
	color: var(--accent-hover);
	letter-spacing: 0.04em;
	text-shadow: 0 0 14px rgba(99, 102, 241, 0.45);
	flex: 0 0 auto;
}

/* ---- Ranked 6-player pre-match: 3×2 cards ------------------------------ */
.six-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 0.75rem;
	margin: 1rem 0 0.3rem;
}
.six-card {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.45rem;
	padding: 0.85rem 0.6rem 0.7rem;
	background: rgba(15, 23, 42, 0.55);
	border: 1px solid rgba(148, 163, 184, 0.18);
	border-radius: 12px;
	min-width: 0;
	opacity: 0;
	animation: result-row-in 0.32s ease-out forwards;
}
.six-card-me { background: rgba(99, 102, 241, 0.18); border-color: rgba(99, 102, 241, 0.5); }
.six-card .rank-badge { width: 72px; height: 72px; }
.six-card .rank-badge-numeral { font-size: 1.3rem; }
.six-card .rank-badge-tier { font-size: 0.5rem; }
.six-card .rank-badge-icon { font-size: 1.5rem; }
.six-name {
	font-size: 0.95rem;
	font-weight: 700;
	color: var(--text);
	max-width: 100%;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.six-rating { font-size: 0.78rem; font-weight: 600; }

@media (max-width: 700px) {
	.vs-display { flex-direction: column; gap: 0.7rem; }
	.vs-divider { font-size: 1.6rem; }
	.six-grid { grid-template-columns: repeat(2, 1fr); }
}

.tournament-place {
	text-align: center;
	font-weight: 800;
	font-size: 1.5rem;
	color: var(--accent-hover);
	margin: 0.5rem 0;
	letter-spacing: 0.02em;
}
.tournament-delta { text-align: center; font-weight: 700; font-size: 1.05rem; margin-bottom: 0.6rem; }
.tournament-delta-up   { color: #4ade80; }
.tournament-delta-down { color: #f87171; }

/* Result panel body: rank-swap column on the left, standings on the right. */
.result-body {
	display: flex;
	align-items: center;
	gap: 1.1rem;
}

.result-body > .result-list { flex: 1; min-width: 0; }

.result-rank-column {
	flex: 0 0 auto;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.45rem;
	width: 108px;
}

.rank-swap {
	position: relative;
	width: 92px;
	height: 92px;
}

.rank-badge {
	width: 92px;
	height: 92px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-direction: column;
	font-weight: 800;
	color: #fff;
	text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45), inset 0 -4px 0 rgba(0, 0, 0, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.2);
	border: 3px solid rgba(255, 255, 255, 0.22);
	user-select: none;
}

/* Inside the swap container, both badges stack on top of each other. */
.rank-swap .rank-badge {
	position: absolute;
	inset: 0;
	width: auto;
	height: auto;
}

.rank-badge-numeral { font-size: 1.6rem; line-height: 1; letter-spacing: 0.02em; }
.rank-badge-tier { font-size: 0.55rem; letter-spacing: 0.18em; opacity: 0.85; margin-top: 0.2rem; }
.rank-badge-icon { font-size: 1.7rem; line-height: 1; }

.rank-badge.tier-bronze   { background: linear-gradient(140deg, #d08b5b 0%, #6b3f23 100%); }
.rank-badge.tier-silver   { background: linear-gradient(140deg, #e2e8f0 0%, #475569 100%); }
.rank-badge.tier-gold     { background: linear-gradient(140deg, #fbbf24 0%, #92400e 100%); box-shadow: 0 0 24px rgba(251, 191, 36, 0.3), 0 6px 18px rgba(0, 0, 0, 0.45), inset 0 -4px 0 rgba(0, 0, 0, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.2); }
.rank-badge.tier-platinum { background: linear-gradient(140deg, #5eead4 0%, #0d9488 100%); box-shadow: 0 0 22px rgba(94, 234, 212, 0.3), 0 6px 18px rgba(0, 0, 0, 0.45), inset 0 -4px 0 rgba(0, 0, 0, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.2); }
.rank-badge.tier-diamond  { background: linear-gradient(140deg, #60a5fa 0%, #1d4ed8 100%); box-shadow: 0 0 24px rgba(96, 165, 250, 0.4), 0 6px 18px rgba(0, 0, 0, 0.45), inset 0 -4px 0 rgba(0, 0, 0, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.2); }
.rank-badge.tier-master   { background: linear-gradient(140deg, #c084fc 0%, #581c87 100%); box-shadow: 0 0 30px rgba(192, 132, 252, 0.55), 0 6px 18px rgba(0, 0, 0, 0.45), inset 0 -4px 0 rgba(0, 0, 0, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.2); }

.rank-swap.changed .rank-badge-old { animation: rank-icon-out 0.75s cubic-bezier(.55, .05, .7, .35) forwards; }
.rank-swap.changed .rank-badge-new { opacity: 0; animation: rank-icon-in 0.75s cubic-bezier(.22, 1, .36, 1) 0.55s forwards; }

@keyframes rank-icon-out {
	0%   { opacity: 1; transform: scale(1) rotate(0); }
	55%  { opacity: 1; transform: scale(1.12) rotate(-8deg); }
	100% { opacity: 0; transform: scale(0.55) rotate(-32deg); }
}

@keyframes rank-icon-in {
	0%   { opacity: 0; transform: scale(0.45) rotate(22deg); }
	55%  { opacity: 1; transform: scale(1.18) rotate(-2deg); }
	100% { opacity: 1; transform: scale(1) rotate(0); }
}

.result-rank-rating {
	text-align: center;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	font-size: 1rem;
	line-height: 1.15;
}

.result-rank-delta {
	font-size: 0.85rem;
	font-weight: 800;
	letter-spacing: 0.02em;
	display: block;
	margin-top: 0.1rem;
}

.result-rank-delta.gain { color: #4ade80; }
.result-rank-delta.loss { color: #f87171; }
.result-rank-delta.flat { color: var(--muted); }

.result-rank-changed {
	font-size: 0.7rem;
	letter-spacing: 0.15em;
	font-weight: 800;
	margin-top: 0.15rem;
	color: var(--muted);
}

.result-rank-changed.promoted { color: #4ade80; }
.result-rank-changed.demoted { color: #f87171; }

@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;
}

/* Flag-mode toggle — only rendered for touch input (set via body.touch).
   The mode flips what a single tap on the board does; long-press always flags. */
.flag-mode-button {
	display: none;
	align-items: center;
	gap: 0.45rem;
	font: inherit;
	font-weight: 600;
	background: var(--surface-2);
	border: 1px solid var(--border);
	color: var(--text);
	border-radius: 8px;
	padding: 0.55rem 0.9rem;
	cursor: pointer;
	user-select: none;
	touch-action: manipulation;
	transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

body.touch .flag-mode-button { display: inline-flex; }

.flag-mode-button[aria-pressed="true"] {
	background: rgba(239, 68, 68, 0.85);
	border-color: rgba(239, 68, 68, 1);
	color: #fff;
	box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25);
}

.flag-mode-icon { font-size: 1rem; line-height: 1; }
.flag-mode-label { line-height: 1; }

/* Let the browser pan inside the scroll container but block pinch/double-tap zoom. */
#game0 { touch-action: pan-x pan-y; }

/* Board scroll container — pass-through on desktop, a scrollable viewport on mobile. */
.board-scroll {
	display: inline-block;
	line-height: 0; /* eliminate gap under inline canvas */
}

/* A directional arrow that only appears on touch devices when there's nothing
   to do in the current viewport and unrevealed frontier exists elsewhere. The
   glyph rotates per-direction; the button itself snaps to the nearest edge. */
.find-next-arrow {
	position: absolute;
	z-index: 4;
	display: none;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: rgba(99, 102, 241, 0.92);
	color: #fff;
	border: 2px solid var(--accent-hover);
	box-shadow: var(--shadow);
	cursor: pointer;
	touch-action: manipulation;
	user-select: none;
	font-size: 0;
	padding: 0;
	opacity: 0;
	transition: opacity 180ms ease;
	pointer-events: none;
}

/* On touch devices it's always mounted (display:inline-flex) but invisible until
   the .visible class is added — needed so the opacity transition can run. */
body.touch .find-next-arrow { display: inline-flex; }
.find-next-arrow.visible { opacity: 1; pointer-events: auto; }

.find-next-arrow-glyph {
	display: inline-block;
	font-size: 1.4rem;
	line-height: 1;
	font-weight: 800;
}

.find-next-arrow:active { transform: scale(0.95); }
.player-board.idle .find-next-arrow { display: none; }

.opponents {
	display: flex;
	flex-direction: column;
	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);
}

/* The live leaderboard sits at the top of the side column — give it the same
   visual weight as the player board so it can show more entries. */
#scoreboard_card { min-height: 480px; display: flex; flex-direction: column; }
#scoreboard_card .scoreboard { flex: 1; }

.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;
	position: relative;
}

.score-row-gap {
	display: block;
	text-align: center;
	color: var(--muted);
	font-weight: 700;
	letter-spacing: 0.1em;
	padding: 0.2rem 0;
	background: transparent;
	border: none;
	font-size: 0.9rem;
}

.score-progress {
	display: inline-block;
	width: 60px;
	height: 6px;
	background: rgba(255, 255, 255, 0.08);
	border-radius: 3px;
	overflow: hidden;
}

.score-progress-fill {
	display: block;
	height: 100%;
	background: linear-gradient(90deg, var(--accent), var(--accent-hover));
	transition: width 0.25s ease-out;
}

.score-progress-finished .score-progress-fill {
	background: linear-gradient(90deg, var(--success), #4ade80);
}

.score-pct {
	font-variant-numeric: tabular-nums;
	font-weight: 700;
	font-size: 0.82rem;
	text-align: right;
}

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

/* Spectator: rows become clickable to switch the big-board target. The
   current target gets a teal outline + a small "watching" indicator. */
.score-row-spectatable { cursor: pointer; }
.score-row-spectatable:hover {
	background: rgba(45, 212, 191, 0.08);
	border-color: rgba(45, 212, 191, 0.3);
}
.score-row-watching {
	background: rgba(45, 212, 191, 0.18) !important;
	border-color: rgba(45, 212, 191, 0.55) !important;
}
.score-row-watching::before {
	content: "▶"; position: absolute; left: -0.55rem;
	color: #2dd4bf; font-size: 0.6rem;
}

.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-tier, .result-tier {
	display: inline-block;
	font-size: 0.7rem;
	font-weight: 700;
	letter-spacing: 0.02em;
	margin-left: 0.15rem;
}

.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; }
}

/* Mobile: hide the unreadable mini opponent boards and the keyboard hint;
   the scoreboard already shows each opponent's tier and status. */
@media (max-width: 700px) {
	.opponents { display: none; }
	.hotkey-hint { display: none; }
	.player-controls { flex-wrap: wrap; }
	.flag-mode-button { padding: 0.7rem 1rem; }

	/* Full-bleed: pull the player board out of `main`'s padding so the playing
	   surface meets the screen edges. Inner content (name, controls) gets its
	   own horizontal padding so only the scrollable board hits the edge. */
	.player-board {
		display: block;
		padding: 0.6rem 0;
		margin-left: calc(50% - 50vw);
		margin-right: calc(50% - 50vw);
		width: 100vw;
		max-width: 100vw;
		border-left: none;
		border-right: none;
		border-radius: 0;
		box-shadow: none;
	}
	.player-board > .player-name { padding: 0 1rem; margin-bottom: 0.45rem; }
	.player-board > .player-controls { padding: 0.55rem 1rem 0; }

	.board-wrap { display: block; }
	.board-scroll {
		display: block;
		max-width: 100%;
		max-height: 75vh;
		overflow: auto;
		-webkit-overflow-scrolling: touch;
		touch-action: pan-x pan-y;
		overscroll-behavior: contain;
		border-radius: 0;
		background: var(--bg);
	}
	#game0 { max-width: none !important; width: auto; }
}

@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; }

	.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; }
}

/* ---- Learn: interactive deduction trainer ---- */
.learn-lessons { margin-bottom: 1rem; }

/* Stepper bar above the current lesson — circles 1-8 with progress arcs. */
.learn-stepper {
	display: flex;
	align-items: center;
	gap: 0.25rem;
	margin-bottom: 1.25rem;
	flex-wrap: wrap;
}

.learn-step {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	background: var(--surface);
	border: 1px solid var(--border);
	color: var(--muted);
	font-weight: 700;
	font-size: 0.85rem;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: not-allowed;
	transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 80ms ease;
	flex: 0 0 auto;
}

.learn-step.unlocked { cursor: pointer; }
.learn-step.unlocked:hover { transform: translateY(-1px); border-color: var(--accent-hover); color: var(--text); }

.learn-step.done {
	background: rgba(34, 197, 94, 0.22);
	border-color: rgba(34, 197, 94, 0.55);
	color: #4ade80;
}

.learn-step.current {
	background: rgba(99, 102, 241, 0.28);
	border-color: rgba(99, 102, 241, 0.7);
	color: #fff;
	box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.learn-step-line {
	flex: 0 0 12px;
	height: 2px;
	background: var(--border);
	border-radius: 1px;
}

.learn-step-line.done { background: rgba(34, 197, 94, 0.55); }

/* Navigation row below the lesson body. */
.learn-nav {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.75rem;
	margin: 0.75rem 0 1.25rem;
	flex-wrap: wrap;
}

.learn-nav .learn-progress-text {
	color: var(--muted);
	font-size: 0.88rem;
	font-weight: 600;
	text-align: center;
	flex: 1 1 200px;
}

.learn-nav .btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Inline "puzzle solved" tick beside the puzzle title. */
.learn-puzzle-solved {
	display: inline-block;
	margin-left: 0.45rem;
	color: #4ade80;
	font-weight: 800;
}

/* Course-complete celebration card. */
.learn-complete {
	text-align: center;
	background: linear-gradient(160deg, rgba(34, 197, 94, 0.12), rgba(99, 102, 241, 0.08));
	border-color: rgba(99, 102, 241, 0.35);
}

.learn-complete-badge { font-size: 3rem; line-height: 1; margin-bottom: 0.6rem; }
.learn-complete h2 { margin: 0 0 0.4rem; font-size: 1.5rem; }
.learn-complete-actions {
	display: flex;
	gap: 0.55rem;
	justify-content: center;
	flex-wrap: wrap;
	margin-top: 1rem;
}

.learn-rules { margin-top: 1rem; }
.learn-lesson { margin-bottom: 1rem; }
.learn-lesson > summary {
	cursor: pointer;
	list-style: none;
	display: flex;
	align-items: baseline;
	gap: 0.6rem;
	flex-wrap: wrap;
}
.learn-lesson > summary::-webkit-details-marker { display: none; }
.learn-lesson-num {
	flex: 0 0 auto;
	width: 1.6rem;
	height: 1.6rem;
	border-radius: 6px;
	background: rgba(99, 102, 241, 0.18);
	color: var(--accent-hover);
	font-weight: 800;
	font-size: 0.85rem;
	display: inline-flex;
	align-items: center;
	justify-content: center;
}
.learn-lesson-title { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.learn-lesson-idea { color: var(--muted); font-size: 0.9rem; }
.learn-lesson[open] > summary .learn-lesson-idea { display: none; }
.learn-lesson-body { margin-top: 0.95rem; }
.learn-how { color: var(--muted); line-height: 1.6; margin: 0 0 0.4rem; }
.learn-mistake {
	font-size: 0.88rem;
	color: var(--muted);
	border-left: 3px solid var(--accent);
	padding-left: 0.65rem;
	margin: 0.75rem 0 0;
	line-height: 1.5;
}
.learn-mistake strong { color: var(--text); }

.learn-puzzle {
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 0.85rem 0.9rem;
	margin-top: 0.85rem;
}
.learn-puzzle-title { font-weight: 600; font-size: 0.92rem; color: var(--text); display: block; margin-bottom: 0.6rem; }

.learn-board { display: inline-block; padding: 6px; background: var(--bg); border-radius: 8px; }
.learn-board canvas { display: block; }

.learn-controls { margin-top: 0.65rem; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.learn-btn {
	font-size: 0.8rem;
	padding: 0.32rem 0.7rem;
	border-radius: 6px;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	cursor: pointer;
	font-weight: 600;
}
.learn-btn:hover { border-color: var(--accent); }
.learn-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.learn-status { font-size: 0.85rem; color: var(--muted); margin-left: 0.2rem; }
.learn-status.ok { color: var(--success); font-weight: 600; }
.learn-status.warn { color: #fbbf24; }
.learn-why {
	margin-top: 0.65rem;
	font-size: 0.88rem;
	color: var(--muted);
	line-height: 1.6;
	display: none;
	background: rgba(99, 102, 241, 0.08);
	border-radius: 8px;
	padding: 0.6rem 0.75rem;
	white-space: pre-line;
}
.learn-why.show { display: block; }

.learn-demo {
	margin: 0.85rem 0 0;
	padding: 0.85rem 0.9rem;
	background: rgba(96, 165, 250, 0.06);
	border: 1px solid rgba(96, 165, 250, 0.22);
	border-radius: 10px;
}
.learn-demo-label {
	font-size: 0.7rem;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--muted);
	font-weight: 700;
	margin-bottom: 0.55rem;
}
.learn-demo .learn-board { background: var(--bg); }
.learn-demo-why {
	margin-top: 0.6rem;
	font-size: 0.9rem;
	color: var(--text);
	line-height: 1.55;
	background: transparent;
	padding: 0;
}
.learn-try-label {
	margin: 1rem 0 -0.25rem;
	font-size: 0.7rem;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--muted);
	font-weight: 700;
}
.learn-courses-list {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
	gap: 1rem;
	margin-bottom: 1.4rem;
}
.learn-course-card {
	text-align: left;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 1.1rem 1.15rem;
	color: var(--text);
	cursor: pointer;
	font-family: inherit;
	display: flex;
	flex-direction: column;
	gap: 0.55rem;
	transition: border-color 0.12s, transform 0.12s, background 0.12s;
}
.learn-course-card:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.learn-course-card:disabled, .learn-course-card.locked { opacity: 0.55; cursor: not-allowed; }
.learn-course-card.done { border-color: rgba(74, 222, 128, 0.4); }
.learn-course-top { display: flex; justify-content: space-between; align-items: center; }
.learn-course-num { font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.learn-course-badge {
	font-size: 0.7rem;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--success);
	font-weight: 700;
	background: rgba(74, 222, 128, 0.12);
	padding: 0.15rem 0.5rem;
	border-radius: 6px;
}
.learn-course-badge.locked { color: var(--muted); background: rgba(148, 163, 184, 0.12); }
.learn-course-card-title { margin: 0; font-size: 1.15rem; font-weight: 700; }
.learn-course-card-sub { margin: 0; font-size: 0.9rem; color: var(--muted); line-height: 1.5; }
.learn-course-bar {
	height: 5px;
	background: rgba(148, 163, 184, 0.18);
	border-radius: 999px;
	overflow: hidden;
	margin-top: 0.2rem;
}
.learn-course-bar-fill {
	height: 100%;
	background: var(--accent);
	border-radius: 999px;
	transition: width 0.2s;
}
.learn-course-card.done .learn-course-bar-fill { background: var(--success); }
.learn-course-meta { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.82rem; color: var(--muted); }
.learn-course-cta { color: var(--accent); font-weight: 600; }
.learn-course-card.done .learn-course-cta { color: var(--success); }
.learn-back-btn { margin-bottom: 0.6rem; }
.learn-demo-tiles {
	display: flex;
	flex-wrap: wrap;
	gap: 0.7rem;
}
.learn-demo-tile { display: inline-flex; flex-direction: column; align-items: center; gap: 0.3rem; }
.learn-demo-tile-cap { font-size: 0.75rem; color: var(--muted); }
.learn-hint { font-size: 0.8rem; color: var(--muted); margin: 0.5rem 0 0; }

/* Analyze modal — opened from the All Puzzles list to play a puzzle
   while inspecting the CSP solver's move trace alongside. */
.puzzle-card-analyze {
	margin-left: auto;
	padding: 0.25rem 0.6rem;
	font-size: 0.78rem;
	color: var(--accent);
	background: transparent;
	border: 1px solid var(--border);
	border-radius: 0.4rem;
	cursor: pointer;
}
.puzzle-card-analyze:hover { background: rgba(99, 102, 241, 0.12); border-color: var(--accent); }
.analyze-modal-backdrop {
	position: fixed; inset: 0;
	background: rgba(7, 10, 22, 0.72);
	display: flex; align-items: center; justify-content: center;
	z-index: 100;
	padding: 1.5rem;
}
.analyze-modal {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 0.8rem;
	box-shadow: var(--shadow);
	width: min(960px, 100%);
	max-height: calc(100vh - 3rem);
	display: flex; flex-direction: column;
	overflow: hidden;
}
.analyze-modal-head {
	display: flex; align-items: baseline; gap: 1rem;
	padding: 0.9rem 1.2rem;
	border-bottom: 1px solid var(--border);
}
.analyze-modal-head h2 { margin: 0; font-size: 1.05rem; }
.analyze-modal-sub { color: var(--muted); font-size: 0.85rem; flex: 1; }
.analyze-modal-close {
	padding: 0.3rem 0.8rem;
	background: transparent; color: var(--text);
	border: 1px solid var(--border); border-radius: 0.4rem;
	cursor: pointer;
}
.analyze-modal-close:hover { background: rgba(99, 102, 241, 0.12); }
.analyze-modal-body {
	display: flex; gap: 1.2rem;
	padding: 1.2rem;
	overflow: auto;
}
.analyze-modal-board { flex: 0 0 auto; }
.analyze-modal-trace { flex: 1 1 auto; min-width: 260px; }
.analyze-trace-head { font-weight: 600; margin-bottom: 0.4rem; }
.analyze-trace-status { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.6rem; }
.analyze-trace-list {
	list-style: none; padding: 0; margin: 0;
	max-height: 480px; overflow-y: auto;
	border: 1px solid var(--border); border-radius: 0.4rem;
}
.analyze-trace-move {
	display: block;
	border-bottom: 1px solid var(--border);
	font-size: 0.82rem;
}
.analyze-trace-move:last-child { border-bottom: none; }
.analyze-trace-move > .analyze-trace-header { gap: 0.5rem; }
.analyze-trace-index { color: var(--muted); min-width: 2.2rem; }
.analyze-trace-action { font-weight: 600; min-width: 3.4rem; }
.analyze-trace-reveal .analyze-trace-action { color: var(--success); }
.analyze-trace-flag   .analyze-trace-action { color: var(--danger); }
.analyze-trace-cells { flex: 1; color: var(--text); font-family: ui-monospace, SFMono-Regular, monospace; font-size: 0.78rem; }
.analyze-trace-compl { color: var(--accent); font-variant-numeric: tabular-nums; }
.analyze-trace-head-row {
	display: flex; align-items: baseline; justify-content: space-between;
	margin-bottom: 0.4rem;
}
.analyze-trace-playall {
	padding: 0.25rem 0.7rem;
	font-size: 0.8rem;
	background: var(--accent); color: white;
	border: none; border-radius: 0.4rem;
	cursor: pointer;
}
.analyze-trace-playall:hover:not(:disabled) { background: var(--accent-hover); }
.analyze-trace-playall:disabled { opacity: 0.4; cursor: default; }
.analyze-trace-move { cursor: pointer; }
.analyze-trace-move:hover { background: rgba(99, 102, 241, 0.08); }
.analyze-trace-move.active { background: rgba(250, 204, 21, 0.12); }
.analyze-trace-enum .analyze-trace-action { color: #fbbf24; }
.analyze-trace-case .analyze-trace-action { color: #c084fc; }
.analyze-trace-header { display: flex; gap: 0.5rem; align-items: baseline; padding: 0.35rem 0.6rem; cursor: pointer; }
.analyze-trace-header:hover { background: rgba(99, 102, 241, 0.08); }
.analyze-trace-toggle { font-size: 0.7rem; color: var(--muted); min-width: 0.9rem; cursor: pointer; user-select: none; }
.analyze-trace-toggle:not(.analyze-trace-toggle-empty):hover { color: var(--accent); }
.analyze-trace-toggle-empty { cursor: default; }
.analyze-trace-depth { color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.analyze-trace-detail { padding: 0.4rem 0.6rem 0.5rem 1.8rem; background: rgba(10, 14, 30, 0.4); font-size: 0.78rem; }
.analyze-deriv-step {
	display: flex; gap: 0.6rem; padding: 0.2rem 0.4rem;
	align-items: baseline; border-radius: 0.25rem; cursor: default;
}
.analyze-deriv-step:hover { background: rgba(250, 204, 21, 0.10); }
.analyze-deriv-label { min-width: 3.4rem; color: #fde68a; font-weight: 600; font-variant-numeric: tabular-nums; }
.analyze-deriv-initial .analyze-deriv-label { color: var(--muted); }
.analyze-deriv-body { flex: 1; color: var(--text); }
.analyze-deriv-compl { color: var(--accent); font-variant-numeric: tabular-nums; }
.analyze-case-branch-head {
	margin: 0.4rem 0 0.2rem 0; padding: 0.25rem 0.4rem;
	background: rgba(99, 102, 241, 0.10); border-radius: 0.25rem;
	display: flex; gap: 0.6rem; align-items: baseline;
}
.analyze-case-hyp { font-weight: 600; color: #c084fc; }
.analyze-case-tag { color: var(--muted); font-size: 0.78rem; }
.analyze-case-tag-ok { color: var(--success); }
.analyze-case-step {
	display: flex; gap: 0.5rem; padding: 0.15rem 0.4rem 0.15rem 1.2rem;
	border-radius: 0.25rem; cursor: default;
}
.analyze-case-step:hover { background: rgba(250, 204, 21, 0.10); }
.analyze-case-step-num { color: var(--muted); min-width: 1.4rem; }
.analyze-case-step-action { font-weight: 600; min-width: 3.4rem; }
.analyze-case-step-reveal .analyze-case-step-action { color: var(--success); }
.analyze-case-step-flag   .analyze-case-step-action { color: var(--danger); }
.analyze-case-step-cells { flex: 1; color: var(--text); font-family: ui-monospace, SFMono-Regular, monospace; font-size: 0.78rem; }
.analyze-case-step-compl { color: var(--accent); font-variant-numeric: tabular-nums; }
.analyze-case-contra {
	margin: 0.1rem 0 0.4rem 1.2rem; padding: 0.15rem 0.4rem;
	color: var(--danger); font-weight: 600; cursor: default;
	border-radius: 0.25rem;
}
.analyze-case-contra:hover { background: rgba(239, 68, 68, 0.10); }

/* Stats panel above the All-Puzzles listing. */
.puzzles-stats {
	margin: 0.6rem 0 1rem;
	border: 1px solid var(--border);
	border-radius: 0.5rem;
	background: var(--surface-2);
	overflow: hidden;
}
.puzzles-stats-toggle {
	width: 100%;
	padding: 0.55rem 0.9rem;
	background: transparent; border: none; color: var(--text);
	text-align: left; font-weight: 600; font-size: 0.92rem;
	cursor: pointer;
}
.puzzles-stats-toggle:hover { background: rgba(99, 102, 241, 0.08); }
.puzzles-stats-body { padding: 0.4rem 0.9rem 0.9rem; display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.puzzles-stats-block { min-width: 0; }
.puzzles-stats-block-title {
	margin: 0 0 0.4rem; font-size: 0.85rem; font-weight: 600; color: var(--muted);
	text-transform: uppercase; letter-spacing: 0.04em;
}
.puzzles-stats-chart { display: flex; flex-direction: column; gap: 0.2rem; }
.puzzles-stats-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.78rem; }
.puzzles-stats-label {
	min-width: 6rem; color: var(--muted);
	font-variant-numeric: tabular-nums; flex-shrink: 0;
}
.puzzles-stats-bar {
	flex: 1; height: 0.9rem; background: rgba(99, 102, 241, 0.06);
	border-radius: 0.18rem; position: relative; overflow: hidden;
}
.puzzles-stats-bar-fill {
	display: block; height: 100%;
	background: linear-gradient(90deg, var(--accent), var(--accent-hover));
	border-radius: 0.18rem;
}
.puzzles-stats-stack { display: flex; height: 100%; border-radius: 0.18rem; overflow: hidden; }
.puzzles-stats-seg { display: block; height: 100%; }
.puzzles-stats-seg-trivial   { background: #475569; }
.puzzles-stats-seg-subset    { background: #6366f1; }
.puzzles-stats-seg-union     { background: #8b5cf6; }
.puzzles-stats-seg-intersect { background: #ec4899; }
.puzzles-stats-seg-case      { background: #c084fc; }
.puzzles-stats-seg-enum      { background: #f59e0b; }
.puzzles-stats-value {
	min-width: 2.5rem; text-align: right;
	color: var(--text); font-variant-numeric: tabular-nums; flex-shrink: 0;
}
.puzzles-stats-legend { display: flex; gap: 0.7rem; flex-wrap: wrap; margin-top: 0.4rem; font-size: 0.75rem; color: var(--muted); }
.puzzles-stats-legend-item { display: inline-flex; align-items: center; gap: 0.3rem; }
.puzzles-stats-legend-item .puzzles-stats-seg { width: 0.7rem; height: 0.7rem; border-radius: 0.15rem; }
.puzzles-stats-note { grid-column: 1 / -1; color: var(--muted); font-size: 0.82rem; margin: 0; }

@media (max-width: 768px) {
	.puzzles-stats-body { grid-template-columns: 1fr; }
}

/* Audio settings popover (music + effects volume sliders). */
.audio-control { position: relative; }
.audio-panel {
	position: absolute;
	top: calc(100% + 0.4rem); right: 0;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 0.5rem;
	box-shadow: var(--shadow);
	padding: 0.6rem 0.8rem;
	display: flex; flex-direction: column; gap: 0.4rem;
	min-width: 14rem;
	z-index: 50;
}
.audio-panel[hidden] { display: none; }
.audio-panel-row { display: flex; align-items: center; gap: 0.6rem; }
.audio-panel-label { min-width: 4.2rem; font-size: 0.82rem; color: var(--muted); }
.audio-panel-row input[type="range"] { flex: 1; }

/* Lobby layout — two-column grid: left sidebar groups game modes by
   section, right column hosts the daily-puzzle hero card with the
   actual board rendered. */
.lobby-grid {
	display: grid;
	grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
	gap: 1.6rem;
	align-items: start;
	max-width: 1180px;
	margin: 0 auto;
	padding: 0.6rem 0;
}
@media (max-width: 900px) {
	.lobby-grid { grid-template-columns: minmax(0, 1fr); }
}

.lobby-modes { display: flex; flex-direction: column; gap: 0.8rem; }
.lobby-modes-heading {
	font-size: 0.8rem; font-weight: 700; letter-spacing: 0.06em;
	color: var(--muted); text-transform: uppercase;
	margin: 0.6rem 0 0;
}
.lobby-mode-list {
	list-style: none; margin: 0; padding: 0;
	display: flex; flex-direction: column; gap: 0.5rem;
}
.lobby-mode {
	display: grid;
	grid-template-columns: 1fr auto auto;
	gap: 0.9rem;
	align-items: center;
	padding: 0.7rem 0.9rem;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 0.55rem;
	transition: border-color 0.15s, transform 0.15s;
}
.lobby-mode:hover { border-color: var(--accent); transform: translateY(-1px); }
.lobby-mode-main { display: flex; flex-direction: column; min-width: 0; }
.lobby-mode-title { font-weight: 600; font-size: 1rem; }
.lobby-mode-sub { font-size: 0.78rem; color: var(--muted); }
.lobby-mode-stat {
	display: flex; flex-direction: column; align-items: flex-end;
	font-size: 0.78rem; color: var(--muted);
	min-width: 4rem; text-align: right;
}
.lobby-mode-stat-label { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; }
.lobby-mode-stat-tier { color: var(--text); font-weight: 600; }
.lobby-mode-stat-rating { font-variant-numeric: tabular-nums; }
.lobby-mode-stat-tag {
	font-size: 0.7rem; font-weight: 600; color: var(--muted);
	letter-spacing: 0.05em; padding-top: 0.2rem;
}
.lobby-mode-action { padding: 0.35rem 0.9rem; font-size: 0.85rem; }

/* Daily-puzzle hero on the right. Keeps the mounted buildLearnPuzzle
   visible but click-through to the Play button below. */
.lobby-daily-hero {
	background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
	border: 1px solid var(--border);
	border-radius: 0.8rem;
	padding: 1.1rem 1.2rem 1.2rem;
	display: flex; flex-direction: column; gap: 0.7rem;
}
.lobby-daily-head {
	display: flex; align-items: baseline; justify-content: space-between;
}
.lobby-daily-tag {
	font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em;
	color: #fbbf24; text-transform: uppercase;
}
.lobby-daily-date { font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.lobby-daily-title { margin: 0; font-size: 1.3rem; }
.lobby-daily-sub { margin: 0; font-size: 0.85rem; color: var(--muted); }

.lobby-daily-board {
	background: rgba(11, 16, 32, 0.4);
	border-radius: 0.5rem;
	padding: 0.6rem;
	min-height: 240px;
	display: flex; align-items: center; justify-content: center;
}
.lobby-daily-board-empty { color: var(--muted); font-size: 0.9rem; }
.lobby-daily-preview { width: 100%; max-width: 420px; pointer-events: none; }
.lobby-daily-preview .learn-controls, .lobby-daily-preview .learn-puzzle-title { display: none; }

.lobby-daily-meta {
	display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem;
	margin-top: 0.2rem;
}
.lobby-daily-meta-cell {
	display: flex; flex-direction: column; gap: 0.15rem;
	padding: 0.5rem 0.7rem;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: 0.4rem;
}
.lobby-daily-meta-label {
	font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em;
	text-transform: uppercase; color: var(--muted);
}
.lobby-daily-meta-value { font-size: 1rem; color: var(--text); font-weight: 600; }
.lobby-daily-action { margin-top: 0.4rem; padding: 0.6rem; font-size: 0.95rem; }

/* Daily-hero state indicators. */
.lobby-daily-hero.daily-solved {
	border-color: rgba(34, 197, 94, 0.45);
	box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.25), 0 12px 32px rgba(34, 197, 94, 0.08);
}
.lobby-daily-hero.daily-missed {
	border-color: rgba(239, 68, 68, 0.45);
	box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.25), 0 12px 32px rgba(239, 68, 68, 0.08);
}
.lobby-daily-hero.daily-solved .lobby-daily-meta-cell:last-child {
	background: rgba(34, 197, 94, 0.10);
	border-color: rgba(34, 197, 94, 0.45);
}
.lobby-daily-hero.daily-solved .lobby-daily-meta-cell:last-child .lobby-daily-meta-value {
	color: var(--success);
}
.lobby-daily-hero.daily-missed .lobby-daily-meta-cell:last-child {
	background: rgba(239, 68, 68, 0.08);
	border-color: rgba(239, 68, 68, 0.35);
}
.lobby-daily-hero.daily-missed .lobby-daily-meta-cell:last-child .lobby-daily-meta-value {
	color: var(--danger);
}

.lobby-daily-board-wrap { position: relative; }
.lobby-daily-badge {
	position: absolute; top: 0.6rem; right: 0.6rem;
	min-width: 2.4rem; height: 2.4rem;
	border-radius: 999px;
	display: none;
	align-items: center; justify-content: center;
	font-weight: 700; font-size: 1.4rem; line-height: 1;
	color: white;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
	z-index: 2;
	padding: 0 0.5rem;
}
.lobby-daily-hero.daily-solved .lobby-daily-badge {
	display: inline-flex;
	background: var(--success);
}
.lobby-daily-hero.daily-solved .lobby-daily-badge::after { content: "✓"; }
.lobby-daily-hero.daily-missed .lobby-daily-badge {
	display: inline-flex;
	background: var(--danger);
}
.lobby-daily-hero.daily-missed .lobby-daily-badge::after { content: "✕"; }

/* Faded board for the post-play states so the badge / colored border
   read as the focal point. */
.lobby-daily-hero.daily-solved .lobby-daily-preview,
.lobby-daily-hero.daily-missed .lobby-daily-preview {
	opacity: 0.55;
}

/* Expandable playstyle cards. Header is a click target; the size
   picker (1v1 / 6-player) lives in a hidden region that animates open. */
.lobby-mode-expandable {
	display: block;
	padding: 0;
	overflow: hidden;
}
.lobby-mode-header {
	width: 100%;
	display: grid;
	grid-template-columns: 1fr auto auto;
	gap: 0.9rem;
	align-items: center;
	padding: 0.7rem 0.9rem;
	background: transparent;
	border: none;
	color: inherit;
	text-align: left;
	cursor: pointer;
}
.lobby-mode-header:hover { background: rgba(99, 102, 241, 0.06); }
.lobby-mode-chevron {
	color: var(--muted);
	font-size: 0.9rem;
	transition: transform 0.2s;
	min-width: 1rem;
	text-align: center;
}
.lobby-mode-expandable.expanded .lobby-mode-chevron { transform: rotate(180deg); color: var(--accent); }
.lobby-mode-expandable.expanded { border-color: var(--accent); }

.lobby-mode-sizes {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 0.5rem;
	padding: 0.2rem 0.9rem 0.8rem;
}
.lobby-mode-sizes[hidden] { display: none; }
.lobby-mode-size {
	display: flex; flex-direction: column; gap: 0.15rem;
	align-items: flex-start;
	padding: 0.6rem 0.8rem;
	text-align: left;
}
.lobby-mode-size-title { font-weight: 600; font-size: 0.95rem; }
.lobby-mode-size-sub { font-size: 0.74rem; opacity: 0.85; }

/* === Flashy mode cards ============================================= */
.mode-card-list { display: flex; flex-direction: column; gap: 0.7rem; margin-bottom: 0.6rem; }
.mode-card {
	position: relative;
	display: grid;
	grid-template-columns: auto 1fr auto;
	gap: 0.8rem;
	align-items: center;
	padding: 0.9rem 1.1rem;
	border-radius: 0.7rem;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	text-decoration: none;
	overflow: hidden;
	transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s;
	isolation: isolate; /* keep ::before art beneath children */
	cursor: pointer;
}
.mode-card::before {
	content: ""; position: absolute; inset: 0; z-index: -1;
	background: radial-gradient(circle at top right, rgba(255,255,255,0.04), transparent 60%);
}
.mode-card:hover {
	transform: translateY(-2px);
	box-shadow: 0 12px 30px rgba(0,0,0,0.35);
}
.mode-card-art {
	position: absolute; top: 0; right: 0;
	width: 50%; height: 100%;
	pointer-events: none;
	z-index: -1;
}
.mode-card-icon {
	width: 2.6rem; height: 2.6rem;
	border-radius: 0.55rem;
	display: flex; align-items: center; justify-content: center;
}
.mode-card-icon svg { width: 1.7rem; height: 1.7rem; }
.mode-card-body { display: flex; flex-direction: column; gap: 0.18rem; min-width: 0; }
.mode-card-title { margin: 0; font-size: 1.05rem; font-weight: 700; letter-spacing: 0.01em; }
.mode-card-tag {
	margin: 0; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.04em;
	color: var(--muted); text-transform: uppercase;
}
.mode-card-pitch { margin: 0.15rem 0 0; font-size: 0.8rem; color: var(--text); opacity: 0.85; }
.mode-card-rank { display: flex; flex-direction: column; align-items: flex-end; font-size: 0.78rem; min-width: 4rem; }
.mode-card-rank-tier { font-weight: 600; }
.mode-card-rank-rating { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Per-playstyle accents on the icon tile and hover glow. */
.mode-card-sprint .mode-card-icon { background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #1a1306; }
.mode-card-sprint:hover { border-color: rgba(251, 191, 36, 0.55); box-shadow: 0 12px 32px rgba(251, 191, 36, 0.18); }
.mode-card-standard .mode-card-icon { background: linear-gradient(135deg, #a78bfa, #7c3aed); color: white; }
.mode-card-standard:hover { border-color: rgba(167, 139, 250, 0.55); box-shadow: 0 12px 32px rgba(124, 58, 237, 0.18); }
.mode-card-tournament .mode-card-icon { background: linear-gradient(135deg, #f87171, #b91c1c); color: white; }
.mode-card-tournament:hover { border-color: rgba(248, 113, 113, 0.55); box-shadow: 0 12px 32px rgba(239, 68, 68, 0.18); }
.mode-card-custom .mode-card-icon { background: linear-gradient(135deg, #34d399, #059669); color: #07261c; }
.mode-card-custom:hover { border-color: rgba(52, 211, 153, 0.55); box-shadow: 0 12px 32px rgba(16, 185, 129, 0.18); }
.mode-card-puzzles .mode-card-icon { background: linear-gradient(135deg, #60a5fa, #2563eb); color: white; }
.mode-card-puzzles:hover { border-color: rgba(96, 165, 250, 0.55); box-shadow: 0 12px 32px rgba(37, 99, 235, 0.18); }
.mode-card-streak .mode-card-icon { background: linear-gradient(135deg, #fb923c, #ea580c); color: white; }
.mode-card-streak:hover { border-color: rgba(251, 146, 60, 0.55); box-shadow: 0 12px 32px rgba(234, 88, 12, 0.20); }
.mode-card-storm .mode-card-icon { background: linear-gradient(135deg, #22d3ee, #0891b2); color: #052029; }
.mode-card-storm:hover { border-color: rgba(34, 211, 238, 0.55); box-shadow: 0 12px 32px rgba(8, 145, 178, 0.20); }

.mode-card-rank-label { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; }
.mode-card-rank-pill {
	display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
	font-size: 0.65rem; font-weight: 700; letter-spacing: 0.06em;
	background: rgba(148, 163, 184, 0.15); color: var(--muted);
}

/* === Ranked picker page ============================================= */
.ranked-picker-head {
	display: grid;
	grid-template-columns: auto 1fr auto;
	gap: 1rem;
	align-items: center;
	margin: 0.6rem 0 1rem;
	padding: 1rem 1.2rem;
	border-radius: 0.7rem;
	background: var(--surface);
	border: 1px solid var(--border);
}
.ranked-picker-icon {
	width: 3.6rem; height: 3.6rem;
	border-radius: 0.6rem;
	display: flex; align-items: center; justify-content: center;
	background: rgba(255,255,255,0.04);
}
.ranked-picker-icon svg { width: 2.4rem; height: 2.4rem; }
.ranked-picker-title { margin: 0; font-size: 1.6rem; }
.ranked-picker-sub { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.85rem; }
.ranked-picker-rating { display: flex; flex-direction: column; align-items: flex-end; }
.ranked-picker-rating-tier { font-weight: 700; font-size: 1.1rem; }
.ranked-picker-rating-num { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.ranked-picker-pitch { color: var(--text); opacity: 0.85; margin: 0 0 1.4rem; font-size: 0.95rem; }
.ranked-picker-prompt { margin: 0 0 0.6rem; font-size: 1rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.ranked-picker-options {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 1rem;
}
@media (max-width: 700px) {
	.ranked-picker-options { grid-template-columns: 1fr; }
}
.ranked-picker-option {
	display: flex; flex-direction: column; align-items: flex-start;
	gap: 0.4rem;
	padding: 1.5rem;
	border-radius: 0.8rem;
	background: var(--surface);
	border: 1px solid var(--border);
	color: var(--text);
	cursor: pointer;
	transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
	text-align: left;
}
.ranked-picker-option:hover {
	transform: translateY(-2px);
	border-color: var(--accent);
	box-shadow: 0 12px 32px rgba(99, 102, 241, 0.15);
}
.ranked-picker-option-icon {
	width: 3rem; height: 3rem;
	display: flex; align-items: center; justify-content: center;
	color: var(--accent);
}
.ranked-picker-option-icon svg { width: 100%; height: 100%; }
.ranked-picker-option-title { font-size: 1.4rem; font-weight: 700; }
.ranked-picker-option-sub { color: var(--muted); font-size: 0.85rem; }

/* === Match-search toast (fixed bottom-right) ====================== */
/* Full-viewport dimming backdrop that centres the waiting-room card. */
.match-overlay {
	position: fixed;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1rem;
	background: rgba(8, 10, 18, 0.62);
	backdrop-filter: blur(3px);
	-webkit-backdrop-filter: blur(3px);
	z-index: 80;
	animation: match-overlay-in 0.18s ease-out;
}
.match-overlay[hidden] { display: none; }
@keyframes match-overlay-in {
	from { opacity: 0; }
	to   { opacity: 1; }
}
.match-toast {
	width: 22rem;
	max-width: 100%;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 0.9rem;
	box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
	padding: 1.1rem 1.25rem 1.2rem;
	color: var(--text);
	animation: match-toast-in 0.2s ease-out;
}
@keyframes match-toast-in {
	from { transform: translateY(12px) scale(0.98); opacity: 0; }
	to   { transform: translateY(0) scale(1);       opacity: 1; }
}
.match-toast-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.match-toast-title { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; font-size: 0.92rem; }
.match-toast-spinner {
	width: 0.9rem; height: 0.9rem;
	border: 2px solid rgba(99, 102, 241, 0.25);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: match-toast-spin 0.8s linear infinite;
}
@keyframes match-toast-spin { to { transform: rotate(360deg); } }
.match-toast-cancel {
	height: 1.6rem; padding: 0 0.6rem;
	border: 1px solid var(--border); border-radius: 0.35rem;
	background: transparent; color: var(--muted);
	cursor: pointer; line-height: 1;
	font-size: 0.74rem; font-weight: 600; letter-spacing: 0.02em;
}
.match-toast-cancel:hover { background: rgba(239, 68, 68, 0.12); color: var(--danger); border-color: var(--danger); }
.match-toast-meta {
	display: flex; justify-content: space-between; align-items: baseline;
	margin: 0.55rem 0 0.35rem;
	font-size: 0.78rem; color: var(--muted);
}
.match-toast-mode { font-weight: 600; color: var(--text); }
.match-toast-elapsed { font-variant-numeric: tabular-nums; }
.match-toast-bar {
	height: 0.45rem;
	background: rgba(99, 102, 241, 0.10);
	border-radius: 0.25rem;
	overflow: hidden;
}
.match-toast-bar-fill {
	display: block; height: 100%;
	background: linear-gradient(90deg, var(--accent), var(--accent-hover));
	border-radius: 0.25rem;
	transition: width 0.3s ease;
	width: 0%;
}
.match-toast-counts {
	margin-top: 0.45rem;
	font-size: 0.78rem; color: var(--muted);
	font-variant-numeric: tabular-nums;
}

/* Waiting-room roster: the list of players/bots in the forming lobby, filling
   in live as they arrive (built by renderMatchRoster() in Lobby.js). */
.match-toast-tagline {
	margin: 0.1rem 0 0.5rem;
	font-size: 0.74rem; color: var(--muted);
}
.match-roster {
	list-style: none; margin: 0 0 0.55rem; padding: 0;
	display: flex; flex-direction: column; gap: 0.3rem;
	/* Fits a full 6-player lobby without scrolling; 16-player tournament
	   scrolls, which is expected. */
	max-height: 16.5rem; overflow-y: auto;
}
.match-roster-row {
	display: flex; align-items: center; gap: 0.45rem;
	padding: 0.4rem 0.55rem;
	background: rgba(255, 255, 255, 0.04);
	border: 1px solid rgba(99, 102, 241, 0.16);
	border-radius: 0.5rem;
	font-size: 0.82rem;
}
.match-roster-row-new { animation: match-roster-in 0.28s ease both; }
.match-roster-row-you {
	background: rgba(99, 102, 241, 0.18);
	border-color: rgba(99, 102, 241, 0.5);
}
.match-roster-name {
	font-weight: 700;
	white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
	flex: 1 1 auto; min-width: 0;
}
.match-roster-you-tag {
	flex: 0 0 auto;
	background: var(--accent); color: #fff;
	font-size: 0.6rem; font-weight: 700; letter-spacing: 0.06em;
	padding: 0.05rem 0.35rem; border-radius: 4px;
}
.match-roster-tier {
	flex: 0 0 auto;
	font-size: 0.72rem; font-weight: 700;
	font-variant-numeric: tabular-nums;
}
.match-roster-slot-empty {
	color: var(--muted); font-style: italic;
	background: rgba(255, 255, 255, 0.015);
	border-style: dashed; border-color: rgba(255, 255, 255, 0.1);
	animation: match-roster-pulse 1.6s ease-in-out infinite;
}
@keyframes match-roster-in {
	from { opacity: 0; transform: translateY(6px) scale(0.97); }
	to   { opacity: 1; transform: none; }
}
@keyframes match-roster-pulse {
	0%, 100% { opacity: 0.5; }
	50%      { opacity: 0.8; }
}
/* On narrow phones the centred card fills most of the width (the overlay's
   padding keeps a small margin) and the roster scrolls if the lobby is large. */
@media (max-width: 600px) {
	.match-toast { width: 100%; }
	.match-roster { max-height: 12rem; }
}

/* Fullscreen game chrome: hide the site navbar and let the game fill the space. The in-game "Exit game"
   button (#leave_button) stays as the single way out. Driven by body.game-fullscreen, kept in sync with
   the real fullscreen state in Fullscreen.js (so Esc reverts it too). */
body.game-fullscreen .topbar { display: none; }
body.game-fullscreen main { max-width: none; }
body.game-fullscreen .site-footer { display: none; }

/* Windowed, the game grid is a left-aligned board (1fr) + a 320px sidebar inside a
   max-width container. In fullscreen `main` loses its max-width, so that board would
   sit jammed against the left edge with a big empty gap. Center the play area instead.
   (Territory and puzzle keep their own bespoke fullscreen layouts.) */
body.game-fullscreen .game-view.solo .game-grid {
	grid-template-columns: auto;
	justify-content: center;
}
body.game-fullscreen .game-view:not(.territory):not(.puzzle):not(.solo) .game-grid {
	grid-template-columns: auto 320px;
	justify-content: center;
}

/* App confirm modal (showConfirm in Overlay.js) — replaces window.confirm(), which is
   suppressed in fullscreen. Appended to body so it sits over everything, fullscreen or not. */
.confirm-backdrop {
	position: fixed;
	inset: 0;
	z-index: 1000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1.25rem;
	background: rgba(2, 6, 23, 0.62);
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
	animation: fade 150ms ease;
}
.confirm-modal {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: 14px;
	box-shadow: var(--shadow);
	padding: 1.6rem 1.6rem 1.3rem;
	max-width: 380px;
	width: 100%;
	text-align: center;
}
.confirm-modal-title { font-size: 1.15rem; font-weight: 700; margin: 0 0 0.5rem; color: var(--text); }
.confirm-modal-msg { color: var(--muted); margin: 0 0 1.35rem; line-height: 1.45; }
.confirm-modal-actions { display: flex; gap: 0.6rem; justify-content: center; }
.confirm-modal-actions .btn { min-width: 104px; }

/* Standalone legal pages (privacy.html, terms.html) — server-rendered HTML
   served at /privacy and /terms, reusing the topbar/logo and colour vars. */
.legal {
	max-width: 760px;
	margin: 0 auto;
	padding: 2.5rem 1.25rem 4rem;
}
.legal a.legal-home {
	display: inline-flex;
	align-items: center;
	gap: 0.55rem;
	text-decoration: none;
	margin-bottom: 2rem;
}
.legal h1 {
	font-size: 1.9rem;
	letter-spacing: -0.01em;
	margin: 0 0 0.35rem;
}
.legal .legal-updated {
	color: var(--muted);
	font-size: 0.9rem;
	margin: 0 0 2rem;
}
.legal h2 {
	font-size: 1.2rem;
	margin: 2rem 0 0.6rem;
	color: var(--text);
}
.legal p, .legal li { color: #c3c9e0; }
.legal ul { padding-left: 1.25rem; }
.legal li { margin: 0.3rem 0; }
.legal a { color: var(--accent-hover); }
.legal .legal-footer {
	margin-top: 3rem;
	padding-top: 1.5rem;
	border-top: 1px solid var(--border);
	color: var(--muted);
	font-size: 0.9rem;
}

/* Footer site links (added to index.html) */
.site-footer {
	max-width: 1100px;
	margin: 3rem auto 0;
	padding: 1.5rem 1.25rem 2rem;
	border-top: 1px solid var(--border);
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem 1.25rem;
	align-items: center;
	color: var(--muted);
	font-size: 0.88rem;
}
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover { color: var(--text); }
.site-footer .site-footer-spacer { flex: 1; }
