/**
 * AdSense manual placements (settings.ADSENSE_SLOTS). The same units and rules
 * as sites/imperialismmap/static/css/adsense.css, whose comments record the
 * measurements behind them; the checks in core/ads/ run against both files.
 * Matchup Index runs the prime trio, in-article, multiplex and the gutter rails
 * (the venue sidebar rectangle and the home in-content unit are VenueStats-only).
 *
 * Reserved heights are the height adsbygoogle.js writes on the <ins> at push,
 * so a filled or unfilled slot does not move the page. For a responsive
 * display unit (data-ad-format="auto") Google picks it from the slot's width
 * alone: 280px from 336px wide, 250px below. The column is the viewport less
 * the 20px .section-shell gutter each side, as on ImperialismMap, so the slot
 * is under 336px wide at a 375px viewport and below.
 */

.ad-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 1.5rem auto;
    overflow: hidden;
    /* reason: the slot is a fixed box with a responsive unit inside it, the
       standard both sites follow (sites/imperialismmap/docs/design/decisions.md,
       2026-10-11). Without the clip, Google's mobile "Ad size optimization"
       (answer 9139818) lets an unpinned unit spill past the box toward the
       viewport width on a phone (measured on ImperialismMap, task-363). The
       clip keeps every unit to the box it was given; it never cuts a
       creative, because Google sizes the unit to the box it sees. */
    /* Never shrink-to-fit: as a flex item, a container sized to its content
       (a width:100% <ins>) resolves to 0 wide, and a 0-wide unit never loads. */
    width: 100%;
}

/* A responsive <ins> is itself a flex item and shrinks to 0 the same way.
   The pinned units are listed too, for the widths their pin leaves to the
   container. */
.ad-billboard ins.adsbygoogle,
.ad-top-display ins.adsbygoogle,
.ad-top-display-mobile ins.adsbygoogle,
.ad-in-article ins.adsbygoogle,
.ad-rail ins.adsbygoogle,
.ad-multiplex ins.adsbygoogle {
    width: 100%;
}

.ad-container ins.adsbygoogle {
    background-color: transparent;
}

/* Prime banners (pinned), as on ImperialismMap. Billboard from 1024px, capped
   at 970px so it asks for 970x280; top-display from 768px; top-display-mobile
   below 768px, 250px tall at 375px and below (the end of this file). Each
   min-height equals its pin, the reservation for an ad-blocked slot. */
.ad-billboard {
    display: none;
    min-height: 280px;
    max-width: 970px;
}

@media (min-width: 1024px) {
    .ad-billboard {
        display: flex;
    }
}

.ad-top-display {
    display: none;
    min-height: 280px;
    max-width: 100%;
}

@media (min-width: 768px) {
    .ad-top-display {
        display: flex;
    }
}

.ad-top-display-mobile {
    display: flex;
    min-height: 280px;
    max-width: 100%;
}

@media (min-width: 768px) {
    .ad-top-display-mobile {
        display: none;
    }
}

/* A prime slot (.ad-prime, under a hub's map) stacks all three and lets the
   breakpoints pick one. Without this the billboard and top-display would both
   show from 1024px. The <ins> is hidden as well as its container: push({})
   requests an ad for a unit hidden only by an ancestor
   (core/templates/core/ads/_ad_loader.js). */
@media (min-width: 1024px) {
    .ad-prime .ad-top-display,
    .ad-prime .ad-top-display ins.adsbygoogle {
        display: none;
    }
}

/* In-article (fluid), all widths. About width / 1.2 while the slot is under
   ~462px wide, then 280px (sites/imperialismmap/static/css/adsense.css). */
.ad-in-article {
    min-height: 280px;
    min-width: 250px;   /* Google's minimum for a fluid unit */
    width: 100%;
    max-width: 100%;
}

@media (max-width: 500px) {
    /* The slot is the viewport less the 40px gutter; +1px rounds Google's
       pixel height up so the reservation never falls short of it. */
    .ad-in-article {
        min-height: max(250px, calc((100vw - 40px) / 1.2 + 1px));
    }
}

@media (max-width: 375px) {
    .ad-top-display-mobile {
        min-height: 250px;
    }
}

/* Multiplex, all widths. Reserves only a little: Google's grid is 580px on
   desktop and far taller on a phone, a blank screen for ad-blocking readers. */
.ad-multiplex {
    min-height: 250px;
    max-width: 100%;
}

/* An unfilled display slot keeps its box: collapsing it would move the page
   under the reader. It shows its house ad instead (core/static/core/css/house_ad.css).
   Multiplex is the exception when it has no house ad. It loads only once on
   screen, at the page bottom, so its collapse moves little more than the
   footer; one that carries a house ad (the default) keeps its 250px box and
   shows it. https://support.google.com/adsense/answer/10762946 */
.ad-container.ad-multiplex:has(ins.adsbygoogle[data-ad-status="unfilled"]):not(:has(.house-ad)) {
    display: none;
}

/* Gutter rails (pinned), wide desktop only, as on ImperialismMap: a 160x600
   from 1640px and a 300x600 from 1920px (settings.ADSENSE_SLOTS 'rail'). The
   rail's inner edge sits at 50% + 640px, 20px outside the 1200px
   .section-shell plus its 20px padding, so a rail of width W needs a viewport
   of 2 * (640 + W + 20): 1640px for 160, 1920px for 300. Below 1640px the
   pinned-size block hides the <ins> itself, so no request goes out. */
.side-rail { display: none; }

@media (min-width: 1640px) {
    .side-rail {
        display: block;
        position: fixed;
        top: 50%;
        transform: translateY(-50%);
        width: 160px;
        z-index: 15;
    }
    /* Hug the content shell, so extra gutter falls toward the viewport edge. */
    .side-rail--left { right: calc(50% + 640px); }
    .side-rail--right { left: calc(50% + 640px); }
}

/* The rail's own box: shown over the same range as its <ins> (test_adsense.py
   checks the two agree), with no margin, and reserving the pinned 600px. */
.ad-rail {
    display: none;
    margin: 0;
    min-height: 600px;
}

@media (min-width: 1640px) {
    .ad-rail {
        display: flex;
    }
}

@media (min-width: 1920px) {
    .side-rail { width: 300px; }
}

/* The 160px rail is the narrowest box a house ad fills. */
.side-rail .house-ad__body {
    padding: var(--space-3);
}

.side-rail .house-ad__name {
    font-size: var(--type-lg);
}

/* DEBUG only: the empty box _adsense_unit.html renders in place of a unit. */
.ad-placeholder {
    border: 1px dashed var(--border);
    border-radius: var(--radius-xs);
    background-color: var(--surface);
}

.ad-placeholder__label {
    font-family: var(--font-body);
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}
