/* Whiteout */

:root {
	--bg: #14151f;
	--panel: #1e2030;
	--slot: #272a3d;
	--line: #34374f;
	--text: #eceefa;
	--muted: #9093ad;
	--gap: 8px;
	--radius: 12px;
	--move: 120ms; /* keep in sync with MOVE_MS in scripts.js */
	--rainbow: linear-gradient(90deg, #ff4545, #ffb545, #ffe845, #45ff7a, #45f0ff, #4585ff, #ff45e6);
}

* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	padding: 0;
	min-height: 100%;
	background: var(--bg);
	color: var(--text);
	font-family: "Fredoka", "Trebuchet MS", Arial, sans-serif;
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}

body {
	background:
		radial-gradient(ellipse at 50% -10%, rgb(120 90 255 / 18%), transparent 60%),
		var(--bg);
	background-attachment: fixed;
}

.hide {
	display: none !important;
}

/* one column; every section shares the same edges as the board */
.app {
	width: min(440px, 100vw - 32px);
	margin: 0 auto;
	padding: 20px 0 40px;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.label {
	font-size: 12px;
	font-weight: 600;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--muted);
}

.value {
	font-size: 24px;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

button {
	font: inherit;
	font-weight: 600;
	font-size: 15px;
	color: var(--text);
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 10px;
	padding: 10px 14px;
	cursor: pointer;
	transition: background-color 150ms, border-color 150ms, opacity 150ms;
	-webkit-tap-highlight-color: transparent;
}

button:hover:not(:disabled) {
	background: var(--slot);
	border-color: #50547a;
}

button:disabled {
	opacity: 0.35;
	cursor: default;
}

button.primary {
	color: #14151f;
	border: none;
	background: var(--rainbow);
}


/* ---------- header ---------- */

.top {
	display: flex;
	flex-wrap: wrap; /* recipes drop under the title on narrow screens */
	align-items: center;
	justify-content: space-between;
	gap: 12px;
}

.title {
	margin: 0;
	font-size: clamp(44px, 14vw, 60px);
	font-weight: 700;
	line-height: 1;
	letter-spacing: -0.01em;
	color: transparent;
	background: var(--rainbow);
	-webkit-background-clip: text;
	background-clip: text;
}

.subtitle {
	margin-top: 6px;
	color: var(--muted);
	font-size: 15px;
}

.recipes {
	flex: none;
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 10px 12px;
	background: var(--panel);
	border-radius: var(--radius);
}

.recipe {
	display: flex;
	align-items: center;
	gap: 4px;
	color: var(--muted);
	font-weight: 700;
}

.recipe span {
	margin: 0 2px;
}


/* ---------- stats + buttons ---------- */

.stats,
.buttons {
	display: grid;
	grid-template-columns: 1fr 1fr 1fr;
	gap: 8px;
}

.stat {
	background: var(--panel);
	border-radius: var(--radius);
	padding: 8px 10px;
	text-align: center;
}

.buttons button {
	width: 100%;
}


/* ---------- board ---------- */

.board {
	--n: 4;
	position: relative;
	width: 100%;
	aspect-ratio: 1;
	padding: calc(var(--gap) / 2);
	background: var(--panel);
	border-radius: 18px;
	box-shadow: 0 10px 40px rgb(0 0 0 / 35%);
	touch-action: none;
	-webkit-user-select: none;
	user-select: none;
}

.cells,
.tiles {
	position: absolute;
	inset: calc(var(--gap) / 2);
}

/* slots and tiles share one coordinate system: one cell = 100% of their own size */
.slot,
.tile {
	position: absolute;
	top: 0;
	left: 0;
	width: calc(100% / var(--n));
	height: calc(100% / var(--n));
	padding: calc(var(--gap) / 2);
	transform: translate(calc(var(--x) * 100%), calc(var(--y) * 100%));
}

.slot::before {
	content: "";
	display: block;
	width: 100%;
	height: 100%;
	border-radius: var(--radius);
	background: var(--slot);
}

.tile {
	transition: transform var(--move) ease-in-out;
	z-index: 2;
}

.tile.merging {
	z-index: 1;
}

.face {
	position: relative;
	width: 100%;
	height: 100%;
	border-radius: var(--radius);
}

/* light: the tile itself brightens with its level. --glow runs from 1/3 (faint) to 1 (full) */
.tile.light .face {
	--glow: 0.33;
	background:
		radial-gradient(circle at 30% 25%, rgb(255 255 255 / calc(var(--glow) * 25%)), transparent 60%),
		rgb(var(--hue) / calc(var(--glow) * 95% + 5%));
	border: 2px solid rgb(var(--hue) / calc(var(--glow) * 75% + 25%));
	box-shadow: 0 0 calc(var(--glow) * 14px) rgb(var(--hue) / calc(var(--glow) * 45%));
	transition: background 200ms, border-color 200ms, box-shadow 200ms;
}

.tile.light.full .face {
	background:
		radial-gradient(circle at 30% 25%, rgb(255 255 255 / 55%), transparent 60%),
		rgb(var(--hue));
	border-color: rgb(255 255 255 / 70%);
	box-shadow: 0 0 22px rgb(var(--hue) / 65%), inset 0 0 12px rgb(255 255 255 / 40%);
}

.tag {
	position: absolute;
	top: 6%;
	left: 9%;
	font-size: clamp(11px, 3.2vw, 14px);
	font-weight: 700;
	color: rgb(255 255 255 / 80%);
}

.tile.full .tag {
	color: rgb(0 0 0 / 55%);
}

.pips {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 12%;
	display: flex;
	justify-content: center;
	gap: 6%;
}

.pips i {
	width: 13%;
	aspect-ratio: 1;
	border-radius: 50%;
	background: rgb(255 255 255 / 15%);
}

.pips i.on {
	background: #fff;
	box-shadow: 0 0 6px #fff;
}

.tile.full .pips i.on {
	background: rgb(0 0 0 / 55%);
	box-shadow: none;
}

.tile:not(.light) .pips,
.tile:not(.light) .tag {
	display: none;
}

/* dark primed: two mixed colors fused on their way to black, tinted by both */
.tile.light.primed .face {
	border: 2px solid rgb(var(--hue) / 60%);
	background:
		linear-gradient(rgb(0 0 0 / 62%), rgb(0 0 0 / 62%)),
		linear-gradient(135deg, rgb(var(--hue)), rgb(var(--hue2)));
	box-shadow: 0 0 18px rgb(0 0 0 / 70%), inset 0 0 14px rgb(var(--hue2) / 35%);
}

.tile.primed .tag {
	color: rgb(255 255 255 / 85%);
}

.tile.waiting .pips {
	display: none;
}

/* the ring shows which color a mixed or primed tile still needs */
.need {
	display: none;
	position: absolute;
	left: 50%;
	bottom: 12%;
	width: 24%;
	aspect-ratio: 1;
	transform: translateX(-50%);
	border-radius: 50%;
	border: 3px solid rgb(var(--need));
	box-shadow: 0 0 8px rgb(var(--need) / 80%);
}

.tile.waiting .need {
	display: block;
}

/* black: a hole in the light */
.tile.black .face {
	background: radial-gradient(circle at 50% 50%, #000 45%, #0b0b12 70%, #1a1b28);
	border: 2px solid rgb(150 150 190 / 25%);
	box-shadow: inset 0 0 18px #000;
}

/* white: only ever seen for a moment */
.tile.white .face {
	background: #fff;
	border: 2px solid #fff;
	box-shadow: 0 0 30px 8px #fff;
}


/* ---------- tile animations ---------- */

.tile.spawn .face {
	animation: spawn 180ms ease-out backwards;
	animation-delay: var(--delay, 0ms);
}

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

.tile.pop .face {
	animation: pop 200ms ease-out;
}

@keyframes pop {
	50% { transform: scale(1.14); }
}

/* white light flares, throws a rainbow ring, and floats away */
.tile.dissolve {
	z-index: 3;
}

.tile.dissolve .face {
	animation: dissolve 650ms ease-out forwards;
}

.tile.dissolve .face::after {
	content: "";
	position: absolute;
	inset: -10%;
	border-radius: 50%;
	background: conic-gradient(#ff4545, #ffe845, #45ff7a, #45f0ff, #4585ff, #ff45e6, #ff4545);
	-webkit-mask: radial-gradient(circle, transparent 55%, #000 57%, #000 68%, transparent 70%);
	mask: radial-gradient(circle, transparent 55%, #000 57%, #000 68%, transparent 70%);
	animation: ring 650ms ease-out forwards;
}

@keyframes dissolve {
	0% { transform: scale(1); }
	30% { transform: scale(1.2); box-shadow: 0 0 40px 12px #fff; }
	100% { transform: scale(0.6) translateY(-20%); opacity: 0; box-shadow: 0 0 60px 20px rgb(255 255 255 / 0%); }
}

@keyframes ring {
	from { transform: scale(0.6) rotate(0deg); opacity: 1; }
	to { transform: scale(2) rotate(120deg); opacity: 0; }
}

/* black forming: the three tiles crush down into it */
.tile.implode .face {
	animation: implode 300ms ease-out;
}

@keyframes implode {
	0% { transform: scale(1.25); filter: brightness(2.5); }
	60% { transform: scale(0.88); }
}

/* black reaching out to dim its neighbors */
.tile.pulse .face {
	animation: pulse 450ms ease-out;
}

@keyframes pulse {
	from { box-shadow: inset 0 0 18px #000, 0 0 0 0 rgb(150 150 200 / 55%); }
	to { box-shadow: inset 0 0 18px #000, 0 0 0 16px rgb(150 150 200 / 0%); }
}

.tile.dimmed .face {
	animation: dimmed 350ms ease-out;
}

@keyframes dimmed {
	30% { filter: brightness(0.35); transform: scale(0.94); }
}

.tile.fade .face {
	animation: fade-out 450ms ease-in forwards;
}

@keyframes fade-out {
	to { opacity: 0; transform: scale(0.5); filter: brightness(0); }
}

/* swipe that moved nothing */
.board.nudge-left { animation: nudge-left 160ms; }
.board.nudge-right { animation: nudge-right 160ms; }
.board.nudge-up { animation: nudge-up 160ms; }
.board.nudge-down { animation: nudge-down 160ms; }

@keyframes nudge-left { 50% { transform: translateX(-4px); } }
@keyframes nudge-right { 50% { transform: translateX(4px); } }
@keyframes nudge-up { 50% { transform: translateY(-4px); } }
@keyframes nudge-down { 50% { transform: translateY(4px); } }


/* ---------- overlay ---------- */

.overlay {
	position: absolute;
	inset: 0;
	z-index: 10;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 10px;
	padding: 24px;
	text-align: center;
	border-radius: 18px;
	background: rgb(20 21 31 / 82%);
	-webkit-backdrop-filter: blur(4px);
	backdrop-filter: blur(4px);
	animation: fade 250ms ease-out;
}

@keyframes fade {
	from { opacity: 0; }
}

.overlay_title {
	font-size: 32px;
	font-weight: 700;
}

.overlay_text {
	color: var(--muted);
	max-width: 300px;
}

.overlay_buttons {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px;
	margin-top: 8px;
}


/* ---------- status line ---------- */

.status {
	min-height: 2.6em;
	color: var(--text);
	font-size: 15px;
	line-height: 1.3;
	text-align: center;
}

.status.flash {
	animation: fade 400ms ease-out;
}


/* ---------- help ---------- */

.help {
	background: var(--panel);
	border-radius: 18px;
	padding: 4px 20px 16px;
	line-height: 1.5;
}

.help h2 {
	font-size: 20px;
	margin: 14px 0 6px;
}

.help ol {
	margin: 0;
	padding-left: 20px;
}

.help li {
	margin: 8px 0;
}

.eq {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	margin: 4px 10px 0 0;
	color: var(--muted);
	white-space: nowrap;
}

.sw {
	display: inline-block;
	width: 18px;
	height: 18px;
	border-radius: 5px;
}

.sw.r { background: rgb(255 64 64); }
.sw.g { background: rgb(64 255 112); }
.sw.b { background: rgb(64 128 255); }
.sw.y { background: rgb(255 232 64); }
.sw.c { background: rgb(64 240 255); }
.sw.m { background: rgb(255 64 224); }
.sw.w { background: #fff; box-shadow: 0 0 6px #fff; }
.sw.k { background: #000; box-shadow: inset 0 0 0 1px rgb(150 150 190 / 40%); }
