:root {
  --bg: #0f172a;
  --bg-soft: #111a2f;
  --panel: #1b2540;
  --panel-2: #243055;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --brand: #22c55e;
  --brand-2: #16a34a;
  --warn: #f59e0b;
  --danger: #ef4444;
  --accent: #38bdf8;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 6px 18px rgba(0,0,0,.35);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}
#app { height: 100dvh; width: 100vw; position: relative; }

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; }

.top-bar {
  padding: calc(18px + var(--safe-top)) 18px 12px;
  background: linear-gradient(180deg, #0b1326 0%, var(--bg) 100%);
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.top-bar h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: .2px; }
.top-bar .sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.pad { padding: 18px 18px calc(32px + var(--safe-bot)); }
.center { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-top: 30px; }

/* Forms */
.field { display: block; margin-bottom: 16px; }
.field .label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 14px 14px;
  font-size: 16px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.06);
  border-radius: var(--radius-sm);
  outline: none;
}
.field input:focus { border-color: var(--accent); }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 6px; display: block; }

/* Buttons */
.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text);
  transition: transform .05s ease, background .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; display: block; margin-top: 12px; }
.btn.primary { background: var(--brand); color: #07210f; }
.btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,.14); }
.btn.sm { padding: 8px 12px; font-size: 13px; }

/* Cards */
.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px;
  margin: 10px 0 16px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 8px; font-size: 16px; }
.check-list { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.check-list li { margin: 4px 0; }

.consent-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border-radius: var(--radius-sm);
  padding: 14px; margin: 14px 0;
}
.consent-row input { width: 18px; height: 18px; accent-color: var(--brand); }

.foot { color: var(--muted); font-size: 12px; margin-top: 14px; text-align: center; }

/* --- Camera screen --- */
.camera-wrap {
  position: relative;
  width: 100%; height: 100%;
  background: #000;
  overflow: hidden;
}
#camVideo, #camOverlay {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
#camOverlay { pointer-events: none; }

.cam-topbar {
  position: absolute; top: calc(14px + var(--safe-top)); left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 14px; gap: 8px;
  z-index: 3;
}
.pill {
  display: inline-block;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  color: #fff;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(255,255,255,.1);
}
.pill.small { font-size: 12px; padding: 6px 10px; }
.pill.ok { background: rgba(34,197,94,.85); }
.pill.bad { background: rgba(239,68,68,.75); }

.cam-instruction {
  position: absolute; left: 14px; right: 14px;
  bottom: calc(130px + var(--safe-bot));
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  padding: 12px 14px;
  border-radius: var(--radius);
  z-index: 3;
}
.cam-instruction .prompt { font-weight: 600; font-size: 15px; }
.cam-instruction .hint { font-size: 12px; color: #c7d2fe; margin-top: 4px; }

.cam-controls {
  position: absolute; left: 0; right: 0;
  bottom: calc(18px + var(--safe-bot));
  display: flex; align-items: center; justify-content: space-around;
  padding: 0 18px;
  z-index: 3;
}
.btn.capture {
  width: 78px; height: 78px;
  border-radius: 50%;
  background: #fff;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 4px rgba(255,255,255,.2);
}
.btn.capture .cap-ring {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--brand);
}
.btn.capture.auto .cap-ring { background: var(--warn); }

.flash {
  position: absolute; inset: 0;
  background: #fff; opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease;
  z-index: 4;
}
.flash.active { opacity: .85; }

/* --- Processing --- */
.spinner {
  width: 42px; height: 42px;
  border: 4px solid rgba(255,255,255,.15);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.bar { width: 100%; height: 8px; background: var(--panel); border-radius: 999px; overflow: hidden; margin-top: 16px; }
.bar-fill { height: 100%; width: 0%; background: var(--brand); transition: width .3s ease; }

/* --- Results --- */
.tabs { display: flex; gap: 4px; background: var(--panel); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 12px; }
.tab {
  flex: 1; text-align: center; padding: 10px 6px;
  font-size: 13px; font-weight: 600; color: var(--muted);
  border-radius: 8px; cursor: pointer;
  background: transparent; border: none;
}
.tab.active { background: var(--panel-2); color: var(--text); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.stat-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px;
}
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat .v { font-size: 20px; font-weight: 700; margin-top: 4px; }
.stat.full { grid-column: 1 / -1; }

#detailsList .detail {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
#detailsList .detail h4 { margin: 0 0 6px; font-size: 15px; }
#detailsList .detail .txt { color: var(--muted); font-size: 13px; }

.img-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.img-grid .tile {
  background: var(--panel); border-radius: var(--radius); overflow: hidden;
  position: relative;
}
.img-grid .tile img { width: 100%; display: block; aspect-ratio: 4 / 3; object-fit: cover; }
.img-grid .tile .tag {
  position: absolute; left: 6px; bottom: 6px;
  background: rgba(0,0,0,.6); color: #fff;
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
}

.json-toolbar { display: flex; gap: 8px; margin-bottom: 8px; }
#jsonOut {
  background: #0a1122;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 12px;
  max-height: 55vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid rgba(255,255,255,.05);
}

.bottom-actions { margin-top: 20px; }

@media (min-width: 720px) {
  .screen { max-width: 720px; margin: 0 auto; }
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .img-grid { grid-template-columns: repeat(3, 1fr); }
}
