/* Lightweight motion and compositor tuning for smooth charts and menus. */
:root {
  --motion-fast: 85ms;
  --motion-panel: 90ms;
  --motion-smooth: cubic-bezier(.2, .78, .2, 1);
}

/* Promote only the large, continuously moving layers. Avoiding a blanket
   will-change keeps GPU memory predictable on mobile devices. */
.space-backdrop,
.space-nebula,
.space-milkyway,
.space-stars,
.space-sun,
.space-planet,
.chart-weather,
.chart-weather > .weather-horizon,
.chart-weather > .weather-fog-layer,
.chart-weather > .weather-gap-fog,
.chart-weather > .weather-cloud,
.chart-weather > .weather-mountains,
.chart-weather > .weather-rain,
.chart-weather > .weather-lightning,
.weather-distant-lightning {
  transform: translateZ(0);
  backface-visibility: hidden;
}

.space-backdrop,
.chart-weather {
  isolation: isolate;
}

.chart-weather > .weather-cloud,
.chart-weather > .weather-fog-layer,
.chart-weather > .weather-gap-fog,
.chart-weather > .weather-rain,
.chart-weather > .weather-lightning {
  will-change: transform, opacity;
}

/* Menus open on the compositor with a short, deliberate lift instead of a
   layout-heavy transition. The existing hidden attribute still controls all
   accessibility and click behavior. */
.market-menu:not([hidden]),
.tool-menu:not([hidden]),
.indicator-panel:not([hidden]),
.settings-panel:not([hidden]),
.compare-panel:not([hidden]),
.language-popover:not([hidden]),
.lab-mode-bar:not([hidden]) {
  animation: menuEnter var(--motion-panel) var(--motion-smooth) both;
  transform-origin: top left;
  will-change: transform, opacity;
}

.modal-backdrop:not([hidden]) {
  animation: backdropEnter var(--motion-fast) ease-out both;
}

.modal-backdrop:not([hidden]) > .alert-modal {
  animation: modalEnter 150ms var(--motion-smooth) both;
  will-change: transform, opacity;
}

.market-menu,
.tool-menu,
.indicator-panel,
.settings-panel,
.compare-panel,
.language-popover,
.lab-mode-bar,
.modal-backdrop,
.alert-modal {
  contain: layout paint;
}

/* Avoid animating shadows during menu interaction: shadows trigger extra
   paint work while the chart is still compositing underneath the panel. */
.market-menu button,
.tool-menu button,
.indicator-panel button,
.settings-panel button,
.compare-panel button,
.language-option,
.primary-button,
.secondary-button,
.icon-button,
.tool-button,
.rail-button {
  transition: transform var(--motion-fast) var(--motion-smooth),
    color var(--motion-fast) ease,
    background-color var(--motion-fast) ease,
    border-color var(--motion-fast) ease;
}

.market-menu button:active,
.tool-menu button:active,
.indicator-panel button:active,
.settings-panel button:active,
.compare-panel button:active,
.language-option:active,
.primary-button:active,
.secondary-button:active,
.icon-button:active,
.tool-button:active,
.rail-button:active {
  transform: translateY(1px) scale(.985);
}

/* Stop every decorative animation while the tab is not visible or the sky
   panel is closed. This saves compositor work without changing the chart. */
html.page-hidden .space-backdrop *,
html.page-hidden .chart-weather *,
html.page-hidden .storm-external-lightning *,
.chart-weather.is-offscreen * {
  animation-play-state: paused !important;
}

/* Give chart gestures the full frame budget on mobile and desktop alike. */
body.chart-interacting .space-backdrop *,
body.chart-interacting .chart-weather *,
body.chart-interacting .storm-external-lightning * {
  animation-play-state: paused !important;
}

@keyframes menuEnter {
  from { opacity: 0; transform: translate3d(0, -5px, 0) scale(.99); }
  to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@keyframes backdropEnter {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalEnter {
  from { opacity: 0; transform: translate3d(0, 7px, 0) scale(.99); }
  to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }
}

@media (max-width: 700px) {
  .chart-weather > .weather-cloud,
  .chart-weather > .weather-fog-layer,
  .chart-weather > .weather-gap-fog {
    will-change: transform;
  }
}

@media (prefers-reduced-motion: reduce) {
  .market-menu:not([hidden]),
  .tool-menu:not([hidden]),
  .indicator-panel:not([hidden]),
  .settings-panel:not([hidden]),
  .compare-panel:not([hidden]),
  .language-popover:not([hidden]),
  .lab-mode-bar:not([hidden]),
  .modal-backdrop:not([hidden]),
  .modal-backdrop:not([hidden]) > .alert-modal {
    animation: none;
  }

  .market-menu button,
  .tool-menu button,
  .indicator-panel button,
  .settings-panel button,
  .compare-panel button,
  .language-option,
  .primary-button,
  .secondary-button,
  .icon-button,
  .tool-button,
  .rail-button {
    transition-duration: .01ms;
  }
}
