.selection-toolbar {
  --selection-accent: var(--accent, #36c7d9);
  position: fixed;
  inset: 0 auto auto 0;
  z-index: 2400;
  display: flex;
  align-items: center;
  max-width: calc(100vw - 20px);
  min-height: 42px;
  padding: 4px;
  border: 1px solid color-mix(in srgb, var(--selection-accent) 28%, var(--border, #26383b));
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface-raised, #111a1c) 94%, transparent);
  box-shadow: 0 16px 42px rgba(0, 0, 0, .28), 0 0 0 1px rgba(255, 255, 255, .025) inset;
  backdrop-filter: blur(14px) saturate(1.08);
  color: var(--text, #eef7f6);
  opacity: 0;
  transition: opacity 120ms ease;
  will-change: transform;
}

::highlight(wikist-selection-anchors) {
  color: inherit;
  background-color: color-mix(in srgb, var(--selection-accent, var(--accent, #36c7d9)) 27%, transparent);
  text-decoration-line: underline;
  text-decoration-color: color-mix(in srgb, var(--selection-accent, var(--accent, #36c7d9)) 96%, #fff 4%);
  text-decoration-thickness: 3px;
  text-underline-offset: .18em;
}

html[data-theme="light"] ::highlight(wikist-selection-anchors) {
  background-color: color-mix(in srgb, var(--accent, #087f8d) 13%, transparent);
  text-decoration-color: color-mix(in srgb, var(--accent, #087f8d) 82%, transparent);
}

::highlight(wikist-selection-target) {
  color: inherit;
  background-color: color-mix(in srgb, var(--accent, #36c7d9) 44%, transparent);
  text-decoration-line: underline;
  text-decoration-color: var(--accent, #36c7d9);
  text-decoration-thickness: 3px;
  text-underline-offset: .2em;
}

html[data-theme="light"] ::highlight(wikist-selection-target) {
  background-color: color-mix(in srgb, var(--accent, #087f8d) 24%, transparent);
}

.selection-toolbar[hidden] {
  display: none !important;
}

.selection-toolbar button[hidden] {
  display: none !important;
}

.selection-toolbar.is-visible {
  opacity: 1;
}

.selection-toolbar::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 8px;
  height: 8px;
  border: inherit;
  background: inherit;
  transform: translateX(-50%) rotate(45deg);
}

.selection-toolbar[data-placement="top"]::after {
  bottom: -5px;
  border-top: 0;
  border-left: 0;
}

.selection-toolbar[data-placement="bottom"]::after {
  top: -5px;
  border-right: 0;
  border-bottom: 0;
}

.selection-toolbar > button,
.selection-toolbar-reference > button,
.selection-quote-menu > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  height: 34px;
  padding: 0 9px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text, #eef7f6);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: color 120ms ease, background 120ms ease;
}

.selection-toolbar button:hover,
.selection-toolbar button:focus-visible,
.selection-toolbar button.active {
  outline: 0;
  background: color-mix(in srgb, var(--selection-accent) 13%, transparent);
  color: var(--selection-accent);
}

.selection-toolbar [data-selection-action="delete"] {
  color: var(--rose, #e9658d);
}

.selection-toolbar [data-selection-action="like"] em {
  min-width: 1ch;
  font-size: 11px;
  font-style: normal;
  font-variant-numeric: tabular-nums;
  opacity: .84;
}

.selection-toolbar [data-selection-action="like"].active {
  color: #ff5f87;
  background: color-mix(in srgb, #e9658d 20%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #ff6f95 56%, transparent);
}

.selection-toolbar [data-selection-action="like"].active:hover,
.selection-toolbar [data-selection-action="like"].active:focus-visible {
  color: #ff789c;
  background: color-mix(in srgb, #e9658d 27%, transparent);
}

.selection-toolbar [data-selection-action="like"].active svg {
  fill: currentColor;
}

.selection-toolbar button:disabled {
  opacity: .55;
  cursor: wait;
}

.selection-toolbar svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.selection-toolbar-reference {
  position: relative;
  display: inline-flex;
}

.selection-quote-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  display: grid;
  width: max-content;
  min-width: 156px;
  padding: 5px;
  border: 1px solid var(--border, #26383b);
  border-radius: 8px;
  background: var(--surface-raised, #111a1c);
  box-shadow: 0 18px 48px rgba(0, 0, 0, .32);
}

.selection-toolbar[data-placement="top"] .selection-quote-menu {
  top: auto;
  bottom: calc(100% + 10px);
}

.selection-quote-menu[hidden] {
  display: none;
}

.selection-quote-menu > button {
  justify-content: flex-start;
  width: 100%;
}

html[data-theme="light"] .selection-toolbar,
html[data-theme="light"] .selection-quote-menu {
  background: rgba(255, 255, 255, .96);
  color: var(--text, #102023);
  box-shadow: 0 14px 38px rgba(22, 44, 48, .15), 0 0 0 1px rgba(255, 255, 255, .8) inset;
}

@media (max-width: 640px) {
  .selection-toolbar {
    overflow: visible;
    padding: 3px;
  }

  .selection-toolbar > button,
  .selection-toolbar-reference > button {
    gap: 4px;
    padding-inline: 7px;
    font-size: 12px;
  }
}

@media (max-width: 430px) {
  .selection-toolbar > button span,
  .selection-toolbar-reference > button > span {
    display: none;
  }

  .selection-toolbar > button,
  .selection-toolbar-reference > button {
    width: 38px;
    padding: 0;
  }

  .selection-quote-menu > button span {
    display: inline;
  }
}

@media (prefers-reduced-motion: reduce) {
  .selection-toolbar,
  .selection-toolbar button {
    transition: none;
  }
}
