/* ---------- modal ---------- */
dialog.modal:focus {
  outline: none;
}
dialog.modal {
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  color: var(--text);
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  max-height: calc(100vh - 48px);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  flex-direction: column;
}
@supports (height: 100dvh) {
  dialog.modal {
    max-height: calc(100dvh - 48px);
  }
}
dialog.modal[open] {
  display: flex;
  animation: pop 0.16s ease;
}
dialog.modal::backdrop {
  background: rgba(10, 5, 15, 0.45);
}
.modal-wide {
  width: min(900px, calc(100vw - 32px)) !important;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 12px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  margin: 0;
  font-size: 1.1rem;
}
.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* Start from the content's height and shrink (scrolling) only past max-height. With
     flex: 1 (a 0% basis) iOS Safari sized the body to 0, so dialogs showed just their
     title and first line. */
  flex: 1 1 auto;
  min-height: 0;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.modal-foot.inline {
  border-top: 0;
  padding: 16px 0 0;
}
dialog.modal-full {
  width: 100vw !important;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-height: none !important;
  border-radius: 0;
  margin: 0;
}
.modal-full .modal-head {
  padding-top: calc(12px + env(safe-area-inset-top));
}
.modal-camera,
.modal-viewer {
  background: #000 !important;
  color: #fff !important;
}
.modal-camera .modal-head,
.modal-viewer .modal-head {
  border-color: rgba(255, 255, 255, 0.12);
}
.modal-camera .icon-btn,
.modal-viewer .modal-head .icon-btn {
  color: #fff;
}
.modal-viewer .viewer-info {
  background: var(--surface);
  color: var(--text);
}
@keyframes pop {
  from {
    transform: scale(0.97);
    opacity: 0;
  }
}
@media (max-width: 640px) {
  dialog.modal:not(.modal-full) {
    width: 100vw !important;
    max-width: 100vw;
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
    max-height: calc(100vh - 24px);
    animation: up 0.2s ease;
  }
  @supports (height: 100dvh) {
    dialog.modal:not(.modal-full) {
      max-height: calc(100dvh - env(safe-area-inset-top) - 12px);
    }
  }
  .modal-body {
    padding: 16px;
  }
  /* The palette fills the sheet, so its box stays put as results come and go. */
  dialog.modal.palette {
    height: calc(100vh - 24px);
  }
  @supports (height: 100dvh) {
    dialog.modal.palette {
      height: calc(100dvh - env(safe-area-inset-top) - 12px);
    }
  }
  .palette .modal-body {
    padding: 0;
  }
}

/* toasts */
.toasts {
  position: fixed;
  z-index: 1000;
  inset: auto auto auto 50%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: visible;
  transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}
@media (max-width: 760px) {
  .toasts {
    bottom: calc(var(--bottombar-h) + var(--tabs-h) + 12px + env(safe-area-inset-bottom));
  }
}
.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow-lg);
  font-size: 0.92rem;
  pointer-events: auto;
  animation: up 0.2s ease;
  transition: opacity 0.3s, transform 0.3s;
}
.toast .btn-text {
  color: var(--accent-soft);
  min-height: 0;
  padding: 4px 8px;
}
/* The generic .btn:hover surface would put the toast's ink on a near-matching background. */
.toast .btn-text:hover {
  background: color-mix(in srgb, currentColor 18%, transparent);
}
.toast-error {
  background: var(--danger);
  color: #fff;
}
.toast-success {
  background: var(--ok);
  color: #fff;
}
:root[data-theme='dark'] .toast-success,
:root[data-theme='dark'] .toast-error {
  color: #10100f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .toast-success,
  :root:not([data-theme='light']) .toast-error {
    color: #10100f;
  }
}
.toast.out {
  opacity: 0;
  transform: translateY(8px);
}

