@import url('/fonts/satoshi.css');

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

:root {
  --bg: #7a1f1c;
  --fg: #ffffff;
  --muted: rgba(255,255,255,.6);
  --accent: #5b2470;
  --ease: cubic-bezier(.22,1,.36,1);
}

html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Satoshi', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* El fondo cambia de color por pregunta: cada pantalla puede tener su arte. */
#stage {
  position: fixed; inset: 0;
  height: 100dvh;
  background: var(--bg); color: var(--fg);
  transition: background-color .9s var(--ease);
  overflow: hidden;
}

/* ---------- Forma animada de fondo ---------- */
#shape {
  position: absolute; left: -30%; bottom: -55%;
  width: 180%; height: 125%;
  background: var(--accent);
  transform: translate3d(0, 110%, 0) rotate(-9deg);
  transform-origin: 0 100%;
  will-change: transform;
  transition: transform 1.1s var(--ease), background-color .9s var(--ease),
              border-radius .9s var(--ease);
  pointer-events: none;
}
#shape.in    { transform: translate3d(0, 32%, 0) rotate(-9deg); }
#shape.wave  { border-radius: 46% 54% 0 0 / 22% 26% 0 0; }
#shape.circle{ border-radius: 50%; left: -10%; width: 120%; height: 120%; }
#shape.circle.in { transform: translate3d(0, 45%, 0) rotate(0deg); }
#shape.none  { opacity: 0; }

/* ---------- Barra de progreso ---------- */
#progress {
  position: absolute; top: 0; left: 0; height: 3px; width: 0;
  background: var(--fg); opacity: .85; z-index: 6;
  transition: width .6s var(--ease);
}

/* ---------- Cromo ---------- */
#logo {
  position: absolute; right: 26px; height: 34px; z-index: 6;
  top: calc(22px + env(safe-area-inset-top));
  opacity: 0; transform: translateY(-6px);
  transition: opacity .6s var(--ease), transform .6s var(--ease);
}
#logo.show { opacity: 1; transform: none; }

#mic {
  position: absolute; right: 22px; z-index: 6;
  bottom: calc(22px + env(safe-area-inset-bottom));
  width: 48px; height: 48px; border: 0; border-radius: 50%;
  background: rgba(255,255,255,.14); color: var(--fg);
  display: none; place-items: center; cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background-color .25s, transform .25s var(--ease);
}
#mic.show { display: grid; }
#mic:focus-visible, #back:focus-visible, .btn:focus-visible, .opt:focus-visible,
.answer:focus-visible { outline: 3px solid rgba(255,255,255,.85); outline-offset: 3px; }
#mic:hover { background: rgba(255,255,255,.24); transform: scale(1.06); }
#mic.rec { background: #fff; color: var(--bg); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 12px rgba(255,255,255,.14); } }

#back {
  position: absolute; left: 22px; z-index: 6;
  bottom: calc(24px + env(safe-area-inset-bottom));
  border: 0; cursor: pointer;
  background: rgba(255,255,255,.1); border-radius: 999px;
  color: rgba(255,255,255,.8);
  font: inherit; font-size: .82rem; letter-spacing: .02em;
  padding: .6rem 1.05rem; min-height: 44px;
  display: none; align-items: center; gap: .45rem;
  transition: color .2s, background-color .2s;
}
#back.show { display: flex; }
#back:hover { color: var(--fg); background: rgba(255,255,255,.2); }

/* ---------- Contenido ---------- */
#view {
  position: relative; z-index: 4;
  height: 100%; display: flex; align-items: center;
  padding: 0 clamp(1.4rem, 6vw, 4rem);
  overflow-y: auto; overscroll-behavior: contain;
}
/* Con el teclado abierto hay poco alto: el contenido se ancla arriba y respira. */
@media (max-height: 560px) {
  /* El logo se quita: con tan poco alto se encimaría con la pregunta. */
  #logo { display: none !important; }
  #view { align-items: flex-start; padding-top: 1.2rem; padding-bottom: 5rem; }
  .q-text { font-size: clamp(1.15rem, 5vw, 1.4rem); }
  .answer { font-size: clamp(1.15rem, 5vw, 1.4rem); }
  .opts { margin-top: 1rem; gap: .45rem; }
  .opt { padding: .6rem 1rem; min-height: 44px; }
  #back { bottom: calc(12px + env(safe-area-inset-bottom)); }
  #mic { bottom: calc(12px + env(safe-area-inset-bottom)); }
  .cover h1 { font-size: clamp(1.8rem, 7vw, 2.4rem); margin-bottom: .9rem; }
  .cover p { font-size: .98rem; }
}
.pane { width: 100%; max-width: 46rem; margin: 0 auto; }

/* Pregunta con foto: dos columnas en pantallas anchas, apilado en móvil. */
.pane.with-photo {
  max-width: 64rem;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 22rem);
  gap: clamp(1.5rem, 4vw, 3.5rem); align-items: center;
}
.q-col { min-width: 0; }

.photo {
  margin: 0; min-width: 0;
  opacity: 0; transform: translate3d(0, 22px, 0) scale(.97);
  transition: opacity .7s var(--ease) .15s, transform .7s var(--ease) .15s;
}
.photo.in { opacity: 1; transform: none; }
.photo picture { display: block; }
.photo img {
  display: block; width: 100%; height: auto;
  max-height: 62vh; object-fit: cover;
  border-radius: 16px;
  box-shadow: 0 18px 45px rgba(0,0,0,.28);
}
.photo figcaption {
  margin-top: .6rem; font-size: .78rem; line-height: 1.35;
  color: var(--muted); letter-spacing: .01em;
}

@media (max-width: 860px) {
  .pane.with-photo { grid-template-columns: 1fr; gap: 1.3rem; max-width: 46rem; }
  /* En vertical la foto va después de la pregunta, sin robarle sitio a la respuesta. */
  .photo { order: 2; }
  .photo img { max-height: 30vh; border-radius: 12px; }
  .photo figcaption { margin-top: .45rem; font-size: .72rem; }
}
@media (max-height: 560px) {
  .photo { display: none; }   /* con el teclado abierto, manda el campo */
}

.enter { animation: rise .55s var(--ease) both; }
.leave { animation: fall .32s var(--ease) both; pointer-events: none; }
@keyframes rise { from { opacity: 0; transform: translate3d(0,18px,0); } }
@keyframes fall { to   { opacity: 0; transform: translate3d(0,-14px,0); } }

/* Portada */
.cover h1 {
  margin: 0 0 1.6rem; font-weight: 700; letter-spacing: -.025em;
  font-size: clamp(2.4rem, 6.6vw, 4.2rem); line-height: 1.02;
}
.cover p { margin: 0 0 1rem; font-size: clamp(1rem, 2.1vw, 1.25rem); line-height: 1.5; color: rgba(255,255,255,.9); font-weight: 400; }
.cover .actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 2.2rem; }

.btn {
  font: inherit; font-weight: 500; font-size: 1rem;
  padding: .85rem 1.6rem; border-radius: 999px; cursor: pointer;
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.08); color: var(--fg);
  transition: background-color .22s, transform .22s var(--ease), border-color .22s;
}
.btn:hover { background: rgba(255,255,255,.2); transform: translateY(-2px); }
.btn.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.btn .flag { margin-right: .5rem; }
.btn.primary:hover { background: #fff; }

/* Pregunta */
.q-text {
  font-size: clamp(1.35rem, 3.1vw, 2rem); font-weight: 400;
  line-height: 1.28; letter-spacing: -.012em; margin: 0 0 .35rem;
  min-height: 1.28em; white-space: pre-wrap;
}
.caret {
  display: inline-block; width: 2px; height: 1.05em; margin-left: 1px;
  background: var(--fg); vertical-align: -.16em;
  animation: blink 1.05s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.q-help { color: var(--muted); font-size: .95rem; margin: .5rem 0 0; }

/* Input sin caja: es lo que hace que no parezca formulario. */
.answer {
  width: 100%; margin-top: 1.1rem;
  font: inherit; font-size: clamp(1.35rem, 3.1vw, 2rem); font-weight: 400;
  line-height: 1.3; color: var(--fg);
  background: none; border: 0; border-radius: 0; outline: none;
  padding: 0; resize: none; overflow: hidden;
  caret-color: var(--fg);
}
.answer::placeholder { color: rgba(255,255,255,.45); }
.answer:-webkit-autofill { -webkit-text-fill-color: var(--fg); transition: background-color 9999s; }

.hint { margin-top: 1.5rem; font-size: .8rem; color: var(--muted); letter-spacing: .02em; }
.go {
  display: none; margin-top: 1.4rem; align-items: center; gap: .55rem; min-height: 48px;
  font: inherit; font-weight: 500; font-size: 1rem;
  padding: .8rem 1.5rem; border-radius: 999px; cursor: pointer;
  background: var(--fg); color: var(--bg); border: 0;
}
body.touch .go { display: inline-flex; }
body.touch .hint { display: none; }
.hint kbd {
  font: inherit; font-size: .74rem; padding: .12rem .42rem; border-radius: 5px;
  background: rgba(255,255,255,.16); border: 0;
}
.err {
  margin-top: .9rem; font-size: .9rem; font-weight: 500;
  color: var(--bg); background: rgba(255,255,255,.92);
  display: inline-block; padding: .4rem .8rem; border-radius: 8px;
  animation: shake .35s;
}
@keyframes shake { 25% { transform: translateX(-5px);} 75% { transform: translateX(5px);} }

/* Opciones */
.opts { list-style: none; margin: 1.4rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .55rem; align-items: flex-start; }
.opts li { max-width: 100%; }
.opt {
  display: flex; align-items: center; gap: .8rem; text-align: left; min-height: 48px;
  font: inherit; font-size: clamp(1rem, 2.1vw, 1.15rem);
  padding: .8rem 1.1rem; border-radius: 12px; cursor: pointer;
  color: var(--fg); background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.22);
  transition: background-color .2s, transform .2s var(--ease), border-color .2s;
  animation: rise .45s var(--ease) both; animation-delay: calc(var(--i) * 55ms + .1s);
}
.opt:hover, .opt.focus { background: rgba(255,255,255,.18); transform: translateX(4px); }
.opt.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.opt .k {
  flex: none; width: 1.5rem; height: 1.5rem; border-radius: 6px;
  display: grid; place-items: center; font-size: .72rem; font-weight: 700;
  background: rgba(255,255,255,.18);
}
.opt.on .k { background: rgba(0,0,0,.12); }

/* Escala */
.scale { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.4rem; }
.scale button {
  font: inherit; width: 3rem; height: 3rem; min-width: 48px; min-height: 48px; border-radius: 12px; cursor: pointer;
  color: var(--fg); background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.22);
  transition: background-color .2s, transform .2s var(--ease);
  animation: rise .4s var(--ease) both; animation-delay: calc(var(--i) * 40ms + .1s);
}
.scale button:hover { background: rgba(255,255,255,.2); transform: translateY(-3px); }

/* Final */
.done h2 { font-size: clamp(1.9rem, 4.4vw, 3rem); font-weight: 700; letter-spacing: -.02em; margin: 0 0 1rem; }
.done p  { font-size: 1.1rem; color: rgba(255,255,255,.88); margin: 0; line-height: 1.5; }
.check {
  width: 54px; height: 54px; margin-bottom: 1.6rem; border-radius: 50%;
  display: grid; place-items: center; background: rgba(255,255,255,.16);
  animation: pop .5s var(--ease) both;
}
@keyframes pop { from { transform: scale(.4); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, #shape, #stage { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
