body:has(.home-back-to-top) {
  --home-top-size: 2.75rem;
  --home-top-edge: calc(.375rem + env(safe-area-inset-right, 0px));
  --home-top-gutter: calc(var(--home-top-size) + var(--home-top-edge) + .375rem);
}

.home-back-to-top {
  position: fixed;
  right: var(--home-top-edge, .375rem);
  bottom: calc(.75rem + env(safe-area-inset-bottom, 0px));
  z-index: 4;
  width: var(--home-top-size, 2.75rem);
  height: var(--home-top-size, 2.75rem);
  box-sizing: border-box;
  padding: 0;
  border: 1px solid #5d1b19;
  border-radius: 50%;
  background: #761f1d;
  color: #fff;
  font: 700 1.35rem/1 system-ui, sans-serif;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.home-back-to-top:hover { background: #5d1b19; }
.home-back-to-top:focus-visible {
  outline: 3px solid #211710;
  outline-offset: 2px;
  box-shadow: 0 0 0 2px #fff;
}

.home-back-to-top[hidden],
body:has(dialog[open], .site-head details[open], .bucha-contents-mobile[open]) .home-back-to-top { display: none; }

/* Keep the control outside the reading and footer columns when the natural margin is narrow. */
body:has(.home-back-to-top) :is(main.home.shell, .site-footer > .footer-wrap) {
  max-width: calc(100% - var(--home-top-gutter) - 1rem);
  margin-inline-end: max(var(--home-top-gutter), calc((100% - 1180px) / 2));
}

@media (max-width: 1320px) {
  body:has(.home-back-to-top) main.inner.shell {
    max-width: calc(100% - var(--home-top-gutter) - 1rem);
    margin-inline-end: var(--home-top-gutter);
  }
}
