/*
 * Back-to-top button (SPEC §2.16). Values from tokens.css only.
 *
 * HTML contract
 *   <a class="back-to-top" href="#top" aria-label="ページの先頭へ戻る"
 *      data-back-to-top></a>
 *   - A link: it navigates to the top of the page, so it works without JS.
 *     Every page has <body id="top"> as the target (an HTML id, never used
 *     in CSS). Without a real target axe flags the link as a broken skip
 *     link (rule skip-link).
 *   - One per page, as the last item inside the page's <footer>, so it is in
 *     a landmark and comes last in the tab order.
 *   - The chevron is decorative (::before); the name is the aria-label.
 *
 * Behaviour (js/components/back-to-top.js, progressive enhancement)
 *   Without JS it is always visible, as drawn in XD. With JS it sets
 *   data-back-to-top="hidden" until the page has been scrolled one viewport
 *   (ASSUMPTION Q20). A click scrolls smoothly (instantly under
 *   prefers-reduced-motion) and moves focus to the start of the document.
 *
 * XD: group "TOP" on all 26 artboards, fixed. 44 circle in green-700 with a
 * #FCFEFB chevron; 16 from the right edge on PC and SP, 18 from the bottom
 * on PC (SP 16–26, mostly 17: 18 used everywhere, Q33). PC = SP.
 *
 * States are ASSUMPTION (Q4): hover green-800 on hover-capable pointers;
 * active = hover look + 1px down; focus = white inner ring + green-700 ring.
 */

.back-to-top {
  position: fixed;
  inset-block-end: var(--back-to-top-inset-block);
  inset-inline-end: var(--back-to-top-inset-inline);
  z-index: var(--z-back-to-top);
  display: grid;
  place-items: center;
  inline-size: var(--back-to-top-size);
  block-size: var(--back-to-top-size);
  color: var(--color-on-dark);
  background-color: var(--color-green-700);
  border-radius: var(--radius-circle);
  transition:
    background-color var(--duration-hover),
    transform var(--duration-hover),
    opacity var(--duration-hover),
    visibility var(--duration-hover);
}

/* Chevron: top and left border of a square turned 45° (see tokens.css) */
.back-to-top::before {
  inline-size: var(--back-to-top-icon-side);
  block-size: var(--back-to-top-icon-side);
  content: "";
  border-block-start: var(--back-to-top-icon-stroke) solid currentcolor;
  border-inline-start: var(--back-to-top-icon-stroke) solid currentcolor;
  transform: translateY(var(--back-to-top-icon-shift)) rotate(45deg);
}

/* ---- Hidden near the top of the page (set by JS only) ----
   visibility also takes it out of the tab order and the accessibility tree;
   it switches after the fade, so the fade-out stays visible. */

.back-to-top[data-back-to-top="hidden"] {
  visibility: hidden;
  opacity: 0;
}

/* ---- States ---- */

@media (hover: hover) {
  .back-to-top:hover {
    background-color: var(--color-green-800);
  }
}

.back-to-top:active {
  background-color: var(--color-green-800);
  transform: translateY(var(--press-offset));
}

/* White inner ring inside the green focus ring, like filled buttons */
.back-to-top:focus-visible {
  box-shadow: 0 0 0 var(--focus-ring-offset) var(--color-surface);
}

@media print {
  .back-to-top {
    display: none;
  }
}
