:root {
  --bg: #0b0d12;
  --surface: #151923;
  --surface-2: #1d2330;
  --text: #f2f4f8;
  --muted: #8a93a6;
  --primary: #3b82f6;
  --primary-press: #2563eb;
  --success: #22c55e;
  --error: #ef4444;
  --warn: #f59e0b;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh; /* fallback */
}

.header {
  padding: calc(12px + var(--safe-top)) 16px 12px;
  text-align: center;
  flex: 0 0 auto;
}

.header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* ---------- Camera preview ---------- */
.preview {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 12px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

#video,
#snapshot {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 13, 18, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.overlay-inner {
  text-align: center;
  max-width: 320px;
}

.overlay-icon {
  font-size: 40px;
  margin: 0 0 8px;
  color: var(--warn);
}

.overlay-msg {
  margin: 0 0 20px;
  color: var(--text);
  line-height: 1.45;
}

/* ---------- Controls ---------- */
.controls {
  flex: 0 0 auto;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
  min-height: 20px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}

.status[data-state="ready"] .status-dot { background: var(--success); }
.status[data-state="uploading"] .status-dot,
.status[data-state="processing"] .status-dot {
  background: var(--primary);
  animation: pulse 1s ease-in-out infinite;
}
.status[data-state="success"] .status-dot { background: var(--success); }
.status[data-state="error"] .status-dot { background: var(--error); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

/* Scrollable log of capture results — newest pushed to the bottom. */
.result {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 32vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px;
}

/* Each capture appends one card into the scroll container. */
.result .result-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.5;
}

/* Capture time, shown above the result content. */
.result .result-card-time {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  padding-right: 28px;
}

/* Leave room for the delete button in the top-right corner. */
.result .result-card-body {
  padding-right: 28px;
}

.result .result-card-del {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.result .result-card-del:active {
  background: var(--surface-2);
  color: var(--text);
}

.result .result-card.success { border-color: rgba(34, 197, 94, 0.4); }
.result .result-card.error { border-color: rgba(239, 68, 68, 0.4); }
.result .result-card.pending { border-color: rgba(59, 130, 246, 0.4); }

.result .result-title {
  font-weight: 600;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.result .result-row {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
}
.result .result-row strong { color: var(--text); font-weight: 500; }

.actions {
  display: flex;
  gap: 10px;
}

.btn {
  flex: 1;
  border: none;
  border-radius: 14px;
  padding: 16px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.05s ease;
  min-height: 56px; /* large touch target */
}

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

.btn-primary { background: var(--primary); }
.btn-primary:active { background: var(--primary-press); }
.btn-primary:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
  transform: none;
}

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

/* DEBUG: on-screen error output for a failed capture. */
.debug {
  margin-top: 10px;
  padding: 10px 12px;
  background: #000;
  color: #9be29b;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  border-radius: 8px;
  max-height: 40vh;
  overflow: auto;
}

[hidden] { display: none !important; }
