Foreign keys – constraints between tables for a variable

I want to limit the number of bicycles that can be parked in each terminal – the number of bicycles differs between the terminals.

These are my original tables

create table terminal(
terminal_id serial primary key,
terminal_town varchar(30) not null,
terminal_street varchar(30) not null,
terminal_max_capacity smallint not null,
sponsor_payment_id serial references sponsor_payment(sponsor_payment_id)

    create table bicycle(
bicycle_id serial primary key,
bicycle_make varchar(30) not null,
bicycle_model varchar(30) not null,
bicycle_colour varchar(30) not null,
bicycle_type varchar(14) not null,
terminal_id serial references terminal(terminal_id) on delete cascade

If you add this:

constraint terminal_max_capacity_check check (references bicycle(bicycle_id between 1 and terminal_max_capacity)

It did not work.

any ideas.
Thank you very much