/*
 * promo.css — the site's one ad slot: a small square pinned to the
 * bottom-right corner of the viewport.
 *
 * Named `promo`, not `ads`, throughout — the file, the classes, the data
 * attributes. Filter lists match on exactly those strings, and this script is
 * what reveals the box, so a blocked `ads.js` would have meant selling
 * impressions that are never delivered. The reader is still told plainly what
 * the square is: it carries a visible label and paid links carry
 * rel="sponsored".
 *
 * It is a standalone stylesheet rather than a block in assets/sass/_custom.sass
 * because layouts/_default/course.html bypasses baseof.html and never loads the
 * theme's bundle. The slot has to look the same on an article and on a course,
 * so it carries its own styles and the partial links them.
 *
 * The box ships hidden and assets/js/promo.js reveals it. That keeps it from
 * flashing unstyled while this file loads, and it is why a reader with no
 * JavaScript sees no slot at all.
 */

.promo-slot {
  position: fixed;
  right: 16px;
  /* The corner is shared. Every page built from baseof.html also puts the
     theme's back-to-top button here, and the slot is the one on top, so those
     pages raise the slot clear of it by setting --promo-slot-bottom in
     assets/sass/_custom.sass. That stylesheet is loaded by baseof and by
     nothing else, which is exactly the set of pages with such a button; a
     course page has none and keeps the default. */
  bottom: var(--promo-slot-bottom, 16px);
  /* Above the site chrome (the theme's header sits at 999) and below the
     trainers' modal overlays (999999), which must stay reachable. */
  z-index: 9000;
  width: clamp(120px, 10vw, 160px);
  display: none;
}

/* Desktop and laptop only: below 1024px there is no room for a floating box
   beside the text.
   
   The height gate is 480px and was 600px, which was wrong by a wide margin. A
   CSS viewport is not the screen: browser chrome takes 87px before a
   bookmarks bar, and OS display scaling takes the rest — a 1920x1080 screen
   at 175% is 1097x617 CSS pixels, so its viewport lands near 530 and the
   square disappeared on an ordinary desktop. 480px still excludes a genuinely
   squashed window while admitting every scaled screen. */
@media (min-width: 1024px) and (min-height: 480px) {
  .promo-slot:not([hidden]) {
    display: block;
    animation: promo-slot-in 0.4s var(--ease, ease-out) both;
  }
}

@keyframes promo-slot-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .promo-slot:not([hidden]) { animation: none; }
}

.promo-slot_unit {
  position: relative;
  aspect-ratio: 1 / 1;
  box-sizing: border-box;
  /* $bg from the theme's _variables.sass — the dark the site's header and the
     course top bar both carry. */
  background: #fff;
  color: #002538;
  border: 1px solid rgba(0, 37, 56, 0.18);
  border-radius: 4px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.16);
  font-family: Metropolis, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  text-align: center;
  overflow: hidden;
}

/* --- the house ad -------------------------------------------------------
   What the square holds when no campaign matches the page, when the manifest
   cannot be fetched, or when a creative fails to load. The box is never
   empty and never broken.

   White on dark blue, and it reads "yuval.guide courses" — it is not an
   advertisement to be disclosed but the site pointing at its own courses, so
   it wears the site's own colour rather than a neutral card. $bg from the
   theme's _variables.sass, the dark the header and the course top bar carry.

   It paints its own background over .promo-slot_unit, so it looks the same
   in light and dark mode. The unit's white stays underneath for a campaign's
   creative to sit on. */

.promo-slot_house {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2em;
  padding: 12px 10px 10px;
  background: #002538;
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease;
}

.promo-slot_house:hover,
.promo-slot_house:focus-visible {
  background: #00344e;
}

@media (prefers-reduced-motion: reduce) {
  .promo-slot_house { transition: none; }
}

/* `display: flex` above is an author rule and `[hidden]` is a user-agent one,
   so the class wins and hiding the house ad in script did nothing: when a
   campaign rendered, the house stayed in the layout underneath it — invisible
   behind an opaque creative, and showing through a transparent one. It also
   stayed in the accessibility tree, so a screen reader announced both. */
.promo-slot_house[hidden] { display: none; }

.promo-slot_brand {
  font-size: clamp(11px, 1.05vw, 15px);
  font-weight: 700;
  letter-spacing: 0.01em;
  /* The site name is a Latin-script mark in both languages. */
  direction: ltr;
}

/* "courses" — the thing being offered, so it is read, not whispered. It was
   the word "ads" at 0.7 opacity when this was a disclosure label. */
.promo-slot_word {
  font-size: clamp(10px, 0.85vw, 13px);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: lowercase;
  opacity: 0.85;
}

/* --- a campaign ---------------------------------------------------------
   The link IS the click shield. A customer's HTML creative runs in a
   sandboxed iframe that can neither navigate this page nor be listened to
   from it, so the iframe is made inert with pointer-events and the anchor
   around it takes every click. One code path for both creative kinds: the
   parent owns the click and can measure it. */

.promo-slot_link {
  position: absolute;
  inset: 0;
  display: none;
  text-decoration: none;
  color: inherit;
}

.promo-slot_link[href] { display: block; }

.promo-slot_media {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  object-fit: contain;
  background: #fff;
}

iframe.promo-slot_media {
  /* Inert on purpose — see the note above. Without this the frame swallows
     the click and the anchor never fires. */
  pointer-events: none;
}

/* The disclosure strip. It sits over the creative and lets clicks through to
   the anchor beneath, so it never becomes a dead patch on a paid square. */
.promo-slot_label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 2px 4px;
  font-size: 9px;
  line-height: 1.4;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #002538;
  background: rgba(255, 255, 255, 0.82);
  pointer-events: none;
}

.promo-slot_label:empty { display: none; }

/* --- the close button ---------------------------------------------------
   It carries more weight than its size suggests. The corner is empty on
   nearly every page, but on a course the square can land on top of a long
   inspector or variables pane — and then closing it is the only way to read
   what is underneath. So it is a visible, filled control rather than a faint
   hairline, big enough to hit without aiming, and ::before widens the target
   another 8px in each direction beyond what is drawn. */

.promo-slot_close {
  position: absolute;
  top: 4px;
  right: 4px;
  /* Above the creative and its click shield, or a full-bleed image would bury
     the one control that dismisses it. */
  z-index: 2;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.86);
  color: #002538;
  opacity: 0.85;
  cursor: pointer;
  line-height: 0;
}

.promo-slot_close::before {
  content: "";
  position: absolute;
  inset: -8px;
}

.promo-slot_close:hover,
.promo-slot_close:focus-visible {
  opacity: 1;
  background: #fff;
}

.promo-slot_close:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 1px;
}

.promo-slot_close svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  fill: none;
}

/* Dark mode: the house square keeps the same two colours, swapped, so a white
   block does not glare out of a dark page. A campaign's own creative is left
   alone — it is the advertiser's artwork, not ours to invert. Course pages
   never set data-mode (that layout has no theme toggle and its shell is
   light), so they always get the light square. */
html[data-mode="dim"] .promo-slot_unit {
  background: #002538;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
}
