:root {
	--bg: #eaf4ff;
	--bg-2: #d7ebff;
	--card: #ffffff;
	--ink: #13253a;
	--muted: #5b6f86;
	--line: #d6e2ef;
	--primary: #1f7ae0;
	--primary-ink: #ffffff;
	--accent: #19b394;
	--danger: #e04f5f;
	--warn: #f0a020;
	--r: #3fb950;
	--c: #2f81f7;
	--i: #f0b400;
	--shadow: 0 10px 30px rgba(19, 37, 58, 0.12);
	--radius: 14px;
	--font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
	--display: 'Fredoka', 'Inter', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg: #0c1622;
		--bg-2: #112033;
		--card: #15263a;
		--ink: #e6eef8;
		--muted: #93a7bd;
		--line: #243a53;
		--shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
	}
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
	font-family: var(--font);
	color: var(--ink);
	background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
	min-height: 100vh;
	-webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }
h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0 0 0.4em; letter-spacing: 0.01em; }
code { font-family: ui-monospace, 'SFMono-Regular', Menlo, monospace; font-size: 0.85em; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- brand ---------- */
.brand {
	display: inline-flex; align-items: center; gap: 10px;
	font-family: var(--display); font-size: 1.6rem; font-weight: 600;
	color: var(--ink); text-decoration: none;
}
.brand b { color: var(--primary); font-weight: 700; }
.brand-mark {
	width: 30px; height: 30px; border-radius: 8px;
	background:
		linear-gradient(#4dabf7, #4dabf7) 5px 13px / 6px 13px no-repeat,
		linear-gradient(#38d9a9, #38d9a9) 12px 5px / 6px 21px no-repeat,
		linear-gradient(#ffd43b, #ffd43b) 19px 10px / 6px 16px no-repeat,
		#0f2a44;
}

/* ---------- buttons & forms ---------- */
.btn {
	appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
	font: 600 0.92rem var(--font); padding: 0.6em 1.1em; border-radius: 10px; cursor: pointer;
	transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s;
	text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { box-shadow: 0 4px 14px rgba(31, 122, 224, 0.18); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 0.25em 0.6em; font-size: 0.78rem; border-radius: 7px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form label, .form .label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.9rem; margin: 0; }
.form small { font-weight: 400; color: var(--muted); }
input, select {
	font: 500 1rem var(--font); color: var(--ink); background: var(--bg);
	border: 1px solid var(--line); border-radius: 10px; padding: 0.65em 0.8em; outline: none;
}
input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 122, 224, 0.18); }
.form-error { color: var(--danger); margin: 0; font-weight: 600; font-size: 0.9rem; }
.row { display: flex; gap: 12px; align-items: flex-end; }
.grow { flex: 1; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }

/* ---------- auth ---------- */
body.auth { overflow-x: hidden; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px 140px; position: relative; z-index: 1; }
.auth-card { width: min(420px, 100%); padding: 32px 28px; }
.auth-card .brand { margin-bottom: 4px; }
.tagline { color: var(--muted); margin: 0 0 22px; }
.switch { text-align: center; margin: 18px 0 0; color: var(--muted); }
.skyline {
	position: fixed; left: 0; right: 0; bottom: 0; height: 200px; z-index: 0; pointer-events: none;
	background: linear-gradient(180deg, #9cc6f0, #6fa7e0);
	opacity: 0.5;
	clip-path: polygon(0 40%, 4% 40%, 4% 20%, 9% 20%, 9% 55%, 14% 55%, 14% 10%, 18% 10%, 18% 45%, 24% 45%, 24% 30%, 30% 30%, 30% 60%, 36% 60%, 36% 5%, 40% 5%, 40% 50%, 47% 50%, 47% 25%, 53% 25%, 53% 65%, 58% 65%, 58% 15%, 63% 15%, 63% 40%, 70% 40%, 70% 22%, 76% 22%, 76% 55%, 82% 55%, 82% 8%, 86% 8%, 86% 45%, 92% 45%, 92% 30%, 100% 30%, 100% 100%, 0 100%);
}

/* ---------- lobby ---------- */
.topbar {
	display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
	padding: 14px 28px; background: var(--card); border-bottom: 1px solid var(--line);
	position: sticky; top: 0; z-index: 5;
}
.topbar-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.player-id { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.player-id code { background: var(--bg); padding: 4px 8px; border-radius: 6px; border: 1px solid var(--line); }
.lobby-main { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; }
.lobby-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin-bottom: 22px; }
.lobby-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.join-form { display: flex; gap: 8px; }
.join-form input { width: 300px; max-width: 60vw; }

.city-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 20px; }
.city-card { overflow: hidden; display: flex; flex-direction: column; transition: transform 0.15s ease, box-shadow 0.15s ease; }
.city-card:hover { transform: translateY(-3px); box-shadow: 0 16px 36px rgba(19, 37, 58, 0.18); }
.city-card canvas { width: 100%; aspect-ratio: 16 / 10; display: block; background: #3d85c6; image-rendering: pixelated; }
.city-card .body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.city-card h3 { font-size: 1.25rem; margin: 0; }
.city-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.84rem; color: var(--muted); }
.city-meta b { color: var(--ink); }
.chip { font-size: 0.72rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.chip.live { background: #19b39422; color: var(--accent); border-color: #19b39455; }
.city-card .actions { display: flex; gap: 8px; margin-top: auto; }
.city-card .actions .btn.primary { flex: 1; }
.empty {
	grid-column: 1 / -1; text-align: center; padding: 60px 20px; border: 2px dashed var(--line); border-radius: var(--radius); color: var(--muted);
}

.invites { margin-bottom: 26px; }
.invite-list { display: flex; flex-direction: column; gap: 10px; }
.invite { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.invite .grow { flex: 1; }

/* ---------- dialogs ---------- */
.dialog {
	border: none; border-radius: 18px; padding: 26px; width: min(520px, calc(100vw - 32px));
	background: var(--card); color: var(--ink); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}
.dialog.wide { width: min(900px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(8, 20, 34, 0.55); backdrop-filter: blur(3px); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.choice-row { display: flex; flex-wrap: wrap; gap: 16px; }
.choice-group { border: 0; margin: 0; padding: 0; min-width: 0; flex: 1 1 260px; }
.choice-group legend { padding: 0; margin-bottom: 6px; }
.segmented { display: flex; gap: 6px; }
.segment { flex: 1; position: relative; cursor: pointer; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment span { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); transition: border-color 0.15s, background 0.15s; }
.segment small { color: var(--muted); font-size: 0.75rem; }
.segment input:checked + span { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, var(--card)); }
.segment input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.choice-desc { margin: 4px 0 0; font-size: 0.85rem; min-height: 2.4em; }
.map-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.map-option { border: 2px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; background: var(--bg); text-align: left; padding: 0; font: inherit; color: inherit; }
.map-option canvas { width: 100%; aspect-ratio: 1; display: block; image-rendering: pixelated; }
.map-option .info { padding: 8px 10px; }
.map-option .info b { display: block; font-family: var(--display); font-size: 1.05rem; }
.map-option .info span { font-size: 0.78rem; color: var(--muted); display: block; line-height: 1.3; }
.map-option[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 122, 224, 0.25); }
.diff { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.diff.Easy { color: var(--r); }
.diff.Medium { color: var(--warn); }
.diff.Hard { color: var(--danger); }

.member-list { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 6px; }
.member-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--bg); border-radius: 10px; }
.member-list li .grow { flex: 1; }
.section-title { font-family: var(--display); font-size: 1.05rem; margin: 18px 0 8px; }
.code-row { display: flex; gap: 8px; align-items: center; }
.code-row code { flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; overflow-wrap: anywhere; }

.toast {
	position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
	background: #13253a; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; z-index: 50;
	box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); }

@media (max-width: 640px) {
	.topbar { padding: 12px 16px; }
	.lobby-main { padding: 20px 16px 40px; }
	.join-form input { width: 100%; }
	.player-id .muted { display: none; }
}
