/* =========================================================
   ENOT — RESPONSIVE ENHANCEMENTS
   Мобильные · Планшеты · Десктоп · Landscape · Reduced-motion
   Подключать ПОСЛЕ style.css
   ========================================================= */

/* ========== ГЛОБАЛЬНЫЕ БАЗОВЫЕ УЛУЧШЕНИЯ ========== */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html, body {
  /* iOS: не «прыгает» при открытии модалки */
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Скрываем горизонтальный скролл из-за длинных слов */
.content { overflow-x: clip; }
.top-name, .guest-top-name, .card-title, .top-name a {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Скроллбар для мобильных — тонкий */
@media (pointer: coarse) {
  ::-webkit-scrollbar { width: 6px; height: 6px; }
}

/* ========== SAFE AREA (iPhone с «вырезом») ========== */
@media (max-width: 900px) {
  .sidebar {
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: calc(16px + var(--safe-bottom));
  }
  .topbar {
    padding-top: calc(12px + var(--safe-top));
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
  }
  .content {
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
  }
  .item-modal-box,
  .bt-modal-box,
  .custom-confirm-box,
  .modal-box {
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 32px) !important;
  }
}

/* ========== ТАЧ-ФРИЕНДЛИ (палец 44px) ========== */
@media (pointer: coarse) {
  .btn, .nav-item, .quick, .shop-tab, .dx2-tab,
  .product-btn, .qb, .dx2-act, .action-btn,
  .clan-quick-btn, .bt-filter, .upd-filter, .ach-filter {
    min-height: 44px;
  }
  .qb { padding: 12px 18px; }
  .product-btn { min-height: 44px; height: auto; padding: 12px; }
  .dx2-act { padding: 16px 8px; }

  /* Формы — увеличиваем поля ввода */
  input[type=text], input[type=number], input[type=password],
  input[type=email], input[type=search], select, textarea {
    font-size: 16px; /* iOS не зумит */
    min-height: 44px;
  }

  /* Убираем hover-эффекты, которые «залипают» на таче */
  .product-card:hover { transform: none; }
  .market-item:hover { background: var(--surface); }
  .card:hover { border-color: var(--border); }
}

/* ========== ПЛАНШЕТ (768–1024px) ========== */
@media (min-width: 861px) and (max-width: 1024px) {
  :root { --sidebar-w: 220px; }

  .topbar { padding: 12px 20px; }
  .content { padding: 20px; }

  .dash-grid { grid-template-columns: 1fr !important; }
  .dash-grid .scene { max-width: 360px; margin: 0 auto; }

  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }

  .market-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
  .biz-grid    { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .shop-grid   { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .car-grid    { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }

  .guest-hero-title { font-size: 32px; }
  .guest-stats { grid-template-columns: repeat(3, 1fr); }

  /* Принудительно одна колонка там, где inline-grid 1fr 340px */
  .biz-layout,
  .casino-layout,
  .clan-layout { grid-template-columns: 1fr !important; }
}

/* ========== МОБИЛЬНЫЙ (<860px) — усиление ========== */
@media (max-width: 860px) {

  /* Топбар — компактнее, но не исчезает */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background: rgba(7, 13, 24, 0.85);
    padding: 10px 14px;
  }

  /* Сайдбар — полная ширина, скролл внутри */
  .sidebar {
    width: min(88vw, 300px);
    box-shadow: 20px 0 60px -20px rgba(0,0,0,.8);
  }

  /* Overlay — плотнее и с blur */
  .overlay.show {
    display: block;
    background: rgba(4, 8, 15, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  /* Карточки — чуть компактнее */
  .card { padding: 14px; }
  .card-head h2 { font-size: 11px; }

  /* Каждая секция на всю ширину */
  .dash-grid { grid-template-columns: 1fr; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }

  /* Про товары: делаем 2 колонки на широких, 1 — на узких */
  .market-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px; }
  .biz-grid    { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px; }
  .shop-grid   { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px; }
  .car-grid    { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px; }

  .product-card { padding: 12px; }
  .product-title { font-size: 13px; }
  .product-price { font-size: 15px; }
  .product-image { margin-bottom: 10px; padding: 8px; }
  .product-type { font-size: 9px; margin-bottom: 8px; }

  /* Inline-фиксы для page_shop / page_cars */
  .market-grid[style*="minmax(230px"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }

  /* Модалки */
  .item-modal { padding: 12px; }
  .item-modal-box { max-width: 100%; }
  .item-modal-img { height: 220px; padding: 16px; }
  .item-modal-body { padding: 20px; }
  .item-modal-title { font-size: 20px; }
  .item-modal-price { font-size: 22px; }

  /* Казино — табы скроллятся */
  .casino-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    margin-left: -14px;
    margin-right: -14px;
    padding-left: 14px;
    padding-right: 14px;
  }
  .casino-tabs::-webkit-scrollbar { display: none; }
  .casino-tab { flex: 0 0 auto; min-width: 90px; }

  /* Слоты — не вылезают */
  .slots-display { gap: 10px; padding: 14px; }
  .slot-reel { width: 82px; height: 100px; }
  .slot-reel .reel-item { height: 100px; font-size: 48px; }

  /* Бизнесы — карточки-ряды */
  .biz-image-box { flex: 0 0 100% !important; }
  .biz-image-img { height: 160px !important; }

  /* Клан — сетка в одну колонку */
  .clan-layout { grid-template-columns: 1fr; }
  .clan-hero-metrics { grid-template-columns: repeat(2, 1fr); }
  .clan-podium { grid-template-columns: 1fr; }
  .clan-podium-item.rank-1 { order: -1; }
  .clan-member-stats { gap: 6px; }
  .clan-member-stat.share { display: none; }

  /* Магазин — вкладки */
  .shop-tabs {
    margin: 0 -14px 16px;
    padding-left: 14px;
    padding-right: 14px;
    -webkit-overflow-scrolling: touch;
  }
  .shop-tab { padding: 8px 12px; font-size: 12px; }
  .shop-tab-count { display: none; }

  /* Achievements */
  .ach-hero-inner { flex-direction: column; align-items: flex-start; }
  .ach-hero-stats { width: 100%; justify-content: space-between; }
  .ach-filters { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .ach-filters::-webkit-scrollbar { display: none; }
  .ach-filter { flex: 0 0 auto; }

  /* Bugs */
  .bt-hero-inner { flex-direction: column; align-items: flex-start; gap: 16px; }
  .bt-hero-stats { width: 100%; justify-content: space-between; }
  .bt-detail-head { padding: 18px; }
  .bt-title { font-size: 20px; }
  .bt-item-stats { display: none; }

  /* Updates */
  .upd-hero { padding: 22px 20px; }
  .upd-hero-title { font-size: 22px; }
  .upd-feed { padding-left: 32px; }
  .upd-feed::before { left: 15px; }
  .upd-dot { left: -32px; width: 32px; height: 32px; font-size: 14px; }
  .upd-filters { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 12px; scrollbar-width: none; }
  .upd-filters::-webkit-scrollbar { display: none; }
  .upd-filter { flex: 0 0 auto; font-size: 11px; padding: 6px 11px; }

  /* Статистика — таблицы в карточки */
  .stats-two { grid-template-columns: 1fr !important; }

  /* Top — компактные строки */
  .top-row, .guest-top-row {
    grid-template-columns: 32px 1fr auto;
    gap: 8px;
    padding: 10px 8px;
  }
  .top-lvl, .guest-top-lvl { display: none; }

  /* Формы */
  .form-row, .filter-row { flex-direction: column; }
  .form-row > *, .filter-row > * { width: 100%; }

  /* Футер */
  .footer { gap: 6px; }
  .footer-muted { display: none; }
}

/* ========== УЗКИЕ ТЕЛЕФОНЫ (≤ 400px) ========== */
@media (max-width: 400px) {
  .market-grid,
  .shop-grid,
  .car-grid,
  .biz-grid,
  .market-grid[style*="minmax(230px"] {
    grid-template-columns: 1fr !important;
  }

  .product-card { padding: 14px; }
  .product-title { font-size: 14px; }
  .product-price { font-size: 16px; }

  .guest-hero-title { font-size: 24px; }
  .guest-hero-raccoon { font-size: 56px; }
  .guest-hero { padding: 32px 14px 26px; }

  .stat .v { font-size: 15px; }
  .clan-hero-metrics { grid-template-columns: 1fr 1fr; }
  .clan-name-big { font-size: 22px; }

  /* Слоты на самых узких */
  .slot-reel { width: 72px; height: 92px; }
  .slot-reel .reel-item { height: 92px; font-size: 42px; }

  .dx2-hero-in { flex-direction: column; align-items: flex-start; }
  .dx2-wealth { width: 100%; text-align: left; }
}

/* ========== LANDSCAPE (телефон лёжа) ========== */
@media (max-height: 500px) and (orientation: landscape) {
  .scene { max-height: 260px; aspect-ratio: auto; }
  .item-modal-box { max-height: 95dvh; }
  .item-modal-img { height: 180px; }
  .guest-hero { padding: 20px 24px; }
  .guest-hero-raccoon { font-size: 48px; margin-bottom: 10px; }
  .guest-hero-title { font-size: 24px; }
  .sidebar { padding-top: 12px; padding-bottom: 12px; }
  .casino-hero { padding: 20px; }
  .hero-text h1 { font-size: 24px; }
}

/* ========== REDUCED MOTION (доступность) ========== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .guest-hero-raccoon,
  .person-wrap,
  .eyelid,
  .upd-hero-icon,
  .dx2-avatar,
  .bt-hero-icon,
  .logo-icon,
  .logo .logo-icon {
    animation: none !important;
  }
}

/* ========== DESKTOP-ONLY: чуть больше воздуха ========== */
@media (min-width: 1440px) {
  .content { padding: 32px 40px; max-width: 1480px; }
  .dash-grid { grid-template-columns: 400px minmax(0, 1fr); }
  .market-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
}

/* ========== СКРЫТИЕ ГОРИЗОНТАЛЬНОГО СКРОЛЛА В МОДАЛКАХ ========== */
.item-modal-box,
.bt-modal-box,
.modal-box,
.custom-confirm-box {
  overflow-x: hidden;
}

/* ========== САЙДБАР: ВИЗУАЛЬНЫЙ КЛОЗ ПО КЛИКУ (мобилка) ========== */
@media (max-width: 860px) {
  .sidebar .nav { padding-bottom: 20px; }
  .sidebar .sidebar-user,
  .sidebar .sidebar-guest { margin-bottom: 12px; }
}

/* ========== READABILITY: МИН. РАЗМЕР ШРИФТА ========== */
@media (max-width: 360px) {
  body { font-size: 13px; }
  .muted, .small { font-size: 11px; }
  .stat .k, .guest-stat .gs-label { font-size: 9.5px; }
}

/* ========== ТАЧ-ДЛЯ ЧЕКБОКСОВ КАЗИНО ========== */
@media (pointer: coarse) {
  .choice-btn { min-height: 90px; padding: 18px 12px; }
  .cb-icon { font-size: 36px; }
  .cb-label { font-size: 14px; }
  .cb-mult { font-size: 12px; }
}

/* ========== УЛУЧШЕНИЕ ЧИТАЕМОСТИ ТАБЛИЦ НА МОБИЛЕ ========== */
@media (max-width: 640px) {
  .prizes-table td { padding: 8px 0; font-size: 12px; }
  .prizes-table td.chance { font-size: 12px; }
  .kv { font-size: 12px; padding: 8px 0; }
  .kv-k { font-size: 11.5px; }
}