.l-sidebar .utugi-psynaut-banner {
  width: 100%;
  margin: 28px 0 0;
  padding: 2px;
  box-sizing: border-box;
  border: 0;
  box-shadow: none;
}
.utugi-psynaut-banner__link,
.utugi-psynaut-banner picture {
  display: block;
  border: 0;
  box-shadow: none;
}
.utugi-psynaut-banner img {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
  aspect-ratio: 1 / 2;
  margin: 0;
  padding: 0;
  border: 0;
  /* Hide the faint frame baked into the image without changing its content. */
  clip-path: inset(2px);
}
.utugi-psynaut-banner__link:focus-visible {
  outline: 2px solid var(--modern-ink, #242925);
  outline-offset: 4px;
}
@media (max-width: 1023px) {
  .l-sidebar .utugi-psynaut-banner {
    width: calc(100% + 2 * var(--site-frame-padding, 28px));
    margin-inline: calc(-1 * var(--site-frame-padding, 28px));
  }
  .utugi-psynaut-banner img {
    aspect-ratio: 4 / 1;
  }
}

/* Use the existing sidebar h2 styling, with its normal content gap. */
.l-sidebar #utugi-advertisement-heading + .utugi-psynaut-banner {
  margin-top: 0;
}

/* Keep the frame close to the final sidebar banner, retaining line clearance. */
.l-wrapper:has(> .l-sidebar .utugi-psynaut-banner) {
  padding-bottom: 2px;
}

/* The advertisement always shares the sticky region with any visible TOC. */
@media (min-width: 1024px) {
  .l-sidebar .widgetSticky:has(> .utugi-psynaut-banner) {
    position: sticky !important;
    top: 84px !important;
    bottom: auto !important;
    width: 100% !important;
    max-height: calc(100dvh - 112px);
    overflow: hidden auto;
    scrollbar-width: thin;
  }
}
@media (max-width: 1023px) {
  .l-sidebar .widgetSticky:has(> .utugi-psynaut-banner) {
    position: static !important;
    top: auto !important;
    width: 100% !important;
    max-height: none;
    overflow: visible;
  }
}

@media (min-width: 1024px) {
  .l-wrapper > .l-sidebar:has(.widgetSticky > .utugi-psynaut-banner) {
    align-self: stretch;
  }
}

/* Article sidebar: reserve the advertisement first; scroll only the TOC list. */
@media (min-width: 1024px) {
  .l-sidebar .widgetSticky.utugi-sticky-split {
    position: sticky !important;
    top: 84px !important;
    bottom: auto !important;
    width: 100% !important;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    min-height: 0;
    max-height: calc(100dvh - 112px);
    overflow: visible !important;
  }
  .l-sidebar .widgetSticky.utugi-sticky-split:has(.ez-toc-widget-container) {
    height: calc(100dvh - 112px);
  }
  .utugi-sticky-split > .utugi-sticky-toc {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }
  .utugi-sticky-split > .utugi-sticky-toc:not(:has(> *)) {
    display: none;
  }
  .utugi-sticky-split .utugi-sticky-toc > .widget {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    overflow: hidden;
  }
  .utugi-sticky-split .utugi-sticky-toc .ez-toc-widget-container {
    position: static !important;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    max-height: none;
    overflow: hidden;
  }
  .utugi-sticky-split .utugi-sticky-toc .ez-toc-widget-container > h2 {
    flex: 0 0 auto;
  }
  .utugi-sticky-split .utugi-sticky-toc .ez-toc-widget-container > nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    scrollbar-width: thin;
    padding-right: 6px;
    padding-bottom: 2px;
  }
  .utugi-sticky-split > .utugi-sticky-ad {
    display: flow-root;
    min-width: 0;
  }
  .l-sidebar .utugi-sticky-ad > #utugi-advertisement-heading {
    margin-top: 14px;
  }
  .l-sidebar .utugi-sticky-ad > .utugi-psynaut-banner--square {
    width: min(100%, max(120px, calc(100dvh - 280px)));
    margin-inline: auto;
  }
  .utugi-psynaut-banner--square img {
    aspect-ratio: 1 / 1;
  }
}
@media (max-width: 1023px) {
  .l-sidebar .widgetSticky.utugi-sticky-split {
    display: block;
    position: static !important;
    top: auto !important;
    width: 100% !important;
    height: auto;
    max-height: none;
    overflow: visible !important;
  }
}
