:root {
  --fondo: #f4f1ec; --tarjeta: #ffffff; --texto: #1d2329; --suave: #66707a;
  --acento: #2f7d6d; --acento-texto: #ffffff; --error: #b3261e; --borde: #e3ded6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #0f1720; --tarjeta: #18222d; --texto: #e6edf3; --suave: #93a1ad;
    --acento: #4fb39d; --acento-texto: #0b1a16; --error: #f2938c; --borde: #263341;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100dvh; display: grid; place-items: center; padding: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--fondo); color: var(--texto);
}
.tarjeta {
  width: 100%; max-width: 380px; background: var(--tarjeta); border: 1px solid var(--borde);
  border-radius: 20px; padding: 32px 24px; text-align: center;
}
.icono { font-size: 3.2rem; line-height: 1; }
h1 { font-size: 1.5rem; margin: 16px 0 8px; }
p { color: var(--suave); margin: 0 0 24px; line-height: 1.45; }
button {
  width: 100%; border: 0; border-radius: 14px; padding: 16px; font-size: 1.05rem; font-weight: 600;
  background: var(--acento); color: var(--acento-texto); cursor: pointer;
}
button:disabled { opacity: .6; }
button.secundario { background: transparent; color: var(--suave); font-weight: 500; margin-top: 8px; }
.error { color: var(--error); min-height: 1.4em; margin: 16px 0 0; }
[hidden] { display: none !important; }

/* ---------- Chat ---------- */
:root {
  --mio: #d9f2e6; --mio-texto: #10241d; --suyo: #ffffff; --leido: #2b8ae2; --leny: #f1ecff; --leny-nombre: #6a4bc4;
  --fondo-chat: #ece6dc; --sombra: 0 1px 1px rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root { --mio: #1f5a4c; --mio-texto: #e8f6f1; --suyo: #1f2b37; --leido: #6cb8ff; --fondo-chat: #0c131a; --sombra: none; --leny: #2a2445; --leny-nombre: #b9a4ff; }
}
#chat {
  position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--fondo-chat);
  height: 100dvh;
}
.cabecera {
  display: flex; align-items: center; gap: 12px; background: var(--tarjeta); border-bottom: 1px solid var(--borde);
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--acento); color: var(--acento-texto);
  display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; flex: none;
}
.quien { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.quien strong { font-size: 1.05rem; }
.quien small { color: var(--suave); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quien small.activo { color: var(--acento); font-weight: 600; }
.icono-boton {
  width: auto; background: transparent; color: var(--suave); padding: 8px 10px; font-size: 1.3rem; border-radius: 10px;
}
.aviso {
  background: #fff4d6; color: #5c4700; text-align: center; font-size: .9rem; padding: 6px 12px;
}
@media (prefers-color-scheme: dark) { .aviso { background: #3a3215; color: #f3e2a6; } }
.avisos {
  display: flex; align-items: center; gap: 10px; background: var(--tarjeta); border-bottom: 1px solid var(--borde);
  padding: 8px 6px 8px 14px; font-size: .92rem; line-height: 1.35;
}
.avisos span { flex: 1; }
.avisos button:not(.icono-boton) { width: auto; padding: 8px 14px; flex: none; }
.avisos .icono-boton { font-size: 1rem; flex: none; }
.lista { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 8px 10px 12px; -webkit-overflow-scrolling: touch; }
.mas, .vacio { text-align: center; color: var(--suave); font-size: .9rem; padding: 12px; }
.vacio { margin: 30vh auto 0; max-width: 300px; line-height: 1.45; }
.dia {
  width: fit-content; margin: 14px auto 8px; padding: 4px 12px; border-radius: 10px; font-size: .8rem;
  background: var(--tarjeta); color: var(--suave); box-shadow: var(--sombra);
}
.dia::first-letter { text-transform: uppercase; }
.msg { display: flex; flex-direction: column; margin: 2px 0; }
.msg.mio { align-items: flex-end; }
.msg.suyo { align-items: flex-start; }
.burbuja {
  max-width: min(80%, 560px); padding: 7px 10px 6px; border-radius: 16px; box-shadow: var(--sombra);
  overflow-wrap: anywhere; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.mio .burbuja { background: var(--mio); color: var(--mio-texto); border-bottom-right-radius: 5px; }
.suyo .burbuja { background: var(--suyo); color: var(--texto); border-bottom-left-radius: 5px; }
.bot .burbuja { background: var(--leny); }
.burbuja .autor { font-size: .78rem; font-weight: 700; color: var(--leny-nombre); margin-bottom: 2px; }
.texto { white-space: pre-wrap; line-height: 1.38; font-size: 1rem; }
.texto a { color: inherit; text-decoration: underline; }
.borrado .texto { font-style: italic; opacity: .65; }
.pie { display: block; text-align: right; font-size: .7rem; opacity: .65; margin-top: 2px; }
.marca.leido { color: var(--leido); opacity: 1; font-weight: 700; }
.cita {
  display: flex; flex-direction: column; border-left: 3px solid var(--acento); background: rgba(0,0,0,.05);
  border-radius: 8px; padding: 4px 8px; margin-bottom: 4px; font-size: .85rem;
}
.cita strong { color: var(--acento); font-size: .8rem; }
.cita span { opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.reacciones {
  margin-top: -6px; padding: 2px 7px; background: var(--tarjeta); border: 1px solid var(--borde);
  border-radius: 12px; font-size: .85rem; box-shadow: var(--sombra); z-index: 1;
}
.mio .reacciones { margin-right: 8px; }
.suyo .reacciones { margin-left: 8px; }
.fallo .burbuja { outline: 2px solid var(--error); }
.fallo .pie::after { content: ' · ⚠️ toca para reintentar'; }
.resaltado .burbuja { animation: resaltar 1.4s ease; }
@keyframes resaltar { 0%, 60% { filter: brightness(.82); } 100% { filter: none; } }
.bajar {
  position: absolute; right: 14px; bottom: calc(84px + env(safe-area-inset-bottom)); width: 44px; height: 44px;
  border-radius: 50%; padding: 0; background: var(--tarjeta); color: var(--texto); border: 1px solid var(--borde);
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.redactar { background: var(--tarjeta); border-top: 1px solid var(--borde); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
.contexto {
  display: flex; align-items: center; gap: 8px; border-left: 3px solid var(--acento); background: var(--fondo);
  border-radius: 10px; padding: 6px 4px 6px 10px; margin-bottom: 8px;
}
.contexto > div { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: .88rem; }
.contexto small { color: var(--acento); font-weight: 600; }
.contexto span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--suave); }
.fila { display: flex; align-items: flex-end; gap: 8px; }
.fila textarea {
  flex: 1; resize: none; border: 1px solid var(--borde); border-radius: 22px; padding: 11px 16px; font: inherit;
  font-size: 1rem; line-height: 1.3; background: var(--fondo); color: var(--texto); max-height: 140px; outline: none;
}
.fila textarea:focus { border-color: var(--acento); }
.enviar { width: 46px; height: 46px; flex: none; border-radius: 50%; padding: 0; font-size: 1.15rem; }
.velo { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; }
.hoja {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; background: var(--tarjeta); border-radius: 20px 20px 0 0;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); max-width: 560px; margin: 0 auto;
  animation: subir .18s ease-out;
}
@keyframes subir { from { transform: translateY(30%); opacity: .4; } }
.reacciones-elegir { display: flex; justify-content: space-around; }
.reacciones-elegir:not(:empty) { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--borde); }
.reacciones-elegir button {
  width: 48px; height: 48px; padding: 0; font-size: 1.6rem; background: transparent; border-radius: 50%;
}
.reacciones-elegir button.elegido { background: var(--fondo); outline: 2px solid var(--acento); }
.accion {
  display: block; text-align: left; background: transparent; color: var(--texto); font-weight: 500; padding: 14px 8px;
  border-radius: 10px;
}
.accion.peligro { color: var(--error); }
/* Fotos y vídeos */
.adjuntar { width: 46px; height: 46px; flex: none; border-radius: 50%; padding: 0; font-size: 1.25rem; background: transparent; color: var(--suave); }
.burbuja.con-media { padding: 4px 4px 6px; }
.burbuja.con-media .texto, .burbuja.con-media .pie, .burbuja.con-media .cita { margin-left: 6px; margin-right: 6px; }
.burbuja.con-media .cita { margin-top: 2px; }
.media {
  position: relative; width: min(68vw, 300px); max-height: 380px; border-radius: 12px; overflow: hidden;
  background: rgba(0,0,0,.08); margin-bottom: 4px;
}
.media img, .media video { display: block; width: 100%; height: 100%; object-fit: cover; }
.media .play {
  position: absolute; inset: 0; margin: auto; width: 54px; height: 54px; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; font-size: 1.4rem; padding-left: 4px;
}
.media .duracion {
  position: absolute; left: 8px; bottom: 6px; color: #fff; font-size: .75rem; font-weight: 600;
  background: rgba(0,0,0,.5); border-radius: 8px; padding: 1px 6px;
}
.media .icono-archivo { display: grid; place-items: center; height: 100%; font-size: 2.4rem; }
.subida .burbuja { cursor: default; }
.subida .nombre { font-size: .85rem; margin: 2px 6px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: min(68vw, 300px); }
.barra { height: 5px; border-radius: 3px; background: rgba(0,0,0,.12); margin: 6px 6px 2px; overflow: hidden; }
.barra > div { height: 100%; background: var(--acento); width: 0; transition: width .3s; }
.subida .estado-subida { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: .75rem; opacity: .8; margin: 0 2px 0 6px; }
.subida .estado-subida button { width: auto; padding: 2px 8px; background: transparent; color: inherit; font-size: .95rem; }
.subida.error .estado-subida { color: var(--error); opacity: 1; }
.visor { position: fixed; inset: 0; z-index: 20; background: #000; color: #fff; display: flex; flex-direction: column; }
.visor-barra {
  display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  background: rgba(0,0,0,.6); font-size: .85rem;
}
.visor-barra span { flex: 1; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.visor-barra .icono-boton { color: #fff; }
.visor-descargar { color: #fff; text-decoration: none; border: 1px solid rgba(255,255,255,.5); border-radius: 18px; padding: 7px 14px; font-weight: 600; white-space: nowrap; }
.visor-contenido { flex: 1; min-height: 0; display: grid; place-items: center; padding-bottom: env(safe-area-inset-bottom); }
.visor-contenido img, .visor-contenido video { max-width: 100%; max-height: 100%; object-fit: contain; }
.visor-contenido p { padding: 24px; text-align: center; line-height: 1.5; }
.nota { color: var(--suave); font-size: .88rem; line-height: 1.4; margin: 14px 0 0; }
/* Efectos: stickers vivos, zumbido y regalo (los dibujos están en efectos.css) */
.msg.sticker .burbuja { background: transparent; box-shadow: none; padding: 0; }
.msg.sticker .pie { color: var(--suave); opacity: .9; }
.msg.sistema { align-items: center; margin: 8px 0; }
.msg.sistema .burbuja {
  background: var(--tarjeta); color: var(--suave); border: 1px solid var(--borde); box-shadow: none;
  font-size: .85rem; border-radius: 12px; padding: 4px 12px; cursor: default;
}
.msg.sistema .pie { display: inline; font-size: .7rem; }
.regalo .burbuja .ef-mini { margin: 4px auto; }
.regalo-titulo { font-weight: 700; font-size: .85rem; margin-bottom: 2px; }
.regalo .burbuja .texto.regalo-titulo { font-size: 1rem; text-align: center; }
.regalo-estado { font-size: .72rem; opacity: .75; margin-top: 3px; }
.bandeja { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; }
.bandeja button {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 2px; border-radius: 14px;
  background: var(--fondo); color: var(--texto); font-weight: 500;
}
.bandeja .icono-efecto { font-size: 1.9rem; line-height: 1.1; }
.bandeja small { font-size: .72rem; color: var(--suave); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.fila .adjuntar + .adjuntar { margin-left: -8px; }
/* Mientras la animación está en pantalla, la burbuja espera (aparece cuando «aterriza» el sticker) */
.msg.tarea:has(.ef-esperando), .msg.sticker:has(.ef-esperando) .pie { visibility: hidden; }
.msg.tarea .ef-mini.ef-emoji { font-size: 44px; }
