:root {
  --bg: #faf7f4;
  --card: #ffffff;
  --ink: #2c2724;
  --muted: #8a817b;
  --line: #e8e0d8;
  --accent: #9a6b48;
  --accent-dark: #7d5436;
  --ok: #3d7a4f;
  --err: #b3413a;
  --radius: 16px;
  --shadow: 0 8px 28px rgba(44, 39, 36, .09);
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

h1, h2, h3 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  letter-spacing: .01em;
  margin: 0;
}

a { color: var(--accent-dark); }

.wrap { max-width: 760px; margin: 0 auto; padding: 20px 16px 48px; }

/* ---------- login ---------- */
.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background:
    radial-gradient(1200px 400px at 50% -10%, #f3e7dd 0%, transparent 60%),
    var(--bg);
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 22px;
}

.brand { text-align: center; margin-bottom: 22px; }
.brand .amp { color: var(--accent); font-style: italic; }
.brand h1 { font-size: 30px; }
.brand p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }

.tabs { display: flex; gap: 6px; background: #f4efe9; padding: 4px; border-radius: 12px; margin-bottom: 18px; }
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 9px;
  font: inherit; font-size: 14px; color: var(--muted); cursor: pointer;
}
.tabs button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.06); }

label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
input[type=email], input[type=password], input[type=text] {
  width: 100%; padding: 13px 14px; font: inherit; color: var(--ink);
  background: #fdfbf9; border: 1px solid var(--line); border-radius: 11px; outline: none;
}
input:focus { border-color: var(--accent); background: #fff; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 14px 18px; margin-top: 18px;
  font: inherit; font-weight: 600; color: #fff; background: var(--accent);
  border: 0; border-radius: 12px; cursor: pointer;
}
.btn:active { background: var(--accent-dark); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent-dark); border: 1px solid var(--line); }
.btn.small { width: auto; padding: 8px 12px; margin: 0; font-size: 13px; border-radius: 9px; }

.msg { margin-top: 14px; font-size: 14px; padding: 11px 13px; border-radius: 10px; display: none; }
.msg.show { display: block; }
.msg.err { background: #fbeceb; color: var(--err); }
.msg.ok { background: #edf5ee; color: var(--ok); }

.hint { margin-top: 16px; font-size: 12.5px; color: var(--muted); text-align: center; line-height: 1.45; }

/* ---------- app ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: rgba(250,247,244,.92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 18px; }
.top .who { font-size: 12px; color: var(--muted); }

.hero { text-align: center; padding: 40px 8px 8px; }
.hero h2 { font-size: 26px; margin-bottom: 8px; }
.hero p { color: var(--muted); font-size: 14.5px; margin: 0 auto; max-width: 420px; }

.selfie-zone { margin: 26px 0 8px; text-align: center; }
.selfie-btn {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  width: 190px; height: 190px; border-radius: 50%;
  background: linear-gradient(160deg, #fff 0%, #f6ece3 100%);
  border: 1px dashed #d9c7b6; color: var(--accent-dark); font: inherit; font-weight: 600;
  cursor: pointer; box-shadow: 0 10px 30px rgba(154,107,72,.13);
}
.selfie-btn:active { transform: scale(.985); }
.selfie-btn svg { width: 46px; height: 46px; opacity: .85; }
.selfie-btn span { font-size: 13.5px; font-weight: 500; color: var(--muted); }

.preview { width: 190px; height: 190px; border-radius: 50%; object-fit: cover; border: 3px solid #fff; box-shadow: var(--shadow); }

/* ---------- desafio de liveness ---------- */
.challenge {
  display: none; text-align: left; max-width: 360px; margin: 0 auto;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.challenge.show { display: block; }
.challenge-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.chip {
  display: inline-block; padding: 3px 9px; border-radius: 20px;
  background: #f3e7dd; color: var(--accent-dark); font-size: 12px; font-weight: 600;
}
.step-preview img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; display: block; }
.challenge p { margin: 0 0 14px; font-size: 15px; line-height: 1.45; }
.challenge-actions { display: flex; gap: 8px; align-items: center; }
.challenge-actions .btn { margin-top: 0; flex: 1; }
.challenge-actions .btn.ghost { flex: 0 0 auto; }

.loading { display: none; padding: 26px 0; text-align: center; color: var(--muted); }
.loading.show { display: block; }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 12px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.results { display: none; margin-top: 10px; }
.results.show { display: block; }
.results-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 18px 0 12px; }
.results-head h3 { font-size: 20px; }
.results-head .count { font-size: 13px; color: var(--muted); }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 620px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 10px; } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.tile {
  position: relative; border: 0; padding: 0; background: #eadfd6;
  border-radius: 10px; overflow: hidden; cursor: pointer; aspect-ratio: 1 / 1;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .badge {
  position: absolute; right: 6px; bottom: 6px; padding: 2px 7px; border-radius: 20px;
  background: rgba(0,0,0,.55); color: #fff; font-size: 10.5px; letter-spacing: .02em;
}

/* ---------- lightbox ---------- */
.lb {
  position: fixed; inset: 0; z-index: 100; display: none;
  background: #141110; color: #fff; isolation: isolate;
  grid-template-rows: auto 1fr auto;
}
.lb.show { display: grid; }
.lb-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; font-size: 13px; }
.lb-head .close { background: none; border: 0; color: #fff; font-size: 26px; line-height: 1; cursor: pointer; }
.lb-body { display: grid; place-items: center; overflow: hidden; position: relative; }
.lb-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,.12); border: 0; color: #fff; width: 42px; height: 64px;
  border-radius: 10px; font-size: 24px; cursor: pointer;
}
.lb-nav.prev { left: 8px; } .lb-nav.next { right: 8px; }
.lb-foot { display: flex; justify-content: center; gap: 10px; padding: 14px; }
.lb-foot a {
  color: #fff; text-decoration: none; border: 1px solid rgba(255,255,255,.35);
  padding: 9px 16px; border-radius: 10px; font-size: 14px;
}

/* ---------- admin ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.panel h3 { font-size: 17px; margin-bottom: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }
code { background: #f4efe9; padding: 2px 6px; border-radius: 6px; font-size: 12.5px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 140px; }
.row .btn { margin-top: 0; }

/* ---------- camera embutida (captura automatica) ---------- */
.cam {
  position: fixed; inset: 0; z-index: 120; display: none;
  background: #0d0b0a; color: #fff; overflow: hidden;
}
.cam.show { display: block; }
.cam video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; transform: scaleX(-1);
}
.cam-guide {
  position: absolute; z-index: 1; left: 50%; top: 44%;
  width: min(66vw, 260px); height: min(86vw, 340px);
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255,255,255,.8);
  border-radius: 50% / 46%;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.35);
  pointer-events: none;
}
.cam-bar {
  position: absolute; z-index: 3; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 16px 14px;
  background: linear-gradient(rgba(0,0,0,.45), transparent);
}
.cam-bar .chip { background: rgba(255,255,255,.16); color: #fff; }
.cam-x {
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.16); color: #fff;
  font-size: 26px; line-height: 1; cursor: pointer;
}
.cam-count {
  position: absolute; z-index: 2; left: 0; right: 0; top: 42%;
  text-align: center; font-family: Georgia, "Times New Roman", serif;
  font-size: 88px; line-height: 1; pointer-events: none;
  text-shadow: 0 4px 24px rgba(0,0,0,.55);
}
.cam-foot {
  position: absolute; z-index: 3; left: 0; right: 0; bottom: 0;
  padding: 24px 20px max(28px, env(safe-area-inset-bottom));
  text-align: center;
  background: linear-gradient(transparent, rgba(0,0,0,.65));
}
.cam-foot p { margin: 0 0 12px; font-size: 17px; line-height: 1.4; }
.cam-native {
  padding: 8px; border: 0; background: none; cursor: pointer;
  color: rgba(255,255,255,.75); font: inherit; font-size: 13px;
  text-decoration: underline;
}
