/* ==========================================================================
   «Магия» — сцены анализа бизнеса и сборки кабинета (docs/SPEC.md §16.9,
   M21 «вау»). Тёмная кинематографичная тема по умолчанию, светлая — через
   [data-theme="light"] (opts.theme или data-theme="light" на <html>). Цвета —
   токены панели (public/panel/panel.css) через var(...) с литеральными
   фолбэками, чтобы работать и без неё (magic-demo.html). Анимируются только
   transform/opacity/filter/clip-path; орб рисует canvas (magic.js).
   ========================================================================== */

/* Блокировка прокрутки страницы под оверлеем (magic.js lockBodyScroll) — классом, без inline-стиля (CSP). */
body.apz-body-locked { overflow: hidden; }

.apz-magic-overlay {
  --apz-ease: cubic-bezier(.22, 1, .36, 1);
  --apz-dur-fade: .3s;
  --apz-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --apz-tight: 'Inter Tight', Inter, -apple-system, BlinkMacSystemFont, Arial, sans-serif;

  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: grid;
  place-items: center;
  overflow: hidden;
  isolation: isolate;
  background: var(--m-bg);
  color: var(--m-fg);
  opacity: 0;
  transform: scale(1.015);
  transition: opacity .5s var(--apz-ease), transform .6s var(--apz-ease);
  -webkit-font-smoothing: antialiased;
  outline: none;
}
.apz-magic-overlay.is-visible { opacity: 1; transform: scale(1); }
.apz-magic-overlay.is-leaving {
  opacity: 0;
  transform: scale(1.03);
  transition: opacity .5s var(--apz-ease), transform .5s var(--apz-ease);
}

/* --- темы: токены панели, перекрытые под сцену --- */
.apz-magic-overlay,
.apz-magic-overlay[data-theme="dark"] {
  --m-bg: var(--dark, #0A0A0F);
  --m-fg: var(--on-dark, #F4F4F6);
  --m-fg-2: var(--on-dark-2, rgba(244, 244, 246, .62));
  --m-fg-3: rgba(244, 244, 246, .58);
  --m-line: rgba(244, 244, 246, .12);
  --m-line-2: rgba(244, 244, 246, .22);
  --m-card: rgba(255, 255, 255, .06);
  --m-card-2: rgba(255, 255, 255, .1);
  --m-accent: #B9A8FF;
  --m-ok: #4FD6A0;
  --m-sheen-1: #C9B8FF;
  --m-sheen-2: #8E78FF;
  --m-glow: rgba(91, 76, 255, .34);
  --m-glow-2: rgba(124, 92, 255, .14);
  --m-vignette: rgba(0, 0, 0, .6);
  --m-grain: .06;
  --m-skip-bg: rgba(255, 255, 255, .08);
  --m-skip-bg-h: rgba(255, 255, 255, .16);
  --apz-orb-core: 233, 225, 255;
  --apz-orb-mid: 124, 92, 255;
  --apz-orb-deep: 59, 43, 217;
  --apz-orb-line: 201, 184, 255;
  --apz-orb-dot: 244, 244, 246;
}
.apz-magic-overlay[data-theme="light"] {
  --m-bg: var(--bg, #F7F7F8);
  --m-fg: var(--ink, #0A0A0D);
  --m-fg-2: var(--ink-2, #5B5B66);
  --m-fg-3: var(--ink-3, #6B6B76);
  --m-line: var(--line, rgba(10, 10, 13, .08));
  --m-line-2: var(--line-2, rgba(10, 10, 13, .14));
  --m-card: var(--surface, #fff);
  --m-card-2: var(--surface-2, #EFEFF2);
  --m-accent: var(--accent, #5B4CFF);
  --m-ok: var(--ok-ink, #167A50);
  --m-sheen-1: #5B4CFF;
  --m-sheen-2: #7C5CFF;
  --m-glow: rgba(91, 76, 255, .2);
  --m-glow-2: rgba(201, 184, 255, .32);
  --m-vignette: var(--bg, #F7F7F8);
  --m-grain: .035;
  --m-skip-bg: rgba(255, 255, 255, .72);
  --m-skip-bg-h: #fff;
  --apz-orb-core: 91, 76, 255;
  --apz-orb-mid: 124, 92, 255;
  --apz-orb-deep: 27, 17, 80;
  --apz-orb-line: 59, 43, 217;
  --apz-orb-dot: 27, 17, 80;
}

@media (prefers-reduced-motion: reduce) {
  .apz-magic-overlay { transform: none; transition: opacity .6s linear; }
  .apz-magic-overlay.is-visible,
  .apz-magic-overlay.is-leaving { transform: none; }
  .apz-magic-overlay.is-leaving { transition: opacity .6s linear; }
}

/* --- верхняя линия прогресса --- */

.apz-magic-topline {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  height: 2px;
  background: var(--m-line);
}
.apz-magic-topline-bar {
  height: 100%;
  width: var(--apz-p, 0%);
  border-radius: 0 999px 999px 0;
  background: var(--grad, linear-gradient(135deg, #1B1150 0%, #3B2BD9 38%, #7C5CFF 70%, #C9B8FF 100%));
  box-shadow: 0 0 16px var(--glow, rgba(91, 76, 255, .35));
  transition: width .6s var(--apz-ease);
}

/* --- фон: ореол, виньетка, зерно, вспышка --- */

.apz-magic-glow {
  position: absolute;
  inset: -10%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(52% 46% at 50% 36%, var(--m-glow), transparent 72%),
    radial-gradient(38% 34% at 82% 78%, var(--m-glow-2), transparent 70%),
    radial-gradient(34% 30% at 14% 70%, var(--m-glow-2), transparent 70%);
  animation: apz-glow-drift 22s ease-in-out infinite alternate;
  will-change: transform;
}
@keyframes apz-glow-drift {
  from { transform: translate3d(-1.5%, -1%, 0) scale(1); }
  to { transform: translate3d(1.5%, 1.2%, 0) scale(1.06); }
}
.apz-magic-overlay[data-stage="decide"] .apz-magic-glow,
.apz-magic-overlay[data-stage="cabinet"] .apz-magic-glow { filter: saturate(1.25) brightness(1.12); transition: filter 1.2s var(--apz-ease); }

.apz-magic-vignette {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(ellipse 90% 80% at 50% 42%, transparent 40%, var(--m-vignette) 100%);
}

.apz-magic-grain {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: var(--m-grain);
  background-repeat: repeat;
  background-size: 180px 180px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.apz-magic-flash {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at var(--apz-fx, 50%) var(--apz-fy, 40%), rgba(255, 255, 255, .6), rgba(124, 92, 255, .28) 16%, transparent 44%);
}
.apz-magic-overlay[data-theme="light"] .apz-magic-flash {
  background: radial-gradient(circle at var(--apz-fx, 50%) var(--apz-fy, 40%), rgba(124, 92, 255, .4), rgba(201, 184, 255, .3) 18%, transparent 46%);
}
.apz-magic-flash.is-on { animation: apz-flash 1s ease-out both; }
@keyframes apz-flash {
  0% { opacity: 0; transform: scale(.9); }
  16% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.12); }
}

/* --- canvas с орбом: поверх колонки, не перехватывает курсор --- */

.apz-magic-canvas {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* --- колонка контента --- */

.apz-magic-stack {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.5dvh, 16px);
  width: 100%;
  max-width: 920px;
  max-height: 100%;
  padding: clamp(16px, 3dvh, 32px) 20px;
  overflow-y: auto;
  scrollbar-width: none;
  text-align: center;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .7s var(--apz-ease), transform .7s var(--apz-ease);
}
.apz-magic-stack::-webkit-scrollbar { display: none; }
.apz-magic-stack > * { flex: none; }
.apz-magic-stack.is-in { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .apz-magic-stack { transform: none; transition: opacity var(--apz-dur-fade) linear; }
}

/* --- шапка-мета: ● ТИТУЛ · host · 00:14 --- */

.apz-magic-eyebrow {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 100%;
  font-family: var(--apz-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  color: var(--m-fg-3);
}
.apz-eyebrow-title { color: var(--m-fg-2); }
.apz-eyebrow-dot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--m-accent);
  box-shadow: 0 0 10px var(--m-accent);
}
.apz-eyebrow-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid var(--m-accent);
  animation: apz-dot-ping 1.8s var(--apz-ease) infinite;
}
@keyframes apz-dot-ping {
  0% { transform: scale(1); opacity: .8; }
  100% { transform: scale(3.2); opacity: 0; }
}
.apz-status-part:empty { display: none; }
.apz-status-part::before { content: "·"; margin-right: 8px; color: var(--m-fg-3); }
.apz-status-host { text-transform: none; letter-spacing: .02em; max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- место орба: размер берётся из свободной высоты экрана --- */

.apz-magic-scene {
  position: relative;
  flex: none;
  width: min(100%, 560px);
  height: clamp(160px, calc(100dvh - 480px), 420px);
}
.apz-magic-overlay[data-mode="assemble"] .apz-magic-scene {
  width: min(100%, 640px);
  height: clamp(220px, calc(100dvh - 300px), 380px);
}

/* --- подпись этапа (aria-live): слова с blur-въездом и переливом бренда --- */

.apz-magic-lower {
  position: relative;
  display: grid;
  justify-items: center;
  width: 100%;
}
.apz-magic-lower > .apz-magic-live { grid-area: 1 / 1; min-width: 0; }

.apz-magic-live {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  transition: opacity .5s var(--apz-ease), transform .5s var(--apz-ease);
}
.apz-magic-title-mask { position: relative; width: 100%; min-height: 1.1em; font-size: clamp(30px, 4.2vw, 52px); line-height: 1.1; }

.apz-magic-title {
  margin: 0;
  font-family: var(--apz-tight);
  font-weight: 700;
  font-size: inherit;
  line-height: inherit;
  letter-spacing: -.03em;
  color: var(--m-fg);
  text-wrap: balance;
}

.apz-magic-title .apz-word {
  display: inline-block;
  opacity: 0;
  transform: translateY(.4em);
  filter: blur(8px);
  color: var(--m-fg);
  background-image: linear-gradient(100deg, var(--m-fg) 0%, var(--m-fg) 34%, var(--m-sheen-1) 46%, var(--m-sheen-2) 54%, var(--m-fg) 66%, var(--m-fg) 100%);
  background-size: 300% 100%;
  background-position: 100% 0;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: apz-word-in .85s var(--apz-ease) both, apz-sheen 6s linear infinite;
  animation-delay: calc(var(--w, 0) * 55ms), calc(var(--w, 0) * -.5s);
}
@keyframes apz-word-in { from { opacity: 0; transform: translateY(.4em); filter: blur(8px); } to { opacity: 1; transform: none; filter: blur(0); } }
@keyframes apz-sheen { from { background-position: 100% 0; } to { background-position: -200% 0; } }

/* предыдущая подпись улетает вверх призраком (поверх, без сдвига раскладки) */
.apz-magic-title.apz-title-ghost {
  position: absolute;
  inset: 0 0 auto 0;
  pointer-events: none;
  animation: apz-ghost-out .55s var(--apz-ease) both;
}
.apz-title-ghost .apz-word { animation: none; opacity: 1; transform: none; filter: none; }
@keyframes apz-ghost-out { to { opacity: 0; transform: translateY(-.45em); filter: blur(10px); } }

.apz-magic-detail {
  margin: 0;
  max-width: 560px;
  min-height: 1.5em;
  font-size: 16px;
  line-height: 1.5;
  color: var(--m-fg-2);
  text-wrap: balance;
}

@media (prefers-reduced-motion: reduce) {
  .apz-magic-title .apz-word { animation: none; opacity: 1; transform: none; filter: none; }
  .apz-magic-title.apz-title-ghost { display: none; }
}

/* --- живые факты: счётчики (только когда пришло число) --- */

.apz-magic-counters {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 10px;
  width: min(100%, 560px);
  min-height: 76px;
  transition: opacity .5s var(--apz-ease), transform .5s var(--apz-ease);
}
.apz-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--m-line-2);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .5s var(--apz-ease), transform .6s var(--apz-ease);
}
.apz-counter[hidden] { display: flex; visibility: hidden; }
.apz-counter.is-in { opacity: 1; transform: none; }
.apz-counter-num {
  font-family: var(--apz-tight);
  font-weight: 700;
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  color: var(--m-fg);
}
.apz-counter-label {
  font-family: var(--apz-mono);
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--m-fg-3);
}

/* --- пилюли фактов и чипы найденных страниц --- */

.apz-magic-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  min-height: 32px;
  transition: opacity .5s var(--apz-ease), transform .5s var(--apz-ease);
}
.apz-pill {
  padding: 6px 13px;
  border-radius: var(--r-pill, 999px);
  background: var(--m-card);
  border: 1px solid var(--m-line-2);
  color: var(--m-fg-2);
  font-size: 12.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transform: scale(.86);
  transition: opacity .4s var(--apz-ease), transform .5s cubic-bezier(.34, 1.56, .64, 1);
}
.apz-pill.is-in { opacity: 1; transform: none; }
.apz-pill.is-accent { color: var(--m-fg); border-color: var(--m-accent); box-shadow: 0 0 22px -6px var(--m-glow); }

.apz-magic-chips {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  gap: 8px;
  width: min(100%, 760px);
  min-height: 70px;
  max-height: 76px;
  overflow: hidden;
  transition: opacity .5s var(--apz-ease), transform .5s var(--apz-ease);
}
.apz-chip {
  display: inline-flex;
  align-items: center;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 6px 12px;
  border-radius: var(--r-pill, 999px);
  background: var(--m-card);
  border: 1px solid var(--m-line);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--m-fg-2);
  animation: apz-chip-land .6s var(--apz-ease) both;
  animation-delay: var(--apz-chip-delay, 0ms);
}
@keyframes apz-chip-land {
  from { opacity: 0; transform: translateY(-26px) scale(.7); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: blur(0); }
}
.apz-chip-reduced { animation: apz-chip-fade .3s linear both; }
@keyframes apz-chip-fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .apz-counter,
  .apz-pill { transform: none; transition: opacity var(--apz-dur-fade) linear; }
}

/* --- степпер: тонкие полосы прогресса, как на лендинге --- */

.apz-magic-stepper {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr));
  gap: 10px;
  width: min(100%, 720px);
  counter-reset: apz-step;
  transition: opacity .5s var(--apz-ease), transform .5s var(--apz-ease);
}
.apz-step {
  counter-increment: apz-step;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  text-align: left;
}
.apz-step:not(.is-running):not(.is-done) .apz-step-bar { opacity: .6; }

.apz-step-bar {
  display: block;
  height: 3px;
  border-radius: 3px;
  background: var(--m-line-2);
  overflow: hidden;
}
.apz-step-bar b {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--grad, linear-gradient(135deg, #3B2BD9, #7C5CFF 70%, #C9B8FF));
  transform: scaleX(0);
  transform-origin: 0 50%;
}
.apz-step.is-running .apz-step-bar b { animation: apz-step-fill 9s cubic-bezier(.12, .6, .2, 1) forwards; }
.apz-step.is-done .apz-step-bar b { transform: scaleX(1); transition: transform .5s var(--apz-ease); }
@keyframes apz-step-fill { from { transform: scaleX(0); } to { transform: scaleX(.92); } }

.apz-step-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--m-fg-3);
}
.apz-step-label::before {
  content: counter(apz-step);
  margin-right: 7px;
  font-family: var(--apz-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--m-accent);
}
.apz-step.is-running .apz-step-label { color: var(--m-fg); }
.apz-step.is-done .apz-step-label { color: var(--m-fg-2); }

@media (prefers-reduced-motion: reduce) {
  .apz-step.is-running .apz-step-bar b { animation: none; transform: scaleX(.5); }
}

/* --- мини-кабинет (сцена assemble) --- */

.apz-cab {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: clamp(52px, 17%, 120px) minmax(0, 1fr);
  gap: 12px;
  padding: 14px;
  overflow: hidden;
  border-radius: var(--r-lg, 20px);
  background: var(--m-card);
  border: 1px solid var(--m-line-2);
  box-shadow: 0 40px 90px -36px var(--m-glow);
}
.apz-cab-block {
  opacity: 0;
  transform: translateY(14px) scale(.97);
  filter: blur(8px);
  transition: opacity .6s var(--apz-ease), transform .7s var(--apz-ease), filter .6s var(--apz-ease);
}
.apz-cab-block.is-in { opacity: 1; transform: none; filter: blur(0); }

.apz-cab-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 12px 8px;
  border-radius: var(--r-md, 12px);
  background: var(--m-card-2);
}
.apz-cab-logo { width: 22px; height: 22px; flex: none; border-radius: 7px; background: var(--grad, linear-gradient(135deg, #1B1150, #3B2BD9 38%, #7C5CFF 70%, #C9B8FF)); }
.apz-cab-nav { display: flex; flex-direction: column; gap: 9px; width: 100%; }
.apz-cab-nav-item { height: 6px; border-radius: 999px; background: var(--m-line-2); }
.apz-cab-nav-item.is-active { background: var(--m-accent); }

.apz-cab-main { display: flex; flex-direction: column; gap: 12px; min-width: 0; min-height: 0; }
.apz-cab-topbar { flex: none; height: 14px; width: 52%; border-radius: 999px; background: var(--m-card-2); }
.apz-cab-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; flex: none; }
.apz-cab-kpi {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: var(--r-md, 12px);
  background: var(--m-card-2);
  text-align: left;
}
.apz-cab-kpi-label { font-family: var(--apz-mono); font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--m-fg-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.apz-cab-kpi-value { min-height: 1.3em; font-size: 14px; font-weight: 600; color: var(--m-fg); white-space: nowrap; }
.apz-cab-kpi-value:empty::before { content: ""; display: block; height: 10px; width: 56%; margin-top: 4px; border-radius: 6px; background: var(--m-line-2); }
.apz-cab-kpi.is-done .apz-cab-kpi-value { color: var(--m-ok); }
.apz-cab-rows { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; overflow: hidden; }
.apz-cab-row { flex: 1 1 0; min-height: 16px; max-height: 36px; border-radius: var(--r-sm, 10px); background: var(--m-card-2); }

/* слот виджета: сюда «стыкуется» орб на стадии «Подключаю виджет» */
.apz-cab-dock {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px dashed var(--m-line-2);
  transition: border-color .6s var(--apz-ease), box-shadow .8s var(--apz-ease);
}
.apz-cab.is-docking .apz-cab-dock { border-style: solid; border-color: var(--m-accent); box-shadow: 0 0 30px -4px var(--m-glow); }
.apz-cab-bubble {
  position: absolute;
  right: 14px;
  bottom: 84px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: min(200px, 60%);
  padding: 10px 12px;
  border-radius: var(--r-md, 12px);
  background: var(--m-card-2);
  border: 1px solid var(--m-line-2);
  box-shadow: 0 16px 40px -18px rgba(0, 0, 0, .5);
  opacity: 0;
  transform: translateY(10px) scale(.94);
  transform-origin: 100% 100%;
  transition: opacity .5s var(--apz-ease), transform .6s cubic-bezier(.34, 1.56, .64, 1);
}
.apz-cab-bubble.is-in { opacity: 1; transform: none; }
.apz-cab-msg { font-size: 11.5px; line-height: 1.3; padding: 5px 10px; border-radius: 999px; text-align: left; }
.apz-cab-msg-in { align-self: flex-start; background: var(--m-card); color: var(--m-fg-2); }
.apz-cab-msg-out { align-self: flex-end; background: var(--accent, #5B4CFF); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .apz-cab-block { transform: none; filter: none; transition: opacity var(--apz-dur-fade) linear; }
  .apz-cab-bubble { transform: none; transition: opacity var(--apz-dur-fade) linear; }
}

/* --- финал и ошибка: на месте подписи этапа --- */

.apz-magic-overlay.is-finishing .apz-magic-live,
.apz-magic-overlay.is-finishing .apz-magic-counters,
.apz-magic-overlay.is-finishing .apz-magic-pills,
.apz-magic-overlay.is-finishing .apz-magic-chips,
.apz-magic-overlay.is-finishing .apz-magic-stepper,
.apz-magic-overlay.is-finishing .apz-magic-eyebrow {
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}
.apz-magic-overlay.is-finishing .apz-magic-eyebrow { transition: opacity .5s var(--apz-ease), transform .5s var(--apz-ease); }

.apz-magic-final {
  /* поверх подписи этапа, но вне раскладки: колонка не «прыгает» при финале */
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 680px;
  margin: 0 auto;
  text-align: center;
  visibility: hidden;
}
.apz-magic-final.is-in { visibility: visible; }

.apz-magic-headline {
  margin: 0;
  padding: .05em .08em;
  font-family: var(--apz-tight);
  font-weight: 700;
  font-size: clamp(34px, 5vw, 60px);
  letter-spacing: -.035em;
  line-height: 1.08;
  text-wrap: balance;
  color: var(--m-fg);
  background-image: linear-gradient(100deg, var(--m-fg) 0%, var(--m-fg) 45%, var(--m-sheen-1) 75%, var(--m-sheen-2) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  clip-path: inset(0 100% 0 0);
  filter: blur(10px);
  transition: clip-path .9s var(--apz-ease), filter .9s var(--apz-ease);
}
.apz-magic-final.is-in .apz-magic-headline { clip-path: inset(-10% -4% -10% -4%); filter: blur(0); }

.apz-magic-sub {
  margin: 0;
  font-size: 17px;
  line-height: 1.5;
  color: var(--m-fg-2);
  text-wrap: balance;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .6s var(--apz-ease), transform .6s var(--apz-ease);
}
.apz-magic-sub.is-in { opacity: 1; transform: none; }

/* мягкое завершение fail() — без заголовка, только сообщение */
.apz-magic-final.is-fail .apz-magic-headline { display: none; }
.apz-magic-final.is-fail .apz-magic-sub { font-size: 20px; color: var(--m-fg); }

@media (prefers-reduced-motion: reduce) {
  .apz-magic-headline { clip-path: none; filter: none; opacity: 0; transition: opacity var(--apz-dur-fade) linear; }
  .apz-magic-final.is-in .apz-magic-headline { clip-path: none; opacity: 1; }
  .apz-magic-sub { transform: none; transition: opacity var(--apz-dur-fade) linear; }
  .apz-magic-glow { animation: none; }
  .apz-eyebrow-dot::after { animation: none; opacity: 0; }
}

/* --- кнопка «Пропустить анимацию»: цель касания ≥44px --- */

.apz-magic-skip {
  position: absolute;
  right: 20px;
  bottom: 20px;
  z-index: 5;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--m-line-2);
  border-radius: 999px;
  background: var(--m-skip-bg);
  color: var(--m-fg-2);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: background-color .2s var(--apz-ease), color .2s var(--apz-ease), border-color .2s var(--apz-ease);
}
.apz-magic-skip:hover { background: var(--m-skip-bg-h); color: var(--m-fg); }
.apz-magic-skip:focus-visible { outline: 2px solid var(--m-accent); outline-offset: 2px; }

/* --- планшет и телефон --- */

@media (max-width: 900px) {
  .apz-magic-stack { padding-bottom: 68px; } /* место под кнопку «Пропустить» */
}
@media (max-width: 640px) {
  .apz-magic-stack { padding: 20px 16px 68px; }
  .apz-magic-scene { height: clamp(140px, calc(100dvh - 520px), 360px); }
  .apz-magic-overlay[data-mode="assemble"] .apz-magic-scene { height: clamp(220px, calc(100dvh - 380px), 380px); }
  .apz-magic-title-mask { font-size: clamp(26px, 7.4vw, 34px); min-height: 2.2em; }
  .apz-magic-detail { font-size: 14.5px; min-height: 3em; }
  .apz-magic-counters { min-height: 64px; gap: 6px; }
  .apz-counter-num { font-size: 28px; }
  .apz-counter-label { font-size: 10px; }
  .apz-magic-chips { min-height: 64px; max-height: 68px; gap: 6px; }
  .apz-chip { max-width: 140px; font-size: 12px; padding: 5px 10px; }
  .apz-magic-stepper { gap: 8px; }
  /* на телефоне подпись этапа уже крупно над счётчиками — подписи степпера только для скринридеров */
  .apz-step-label { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .apz-step { position: relative; }
  .apz-cab { gap: 8px; padding: 10px; }
  .apz-cab-kpis { gap: 6px; }
  .apz-cab-kpi { padding: 8px; }
  .apz-cab-kpi-label { font-size: 9px; }
  .apz-cab-kpi-value { font-size: 12px; }
  .apz-cab-dock { right: 10px; bottom: 10px; width: 48px; height: 48px; }
  .apz-cab-bubble { right: 10px; bottom: 70px; }
  .apz-magic-sub { font-size: 15px; }
}
@media (max-width: 480px) {
  .apz-magic-skip { right: 12px; bottom: 12px; padding: 0 14px; font-size: 12.5px; }
}
@media (max-height: 640px) {
  .apz-magic-counters { min-height: 0; }
  .apz-magic-chips { min-height: 0; }
}

/* ==========================================================================
   Каскадное появление карточек — APZMagic.reveal(rootEl) и класс .apz-reveal
   без JS (нужны --i через nth-child для первых 12 потомков .card/.grad-card/.kpi
   в контейнерах .grid/.kpi-grid, или инлайновый --i, который ставит reveal()).
   Не часть сцены — используется независимо (например, на «Сегодня»).
   ========================================================================== */

@keyframes apz-card-in {
  from { opacity: 0; transform: translateY(18px) scale(.985); }
  to { opacity: 1; transform: none; }
}
@keyframes apz-card-glow {
  0% { filter: brightness(1); }
  45% { filter: brightness(1.2); }
  100% { filter: brightness(1); }
}

.apz-reveal .card,
.apz-reveal.card,
.apz-reveal .kpi,
.apz-reveal.kpi {
  animation: apz-card-in .52s var(--apz-ease, cubic-bezier(.16, 1, .3, 1)) both;
  animation-delay: calc(var(--i, 0) * 70ms);
}

.apz-reveal .grad-card,
.apz-reveal.grad-card {
  animation:
    apz-card-in .52s var(--apz-ease, cubic-bezier(.16, 1, .3, 1)) both,
    apz-card-glow .9s var(--apz-ease, cubic-bezier(.16, 1, .3, 1)) both;
  animation-delay: calc(var(--i, 0) * 70ms), calc(var(--i, 0) * 70ms + 420ms);
}

/* автоматический --i по позиции в сетке — работает без JS */
:is(.apz-reveal.grid, .apz-reveal .grid, .apz-reveal.kpi-grid, .apz-reveal .kpi-grid, .apz-reveal) > :is(.card, .grad-card, .kpi):nth-child(1) { --i: 0; }
:is(.apz-reveal.grid, .apz-reveal .grid, .apz-reveal.kpi-grid, .apz-reveal .kpi-grid, .apz-reveal) > :is(.card, .grad-card, .kpi):nth-child(2) { --i: 1; }
:is(.apz-reveal.grid, .apz-reveal .grid, .apz-reveal.kpi-grid, .apz-reveal .kpi-grid, .apz-reveal) > :is(.card, .grad-card, .kpi):nth-child(3) { --i: 2; }
:is(.apz-reveal.grid, .apz-reveal .grid, .apz-reveal.kpi-grid, .apz-reveal .kpi-grid, .apz-reveal) > :is(.card, .grad-card, .kpi):nth-child(4) { --i: 3; }
:is(.apz-reveal.grid, .apz-reveal .grid, .apz-reveal.kpi-grid, .apz-reveal .kpi-grid, .apz-reveal) > :is(.card, .grad-card, .kpi):nth-child(5) { --i: 4; }
:is(.apz-reveal.grid, .apz-reveal .grid, .apz-reveal.kpi-grid, .apz-reveal .kpi-grid, .apz-reveal) > :is(.card, .grad-card, .kpi):nth-child(6) { --i: 5; }
:is(.apz-reveal.grid, .apz-reveal .grid, .apz-reveal.kpi-grid, .apz-reveal .kpi-grid, .apz-reveal) > :is(.card, .grad-card, .kpi):nth-child(7) { --i: 6; }
:is(.apz-reveal.grid, .apz-reveal .grid, .apz-reveal.kpi-grid, .apz-reveal .kpi-grid, .apz-reveal) > :is(.card, .grad-card, .kpi):nth-child(8) { --i: 7; }
:is(.apz-reveal.grid, .apz-reveal .grid, .apz-reveal.kpi-grid, .apz-reveal .kpi-grid, .apz-reveal) > :is(.card, .grad-card, .kpi):nth-child(9) { --i: 8; }
:is(.apz-reveal.grid, .apz-reveal .grid, .apz-reveal.kpi-grid, .apz-reveal .kpi-grid, .apz-reveal) > :is(.card, .grad-card, .kpi):nth-child(10) { --i: 9; }
:is(.apz-reveal.grid, .apz-reveal .grid, .apz-reveal.kpi-grid, .apz-reveal .kpi-grid, .apz-reveal) > :is(.card, .grad-card, .kpi):nth-child(11) { --i: 10; }
:is(.apz-reveal.grid, .apz-reveal .grid, .apz-reveal.kpi-grid, .apz-reveal .kpi-grid, .apz-reveal) > :is(.card, .grad-card, .kpi):nth-child(12) { --i: 11; }

@media (prefers-reduced-motion: reduce) {
  .apz-reveal .card, .apz-reveal.card,
  .apz-reveal .kpi, .apz-reveal.kpi,
  .apz-reveal .grad-card, .apz-reveal.grad-card {
    animation: apz-card-in-reduced .3s linear both;
    animation-delay: calc(var(--i, 0) * 40ms);
  }
}
@keyframes apz-card-in-reduced { from { opacity: 0; } to { opacity: 1; } }

/* ==========================================================================
   Ниже — только вёрстка magic-demo.html (просмотр сцен), к панели отношения
   не имеет. Использует токены и компоненты panel.css (карточки, кнопки).
   ========================================================================== */

.apz-demo { max-width: 1040px; margin: 0 auto; padding: 48px 24px 96px; }
.apz-demo-head { max-width: 680px; margin-bottom: 28px; display: flex; flex-direction: column; gap: 10px; }
.apz-demo-head h1 { font-size: clamp(24px, 3.6vw, 34px); }
.apz-demo-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.apz-demo-slow { display: flex; align-items: center; gap: 9px; margin-bottom: 18px; font-size: 13.5px; color: var(--ink-2, #5B5B66); cursor: pointer; }
.apz-demo-slow input { width: 16px; height: 16px; accent-color: var(--accent, #5B4CFF); cursor: pointer; }
.apz-demo-log { min-height: 1.4em; margin-bottom: 28px; font-size: 13.5px; }
.apz-demo-hero .eyebrow, .apz-demo-hero h2, .apz-demo-hero p { color: #fff; }
.apz-demo-hero .eyebrow { color: rgba(255, 255, 255, .72); }
.apz-demo-hero .muted { color: rgba(255, 255, 255, .82); }

@media (max-width: 480px) {
  .apz-demo { padding: 32px 16px 72px; }
}
