:root {
  --mobile-safe-top: env(safe-area-inset-top, 0px);
  --mobile-safe-right: env(safe-area-inset-right, 0px);
  --mobile-safe-bottom: env(safe-area-inset-bottom, 0px);
  --mobile-safe-left: env(safe-area-inset-left, 0px);
  --mobile-touch: 44px;
  --mobile-gap: 12px;
  --mobile-bottom-offset: calc(88px + var(--mobile-safe-bottom));
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 0;
}

img,
video,
canvas,
iframe {
  max-width: 100%;
}

button,
.button,
input,
select,
textarea,
a[role="button"] {
  min-height: var(--mobile-touch);
}

.mobile-scroll-x,
.nav,
.studio-strip,
.reel-category-rail {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-inline: contain;
}

@media (max-width: 1024px) {
  .layout,
  .hero,
  .premium-hero-lux {
    gap: 14px;
  }

  .grid,
  .lux-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 768px) {
  body {
    padding-left: var(--mobile-safe-left);
    padding-right: var(--mobile-safe-right);
    padding-bottom: var(--mobile-safe-bottom);
  }

  .wrap,
  .container,
  .shell {
    width: 100% !important;
    max-width: 100vw !important;
    padding-left: max(12px, var(--mobile-safe-left)) !important;
    padding-right: max(12px, var(--mobile-safe-right)) !important;
  }

  h1 {
    font-size: clamp(30px, 11vw, 46px) !important;
    line-height: 0.98 !important;
  }

  h2 {
    font-size: clamp(21px, 7vw, 31px) !important;
    line-height: 1.08 !important;
  }

  h3 {
    font-size: clamp(18px, 5.6vw, 24px) !important;
  }

  p,
  li,
  td,
  th {
    font-size: clamp(14px, 4vw, 16px);
    line-height: 1.55;
  }

  .layout,
  .hero,
  .premium-hero-lux,
  .grid,
  .lux-grid,
  .ai-preview,
  .profile-main {
    grid-template-columns: 1fr !important;
  }

  .card,
  .glass-panel,
  .lux-card,
  .premium-promo-card,
  .premium-analytics-preview {
    border-radius: 18px !important;
    padding: 14px !important;
    content-visibility: auto;
    contain: layout paint;
    contain-intrinsic-size: auto 240px;
  }

  .actions {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  .actions .button,
  .actions button,
  .button,
  button {
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-bottom-nav,
  .bottom-nav {
    min-height: calc(66px + var(--mobile-safe-bottom)) !important;
    padding-bottom: calc(7px + var(--mobile-safe-bottom)) !important;
  }

  .mobile-bottom-nav a,
  .bottom-nav a {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .pulse-fab,
  .floating-action,
  .private-chat-launcher {
    bottom: var(--mobile-bottom-offset) !important;
    right: max(14px, var(--mobile-safe-right)) !important;
  }

  .premium-sticky-cta {
    position: relative !important;
    bottom: auto !important;
    display: grid !important;
    margin-bottom: calc(20px + var(--mobile-safe-bottom));
  }

  .premium-copy {
    justify-content: start !important;
  }

  .premium-copy h2 {
    font-size: clamp(42px, 15vw, 68px) !important;
  }

  .prestige-card {
    min-height: 340px !important;
  }

  .premium-table,
  table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .messenger-shell,
  .unified-messenger,
  .chat-layout {
    min-height: min(760px, calc(100dvh - 130px));
    max-height: calc(100dvh - 120px);
    overflow: hidden;
  }

  .message-thread,
  .messages-list,
  .chat-messages {
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 12px;
  }

  .chat-composer,
  .message-composer,
  .composer {
    position: sticky;
    bottom: 0;
    z-index: 8;
    padding-bottom: max(8px, var(--mobile-safe-bottom));
  }

  .media-tray,
  .action-sheet,
  .bottom-sheet {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    max-height: min(82dvh, 640px);
    overflow-y: auto;
    border-radius: 22px 22px 0 0 !important;
    padding-bottom: calc(16px + var(--mobile-safe-bottom)) !important;
    backdrop-filter: none !important;
  }

  .reels-shell,
  .reel-viewport {
    width: min(100vw, calc(100dvh * 9 / 16)) !important;
    max-width: 100vw !important;
    height: min(100dvh, calc(100vw * 16 / 9)) !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
  }

  .live-studio,
  .live-preview,
  .camera-overlay {
    min-height: 100dvh;
    padding-top: var(--mobile-safe-top);
    padding-bottom: var(--mobile-safe-bottom);
  }
}

@media (max-width: 480px) {
  :root {
    --mobile-touch: 46px;
    --mobile-gap: 10px;
  }

  .wrap,
  .container,
  .shell {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  .mobile-bottom-nav a,
  .bottom-nav a {
    font-size: 10px !important;
    letter-spacing: 0 !important;
  }

  .mobile-bottom-nav .nav-ico,
  .bottom-nav .nav-ico {
    font-size: 17px !important;
  }

  .pill,
  .premium-chip,
  .premium-badge {
    font-size: 12px !important;
    padding: 5px 8px !important;
  }

  .profile-cover {
    height: 164px !important;
  }

  .profile-avatar {
    width: 96px !important;
    height: 96px !important;
  }
}

@media (max-width: 414px) {
  .mobile-bottom-nav a,
  .bottom-nav a {
    grid-template-rows: 19px 13px !important;
    min-height: 48px !important;
  }

  .card,
  .glass-panel,
  .lux-card {
    padding: 12px !important;
  }
}

@media (max-width: 390px) {
  h1 {
    font-size: clamp(28px, 10vw, 40px) !important;
  }

  .mobile-bottom-nav a,
  .bottom-nav a {
    font-size: 9px !important;
  }
}

@media (max-width: 375px) {
  .button,
  button {
    padding-left: 9px !important;
    padding-right: 9px !important;
  }

  .mobile-bottom-nav {
    gap: 0 !important;
  }
}

@media (max-width: 320px) {
  .mobile-bottom-nav .nav-label,
  .bottom-nav .nav-label {
    display: none !important;
  }

  .mobile-bottom-nav a,
  .bottom-nav a {
    grid-template-rows: 1fr !important;
    min-height: 42px !important;
  }
}
