html.ios-sheet-locked {
  overflow: hidden;
  touch-action: none;
}

.ios-sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 6000;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  /* Lighter scrim so the frosted background blur reads as a slight blur
     rather than a flat dim. saturate() gives the iOS-style frosted look. */
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  -webkit-tap-highlight-color: transparent;
}

.ios-sheet-backdrop.open {
  display: flex;
}

.ios-sheet {
  width: 100%;
  max-width: 520px;
  max-height: min(92dvh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--ios-sheet-bg, #ffffff);
  color: var(--ios-sheet-fg, #0f172a);
  border: 1px solid var(--ios-sheet-border, rgba(0, 0, 0, 0.08));
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  transform: translateY(100%);
  opacity: 1;
  transition:
    transform 0.38s cubic-bezier(0.32, 0.72, 0, 1),
    opacity 0.28s ease;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.ios-sheet--visible {
  transform: translateY(0);
}

.ios-sheet-grabber {
  flex-shrink: 0;
  position: relative;
  width: 36px;
  height: 5px;
  margin: 8px auto 4px;
  border-radius: 999px;
  background: var(--ios-sheet-grabber, rgba(0, 0, 0, 0.18));
  touch-action: none;
}

.ios-sheet-grabber::before {
  content: '';
  position: absolute;
  left: -40vw;
  right: -40vw;
  top: -14px;
  bottom: -10px;
}

.ios-sheet-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 3rem;
  flex-shrink: 0;
  border-bottom: 1px solid var(--ios-sheet-border, rgba(0, 0, 0, 0.08));
}

.ios-sheet-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-align: center;
  line-height: 1.3;
}

.ios-sheet-close {
  position: absolute;
  left: max(12px, env(safe-area-inset-left, 0px));
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--ios-sheet-close-bg, rgba(0, 0, 0, 0.06));
  color: var(--ios-sheet-muted, rgba(0, 0, 0, 0.55));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}

.ios-sheet-close:hover {
  background: var(--ios-sheet-close-hover, rgba(0, 0, 0, 0.1));
  color: var(--ios-sheet-fg, #0f172a);
}

.ios-sheet-close[hidden] {
  display: none !important;
}

.ios-sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 1rem 1.15rem 1.25rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ios-sheet-bg: #121722;
    --ios-sheet-fg: #e9eef6;
    --ios-sheet-muted: rgba(255, 255, 255, 0.55);
    --ios-sheet-border: rgba(255, 255, 255, 0.1);
    --ios-sheet-grabber: rgba(255, 255, 255, 0.28);
    --ios-sheet-close-bg: rgba(255, 255, 255, 0.08);
    --ios-sheet-close-hover: rgba(255, 255, 255, 0.14);
    --ios-sheet-link: #60a5fa;
  }
}

@media (min-width: 768px) {
  .ios-sheet-backdrop:not(.ios-sheet-backdrop--sheet-only) {
    align-items: center;
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  }

  .ios-sheet-backdrop:not(.ios-sheet-backdrop--sheet-only) .ios-sheet-grabber {
    display: none;
  }

  .ios-sheet-backdrop:not(.ios-sheet-backdrop--sheet-only) .ios-sheet {
    border-radius: 16px;
    border-bottom: 1px solid var(--ios-sheet-border, rgba(0, 0, 0, 0.08));
    max-height: min(86dvh, 640px);
    transform: translateY(16px) scale(0.97);
    opacity: 0;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
  }

  .ios-sheet-backdrop:not(.ios-sheet-backdrop--sheet-only).open .ios-sheet.ios-sheet--visible {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}
