/*
 * The map page's sheets: the mission drawer and the other popups.
 *
 * Mission drawer (#detailsPopup in worldmap.html).
 * Phones: a bottom sheet resting at ~40% of the screen that grows to full
 * height (.is-expanded, toggled by worldmap-app.js). 900px and up: a fixed
 * panel on the left. No scrim either way, so the map stays tappable and
 * picking another mission swaps the drawer's content.
 */

/* The backdrop only positions the drawer; it never takes clicks, so taps
   reach the map. !important beats worldmap.css's rule that turns pointer
   events back on for every .modern-popup-backdrop. */
#detailsPopup.mission-drawer-backdrop {
  background: none;
  pointer-events: none !important;
  display: block;
  padding: 0;
  /* Fill the screen exactly, so the drawer meets the bottom edge. The other
     popups size from --popup-viewport-*, which can lag behind the window. */
  top: 0;
  bottom: 0;
  height: auto;
}

#detailsPopup .mission-drawer {
  pointer-events: auto;
  touch-action: pan-y; /* scroll only: a pinch here must not zoom the page */
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 42%;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-body);
  border-radius: var(--radius-3xl) var(--radius-3xl) 0 0;
  box-shadow: 0 -10px 30px rgba(20, 33, 61, 0.2);
  transform: translateY(24px);
  transition: height 0.3s ease, transform 0.3s ease;
  box-sizing: border-box;
}

#detailsPopup.show .mission-drawer {
  transform: translateY(0);
}

/* Full height, leaving the header bar visible */
#detailsPopup.is-expanded .mission-drawer {
  height: calc(100% - 64px);
}

.mission-drawer__handle {
  flex-shrink: 0;
  height: 30px;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.mission-drawer__handle span {
  width: 44px;
  height: 5px;
  border-radius: 3px;
  background: var(--color-border);
}

.mission-drawer__close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--color-surface-soft);
  color: var(--color-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1;
}

.mission-drawer__close:hover {
  background: var(--color-surface-muted);
}

.mission-drawer__scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--space-5) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ---- Header ---- */
.mission-drawer__header {
  padding-right: 48px; /* room for the close button */
}

.mission-drawer__eyebrow {
  font-size: 11px;
  font-weight: var(--font-weight-extrabold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-primary);
}

#detailsPopup .mission-drawer__title {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 29px;
  font-weight: var(--font-weight-bold);
  line-height: 1.08;
  color: var(--color-text);
}

/* Countries under the name: flag + name, wrapping as needed */
.mission-places {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1-5) var(--space-4);
  margin-top: var(--space-2-5);
}

.mission-place {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-muted);
}

.mission-place__flag {
  width: 27px;
  height: 18px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: 3px;
  box-shadow: 0 0 0 1px var(--color-border-soft);
}

/* ---- Sections ---- */
#detailsPopup .mission-drawer__section {
  margin: 0;
}

#detailsPopup .mission-drawer__section .section-title {
  margin: 0 0 var(--space-2-5);
  font-family: var(--font-body);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-extrabold);
  color: var(--color-text);
}




.mission-drawer__correction {
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.mission-drawer__correction a {
  font-weight: var(--font-weight-bold);
  color: var(--color-link);
}

/* ---- Pinned footer ---- */
.mission-drawer__footer {
  flex-shrink: 0;
  display: flex;
  gap: var(--space-2-5);
  padding: var(--space-3) var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--color-border-soft);
  background: var(--color-surface);
  border-radius: 0 0 inherit inherit;
}

/* Nothing to pin when not in a game */
.mission-drawer__footer:has(#guessButtonArea[style*="none"]) {
  display: none;
}

#detailsPopup .map-guess-button-area {
  flex: 1;
  margin: 0;
}

.mission-drawer__guess {
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-extrabold);
  cursor: pointer;
}

.mission-drawer__guess:hover {
  background: var(--color-primary-hover);
}

/* ---- Desktop: side panel ---- */
@media (min-width: 900px) {
  #detailsPopup .mission-drawer {
    left: var(--space-6);
    right: auto;
    top: 88px;
    bottom: var(--space-6);
    width: 420px;
    max-width: calc(100% - 48px);
    height: auto;
    border-radius: var(--radius-2xl);
    box-shadow: 0 16px 40px rgba(20, 33, 61, 0.2);
    transform: translateX(-16px);
    overflow: hidden;
  }

  #detailsPopup.show .mission-drawer,
  #detailsPopup.is-expanded .mission-drawer {
    transform: translateX(0);
    height: auto;
  }

  .mission-drawer__handle {
    display: none;
  }

  .mission-drawer__scroll {
    padding-top: var(--space-5);
  }

  #detailsPopup .mission-drawer__title {
    font-size: 34px;
    line-height: 1.05;
  }

}

/* ==== Other map popups (.modern-popup-*) as G sheets ====
   White header with a Newsreader title and a round close button. Centered
   dialogs on desktop; bottom sheets on phones, like the drawer. */
.modern-popup-backdrop:not(.mission-drawer-backdrop) {
  background: rgba(20, 33, 61, 0.45);
}

.modern-popup-panel {
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-sheet-strong);
}

.modern-popup-header {
  align-items: flex-start;
  gap: var(--space-3);
  min-height: 0;
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 0;
  background: var(--color-surface);
  color: var(--color-text);
}

.modern-popup-title {
  font-family: var(--font-display);
  font-size: var(--font-size-4xl);
  font-weight: var(--font-weight-bold);
  line-height: 1.15;
  color: var(--color-text);
}

.modern-popup-close {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  margin: 0;
  padding: 0;
  border-radius: var(--radius-pill);
  background: var(--color-surface-soft);
  color: var(--color-text);
  font-size: var(--font-size-4xl);
  line-height: 1;
  opacity: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modern-popup-close:hover {
  background: var(--color-surface-muted);
  border-radius: var(--radius-pill);
}

.modern-btn {
  border-radius: var(--radius-lg);
  font-weight: var(--font-weight-extrabold);
}

.modern-btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}

.modern-btn-primary:hover {
  background: var(--color-primary-hover);
  transform: none;
}

/* Sheet building blocks (guess sheet) */
.sheet-eyebrow {
  margin-bottom: var(--space-1);
  font-size: 11px;
  font-weight: var(--font-weight-extrabold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--color-primary);
}

.sheet-label {
  display: block;
  margin-top: var(--space-1-5);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
}

#guessPopup .sheet-field {
  width: 100%;
  max-width: none;
  height: 50px;
  padding: 0 var(--space-3-5);
  box-sizing: border-box;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--font-size-lg);
}

#guessPopup .sheet-field:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-a10);
}

.sheet-primary {
  width: 100%;
  height: 54px;
  margin-top: var(--space-3);
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-size: var(--font-size-lg-plus);
  font-weight: var(--font-weight-extrabold);
  cursor: pointer;
}

.sheet-primary:hover {
  background: var(--color-primary-hover);
}

.sheet-link {
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--color-text);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-bold);
  cursor: pointer;
}

#guessPopup .modern-popup-content.wm-guess-popup-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-1-5);
  padding: var(--space-2) var(--space-5) var(--space-3);
  text-align: left;
}

@media (max-width: 899px) {
  /* Span the screen exactly so sheets meet the bottom edge; the
     --popup-viewport-* values can lag behind the window. */
  .modern-popup-backdrop:not(.mission-drawer-backdrop) {
    align-items: flex-end;
    top: 0 !important;
    bottom: 0 !important;
    height: auto !important;
  }

  .modern-popup-backdrop:not(.mission-drawer-backdrop) > .modern-popup-panel {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    max-height: calc(var(--popup-viewport-height, 100vh) - 64px) !important;
    border-radius: var(--radius-3xl) var(--radius-3xl) 0 0 !important;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateY(32px);
  }

  .modern-popup-backdrop.show:not(.mission-drawer-backdrop) > .modern-popup-panel {
    transform: none;
  }
}

/* ==== Map controls ====
   Desktop: one column at the bottom right, above Random mission and Temples,
   so the mission panel on the left never covers them. */
@media (min-width: 900px) {
  .infoBtnBackground,
  .searchBtnBackground,
  .guessesListBtnBackground,
  .linkBtnBackground,
  .trophyBtnBackground,
  .statsBtnBackground {
    left: auto;
    right: 15px;
  }
  .infoBtnBackground { bottom: 180px; }
  .searchBtnBackground { bottom: 240px; }
  .guessesListBtnBackground { bottom: 300px; }
  .linkBtnBackground { bottom: 360px; }
  .trophyBtnBackground { bottom: 420px; }
  .statsBtnBackground { bottom: 480px; }
}

/* Merch card inside the drawer */
#detailsPopup .mission-store-section {
  border-width: 1px;
}

#detailsPopup .mission-store-title {
  font-family: var(--font-display);
  font-weight: var(--font-weight-bold);
}

/* Sections keep their natural height in the drawer's scrolling column */
#detailsPopup .mission-drawer__scroll > * {
  flex-shrink: 0;
}

/* worldmap.css forces everything inside ad slots to display:block; the
   label row under each ad is a flex row. */
.modern-popup-backdrop.show #detailsPopupAdSpot .ad-frame__label,
.modern-popup-backdrop.show #sponsoredAdSpot .ad-frame__label,
.modern-popup-backdrop.show #infoPopupAdSpot .ad-frame__label,
.modern-popup-backdrop.show #myGuessAdSpot .ad-frame__label,
.modern-popup-backdrop.show #mainMenuAdSpot .ad-frame__label,
.modern-popup-backdrop.show #guessesListAdSpot .ad-frame__label {
  display: flex !important;
}

/* Same for the promo line, a wrapping flex row. */
.modern-popup-backdrop.show #detailsPopupAdSpot .ad-frame__promo,
.modern-popup-backdrop.show #sponsoredAdSpot .ad-frame__promo,
.modern-popup-backdrop.show #infoPopupAdSpot .ad-frame__promo,
.modern-popup-backdrop.show #myGuessAdSpot .ad-frame__promo,
.modern-popup-backdrop.show #mainMenuAdSpot .ad-frame__promo,
.modern-popup-backdrop.show #guessesListAdSpot .ad-frame__promo {
  display: flex !important;
}

#detailsPopup #detailsPopupAdSpot {
  margin: 0 !important;
  padding: 0 !important;
}

/* "Thanks for guessing" success sheet */
#myGuessPopup #guessInfoDisplay {
  border-color: var(--color-border-soft);
}

#myGuessPopup .wm-share-btn-btn {
  width: 100%;
  max-width: none;
  height: 54px;
}

/* ==== In-game card (game name + search) ==== */
.gameNameBtnBackground {
  top: 68px !important;
  left: 16px !important;
  right: 16px !important;
  transform: none !important;
  z-index: 3 !important;
}

.game-card {
  display: flex;
  align-items: center;
  gap: var(--space-2-5);
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-3);
  background: var(--color-surface);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-raised);
  pointer-events: auto;
}

.game-card__main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2-5);
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  cursor: pointer;
}

.game-card__icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-tint);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-card__text {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.game-card__name {
  font-family: var(--font-display);
  font-size: var(--font-size-lg-plus);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-card__hint {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.game-card__search {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--color-surface-soft);
  color: var(--color-text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

@media (min-width: 900px) {
  .gameNameBtnBackground {
    top: 80px !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: 420px;
  }
}

/* Phones in a game: the card and the game menu cover what the side
   buttons did, so the map stays clear. */
@media (max-width: 899px) {
  .in-game .statsBtnBackground,
  .in-game .trophyBtnBackground,
  .in-game .linkBtnBackground,
  .in-game .guessesListBtnBackground,
  .in-game .searchBtnBackground,
  .in-game .infoBtnBackground {
    display: none !important;
  }
}

/* ==== Button hierarchy in sheets ==== */
.modern-btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1.5px solid var(--color-border);
}

.modern-btn-secondary:hover {
  background: var(--color-surface-soft);
}

.modern-btn.is-danger {
  background: var(--color-danger);
}

.modern-btn.is-danger:hover {
  background: var(--color-danger-strong);
}

/* ==== Game menu: one solid action, then a list of rows ==== */
#gameMenuPopup .game-menu {
  text-align: left;
}

#gameMenuPopup .wm-game-menu-popup-div {
  max-width: none;
}

#gameMenuPopup #shareBtn {
  margin-bottom: var(--space-2);
}

.menu-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 52px;
  padding: 0 var(--space-1);
  border: 0;
  border-bottom: 1px solid var(--color-border-soft);
  background: none;
  color: var(--color-text);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  text-align: left;
  cursor: pointer;
}

.menu-row:last-child {
  border-bottom: 0;
}

.menu-row:hover {
  color: var(--color-link);
}

.menu-row svg,
.menu-row img {
  width: 20px;
  height: 20px;
  margin: 0;
  flex-shrink: 0;
  color: var(--color-text-muted);
}

@media (min-width: 900px) {
  #gameMenuPopup .modern-popup-panel {
    max-width: 440px;
  }

  #gameMenuPopup .game-menu {
    padding: var(--space-2) var(--space-5) var(--space-5);
  }
}

/* ==== Left-aligned sheets ==== */
#emailPopup .modern-popup-content,
#emailPopup .modern-popup-content *,
#enterCreatorCodePopup .modern-popup-content,
#enterCreatorCodePopup .modern-popup-content *,
#callPopup .modern-popup-content,
#callPopup .modern-popup-content *,
#infoPopup .modern-popup-content,
#infoPopup .modern-popup-content *,
#confirmPopup .modern-popup-content,
#confirmPopup .modern-popup-content *,
#myGuessPopup .modern-popup-content,
#myGuessPopup .modern-popup-content * {
  text-align: left !important;
}

/* Fields fill the sheet instead of sitting in a narrow centered column */
#emailPopup input[type="email"],
#emailPopup textarea,
#enterCreatorCodePopup input,
#callPopup select,
#callPopup input {
  width: 100% !important;
  max-width: none !important;
}

#emailPopup .wm-email-popup-div,
#emailPopup .wm-email-popup-label,
#emailPopup #guessEmailValidation {
  max-width: none !important;
  align-items: flex-start;
}

/* How to play: a light panel instead of a heavy blue box */
#infoPopup #infoPopupShareSection {
  border: 1px solid var(--color-border-soft) !important;
  background: var(--color-surface-soft) !important;
}

/* Readable link color on white (the light accent is for the navy header) */
#lostCreatorCodeLink {
  color: var(--color-link) !important;
  font-weight: var(--font-weight-bold);
}

/* ==== Game statistics as a sheet ==== */
@media (max-width: 899px) {
  #statsPopup .modern-popup-panel {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    border-radius: var(--radius-3xl) var(--radius-3xl) 0 0 !important;
    max-height: calc(var(--popup-viewport-height, 100vh) - 64px) !important;
  }
}

#enterCreatorCodePopup #enterCreatorCodePopupBtn {
  width: 100%;
}

/* Game statistics: compact tiles */
#statsPopup .stat-card {
  padding: var(--space-3-5) var(--space-3);
}

#statsPopup .stat-icon {
  font-size: 1.2em;
  margin-bottom: var(--space-1);
}

/* Game over: the call reads as the headline */
#gameFinishedPopup #actuallyCalledMissionLabel {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: var(--font-weight-bold);
  line-height: 1.15;
}

/* Buttons keep centered labels inside the left-aligned sheets */
#emailPopup .modern-popup-content button,
#enterCreatorCodePopup .modern-popup-content button,
#callPopup .modern-popup-content button,
#infoPopup .modern-popup-content button,
#confirmPopup .modern-popup-content button,
#myGuessPopup .modern-popup-content button {
  text-align: center !important;
  justify-content: center;
}

#enterCreatorCodePopup #enterCreatorCodePopupBtn {
  display: flex;
  padding-left: var(--space-4);
  padding-right: var(--space-4);
}

/* ==== Popup action buttons: one rule everywhere ====
   One action: full width. Two actions: side by side, filling the row
   equally (secondary left, primary right). All 52px tall. Text-link
   actions are full width and centered. Menu rows and small icon buttons
   (edit pencil, stats tile) are left alone. */
.modern-popup-content .modern-btn,
.modern-popup-content .sheet-primary,
.modern-popup-content .wm-mission-call-store-popup-button {
  width: 100% !important;
  max-width: none !important;
  height: 52px !important;
  min-height: 52px !important;
  max-height: 52px !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  padding: 0 var(--space-4) !important;
  box-sizing: border-box;
  display: flex !important;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-lg) !important;
  font-weight: var(--font-weight-extrabold) !important;
  border-radius: var(--radius-lg) !important;
}

/* The rule above forces every popup button visible; a button that is hidden
   until it applies uses the hidden attribute. */
.modern-popup-content .modern-btn[hidden] {
  display: none !important;
}

/* Rows of two: fill the row, equal halves */
.modern-popup-content .wm-email-popup-div-2,
.modern-popup-content .wm-confirm-popup-div {
  display: flex !important;
  gap: var(--space-2-5) !important;
  width: 100% !important;
  max-width: none !important;
  margin: var(--space-4) 0 0 !important;
}

.modern-popup-content .wm-email-popup-div-2 > .modern-btn,
.modern-popup-content .wm-confirm-popup-div > .modern-btn {
  flex: 1 1 0 !important;
  width: auto !important;
}

/* Single-button wrappers stretch so the button can */
.modern-popup-content .u-flex-center,
.modern-popup-content .wm-mission-call-store-popup-div,
.modern-popup-content .wm-my-guess-popup-div,
.modern-popup-content .wm-no-guesses-label-div-2 {
  display: block !important;
  width: 100% !important;
  max-width: none !important;
}

/* Text-link action */
.modern-popup-content .sheet-link {
  width: 100%;
  text-align: center !important;
}

/* Share: the two or three options fill the row */
#shareModal #shareButtons {
  flex-wrap: nowrap;
}

#shareModal .share-btn {
  flex: 1 1 0;
  max-width: none;
  height: 52px;
  font-size: var(--font-size-base);
}

/* The open phone menu covers this area; the card would otherwise float over it */
body.nav-open .gameNameBtnBackground {
  display: none !important;
}
