/*
 * Listing cards and the listings page. The landing page links this file for its preview,
 * so anything that hides content is scoped to .page-listings, where listings.js runs.
 */

/* Grid. Inside .wrap, a column gap of twice the gutter centres each gap on a .rules line. */

.listing-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(40px, 4vw, 64px) calc(var(--gutter) * 2);
}

@media (max-width: 900px) {
  .listing-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: var(--gutter);
  }
}

@media (max-width: 600px) {
  .listing-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Card */

.listing-grid[hidden],
.listing-card[hidden] { display: none; }

.listing-card__media {
  position: relative;
  aspect-ratio: 7 / 5;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--paper-2);
}

.listing-card__frame {
  position: absolute;
  inset: 0;
}

.listing-card__frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.86); /* calmer against the warm page, especially the pool's blue */
  color: transparent; /* If a file is missing, leave the neutral block rather than stray alt text. */
  transition: transform 1.6s var(--ease-out), opacity 0.6s linear;
}

.listing-card__frame img.is-loading { opacity: 0; }

.listing-card__pills {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.listing-card__pills .pill { background: rgba(250, 248, 244, 0.94); color: var(--ink); }

.listing-card__pills .pill:first-child { background: var(--ink); color: var(--on-dark); }

.listing-card__body { padding-top: 14px; }

.listing-card__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.listing-card__title {
  font-size: 1.0625rem;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: -0.018em;
  text-wrap: pretty;
}

.listing-card__price {
  flex: none;
  font-family: var(--serif);
  font-size: 1.5rem;
  line-height: 1.1;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.listing-card__location {
  margin-top: 2px;
  font-size: var(--text-sm);
  color: var(--ink-3);
}

.listing-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: var(--text-xs);
  color: var(--ink-3);
}

.listing-card__meta li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.listing-card__meta svg { flex: none; }

/* Sample data note */

.sample-note {
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--ink-2);
  text-wrap: balance;
}

/* Page */

.page-listings {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;
}

.page-listings main { flex: 1; }

.listings {
  padding-top: calc(var(--header-h) + clamp(16px, 2vw, 28px));
  padding-bottom: clamp(72px, 8vw, 120px);
}

.listings-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.listings-head .eyebrow--rule { align-self: stretch; }

/* Sized to nearly fill the centre column between the rules, as in the reference. */

.listings-head__title {
  margin-top: clamp(12px, 1.2vw, 18px);
  font-size: var(--section-title);
  font-weight: 300;
}

/* Each word rises from behind its own mask. The padding stops the mask cutting descenders. */

.listings-head__title .word {
  display: inline-block;
  overflow: hidden;
  padding: 0.04em 0.05em 0.16em;
  margin: -0.04em -0.05em -0.16em;
  vertical-align: top;
}

.listings-head__title .word > span { display: inline-block; }

.listings-head .sample-note { margin-top: 12px; }

/* Stay inside the centre column, between the rules. */

@media (min-width: 901px) {
  .listings-head .sample-note { max-width: calc(33.333vw - 32px); }
}

/* Tabs. They only appear once listings.js is running, as otherwise every listing is shown and they
   would do nothing. They share one rail so they read as a single control. Both are the same width,
   so the black thumb only needs a transform to move. */

.listing-tabs { display: none; }

.listings-live .listing-tabs {
  --tab-inset: 4px;
  position: relative;
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: var(--tab-inset);
  border-radius: calc(var(--radius) + 2px);
  background: var(--paper-2);
  margin-top: clamp(22px, 2.2vw, 32px);
}

.listing-tabs__thumb {
  position: absolute;
  top: var(--tab-inset);
  left: var(--tab-inset);
  z-index: 1;
  width: calc((100% - 2 * var(--tab-inset)) / 2);
  height: calc(100% - 2 * var(--tab-inset));
  border-radius: var(--radius);
  background: var(--ink);
}

.listing-tabs.is-live .listing-tabs__thumb { transition: transform 0.45s var(--ease-out); }

.listing-tabs[data-active="test"] .listing-tabs__thumb {
  transform: translateX(100%);
}

.listing-tab {
  position: relative;
  min-width: 88px;
  height: 44px;
  padding-inline: 18px;
  font-size: var(--text-sm);
  letter-spacing: -0.005em;
  white-space: nowrap;
}

.listing-tab > span,
.listing-tab::after {
  position: relative;
  z-index: 2;
  transition: opacity 0.35s linear;
}

.listing-tab > span { color: var(--ink-2); }

.listing-tab::after {
  content: attr(data-label);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--paper);
  opacity: 0;
}

.listing-tab[aria-selected="true"] > span { opacity: 0; }
.listing-tab[aria-selected="true"]::after { opacity: 1; }
.listing-tab[aria-selected="false"]:hover > span { color: var(--ink); }

/* Listings panel */

#listings-panel {
  margin-top: clamp(24px, 2vw, 30px);
  outline-offset: 10px;
}

.listing-card:focus-visible { outline-offset: 8px; }

.listings-empty {
  padding-block: clamp(64px, 12vw, 160px);
  text-align: center;
  color: var(--ink-2);
}

.listings-empty[hidden] { display: none; }

/* Load More. As with the tabs, it needs listings.js, or every listing is already on the page. */

.listings-more { display: none; }

.listings-live .listings-more {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: clamp(32px, 2.9vw, 44px);
}

/* How far through the list the visitor is, so the rest feels within reach. */

.listings-count { font-size: var(--text-sm); color: var(--ink-2); }

.listings-bar {
  display: block;
  width: min(14rem, 60vw);
  height: 2px;
  margin-block: 10px 18px;
  overflow: hidden;
  background: var(--line);
}

.listings-bar i {
  display: block;
  height: 100%;
  background: var(--ink);
  transform-origin: left;
  transition: transform 0.6s var(--ease-out);
}

.listings-live .listings-more[hidden] { display: none; }

/*
 * Motion, listings page only. listings.js adds .is-in to play these. If it never runs, the
 * fallback animation shows everything after three seconds, and .listings-live cancels that.
 */

@media (prefers-reduced-motion: no-preference) {
  .js .page-listings .listings-head .eyebrow--rule::after,
  .js .page-listings .listings-head .eyebrow--rule > span,
  .js .page-listings .listings-head .word > span,
  .js .page-listings .listings-head .sample-note,
  .js .page-listings .listing-card__media,
  .js .page-listings .listing-card__body {
    animation: listings-show 0.01s linear 3s forwards;
  }

  .listings-live .page-listings .listings-head .eyebrow--rule::after,
  .listings-live .page-listings .listings-head .eyebrow--rule > span,
  .listings-live .page-listings .listings-head .word > span,
  .listings-live .page-listings .listings-head .sample-note,
  .listings-live .page-listings .listing-card__media,
  .listings-live .page-listings .listing-card__body {
    animation: none;
  }

  /* Heading */

  .js .page-listings .listings-head .eyebrow--rule::after {
    transition: transform 1s var(--ease-out);
  }

  .js .page-listings .listings-head:not(.is-in) .eyebrow--rule::after { transform: scaleX(0); }

  .js .page-listings .listings-head .eyebrow--rule > span {
    transition: opacity 0.5s linear;
  }

  .js .page-listings .listings-head:not(.is-in) .eyebrow--rule > span { opacity: 0; }

  .js .page-listings .listings-head .word > span {
    transition: transform 0.95s var(--ease-out);
    transition-delay: calc(0.04s + var(--line, 0) * 0.1s);
  }

  .js .page-listings .listings-head:not(.is-in) .word > span { transform: translateY(118%); }

  .js .page-listings .listings-head .sample-note,
  .js .page-listings .listings-head .listing-tabs {
    transition: opacity 0.5s linear 0.12s, transform 0.7s var(--ease-out) 0.12s;
  }

  .js .page-listings .listings-head:not(.is-in) .sample-note,
  .js .page-listings .listings-head:not(.is-in) .listing-tabs {
    opacity: 0;
    transform: translateY(10px);
  }

  /* Cards: the image wipes open from the top, then the text rises. */

  .js .page-listings .listing-card__media {
    clip-path: inset(0 0 0 0);
    transition: clip-path 0.95s var(--ease-out) var(--d, 0s);
  }

  .js .page-listings .listing-card:not(.is-in) .listing-card__media { clip-path: inset(0 0 100% 0); }

  .js .page-listings .listing-card:not(.is-in) .listing-card__frame img { transform: scale(1.07); }

  .js .page-listings .listing-card__body {
    transition: opacity 0.5s linear calc(var(--d, 0s) + 0.08s), transform 0.8s var(--ease-out) calc(var(--d, 0s) + 0.08s);
  }

  .js .page-listings .listing-card:not(.is-in) .listing-card__body {
    opacity: 0;
    transform: translateY(12px);
  }

  /* Outgoing cards when the tab changes. */

  .listing-grid.is-leaving .listing-card {
    opacity: 0;
    transition: opacity 0.12s linear;
  }

  .js .page-listings .listings-more { transition: opacity 0.5s linear 0.15s; }

  .js .page-listings .listings-more:not(.is-in) {
    opacity: 0;
    transition: none;
  }
}

@keyframes listings-show {
  to {
    opacity: 1;
    transform: none;
    clip-path: inset(0 0 0 0);
  }
}
