:root {
  --bg: #0b0f14;
  --bg-card: #151b23;
  --border: #232b35;
  --text: #eef2f6;
  --text-dim: #8b98a5;
  --primary: #3b82f6;
  --primary-dim: #1d4ed8;
  --ok: #22c55e;
  --ok-bg: #0f2318;
  --warn: #eab308;
  --warn-bg: #241d0a;
  --bad: #ef4444;
  --bad-bg: #260f0f;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --bg-card: #ffffff;
    --border: #e3e8ee;
    --text: #12181f;
    --text-dim: #5b6673;
    --ok-bg: #e9f9ee;
    --warn-bg: #fdf6dd;
    --bad-bg: #fdeaea;
  }
}

* { box-sizing: border-box; }

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

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 520px;
  margin: 0 auto;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.topbar {
  padding: 14px 18px 10px;
  text-align: center;
}
.logo {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.pantalla {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 0 16px 20px;
  gap: 14px;
  animation: fadein .25s ease;
}
.pantalla.activa { display: flex; }

@keyframes fadein {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Captura ---------- */
.camera-wrap {
  position: relative;
  flex: 1;
  min-height: 300px;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.camera-wrap.sin-camara #video { display: none; }
.camera-wrap.sin-camara::after {
  content: "📷";
  font-size: 64px;
  opacity: .25;
}

.overlay-guide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.aro {
  width: 62%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,.55);
  box-shadow: 0 0 0 2000px rgba(0,0,0,.35);
  transition: border-color .15s, box-shadow .15s;
}
.aro.enfocado {
  border-color: var(--ok);
  box-shadow: 0 0 0 2000px rgba(0,0,0,.25), 0 0 24px 2px rgba(34,197,94,.5);
}

.badge-foco {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}
.badge-foco.enfocado { background: rgba(22,163,74,.85); }

.btn-linterna {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.btn-linterna.encendida {
  background: #eab308;
  box-shadow: 0 0 14px 2px rgba(234,179,8,.6);
}

.link-secundario {
  text-align: center;
  font-size: 12.5px;
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
  padding: 2px;
}

.zoom-wrap {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  border-radius: 999px;
  padding: 8px 14px;
}
.zoom-icon { font-size: 13px; color: #fff; opacity: .85; }
#zoom-slider {
  flex: 1;
  accent-color: var(--primary);
  height: 28px;
}

.candidatos-lista {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  max-width: 320px;
}
.candidatos-lista span {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px 8px;
  font-family: "SF Mono", "Courier New", monospace;
}

.tip-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--text-dim);
}
.tip-card b { color: var(--text); }

.controles {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px 18px;
  border-radius: 14px;
  border: none;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  transition: transform .08s ease, opacity .15s ease;
  text-align: center;
}
.btn:active { transform: scale(.97); }
.btn-icon { font-size: 18px; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

.hint {
  text-align: center;
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 0;
  min-height: 16px;
}

.hidden { display: none !important; }

/* ---------- Procesando ---------- */
#pantalla-procesando { align-items: center; justify-content: center; }
.procesando-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}
.preview-thumb {
  width: 160px;
  height: 160px;
  object-fit: cover;
  border-radius: 50%;
  border: 3px solid var(--border);
  opacity: .9;
}
.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.procesando-texto { font-size: 16px; font-weight: 600; margin: 0; }
.procesando-sub { font-size: 13px; color: var(--text-dim); margin: 0; }

/* ---------- Resultado ---------- */
#pantalla-resultado { justify-content: center; }
.resultado-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.resultado-box.ok { background: var(--ok-bg); border-color: var(--ok); }
.resultado-box.revisar { background: var(--warn-bg); border-color: var(--warn); }
.resultado-box.rechaza { background: var(--bad-bg); border-color: var(--bad); }

.resultado-icono { font-size: 52px; line-height: 1; }
.resultado-titulo { font-size: 18px; font-weight: 700; margin-top: 4px; }
.codigo-label {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 16px 0 6px;
}
.input-codigo {
  width: 100%;
  max-width: 280px;
  font-family: "SF Mono", "Courier New", monospace;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 3px;
  text-align: center;
  text-transform: uppercase;
  padding: 10px 8px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
}
.input-codigo:focus {
  outline: none;
  border-color: var(--primary, #2563eb);
}
/* En verificacion el codigo es de solo lectura: se muestra como un dato grande,
   no como un campo de formulario (sin borde de input ni cursor de edicion). */
.input-codigo[readonly] {
  border-color: transparent;
  background: transparent;
  font-size: 30px;
  cursor: default;
  margin-top: 6px;
}
.resultado-detalle {
  font-size: 13.5px;
  color: var(--text-dim);
  max-width: 320px;
  line-height: 1.4;
}
.resultado-meta {
  font-size: 11.5px;
  color: var(--text-dim);
  opacity: .6;
  margin-top: 14px;
}
