:root {
	--bg: #0b0d12;
	--panel: #161a22;
	--line: #262c38;
	--text: #e9e6e1;
	--muted: #8d93a0;
	--accent: #f2b56b;
	--ok: #5bd68a;
	--warn: #f2c94c;
	--bad: #ff5c5c;
	color-scheme: dark;
}

* {
	box-sizing: border-box;
}

html,
body {
	margin: 0;
	height: 100%;
	background: var(--bg);
	color: var(--text);
	font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
	-webkit-tap-highlight-color: transparent;
	-webkit-text-size-adjust: 100%;
}

main {
	max-width: 520px;
	margin: 0 auto;
	padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

h1 {
	font-size: 28px;
	margin: 8px 0 4px;
	letter-spacing: -0.02em;
}

h1 span {
	color: var(--accent);
}

p {
	margin: 8px 0;
}

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

[hidden] {
	display: none !important;
}

/* Go dark: black behind everything, so the browser's top bar can follow. */
html.dark,
html.dark body {
	background: #000;
}

button {
	font: inherit;
	color: var(--text);
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 12px;
	padding: 12px 16px;
	min-height: 48px;
	cursor: pointer;
}

button:active {
	transform: scale(0.98);
}

button:disabled {
	opacity: 0.5;
}

button.big {
	width: 100%;
	font-size: 20px;
	font-weight: 600;
	padding: 18px;
	margin: 16px 0;
	background: var(--accent);
	color: #1a1205;
	border: 0;
}

button.on {
	border-color: var(--accent);
	color: var(--accent);
}

.row {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin: 12px 0;
}

.row > button {
	flex: 1 1 0;
	min-width: 0;
}

/* Start screens: just the essentials, vertically centred. */
main.center {
	min-height: 100vh;
	min-height: 100dvh;
	display: flex;
	flex-direction: column;
	justify-content: center;
}

.tips {
	color: var(--muted);
	font-size: 15px;
}

.tips summary {
	display: inline-block;
	padding: 8px 0;
	cursor: pointer;
	list-style: none;
	text-decoration: underline;
	text-underline-offset: 3px;
}

.tips summary::-webkit-details-marker {
	display: none;
}

.tips ul {
	margin: 4px 0 0;
	padding-left: 18px;
	display: grid;
	gap: 8px;
}

.status {
	display: flex;
	align-items: center;
	gap: 10px;
	font-size: 18px;
	font-weight: 600;
	margin: 12px 0;
}

.dot {
	width: 12px;
	height: 12px;
	flex: none;
	border-radius: 50%;
	background: var(--muted);
}

.dot.ok {
	background: var(--ok);
	box-shadow: 0 0 10px var(--ok);
}

.dot.warn {
	background: var(--warn);
}

.dot.bad {
	background: var(--bad);
}

.warning {
	background: #2a1f0c;
	border: 1px solid #5c4214;
	color: var(--warn);
	border-radius: 12px;
	padding: 10px 12px;
	margin: 8px 0;
	font-size: 15px;
}

.warning.bad {
	background: #2b1012;
	border-color: #6b1f24;
	color: #ff9a9a;
}

.error {
	color: #ff9a9a;
}

.debug {
	font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
	color: var(--muted);
}

video {
	display: block;
	width: 100%;
	background: #000;
	border-radius: 12px;
}

/* Fixed-size box: a flip to a camera with a different shape mustn't move the layout. */
.preview {
	position: relative;
}

.preview video {
	height: min(50vh, 420px);
	object-fit: contain;
}

/* Round translucent button over the preview, like the camera-flip button in iOS Camera. */
.icon-btn {
	position: absolute;
	right: 10px;
	bottom: 10px;
	width: 44px;
	height: 44px;
	min-height: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	display: grid;
	place-items: center;
	color: #fff;
	background: rgba(0, 0, 0, 0.45);
	-webkit-backdrop-filter: blur(8px);
	backdrop-filter: blur(8px);
}

/* Compact sheet at the bottom with a light backdrop, so the video stays visible above it. */
dialog {
	width: min(100vw - 32px, 380px);
	margin: auto auto max(16px, env(safe-area-inset-bottom));
	padding: 0;
	border: 1px solid var(--line);
	border-radius: 16px;
	background: var(--panel);
	color: var(--text);
}

dialog::backdrop {
	background: rgba(0, 0, 0, 0.3);
}

.dialog-body {
	padding: 10px 10px 14px 16px;
}

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

.dialog-head p {
	margin: 0;
	font-weight: 600;
}

.close-btn {
	flex: none;
	width: 32px;
	height: 32px;
	min-height: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	display: grid;
	place-items: center;
	background: var(--line);
	color: var(--text);
}

.pair {
	display: flex;
	gap: 12px;
	padding-right: 6px;
}

.pair-actions {
	flex: 1;
	display: flex;
	flex-direction: column;
	justify-content: center;
	gap: 8px;
}

.link-field {
	display: block;
	width: calc(100% - 6px);
	margin-top: 10px;
	padding: 10px 12px;
	border: 1px solid var(--line);
	border-radius: 10px;
	background: var(--bg);
	color: var(--muted);
	font: 16px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; /* 16px: iOS zooms in on smaller fields */
	text-overflow: ellipsis;
}

#qr {
	flex: none;
	width: 132px;
	padding: 8px;
	border-radius: 10px;
	background: #fff;
}

#qr svg {
	display: block;
	width: 100%;
	height: auto;
}

/* Full-screen black layer: keeps the room dark, tap to leave. */
.night {
	position: fixed;
	inset: 0;
	background: #000;
	z-index: 10;
}

.night .whisper {
	position: absolute;
	color: #fff;
	opacity: 0.22;
	font-size: 14px;
	max-width: 70%;
	transition: top 2s, left 2s;
}

/* Sound meter: ten LEDs, like a hardware baby monitor. */
.meter {
	display: flex;
	gap: 4px;
	height: 18px;
	align-items: stretch;
}

.meter i {
	flex: 1;
	border-radius: 3px;
	background: #20252f;
}

.meter i.lit {
	background: var(--ok);
}

.meter i.lit:nth-child(n + 6) {
	background: var(--warn);
}

.meter i.lit:nth-child(n + 9) {
	background: var(--bad);
}

.alarm {
	position: fixed;
	inset: 0;
	z-index: 30;
	background: #8b0f16;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
	padding: 24px;
	gap: 12px;
	animation: pulse 1s infinite alternate;
}

.alarm h2 {
	font-size: 28px;
	margin: 0;
}

@keyframes pulse {
	to {
		background: #c3141f;
	}
}
