.iap-confirm-layer {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(6, 10, 20, .78);
  backdrop-filter: blur(5px);
}

.iap-confirm-dialog {
  width: min(440px, 100%);
  padding: 24px;
  border: 2px solid #77e0ff;
  border-radius: 18px;
  background: #111827;
  color: #f8fafc;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .55);
}

.iap-confirm-dialog h2 { margin: 0 0 16px; }
.iap-confirm-dialog p { margin: 8px 0; }
.iap-confirm-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.iap-confirm-actions button { min-height: 44px; padding: 10px 16px; border-radius: 10px; font: inherit; cursor: pointer; }
.iap-confirm-buy { border: 0; background: #22c55e; color: #07140b; font-weight: 700; }
.iap-confirm-cancel { border: 1px solid #64748b; background: #1e293b; color: #f8fafc; }
.iap-confirm-dialog:focus { outline: 3px solid #fde047; outline-offset: 3px; }
.iap-confirm-actions button:focus-visible { outline: 3px solid #fde047; outline-offset: 2px; }
/* Arming delay: the primary action is inactive for a moment after the dialog appears (accidental confirmation guard). */
.iap-confirm-actions button[disabled] { opacity: .5; cursor: not-allowed; }
.iap-confirm-arming { min-height: 1.4em; margin: 10px 0 0; color: #cbd5e1; font-size: .9em; }
.iap-insufficient-dialog { border: 2px solid #f59e0b; }
.iap-insufficient-dialog h2 { color: #fbbf24; }
/* The canonical Жетон (docs/TOKEN_ASSET.md): its own PNG size, never scaled; width / height reserve the space. */
.twg-token { display: inline-block; flex: none; vertical-align: middle; }
.iap-dialog-token { width: 32px; height: 32px; }
.iap-confirm-dialog h2 { display: flex; align-items: center; gap: 10px; }
/* Aligned with the first text line when a long line wraps on a phone. */
.iap-token-line { display: flex; align-items: flex-start; gap: 6px; }
.iap-token-line .twg-token { width: 16px; height: 16px; margin-top: .25em; margin-top: calc((1lh - 16px) / 2); }

/* Portal UX hardening: the portal-owned Token Shop overlay over the (still running, inert) game frame. */
.iap-shop-layer {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(6, 10, 20, .78);
  backdrop-filter: blur(4px);
  overscroll-behavior: contain;
}
.iap-shop-layer[hidden] { display: none; }
.iap-shop-dialog {
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  height: min(860px, 100%);
  max-height: 100%;
  border: 2px solid #77e0ff;
  border-radius: 18px;
  background: #111827;
  color: #f8fafc;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .55);
  overflow: hidden;
}
.iap-shop-dialog:focus { outline: 3px solid #fde047; outline-offset: 3px; }
.iap-shop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 10px 18px;
  border-bottom: 1px solid #334155;
}
.iap-shop-header h2 { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 1.1rem; overflow-wrap: anywhere; }
.iap-shop-close {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid #64748b;
  border-radius: 10px;
  background: #1e293b;
  color: #f8fafc;
  font: inherit;
  cursor: pointer;
}
.iap-shop-close:focus-visible { outline: 3px solid #fde047; outline-offset: 2px; }
.iap-shop-frame { flex: 1 1 auto; width: 100%; min-height: 0; border: 0; background: #0b1220; }
html.iap-shop-open, html.iap-shop-open body { overflow: hidden; }
/* Phones: a full-screen sheet, no horizontal overflow, touch-sized controls. */
@media (max-width: 640px) {
  .iap-shop-layer { padding: 0; place-items: stretch; }
  .iap-shop-dialog { width: 100%; height: 100%; border: 0; border-radius: 0; }
  .iap-shop-header { padding: max(8px, env(safe-area-inset-top)) 8px 8px 14px; }
}

/* «Недостаточно Жетонов» with the «Купить Жетоны» block: the server's packages right in the dialog (compact grid, no
   horizontal scroll). Dark navy dialog, gold frame, canonical Жетон; each package is an armed action like «Купить». */
.iap-insufficient-packages { width: min(520px, 100%); max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); overflow-y: auto; box-sizing: border-box; }
.iap-packages { margin-top: 16px; padding-top: 14px; border-top: 1px solid #334155; }
.iap-packages h3 { margin: 0 0 10px; font-size: 1.05rem; color: #f8fafc; }
/* A package is one row: «[Жетон] 50 Жетонов» on the left, the price pill on the right. 2 columns (the 5th spans the row);
   1 column on phones. Never a wrapped amount, never a horizontal scroll. */
.iap-package-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.iap-package {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; min-height: 52px;
  padding: 8px 12px; border: 2px solid #fbbf24; border-radius: 12px; background: #1e293b; color: #f8fafc;
  font: inherit; text-align: left; cursor: pointer;
}
.iap-package:last-child:nth-child(odd) { grid-column: 1 / -1; }
.iap-package:hover:not([disabled]) { background: #273449; border-color: #fde047; }
.iap-package:focus-visible { outline: 3px solid #fde047; outline-offset: 2px; }
.iap-package[disabled] { opacity: .5; cursor: not-allowed; }
.iap-package-amount { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 700; font-size: 1rem; white-space: nowrap; }
.iap-package-amount .twg-token { width: 24px; height: 24px; }
.iap-package-price { flex: none; padding: 3px 10px; border-radius: 999px; background: #fbbf24; color: #1c1300; font-weight: 800; white-space: nowrap; }
.iap-insufficient-packages .iap-confirm-actions { margin-top: 14px; }
.iap-insufficient-packages .iap-confirm-cancel { flex: 1 1 100%; }
@media (max-width: 520px) {
  .iap-insufficient-packages { padding: 18px 16px; }
  .iap-package-grid { grid-template-columns: 1fr; gap: 8px; }
  .iap-package:last-child:nth-child(odd) { grid-column: auto; }
}

/* The compact purchase flow of the same overlay (a package chosen in «Недостаточно Жетонов»): a smaller dialog with the
   gold frame; phones keep the full-screen sheet. */
/* Auto height: the frame takes the height the shop document reports for its content (portal-iap.js sizeShopFrame);
   the dialog is capped at the viewport (layer padding included), and only then the frame scrolls inside. */
.iap-shop-dialog.iap-shop-dialog-compact { width: min(500px, 100%); height: auto; max-height: 100%; border-color: #f59e0b; }
.iap-shop-dialog-compact .iap-shop-frame { flex: 0 1 auto; height: 360px; }
@media (max-width: 640px) {
  .iap-shop-dialog.iap-shop-dialog-compact { width: 100%; height: 100%; border: 0; border-top: 3px solid #f59e0b; }
  /* Phones: the full-screen sheet; the frame fills it whatever height the content reports. */
  .iap-shop-dialog-compact .iap-shop-frame { flex: 1 1 0; }
}
