:root {
	color-scheme: dark;
	font-family: 'Segoe UI', system-ui, sans-serif;
	--felt: #1a5c38;
	--felt-dark: #0f3d24;
	--felt-light: #237a4b;
	--gold: #c9a84c;
	--gold-dim: #8a7235;
	--card-white: #f5f0e8;
	--card-shadow: rgba(0, 0, 0, 0.4);
	--red-suit: #c0392b;
	--black-suit: #1a1a2e;
	--card-w: min(11vw, 100px);
	--card-h: calc(var(--card-w) * 1.45);
	--card-radius: clamp(4px, 0.6vw, 8px);
	--stack-offset: calc(var(--card-h) * 0.18);
	--stack-offset-hidden: calc(var(--card-h) * 0.07);
}

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

body {
	background: var(--felt-dark);
	overflow: hidden;
	height: 100dvh;
	user-select: none;
	-webkit-user-select: none;
}

.solitaire {
	height: 100dvh;
	display: flex;
	flex-direction: column;
	background:
		radial-gradient(ellipse at 50% 30%, var(--felt-light) 0%, var(--felt) 50%, var(--felt-dark) 100%);
}

/* Header */
.solitaire__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px clamp(12px, 3vw, 24px);
	background: rgba(0, 0, 0, 0.3);
	backdrop-filter: blur(8px);
	border-bottom: 1px solid rgba(201, 168, 76, 0.2);
	flex-shrink: 0;
}

.solitaire__brand {
	display: flex;
	align-items: center;
	gap: 8px;
}

.solitaire__icon {
	width: 22px;
	height: 22px;
	color: var(--gold);
}

.solitaire__title {
	font-size: clamp(16px, 2.5vw, 22px);
	font-weight: 700;
	color: var(--gold);
	letter-spacing: 0.05em;
	text-transform: uppercase;
}

.solitaire__stats {
	display: flex;
	gap: clamp(12px, 3vw, 32px);
}

.solitaire__stat {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 1px;
}

.solitaire__stat-label {
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: rgba(255, 255, 255, 0.4);
}

.solitaire__stat-value {
	font-size: clamp(14px, 2vw, 18px);
	font-weight: 700;
	color: #fff;
	font-variant-numeric: tabular-nums;
}

.solitaire__new-game {
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 8px 16px;
	background: rgba(201, 168, 76, 0.15);
	border: 1px solid var(--gold-dim);
	border-radius: 6px;
	color: var(--gold);
	font-size: 13px;
	font-weight: 600;
	cursor: pointer;
	transition: all 0.2s;
	white-space: nowrap;
}

.solitaire__auto-btn {
	border-color: #4a9eff55;
	color: #4a9eff;
	background: rgba(74, 158, 255, 0.10);
}

.solitaire__auto-btn:hover {
	background: rgba(74, 158, 255, 0.22) !important;
	border-color: #4a9eff !important;
	color: #4a9eff !important;
}

.solitaire__auto-btn.is-playing {
	background: rgba(74, 158, 255, 0.22);
	border-color: #4a9eff;
	color: #4a9eff;
	animation: autoPulse 1s ease-in-out infinite;
}

@keyframes autoPulse {
	0%, 100% {
		box-shadow: 0 0 0 0 rgba(74, 158, 255, 0.35);
	}

	50% {
		box-shadow: 0 0 0 6px rgba(74, 158, 255, 0);
	}
}

.solitaire__new-game:hover {
	background: rgba(201, 168, 76, 0.25);
	border-color: var(--gold);
}

.solitaire__new-game svg {
	width: 14px;
	height: 14px;
}

/* Board */
.solitaire__board {
	flex: 1;
	display: flex;
	flex-direction: column;
	padding: clamp(8px, 2vw, 20px) clamp(8px, 2vw, 24px);
	gap: clamp(10px, 2vw, 20px);
	overflow: hidden;
}

.solitaire__top-row {
	display: flex;
	justify-content: space-between;
	flex-shrink: 0;
}

.solitaire__stock-waste {
	display: flex;
	gap: clamp(6px, 1.5vw, 14px);
}

.solitaire__foundations {
	display: flex;
	gap: clamp(6px, 1.5vw, 14px);
}

/* Card zones */
.card-zone {
	width: var(--card-w);
	min-height: var(--card-h);
	position: relative;
	border-radius: var(--card-radius);
}

.card-zone--stock,
.card-zone--waste,
.card-zone--foundation {
	height: var(--card-h);
	background: rgba(0, 0, 0, 0.15);
	border: 2px dashed rgba(255, 255, 255, 0.1);
}

.card-zone--stock {
	cursor: pointer;
}

.card-zone__label {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: 0.1em;
	color: rgba(255, 255, 255, 0.12);
	pointer-events: none;
}

.card-zone__suit {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: clamp(20px, 3vw, 32px);
	color: rgba(255, 255, 255, 0.08);
	pointer-events: none;
}

.card-zone--tableau {
	flex: 1;
	min-height: calc(var(--card-h) + var(--stack-offset) * 6);
}

.solitaire__tableau {
	display: flex;
	gap: clamp(4px, 1vw, 12px);
	flex: 1;
	justify-content: center;
}

/* Cards */
.card {
	position: absolute;
	width: var(--card-w);
	height: var(--card-h);
	border-radius: var(--card-radius);
	cursor: pointer;
	transition: box-shadow 0.15s;
	transform-origin: center center;
	z-index: var(--z, 1);
	top: var(--top, 0);
	left: 0;
}

.card--face-up {
	background: var(--card-white);
	border: 1px solid rgba(0, 0, 0, 0.12);
	box-shadow: 0 1px 3px var(--card-shadow);
	display: flex;
	flex-direction: column;
	padding: clamp(2px, 0.4vw, 5px);
}

.card--face-up:hover {
	box-shadow: 0 3px 10px var(--card-shadow);
}

.card--face-down {
	background:
		repeating-linear-gradient(45deg,
			#1a3a6e,
			#1a3a6e 3px,
			#1e4080 3px,
			#1e4080 6px);
	border: 2px solid #264d93;
	box-shadow:
		0 1px 3px var(--card-shadow),
		inset 0 0 0 3px rgba(0, 0, 0, 0.15),
		inset 0 0 0 5px rgba(100, 140, 200, 0.15);
}

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

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

.card__corner {
	display: flex;
	flex-direction: column;
	align-items: center;
	line-height: 1;
	gap: 0;
}

.card__corner--top {
	align-self: flex-start;
}

.card__corner--bottom {
	align-self: flex-end;
	transform: rotate(180deg);
	margin-top: auto;
}

.card__rank {
	font-size: clamp(11px, 1.6vw, 16px);
	font-weight: 800;
}

.card__suit {
	font-size: clamp(10px, 1.4vw, 14px);
	line-height: 1;
}

.card__center-suit {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	font-size: clamp(22px, 3.5vw, 36px);
	opacity: 0.3;
}

/* Dragging */
.card--dragging {
	z-index: 10000 !important;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5) !important;
	pointer-events: none;
	transition: none;
	transform: rotate(2deg);
}

.card--dragging-child {
	z-index: 10000 !important;
	pointer-events: none;
	transition: none;
}

/* Drop target highlight */
.card-zone--highlight {
	box-shadow: 0 0 0 3px var(--gold), 0 0 20px rgba(201, 168, 76, 0.3);
}

/* Card dealing animation */
.card--dealing {
	opacity: 0;
	animation: dealCard 0.4s cubic-bezier(0.22, 0.68, 0.35, 1.2) forwards;
	animation-delay: var(--deal-delay, 0s);
}

@keyframes dealCard {
	0% {
		opacity: 0;
		transform: translateY(-40px) translateX(-20px) scale(0.8) rotate(-4deg);
	}

	50% {
		opacity: 1;
	}

	75% {
		transform: translateY(3px) translateX(0) scale(1.015) rotate(0.5deg);
	}

	100% {
		opacity: 1;
		transform: translateY(0) translateX(0) scale(1) rotate(0deg);
	}
}

.card--deal-stock {
	opacity: 0;
	animation: dealStock 0.2s ease-out forwards;
	animation-delay: var(--deal-delay, 0s);
}

@keyframes dealStock {
	from {
		opacity: 0;
		transform: scale(0.9);
	}

	to {
		opacity: 1;
		transform: scale(1);
	}
}

/* Stock recycle indicator */
.card-zone--stock.card-zone--empty {
	cursor: pointer;
}

.card-zone--stock.card-zone--empty::after {
	content: '';
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: var(--card-radius);
	background: rgba(201, 168, 76, 0.08);
}

/* Win overlay */
.solitaire__win-overlay {
	position: fixed;
	inset: 0;
	background: rgba(0, 0, 0, 0.7);
	backdrop-filter: blur(6px);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 20000;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.4s;
}

.solitaire__win-overlay--visible {
	opacity: 1;
	pointer-events: all;
}

.solitaire__win-card {
	background: linear-gradient(145deg, #1a3322, #0f2618);
	border: 2px solid var(--gold);
	border-radius: 16px;
	padding: 40px 48px;
	text-align: center;
	box-shadow: 0 0 60px rgba(201, 168, 76, 0.2);
}

.solitaire__win-title {
	font-size: 36px;
	color: var(--gold);
	margin-bottom: 20px;
	letter-spacing: 0.05em;
}

.solitaire__win-stats {
	display: flex;
	gap: 32px;
	justify-content: center;
	margin-bottom: 28px;
	color: rgba(255, 255, 255, 0.6);
	font-size: 15px;
}

.solitaire__win-stats strong {
	color: #fff;
}

/* Double-click hint */
.card--hint {
	animation: hintPulse 0.4s ease;
}

@keyframes hintPulse {
	0%, 100% {
		transform: scale(1);
	}

	50% {
		transform: scale(1.03);
		box-shadow: 0 0 15px rgba(201, 168, 76, 0.4);
	}
}

@media (max-width: 600px) {
	:root {
		--card-w: 13vw;
	}

	.solitaire__header {
		padding: 8px 10px;
	}

	.solitaire__stats {
		gap: 10px;
	}

	.solitaire__new-game span {
		display: none;
	}
}