/* Keep deck creation usable in short windows, split-screen, and mobile keyboards. */
#deck-modal {
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  padding-top: max(.75rem, env(safe-area-inset-top, 0px)) !important;
  padding-bottom: max(.75rem, env(safe-area-inset-bottom, 0px)) !important;
}

#deck-modal > div {
  display: flex !important;
  width: min(100%, 56rem) !important;
  max-height: calc(var(--sc-deck-modal-vh, 100dvh) - 1.5rem) !important;
  min-height: 0;
  flex-direction: column;
  overflow: hidden !important;
  border-radius: 1.5rem;
}

#deck-modal > div > div:first-child {
  flex: 0 0 auto;
  padding: clamp(.85rem, 2.4vh, 1.5rem) clamp(1rem, 3vw, 2rem) !important;
}

#deck-modal > div > div:nth-child(2) {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(.85rem, 2.5vw, 2rem) !important;
  scrollbar-gutter: stable;
}

#deck-modal #deck-card-rows {
  max-height: min(34dvh, 17.5rem) !important;
  overscroll-behavior: contain;
}

#deck-modal .deck-modal-actions {
  position: sticky;
  z-index: 2;
  bottom: -.1rem;
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: .65rem;
  margin: .25rem -.15rem -.2rem;
  padding: .8rem .15rem .2rem;
  background: linear-gradient(to bottom, rgba(255,255,255,0), rgba(255,255,255,.96) 28%, #fff 100%);
}

#deck-modal .deck-modal-actions button {
  min-height: 2.75rem;
}

@media (max-width: 680px) {
  html body[data-sc-sidebar-page="cards"] #deck-modal {
    align-items: center !important;
    padding: max(.4rem, env(safe-area-inset-top, 0px)) .4rem max(.4rem, env(safe-area-inset-bottom, 0px)) !important;
  }

  html body[data-sc-sidebar-page="cards"] #deck-modal > div {
    width: 100% !important;
    max-height: calc(var(--sc-deck-modal-vh, 100dvh) - max(.8rem, env(safe-area-inset-top, 0px)) - max(.8rem, env(safe-area-inset-bottom, 0px))) !important;
    border-radius: 1rem;
  }

  #deck-modal > div > div:first-child {
    gap: .75rem;
  }

  #deck-modal > div > div:first-child h3 {
    font-size: 1.2rem;
    line-height: 1.2;
  }

  #deck-modal #deck-card-rows {
    max-height: min(29dvh, 13rem) !important;
  }

  #deck-modal .deck-modal-actions {
    gap: .5rem;
    padding-top: .65rem;
  }

  #deck-modal .deck-modal-actions button {
    flex: 1 1 8rem;
    padding: .7rem .8rem;
  }
}

@media (max-height: 560px) {
  #deck-modal > div {
    max-height: calc(var(--sc-deck-modal-vh, 100dvh) - 1rem) !important;
    border-radius: 1rem;
  }

  #deck-modal > div > div:first-child {
    padding-block: .65rem !important;
  }

  #deck-modal #deck-card-rows {
    max-height: min(25dvh, 8rem) !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  #deck-modal *, #deck-modal *::before, #deck-modal *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
