/*
 * CricketWindies modal shell -- generic, reusable base built on Micromodal
 * (micromodal.min.js, vanilla JS, unstyled by design: it only handles
 * open/close, focus trap, ESC key, and aria-hidden toggling). This file
 * owns the actual look. Not feature-specific -- the avatar cropper is the
 * first thing built on top of it, but the same .modal/.modal__overlay/
 * .modal__container/.modal__close classes are meant to be reused for
 * anything else that needs a focused overlay later (forced announcements,
 * an image lightbox, etc.), each with its own .modal__content inside.
 *
 * Markup shape (Micromodal's own documented pattern):
 *   <div class="modal micromodal-slide" id="x-modal" aria-hidden="true">
 *     <div class="modal__overlay" tabindex="-1" data-micromodal-close>
 *       <div class="modal__container" role="dialog" aria-modal="true" aria-labelledby="x-modal-title">
 *         <div class="modal__header">
 *           <h2 class="modal__title" id="x-modal-title">Title</h2>
 *           <button class="modal__close" aria-label="Close" data-micromodal-close></button>
 *         </div>
 *         <div class="modal__content" id="x-modal-content">...</div>
 *         <div class="modal__footer">...</div>
 *       </div>
 *     </div>
 *   </div>
 */

.modal {
  display: none;
}

.modal.is-open {
  display: block;
}

.modal__overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 12, 10, .65);
}

.modal__container {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  box-sizing: border-box;
  padding: 20px;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e4ddd7);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(21, 32, 51, .25);
  color: var(--ink, #152033);
}

.modal__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal__title {
  margin: 0;
  color: var(--ink, #152033);
  font-size: 18px;
  line-height: 1.25;
}

.modal__close {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  color: var(--muted, #5f6877);
  background: transparent;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

.modal__close::before {
  content: "";
  width: 14px;
  height: 14px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 6l12 12M18 6l-12 12' stroke='%23000' stroke-width='2.4' stroke-linecap='round' fill='none'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 6l12 12M18 6l-12 12' stroke='%23000' stroke-width='2.4' stroke-linecap='round' fill='none'/%3E%3C/svg%3E") center / contain no-repeat;
}

.modal__close:hover,
.modal__close:focus-visible {
  color: var(--ink, #152033);
  background: var(--surface-hover, #f4f1ed);
}

.modal__content {
  color: var(--ink, #152033);
  font-size: 14px;
  line-height: 1.5;
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border, #e4ddd7);
}

[data-theme="dark"] .modal__overlay {
  background: rgba(0, 0, 0, .75);
}

/* Slide/fade animation -- Micromodal's own documented companion class,
   keyed off aria-hidden rather than the is-open class so the closing
   animation still plays during the brief window between "close requested"
   and the library removing is-open (awaitCloseAnimation in the JS config
   is what actually waits for this). */
.micromodal-slide[aria-hidden="false"] .modal__overlay {
  animation: cw-modal-fade-in .2s cubic-bezier(0, 0, .2, 1);
}

.micromodal-slide[aria-hidden="false"] .modal__container {
  animation: cw-modal-slide-in .2s cubic-bezier(0, 0, .2, 1);
}

.micromodal-slide[aria-hidden="true"] .modal__overlay {
  animation: cw-modal-fade-out .15s cubic-bezier(0, 0, .2, 1);
}

.micromodal-slide[aria-hidden="true"] .modal__container {
  animation: cw-modal-slide-out .15s cubic-bezier(0, 0, .2, 1);
}

.micromodal-slide .modal__container,
.micromodal-slide .modal__overlay {
  will-change: transform;
}

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

@keyframes cw-modal-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes cw-modal-slide-in {
  from { transform: translateY(-8%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes cw-modal-slide-out {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-8%); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .micromodal-slide[aria-hidden="false"] .modal__overlay,
  .micromodal-slide[aria-hidden="false"] .modal__container,
  .micromodal-slide[aria-hidden="true"] .modal__overlay,
  .micromodal-slide[aria-hidden="true"] .modal__container {
    animation: none;
  }
}

@media (max-width: 600px) {
  .modal__overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal__container {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px 8px 0 0;
  }
}
