:root {
  --tinta: #0F1B14;
  --papel: #F6F3E9;
  --ambar: #E8A23D;
  --ambar-fuerte: #C97B1E;
  --verde-ok: #4E9A6B;
  --rojo-no: #B5473A;
  --linea: rgba(246, 243, 233, 0.1);
  --mono: 'IBM Plex Mono', 'Courier New', monospace;
  --sans: 'IBM Plex Sans', 'Segoe UI', sans-serif;
}

@font-face {
  font-family: 'IBM Plex Mono';
  src: local('IBM Plex Mono');
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--tinta);
  color: var(--papel);
  font-family: var(--sans);
  overflow: hidden;
}

body {
  background-image: radial-gradient(circle at 6px 6px, rgba(246,243,233,0.02) 1.5px, transparent 1.6px);
  background-size: 24px 24px;
}

.cabecera {
  position: absolute;
  top: 12px;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  z-index: 10;
}

.reloj {
  font-family: var(--mono);
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  color: var(--ambar);
  background: rgba(15, 27, 20, 0.85);
  padding: 4px 16px;
  border-radius: 30px;
  border: 1px solid var(--linea);
  backdrop-filter: blur(8px);
}

.tablero {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 56px 20px calc(24px + env(safe-area-inset-bottom)) 20px;
  max-width: 500px;
  margin: 0 auto;
}

.visor-contenedor {
  width: 100%;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
}

.visor {
  position: relative;
  width: 100%;
  height: 100%;
  max-height: 52vh;
  aspect-ratio: 3 / 4;
  border-radius: 24px;
  overflow: hidden;
  background: #000;
  border: 1px solid rgba(246, 243, 233, 0.12);
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.7);
}

.visor video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.visor canvas#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.marco {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 72%;
  height: 55%;
  transform: translate(-50%, -55%);
  border: 2px dashed rgba(246, 243, 233, 0.15);
  border-radius: 50% / 45%;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.marco::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: 
    linear-gradient(90deg, transparent 35%, rgba(232, 162, 61, 0.15) 35%, rgba(232, 162, 61, 0.15) 65%, transparent 65%),
    linear-gradient(0deg, transparent 40%, rgba(232, 162, 61, 0.15) 40%, rgba(232, 162, 61, 0.15) 60%, transparent 60%);
  background-size: 100% 35%, 50% 100%;
  background-position: center 32%, center;
  background-repeat: no-repeat;
  opacity: 0.6;
}

.marco::after {
  content: '';
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 40%;
  height: 3px;
  background: var(--ambar);
  border-radius: 2px;
  opacity: 0.4;
  transition: all 0.3s ease;
}

.punto-ojo-izq,
.punto-ojo-der,
.punto-barbilla {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(232, 162, 61, 0.25);
  transition: all 0.3s ease;
}

.punto-ojo-izq { top: 32%; left: 25%; }
.punto-ojo-der { top: 32%; right: 25%; }
.punto-barbilla { bottom: 15%; left: 50%; transform: translateX(-50%); }

.marco.detectado {
  border-color: rgba(232, 162, 61, 0.5);
  box-shadow: 0 0 30px rgba(232, 162, 61, 0.15), inset 0 0 30px rgba(232, 162, 61, 0.05);
}

.marco.detectado::after {
  opacity: 1;
  width: 60%;
  background: var(--ambar);
}

.marco.detectado .punto-ojo-izq,
.marco.detectado .punto-ojo-der,
.marco.detectado .punto-barbilla {
  background: var(--ambar);
  box-shadow: 0 0 8px rgba(232, 162, 61, 0.5);
}

.marco.reconocido {
  border-color: transparent;
  border: 2px solid var(--verde-ok);
  box-shadow: 0 0 40px rgba(78, 154, 107, 0.25), inset 0 0 40px rgba(78, 154, 107, 0.08);
  animation: pulso-exito 1.5s ease infinite;
}

.marco.reconocido::after {
  background: var(--verde-ok);
  opacity: 1;
}

.marco.reconocido .punto-ojo-izq,
.marco.reconocido .punto-ojo-der,
.marco.reconocido .punto-barbilla {
  background: var(--verde-ok);
  box-shadow: 0 0 10px rgba(78, 154, 107, 0.6);
}

.marco.no-reconocido {
  border-color: transparent;
  border: 2px solid var(--rojo-no);
  box-shadow: 0 0 30px rgba(181, 71, 58, 0.2);
  animation: shake 0.5s ease;
}

.marco.no-reconocido::after {
  background: var(--rojo-no);
  opacity: 0.8;
}

@keyframes pulso-exito {
  0%, 100% { transform: translate(-50%, -55%) scale(1); }
  50% { transform: translate(-50%, -55%) scale(1.02); }
}

@keyframes shake {
  0%, 100% { transform: translate(-50%, -55%) translateX(0); }
  20% { transform: translate(-50%, -55%) translateX(-8px); }
  40% { transform: translate(-50%, -55%) translateX(8px); }
  60% { transform: translate(-50%, -55%) translateX(-4px); }
  80% { transform: translate(-50%, -55%) translateX(4px); }
}

.centrado-hint {
  position: absolute;
  bottom: 12%;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(246, 243, 233, 0.3);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.centrado-hint.visible {
  opacity: 1;
}

.panel-estado {
  width: 100%;
  text-align: center;
  margin: 12px 0 20px 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.paso-actual {
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.75rem;
  color: var(--ambar);
  margin: 0;
}

.mensaje {
  font-weight: 600;
  font-size: 1.9rem; 
  line-height: 1.2;
  margin: 0;
  color: var(--papel);
  letter-spacing: -0.02em;
}

.panel-estado.exito .mensaje { color: var(--verde-ok); }
.panel-estado.error .mensaje { color: var(--rojo-no); }

.detalle {
  font-family: var(--mono);
  font-size: 0.9rem;
  color: rgba(246, 243, 233, 0.4);
  margin: 0;
  min-height: 1.2em;
}

.acciones {
  width: 100%;
  margin-bottom: 8px;
}

.btn-capturar {
  width: 100%;
  height: 52px;
  border: none;
  outline: none;
  background: var(--papel);
  color: var(--tinta);
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  border-radius: 26px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.btn-capturar:active:not(:disabled) {
  transform: scale(0.97);
  opacity: 0.85;
}

.btn-capturar:disabled {
  background: rgba(246, 243, 233, 0.05);
  color: rgba(246, 243, 233, 0.2);
  border: 1px solid rgba(246, 243, 233, 0.03);
  box-shadow: none;
  cursor: not-allowed;
}

.pie {
  width: 100%;
  text-align: center;
  margin-top: 4px;
}

.enlace-admin {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: rgba(246, 243, 233, 0.25);
  text-decoration: none;
  letter-spacing: 0.05em;
  padding: 4px;
  display: inline-block;
}

@media (max-height: 700px) {
  .tablero { padding-top: 48px; }
  .visor { max-height: 45vh; }
  .mensaje { font-size: 1.5rem; }
  .btn-capturar { height: 46px; }
  .marco { width: 68%; height: 50%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}