/* Narrow viewports and touch devices: listings popover backdrop */
@media (hover: none) and (pointer: coarse), (max-width: 1024px) {
  .listings-popover-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.02);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    z-index: 10000;
  }

  .listings-popover-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }
}

@media (max-width: 1024px) {
  /* Lift “Back to top” off the home-indicator corner; still fixed, easier to tap. */
  .back-to-top {
    right: max(16px, calc(env(safe-area-inset-right, 0px) + 12px));
    bottom: max(28px, calc(env(safe-area-inset-bottom, 0px) + 22px));
  }

  .topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
  }

  .theme-toggle {
    order: 3;
  }

  body {
    padding: 20px 14px 28px;
  }

  .topbar-right {
    justify-content: flex-start;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .theme-toggle,
  .settings-btn {
    position: static;
    width: 36px;
    height: 36px;
    background: rgba(9, 12, 18, 0.45);
    border: 1px solid var(--line);
  }

  :root.light-theme .theme-toggle,
  :root.light-theme .settings-btn {
    background: rgba(255, 255, 255, 0.8);
  }

  .settings-modal {
    width: min(560px, 94vw);
  }
}

@media (max-width: 740px) {
  body {
    padding: 16px 10px 22px;
  }

  .site-footer {
    margin-top: 18px;
  }

  .range-label-row {
    flex-wrap: wrap;
    row-gap: 3px;
  }

  .range-values {
    width: 100%;
    justify-content: flex-end;
  }

  .cards {
    gap: 8px;
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  }

  .favorite-toggle {
    width: 24px;
    height: 24px;
    font-size: 1rem;
  }

  .settings-modal {
    width: 100%;
    max-height: calc(100dvh - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)));
    border-radius: 14px;
  }

  .settings-overlay {
    align-items: flex-end;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  }

  .settings-header,
  .settings-body,
  .settings-footer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .settings-header {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-strong);
  }

  .settings-footer {
    position: sticky;
    bottom: 0;
    background: var(--surface-strong);
  }

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

  .settings-input {
    width: 100%;
    max-width: 100%;
  }

  #overview {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .eyebrow {
    font-size: 0.72rem;
    letter-spacing: 0.14em;
  }

  h1 {
    font-size: clamp(1.4rem, 8vw, 1.9rem);
  }


  .cards {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  }

  .art-frame {
    height: 134px;
  }

  .item-art {
    max-height: 118px;
  }

  .price-box {
    font-size: 0.7rem;
  }
}
