/* Text-only selection highlight shared by every static HTML surface.
   The browser keeps the real Selection for copy/paste; text-selection.js
   rebuilds only non-whitespace text subranges for visual painting. */

html.text-selection-enhanced::selection,
html.text-selection-enhanced ::selection {
  background: transparent;
  color: var(--text-selection-foreground, currentColor);
}

/* Form/editing controls keep their native selection behavior. */
html.text-selection-enhanced input::selection,
html.text-selection-enhanced textarea::selection,
html.text-selection-enhanced select::selection,
html.text-selection-enhanced [contenteditable="true"]::selection,
html.text-selection-enhanced [contenteditable="true"] *::selection {
  background: Highlight;
  color: HighlightText;
}

/* Primary path: paints behind text and preserves a high-contrast foreground. */
::highlight(kit-text-selection) {
  background-color: rgba(251, 191, 36, 0.24);
  background-color: color-mix(in srgb, #fbbf24 24%, transparent);
  color: var(--text-selection-foreground, currentColor);
}

/* Compatibility fallback for browsers without CSS Custom Highlights. */
.text-selection-layer {
  position: fixed;
  inset: 0;
  z-index: 2147483646;
  overflow: hidden;
  pointer-events: none;
}

.text-selection-layer[hidden] {
  display: none;
}

.text-selection-rect {
  position: absolute;
  border-radius: 2px;
  background: rgba(251, 191, 36, 0.16);
  background: color-mix(in srgb, #fbbf24 16%, transparent);
}

@media (forced-colors: active) {
  html.text-selection-enhanced::selection,
  html.text-selection-enhanced ::selection,
  ::highlight(kit-text-selection) {
    color: HighlightText;
  }
}

@media print {
  .text-selection-layer { display: none; }
}
