@media screen and (min-width: 981px) {
  .isMobile:not(.isDesktop),
  .isTablet:not(.isDesktop) {
    display: none !important;
  }
}

@media screen and (max-width: 1180px) {
  .listing-card-list.listing-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .book-category-grid {
    --book-category-per-page: 3;
  }
}

@media screen and (max-width: 980px) {
  :root {
    --sticky-page-top: 78px;
  }

  .app-topbar .wrapper {
    padding-left: 0;
  }

  .topbar-shell {
    border-radius: 20px;
  }

  .topbar-account {
    position: relative;
    right: auto;
    top: auto;
    z-index: auto;
  }

  .second-shelf-layout {
    display: block;
  }

  .second-shelf-main-area {
    grid-column: auto;
  }

  body:after {
    display: none;
  }

  .app-sidebar {
    height: auto;
    left: auto;
    margin-bottom: 24px;
    position: static;
    top: auto;
    width: 100%;
  }

  .app-sidebar:before,
  .app-sidebar:after {
    display: none;
  }

  .app-sidebar-inner {
    border-radius: 20px;
    height: auto;
    padding: 20px;
  }

  .sidebar-logo {
    margin: 0 0 18px;
  }

  .sidebar-menu,
  .sidebar-menu-muted {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sidebar-menu-muted {
    margin-top: 16px;
  }

  .settings-menu {
    left: 0;
    top: calc(100% + 8px);
    transform: translateY(-6px);
  }

  .sidebar-menu-settings:hover .settings-menu,
  .sidebar-menu-settings:focus-within .settings-menu {
    transform: translateY(0);
  }

  .home-discover {
    margin-top: 0;
  }

  .form-horizontal .control-label,
  .form-horizontal .controls {
    float: none;
    text-align: left;
    width: 100%;
  }

  .form-horizontal .actions,
  .form-horizontal .pblbt,
  .form-horizontal .recpt,
  .item-post h2 {
    margin-left: 0;
  }
}

@media screen and (min-width: 768px) and (max-width: 980px) {
  .isDesktop:not(.isTablet),
  .isMobile:not(.isTablet) {
    display: none !important;
  }
}

@media screen and (max-width: 767px) {
  :root {
    --sticky-page-top: 70px;
  }

  .book-category-grid {
    --book-category-per-page: 2;
  }

  .isDesktop:not(.isMobile),
  .isTablet:not(.isMobile) {
    display: none !important;
  }

  .wrapper {
    width: min(100% - 24px, 1180px);
  }

  .app-topbar {
    padding-top: 10px;
  }

  .topbar-shell {
    min-height: 58px;
    padding: 0 14px;
  }

  .account-trigger span {
    display: none;
  }

  .home-discover h1,
  body.search h1,
  body.user h1,
  body.item h1,
  .form-container .header h1 {
    font-size: 32px;
    line-height: 38px;
  }

  .home-discover,
  #main > h1 {
    border-radius: 0 0 16px 16px;
    padding: 14px;
  }

  .form-container > .header {
    margin: -22px -22px 18px;
    padding: 14px 22px 0;
  }

  .home-book-search {
    display: grid;
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
    padding: 10px;
  }

  .home-book-search-category,
  .home-book-search-query {
    border: 0;
    height: 46px;
  }

  .home-book-search button {
    height: 42px;
    margin: 8px 0 0;
    width: 100%;
  }

  .listing-card-list.listing-grid {
    grid-template-columns: 1fr;
  }

  .listing-card {
    min-height: 0;
  }

  .listing-thumb {
    height: 190px;
  }

  .item-photos {
    grid-template-columns: 1fr;
  }

  .photo-uploader {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .item-photos .thumbs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: repeat(2, 75px);
  }

  .item-photos .thumbs a {
    height: 75px;
    width: 100%;
  }

  .item-detail-actions {
    flex-direction: column;
  }

  .chat-page {
    height: calc(100vh - 220px);
  }

  .chat-list-pane {
    display: flex;
    width: 100%;
  }

  .chat-thread-pane {
    display: none;
  }

  .chat-page.has-active .chat-list-pane {
    display: none;
  }

  .chat-page.has-active .chat-thread-pane {
    display: flex;
  }

  .chat-back {
    display: inline-flex;
  }

  .chat-item-card {
    margin: 12px 14px 0;
  }

  .chat-thread-header,
  .chat-messages,
  .chat-quick-replies,
  .chat-input-bar {
    padding-left: 14px;
    padding-right: 14px;
  }

  .second_shelf-item-chat-overlay {
    padding: 0;
  }

  .second_shelf-item-chat-box {
    border-radius: 0;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
  }

  .second_shelf-item-chat-close {
    right: 12px;
    top: 12px;
  }

  /* Edge to edge: the page's usual side padding would leave a strip of
     the book page showing around the chat. */
  /* (html prefix: outranks chat.css's 20px, which loads later.) */
  html body.chat-page-embed section,
  html body.chat-page-embed .wrapper#content {
    padding: 0;
  }

  html body.chat-page-embed .chat-page {
    border-radius: 0;
    border: 0;
    height: 100vh;
    height: 100dvh;
  }
}

@media screen and (max-width: 520px) {
  .sidebar-menu,
  .sidebar-menu-muted {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }
}

/* Phones: the filter is a sheet from the bottom, the page dimmed behind it
   (a tap there closes it, global.js) — a dropdown at the button ran off the
   screen's edge or under the bottom bar. */
@media screen and (max-width: 767px) {
  .search-filter.is-open::before {
    background: rgba(23,25,29,0.45);
    content: '';
    inset: 0;
    position: fixed;
    z-index: 95;
  }

  .search-filter-panel {
    border-radius: 22px 22px 0 0;
    bottom: 0;
    left: 0;
    max-height: 85vh;
    max-height: 85dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 26px 20px calc(20px + env(safe-area-inset-bottom));
    position: fixed;
    right: 0;
    top: auto;
    transform: translateY(24px);
    width: auto;
    z-index: 96;
  }

  /* A little grab handle on top of the sheet. */
  .search-filter-panel::before {
    background: rgba(23,25,29,0.15);
    border-radius: 999px;
    content: '';
    height: 4px;
    left: 50%;
    position: absolute;
    top: 10px;
    transform: translateX(-50%);
    width: 40px;
  }

  body:has(.search-filter.is-open) .bottom-nav {
    display: none;
  }

  html:has(.search-filter.is-open),
  html:has(.search-filter.is-open) body {
    overflow: hidden;
  }
}

/* Phones: the chat (its own page, not the window over a book) nearly edge
   to edge — page padding, the wrapper's margin, the pane's and the message
   list's padding used to leave a third of the width empty. */
@media screen and (max-width: 767px) {
  body.chat-page-body:not(.chat-page-embed) section {
    padding-left: 6px;
    padding-right: 6px;
  }

  /* Full width of the section (its 6px each side) — centred; the phone
     width rule (100% − 24px) without its auto margins sat on the left. */
  body.chat-page-body:not(.chat-page-embed) .wrapper#content {
    margin-left: 0;
    margin-right: 0;
    width: 100%;
  }

  /* The panes are <section>s: the theme's phone padding for page sections
     (0 15px 52px) doesn't belong inside the chat — it left a gap under the
     composer. And chat.css (loaded later) mustn't bring back the desktop
     layout: one pane at a time, full width. */
  .chat-page section.chat-thread-pane,
  .chat-page section.chat-list-pane {
    padding: 0;
  }

  .chat-page .chat-list-pane {
    border-right: 0;
    width: 100%;
  }

  .chat-page .chat-thread-pane {
    display: none;
  }

  .chat-page.has-active .chat-thread-pane {
    display: flex;
  }

  .chat-page.has-active .chat-list-pane {
    display: none;
  }

  /* Quick replies: one row to swipe through instead of three lines that
     left the messages a sliver. */
  .chat-page .chat-quick-replies {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .chat-page .chat-quick-replies::-webkit-scrollbar {
    display: none;
  }

  .chat-page .chat-quick-replies > * {
    flex-shrink: 0;
    white-space: nowrap;
  }

  body.chat-page-body .chat-messages {
    padding-left: 6px;
    padding-right: 6px;
  }

  /* The composer's hint stays on one line. */
  .chat-input-bar textarea::placeholder {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Phones: the footer above the page's decorative background layers (they
   covered half of it), without the long list of languages — the language
   is changed in the settings (and the profile). */
@media screen and (max-width: 980px) {
  footer {
    position: relative;
    z-index: 3;
  }

  footer .language {
    display: none;
  }
}
