  /* In-frame ad UX (banner peek + in-frame back arrow) */
  .ad-back {
    position: absolute;
    top: 10px; left: 10px;
    width: 36px; height: 36px;
    border-radius: 11px;
    z-index: 6;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }
  .ad-back.show { opacity: 0.92; pointer-events: auto; }
  .ad-back:hover { opacity: 1; }
  .ad-back svg { width: 18px; height: 18px; }
  /* During an active ad (catcher mounted), the megaphone stays visible, and
     the back arrow becomes a faded, unclickable placeholder — the ad-close X
     to the right of the countdown is the only way to dismiss the ad. Toggled
     via `.ad-active` on the parent frame in adAttachToIframe's peek start/end. */
  .ad-active .ad-back {
    opacity: 0.35 !important;
    pointer-events: none !important;
    cursor: default !important;
  }
  .ad-active .ad-mark { opacity: 1; }
  .ad-hot {
    position: absolute;
    top: 0; left: 0;
    width: 88px; height: 88px;
    z-index: 5;
    pointer-events: auto;
  }
  /* Countdown pip — sits next to .ad-mark during the 5s ad window.
     .ad-back at left:10/width:36, .ad-mark at left:56/width:32 → countdown
     at left:96 (56+32+8 padding). Matte-green to match the .ad-back family;
     megaphone keeps its amber identity in between. */
  .ad-countdown {
    position: absolute;
    top: 10px; left: 96px;
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: 50%;
    background: rgba(20, 50, 38, 0.78);
    color: var(--accent-soft);
    border: 1px solid rgba(60,130,110,0.55);
    font-weight: 700; font-size: 18px;
    z-index: 7;
    pointer-events: none;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 0 0 1px var(--accent-glow), 0 2px 6px rgba(0,0,0,0.45);
  }
  /* Ad close-X — sits next to .ad-countdown (left:136 = 96+32+8) during the
     5s ad window. Red-ish destructive tint matching .confirm-pop .danger.
     Click closes the ad immediately (same path as the legacy ad-back peek
     exit: endPeekIfActive('back') + 60s cooldown). */
  .ad-close {
    position: absolute;
    top: 10px; left: 136px;
    width: 32px; height: 32px;
    border-radius: 50%;
    display: grid; place-items: center;
    border: 1px solid rgba(180,80,60,0.55);
    background: rgba(70, 25, 18, 0.78);
    color: #ffd4c4;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, background 0.12s ease;
    z-index: 11;
  }
  .ad-active .ad-close { opacity: 1; pointer-events: auto; }
  .ad-close:hover { background: rgba(120,40,30,0.95); }
  .ad-close svg { width: 16px; height: 16px; display: block; }
  .ad-catcher {
    position: absolute;
    inset: 0;
    z-index: 4;
    background: transparent;
    cursor: pointer;
    /* Explicit opt-in — родитель .fs-ad-host имеет pointer-events:none, без
       этого clicks по catcher'у не доходили в FS-режиме. */
    pointer-events: auto;
  }
  /* Ad-overlay iframe (показывает рекламу поверх игрового iframe'а). PE:auto
     чтобы игра-реклама принимала interactions ВНУТРИ overlay'а — но catcher
     стоит выше (z:4) и перехватывает клики для travel-mechanic'а. */
  .ad-overlay-frame {
    pointer-events: auto;
  }
  /* Static "this is an ad" indicator — sits next to .ad-back during the 5s ad window.
     .ad-back is at top:10/left:10/width:36 → place at top:10/left:56 (10+36+10). */
  .ad-mark {
    position: absolute;
    top: 10px; left: 56px;
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: 50%;
    border: 1px solid rgba(140,140,80,0.45);
    background: rgba(40,40,8,0.72);
    color: #ffd47a;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    z-index: 6;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease;
  }
  .ad-mark.show { opacity: 1; }
  .ad-mark svg { width: 16px; height: 16px; }

  /* Narrow frames: ad controls are repositioned by JS (adAttachToIframe →
     refreshAdLayout / ResizeObserver) based on the ACTUAL frame width, not
     the viewport width. Inline styles applied there override these defaults.
     The old @media(max-width:380px) viewport-based rule is intentionally
     removed — it compared the wrong dimension (viewport vs. frame). */

  /* ── Лайтбокс ассета (фуллскрин-просмотр картинки/видео) ───────────────────
     Используется галереей промоматериалов (лайтбокс в #modal-root) И экраном
     #asset/<id> (asset-view, встроен в #main, без оверлея — переиспользует
     .asset-lb-bar / .asset-lb-stage / .asset-lb-media). Грузится eagerly
     (index.html), чтобы deep-link на ассет работал без admin-чанка. */
  .asset-lb-back {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    z-index: 9000;
    background: rgba(8, 10, 14, 0.92);
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow: hidden;
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }
  .asset-lb-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    flex: 0 0 auto;
    flex-wrap: wrap;
    min-height: 44px;
  }
  .asset-lb-title {
    font-size: 14px;
    font-weight: 600;
    color: #f0f2f5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: min(50vw, calc(100% - 160px));
  }
  .asset-lb-spacer { flex: 1 1 auto; }
  .asset-lb-close { font-size: 18px; line-height: 1; padding: 6px 12px; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
  .asset-lb-stage {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px 18px;
    overflow: hidden;
    box-sizing: border-box;
  }
  .asset-lb-media {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
    display: block;
  }

  /* ── Ad-end modal (центральная карточка после полного просмотра рекламы) ───
     Показывается из ad-end-modal.js по истечении 5s счётчика. Закрытие ТОЛЬКО
     крестиком справа вверху → возобновляет игру-хост. z-index ВЫШЕ overlay'а
     рекламы и fullscreen-режима (.ad-overlay-frame=1, fs-overlay ≈9000+). */
  .ad-end-backdrop {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    z-index: 2147480000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 16px;
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    background: rgba(8, 6, 4, 0.78);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }
  .ad-end-card {
    position: relative;
    width: 100%;
    max-width: 520px;
    max-height: 90dvh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--surface, #221d19);
    border: 1px solid var(--border-2, rgba(255,220,180,0.12));
    border-radius: var(--r-lg, 16px);
    box-shadow: var(--shadow-card, 0 8px 24px rgba(0,0,0,0.45));
    color: var(--text, #f1e8de);
  }
  .ad-end-media {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: var(--bg-2, #1a1714);
    border-top-left-radius: var(--r-lg, 16px);
    border-top-right-radius: var(--r-lg, 16px);
    overflow: hidden;
    display: block;
  }
  .ad-end-media > svg,
  .ad-end-cover-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }
  /* Большая кнопка «Играть» — сразу под обложкой, на всю ширину карточки.
     Акцентный фон как у .btn.primary, тач-таргет ≥44px, шрифт 16px. */
  .ad-end-play {
    display: block;
    width: calc(100% - 36px);
    margin: 14px 18px 4px;
    min-height: 48px;
    padding: 12px 18px;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    color: #eef5f1;
    background: linear-gradient(180deg, #2e7e64 0%, #1a4f3e 100%);
    border: 1px solid rgba(70, 110, 95, 0.55);
    border-radius: var(--r-md, 12px);
    box-shadow:
      0 1px 0 rgba(255, 255, 255, 0.07) inset,
      0 -1px 0 rgba(0, 0, 0, 0.4) inset,
      0 2px 6px rgba(0, 0, 0, 0.45);
    cursor: pointer;
    transition: background 0.15s ease, transform 0.08s ease;
  }
  @media (hover: hover) {
    .ad-end-play:hover { background: linear-gradient(180deg, #348c70 0%, #225e4a 100%); }
  }
  .ad-end-play:active { transform: translateY(1px); }
  .ad-end-body {
    padding: 16px 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .ad-end-badge {
    align-self: flex-start;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #ffd47a;
    background: rgba(40, 40, 8, 0.72);
    border: 1px solid rgba(140, 140, 80, 0.45);
    border-radius: 999px;
    padding: 3px 10px;
  }
  .ad-end-title {
    margin: 0;
    font-size: 22px;
    line-height: 1.2;
    font-weight: 700;
    color: var(--text, #f1e8de);
  }
  .ad-end-desc {
    margin: 0;
    font-size: 14px;
    line-height: 1.45;
    color: var(--muted, #b3a89c);
    white-space: pre-wrap;
    word-break: break-word;
  }
  .ad-end-rate,
  .ad-end-catrate { margin-top: 2px; }
  .ad-end-rate:empty,
  .ad-end-catrate:empty { display: none; }
  /* iOS не зумит при фокусе если шрифт инпутов/range ≥16px. */
  .ad-end-card input,
  .ad-end-card select,
  .ad-end-card textarea { font-size: 16px; }
  .ad-end-close {
    position: absolute;
    top: 8px; right: 8px;
    width: 44px; height: 44px;
    min-width: 44px; min-height: 44px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border: 1px solid var(--border-2, rgba(255,220,180,0.12));
    background: rgba(20, 16, 12, 0.78);
    color: var(--text, #f1e8de);
    cursor: pointer;
    z-index: 2;
    transition: background 0.15s ease;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }
  .ad-end-close:hover { background: rgba(40, 32, 24, 0.95); }
  .ad-end-close svg { width: 20px; height: 20px; display: block; }
  @media (max-width: 560px) {
    .ad-end-backdrop { padding: 10px; }
    .ad-end-card { max-width: 100%; max-height: 94dvh; }
    .ad-end-title { font-size: 19px; }
  }

  /* Экран-вьюер #asset/<id>: тот же тёмный фуллскрин-вид, но как страница в
     #main (не оверлей). Высота — почти весь вьюпорт. */
  .asset-view-page {
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - 40px);
    height: calc(100dvh - 40px);
    max-width: 100%;
    box-sizing: border-box;
    background: rgba(8, 10, 14, 0.92);
    border-radius: 10px;
    overflow: hidden;
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
  }
  .asset-view-error { align-items: center; justify-content: center; }

  /* ── On-demand ad overlay (portal-api / wfe.ads.*) ─────────────────────────
     Full-viewport ad shown by showAdOnDemand() when a game calls
     wfe.ads.interstitial()/rewarded(). Distinct from the host-scheduled peek
     (.ad-overlay-frame, which is absolutely positioned INSIDE a game frame):
     this one is a fixed top-level overlay in portal chrome, so it must lift
     above the fullscreen play overlay (z:1000) and pooled play iframe
     (z:1001-1003). The host game is paused behind it. */
  .ad-ondemand-back {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: #000;
    display: block;
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
  }
  .ad-ondemand-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    background: #000;
  }
  .ad-ondemand-badge {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    left: 10px;
    z-index: 2;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.4px;
    border: 1px solid rgba(140,140,80,0.45);
    background: rgba(40,40,8,0.72);
    color: #ffd47a;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    pointer-events: none;
  }
  .ad-ondemand-cd {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    right: 56px;
    z-index: 2;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #cfe9d8;
    border: 1px solid rgba(95,180,135,0.45);
    background: rgba(8,28,18,0.72);
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    pointer-events: none;
  }
  .ad-ondemand-close {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    right: 10px;
    z-index: 2;
    width: 36px; height: 36px;
    border-radius: 11px;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(20,20,24,0.78);
    color: #fff;
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }
  .ad-ondemand-close:hover { background: rgba(40,40,46,0.9); }
  .ad-ondemand-close svg { width: 18px; height: 18px; display: block; }
