.modal {
  display: flex;
  flex-direction: column;
  width: min(calc(100% - var(--space-4) * 2), 36rem);
  max-height: calc(100dvh - var(--space-4) * 2);
  margin: auto;
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.modal:not([open]) {
  display: none;
}

/* While the server works on something asked for from the modal (a pane
   loading, a form or a button's request in flight), a line runs along its
   top edge. dialog_controller.js sets data-busy. It waits a moment before
   showing, so a quick answer draws nothing. */
.modal[data-busy]::before {
  content: "";
  position: absolute;
  top: 0;
  right: var(--radius-md);
  left: var(--radius-md);
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 50% 100%;
  background-repeat: no-repeat;
  opacity: 0;
  animation:
    modal-busy-show 150ms 200ms linear forwards,
    modal-busy-run 1.1s 200ms ease-in-out infinite;
}

@keyframes modal-busy-show {
  100% {
    opacity: 1;
  }
}

@keyframes modal-busy-run {
  0% {
    background-position: -100% 0;
  }

  100% {
    background-position: 200% 0;
  }
}

/* Reduced motion: the whole line, breathing in place. */
@media (prefers-reduced-motion: reduce) {
  .modal[data-busy]::before {
    background: var(--accent);
    animation: modal-busy-breathe 1.6s 200ms ease-in-out infinite alternate;
  }
}

@keyframes modal-busy-breathe {
  0% {
    opacity: 0.25;
  }

  100% {
    opacity: 1;
  }
}

.modal-wide {
  width: min(calc(100% - var(--space-4) * 2), 64rem);
}

.modal::backdrop {
  background: var(--backdrop);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--line-width) solid var(--line);
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: 600;
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap-dense);
  height: var(--tap-dense);
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  font-size: var(--text-xl);
  cursor: pointer;
}

.modal-close:hover {
  background: var(--surface-sunken);
  color: var(--ink);
}

.modal-body {
  container-type: inline-size;
  overflow-y: auto;
  padding: var(--space-4);
}

/* While the modal eases to a new height (dialog_controller.js), the body
   is clipped so no scrollbar flickers in for the length of the move. */
.modal-body[data-resizing] {
  overflow-y: hidden;
}

.modal-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: var(--line-width) solid var(--line);
}
