/* ==========================================================================
   SIMIAN SAGE — INTRO PRELOADER ("El sistema arranca")
   Sin dependencias. Integración: ver LEEME_PRELOADER.md
   ========================================================================== */

:root {
  --ssp-bg: #07090c;
  --ssp-bg-2: #0c1016;
  --ssp-ink: #f2f4f7;
  --ssp-muted: #6b7480;
  --ssp-grid: rgba(255, 255, 255, 0.045);
  --ssp-blue: #2563eb;
  --ssp-orange: #ff8a00;
  --ssp-red: #ff2055;
  --ssp-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", "Consolas", "Liberation Mono", monospace;
  --ssp-sans: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

html.ssp-lock, html.ssp-lock body { overflow: hidden; }

.ssp {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  color: var(--ssp-ink);
  font-family: var(--ssp-sans);
  pointer-events: auto;
}

/* Las dos mitades que se abren al salir */
.ssp__half {
  position: absolute;
  left: 0;
  right: 0;
  height: 50.5%;
  background: var(--ssp-bg);
  transition: transform 0.9s cubic-bezier(0.77, 0, 0.18, 1);
  will-change: transform;
}
.ssp__half--top { top: 0; }
.ssp__half--bottom { bottom: 0; }

/* Retícula técnica + viñeta */
.ssp__grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--ssp-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--ssp-grid) 1px, transparent 1px);
  background-size: 48px 48px;
  background-position: center center;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, #000 30%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, #000 30%, transparent 100%);
  opacity: 0;
  animation: ssp-fade-in 0.8s ease-out 0.05s forwards;
}

/* Línea de escaneo */
.ssp__scan {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 140px;
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.035) 85%, rgba(255, 255, 255, 0.09));
  transform: translateY(-140px);
  animation: ssp-scan 2.6s cubic-bezier(0.45, 0, 0.25, 1) 0.15s 1 forwards;
  pointer-events: none;
}

/* Escena central */
.ssp__stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(14px, 2.4vh, 26px);
  transition: transform 0.7s cubic-bezier(0.65, 0, 0.35, 1), opacity 0.5s ease;
}

.ssp__mark {
  width: clamp(120px, 22vmin, 210px);
  height: auto;
  overflow: visible;
}

/* Trazos del circuito */
.ssp__trace {
  fill: none;
  stroke: var(--ssp-ink);
  stroke-width: 30;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: var(--len) var(--len);
  stroke-dashoffset: var(--len);
}
.ssp.is-running .ssp__trace--a { animation: ssp-draw 1.15s cubic-bezier(0.65, 0, 0.35, 1) 0.45s forwards; }
.ssp.is-running .ssp__trace--b { animation: ssp-draw 1.15s cubic-bezier(0.65, 0, 0.35, 1) 0.6s forwards; }

/* Halo del trazo (aspecto de corriente) */
.ssp__glow {
  fill: none;
  stroke-width: 30;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: url(#ssp-blur);
  opacity: 0.55;
}

/* Pulsos de color: un segmento corto que recorre el trazo */
.ssp__pulse {
  fill: none;
  stroke-width: 30;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 70px var(--len);
  stroke-dashoffset: 70px;
  opacity: 0;
}
.ssp__pulse--blue { stroke: var(--ssp-blue); }
.ssp__pulse--orange { stroke: var(--ssp-orange); }
.ssp__pulse--red { stroke: var(--ssp-red); }
.ssp.is-running .ssp__pulse--blue { animation: ssp-pulse 1s cubic-bezier(0.5, 0, 0.3, 1) 1.55s forwards; }
.ssp.is-running .ssp__pulse--orange { animation: ssp-pulse 1s cubic-bezier(0.5, 0, 0.3, 1) 1.8s forwards; }
.ssp.is-running .ssp__pulse--red { animation: ssp-pulse 1s cubic-bezier(0.5, 0, 0.3, 1) 2.05s forwards; }

/* Nodos */
.ssp__node {
  fill: var(--ssp-ink);
  transform-box: fill-box;
  transform-origin: center;
  transform: scale(0);
}
.ssp.is-running .ssp__node { animation: ssp-node 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }
.ssp.is-running .ssp__node--a1 { animation-delay: 0.25s; }
.ssp.is-running .ssp__node--b1 { animation-delay: 0.35s; }
.ssp.is-running .ssp__node--a2 { animation-delay: 1.5s; }
.ssp.is-running .ssp__node--b2 { animation-delay: 1.65s; }

.ssp__ring {
  fill: none;
  stroke: var(--ssp-ink);
  stroke-width: 3;
  transform-box: fill-box;
  transform-origin: center;
  opacity: 0;
}
.ssp.is-running .ssp__ring { animation: ssp-ring 1.1s ease-out forwards; }
.ssp.is-running .ssp__ring--a1 { animation-delay: 0.3s; }
.ssp.is-running .ssp__ring--b1 { animation-delay: 0.4s; }

/* Nombre */
.ssp__name {
  margin: 0;
  font-family: var(--ssp-sans);
  font-weight: 600;
  font-size: clamp(22px, 4.2vmin, 40px);
  letter-spacing: 0.32em;
  margin-right: -0.32em; /* compensa el tracking para centrar */
  white-space: nowrap;
  min-height: 1.2em;
}
.ssp__name .is-scrambling { color: var(--ssp-muted); }

.ssp__sub {
  margin-top: calc(clamp(14px, 2.4vh, 26px) * -0.55);
  font-family: var(--ssp-mono);
  font-size: clamp(10px, 1.45vmin, 12px);
  letter-spacing: 0.55em;
  margin-right: -0.55em;
  color: var(--ssp-muted);
  opacity: 0;
}
.ssp.is-running .ssp__sub { animation: ssp-fade-in 0.6s ease-out 2.2s forwards; }

/* Tres niveles */
.ssp__levels {
  display: flex;
  gap: 10px;
  height: 3px;
}
.ssp__levels span {
  width: clamp(26px, 5vmin, 44px);
  height: 3px;
  border-radius: 2px;
  transform: scaleX(0);
  transform-origin: left center;
}
.ssp__levels span:nth-child(1) { background: var(--ssp-blue); }
.ssp__levels span:nth-child(2) { background: var(--ssp-orange); }
.ssp__levels span:nth-child(3) { background: var(--ssp-red); }
.ssp.is-running .ssp__levels span { animation: ssp-bar 0.5s cubic-bezier(0.65, 0, 0.35, 1) forwards; }
.ssp.is-running .ssp__levels span:nth-child(1) { animation-delay: 2.15s; }
.ssp.is-running .ssp__levels span:nth-child(2) { animation-delay: 2.3s; }
.ssp.is-running .ssp__levels span:nth-child(3) { animation-delay: 2.45s; }

/* Registro de arranque (esquina inferior izquierda) */
.ssp__log {
  position: absolute;
  left: clamp(16px, 4vw, 48px);
  bottom: clamp(16px, 5vh, 44px);
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: var(--ssp-mono);
  font-size: 11px;
  line-height: 1.85;
  color: var(--ssp-muted);
  letter-spacing: 0.04em;
}
.ssp__log li { opacity: 0; transform: translateY(4px); transition: opacity 0.25s, transform 0.25s; white-space: pre; }
.ssp__log li.is-on { opacity: 1; transform: none; }
.ssp__log .ok { color: var(--ssp-ink); }

/* Contador de carga (esquina inferior derecha) */
.ssp__meter {
  position: absolute;
  right: clamp(16px, 4vw, 48px);
  bottom: clamp(16px, 5vh, 44px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  font-family: var(--ssp-mono);
}
.ssp__count {
  font-size: clamp(28px, 5vmin, 44px);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  line-height: 1;
}
.ssp__track {
  width: clamp(110px, 16vw, 180px);
  height: 2px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}
.ssp__fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--ssp-ink);
  transform: scaleX(0);
  transform-origin: left center;
}

/* Botón saltar */
.ssp__skip {
  position: absolute;
  top: clamp(14px, 3vh, 28px);
  right: clamp(16px, 4vw, 48px);
  padding: 8px 14px;
  font-family: var(--ssp-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--ssp-muted);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.ssp__skip:hover,
.ssp__skip:focus-visible { color: var(--ssp-ink); border-color: rgba(255, 255, 255, 0.4); outline: none; }

/* Esquinas técnicas */
.ssp__corner {
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: rgba(255, 255, 255, 0.18);
  border-style: solid;
  border-width: 0;
}
.ssp__corner--tl { top: clamp(14px, 3vh, 28px); left: clamp(16px, 4vw, 48px); border-top-width: 1px; border-left-width: 1px; }
.ssp__corner--br { display: none; }

.ssp__brand {
  position: absolute;
  top: clamp(14px, 3vh, 28px);
  left: calc(clamp(16px, 4vw, 48px) + 30px);
  font-family: var(--ssp-mono);
  font-size: 11px;
  line-height: 18px;
  letter-spacing: 0.2em;
  color: var(--ssp-muted);
}

/* Capa de contenido (todo menos las mitades) */
.ssp__layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transition: opacity 0.45s ease;
}

/* ---------- Salida ---------- */
.ssp.is-leaving .ssp__layer { opacity: 0; }
.ssp.is-leaving .ssp__stage { transform: scale(0.92); }
.ssp.is-leaving .ssp__half--top { transform: translateY(-101%); transition-delay: 0.25s; }
.ssp.is-leaving .ssp__half--bottom { transform: translateY(101%); transition-delay: 0.25s; }
.ssp.is-done { display: none; }

/* ---------- Animaciones ---------- */
@keyframes ssp-fade-in { to { opacity: 1; } }
@keyframes ssp-scan { to { transform: translateY(100vh); } }
@keyframes ssp-draw { to { stroke-dashoffset: 0px; } }
@keyframes ssp-node { to { transform: scale(1); } }
@keyframes ssp-ring {
  0% { opacity: 0.6; transform: scale(1); }
  100% { opacity: 0; transform: scale(2.6); }
}
@keyframes ssp-pulse {
  0% { opacity: 1; stroke-dashoffset: 70px; }
  85% { opacity: 1; }
  100% { opacity: 0; stroke-dashoffset: var(--len-neg); }
}
@keyframes ssp-bar { to { transform: scaleX(1); } }

/* ---------- Pantallas pequeñas ---------- */
@media (max-width: 560px) {
  .ssp__log { font-size: 10px; line-height: 1.7; }
  .ssp__log li.is-old { display: none; }
  .ssp__brand { display: none; }
}

/* ---------- Movimiento reducido: sin coreografía, solo un fundido breve ---------- */
@media (prefers-reduced-motion: reduce) {
  .ssp *, .ssp *::before, .ssp *::after { animation: none !important; transition: none !important; }
  .ssp__trace { stroke-dashoffset: 0; }
  .ssp__node { transform: scale(1); }
  .ssp__grid, .ssp__sub { opacity: 1; }
  .ssp__levels span { transform: scaleX(1); }
  .ssp__scan, .ssp__ring, .ssp__pulse, .ssp__log, .ssp__meter { display: none; }
  .ssp { transition: opacity 0.3s ease !important; }
  .ssp.is-leaving { opacity: 0; }
  .ssp.is-leaving .ssp__half { transform: none; }
}
