.watch-rider-post-content .watch-rider-ad-space {
  --wr-ad-top: calc(var(--header-h, 72px) + var(--watch-rider-admin-bar-offset, 0px));
  --wr-ad-available-height: max(0px, calc(100vh - var(--wr-ad-top)));
  width: 90%;
  max-width: 100%;
  margin: 32px auto;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel-strong);
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  isolation: isolate;
}

@supports (height: 100svh) {
  .watch-rider-post-content .watch-rider-ad-space {
    --wr-ad-available-height: max(0px, calc(100svh - var(--wr-ad-top)));
  }
}

/* Measure the same available height even while the creative is inline. */
.watch-rider-ad-space__measure {
  position: fixed;
  top: var(--wr-ad-top);
  left: 0;
  width: 0;
  height: var(--wr-ad-available-height);
  visibility: hidden;
  pointer-events: none;
}

.watch-rider-ad-space[hidden] {
  display: none !important;
}

/* Mark the end of the ad without adding another heading or clickable element. */
.watch-rider-post-content .watch-rider-ad-space::after {
  content: '';
  display: block;
  height: 2px;
  background: var(--accent);
}

.watch-rider-ad-space__label {
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--accent);
  color: var(--panel-strong);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: 0.02em;
}

.watch-rider-ad-space__window {
  position: relative;
  width: 100%;
}

.watch-rider-ad-space__stage {
  width: 100%;
  min-height: 280px;
  padding: 16px 0;
}

.watch-rider-ad-space--adsense .watch-rider-ad-space__stage {
  padding: 0;
}

.watch-rider-ad-space--banner .watch-rider-ad-space__stage {
  display: flex;
  align-items: center;
  justify-content: center;
}

.watch-rider-ad-space__creative {
  width: 100%;
}

.watch-rider-ad-space__link {
  display: block;
  color: inherit;
}

.watch-rider-ad-space__link:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 5px;
}

.watch-rider-post-content .watch-rider-ad-space__image {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 600px;
  margin: 0 auto;
  border: 0;
  object-fit: contain;
}

.watch-rider-post-content .watch-rider-ad-space--interscroll,
.watch-rider-post-content .watch-rider-ad-space--desktop {
  display: none;
}

@media (min-width: 1024px) {
  .watch-rider-post-content .watch-rider-ad-space--desktop {
    display: block;
    width: 90%;
    border: 0;
    background: transparent;
  }

  .watch-rider-ad-space--desktop .watch-rider-ad-space__label {
    padding: 4px 15px 3px;
    border: 0;
    font-size: 13px;
    line-height: 1.6;
    letter-spacing: 0;
  }

  .watch-rider-ad-space--desktop .watch-rider-ad-space__window {
    /* Keep the ad and both bars aligned with the article images. */
    width: 100%;
    margin-block: 5px;
    margin-inline: auto;
    background: rgba(166, 175, 185, 0.3);
  }

  .watch-rider-ad-space--desktop .watch-rider-ad-space__clip,
  .watch-rider-ad-space--desktop .watch-rider-ad-space__stage {
    position: static;
    height: auto;
    min-height: 0;
    clip: auto;
    clip-path: none;
    overflow: visible;
  }
}

/* Full-width mobile window with a narrow, theme-colored caption bar. */
@media (min-width: 320px) and (max-width: 1023px) {
  .watch-rider-post-content .watch-rider-ad-space--full-width,
  .watch-rider-post-content .watch-rider-ad-space--interscroll {
    width: var(--wr-ad-page-width, 100%);
    max-width: none;
    margin-inline: calc((100% - var(--wr-ad-page-width, 100%)) / 2);
    border-inline: 0;
  }

  .watch-rider-post-content .watch-rider-ad-space--interscroll {
    display: block;
    margin-block: 0;
    padding: 10px 0 15px;
    border: 0;
    background: transparent;
  }

  .watch-rider-ad-space--interscroll .watch-rider-ad-space__label {
    padding: 4px 15px 3px;
    border: 0;
    font-size: 13px;
    line-height: 1.6;
    letter-spacing: 0;
  }

  .watch-rider-ad-space--interscroll .watch-rider-ad-space__window {
    background: rgba(166, 175, 185, 0.3);
  }

  .watch-rider-ad-space--interscroll .watch-rider-ad-space__stage {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 16px 0;
  }

  .watch-rider-ad-space--interscroll .watch-rider-ad-space__creative {
    flex: 0 0 var(--wr-ad-creative-width, 300px);
    width: var(--wr-ad-creative-width, 300px);
    max-width: 100%;
    line-height: 0;
  }

  .watch-rider-ad-space--interscroll.watch-rider-ad-space--adsense .watch-rider-ad-space__creative {
    min-height: var(--wr-ad-creative-height, 600px);
  }

  .watch-rider-ad-space--interscroll .watch-rider-ad-space__image {
    max-height: min(600px, max(50px, calc(var(--wr-ad-available-height) - 16px)));
  }

  /* Scrolling moves the window, not the creative. No scroll handlers or transforms. */
  @supports (clip-path: inset(0)) {
    @media (prefers-reduced-motion: no-preference) {
      .watch-rider-ad-space--interscroll[data-wr-ad-fixed="1"] .watch-rider-ad-space__window {
        height: var(--wr-ad-visible-height, var(--wr-ad-available-height));
        overflow: hidden;
      }

      .watch-rider-ad-space--interscroll[data-wr-ad-fixed="1"] .watch-rider-ad-space__clip {
        position: absolute;
        inset: 0;
        clip: rect(0, auto, auto, 0);
        clip-path: inset(0);
      }

      .watch-rider-ad-space--interscroll[data-wr-ad-fixed="1"] .watch-rider-ad-space__stage {
        position: fixed;
        inset: var(--wr-ad-top) 0 auto;
        width: var(--wr-ad-page-width, 100%);
        height: var(--wr-ad-visible-height, var(--wr-ad-available-height));
        padding: 0;
      }

      /* Keyboard-focused links must stay reachable, not clipped offscreen. */
      .watch-rider-ad-space--interscroll[data-wr-ad-keyboard="1"]:focus-within .watch-rider-ad-space__window {
        height: auto;
        overflow: visible;
      }

      .watch-rider-ad-space--interscroll[data-wr-ad-keyboard="1"]:focus-within .watch-rider-ad-space__clip,
      .watch-rider-ad-space--interscroll[data-wr-ad-keyboard="1"]:focus-within .watch-rider-ad-space__stage {
        position: static;
        clip: auto;
        clip-path: none;
        height: auto;
      }
    }
  }
}
