/* =========================================
   MOBILE OVERRIDES
   ========================================= */
@media (max-width: 768px) {
  html body {
    --side-btn-size: var(--size-touch);
    --side-btn-gap: var(--space-xs);
    --mobile-top-controls-height: calc(80px + env(safe-area-inset-top, 0px));
  }

  html body.mobile-surface-open {
    overflow: hidden !important;
    overscroll-behavior: none !important;
  }

  .desktop-only { display: none !important; }
  .mobile-only { display: inline-flex !important; }

  .magic-btn,
  .cat-btn,
  .icon-btn,
  .context-chip,
  .mobile-menu-item {
    -webkit-tap-highlight-color: rgba(123, 140, 255, 0.18);
  }

  html body .main .card-frame {
    max-width: calc(100vw - var(--space-md) * 2) !important;
  }
  html body .main .context-actions {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  html body .main #waifu,
  html body .main #waifu-buffer {
    max-width: 100% !important;
    max-height: 62vh !important;
    object-fit: contain !important;
    display: block !important;
  }

  html body .gallery-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    grid-auto-flow: row !important;
  }

  .gallery-item-actions {
    opacity: 1;
    left: 50%;
    right: auto;
    top: auto;
    bottom: 8px;
    transform: translateX(-50%);
    pointer-events: auto;
  }

  html body #sidebar {
    z-index: 3000 !important;
    width: 88vw !important;
    max-width: 360px !important;
    height: 100dvh !important;
    padding-top: calc(8px + env(safe-area-inset-top, 0px)) !important;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1) !important;
    box-shadow: 20px 0 60px rgba(0, 0, 0, 0.6) !important;
  }

  html body #sidebar::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.45);
    z-index: -1;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.32s ease;
  }

  html body #sidebar.open::before {
    opacity: 1;
  }

  .gallery-action-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(10, 14, 28, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.14);
  }

  .gallery-action-btn svg {
    width: 16px;
    height: 16px;
  }

  html body .gallery-item-wrapper {
    width: 100% !important;
    height: auto !important;
    padding: 0 !important;
  }

  html body .gallery-item-media {
    height: var(--gallery-tile-height) !important;
    min-height: 160px !important;
    border-radius: 16px !important;
  }

  /* 0. Отключаем flex-раскладку top-controls на мобилке — кнопки позиционируем отдельно */
  .top-controls {
    display: block !important;
    position: static !important;
    width: 0 !important;
    height: 0 !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* All standalone buttons hidden on mobile — everything is in the hamburger */
  html body .categories-wrapper {
    position: static !important;
    width: 0 !important;
    height: 0 !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  html body button.magic-btn.cat-toggle {
    display: none !important;
  }

  html body button#open-gallery-btn.magic-btn.small-btn,
  html body #open-gallery-btn {
    display: none !important;
  }

  html body .mobile-top-rail {
    position: fixed !important;
    top: calc(8px + env(safe-area-inset-top, 0px)) !important;
    left: calc(8px + env(safe-area-inset-left, 0px)) !important;
    right: calc(8px + env(safe-area-inset-right, 0px)) !important;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 6px !important;
    padding: 6px !important;
    border-radius: 20px !important;
    background:
      linear-gradient(180deg, rgba(9, 13, 25, 0.94) 0%, rgba(12, 18, 33, 0.92) 100%) !important;
    border: 1px solid rgba(138, 160, 255, 0.14) !important;
    box-shadow:
      0 12px 36px rgba(0, 0, 0, 0.42),
      0 0 0 1px rgba(123, 140, 255, 0.06) inset !important;
    backdrop-filter: blur(18px) !important;
    -webkit-backdrop-filter: blur(18px) !important;
    z-index: 2001 !important;
    isolation: isolate !important;
  }

  html body .mobile-top-rail .mobile-menu-wrap {
    position: relative !important;
    top: auto !important;
    right: auto !important;
    left: auto !important;
    bottom: auto !important;
    display: block !important;
    width: 100% !important;
    z-index: auto !important;
  }

  html body .mobile-explore-wrap {
    position: relative !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  html body .mobile-top-rail-btn {
    width: 100% !important;
    min-width: 0 !important;
    height: 50px !important;
    min-height: 50px !important;
    padding: 0 10px !important;
    gap: 8px !important;
    border-radius: 14px !important;
    justify-content: flex-start !important;
    overflow: hidden !important;
  }

  html body .mobile-top-rail-icon {
    width: 30px !important;
    height: 30px !important;
    min-width: 30px !important;
    min-height: 30px !important;
    border-radius: 10px !important;
  }

  html body .mobile-top-rail-icon svg {
    width: 16px !important;
    height: 16px !important;
  }

  html body .mobile-top-rail-copy {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow: hidden !important;
    align-items: flex-start !important;
    justify-content: center !important;
    padding: 1px 0 !important;
  }

  html body .mobile-top-rail-label {
    display: block !important;
    min-width: 0 !important;
    max-width: 100% !important;
    font-size: 12.5px !important;
    line-height: 1.2 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }

  html body .mobile-top-rail-hint {
    font-size: 10.5px !important;
    line-height: 1.3 !important;
  }

  html body .mobile-menu-dropdown {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    width: min(92vw, 340px) !important;
    min-width: min(90vw, 280px) !important;
    max-width: min(92vw, 340px) !important;
    max-height: calc(
      100dvh - var(--mobile-top-controls-height, calc(80px + env(safe-area-inset-top, 0px)))
      - env(safe-area-inset-bottom, 0px)
      - 12px
    ) !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
    padding: 8px !important;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
    background: var(--panel-bg-mobile) !important;
    border: 1.5px solid var(--panel-border-accent) !important;
    border-radius: 20px !important;
    box-shadow:
      0 16px 44px rgba(0, 0, 0, 0.52),
      0 0 0 1px rgba(123, 140, 255, 0.08) !important;
    z-index: 5001 !important;
    transform: translate(-50%, calc(-50% - 10px)) !important;
    contain: layout style paint !important;
    will-change: transform !important;
    backface-visibility: hidden !important;
  }

  html body .mobile-menu-dropdown.show {
    transform: translate(-50%, -50%) !important;
  }

  html body .search-suggestions {
    max-height: min(42dvh, 320px) !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
  }

  html body .mobile-menu-dropdown,
  html body .cat-dropdown,
  html body .search-panel,
  html body .gallery-content,
  html body .auth-panel {
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y pinch-zoom !important;
  }

  html body .mobile-menu-panel-head {
    padding: 2px 2px 10px !important;
  }

  html body .mobile-menu-title {
    font-size: 13px !important;
  }

  html body .mobile-menu-section + .mobile-menu-section {
    margin-top: 8px !important;
    padding-top: 8px !important;
  }

  html body .mobile-menu-item {
    min-height: 52px !important;
    padding: 8px 10px !important;
    border-radius: 14px !important;
    column-gap: 10px !important;
    font-size: 13.5px !important;
  }

  html body .mobile-menu-item-icon {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    border-radius: 12px !important;
  }

  html body .mobile-menu-item-icon svg {
    width: 16px !important;
    height: 16px !important;
  }

  html body .mobile-menu-item-label {
    font-size: 13.5px !important;
  }

  html body .mobile-menu-item-description {
    font-size: 10.5px !important;
  }

  html body .mobile-menu-item-meta {
    min-height: 24px !important;
    padding: 0 8px !important;
    font-size: 10px !important;
  }

  /* History button hidden on mobile — available in hamburger */
  html body button#toggleHistory {
    display: none !important;
  }

  /* 5. НИЖНЯЯ ПАНЕЛЬ (Лайк, Новое фото, Скачать) */
  html body .main .card-frame .card-inner .button-wrapper,
  html body .button-wrapper {
    position: fixed !important;
    bottom: calc(var(--space-lg) + env(safe-area-inset-bottom, 0px)) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 100% !important;
    max-width: min(400px, calc(100vw - 24px)) !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    gap: var(--space-sm) !important;
    z-index: 2000 !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    padding: 0 var(--space-sm) !important;
  }

  /* Боковые кнопки снизу (Лайк и Скачать) */
  html body .main .button-wrapper button.magic-btn.small-btn,
  html body .button-wrapper button.magic-btn.small-btn {
    width: var(--size-touch) !important;
    height: var(--size-touch) !important;
    min-width: var(--size-touch) !important;
    flex-shrink: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* Центральная кнопка New Image */
  html body .main .button-wrapper button.magic-btn.main-btn,
  html body .button-wrapper button.magic-btn.main-btn {
    height: var(--size-touch) !important;
    min-height: var(--size-touch) !important;
    padding: 0 var(--space-lg) !important;
    margin: 0 !important;
    flex: 1 1 auto !important;
  }

  html body .context-actions {
    width: min(94vw, 420px) !important;
    padding: 0 10px !important;
    box-sizing: border-box !important;
    gap: 6px !important;
    margin-bottom: 6px !important;
  }

  html body .context-chip {
    flex: 1 1 calc(50% - 6px) !important;
    min-height: 38px !important;
    font-size: 11px !important;
    padding: 6px 12px !important;
  }

  html body .image-feedback {
    left: 12px !important;
    right: 12px !important;
    bottom: 12px !important;
    padding: 10px !important;
  }

  /* Унифицируем размер всех иконок в маленьких кнопках */
  html body button.magic-btn.small-btn svg {
    width: 20px !important;
    height: 20px !important;
  }

  /* Скрываем кнопку фуллскрина на телефоне (она там не нужна) */
  html body button#expand-btn.magic-btn.small-btn {
    display: none !important;
  }

  /* 6. На мобилке радио скрыто */
  .music-player {
    display: none !important;
  }

  .music-controls {
    display: none !important;
  }

  /* Единая высота всех кнопок на мобилке */
  html body button.magic-btn,
  html body .magic-btn {
    height: var(--size-touch) !important;
    min-height: var(--size-touch) !important;
  }

  /* ===== ПОЛНОСТЬЮ НОВЫЙ ДИЗАЙН КАТЕГОРИЙ ДЛЯ МОБИЛОК ===== */
  html body .cat-dropdown {
    position: fixed !important;
    top: calc(50% + 10px) !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    width: min(92vw, 380px) !important;
    max-width: min(92vw, 380px) !important;
    max-height: min(78vh, 620px) !important;
    padding: var(--space-md) !important;
    gap: var(--space-sm) !important;
    background:
      linear-gradient(180deg, rgba(10, 14, 24, 0.985) 0%, rgba(14, 18, 32, 0.975) 100%) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border: 2px solid rgba(126, 151, 255, 0.3) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--panel-shadow-overlay-strong) !important;
    overflow-y: auto !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
    z-index: 5000 !important;
    transform: translate(-50%, calc(-50% - 10px)) !important;
  }

  html body .cat-dropdown.show {
    transform: translate(-50%, -50%) !important;
    box-shadow:
      0 30px 80px rgba(0, 0, 0, 0.84),
      0 0 0 100vmax rgba(3, 5, 12, 0.28) !important;
  }

  html body .cat-dropdown>div:first-child {
    position: sticky !important;
    top: calc(var(--space-md) * -1) !important;
    z-index: 3 !important;
    margin: calc(var(--space-md) * -1) calc(var(--space-md) * -1) 4px calc(var(--space-md) * -1) !important;
    padding: var(--space-md) !important;
    background: linear-gradient(180deg, rgba(17, 21, 38, 0.98) 0%, rgba(17, 21, 38, 0.94) 100%) !important;
    border-bottom: 1px solid var(--panel-border-accent-soft) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
  }

  html body .cat-dropdown>div:first-child input {
    min-height: var(--size-touch) !important;
    padding: 0 var(--space-md) !important;
    border: 1px solid var(--panel-border-faint) !important;
    border-radius: var(--radius-sm) !important;
    font-size: 16px !important;
    background: var(--panel-bg-input) !important;
    box-sizing: border-box !important;
  }

  html body .cat-dropdown>div:first-child button {
    min-width: var(--size-touch) !important;
    min-height: var(--size-touch) !important;
    border-radius: var(--radius-sm) !important;
  }

  html body .cat-dropdown>div:first-child>div:last-child {
    margin-top: 10px !important;
    max-height: min(32vh, 220px) !important;
    border-radius: var(--radius-sm) !important;
    background: rgba(20, 24, 42, 0.95) !important;
  }

  /* Обертка каждой отдельной группы категорий */
  html body .cat-dropdown>div {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    width: 100% !important;
    position: static !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
    margin: 0 !important;
    max-width: none !important;
    max-height: none !important;
    height: auto !important;
    background: var(--panel-bg-mobile-section) !important;
    padding: 12px !important;
    border-radius: var(--radius-md) !important;
    border: 1px solid var(--panel-border-subtle) !important;
    box-shadow: none !important;
    box-sizing: border-box !important;
  }

  /* Заголовки групп (названия категорий) */
  html body .cat-dropdown>div>div:first-child {
    min-height: 38px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    font-size: 11px !important;
    font-weight: 800 !important;
    color: var(--color-accent-blue) !important;
    text-transform: uppercase !important;
    letter-spacing: 1.2px !important;
    padding: 0 2px 8px 2px !important;
    margin: 0 !important;
    text-align: left !important;
    border-bottom: 1px solid var(--panel-border-accent-faint) !important;
    margin-bottom: 2px !important;
  }

  /* Сами кнопки подкатегорий */
  html body .cat-btn {
    width: 100% !important;
    font-size: 12.5px !important;
    font-weight: 600 !important;
    padding: 9px 10px !important;
    margin: 0 !important;
    min-height: 38px !important;
    text-align: left !important;
    background: var(--panel-bg-mobile-item) !important;
    /* Плотный цвет самой кнопки */
    border: 1px solid var(--panel-border-faint) !important;
    border-radius: var(--radius-sm) !important;
    color: var(--color-white) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
  }

  /* Эффект при нажатии на категорию */
  html body .cat-btn:active {
    background: var(--color-accent-blue) !important;
    color: var(--color-white) !important;
    border-color: var(--color-accent-blue) !important;
    transform: scale(0.98) !important;
  }

  /* Убираем текст, оставляем символ через ::before */
  html body .cat-toggle .cat-text {
    display: none !important;
  }

  html body .cat-toggle::before {
    content: "❖" !important;
    font-size: 24px !important;
    font-weight: normal !important;
    color: var(--color-white) !important;
    line-height: 1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
}

  @media (max-width: 430px) {
  html body {
    --mobile-top-controls-height: calc(74px + env(safe-area-inset-top, 0px));
  }

  html body .mobile-top-rail {
    gap: 5px !important;
    padding: 5px !important;
    border-radius: 16px !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  html body .mobile-top-rail-btn {
    height: 46px !important;
    min-height: 46px !important;
    padding: 0 8px !important;
    gap: 6px !important;
    border-radius: 12px !important;
  }

  html body .mobile-top-rail-icon {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    border-radius: 9px !important;
  }

  html body .mobile-top-rail-icon svg {
    width: 15px !important;
    height: 15px !important;
  }

  html body .mobile-top-rail-label {
    font-size: 11.5px !important;
  }

  html body .mobile-top-rail-hint {
    display: none !important;
  }

  html body .mobile-top-rail-copy {
    gap: 0 !important;
    min-width: 0 !important;
  }
}

@media (max-width: 560px) {
  html body .mobile-menu-dropdown {
    width: min(94vw, 340px) !important;
    min-width: min(94vw, 280px) !important;
    max-width: min(94vw, 340px) !important;
    border-radius: 18px !important;
  }

  html body .search-header {
    gap: 8px !important;
  }

  html body .search-input-wrap {
    min-width: 0 !important;
  }

  html body .search-results-grid {
    columns: 2 118px !important;
    column-gap: 8px !important;
  }

  html body .search-card-meta {
    padding: 6px 8px 8px !important;
  }

  html body .search-card-note {
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    white-space: normal !important;
  }
}

@media (max-width: 768px) {
  html body .auth-modal {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  html body .auth-panel {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 100dvh !important;
    max-height: 100dvh !important;
    margin-top: auto !important;
    padding:
      calc(16px + env(safe-area-inset-top, 0px))
      14px
      calc(18px + env(safe-area-inset-bottom, 0px))
      14px !important;
    border-radius: 24px 24px 0 0 !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
  }

  html body .auth-close-btn {
    top: calc(12px + env(safe-area-inset-top, 0px)) !important;
    right: 14px !important;
    width: 40px !important;
    height: 40px !important;
  }

  html body .auth-panel-head {
    padding: 0 48px 0 0 !important;
    text-align: left !important;
  }

  html body .auth-vault-panel {
    padding: 12px !important;
  }

  html body .auth-liked-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  html body .auth-account-actions {
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
  }

  html body .gallery-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  html body .gallery-content {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    border-radius: 24px 24px 0 0 !important;
    padding:
      calc(12px + env(safe-area-inset-top, 0px))
      10px
      calc(14px + env(safe-area-inset-bottom, 0px))
      10px !important;
    box-shadow:
      0 -8px 32px rgba(0, 0, 0, 0.4) !important;
  }

  html body .gallery-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 3 !important;
    margin: calc(-12px - env(safe-area-inset-top, 0px)) -10px 10px -10px !important;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 12px 10px 12px !important;
    background: linear-gradient(180deg, rgba(12, 17, 34, 0.98), rgba(12, 17, 34, 0.92)) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  html body .gallery-header h2 {
    font-size: clamp(18px, 5vw, 24px) !important;
  }

  html body #close-gallery-btn {
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
  }

  html body .gallery-grid {
    gap: 8px !important;
    padding-right: 0 !important;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
  }

  html body .search-panel {
    width: 100vw !important;
    max-width: 100vw !important;
    min-height: 100dvh !important;
    max-height: 100dvh !important;
    margin-top: 0 !important;
    border-radius: 24px 24px 0 0 !important;
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
  }

  html body .search-header {
    position: sticky !important;
    top: 0 !important;
    z-index: 4 !important;
    padding:
      calc(10px + env(safe-area-inset-top, 0px))
      10px
      10px
      10px !important;
    background: linear-gradient(180deg, rgba(12, 17, 34, 0.98), rgba(12, 17, 34, 0.94)) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  html body .search-input {
    min-height: 44px !important;
    padding: 10px 12px 10px 38px !important;
    font-size: 16px !important;
    border-radius: 14px !important;
  }

  html body .search-close-btn {
    width: 40px !important;
    height: 40px !important;
    font-size: 22px !important;
  }

  html body .search-status {
    padding: 6px 12px !important;
    font-size: 11px !important;
  }

  html body .search-body {
    padding: 8px 10px calc(16px + env(safe-area-inset-bottom, 0px)) !important;
  }

  html body .search-results-grid {
    columns: 2 130px !important;
    column-gap: 6px !important;
  }

  html body .search-card {
    margin-bottom: 6px !important;
    border-radius: 14px !important;
  }
}

@media (max-width: 768px) {
  .lightbox-content {
    padding: calc(6px + env(safe-area-inset-top, 0px)) 4px calc(6px + env(safe-area-inset-bottom, 0px)) 4px !important;
  }

  .lightbox-overlay {
    background: rgba(3, 5, 14, 0.97) !important;
  }

  .lightbox-overlay .close-btn {
    top: calc(10px + env(safe-area-inset-top, 0px)) !important;
    right: calc(10px + env(safe-area-inset-right, 0px)) !important;
    width: 44px;
    height: 44px;
    font-size: 24px;
    background: rgba(15, 20, 40, 0.7) !important;
    border-color: rgba(255, 255, 255, 0.12) !important;
  }

  .lightbox-overlay .nav-btn {
    top: auto !important;
    bottom: calc(28px + env(safe-area-inset-bottom, 0px)) !important;
    transform: none !important;
    width: 54px;
    height: 54px;
    font-size: 22px;
    background: rgba(15, 20, 40, 0.72) !important;
    border-color: rgba(255, 255, 255, 0.14) !important;
    border-radius: 16px !important;
  }

  .lightbox-overlay .nav-btn:active {
    transform: scale(0.92) !important;
    transition: transform 0.06s ease-out;
  }

  .lightbox-overlay .left-btn {
    left: calc(16px + env(safe-area-inset-left, 0px)) !important;
  }

  .lightbox-overlay .right-btn {
    right: calc(16px + env(safe-area-inset-right, 0px)) !important;
  }

  #lightbox-img {
    border-radius: 4px !important;
  }

  .lightbox-overlay.is-dragging #lightbox-img {
    transition: none !important;
  }
}

@media (max-width: 460px) {
  html body .auth-panel {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  html body .gallery-content {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  html body .gallery-header {
    margin-left: -10px !important;
    margin-right: -10px !important;
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  html body .search-header {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  html body .search-body {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
}

/* =========================================
   HISTORY SIDEBAR — MOBILE TOUCH TARGETS
   ========================================= */
@media (max-width: 768px) {
  html body .history-item-wrapper .open-original-btn {
    opacity: 0.85;
    transform: translateY(0);
    width: 36px;
    height: 36px;
    bottom: 6px;
    right: 6px;
    backdrop-filter: none;
    background: rgba(10, 14, 28, 0.78);
  }

  html body .history-item-wrapper .open-original-btn:active {
    transform: scale(0.88);
    background: rgba(123, 140, 255, 0.4);
    transition: transform 0.06s ease-out, background 0.06s ease-out;
  }

  html body .history-item-wrapper:active {
    transform: scale(0.96);
    transition: transform 0.08s ease-out;
  }

  html body .empty-history {
    font-size: 14px;
    padding: 24px 16px;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.45);
  }
}

/* =========================================
   CATEGORY DROPDOWN — MOBILE POLISH
   ========================================= */
@media (max-width: 768px) {
  html body .cat-dropdown {
    max-height: min(78dvh, 620px) !important;
  }

  html body .cat-btn {
    min-height: 40px !important;
    padding: 8px 12px !important;
    font-size: 12.5px !important;
  }

  html body .cat-btn:hover {
    transform: none !important;
  }

  html body .cat-btn:active {
    transform: scale(0.96) !important;
    background: rgba(123, 140, 255, 0.18) !important;
    transition: transform 0.06s ease-out, background 0.06s ease-out;
  }
}

/* =========================================
   PRELOADER — MOBILE SIZING
   ========================================= */
@media (max-width: 768px) {
  #preloader {
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  }

  .preloader-brand {
    letter-spacing: 0.18em;
    padding: 14px 16px;
  }
}

@media (max-width: 390px) {
  .preloader-brand {
    letter-spacing: 0.12em;
    font-size: clamp(28px, 7.5vw, 48px);
  }
}

/* =========================================
   EMPTY STATES — MOBILE COMPACT
   ========================================= */
@media (max-width: 768px) {
  html body .gallery-empty-state {
    min-height: 180px;
    padding: 20px 16px;
    border-radius: 16px;
  }

  html body .gallery-empty-state h3 {
    font-size: 16px;
  }

  html body .gallery-empty-state p {
    font-size: 13px;
  }
}

/* =========================================
   MOBILE KEYBOARD & VISUAL VIEWPORT
   ========================================= */
@media (max-width: 768px) {
  html body .search-panel {
    max-height: 100dvh !important;
    max-height: -webkit-fill-available !important;
  }

  html body .search-body {
    flex: 1 1 0 !important;
    min-height: 0 !important;
  }

  html body .auth-panel {
    overflow-y: auto !important;
    max-height: 100dvh !important;
    max-height: -webkit-fill-available !important;
  }
}

/* =========================================
   TOUCH UX — MOBILE PRESS STATES & FEEDBACK
   ========================================= */
@media (max-width: 768px) {
  .gallery-item-wrapper .gallery-item-actions {
    opacity: 1;
    transform: translate(-50%, 0);
    pointer-events: auto;
  }

  .gallery-item-wrapper:hover .gallery-item-media,
  .gallery-item-wrapper:focus-within .gallery-item-media {
    transform: none;
    box-shadow: 0 18px 40px rgba(5, 10, 24, 0.28);
  }

  .gallery-item-media:active {
    transform: scale(0.97);
    transition: transform 0.08s ease-out;
  }

  .gallery-action-btn:active {
    transform: scale(0.92);
    transition: transform 0.06s ease-out;
  }

  .mobile-menu-item:active {
    transform: scale(0.98);
    background: rgba(123, 140, 255, 0.14) !important;
    transition: transform 0.06s ease-out, background 0.06s ease-out;
  }

  .mobile-top-rail-btn:active {
    transform: scale(0.96);
    transition: transform 0.06s ease-out;
  }

  .context-chip:active {
    transform: scale(0.96);
    transition: transform 0.06s ease-out;
  }

  .search-card:active {
    transform: scale(0.98);
    transition: transform 0.06s ease-out;
  }

  html body .pin-viewer-action:active {
    transform: scale(0.92);
    transition: transform 0.06s ease-out;
  }

  html body .pin-viewer-close:active {
    transform: scale(0.88);
    transition: transform 0.06s ease-out;
  }

  html body .pin-viewer-story-card:active {
    transform: scale(0.97);
    transition: transform 0.06s ease-out;
  }

  #close-gallery-btn:active,
  .search-close-btn:active,
  .auth-close-btn:active {
    transform: scale(0.88);
    transition: transform 0.06s ease-out;
  }
}
