.modal-scrim {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(var(--s-4), var(--safe-top)) max(var(--s-4), var(--safe-right)) max(var(--s-4), var(--safe-bottom)) max(var(--s-4), var(--safe-left));
  background: rgba(0, 0, 0, 0.6);
  animation: modal-scrim-in var(--dur) var(--ease);
}

.modal {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - var(--s-8));
  max-height: calc(100dvh - var(--s-8));
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  animation: modal-in var(--dur) var(--ease);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--border);
}

.modal__title {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text);
}

.modal__close {
  flex-shrink: 0;
  display: flex;
  color: var(--text-muted);
  padding: var(--s-1);
  border-radius: var(--r-sm);
  transition: color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}

.modal__close:hover {
  color: var(--text);
  background: var(--surface-3);
}

.modal__close:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.modal__body {
  padding: var(--s-5);
  overflow-y: auto;
}

.modal__message {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  line-height: 1.5;
}

.modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--border);
}

body.has-modal {
  overflow: hidden;
}

@keyframes modal-scrim-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .modal-scrim, .modal {
    animation: none;
  }
}

@media (max-width: 480px) {
  /* phones: the dialog docks to the bottom like a native sheet, easy to reach and dismiss */
  .modal-scrim {
    align-items: flex-end;
    padding: 0;
    padding-top: var(--safe-top);
  }

  .modal {
    max-width: 100%;
    max-height: calc(100dvh - var(--safe-top) - var(--s-4));
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: none;
    animation-name: modal-sheet-in;
  }

  .modal__body {
    overscroll-behavior: contain;
  }

  .modal__footer {
    padding-bottom: calc(var(--s-4) + var(--safe-bottom));
  }
}

@keyframes modal-sheet-in {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}
