/* ---------------------------------------------------------------------
   Personal productivity controls
------------------------------------------------------------------------ */

.page-tools {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: -0.35rem 0 1.25rem;
}

.page-tool {
  min-height: 2.25rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  font: inherit;
  font-size: var(--step--1);
}

.page-tool:hover,
.page-tool:focus-visible {
  background: var(--bg-raised);
  color: var(--text);
}

.page-tool.is-active {
  color: var(--accent-strong);
  border-color: var(--accent);
  background: var(--accent-tint);
}

.recent-wrap {
  position: relative;
}

.recent-pages {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 60;
  width: min(22rem, calc(100vw - 2rem));
  max-height: min(60vh, 24rem);
  overflow-y: auto;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(20, 24, 30, 0.15);
}

.recent-pages h2 {
  margin: 0 0 0.5rem;
  font-size: var(--step--1);
}

.recent-pages ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.recent-pages li + li {
  margin-top: 0.2rem;
}

.recent-pages a {
  display: block;
  padding: 0.55rem 0.6rem;
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.recent-pages a:hover,
.recent-pages a:focus-visible {
  background: var(--accent-tint);
  color: var(--accent-strong);
}

.recent-empty {
  padding: 0.55rem 0.6rem;
  color: var(--text-faint);
  font-size: var(--step--1);
}

.heading-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  min-width: 2rem;
  height: 2rem;
  margin-left: 0.4rem;
  padding: 0;
  vertical-align: middle;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.8em;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease;
}

.doc-content h2:hover .heading-link,
.doc-content h3:hover .heading-link,
.heading-link:focus-visible,
.heading-link.is-copied {
  opacity: 1;
}

.heading-link:hover,
.heading-link:focus-visible {
  border-color: var(--control-border);
  background: var(--bg-raised);
  color: var(--accent-strong);
}

.heading-link.is-copied {
  color: var(--pass);
}

.back-to-top {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 70;
  min-width: 3.25rem;
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--control-border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  font: inherit;
  font-size: var(--step--1);
}

.back-to-top:hover,
.back-to-top:focus-visible {
  background: var(--accent-tint);
  color: var(--accent-strong);
}

@media (max-width: 640px) {
  .page-tools {
    margin-top: -0.15rem;
    margin-bottom: 1rem;
  }

  .page-tool {
    min-height: 2.5rem;
    padding-inline: 0.7rem;
  }

  .heading-link {
    opacity: 1;
    width: 2.25rem;
    min-width: 2.25rem;
    height: 2.25rem;
  }

  .back-to-top {
    right: 0.75rem;
    bottom: 0.75rem;
    min-width: 2.75rem;
    width: 2.75rem;
    padding: 0;
  }

  .back-to-top span:last-child {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .heading-link {
    transition: none;
  }
}
