/**
 * OE FANZA Floating Ads
 * Side groups remain outside the centered 1160px page; the bottom group uses
 * five jacket-first columns on desktop and a native horizontal strip on phones.
 */

.oe-fanza-ads {
  --oe-fanza-content-width: 1160px;
  /* 180px at 1600px: 1160px content + 24px gap + 16px viewport edge. */
  --oe-fanza-side-width: clamp(180px, calc(50vw - 620px), 240px);
  --oe-fanza-side-gap: 24px;
  --oe-fanza-side-image-height: clamp(110px, calc((var(--oe-fanza-side-width) - 16px) / 1.45), 150px);
  --oe-fanza-bottom-image-height: clamp(120px, 12vw, 140px);
  --oe-fanza-layer: 40;
  --oe-fanza-ink: #18181b;
  pointer-events: none;
}

.oe-fanza-ads[hidden],
.oe-fanza-ad[hidden],
.oe-fanza-ad__scroll[hidden] {
  display: none !important;
}

.oe-fanza-ad,
.oe-fanza-ad *,
.oe-fanza-ad *::before,
.oe-fanza-ad *::after {
  box-sizing: border-box;
}

.oe-fanza-ad {
  position: fixed;
  z-index: var(--oe-fanza-layer);
  display: none;
  overflow: hidden;
  color: var(--oe-fanza-ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #fff;
  border: 1px solid rgb(24 24 27 / 14%);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgb(0 0 0 / 16%);
  opacity: 1;
  pointer-events: auto;
  transition: opacity 180ms ease;
}

.oe-fanza-ad.is-dismissing {
  opacity: 0;
  pointer-events: none;
}

.oe-fanza-ad__header {
  position: relative;
  display: flex;
  min-height: 44px;
  flex: 0 0 44px;
  align-items: center;
  padding: 0 48px 0 10px;
  border-bottom: 1px solid rgb(24 24 27 / 10%);
}

.oe-fanza-ad__meta {
  margin: 0;
  color: var(--oe-fanza-ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.oe-fanza-ad__works {
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  padding: 6px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.oe-fanza-ad .oe-fanza-ad__list {
  display: grid;
  min-width: 0;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.oe-fanza-ad .oe-fanza-ad__item {
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid rgb(24 24 27 / 10%);
  border-radius: 5px;
}

.oe-fanza-ad__link,
.oe-fanza-ad__media {
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.oe-fanza-ad__link {
  display: flex;
  width: 100%;
  height: 100%;
  flex-direction: column;
  overflow: hidden;
  border-radius: 4px;
}

.oe-fanza-ad__link:hover {
  color: inherit;
  background: #f7f7fa;
}

.oe-fanza-ad__link:focus-visible,
.oe-fanza-ad__works:focus-visible {
  outline: 3px solid #1769e0;
  outline-offset: -3px;
}

.oe-fanza-ad .oe-fanza-ad__image,
.oe-fanza-ad .oe-fanza-ad__media img,
.oe-fanza-ad .oe-fanza-ad__placeholder {
  display: block;
  width: 100% !important;
  min-width: 0 !important;
  flex: 0 0 auto;
  max-width: 100% !important;
  object-fit: contain !important;
  object-position: center;
  background: #f5f5f7;
}

.oe-fanza-ad .oe-fanza-ad__placeholder {
  display: grid;
  place-items: center;
  overflow: hidden;
  color: #777780;
  font-size: 12px;
  line-height: 1.25;
  text-align: center;
  background: linear-gradient(135deg, #f5f5f7, #ececf0);
}

.oe-fanza-ad__body {
  display: flex;
  min-width: 0;
  flex: 1 1 auto;
  align-items: flex-start;
  padding: 4px 6px 6px;
}

.oe-fanza-ad__title {
  display: -webkit-box;
  min-width: 0;
  width: 100%;
  height: 2.6em;
  margin: 0;
  overflow: hidden;
  color: var(--oe-fanza-ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.oe-fanza-ad__close,
.oe-fanza-ad__scroll {
  position: absolute;
  z-index: 3;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  overflow: hidden;
  color: transparent;
  font-size: 0;
  appearance: none;
  cursor: pointer;
  background: rgb(255 255 255 / 96%);
  border: 0;
  touch-action: manipulation;
}

.oe-fanza-ad__close {
  top: 0;
  right: 0;
  border-radius: 0 9px 0 0;
}

.oe-fanza-ad__close::before,
.oe-fanza-ad__close::after {
  position: absolute;
  top: 21px;
  left: 13px;
  width: 18px;
  height: 2px;
  content: "";
  background: #27272a;
  border-radius: 2px;
}

.oe-fanza-ad__close::before {
  transform: rotate(45deg);
}

.oe-fanza-ad__close::after {
  transform: rotate(-45deg);
}

.oe-fanza-ad__close:hover,
.oe-fanza-ad__scroll:hover {
  background: #f0f0f2;
}

.oe-fanza-ad__close:focus-visible,
.oe-fanza-ad__scroll:focus-visible {
  outline: 3px solid #1769e0;
  outline-offset: -3px;
}

.oe-fanza-ad__scroll {
  top: calc(50px + (var(--oe-fanza-bottom-image-height) / 2) - 22px);
  border: 1px solid rgb(24 24 27 / 18%);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgb(0 0 0 / 12%);
}

.oe-fanza-ad__scroll--previous {
  left: 7px;
}

.oe-fanza-ad__scroll--next {
  right: 7px;
}

.oe-fanza-ad__scroll::before {
  position: absolute;
  top: 16px;
  left: 15px;
  width: 10px;
  height: 10px;
  content: "";
  border-top: 2px solid #27272a;
  border-right: 2px solid #27272a;
  transform: rotate(45deg);
}

.oe-fanza-ad__scroll--previous::before {
  left: 18px;
  transform: rotate(-135deg);
}

.oe-fanza-ad__scroll:disabled {
  visibility: hidden;
  pointer-events: none;
}

/* Wide screens: two vertical five-work groups in the page gutters. */
@media screen and (min-width: 1600px) {
  .oe-fanza-ad--left,
  .oe-fanza-ad--right {
    top: 50%;
    display: flex;
    width: var(--oe-fanza-side-width);
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    flex-direction: column;
    transform: translateY(-50%);
  }

  .oe-fanza-ad--left {
    left: max(16px, calc(50% - (var(--oe-fanza-content-width) / 2) - var(--oe-fanza-side-width) - var(--oe-fanza-side-gap)));
  }

  .oe-fanza-ad--right {
    right: max(16px, calc(50% - (var(--oe-fanza-content-width) / 2) - var(--oe-fanza-side-width) - var(--oe-fanza-side-gap)));
  }

  .oe-fanza-ad--left .oe-fanza-ad__works,
  .oe-fanza-ad--right .oe-fanza-ad__works {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .oe-fanza-ad--left .oe-fanza-ad__image,
  .oe-fanza-ad--right .oe-fanza-ad__image,
  .oe-fanza-ad--left .oe-fanza-ad__placeholder,
  .oe-fanza-ad--right .oe-fanza-ad__placeholder {
    /* AFFINGER applies height:auto !important to images. Keep this box bounded. */
    height: var(--oe-fanza-side-image-height) !important;
    min-height: var(--oe-fanza-side-image-height) !important;
    max-height: var(--oe-fanza-side-image-height) !important;
  }

  body.admin-bar .oe-fanza-ad--left,
  body.admin-bar .oe-fanza-ad--right {
    top: calc(50% + 16px);
    max-height: calc(100vh - 80px);
    max-height: calc(100dvh - 80px);
  }
}

/* All screens: five works in one bounded horizontal bottom group. */
@media screen {
  .oe-fanza-ad--bottom {
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 50%;
    display: flex;
    /* Keeping this inside the 1160px content footprint avoids the side groups. */
    width: min(calc(100vw - 32px), var(--oe-fanza-content-width));
    max-height: calc(100vh - 36px - env(safe-area-inset-bottom));
    max-height: calc(100dvh - 36px - env(safe-area-inset-bottom));
    flex-direction: column;
    transform: translateX(-50%);
  }

  .oe-fanza-ad--bottom .oe-fanza-ad__works {
    overflow: auto;
  }

  .oe-fanza-ad--bottom .oe-fanza-ad__list {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 6px;
  }

  .oe-fanza-ad--bottom .oe-fanza-ad__image,
  .oe-fanza-ad--bottom .oe-fanza-ad__placeholder {
    height: var(--oe-fanza-bottom-image-height) !important;
    min-height: var(--oe-fanza-bottom-image-height) !important;
    max-height: var(--oe-fanza-bottom-image-height) !important;
  }

  .oe-fanza-ad--bottom .oe-fanza-ad__title {
    font-size: 12px;
  }

  body.oe-fanza-ads-has-bottom {
    padding-bottom: calc(var(--oe-fanza-existing-body-padding-bottom, 0px) + var(--oe-fanza-bottom-offset, 0px));
    scroll-padding-bottom: calc(var(--oe-fanza-existing-body-scroll-padding-bottom, 0px) + var(--oe-fanza-bottom-offset, 0px));
  }

  html.oe-fanza-ads-has-bottom {
    scroll-padding-bottom: calc(var(--oe-fanza-existing-root-scroll-padding-bottom, 0px) + var(--oe-fanza-bottom-offset, 0px));
  }
}

/* Phones: large jackets above the title; all five remain touch/keyboard accessible. */
@media screen and (max-width: 767.98px) {
  .oe-fanza-ad--bottom {
    --oe-fanza-bottom-image-height: 116px;
    bottom: env(safe-area-inset-bottom);
    width: min(calc(100vw - 16px), 720px);
    border-radius: 8px 8px 0 0;
  }

  .oe-fanza-ad--bottom .oe-fanza-ad__works {
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 6px;
    -webkit-overflow-scrolling: touch;
  }

  .oe-fanza-ad--bottom .oe-fanza-ad__list {
    display: flex;
    gap: 10px;
  }

  .oe-fanza-ad--bottom .oe-fanza-ad__item {
    flex: 0 0 178px;
    scroll-snap-align: start;
  }

  .oe-fanza-ad--bottom .oe-fanza-ad__link {
    height: 100%;
    flex-direction: column;
    padding: 3px;
  }

  .oe-fanza-ad--bottom .oe-fanza-ad__image,
  .oe-fanza-ad--bottom .oe-fanza-ad__placeholder {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: var(--oe-fanza-bottom-image-height) !important;
    min-height: var(--oe-fanza-bottom-image-height) !important;
    max-height: var(--oe-fanza-bottom-image-height) !important;
    border-radius: 3px;
  }

  .oe-fanza-ad--bottom .oe-fanza-ad__body {
    padding: 4px 3px 2px;
  }

  .oe-fanza-ad--bottom .oe-fanza-ad__title {
    font-size: 12px;
  }
}

/* Small screens: the existing content-end group occupies normal document flow. */
@media screen and (max-width: 1023.98px) {
  .oe-fanza-ad--bottom {
    position: relative;
    left: auto;
    bottom: auto;
    width: min(100%, 720px);
    max-height: none;
    margin: 24px auto;
    border-radius: 8px;
    z-index: auto;
    transform: none;
  }
}

/* Short desktop viewports retain reading space above the fixed group. */
@media screen and (min-width: 1024px) and (max-height: 500px) {
  .oe-fanza-ad--bottom {
    --oe-fanza-bottom-image-height: clamp(48px, 16vh, 80px);
    --oe-fanza-bottom-image-height: clamp(48px, 16dvh, 80px);
  }

  .oe-fanza-ad--bottom .oe-fanza-ad__title {
    height: 1.3em;
    font-size: 11px;
    -webkit-line-clamp: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .oe-fanza-ad {
    transition: none;
  }
}

@media print {
  .oe-fanza-ads,
  .oe-fanza-ad {
    display: none !important;
  }

  body.oe-fanza-ads-has-bottom {
    padding-bottom: var(--oe-fanza-existing-body-padding-bottom, 0px);
  }
}

.oe-fanza-page-notice {
  margin: 0 0 12px;
  color: #5b6066;
  font-size: 13px;
  line-height: 1.6;
}

.oe-fanza-site-credit {
  clear: both;
  margin: 16px auto;
  text-align: center;
  line-height: 1;
}

.oe-fanza-site-credit img {
  display: inline-block;
  width: 135px;
  height: 17px;
  max-width: 100%;
}
