* { 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;
	--text: #ffffff;
	--text-muted: #7a9aa5;
	--card-red: #c23b3b;
	--card-black: #1a2430;
	--card-face: #f4efe4;
	--card-w: clamp(42px, 11vw, 160px);
	--card-h: calc(var(--card-w) * 1.4);
	--fan-down: max(10px, calc(var(--card-h) * 0.16));
	--fan-up: max(16px, calc(var(--card-h) * 0.26));
	--radius: 8px;
}

body {
	font-family: 'Montserrat', sans-serif;
	background: linear-gradient(135deg, var(--bg-dark) 0%, #0d2530 100%);
	min-height: 100vh;
	min-height: 100dvh;
	color: var(--text);
	background-size: cover;
	background-position: center;
	background-attachment: fixed;
}

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

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

.name-box::-webkit-scrollbar,
.result-box::-webkit-scrollbar {
	width: 8px;
}
.name-box::-webkit-scrollbar-track,
.result-box::-webkit-scrollbar-track {
	background: var(--bg-dark);
	border-radius: 8px;
}
.name-box::-webkit-scrollbar-thumb,
.result-box::-webkit-scrollbar-thumb {
	background: var(--gold-dark);
	border-radius: 8px;
}
.name-box::-webkit-scrollbar-thumb:hover,
.result-box::-webkit-scrollbar-thumb:hover {
	background: var(--gold);
}

.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;
	display: block;
}
.result-box .trophy {
	width: 88px;
	height: 88px;
	margin: 0 auto 16px;
	border-radius: 20px;
	overflow: hidden;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 48px;
	background: var(--bg-dark);
	border: 1px solid var(--bg-light);
}
.name-box h2, .result-box h2 {
	font-family: 'Cormorant Garamond', serif;
	color: var(--gold);
	margin-bottom: 22px;
	font-size: 32px;
	font-weight: 500;
}
.name-box .subtitle, .result-box .player-result { color: var(--text-muted); margin-bottom: 22px; }

.name-box input {
	width: 100%;
	padding: 14px 18px;
	border: 2px solid var(--bg-light);
	border-radius: 12px;
	background: var(--bg-dark);
	color: var(--text);
	font-size: 16px;
	margin-bottom: 12px;
	outline: none;
}

.name-box input:focus { border-color: var(--cyan); }
.name-box input::placeholder { color: var(--text-muted); }

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

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

.picker-grid--sets { grid-template-columns: repeat(2, 1fr); }
.picker-grid--bg { grid-template-columns: repeat(3, 1fr); }
.picker-grid--mode { grid-template-columns: 1fr 1fr; }

.picker-item {
	border: 2px solid var(--bg-light);
	background: var(--bg-dark);
	border-radius: 12px;
	overflow: hidden;
	cursor: pointer;
	color: var(--text);
	padding: 0;
	font: inherit;
}

.picker-item img {
	width: 100%;
	aspect-ratio: 1;
	height: auto;
	object-fit: contain;
	object-position: center;
	display: block;
	background: #ffffff;
	padding: 12px;
}

.picker-grid--bg .picker-item img {
	aspect-ratio: 16 / 10;
	object-fit: cover;
	padding: 0;
	background: #0d2a35;
}

.picker-grid--bg .picker-item span { display: none; }

.picker-item span {
	display: block;
	padding: 6px 4px 8px;
	font-size: 13px;
}

.picker-item.is-selected,
.mode-btn.is-selected {
	border-color: var(--gold);
	box-shadow: 0 0 0 1px var(--gold);
}

.mode-btn {
	padding: 12px 10px;
	border-radius: 12px;
	border: 2px solid var(--bg-light);
	background: var(--bg-dark);
	color: var(--text);
	cursor: pointer;
	font-weight: 600;
}

.record-hint {
	color: var(--cyan);
	font-size: 13px;
	min-height: 1.2em;
	margin: 8px 0 4px;
}

.btn {
	padding: 14px 28px;
	border: none;
	border-radius: 12px;
	font-size: 16px;
	font-weight: 600;
	cursor: pointer;
	transition: transform 0.2s, box-shadow 0.2s;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
}

.btn-gold { background: linear-gradient(135deg, var(--gold) 0%, var(--gold-dark) 100%); color: #000; }
.btn-gold:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(201, 169, 98, 0.4); }
.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; transform: none; }

.lbl-short { display: none; }

.game-wrap {
	width: min(1600px, 100%);
	padding: 8px 12px 16px;
}

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

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

#gameScreen .game-header {
	flex: 0 0 auto;
	margin-bottom: 6px;
}

#gameScreen .board {
	flex: 1 1 auto;
	min-height: 0;
	display: flex;
	flex-direction: column;
}

#gameScreen .top-row {
	flex: 0 0 auto;
	margin-bottom: 8px;
}

#gameScreen .tableau-row {
	flex: 1 1 auto;
	min-height: 0;
	align-items: start;
	margin-bottom: 0;
}

.game-header {
	background: var(--bg-card);
	border-radius: 16px;
	padding: 10px 12px;
	margin-bottom: 12px;
	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; }
.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 {
	font-family: 'Montserrat', sans-serif;
	color: var(--text-muted);
	font-size: 13px;
	font-weight: 500;
	letter-spacing: 0.02em;
	margin-top: 2px;
}

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

.game-stats {
	display: flex;
	justify-content: space-around;
	gap: 6px;
	flex: 1 1 auto;
	min-width: 0;
}

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

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

.board {
	user-select: none;
	touch-action: none;
}

.top-row, .tableau-row {
	display: grid;
	grid-template-columns: repeat(7, minmax(0, 1fr));
	gap: var(--board-gap, 6px);
	margin-bottom: 10px;
}

.pile {
	position: relative;
	width: 100%;
	min-height: var(--card-h);
	border-radius: var(--radius);
}

.pile.is-target,
.pile.is-drop-target {
	outline: none;
}

.pile.is-drop-target .pile-slot,
.pile-slot.is-drop-target-card,
.card.is-drop-target-card {
	box-shadow: 0 0 0 3px var(--gold), 0 0 18px 4px rgba(201, 169, 98, 0.8);
}

.card.is-drop-target-card {
	z-index: 25;
}

.card.is-hint-source,
.card.is-hint-target,
.pile.is-hint .pile-slot,
.pile.is-hint > .card,
.pile-slot.is-hint-source {
	outline: 3px solid var(--gold);
	outline-offset: 3px;
	box-shadow: 0 0 0 3px var(--gold), 0 0 22px 6px rgba(201, 169, 98, 0.95);
	animation: hintGlow 0.8s ease 3;
	z-index: 30;
}

.pile-slot {
	width: 100%;
	max-width: var(--card-w);
	height: var(--card-h);
	margin: 0 auto;
	border-radius: var(--radius);
	border: 2px dashed rgba(63, 181, 197, 0.35);
	background: rgba(13, 42, 53, 0.35);
}

.card {
	width: 100%;
	max-width: var(--card-w);
	height: var(--card-h);
	border-radius: var(--radius);
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	transform-style: preserve-3d;
	cursor: pointer;
	box-shadow: 0 4px 10px rgba(0,0,0,0.35);
	transition: top 0.18s ease, left 0.18s ease;
}

.card.face-down .card-face { display: none; }
.card.face-up .card-back { display: none; }

.card-face, .card-back {
	position: absolute;
	inset: 0;
	border-radius: inherit;
	overflow: hidden;
	border: 1px solid rgba(0,0,0,0.15);
}

.card-back {
	background-color: #0d2a35;
	background-image:
		linear-gradient(135deg, rgba(201,169,98,0.25), rgba(63,181,197,0.2)),
		repeating-linear-gradient(45deg, #0d2a35 0 8px, #123440 8px 16px);
	background-repeat: repeat;
	background-position: center;
}

.card-face {
	background: var(--card-face);
	color: var(--card-black);
}

.card.red .card-face { color: var(--card-red); }

.card.is-selected {
	box-shadow: 0 0 0 2px var(--gold), 0 8px 18px rgba(201,169,98,0.45);
	z-index: 20;
}

.card.is-dragging {
	opacity: 0.22;
}

.card-ghost-stack {
	position: fixed;
	pointer-events: none;
	z-index: 2000;
	transition: none !important;
}

.card-ghost-stack .card,
.card-ghost {
	position: absolute;
	left: 0;
	transform: none !important;
	transition: none !important;
	pointer-events: none;
	margin: 0;
	filter: drop-shadow(0 12px 20px rgba(0,0,0,0.45));
}

.corner {
	position: absolute;
	font-weight: 700;
	line-height: 1.05;
	text-align: center;
	font-size: calc(var(--card-w) * 0.22);
}

.corner.tl { top: 3px; left: 4px; }
.corner.br { bottom: 3px; right: 4px; transform: rotate(180deg); }

.card-center {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 86%;
	height: 72%;
	transform: translate(-50%, -50%);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: calc(var(--card-w) * 0.5);
}

.card-center img {
	width: 100%;
	height: 100%;
	object-fit: contain;
	border-radius: 6px;
}

.waste-pile .card { left: 50%; }
.waste-pile .card.waste-peek-0 { transform: translateX(-50%); }
.waste-pile .card.waste-peek-1 { transform: translateX(calc(-50% + var(--card-w) * 0.28)); }
.waste-pile .card.waste-peek-2 { transform: translateX(calc(-50% + var(--card-w) * 0.56)); }

.tableau-pile {
	min-height: var(--card-h);
}

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

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

.leaderboard-title { color: var(--gold); margin: 12px 0; }
.lb-tabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; }

.period-note {
	color: var(--text-muted);
	font-size: 12px;
	margin: -6px 0 10px;
}

.leaderboard { text-align: left; max-height: 240px; overflow: auto; }
.leaderboard--mine { max-height: 280px; }
.leaderboard-item {
	display: flex;
	align-items: center;
	padding: 8px 10px;
	border-radius: 8px;
	margin-bottom: 4px;
	background: rgba(255,255,255,0.03);
	gap: 8px;
}

.leaderboard-item:nth-child(1) { background: rgba(201, 169, 98, 0.15); }
.leaderboard-item:nth-child(2) { background: rgba(63, 181, 197, 0.1); }
.leaderboard--mine .leaderboard-item:nth-child(1),
.leaderboard--mine .leaderboard-item:nth-child(2) { background: rgba(255,255,255,0.03); }
.lb-rank {
	width: 24px; height: 24px; border-radius: 50%;
	background: var(--bg-light); display: flex; align-items: center; justify-content: center;
	font-size: 12px; font-weight: 700;
	flex-shrink: 0;
}
.leaderboard-item:nth-child(1) .lb-rank { background: var(--gold); color: #000; }
.leaderboard--mine .leaderboard-item:nth-child(1) .lb-rank { background: var(--bg-light); color: inherit; }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-meta { color: var(--text-muted); font-size: 12px; flex-shrink: 0; }
.lb-score { color: var(--gold); font-weight: 600; flex-shrink: 0; }
.lb-result { font-size: 11px; font-weight: 600; flex-shrink: 0; }
.lb-result.is-win { color: var(--cyan); }
.lb-result.is-loss { color: var(--text-muted); }
.leaderboard-empty { color: var(--text-muted); padding: 16px; text-align: center; }

.fly-layer {
	position: fixed;
	inset: 0;
	pointer-events: none;
	z-index: 40;
}

.card.deal-in {
	animation: dealIn 0.35s ease both;
}

@keyframes dealIn {
	from { opacity: 0; transform: translateX(-50%) translateY(-40px) scale(0.8); }
	to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.card.shake {
	animation: shake 0.28s ease;
}

@keyframes shake {
	0%, 100% { transform: translateX(-50%); }
	25% { transform: translateX(calc(-50% - 6px)); }
	75% { transform: translateX(calc(-50% + 6px)); }
}

@keyframes hintGlow {
	0%, 100% { box-shadow: 0 0 0 2px var(--gold); }
	50% { box-shadow: 0 0 0 4px var(--gold), 0 0 22px 6px rgba(201, 169, 98, 0.9); }
}

.win-burst .card {
	animation: winFly 1.4s ease-in forwards;
}

@keyframes winFly {
	to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0.2; }
}

@media (max-width: 720px) {
	.name-box, .result-box { padding: 22px 16px; }
	.player-info .name { font-size: 18px; }
	.header-actions .btn-small {
		padding: 10px 6px;
		font-size: 12px;
		min-height: 40px;
	}
	.stat-item { padding: 6px 4px; }
	.stat-item .value { font-size: 16px; }
	.waste-pile .card.waste-peek-1 { transform: translateX(calc(-50% + var(--card-w) * 0.18)); }
	.waste-pile .card.waste-peek-2 { transform: translateX(calc(-50% + var(--card-w) * 0.34)); }
}

@media (max-width: 420px) {
	.lbl-long { display: none; }
	.lbl-short { display: inline; }
	.header-actions { gap: 4px; }
	.header-actions .btn-small { font-size: 11px; padding: 8px 4px; }
}

@media (orientation: landscape) and (max-height: 520px) {
	.lbl-long { display: none; }
	.lbl-short { display: inline; }
	#gameScreen .game-header { margin-bottom: 4px; }
	.game-header {
		flex-direction: row;
		align-items: center;
		flex-wrap: nowrap;
		padding: 4px 8px;
		gap: 8px;
		border-radius: 12px;
	}
	.game-header-bar { flex: 1 1 auto; min-width: 0; }
	.player-info .name { font-size: 16px; }
	.player-info .mode { font-size: 11px; margin-top: 0; }
	.game-stats { gap: 4px; }
	.stat-item {
		display: flex;
		align-items: baseline;
		justify-content: center;
		gap: 4px;
		padding: 2px 6px;
		border-radius: 8px;
	}
	.stat-item .value { font-size: 13px; }
	.stat-item .label { font-size: 10px; }
	.header-actions {
		flex: 0 1 auto;
		gap: 4px;
	}
	.header-actions .btn-small {
		padding: 6px 8px;
		font-size: 11px;
		min-height: 32px;
		border-radius: 8px;
	}
	#gameScreen .top-row { margin-bottom: 4px; }
	.corner { font-size: calc(var(--card-w) * 0.2); }
}

@media (prefers-reduced-motion: reduce) {
	.card, .btn { transition: none; }
	.card.deal-in, .win-burst .card { animation: none; }
}

/* Ссылка на сводку результатов по всем играм сайта */
.profile-link {
	display: inline-block;
	margin-top: 14px;
	font-size: 14px;
	text-decoration: none;
	opacity: 0.92;
}

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