/* Reading toolbar: one floating pill with contents / text settings / wide / find / back-to-top.
   Loaded after style.min.css and overrides its older #reading-toolbar rules. */

#reading-toolbar {
  --rt-bg: #fff;
  --rt-fg: #495057;
  --rt-muted: #868e96;
  --rt-border: #e2e2e6;
  --rt-hover: #f0e9f6;
  --rt-accent: #8230b1;
  --rt-shadow: 0 4px 18px rgba(0, 0, 0, 0.14);

  display: none;
  position: fixed;
  right: 16px;
  bottom: 24px;
  z-index: 1040;
  flex-direction: row;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--rt-bg);
  border: 1px solid var(--rt-border);
  border-radius: 999px;
  box-shadow: var(--rt-shadow);
  transition: bottom 0.3s ease-out, transform 0.25s ease, opacity 0.25s ease;
}
#reading-toolbar.visible {
  display: flex;
}

#reading-toolbar button,
#reading-toolbar .finder-activator {
  position: static;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 40px;
  height: 40px;
  padding: 0 8px;
  margin: 0;
  border: none;
  border-radius: 999px;
  background: none;
  color: var(--rt-fg);
  font: 600 15px/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
#reading-toolbar button svg {
  flex-shrink: 0;
}
#reading-toolbar button sup {
  font-size: 10px;
  top: -0.4em;
}
@media (hover: hover) {
  #reading-toolbar button:hover:not(:disabled),
  #reading-toolbar .finder-activator:hover {
    background: var(--rt-hover);
    color: var(--rt-accent);
  }
}
/* style.min.css :hover sticks after a tap on touch screens */
@media (hover: none) {
  body #reading-toolbar button:hover:not(.active),
  body #reading-toolbar .finder-activator:hover {
    background: none;
    color: var(--rt-fg);
  }
  body #reading-toolbar #rt-popover button:hover {
    background: var(--rt-hover);
  }
  body #reading-toolbar #rt-popover .rt-reset:hover {
    background: none;
    color: var(--rt-accent);
  }
}
#reading-toolbar button.active {
  background: var(--rt-accent);
  color: #fff;
}
#reading-toolbar button:disabled {
  opacity: 0.35;
  cursor: default;
}
#reading-toolbar button:focus-visible {
  outline: 2px solid var(--rt-accent);
  outline-offset: -2px;
}

#reading-toolbar .rt-aa {
  font-size: 17px;
  letter-spacing: -0.02em;
}
#reading-toolbar .rt-aa small {
  font-size: 13px;
}

/* Back-to-top lives in the pill once the page has scrolled */
#reading-toolbar #rt-top {
  display: none;
}
#reading-toolbar.rt-scrolled #rt-top {
  display: inline-flex;
}
#reading-toolbar.rt-scrolled #rt-top::before {
  content: "";
  width: 1px;
  height: 20px;
  margin-left: -8px;
  margin-right: 8px;
  background: var(--rt-border);
}
body.reading-toolbar-on #back-to-top {
  display: none !important;
}

#reading-toolbar .rt-desktop-only {
  display: inline-flex;
}

/* ---- Text settings popover ---- */
#rt-popover {
  position: absolute;
  right: 0;
  bottom: calc(100% + 10px);
  width: 252px;
  padding: 10px 12px 8px;
  background: var(--rt-bg);
  border: 1px solid var(--rt-border);
  border-radius: 16px;
  box-shadow: var(--rt-shadow);
  color: var(--rt-fg);
}
#rt-popover[hidden] {
  display: none;
}
#rt-popover .rt-row {
  display: grid;
  grid-template-columns: 1fr 40px 46px 40px;
  align-items: center;
  gap: 2px;
  padding: 2px 0;
}
#rt-popover .rt-label {
  font-size: 13px;
  color: var(--rt-muted);
}
#rt-popover output {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
#rt-popover button {
  min-width: 40px;
  padding: 0;
  background: var(--rt-hover);
}
#reading-toolbar #rt-popover .rt-reset {
  display: block;
  width: 100%;
  height: 32px;
  margin-top: 6px;
  background: none;
  color: var(--rt-accent);
  font-size: 13px;
}
#reading-toolbar #rt-popover .rt-reset:disabled {
  visibility: hidden;
  height: 0;
  margin: 0;
}

/* ---- Finder bar open: lift above it ---- */
body:has(.finder.active) #reading-toolbar {
  bottom: 84px;
}

/* ---- Phones ---- */
@media screen and (max-width: 800px) {
  #reading-toolbar {
    right: 12px;
    bottom: calc(70px + env(safe-area-inset-bottom));
  }
  #reading-toolbar .rt-desktop-only {
    display: none;
  }
  #reading-toolbar button,
  #reading-toolbar .finder-activator {
    min-width: 42px;
    height: 42px;
  }
  body:has(.finder.active) #reading-toolbar {
    bottom: calc(120px + env(safe-area-inset-bottom));
  }
  /* Tucked away while scrolling down */
  #reading-toolbar.rt-away {
    transform: translateY(16px);
    opacity: 0;
    pointer-events: none;
  }
  #rt-popover {
    width: min(280px, calc(100vw - 24px));
  }
}

/* ---- Dark mode ---- */
body.dark-mode #reading-toolbar {
  --rt-bg: #252525;
  --rt-fg: #c8c4bd;
  --rt-muted: #8f8a83;
  --rt-border: #3a3a3a;
  --rt-hover: #333;
  --rt-accent: #c79be6;
  --rt-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
  background: var(--rt-bg);
  border-color: var(--rt-border);
}
body.dark-mode #reading-toolbar button.active {
  background: #7a3fa0;
  color: #fff;
}
