:root {
	--bg: #f5f0e6;
	--surface: #fffdf8;
	--surface-2: #efe8da;
	--ink: #2a251f;
	--muted: #6f665a;
	--line: #ddd3c2;
	--accent: #2f5d50;
	--accent-ink: #ffffff;
	--accent-soft: #dbe8e2;
	--highlight: #a5532b;
	--highlight-soft: #f4e2d6;
	--ok: #3b7a3b;
	--warn-bg: #fbf0d5;
	--error: #a33a2c;
	--error-bg: #f9e3df;
	--male: #c9dbe8;
	--female: #ecd3d3;
	--unknown: #e2dccf;
	--shadow: 0 1px 2px rgb(42 37 31 / 6%), 0 4px 14px rgb(42 37 31 / 6%);
	--radius: 12px;
	--serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
	--sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #181714;
		--surface: #22201c;
		--surface-2: #2b2924;
		--ink: #ece6da;
		--muted: #a59c8e;
		--line: #3a372f;
		--accent: #7fb8a4;
		--accent-ink: #12201b;
		--accent-soft: #2a3b35;
		--highlight: #e09a72;
		--highlight-soft: #3d2c22;
		--ok: #8fc98f;
		--warn-bg: #3a3220;
		--error: #f0a195;
		--error-bg: #3d2622;
		--male: #34485a;
		--female: #553a40;
		--unknown: #3a372f;
		--shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 14px rgb(0 0 0 / 25%);
		color-scheme: dark;
	}
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
	margin: 0;
	background: var(--bg);
	color: var(--ink);
	font: 16px/1.5 var(--sans);
	min-height: 100vh;
	display: flex;
	flex-direction: column;
}

a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* ---------- Päis ja jalus ---------- */

.top {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: .9rem clamp(16px, 4vw, 40px);
	border-bottom: 1px solid var(--line);
	background: var(--surface);
}
.brand {
	display: inline-flex;
	align-items: center;
	gap: .45rem;
	font-family: var(--serif);
	font-size: 1.35rem;
	font-weight: 600;
	color: var(--ink);
	text-decoration: none;
}
.brand svg { color: var(--accent); }
.account { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.account form { margin: 0; }
.me-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }

main {
	flex: 1;
	width: 100%;
	max-width: 1080px;
	margin: 0 auto;
	padding: clamp(20px, 4vw, 40px) 16px 48px;
}

.foot {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	gap: .5rem 1.5rem;
	padding: 1rem clamp(16px, 4vw, 40px);
	border-top: 1px solid var(--line);
	color: var(--muted);
	font-size: .875rem;
}

.intro { max-width: 680px; margin-bottom: 1.75rem; }
.intro h1 { font-size: clamp(1.7rem, 4.5vw, 2.5rem); letter-spacing: -.01em; }
.intro p { color: var(--muted); font-size: 1.075rem; }

/* ---------- Komponendid ---------- */

.panel {
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: clamp(16px, 3vw, 28px);
}
.login { max-width: 640px; }

.btn {
	--b: var(--surface-2);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: .35rem;
	padding: .55rem 1rem;
	border: 1px solid var(--line);
	border-radius: 999px;
	background: var(--b);
	color: var(--ink);
	font: inherit;
	font-weight: 500;
	text-decoration: none;
	cursor: pointer;
	white-space: nowrap;
	transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible, .diagram-scroll:focus-visible {
	outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
	outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: .3rem .75rem; font-size: .875rem; }
.btn.big { padding: .75rem 1.6rem; font-size: 1.05rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.tag {
	display: inline-block;
	padding: .05rem .5rem;
	border-radius: 999px;
	background: var(--surface-2);
	color: var(--muted);
	font-size: .75rem;
	font-weight: 600;
	white-space: nowrap;
}
.tag.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }

.notice {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 1.25rem;
	padding: .75rem 1rem;
	border-radius: var(--radius);
	background: var(--accent-soft);
}
.notice.warn { background: var(--warn-bg); }
.notice.error { background: var(--error-bg); color: var(--error); }
.notice .close { border: 0; background: none; color: inherit; font-size: 1.25rem; line-height: 1; cursor: pointer; }
.error { color: var(--error); }

.field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: .6rem; }
.field > span { font-size: .875rem; color: var(--muted); }
input, select {
	font: inherit;
	color: var(--ink);
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: 10px;
	padding: .55rem .75rem;
	min-width: 0;
	width: 100%;
}
select { width: auto; }

/* ---------- Avatarid ---------- */

.avatar {
	flex: none;
	display: inline-grid;
	place-items: center;
	border-radius: 50%;
	object-fit: cover;
	background: var(--unknown);
	color: var(--ink);
	font-weight: 600;
	font-family: var(--serif);
}
.avatar.sm { width: 32px; height: 32px; font-size: .8rem; }
.avatar.md { width: 44px; height: 44px; font-size: .95rem; }
.avatar.lg { width: 60px; height: 60px; font-size: 1.2rem; }
.avatar.g-m { background: var(--male); }
.avatar.g-f { background: var(--female); }

/* ---------- Isikute valik ---------- */

.pickers {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
	gap: 1rem;
	align-items: start;
}
.link-mark { color: var(--muted); padding-top: 3.1rem; }

.picker {
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 18px;
	min-width: 0;
}
.picker-title { font-size: 1.15rem; }
.search { display: grid; grid-template-columns: minmax(0, 1fr) 7.5rem auto; gap: .5rem; margin-bottom: .6rem; }
.use-me { margin-bottom: .5rem; }

.chosen { display: flex; align-items: center; gap: .9rem; padding: .25rem 0; }
.chosen-body { flex: 1; min-width: 0; }
.chosen-body .pname { font-weight: 600; font-size: 1.1rem; display: block; }

.result-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; max-height: 460px; overflow-y: auto; }
.result {
	display: grid;
	grid-template-columns: auto minmax(0, 1fr);
	gap: .25rem .75rem;
	align-items: start;
	padding: .65rem;
	border: 1px solid var(--line);
	border-radius: 10px;
	background: var(--surface);
}
.result.match { border-color: color-mix(in srgb, var(--ok) 50%, var(--line)); }
.result-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .4rem; }
.pname { font-weight: 600; }
.maiden { font-weight: 400; color: var(--muted); }
.result-actions { grid-column: 2; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.geni-link { font-size: .875rem; }
.family { margin-top: .4rem; font-size: .875rem; }
.family dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .15rem .6rem; }
.family dt { color: var(--muted); }
.family dd { margin: 0; }
.more { margin-top: .5rem; }

.finder {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 1rem 1.5rem;
	margin: 1.5rem 0;
}

/* ---------- Tulemus ---------- */

.pending { display: flex; align-items: center; gap: 1rem; }
.pending > div { flex: 1; }
.pending p { margin: 0; }
.spinner {
	width: 28px;
	height: 28px;
	border-radius: 50%;
	border: 3px solid var(--line);
	border-top-color: var(--accent);
	animation: spin 0.9s linear infinite;
	flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.error-panel { border-color: color-mix(in srgb, var(--error) 35%, var(--line)); }
.hints { padding-left: 1.2rem; color: var(--muted); }

.verdict { text-align: center; padding: .5rem 0 1rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; font-weight: 700; color: var(--highlight); margin-bottom: .25rem; }
.term { font-family: var(--serif); font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.1; font-weight: 600; margin-bottom: .6rem; }
.explain { max-width: 640px; margin: 0 auto .5rem; font-size: 1.05rem; }
.facts { color: var(--muted); font-size: .9rem; }

.section-title {
	font-size: .8rem;
	font-family: var(--sans);
	text-transform: uppercase;
	letter-spacing: .1em;
	color: var(--muted);
	margin: 1.5rem 0 .75rem;
	padding-top: 1rem;
	border-top: 1px solid var(--line);
}

.diagram-scroll {
	overflow-x: auto;
	padding: 14px 4px 10px;
	border-radius: 10px;
	background:
		radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--line) 80%, transparent) 1px, transparent 0) 0 0 / 18px 18px,
		var(--surface-2);
}
.diagram { position: relative; margin: 0 auto; }
.diagram-toggle { display: none; }
.tag.apex-tag { background: var(--highlight-soft); color: var(--highlight); }
.edges { position: absolute; inset: 0; overflow: visible; }
.edge { fill: none; stroke: var(--muted); stroke-width: 2; }
.edge.spouse { stroke-dasharray: 5 5; }
.edge-label {
	position: absolute;
	transform: translate(-50%, -50%);
	padding: 0 .45rem;
	border-radius: 999px;
	background: var(--surface);
	border: 1px solid var(--line);
	font-size: .75rem;
	color: var(--muted);
	white-space: nowrap;
	z-index: 1;
}
.node {
	position: absolute;
	display: grid;
	grid-template-columns: auto minmax(0, 1fr);
	grid-template-rows: auto auto;
	column-gap: .5rem;
	align-content: center;
	padding: .5rem .6rem;
	border-radius: 10px;
	background: var(--surface);
	border: 1px solid var(--line);
	box-shadow: var(--shadow);
	color: var(--ink);
	text-decoration: none;
	z-index: 2;
}
a.node:hover { border-color: var(--accent); }
.node .avatar { grid-row: span 2; align-self: center; }
.n-name { font-weight: 600; font-size: .85rem; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.n-life { font-size: .75rem; color: var(--muted); }
.node.endpoint { border: 2px solid var(--accent); background: var(--accent-soft); }
.node.apex { border: 2px solid var(--highlight); background: var(--highlight-soft); }
.role {
	position: absolute;
	top: -.7rem;
	left: .6rem;
	padding: 0 .4rem;
	border-radius: 999px;
	background: var(--accent);
	color: var(--accent-ink);
	font-size: .7rem;
	font-weight: 700;
}
.node.apex .role { background: var(--highlight); color: var(--surface); }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: .1rem; }
.steps li { display: flex; align-items: center; gap: .65rem; padding: .4rem 0; }
.steps .arrow { width: 1.25rem; text-align: center; color: var(--muted); font-weight: 700; flex: none; }
.result-actions-row { margin-top: 1.25rem; }
.disclaimer { margin-top: 1rem; }

/* ---------- Tekstilehed ---------- */

.prose { max-width: 720px; }
.prose h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); }
.prose h2 { margin-top: 2rem; font-size: 1.3rem; }
.prose li { margin-bottom: .35rem; }

/* ---------- Kitsas ekraan ---------- */

@media (max-width: 760px) {
	.pickers { grid-template-columns: minmax(0, 1fr); }
	.link-mark { justify-self: center; padding: 0; transform: rotate(90deg); }
	.diagram-toggle { display: inline-flex; }
	.diagram-wrap:not(.open) { display: none; }
	.diagram-wrap { margin-top: .75rem; }
	.search { grid-template-columns: minmax(0, 1fr) 6.5rem; }
	.search .btn { grid-column: 1 / -1; }
	.me-name { display: none; }
	.finder { flex-direction: column; align-items: stretch; }
	.finder .btn { width: 100%; }
	.field.inline { justify-content: space-between; }
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.help { padding: .75rem .9rem; border-radius: 10px; background: var(--warn-bg); font-size: .925rem; }
.help ol { margin: .25rem 0 .75rem; padding-left: 1.2rem; }
.help li { margin-bottom: .2rem; }
