/* HOUSE inventory — first-party reservations and creative presentation.
   The outer slot owns a fixed height before JS runs. Empty and blocked slots
   intentionally keep that height; collapsing one would reintroduce CLS.

   HOUSE-AD-AUTOSCALE-0904: the creative sizes itself off the SLOT, not the
   viewport. `native` is served at 267px in the /scores AP rail and at 1828px
   on /players, and a viewport-relative `5vw` title gave both the same 34px —
   which escaped the 267px card by 61px and painted over the eyebrow and the
   label. Every text-bearing child is now line-clamped and owns its own grid
   row, so no copy length can make two of them collide. Geometry is gated by
   tools/house-ad-fit.test.mjs. */
.house-ad-slot {
  --house-ad-width: 100%;
  box-sizing: border-box;
  display: block;
  width: 100%;
  max-width: var(--house-ad-width);
  margin-inline: auto;
  overflow: hidden;
  contain: layout paint;
  /* The creative's type and layout query THIS box, so one format renders
     correctly at every width it is actually served at. */
  container-type: inline-size;
}

.house-ad-slot[data-ad-format="feed-1"],
.house-ad-slot[data-ad-format="article"] {
  --house-ad-width: 336px;
  position: relative;
  left: 50%;
  width: min(336px, calc(100vw - 24px));
  max-width: none;
  height: 280px;
  min-height: 280px;
  transform: translateX(-50%);
}

.house-ad-slot[data-ad-format="feed-2"] {
  --house-ad-width: 320px;
  position: relative;
  left: 50%;
  width: min(320px, calc(100vw - 24px));
  max-width: none;
  height: 100px;
  min-height: 100px;
  transform: translateX(-50%);
}

.house-ad-slot[data-ad-format="native"] {
  height: 150px;
  min-height: 150px;
}

.house-ad-slot[data-ad-format="rail"] {
  display: none;
  --house-ad-width: 300px;
  width: 300px;
  height: 250px;
  min-height: 250px;
}

/* Base creative. The title used to share a flexible row with `align-self:end`,
   so a title that wrapped grew UPWARD out of its track and over the eyebrow.
   Giving each text element its own row makes that impossible for any copy. */
.house-ad-creative {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 5px 14px;
  width: 100%;
  height: 100%;
  padding: 16px 18px;
  overflow: hidden;
  color: #fff;
  text-decoration: none;
  background:
    radial-gradient(circle at 92% 12%, rgba(255, 45, 45, .24), transparent 42%),
    linear-gradient(145deg, #171717, #090909 72%);
  border: 1px solid #343434;
  border-left: 3px solid #ff2d2d;
  border-radius: 10px;
}

/* Grid items floor at min-content, which is what let a long word push a child
   past its track. */
.house-ad-creative > * {
  min-width: 0;
  min-height: 0;
}

.house-ad-creative:focus-visible {
  outline: 3px solid #fff;
  outline-offset: -4px;
}

.house-ad-label,
.house-ad-eyebrow,
.house-ad-cta {
  font-family: var(--f-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: .11em;
  text-transform: uppercase;
}

.house-ad-label {
  grid-column: 1;
  grid-row: 1;
  overflow: hidden;
  color: #ff7777;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.house-ad-eyebrow {
  grid-column: 2;
  grid-row: 1;
  /* 18ch flat truncated "Commissioner Premium" even on a 1180px card. Let the
     eyebrow use up to 45% of the slot before it ellipsizes. */
  max-width: 24ch; /* fallback: no container-query units */
  max-width: min(24ch, 45cqi);
  overflow: hidden;
  color: #aaa;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.house-ad-title {
  grid-column: 1 / -1;
  grid-row: 2;
  align-self: end;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  margin: 0;
  overflow: hidden;
  color: #fff;
  font-family: var(--f-display, Impact, sans-serif);
  /* Container-relative, so a 267px rail card and a 1828px table card each get
     type in proportion to the box they occupy. */
  font-size: 26px; /* fallback: no container-query units */
  font-size: clamp(19px, 4.6cqi, 34px);
  font-weight: 700;
  /* 1 clipped the descenders of the display face at every size. */
  line-height: 1.08;
  letter-spacing: .025em;
  text-transform: uppercase;
}

.house-ad-body {
  grid-column: 1;
  grid-row: 3;
  align-self: end;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  margin: 0;
  overflow: hidden;
  color: #c9c9c9;
  font-family: var(--f-body, system-ui, sans-serif);
  font-size: 16px;
  line-height: 1.35;
}

.house-ad-cta {
  grid-column: 2;
  grid-row: 3;
  align-self: end;
  color: #fff;
  white-space: nowrap;
}

.house-ad-cta::after {
  content: " \2192";
  color: #ff2d2d;
}

/* Narrow cards go single-column. The two-column base sits the nowrap CTA
   beside the body; under ~520px the CTA took so much of the row that the body
   collapsed to a ~40px column and wrapped one word per line. */
@container (max-width: 519px) {
  .house-ad-slot[data-ad-format="native"] .house-ad-creative {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: 4px;
    padding: 12px 14px;
  }

  .house-ad-slot[data-ad-format="native"] .house-ad-eyebrow {
    display: none;
  }

  .house-ad-slot[data-ad-format="native"] .house-ad-label,
  .house-ad-slot[data-ad-format="native"] .house-ad-title,
  .house-ad-slot[data-ad-format="native"] .house-ad-body,
  .house-ad-slot[data-ad-format="native"] .house-ad-cta {
    grid-column: 1;
  }

  .house-ad-slot[data-ad-format="native"] .house-ad-title {
    font-size: 21px; /* fallback: no container-query units */
    font-size: clamp(19px, 5.8cqi, 24px);
  }

  /* 150px of card, less the label, a two-line title and the CTA, leaves room
     for exactly one line of body copy. */
  .house-ad-slot[data-ad-format="native"] .house-ad-body {
    grid-row: 3;
    align-self: start;
    -webkit-line-clamp: 1;
  }

  .house-ad-slot[data-ad-format="native"] .house-ad-cta {
    grid-row: 4;
    align-self: end;
  }

  /* Tall mobile billboard (336x280): one column, and the height to carry the
     eyebrow and a real body paragraph the two-column row would starve. Copy
     stacks from the top and the CTA is pinned to the bottom, rather than a
     flexible row opening a gap between the eyebrow and the title. */
  .house-ad-slot[data-ad-format="feed-1"] .house-ad-creative,
  .house-ad-slot[data-ad-format="article"] .house-ad-creative {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto minmax(0, 1fr);
  }

  .house-ad-slot[data-ad-format="feed-1"] .house-ad-eyebrow,
  .house-ad-slot[data-ad-format="article"] .house-ad-eyebrow {
    grid-column: 1;
    grid-row: 2;
    max-width: none;
    text-align: left;
  }

  .house-ad-slot[data-ad-format="feed-1"] .house-ad-title,
  .house-ad-slot[data-ad-format="article"] .house-ad-title {
    grid-column: 1;
    grid-row: 3;
    align-self: start;
    font-size: 26px; /* fallback: no container-query units */
    font-size: clamp(22px, 8.5cqi, 30px);
  }

  .house-ad-slot[data-ad-format="feed-1"] .house-ad-body,
  .house-ad-slot[data-ad-format="article"] .house-ad-body {
    grid-column: 1;
    grid-row: 4;
    align-self: start;
    -webkit-line-clamp: 3;
    margin-top: 6px;
  }

  .house-ad-slot[data-ad-format="feed-1"] .house-ad-cta,
  .house-ad-slot[data-ad-format="article"] .house-ad-cta {
    grid-column: 1;
    grid-row: 5;
    align-self: end;
  }
}

/* Compact billboards keep copy within the 90/100px contract. */
.house-ad-slot[data-ad-format="feed-2"] .house-ad-creative {
  grid-template-rows: auto minmax(0, 1fr);
  padding: 12px 14px;
}

.house-ad-slot[data-ad-format="feed-2"] .house-ad-title {
  grid-column: 1;
  grid-row: 2;
  align-self: center;
  -webkit-line-clamp: 1;
  font-size: 18px; /* fallback: no container-query units */
  font-size: clamp(17px, 2.7cqi, 19px);
}

.house-ad-slot[data-ad-format="feed-2"] .house-ad-body,
.house-ad-slot[data-ad-format="feed-2"] .house-ad-eyebrow {
  display: none;
}

.house-ad-slot[data-ad-format="feed-2"] .house-ad-cta {
  grid-row: 2;
  align-self: center;
}

/* A 320x100 billboard cannot fit the title beside a nowrap CTA: "Start a new
   league" ellipsized to "START A…" alongside "CREATE A LEAGUE". Stacked, the
   title gets the full 292px. Must follow the block above — same specificity. */
@container (max-width: 519px) {
  .house-ad-slot[data-ad-format="feed-2"] .house-ad-creative {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .house-ad-slot[data-ad-format="feed-2"] .house-ad-title {
    grid-column: 1;
    grid-row: 2;
    align-self: start;
  }

  .house-ad-slot[data-ad-format="feed-2"] .house-ad-cta {
    grid-column: 1;
    grid-row: 3;
    align-self: end;
  }
}

/* News starts in a timed video reel. The units become layout participants only
   when the non-timed article feed is selected. The class is stamped before
   article cards render, including deep-link first paint. */
html[data-route="/news"]:not(.nw-article-feed) .house-ad-slot {
  display: none;
}

.house-ad-rail {
  display: none;
}

/* No inventory is exposed inside either native WebView. */
html.cap-native .house-ad-slot,
html.cap-native .house-ad-rail {
  display: none !important;
}

@media (min-width: 768px) {
  .house-ad-slot[data-ad-format="feed-1"],
  .house-ad-slot[data-ad-format="feed-2"],
  .house-ad-slot[data-ad-format="article"] {
    --house-ad-width: 728px;
    width: min(728px, calc(100vw - 24px));
    height: 90px;
    min-height: 90px;
  }

  .house-ad-slot[data-ad-format="feed-1"] .house-ad-creative,
  .house-ad-slot[data-ad-format="article"] .house-ad-creative {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 12px 16px;
  }

  .house-ad-slot[data-ad-format="feed-1"] .house-ad-title,
  .house-ad-slot[data-ad-format="article"] .house-ad-title {
    grid-column: 1;
    grid-row: 2;
    align-self: center;
    -webkit-line-clamp: 1;
    font-size: 20px; /* fallback: no container-query units */
    font-size: clamp(18px, 3cqi, 22px);
  }

  .house-ad-slot[data-ad-format="feed-1"] .house-ad-body,
  .house-ad-slot[data-ad-format="feed-1"] .house-ad-eyebrow,
  .house-ad-slot[data-ad-format="article"] .house-ad-body,
  .house-ad-slot[data-ad-format="article"] .house-ad-eyebrow {
    display: none;
  }

  .house-ad-slot[data-ad-format="feed-1"] .house-ad-cta,
  .house-ad-slot[data-ad-format="article"] .house-ad-cta {
    grid-column: 2;
    grid-row: 2;
    align-self: center;
  }
}

@media (min-width: 1100px) {
  main.house-ad-rail-page {
    position: relative;
    min-height: max(1250px, calc(80vh + 550px));
    padding-right: 324px;
  }

  .house-ad-rail {
    box-sizing: border-box;
    display: block;
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;
  }

  .house-ad-slot[data-ad-format="rail"] {
    display: block;
  }

  .house-ad-rail .house-ad-slot[data-ad-slot="rail-bottom"] {
    margin-top: clamp(720px, 80vh, 960px);
  }

  /* 300x250: label, eyebrow and title each own a row. The title previously sat
     `align-self:end` in the flexible row and overlapped the eyebrow on every
     page that carries a rail. The body absorbs the slack instead. */
  .house-ad-slot[data-ad-format="rail"] .house-ad-creative {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    padding: 18px;
  }

  .house-ad-slot[data-ad-format="rail"] .house-ad-label,
  .house-ad-slot[data-ad-format="rail"] .house-ad-eyebrow,
  .house-ad-slot[data-ad-format="rail"] .house-ad-title,
  .house-ad-slot[data-ad-format="rail"] .house-ad-body,
  .house-ad-slot[data-ad-format="rail"] .house-ad-cta {
    grid-column: 1;
  }

  .house-ad-slot[data-ad-format="rail"] .house-ad-eyebrow {
    grid-row: 2;
    max-width: none;
    text-align: left;
  }

  .house-ad-slot[data-ad-format="rail"] .house-ad-title {
    grid-row: 3;
    align-self: start;
    font-size: 25px; /* fallback: no container-query units */
    font-size: clamp(22px, 9.4cqi, 28px);
  }

  .house-ad-slot[data-ad-format="rail"] .house-ad-body {
    grid-row: 4;
    align-self: start;
    -webkit-line-clamp: 3;
    margin-top: 8px;
  }

  .house-ad-slot[data-ad-format="rail"] .house-ad-cta {
    grid-row: 5;
    align-self: end;
    margin-top: 12px;
  }
}
