/* Styles of the settings panel built by settings-panel.js. Plain CSS with sp- classes, no
   dependence on ids. Colors: the site tokens (--color-bg, --color-fg) plus neutral greys.
   Form controls keep their browser look; only accent-color is set (no global reset). */

.sp {
  --sp-line-strong: #555;
  --sp-mute: #8a8a8a;
  --sp-raise: #1c1c1c; /* hover */
  --sp-active: #222; /* selected tab */
  --sp-scope-bg: #2a2a2a; /* the scope-switch bar (.sp-scope) - a bit lighter than --sp-active */
  display: flex;
  flex: 1;
  min-height: 0;
  color: var(--color-fg);
  accent-color: var(--color-fg);
}

/* ---- Rail of tabs ---- */

.sp-rail {
  flex: none;
  width: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.sp-divider {
  height: 12px; /* a gap between the groups of tabs, no line */
}

.sp-tab {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--sp-mute);
  cursor: pointer;
}

.sp-tab:hover,
.sp-tab[aria-selected="true"] {
  color: var(--color-fg);
}

.sp-tab:hover {
  background: var(--sp-raise);
}

.sp-tab[aria-selected="true"] {
  background: var(--sp-active);
}

.sp-tab:focus-visible {
  outline: 2px solid var(--sp-mute);
  outline-offset: 1px;
}

/* Automation dots: a tab (or a scope segment) with sliders set to automate */
.sp-tab[data-auto]::after,
.sp-seg button[data-auto]::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.sp-tab[data-auto]::after {
  top: 5px;
  right: 5px;
}

.sp-seg button[data-auto]::after {
  top: 3px;
  right: 3px;
  width: 5px;
  height: 5px;
}

/* A repeating scope's item switched off by its repeatToggle: dimmed segment, still clickable.
   Not while it's also the pressed/shown one - honeycomb's connected-look tabs (below) give the
   pressed button a solid background matching the content, and fading it here would blend that
   into the strip behind it instead. */
.sp-seg button[data-inactive]:not([aria-pressed="true"]) {
  opacity: .45;
}

.sp-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* Rail tab tooltip: a single node reused across tabs, positioned in JS (settings-panel.js),
   appended outside the panel so it can render past the sidebar card's clip. */
.sp-tab-tip {
  position: fixed;
  transform: translate(-100%, -50%);
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--sp-bg, var(--color-bg));
  color: var(--color-fg);
  font: inherit;
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
}

/* ---- Content ---- */

.sp-main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

/* Scope switch (Global / 1 / 2 / 3) with its note; stays in view while the groups scroll */
.sp-scope {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 8px 0;
  /* Lighter than the page: honeycomb's connected-look tabs (panel/scope-bar.js) need a visibly
     raised strip behind them to sit on - see that block below. */
  background: var(--sp-scope-bg, var(--color-bg));
}

.sp-panels {

}

.sp-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 24px;
  margin-top: 8px;
  color: var(--sp-mute);
}

.sp-note[hidden] {
  display: none;
}

.sp-dim {
  opacity: 0.4;
}

/* A repeating scope's item switched off by its repeatToggle, shown on its own tab: lighter than
   .sp-dim and never paired with inert - the controls stay fully editable (see settings-panel spec,
   "Inactive-item dimming"). */
.sp-dim-soft {
  opacity: 0.6;
}

.sp-group {
  margin-top: 16px;
  padding-left: 16px;
  padding-right: 16px;
}

.sp-head {
  position: relative; /* anchors an info popover (.sp-info-pop) of this group, if it has one */
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sp-head h4 {
  margin: 0;
  font-size: 11px;
  font-weight: inherit;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--sp-mute);
}

.sp-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

/* A group's master toggle row (controls.js addGroup: "Enabled") is a sibling of .sp-head, not a
   child of .sp-body, so it stays reachable while the body is dimmed/inert - but that means it
   misses .sp-body's own margin-top. Same 8px here, so it sits the same distance from the title
   whether or not the group has a master. Higher specificity than .sp-check's margin shorthand
   (below), so it overrides only the top offset and leaves the focus-tint hit-box trick intact. */
.sp-head + .sp-check {
  margin-top: 8px;
}

.sp-body.sp-off {
  opacity: 0.4;
}

/* ---- Rows ---- */

.sp-row {
  position: relative; /* anchors an info popover (.sp-info-pop) of this control, if it has one */
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* Padding to carry a focus tint (below), offset by a negative margin so it does not shift
     the row's size or spacing from its neighbors at rest. Vertical inset stays well under
     half of .sp-body's 10px row gap so two rows' insets can never make them overlap. */
  padding: 2px 8px;
  margin: -2px -8px;
  border-radius: 4px;
}

/* A row's slider (or select, etc.) has no visible box of its own worth tinting; the row itself
   shows keyboard focus instead, never an outline (src/tailwind.css kills the native ring). */
.sp-row:focus-within {
  background: var(--sp-raise);
}

/* A row whose control already has its own visible, bordered box (Sides' sp-scope-tabs buttons)
   shows its own focus outline (.sp-seg button:focus, below) instead - the row tint above would
   just double up on top of it. */
.sp-row.sp-row-boxed:focus-within {
  background: none;
}

/* Wraps a title (label span, or a group's h4) together with its info trigger, so a
   justify-content: space-between row treats them as one item instead of spreading them apart */
.sp-title {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.sp-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sp-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sp-val {
  font-variant-numeric: tabular-nums;
}

/* Filled-bar slider: no visible thumb, the track itself shows the value as a hard-stop gradient
   fill up to --pct (0-100, written in controls.js wherever the value is already read - there is
   no cross-browser "value so far" pseudo-element to lean on instead: Firefox has
   ::-moz-range-progress, Chrome/Safari have nothing equivalent, and a single gradient rule
   covers all engines the same way rather than mixing two mechanisms). The thumb is sized to the
   track and made transparent, not display:none - removing it from rendering entirely can also
   drop the engine's own drag hit-testing, since the thumb is what a browser hit-tests to start a
   drag; a transparent thumb keeps that while showing nothing. */
.sp-row input[type="range"] {
  width: 100%;
  height: 10px;
  margin: 2px 0 0;
  -webkit-appearance: none;
  appearance: none;
  background: none;
  cursor: pointer;
}

.sp-row input[type="range"]::-webkit-slider-runnable-track {
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(
    to right,
    var(--color-fg) 0%,
    var(--color-fg) calc(var(--pct, 0) * 1%),
    var(--sp-line-strong) calc(var(--pct, 0) * 1%),
    var(--sp-line-strong) 100%
  );
}

.sp-row input[type="range"]::-moz-range-track {
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(
    to right,
    var(--color-fg) 0%,
    var(--color-fg) calc(var(--pct, 0) * 1%),
    var(--sp-line-strong) calc(var(--pct, 0) * 1%),
    var(--sp-line-strong) 100%
  );
}

.sp-row input[type="range"]::-webkit-slider-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: transparent;
  border: none;
  -webkit-appearance: none;
  appearance: none;
}

.sp-row input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: transparent;
  border: none;
}

.sp-row select,
.sp-row textarea,
.sp-row input[type="text"] {
  width: 100%;
  box-sizing: border-box;
}

/* multiline text control: styled like the Presets tab's name field, resizes vertically only */
.sp-row textarea {
  resize: vertical;
  padding: 4px 8px;
  border: 1px solid var(--sp-line-strong);
  border-radius: 4px;
  background: none;
  color: var(--color-fg);
  font: inherit;
}

/* A select has its own visible box, unlike a slider/checkbox: tint it directly on focus,
   never an outline (src/tailwind.css kills the native ring). */
.sp-row select:focus,
.sp-row textarea:focus,
.sp-row input[type="text"]:focus {
  background: var(--sp-raise);
}

.sp-auto {
  margin: 0;
  padding: 0 5px;
  border: 1px solid var(--sp-line-strong);
  border-radius: 3px;
  background: none;
  font: inherit;
  font-size: 10px;
  color: var(--sp-mute);
  cursor: pointer;
  user-select: none;
}

/* Too small for a background tint to read; an outline in the site's text color instead
   (the panel's one deliberate exception to "no ring"). */
.sp-auto:focus {
  outline: 1px solid var(--color-fg);
  outline-offset: 1px;
}

.sp-auto.on {
  border-color: var(--color-fg);
  color: var(--color-fg);
}

.sp-rand {
  margin: 0;
  padding: 0 5px;
  border: 1px solid var(--sp-line-strong);
  border-radius: 3px;
  background: none;
  font: inherit;
  font-size: 10px;
  color: var(--sp-mute);
  cursor: pointer;
  user-select: none;
}

/* Too small for a background tint to read; an outline in the site's text color instead
   (the panel's one deliberate exception to "no ring"). */
.sp-rand:focus {
  outline: 1px solid var(--color-fg);
  outline-offset: 1px;
}

.sp-rand.on {
  border-color: var(--color-fg);
  color: var(--color-fg);
}

.sp-check .sp-rand,
.sp-head .sp-rand {
  margin-left: auto;
}

.sp-check {
  position: relative; /* anchors an info popover (.sp-info-pop) of this control, if it has one */
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  /* Padding to carry a focus tint (below), offset by a negative margin so it does not shift
     the label's size or spacing from its neighbors at rest (same 2px vertical cap as .sp-row,
     and safe for a lone master-row checkbox that sits directly under a group header with no
     gap of its own). */
  padding: 2px 6px;
  margin: -2px -6px;
  border-radius: 4px;
}

/* A checkbox has no visible box worth tinting; its label shows keyboard focus instead, never
   an outline (src/tailwind.css kills the native ring). Covers toggles, master switches, and
   repeat-toggle rows - all built as a .sp-check label wrapping the checkbox. */
.sp-check:focus-within {
  background: var(--sp-raise);
}

/* ---- Toggle switch ----
   The real <input type="checkbox"> stays in the DOM (for native state, form semantics and a11y)
   but is visually hidden the same way .sp-file hides its file input below: clipped to 1px, not
   display:none, so it keeps its place in the tab order. A sibling <span class="sp-toggle"> - not
   a replaced element, unlike the input - draws the track and, via ::after, the knob; ::before/
   ::after are not reliably rendered on the input itself even with appearance:none. State reads
   off the input via the sibling combinator, so no click handler is needed on the span - clicking
   anywhere in the label already toggles the input per native <label> behavior. Used by every
   checkbox-shaped control: plain toggles and repeat-toggle rows (.sp-check), the group master
   switch (.sp-check), and the overview tab's Automate/Randomize rows (.sp-orow) - each of those
   labels already has position: relative to anchor this. */
.sp-toggle-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.sp-toggle {
  position: relative;
  flex: none;
  width: 28px;
  height: 16px;
  border-radius: 8px;
  background: var(--sp-line-strong);
  transition: background 0.15s;
}

.sp-toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--color-bg);
  transition: transform 0.15s;
}

.sp-toggle-input:checked ~ .sp-toggle {
  background: var(--color-fg);
}

.sp-toggle-input:checked ~ .sp-toggle::after {
  transform: translateX(12px);
}

/* ---- Info icon + popover ---- */

.sp-info-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--sp-mute);
  cursor: pointer;
  outline: none; /* no ring - it already goes from hidden to visible on focus (below), its own cue */
  transition: opacity 0.15s;
}

.sp-info-btn:hover,
.sp-info-btn[aria-expanded="true"] {
  color: var(--color-fg);
}

/* Hidden until its row/header is hovered, it has keyboard focus, or its popover is open - keeps
   the panel looking clean at rest. Only on devices with real hover: a touch device has no way to
   "hover" a row first, so the icon must stay visible there or it could never be reached at all. */
@media (hover: hover) {
  .sp-info-btn {
    opacity: 0;
  }

  .sp-row:hover .sp-info-btn,
  .sp-check:hover .sp-info-btn,
  .sp-head:hover .sp-info-btn,
  .sp-info-btn:focus-visible,
  .sp-info-btn[aria-expanded="true"] {
    opacity: 1;
  }
}

.sp-info-btn svg {
  width: 14px;
  height: 14px;
}

/* Closed: visually hidden but still in the accessibility tree (same technique as .sp-file), so
   aria-describedby reaches the text whether or not the popover has ever been opened. */
.sp-info-pop {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* The shared info panel (one node for every control's/group's info icon; positioned in JS,
   panel/rail.js): docked below #sidebar by default, matching its width and corner rounding
   (rounded-lg, set as a class in rail.js so Tailwind's scanner picks it up - see docs/styling.md on
   icon/class scanning). Lives outside #sidebar's subtree so its own overflow:hidden can never
   clip it (same reasoning as .sp-tab-tip below). */
.sp-info-panel {
  position: fixed;
  padding: 10px 12px;
  background: var(--sp-bg, #141414);
  color: var(--color-fg);
  font: inherit;
  font-size: 11px;
  white-space: normal;
}

/* ---- Buttons and segmented choices ---- */

.sp-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sp-btns button,
.sp-note button,
.sp-seg button,
.sp-save button {
  padding: 4px 10px;
  border: 1px solid var(--sp-line-strong);
  border-radius: 4px;
  background: none;
  color: var(--color-fg);
  font: inherit;
  cursor: pointer;
}

.sp-btns button:hover,
.sp-note button:hover,
.sp-seg button:hover,
.sp-save button:hover {
  border-color: var(--color-fg);
}

.sp-btns button:focus,
.sp-note button:focus,
.sp-seg button:focus,
.sp-save button:focus {
  outline: 1px solid var(--color-fg);
  outline-offset: 1px;
}

/* Presets tab's own buttons (Save/Load here, preset rows below): no border, a background a step
   lighter than the panel (--sp-raise) instead, another step lighter still on hover (--sp-active) -
   both existing neutral-grey tokens, not new ones. Higher specificity than the shared rule above
   (same selector, later in source), overriding just its border/background. */
.sp-save button {
  border: none;
  background: var(--sp-raise);
}

.sp-save button:hover {
  background: var(--sp-active);
}

.sp-save button:disabled {
  opacity: 0.4;
  cursor: default;
}

.sp-save button:disabled:hover {
  background: var(--sp-raise);
}

.sp-seg {
  display: flex;
}

.sp-seg button {
  position: relative;
  flex: 1;
  border-radius: 0;
}

.sp-seg button + button {
  margin-left: -1px;
}

.sp-seg button:first-child {
  border-radius: 4px 0 0 4px;
}

.sp-seg button:last-child {
  border-radius: 0 4px 4px 0;
}

.sp-seg button:only-child {
  border-radius: 4px;
}

.sp-seg button[aria-pressed="true"] {
  background: var(--color-fg);
  border-color: var(--color-fg);
  color: var(--color-bg);
}

.sp-seg button[hidden] {
  display: none;
}

/* Rail-tab-style square buttons (separate, gapped, background-only states, no border by default)
   instead of a fused segmented pill: honeycomb's scope switch (panel/scope-bar.js, Timer icons -
   only its numbered segments; a scope's Global segment, when shown, keeps the plain text/fused
   look) and the Sides choice (panel/controls.js, its own text instead of an icon). The .sp-seg
   prefix on every rule keeps these at higher specificity than the plain .sp-seg rules above,
   regardless of source order. */
.sp-seg.sp-scope-tabs {
  gap: 4px;
}

.sp-seg.sp-scope-tabs button {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 40px;
  margin-left: 0;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--sp-mute);
}

/* Higher specificity than the display:flex above, so a hidden segment (honeycomb's own Global,
   always hidden - see clampScope) stays hidden instead of the flex display winning at equal
   specificity by source order. */
.sp-seg.sp-scope-tabs button[hidden] {
  display: none;
}

.sp-seg.sp-scope-tabs button:first-child,
.sp-seg.sp-scope-tabs button:last-child,
.sp-seg.sp-scope-tabs button:only-child {
  border-radius: 4px;
}

.sp-seg.sp-scope-tabs button:hover,
.sp-seg.sp-scope-tabs button[aria-pressed="true"] {
  color: var(--color-fg);
}

.sp-seg.sp-scope-tabs button:hover {
  background: var(--sp-raise);
}

.sp-seg.sp-scope-tabs button[aria-pressed="true"] {
  background: var(--sp-active);
}

/* Sides' own variant: a light border, since its buttons show plain digits rather than an icon and
   read better with a visible edge (higher specificity than the borderless rule above). Also
   stretches to fill the row's width (unlike the scope switch's fixed 60px squares above) - Sides
   has few, short (1-digit) options, so a fixed width leaves the row looking unbalanced. */
.sp-seg.sp-scope-tabs.sp-scope-tabs-line button {
  flex: 1;
  width: auto;
  border: 1px solid var(--sp-line-strong);
}

/* Honeycomb's scope switch (panel/scope-bar.js): real browser-style tabs, connected to the content
   they open by color alone, no border tricks. Three flat levels, all existing tokens: the strip
   behind the tabs (.sp-scope above) is lightest (--sp-active); an inactive tab is a step darker
   (--sp-raise), reading as a separate, receded chip sitting on that strip; the active tab drops all
   the way to --sp-bg - the page's own, unchanged, "current" background - the same shade its content
   already sits on (panel/rail.js sets no background of its own on a tab panel), so it reads as a
   hole cut straight through the strip down to the content. Higher specificity than the plain
   sp-scope-tabs rules above (4 classes vs. 2-3), so this need not care about source order either. */
.sp-seg.sp-scope-tabs.sp-scope-tabs-connected button {
  border-radius: 4px 4px 0 0;
  background: var(--sp-raise);
}

.sp-seg.sp-scope-tabs.sp-scope-tabs-connected button[aria-pressed="true"] {
  background: var(--sp-bg);
  color: var(--color-fg);
}

/* ---- Overview tab: Automate | Randomize ---- */

/* Same three-flat-levels trick as .sp-scope (above): a lighter strip behind the tabs so an
   inactive one reads as a receded chip and the active one drops to the page's own background,
   like a hole cut through down to the content. Stretched full width (unlike the scope switch's
   fixed-width digit buttons) since these are words. */
.sp-oswitch {
  padding: 8px 8px 0;
  border-radius: 4px 4px 0 0;
  background: var(--sp-scope-bg, var(--color-bg));
}

.sp-oswitch.sp-scope-tabs.sp-scope-tabs-connected button {
  flex: 1;
  width: auto;
}

.sp-orows {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sp-osec h5 {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: inherit;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--sp-mute);
}

.sp-onote {
  color: var(--sp-mute);
}

.sp-orow {
  position: relative; /* anchors the hidden checkbox (below), same reason .sp-check does */
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  cursor: pointer;
}

.sp-oname {
  flex: 1;
  min-width: 0;
}

.sp-orange {
  color: var(--sp-mute);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.sp-orow .sp-val {
  min-width: 3ch;
  text-align: right;
}

/* ---- Presets tab: name field + Save, then a scrollable list of clickable rows
   (the panel body, .sp-main, already scrolls) ---- */

.sp-save {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  margin-left: 16px;
  margin-right: 16px;
}

.sp-save input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid var(--sp-line-strong);
  border-radius: 4px;
  background: none;
  color: var(--color-fg);
  font: inherit;
}

/* Its own visible box: tint it directly on focus, never an outline (src/tailwind.css kills
   the native ring). */
.sp-save input[type="text"]:focus {
  background: var(--sp-raise);
}

/* The Load button's file input: visually hidden (not display:none, which some browsers treat as
   "not interactive"), triggered by the visible button via .click() */
.sp-file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.sp-presets {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  margin-left: 16px;
  margin-right: 16px;
}

.sp-preset-row {
  padding: 6px 10px;
  border: none;
  border-radius: 4px;
  background: var(--sp-raise);
  color: var(--color-fg);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.sp-preset-row:hover {
  background: var(--sp-active);
}

.sp-preset-row:focus {
  outline: 1px solid var(--color-fg);
  outline-offset: 1px;
}

.sp-preset-row[aria-pressed="true"] {
  background: var(--color-fg);
  color: var(--color-bg);
}
