.main {
  min-height: 100vh;
  padding: 24px;
}

.button {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 2.5rem;
  padding: 0 0.875rem;
  margin: 0;
  outline: 0;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  background-color: #f9fafb;
  font: inherit;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.5rem;
  color: #111827;
  user-select: none;
  cursor: pointer;

  @media (hover: hover) {
    &:hover {
      background-color: #f3f4f6;
    }
  }

  &:active {
    background-color: #f3f4f6;
  }

  &:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: -1px;
  }
}

.ghostButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.5rem;
  border: 0;
  border-radius: 0.25rem;
  outline: 0;
  background: transparent;
  color: #2563eb;
  padding: 0.125rem 0.375rem;
  margin: -0.125rem -0.375rem;
  cursor: pointer;

  @media (hover: hover) {
    &:hover {
      background-color: color-mix(in oklch, #2563eb, transparent 95%);
    }
  }

  &:active {
    background-color: color-mix(in oklch, #2563eb, transparent 90%);
  }

  &:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: -1px;
  }
}

.backdrop {
  --backdrop-opacity: 0.2;
  --bleed: 3rem;
  position: fixed;
  min-height: 100dvh;
  inset: 0;
  background-color: black;
  opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress, 0)));
  transition-duration: calc(var(--drawer-swipe-strength, 1) * 450ms);
  transition-property: opacity;
  transition-timing-function: cubic-bezier(0.32, 0.72, 0, 1);

  &[data-state='open'] {
    animation: fadeInBackdrop calc(var(--drawer-swipe-strength, 1) * 450ms) cubic-bezier(0.32, 0.72, 0, 1);
  }

  &[data-state='closed'] {
    animation: fadeOutBackdrop calc(var(--drawer-swipe-strength, 1) * 450ms) cubic-bezier(0.32, 0.72, 0, 1);
    opacity: 0;
  }

  &[data-swiping] {
    transition-duration: 0ms;
    animation: none;
  }
}

.positioner {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;

  &[data-swipe-direction='up'] {
    align-items: flex-start;
  }

  &[data-swipe-direction='left'] {
    justify-content: flex-start;
    align-items: stretch;
  }

  &[data-swipe-direction='right'] {
    justify-content: flex-end;
    align-items: stretch;
  }
}

.contentHost {
  width: 100%;

  &[data-nested-drawer-open] {
    & > .popup {
      height: calc(var(--stack-height) + var(--bleed));
      overflow: hidden;
    }

    & > .popup::after {
      background-color: rgb(0 0 0 / 0.05);
    }

    & > .popup > .content,
    & > .popup > .handle {
      opacity: 0;
    }
  }

  &[data-nested-drawer-open][data-swiping],
  &[data-nested-drawer-open][data-nested-drawer-swiping] {
    & > .popup > .content,
    & > .popup > .handle {
      opacity: 1;
    }
  }

  &[data-state='open'] {
    animation: slideInContentHost calc(var(--drawer-swipe-strength, 1) * 450ms) cubic-bezier(0.32, 0.72, 0, 1);
  }

  &[data-state='closed'] {
    animation: slideOutContentHost calc(var(--drawer-swipe-strength, 1) * 450ms) cubic-bezier(0.32, 0.72, 0, 1);
  }

  &[data-swiping],
  &[data-nested-drawer-swiping] {
    animation: none;

    & > .popup {
      transition-duration: 0ms;
    }
  }

  &[data-swiping] {
    & > .popup {
      user-select: none;
    }
  }
}

.popup {
  --bleed: 3rem;
  --peek: 1rem;
  --stack-progress: clamp(0, var(--drawer-swipe-progress, 0), 1);
  --stack-step: 0.05;
  --stack-peek-offset: max(0px, calc((var(--nested-drawers, 0) - var(--stack-progress)) * var(--peek)));
  --stack-scale-base: max(0, calc(1 - (var(--nested-drawers, 0) * var(--stack-step))));
  --stack-scale: calc(var(--stack-scale-base) + (var(--stack-step) * var(--stack-progress)));
  --stack-shrink: calc(1 - var(--stack-scale));
  --stack-height: max(0px, var(--drawer-frontmost-height, var(--drawer-height, 0px)));
  --translate-y: calc(0px - var(--stack-peek-offset) - (var(--stack-shrink) * var(--stack-height)));
  box-sizing: border-box;
  position: relative;
  width: 100%;
  max-height: calc(80vh + var(--bleed));
  height: auto;
  margin-bottom: calc(-1 * var(--bleed));
  padding: 1rem 1.5rem 1.5rem;
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px) + var(--bleed));
  border-radius: 1rem 1rem 0 0;
  outline: 1px solid #d1d5db;
  background-color: #f9fafb;
  color: #111827;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.1);
  transform-origin: 50% calc(100% - var(--bleed));
  transition:
    transform calc(var(--drawer-swipe-strength, 1) * 450ms) cubic-bezier(0.32, 0.72, 0, 1),
    height calc(var(--drawer-swipe-strength, 1) * 450ms) cubic-bezier(0.32, 0.72, 0, 1),
    box-shadow calc(var(--drawer-swipe-strength, 1) * 450ms) cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
  transform: translateY(var(--translate-y)) scale(var(--stack-scale));

  &::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background-color: transparent;
    pointer-events: none;
    transition: background-color 450ms cubic-bezier(0.32, 0.72, 0, 1);
  }
}

.content {
  width: 100%;
  max-width: 32rem;
  margin: 0 auto;
  transition: opacity 300ms cubic-bezier(0.45, 1.005, 0, 1.005);
}

.handle {
  width: 3rem;
  height: 0.25rem;
  margin: 0 auto 1rem;
  border-radius: 9999px;
  background-color: #d1d5db;
  transition: opacity 200ms;
}

.title {
  margin-top: 0;
  margin-bottom: 0.25rem;
  font-size: 1.125rem;
  line-height: 1.75rem;
  font-weight: 500;
  text-align: center;
}

.description {
  margin: 0 0 1.5rem;
  font-size: 1rem;
  line-height: 1.5rem;
  color: #4b5563;
  text-align: center;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
}

.actionsLeft {
  margin-right: auto;
}

.list {
  margin: 0 0 1.5rem;
  padding-left: 1.25rem;
  color: #374151;
}

.field {
  display: grid;
  gap: 0.375rem;
  margin-bottom: 1rem;
}

.label {
  font-size: 0.925rem;
  line-height: 1.25rem;
  font-weight: 500;
  color: #374151;
}

.input,
.textarea {
  box-sizing: border-box;
  width: 100%;
  border-radius: 0.375rem;
  border: 1px solid #d1d5db;
  background-color: #f9fafb;
  color: #111827;
  padding: 0.5rem 0.625rem;
  font: inherit;

  &:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: -1px;
  }
}

.textarea {
  resize: vertical;
}

@keyframes slideInContentHost {
  from {
    transform: translate3d(0, 100%, 0);
  }

  to {
    transform: translate3d(var(--drawer-translate-x, 0px), var(--drawer-translate-y, 0px), 0);
  }
}

@keyframes slideOutContentHost {
  from {
    transform: translate3d(var(--drawer-translate-x, 0px), var(--drawer-translate-y, 0px), 0);
  }

  to {
    transform: translate3d(0, 100%, 0);
  }
}

@keyframes fadeInBackdrop {
  from {
    opacity: 0;
  }

  to {
    opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress, 0)));
  }
}

@keyframes fadeOutBackdrop {
  from {
    opacity: calc(var(--backdrop-opacity) * (1 - var(--drawer-swipe-progress, 0)));
  }

  to {
    opacity: 0;
  }
}
