:root {
  --bg: #f7f7f5;
  --text: #1f1d1a;
  --muted: #6c675f;
  --accent: #2f46c8;
  --on-accent: #ffffff;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --text: #e9ecf2;
    --muted: #9aa3b5;
    --accent: #8fa2ff;
    --on-accent: #0f1218;
  }
}

* {
  box-sizing: border-box;
}

body {
  position: relative; /* the sentinel is positioned against the body */
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

.page {
  max-width: 600px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

h1 {
  margin: 0 0 0.75rem;
  font-size: 1.75rem;
}

h2 {
  margin: 2rem 0 0.4rem;
  font-size: 1.15rem;
}

p {
  margin: 0 0 0.9rem;
}

.hint {
  color: var(--muted);
}

/* An invisible 1px marker 400px from the top. When it scrolls out of view, the button appears. */
#sentinel {
  position: absolute;
  top: 400px;
  left: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.to-top {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.22);
  /* hidden state: visibility also removes it from the Tab order */
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
}

.to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.to-top:focus-visible {
  outline: 3px solid var(--text);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .to-top {
    transition: none;
    transform: none;
  }
}
