/* ============================================================
   LOBBIVO ULTIMATE MOBILE & RESPONSIVE DESIGN SYSTEM
   Адаптивность для смартфонов (iOS / Android), планшетов и ПК
   ============================================================ */

/* 1. БОЛЬШИЕ И СРЕДНИЕ ЭКРАНЫ (DESKTOP & LAPTOPS) */
@media (max-width: 1240px) {
  .games-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
  }
}

@media (max-width: 992px) {
  .games-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
  }
  
  .capsule-header {
    max-width: 100%;
  }

  .capsule-center {
    max-width: 200px;
  }

  .coin-packs-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* 2. ПЛАНШЕТЫ И СМАРТФОНЫ (TABLETS & MOBILE <= 768px) */
@media (max-width: 768px) {
  :root {
    --header-height: 48px;
  }

  /* Предотвращение авто-зума на iOS Safari при фокусе в поле ввода */
  input[type="text"],
  input[type="password"],
  input[type="number"],
  input[type="email"],
  textarea,
  select {
    font-size: 16px !important;
  }

  .app-wrapper {
    padding: 8px 10px 90px;
  }

  /* Парящая шапка-капсула */
  .capsule-header-container {
    top: 6px;
    margin-bottom: 14px;
    padding: 0 6px;
    width: 100%;
    box-sizing: border-box;
  }

  .capsule-header {
    width: 100%;
    max-width: 100%;
    height: 46px;
    padding: 4px 6px 4px 8px;
    gap: 6px;
    border-radius: 23px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    overflow: visible;
  }

  .capsule-brand {
    gap: 6px;
    flex-shrink: 0;
    min-width: 0;
  }

  .l-logo-badge {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    flex-shrink: 0;
  }

  .header-logo-l {
    font-size: 1.05rem;
  }

  .brand-title {
    font-size: 0.95rem;
    letter-spacing: 0.8px;
    white-space: nowrap;
  }

  .beta-badge {
    font-size: 0.45rem;
    padding: 1px 4px;
    margin-top: 1px;
  }

  /* На мобильных скрываем инпут поиска из капсулы, кнопка лупы доступна справа */
  .capsule-center {
    display: none;
  }

  .capsule-right {
    gap: 5px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }

  .search-toggle-btn {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
  }

  .search-toggle-btn svg {
    width: 14px;
    height: 14px;
  }

  .capsule-coin-btn {
    height: 32px;
    padding: 2px 7px 2px 4px;
    gap: 4px;
    border-radius: 16px;
    flex-shrink: 0;
  }

  .capsule-coin-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
  }

  .coin-l-letter {
    font-size: 0.78rem;
  }

  .capsule-coin-amount {
    font-size: 0.82rem;
    font-weight: 700;
  }

  .capsule-coin-currency {
    display: none;
  }

  /* Кнопка админки в шапке на мобильных */
  .capsule-admin-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
  }

  .capsule-admin-btn .capsule-admin-label {
    display: none;
  }

  .capsule-admin-icon {
    width: 16px;
    height: 16px;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .capsule-admin-icon svg {
    width: 16px;
    height: 16px;
  }

  .admin-complaints-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 14px;
    height: 14px;
    font-size: 0.55rem;
    padding: 0 3px;
  }

  .capsule-profile-wrapper {
    flex-shrink: 0;
    position: relative;
  }

  .capsule-profile-btn {
    height: 32px;
    padding: 2px 8px 2px 3px;
    gap: 5px;
    border-radius: 16px;
    flex-shrink: 0;
    position: relative;
    max-width: 120px;
    box-sizing: border-box;
  }

  .profile-avatar-thumb {
    width: 26px;
    height: 26px;
    font-size: 0.75rem;
    flex-shrink: 0;
  }

  #capsuleProfileLabel {
    font-size: 0.8rem;
    max-width: 60px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Выпадающее меню профиля на мобильных */
  .profile-dropdown-panel {
    right: 0;
    top: calc(100% + 8px);
    width: 260px;
    max-width: calc(100vw - 20px);
    border-radius: 20px;
    padding: 14px 12px;
  }

  /* Баннер режима гостя */
  .games-guest-banner {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 16px;
    margin-bottom: 14px;
  }

  .guest-banner-left {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .guest-banner-text {
    font-size: 0.82rem;
    line-height: 1.35;
  }

  /* Сетка постеров игр */
  .games-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .game-poster-card {
    height: 250px;
    border-radius: 16px;
  }

  .poster-art-wrapper {
    height: 175px;
  }

  .poster-info-wrapper {
    padding: 10px 8px;
  }

  .poster-title {
    font-size: 0.95rem;
    line-height: 1.15;
    margin-bottom: 6px;
  }

  .btn-find-party {
    font-size: 0.65rem;
    padding: 6px 12px;
    letter-spacing: 0.8px;
    border-radius: 10px;
  }

  /* Сетка тиммейтов / анкет */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 16px;
  }

  .page-title-wrapper h2 {
    font-size: 1.3rem;
  }

  .filter-bar {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .filter-bar .btn {
    flex: 1;
    justify-content: center;
    padding: 9px 12px;
    font-size: 0.85rem;
  }

  .players-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .player-card {
    padding: 14px;
    border-radius: 18px;
  }

  .player-top {
    gap: 12px;
  }

  .player-avatar {
    width: 46px;
    height: 46px;
    font-size: 1.15rem;
  }

  .player-name {
    font-size: 1.05rem;
  }

  .player-game {
    font-size: 0.82rem;
  }

  .card-actions {
    margin-top: 12px;
    gap: 8px;
  }

  .card-actions .btn {
    flex: 1;
    justify-content: center;
    padding: 8px 10px;
  }

  /* ============================================================
     МОБИЛЬНЫЙ ЧАТ 2.0 (NATIVE BOTTOM SHEET MESSENGER)
     ============================================================ */
  .chat-container {
    bottom: 0 !important;
    right: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 88vh !important;
    max-height: 88vh !important;
    border-radius: 24px 24px 0 0 !important;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.8) !important;
    transform: translateY(105%);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1) !important;
    border-bottom: none !important;
  }

  .chat-container.open {
    transform: translateY(0) !important;
  }

  .chat-header {
    padding: 12px 14px;
    border-radius: 24px 24px 0 0;
  }

  .chat-user .avatar {
    width: 32px;
    height: 32px;
    font-size: 0.95rem;
  }

  #chatUserName {
    font-size: 0.98rem;
  }

  .chat-close {
    width: 34px;
    height: 34px;
  }

  .chat-tab-bar {
    padding: 6px 10px;
  }

  .chat-tab-pill {
    padding: 8px 10px;
    font-size: 0.85rem;
  }

  .chat-input,
  .world-chat-input {
    padding: 10px 12px max(10px, env(safe-area-inset-bottom)) !important;
  }

  .chat-input input,
  .world-chat-input input {
    height: 42px;
    font-size: 16px !important;
    padding: 8px 12px;
  }

  .send-btn {
    width: 42px;
    height: 42px;
  }

  .btn-msg-reply {
    display: flex !important;
    position: static !important;
    transform: none !important;
    width: 22px;
    height: 22px;
    margin-left: auto;
    background: rgba(255, 255, 255, 0.08);
    opacity: 0.8;
  }

  .chat-reply-preview {
    padding: 6px 10px !important;
  }

  .reply-preview-text {
    max-width: 200px !important;
  }

  /* Плавающая кнопка чата */
  .chat-fab,
  .chat-fab-button {
    bottom: max(16px, env(safe-area-inset-bottom));
    right: 16px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    box-shadow: 0 8px 25px rgba(0, 212, 255, 0.4);
  }

  .chat-fab svg,
  .chat-fab-button svg {
    width: 22px;
    height: 22px;
  }

  /* Модалки на смартфонах */
  .modal-overlay {
    padding: 10px;
    align-items: flex-end;
  }

  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 90vh !important;
    border-radius: 24px 24px 14px 14px !important;
    padding: 22px 16px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .modal-close {
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
  }

  /* Модалка Lobbivo Coin Hub */
  .coin-modal-glass {
    padding: 20px 14px !important;
  }

  .coin-modal-hero {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
  }

  .coin-3d-visual {
    width: 60px;
    height: 60px;
  }

  .coin-3d-gold {
    width: 52px;
    height: 52px;
  }

  .coin-3d-l {
    font-size: 1.6rem;
  }

  .coin-modal-title {
    font-size: 1.4rem;
  }

  .coin-balance-badge {
    justify-content: center;
  }

  .coin-about-banner {
    padding: 10px 12px;
    gap: 10px;
  }

  .coin-about-text {
    font-size: 0.78rem;
    line-height: 1.35;
  }

  .coin-modal-tabs {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 4px;
    padding: 3px;
  }

  .coin-tab-btn {
    padding: 6px 4px;
    font-size: 0.76rem;
    gap: 4px;
    height: 36px;
  }

  .coin-tab-btn svg {
    width: 13px;
    height: 13px;
  }

  .coin-task-card {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px 12px;
  }

  .task-card-right {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 10px;
    width: 100%;
  }

  .coin-packs-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .coin-pack-card {
    padding: 14px 10px;
  }

  .pack-amount {
    font-size: 1.15rem;
  }

  .pack-price {
    font-size: 1.1rem;
    margin: 8px 0;
  }

  .btn-pack-buy {
    padding: 7px 10px;
    font-size: 0.8rem;
  }

  .converter-row {
    flex-direction: column;
    gap: 10px;
  }

  .converter-arrow {
    transform: rotate(90deg);
  }

  /* Профиль игрока и кастомизация */
  .profile-container {
    max-width: 100%;
  }

  .profile-hero-card {
    padding: 18px 14px;
    border-radius: 20px;
  }

  .profile-hero-top {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 14px;
  }

  .profile-hero-details {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .profile-name-row {
    justify-content: center;
  }

  .profile-tags-row {
    justify-content: center;
  }

  .profile-hero-coins-box {
    align-items: center;
    width: 100%;
    box-sizing: border-box;
  }

  .profile-nav-tabs {
    flex-direction: row;
    gap: 6px;
    padding: 4px;
  }

  .profile-tab-btn {
    padding: 8px 10px;
    font-size: 0.82rem;
    gap: 4px;
  }

  .profile-tab-btn svg {
    width: 14px;
    height: 14px;
  }

  .profile-overview-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .premium-showcase-content {
    flex-direction: column;
    text-align: center;
    align-items: center;
  }

  .custom-avatar-stage-card {
    flex-direction: column;
    text-align: center;
    padding: 20px 14px;
    gap: 14px;
  }

  .stage-frame-name {
    justify-content: center;
  }

  .custom-frames-grid,
  .custom-themes-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .edit-avatar-upload-row {
    flex-direction: column;
    text-align: center;
    align-items: center;
  }

  .edit-clean-footer-actions {
    flex-direction: column;
    gap: 8px;
  }

  .edit-clean-footer-actions .btn {
    width: 100%;
    justify-content: center;
  }

  /* Кастомные селекторы на мобильных */
  .game-picker-panel,
  .device-select-panel {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    max-height: 70vh !important;
    border-radius: 24px 24px 0 0 !important;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.8) !important;
    z-index: 1000 !important;
    padding: 18px 14px max(16px, env(safe-area-inset-bottom)) !important;
  }

  .game-picker-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    max-height: 46vh !important;
    gap: 8px !important;
  }

  .device-panel-grid {
    grid-template-columns: 1fr !important;
    max-height: 48vh !important;
    gap: 8px !important;
  }

  /* Welcome Landing Gateway */
  .welcome-hero-card {
    padding: 26px 14px 22px;
    border-radius: 22px;
  }

  .welcome-title-gradient {
    font-size: 2.1rem;
    letter-spacing: 1.5px;
  }

  .welcome-beta-badge {
    font-size: 0.5rem;
    padding: 1.5px 5px;
    margin-left: 4px;
  }

  .welcome-title-sub {
    font-size: 1.05rem;
  }

  .welcome-hero-desc {
    font-size: 0.9rem;
    margin-bottom: 20px;
  }

  .welcome-features-strip {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 20px;
  }

  .welcome-feature-card {
    padding: 10px 12px;
  }

  .welcome-actions-hub {
    flex-direction: column;
    width: 100%;
    gap: 9px;
    margin-bottom: 20px;
  }

  .welcome-btn {
    width: 100%;
    justify-content: center;
    padding: 12px 16px;
    font-size: 0.95rem;
  }

  .welcome-stats-row {
    flex-direction: column;
    gap: 12px;
  }

  .welcome-stat-divider {
    width: 50px;
    height: 1px;
  }

  /* Уведомления (Toast) */
  .notification {
    left: 10px;
    right: 10px;
    bottom: max(75px, env(safe-area-inset-bottom));
    max-width: none;
    border-radius: 16px;
    padding: 14px 16px;
  }
}

/* 3. КОМПАКТНЫЕ СМАРТФОНЫ (SMALL PHONES <= 480px) */
@media (max-width: 480px) {
  .app-wrapper {
    padding: 6px 8px 85px;
  }

  .games-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .game-poster-card {
    height: 235px;
    border-radius: 14px;
  }

  .poster-art-wrapper {
    height: 165px;
  }

  .poster-info-wrapper {
    padding: 8px 6px;
  }

  .poster-title {
    font-size: 0.88rem;
  }

  .btn-find-party {
    font-size: 0.6rem;
    padding: 5px 8px;
    letter-spacing: 0.5px;
  }

  .welcome-title-gradient {
    font-size: 1.85rem;
    letter-spacing: 1px;
  }

  .welcome-brand-emblem-wrap {
    width: 88px;
    height: 88px;
    margin-bottom: 14px;
  }

  .welcome-orbit-ring.ring-outer {
    width: 84px;
    height: 84px;
  }

  .welcome-orbit-ring.ring-inner {
    width: 66px;
    height: 66px;
  }

  .welcome-brand-badge {
    width: 52px;
    height: 52px;
    border-radius: 14px;
  }

  .welcome-badge-l {
    font-size: 1.8rem;
  }

  .system-loader-card {
    padding: 22px 18px;
    min-width: 220px;
  }

  .coin-packs-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .game-picker-grid {
    grid-template-columns: 1fr !important;
  }

  /* Шапка-капсула и кнопка профиля для iPhone и компактных смартфонов */
  .capsule-header {
    height: 44px;
    padding: 3px 6px;
    gap: 4px;
  }

  .capsule-brand {
    gap: 5px;
  }

  .beta-badge {
    display: none;
  }

  .capsule-right {
    gap: 4px;
  }

  .search-toggle-btn {
    width: 30px;
    height: 30px;
  }

  .capsule-coin-btn {
    height: 30px;
    padding: 2px 6px 2px 3px;
    gap: 3px;
  }

  .capsule-coin-icon {
    width: 20px;
    height: 20px;
  }

  .coin-l-letter {
    font-size: 0.72rem;
  }

  .capsule-coin-amount {
    font-size: 0.78rem;
  }

  .capsule-admin-btn {
    width: 30px;
    height: 30px;
    padding: 0;
  }

  .capsule-admin-icon svg {
    width: 15px;
    height: 15px;
  }

  /* На смартфонах кнопка профиля превращается в аккуратный круглый аватар */
  .capsule-profile-btn {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: 50%;
    justify-content: center;
  }

  #capsuleProfileLabel {
    display: none;
  }

  .profile-avatar-thumb {
    width: 26px;
    height: 26px;
  }

  .capsule-profile-btn .notif-dot {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 6px;
    margin: 0;
  }

  /* Адаптив админ-панели */
  .capsule-admin-btn .capsule-admin-label {
    display: none;
  }

  .admin-stats-bar {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .admin-nav-tabs {
    flex-direction: column;
    gap: 4px;
  }

  .ban-presets-grid,
  .mute-presets-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  .complaint-actions-row {
    flex-direction: column;
    align-items: stretch;
  }

  .complaint-actions-row button {
    width: 100%;
    justify-content: center;
  }

  /* Адаптив магазина Lobbivo на смартфонах */
  .premium-plans-grid {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }

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

  .shop-frames-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

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

  .shop-boost-card {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
  }

  .boost-card-actions {
    justify-content: space-between !important;
    width: 100% !important;
  }

  .btn-buy-boost {
    flex: 1 !important;
    text-align: center !important;
  }

  .vip-pinned-capsule {
    flex-wrap: wrap !important;
    gap: 8px !important;
    padding: 8px 10px !important;
  }

  .vip-pinned-left {
    width: 100% !important;
  }

  .vip-pinned-actions {
    width: 100% !important;
    justify-content: space-between !important;
  }

  .btn-vip-join {
    flex: 1 !important;
    justify-content: center !important;
  }
}