/* Slider: shadcn's thin track, the filled range, round thumbs. UI SDK places the indicator and
   thumbs with inline positions once it upgrades; until then data-start/-end/-position (from
   the server) place them with the same percentages. */
@layer runeui.components {
  [data-slot="slider"] { display: flex; flex-direction: column; gap: 0.5rem; width: 100%; min-width: 8rem; touch-action: none; user-select: none; }
  [data-slot="slider"][data-disabled] { opacity: 0.5; }
  [data-slot="slider-value"] { align-self: flex-end; color: var(--muted-foreground); font-size: var(--ui-text-sm); font-variant-numeric: tabular-nums; }
  ui-slider-value:not(:defined)::before, [data-slot="slider-value"]:not([data-text])::before { content: attr(data-label); }

  [data-slot="slider-control"] { display: flex; align-items: center; width: 100%; height: 1.25rem; cursor: pointer; }
  [data-slot="slider"][data-disabled] [data-slot="slider-control"] { cursor: not-allowed; }

  [data-slot="slider-track"] { position: relative; flex: 1; height: 0.375rem; border-radius: var(--ui-radius-full); background: var(--muted); }
  [data-slot="slider-indicator"] { position: absolute; top: 0; bottom: 0; border-radius: inherit; background: var(--primary); }

  [data-slot="slider-thumb"] {
    position: absolute;
    top: 50%;
    display: block;
    width: 1rem;
    height: 1rem;
    border: 1px solid var(--primary);
    border-radius: var(--ui-radius-full);
    background: var(--background);
    box-shadow: var(--ui-shadow-sm);
    transition: box-shadow var(--ui-duration);
  }

  [data-slot="slider-thumb"]:is(:has(:focus-visible), [data-dragging]) { box-shadow: 0 0 0 4px color-mix(in oklab, var(--ring) 50%, transparent); }
  @media (hover: hover) and (pointer: fine) { [data-slot="slider-thumb"]:hover { box-shadow: 0 0 0 4px color-mix(in oklab, var(--ring) 50%, transparent); } }

  /* Before upgrade: the server's percentages. */
  ui-slider-indicator:not(:defined) { left: calc(attr(data-start type(<number>), 0) * 1%); right: calc(100% - attr(data-end type(<number>), 0) * 1%); }
  ui-slider-thumb:not(:defined) { left: calc(attr(data-position type(<number>), 0) * 1%); translate: -50% -50%; }

  [data-slot="slider"][data-orientation="vertical"] { width: auto; min-width: 0; height: 10rem; }
  [data-slot="slider"][data-orientation="vertical"] [data-slot="slider-control"] { flex-direction: column; width: 1.25rem; height: 100%; }
  [data-slot="slider"][data-orientation="vertical"] [data-slot="slider-track"] { width: 0.375rem; height: auto; }
  [data-slot="slider"][data-orientation="vertical"] [data-slot="slider-indicator"] { left: 0; right: 0; }
}

@layer runeui.components {
  [data-slot="slider"][aria-invalid="true"] [data-slot="slider-thumb"] { border-color: var(--destructive); }
}

/* show_value: the value riding over the thumb (after microinteractions.dev's edge-aware tooltip).
   Anchored to the thumb (a range's to the span between its thumbs) and centred on it with
   justify-self: anchor-center, which shifts it inward rather than past the slider's edge; the
   arrow is placed on its own, at the anchor's centre, so it stays on the thumb when the label
   stops. It follows the value with no transition at all: a label that lags misreports it. The
   anchor name is scoped to each slider, so every slider finds its own thumb. Without anchor
   positioning the value stays where it was, at the end of the row. */
@layer runeui.components {
  [data-slot="slider-value-arrow"] { display: none; }

  @supports (position-anchor: --a) and (justify-self: anchor-center) and (anchor-scope: --a) {
    [data-slot="slider"]:has(> [data-slot="slider-value-arrow"]):not([data-orientation="vertical"]) {
      position: relative;
      padding-top: 2rem;
      anchor-scope: --ui-slider-value;
    }
    [data-slot="slider"]:not([data-range]) [data-slot="slider-thumb"],
    [data-slot="slider"][data-range] [data-slot="slider-indicator"] { anchor-name: --ui-slider-value; }
    [data-slot="slider"]:not([data-orientation="vertical"]) > [data-slot="slider-value"] {
      position: absolute;
      top: 0;
      position-anchor: --ui-slider-value;
      justify-self: anchor-center;
      padding: 0.125rem 0.5rem;
      border-radius: var(--ui-radius-md);
      background: var(--primary);
      color: var(--primary-foreground);
      font-size: var(--ui-text-xs);
      font-weight: 500;
      line-height: 1.25rem;
      white-space: nowrap;
      transition-property: none;
    }
    [data-slot="slider"]:not([data-orientation="vertical"]) > [data-slot="slider-value-arrow"] {
      position: absolute;
      top: calc(1.5rem - 4px);
      left: calc(anchor(--ui-slider-value center) - 4px);
      display: block;
      width: 8px;
      height: 8px;
      background: var(--primary);
      rotate: 45deg;
      clip-path: polygon(100% 0, 100% 100%, 0 100%);
      pointer-events: none;
      transition-property: none;
    }
    [data-slot="slider"][data-disabled] > :is([data-slot="slider-value"], [data-slot="slider-value-arrow"]) { opacity: 0.5; }
  }

  @media (forced-colors: active) {
    [data-slot="slider"] > [data-slot="slider-value"] { border: 1px solid CanvasText; }
    [data-slot="slider"] > [data-slot="slider-value-arrow"] { background: CanvasText; }
  }
}
