:root {
	--bg: #f6f5f1;
	--surface: #ffffff;
	--text: #1c1f1e;
	--muted: #66706c;
	--line: #e3e1da;
	--accent: #0f5c4a;
	--accent-text: #ffffff;
	--user-bg: #e6efe9;
	--code-bg: #f1efe9;
	--error: #b3261e;
	--radius: 12px;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #141716;
		--surface: #1c201f;
		--text: #e8ebe9;
		--muted: #98a29e;
		--line: #2e3432;
		--accent: #4fb393;
		--accent-text: #0c1412;
		--user-bg: #22302b;
		--code-bg: #262b29;
		--error: #f2877e;
		color-scheme: dark;
	}
}

* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	height: 100%;
}

body {
	background: var(--bg);
	color: var(--text);
	font: 16px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
	display: flex;
	flex-direction: column;
}

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

button {
	cursor: pointer;
	border: 0;
	border-radius: 999px;
	padding: 0.55rem 1.1rem;
	background: var(--accent);
	color: var(--accent-text);
	font-weight: 600;
}

button.ghost {
	white-space: nowrap;
	background: transparent;
	color: var(--muted);
	border: 1px solid var(--line);
	font-weight: 500;
}

button.ghost:hover {
	color: var(--text);
}

button:focus-visible,
textarea:focus-visible,
input:focus-visible,
summary:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

.muted {
	color: var(--muted);
}

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

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

/* Login */

body.login {
	align-items: center;
	justify-content: center;
	padding: 16px;
}

.login-card {
	width: 100%;
	max-width: 360px;
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 2rem;
}

.login-card form {
	display: grid;
	gap: 0.6rem;
	margin-top: 1.25rem;
}

.login-card label {
	font-weight: 600;
	font-size: 0.9rem;
}

.login-card input {
	padding: 0.65rem 0.8rem;
	border: 1px solid var(--line);
	border-radius: 8px;
	background: var(--bg);
}

.login-error {
	display: none;
	margin: 0;
	color: var(--error);
	font-size: 0.9rem;
}

.login-error.visible {
	display: block;
}

/* App */

@media (max-width: 480px) {
	.topbar button.ghost {
		padding: 0.4rem 0.75rem;
		font-size: 0.875rem;
	}
}

.topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.75rem 16px;
	border-bottom: 1px solid var(--line);
	background: var(--surface);
}

.topbar-actions {
	display: flex;
	gap: 0.5rem;
}

.topbar-actions form {
	margin: 0;
}

.thread {
	flex: 1;
	overflow-y: auto;
	padding: 1.5rem 16px 2rem;
	display: flex;
	flex-direction: column;
	gap: 1.25rem;
}

.thread > * {
	width: 100%;
	max-width: 760px;
	margin-inline: auto;
}

.intro {
	margin-top: 8vh;
}

.intro h1 {
	font-size: 1.75rem;
	letter-spacing: -0.02em;
	margin: 0 0 0.5rem;
}

.examples {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
	gap: 0.6rem;
	margin-top: 1.5rem;
}

.example {
	text-align: left;
	background: var(--surface);
	color: var(--text);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	font-weight: 400;
	padding: 0.8rem 1rem;
}

.example:hover {
	border-color: var(--accent);
}

.msg.user {
	align-self: flex-end;
	width: auto;
	max-width: min(560px, 100%);
	margin-inline: auto 0;
	background: var(--user-bg);
	border-radius: var(--radius) var(--radius) 4px var(--radius);
	padding: 0.7rem 1rem;
	white-space: pre-wrap;
}

@media (min-width: 800px) {
	.msg.user {
		margin-right: calc((100% - 760px) / 2);
	}
}

.msg.assistant {
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 1rem 1.25rem;
}

.steps summary {
	cursor: pointer;
	color: var(--muted);
	font-size: 0.875rem;
}

.steps ol {
	list-style: none;
	margin: 0.6rem 0 0;
	padding: 0 0 0 0.9rem;
	border-left: 2px solid var(--line);
	display: grid;
	gap: 0.35rem;
	font-size: 0.875rem;
}

.step {
	display: flex;
	flex-wrap: wrap;
	gap: 0.25rem 0.5rem;
	align-items: baseline;
}

.step.narration {
	color: var(--muted);
	font-style: italic;
}

.step-detail {
	color: var(--muted);
	overflow-wrap: anywhere;
}

.step details summary {
	cursor: pointer;
}

.step pre {
	margin: 0.35rem 0 0;
	max-width: 100%;
}

.status {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	color: var(--muted);
	font-size: 0.9rem;
	margin-top: 0.75rem;
}

.spinner {
	width: 0.9rem;
	height: 0.9rem;
	border: 2px solid var(--line);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: spin 0.8s linear infinite;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

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

.answer:not(:empty) {
	margin-top: 0.75rem;
}

.answer > :first-child {
	margin-top: 0;
}

.answer > :last-child {
	margin-bottom: 0;
}

.answer h1,
.answer h2,
.answer h3 {
	font-size: 1.05rem;
	margin: 1.2rem 0 0.4rem;
}

.answer table {
	border-collapse: collapse;
	display: block;
	overflow-x: auto;
	font-size: 0.9rem;
}

.answer th,
.answer td {
	border: 1px solid var(--line);
	padding: 0.35rem 0.6rem;
	text-align: left;
}

code,
pre {
	font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
	font-size: 0.85em;
}

:not(pre) > code {
	background: var(--code-bg);
	border-radius: 4px;
	padding: 0.1em 0.35em;
}

pre {
	background: var(--code-bg);
	border-radius: 8px;
	padding: 0.75rem;
	overflow-x: auto;
	white-space: pre;
}

.error {
	color: var(--error);
}

.composer {
	border-top: 1px solid var(--line);
	background: var(--surface);
	padding: 0.75rem 16px;
}

.composer form {
	display: flex;
	gap: 0.5rem;
	align-items: flex-end;
	max-width: 760px;
	margin-inline: auto;
}

.composer textarea {
	flex: 1;
	resize: none;
	min-height: 2.75rem;
	max-height: 240px;
	padding: 0.65rem 0.9rem;
	border: 1px solid var(--line);
	border-radius: var(--radius);
	background: var(--bg);
}

.composer .hint {
	max-width: 760px;
	margin: 0.4rem auto 0;
	font-size: 0.8rem;
}
