:root {
	--bg: #0f172a;
	--surface: #1e293b;
	--text: #f8fafc;
	--muted: #94a3b8;
	--primary: #2563eb;
	--primary-dark: #1d4ed8;
	--secondary: #475569;
	--admit: #16a34a;
	--deny: #dc2626;
	--retry: #d97706;
	--guide: rgba(255, 255, 255, 0.95);
	--shadow: rgba(15, 23, 42, 0.35);
	--screen-pad-x: clamp(12px, 3vw, 24px);
	--screen-pad-y: clamp(8px, 2vh, 20px);
	--screen-gap: clamp(8px, 1.5vh, 16px);
}

* {
	box-sizing: border-box;
}

html {
	height: 100%;
	height: 100dvh;
}

body {
	height: 100%;
	height: 100dvh;
	margin: 0;
	font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
	background: var(--bg);
	color: var(--text);
	overflow: hidden;
}

.hidden {
	display: none !important;
}

.app {
	height: 100%;
	height: 100dvh;
	max-height: 100dvh;
	overflow: hidden;
}

.screen {
	display: none;
	height: 100%;
	max-height: 100dvh;
	padding:
		max(var(--screen-pad-y), env(safe-area-inset-top))
		max(var(--screen-pad-x), env(safe-area-inset-right))
		max(var(--screen-pad-y), env(safe-area-inset-bottom))
		max(var(--screen-pad-x), env(safe-area-inset-left));
	gap: var(--screen-gap);
	overflow: hidden;
}

.screen.active {
	display: flex;
	flex-direction: column;
	align-items: center;
	position: fixed;
	inset: 0;
	width: 100%;
	height: 100%;
	height: 100dvh;
	z-index: 1;
}

.screen-header {
	flex-shrink: 0;
	text-align: center;
	max-width: 640px;
}

.screen-header h1 {
	margin: 0 0 4px;
	font-size: clamp(1.25rem, 3.5vh, 2rem);
	line-height: 1.2;
}

.screen-header p {
	margin: 0;
	color: var(--muted);
	font-size: clamp(0.875rem, 2vh, 1.125rem);
	line-height: 1.35;
}

.screen-capture.active {
	justify-content: stretch;
}

.screen-capture .screen-header,
.screen-capture .btn,
.screen-capture .error-message {
	flex-shrink: 0;
}

.camera-wrap {
	position: relative;
	flex: 1 1 auto;
	width: min(100%, 640px);
	min-height: 0;
	max-height: 100%;
	margin: 0 auto;
	border-radius: clamp(12px, 2vh, 20px);
	overflow: hidden;
	background: #000;
	box-shadow: 0 12px 32px var(--shadow);
}

#video {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.guide-overlay {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: flex-start;
	justify-content: center;
	padding-top: 18%;
	pointer-events: none;
}

.guide-frame {
	width: 82%;
	height: 52%;
	border: 3px solid var(--guide);
	border-radius: 12px;
	box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
}

.btn {
	flex-shrink: 0;
	min-height: clamp(48px, 7vh, 56px);
	min-width: 140px;
	padding: clamp(10px, 1.5vh, 16px) clamp(20px, 4vw, 28px);
	border: 0;
	border-radius: 14px;
	font-size: clamp(1rem, 2.2vh, 1.125rem);
	font-weight: 700;
	cursor: pointer;
	transition: transform 0.15s ease, background 0.15s ease;
}

.btn:active {
	transform: scale(0.98);
}

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

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

.btn-primary:hover:not(:disabled) {
	background: var(--primary-dark);
}

.btn-secondary {
	background: var(--secondary);
	color: white;
}

.screen-code.active {
	justify-content: stretch;
	width: 100%;
}

.screen-code .screen-header,
.screen-code .code-display,
.screen-code .code-actions {
	flex-shrink: 0;
	width: 100%;
	max-width: 480px;
}

.screen-code .code-body {
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	justify-content: center;
	width: 100%;
	max-width: 480px;
	min-height: 0;
	gap: var(--screen-gap);
}

.code-display {
	font-size: clamp(1.75rem, 6vh, 2.75rem);
	font-weight: 700;
	letter-spacing: 0.3em;
	padding: clamp(14px, 2.5vh, 24px) clamp(16px, 4vw, 28px);
	background: var(--surface);
	border-radius: 16px;
	width: 100%;
	text-align: center;
}

.keypad {
	flex: 1 1 auto;
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	grid-template-rows: repeat(4, 1fr);
	gap: clamp(8px, 1.2vh, 12px);
	width: 100%;
	min-height: 0;
	margin: 0;
}

.key {
	min-height: clamp(52px, 10vh, 88px);
	border: 0;
	border-radius: 12px;
	background: var(--surface);
	color: var(--text);
	font-size: clamp(1.25rem, 3.5vh, 1.75rem);
	font-weight: 700;
	cursor: pointer;
}

.key-action {
	font-size: clamp(0.875rem, 2vh, 1rem);
}

.key:active {
	background: #334155;
}

.code-actions {
	display: flex;
	gap: 10px;
	justify-content: center;
	width: 100%;
	flex-shrink: 0;
}

.code-actions .btn {
	flex: 1 1 0;
}

.screen-processing {
	justify-content: center;
	gap: 12px;
}

.spinner {
	width: clamp(56px, 10vh, 72px);
	height: clamp(56px, 10vh, 72px);
	border: 5px solid rgba(255, 255, 255, 0.15);
	border-top-color: white;
	border-radius: 50%;
	animation: spin 0.9s linear infinite;
}

.processing-text {
	font-size: clamp(1.125rem, 3vh, 1.5rem);
	color: var(--muted);
	margin: 0;
}

.screen-result {
	justify-content: center;
	text-align: center;
	padding-inline: 20px;
}

.result-icon {
	width: clamp(80px, 14vh, 120px);
	height: clamp(80px, 14vh, 120px);
	border-radius: 50%;
	display: grid;
	place-items: center;
	font-size: clamp(2.5rem, 8vh, 4rem);
	font-weight: 700;
	margin-bottom: 8px;
	flex-shrink: 0;
}

.result-title {
	margin: 0;
	font-size: clamp(2rem, 7vh, 3.5rem);
	line-height: 1.1;
}

.result-message {
	margin: 8px 0 0;
	max-width: 560px;
	font-size: clamp(1rem, 2.5vh, 1.375rem);
	line-height: 1.4;
	color: var(--muted);
}

.screen-result.result-admit {
	background: linear-gradient(180deg, #14532d 0%, #052e16 100%);
}

.screen-result.result-admit .result-icon {
	background: rgba(255, 255, 255, 0.15);
	color: white;
}

.screen-result.result-admit .result-message {
	color: #dcfce7;
}

.screen-result.result-deny {
	background: linear-gradient(180deg, #7f1d1d 0%, #450a0a 100%);
}

.screen-result.result-deny .result-icon {
	background: rgba(255, 255, 255, 0.15);
	color: white;
}

.screen-result.result-deny .result-message {
	color: #fecaca;
}

.screen-result.result-already-checked {
	background: linear-gradient(180deg, #1e3a5f 0%, #0f172a 100%);
}

.screen-result.result-already-checked .result-icon {
	background: rgba(255, 255, 255, 0.15);
	color: white;
}

.screen-result.result-already-checked .result-message {
	color: #bfdbfe;
}

.screen-result.result-retry {
	background: linear-gradient(180deg, #78350f 0%, #451a03 100%);
}

.screen-result.result-retry .result-icon {
	background: rgba(255, 255, 255, 0.15);
	color: white;
}

.screen-result.result-retry .result-message {
	color: #fde68a;
}

.error-message {
	flex-shrink: 0;
	color: #fca5a5;
	text-align: center;
	max-width: 560px;
	font-size: clamp(0.875rem, 2vh, 1rem);
	line-height: 1.4;
	margin: 0;
}

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

@media (max-height: 600px) {
	.screen-header p {
		display: none;
	}
}
