.n1-back-to-top {
  position: fixed;
  right: 22px;
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  min-height: 52px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: #166681;
  color: #fff;
  box-shadow: 0 0 0 4px rgba(53, 132, 160, .24), 0 8px 25px rgba(20, 75, 94, .2);
  cursor: pointer;
  transition: width .32s cubic-bezier(.23, 1, .32, 1), background-color .24s ease, box-shadow .24s ease;
}
.n1-back-to-top[hidden] { display: none !important; }
.n1-back-to-top__icon {
  display: block;
  flex: none;
  width: 21px;
  height: 21px;
  transition: transform .28s ease, opacity .22s ease;
}
.n1-back-to-top__label {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #fff;
  font: 700 13px/1 system-ui, sans-serif;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(30px);
  pointer-events: none;
  transition: transform .28s ease, opacity .22s ease;
}
.n1-back-to-top:focus-visible { outline: 3px solid #82d4e8; outline-offset: 6px; }
.n1-back-to-top:active { box-shadow: 0 0 0 4px rgba(53, 132, 160, .3), 0 4px 14px rgba(20, 75, 94, .2); }
html[data-theme="night"] .n1-back-to-top {
  background: #173945;
  box-shadow: 0 0 0 4px rgba(93, 194, 218, .22), 0 8px 25px rgba(0, 0, 0, .22);
}

@media (hover: hover) and (pointer: fine) and (min-width: 761px) {
  .n1-back-to-top:is(:hover, :focus-visible) {
    width: 140px;
    background: #3088a4;
    box-shadow: 0 0 0 4px rgba(53, 132, 160, .28), 0 11px 28px rgba(20, 75, 94, .24);
  }
  html[data-theme="night"] .n1-back-to-top:is(:hover, :focus-visible) { background: #2a839f; }
  .n1-back-to-top:is(:hover, :focus-visible) .n1-back-to-top__icon { opacity: 0; transform: translateY(-32px); }
  .n1-back-to-top:is(:hover, :focus-visible) .n1-back-to-top__label { opacity: 1; transform: translateY(0); }
}

@media (max-width: 760px) {
  .n1-back-to-top {
    right: 16px;
    bottom: calc(86px + env(safe-area-inset-bottom));
    width: 48px;
    height: 48px;
    min-height: 48px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .n1-back-to-top,
  .n1-back-to-top__icon,
  .n1-back-to-top__label { transition: none; }
}

/* The portal and forum use their own rose palette; N1 keeps its blue button. */
html:is([data-site="portal"], [data-site="forum"]) .n1-back-to-top {
  background: var(--rose-deep);
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--rose) 25%, transparent),
    0 8px 25px color-mix(in srgb, var(--rose-deep) 28%, transparent);
}
html:is([data-site="portal"], [data-site="forum"]) .n1-back-to-top:focus-visible {
  outline-color: var(--rose);
}
html:is([data-site="portal"], [data-site="forum"]) .n1-back-to-top:active {
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--rose) 34%, transparent),
    0 4px 14px color-mix(in srgb, var(--rose-deep) 32%, transparent);
}
html:is([data-site="portal"], [data-site="forum"])[data-theme="night"] .n1-back-to-top {
  background: color-mix(in srgb, var(--rose) 28%, #281a28);
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--rose) 25%, transparent),
    0 8px 25px rgba(0, 0, 0, .25);
}
@media (hover: hover) and (pointer: fine) and (min-width: 761px) {
  html:is([data-site="portal"], [data-site="forum"]) .n1-back-to-top:is(:hover, :focus-visible) {
    background: var(--rose);
    box-shadow:
      0 0 0 4px color-mix(in srgb, var(--rose) 30%, transparent),
      0 11px 28px color-mix(in srgb, var(--rose-deep) 32%, transparent);
  }
  html:is([data-site="portal"], [data-site="forum"])[data-theme="night"] .n1-back-to-top:is(:hover, :focus-visible) {
    background: color-mix(in srgb, var(--rose) 42%, #281a28);
  }
}
@media (max-width: 760px) {
  html:is([data-site="portal"], [data-site="forum"]) .n1-back-to-top {
    bottom: calc(22px + env(safe-area-inset-bottom));
  }
}
