/* ETHOS · entrada (login, invitación, nueva contraseña, instalar).
 *
 * Va después de tokens.css y ethos.css, solo en las pantallas de acceso.
 * Todo son tokens: ningún hex nuevo salvo los de la paleta del Brain, que
 * están en los shaders de la intro y aquí en los degradados del aro.
 *
 * Piezas:
 *   e-acceso*   layout y tarjeta de acceso (vidrio, filo de luz, marca)
 *   e-orbita*   la escena viva de detrás (órbitas y satélites; la monta entrada.js)
 *   e-intro*    la capa de la intro del login (la monta entrada-intro.js)
 */

/* ════════════════════════════════════════════════════════════════════════
   1. Layout y tarjeta
   ════════════════════════════════════════════════════════════════════════ */

.e-acceso {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: clamp(20px, 5vh, 56px) 16px calc(24px + env(safe-area-inset-bottom, 0px));
}
.e-acceso__col {
  width: min(100%, 420px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.e-acceso__col--ancha { width: min(100%, 520px); }

.e-acceso__tarjeta {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 38px 34px 30px;
  border-radius: var(--e-r-2xl);
  background: var(--e-vidrio);
  border: 1px solid var(--e-borde-suave);
  -webkit-backdrop-filter: var(--e-blur-fuerte);
  backdrop-filter: var(--e-blur-fuerte);
  box-shadow: var(--e-sombra-modal), inset 0 1px 0 rgba(232, 230, 225, .05);
}
/* Filo de luz fijo, arriba (el mismo del Núcleo) */
.e-acceso__tarjeta::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  top: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--e-filo-1), var(--e-filo-2), transparent);
  pointer-events: none;
}
/* Y un barrido de luz por el borde cuando la tarjeta aparece (una sola vuelta) */
@property --e-giro { syntax: "<angle>"; inherits: false; initial-value: 0deg; }
.e-acceso__tarjeta::before {
  content: "";
  position: absolute;
  inset: -1px;
  padding: 1px;
  border-radius: inherit;
  background: conic-gradient(from var(--e-giro), transparent 0 62%, rgba(255, 201, 160, .05) 62%, rgba(255, 201, 160, .85) 92%, rgba(208, 113, 154, 0) 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  pointer-events: none;
  animation: e-acceso-filo 2.4s var(--e-ease-suave) .25s both;
}
@keyframes e-acceso-filo {
  0% { --e-giro: 0deg; opacity: 0; }
  12% { opacity: 1; }
  100% { --e-giro: 360deg; opacity: 0; }
}

/* La marca: el wordmark de ETHOS con el degradado del Brain */
.e-acceso__marca {
  display: block;
  width: 150px;
  height: 36px;
  margin: 0 auto 26px;
  background: linear-gradient(100deg, #FFE7D4 0%, #FFC9A0 55%, #E99BAA 100%);
  -webkit-mask: url(/assets/ethos/ethos-wordmark.png) center / contain no-repeat;
  mask: url(/assets/ethos/ethos-wordmark.png) center / contain no-repeat;
}
.e-acceso__titulo {
  font-size: var(--e-t-2xl);
  font-weight: var(--e-peso-fuerte);
  line-height: var(--e-interlineado-titulo);
  letter-spacing: var(--e-tracking-titulo);
  text-align: center;
  color: var(--e-texto);
}
.e-acceso__sub {
  margin-top: 8px;
  font-size: var(--e-t-base);
  line-height: var(--e-interlineado);
  text-align: center;
  color: var(--e-texto-2);
  text-wrap: balance;
}
.e-acceso__dato {
  margin-top: 6px;
  font-family: var(--e-mono);
  font-size: var(--e-t-xs);
  letter-spacing: .08em;
  text-align: center;
  color: var(--e-texto-3);
  overflow-wrap: anywhere;
}

.e-acceso__saludo { text-align: center; font-weight: var(--e-peso-medio); color: var(--e-texto); }
.e-acceso__nota { margin-top: 16px; font-size: var(--e-t-sm); line-height: 1.5; text-align: center; color: var(--e-texto-3); }
.e-acceso__form { display: flex; flex-direction: column; gap: 16px; margin-top: 26px; }
.e-acceso__form[hidden] { display: none; }
.e-acceso__clave { position: relative; display: flex; align-items: center; }
.e-acceso__clave .e-input { padding-right: 52px; }
.e-acceso__ojo {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
}
.e-acceso__ojo .e-acceso__ojo-tachado { display: none; }
.e-acceso__ojo.is-visible .e-acceso__ojo-tachado { display: block; }
.e-acceso__ojo:active { transform: translateY(-50%) scale(.96); }
.e-acceso__form .e-boton { margin-top: 4px; }

/* Enlaces de pie dentro y fuera de la tarjeta */
.e-acceso__enlace {
  align-self: center;
  margin-top: 18px;
  padding: 6px 10px;
  border: 0;
  border-radius: var(--e-r-xs);
  background: none;
  font: inherit;
  font-size: var(--e-t-sm);
  color: var(--e-texto-3);
  text-decoration: none;
  cursor: pointer;
  transition: color var(--e-dur-2) ease;
}
.e-acceso__enlace:hover { color: var(--e-texto); }
.e-acceso__pie {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  font-family: var(--e-mono);
  font-size: var(--e-t-xs);
  letter-spacing: .08em;
  color: var(--e-texto-3);
}
.e-acceso__pie a {
  color: var(--e-texto-2);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: var(--e-r-pill);
  border: 1px solid var(--e-borde-suave);
  background: var(--e-relleno);
  transition: color var(--e-dur-2) ease, border-color var(--e-dur-2) ease;
}
.e-acceso__pie a:hover { color: var(--e-texto); border-color: var(--e-borde-fuerte); }

/* Mensajes dentro del formulario */
.e-acceso__aviso { margin-top: 2px; }
.e-acceso__aviso[hidden] { display: none; }

/* Cuentas (cuando el email pertenece a varias) */
.e-acceso__cuentas { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.e-acceso__cuenta {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--e-r-lg);
  border: 1px solid var(--e-borde-suave);
  background: var(--e-hundido);
  color: var(--e-texto);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--e-dur-2) ease, background var(--e-dur-2) ease, transform var(--e-dur-2) var(--e-ease-suave);
}
.e-acceso__cuenta:hover { border-color: var(--e-borde-fuerte); background: var(--e-relleno-hover); transform: translateY(-1px); }
.e-acceso__cuenta-nombre { display: block; font-weight: var(--e-peso-medio); }
.e-acceso__cuenta-detalle { display: block; margin-top: 2px; font-size: var(--e-t-sm); color: var(--e-texto-3); }

/* Instalar: pasos y estado */
.e-acceso__estado {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
  padding: 12px 14px;
  border-radius: var(--e-r-md);
  border: 1px solid var(--e-borde-suave);
  background: var(--e-hundido);
  font-size: var(--e-t-sm);
  line-height: 1.45;
  color: var(--e-texto-2);
}
.e-acceso__estado .e-punto { --e-c: var(--e-atencion); }
.e-acceso__estado.ready .e-punto, .e-acceso__estado.installed .e-punto { --e-c: var(--e-ok); }
.e-acceso__estado.blocked .e-punto { --e-c: var(--e-peligro); }
.e-acceso__pasos { list-style: none; margin: 18px 0 0; padding: 0; display: flex; flex-direction: column; }
.e-acceso__paso {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 14px;
  padding: 14px 0;
  border-top: 1px solid var(--e-borde-suave);
}
.e-acceso__paso:first-child { border-top: 0; }
.e-acceso__paso-num {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--e-borde);
  background: var(--e-hundido);
  font-family: var(--e-mono);
  font-size: var(--e-t-sm);
  color: var(--e-texto-2);
}
.e-acceso__paso div strong { display: block; font-weight: var(--e-peso-fuerte); font-size: var(--e-t-base); line-height: 1.3; }
.e-acceso__paso div span { display: block; margin-top: 3px; font-size: var(--e-t-sm); line-height: 1.5; color: var(--e-texto-3); }
.e-acceso__acciones { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.e-acceso__icono { width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 16px; box-shadow: var(--e-sombra-2); }

/* Entrada normal (sin intro): la tarjeta sube y los hijos la siguen */
.e-acceso__tarjeta { animation: e-acceso-aparece .7s var(--e-ease) both; }
.e-acceso__tarjeta > * { animation: e-acceso-sube .9s var(--e-ease) both; animation-delay: calc(.08s + var(--i, 0) * .06s); }
.e-acceso__tarjeta > .e-acceso__marca { animation: none; }
@keyframes e-acceso-aparece { from { opacity: 0; } to { opacity: 1; } }
@keyframes e-acceso-sube { from { opacity: 0; translate: 0 12px; } to { opacity: 1; translate: 0 0; } }

@media (max-width: 860px) {
  .e-acceso { align-items: start; padding-top: clamp(28px, 9vh, 72px); }
  .e-acceso__tarjeta { padding: 30px 22px 24px; }
  .e-acceso__marca { margin-bottom: 22px; }
}

/* ════════════════════════════════════════════════════════════════════════
   2. Escena viva: órbitas y satélites (entrada.js). Solo transform y opacity.
   ════════════════════════════════════════════════════════════════════════ */

.e-orbita {
  position: fixed;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
  /* .001 y no 0: el navegador lo rasteriza antes de que haga falta. */
  opacity: .001;
}
.e-orbita.is-visible { opacity: 1; }
.e-orbita__aro {
  position: absolute;
  left: var(--cx);
  top: var(--cy);
  width: calc(var(--rx) * 2);
  height: calc(var(--rx) * 2);
  margin: calc(var(--rx) * -1) 0 0 calc(var(--rx) * -1);
  transform: rotate(var(--incl)) scaleY(var(--k));
  transition: width .6s var(--e-ease), height .6s var(--e-ease), margin .6s var(--e-ease), left .6s var(--e-ease), top .6s var(--e-ease), transform .6s var(--e-ease);
}
.e-orbita__linea {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(232, 230, 225, .15);
}
/* Cabeza de cometa: un arco de luz con cola que gira (conic + máscara de aro) */
.e-orbita__giro {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  will-change: transform;
  --_cola: rgba(255, 201, 160, 1);
  background: conic-gradient(from 0deg,
    transparent 0deg,
    color-mix(in srgb, var(--_cola) 4%, transparent) 144deg,
    color-mix(in srgb, var(--_cola) 12%, transparent) 216deg,
    color-mix(in srgb, var(--_cola) 33%, transparent) 288deg,
    color-mix(in srgb, var(--_cola) 70%, transparent) 342deg,
    color-mix(in srgb, var(--_cola) 90%, transparent) 359deg,
    transparent 360deg);
  -webkit-mask: radial-gradient(closest-side, transparent calc(100% - 2px), #000 calc(100% - 1px));
  mask: radial-gradient(closest-side, transparent calc(100% - 2px), #000 calc(100% - 1px));
}
.e-orbita__giro::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: inherit;
  opacity: .32;
  -webkit-mask: radial-gradient(closest-side, transparent calc(100% - 11px), #000 calc(100% - 5px), transparent 100%);
  mask: radial-gradient(closest-side, transparent calc(100% - 11px), #000 calc(100% - 5px), transparent 100%);
}
.e-orbita__aro--b .e-orbita__giro { --_cola: rgba(170, 190, 255, 1); }
.e-orbita__aro--b .e-orbita__linea { border-color: rgba(232, 230, 225, .09); }
.e-orbita__vuelta { position: absolute; inset: 0; will-change: transform; }
.e-orbita__sat {
  position: absolute;
  left: 100%;
  top: 50%;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 50%;
  background: var(--e-c);
  box-shadow: 0 0 12px 2px color-mix(in srgb, var(--e-c) 55%, transparent);
}
/* Estela del satélite, detrás de su movimiento */
.e-orbita__sat::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 2px;
  height: 38px;
  margin-left: -1px;
  background: linear-gradient(to top, color-mix(in srgb, var(--e-c) 75%, transparent), transparent);
}
.e-orbita__sat--inv::before { bottom: auto; top: 50%; background: linear-gradient(to bottom, color-mix(in srgb, var(--e-c) 75%, transparent), transparent); }

/* ════════════════════════════════════════════════════════════════════════
   3. Intro del login
   ════════════════════════════════════════════════════════════════════════ */

/* Antes de que exista la capa: negro, y el formulario oculto pero presente. */
html.intro-espera, html.intro-espera body.e-fondo { background: #000; }
html.intro-espera .e-fondo::before, html.intro-espera .e-fondo::after { visibility: hidden; }
html.intro-espera, html.intro { overflow: hidden; }
html.intro-espera .e-acceso__tarjeta, html.intro-espera .e-acceso__pie { opacity: 0; }

/* Mientras dura, la tarjeta espera su segundo (opacidad 0, sigue en el DOM y
   se puede enfocar y rellenar) y su desenfoque de vidrio no se calcula. */
html.intro .e-acceso__tarjeta:not(.intro-suelta) {
  opacity: 0;
  animation: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}
html.intro .e-acceso__tarjeta:not(.intro-suelta)::before,
html.intro .e-acceso__tarjeta:not(.intro-suelta) > * { animation: none; }
html.intro .e-acceso__marca:not(.intro-suelta) { opacity: 0; }
html.intro .e-acceso__pie:not(.intro-suelta) { opacity: 0; }
/* --intro-k: ritmo de la intro en móvil; al saltar baja a 0,4 y todo entra deprisa. */
html.intro .e-acceso__tarjeta.intro-suelta { animation: e-acceso-aparece calc(1.1s * var(--intro-k, 1)) var(--e-ease) both; }
html.intro .e-acceso__tarjeta.intro-suelta > :not(.e-acceso__marca) {
  animation: e-acceso-sube calc(.95s * var(--intro-k, 1)) var(--e-ease) both;
  animation-delay: calc((.1s + var(--i, 0) * .07s) * var(--intro-k, 1));
}
html.intro .e-acceso__tarjeta.intro-suelta::before { animation: e-acceso-filo calc(2.2s * var(--intro-k, 1)) var(--e-ease-suave) calc(.1s * var(--intro-k, 1)) both; }
html.intro .e-acceso__pie.intro-suelta { animation: e-acceso-aparece calc(1.2s * var(--intro-k, 1)) ease calc(.5s * var(--intro-k, 1)) both; }
html.intro .e-acceso__marca.intro-suelta { animation: e-acceso-aparece calc(.8s * var(--intro-k, 1)) ease both; }

.e-intro { position: fixed; inset: 0; z-index: 1; overflow: hidden; pointer-events: none; }
.e-intro__negro { position: absolute; inset: 0; background: #000; opacity: .995; }
.e-intro__escena { position: absolute; inset: 0; }
.e-intro__lienzo { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.e-intro__chispa {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 280px;
  height: 280px;
  opacity: .001;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(closest-side, rgba(255, 231, 212, .95), rgba(255, 201, 160, .34) 28%, rgba(208, 113, 154, .1) 58%, transparent);
  will-change: transform, opacity;
  /* Brilla desde el primer frame, mientras el motor enlaza sus shaders; al
     arrancar, el guion sigue desde este mismo estado (opacidad 1, escala .7). */
  animation: e-intro-chispa .7s ease-out both;
}
@keyframes e-intro-chispa {
  from { opacity: 0; transform: translate(-50%, -50%) scale(.3); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(.7); }
}
.e-intro__halo {
  position: absolute;
  opacity: .001;
  will-change: opacity, transform;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 176, 146, .22), rgba(208, 113, 154, .09) 55%, transparent);
}
.e-intro__vineta { position: absolute; inset: 0; background: radial-gradient(ellipse at 50% 50%, transparent 50%, rgba(0, 0, 0, .6) 100%); }
.e-intro__grano { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.e-intro__grano::before {
  content: "";
  position: absolute;
  inset: -60px;
  opacity: .085;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: e-intro-grano .6s steps(1) infinite;
}
@keyframes e-intro-grano {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-23px, 17px); }
  40% { transform: translate(31px, -9px); }
  60% { transform: translate(-11px, -29px); }
  80% { transform: translate(19px, 27px); }
}
.e-intro__saltar {
  position: fixed;
  right: 28px;
  bottom: 24px;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 8px 12px 8px 16px;
  border-radius: var(--e-r-pill);
  border: 1px solid rgba(232, 230, 225, .14);
  background: rgba(8, 12, 22, .4);
  color: rgba(232, 230, 225, .6);
  font: 500 11px var(--e-mono);
  letter-spacing: .16em;
  text-transform: uppercase;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: color .25s ease, border-color .25s ease, background .25s ease;
}
.e-intro__saltar:hover { color: var(--e-texto); border-color: rgba(232, 230, 225, .3); background: rgba(16, 24, 40, .6); }
.e-intro__saltar:focus-visible { outline: var(--e-foco-ancho) solid var(--e-foco); outline-offset: var(--e-foco-sep); }
.e-intro__tecla {
  font-size: 10px;
  letter-spacing: .06em;
  padding: 3px 6px;
  border-radius: 6px;
  border: 1px solid rgba(232, 230, 225, .16);
  color: rgba(232, 230, 225, .45);
}
/* Modo limpio para grabar (?intro=1&limpia=1): sin botón; Esc y clic siguen saltando. */
.e-intro__saltar--oculto { display: none; }
@media (max-width: 860px) {
  .e-intro__saltar { right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); }
  .e-intro__tecla { display: none; }
}

/* ════════════════════════════════════════════════════════════════════════
   4. Movimiento reducido: sin intro, sin giro; la tarjeta entra con un fundido
   ════════════════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  .e-acceso__tarjeta { animation: e-acceso-aparece .5s ease both; }
  .e-acceso__tarjeta > *, .e-acceso__tarjeta::before { animation: none; }
  .e-orbita { transition: none !important; }
  .e-acceso__cuenta:hover { transform: none; }
}

/* Instalar la app: solo en móvil táctil y con la app sin instalar */
@media (pointer: fine), (display-mode: standalone) { .e-acceso__instalar { display: none; } }
