:root {
	color-scheme: light;
	--ink: #1f1c16;
	--ink-soft: #3a342c;
	--paper: #f6f0e6;
	--paper-strong: #fff7ef;
	--accent: #2c7a5f;
	--accent-strong: #1d5b46;
	--accent-warm: #e07b2f;
	--border: rgba(31, 28, 22, 0.16);
	--shadow: 0 18px 40px rgba(31, 28, 22, 0.12);
}

* {
	box-sizing: border-box;
}

.hidden {
	display: none !important;
}

body {
	margin: 0;
	font-family: "Bricolage Grotesque", "Space Grotesk", sans-serif;
	color: var(--ink);
	background: radial-gradient(circle at 15% 20%, #fdf7ef 0%, transparent 50%),
		radial-gradient(circle at 85% 10%, #ffe8d3 0%, transparent 45%),
		radial-gradient(circle at 70% 85%, #dbeee4 0%, transparent 55%),
		var(--paper);
	min-height: 100vh;
	position: relative;
	overflow-x: hidden;
}

body::before,
body::after {
	content: "";
	position: fixed;
	width: 42vw;
	height: 42vw;
	border-radius: 40% 60% 45% 55%;
	filter: blur(10px);
	opacity: 0.5;
	z-index: 0;
	animation: float 18s ease-in-out infinite;
}

body::before {
	background: radial-gradient(circle at 30% 30%, #ffe2c4, transparent 70%);
	top: -12vw;
	left: -8vw;
}

body::after {
	background: radial-gradient(circle at 70% 70%, #cde8d7, transparent 70%);
	bottom: -18vw;
	right: -8vw;
	animation-delay: 3s;
}

.grain {
	position: fixed;
	inset: 0;
	background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="120" height="120" viewBox="0 0 120 120"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.8" numOctaves="3" stitchTiles="stitch"/></filter><rect width="120" height="120" filter="url(%23n)" opacity="0.18"/></svg>');
	mix-blend-mode: soft-light;
	pointer-events: none;
	z-index: 1;
}

.page {
	position: relative;
	z-index: 2;
	max-width: 1200px;
	margin: 0 auto;
	padding: 48px 24px 80px;
	display: flex;
	flex-direction: column;
	gap: 24px;
}

.hero {
	display: grid;
	grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
	gap: 24px;
	align-items: stretch;
}

.eyebrow {
	text-transform: uppercase;
	letter-spacing: 0.24em;
	font-size: 0.7rem;
	color: var(--accent-strong);
	margin: 0 0 12px;
}

h1 {
	font-size: clamp(2.4rem, 4vw, 3.6rem);
	margin: 0 0 12px;
}

.lede {
	font-size: 1rem;
	line-height: 1.6;
	color: var(--ink-soft);
	max-width: 36rem;
}

.card {
	background: var(--paper-strong);
	border: 1px solid var(--border);
	border-radius: 20px;
	box-shadow: var(--shadow);
	padding: 20px;
	backdrop-filter: blur(6px);
}

.section-title {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-bottom: 16px;
}

h2 {
	margin: 0;
	font-size: 1.3rem;
}

h3 {
	margin: 0 0 8px;
	font-size: 1rem;
}

.muted {
	color: var(--ink-soft);
	font-size: 0.92rem;
}

.row {
	display: flex;
	flex-wrap: wrap;
	gap: 12px;
	align-items: center;
}

input {
	flex: 1 1 240px;
	padding: 12px 14px;
	border-radius: 12px;
	border: 1px solid var(--border);
	font-size: 0.95rem;
	background: #fff;
}

.btn {
	border: none;
	border-radius: 999px;
	padding: 10px 18px;
	font-weight: 600;
	cursor: pointer;
	transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
	font-family: "Bricolage Grotesque", "Space Grotesk", sans-serif;
}

.btn.primary {
	background: var(--accent);
	color: #fff;
	box-shadow: 0 10px 24px rgba(44, 122, 95, 0.3);
}

.btn.primary:hover {
	background: var(--accent-strong);
	transform: translateY(-1px);
}

.btn.ghost {
	background: transparent;
	color: var(--ink-soft);
	border: 1px dashed var(--border);
}

.btn.ghost:hover {
	border-color: var(--ink-soft);
	transform: translateY(-1px);
}

.btn.btn-danger {
	color: #b42318;
	border-color: rgba(180, 35, 24, 0.35);
}

.btn.btn-danger:hover {
	background: rgba(180, 35, 24, 0.08);
	border-color: #b42318;
	color: #991b1b;
}

.grid {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 24px;
}

.instance-list {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.instance-card {
	border: 1px solid var(--border);
	border-radius: 16px;
	padding: 12px 14px;
	background: #fff;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.instance-card.selected {
	border-color: var(--accent);
	box-shadow: 0 10px 22px rgba(44, 122, 95, 0.2);
}

.instance-meta {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 12px;
}

.status-pill {
	padding: 6px 12px;
	border-radius: 999px;
	background: rgba(44, 122, 95, 0.12);
	color: var(--accent-strong);
	font-size: 0.8rem;
	font-weight: 600;
}

.status-pill.muted {
	background: rgba(31, 28, 22, 0.1);
	color: var(--ink-soft);
}

.status-pill.warning {
	background: rgba(224, 123, 47, 0.15);
	color: var(--accent-warm);
}

.qr-panel {
	display: grid;
	grid-template-columns: 240px minmax(0, 1fr);
	gap: 16px;
	align-items: center;
}

.qr-box {
	position: relative;
	width: 240px;
	height: 240px;
	border-radius: 18px;
	border: 1px dashed var(--border);
	background: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
}

#qrCanvas {
	width: 220px;
	height: 220px;
}

.qr-fallback {
	position: absolute;
	text-align: center;
	padding: 16px;
	font-size: 0.85rem;
	color: var(--ink-soft);
}

/* Connected state styles */
.qr-box.connected {
	border: 2px solid var(--accent);
	background: linear-gradient(135deg, rgba(44, 122, 95, 0.08) 0%, rgba(44, 122, 95, 0.02) 100%);
	animation: connectedPulse 2s ease-in-out infinite;
}

.qr-connected {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	animation: fadeIn 0.4s ease-out;
}

.qr-connected-icon {
	width: 80px;
	height: 80px;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 8px 24px rgba(44, 122, 95, 0.35);
	animation: scaleIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.qr-connected-icon svg {
	width: 44px;
	height: 44px;
	stroke: white;
	stroke-width: 3;
	fill: none;
	animation: checkDraw 0.6s ease-out 0.2s both;
}

.qr-connected-text {
	font-size: 1.1rem;
	font-weight: 700;
	color: var(--accent-strong);
	letter-spacing: 0.02em;
}

.qr-connected-subtitle {
	font-size: 0.8rem;
	color: var(--ink-soft);
	margin-top: -4px;
}

@keyframes connectedPulse {
	0%, 100% {
		box-shadow: 0 0 0 0 rgba(44, 122, 95, 0.2);
	}
	50% {
		box-shadow: 0 0 0 8px rgba(44, 122, 95, 0);
	}
}

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

@keyframes scaleIn {
	from {
		transform: scale(0);
		opacity: 0;
	}
	to {
		transform: scale(1);
		opacity: 1;
	}
}

@keyframes checkDraw {
	from {
		stroke-dasharray: 100;
		stroke-dashoffset: 100;
	}
	to {
		stroke-dasharray: 100;
		stroke-dashoffset: 0;
	}
}

.status-stack {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.status-stack .row input {
	max-width: 120px;
}

/* Sync progress bar */
.sync-progress {
	display: flex;
	align-items: center;
	gap: 10px;
}

.sync-progress-bar {
	flex: 1;
	height: 8px;
	background: rgba(31, 28, 22, 0.1);
	border-radius: 4px;
	overflow: hidden;
}

.sync-progress-fill {
	height: 100%;
	background: linear-gradient(90deg, var(--accent) 0%, var(--accent-strong) 100%);
	border-radius: 4px;
	transition: width 0.3s ease;
	width: 0%;
}

.sync-progress-fill.complete {
	background: linear-gradient(90deg, #22c55e 0%, #16a34a 100%);
}

.sync-progress-fill.partial {
	background: linear-gradient(90deg, var(--accent-warm) 0%, #c2410c 100%);
}

#syncProgressText {
	font-size: 0.8rem;
	font-weight: 600;
	min-width: 40px;
	text-align: right;
}

.sync-details {
	font-size: 0.75rem;
	line-height: 1.5;
}

/* Sync status pills */
.status-pill.sync-complete {
	background: rgba(34, 197, 94, 0.15);
	color: #16a34a;
}

.status-pill.sync-partial {
	background: rgba(224, 123, 47, 0.15);
	color: var(--accent-warm);
}

.status-pill.sync-syncing {
	background: rgba(59, 130, 246, 0.15);
	color: #2563eb;
	animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.6; }
}

.history-controls {
	align-items: center;
}

.history-controls label {
	font-size: 0.8rem;
	color: var(--ink-soft);
}

.preview-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
	gap: 16px;
}

pre {
	background: #161514;
	color: #f5f1ea;
	border-radius: 14px;
	padding: 14px;
	min-height: 120px;
	font-size: 0.8rem;
	font-family: "Space Mono", "Bricolage Grotesque", monospace;
	white-space: pre-wrap;
}

.footer-note {
	text-align: center;
	font-size: 0.9rem;
	color: var(--ink-soft);
}

.footer-note {
	margin-top: 24px;
}

#systemMessage {
	position: fixed;
	top: 16px;
	right: 16px;
	max-width: 360px;
	padding: 10px 14px;
	border-radius: 12px;
	border: 1px solid var(--border);
	background: rgba(255, 255, 255, 0.92);
	box-shadow: var(--shadow);
	backdrop-filter: blur(6px);
	z-index: 20;
	display: inline-flex;
	gap: 10px;
	align-items: center;
	font-weight: 600;
}

#systemMessage.is-info {
	color: var(--accent-strong);
	background: rgba(227, 246, 238, 0.95);
}

#systemMessage.is-warning {
	color: #b42318;
	background: rgba(255, 229, 224, 0.95);
	border-color: rgba(180, 35, 24, 0.35);
}

.toast-icon {
	width: 28px;
	height: 28px;
	border-radius: 999px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-weight: 700;
	font-size: 0.95rem;
	background: rgba(44, 122, 95, 0.12);
	color: var(--accent-strong);
}

#systemMessage.is-warning .toast-icon {
	background: rgba(180, 35, 24, 0.15);
	color: #b42318;
}

.toast-icon::before {
	content: 'i';
}

#systemMessage.is-warning .toast-icon::before {
	content: '!';
}

#systemMessage.hidden {
	display: none;
}

.stagger {
	animation: fadeUp 0.6s ease both;
}

.stagger:nth-of-type(2) {
	animation-delay: 0.1s;
}

.stagger:nth-of-type(3) {
	animation-delay: 0.2s;
}

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

@keyframes float {
	0%,
	100% {
		transform: translateY(0px) translateX(0px);
	}
	50% {
		transform: translateY(16px) translateX(-12px);
	}
}

@media (max-width: 980px) {
	.hero {
		grid-template-columns: 1fr;
	}

	.grid {
		grid-template-columns: 1fr;
	}

	.qr-panel {
		grid-template-columns: 1fr;
	}

	.qr-box {
		width: 100%;
		height: auto;
		aspect-ratio: 1 / 1;
	}
}

@media (prefers-reduced-motion: reduce) {
	* {
		animation: none !important;
		transition: none !important;
	}
}
