:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #15202b;
  --muted: #5b6875;
  --line: #d5dbe1;
  --brand: #16324f;
  --primary: #1f6feb;
  --primary-ink: #ffffff;
  --ok: #1a7f37;
  --warn: #9a6700;
  --bad: #cf222e;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 19px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#topbar { position: sticky; top: 0; z-index: 5; background: var(--brand); color: #fff; padding-top: env(safe-area-inset-top); }
.bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 56px; }
.brand { background: none; border: 0; color: #fff; font: inherit; font-weight: 700; font-size: 1.1rem; padding: 8px 0; }
.who { margin-left: auto; opacity: 0.9; }
.pill { border: 0; border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 0.9rem; font-weight: 600; }
.pill.ok { background: #d1f0da; color: var(--ok); }
.pill.warn { background: #fff1c2; color: var(--warn); }
.pill.bad { background: #ffd8d3; color: var(--bad); }
.demo { background: #ffd33d; color: #3b2f00; font-weight: 700; text-align: center; padding: 6px 12px; font-size: 0.85rem; }

main { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
.screen { display: flex; flex-direction: column; gap: 14px; }
.screen.center { text-align: center; align-items: stretch; padding-top: 24px; }
h1 { font-size: 1.8rem; margin: 8px 0 4px; }
h2 { font-size: 1.2rem; margin: 10px 0 0; }
.lead { font-size: 1.15rem; margin: 0; }
.muted { color: var(--muted); }
.note { background: #fff1c2; padding: 10px 14px; border-radius: var(--radius); margin: 0; }
.error { color: var(--bad); font-weight: 600; min-height: 1.4em; margin: 0; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-weight: 700; background: #e8edf2; padding: 1px 6px; border-radius: 6px; }
.path { color: var(--muted); font-size: 0.95rem; }
.bigcode { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 2.6rem; font-weight: 800; margin: 8px 0 16px; word-break: break-all; }

.btn {
  display: block; width: 100%; min-height: 64px; padding: 14px 18px;
  font: inherit; font-size: 1.2rem; font-weight: 600; text-align: center;
  background: var(--card); color: var(--ink); border: 2px solid var(--line); border-radius: var(--radius);
  touch-action: manipulation; cursor: pointer;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.huge { min-height: 96px; font-size: 1.5rem; }
.btn.small { width: auto; min-height: 48px; padding: 8px 16px; font-size: 1rem; display: inline-block; }
.btn:disabled { opacity: 0.6; }
.btn:active { transform: scale(0.99); }
.filebtn { position: relative; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.filebtn input { position: absolute; inset: 0; opacity: 0; font-size: 200px; cursor: pointer; }
.link { background: none; border: 0; color: var(--primary); font: inherit; font-weight: 600; padding: 14px; min-height: 48px; }
.link.danger { color: var(--bad); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.row-end { display: flex; justify-content: space-between; gap: 10px; margin-top: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.field input {
  font: inherit; font-size: 1.3rem; font-weight: 400; padding: 14px; min-height: 60px;
  border: 2px solid var(--line); border-radius: var(--radius); background: #fff; width: 100%;
}
.field input:focus { outline: 3px solid #9cc3ff; border-color: var(--primary); }

.pin-dots { text-align: center; font-size: 2rem; letter-spacing: 0.3em; min-height: 56px; padding: 8px; }
.pin-dots.empty { font-size: 1.1rem; letter-spacing: normal; color: var(--muted); padding-top: 16px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key {
  min-height: 72px; font: inherit; font-size: 1.8rem; font-weight: 600; background: var(--card);
  border: 2px solid var(--line); border-radius: var(--radius); touch-action: manipulation;
}
.key.small { font-size: 1.1rem; }
.key:active { background: #e8edf2; }
.stepper { display: grid; grid-template-columns: 80px 1fr 80px; gap: 10px; }
.stepper input { text-align: center; font-size: 1.6rem; font-weight: 700; }

.card { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.card.bad { border-color: var(--bad); }
.card .title { font-size: 1.3rem; font-weight: 700; }
.binbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: #e3eefc; border-radius: var(--radius); padding: 6px 6px 6px 14px; }

.choices { display: flex; flex-wrap: wrap; gap: 10px; }
.choices.list { flex-direction: column; }
.choice {
  font: inherit; text-align: left; min-height: 56px; padding: 10px 16px; background: var(--card);
  border: 2px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; gap: 2px;
}
.choices:not(.list) .choice { justify-content: center; }
.choice small { color: var(--muted); }
.choice.on { border-color: var(--primary); background: #e3eefc; box-shadow: inset 0 0 0 2px var(--primary); }
.demo-people { display: flex; flex-direction: column; gap: 8px; }
.chip { font: inherit; text-align: left; padding: 10px 14px; border: 2px dashed #c9a400; background: #fffbe6; border-radius: var(--radius); display: flex; flex-direction: column; }
.chip small { color: var(--muted); }

.viewfinder { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; }
.viewfinder video { width: 100%; height: 100%; object-fit: cover; display: block; }
.aim { position: absolute; inset: 18%; border: 4px solid rgba(255, 255, 255, 0.85); border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25); }
.preview { width: 100%; max-height: 60vh; object-fit: contain; background: #000; border-radius: var(--radius); }
.thumb { width: 140px; height: 140px; object-fit: cover; border-radius: var(--radius); align-self: center; }

.saved .check { font-size: 5rem; line-height: 1; color: #fff; background: var(--ok); width: 140px; height: 140px; border-radius: 50%; display: grid; place-items: center; margin: 12px auto 0; }

/* Stage 2 */
.pill { background: rgba(255, 255, 255, 0.15); color: #fff; }
.searchbox {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 64px; padding: 14px 18px;
  font: inherit; font-size: 1.25rem; color: var(--muted); text-align: left;
  background: #fff; border: 2px solid var(--line); border-radius: 999px;
}
.searchbox span { font-size: 1.6rem; color: var(--ink); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.list, .results { display: flex; flex-direction: column; gap: 8px; }
.result {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 72px; padding: 8px 12px;
  font: inherit; text-align: left; color: var(--ink); background: var(--card);
  border: 2px solid var(--line); border-radius: var(--radius);
}
.rtext { display: block; min-width: 0; line-height: 1.35; }
.rtext small { display: block; margin-top: 2px; color: var(--muted); overflow-wrap: anywhere; }
.tslot { flex: 0 0 56px; width: 56px; height: 56px; border-radius: 10px; background: #e8edf2; overflow: hidden; display: grid; place-items: center; }
.tslot img { width: 100%; height: 100%; object-fit: cover; }
.tslot.place { background: #dbe7f6; color: var(--brand); font-weight: 800; font-size: 1.4rem; }
.photo-box { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.photo-box .tslot { width: 160px; height: 160px; flex-basis: 160px; }
.tag { display: inline-block; font-size: 0.85rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #e8edf2; color: var(--ink); }
.tag.bad { background: #ffd8d3; color: var(--bad); }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; color: var(--muted); }
.crumb { font: inherit; font-size: 0.95rem; background: none; border: 0; color: var(--primary); padding: 8px 4px; min-height: 40px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 400; min-height: 44px; }
.check input { width: 26px; height: 26px; }
.check.big { font-size: 1.05rem; }
.checks { display: flex; flex-direction: column; gap: 4px; max-height: 360px; overflow-y: auto; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.binbar > div:last-child { display: flex; gap: 4px; }

/* Stage 3 */
.field.small { font-weight: 400; font-size: 0.95rem; }
.field.small input { width: 110px; min-height: 48px; font-size: 1.1rem; padding: 8px 10px; }
.card a { color: var(--primary); }
