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

html, body {
	overflow-x: hidden;
	width: 100%;
	max-width: 100vw;
}

html.is-playing,
body.is-playing {
	height: 100%;
	overflow: hidden;
	overscroll-behavior: none;
}

:root {
	--bg-dark: #0a1a1f;
	--bg-card: #0d2a35;
	--bg-light: #1a4a5a;
	--cyan: #3fb5c5;
	--cyan-dark: #2d7a8a;
	--gold: #c9a962;
	--gold-dark: #a08040;
	--champagne: #f4e4c1;
	--text: #ffffff;
	--text-muted: #7a9aa5;
}

body {
	font-family: 'Montserrat', sans-serif;
	background: #0d1621;
	background-image:
		radial-gradient(ellipse at 50% 0%, #1a2940 0%, transparent 55%),
		radial-gradient(circle at 20% 80%, rgba(63, 181, 197, 0.12), transparent 32%),
		radial-gradient(circle at 80% 30%, rgba(212, 165, 116, 0.1), transparent 28%);
	min-height: 100vh;
	min-height: 100dvh;
	color: var(--text);
	background-size: cover;
	background-position: center;
	background-attachment: fixed;
}

body.bg-midnight {
	background-color: #0d1621;
	background-image:
		radial-gradient(ellipse at 50% 0%, #1a2940 0%, transparent 55%),
		radial-gradient(circle at 18% 78%, rgba(63, 181, 197, 0.14), transparent 34%),
		radial-gradient(circle at 82% 24%, rgba(212, 165, 116, 0.12), transparent 30%);
}

body.bg-teal {
	background-color: #07161c;
	background-image:
		radial-gradient(ellipse at 50% 10%, #12343c 0%, transparent 58%),
		radial-gradient(circle at 70% 80%, rgba(45, 122, 138, 0.35), transparent 40%);
}

body.bg-dusk {
	background-color: #140f0a;
	background-image:
		radial-gradient(ellipse at 50% 0%, #2a2214 0%, transparent 55%),
		radial-gradient(circle at 30% 70%, rgba(212, 165, 116, 0.18), transparent 36%);
}

.screen {
	min-height: 100vh;
	min-height: 100dvh;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
	width: 100%;
}

.screen.hidden { display: none; }
.hidden { display: none !important; }

.menu-box, .result-box {
	background: var(--bg-card);
	border-radius: 24px;
	padding: 28px 24px;
	text-align: center;
	max-width: 720px;
	width: 100%;
	max-height: calc(100vh - 32px);
	overflow-y: auto;
	border: 1px solid var(--bg-light);
	scrollbar-width: thin;
	scrollbar-color: var(--gold-dark) var(--bg-dark);
}

.menu-box h1, .result-box h2 {
	font-family: 'Cormorant Garamond', serif;
	color: var(--gold);
	margin-bottom: 8px;
	font-size: 34px;
	font-weight: 500;
}

.name-box .logo {
	width: 100px;
	height: 100px;
	margin: 0 auto 20px;
	border-radius: 20px;
	overflow: hidden;
}
.name-box .logo img {
	width: 100%;
	height: 100%;
	object-fit: contain;
}

.name-box .btn-full + .btn-full {
	margin-top: 16px;
}

#nameStart {
	margin-bottom: 16px;
}

#continueBtn,
#boardBtn,
#endlessBtn {
	margin-bottom: 14px;
}

.pack-list {
	display: flex;
	flex-direction: column;
	gap: 12px;
	margin: 0 0 12px;
}

.subtitle {
	color: var(--text-muted);
	margin-bottom: 18px;
	font-size: 14px;
	line-height: 1.45;
}

.color-legend {
	display: flex;
	justify-content: center;
	gap: 10px;
	margin: 0 0 16px;
}

.color-legend .dot {
	width: 16px;
	height: 16px;
	border-radius: 50%;
	border: 1px solid rgba(0, 0, 0, 0.25);
}

.dot-gold { background: #f0c14d; }
.dot-champagne { background: #fff6e4; }
.dot-cyan { background: #2ee4f2; }
.dot-steel { background: #c5d6ff; }
.dot-teal { background: #5fe0b8; }

#endlessBtn,
#farBtn {
	flex-direction: column;
	gap: 4px;
	margin: 0 0 18px;
	padding: 16px 20px;
	line-height: 1.25;
}

#endlessBtn {
	margin-bottom: 10px;
}

#endlessBtn .endless-best,
#farBtn .endless-best {
	font-size: 12px;
	font-weight: 500;
	color: #1a1208;
	opacity: 0.75;
}

.pack-back { margin-bottom: 4px; }

.pack-heading {
	font-family: 'Cormorant Garamond', serif;
	color: var(--gold);
	margin: 10px 0 4px;
	font-size: 28px;
	font-weight: 500;
}

#endlessBtn .endless-best:empty,
#farBtn .endless-best:empty { display: none; }

#menuScreen.showing-pack .menu-box > h1,
#menuScreen.showing-pack #endlessBtn,
#menuScreen.showing-pack #farBtn,
#menuScreen.showing-pack #continueBtn,
#menuScreen.showing-pack #boardBtn,
#menuScreen.showing-pack .player-strip {
	display: none;
}

.picker-label {
	display: block;
	text-align: left;
	color: var(--gold);
	font-size: 13px;
	margin: 10px 0 8px;
	font-weight: 600;
}

.bg-row {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 8px;
	margin-bottom: 16px;
}

.bg-btn {
	height: 44px;
	border-radius: 12px;
	border: 2px solid var(--bg-light);
	cursor: pointer;
	color: var(--text);
	font: inherit;
	font-size: 12px;
	font-weight: 600;
}

.bg-btn[data-bg="midnight"] { background: #1a2940; }
.bg-btn[data-bg="teal"] { background: #12343c; }
.bg-btn[data-bg="dusk"] { background: #2a2214; }
.bg-btn.is-selected {
	border-color: var(--gold);
	box-shadow: 0 0 0 1px var(--gold);
}

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

.level-card {
	text-align: left;
	border: 2px solid var(--bg-light);
	background: var(--bg-dark);
	border-radius: 14px;
	padding: 12px 12px 10px;
	color: var(--text);
	cursor: pointer;
	font: inherit;
}

.level-card:hover { border-color: var(--cyan); }
.level-card .num {
	color: var(--gold);
	font-weight: 700;
	font-size: 12px;
	letter-spacing: 0.04em;
}
.level-card .title {
	display: block;
	margin: 4px 0 6px;
	font-size: 15px;
	font-weight: 600;
}
.level-card .stars {
	color: var(--gold);
	font-size: 13px;
	letter-spacing: 2px;
}
.level-card .stars.is-empty { color: var(--bg-light); }

.btn {
	padding: 14px 28px;
	border: none;
	border-radius: 12px;
	font-size: 16px;
	font-weight: 600;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	font-family: inherit;
}

.btn-gold { background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%); color: #000; }
.btn-secondary { background: var(--bg-light); color: var(--text); }
.btn-full { width: 100%; }
.btn-small { padding: 8px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.btn-pack {
	flex-direction: column;
	gap: 3px;
	padding: 14px 18px;
	background: var(--bg-dark);
	color: var(--text);
	border: 2px solid var(--bg-light);
	line-height: 1.25;
}

.btn.btn-pack:hover { border-color: var(--cyan); }
.btn.btn-pack.is-tutorial {
	border-color: var(--gold);
	background: linear-gradient(135deg, rgba(201, 169, 98, 0.18) 0%, var(--bg-dark) 100%);
}

.btn.btn-pack .pack-meta {
	font-size: 12px;
	font-weight: 500;
	color: var(--gold);
}

.btn.btn-pack.is-locked {
	opacity: 0.55;
	cursor: default;
	pointer-events: none;
}

.btn.btn-pack.is-locked:hover {
	border-color: var(--bg-light);
}

.pack-lock-note {
	display: block;
	margin-top: 4px;
	font-size: 12px;
	font-weight: 500;
	color: var(--text-muted);
}

.player-strip {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 8px;
	font-size: 13px;
	color: var(--text-muted);
}

.linkish {
	background: none;
	border: none;
	color: var(--gold);
	cursor: pointer;
	font: inherit;
	padding: 0;
}

.name-box input {
	width: 100%;
	margin: 0 0 12px;
	padding: 12px 14px;
	border-radius: 12px;
	border: 1px solid var(--bg-light);
	background: rgba(0, 0, 0, 0.28);
	color: var(--champagne);
	font: inherit;
}

.field-label {
	display: block;
	margin: 8px 0 6px;
	font-size: 12px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--text-muted);
}

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

.board-tabs {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 12px 0 16px;
}

.board-tab {
	flex: 1 1 0;
	min-width: 0;
	height: 44px;
	padding: 0 10px;
	border-radius: 12px;
	border: 2px solid var(--bg-light);
	background: var(--bg-dark);
	color: var(--text);
	cursor: pointer;
	font: inherit;
	font-size: 13px;
	font-weight: 600;
}

.board-tab.is-selected {
	border-color: var(--gold);
	background: var(--bg-light);
	box-shadow: 0 0 0 1px var(--gold);
	color: var(--gold);
}

.board-list {
	margin: 0;
	padding: 0;
	list-style: none;
}

.board-row {
	display: grid;
	grid-template-columns: 2em 1fr auto;
	gap: 10px;
	padding: 10px 0;
	border-bottom: 1px solid var(--bg-light);
	font-size: 15px;
}

.board-row.is-me {
	color: var(--gold);
}

/* Короткий рейтинг прямо на экране результата */
.result-board {
	margin: 18px 0 16px;
	padding: 14px 0 2px;
	border-top: 1px solid var(--bg-light);
	border-bottom: 1px solid var(--bg-light);
	text-align: left;
}

.result-board[hidden] {
	display: none;
}

.result-board-title {
	margin: 0 0 8px;
	font-size: 12px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--text-muted);
}

.board-list--compact .board-row {
	padding: 7px 0;
	font-size: 14px;
}

.board-list--compact .board-row:last-child {
	border-bottom: none;
}

.profile-link {
	display: inline-block;
	margin-top: 14px;
	color: var(--gold);
	font-size: 14px;
	text-decoration: none;
	border-bottom: 1px solid rgba(240, 193, 77, 0.4);
}

.profile-link:hover {
	color: var(--champagne);
}

.profile-link.hidden {
	display: none;
}

#gameScreen.screen:not(.hidden) {
	min-height: 0;
	height: 100vh;
	height: 100dvh;
	max-height: 100vh;
	max-height: 100dvh;
	overflow: hidden;
	align-items: stretch;
	padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
}

.game-wrap {
	height: 100%;
	width: 100%;
	max-width: 1080px;
	margin: 0 auto;
	display: flex;
	flex-direction: column;
	min-height: 0;
}

.game-header {
	flex: 0 0 auto;
	background: var(--bg-card);
	border-radius: 16px;
	padding: 10px 12px;
	margin-bottom: 6px;
	border: 1px solid var(--bg-light);
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.game-header-bar {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 8px;
	min-width: 0;
}

.player-info {
	min-width: 0;
	flex: 1 1 auto;
	overflow: hidden;
}
.player-info .name {
	font-family: 'Cormorant Garamond', serif;
	color: var(--gold);
	font-size: 22px;
	font-weight: 500;
	line-height: 1.2;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.player-info .mode {
	color: var(--text-muted);
	font-size: 13px;
	margin-top: 2px;
}
.player-info .mode:empty {
	display: none;
}

.game-stats {
	display: flex;
	gap: 6px;
	flex: 0 0 auto;
	justify-content: flex-end;
}

.stat-item {
	text-align: center;
	padding: 6px 8px;
	background: var(--bg-dark);
	border-radius: 10px;
	border: 1px solid var(--bg-light);
	min-width: 58px;
}

.stat-item .value { font-size: 18px; font-weight: 700; color: var(--cyan); line-height: 1.1; }
.stat-item .label { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

.header-actions {
	display: flex;
	gap: 6px;
}

.header-actions .btn {
	flex: 1 1 0;
	min-width: 0;
	white-space: nowrap;
	touch-action: manipulation;
}

.hint-bar {
	color: var(--champagne);
	font-size: 13px;
	line-height: 1.35;
	text-align: left;
}

.hint-bar:empty {
	display: none;
}

.board-wrap {
	flex: 1 1 auto;
	min-height: 0;
	position: relative;
	border-radius: 16px;
	overflow: hidden;
	border: 1px solid rgba(63, 181, 197, 0.28);
	background: rgba(8, 16, 24, 0.28);
}

#gameCanvas {
	display: block;
	width: 100%;
	height: 100%;
	touch-action: none;
	cursor: crosshair;
}

.result-stars {
	color: var(--gold);
	font-size: 28px;
	letter-spacing: 6px;
	margin: 8px 0 12px;
}

.final-stats {
	display: flex;
	gap: 8px;
	margin: 16px 0;
}

.final-stat {
	flex: 1;
	background: var(--bg-dark);
	border: 1px solid var(--bg-light);
	border-radius: 12px;
	padding: 10px 6px;
}

.final-stat .value { color: var(--cyan); font-size: 20px; font-weight: 700; }
.final-stat .label { color: var(--text-muted); font-size: 12px; }

.overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.55);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 50;
	padding: 16px;
}

.overlay.hidden { display: none; }

.dialog {
	background: var(--bg-card);
	border: 1px solid var(--bg-light);
	border-radius: 16px;
	padding: 24px;
	max-width: 360px;
	width: 100%;
	text-align: center;
}

.dialog h3 { color: var(--gold); margin-bottom: 8px; }
.dialog p { color: var(--text-muted); margin-bottom: 16px; }
.dialog-buttons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.logo-mark {
	width: 72px;
	height: 72px;
	margin: 0 auto 12px;
	display: block;
}

.note {
	margin-top: 16px;
	font-size: 12px;
	color: var(--text-muted);
}

@media (min-width: 640px) {
	.level-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
	.level-card .title { font-size: 14px; }
}

@media (max-width: 639px) {
	.lbl-long { display: none; }
	.menu-box h1 { font-size: 28px; }
	.name-box .logo { width: 84px; height: 84px; }
	.stat-item { min-width: 52px; padding: 6px 5px; }
	.stat-item .value { font-size: 16px; }
	.stat-item .label { font-size: 10px; }
	.hint-bar { font-size: 12px; }
	.header-actions { flex-wrap: wrap; }
	.header-actions .btn { padding: 8px 8px; font-size: 12px; }
	.player-info .name { font-size: 18px; }
	.board-tab { font-size: 12px; }
}

@media (min-width: 640px) {
	.lbl-short { display: none; }
}
