/*
 * Pantalla «En actualización» (sitio dormido, ver config/visibility.yml).
 * Una sola pantalla con fondo vivo: foto atenuada, retícula de plano técnico y
 * un horizonte de estructuras de celosía que se arman, se encienden y se
 * desvanecen en bucle (ciclo de 16 s). Solo se animan transform, opacity y
 * stroke-dashoffset. Con movimiento reducido todo queda armado y estático
 * (base.css anula las animaciones).
 */
@layer pages {
  .updating-page { margin: 0; background: var(--petroleo-hondo); }

  .updating {
    --cycle: 16s;
    --strip: 3.25rem;
    --cell: 64px;
    position: relative;
    isolation: isolate;
    display: grid;
    grid-template-rows: minmax(0, 1fr) var(--strip);
    min-height: 100svh;
    overflow: clip;
    color: var(--blanco);
    background: var(--petroleo-hondo);
  }

  /* ---------------------------------------------------------------- fondo */
  .updating__photo { position: absolute; inset: 0; z-index: 0; overflow: hidden; }
  .updating__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0.5;
    animation: updating-zoom 40s ease-in-out infinite alternate;
  }
  @keyframes updating-zoom { to { scale: 1.12; } }

  .updating__veil {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: color-mix(in srgb, var(--petroleo-hondo) 74%, transparent);
  }

  /* Retícula: celdas de 64 px, línea mayor cada 256 px; se desplaza una celda mayor y vuelve a empezar. */
  .updating__grid {
    position: absolute;
    inset: calc(var(--cell) * -4) 0 0 calc(var(--cell) * -4);
    z-index: 2;
    background-image:
      linear-gradient(to right, color-mix(in srgb, var(--acero) 26%, transparent) 1px, transparent 1px),
      linear-gradient(to bottom, color-mix(in srgb, var(--acero) 26%, transparent) 1px, transparent 1px),
      linear-gradient(to right, color-mix(in srgb, var(--acero) 12%, transparent) 1px, transparent 1px),
      linear-gradient(to bottom, color-mix(in srgb, var(--acero) 12%, transparent) 1px, transparent 1px);
    background-size:
      calc(var(--cell) * 4) calc(var(--cell) * 4),
      calc(var(--cell) * 4) calc(var(--cell) * 4),
      var(--cell) var(--cell),
      var(--cell) var(--cell);
    animation: updating-grid 48s linear infinite;
  }
  @keyframes updating-grid { to { translate: calc(var(--cell) * 4) calc(var(--cell) * 4); } }

  /* ------------------------------------------------------------ horizonte */
  .updating__horizon {
    position: absolute;
    inset: 0 0 var(--strip) 0;
    z-index: 3;
    pointer-events: none;
  }
  .updating__item {
    --sink: 6%;
    position: absolute;
    bottom: 0;
    left: var(--x);
    height: var(--h);
    aspect-ratio: 640 / 820;
    translate: -50% var(--sink);
    opacity: var(--a);
  }
  .updating__item--truss { --sink: 10%; aspect-ratio: 640 / 690; }

  /* Cada silueta: se arma de abajo hacia arriba, sostiene y se desvanece.
     Los retrasos de dibujo (--d) se estiran con --k para que todas tarden igual. */
  .updating .structure {
    animation: updating-fade var(--cycle) linear var(--o, 0s) infinite backwards;
  }
  .updating .structure__stroke {
    stroke-linecap: butt;
    animation: updating-draw var(--cycle) var(--ease) calc(var(--o, 0s) + var(--d, 0s) * var(--k, 1)) infinite backwards;
  }
  .updating .structure__node {
    animation: updating-lamp-node var(--cycle) var(--ease) calc(var(--o, 0s) + 7.4s + var(--d, 0s) * 0.1) infinite backwards;
  }
  /* Baliza: se enciende al completarse la estructura y parpadea. */
  .updating .structure__beacon {
    animation:
      updating-lamp var(--cycle) var(--ease) calc(var(--o, 0s) + 7.4s) infinite backwards,
      updating-blink 2.4s ease-in-out calc(var(--o, 0s) + 7.4s) infinite;
  }
  .updating .structure__halo {
    r: 15px;
    opacity: 0.4;
    animation:
      updating-lamp var(--cycle) var(--ease) calc(var(--o, 0s) + 7.4s) infinite backwards,
      updating-halo 2.4s ease-out calc(var(--o, 0s) + 7.4s) infinite;
  }

  @keyframes updating-fade {
    0%, 20% { opacity: 0; }
    21.5%, 82% { opacity: 1; }
    90%, 100% { opacity: 0; }
  }
  @keyframes updating-draw {
    0%, 21.25% { stroke-dashoffset: 1; }
    25.6%, 100% { stroke-dashoffset: 0; }
  }
  @keyframes updating-lamp-node {
    0%, 100% { scale: 0; opacity: 0; }
    3% { scale: 1.6; opacity: 1; }
    6%, 35% { scale: 1; opacity: 1; }
    40% { scale: 0; opacity: 0; }
  }
  @keyframes updating-lamp {
    0%, 40%, 100% { scale: 0; }
    3%, 35% { scale: 1; }
  }
  @keyframes updating-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.15; }
  }
  @keyframes updating-halo {
    0%, 100% { opacity: 0; }
    10% { opacity: 0.5; }
    50% { opacity: 0.05; }
  }

  /* ------------------------------------------------------------ contenido */
  .updating__main {
    position: relative;
    z-index: 4;
    align-self: start;
    max-width: calc(var(--gutter) + 50rem);
    padding: clamp(2rem, 11svh, 7rem) var(--gutter) 0;
  }
  .updating__main:focus { outline: none; }

  .updating__logo { display: block; height: clamp(6.5rem, 6vw + 5svh + 2rem, 11rem); width: auto; margin-bottom: clamp(1.25rem, 3.5svh, 2.5rem); }

  .updating__title {
    font-size: clamp(2.4rem, 1rem + 6vw, 5.2rem);
    font-stretch: 100%;
    font-weight: 690;
    line-height: 1.02;
    letter-spacing: -0.02em;
    text-wrap: balance;
  }

  /* Cota de obra en curso: la línea se extiende y se retrae, con su marca en la punta. */
  .updating__cota {
    --cota: clamp(7rem, 22vw, 11rem);
    position: relative;
    display: block;
    width: var(--cota);
    height: 0.75rem;
    margin-top: clamp(1rem, 2.5svh, 1.5rem);
  }
  .updating__cota::before,
  .updating__cota::after {
    content: "";
    position: absolute;
    left: 0;
  }
  .updating__cota::before {
    top: calc(50% - 1px);
    width: 100%;
    height: 2px;
    background: var(--senal);
    transform-origin: left center;
    animation: updating-cota 5.5s var(--ease) infinite;
  }
  .updating__cota::after {
    top: 0;
    width: 2px;
    height: 100%;
    background: var(--senal);
    animation: updating-cota-tick 5.5s var(--ease) infinite;
  }
  @keyframes updating-cota {
    0% { scale: 0 1; }
    45%, 60% { scale: 1 1; }
    100% { scale: 0 1; }
  }
  @keyframes updating-cota-tick {
    0% { translate: 0 0; }
    45%, 60% { translate: calc(var(--cota) - 2px) 0; }
    100% { translate: 0 0; }
  }

  .updating__text {
    margin-top: clamp(1.25rem, 3svh, 2rem);
    max-width: 30rem;
    font-size: var(--fs-1);
    line-height: 1.4;
    color: var(--blanco);
  }
  .updating__mail { margin-top: clamp(1rem, 2.5svh, 1.5rem); font-size: var(--fs-0); }
  .updating__mail a {
    color: var(--blanco);
    text-decoration: underline;
    text-decoration-color: var(--senal);
    text-decoration-thickness: 2px;
    text-underline-offset: 0.3em;
  }

  /* Entrada sobria, una sola vez. */
  .updating__logo, .updating__title, .updating__cota, .updating__text, .updating__mail {
    animation: updating-in var(--t-slow) var(--ease) backwards;
  }
  .updating__title { animation-delay: 0.25s; }
  .updating__cota { animation-delay: 0.45s; }
  .updating__text { animation-delay: 0.6s; }
  .updating__mail { animation-delay: 0.8s; }
  .updating__logo { animation-delay: 0.05s; }
  @keyframes updating-in { from { opacity: 0; translate: 0 0.75rem; } }
  /* La cota repite su propia animación en ::before/::after; su entrada solo es de opacidad. */
  .updating__cota { animation-name: updating-in-fade; }
  @keyframes updating-in-fade { from { opacity: 0; } }

  /* ------------------------------------------------------- franja inferior */
  .updating__strip {
    position: relative;
    z-index: 5;
    grid-row: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 var(--gutter);
    font-size: var(--fs-small);
    color: var(--acero-claro);
    background: var(--petroleo-hondo);
    border-top: 1px solid color-mix(in srgb, var(--acero) 45%, transparent);
  }
  .updating__version {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    letter-spacing: 0.02em;
  }
  /* Puntos de «trabajando»: aparecen uno por uno y se apagan juntos. */
  .updating__dots i { font-style: normal; animation: 2.4s steps(1, end) infinite; }
  .updating__dots i:nth-child(1) { animation-name: updating-dot-1; }
  .updating__dots i:nth-child(2) { animation-name: updating-dot-2; }
  .updating__dots i:nth-child(3) { animation-name: updating-dot-3; }
  @keyframes updating-dot-1 { 0%, 100% { opacity: 0; } 20%, 80% { opacity: 1; } }
  @keyframes updating-dot-2 { 0%, 100% { opacity: 0; } 40%, 80% { opacity: 1; } }
  @keyframes updating-dot-3 { 0%, 100% { opacity: 0; } 60%, 80% { opacity: 1; } }

  /* Móvil y tableta estrecha: contenido arriba, torres debajo. */
  @media (max-width: 59.99rem) {
    .updating__item { left: var(--xm); height: var(--hm); }
    .updating__main { padding-top: clamp(1.75rem, 6svh, 3rem); }
  }
}
