/* components/paywall.css — layout for partials/paywall.hbs: the
   membership CTA (components/membership-cta.css), full width at the end of
   a gated post's preview.
   assets/js/paywall.js sets [data-open] while the CTA's button is on
   screen (the page above dims, an X shows) and [data-dismissed] once the
   reader closes it, or already has this session. Without JS it's just the
   box, and the page ends at it. */

/* The page ends at the paywall until it's dismissed. Everything after it
   still renders — the rest of the article (tags, author box), the related
   rails after the article, and default.hbs's ad and footer — and comes
   back on dismissal. */
body:has(.paywall:not([data-dismissed])) :is(
  [data-gated] > .post-content ~ *,
  .post[data-gated] ~ *,
  .ad-break,
  .site-footer
) {
  display: none;
}

/* Out of .post-content's measure to the page edges, like a full-width
   card (body's overflow-x: clip absorbs the scrollbar). Prefixed to beat
   ghost-content.css's .post-content > *, which loads later. */
.post-content > .paywall {
  max-width: 100vw;
  width: 100vw;
  margin-inline: calc(50% - 50vw);
}

/* Over the backdrop, its earlier sibling, on the page colour. Both stay
   under --z-header: the sticky masthead and its menu stay usable.
   --paywall-sheet-pad is also the stacked X's spacing, below. */
.paywall__sheet {
  --paywall-sheet-pad: var(--space-4);

  position: relative;
  z-index: var(--z-sticky);
  padding-block: var(--paywall-sheet-pad);
  background-color: var(--paywall-bg);
}

/* The masthead's width; .post-content has set --container to its own. */
.paywall__inner {
  --container: var(--container-site);
}

/* Visibility waits out the fade, so the dim stops catching clicks only
   once it's gone. */
.paywall__backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-sticky);
  background-color: var(--paywall-backdrop);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--paywall-transition), visibility 0s var(--paywall-transition);
}

.paywall[data-open] .paywall__backdrop {
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}

/* The CTA box: bordered, on the sheet's colour instead of the band's. The
   band's palette is reset because it pins dark text for a light band. */
.membership-cta--paywall {
  --membership-cta-bg: var(--paywall-bg);
  --color-fg: inherit;
  --color-border: inherit;
  --membership-cta-button-hover-fg: var(--color-bg);

  /* The X: its icon, and the button around it (padding included). */
  --paywall-close-icon: 1.25rem;
  --paywall-close-size: calc(var(--paywall-close-icon) + var(--space-3) * 2);

  position: relative;
  margin-block: 0;
}

/* The border is on the grid, not the box: the box is the container, which
   its own container queries can't reach. */
.membership-cta--paywall .membership-cta__inner {
  border: var(--border-width) solid var(--color-border-soft);
}

.membership-cta--paywall .membership-cta__media {
  background-color: var(--paywall-media-bg);
}

.paywall__signin {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}

/* Sized and placed like Portal's close button, which portal-style.js inks
   and fades the same way. Only while the page is dimmed. */
.paywall__close {
  --icon-size: var(--paywall-close-icon);

  display: none;
  position: absolute;
  inset-block-start: var(--space-3);
  inset-inline-end: var(--space-3);
  place-items: center;
  inline-size: var(--paywall-close-size);
  block-size: var(--paywall-close-size);
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-fg);
  cursor: pointer;
  transition: opacity var(--transition);
}

.paywall[data-open] .paywall__close {
  display: grid;
}

@media (hover: hover) {
  .paywall__close:hover {
    opacity: var(--card-hover-opacity);
  }
}

/* Stacked: the X goes in a strip above the bordered grid, at its top
   right, rather than over the engraving. A margin, so the strip is outside
   the border; kept when the X isn't showing, so the box doesn't jump as
   the dim comes and goes. The strip is the icon plus the sheet's padding,
   so the icon has that padding above and below it. */
@container membership-cta (width < 40rem) {
  .membership-cta--paywall .membership-cta__inner {
    margin-block-start: calc(var(--paywall-close-icon) + var(--paywall-sheet-pad));
  }

  /* Tighter than the band, to keep the stacked box short. */
  .membership-cta--paywall .membership-cta__body {
    gap: var(--space-3);
    padding-block: var(--space-5);
  }

  /* Shallower than the band's 3:2, so more of the pitch is above the fold. */
  .membership-cta--paywall .membership-cta__media {
    aspect-ratio: 16 / 9;
  }

  .membership-cta--paywall .membership-cta__image {
    object-position: center;
  }

  /* A step down each, so the pitch fits under the image on a phone. */
  .membership-cta--paywall .membership-cta__title {
    font-size: var(--text-2xl);
  }

  .membership-cta--paywall .membership-cta__text {
    font-size: var(--text-base);
  }

  /* Out by the button's padding, so the icon itself sits at the strip's
     top and the box's edge (the page gutter). */
  .paywall__close {
    inset-block-start: calc(var(--space-3) * -1);
    inset-inline-end: calc(var(--space-3) * -1);
  }
}

/* Image a quarter, not the band's third. */
@container membership-cta (width >= 40rem) {
  .membership-cta--paywall .membership-cta__inner {
    grid-template-columns: minmax(0, 1fr) minmax(0, 3fr);
  }
}

@media (width >= 48rem) {
  .paywall__sheet {
    --paywall-sheet-pad: var(--space-10);
  }
}
