@use '@/styles/variables.scss' as *;

.page-transition {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;

  &__layer {
    display: flex;
    flex-direction: column;
    gap: $spacing-lg;
    min-height: 0;
    flex: 1;
    background: var(--bg-secondary);
    backface-visibility: hidden;
    transform: translateZ(0);

    // During animation, exit layer uses absolute positioning
    &--exit {
      position: absolute;
      inset: 0;
      overflow: hidden;
      pointer-events: none;
      will-change: transform, opacity;
    }

    &--stacked {
      display: none;

      // Keep the previous layer rendered (but invisible) to avoid a blank flash when popping back.
      // Older stacked layers remain `display: none` for performance.
      &.page-transition__layer--stacked-keep {
        display: flex;
        position: absolute;
        inset: 0;
        overflow: hidden;
        pointer-events: none;
        opacity: 0;
        will-change: transform, opacity;
      }
    }
  }

  &--animating &__layer {
    will-change: transform, opacity;
  }

  &--animating &__layer:not(.page-transition__layer--exit):not(.page-transition__layer--stacked) {
    position: relative;
  }
}
