:root {
	color-scheme: dark;
	--bg: #0f0e12;
	--surface: #1a181f;
	--fg: #efe8df;
	--muted: #9c948c;
	--accent: #d8b4a0;
	--border: #2a2730;
	--danger: #ff9a8f;
	--radius: 12px;
	--space: 1rem;
	--font: "Commissioner", -apple-system, "Helvetica Neue", sans-serif;
	--serif: "Literata", Georgia, serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
	margin: 0;
	background: var(--bg);
	color: var(--fg);
	font-family: var(--font);
	font-size: 17px;
	line-height: 1.6;
	-webkit-font-smoothing: antialiased;
	overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
h1, h2 { margin: 0; font-weight: 500; }

.app {
	display: flex;
	flex-direction: column;
	height: 100dvh;
	max-width: 46rem;
	margin: 0 auto;
}
.topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: calc(env(safe-area-inset-top) + 4px) 8px 4px;
}
.topbar-title { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.brand { font-family: var(--serif); font-size: 1.15rem; letter-spacing: 0.02em; }
.conv-title {
	font-size: 0.75rem;
	color: var(--muted);
	max-width: 60vw;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.icon-btn {
	display: inline-grid;
	place-items: center;
	width: 44px;
	height: 44px;
	flex: none;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--muted);
	cursor: pointer;
}
.icon-btn:active { opacity: 0.6; }
.icon-btn.on { color: var(--accent); }
.icon-btn.listening { animation: pulse 1.2s ease-in-out infinite; }
.icon-btn.small { width: 32px; height: 32px; }
.icon-spacer { width: 44px; }
@keyframes pulse { 50% { opacity: 0.45; } }

.thread {
	flex: 1;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	padding: 8px 20px 16px;
}
.msg { margin: 0 0 22px; }
.msg p { margin: 0 0 0.6em; }
.msg-user { color: var(--muted); padding-left: 14px; border-left: 1px solid var(--border); }
.msg-mira .prose { font-family: var(--serif); font-size: 1.05rem; }
.msg-mira em { color: var(--accent); font-style: italic; }
.msg-actions { opacity: 0.5; margin-top: -6px; }
.msg-figure { margin: 0; }
.msg-figure img { display: block; width: 100%; height: auto; border-radius: 6px; }
.msg-figure figcaption { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.hidden-img { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
.img-wait {
	display: flex;
	flex-direction: column;
	gap: 8px;
	justify-content: center;
	align-items: flex-start;
	min-height: 120px;
	color: var(--muted);
}
.img-wait-text { animation: pulse 1.6s ease-in-out infinite; }

.typing { display: flex; gap: 6px; padding: 8px 0; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: pulse 1s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

.welcome { padding: 12vh 0 0; }
.welcome h1 { font-family: var(--serif); font-size: 3.2rem; line-height: 1.1; margin-bottom: 12px; }
.welcome p { color: var(--muted); margin: 0 0 28px; }
.starters { display: grid; gap: 4px; }
.starter {
	text-align: left;
	border: 0;
	border-bottom: 1px solid var(--border);
	background: transparent;
	padding: 12px 0;
	color: var(--fg);
	cursor: pointer;
}
.starter.accent { color: var(--accent); border-bottom: 0; }

.composer { padding: 6px 10px calc(env(safe-area-inset-bottom) + 8px); border-top: 1px solid var(--border); }
.mode-note { font-size: 0.8rem; color: var(--accent); padding: 2px 8px 6px; }
.composer-row { display: flex; align-items: flex-end; gap: 2px; }
.composer-input {
	flex: 1;
	min-width: 0;
	resize: none;
	border: 0;
	background: transparent;
	color: var(--fg);
	font: inherit;
	font-size: 17px;
	padding: 10px 6px;
	max-height: 160px;
	outline: none;
}
.composer-input::placeholder { color: var(--muted); }
.send-btn {
	display: grid;
	place-items: center;
	width: 38px;
	height: 38px;
	margin: 3px;
	flex: none;
	border: 0;
	border-radius: 50%;
	background: var(--fg);
	color: var(--bg);
	cursor: pointer;
}
.send-btn:disabled { opacity: 0.25; }

.sheet {
	position: fixed;
	inset: 0;
	z-index: 10;
	background: var(--bg);
	display: flex;
	flex-direction: column;
}
.sheet-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: calc(env(safe-area-inset-top) + 4px) 8px 4px;
	max-width: 46rem;
	width: 100%;
	margin: 0 auto;
}
.sheet-head h2 { font-size: 1rem; text-align: center; }
.sheet-body {
	flex: 1;
	overflow-y: auto;
	padding: 12px 20px calc(env(safe-area-inset-bottom) + 24px);
	max-width: 46rem;
	width: 100%;
	margin: 0 auto;
}
.sheet-list { list-style: none; margin: 0; padding: 0; }
.sheet-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	width: 100%;
	min-height: 52px;
	padding: 10px 0;
	border: 0;
	border-bottom: 1px solid var(--border);
	background: transparent;
	text-align: left;
	cursor: pointer;
}
.sheet-row strong { display: block; font-weight: 500; }
.sheet-row small { display: block; color: var(--muted); font-size: 0.8rem; }
.history-item { border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.history-item .sheet-row { border-bottom: 0; }
.history-actions { display: flex; gap: 16px; flex-wrap: wrap; }
.sheet-save { margin-top: 24px; display: grid; gap: 12px; }
.logout { margin-top: 28px; }

.link-btn { border: 0; background: none; color: var(--accent); padding: 8px 0; cursor: pointer; font-size: 0.9rem; }
.link-btn.danger { color: var(--danger); }

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 0.55rem 1.1rem;
	border: 1px solid transparent;
	border-radius: var(--radius);
	background: var(--fg);
	color: var(--bg);
	font-weight: 500;
	cursor: pointer;
}
.btn:disabled { opacity: 0.4; }
.btn-secondary { background: transparent; color: var(--fg); border-color: var(--border); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-wide { width: 100%; }

.input, .select, .textarea {
	width: 100%;
	padding: 0.65rem 0.8rem;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--fg);
	font: inherit;
	font-size: 16px;
}
.field { display: grid; gap: 0.35rem; }
.field > label { font-size: 0.875rem; color: var(--muted); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.toggle { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.toggle input { margin-top: 5px; width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.toggle small { display: block; color: var(--muted); font-size: 0.82rem; }
.choice { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 20px; }
.choice legend { font-size: 0.875rem; color: var(--muted); margin-bottom: 8px; width: 100%; }
.choice label { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.choice input { accent-color: var(--accent); width: 18px; height: 18px; }

.auth {
	min-height: 100dvh;
	max-width: 24rem;
	margin: 0 auto;
	padding: calc(env(safe-area-inset-top) + 14vh) 24px 32px;
	display: flex;
	flex-direction: column;
	gap: 16px;
}
.auth-mark { font-family: var(--serif); font-size: 3.4rem; line-height: 1; }
.auth-lede { color: var(--muted); margin: 0 0 12px; }
.auth-form { display: grid; gap: 14px; }
.boot { min-height: 100dvh; display: grid; place-content: center; gap: 12px; padding: 24px; }

.stack { display: grid; gap: 18px; }
.row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.hint { margin: 0; color: var(--muted); font-size: 0.9rem; }
.card { padding: var(--space); border: 1px solid var(--border); border-radius: var(--radius); }
.grid { display: grid; gap: var(--space); grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr)); }
.list { display: grid; gap: 0.5rem; margin: 0; padding: 0; list-style: none; }
.list-item { display: flex; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; padding: 0.7rem 0; }
.badge { display: inline-block; padding: 0.1rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.8rem; color: var(--muted); }

.empty { padding: 2rem 0; text-align: center; color: var(--muted); }
.empty-title { margin: 0 0 0.25rem; color: var(--fg); font-weight: 500; }
.loading { display: flex; align-items: center; justify-content: center; gap: 0.6rem; padding: 1.5rem; color: var(--muted); }
.spinner {
	flex: none;
	width: 1.15rem;
	height: 1.15rem;
	border: 2px solid var(--border);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: fab-spin 0.7s linear infinite;
}
@keyframes fab-spin { to { transform: rotate(360deg); } }
.skeleton {
	display: block;
	height: 1rem;
	border-radius: 6px;
	background: linear-gradient(90deg, var(--border), transparent, var(--border));
	background-size: 200% 100%;
	animation: fab-shimmer 1.2s linear infinite;
}
@keyframes fab-shimmer { to { background-position: -200% 0; } }
.alert {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	flex-wrap: wrap;
	padding: 0.5rem 0 0.5rem 0.85rem;
	border-left: 2px solid var(--muted);
	margin: 8px 0;
}
.alert-error { border-left-color: var(--danger); color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
	.spinner, .skeleton, .typing span, .img-wait-text, .icon-btn.listening { animation: none; }
}
:where(a, button, input, select, textarea):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
