.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 19, 24, 0.4);
  overscroll-behavior: contain;
}

body:has(.modal:not(.hidden)) {
  overflow: hidden;
}

.modal-card {
  position: relative;
  display: grid;
  gap: 14px;
  width: min(560px, 100%);
  max-height: calc(100dvh - 40px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(16, 24, 40, 0.2);
  overscroll-behavior: contain;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.92);
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.modal-close:hover {
  color: var(--ink);
  background: #f3f6f5;
}

.package-modal-card {
  width: min(680px, 100%);
}

.modal-actions {
  position: sticky;
  bottom: -1px;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 2px -22px -22px;
  border-top: 1px solid var(--line);
  padding: 12px 22px calc(12px + var(--safe-bottom));
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -10px 22px rgba(16, 24, 40, 0.08);
}

.split-actions {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
}

.course-modal-summary {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.course-modal-summary strong {
  color: var(--ink);
  font-size: 16px;
}

@media (min-width: 1181px) and (max-width: 1512px) {
  .modal-card {
    max-width: min(720px, calc(100vw - 40px));
  }

  .package-modal-card {
    max-width: min(760px, calc(100vw - 40px));
  }
}

@media (max-width: 800px) {
  .modal {
    align-items: end;
    justify-items: center;
    padding: 12px 10px calc(12px + var(--safe-bottom));
    touch-action: none;
  }

  .modal-card {
    width: 100%;
    max-width: min(520px, 100%);
    min-width: 0;
    max-height: calc(100dvh - 24px - var(--safe-top) - var(--safe-bottom));
    overflow: auto;
    overscroll-behavior: contain;
    border-radius: 16px 16px 0 0;
    padding: 18px 16px 16px;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  .modal-close {
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
  }

  .modal-card > .panel-title,
  .modal-card > .eyebrow,
  .modal-card > h2 {
    padding-right: 42px;
  }

  .course-modal-summary {
    font-size: 13px;
    line-height: 1.5;
  }

  .modal-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    margin: 2px -16px -16px;
    padding: 12px 16px calc(12px + var(--safe-bottom));
  }

  .modal-actions button {
    width: 100%;
    min-width: 0;
    justify-content: center;
  }

  .split-actions {
    grid-template-columns: 1fr 1fr;
  }

  .split-actions > span {
    display: none;
  }

  .split-actions .danger-button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 480px) {
  .modal-actions {
    grid-template-columns: 1fr;
  }

  .modal-actions button,
  .split-actions button {
    width: 100%;
  }
}
