/* La carga «tejido» (views/partials/tejido.ejs, public/js/tejido.js).
   Una telaraña radial que se teje: radios, después las vueltas, los nudos se
   encienden y, al terminar, el centro se llena y aparece ✓. Solo tokens de
   brand.css. Con prefers-reduced-motion, sin animación: la red ya tejida. */

.tj {
  position: fixed; inset: 0; z-index: 90;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  background: rgb(var(--sn-bg-rgb) / 0.78);
  -webkit-backdrop-filter: blur(14px) saturate(140%); backdrop-filter: blur(14px) saturate(140%);
  opacity: 0; transition: opacity .25s ease;
}
.tj[hidden] { display: none; }
.tj.is-on { opacity: 1; }
/* Dentro de una caja (el QR del panel): ocupa la caja, no la pantalla. */
.tj.tj--caja { position: absolute; border-radius: inherit; gap: 8px; }
.tj.tj--caja .tj-web { width: 56px; height: 56px; }
.tj.tj--caja .tj-text { font-size: .75rem; }

/* El giro va en el <svg> entero (una caja HTML, la mueve el compositor): sigue
   girando aunque el hilo principal se pare al cambiar de página. */
.tj-web { width: 84px; height: 84px; overflow: visible; filter: drop-shadow(0 0 18px rgb(var(--sn-accent-rgb) / 0.35)); will-change: transform; }
/* Vueltas rápidas: una vuelta entera en 0,7 s y una pausa. Siempre se para en
   la posición de partida, con un radio recto en vertical. */
.tj.is-on .tj-web { animation: tj-giro 1.3s cubic-bezier(.65, 0, .35, 1) infinite; }
.tj-spoke, .tj-ring {
  fill: none; stroke: var(--sn-accent); stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 1; stroke-dashoffset: 1;
}
.tj-spoke { stroke-width: .9; opacity: .75; }
.tj-ring { stroke-width: .8; opacity: .55; }
.tj-node { fill: var(--sn-accent-hi); opacity: 0; transform-box: fill-box; transform-origin: center; filter: drop-shadow(0 0 2.5px rgb(255 255 255 / 0.95)) drop-shadow(0 0 6px rgb(var(--sn-accent-rgb) / 0.9)); }
.tj-core { fill: rgb(var(--sn-accent-rgb) / 0.16); stroke: var(--sn-accent); stroke-width: 1; transform-box: fill-box; transform-origin: center; }
.tj-check { fill: none; stroke: var(--sn-bg); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 1; }
.tj-text { margin: 0; color: var(--sn-text); font-family: var(--sn-font); font-weight: 400; letter-spacing: .01em; text-align: center; }

/* Los retardos van por clase (tj-i0…, tj-k0…, tj-j0…): las vistas no llevan style=. */
.tj-i0 { --i: 0; } .tj-i1 { --i: 1; } .tj-i2 { --i: 2; } .tj-i3 { --i: 3; } .tj-i4 { --i: 4; } .tj-i5 { --i: 5; } .tj-i6 { --i: 6; } .tj-i7 { --i: 7; }
.tj-k0 { --k: 0; } .tj-k1 { --k: 1; } .tj-k2 { --k: 2; }
.tj-j0 { --j: 0; } .tj-j1 { --j: 1; } .tj-j2 { --j: 2; } .tj-j3 { --j: 3; } .tj-j4 { --j: 4; }
.tj.is-on .tj-spoke { animation: tj-draw .42s cubic-bezier(.4, 0, .2, 1) forwards; animation-delay: calc(var(--i) * 45ms); }
.tj.is-on .tj-ring { animation: tj-draw .5s cubic-bezier(.4, 0, .2, 1) forwards; animation-delay: calc(.38s + var(--k) * 150ms); }
.tj.is-on .tj-node { animation: tj-pop .3s cubic-bezier(.34, 1.56, .64, 1) forwards, tj-glow .9s ease-in-out infinite; animation-delay: calc(.6s + var(--j) * 70ms), calc(.9s + var(--j) * 140ms); }
.tj.is-on .tj-core { animation: tj-breathe 1.4s ease-in-out infinite; }
.tj.is-done .tj-core { animation: tj-fill .32s ease forwards; }
.tj.is-done .tj-check { animation: tj-draw .3s ease forwards .12s; }
.tj.is-done .tj-web { animation: none; }

@keyframes tj-draw { to { stroke-dashoffset: 0; } }
@keyframes tj-pop { from { opacity: 0; transform: scale(.2); } to { opacity: 1; transform: scale(1); } }
@keyframes tj-glow { 50% { fill: #fff; transform: scale(1.45); } }
@keyframes tj-breathe { 50% { transform: scale(1.18); } }
@keyframes tj-fill { to { fill: var(--sn-accent); transform: scale(1.35); } }
@keyframes tj-spin { to { transform: rotate(360deg); } }
@keyframes tj-giro { 0% { transform: rotate(0deg); } 55%, 100% { transform: rotate(360deg); } }

/* ---- El puente: la misma telaraña en la página SIGUIENTE, desde el primer
   fotograma (html.sn-tejiendo lo pone /js/tejido-puente.js, en la cabecera)
   hasta que la página ha cargado; después se funde. Sin JS, nada. */
html.sn-tejiendo::before {
  content: attr(data-tejido); position: fixed; inset: 0; z-index: 2147483646;
  display: flex; align-items: center; justify-content: center; padding-top: 130px; box-sizing: border-box;
  background: rgb(0 0 0 / 0.94); color: #E8EEF6; font: 600 1rem/1.4 var(--sn-font, system-ui, sans-serif); letter-spacing: .01em;
  transition: opacity .4s ease;
}
html.sn-tejiendo::after {
  content: ""; position: fixed; z-index: 2147483647; left: 50%; top: 50%; width: 84px; height: 84px; margin: -62px 0 0 -42px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cg fill='none' stroke='%232FB8FF' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='50' y1='50' x2='94.0' y2='50.0' stroke-width='.9' opacity='.75'/%3E%3Cline x1='50' y1='50' x2='81.1' y2='81.1' stroke-width='.9' opacity='.75'/%3E%3Cline x1='50' y1='50' x2='50.0' y2='94.0' stroke-width='.9' opacity='.75'/%3E%3Cline x1='50' y1='50' x2='18.9' y2='81.1' stroke-width='.9' opacity='.75'/%3E%3Cline x1='50' y1='50' x2='6.0' y2='50.0' stroke-width='.9' opacity='.75'/%3E%3Cline x1='50' y1='50' x2='18.9' y2='18.9' stroke-width='.9' opacity='.75'/%3E%3Cline x1='50' y1='50' x2='50.0' y2='6.0' stroke-width='.9' opacity='.75'/%3E%3Cline x1='50' y1='50' x2='81.1' y2='18.9' stroke-width='.9' opacity='.75'/%3E%3Cpolygon points='64.0,50.0 59.9,59.9 50.0,64.0 40.1,59.9 36.0,50.0 40.1,40.1 50.0,36.0 59.9,40.1' stroke-width='.8' opacity='.55'/%3E%3Cpolygon points='76.0,50.0 68.4,68.4 50.0,76.0 31.6,68.4 24.0,50.0 31.6,31.6 50.0,24.0 68.4,31.6' stroke-width='.8' opacity='.55'/%3E%3Cpolygon points='88.0,50.0 76.9,76.9 50.0,88.0 23.1,76.9 12.0,50.0 23.1,23.1 50.0,12.0 76.9,23.1' stroke-width='.8' opacity='.55'/%3E%3C/g%3E%3Ccircle cx='50' cy='50' r='7' fill='%232FB8FF' fill-opacity='.16' stroke='%232FB8FF'/%3E%3Ccircle cx='76.0' cy='50.0' r='2.6' fill='%23A8DCFF'/%3E%3Ccircle cx='23.1' cy='76.9' r='2.6' fill='%23A8DCFF'/%3E%3Ccircle cx='40.1' cy='40.1' r='2.6' fill='%23A8DCFF'/%3E%3Ccircle cx='50.0' cy='12.0' r='2.6' fill='%23A8DCFF'/%3E%3Ccircle cx='50.0' cy='76.0' r='2.6' fill='%23A8DCFF'/%3E%3C/svg%3E") center / contain no-repeat;
  filter: drop-shadow(0 0 18px rgb(56 198 244 / 0.35));
  animation: tj-giro 1.3s cubic-bezier(.65, 0, .35, 1) infinite; will-change: transform; transition: opacity .4s ease;
}
html.sn-tejiendo-fuera::before, html.sn-tejiendo-fuera::after { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  html.sn-tejiendo::after { animation: none !important; }
  .tj, .tj * { animation: none !important; transition: none !important; }
  .tj-spoke, .tj-ring { stroke-dashoffset: 0; }
  .tj-node { opacity: 1; }
  .tj.is-done .tj-check { stroke-dashoffset: 0; }
  .tj.is-done .tj-core { fill: var(--sn-accent); }
}
