.sim-ad {
  position: fixed;
  z-index: 5;
  left: 50%;
  margin: 0;
  padding: 0;
  transform: translateX(-50%);
}

html[data-sim-ads] {
  --sim-ad-motion: 240ms cubic-bezier(.2,.75,.25,1);
  --sim-ad-close-delay: 4s;
}

.sim-ad-anchor.sim-ad-filled:not([hidden]) {
  z-index: 8;
  animation: sim-ad-anchor-reveal var(--sim-ad-motion) both;
}

.sim-ad-anchor > div {
  display: grid;
  place-items: end center;
}

.sim-ad-anchor { pointer-events: none; }
.sim-ad-anchor.sim-ad-filled:not(.sim-ad-closing) > button,
.sim-ad-anchor.sim-ad-filled:not(.sim-ad-closing) > div > * {
  pointer-events: auto;
}

#np-int-closer.sim-ad-close-loading {
  visibility: hidden !important;
}

#np-int-closer.sim-ad-close-delay,
.sim-ad-anchor.sim-ad-filled:not([hidden],.sim-ad-closing) > button {
  animation: sim-ad-hide-close var(--sim-ad-close-delay) step-end;
}

@keyframes sim-ad-hide-close {
  from, to { visibility: hidden; }
}

/* Keep the game frame fixed and clear the controls nearest the anchor. */
html[data-sim-ad-anchor-visible] #game #banner :is(#bannerInfo,#ledger,#bannerRates) {
  top: min(91.7593%,calc(100% - var(--sim-ad-anchor-clearance) - 2.71cqw));
}
html[data-sim-ad-anchor-large] #game #banner #buttons {
  top: calc(-1 * var(--sim-ad-anchor-clearance) - 4.5cqw);
}
@container (max-width: 1200px) {
  html[data-sim-ad-anchor-visible] #game #banner #buttons { top: calc(-56px - 4.5cqw); }
  html[data-sim-ad-anchor-visible] #game #banner #bannerRail { bottom: max(14%,56px); }
}

.sim-ad-anchor.sim-ad-closing:not([hidden]) {
  animation-direction: reverse;
  animation-name: sim-ad-anchor-dismiss;
  pointer-events: none;
}

@keyframes sim-ad-anchor-reveal {
  from { transform: translate(-50%, 100%); clip-path: inset(-52px -52px 100% -52px); opacity: 0; }
  to { transform: translateX(-50%); clip-path: inset(-52px -52px 0 -52px); opacity: 1; }
}

@keyframes sim-ad-anchor-dismiss {
  from { transform: translate(-50%, 100%); clip-path: inset(-52px -52px 100% -52px); opacity: 0; }
  to { transform: translateX(-50%); clip-path: inset(-52px -52px 0 -52px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .sim-ad-anchor:is(.sim-ad-filled,.sim-ad-closing):not([hidden]) { animation: none; }
}

.sim-ad > button {
  position: absolute;
  right: calc(50% - 22px);
  bottom: calc(100% + 4px);
  width: 44px;
  height: 44px;
  padding: 0;
  background: #19191e;
  color: #fff;
  border: 1px solid #aaa;
  border-radius: 6px;
}

.sim-ad-close-side > button {
  left: calc(50% + var(--sim-ad-creative-width, 100%)/2 + 4px);
  right: auto;
  bottom: 0;
}

.sim-ad-empty,
.sim-ad:not(.sim-ad-filled) > button,
html:has(:fullscreen) .sim-ad {
  visibility: hidden;
  pointer-events: none;
}

.sim-ad:not(.sim-ad-filled) {
  pointer-events: none;
}

.sim-ad-native-rail,
.sim-ad-native-rail > [id^="p5x-sim-wide-"],
.sim-ad-native-rail iframe {
  background-color: transparent !important;
}

html:not([data-sim-ad-rail-size="300x600"]) .sim-ad-native-rail-300x600,
html:not([data-sim-ad-rail-size="160x600"]) .sim-ad-native-rail-160x600,
html:not([data-sim-ad-rail-size="300x250"]) .sim-ad-native-rail-300x250,
html:has(:fullscreen) .sim-ad-native-rail {
  display: none !important;
}

#np-int-modal:has(> .sim-ad-interstitial-progress, #np-int-closer.sim-ad-close-delay) {
  position: relative;
}

#np-int-modal:has(#np-int-closer.sim-ad-close-delay)::after {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  z-index: 2;
  height: 4px;
  background: #261d12 linear-gradient(#ffd84d 0 0) left center / 0% 100% no-repeat;
  box-shadow: 0 1px 2px #0009;
  visibility: hidden;
  pointer-events: none;
  animation: sim-ad-close-progress var(--sim-ad-close-delay) linear;
}

@keyframes sim-ad-close-progress {
  from { background-size: 0% 100%; visibility: visible; }
  to { background-size: 100% 100%; visibility: visible; }
}

@media (prefers-reduced-motion: reduce) {
  #np-int-modal:has(#np-int-closer.sim-ad-close-delay)::after {
    animation-timing-function: steps(4, end);
  }
}

.sim-ad-interstitial-progress {
  position: absolute;
  inset: auto 0 0;
  width: 100%;
  height: 4px;
  padding: 0;
  border: 0;
  overflow: hidden;
  border-radius: 0 0 5px 5px;
  appearance: none;
  background: #e4e0e3;
  color: #bc1638;
  pointer-events: none;
}

.sim-ad-interstitial-progress::-webkit-progress-bar { background: #e4e0e3; }
.sim-ad-interstitial-progress::-webkit-progress-value { background: #bc1638; }
.sim-ad-interstitial-progress::-moz-progress-bar { background: #bc1638; }

.sim-ad-records {
  inset: auto 0 max(8px, env(safe-area-inset-bottom));
  width: max-content;
  height: max-content;
  margin: 0 auto;
  border: 0;
  background: transparent;
  overflow: visible;
  transform: none;
}

#records[data-history-ad] footer {
  translate: 0 calc(-1 * var(--history-ad-overlap, 0px));
}

#records[data-history-ad] #recordPity {
  margin-top: calc(-1 * var(--history-ad-overlap, 0px));
}

#records[data-history-ad] section {
  bottom: calc(22.96% + var(--history-ad-overlap, 0px));
}

@media (max-width: 580px) and (orientation: portrait) {
  #records[data-history-ad] section {
    bottom: calc(26% + var(--history-ad-overlap, 0px));
  }
}

#records[data-history-ad] ~ #panel.ledgerPanel {
  inset-block-end: var(--history-ad-reserve, 0px);
  max-height: calc(100dvh - 24px - var(--history-ad-reserve, 0px));
}
