/* El auto de la web del conductor (dibujo en auto.svg, generado por scripts/dibujo/auto.mjs).
   Se maneja desde app.js con atributos en el contenedor .au:
     --au-nivel  0..1, enciende los 10 módulos de la batería
     data-vista  "solido" (carrocería pintada) o "rayos" (rayos X: se ve la batería)
     data-estado "conectado", "cargando" (late el módulo que se llena y corre energía por el cable) o "lleno"
   Rendimiento: dentro del SVG solo se animan opacity, fill-opacity, clip-path y stroke-dashoffset
   (medido: 0 recálculos de layout); los transform van en elementos HTML. Sin filtros (blur, drop-shadow): los reflejos y halos son trazos con opacidad. */
.au { --au-acento: var(--cg-acento, #a3b1ff); --au-claro: var(--cg-acento-claro, #c9d1ff); --au-rx-t: 1.1s; --au-rx-d: .45s; }
.au svg { overflow: visible; }

/* ---------- carrocería ---------- */
.au .au-faro { fill: #f1f3ff; }
.au .au-faro-halo { stroke: var(--au-claro); stroke-opacity: .35; }
.au .au-cola { fill: #ff4f63; }
.au .au-cola-halo { stroke: #ff4f63; stroke-opacity: .3; }
.au .au-freno { stroke: var(--au-acento); }
.au .au-puerto { fill: #10131c; stroke: #7d84a0; stroke-width: .6; }
.au[data-estado="cargando"] .au-puerto, .au[data-estado="lleno"] .au-puerto { fill: var(--au-acento); stroke: var(--au-claro); }

/* ---------- rayos X ---------- */
.au .au-rx-cuerpo { fill: var(--au-acento); fill-opacity: .07; stroke: var(--au-claro); stroke-width: 1.2; }
.au .au-rx-linea { fill: none; stroke: var(--au-acento); stroke-opacity: .6; stroke-width: .9; }
.au .au-rx-tenue { fill: none; stroke: var(--au-acento); stroke-opacity: .28; stroke-width: .8; }
.au .au-rx-motor { fill: var(--au-acento); fill-opacity: .16; stroke: var(--au-acento); stroke-width: .9; }
.au .au-rx-cable { fill: none; stroke: var(--au-acento); stroke-opacity: .55; stroke-width: 1.6; stroke-linecap: round; stroke-dasharray: 3 5; }
.au .au-rx-pack { fill: #0d1020; stroke: var(--au-claro); stroke-width: 1; }
.au .au-modulo { fill: #1c2238; }
.au .au-carga { fill: var(--au-acento); opacity: clamp(0, calc(var(--au-nivel, 0) * 10 - var(--i)), 1); }
.au .au-pulso { fill: #fff; opacity: 0; }
.au .au-brillo { stroke: #fff; stroke-opacity: .25; stroke-width: .8; }
.au .au-pct { fill: #fff; font: 600 17px/1 var(--f-cifras, system-ui, sans-serif); font-variant-numeric: tabular-nums; letter-spacing: .02em; }

/* ---------- de sólido a rayos X: un barrido de izquierda a derecha ---------- */
/* La capa pintada se recorta desde la izquierda mientras la de rayos aparece detrás de la franja de luz.
   Las dos transiciones y la franja usan el mismo tiempo y la misma curva: el borde va junto. */
.au .au-solido { clip-path: inset(0 0 0 0); transition: clip-path var(--au-rx-t) cubic-bezier(.5, 0, .5, 1); }
.au .au-rx { clip-path: inset(0 100% 0 0); transition: clip-path var(--au-rx-t) cubic-bezier(.5, 0, .5, 1); }
.au[data-vista="rayos"] .au-solido { clip-path: inset(0 0 0 100%); transition-delay: var(--au-rx-d); }
.au[data-vista="rayos"] .au-rx { clip-path: inset(0 0 0 0); transition-delay: var(--au-rx-d); }
/* La franja es un ::after del contenedor (HTML), no del SVG: un transform dentro del SVG obliga a
   recalcular el layout en cada cuadro; afuera lo mueve la placa de video sola. El borde derecho de la
   capa es la franja: la capa entera va de -100 % a 0, o sea, la franja cruza el ancho del auto. */
.au { position: relative; overflow: hidden; }
.au::after {
  content: ""; position: absolute; inset: 17% 0 10%; pointer-events: none; opacity: 0;
  background: linear-gradient(90deg, transparent 93%, color-mix(in srgb, var(--au-acento) 45%, transparent) 98.6%, #fff 99.6%, transparent);
  transform: translateX(-100%);
}
.au[data-vista="rayos"]::after { animation: au-barre var(--au-rx-t) cubic-bezier(.5, 0, .5, 1) var(--au-rx-d) both; }
@keyframes au-barre {
  0% { transform: translateX(-100%); opacity: 1; }
  92% { opacity: 1; }
  100% { transform: translateX(0); opacity: 0; }
}

/* ---------- cargando: late el módulo que se está llenando y la energía corre por el cable ---------- */
/* El pulso solo se ve en el módulo i con nivel*10 entre i y i+1. */
.au[data-estado="cargando"] .au-pulso {
  --au-m: calc(var(--au-nivel, 0) * 10 - var(--i));
  opacity: clamp(0, min(calc(var(--au-m) * 1000 + 1), calc((1 - var(--au-m)) * 1000)), 1);
  fill-opacity: 0; animation: au-latido 1.6s ease-in-out infinite;
}
@keyframes au-latido { 50% { fill-opacity: .55; } }
.au[data-vista="rayos"][data-estado="cargando"] .au-rx-cable { stroke-opacity: .95; animation: au-flujo .9s linear infinite; }
@keyframes au-flujo { to { stroke-dashoffset: -16; } }
.au[data-estado="cargando"] .au-puerto { animation: au-latido-puerto 1.6s ease-in-out infinite; }
@keyframes au-latido-puerto { 50% { fill-opacity: .4; } }
.au[data-estado="lleno"] .au-rx-pack { stroke: var(--au-acento); stroke-width: 1.6; }

/* En tamaño chico el detalle fino es ruido: se oculta, y el porcentaje no se leería. */
.au[data-detalle="no"] .au-fino, .escena[data-tam="chica"] .au .au-fino, .escena[data-tam="chica"] .au .au-pct { display: none; }

@media (prefers-reduced-motion: reduce) {
  .au .au-solido, .au .au-rx { transition: none; }
  .au[data-vista="rayos"]::after { animation: none; opacity: 0; }
  .au[data-estado="cargando"] .au-pulso { animation: none; fill-opacity: .3; }
  .au[data-vista="rayos"][data-estado="cargando"] .au-rx-cable, .au[data-estado="cargando"] .au-puerto { animation: none; }
}
