/* Smart Playlist Builder modal */
.spb-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.62);
  backdrop-filter: blur(8px);
  z-index: 9000;
  display: grid; place-items: center;
  padding: 32px;
  animation: spb-fade-in 140ms ease;
}
@keyframes spb-fade-in { from { opacity: 0; } to { opacity: 1; } }

.spb-panel {
  width: min(960px, 100%);
  max-height: 86vh;
  background: rgba(20,16,12,0.98);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 18px;
  box-shadow: 0 32px 80px rgba(0,0,0,0.6);
  color: #fff;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  font-family: inherit;
  animation: spb-slide-in 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes spb-slide-in {
  from { transform: translateY(12px) scale(0.98); opacity: 0; }
  to   { transform: translateY(0) scale(1);       opacity: 1; }
}

[data-theme="light"] .spb-panel {
  background: #fff;
  color: rgba(0,0,0,0.92);
  border-color: rgba(0,0,0,0.08);
}

.spb-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.spb-head__l { flex: 1; min-width: 0; }
.spb-head__r { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

/* Match ALL / Match ANY toggle */
.spb-mode {
  display: inline-flex;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
[data-theme="light"] .spb-mode { background: rgba(0,0,0,0.03); border-color: rgba(0,0,0,0.1); }
.spb-mode__btn {
  background: transparent; border: 0; cursor: pointer;
  padding: 5px 10px; font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  color: rgba(255,255,255,0.55); border-radius: 6px;
  font-family: inherit;
}
.spb-mode__btn.is-on {
  background: rgba(255,255,255,0.1);
  color: #fff;
}
[data-theme="light"] .spb-mode__btn { color: rgba(0,0,0,0.55); }
[data-theme="light"] .spb-mode__btn.is-on { background: rgba(0,0,0,0.08); color: #000; }

/* Presets row */
.spb-presets {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 24px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
[data-theme="light"] .spb-presets { border-bottom-color: rgba(0,0,0,0.06); }
.spb-presets__lbl {
  font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  color: rgba(255,255,255,0.45); font-weight: 600; flex-shrink: 0;
}
[data-theme="light"] .spb-presets__lbl { color: rgba(0,0,0,0.5); }
.spb-presets__row { display: flex; gap: 6px; flex-wrap: wrap; }
.spb-pset {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.85);
  padding: 5px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 500; font-family: inherit;
  cursor: pointer; transition: all 100ms ease;
}
.spb-pset:hover { border-color: rgba(255,255,255,0.25); color: #fff; }
.spb-pset.is-on {
  background: var(--accent, #FA3A05);
  border-color: var(--accent, #FA3A05);
  color: #1a0e08;
}
.spb-pset--clear { color: rgba(255,255,255,0.5); }
[data-theme="light"] .spb-pset { background: rgba(0,0,0,0.03); border-color: rgba(0,0,0,0.12); color: rgba(0,0,0,0.85); }

/* Custom presets — split button: label + small × to delete */
.spb-pset--custom {
  padding: 0;
  display: inline-flex; align-items: stretch;
  overflow: hidden;
  cursor: default;
}
.spb-pset--custom .spb-pset__lbl {
  appearance: none; border: 0; background: transparent;
  color: inherit; font: inherit; cursor: pointer;
  padding: 6px 8px 6px 12px;
}
.spb-pset--custom .spb-pset__x {
  appearance: none; border: 0; background: transparent;
  color: rgba(255,255,255,0.45); cursor: pointer;
  padding: 0 9px;
  font-size: 14px; line-height: 1;
  border-left: 1px solid rgba(255,255,255,0.08);
  transition: color 100ms ease, background 100ms ease;
}
.spb-pset--custom .spb-pset__x:hover { color: #fff; background: rgba(255,255,255,0.06); }
.spb-pset--custom.is-on .spb-pset__x { color: rgba(26,14,8,0.55); border-left-color: rgba(0,0,0,0.18); }
.spb-pset--custom.is-on .spb-pset__x:hover { color: #1a0e08; background: rgba(0,0,0,0.1); }
[data-theme="light"] .spb-pset--custom .spb-pset__x { color: rgba(0,0,0,0.4); border-left-color: rgba(0,0,0,0.1); }
.spb-presets__div {
  width: 1px; height: 18px; align-self: center;
  background: rgba(255,255,255,0.12);
  margin: 0 4px;
}
[data-theme="light"] .spb-presets__div { background: rgba(0,0,0,0.12); }

/* Collapsible group */
.spb-grp {
  border-bottom: 1px solid rgba(255,255,255,0.06);
  padding: 0;
}
[data-theme="light"] .spb-grp { border-bottom-color: rgba(0,0,0,0.06); }
.spb-grp:last-child { border-bottom: 0; }
.spb-grp__head {
  width: 100%;
  background: transparent; border: 0; cursor: pointer;
  display: flex; align-items: center; gap: 8px;
  padding: 14px 0;
  color: inherit; font-family: inherit; text-align: left;
}
.spb-grp__caret {
  display: inline-block;
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  transform: rotate(-90deg);
  transition: transform 140ms ease;
}
.spb-grp.is-open .spb-grp__caret { transform: rotate(0deg); }
.spb-grp__title {
  font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase;
  font-weight: 700; color: rgba(255,255,255,0.92);
}
[data-theme="light"] .spb-grp__title { color: rgba(0,0,0,0.85); }
.spb-grp__count {
  background: var(--accent, #FA3A05);
  color: #1a0e08;
  font-size: 10px; font-weight: 700;
  padding: 2px 7px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.spb-grp__body {
  padding: 0 0 6px 16px;
}

/* Filter row right side: value + exclude pill */
.spb-sec__rt { display: flex; align-items: center; gap: 8px; }
.spb-excl {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.5);
  font-size: 9px; font-weight: 700; letter-spacing: 0.08em;
  padding: 3px 7px; border-radius: 999px;
  cursor: pointer; font-family: inherit;
  text-transform: uppercase;
}
.spb-excl:hover { border-color: rgba(255,255,255,0.3); color: rgba(255,255,255,0.9); }
.spb-excl.is-on {
  background: rgba(255, 80, 60, 0.15);
  border-color: rgba(255, 80, 60, 0.6);
  color: rgb(255, 130, 110);
}
[data-theme="light"] .spb-excl { border-color: rgba(0,0,0,0.15); color: rgba(0,0,0,0.5); }
[data-theme="light"] .spb-excl.is-on {
  background: rgba(220, 40, 20, 0.1);
  border-color: rgba(220, 40, 20, 0.5);
  color: rgb(190, 50, 30);
}

/* Toggle (checkbox + label inline) */
.spb-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; color: rgba(255,255,255,0.75);
  cursor: pointer;
  margin: 6px 0;
}
[data-theme="light"] .spb-toggle { color: rgba(0,0,0,0.75); }
.spb-toggle--mt { margin-top: 10px; }
.spb-toggle input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 14px; height: 14px;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 3px; background: transparent;
  position: relative; cursor: pointer;
  flex-shrink: 0;
}
.spb-toggle input[type="checkbox"]:checked {
  background: var(--accent, #FA3A05);
  border-color: var(--accent, #FA3A05);
}
.spb-toggle input[type="checkbox"]:checked::after {
  content: ""; position: absolute; left: 3px; top: 0;
  width: 4px; height: 8px;
  border: solid #1a0e08;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
[data-theme="light"] .spb-toggle input[type="checkbox"] { border-color: rgba(0,0,0,0.25); }

/* Preview combine-mode line */
.spb-preview__mode {
  font-size: 10px; color: rgba(255,255,255,0.4);
  margin-top: 8px; letter-spacing: 0.04em;
  text-transform: uppercase;
}
.spb-preview__mode strong {
  color: var(--accent, #FA3A05);
  font-weight: 700;
}
[data-theme="light"] .spb-preview__mode { color: rgba(0,0,0,0.5); }

/* Footer message flash */
.spb-foot__msg {
  color: var(--accent, #FA3A05);
  font-weight: 600;
}
.spb-btn--ghost {
  background: transparent;
}
[data-theme="light"] .spb-head { border-bottom-color: rgba(0,0,0,0.06); }
.spb-eyebrow {
  font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  color: rgba(255,255,255,0.5); margin-bottom: 6px; font-weight: 600;
}
[data-theme="light"] .spb-eyebrow { color: rgba(0,0,0,0.5); }
.spb-name {
  background: transparent; border: 0; padding: 0;
  font-size: 22px; font-weight: 600; letter-spacing: -0.01em;
  color: inherit; outline: none; width: 100%;
}
.spb-name:focus { outline: none; }
.spb-name:hover { background: rgba(255,255,255,0.03); border-radius: 4px; padding: 0 4px; margin: 0 -4px; }

.spb-close {
  background: transparent; border: 0; cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px;
  font-size: 20px; line-height: 1; color: rgba(255,255,255,0.6);
  display: grid; place-items: center;
}
.spb-close:hover { background: rgba(255,255,255,0.08); color: #fff; }
[data-theme="light"] .spb-close { color: rgba(0,0,0,0.5); }
[data-theme="light"] .spb-close:hover { background: rgba(0,0,0,0.06); color: #000; }

.spb-body {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  min-height: 0;
}
@media (max-width: 720px) {
  .spb-body { grid-template-columns: 1fr; }
}

.spb-rules { padding: 20px 24px; overflow: auto; min-height: 0; }
.spb-sec { padding: 14px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
[data-theme="light"] .spb-sec { border-bottom-color: rgba(0,0,0,0.05); }
.spb-sec:last-child { border-bottom: 0; }
.spb-sec--row { display: flex; gap: 16px; }
.spb-sec--row .spb-field { flex: 1; }

.spb-sec__head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 10px;
}
.spb-sec__lbl {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  font-weight: 600; color: rgba(255,255,255,0.55);
}
[data-theme="light"] .spb-sec__lbl { color: rgba(0,0,0,0.55); }
.spb-sec__val {
  font-size: 13px; color: rgba(255,255,255,0.92);
  font-variant-numeric: tabular-nums;
}
[data-theme="light"] .spb-sec__val { color: rgba(0,0,0,0.85); }

/* Dual-thumb BPM range using stacked sliders */
.spb-range {
  position: relative; height: 28px; display: grid; align-items: center;
}
.spb-range input[type="range"] {
  position: absolute; inset: 0;
  width: 100%; height: 28px;
  background: transparent;
  -webkit-appearance: none; appearance: none;
  pointer-events: none;
  margin: 0;
}
.spb-range input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: rgba(255,255,255,0.1);
}
.spb-range input[type="range"]::-moz-range-track {
  height: 4px; border-radius: 2px;
  background: rgba(255,255,255,0.1);
}
.spb-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 999px;
  background: var(--accent, #FA3A05);
  border: 2px solid rgba(20,16,12,0.98);
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  margin-top: -6px;
  pointer-events: auto; cursor: grab;
}
.spb-range input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 999px;
  background: var(--accent, #FA3A05);
  border: 2px solid rgba(20,16,12,0.98);
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
  pointer-events: auto; cursor: grab;
}
.spb-range__ticks {
  display: flex; justify-content: space-between;
  font-size: 10px; color: rgba(255,255,255,0.4);
  margin-top: 4px;
}

/* Chip (key + genre selectors) */
.spb-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.spb-chip {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.75);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 100ms ease;
  font-family: inherit;
}
.spb-chip:hover { border-color: rgba(255,255,255,0.25); color: #fff; }
.spb-chip.is-on {
  background: var(--accent, #FA3A05);
  border-color: var(--accent, #FA3A05);
  color: #1a0e08;
  font-weight: 600;
}
[data-theme="light"] .spb-chip {
  border-color: rgba(0,0,0,0.12);
  color: rgba(0,0,0,0.7);
}
[data-theme="light"] .spb-chip:hover { border-color: rgba(0,0,0,0.3); color: #000; }

/* Limit + sort fields */
.spb-field {
  display: flex; flex-direction: column; gap: 6px;
}
.spb-field input[type="number"],
.spb-field select {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  color: inherit;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.spb-field input[type="number"]:focus,
.spb-field select:focus {
  border-color: var(--accent, #FA3A05);
  background: rgba(255,255,255,0.06);
}
[data-theme="light"] .spb-field input[type="number"],
[data-theme="light"] .spb-field select {
  background: rgba(0,0,0,0.03); border-color: rgba(0,0,0,0.12);
}

/* Preview pane */
.spb-preview {
  background: rgba(255,255,255,0.025);
  border-left: 1px solid rgba(255,255,255,0.05);
  display: flex; flex-direction: column;
  min-height: 0;
}
[data-theme="light"] .spb-preview {
  background: rgba(0,0,0,0.02);
  border-left-color: rgba(0,0,0,0.05);
}
.spb-preview__head {
  padding: 20px 24px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
[data-theme="light"] .spb-preview__head { border-bottom-color: rgba(0,0,0,0.05); }
.spb-preview__num {
  font-size: 36px; font-weight: 600; letter-spacing: -0.02em;
  color: #fff; line-height: 1;
}
[data-theme="light"] .spb-preview__num { color: #000; }
.spb-preview__sub {
  font-size: 12px; color: rgba(255,255,255,0.55); margin-top: 4px;
}
[data-theme="light"] .spb-preview__sub { color: rgba(0,0,0,0.55); }

.spb-list { list-style: none; margin: 0; padding: 8px 0; overflow: auto; min-height: 0; flex: 1; }
.spb-item { display: block; padding: 0 16px; font-size: 13px; }
.spb-item--more {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center; gap: 10px;
  padding: 8px 24px;
}
.spb-item__row {
  appearance: none; border: 0; background: transparent;
  width: 100%;
  display: grid; grid-template-columns: 28px 1fr auto;
  align-items: center; gap: 10px;
  padding: 7px 8px;
  color: inherit; font: inherit; text-align: left;
  border-radius: 6px; cursor: pointer;
  transition: background 100ms ease;
}
.spb-item__row:hover { background: rgba(255,255,255,0.04); }
.spb-item__row:focus-visible { outline: 2px solid var(--accent, #FA3A05); outline-offset: -2px; }
[data-theme="light"] .spb-item__row:hover { background: rgba(0,0,0,0.04); }
.spb-item__num {
  position: relative;
  width: 28px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.35); font-size: 11px;
}
.spb-item__numtxt, .spb-item__play, .spb-item__eq {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 120ms ease;
}
.spb-item__play { opacity: 0; color: var(--accent, #FA3A05); font-size: 9px; }
.spb-item__eq   { opacity: 0; gap: 2px; }
.spb-item__row:hover .spb-item__numtxt { opacity: 0; }
.spb-item__row:hover .spb-item__play   { opacity: 1; }
.spb-item.is-playing .spb-item__numtxt { opacity: 0; }
.spb-item.is-playing .spb-item__play   { opacity: 0; }
.spb-item.is-playing .spb-item__eq     { opacity: 1; }
.spb-item.is-playing .spb-item__row    { background: rgba(250,58,5,0.06); }
.spb-item.is-playing .spb-item__title  { color: #fff; }
[data-theme="light"] .spb-item.is-playing .spb-item__row { background: rgba(250,58,5,0.08); }
[data-theme="light"] .spb-item.is-playing .spb-item__title { color: #1a0e08; }
.spb-item__eq i {
  display: block; width: 2px; height: 10px;
  background: var(--accent, #FA3A05); border-radius: 1px;
  animation: spbEq 700ms ease-in-out infinite;
}
.spb-item__eq i:nth-child(2) { animation-delay: 120ms; height: 7px; }
.spb-item__eq i:nth-child(3) { animation-delay: 240ms; height: 12px; }
@keyframes spbEq { 0%,100% { transform: scaleY(0.5); } 50% { transform: scaleY(1); } }
.spb-item__title {
  color: rgba(255,255,255,0.92);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
[data-theme="light"] .spb-item__title { color: rgba(0,0,0,0.9); }
.spb-item__meta { color: rgba(255,255,255,0.45); font-size: 11px; }
.spb-item--more { color: rgba(255,255,255,0.45); padding-top: 10px; }

.spb-empty { padding: 32px 24px; text-align: center; }
.spb-empty__h { font-weight: 600; color: rgba(255,255,255,0.85); margin-bottom: 6px; }
.spb-empty__b { font-size: 13px; color: rgba(255,255,255,0.5); }
[data-theme="light"] .spb-empty__h { color: rgba(0,0,0,0.85); }
[data-theme="light"] .spb-empty__b { color: rgba(0,0,0,0.55); }

/* Footer */
.spb-foot {
  padding: 16px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.2);
}
[data-theme="light"] .spb-foot {
  border-top-color: rgba(0,0,0,0.06);
  background: rgba(0,0,0,0.02);
}
.spb-foot__hint {
  font-size: 11px; color: rgba(255,255,255,0.45); flex: 1;
}
[data-theme="light"] .spb-foot__hint { color: rgba(0,0,0,0.5); }
.spb-foot__actions { display: flex; gap: 8px; }

/* New: text input + custom date range + show-more toggle */
.spb-text {
  width: 100%;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  color: inherit;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
.spb-text:focus { border-color: var(--accent, #FA3A05); background: rgba(255,255,255,0.06); }
[data-theme="light"] .spb-text { background: rgba(0,0,0,0.03); border-color: rgba(0,0,0,0.12); }

.spb-daterange { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.spb-daterange input[type="date"] {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  color: inherit;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  color-scheme: dark;
}
[data-theme="light"] .spb-daterange input[type="date"] { background: rgba(0,0,0,0.03); border-color: rgba(0,0,0,0.12); color-scheme: light; }
.spb-daterange input[type="date"]:focus { border-color: var(--accent, #FA3A05); }

.spb-more {
  background: transparent; border: 0;
  color: rgba(255,255,255,0.55);
  font-size: 11px; font-weight: 500;
  padding: 6px 0 0; cursor: pointer; font-family: inherit;
}
.spb-more:hover { color: var(--accent, #FA3A05); }
[data-theme="light"] .spb-more { color: rgba(0,0,0,0.55); }
.spb-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.85);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13px; font-weight: 500;
  cursor: pointer; font-family: inherit;
  transition: all 100ms ease;
}
.spb-btn:hover:not(:disabled) { border-color: rgba(255,255,255,0.25); color: #fff; }
.spb-btn--primary {
  background: var(--accent, #FA3A05);
  border-color: var(--accent, #FA3A05);
  color: #1a0e08; font-weight: 600;
}
.spb-btn--primary:hover:not(:disabled) {
  filter: brightness(1.08);
}
.spb-btn:disabled { opacity: 0.4; cursor: not-allowed; }
[data-theme="light"] .spb-btn { border-color: rgba(0,0,0,0.15); color: rgba(0,0,0,0.85); }
[data-theme="light"] .spb-btn:hover:not(:disabled) { border-color: rgba(0,0,0,0.35); color: #000; }

@media (max-width: 720px) {
  .spb-overlay {
    place-items: start center;
    padding: calc(var(--m-safe-top, env(safe-area-inset-top, 0px)) + 12px) 12px calc(var(--m-tabbar-h, 64px) + var(--m-safe-bottom, env(safe-area-inset-bottom, 0px)) + 24px);
    box-sizing: border-box;
  }
  .spb-panel {
    width: 100%;
    max-height: calc(100dvh - var(--m-safe-top, env(safe-area-inset-top, 0px)) - var(--m-tabbar-h, 64px) - var(--m-safe-bottom, env(safe-area-inset-bottom, 0px)) - 36px);
  }
  .spb-presets {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    padding: 10px 16px 12px;
  }
  .spb-presets__row {
    width: 100%;
    min-width: 0;
    gap: 8px;
  }
  .spb-body {
    min-height: 0;
    overflow: hidden;
  }
  .spb-rules {
    padding: 16px;
  }
  .spb-foot {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px calc(var(--m-safe-bottom, env(safe-area-inset-bottom, 0px)) + 12px);
  }
  .spb-foot__actions {
    flex-wrap: wrap;
  }
  .spb-btn {
    flex: 1 1 120px;
  }
}
