/* ===== Base ===== */
:root {
  --app-h: 100dvh; /* app.js lo ajusta con visualViewport para que el teclado del celular no tape nada */
  --brand: #2563EB;
  --brand-d: #1D4ED8;
  --ink: #14211E;
}
html { scroll-behavior: smooth; }
body { margin: 0; background: #F3F7FF; color: var(--ink); }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

/* ===== Fondo animado ===== */
.mesh {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(180deg, #EAF1FF 0%, #F7F9FF 60%, #FFF 100%);
}
.mesh span {
  position: absolute;
  border-radius: 9999px;
  filter: blur(70px);
  opacity: .55;
  animation: drift 18s ease-in-out infinite alternate;
}
.mesh .b1 { width: 46vmax; height: 46vmax; left: -12vmax; top: -14vmax; background: #93C5FD; }
.mesh .b2 { width: 38vmax; height: 38vmax; right: -10vmax; top: 12vh; background: #FBCFE8; animation-duration: 22s; animation-delay: -6s; }
.mesh .b3 { width: 34vmax; height: 34vmax; left: 20vw; bottom: -16vmax; background: #99F6E4; opacity: .4; animation-duration: 26s; animation-delay: -12s; }
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(4vmax, 3vmax, 0) scale(1.12); }
}

/* Corazones y cruces que suben despacio */
.floaters { position: fixed; inset: 0; z-index: 1; overflow: hidden; pointer-events: none; }
.floaters span {
  position: absolute;
  bottom: -40px;
  opacity: 0;
  animation: rise linear infinite;
}
@keyframes rise {
  0%   { transform: translateY(0) rotate(0deg); opacity: 0; }
  12%  { opacity: .55; }
  88%  { opacity: .3; }
  100% { transform: translateY(-112vh) rotate(40deg); opacity: 0; }
}

/* ===== Contenedor de la app (pantalla completa, columna de celular) ===== */
.app {
  position: relative;
  height: var(--app-h);
  max-width: 30rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Barra superior */
.topbar {
  flex: none;
  padding: calc(.7rem + env(safe-area-inset-top)) 1.1rem .4rem;
}
.brandrow { display: flex; align-items: center; justify-content: space-between; }
.brand {
  display: flex;
  align-items: center;
  gap: .1rem;
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 800;
  font-size: 1.05rem;
}
.brand-ico {
  width: 28px;
  height: 28px;
  margin-right: .5rem;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--brand);
}
.stepcount { font-size: .75rem; font-weight: 600; color: rgba(20, 33, 30, .55); }
.steps {
  display: flex;
  gap: 5px;
  margin-top: .55rem;
  height: 5px;
  opacity: 0;
  transition: opacity .4s ease;
}
.steps.visible { opacity: 1; }
.steps i {
  position: relative;
  flex: 1;
  border-radius: 9999px;
  background: rgba(37, 99, 235, .16);
  overflow: hidden;
}
.steps i::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, #2563EB, #4338CA);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .5s cubic-bezier(.22, 1, .36, 1);
}
.steps i.on::after { transform: none; }

/* ===== Escenario: burbuja + avatar ===== */
.stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .4rem 1.1rem 0;
}
.hero {
  position: relative;
  flex: 1 1 0;
  min-height: 70px;
  width: 100%;
  margin-top: .75rem;
}

/* Burbuja de diálogo */
.speech {
  position: relative;
  flex: none;
  width: 100%;
  min-height: 4.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .9rem 1.1rem;
  text-align: center;
  font-size: 1.02rem;
  line-height: 1.4;
  font-weight: 500;
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 16px 36px -16px rgba(37, 99, 235, .45), 0 2px 6px rgba(20, 33, 30, .06);
  opacity: 0;
  transform-origin: 50% 100%;
}
.speech > div { display: block; }
.speech::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 4px;
  transform: translateX(-50%) rotate(45deg);
}
.speech.show { animation: bubble-in .5s cubic-bezier(.22, 1.25, .36, 1) forwards; }
.speech strong { color: var(--brand-d); font-weight: 700; }
.speech .w {
  display: inline-block;
  opacity: 0;
  transform: translateY(6px);
  animation: word .3s ease forwards;
  animation-delay: calc(var(--n) * 38ms + .1s);
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(10px) scale(.92); }
  to   { opacity: 1; transform: none; }
}
@keyframes word {
  to { opacity: 1; transform: none; }
}

/* Latido de fondo */
.ecg {
  position: absolute;
  left: -1rem;
  right: -1rem;
  top: 50%;
  width: calc(100% + 2rem);
  height: 3.5rem;
  margin-top: -1.2rem;
  opacity: .5;
}
.ecg path {
  fill: none;
  stroke: #2563EB;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 90 410;
  animation: ecg 3.2s linear infinite;
}
@keyframes ecg {
  from { stroke-dashoffset: 0; }
  to   { stroke-dashoffset: -500; }
}

/* ===== Avatar ===== */
.avatar {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: auto;
  overflow: visible;
  opacity: 0;
  transform: translateY(40px) scale(.7);
}
.app.ready .avatar { animation: avatar-in 1s cubic-bezier(.22, 1.35, .36, 1) forwards; }
@keyframes avatar-in {
  from { opacity: 0; transform: translateY(40px) scale(.7); }
  to   { opacity: 1; transform: none; }
}

.a-bob { animation: bob 3.2s ease-in-out infinite; transform-origin: 120px 206px; }
.a-shadow { transform-origin: 120px 228px; animation: shadow 3.2s ease-in-out infinite; }
@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-7px); }
}
@keyframes shadow {
  0%, 100% { transform: scaleX(1); opacity: .13; }
  50%      { transform: scaleX(.86); opacity: .08; }
}

.a-body { transform-origin: 120px 206px; transition: transform .4s ease; }
.a-body { animation: beat 1.5s ease-in-out infinite; }
@keyframes beat {
  0%, 100% { transform: scale(1); }
  12%      { transform: scale(1.035); }
  24%      { transform: scale(1); }
  36%      { transform: scale(1.025); }
  48%      { transform: scale(1); }
}

/* parpadeo */
.a-eye { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
.a-eye-r { animation-delay: .02s; }
@keyframes blink {
  0%, 93%, 100% { transform: scaleY(1); }
  96%           { transform: scaleY(.08); }
}
.a-pupil {
  transform: translate(var(--px, 0px), var(--py, 0px)); /* app.js mueve los ojos hacia el mouse en computadora */
  transition: transform .18s ease-out;
}

/* destellos */
.a-spark { transform-box: fill-box; transform-origin: center; animation: twinkle 2.6s ease-in-out infinite; }
.a-spark.s2 { animation-delay: -1.2s; }
@keyframes twinkle {
  0%, 100% { transform: scale(.6) rotate(0deg); opacity: .5; }
  50%      { transform: scale(1.15) rotate(25deg); opacity: 1; }
}

/* brazos */
.a-arm { transition: transform .45s cubic-bezier(.22, 1.3, .36, 1); }
.a-arm-l { transform-origin: 44px 128px; }
.a-arm-r { transform-origin: 196px 128px; }

/* boca: sonrisa en reposo, boca abierta al hablar */
.a-mouth { opacity: 0; transform-box: fill-box; transform-origin: 50% 0%; }
.avatar.talking .a-smile { opacity: 0; }
.avatar.talking .a-mouth { opacity: 1; animation: talk .26s ease-in-out infinite alternate; }
@keyframes talk {
  from { transform: scaleY(.35); }
  to   { transform: scaleY(1); }
}

/* signo de pregunta */
.a-think { opacity: 0; transform-box: fill-box; transform-origin: center; }

/* ---- estados de ánimo ---- */
.avatar[data-mood="wave"] .a-arm-r { animation: wave 1s ease-in-out infinite; }
@keyframes wave {
  0%, 100% { transform: rotate(-70deg); }
  50%      { transform: rotate(-108deg); }
}
.avatar[data-mood="happy"] .a-arm-r { transform: rotate(0deg); }

.avatar[data-mood="think"] .a-pupil { transform: translate(5px, -5px); }
.avatar[data-mood="think"] .a-think { opacity: 1; animation: pop-q .5s cubic-bezier(.22, 1.5, .36, 1) both; }
.avatar[data-mood="think"] .a-body { transform: rotate(-4deg); animation: none; }
@keyframes pop-q {
  from { transform: scale(0) rotate(-20deg); }
  to   { transform: scale(1) rotate(0); }
}

.avatar[data-mood="cheer"] .a-arm-l { transform: rotate(100deg); }
.avatar[data-mood="cheer"] .a-arm-r { transform: rotate(-100deg); }
.avatar[data-mood="cheer"] .a-bob { animation: jump .7s cubic-bezier(.3, 0, .4, 1) infinite; }
.avatar[data-mood="cheer"] .a-smile { opacity: 0; }
.avatar[data-mood="cheer"] .a-mouth { opacity: 1; }
@keyframes jump {
  0%, 100% { transform: translateY(0); }
  45%      { transform: translateY(-22px); }
}

/* asentir al elegir una opción */
.avatar.nod .a-body { animation: nod .5s ease; }
@keyframes nod {
  0%   { transform: scale(1) translateY(0); }
  35%  { transform: scale(1.06, .94) translateY(4px); }
  70%  { transform: scale(.97, 1.04) translateY(-4px); }
  100% { transform: scale(1) translateY(0); }
}

/* ===== Panel inferior (opciones) ===== */
.sheet {
  flex: none;
  max-height: 56dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.1rem 1rem calc(1.1rem + env(safe-area-inset-bottom));
  border-radius: 28px 28px 0 0;
  background: rgba(255, 255, 255, .95);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  box-shadow: 0 -18px 50px -20px rgba(37, 99, 235, .4);
  transform: translateY(105%);
  transition: transform .7s cubic-bezier(.22, 1, .36, 1);
}
.sheet.up { transform: none; }
.sheet-body { transition: opacity .14s ease, transform .14s ease; }
.sheet-body.leave { opacity: 0; transform: translateY(8px); }
.sheet-body:empty { min-height: 1px; }

/* Opciones grandes */
.tiles { display: grid; gap: .65rem; }
.tiles.cols-1 { grid-template-columns: 1fr; }
.tiles.cols-2 { grid-template-columns: 1fr 1fr; }
.tiles.cols-3 { grid-template-columns: repeat(3, 1fr); }
.tile {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .9rem 1.05rem;
  border: 2px solid rgba(37, 99, 235, .14);
  border-radius: 20px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 8px 18px -14px rgba(37, 99, 235, .6);
  opacity: 0;
  transform: translateY(14px) scale(.97);
  animation: tile-in .5s cubic-bezier(.22, 1, .36, 1) forwards;
  animation-delay: calc(var(--i) * 70ms + .08s);
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease, filter .15s ease;
}
@keyframes tile-in {
  to { opacity: 1; transform: none; }
}
.tile:active { transform: scale(.96) !important; }
@media (hover: hover) {
  .tile:hover { border-color: var(--brand); box-shadow: 0 12px 24px -12px rgba(37, 99, 235, .7); }
}
.tiles.cols-2 .tile,
.tiles.cols-3 .tile {
  flex-direction: column;
  justify-content: center;
  gap: .3rem;
  padding: .9rem .4rem;
  text-align: center;
}
.t-emo { font-size: 1.8rem; line-height: 1; }
.t-l { display: block; font-weight: 700; font-size: 1rem; line-height: 1.2; }
.t-s { display: block; margin-top: .15rem; font-size: .78rem; line-height: 1.25; color: rgba(20, 33, 30, .55); }
.tile.primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, #2563EB, #4338CA);
  box-shadow: 0 16px 30px -14px rgba(37, 99, 235, .9);
}
.tile.primary .t-s { color: rgba(255, 255, 255, .78); }
.tile.selected {
  border-color: var(--brand);
  background: #EFF4FF;
  transform: scale(.98);
}
.tile.primary.selected { background: linear-gradient(135deg, #2563EB, #4338CA); filter: brightness(1.08); }
.tiles.chosen .tile:not(.selected) { opacity: .22 !important; transition: opacity .2s ease; }

/* Selección múltiple: tilde en las opciones marcadas */
.tile { position: relative; }
.tiles.multi { margin-bottom: .1rem; }
.tiles.multi .tile.selected::after {
  content: "✓";
  position: absolute;
  top: 8px;
  right: 10px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 9999px;
  color: #fff;
  font-size: .8rem;
  font-weight: 800;
  background: var(--brand);
  animation: check-pop .3s cubic-bezier(.22, 1.6, .36, 1);
}
@keyframes check-pop {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* Campo de texto */
.fieldbox { display: block; }
.field {
  width: 100%;
  padding: 1rem 1.1rem;
  font-size: 1.15rem; /* 16px o más evita el zoom automático en iOS */
  font-weight: 600;
  border: 2px solid rgba(37, 99, 235, .22);
  border-radius: 18px;
  background: #fff;
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field::placeholder { color: rgba(20, 33, 30, .35); font-weight: 500; }
.field:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 5px rgba(37, 99, 235, .15); }
.cta {
  width: 100%;
  margin-top: .7rem;
  padding: 1rem;
  border: 0;
  border-radius: 18px;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  background: linear-gradient(135deg, #2563EB, #4338CA);
  box-shadow: 0 16px 30px -14px rgba(37, 99, 235, .9);
  transition: transform .15s ease, opacity .2s ease, box-shadow .2s ease;
}
.cta:disabled { opacity: .4; box-shadow: none; cursor: default; }
.cta:not(:disabled):active { transform: scale(.97); }
.hint { margin-top: .75rem; font-size: .78rem; line-height: 1.4; text-align: center; color: rgba(20, 33, 30, .55); }
.hint a { text-decoration: underline; }
.err { margin-top: .6rem; font-size: .85rem; font-weight: 600; line-height: 1.35; text-align: center; color: #DC2626; }
.err:empty { display: none; }
.shake { animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-7px); }
  40%, 80% { transform: translateX(7px); }
}

/* Resumen final */
.recap {
  padding: 1rem 1.1rem;
  border: 1px solid rgba(20, 33, 30, .08);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 10px 30px -16px rgba(37, 99, 235, .4);
  animation: tile-in .5s cubic-bezier(.22, 1, .36, 1) both;
}
.recap h4 {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin: 0 0 .7rem;
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 700;
  font-size: .95rem;
}
.recap dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .45rem .9rem;
  margin: 0;
  font-size: .85rem;
}
.recap dt { color: rgba(20, 33, 30, .5); }
.recap dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.wa-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  width: 100%;
  margin-top: .8rem;
  padding: 1rem;
  border-radius: 18px;
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  background: #16A34A;
  box-shadow: 0 14px 26px -12px rgba(22, 163, 74, .8);
  animation: tile-in .5s .2s cubic-bezier(.22, 1, .36, 1) both;
}
.wa-btn:active { transform: scale(.97); }

/* Partículas al tocar una opción */
.pop {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  font-size: 18px;
  animation: pop .8s ease-out forwards;
}
@keyframes pop {
  from { opacity: 1; transform: translate(-50%, -50%) scale(.6); }
  to   { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.3); }
}

/* Confeti de cierre */
.confetti { position: absolute; inset: 0; z-index: 30; overflow: hidden; pointer-events: none; }
.confetti i {
  position: absolute;
  top: -14px;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  opacity: 0;
  animation: fall 2.6s ease-out forwards;
}
@keyframes fall {
  0%   { opacity: 1; transform: translate3d(0, 0, 0) rotate(0); }
  100% { opacity: 0; transform: translate3d(var(--dx, 0), 110vh, 0) rotate(var(--rot, 540deg)); }
}

/* ===== Accesibilidad ===== */
a:focus-visible,
button:focus-visible {
  outline: 3px solid #2563EB;
  outline-offset: 2px;
}

/* ===== Pantallas bajas (celulares chicos o con teclado abierto) ===== */
@media (max-height: 640px) {
  .speech { min-height: 3.6rem; font-size: .95rem; padding: .7rem .9rem; }
  .t-emo { font-size: 1.5rem; }
  .tile { padding: .7rem .9rem; }
}

/* ===== Escritorio: columna de celular centrada ===== */
@media (min-width: 600px) {
  .app { box-shadow: 0 0 0 1px rgba(37, 99, 235, .08), 0 40px 90px -40px rgba(37, 99, 235, .45); background: rgba(255, 255, 255, .35); }
}

/* ===== Computadora (pantalla ancha): avatar a la izquierda, opciones en una tarjeta a la derecha ===== */
.perks { display: none; }

@media (min-width: 900px) {
  .app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 30rem);
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: clamp(2rem, 5vw, 5rem);
    max-width: 76rem;
    padding: 0 clamp(1.5rem, 4vw, 3rem);
    background: none;
    box-shadow: none;
  }

  .topbar { grid-column: 1 / -1; padding: 1.5rem 0 .5rem; }
  .brand { font-size: 1.25rem; }
  .brand-ico { width: 34px; height: 34px; border-radius: 11px; }
  .stepcount { font-size: .85rem; }
  .steps { height: 6px; margin-top: .8rem; }

  /* Izquierda: burbuja + avatar grande + sellos de confianza */
  .stage {
    grid-column: 1;
    grid-row: 2;
    justify-content: center;
    padding: 0 0 2rem;
  }
  .speech {
    max-width: 30rem;
    min-height: 5rem;
    margin-bottom: 1.6rem;
    font-size: 1.2rem;
    padding: 1.1rem 1.4rem;
  }
  .hero {
    flex: 0 1 auto;
    height: min(46dvh, 440px);
    min-height: 220px;
    margin-top: 0;
  }
  .perks {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .6rem;
    margin: 1.2rem 0 0;
    padding: 0;
    list-style: none;
  }
  .perks li {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem .9rem;
    border: 1px solid rgba(37, 99, 235, .12);
    border-radius: 9999px;
    background: rgba(255, 255, 255, .75);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    font-size: .85rem;
    font-weight: 600;
    color: rgba(20, 33, 30, .75);
  }
  .perks svg, .perks i { width: 16px; height: 16px; color: var(--brand); }

  /* Derecha: el panel pasa a ser una tarjeta flotante centrada */
  .sheet {
    grid-column: 2;
    grid-row: 2;
    align-self: center;
    max-height: calc(var(--app-h) - 9rem);
    padding: 1.7rem;
    border-radius: 28px;
    background: rgba(255, 255, 255, .92);
    box-shadow: 0 30px 80px -30px rgba(37, 99, 235, .5), 0 0 0 1px rgba(37, 99, 235, .08);
    opacity: 0;
    transform: translateX(40px);
    transition: transform .7s cubic-bezier(.22, 1, .36, 1), opacity .45s ease;
  }
  .sheet.up { opacity: 1; transform: none; }
  /* entre pregunta y pregunta la tarjeta se desvanece en vez de quedar vacía */
  .sheet.up:has(.sheet-body:empty) { opacity: 0; }

  .t-l { font-size: 1.05rem; }
  .field { font-size: 1.2rem; padding: 1.1rem 1.2rem; }
  .cta { padding: 1.1rem; }
}

/* Pantallas anchas pero bajas (notebooks): avatar un poco más chico */
@media (min-width: 900px) and (max-height: 760px) {
  .hero { height: min(40dvh, 320px); min-height: 180px; }
  .speech { font-size: 1.08rem; min-height: 4.2rem; margin-bottom: 1rem; }
  .perks { margin-top: .8rem; }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .mesh span, .floaters span, .ecg path, .a-bob, .a-shadow, .a-body, .a-eye, .a-spark { animation: none !important; }
  .avatar { opacity: 1; transform: none; animation: none !important; }
  .speech, .speech .w, .tile { opacity: 1; transform: none; animation: none !important; }
  .sheet { transition: none; }
}
