/*
 * Diseño alineado con /diagnostico de carochaparro.co: tipografía, colores,
 * contador, opciones y botones. Propio de este formulario: las texturas de fondo
 * (papel arrugado + cuadrícula por esquina) y la transición del círculo.
 */

:root {
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Poppins", Arial, sans-serif;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --gutter: clamp(20px, 4vw, 56px);
  --gold: #f3cc56;

  --paper-light: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='720' height='720'%3E%3Cfilter id='p' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.011 0.017' numOctaves='6' seed='11' stitchTiles='stitch'/%3E%3CfeDiffuseLighting lighting-color='%23fff' surfaceScale='7'%3E%3CfeDistantLight azimuth='225' elevation='58'/%3E%3C/feDiffuseLighting%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23p)'/%3E%3C/svg%3E");
  --paper-dark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='720' height='720'%3E%3Cfilter id='p' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.011 0.017' numOctaves='6' seed='11' stitchTiles='stitch'/%3E%3CfeDiffuseLighting lighting-color='%23fff' surfaceScale='7'%3E%3CfeDistantLight azimuth='225' elevation='30'/%3E%3C/feDiffuseLighting%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23p)'/%3E%3C/svg%3E");
}

/* ---------- Temas: claro y morado (mismos valores que /diagnostico) ---------- */

body,
body[data-theme="light"] {
  --ink: #1d123e;
  --muted: #665f7b;
  --purple: #6220c9;
  --line: rgba(78, 43, 138, 0.18);
  --option-bg: rgba(255, 255, 255, 0.43);
  --field-bg: rgba(255, 255, 255, 0.66);
  --field-ink: #24183f;
  --btn-bg: #281044;
  --btn-fg: #ffffff;
  --danger: #b32855;
  --logo-filter: none;
  --bg: radial-gradient(circle at 13% 12%, rgba(139, 89, 236, 0.17), transparent 30%),
    radial-gradient(circle at 82% 86%, rgba(190, 148, 255, 0.22), transparent 33%),
    linear-gradient(145deg, #fff 0%, #f8f4ff 55%, #eee7ff 100%);
  --grid-line: rgba(98, 32, 201, 0.1);
  --paper-img: var(--paper-light);
  --paper-blend: multiply;
  --paper-opacity: 0.2;
  --grain-opacity: 0.05;
}

body[data-theme="dark"] {
  --ink: #fffaff;
  --muted: #d7cbe9;
  --purple: #c68dff;
  --line: rgba(255, 255, 255, 0.18);
  --option-bg: rgba(255, 255, 255, 0.055);
  --field-bg: rgba(255, 255, 255, 0.07);
  --field-ink: #fffaff;
  --btn-bg: #c68dff;
  --btn-fg: #1d123e;
  --danger: #ffb3c7;
  --logo-filter: brightness(0) invert(1);
  --bg: radial-gradient(circle at 16% 8%, rgba(166, 99, 255, 0.32), transparent 33%),
    radial-gradient(circle at 86% 92%, rgba(96, 34, 171, 0.4), transparent 34%),
    linear-gradient(145deg, #130722 0%, #261046 48%, #170a31 100%);
  --grid-line: rgba(255, 255, 255, 0.1);
  --paper-img: var(--paper-dark);
  --paper-blend: soft-light;
  --paper-opacity: 0.8;
  --grain-opacity: 0.1;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 4px;
}

/* ---------- Texturas de fondo (propias de este formulario) ---------- */

.top,
.stage {
  position: relative;
  z-index: 1;
}

.top {
  grid-row: 1;
}

.stage {
  grid-row: 2;
}

.tex {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  animation: tex-in 600ms ease both;
}

@keyframes tex-in {
  from {
    opacity: 0;
  }
}

/* Cuadrícula de líneas finas que se desvanece desde una esquina. */
.tex-grid {
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: var(--cell, 32px) var(--cell, 32px);
  background-position: var(--gx, 100%) var(--gy, 0%);
  -webkit-mask-image: radial-gradient(
    circle at var(--gx, 100%) var(--gy, 0%),
    #000 0%,
    rgba(0, 0, 0, 0.55) calc(var(--gr, 38vmax) * 0.45),
    transparent var(--gr, 38vmax)
  );
  mask-image: radial-gradient(
    circle at var(--gx, 100%) var(--gy, 0%),
    #000 0%,
    rgba(0, 0, 0, 0.55) calc(var(--gr, 38vmax) * 0.45),
    transparent var(--gr, 38vmax)
  );
}

/* Papel arrugado que se funde desde la esquina opuesta. */
.tex-paper {
  background-image: var(--paper-img);
  background-size: 720px 720px;
  mix-blend-mode: var(--paper-blend);
  opacity: var(--paper-opacity);
  -webkit-mask-image: radial-gradient(
    ellipse at var(--px, 0%) var(--py, 100%),
    #000 0%,
    rgba(0, 0, 0, 0.6) calc(var(--pr, 60vmax) * 0.5),
    transparent var(--pr, 60vmax)
  );
  mask-image: radial-gradient(
    ellipse at var(--px, 0%) var(--py, 100%),
    #000 0%,
    rgba(0, 0, 0, 0.6) calc(var(--pr, 60vmax) * 0.5),
    transparent var(--pr, 60vmax)
  );
}

/* Grano muy fino en toda la pantalla. */
.tex-grain {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: 220px 220px;
  mix-blend-mode: overlay;
  opacity: var(--grain-opacity);
}

/* Portada: todo el fondo es papel arrugado y la cuadrícula morada queda arriba a la derecha. */
body[data-tex="0"] {
  --grid-line: rgba(98, 32, 201, 0.2);
}

body[data-tex="0"] .tex-paper {
  -webkit-mask-image: none;
  mask-image: none;
}

/* Una composición distinta por pantalla (portada, 7 preguntas y cierre). */
body[data-tex="0"] { --gx: 100%; --gy: 0%;   --gr: 42vmax; --cell: 36px; --px: 0%;   --py: 100%; --pr: 62vmax; }
body[data-tex="1"] { --gx: 0%;   --gy: 0%;   --gr: 36vmax; --cell: 28px; --px: 100%; --py: 100%; --pr: 58vmax; }
body[data-tex="2"] { --gx: 100%; --gy: 100%; --gr: 40vmax; --cell: 44px; --px: 0%;   --py: 0%;   --pr: 55vmax; }
body[data-tex="3"] { --gx: 0%;   --gy: 100%; --gr: 34vmax; --cell: 24px; --px: 100%; --py: 0%;   --pr: 64vmax; }
body[data-tex="4"] { --gx: 100%; --gy: 0%;   --gr: 30vmax; --cell: 20px; --px: 0%;   --py: 100%; --pr: 70vmax; }
body[data-tex="5"] { --gx: 50%;  --gy: 0%;   --gr: 34vmax; --cell: 40px; --px: 100%; --py: 100%; --pr: 52vmax; }
body[data-tex="6"] { --gx: 0%;   --gy: 0%;   --gr: 44vmax; --cell: 32px; --px: 100%; --py: 60%;  --pr: 56vmax; }
body[data-tex="7"] { --gx: 100%; --gy: 100%; --gr: 32vmax; --cell: 26px; --px: 0%;   --py: 0%;   --pr: 66vmax; }
body[data-tex="8"] { --gx: 0%;   --gy: 100%; --gr: 46vmax; --cell: 48px; --px: 100%; --py: 0%;   --pr: 60vmax; }

/* ---------- Transición: círculo que crece desde el botón ---------- */

.wipe {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  will-change: clip-path;
}

/* ---------- Progreso (como /diagnostico) ---------- */

.progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 50;
  height: 4px;
  background: rgba(105, 71, 163, 0.12);
}

.progress-fill {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #7a35d9, #c28aff);
  transition: width 360ms ease;
}

/* ---------- Cabecera ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px var(--gutter);
}

.brand img {
  display: block;
  height: 46px;
  width: auto;
  filter: var(--logo-filter);
}

.lang {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.lang button {
  background: none;
  border: 0;
  padding: 4px 2px;
  color: var(--muted);
  letter-spacing: inherit;
}

.lang button[aria-pressed="true"] {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 5px;
  text-decoration-thickness: 1.5px;
}

/* ---------- Escena ---------- */

.stage {
  display: grid;
  place-items: center;
  padding: 16px 20px 40px;
}

.screen {
  width: min(100%, 820px);
}

.screen:focus {
  outline: none;
}

/* Entrada escalonada: cada bloque (y cada opción) aparece uno tras otro. */
.screen > *,
.opt {
  animation: rise 300ms var(--ease) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}

.screen > .options {
  animation: none;
}

.screen.from-top > *,
.screen.from-top .opt {
  animation-name: drop;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
}

@keyframes drop {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
}

/* Contador "01 DE 07": el número actual en morado, el total apagado. */
.meta {
  display: flex;
  gap: 12px;
  color: var(--purple);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.17em;
}

.meta span:last-child {
  color: var(--muted);
}

.question {
  max-width: 26ch;
  margin: 12px 0 20px;
  font-family: var(--serif);
  font-size: clamp(2rem, 3.4vw, 3.2rem);
  font-weight: 600;
  letter-spacing: -0.045em;
  line-height: 0.98;
  color: var(--ink);
  outline: none;
}

.lead {
  max-width: 680px;
  margin: 22px auto 0;
  color: var(--muted);
  font-size: clamp(0.95rem, 1.6vw, 1.08rem);
  line-height: 1.8;
}

/* ---------- Portada y cierre: centrados ---------- */

.intro,
.done {
  width: min(100%, 1000px);
  text-align: center;
}

.intro .question {
  max-width: none;
  margin: 0 auto;
  font-size: clamp(2.6rem, 1rem + 6.4vw, 6rem);
  line-height: 0.95;
  white-space: nowrap;
}

.intro .question em {
  font-style: normal;
  color: var(--purple);
}

.intro .actions,
.done .actions {
  justify-content: center;
  margin-top: 30px;
}

.done .question {
  max-width: 18ch;
  margin: 0 auto;
  font-size: clamp(2.7rem, 6vw, 5.5rem);
  line-height: 0.95;
}

.hint {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.hint kbd {
  font-family: inherit;
  font-weight: 700;
  color: var(--ink);
}

@media (hover: none) {
  .hint {
    display: none;
  }
}

/* ---------- Campos (como /diagnostico) ---------- */

.field {
  max-width: 560px;
}

.input,
.textarea,
.select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field-bg);
  color: var(--field-ink);
  padding: 15px 17px;
  font-size: 0.95rem;
  outline-offset: 3px;
  transition:
    border-color 160ms ease,
    outline-color 160ms ease;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--purple);
  outline: 2px solid rgba(111, 46, 211, 0.18);
}

.textarea {
  resize: none;
  min-height: 7.5em;
  max-height: 40vh;
  line-height: 1.6;
}

.phone {
  display: grid;
  grid-template-columns: 122px minmax(0, 1fr);
  gap: 9px;
}

.select {
  appearance: none;
  padding-right: 30px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    right 16px center,
    right 11px center;
  background-size:
    5px 5px,
    5px 5px;
  background-repeat: no-repeat;
  background-color: var(--field-bg);
  font-variant-numeric: tabular-nums;
}

.select option {
  color: #1d123e;
  background: #ffffff;
}

/* ---------- Opciones (idénticas a /diagnostico) ---------- */

.options {
  display: grid;
  gap: 8px;
}

.opt {
  display: grid;
  grid-template-columns: 34px 1fr 20px;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 61px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 10px 15px;
  background: var(--option-bg);
  color: var(--ink);
  text-align: left;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease,
    box-shadow 160ms ease;
}

.opt:hover {
  border-color: var(--purple);
  transform: translateX(3px);
}

.opt[aria-checked="true"] {
  border-color: var(--purple);
  background: rgba(134, 66, 220, 0.13);
  box-shadow: 0 9px 24px rgba(49, 20, 98, 0.12);
}

.opt-key {
  display: grid;
  width: 29px;
  height: 29px;
  border: 1px solid currentColor;
  border-radius: 50%;
  place-items: center;
  color: var(--purple);
  font-size: 0.69rem;
  font-weight: 700;
}

.opt-copy {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
}

.opt-check {
  display: grid;
  width: 21px;
  height: 21px;
  border: 1px solid var(--line);
  border-radius: 50%;
  place-items: center;
  color: transparent;
  transition:
    background 160ms ease,
    border-color 160ms ease;
}

.opt[aria-checked="true"] .opt-check {
  border-color: var(--purple);
  background: var(--purple);
  color: #fff;
}

body[data-theme="dark"] .opt[aria-checked="true"] .opt-check {
  color: #1d123e;
}

/* ---------- Botones (como /diagnostico) ---------- */

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 12px 21px;
  font-size: 0.8rem;
  font-weight: 700;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.btn .icon {
  display: inline-flex;
}

.btn:hover:not(:disabled) {
  box-shadow: 0 10px 23px rgba(59, 24, 122, 0.17);
  transform: translateY(-2px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.btn-primary {
  min-width: 205px;
  background: var(--btn-bg);
  color: var(--btn-fg);
}

.btn-ghost {
  border-color: var(--line);
  background: transparent;
  color: var(--ink);
}

.error {
  min-height: 1.3em;
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 0.78rem;
}

/* ---------- Varios ---------- */

.hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.noscript {
  max-width: 640px;
  margin: 0 auto;
  font-family: var(--serif);
  font-size: 1.8rem;
}

@media (max-width: 620px) {
  .tex-paper {
    opacity: calc(var(--paper-opacity) * 0.55);
  }
  body[data-tex="0"] .tex-paper {
    opacity: var(--paper-opacity);
  }
  .brand img {
    height: 36px;
  }
  .stage {
    place-items: start center;
    padding: 6vh 16px 24px;
  }
  .question {
    max-width: 23ch;
    margin: 10px 0 18px;
    font-size: clamp(1.95rem, 9.2vw, 2.7rem);
    line-height: 1;
  }
  .intro .question {
    font-size: clamp(2.3rem, 11vw, 3.4rem);
  }
  .options {
    gap: 7px;
  }
  .opt {
    grid-template-columns: 29px 1fr 17px;
    gap: 9px;
    min-height: 57px;
    padding: 9px 11px;
  }
  .opt-key {
    width: 25px;
    height: 25px;
    font-size: 0.64rem;
  }
  .opt-copy {
    font-size: 0.78rem;
  }
  .btn {
    min-height: 45px;
    padding: 10px 16px;
    font-size: 0.74rem;
  }
  .btn-primary {
    min-width: unset;
  }
  .intro .btn-primary {
    width: 100%;
  }
  .phone {
    grid-template-columns: 104px 1fr;
  }
}

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