/* colours: light by default, dark from the system or the toggle (data-theme on <html>) */

:root {
	--bg: #f5f6f8;
	--surface: #ffffff;
	--raised: #f8f9fb;
	--sunken: #f0f2f5;
	--line: #e3e6eb;
	--line-strong: #cfd4dc;
	--text: #111827;
	--text-2: #374151;
	--muted: #6b7280;
	--accent: #4f5bd5;
	--accent-hover: #434dc0;
	--accent-soft: #eceefd;
	--accent-text: #ffffff;
	--good: #157f4a;
	--good-soft: #e3f5eb;
	--warn: #a16207;
	--warn-soft: #fdf3dc;
	--bad: #c2312f;
	--bad-soft: #fde8e7;
	--shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 1px 3px rgb(16 24 40 / 0.04);
	--shadow-lg: 0 12px 32px rgb(16 24 40 / 0.14);
	--json-key: #4f5bd5;
	--json-str: #157f4a;
	--json-num: #b45309;
	--json-lit: #c2312f;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root:not([data-theme="light"]) {
		--bg: #0c0e13;
		--surface: #14171e;
		--raised: #191d25;
		--sunken: #10131a;
		--line: #252a34;
		--line-strong: #343a47;
		--text: #e8eaef;
		--text-2: #c4c9d3;
		--muted: #8a92a2;
		--accent: #7f8cff;
		--accent-hover: #95a0ff;
		--accent-soft: #1f2340;
		--accent-text: #0c0e13;
		--good: #4ac285;
		--good-soft: #12291d;
		--warn: #e2ad4f;
		--warn-soft: #2c2312;
		--bad: #f07272;
		--bad-soft: #321719;
		--shadow: 0 1px 2px rgb(0 0 0 / 0.3);
		--shadow-lg: 0 16px 40px rgb(0 0 0 / 0.5);
		--json-key: #8f9bff;
		--json-str: #6fd19c;
		--json-num: #e9b45f;
		--json-lit: #f08585;
		color-scheme: dark;
	}
}

:root[data-theme="dark"] {
	--bg: #0c0e13;
	--surface: #14171e;
	--raised: #191d25;
	--sunken: #10131a;
	--line: #252a34;
	--line-strong: #343a47;
	--text: #e8eaef;
	--text-2: #c4c9d3;
	--muted: #8a92a2;
	--accent: #7f8cff;
	--accent-hover: #95a0ff;
	--accent-soft: #1f2340;
	--accent-text: #0c0e13;
	--good: #4ac285;
	--good-soft: #12291d;
	--warn: #e2ad4f;
	--warn-soft: #2c2312;
	--bad: #f07272;
	--bad-soft: #321719;
	--shadow: 0 1px 2px rgb(0 0 0 / 0.3);
	--shadow-lg: 0 16px 40px rgb(0 0 0 / 0.5);
	--json-key: #8f9bff;
	--json-str: #6fd19c;
	--json-num: #e9b45f;
	--json-lit: #f08585;
	color-scheme: dark;
}

:root {
	--radius: 12px;
	--radius-sm: 8px;
	--width: 1080px;
	--font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
	--mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
	min-height: 100vh;
	background: var(--bg);
	color: var(--text);
	font: 14px/1.55 var(--font);
	-webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

svg { display: block; }

[hidden] { display: none !important; }

.boot { margin: 0; min-height: 100vh; display: grid; place-items: center; color: var(--muted); }

/* brand */

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; }

.brand-mark {
	width: 30px;
	height: 30px;
	border-radius: 8px;
	display: grid;
	place-items: center;
	background: var(--accent);
	color: var(--accent-text);
	font-size: 15px;
	font-weight: 800;
}

.brand-logo { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: none; background: #0b0a09; }
.signin-card .brand-logo { width: 64px; height: 64px; }
.signin-card .brand { flex-direction: column; gap: 12px; }

/* top bar */

.topbar {
	position: sticky;
	top: 0;
	z-index: 5;
	background: color-mix(in srgb, var(--surface) 88%, transparent);
	backdrop-filter: blur(10px);
	border-bottom: 1px solid var(--line);
}

.topbar-inner {
	max-width: var(--width);
	margin: 0 auto;
	padding: 10px 24px;
	display: flex;
	align-items: center;
	gap: 20px;
}

.nav { display: flex; gap: 2px; padding: 3px; background: var(--sunken); border: 1px solid var(--line); border-radius: 10px; }

.nav-link {
	background: none;
	border: 0;
	border-radius: 7px;
	padding: 6px 14px;
	cursor: pointer;
	color: var(--muted);
	font-weight: 500;
	white-space: nowrap;
}

.nav-link:hover { color: var(--text); }
.nav-link[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.topbar-end { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.me { display: flex; align-items: center; gap: 10px; padding-left: 10px; border-left: 1px solid var(--line); }
.me-text { line-height: 1.25; min-width: 0; }
.me-name { font-weight: 600; white-space: nowrap; }
.me-role { color: var(--muted); font-size: 12px; white-space: nowrap; }

.avatar {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	background: var(--sunken);
	border: 1px solid var(--line);
	object-fit: cover;
	flex: none;
	display: grid;
	place-items: center;
	color: var(--muted);
	font-weight: 700;
}

.avatar.large { width: 76px; height: 76px; border-radius: 18px; font-size: 26px; }

/* page */

.page { max-width: var(--width); margin: 0 auto; padding: 32px 24px 64px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; line-height: 1.2; }
.page-sub { margin: 4px 0 0; color: var(--muted); }

@media (max-width: 820px) {
	.topbar-inner { flex-wrap: wrap; gap: 10px 12px; padding: 10px 16px; }
	.nav { order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; }
	.nav-link { flex: 1; }
	.me-text { display: none; }
	.page { padding: 20px 16px 48px; }
	.page-head h1 { font-size: 21px; }
}

/* sign in */

.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; position: relative; }
.signin .icon-button { position: absolute; top: 16px; right: 16px; }

.signin-card {
	width: 100%;
	max-width: 380px;
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: 18px;
	padding: 36px 28px 30px;
	text-align: center;
	box-shadow: var(--shadow-lg);
}

.signin-card .brand { justify-content: center; font-size: 19px; margin-bottom: 10px; }
.signin-card .brand-mark { width: 40px; height: 40px; font-size: 20px; border-radius: 11px; }
.signin-card p { margin: 0 0 24px; color: var(--muted); }
.signin-card .button { width: 100%; padding: 10px 14px; }
.signin-card .error { color: var(--bad); margin: 16px 0 0; }

/* surfaces */

.card {
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 20px;
	margin-bottom: 16px;
	box-shadow: var(--shadow);
	min-width: 0;
}

.card h3 { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.card h3.gap-top { margin-top: 26px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.spread { justify-content: space-between; }

.gap-top { margin-top: 16px; }
.gap-small { margin-top: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.bad-text { color: var(--bad); }
.note { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

/* controls */

input[type="text"], input[type="number"], select, textarea {
	background: var(--surface);
	border: 1px solid var(--line-strong);
	border-radius: var(--radius-sm);
	padding: 8px 11px;
	min-width: 0;
	transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

textarea { width: 100%; font-family: var(--mono); font-size: 12.5px; resize: vertical; background: var(--sunken); }

select { cursor: pointer; }

.button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	background: var(--surface);
	border: 1px solid var(--line-strong);
	border-radius: var(--radius-sm);
	padding: 7px 14px;
	cursor: pointer;
	font-weight: 500;
	white-space: nowrap;
	transition: background 0.15s, border-color 0.15s;
}

.button:hover:not(:disabled) { background: var(--raised); border-color: var(--muted); }
.button:disabled { opacity: 0.5; cursor: default; }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.button.danger { color: var(--bad); }
.button.danger:hover:not(:disabled) { background: var(--bad-soft); border-color: var(--bad); }
.button.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.button.ghost { background: none; border-color: transparent; color: var(--muted); }
.button.ghost:hover:not(:disabled) { background: var(--sunken); color: var(--text); border-color: transparent; }

.icon-button {
	width: 34px;
	height: 34px;
	display: grid;
	place-items: center;
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius-sm);
	color: var(--muted);
	cursor: pointer;
}

.icon-button:hover { color: var(--text); border-color: var(--line-strong); }

.link-button { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-weight: 500; text-align: left; }
.link-button:hover { text-decoration: underline; }

/* search */

.search {
	display: flex;
	gap: 8px;
	padding: 8px;
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: 14px;
	box-shadow: var(--shadow);
	margin-bottom: 20px;
}

.search-field { flex: 1; position: relative; display: flex; align-items: center; min-width: 0; }
.search-field svg { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search-field input { width: 100%; border: 0; background: none; padding: 9px 12px 9px 38px; font-size: 15px; }
.search-field input:focus { box-shadow: none; }

/* badges */

.badge {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 2px 9px;
	border-radius: 999px;
	font-size: 12px;
	font-weight: 600;
	background: var(--sunken);
	color: var(--muted);
	border: 1px solid var(--line);
	white-space: nowrap;
}

.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.8; }
.badge.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

/* roles: --role is set per pill from JS, the text is mixed with the theme's text colour so any pick stays readable */

.role-pill {
	--role: #8a92a2;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 1px 9px;
	border-radius: 999px;
	font-size: 12px;
	font-weight: 600;
	line-height: 1.6;
	white-space: nowrap;
	color: color-mix(in srgb, var(--role) 72%, var(--text));
	background: color-mix(in srgb, var(--role) 14%, transparent);
	border: 1px solid color-mix(in srgb, var(--role) 32%, transparent);
}

.role-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--role); flex: none; }
.me-role .role-pill { padding: 0 7px; font-size: 11px; line-height: 1.5; }
.who { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.row.end { justify-content: flex-end; flex-wrap: nowrap; }
.card-head { margin-bottom: 8px; }
.card-head h3 { margin: 0; }

/* player */

.player { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.player-info { min-width: 0; flex: 1; }
.player-name { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.25; }
.player-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.player .actions { justify-content: flex-end; }

@media (max-width: 640px) {
	.player .actions { width: 100%; justify-content: flex-start; }
}

/* tabs */

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: -4px 0 18px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }

.tab {
	background: none;
	border: 0;
	border-bottom: 2px solid transparent;
	margin-bottom: -1px;
	padding: 8px 14px;
	cursor: pointer;
	color: var(--muted);
	font-weight: 500;
	white-space: nowrap;
}

.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

/* tables */

.table-wrap { overflow-x: auto; margin: 0 -4px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; background: var(--raised); }
th:first-child { border-top-left-radius: var(--radius-sm); }
th:last-child { border-top-right-radius: var(--radius-sm); }
tbody tr:hover td { background: var(--raised); }
tr:last-child td { border-bottom: 0; }
td.wrap { max-width: 420px; overflow-wrap: anywhere; }
td span[title] { white-space: nowrap; color: var(--text-2); }

.empty { color: var(--muted); padding: 14px 0; margin: 0; }

/* facts */

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.fact { background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; }
.fact > span:first-child { display: block; color: var(--muted); font-size: 12px; margin-bottom: 2px; }

/* json tree */

.json { font-family: var(--mono); font-size: 12.5px; line-height: 1.7; background: var(--sunken); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; overflow-x: auto; }
.json details { margin-left: 16px; }
.json > details { margin-left: 0; }
.json summary { cursor: pointer; list-style: none; }
.json summary::-webkit-details-marker { display: none; }
.json summary::before { content: "▸"; display: inline-block; width: 14px; color: var(--muted); }
.json details[open] > summary::before { content: "▾"; }
.json .leaf { margin-left: 30px; white-space: pre-wrap; overflow-wrap: anywhere; }
.json .key { color: var(--json-key); }
.json .str { color: var(--json-str); }
.json .num { color: var(--json-num); }
.json .lit { color: var(--json-lit); }

/* dialog */

dialog {
	border: 1px solid var(--line);
	border-radius: 16px;
	background: var(--surface);
	color: var(--text);
	padding: 24px;
	width: min(460px, calc(100vw - 32px));
	box-shadow: var(--shadow-lg);
}

dialog::backdrop { background: rgb(8 10 14 / 0.55); backdrop-filter: blur(2px); }
dialog h3 { margin: 0 0 6px; font-size: 17px; overflow-wrap: anywhere; }
dialog p { margin: 0 0 18px; color: var(--muted); }
dialog label { display: block; margin-bottom: 14px; }
dialog label span { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
dialog label input, dialog label select { width: 100%; }
dialog .row { justify-content: flex-end; margin-top: 8px; }
dialog .small { color: var(--bad); margin: -4px 0 10px; }
dialog .hint { font-size: 12px; margin: -8px 0 14px; }

dialog.wide { width: min(620px, calc(100vw - 32px)); }

.field { margin-bottom: 14px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }

.color-field { display: flex; align-items: center; gap: 12px; }

input[type="color"] {
	width: 44px;
	height: 36px;
	padding: 3px;
	border: 1px solid var(--line-strong);
	border-radius: var(--radius-sm);
	background: var(--surface);
	cursor: pointer;
	flex: none;
}

input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); flex: none; cursor: pointer; }
input:disabled, select:disabled { opacity: 0.6; cursor: default; }

.perm-group { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 10px; overflow: hidden; }

.perm-group h4 {
	margin: 0;
	padding: 6px 12px;
	font-size: 11px;
	font-weight: 600;
	color: var(--muted);
	text-transform: uppercase;
	letter-spacing: 0.04em;
	background: var(--raised);
	border-bottom: 1px solid var(--line);
}

dialog .perm { display: flex; align-items: center; gap: 12px; padding: 8px 12px; margin: 0; border-bottom: 1px solid var(--line); }
dialog .perm:last-child { border-bottom: 0; }
dialog label.perm { cursor: pointer; }
dialog label.perm:hover { background: var(--raised); }
.perm > div { flex: 1; min-width: 0; }
.perm-text { line-height: 1.35; }
dialog .perm span { display: inline; font-size: inherit; font-weight: 400; color: inherit; margin: 0; }
dialog .perm .perm-id { display: block; font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 1px; }
dialog .perm select { width: auto; padding: 5px 8px; flex: none; }
dialog .perm select.allow { border-color: var(--good); color: var(--good); }
dialog .perm select.deny { border-color: var(--bad); color: var(--bad); }

/* toasts */

#toasts {
	position: fixed;
	right: 16px;
	bottom: 16px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	z-index: 10;
	max-width: calc(100vw - 32px);
}

.toast {
	background: var(--surface);
	border: 1px solid var(--line);
	border-left: 4px solid var(--accent);
	border-radius: 10px;
	padding: 11px 15px;
	max-width: 380px;
	box-shadow: var(--shadow-lg);
	animation: toast-in 0.18s ease-out;
}

.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }

@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
	.toast { animation: none; }
}
