/* Characters and Scenes only. Keep the established mobile and wide layouts. */
@media (min-width: 761px) and (max-width: 1399px) {
  main.catalog-page:has(.page-actions > .primary-action:is([data-entry-type="character"], [data-entry-type="scene"])) > .catalog-sticky-region > .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }
  main.catalog-page:has(.page-actions > .primary-action:is([data-entry-type="character"], [data-entry-type="scene"])) .page-header > div:first-child {
    min-width: 0;
    overflow-wrap: anywhere;
  }
  main.catalog-page:has(.page-actions > .primary-action:is([data-entry-type="character"], [data-entry-type="scene"])) .page-header > .page-actions {
    display: flex;
    flex: none;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    gap: 10px;
  }
  main.catalog-page:has(.page-actions > .primary-action:is([data-entry-type="character"], [data-entry-type="scene"])) .page-actions > * {
    max-width: 100%;
  }
  main.catalog-page:has(.page-actions > .primary-action:is([data-entry-type="character"], [data-entry-type="scene"])) .page-actions > :is(.primary-action, .add-chapter-action, .fast-upload-toggle, .empty-chapter-toggle, .scene-location-toggle) {
    flex: 0 0 auto;
    min-height: 44px;
  }
  main.catalog-page:has(.page-actions > .primary-action:is([data-entry-type="character"], [data-entry-type="scene"])) .character-sort {
    flex-wrap: wrap;
    min-width: 0;
    margin-left: 0;
  }
  main.catalog-page:has(.page-actions > .primary-action:is([data-entry-type="character"], [data-entry-type="scene"])) .character-sort select {
    min-width: 0;
    max-width: 100%;
  }
  main.catalog-page:has(.page-actions > .primary-action:is([data-entry-type="character"], [data-entry-type="scene"])) > .catalog-sticky-region > .catalog-toolbar {
    flex-wrap: wrap;
    gap: 10px;
  }
  main.catalog-page:has(.page-actions > .primary-action:is([data-entry-type="character"], [data-entry-type="scene"])) .catalog-toolbar > .search-box {
    flex: 1 1 220px;
    min-width: 160px;
    width: auto;
    max-width: 100%;
  }

  /* Fit readable portraits to the workspace instead of shrinking six tracks. */
  main.catalog-page.catalog-grid-view > .catalog-section > .character-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr));
  }

}

/* Match the Scenes header instead of the legacy compact Characters override. */
@media (min-width: 761px) and (max-width: 899px) {
  body.navigation-shell-mounted main.catalog-page > .catalog-sticky-region > .page-header:has(> .page-actions > .primary-action[data-entry-type="character"]):has(> .page-actions > .fast-upload-toggle):has(> .page-actions > .add-chapter-action) {
    padding-block: 16px;
    row-gap: 14px;
  }
}

/* Keep the complete header and toolbar visible in short desktop windows. */
@media (min-width: 761px) and (max-width: 1399px) and (max-height: 650px) {
  body.navigation-shell-mounted main.catalog-page:has(.page-actions > .primary-action:is([data-entry-type="character"], [data-entry-type="scene"])) > .catalog-sticky-region {
    max-height: calc(100dvh - var(--navigation-top) - 88px);
  }
}
