/* Ad slots. The server publishes every breakpoint's size as per-class custom
   properties on the slot; the queries below choose the active pair, so a
   leaderboard reserves 728x90 on a tablet and 320x50 on a phone rather than
   forcing its desktop box onto both. */

.ad-unit {
  margin: 0;
  padding: 0;
  text-align: center;
  font-size: 0;
}

/* A sidebar ad sits between cards and buttons that carry their own margins, so
   without this it butts flush against whatever precedes or follows it. The
   billboards are excluded: they are full-bleed bands and must stay flush. */
aside:not(.article-side) .ad-unit { margin: 18px 0; }
aside:not(.article-side) .ad-unit:first-child { margin-top: 0; }
aside:not(.article-side) .ad-unit:last-child { margin-bottom: 0; }

.ad-unit iframe {
  border: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

/* Freestar injects an ancillary element we don't lay out for. */
.ad-unit .__fs-ancillary {
  display: none !important;
}

.ad-placeholder {
  position: relative;
  display: inline-block;
  background: #f9f9f9;
  color: #91949b;
  font-size: 16px;
  text-align: center;
  user-select: none;
  cursor: pointer;
  overflow: hidden;
}

/* The caption reports the box it sits in, so it reads from the same properties
   rather than from a size the server picked once. */
.ad-placeholder-size::after {
  content: var(--ad-label);
}

.ad-placeholder-size {
  display: block;
  line-height: calc(var(--ad-h) * 1px);
}

/* Both slot kinds resolve the active class to plain --ad-w/--ad-h, so only
   these two properties vary by breakpoint and everything else reads them. */
.ad-placeholder,
.ad-slot {
  --ad-w: var(--ad-w-xsmall);
  --ad-h: var(--ad-h-xsmall);
  --ad-label: var(--ad-label-xsmall);
}

.ad-placeholder {
  width: calc(var(--ad-w) * 1px);
  height: calc(var(--ad-h) * 1px);
}

/* A live slot only reserves height: Freestar sets the width itself, and pinning
   one would stop a narrow creative centring in the band. */
.ad-slot { min-height: calc(var(--ad-h) * 1px); }

/* A class the catalog hides publishes --ad-hide-<class>:none, which collapses
   the whole band; every other class leaves the property unset, and the `,` in
   the fallback makes that resolve to `revert`. */
.ad-unit { display: var(--ad-hide-xsmall, revert); }

@media (min-width: 768px) {
  .ad-placeholder,
  .ad-slot {
    --ad-w: var(--ad-w-small);
    --ad-h: var(--ad-h-small);
    --ad-label: var(--ad-label-small);
  }

  .ad-unit { display: var(--ad-hide-small, revert); }
}

@media (min-width: 980px) {
  .ad-placeholder,
  .ad-slot {
    --ad-w: var(--ad-w-medium);
    --ad-h: var(--ad-h-medium);
    --ad-label: var(--ad-label-medium);
  }

  .ad-unit { display: var(--ad-hide-medium, revert); }
}

@media (min-width: 1200px) {
  .ad-placeholder,
  .ad-slot {
    --ad-w: var(--ad-w-large);
    --ad-h: var(--ad-h-large);
    --ad-label: var(--ad-label-large);
  }

  .ad-unit { display: var(--ad-hide-large, revert); }
}

/* Placeholder diagnostics: an overlay clipped to the slot's reserved box, so
   toggling it never changes the page's layout. */
.ad-debug {
  display: none;
  position: absolute;
  inset: 0;
  overflow: auto;
}

.ad-debug-toggle:checked ~ .ad-placeholder .ad-debug { display: block; }
.ad-debug-toggle:checked ~ .ad-placeholder .ad-placeholder-size { visibility: hidden; }

.ad-debug dl {
  padding: 10px;
  margin: 5px;
  text-align: left;
  font-size: 11px;
  line-height: 13px;
  background: rgba(255, 255, 255, 0.6);
  display: grid;
  grid-template: auto / 80px 1fr;
}

.ad-debug dt { font-weight: bold; grid-column: 1; }
.ad-debug dd { margin: 0; grid-column: 2; user-select: text; word-break: break-all; }

.ad-debug dt,
.ad-debug dd { border-top: 1px solid rgba(0, 0, 0, 0.1); padding: 3px 0; }
.ad-debug dt:first-of-type,
.ad-debug dd:first-of-type { border-top: 0; padding-top: 0; }
.ad-debug dt:last-of-type,
.ad-debug dd:last-of-type { padding-bottom: 0; }
.ad-debug dd + dd { border-top: 0; }

/* Full-bleed grey bands for the billboards, escaping the container. */
.ad-top_billboard,
.ad-mid_billboard,
.ad-bottom_billboard {
  position: relative;
  width: 100vw;
  left: 50%;
  right: 50%;
  margin-left: -50vw;
  margin-right: -50vw;
}

.ad-top_billboard {
  background: #e3e3e3;
  padding: 30px 0;
}

.ad-mid_billboard,
.ad-bottom_billboard {
  background: #ebebeb;
  border-top: 1px solid #d6d6d6;
  border-bottom: 1px solid #d6d6d6;
  padding: 50px 0;
}

@media (max-width: 767px) {
  .ad-top_billboard {
    padding: 15px 0;
  }

  .ad-mid_billboard,
  .ad-bottom_billboard {
    padding: 40px 0;
  }
}

/* A grid ad occupies one card cell and centres its creative. */
.ad-grid-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 250px;
}
