:root {
	color-scheme: light;
	--bg: #fff7fb;
	--panel: #ffffff;
	--text: #2b1f2a;
	--muted: #7a6675;
	--accent: #d86b9a;
	--accent-soft: #f7d9e8;
	--user: #fff;
	--assistant: #fde8f1;
	--border: #efd5e2;
}

* {
	box-sizing: border-box;
}

html {
	height: 100%;
	overflow: hidden;
}

body {
	margin: 0;
	font-family: "PingFang SC", "Helvetica Neue", sans-serif;
	background: linear-gradient(180deg, #fff7fb 0%, #fff 40%);
	color: var(--text);
	height: 100%;
	overflow: hidden;
}

.persona-quiz {
	position: fixed;
	inset: 0;
	z-index: 200;
	display: grid;
	place-items: center;
	padding: 20px;
	background: rgba(43, 31, 42, 0.45);
	backdrop-filter: blur(4px);
}

.persona-quiz.hidden {
	display: none;
}

.quiz-card {
	width: min(560px, 100%);
	max-height: 90vh;
	overflow: auto;
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 18px;
	padding: 22px 22px 18px;
	box-shadow: 0 18px 50px rgba(43, 31, 42, 0.18);
}

.quiz-top {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 10px;
}

.quiz-badge {
	font-size: 0.8rem;
	color: var(--accent);
	font-weight: 600;
}

.quiz-progress {
	font-size: 0.8rem;
	color: var(--muted);
}

.quiz-card h2 {
	margin: 0 0 8px;
	font-size: 1.35rem;
}

.quiz-subtitle {
	margin: 0 0 16px;
	color: var(--muted);
	line-height: 1.6;
}

.quiz-body {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.quiz-options {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.quiz-option {
	text-align: left;
	border: 1px solid var(--border);
	background: #fff;
	border-radius: 14px;
	padding: 12px 14px;
	cursor: pointer;
	font: inherit;
}

.quiz-option strong {
	display: block;
	margin-bottom: 2px;
}

.quiz-option span {
	display: block;
	font-size: 0.88rem;
	color: var(--muted);
	line-height: 1.45;
}

.quiz-option.selected {
	border-color: var(--accent);
	background: var(--accent-soft);
}

.quiz-text input {
	width: 100%;
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 12px;
	font: inherit;
}

.quiz-summary {
	padding: 14px;
	border-radius: 12px;
	background: #faf5f8;
	line-height: 1.7;
}

.quiz-actions {
	display: flex;
	justify-content: space-between;
	gap: 10px;
	margin-top: 18px;
}

.quiz-blocked {
	opacity: 0.45;
	pointer-events: none;
	user-select: none;
}

.app {
	display: grid;
	grid-template-columns: 1fr;
	grid-template-rows: auto minmax(0, 1fr);
	height: 100vh;
	max-width: 820px;
	margin: 0 auto;
	gap: 8px;
	padding: 8px;
	overflow: hidden;
}

.header {
	grid-column: 1 / -1;
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	gap: 10px;
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 10px 14px;
}

.header-copy {
	flex: 1;
	min-width: 0;
}

.header h1 {
	margin: 0;
	font-size: 1.2rem;
}

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

.agent-header-copy {
	margin: 6px 0 0;
	font-size: 0.9rem;
	line-height: 1.4;
	color: var(--text);
}

.header-actions {
	display: flex;
	gap: 5px;
	flex-shrink: 0;
}

.insights-panel {
	position: fixed;
	inset: 0;
	z-index: 150;
	display: grid;
	grid-template-columns: 1fr auto;
}

.insights-panel.hidden {
	display: none;
}

.insights-backdrop {
	border: none;
	margin: 0;
	padding: 0;
	background: rgba(43, 31, 42, 0.28);
	cursor: pointer;
}

.insights-drawer {
	width: min(380px, 92vw);
	height: 100%;
	overflow: auto;
	background: var(--panel);
	border-left: 1px solid var(--border);
	padding: 16px;
	box-shadow: -8px 0 32px rgba(43, 31, 42, 0.12);
}

.insights-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 12px;
	margin-bottom: 14px;
}

.insights-head h2 {
	margin: 0;
	font-size: 1.05rem;
}

.insights-drawer .summary-card {
	margin-bottom: 12px;
}

.insights-drawer .summary-card h3 {
	margin: 0 0 8px;
	font-size: 0.95rem;
}

.header-actions button.active {
	background: var(--accent);
	color: #fff;
}

button.small {
	padding: 6px 12px;
	font-size: 0.85rem;
}

.summary-card,
.chat {
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 8px 10px;
}

.summary-text {
	margin: 0 0 8px;
	line-height: 1.7;
	font-size: 0.95rem;
}

.fact-list {
	margin: 0;
	padding-left: 1.1rem;
	color: var(--muted);
	font-size: 0.9rem;
	line-height: 1.6;
}

.memory-hint {
	margin: 8px 0 0;
	font-size: 0.85rem;
}

.chat {
	display: flex;
	flex-direction: column;
	min-height: 0;
	overflow: hidden;
}

.starter-area {
	margin-bottom: 6px;
	padding: 8px 10px;
	background: #faf5f8;
	border-radius: 10px;
	border: 1px dashed var(--border);
}

.starter-area.hidden {
	display: none;
}

.starter-label {
	margin: 0 0 6px;
	font-size: 0.8rem;
	color: var(--muted);
}

.starter-chips {
	display: flex;
	flex-wrap: wrap;
	gap: 5px;
}

.starter-chip {
	background: white;
	border: 1px solid var(--border);
	border-radius: 999px;
	padding: 5px 10px;
	font-size: 0.82rem;
	line-height: 1.3;
	text-align: left;
}

.starter-chip:hover {
	border-color: var(--accent);
	background: var(--accent-soft);
}

.thread {
	flex: 1;
	min-height: 0;
	overflow: auto;
	overflow-anchor: none;
	scroll-behavior: auto;
	display: flex;
	flex-direction: column;
	gap: 3px;
	padding-bottom: 3px;
}

.empty-state {
	color: var(--muted);
	line-height: 1.7;
	padding: 8px 4px;
}

.bubble {
	max-width: 80%;
	padding: 1px 6px;
	border-radius: 5px;
	line-height: 1.2;
	white-space: pre-wrap;
	font-size: 0.92rem;
	border-width: 0.5px;
}

.bubble .meta {
	font-size: 0.6rem;
	color: var(--muted);
	opacity: 0.5;
	display: inline;
	margin-right: 4px;
}

.bubble.user {
	align-self: flex-end;
	background: var(--user);
	border: 0.5px solid var(--border);
	animation: bubbleIn 0.2s ease both;
}

.bubble.user.pending {
	opacity: 0.92;
}

.bubble.assistant {
	align-self: flex-start;
	background: var(--assistant);
	border: 0.5px solid var(--border);
	animation: bubbleIn 0.35s ease both;
}

.bubble.assistant.stagger {
	animation-delay: 0.6s;
}

@keyframes bubbleIn {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.typing-indicator {
	align-self: flex-start;
	display: flex;
	gap: 4px;
	padding: 12px 14px;
	border-radius: 16px;
	background: var(--assistant);
}

.typing-indicator span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--muted);
	animation: typingDot 1s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) {
	animation-delay: 0.15s;
}

.typing-indicator span:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes typingDot {
	0%,
	80%,
	100% {
		opacity: 0.35;
		transform: translateY(0);
	}
	40% {
		opacity: 1;
		transform: translateY(-3px);
	}
}

.meta {
	font-size: 12px;
	color: var(--muted);
	margin-bottom: 4px;
}

.chat-form {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 8px;
	align-items: end;
}

.composer {
	display: flex;
	flex-direction: column;
	gap: 6px;
	min-width: 0;
}

.composer-toolbar {
	display: flex;
	gap: 4px;
}

.icon-btn {
	padding: 4px 8px;
	font-size: 1.1rem;
	border: none;
	background: transparent;
	cursor: pointer;
	border-radius: 8px;
	transition: background 0.15s, opacity 0.15s;
	line-height: 1;
}

.icon-btn:hover:not(:disabled) {
	background: var(--accent-soft);
}

.icon-btn:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.icon-btn.recording {
	background: #fde8e8;
	animation: recordPulse 1.2s ease-in-out infinite;
}

@keyframes recordPulse {
	0%,
	100% {
		box-shadow: 0 0 0 0 rgba(216, 107, 154, 0.35);
	}
	50% {
		box-shadow: 0 0 0 6px rgba(216, 107, 154, 0);
	}
}

.chat-form textarea {
	width: 100%;
	resize: none;
	max-height: 80px;
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 8px 10px;
	font: inherit;
	font-size: 0.92rem;
}

.chat-form button.primary {
	padding: 8px 14px;
	font-size: 0.92rem;
	align-self: end;
}

.recording-bar {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 6px 10px;
	border-radius: 10px;
	background: #fff0f5;
	border: 1px solid var(--border);
	font-size: 0.85rem;
	color: var(--text);
	min-height: 32px;
}

.recording-bar.hidden {
	display: none;
}

.recording-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #e74c3c;
	animation: recordPulse 1.2s ease-in-out infinite;
}

#recording-timer {
	margin-left: auto;
	color: var(--muted);
	font-variant-numeric: tabular-nums;
}

.hidden-file-input {
	display: none;
}

.toast {
	position: fixed;
	left: 50%;
	bottom: calc(88px + env(safe-area-inset-bottom, 0px));
	transform: translateX(-50%);
	max-width: min(420px, calc(100vw - 32px));
	padding: 10px 14px;
	border-radius: 12px;
	background: rgba(43, 31, 42, 0.92);
	color: #fff;
	font-size: 0.88rem;
	line-height: 1.45;
	z-index: 300;
	box-shadow: 0 8px 24px rgba(43, 31, 42, 0.2);
	pointer-events: none;
}

.toast.hidden {
	display: none;
}

.bubble-image {
	display: block;
	max-width: min(220px, 100%);
	max-height: 180px;
	border-radius: 8px;
	margin: 4px 0 2px;
	object-fit: cover;
}

button {
	border: none;
	border-radius: 999px;
	padding: 10px 16px;
	cursor: pointer;
	font: inherit;
}

button.primary {
	background: var(--accent);
	color: white;
}

button.secondary,
.header-actions button {
	background: var(--accent-soft);
	color: var(--text);
}

/* ── Auth Screen ── */

.auth-screen {
	display: grid;
	place-items: center;
	min-height: 100vh;
	padding: 24px;
}

.auth-screen.hidden {
	display: none;
}

.chat-screen.hidden {
	display: none;
}

.auth-card {
	width: min(400px, 100%);
	background: var(--panel);
	border: 1px solid var(--border);
	border-radius: 20px;
	padding: 36px 28px 28px;
	box-shadow: 0 18px 50px rgba(43, 31, 42, 0.12);
}

.auth-brand {
	text-align: center;
	margin-bottom: 28px;
}

.auth-brand h1 {
	margin: 0 0 6px;
	font-size: 2rem;
	color: var(--accent);
}

.auth-tabs {
	display: flex;
	gap: 0;
	margin-bottom: 24px;
	border: 1px solid var(--border);
	border-radius: 12px;
	overflow: hidden;
}

.auth-tab {
	flex: 1;
	padding: 10px;
	border: none;
	background: transparent;
	font: inherit;
	font-size: 0.95rem;
	cursor: pointer;
	text-align: center;
	transition: background 0.15s, color 0.15s;
}

.auth-tab.active {
	background: var(--accent);
	color: #fff;
	font-weight: 600;
}

.auth-form {
	display: flex;
	flex-direction: column;
	gap: 16px;
}

.auth-field {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.auth-field span {
	font-size: 0.85rem;
	color: var(--muted);
	font-weight: 500;
}

.auth-field input {
	padding: 10px 12px;
	border: 1px solid var(--border);
	border-radius: 10px;
	font: inherit;
	font-size: 0.95rem;
	transition: border-color 0.15s;
}

.auth-field input:focus {
	outline: none;
	border-color: var(--accent);
}

.auth-submit {
	margin-top: 4px;
	padding: 12px;
	border: none;
	border-radius: 12px;
	background: var(--accent);
	color: #fff;
	font: inherit;
	font-size: 1rem;
	font-weight: 600;
	cursor: pointer;
	transition: opacity 0.15s;
}

.auth-submit:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.auth-submit:hover:not(:disabled) {
	opacity: 0.9;
}

.auth-error {
	padding: 10px 12px;
	border-radius: 10px;
	background: #fef2f2;
	color: #c0392b;
	font-size: 0.9rem;
	border: 1px solid #f5c6cb;
}

.auth-error.hidden {
	display: none;
}

.auth-success {
	padding: 10px 12px;
	border-radius: 10px;
	background: #f0fdf4;
	color: #27ae60;
	font-size: 0.9rem;
	border: 1px solid #bbf7d0;
}

.auth-success.hidden {
	display: none;
}

#logout-btn {
	background: transparent;
	color: var(--muted);
	border: 1px solid var(--border);
}

/* User note in insights */
.user-note-input {
	width: 100%;
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 8px 10px;
	font: inherit;
	font-size: 0.85rem;
	resize: vertical;
	min-height: 60px;
	margin-top: 8px;
	line-height: 1.4;
}

.user-note-input:focus {
	outline: none;
	border-color: var(--accent);
}

.user-note-actions {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-top: 6px;
}

.user-note-actions .muted {
	font-size: 0.78rem;
}

.auth-apk-link {
	text-align: center;
	margin-top: 20px;
	font-size: 0.85rem;
}

.auth-apk-link a {
	color: var(--accent);
	text-decoration: none;
}

.auth-apk-link a:hover {
	text-decoration: underline;
}

@media (max-width: 820px) {
	:root {
		--safe-bottom: env(safe-area-inset-bottom, 0px);
	}

	body {
		background: var(--panel);
	}

	/* Auth Screen */
	.auth-screen {
		padding: 16px;
		align-items: flex-start;
		padding-top: max(40px, env(safe-area-inset-top));
	}

	.auth-card {
		padding: 28px 20px 24px;
		box-shadow: none;
		border-radius: 16px;
	}

	.auth-brand {
		margin-bottom: 24px;
	}

	.auth-brand h1 {
		font-size: 1.7rem;
	}

	/* App Layout */
	.app {
		padding: 0;
		gap: 0;
		height: 100dvh;
		max-width: 100%;
	}

	.header {
		border-radius: 0;
		border-left: none;
		border-right: none;
		border-top: none;
		padding: 8px 10px;
		gap: 4px;
	}

	.header h1 {
		font-size: 1rem;
		margin: 0;
	}

	#page-subtitle {
		display: none;
	}

	.agent-header-copy {
		font-size: 0.78rem;
		margin: 2px 0 0;
		line-height: 1.3;
	}

	.header-copy {
		min-width: 0;
		flex-shrink: 1;
	}

	.header-actions {
		flex-wrap: wrap;
		gap: 3px;
		justify-content: flex-end;
	}

	.header-actions button {
		font-size: 0.7rem;
		padding: 4px 7px;
		line-height: 1.2;
	}

	/* Chat - compact */
	.chat {
		border-radius: 0;
		border-left: none;
		border-right: none;
		border-bottom: none;
		padding: 4px 8px;
		padding-bottom: calc(4px + var(--safe-bottom));
	}

	.bubble {
		max-width: 95%;
		padding: 1px 5px;
		font-size: 0.9rem;
		line-height: 1.25;
		border-radius: 5px;
		border-width: 0.5px;
	}

	.bubble .meta {
		display: none;
	}

	.thread {
		gap: 2px;
		padding-bottom: 2px;
	}

	/* Chat Form */
	.chat-form {
		gap: 6px;
		position: sticky;
		bottom: 0;
		background: var(--panel);
		padding: 6px 0 0;
	}

	.composer-toolbar {
		gap: 2px;
	}

	.icon-btn {
		padding: 2px 6px;
		font-size: 1rem;
	}

	#chat-form textarea {
		max-height: 60px;
		padding: 6px 8px;
		font-size: 0.85rem;
		border-radius: 8px;
	}

	#chat-form button.primary {
		padding: 6px 10px;
		font-size: 0.85rem;
	}

	.toast {
		bottom: calc(72px + env(safe-area-inset-bottom, 0px));
	}

	/* Starters */
	.starter-area {
		padding: 6px 8px;
		margin-bottom: 4px;
	}

	.starter-label {
		font-size: 0.75rem;
		margin-bottom: 4px;
	}

	.starter-chip {
		padding: 4px 8px;
		font-size: 0.75rem;
	}

	.starter-chips {
		gap: 4px;
	}

	/* Quiz Overlay */
	.persona-quiz {
		padding: 12px;
		align-items: flex-end;
	}

	.quiz-card {
		width: 100%;
		max-height: 92dvh;
		border-radius: 16px 16px 0 0;
		padding: 18px 16px 16px;
		margin-bottom: 0;
	}

	.quiz-card h2 {
		font-size: 1.15rem;
	}

	.quiz-subtitle {
		font-size: 0.88rem;
	}

	.quiz-option {
		padding: 10px 12px;
	}

	.quiz-option strong {
		font-size: 0.93rem;
	}

	.quiz-option span {
		font-size: 0.83rem;
	}

	.quiz-actions {
		flex-direction: column;
		gap: 8px;
		margin-top: 14px;
	}

	.quiz-actions button {
		width: 100%;
	}

	/* Insights Panel */
	.insights-panel {
		grid-template-columns: 1fr;
		grid-template-rows: auto 1fr;
	}

	.insights-backdrop {
		min-height: 72px;
	}

	.insights-drawer {
		width: 100%;
		height: auto;
		max-height: calc(100dvh - 72px);
		border-left: none;
		border-top: 1px solid var(--border);
		border-radius: 16px 16px 0 0;
	}
}

/* Extra small phones */
@media (max-width: 380px) {
	.header-actions button {
		font-size: 0.72rem;
		padding: 5px 8px;
	}

	.bubble {
		max-width: 92%;
		font-size: 0.9rem;
		padding: 8px 10px;
	}

	.auth-card {
		padding: 20px 16px 20px;
	}
}

/* Desktop-only elements */
.desktop-only {
	display: inline-block;
}

.download-apk-btn {
	background: transparent;
	color: var(--muted);
	border: 1px solid var(--border);
	font-size: 0.85rem;
	padding: 6px 10px;
	border-radius: 999px;
	text-decoration: none;
	cursor: pointer;
	font: inherit;
	line-height: 1.2;
}

.download-apk-btn:hover {
	background: var(--accent-soft);
	color: var(--text);
}

/* Hide APK download link on mobile / tablet */
@media (max-width: 820px) {
	.auth-apk-link {
		display: none;
	}

	.desktop-only {
		display: none;
	}
}

/* Image preview strip */
.image-preview-area {
	display: none;
	padding: 8px 8px 4px;
	gap: 6px;
	flex-wrap: wrap;
}

.image-preview-area.has-images {
	display: flex;
}

.preview-thumb {
	position: relative;
	width: 60px;
	height: 60px;
	border-radius: 8px;
	overflow: hidden;
	border: 1px solid var(--border);
}

.preview-thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.preview-remove {
	position: absolute;
	top: -4px;
	right: -4px;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	border: none;
	background: #c0392b;
	color: #fff;
	font-size: 10px;
	line-height: 1;
	cursor: pointer;
	padding: 0;
	display: flex;
	align-items: center;
	justify-content: center;
}

/* Avatar */
.header-title-row {
	display: flex;
	align-items: center;
	gap: 10px;
}

.avatar-wrap {
	position: relative;
	flex-shrink: 0;
}

.avatar-img {
	display: block;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	overflow: hidden;
	cursor: pointer;
	background: var(--accent-soft);
	font-size: 20px;
	line-height: 40px;
	text-align: center;
	border: 2px solid var(--accent);
	transition: opacity 0.15s;
}

.avatar-img:hover {
	opacity: 0.8;
}

.avatar-img img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}
