:root {
  --bg: #0b0d12;
  --surface: #141820;
  --surface-2: #1c212b;
  --border: #2a3140;
  --text: #f3f5f9;
  --text-muted: #8b95a8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.app {
  max-width: 440px;
  margin: 0 auto;
  min-height: 100%;
  padding: 20px 18px calc(28px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Header */
.header {
  text-align: center;
  padding-top: 6px;
}

.logo {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin-top: 4px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Camera stage */
.stage {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

#video,
#snapshot,
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#overlay {
  pointer-events: none;
}

.viewport-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  background: var(--surface);
}

.placeholder-icon {
  font-size: 2.4rem;
  opacity: 0.7;
}

.viewport-placeholder p {
  font-size: 0.95rem;
}

.status-bar {
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
  min-height: 1.3em;
}

/* Buttons */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  padding: 15px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

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

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

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

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #252b38;
}

.btn.full {
  grid-column: 1 / -1;
}

/* Result */
.result {
  animation: fadeUp 0.3s ease;
}

.result[hidden] {
  display: none !important;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.result-portrait-wrap {
  flex-shrink: 0;
  width: 84px;
  height: 84px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface-2);
}

#result-portrait {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.result-body {
  flex: 1;
  min-width: 0;
}

#result-name {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.confidence {
  font-size: 0.98rem;
  font-weight: 600;
}

.confidence.high { color: var(--success); }
.confidence.medium { color: var(--warning); }
.confidence.low { color: var(--danger); }

.meta {
  margin-top: 3px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Footer */
.footer {
  margin-top: auto;
  padding-top: 8px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Animations */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Small phones */
@media (max-width: 360px) {
  .app {
    padding: 14px 12px calc(22px + var(--safe-bottom));
  }
  .actions {
    grid-template-columns: 1fr;
  }
}
