/* One motion layer for the app shell. Only interactions create motion: no idle
   loops, cursor animation, scroll interception, or game-canvas transforms. */
:root {
  --uv-motion-quick: 165ms;
  --uv-motion-panel: 220ms;
  --uv-motion-view: 235ms;
  --uv-motion-ease: cubic-bezier(.16, 1, .3, 1);
}

@media (prefers-reduced-motion: no-preference) {
  :root[data-smooth-ui="on"] body,
  :root[data-smooth-ui="on"] :is(.chat-sidebar, .settings-group, .simple-panel) {
    transition: none;
  }

  /* Fading whole views avoids transformed containing blocks that make fixed
     toolbars/dialogs jump. Each entrance ends; there is no animation at idle. */
  :root[data-smooth-ui="on"] :is(
    .page-identity, .development-view, .games-view, .media-choice-view,
    .music-view, .videos-view, .browser-view, .ai-view, .chat-view, .settings-view, .release-notes-view
  ):not([hidden]) {
    animation: uv-motion-view-in var(--uv-motion-view) ease-out backwards;
    transition-property: opacity;
  }

  :root[data-smooth-ui="on"] .home {
    transition: opacity var(--uv-motion-panel) var(--uv-motion-ease);
  }

  :root[data-smooth-ui="on"] .settings-panel:not([hidden]) {
    animation: uv-motion-view-in var(--uv-motion-panel) ease-out backwards;
  }

  /* Move only self-contained surfaces, never a route wrapper with fixed UI.
     A single panel entrance avoids a cascade across hundreds of game cards. */
  :root[data-smooth-ui="on"] :is(
    .uv-media-choice-content, .auth-form:not([hidden]),
    .auth-confirmation:not([hidden]), .games-header, .music-library-header,
    .videos-heading, .settings-header, .ai-empty-state, .friends-toolbar,
    .settings-panel:not([hidden]) > .settings-group:first-child > .group-heading
  ) {
    animation: uv-motion-surface-in var(--uv-motion-view) var(--uv-motion-ease) backwards;
  }

  :root[data-smooth-ui="on"] :is(
    .home, .settings-view, .games-library, .music-library-scroll,
    .message-stage, .chat-sidebar, .friends-main, .gif-results
  ) {
    scroll-behavior: smooth;
  }

  /* Visibility changes only after the closing fade, and immediately on open.
     Opening during a close reverses the same transition without reflow. */
  :root[data-smooth-ui="on"] .pages-launcher .site-menu {
    transition: opacity var(--uv-motion-panel) var(--uv-motion-ease),
      transform var(--uv-motion-panel) var(--uv-motion-ease),
      visibility 0s linear var(--uv-motion-panel);
    transform-origin: left bottom;
    transform: translateY(.5rem) scale(.98);
  }
  :root[data-smooth-ui="on"] .is-menu-open .pages-launcher .site-menu {
    transition-delay: 0s;
    transform: none;
  }

  /* Include all real controls, not only a small list of legacy button names.
     Small-control color changes are cheap; large surfaces never color-fade. */
  :root[data-smooth-ui="on"] :where(button, .file-button, .menu-link, [role="button"]) {
    transition-property: opacity, transform, translate, color, border-color;
    transition-duration: var(--uv-motion-quick);
    transition-timing-function: var(--uv-motion-ease);
  }
  :root[data-smooth-ui="on"] :where(input:not([type="range"]), textarea, select) {
    transition: border-color var(--uv-motion-quick) ease, color var(--uv-motion-quick) ease;
  }
  :root[data-smooth-ui="on"] :is(
    .menu-button, .auth-submit, .auth-tab, .settings-tab, .uv-settings-choice, .uv-background-choice,
    .uv-cursor-choice, .primary-action, .secondary-action, .composer-send,
    .ai-send, .quick-overlay-icon-button, .uv-media-button, .uv-media-icon-button,
    .game-card, .game-card-copy, .music-track-card, .music-track-play,
    .game-card-artwork img, .menu-icon, .rail-button, .friend-row, .dm-item,
    .channel-item, .sidebar-destination, .message-link-card, .uv-media-choice,
    .uv-media-choice-arrow, .ai-sidebar
  ) {
    transition-property: opacity, transform, translate, color, border-color;
    transition-duration: var(--uv-motion-quick);
    transition-timing-function: var(--uv-motion-ease);
  }
  :root[data-smooth-ui="on"] :is(.game-card-copy, .game-card-artwork img) {
    transition-duration: var(--uv-motion-panel);
  }
  :root[data-smooth-ui="on"] .games-view .game-card-copy {
    translate: 0 .35rem;
  }
  :root[data-smooth-ui="on"] .games-view .game-card:is(:hover, :focus-visible) .game-card-copy {
    translate: 0 0;
  }

  :root[data-smooth-ui="on"] :where(button, .file-button, [role="button"]):active:not(:disabled):not([aria-disabled="true"]) {
    transform: scale(.98);
    translate: 0 0;
    transition-duration: 90ms;
  }

  @media (hover: hover) and (pointer: fine) {
    :root[data-smooth-ui="on"] :is(
      .auth-submit, .primary-action, .secondary-action, .uv-media-choice,
      .uv-settings-choice, .uv-background-choice, .uv-cursor-choice
    ):hover:not(:active):not(:disabled):not([aria-disabled="true"]) {
      translate: 0 -2px;
    }
    :root[data-smooth-ui="on"] .games-view .game-card:hover:not(:active) {
      translate: 0 -3px;
    }
    :root[data-smooth-ui="on"] :is(
      .menu-link, .settings-tab, .friend-row, .dm-item, .sidebar-destination
    ):hover:not(:active):not(:disabled):not([aria-disabled="true"]) {
      translate: 2px 0;
    }
    :root[data-smooth-ui="on"] :is(
      .uv-media-choice, .uv-settings-choice, .uv-background-choice, .uv-cursor-choice,
      .menu-link, .settings-tab, .friend-row, .dm-item, .sidebar-destination
    ) {
      transition-property: opacity, transform, translate, color, border-color;
    }
  }

  @media (hover: none) {
    :root[data-smooth-ui="on"] .games-view .game-card-copy { translate: 0 0; }
  }

  /* Individual translate/scale preserve a popup's existing centering transform.
     They return to their base values when the finite entrance finishes. */
  :root[data-smooth-ui="on"] :is(
    .emoji-picker, .gif-picker, .mention-suggestions, .chat-toast,
    .ai-voice-panel, .uv-media-track-menu
  ):not([hidden]),
  :root[data-smooth-ui="on"] dialog[open] {
    animation: uv-motion-surface-in var(--uv-motion-panel) var(--uv-motion-ease) backwards;
  }
  :root[data-smooth-ui="on"] dialog[open]::backdrop {
    animation: uv-motion-view-in var(--uv-motion-quick) ease-out backwards;
  }

  /* Modern browsers retain a closing dialog in the top layer until its fade
     finishes. No timers, monkey-patched close(), or delayed focus restoration.
     Older browsers keep the bounded entrance above and close immediately. */
  @supports (transition-behavior: allow-discrete) and (overlay: auto) {
    :root[data-smooth-ui="on"] body:not(.has-quick-overlay-fallback) dialog {
      opacity: 0;
      translate: 0 .5rem;
      transition: opacity var(--uv-motion-quick) ease,
        translate var(--uv-motion-panel) var(--uv-motion-ease),
        display var(--uv-motion-panel) allow-discrete,
        overlay var(--uv-motion-panel) allow-discrete;
    }
    :root[data-smooth-ui="on"] body:not(.has-quick-overlay-fallback) dialog[open] {
      opacity: 1;
      translate: 0 0;
      animation: none;
    }
    :root[data-smooth-ui="on"] body:not(.has-quick-overlay-fallback) dialog::backdrop {
      opacity: 0;
      transition: opacity var(--uv-motion-quick) ease,
        display var(--uv-motion-panel) allow-discrete,
        overlay var(--uv-motion-panel) allow-discrete;
      animation: none;
    }
    :root[data-smooth-ui="on"] body:not(.has-quick-overlay-fallback) dialog[open]::backdrop {
      opacity: 1;
    }
    @starting-style {
      :root[data-smooth-ui="on"] body:not(.has-quick-overlay-fallback) dialog[open] {
        opacity: 0;
        translate: 0 .5rem;
      }
      :root[data-smooth-ui="on"] body:not(.has-quick-overlay-fallback) dialog[open]::backdrop {
        opacity: 0;
      }
    }
  }

  /* A switch knob moves, but does not tween its border/shadow/size. */
  :root[data-smooth-ui="on"] .smooth-ui-track {
    transition: none;
  }
  :root[data-smooth-ui="on"] .smooth-ui-track > span {
    transition: transform var(--uv-motion-panel) var(--uv-motion-ease);
  }
}

@keyframes uv-motion-view-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes uv-motion-surface-in {
  from { opacity: 0; translate: 0 .5rem; scale: .99; }
  to { opacity: 1; translate: 0 0; scale: 1; }
}

/* Both controls are authoritative, even if legacy styles specify motion with
   higher specificity. Keyboard focus outlines and hidden-state layout remain. */
:root[data-smooth-ui="off"] *,
:root[data-smooth-ui="off"] *::before,
:root[data-smooth-ui="off"] *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
