/* Back to top: a small mined block in the lower right corner.
   It warms up from slate to amber to ember orange as the page is scrolled
   (--heat 0..1, set by totop.js), the same idea as a block that is
   "mined hot". No idle animation: it only moves when it appears or is pointed at. */
.totop {
  --heat: 0;
  --hot: color-mix(in srgb, #FF6A2B calc(var(--heat) * 100%), #F5A524);
  --face: color-mix(in srgb, var(--hot) calc(min(1, var(--heat) * 1.7) * 100%), #3A3F47);
  position: fixed; z-index: 9;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 52px; height: 56px; padding: 0;
  display: grid; justify-items: center; align-content: center; gap: 5px;
  border: 1px solid var(--slate, #2A2E35); border-radius: 14px;
  background: rgba(20, 22, 26, .84);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: 0 10px 28px -10px rgba(0, 0, 0, .9);
  color: var(--face); cursor: pointer;
  opacity: 0; visibility: hidden; transform: translateY(10px);
  transition: opacity .25s ease, transform .25s ease, visibility 0s linear .25s, border-color .2s ease;
}
.totop.show { opacity: 1; visibility: visible; transform: none; transition: opacity .25s ease, transform .25s ease, visibility 0s, border-color .2s ease; }
.totop:hover { border-color: color-mix(in srgb, var(--hot) 55%, #2A2E35); }
.totop:focus-visible { outline: 2px solid var(--frost, #8FB8D8); outline-offset: 3px; }

/* The arrow above the block */
.totop-arrow { width: 14px; height: 9px; display: block; transition: transform .25s cubic-bezier(.3, .8, .3, 1); }
.totop-arrow path { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* The block: an isometric CSS cube */
.totop-scene { width: 26px; height: 22px; perspective: 400px; display: grid; place-items: center; }
.totop-cube {
  --s: 14px;
  position: relative; width: var(--s); height: var(--s);
  transform-style: preserve-3d;
  transform: rotateX(-30deg) rotateY(-45deg);
  transition: transform .45s cubic-bezier(.3, .8, .3, 1);
}
.totop-cube i {
  position: absolute; inset: 0; display: block;
  border: 1px solid color-mix(in srgb, var(--face) 70%, #F2EFEA);
  background: var(--face);
  backface-visibility: hidden;
}
.totop-cube .t { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); background: color-mix(in srgb, var(--face) 82%, #F2EFEA); }
.totop-cube .b { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
.totop-cube .f { transform: translateZ(calc(var(--s) / 2)); background: color-mix(in srgb, var(--face) 78%, #14161A); }
.totop-cube .k { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.totop-cube .l { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); background: color-mix(in srgb, var(--face) 92%, #14161A); }
.totop-cube .r { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); background: color-mix(in srgb, var(--face) 58%, #14161A); }
/* warmth under the block, stronger as it heats */
.totop-scene::after {
  content: ""; position: absolute; width: 30px; height: 10px; margin-top: 22px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 106, 43, .55), transparent);
  opacity: calc(var(--heat) * .9); pointer-events: none;
}
.totop-scene { position: relative; }

/* Pointed at: the block lifts and turns a little, the arrow rises */
.totop:hover .totop-cube, .totop:focus-visible .totop-cube { transform: translateY(-3px) rotateX(-30deg) rotateY(-135deg); }
.totop:hover .totop-arrow, .totop:focus-visible .totop-arrow { transform: translateY(-2px); }

@media (max-width: 760px) {
  .totop { width: 46px; height: 50px; border-radius: 12px; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  .totop, .totop.show, .totop-cube, .totop-arrow { transition: none; }
  .totop { transform: none; }
  .totop:hover .totop-cube, .totop:focus-visible .totop-cube { transform: rotateX(-30deg) rotateY(-45deg); }
  .totop:hover .totop-arrow, .totop:focus-visible .totop-arrow { transform: none; }
}
@media print { .totop { display: none; } }
main[tabindex="-1"]:focus, #top[tabindex="-1"]:focus { outline: none; }
