:root {
  --tg-safe-top: var(--tg-content-safe-area-inset-top, var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)));
  --tg-safe-right: var(--tg-content-safe-area-inset-right, var(--tg-safe-area-inset-right, env(safe-area-inset-right, 0px)));
  --tg-safe-bottom: var(--tg-content-safe-area-inset-bottom, var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  --tg-safe-left: var(--tg-content-safe-area-inset-left, var(--tg-safe-area-inset-left, env(safe-area-inset-left, 0px)));
}

[data-payment-gateway="telegram_stars"] { display: none !important; }

.telegram-mini-app body {
  background: var(--tg-theme-bg-color, #0a0a0a);
  color: var(--tg-theme-text-color, #fff);
  padding-top: var(--tg-safe-top);
  padding-right: var(--tg-safe-right);
  padding-left: var(--tg-safe-left);
  overscroll-behavior-y: none;
}

.telegram-mini-app #root {
  min-height: calc(100dvh - var(--tg-safe-top));
  padding-bottom: var(--tg-safe-bottom);
}

.telegram-mini-app [data-payment-gateway="wata"],
.telegram-mini-app [data-payment-gateway="oxapay"] {
  display: none !important;
}

.telegram-mini-app [data-payment-gateway="telegram_stars"] {
  display: flex !important;
}

.telegram-mini-app .seo-content,
.telegram-mini-app .network-links,
.telegram-mini-app .site-footer {
  display: none !important;
}

.telegram-auth-pending #root {
  visibility: hidden;
}

.telegram-auth-pending body::before {
  content: "Входим через Telegram…";
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: grid;
  place-items: center;
  background: #0a0a0a;
  color: rgba(255, 255, 255, .72);
  font: 600 15px/1.4 Inter, system-ui, sans-serif;
}

#miniapp-auth-error {
  position: fixed;
  inset: 16px;
  z-index: 100000;
  margin: auto;
  width: min(420px, calc(100% - 32px));
  height: max-content;
  padding: 24px;
  border: 1px solid rgba(239, 68, 68, .38);
  border-radius: 20px;
  background: #171111;
  color: #fff;
  box-shadow: 0 20px 70px rgba(0, 0, 0, .55);
  font-family: Inter, system-ui, sans-serif;
}

#miniapp-auth-error strong,
#miniapp-auth-error span { display: block; }
#miniapp-auth-error span { margin: 10px 0 18px; color: rgba(255,255,255,.64); }
#miniapp-auth-error button,
#miniapp-auth-error a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
}
#miniapp-auth-error button { margin-right: 8px; background: #9333ea; color: #fff; }
#miniapp-auth-error a { background: rgba(255,255,255,.08); color: #fff; }

@media (max-width: 640px) {
  #root button,
  #root a[role="button"] { min-height: 44px; }
  #root [role="dialog"] {
    width: calc(100vw - 24px) !important;
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
  }
  .telegram-mini-app #root [class*="fixed"][class*="bottom-"] {
    bottom: calc(8px + var(--tg-safe-bottom)) !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* Mobile media previews: keep full templates visible instead of center-cropping them. */
@media (max-width: 1023px) {
  #root img[src*="/images/menu_assets/"],
  #root img[src*="/images/outfits/"],
  #root img[src*="/images/poses/"],
  #root img[src*="/images/template-thumb_"],
  #root img[src*="/images/collection-thumb_"],
  #root img[src*="/images/collections/"],
  #root video[src*="/images/menu_assets/"],
  #root video[src*="/video/"] {
    width: 100%;
    max-width: 100%;
    height: 100%;
    object-fit: contain !important;
    object-position: center center !important;
    background-color: #080808;
  }
}

@media (max-width: 1023px) and (hover: none) and (pointer: coarse) {
  #root img[src*="/images/menu_assets/"],
  #root img[src*="/images/outfits/"],
  #root img[src*="/images/poses/"],
  #root img[src*="/images/template-thumb_"],
  #root img[src*="/images/collection-thumb_"],
  #root img[src*="/images/collections/"],
  #root video[src*="/images/menu_assets/"],
  #root video[src*="/video/"] {
    transform: none !important;
  }
}

/* Video mode picker: keep the complete source frame visible. The poster is
   shown only until the lazily loaded MP4 has decoded its first frame. */
@media (max-width: 1023px) {
  html.telegram-mini-app [role="dialog"] img[src^="/video/"] {
    position: absolute !important;
    inset: 0 !important;
    display: block;
    width: 100% !important;
    max-width: none !important;
    height: 100% !important;
    object-fit: contain !important;
    object-position: center center !important;
    background-color: #080808;
    z-index: 2 !important;
    pointer-events: none;
    will-change: opacity;
  }

  /* Only cards near the visible scroll viewport receive an MP4 source. */
  html.telegram-mini-app [role="dialog"] img[src^="/video/"] + video {
    position: absolute !important;
    inset: 0 !important;
    display: block !important;
    visibility: visible !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    object-position: center center !important;
    background-color: #080808;
    z-index: 1 !important;
  }
}

/* Mobile media previews: keep full templates visible instead of center-cropping them. */
@media (max-width: 1023px) {
  img[src*="/images/menu_assets/"],
  img[src*="/images/outfits/"],
  img[src*="/images/poses/"],
  img[src*="/images/template-thumb_"],
  img[src*="/images/collection-thumb_"],
  img[src*="/images/collections/"],
  video[src*="/images/menu_assets/"],
  video[src*="/video/"] {
    width: 100%;
    max-width: 100%;
    height: 100%;
    object-fit: contain !important;
    object-position: center center !important;
    background-color: #080808;
  }
}

@media (max-width: 1023px) and (hover: none) and (pointer: coarse) {
  img[src*="/images/menu_assets/"],
  img[src*="/images/outfits/"],
  img[src*="/images/poses/"],
  img[src*="/images/template-thumb_"],
  img[src*="/images/collection-thumb_"],
  img[src*="/images/collections/"],
  video[src*="/images/menu_assets/"],
  video[src*="/video/"] {
    transform: none !important;
  }
}
