:root {
	--paper: #0E0C13;
	--surface: #17141F;
	--surface-raised: #211C2C;
	--line: #2B2637;
	--ink: #ECE8F2;
	--muted: #A49DB3;
	--accent: #A3B6DF;
	--brand: #FF6A1F;
	--brand-deep: #D2341B;
	--on-brand: #15111C;
	--high: #5BD68A;
	--medium: #F2C14E;
	--low: #F28C4E;
	--none: #6E6680;
	--radius: 14px;
	color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
	background: var(--paper);
	color: var(--ink);
	font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	-webkit-tap-highlight-color: transparent;
	overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

.screen {
	display: flex;
	flex-direction: column;
	min-height: 100dvh;
	max-width: 520px;
	margin: 0 auto;
}

/* header */
.top {
	position: sticky;
	top: 0;
	z-index: 5;
	background: var(--paper);
	padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
	border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 8px; }
.count { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.count small { color: var(--muted); font-weight: 400; }
.filter {
	flex: 1;
	min-width: 0;
	height: 40px;
	padding: 0 10px;
	border-radius: 10px;
	border: 1px solid var(--line);
	background: var(--surface);
}
.icon-button {
	width: 44px;
	height: 40px;
	border-radius: 10px;
	border: 1px solid var(--line);
	background: var(--surface);
	font-size: 20px;
	line-height: 1;
}
.progress { height: 4px; border-radius: 2px; background: var(--line); margin-top: 8px; overflow: hidden; }
.progress > div { height: 100%; background: var(--brand); transition: width .3s; }

/* card */
.body { display: flex; flex-direction: column; }
.card { padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 12px; }
.card.enter { animation: enter .18s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateX(24px); } }
.hero { display: flex; gap: 14px; align-items: center; }
.hero > img {
	width: 132px;
	height: 132px;
	flex: none;
	border-radius: 12px;
	background: #000;
	image-rendering: pixelated;
	border: 1px solid var(--line);
}
.hero-text { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.kind { font-size: 13px; color: var(--muted); }
.stem { font-size: 12px; color: var(--muted); word-break: break-all; }
.members { display: flex; gap: 4px; flex-wrap: wrap; }
.members img { width: 28px; height: 28px; border-radius: 4px; image-rendering: pixelated; background: #000; }
.confidence {
	display: inline-flex;
	gap: 6px;
	align-items: baseline;
	font-size: 13px;
	line-height: 1.3;
	color: var(--muted);
}
.confidence b { white-space: nowrap; }
.confidence::before {
	content: "";
	flex: none;
	width: 9px;
	height: 9px;
	border-radius: 50%;
	background: var(--dot);
	transform: translateY(-1px);
}
.conf-high { --dot: var(--high); }
.conf-medium { --dot: var(--medium); }
.conf-low { --dot: var(--low); }
.conf-none { --dot: var(--none); }

.label { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.label span:last-child { text-align: right; }
.name-row { position: relative; }
.name-input {
	width: 100%;
	height: 52px;
	padding: 0 48px 0 14px;
	border-radius: 12px;
	border: 1.5px solid var(--line);
	background: var(--surface);
	font-size: 19px;
	font-weight: 600;
}
.name-input:focus { outline: none; border-color: var(--brand); }
.name-input::placeholder { color: var(--none); font-weight: 400; }
.clear {
	position: absolute;
	right: 4px;
	top: 4px;
	width: 44px;
	height: 44px;
	border: 0;
	background: none;
	color: var(--muted);
	font-size: 18px;
}
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
	flex: none;
	display: flex;
	align-items: center;
	gap: 8px;
	min-height: 44px;
	padding: 4px 12px 4px 6px;
	border-radius: 22px;
	border: 1px solid var(--line);
	background: var(--surface);
	text-align: left;
	max-width: 260px;
}
.chip img { width: 32px; height: 32px; border-radius: 6px; image-rendering: pixelated; background: #000; }
.chip-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.chip-text b { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-text small { font-size: 11px; color: var(--muted); white-space: nowrap; }
.chip.no-image { padding-left: 12px; }

.classes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.class {
	height: 48px;
	border-radius: 12px;
	border: 1.5px solid var(--line);
	background: var(--surface);
	font-weight: 600;
	font-size: 15px;
}
.class.general { grid-column: span 2; }
.class[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-brand); }

/* actions */
.actions {
	display: grid;
	grid-template-columns: 52px 1.2fr .85fr 1.5fr;
	gap: 8px;
	padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px);
}
.action {
	height: 58px;
	border-radius: var(--radius);
	border: 1px solid var(--line);
	background: var(--surface-raised);
	font-weight: 600;
	font-size: 15px;
	padding: 0 4px;
}
.action.wide { width: 100%; max-width: 280px; }
.action:active { transform: scale(.97); }
.action.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); font-size: 17px; }
.action.primary:disabled { background: var(--line); border-color: var(--line); color: var(--muted); }
.action.undo { font-size: 22px; }
.action:disabled { opacity: .45; }

.empty { min-height: 50dvh; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 12px;
	text-align: center; padding: 32px 24px; color: var(--muted); }
.empty h2 { color: var(--ink); margin: 0; font-size: 22px; }

/* sheet menu */
.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .55); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
	width: 100%;
	max-width: 520px;
	max-height: 92dvh;
	overflow-y: auto;
	background: var(--surface);
	border-radius: 18px 18px 0 0;
	padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px);
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 8px; }
.sheet-item {
	height: 54px;
	border-radius: 12px;
	border: 0;
	background: var(--surface-raised);
	text-align: left;
	padding: 0 16px;
	font-size: 17px;
}
.sheet .card { padding: 0; }
.sheet h2 { margin: 4px 0; font-size: 20px; }
.help { margin: 0; color: var(--muted); }
.sheet .actions { padding: 8px 0 0; grid-template-columns: 1fr 1fr 1.6fr; }

/* pages */
.page { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.page h2, .page-title { margin: 0; font-size: 18px; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.tile b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.tile span { font-size: 12px; color: var(--muted); }
.rows { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; background: var(--surface); }
.row + .row { border-top: 1px solid var(--line); }
.row span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--surface);
	padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.segmented button { height: 40px; border: 0; border-radius: 9px; background: none; font-weight: 600; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--surface-raised); color: var(--ink); }
.search { height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px; width: 100%; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.grid-item { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px;
	display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.grid-item img { width: 56px; height: 56px; image-rendering: pixelated; border-radius: 8px; background: #000; }
.grid-item b { font-size: 13px; line-height: 1.2; overflow-wrap: anywhere; }
.grid-item small { font-size: 11px; color: var(--muted); }
.more { height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }

/* login */
.login { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 14px; padding: 24px 20px; }
.login h1 { margin: 0; font-size: 26px; }
.login p { margin: 0 0 8px; color: var(--muted); }
.login input { height: 54px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); padding: 0 14px; font-size: 18px; }
.login input:focus { outline: none; border-color: var(--brand); }
.login .error { color: var(--low); min-height: 1.4em; margin: 0; }

#toast {
	position: fixed;
	left: 50%;
	bottom: calc(env(safe-area-inset-bottom) + 86px);
	transform: translate(-50%, 20px);
	background: var(--ink);
	color: var(--on-brand);
	padding: 10px 16px;
	border-radius: 22px;
	font-weight: 600;
	font-size: 14px;
	opacity: 0;
	pointer-events: none;
	transition: opacity .2s, transform .2s;
	max-width: calc(100% - 32px);
	z-index: 30;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-height: 760px) {
	.hero > img { width: 160px; height: 160px; }
}
