/* =====================================================
   CÓDIGO DE COLORES DE LA MARCA
   ===================================================== */
:root {
  --marca-primario:    #0F3D5E;
  --marca-secundario:  #FFC93C;
  --marca-acento:      #FF6B4A;
  --marca-texto:       #0E1F2B;
  --marca-papel:       #FFFDF6;
  --error-fondo:       #FFE4DE;
  --error-texto:       #7A1D10;
  --fuente: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  font-family: var(--fuente);
  background: var(--marca-primario);
  color: var(--marca-papel);
  min-height: 100dvh;
  padding:
    env(safe-area-inset-top,    0px)
    env(safe-area-inset-right,  0px)
    env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left,   0px);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

/* ── Cabecera ─────────────────────────────────────────── */
.cabecera {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.25rem 0;
}
.logo { height: 44px; width: auto; max-width: 60vw; }
.modo-badge {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .05em;
  padding: .3rem .75rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--marca-papel) 15%, transparent);
  color: var(--marca-papel);
}

/* ── Layout ───────────────────────────────────────────── */
main { max-width: 30rem; margin: 0 auto; padding: 1.75rem 1.25rem 3rem; }

.paso { margin: 0 0 .5rem; font-size: .95rem; opacity: .75; }

h1 {
  margin: 0 0 1rem;
  font-size: clamp(3rem, 15vw, 4.75rem);
  line-height: .92;
  font-weight: 800;
  letter-spacing: -.035em;
  color: var(--marca-secundario);
  text-wrap: balance;
}
h2 {
  margin: 0 0 .75rem;
  font-size: clamp(1.75rem, 8vw, 2.25rem);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -.02em;
  text-wrap: balance;
}
h1:focus, h2:focus { outline: none; }
.bajada { margin: 0 0 1.5rem; font-size: 1.0625rem; line-height: 1.5; max-width: 36ch; }

/* ── Tarjeta / formulario ─────────────────────────────── */
.tarjeta {
  display: grid;
  gap: .75rem;
  padding: 1.25rem;
  background: var(--marca-papel);
  color: var(--marca-texto);
  border-radius: 1.25rem;
}
.tarjeta > label { font-weight: 600; }

input[type="text"] {
  width: 100%;
  font: inherit;
  font-size: 1.125rem;
  padding: .85rem 1rem;
  color: inherit;
  background: #fff;
  border: 2px solid color-mix(in srgb, var(--marca-texto) 22%, transparent);
  border-radius: .75rem;
}
input[type="text"]:focus {
  outline: none;
  border-color: var(--marca-primario);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--marca-primario) 25%, transparent);
}

.check { display: flex; gap: .65rem; align-items: flex-start; font-size: .95rem; line-height: 1.4; margin: .25rem 0; }
.check input { flex: none; width: 1.3rem; height: 1.3rem; margin: .1rem 0 0; accent-color: var(--marca-primario); }

/* ── Botones ──────────────────────────────────────────── */
.btn {
  width: 100%;
  min-height: 3.25rem;
  padding: 1rem 1.5rem;
  font: inherit;
  font-size: 1.0625rem;
  font-weight: 700;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform .12s ease;
}
.btn:active   { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: progress; }
.primario   { background: var(--marca-secundario); color: var(--marca-texto); }
.secundario { background: transparent; color: var(--marca-papel); box-shadow: inset 0 0 0 2px currentColor; }

.btn:focus-visible, .enlace:focus-visible, .alt:focus-within {
  outline: 3px solid var(--marca-acento);
  outline-offset: 3px;
}

.enlace {
  display: block;
  margin: 1.25rem auto 0;
  padding: .75rem;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  opacity: .85;
}

.error {
  margin: 0;
  padding: .75rem 1rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--error-texto);
  background: var(--error-fondo);
  border-radius: .75rem;
}
.error:empty { display: none; }
#err-camara, #err-firma { margin-bottom: 1rem; }

/* ── Visor de cámara ─────────────────────────────────── */
.visor {
  position: relative;
  aspect-ratio: 3 / 4;
  margin: 0 0 1rem;
  overflow: hidden;
  background: color-mix(in srgb, var(--marca-texto) 70%, black);
  border-radius: 1.5rem;
}
.visor video, .visor img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.visor video { transform: scaleX(-1); }
.marco {
  position: absolute;
  inset: 12% 17% 20%;
  border: 3px dashed color-mix(in srgb, var(--marca-papel) 75%, transparent);
  border-radius: 50%;
  pointer-events: none;
}
.visor-vacio {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: .5rem;
  opacity: .6;
}

.acciones { display: grid; gap: .75rem; }

.alt { display: block; position: relative; margin-top: 1rem; text-align: center; cursor: pointer; border-radius: .5rem; }
.alt input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.alt span { text-decoration: underline; text-underline-offset: 3px; }

/* ── Lienzo de firma ─────────────────────────────────── */
.lienzo-wrap {
  position: relative;
  margin: 0 0 1rem;
  aspect-ratio: 5 / 2;
  background: #fff;
  border-radius: 1.25rem;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
  /* borde sutil que no choca con el fondo oscuro */
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--marca-papel) 25%, transparent),
              0 8px 32px color-mix(in srgb, black 30%, transparent);
}
#lienzo {
  display: block;
  width: 100%;
  height: 100%;
  /* touch-action heredado del contenedor */
}
/* Línea de base punteada */
.lienzo-guia {
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: 32%;
  height: 0;
  border-bottom: 2px dashed color-mix(in srgb, var(--marca-texto) 18%, transparent);
  pointer-events: none;
}
/* Texto de ayuda que desaparece al primer trazo */
.lienzo-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 36%;
  gap: .4rem;
  color: color-mix(in srgb, var(--marca-texto) 35%, transparent);
  font-size: .9rem;
  font-weight: 600;
  pointer-events: none;
  transition: opacity .3s;
}
.lienzo-hint.oculto { opacity: 0; }

/* ── Boleto final ─────────────────────────────────────── */
.boleto {
  --corte: 7rem;
  display: grid;
  grid-template-columns: var(--corte) 1fr;
  margin: 1.5rem 0 .5rem;
  color: var(--marca-texto);
  background: var(--marca-secundario);
  border-radius: 1.25rem;
  overflow: hidden;
  transform: rotate(-1.5deg);
  -webkit-mask:
    radial-gradient(circle at var(--corte) 0,     transparent .8rem, #000 .85rem) top    / 100% 51% no-repeat,
    radial-gradient(circle at var(--corte) 100%,  transparent .8rem, #000 .85rem) bottom / 100% 51% no-repeat;
          mask:
    radial-gradient(circle at var(--corte) 0,     transparent .8rem, #000 .85rem) top    / 100% 51% no-repeat,
    radial-gradient(circle at var(--corte) 100%,  transparent .8rem, #000 .85rem) bottom / 100% 51% no-repeat;
  animation: imprimir .7s cubic-bezier(.2, .9, .3, 1.3) both;
}

/* Foto: retrato */
.boleto-captura img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 9rem;
  object-fit: cover;
}
/* Firma: paisaje con fondo blanco */
.boleto[data-tipo="firma"] .boleto-captura {
  display: flex;
  align-items: center;
  background: #fff;
  padding: .5rem;
}
.boleto[data-tipo="firma"] .boleto-captura img {
  object-fit: contain;
  min-height: 4.5rem;
}

.boleto-datos {
  padding: 1.1rem 1.1rem 1.1rem 1.25rem;
  border-left: 2px dashed color-mix(in srgb, var(--marca-texto) 40%, transparent);
  min-width: 0;
}
.b-etiqueta { margin: 0; font-size: .8rem; opacity: .7; }
.b-nombre   { margin: 0 0 .9rem; font-size: 1.15rem; font-weight: 800; line-height: 1.15; overflow-wrap: anywhere; }
.b-codigo   { margin: 0; font-size: 1.65rem; font-weight: 800; letter-spacing: .05em; font-variant-numeric: tabular-nums; }

@keyframes imprimir {
  from { opacity: 0; transform: translateY(1.5rem) rotate(4deg) scale(.96); }
  to   { opacity: 1; transform: rotate(-1.5deg); }
}

/* ── Confeti ──────────────────────────────────────────── */
.confeti { position: fixed; inset: 0; z-index: 10; overflow: hidden; pointer-events: none; }
.confeti i {
  position: absolute; top: -2rem;
  width: .5rem; height: .9rem;
  border-radius: 2px;
  animation: caer linear forwards;
}
@keyframes caer { to { transform: translate(var(--deriva), 110vh) rotate(var(--giro)); } }

@media (prefers-reduced-motion: reduce) {
  .boleto { animation: none; }
  .btn { transition: none; }
  .lienzo-hint { transition: none; }
}
