@media screen and (max-width: 1024px) {
  #back-to-top-button,
  #back-to-top-button a {
    display: none !important;
    visibility: hidden !important;
  }
}

#back-to-top-button {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
}

#back-to-top-button a {
  display: block;
  width: 56px;
  height: 56px;
  line-height: 56px;
  text-align: center;
  border-radius: 50%;
  background: #333;
  color: #fff !important;
  text-decoration: none;
  font-size: 26px;
}

/* 掲示板では右下のボタンは表示しない */
body:has(form[action*="/forum/thread/"]) #back-to-top-button,
body:has(form[action*="/forum/comment"]) #back-to-top-button,
body:has(a[href*="/kaedeno/forum/thread/"]):has(textarea) #back-to-top-button {
  display: none !important;
  visibility: hidden !important;
}

/* afを幅の広い画面で追従させる */
@media screen and (min-width: 960px) {
  /* 左メニューの高さを本文に合わせる */
  #atwiki-jp-bg2 .atwiki-container > .atwiki-left-column {
    align-self: stretch;
    display: flex;
    flex-direction: column;
  }

  #menubar {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  #menubar > .atwiki-contents {
    flex: 1 1 auto;
    overflow: visible;
  }

  /* アフィリエイト部分だけ独立した枠で追従 */
  #menubar .affiliatebox {
    position: sticky;
    top: 80px;
    box-sizing: border-box;
    max-height: calc(100vh - 100px);
    overflow: auto;
    margin-top: 16px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
  }

  #menubar .affiliatebox img {
    box-sizing: border-box;
    max-width: 100%;
    height: auto;
  }
}

/* メニュー広告を追従 */
@media screen and (min-width: 960px) {
  #atwiki-jp-bg2 .atwiki-left-column {
    width: 320px;
    flex-shrink: 0;
  }

  #atwiki-jp-bg2 .atwiki-main-column {
    width: calc(100% - 588px);
  }
}