/* =========================================================
   Settings panel (built by js/settings.js)
   Desktop: a popover above the dock. Phones: a bottom sheet.
   Both open and close with a transition, never with display:none.
   ========================================================= */
.sp-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(8, 6, 20, 0.45);
  opacity: 0;
  visibility: hidden;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.28s ease, visibility 0s linear 0.28s;
}
.sp-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.28s ease, visibility 0s;
}

.sp {
  --sp-bg: rgba(24, 24, 30, 0.94);
  --sp-ink: #f4f4f5;
  --sp-edge: rgba(255, 255, 255, 0.12);
  --sp-field: rgba(255, 255, 255, 0.07);
  --sp-field-edge: rgba(255, 255, 255, 0.14);
  --sp-accent: #7c3aed;
  --drag: 0px;

  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(104px + env(safe-area-inset-bottom, 0px));
  width: min(92vw, 22rem);
  max-height: calc(100dvh - 140px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 1.1rem 1.1rem;
  border-radius: 20px;
  background: var(--sp-bg);
  color: var(--sp-ink);
  border: 1px solid var(--sp-edge);
  box-shadow: 0 28px 56px -18px rgba(0, 0, 0, 0.75);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  backdrop-filter: blur(18px) saturate(1.2);
  font: 0.95rem/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  outline: none;

  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 14px) scale(0.94);
  transform-origin: 50% 100%;
  transition:
    opacity 0.22s ease,
    transform 0.34s cubic-bezier(0.32, 1.2, 0.4, 1),
    background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease,
    visibility 0s linear 0.34s;
}
.sp.is-open {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0) scale(1);
  transition:
    opacity 0.22s ease,
    transform 0.38s cubic-bezier(0.32, 1.2, 0.4, 1),
    background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease,
    visibility 0s;
}

html[data-theme="light"] .sp {
  --sp-bg: rgba(255, 255, 255, 0.95);
  --sp-ink: #1b1530;
  --sp-edge: rgba(30, 20, 70, 0.14);
  --sp-field: rgba(76, 29, 149, 0.06);
  --sp-field-edge: rgba(76, 29, 149, 0.2);
  --sp-accent: #6d28d9;
  box-shadow: 0 28px 56px -18px rgba(30, 20, 70, 0.45);
}
html[data-theme="light"] .sp-backdrop { background: rgba(30, 20, 70, 0.25); }

.sp__grab {
  display: none;
  width: 2.6rem;
  height: 0.3rem;
  margin: -0.35rem auto 0.7rem;
  border-radius: 99px;
  background: currentColor;
  opacity: 0.25;
}

.sp__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}
.sp__title { font-size: 1.1rem; font-weight: 800; margin: 0; }
.sp__label {
  margin: 0.9rem 0 0.45rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.65;
  display: flex;
  justify-content: space-between;
}
.sp__val { font-variant-numeric: tabular-nums; }
.sp__row { display: flex; gap: 0.4rem; align-items: center; }

.sp button,
.sp__login {
  font: inherit;
  font-weight: 700;
  color: inherit;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--sp-field-edge);
  background: var(--sp-field);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.12s ease, opacity 0.2s ease;
}
.sp button:active,
.sp__login:active { transform: scale(0.97); }
.sp button:disabled { opacity: 0.35; cursor: default; transform: none; }

.sp .sp__x {
  flex: none;
  width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  margin: -0.4rem -0.5rem -0.4rem 0;
  padding: 0;
  border: 0;
  background: none;
  border-radius: 50%;
}
.sp__x svg {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.sp__seg {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0 0.4rem;
}
.sp__seg svg {
  width: 1.05rem;
  height: 1.05rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sp__seg[aria-pressed="true"] {
  background: var(--sp-accent);
  border-color: transparent;
  color: #fff;
}

.sp__step { min-width: 48px; padding: 0 0.5rem; }
.sp__step--big { font-size: 1.12em; }
.sp input[type="range"] { flex: 1; min-width: 0; accent-color: var(--sp-accent); height: 44px; margin: 0; }

.sp__foot { display: flex; justify-content: flex-end; margin: 0.3rem 0 0.7rem; }
.sp .sp__link {
  min-height: 40px;
  padding: 0 0.7rem;
  background: none;
  border: 0;
  text-decoration: underline;
  font-weight: 600;
  opacity: 0.8;
}

.sp__login {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  text-decoration: none;
  background: linear-gradient(180deg, #8b5cf6, #6d28d9);
  border-color: transparent;
  color: #fff;
}
.sp__login svg {
  width: 1.15em;
  height: 1.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sp button:focus-visible,
.sp__login:focus-visible,
.sp input:focus-visible { outline: 2px solid #0a84ff; outline-offset: 2px; }

/* phones: bottom sheet that slides up */
@media (max-width: 600px) {
  .sp {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 82dvh;
    padding: 1rem 1.1rem calc(1.2rem + env(safe-area-inset-bottom, 0px));
    border-radius: 22px 22px 0 0;
    border-bottom: 0;
    opacity: 1;
    transform: translateY(105%);
    transform-origin: 50% 100%;
    transition:
      transform 0.34s cubic-bezier(0.4, 0, 0.2, 1),
      visibility 0s linear 0.34s;
  }
  .sp.is-open {
    transform: translateY(var(--drag, 0px));
    transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s;
  }
  .sp.is-dragging { transition: none !important; }
  .sp__grab { display: block; touch-action: none; }
  .sp__head { touch-action: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sp,
  .sp.is-open { transition: opacity 0.15s linear, visibility 0s linear 0.15s; }
  .sp.is-open { transition: opacity 0.15s linear, visibility 0s; }
  .sp-backdrop { transition-duration: 0.01s; }
}
