:root {
	--ink: #f8fbff;
	--deep: #11233a;
	--panel: rgba(10, 24, 42, 0.84);
	--line: rgba(255, 255, 255, 0.18);
	--sun: #ffd166;
	--mint: #8de7b2;
	--red: #ef476f;
	--black: #16324f;
	--shadow: 0 18px 46px rgba(8, 10, 38, 0.34);
	--card-width: clamp(4rem, 8vw, 5.25rem);
	--card-height: calc(var(--card-width) * 1.4);
	--tableau-gap: clamp(1.35rem, 3vw, 1.9rem);
	--drag-snap: 130ms;
	--drag-return: 150ms;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
	height: 100%;
	min-height: 100%;
	overflow: hidden;
}

body {
	margin: 0;
	height: 100vh;
	height: 100dvh;
	min-height: 100vh;
	min-height: 100dvh;
	font-family: Nunito, system-ui, sans-serif;
	color: var(--ink);
	background:
		radial-gradient(circle at 18% 12%, rgba(255, 209, 102, 0.28), transparent 26%),
		radial-gradient(circle at 80% 18%, rgba(141, 231, 178, 0.22), transparent 24%),
		linear-gradient(160deg, #0f1c30 0%, #14455e 50%, #1f7a58 100%);
	overflow: hidden;
	touch-action: manipulation;
}

button, a {
	font: inherit;
	-webkit-touch-callout: none;
}

.app-shell {
	height: 100vh;
	height: 100dvh;
	display: grid;
	grid-template-rows: auto minmax(0, 1fr) auto;
	gap: clamp(0.45rem, 1.5vw, 0.8rem);
	padding: calc(0.5rem + env(safe-area-inset-top)) calc(0.55rem + env(safe-area-inset-right)) calc(0.65rem + env(safe-area-inset-bottom)) calc(0.55rem + env(safe-area-inset-left));
	overflow: hidden;
}

.topbar,
.board-panel,
.status-text {
	border: 1px solid var(--line);
	box-shadow: var(--shadow);
	backdrop-filter: blur(14px);
}

.topbar {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.75rem;
	padding: clamp(0.55rem, 1.8vw, 0.9rem) clamp(0.65rem, 2vw, 1rem);
	border-radius: 1.35rem;
	background: rgba(6, 20, 36, 0.78);
}

.eyebrow,
.subtitle,
.version-pill,
.stat-card span,
.help-card p,
.overlay-kicker,
.celebration-card p {
	margin: 0;
}

.eyebrow,
.overlay-kicker,
.stat-card span {
	color: var(--sun);
	font-size: clamp(0.68rem, 2.2vw, 0.78rem);
	font-weight: 900;
	letter-spacing: 0.16em;
	text-transform: uppercase;
}

h1, h2 {
	margin: 0;
	font-family: Fredoka, system-ui, sans-serif;
}

h1 {
	font-size: clamp(1.6rem, 6vw, 3rem);
	line-height: 0.95;
	text-shadow: 0 4px 0 rgba(0, 0, 0, 0.18);
}

.subtitle {
	margin-top: 0.28rem;
	max-width: 42rem;
	color: rgba(248, 251, 255, 0.86);
	font-size: clamp(0.84rem, 2.5vw, 0.98rem);
}

.version-pill {
	display: inline-flex;
	gap: 0.25rem;
	margin-top: 0.38rem;
	padding: 0.2rem 0.52rem;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.12);
	border: 1px solid rgba(255, 255, 255, 0.22);
	color: rgba(248, 251, 255, 0.9);
	font-size: 0.72rem;
	font-weight: 900;
}

.toolbar-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.45rem;
	justify-content: flex-end;
	align-items: center;
}

#goBack,
button {
	border: 1px solid rgba(255, 255, 255, 0.18);
	border-radius: 999px;
	padding: 0.58rem 0.82rem;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: linear-gradient(135deg, #ffd166, #ef476f);
	color: var(--ink);
	font-weight: 900;
	text-decoration: none;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}

#goBack:hover,
#goBack:focus-visible,
button:hover,
button:focus-visible {
	outline: none;
	border-color: rgba(255, 255, 255, 0.58);
}

.play-layout {
	min-height: 0;
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	gap: clamp(0.55rem, 1.5vw, 0.9rem);
	overflow: hidden;
}

.board-panel {
	min-height: 0;
	padding: clamp(0.35rem, 1.5vw, 0.6rem);
	border-radius: 1.4rem;
	background: rgba(255, 255, 255, 0.1);
	overflow: hidden;
	user-select: none;
	touch-action: none;
}

.board-wrap {
	position: relative;
	height: 100%;
	min-height: 0;
	border-radius: 1.15rem;
	overflow: hidden;
	background:
		radial-gradient(circle at 50% 20%, rgba(255, 255, 255, 0.07), transparent 35%),
		linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.06)),
		linear-gradient(145deg, #0b5f42, #0f7c58 55%, #0a6241);
	}

.game-board {
	height: 100%;
	display: grid;
	grid-template-rows: auto minmax(0, 1fr);
	gap: 0.9rem;
	padding: clamp(0.75rem, 2vw, 1rem);
	position: relative;
	z-index: 1;
	touch-action: none;
}

.top-row,
.tableau-row {
	display: grid;
	gap: 0.7rem;
}

.top-row {
	grid-template-columns: repeat(7, minmax(0, 1fr));
	align-items: start;
}

.tableau-row {
	grid-template-columns: repeat(7, minmax(0, 1fr));
	min-height: 0;
}

.draw-zone,
.waste-zone,
.foundation-pile,
.tableau-pile {
	position: relative;
	min-height: var(--card-height);
	border-radius: 1rem;
	background: rgba(255, 255, 255, 0.08);
	border: 1px dashed rgba(255, 255, 255, 0.18);
	padding: 0.18rem;
}

.tableau-pile {
	min-height: min(52vh, 34rem);
	padding-top: 0.25rem;
	padding-bottom: 0.75rem;
	outline: none;
	touch-action: none;
}

.pile-label {
	position: absolute;
	inset: auto 0.45rem 0.35rem auto;
	font-size: 0.68rem;
	font-weight: 800;
	color: rgba(255, 255, 255, 0.46);
	pointer-events: none;
}

.card {
	position: relative;
	width: 100%;
	max-width: var(--card-width);
	height: var(--card-height);
	margin: 0 auto;
	border-radius: 0.8rem;
	border: 2px solid rgba(17, 35, 58, 0.16);
	background: linear-gradient(180deg, #ffffff, #f3f5f7);
	color: var(--black);
	box-shadow: 0 10px 24px rgba(5, 15, 25, 0.18);
	display: grid;
	grid-template-rows: auto 1fr auto;
	grid-template-columns: 1fr;
	padding: 0.34rem 0.4rem;
	cursor: pointer;
	transition: transform 0.15s ease, box-shadow 0.15s ease, outline-color 0.15s ease;
	touch-action: none;
}

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

.card.face-down {
	background:
		radial-gradient(circle at 30% 24%, rgba(255, 255, 255, 0.18), transparent 20%),
		repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.08) 0 10px, transparent 10px 20px),
		linear-gradient(135deg, #174c87, #266dd3 52%, #7dd3fc);
	border-color: rgba(255, 255, 255, 0.18);
	color: transparent;
}

.card.selected {
	transform: translateY(-0.35rem);
	box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.45), 0 16px 32px rgba(5, 15, 25, 0.22);
	outline: 3px solid rgba(255, 209, 102, 0.75);
	outline-offset: 1px;
}

.card.auto-target {
	box-shadow: 0 0 0 4px rgba(141, 231, 178, 0.34), 0 10px 24px rgba(5, 15, 25, 0.22);
	border-color: rgba(141, 231, 178, 0.8);
}

.card.drag-source {
	opacity: 0.55;
}

.drag-ghost {
	position: fixed;
	left: 0;
	top: 0;
	margin: 0;
	z-index: 80;
	pointer-events: none;
	opacity: 0.98;
	box-shadow: 0 18px 34px rgba(5, 15, 25, 0.32);
	transform: translate3d(0, 0, 0);
	will-change: transform;
	transition: transform var(--drag-snap) cubic-bezier(0.2, 0.9, 0.2, 1.04), opacity var(--drag-snap) ease;
}

.drag-ghost.is-dropping {
	opacity: 0.9;
}

.drag-ghost.is-returning {
	transition-duration: var(--drag-return);
	opacity: 0.86;
}

.card-rank {
	font-size: 0.95rem;
	font-weight: 900;
	line-height: 1;
}

.card-corner {
	display: grid;
	justify-items: start;
	gap: 0.04rem;
}

.card-center {
	align-self: center;
	justify-self: center;
	font-size: clamp(1.35rem, 2.6vw, 2rem);
	line-height: 1;
	opacity: 0.92;
}

.card-suit,
.card-suit-bottom {
	font-size: 1rem;
	line-height: 1;
}

.card-suit-bottom {
	justify-self: end;
	align-self: end;
	transform: rotate(180deg);
}

.tableau-pile .card {
	position: absolute;
	left: 50%;
	transform: translateX(-50%);
	width: calc(100% - 0.3rem);
	max-width: var(--card-width);
	margin: 0;
}

.tableau-pile .card.selected {
	transform: translateX(-50%) translateY(-0.35rem);
}

.foundation-pile.can-drop,
.tableau-pile.can-drop,
.draw-zone.can-drop,
.waste-zone.can-drop {
	border-color: rgba(255, 209, 102, 0.7);
	box-shadow: inset 0 0 0 2px rgba(255, 209, 102, 0.25);
}

.stock-back,
.empty-placeholder,
.recycle-mark {
	display: grid;
	place-items: center;
	width: 100%;
	height: var(--card-height);
	max-width: var(--card-width);
	margin: 0 auto;
	border-radius: 0.8rem;
	font-family: Fredoka, system-ui, sans-serif;
	font-size: 1.65rem;
	font-weight: 900;
	color: rgba(255, 255, 255, 0.7);
	background: rgba(255, 255, 255, 0.08);
	border: 2px dashed rgba(255, 255, 255, 0.16);
	cursor: pointer;
}

.stock-back {
	background:
		radial-gradient(circle at 30% 24%, rgba(255, 255, 255, 0.18), transparent 20%),
		repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.08) 0 10px, transparent 10px 20px),
		linear-gradient(135deg, #174c87, #266dd3 52%, #7dd3fc);
	border-style: solid;
	color: transparent;
	box-shadow: 0 10px 24px rgba(5, 15, 25, 0.18);
}

.waste-zone > .card,
.foundation-pile > .card {
	width: 100%;
	max-width: var(--card-width);
}

.celebration-card {
	border-radius: 1rem;
	padding: 0.7rem;
	background: rgba(255, 255, 255, 0.09);
	border: 1px solid rgba(255, 255, 255, 0.14);
}

.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.celebration-overlay {
	position: absolute;
	inset: 0;
	pointer-events: none;
	z-index: 3;
}

.celebration-overlay {
	display: grid;
	place-items: center;
	padding: 1rem;
	background: linear-gradient(180deg, rgba(4, 12, 21, 0.12), rgba(4, 12, 21, 0.34));
	pointer-events: auto;
}

.celebration-overlay[hidden] {
	display: none;
}

.celebration-card {
	text-align: center;
	max-width: 20rem;
	background: rgba(7, 18, 33, 0.9);
	box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.celebration-card p + p {
	margin-top: 0.35rem;
	color: rgba(248, 251, 255, 0.82);
	font-size: 0.94rem;
	line-height: 1.35;
}

.celebration-card button {
	margin-top: 0.75rem;
	pointer-events: auto;
}

@media (max-width: 1180px) {
	.tableau-pile {
		min-height: min(48vh, 28rem);
	}
}

@media (max-width: 720px) {
	:root {
		--card-width: clamp(3.25rem, 12vw, 4rem);
		--tableau-gap: clamp(1rem, 4vw, 1.35rem);
	}

	.card {
		padding: 0.28rem 0.34rem;
	}

	.card-rank {
		font-size: 0.84rem;
	}

	.card-center {
		font-size: clamp(1.16rem, 2.2vw, 1.62rem);
	}

	.card-suit,
	.card-suit-bottom {
		font-size: 0.84rem;
	}

	.app-shell {
		padding: calc(0.36rem + env(safe-area-inset-top)) calc(0.4rem + env(safe-area-inset-right)) calc(0.45rem + env(safe-area-inset-bottom)) calc(0.4rem + env(safe-area-inset-left));
		gap: 0.42rem;
	}

	.topbar {
		align-items: flex-start;
		padding: 0.48rem 0.56rem;
		border-radius: 1rem;
	}

	.subtitle,
	.version-pill {
		display: none;
	}

	.toolbar-actions {
		max-width: 15rem;
	}

	.toolbar-actions #goBack,
	.toolbar-actions button {
		flex: 1 1 5.2rem;
		padding: 0.42rem 0.45rem;
		font-size: 0.76rem;
	}

	.game-board {
		padding: 0.7rem 0.55rem 0.45rem;
		gap: 0.65rem;
		grid-template-rows: auto auto;
		align-content: center;
	}

	.top-row,
	.tableau-row {
		gap: 0.3rem;
	}

	.tableau-pile {
		min-height: min(50vh, 24rem);
	}

}

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		scroll-behavior: auto !important;
		transition-duration: 0.01ms !important;
	}
}
