/*
 * Promotion boxes (app/lib/promo.php, docs/promo.md): themes/modern/partials/promo-box.twig. Loaded by the first box of
 * a page only. Colors come from the scheme tokens, so every palette (light/dark) styles them; the --promo-* tokens are
 * aliases that dev/palette-contrast.py checks (text on each tint).
 * Placements: below_banners / home / topic_after_first_post (card), top_bar (slim strip), sidebar (narrow card),
 * modal (<dialog>). Device targeting: .promo-only-mobile / .promo-only-desktop (CSS only, no UA sniffing).
 */
:root {
  --promo-tint-info: var(--info-soft);
  --promo-tint-feature: var(--accent-soft);
  --promo-tint-warning: var(--warn-soft);
  --promo-tint-celebration: var(--ok-soft);
}

.promo {
  --promo-c: var(--info);
  --promo-tint: var(--promo-tint-info);
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3) var(--space-4);
  margin: var(--space-4) 0;
  padding: var(--space-4) var(--space-5);
  padding-right: calc(var(--space-5) + 28px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(100deg, var(--promo-tint) 0, var(--surface) 46%) border-box;
  box-shadow: var(--shadow);
  color: var(--text);
  overflow: hidden;
}
.promo::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--promo-c);
}
.promo-feature { --promo-c: var(--accent); --promo-tint: var(--promo-tint-feature); }
.promo-warning { --promo-c: var(--warn); --promo-tint: var(--promo-tint-warning); }
.promo-celebration { --promo-c: var(--ok); --promo-tint: var(--promo-tint-celebration); }
.promo-celebration::before { background: linear-gradient(180deg, var(--accent), var(--ok), var(--info)); }

.promo-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: var(--promo-tint);
  color: var(--promo-c);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--promo-c) 22%, transparent);
}
.promo-icon .icon { width: 22px; height: 22px; }
.promo-emoji { font-size: 24px; line-height: 1; }
.promo-image { display: block; width: 72px; height: 72px; object-fit: cover; border-radius: var(--radius); }
.promo-text { min-width: 0; }
.promo-kicker {
  display: inline-block;
  margin: 0 0 2px;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  background: var(--promo-tint);
  color: var(--promo-c);
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.promo-title { margin: 0; font-size: var(--fs-md); font-weight: 680; line-height: var(--lh-tight); text-wrap: balance; }
.promo-body { margin: 4px 0 0; color: var(--text-2); font-size: var(--fs-sm); line-height: var(--lh); }
.promo-body a { color: var(--link); }
.promo-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--space-2) var(--space-3); }
.promo-cta { white-space: nowrap; }
.promo-link2 { color: var(--text-2); font-size: var(--fs-sm); text-decoration: underline; text-underline-offset: 2px; }
.promo-link2:hover { color: var(--text); }
.promo-close {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.promo-close:hover { background: var(--surface-2); color: var(--text); }
.promo-close:focus-visible, .promo-cta:focus-visible, .promo-link2:focus-visible { outline: 2px solid var(--promo-c); outline-offset: 2px; }
.promo-close .icon { width: 16px; height: 16px; }
.promo[hidden] { display: none !important; }

/* under the ad band: the page container */
.promo-wrap { margin-top: var(--space-4); }
.promo-wrap .promo { margin: 0; }

/* topic: between the first post and the rest */
.posts > .promo { margin: var(--space-4) 0; }

/* top bar: one slim line above the header */
.promo-top-bar {
  grid-template-columns: auto minmax(0, 1fr) auto;
  margin: 0;
  padding: 6px max(16px, env(safe-area-inset-right, 0px)) 6px max(16px, env(safe-area-inset-left, 0px));
  padding-right: 48px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  box-shadow: none;
  background: var(--promo-tint);
}
.promo-top-bar::before { display: none; }
.promo-top-bar .promo-icon { width: 26px; height: 26px; background: transparent; box-shadow: none; }
.promo-top-bar .promo-icon .icon { width: 18px; height: 18px; }
.promo-top-bar .promo-text { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
.promo-top-bar .promo-title { font-size: var(--fs-sm); }
.promo-top-bar .promo-body { margin: 0; font-size: var(--fs-sm); }
.promo-top-bar .promo-image, .promo-top-bar .promo-kicker { display: none; }
.promo-top-bar .promo-cta { min-height: 28px; padding: 0 10px; font-size: var(--fs-sm); }
.promo-top-bar .promo-close { top: 50%; transform: translateY(-50%); width: 28px; height: 28px; }

/* sidebar: narrow, stacked */
.promo-sidebar { grid-template-columns: auto minmax(0, 1fr); padding: 16px 18px; padding-right: 40px; margin: 0 0 var(--space-4); }
.promo-sidebar .promo-actions { grid-column: 1 / -1; justify-content: flex-start; }
.promo-sidebar .promo-image { grid-column: 1 / -1; width: 100%; height: auto; max-height: 140px; }

/* the modal: a centered dialog over a dimmed page */
dialog.promo-modal {
  display: none;
  max-width: min(520px, calc(100vw - 32px));
  width: 100%;
  margin: auto;
  padding: var(--space-6);
  padding-right: calc(var(--space-6) + 24px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  grid-template-columns: auto minmax(0, 1fr);
}
dialog.promo-modal[open] { display: grid; }
dialog.promo-modal::backdrop { background: var(--backdrop, rgba(10, 12, 16, .55)); backdrop-filter: blur(2px); }
dialog.promo-modal .promo-actions { grid-column: 1 / -1; justify-content: flex-start; margin-top: var(--space-2); }
dialog.promo-modal .promo-image { grid-column: 1 / -1; width: 100%; height: auto; max-height: 220px; }
dialog.promo-modal .promo-title { font-size: var(--fs-lg); }

/* phones: stack the actions under the text */
@media (max-width: 640px) {
  .promo:not(.promo-top-bar) { grid-template-columns: auto minmax(0, 1fr); align-items: start; padding: var(--space-4); padding-right: 40px; }
  .promo:not(.promo-top-bar) .promo-icon { width: 36px; height: 36px; }
  .promo:not(.promo-top-bar) .promo-icon .icon { width: 18px; height: 18px; }
  .promo:not(.promo-top-bar) .promo-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .promo:not(.promo-top-bar) .promo-cta { flex: 1 1 auto; justify-content: center; }
  .promo-image { width: 56px; height: 56px; }
  .promo-top-bar .promo-body { display: none; }
}

/* device targeting */
@media (max-width: 719.98px) { .promo-only-desktop { display: none !important; } }
@media (min-width: 720px) { .promo-only-mobile { display: none !important; } }
/* "touch": phones and tablets in a normal browser; never a mouse computer, never the installed app (app-mode.js sets html.es-app) */
@media (hover: hover) and (pointer: fine) { .promo-only-touch, .promo-wrap:has(> .promo-only-touch) { display: none !important; } }
@media (display-mode: standalone) { .promo-only-touch, .promo-wrap:has(> .promo-only-touch) { display: none !important; } }
html.es-app .promo-only-touch, html.es-app .promo-wrap:has(> .promo-only-touch) { display: none !important; }

@media (prefers-reduced-motion: no-preference) {
  .promo:not(.promo-modal) { animation: promo-in var(--dur, .2s) var(--ease, ease-out) both; }
  @keyframes promo-in { from { opacity: 0; } to { opacity: 1; } }
}
