/* The Eras Chain: Vault Edition — game + leaderboard.
 * Every selector is scoped as :is(.iv2048-root,#iv2048-x) (ID-level specificity) so theme
 * rules such as `button{height:42px;text-transform:uppercase}` cannot reach inside.
 * Colors are variables declared with :where() (zero specificity), so any rule on
 * .iv2048-root (Elementor controls, Additional CSS) can override them. */

:where(.iv2048-root) {
	--iv-ivory: #fbf7f0;
	--iv-sand: #f3ebdd;
	--iv-paper: #ffffff;
	--iv-ink: #1e1a14;
	--iv-muted: #5f564a;
	--iv-gold: #b8860b;
	--iv-gold-deep: #8a6508;
	--iv-gold-soft: #f1e3b8;
	--iv-line: #e6dcc8;
	--iv-board: #d9c9a6;
	--iv-cell: rgba(251, 247, 240, 0.55);
	--iv-tile: #eadfc8;
	--iv-radius: 14px;
	--iv-gap: 10px;
	--iv-size: 4;
	--iv-slide: 120ms;
	--iv-ease: cubic-bezier(0.2, 0.7, 0.2, 1);
	--iv-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
	--iv-font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
	--iv-font-display: 'Fraunces', 'Iowan Old Style', Georgia, serif;
	--iv-shadow: 0 18px 40px rgba(138, 101, 8, 0.15);
}

:is(.iv2048-root,#iv2048-x) {
	font-family: var(--iv-font);
	color: var(--iv-ink);
	box-sizing: border-box;
}

:is(.iv2048-root,#iv2048-x) *,
:is(.iv2048-root,#iv2048-x) *::before,
:is(.iv2048-root,#iv2048-x) *::after {
	box-sizing: border-box;
}

/* Theme-proof base for text and buttons */
:is(.iv2048-root,#iv2048-x) :is(h2, h3, p, span, label, td, th) {
	font-family: inherit;
	letter-spacing: normal;
	text-transform: none;
}

:is(.iv2048-root,#iv2048-x) button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: auto;
	height: auto;
	min-height: 0;
	min-width: 0;
	margin: 0;
	padding: 12px 22px;
	border: 1.5px solid transparent;
	border-radius: 999px;
	background: var(--iv-bbg, transparent);
	color: var(--iv-bfg, inherit);
	font: 700 15px/1.2 var(--iv-font);
	letter-spacing: normal;
	text-transform: none;
	text-decoration: none;
	box-shadow: none;
	cursor: pointer;
	transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

:is(.iv2048-root,#iv2048-x) button:hover,
:is(.iv2048-root,#iv2048-x) button:focus {
	background: var(--iv-bbg-hover, var(--iv-bbg, transparent));
	color: var(--iv-bfg-hover, var(--iv-bfg, inherit));
}

:is(.iv2048-root,#iv2048-x) button:active {
	transform: scale(0.97);
}

:is(.iv2048-root,#iv2048-x) button:focus-visible,
:is(.iv2048-root,#iv2048-x) input:focus-visible,
:is(.iv2048-root,#iv2048-x) .iv2048-container:focus-visible {
	outline: 3px solid var(--iv-gold);
	outline-offset: 3px;
}

:is(.iv2048-root,#iv2048-x) button[hidden],
:is(.iv2048-root,#iv2048-x) [hidden] {
	display: none;
}

:is(.iv2048-root,#iv2048-x) .iv2048-btn {
	--iv-bbg: var(--iv-ink);
	--iv-bfg: var(--iv-ivory);
	--iv-bbg-hover: var(--iv-gold-deep);
	--iv-bfg-hover: #fff;
}

:is(.iv2048-root,#iv2048-x) .iv2048-btn-ghost,
:is(.iv2048-root,#iv2048-x) .iv2048-btn-new {
	--iv-bbg: transparent;
	--iv-bfg: var(--iv-ink);
	--iv-bbg-hover: var(--iv-ink);
	--iv-bfg-hover: var(--iv-ivory);
	border-color: var(--iv-ink);
}

:is(.iv2048-root,#iv2048-x) .iv2048-btn-new.is-confirm {
	--iv-bbg: var(--iv-gold-soft);
	--iv-bfg: var(--iv-ink);
	--iv-bbg-hover: var(--iv-gold-soft);
	--iv-bfg-hover: var(--iv-ink);
	border-color: var(--iv-gold);
}

:is(.iv2048-root,#iv2048-x) .iv2048-btn-link {
	--iv-bbg: transparent;
	--iv-bfg: var(--iv-gold-deep);
	--iv-bbg-hover: transparent;
	--iv-bfg-hover: var(--iv-ink);
	padding: 4px 6px;
	text-decoration: underline;
	text-underline-offset: 3px;
}

/* ---------- Game ---------- */

:is(.iv2048-root,#iv2048-x).iv2048-game-wrap {
	position: relative;
	width: 100%;
	max-width: var(--iv-max, 520px);
	margin: 0 auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	align-items: center;
	touch-action: pan-y;
	user-select: none;
	-webkit-user-select: none;
}

:is(.iv2048-root,#iv2048-x) .iv2048-cover {
	position: absolute;
	inset: 0;
	z-index: 5;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 18px;
	padding: 28px;
	background: var(--iv-cover-bg, radial-gradient(120% 80% at 50% 0%, var(--iv-gold-soft) 0%, var(--iv-ivory) 55%, var(--iv-sand) 100%));
	border: 1px solid var(--iv-line);
	border-radius: 28px;
	text-align: center;
	transition: opacity 0.35s var(--iv-ease), transform 0.35s var(--iv-ease);
}

:is(.iv2048-root,#iv2048-x) .iv2048-cover.iv2048-cover-hidden {
	opacity: 0;
	transform: scale(0.98);
	pointer-events: none;
	visibility: hidden;
	transition: opacity 0.35s var(--iv-ease), transform 0.35s var(--iv-ease), visibility 0s 0.35s;
}

:is(.iv2048-root,#iv2048-x) .iv2048-cover-title {
	margin: 0;
	font-family: var(--iv-font-display);
	font-size: clamp(1.6rem, 5vw, 2.2rem);
	font-weight: 600;
	line-height: 1.1;
	color: var(--iv-ink);
}

:is(.iv2048-root,#iv2048-x) .iv2048-cover-desc {
	margin: 0;
	max-width: 330px;
	font-size: 1rem;
	line-height: 1.55;
	color: var(--iv-muted);
}

:is(.iv2048-root,#iv2048-x) .iv2048-btn-play {
	padding: 15px 34px;
	font-size: 17px;
	box-shadow: 0 14px 28px rgba(184, 134, 11, 0.35);
	--iv-bbg: var(--iv-gold);
	--iv-bfg: #fff;
	--iv-bbg-hover: var(--iv-gold-deep);
}

:is(.iv2048-root,#iv2048-x) .iv2048-header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	width: 100%;
	max-width: min(90vmin, 480px);
	margin-bottom: 14px;
}

:is(.iv2048-root,#iv2048-x) .iv2048-scores {
	flex: 1 1 280px;
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 8px;
}

:is(.iv2048-root,#iv2048-x) .iv2048-score-box {
	position: relative;
	min-width: 0;
	padding: 8px 10px;
	background: var(--iv-paper);
	border: 1px solid var(--iv-line);
	border-radius: 16px;
	text-align: center;
}

:is(.iv2048-root,#iv2048-x) .iv2048-label {
	display: block;
	font-size: 11px;
	font-weight: 700;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--iv-muted);
}

:is(.iv2048-root,#iv2048-x) :is(.iv2048-score, .iv2048-record, .iv2048-best-tile) {
	display: block;
	max-width: 100%;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	font-family: var(--iv-font-display);
	font-size: 22px;
	font-weight: 600;
	line-height: 1.25;
	color: var(--iv-ink);
	font-variant-numeric: tabular-nums;
}

:is(.iv2048-root,#iv2048-x) .iv2048-best-tile {
	font-size: 17px;
	line-height: 1.6;
}

:is(.iv2048-root,#iv2048-x) .iv2048-plus {
	position: absolute;
	right: 10px;
	top: 6px;
	font-weight: 800;
	font-size: 14px;
	color: var(--iv-gold-deep);
	pointer-events: none;
	animation: iv2048-plus 0.7s var(--iv-ease) forwards;
}

@keyframes iv2048-plus {
	from { opacity: 1; transform: translateY(0); }
	to { opacity: 0; transform: translateY(-26px); }
}

:is(.iv2048-root,#iv2048-x) .iv2048-btn-new {
	flex: 0 0 auto;
	margin-left: auto;
	padding: 11px 18px;
	font-size: 14px;
}

:is(.iv2048-root,#iv2048-x) .iv2048-container {
	position: relative;
	width: 100%;
	max-width: min(90vmin, 480px);
	aspect-ratio: 1;
	padding: var(--iv-gap);
	background-color: var(--iv-board);
	border-radius: 24px;
	box-shadow: var(--iv-shadow);
	touch-action: none;
	cursor: grab;
	transition: background-color 0.5s ease;
}

:is(.iv2048-root,#iv2048-x) .iv2048-container:active {
	cursor: grabbing;
}

:is(.iv2048-root,#iv2048-x) :is(.iv2048-grid, .iv2048-tiles) {
	position: absolute;
	inset: var(--iv-gap);
}

:is(.iv2048-root,#iv2048-x) .iv2048-grid {
	display: grid;
	grid-template-columns: repeat(var(--iv-size), 1fr);
	grid-template-rows: repeat(var(--iv-size), 1fr);
	gap: var(--iv-gap);
	pointer-events: none;
}

:is(.iv2048-root,#iv2048-x) .iv2048-cell {
	background: var(--iv-cell);
	border-radius: var(--iv-radius);
}

:is(.iv2048-root,#iv2048-x) .iv2048-tiles {
	pointer-events: none;
}

:is(.iv2048-root,#iv2048-x) .iv2048-tile {
	position: absolute;
	left: 0;
	top: 0;
	width: calc((100% - (var(--iv-size) - 1) * var(--iv-gap)) / var(--iv-size));
	height: calc((100% - (var(--iv-size) - 1) * var(--iv-gap)) / var(--iv-size));
	transform: translate(calc(var(--x, 0) * (100% + var(--iv-gap))), calc(var(--y, 0) * (100% + var(--iv-gap))));
	transition: transform var(--iv-slide) ease-in-out;
	will-change: transform;
}

:is(.iv2048-root,#iv2048-x) .iv2048-tile-inner {
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	background: var(--iv-tile);
	border-radius: var(--iv-radius);
	box-shadow: 0 6px 14px rgba(30, 26, 20, 0.12);
}

:is(.iv2048-root,#iv2048-x) .iv2048-tile-inner.is-new {
	animation: iv2048-appear 0.2s var(--iv-ease) both;
}

:is(.iv2048-root,#iv2048-x) .iv2048-tile-inner.is-merged {
	animation: iv2048-pop 0.22s var(--iv-spring) both;
}

@keyframes iv2048-appear {
	from { opacity: 0; transform: scale(0.6); }
	to { opacity: 1; transform: scale(1); }
}

@keyframes iv2048-pop {
	0% { transform: scale(0.85); }
	55% { transform: scale(1.12); }
	100% { transform: scale(1); }
}

:is(.iv2048-root,#iv2048-x) .iv2048-tile img {
	display: block;
	width: 100%;
	height: 100%;
	max-width: none;
	margin: 0;
	object-fit: cover;
	object-position: center;
	border-radius: 0;
	-webkit-user-drag: none;
}

:is(.iv2048-root,#iv2048-x) .iv2048-tile-value {
	font-family: var(--iv-font-display);
	font-size: clamp(16px, 5vw, 30px);
	font-weight: 600;
	color: var(--iv-ink);
}

/* Cycle 1: gold */
:is(.iv2048-root,#iv2048-x) .iv2048-cycle-1 .iv2048-tile-inner {
	box-shadow: 0 0 0 2px #d4af37, 0 0 14px rgba(212, 175, 55, 0.6);
}
:is(.iv2048-root,#iv2048-x) .iv2048-cycle-1 img {
	filter: sepia(1) saturate(5) brightness(1.1);
}

/* Cycle 2+: diamond */
:is(.iv2048-root,#iv2048-x) .iv2048-cycle-2 .iv2048-tile-inner {
	box-shadow: 0 0 0 2px #b8d4e8, 0 0 18px rgba(200, 230, 255, 0.85);
}
:is(.iv2048-root,#iv2048-x) .iv2048-cycle-2 img {
	filter: hue-rotate(180deg) brightness(1.5) saturate(1.5);
}

:is(.iv2048-root,#iv2048-x) .iv2048-game-message {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 6px 10px;
	min-height: 28px;
	margin-top: 14px;
	font-weight: 700;
	color: var(--iv-gold-deep);
	text-align: center;
}

/* ---------- End-of-game dialog ---------- */

html.iv2048-modal-open {
	overflow: hidden;
}

:is(.iv2048-root,#iv2048-x) .iv2048-dialog {
	width: min(92vw, 400px);
	max-width: none;
	max-height: none;
	margin: auto;
	padding: 0;
	border: 0;
	border-radius: 28px;
	background: var(--iv-paper);
	color: var(--iv-ink);
	box-shadow: 0 30px 60px rgba(138, 101, 8, 0.22);
	user-select: text;
	-webkit-user-select: text;
}

:is(.iv2048-root,#iv2048-x) .iv2048-dialog[open] {
	animation: iv2048-dialog-in 0.25s var(--iv-ease) both;
}

:is(.iv2048-root,#iv2048-x) .iv2048-dialog:not([open]) {
	display: none;
}

/* Fallback for browsers without <dialog>.showModal */
:is(.iv2048-root,#iv2048-x) .iv2048-dialog.is-fallback[open] {
	position: fixed;
	inset: 0;
	z-index: 2147483647;
	height: fit-content;
	box-shadow: 0 0 0 100vmax rgba(30, 26, 20, 0.45), 0 30px 60px rgba(138, 101, 8, 0.22);
}

:is(.iv2048-root,#iv2048-x) .iv2048-dialog::backdrop {
	background: rgba(30, 26, 20, 0.45);
	-webkit-backdrop-filter: blur(4px);
	backdrop-filter: blur(4px);
}

@keyframes iv2048-dialog-in {
	from { opacity: 0; transform: translateY(12px) scale(0.98); }
	to { opacity: 1; transform: none; }
}

:is(.iv2048-root,#iv2048-x) .iv2048-modal {
	margin: 0;
	padding: 28px 24px 24px;
}

:is(.iv2048-root,#iv2048-x) .iv2048-modal-title {
	margin: 0 0 8px;
	font-family: var(--iv-font-display);
	font-size: 1.6rem;
	font-weight: 600;
	line-height: 1.15;
	color: var(--iv-ink);
}

:is(.iv2048-root,#iv2048-x) .iv2048-modal-score {
	margin: 0 0 6px;
	font-size: 1rem;
	line-height: 1.5;
	color: var(--iv-muted);
}

:is(.iv2048-root,#iv2048-x) .iv2048-modal-record {
	display: inline-block;
	margin: 4px 0 8px;
	padding: 4px 12px;
	border-radius: 999px;
	background: var(--iv-gold-soft);
	color: #7a5a07;
	font-size: 13px;
	font-weight: 800;
}

:is(.iv2048-root,#iv2048-x) .iv2048-modal-record[hidden] {
	display: none;
}

:is(.iv2048-root,#iv2048-x) .iv2048-modal-form {
	margin-top: 14px;
}

:is(.iv2048-root,#iv2048-x) .iv2048-modal label {
	display: block;
	margin: 0 0 6px;
	font-size: 14px;
	font-weight: 700;
	color: var(--iv-ink);
}

:is(.iv2048-root,#iv2048-x) .iv2048-input-name {
	display: block;
	width: 100%;
	height: auto;
	min-height: 48px;
	margin: 0;
	padding: 12px 14px;
	border: 1.5px solid var(--iv-line);
	border-radius: 14px;
	background: var(--iv-ivory);
	color: var(--iv-ink);
	font: 500 16px/1.3 var(--iv-font);
	box-shadow: none;
}

:is(.iv2048-root,#iv2048-x) .iv2048-input-name:focus {
	border-color: var(--iv-gold);
	background: #fff;
}

:is(.iv2048-root,#iv2048-x) .iv2048-modal-status {
	display: block;
	min-height: 1.4em;
	margin: 10px 0;
	font-size: 14px;
	font-weight: 600;
	line-height: 1.4;
	color: var(--iv-gold-deep);
}

:is(.iv2048-root,#iv2048-x) .iv2048-modal-actions {
	display: flex;
	margin-top: 4px;
	flex-wrap: wrap;
	gap: 10px;
}

:is(.iv2048-root,#iv2048-x) .iv2048-modal-actions .iv2048-btn-save {
	--iv-bbg: var(--iv-gold);
	--iv-bfg: #fff;
	--iv-bbg-hover: var(--iv-gold-deep);
	flex: 1 1 100%;
}

:is(.iv2048-root,#iv2048-x) .iv2048-btn-save:disabled {
	opacity: 0.7;
	cursor: progress;
}

:is(.iv2048-root,#iv2048-x) .iv2048-modal-actions .iv2048-btn-again,
:is(.iv2048-root,#iv2048-x) .iv2048-modal-actions .iv2048-btn-close-modal {
	flex: 1 1 0;
}

/* ---------- Leaderboard ---------- */

:is(.iv2048-root,#iv2048-x).iv2048-leaderboard-wrap {
	width: 100%;
	max-width: var(--iv-max-board, 640px);
	margin: 1em auto;
	padding: 20px;
	background: var(--iv-paper);
	border: 1px solid var(--iv-line);
	border-radius: 28px;
	box-shadow: 0 24px 60px rgba(138, 101, 8, 0.1);
	overflow-x: auto;
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-head {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 8px 12px;
	margin-bottom: 12px;
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-title {
	margin: 0;
	font-family: var(--iv-font-display);
	font-size: 1.35rem;
	font-weight: 600;
	line-height: 1.2;
	color: var(--iv-ink);
}

:is(.iv2048-root,#iv2048-x) .iv2048-live {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 4px 10px;
	border-radius: 999px;
	background: var(--iv-gold-soft);
	color: #7a5a07;
	font-size: 12px;
	font-weight: 800;
	letter-spacing: 0.06em;
	text-transform: uppercase;
}

:is(.iv2048-root,#iv2048-x) .iv2048-live-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--iv-gold);
	animation: iv2048-live 1.6s ease-in-out infinite;
}

@keyframes iv2048-live {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.25; }
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-table {
	width: 100%;
	margin: 0;
	border: 0;
	border-collapse: collapse;
	font-size: 15px;
	background: transparent;
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-table :is(th, td) {
	padding: 11px 12px;
	border: 0;
	border-bottom: 1px solid var(--iv-line);
	background: transparent;
	color: var(--iv-ink);
	text-align: left;
	vertical-align: middle;
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-table th {
	font-size: 11px;
	font-weight: 800;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--iv-muted);
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-table .iv2048-num {
	text-align: right;
	font-variant-numeric: tabular-nums;
	font-weight: 700;
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-table tbody tr:last-child td {
	border-bottom: 0;
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-table tbody td:first-child {
	width: 3em;
	font-weight: 800;
	color: var(--iv-muted);
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-table tbody tr:nth-child(-n + 3) td:first-child {
	color: var(--iv-gold-deep);
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-table tbody tr.is-mine td {
	background: var(--iv-ivory);
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-table tbody tr.is-mine td:nth-child(2) {
	font-weight: 800;
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-table tbody tr.is-new td {
	background: var(--iv-gold-soft);
	animation: iv2048-row-in 0.5s var(--iv-ease) both;
}

@keyframes iv2048-row-in {
	from { opacity: 0; transform: translateY(-6px); }
	to { opacity: 1; transform: none; }
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-empty td {
	color: var(--iv-muted);
	text-align: center;
}

:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-empty[hidden] {
	display: none;
}

@media (max-width: 480px) {
	:is(.iv2048-root,#iv2048-x).iv2048-game-wrap {
		padding: 8px 0;
	}
	:where(.iv2048-root) {
		--iv-gap: 8px;
		--iv-radius: 12px;
	}
	:is(.iv2048-root,#iv2048-x).iv2048-leaderboard-wrap {
		padding: 14px;
		border-radius: 22px;
	}
	:is(.iv2048-root,#iv2048-x) .iv2048-leaderboard-table :is(th, td) {
		padding: 10px 8px;
	}
}

@media (prefers-reduced-motion: reduce) {
	:is(.iv2048-root,#iv2048-x) *,
	:is(.iv2048-root,#iv2048-x) *::before,
	:is(.iv2048-root,#iv2048-x) *::after {
		animation: none !important;
		transition: none !important;
	}
}
