/**
 * Unified modal skin for every game-local overlay card.
 *
 * Loaded after game.css so one modern shell wins over the old bordered boxes.
 * Platform .pd-modal / .pd-pause already use the same tokens in components.css.
 */

/* --- Shared card shell -------------------------------------------------- */

.game-18words .modal-content,
.game-wordsnake .modal-overlay .modal,
.game-wordsnake .ws-tut-modal,
.game-themiddle .modal-overlay .modal,
.game-zanagrams .overlay .modal,
.game-zanagrams .modal.modal-tut,
.game-sunflowers .confirm-modal-card,
.game-sunflowers .modal-tut {
  background: var(--pd-modal-surface, var(--pd-colour-surface)) !important;
  border: var(--pd-modal-border) !important;
  border-radius: var(--pd-modal-radius, 22px) !important;
  box-shadow: var(--pd-shadow-modal) !important;
  padding: var(--pd-modal-pad, 28px 22px 24px) !important;
  max-width: var(--pd-modal-max-width, 400px) !important;
  color: var(--pd-colour-text) !important;
  font-family: var(--pd-font-ui) !important;
  box-sizing: border-box !important;
}

/* Softer enter — desktop only; mobile sheets use --pd-sheet-y. */
@media (min-width: 769px) {
  .game-wordsnake .modal-overlay .modal {
    transform: translateY(14px) scale(0.98) !important;
    transition:
      transform 0.28s var(--pd-ease-rise, cubic-bezier(0.22, 1, 0.36, 1)),
      opacity 0.22s ease !important;
  }

  .game-wordsnake .modal-overlay.show .modal {
    transform: none !important;
  }

  .game-themiddle .modal-overlay .modal {
    transform: translateY(14px) scale(0.98) !important;
  }

  .game-themiddle .modal-overlay.active .modal {
    transform: none !important;
    opacity: 1 !important;
  }
}

/* --- Titles ------------------------------------------------------------- */

.game-18words .modal-header h2,
.game-wordsnake .modal-header h2,
.game-wordsnake .modal h2,
.game-themiddle .modal h2,
.game-zanagrams .modal-head h2,
.game-zanagrams .modal h2,
.game-sunflowers .confirm-modal-card h2,
.game-sunflowers .modal-tut h2 {
  font-family: var(--pd-font-heading) !important;
  font-size: var(--pd-modal-title-size, 26px) !important;
  font-weight: 800 !important;
  line-height: 1.15 !important;
  letter-spacing: -0.02em !important;
  color: var(--pd-colour-heading) !important;
  text-align: center !important;
  padding: 0 40px !important;
  margin: 0 0 12px !important;
}

/* --- Close × ------------------------------------------------------------ */

.game-18words .close-modal,
.game-wordsnake .modal-close-x,
.game-themiddle .modal-close,
.game-zanagrams .modal-close,
.game-sunflowers .modal-x {
  top: 12px !important;
  right: 12px !important;
  width: var(--pd-modal-close-size, 48px) !important;
  height: var(--pd-modal-close-size, 48px) !important;
  border-radius: 50% !important;
  background: transparent !important;
  border: none !important;
  color: var(--pd-colour-muted) !important;
  font-size: 34px !important;
  font-weight: 500 !important;
  line-height: 1 !important;
  box-shadow: none !important;
}

.game-18words .close-modal:hover,
.game-wordsnake .modal-close-x:hover,
.game-themiddle .modal-close:hover,
.game-zanagrams .modal-close:hover,
.game-sunflowers .modal-x:hover {
  background: var(--pd-colour-press) !important;
  color: var(--pd-colour-heading) !important;
}

/* --- Bottom “Close” CTAs → soft primary pill ---------------------------- */

.game-18words .modal-bottom-close,
.game-wordsnake .modal-close,
.game-themiddle .modal-bottom-close,
.game-zanagrams .modal-bottom-close {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  margin-top: 18px !important;
  padding: 14px 20px !important;
  border: none !important;
  border-radius: var(--pd-radius-pill, 999px) !important;
  background: var(--pd-colour-heading) !important;
  color: var(--pd-colour-surface) !important;
  font-family: var(--pd-font-ui) !important;
  font-size: 16px !important;
  font-weight: 700 !important;
  box-shadow: none !important;
  cursor: pointer !important;
  transition: background 0.15s ease, transform 0.06s ease !important;
}

.game-18words .modal-bottom-close:hover,
.game-wordsnake .modal-close:hover,
.game-themiddle .modal-bottom-close:hover,
.game-zanagrams .modal-bottom-close:hover {
  background: color-mix(in srgb, var(--pd-colour-heading) 88%, #000) !important;
  transform: none !important;
  box-shadow: none !important;
  border-color: transparent !important;
}

html[data-theme="dark"] .game-18words .modal-bottom-close:hover,
html[data-theme="dark"] .game-wordsnake .modal-close:hover,
html[data-theme="dark"] .game-themiddle .modal-bottom-close:hover,
html[data-theme="dark"] .game-zanagrams .modal-bottom-close:hover {
  background: color-mix(in srgb, var(--pd-colour-heading) 88%, #fff) !important;
}

/* Tut cards can be wider; keep the soft shell */
.game-zanagrams .modal.modal-tut,
.game-sunflowers .modal-tut,
.game-wordsnake .ws-tut-modal {
  max-width: min(440px, calc(100vw - 32px)) !important;
}

/* Mobile: game overlays as full-width bottom sheets */
@media (max-width: 768px) {
  .game-18words .modal.active,
  .game-wordsnake .modal-overlay,
  .game-wordsnake .ws-tut-overlay.is-open,
  .game-themiddle .modal-overlay,
  .game-zanagrams .overlay.open,
  .game-sunflowers .confirm-modal.show,
  .game-sunflowers .tut-overlay.show {
    align-items: flex-end !important;
    justify-content: stretch !important;
    padding: 0 !important;
  }

  .game-18words .modal-content,
  .game-wordsnake .modal-overlay .modal,
  .game-wordsnake .ws-tut-modal,
  .game-themiddle .modal-overlay .modal,
  .game-zanagrams .overlay .modal,
  .game-zanagrams .modal.modal-tut,
  .game-sunflowers .confirm-modal-card,
  .game-sunflowers .modal-tut {
    --pd-sheet-y: 110%;
    width: 100% !important;
    max-width: none !important;
    height: 90dvh !important;
    max-height: 90dvh !important;
    border-radius: var(--pd-modal-radius, 20px) var(--pd-modal-radius, 20px) 0 0 !important;
    border-bottom: 0 !important;
    /* Variable keeps swipe offsets working even with !important transform. */
    transform: translateY(var(--pd-sheet-y, 110%)) !important;
    transition: transform 0.34s var(--pd-ease-rise, cubic-bezier(0.22, 1, 0.36, 1)) !important;
    margin: 0 !important;
    /* Prefer a nested scroller when present; card scrolls as fallback. */
    overflow: auto !important;
    overscroll-behavior: contain !important;
    /* Entrance keyframes fight --pd-sheet-y / swipe on iOS. */
    animation: none !important;
  }

  /* Words-found sheets: card pinned, list scrolls (same as .pd-modal-card). */
  .game-zanagrams #defOverlay.open .modal {
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    touch-action: none !important;
  }

  .game-zanagrams #defOverlay .modal #defList {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .game-18words .modal.active .modal-content,
  .game-wordsnake .modal-overlay.show .modal,
  .game-wordsnake .ws-tut-overlay.is-open .ws-tut-modal,
  .game-themiddle .modal-overlay.active .modal,
  .game-zanagrams .overlay.open .modal,
  .game-sunflowers .confirm-modal.show .confirm-modal-card,
  .game-sunflowers .tut-overlay.show .modal-tut {
    --pd-sheet-y: 0px;
    transform: translateY(var(--pd-sheet-y, 0px)) !important;
    opacity: 1 !important;
  }

  .game-18words .modal-content.is-sheet-dragging,
  .game-wordsnake .modal-overlay .modal.is-sheet-dragging,
  .game-wordsnake .ws-tut-modal.is-sheet-dragging,
  .game-themiddle .modal-overlay .modal.is-sheet-dragging,
  .game-zanagrams .overlay .modal.is-sheet-dragging,
  .game-sunflowers .confirm-modal-card.is-sheet-dragging,
  .game-sunflowers .modal-tut.is-sheet-dragging {
    transition: none !important;
  }
}
