/*
  Сцена голосового агента (scripts/work/scene-voice.mjs) — кадр вместо видео.

  Без класса is-live сцена стоит целиком: всё горит, сводная подпись внизу —
  так её видят без JavaScript и при «меньше движения». public/work.js ставит
  is-live и data-step 1…8 по кругу; на каждом шаге анимации заново стартуют,
  потому что селектор шага перестаёт и снова начинает совпадать.
  Импульс по проводу — штрих длиной 14 из 100 (pathLength), его гонит
  stroke-dashoffset: 14 → −100 от начала пути к концу, обратно — наоборот.
*/

/* Полупрозрачные --glacier (#bfe3ff) и --signal (#4fc8ff) — литералами rgba, не color-mix:
   Chrome 158 переход stroke от color-mix(…, transparent) к #4fc8ff считает в oklab
   и выдаёт oklab(1 200 255) — жёлтую рамку (проверено 24.11 getComputedStyle) */
.scene {
  --g8: rgba(191, 227, 255, 0.08);
  --g16: rgba(191, 227, 255, 0.16);
  --g28: rgba(191, 227, 255, 0.28);
  --g50: rgba(191, 227, 255, 0.5);
  --s14: rgba(79, 200, 255, 0.14);
  --s55: rgba(79, 200, 255, 0.55);
  position: absolute;
  inset: 0;
  container-type: inline-size;
  background:
    radial-gradient(60% 70% at 21% 50%, rgba(11, 58, 102, 0.3), transparent 70%),
    var(--void);
}
.scene svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.scene svg * { transition: opacity 0.35s ease, fill 0.35s ease, stroke 0.35s ease; }

/* --- Плата */
.scene .case { fill: #0a1825; stroke: var(--g28); stroke-width: 2; }
.scene .bevel { fill: none; stroke: var(--g8); stroke-width: 1.5; }
.scene pattern circle { fill: var(--g28); }
.scene .grille { fill: url(#vs-dots); }
.scene .grille-rim { fill: none; stroke: var(--g16); stroke-width: 2; }
.scene .mic { fill: var(--void); stroke: var(--g50); stroke-width: 1.5; }
.scene .port { fill: var(--g28); }
.scene .led { fill: var(--signal); filter: drop-shadow(0 0 7px var(--signal)); }
.scene .halo { opacity: 0.7; }
.scene .arc { fill: none; stroke: var(--glacier); stroke-width: 3; stroke-linecap: round; opacity: 0.22; transform-box: view-box; transform-origin: 330px 450px; }
.scene .caption-dev { font-family: var(--font-mono); font-size: 15px; letter-spacing: 3px; fill: var(--g50); text-anchor: middle; }
.scene .badge rect { fill: var(--s14); stroke: var(--s55); stroke-width: 1.5; }
.scene .badge text { font-family: var(--font-mono); font-size: 16px; letter-spacing: 2.6px; fill: var(--ice); text-anchor: middle; }
.scene .b-fw, .scene .b-ok { opacity: 0; }

/* --- Провода и узлы */
.scene .wire { fill: none; stroke: var(--g28); stroke-width: 2; stroke-dasharray: 2 7; }
.scene .pulse {
  fill: none;
  stroke: var(--signal);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 14 300;
  stroke-dashoffset: 14;
  filter: drop-shadow(0 0 6px var(--signal));
}
.scene .node { fill: #0a1622; stroke: var(--g28); stroke-width: 1.5; }
.scene .label { font-family: var(--font-mono); font-size: 17px; letter-spacing: 3.4px; fill: var(--signal); }
.scene .sub { font-family: var(--font-display); font-size: 21px; fill: var(--glacier); }
.scene .check { font-family: var(--font-mono); font-size: 16px; letter-spacing: 2px; fill: var(--signal); }
.scene .bar { fill: var(--signal); opacity: 0.6; transform-box: fill-box; transform-origin: center; }
.scene .chip rect { fill: transparent; stroke: var(--g28); stroke-width: 1.5; }
.scene .chip text { font-family: var(--font-mono); font-size: 14px; letter-spacing: 2px; fill: var(--glacier); text-anchor: middle; }
.scene .state { font-family: var(--font-mono); font-size: 16px; fill: var(--glacier); }
.scene .s-lights, .scene .st-done, .scene .st-ask, .scene .st-yes { opacity: 0; fill: var(--signal); }
.scene .dots circle { fill: var(--g28); }
.scene .sdot { fill: var(--g50); }

/* --- Реплики и подписи: HTML поверх, кегль от ширины кадра */
.scene .bubble {
  position: absolute;
  left: 9.4%;
  bottom: 72.5%;
  max-width: 40cqw;
  margin: 0;
  padding: 0.55em 0.95em;
  border-radius: 1.1em;
  font-size: clamp(10px, 1.55cqw, 17px);
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
}
.scene .bubble.you { color: var(--glacier); background: #0a1622; border: 1px solid var(--g28); border-bottom-left-radius: 0.25em; }
.scene .bubble.dev { color: var(--ice); background: #0e2a3a; border: 1px solid var(--s55); border-bottom-right-radius: 0.25em; }

.scene .scene-caps, .scene .scene-static {
  position: absolute;
  left: 9.4%;
  right: 4%;
  bottom: 5%;
  margin: 0;
  list-style: none;
  font-size: clamp(11px, 1.45cqw, 17px);
  color: var(--ice);
}
.scene .scene-caps { display: none; }
.scene .scene-caps li { position: absolute; left: 0; bottom: 0; display: flex; gap: 1.1em; margin: 0; padding: 0; opacity: 0; transition: opacity 0.4s ease; }
.scene .scene-caps li::before { content: none; }
.scene .scene-caps span { font-family: var(--font-mono); font-size: 0.8em; letter-spacing: 0.18em; color: var(--signal); padding-top: 0.2em; white-space: nowrap; }
.scene .scene-static { font-family: var(--font-mono); font-size: clamp(10px, 1.2cqw, 14px); letter-spacing: 0.08em; color: var(--glacier); }

/* --- Живой режим: всё гаснет, шаг зажигает своё */
.scene.is-live .scene-static { display: none; }
.scene.is-live .scene-caps { display: block; }
.scene.is-live .led { fill: var(--g16); filter: none; }
.scene.is-live .halo, .scene.is-live .arc, .scene.is-live .b-wake { opacity: 0; }
.scene.is-live .check { opacity: 0.22; }
.scene.is-live .bar { opacity: 0.18; transform: scaleY(0.3); }

.scene[data-step="1"] .scene-caps li:nth-child(1),
.scene[data-step="2"] .scene-caps li:nth-child(2),
.scene[data-step="3"] .scene-caps li:nth-child(3),
.scene[data-step="4"] .scene-caps li:nth-child(4),
.scene[data-step="5"] .scene-caps li:nth-child(5),
.scene[data-step="6"] .scene-caps li:nth-child(6),
.scene[data-step="7"] .scene-caps li:nth-child(7),
.scene[data-step="8"] .scene-caps li:nth-child(8) { opacity: 1; }

/* Кольцо горит, пока канал открыт (шаги 2–8) */
.scene.is-live:not([data-step="1"]) .led { fill: var(--signal); filter: drop-shadow(0 0 7px var(--signal)); }

/* 1 — слово на плате: голос входит, кольцо зажигается по кругу */
.scene[data-step="1"] .arc { animation: vs-arc 0.9s ease-out calc((2 - var(--i)) * 0.14s) 2 both; }
.scene[data-step="1"] .led { animation: vs-led 0.3s ease calc(1.2s + var(--i) * 0.09s) both; }
.scene[data-step="1"] .halo { animation: vs-show 0.6s ease 1.7s both; }
.scene[data-step="1"] .b-wake { animation: vs-show 0.4s ease 1.9s both; }

/* 2 — токен до модели */
.scene[data-step="2"] .p-dev { animation: vs-out 0.8s ease-in-out 0.1s both; }
.scene[data-step="2"] .bridge { animation: vs-node 0.4s ease 0.9s both; }
.scene[data-step="2"] .k-token { animation: vs-show 0.3s ease 1s both; }
.scene[data-step="2"] .k-mac { animation: vs-show 0.3s ease 1.4s both; }
.scene[data-step="2"] .p-live { animation: vs-out 0.8s ease-in-out 1.9s both; }
.scene[data-step="2"] .n-live { animation: vs-node 0.4s ease 2.6s both; }

/* 3 — модель слышит */
.scene[data-step="3"] .s3 { animation: vs-show 0.35s ease 0.1s both; }
.scene[data-step="3"] .arc { animation: vs-arc 0.9s ease-out calc(0.2s + (2 - var(--i)) * 0.14s) both; }
.scene[data-step="3"] .p-dev { animation: vs-out 0.8s ease-in-out 0.8s both; }
.scene[data-step="3"] .p-live { animation: vs-out 0.8s ease-in-out 1.5s both; }
.scene[data-step="3"] .n-live { animation: vs-node 0.4s ease 2.2s both; }
.scene[data-step="3"] .bar { animation: vs-bar 0.6s ease-in-out calc(2.2s + var(--i) * 0.035s) infinite alternate both; }

/* 4 — инструмент и ответ */
.scene[data-step="4"] .n-live { animation: vs-node 0.3s ease both; }
.scene[data-step="4"] .bar { animation: vs-bar 0.6s ease-in-out calc(var(--i) * 0.035s) 2 alternate both; }
.scene[data-step="4"] .p-live { animation: vs-in 0.8s ease-in-out 0.4s both; }
.scene[data-step="4"] .p-tools { animation: vs-out 0.8s ease-in-out 1.1s both; }
.scene[data-step="4"] .n-tools { animation: vs-node 0.4s ease 1.8s both; }
.scene[data-step="4"] .c-lights rect { animation: vs-chip 0.4s ease 1.8s both; }
.scene[data-step="4"] .s-lights { animation: vs-show 0.4s ease 1.9s both; }
.scene[data-step="4"] .p-dev { animation: vs-in 0.8s ease-in-out 2.2s both; }
.scene[data-step="4"] .s4 { animation: vs-show 0.35s ease 2.9s both; }
.scene[data-step="4"] .arc { animation: vs-arc 0.9s ease-out calc(2.9s + var(--i) * 0.14s) both; }

/* 5 — тяжёлое основному агенту */
.scene[data-step="5"] .s5 { animation: vs-show 0.35s ease 0.1s both; }
.scene[data-step="5"] .arc { animation: vs-arc 0.9s ease-out calc(0.2s + (2 - var(--i)) * 0.14s) both; }
.scene[data-step="5"] .p-dev { animation: vs-out 0.8s ease-in-out 0.8s both; }
.scene[data-step="5"] .p-agent { animation: vs-out 0.8s ease-in-out 1.5s both; }
.scene[data-step="5"] .n-agent { animation: vs-node 0.4s ease 2.2s both; }
.scene[data-step="5"] .dots circle { animation: vs-dot 0.9s ease-in-out 2.3s infinite both; }
.scene[data-step="5"] .dots circle:nth-child(2) { animation-delay: 2.45s; }
.scene[data-step="5"] .dots circle:nth-child(3) { animation-delay: 2.6s; }

/* 6 — говорит первой: чат закончил */
.scene[data-step="6"] .n-code { animation: vs-node 0.4s ease 0.2s both; }
.scene[data-step="6"] .st-run { animation: vs-hide 0.3s ease 0.2s both; }
.scene[data-step="6"] .st-done { animation: vs-show 0.3s ease 0.2s both; }
.scene[data-step="6"] .d1 { fill: var(--signal); }
.scene[data-step="6"] .p-code { animation: vs-in 0.8s ease-in-out 0.6s both; }
.scene[data-step="6"] .p-dev { animation: vs-in 0.8s ease-in-out 1.3s both; }
.scene[data-step="6"] .s6 { animation: vs-show 0.35s ease 2s both; }
.scene[data-step="6"] .arc { animation: vs-arc 0.9s ease-out calc(2s + var(--i) * 0.14s) 2 both; }
.scene[data-step="6"] .led { animation: vs-pulse 0.5s ease-in-out 2s 4 alternate both; }

/* 7 — окно разрешения голосом */
.scene[data-step="7"] .n-code { animation: vs-node 0.4s ease 0.1s both; }
.scene[data-step="7"] .st-idle { animation: vs-hide 0.3s ease 0.1s both; }
.scene[data-step="7"] .st-ask { animation: vs-ask 4.8s linear both; }
.scene[data-step="7"] .d2 { fill: var(--signal); }
/* Второй импульс — только forwards: с both его начало перекрыло бы первый ещё до старта */
.scene[data-step="7"] .p-code { animation: vs-in 0.7s ease-in-out 0.4s both, vs-out 0.6s ease-in-out 3.8s forwards; }
.scene[data-step="7"] .p-dev { animation: vs-in 0.7s ease-in-out 1s both, vs-out 0.6s ease-in-out 3.3s forwards; }
.scene[data-step="7"] .s7a { animation: vs-window 4.8s linear both; }
.scene[data-step="7"] .led { animation: vs-pulse 0.5s ease-in-out 1.8s 2 alternate both; }
.scene[data-step="7"] .s7b { animation: vs-show 0.3s ease 3.1s both; }
.scene[data-step="7"] .st-yes { animation: vs-show 0.3s ease 4.3s both; }

/* 8 — прошивка с воздуха и отметка платы */
.scene[data-step="8"] .b-fw { animation: vs-fw 4.2s linear both; }
.scene[data-step="8"] .p-dev { stroke: var(--ice); animation: vs-in 1s ease-in-out 0.2s both, vs-out 0.7s ease-in-out 2.6s forwards; }
.scene[data-step="8"] .led { animation: vs-flash 0.25s ease-in-out 1.3s 6 alternate both; }
.scene[data-step="8"] .b-ok { animation: vs-show 0.3s ease 2.4s both; }
.scene[data-step="8"] .bridge { animation: vs-node 0.4s ease 3.2s both; }

@keyframes vs-out { from { stroke-dashoffset: 14; } to { stroke-dashoffset: -100; } }
@keyframes vs-in { from { stroke-dashoffset: -100; } to { stroke-dashoffset: 14; } }
@keyframes vs-show { from { opacity: 0; } to { opacity: 1; } }
@keyframes vs-hide { from { opacity: 1; } to { opacity: 0; } }
@keyframes vs-node { to { stroke: var(--signal); fill: #0c2134; } }
@keyframes vs-chip { to { fill: var(--signal); stroke: var(--signal); } }
@keyframes vs-led { from { fill: var(--g16); filter: none; } to { fill: var(--signal); filter: drop-shadow(0 0 7px var(--signal)); } }
@keyframes vs-pulse { from { opacity: 1; } to { opacity: 0.35; } }
@keyframes vs-flash { from { fill: var(--signal); } to { fill: var(--ice); } }
@keyframes vs-arc { 0% { opacity: 0; transform: scale(1.12); } 35% { opacity: 0.8; } 100% { opacity: 0; transform: scale(0.94); } }
@keyframes vs-bar { from { opacity: 0.45; transform: scaleY(0.3); } to { opacity: 1; transform: scaleY(1); } }
@keyframes vs-dot { 0%, 100% { fill: var(--g28); } 50% { fill: var(--signal); } }
@keyframes vs-ask { 0%, 2% { opacity: 0; } 6%, 86% { opacity: 1; } 90%, 100% { opacity: 0; } }
@keyframes vs-window { 0%, 36% { opacity: 0; } 40%, 61% { opacity: 1; } 64%, 100% { opacity: 0; } }
@keyframes vs-fw { 0%, 2% { opacity: 0; } 6%, 52% { opacity: 1; } 56%, 100% { opacity: 0; } }

/* Чип «LIGHTS» горит — текст на нём тёмный */
.scene[data-step="4"] .c-lights text { animation: vs-chip-text 0.4s ease 1.8s both; }
@keyframes vs-chip-text { to { fill: var(--void); } }
