/* purple little guy: a pale garden street, purple residents, one hand-lettered sign. */
:root {
	--bg: #e8eee3;
	--sky: #f2f6ee;
	--paper: #f8fbf5;
	--cell: #ffffff;
	--fg: #241b33;
	--muted: #5c5568;
	--line: #c8d2c0;
	--accent: #7442d6;
	--on-accent: #ffffff;
	--accent-soft: #e2d7f8;
	--ground: #cdd8c3;
	--house: #dfe7d8;
	--window: #eef3e9;
	--cloud: #ffffff;
	--bubble: #ffffff;
	--heart: #e0457f;
	--shadow: rgba(36, 27, 51, 0.12);
	--sprite-filter: none;
	--f-display: "Gluten", "Comic Sans MS", ui-rounded, system-ui, sans-serif;
	--f-body: "Figtree", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
	--f-hand: "Gaegu", "Comic Sans MS", ui-rounded, cursive;
	--f-mono: "DM Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
	color-scheme: light;
}
@media (prefers-color-scheme: dark) {
	:root {
		--bg: #15111c;
		--sky: #19141f;
		--paper: #1e1828;
		--cell: #2a2335;
		--fg: #eee8f7;
		--muted: #a79fb5;
		--line: #352b42;
		--accent: #b492ff;
		--on-accent: #15111c;
		--accent-soft: #2e2344;
		--ground: #2c2439;
		--house: #221b2c;
		--window: #3a3049;
		--cloud: #241d2e;
		--bubble: #2b2238;
		--heart: #ff7ab0;
		--shadow: rgba(0, 0, 0, 0.45);
		/* a thin light outline, so ink and deep purple squares don't vanish into the night */
		--sprite-filter: drop-shadow(1px 0 0 rgba(238, 232, 247, 0.5)) drop-shadow(-1px 0 0 rgba(238, 232, 247, 0.5))
			drop-shadow(0 1px 0 rgba(238, 232, 247, 0.5)) drop-shadow(0 -1px 0 rgba(238, 232, 247, 0.5));
		color-scheme: dark;
	}
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--f-body); font-size: 16px; line-height: 1.5; }
[hidden] { display: none !important; }

/* the street fills the window */
.street {
	position: relative;
	height: 100%;
	min-height: 480px;
	overflow: hidden;
	background: var(--sky);
	user-select: none;
	-webkit-user-select: none;
}
.sign {
	position: absolute;
	top: max(18px, env(safe-area-inset-top));
	left: max(20px, env(safe-area-inset-left));
	z-index: 300;
	pointer-events: none;
}
h1 { margin: 0; font: 700 clamp(30px, 6vw, 48px) / 0.95 var(--f-display); letter-spacing: -0.01em; color: var(--accent); }
.pop { margin: 6px 0 0; font: 13px var(--f-mono); color: var(--muted); }
.leave {
	position: absolute;
	top: max(18px, env(safe-area-inset-top));
	right: max(20px, env(safe-area-inset-right));
	z-index: 400;
}
.houses { position: absolute; left: 0; right: 0; bottom: 150px; height: 150px; pointer-events: none; }
.houses svg { display: block; }
.house { fill: var(--house); }
.window { fill: var(--window); }
.ground { position: absolute; left: 0; right: 0; bottom: 0; height: 150px; background: var(--ground); }
.source {
	position: absolute;
	right: max(16px, env(safe-area-inset-right));
	bottom: max(10px, env(safe-area-inset-bottom));
	z-index: 300;
	font: 12px var(--f-mono);
	color: var(--muted);
}
.cloud { position: absolute; width: 120px; height: 34px; border-radius: 999px; background: var(--cloud); pointer-events: none; animation: drift 140s linear infinite; }
.cloud::before { content: ""; position: absolute; left: 24px; top: -18px; width: 52px; height: 44px; border-radius: 50%; background: var(--cloud); }
.cloud.c1 { top: 18%; animation-delay: -40s; }
.cloud.c2 { top: 30%; transform: scale(0.7); animation-duration: 190s; animation-delay: -120s; }
@keyframes drift { from { left: -160px; } to { left: 100%; } }

/* buttons */
.btn {
	font: 600 15px var(--f-body);
	border-radius: 999px;
	padding: 9px 17px;
	cursor: pointer;
	border: 1.5px solid var(--fg);
	background: var(--paper);
	color: var(--fg);
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { font-size: 13px; padding: 6px 12px; }
.btn.wide { width: 100%; }
.btn[aria-pressed="true"] { background: var(--accent-soft); }
button:focus-visible, a:focus-visible, .host:focus-visible, input:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }

/* the big guy */
.host { position: absolute; left: 0; bottom: 24px; width: 120px; z-index: 200; cursor: pointer; will-change: transform; }
.host-flip { transform-origin: 50% 92%; }
.host-flip svg { display: block; width: 100%; height: auto; overflow: visible; }
.shadow { position: absolute; left: 20%; right: 20%; bottom: -3px; height: 10px; border-radius: 50%; background: var(--shadow); }
.guy .arm, .guy .leg { transform-box: fill-box; }
.guy .arm { transform-origin: 50% 12%; }
.guy .eo { animation: blink-open 4.6s infinite; animation-delay: var(--bd, 0s); }
.guy .ec { opacity: 0; animation: blink-closed 4.6s infinite; animation-delay: var(--bd, 0s); }
.walking .leg-l { animation: step 0.34s ease-in-out infinite; }
.walking .leg-r { animation: step 0.34s ease-in-out infinite; animation-delay: -0.17s; }
.walking .arm-l { animation: swing 0.34s ease-in-out infinite alternate; }
.walking .arm-r { animation: swing 0.34s ease-in-out infinite alternate-reverse; }
.waving .arm-r { animation: wave 0.26s ease-in-out infinite alternate; }
@keyframes step { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes swing { from { transform: rotate(16deg); } to { transform: rotate(-16deg); } }
@keyframes wave { from { transform: rotate(-112deg); } to { transform: rotate(-160deg); } }
@keyframes blink-open { 0%, 94%, 98%, 100% { opacity: 1; } 95%, 97% { opacity: 0; } }
@keyframes blink-closed { 0%, 94%, 98%, 100% { opacity: 0; } 95%, 97% { opacity: 1; } }

.bubble {
	position: absolute;
	bottom: calc(100% + 8px);
	left: 50%;
	transform: translateX(-50%);
	white-space: nowrap;
	font: 700 22px/1 var(--f-hand);
	padding: 8px 13px 6px;
	background: var(--bubble);
	color: var(--fg);
	border: 1.5px solid var(--fg);
	border-radius: 14px;
	z-index: 3;
}
.bubble::after {
	content: "";
	position: absolute;
	left: 50%;
	top: 100%;
	width: 10px;
	height: 10px;
	background: var(--bubble);
	border-right: 1.5px solid var(--fg);
	border-bottom: 1.5px solid var(--fg);
	transform: translate(-50%, -45%) rotate(45deg);
}
.bubble.al { left: 0; transform: none; }
.bubble.al::after { left: 48px; }
.bubble.ar { left: auto; right: 0; transform: none; }
.bubble.ar::after { left: auto; right: 44px; transform: translate(0, -45%) rotate(45deg); }

.pt { position: absolute; z-index: 250; pointer-events: none; font: 700 24px/1 var(--f-hand); color: var(--accent); animation: rise 1.9s ease-out forwards; }
.pt.heart { color: var(--heart); font-size: 22px; animation-duration: 1.2s; }
.pt.hi { color: var(--fg); font-size: 18px; animation-duration: 1.4s; }
.pt.dust { width: 12px; height: 12px; border-radius: 50%; background: var(--ground); border: 1.5px solid var(--line); animation: puff 0.7s ease-out forwards; }
@keyframes rise { 0% { opacity: 0; transform: translate(0, 0) scale(0.7); } 15% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--dx, 14px), -64px) scale(1.15); } }
@keyframes puff { 0% { opacity: 0.9; transform: translate(0, 0) scale(0.6); } 100% { opacity: 0; transform: translate(var(--dx, 10px), -16px) scale(1.5); } }

/* the little guys */
.walker { position: absolute; left: 0; width: 48px; height: 48px; cursor: pointer; will-change: transform; }
.walker canvas { display: block; width: 48px; height: 48px; image-rendering: pixelated; image-rendering: crisp-edges; filter: var(--sprite-filter); }
.tag {
	position: absolute;
	bottom: calc(100% + 4px);
	left: 50%;
	transform: translateX(-50%);
	font: 11px var(--f-mono);
	background: var(--accent);
	color: var(--on-accent);
	padding: 1px 8px;
	border-radius: 999px;
	white-space: nowrap;
}

/* the leave-a-guy sheet */
.sheet {
	position: absolute;
	top: max(72px, calc(env(safe-area-inset-top) + 60px));
	right: max(20px, env(safe-area-inset-right));
	z-index: 500;
	width: min(340px, calc(100% - 32px));
	max-height: calc(100% - 90px);
	overflow-y: auto;
	padding: 16px;
	background: var(--bubble);
	border: 1.5px solid var(--fg);
	border-radius: 18px;
	box-shadow: 0 22px 44px -24px var(--shadow);
	user-select: none;
}
.sheet-part { display: grid; gap: 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet h2 { margin: 0; font: 600 24px/1 var(--f-display); }
.x { border: 0; background: none; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 8px; }
.hint { margin: 0; font-size: 14px; color: var(--muted); }
.pix {
	/* shrinks on short screens so the Add button always fits */
	width: min(100%, max(156px, calc(100dvh - 440px)));
	justify-self: center;
	aspect-ratio: 1;
	display: grid;
	grid-template-columns: repeat(12, 1fr);
	gap: 1px;
	background: var(--line);
	border: 1px solid var(--line);
	border-radius: 6px;
	overflow: hidden;
	touch-action: none;
	cursor: crosshair;
}
.pix div { background: var(--cell); }
.swatches { display: flex; gap: 8px; }
.sw { width: 34px; height: 34px; border-radius: 9px; border: 1.5px solid var(--line); cursor: pointer; padding: 0; }
.sw[aria-pressed="true"] { outline: 2.5px solid var(--fg); outline-offset: 2px; }
.sw.eraser { background: linear-gradient(135deg, transparent 45%, var(--muted) 45% 55%, transparent 55%), var(--cell); }
.row { display: flex; flex-wrap: wrap; gap: 6px; }
.msg { margin: 0; min-height: 1.4em; font-size: 14px; color: var(--accent); }
.link-row { display: flex; gap: 6px; }
.link-row input { flex: 1; min-width: 0; font: 13px var(--f-mono); padding: 6px 10px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--fg); user-select: text; }

.toast {
	position: absolute;
	left: 50%;
	bottom: calc(160px + env(safe-area-inset-bottom));
	transform: translateX(-50%);
	z-index: 450;
	max-width: min(420px, calc(100% - 32px));
	margin: 0;
	padding: 10px 16px;
	background: var(--paper);
	border: 1.5px solid var(--fg);
	border-radius: 14px;
	font-size: 15px;
	text-align: center;
}

@media (max-width: 560px) {
	.host { width: 96px; }
	.leave { top: auto; bottom: calc(166px + env(safe-area-inset-bottom)); right: 16px; }
	.sheet { top: auto; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); width: auto; max-height: calc(100% - 24px); }
	.pix { width: min(100%, 300px, max(156px, calc(100dvh - 440px))); }
	.toast { bottom: calc(220px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
	.guy *, .cloud { animation: none !important; }
	.pt { animation-duration: 0.01s !important; }
}
