/* ─── Living Cosmos — фон «живая вселенная» ───────────────────────────────
 * Слои:
 * 1) .cosmic-bg::before/.after — CSS-градиенты туманностей (медленный дрифт)
 * 2) #cosmic-stars — Canvas 2D: звёзды, пыль, созвездия, падающие звёзды, импульс
 * 3) .cosmic-geometry — SVG-мандалы и сакральные фигуры (мягкое появление)
 * Контент — выше по z-index. Учитывает prefers-reduced-motion и тему.
 * В светлой теме — «пергаментный космос» (ink-звёзды на тёплом кремовом фоне).
 * ───────────────────────────────────────────────────────────────────────── */
.cosmic-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}
.cosmic-nebula,
.cosmic-nebula::after { position: absolute; inset: -18%; pointer-events: none; }
.cosmic-nebula {
  background:
    radial-gradient(46rem 34rem at 16% 22%, rgba(81, 65, 122, 0.5), transparent 62%),
    radial-gradient(52rem 40rem at 86% 12%, rgba(32, 42, 73, 0.85), transparent 60%),
    radial-gradient(48rem 42rem at 78% 88%, rgba(76, 158, 170, 0.28), transparent 58%),
    radial-gradient(40rem 34rem at 12% 82%, rgba(214, 179, 106, 0.1), transparent 55%);
  filter: saturate(1.05);
  animation: cosmic-nebula-drift 36s ease-in-out infinite alternate;
}
.cosmic-nebula::after {
  content: "";
  background:
    radial-gradient(30rem 22rem at 62% 46%, rgba(169, 154, 245, 0.16), transparent 60%),
    radial-gradient(24rem 18rem at 30% 60%, rgba(214, 179, 106, 0.12), transparent 62%);
  animation: cosmic-nebula-drift-2 28s ease-in-out infinite alternate;
}
@keyframes cosmic-nebula-drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(3.5%, -3%, 0) scale(1.06); }
}
@keyframes cosmic-nebula-drift-2 {
  from { transform: translate3d(0, 0, 0) scale(1.02); }
  to   { transform: translate3d(-4%, 3.5%, 0) scale(1); }
}
#cosmic-stars { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* Сакральная геометрия: три фигуры, появляющиеся по кругу */
.cosmic-geometry { opacity: 0; transform: scale(0.88); animation: cosmic-geometry-cycle 39s ease-in-out infinite; animation-delay: 0s; }
.cosmic-geometry--b { animation: cosmic-geometry-cycle--b 39s ease-in-out infinite; animation-delay: -13s; }
.cosmic-geometry--c { animation: cosmic-geometry-cycle--c 39s ease-in-out infinite; animation-delay: -26s; }
@keyframes cosmic-geometry-cycle {
  0% { opacity: 0; transform: rotate(0deg) scale(0.8); }
  10% { opacity: 0.55; }
  30% { opacity: 0.38; }
  38% { opacity: 0; }
  100% { opacity: 0; }
}
@keyframes cosmic-geometry-cycle--b {
  0%   { opacity: 0; transform: rotate(0deg) scale(0.8) translateY(0); }
  10%  { opacity: 0.48; }
  30%  { opacity: 0.36; }
  38%  { opacity: 0; }
  100% { opacity: 0; }
}
@keyframes cosmic-geometry-cycle--c {
  0%   { opacity: 0; transform: rotate(0deg) scale(0.8); }
  10%  { opacity: 0.45; }
  30%  { opacity: 0.38; }
  38%  { opacity: 0; }
  100% { opacity: 0; }
}

.cosmic-geometry,
.cosmic-geometry--b,
.cosmic-geometry--c {
  position: absolute;
  left: 54%;
  top: 28%;
  width: 30vmin;
  height: 30vmin;
  pointer-events: none;
}
.cosmic-geometry--b { left: 16%; top: 56%; width: 24vmin; height: 24vmin; }
.cosmic-geometry--c { left: 72%; top: 58%; width: 18vmin; height: 18vmin; }
.cosmic-geometry svg,
.cosmic-geometry--b svg,
.cosmic-geometry--c svg { width: 100%; height: 100%; overflow: visible; }

/* Светлая тема — пергамент с тонким чернильным космосом */
:root[data-theme="light"] .cosmic-nebula {
  background:
    radial-gradient(46rem 34rem at 16% 22%, rgba(121, 101, 181, 0.12), transparent 65%),
    radial-gradient(52rem 40rem at 86% 12%, rgba(41, 37, 54, 0.05), transparent 60%),
    radial-gradient(48rem 42rem at 78% 88%, rgba(111, 91, 168, 0.09), transparent 60%),
    radial-gradient(40rem 34rem at 12% 82%, rgba(125, 95, 40, 0.08), transparent 55%);
}
:root[data-theme="light"] .cosmic-nebula::after {
  background:
    radial-gradient(30rem 22rem at 62% 46%, rgba(121, 101, 181, 0.08), transparent 60%),
    radial-gradient(24rem 18rem at 30% 60%, rgba(125, 95, 40, 0.07), transparent 62%);
}

/* Контент выше космического фона. Липкость шапки и фиксированную
   боковую панель НЕ отключаем: у .app-header sticky z-45, у .sidebar fixed z-70 —
   этого достаточно, чтобы быть выше фона (z-index: 0). */
.app-main, .app-footer { position: relative; z-index: 1; }

/* Telegram Mini App: viewport-sized canvas + safe-area */
.in-telegram .cosmic-bg { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.in-telegram .cosmic-geometry { display: none; }
@media (max-width: 480px) {
  .cosmic-geometry { display: none; }
  .cosmic-geometry--b, .cosmic-geometry--c { display: none; }
}

/* Reduced motion: статичный фон, без мандал */
@media (prefers-reduced-motion: reduce) {
  .cosmic-nebula, .cosmic-nebula::after { animation: none; }
  .cosmic-geometry, .cosmic-geometry--b, .cosmic-geometry--c { animation: none; opacity: 0; }
}
