:root {
  --bg: #0a0a12;
  --fg: #f3f3fb;
  --muted: #a7a7c4;
  --accent: #7c5cff;
  --accent-rgb: 124, 92, 255;
  --accent2: #2dd4bf;
  --accent2-rgb: 45, 212, 191;
  --accent3: #b06bff;
  --accent3-rgb: 176, 107, 255;
  --danger: #ff5c7c;
  --good: #2dd4bf;
  --glass: rgba(255, 255, 255, 0.06);
  --glass-bd: rgba(255, 255, 255, 0.10);
  --radius: 20px;
  --grad: linear-gradient(135deg, var(--accent), var(--accent3));
  --grad-live: linear-gradient(90deg, var(--accent2), var(--accent));
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html { background: var(--bg); }
html, body {
  margin: 0; min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}
body { background: transparent; }
button { font-family: inherit; cursor: pointer; }
svg { display: block; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(var(--accent-rgb), 0.55) transparent; }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb {
  border-radius: 99px; border: 3px solid transparent; background-clip: padding-box;
  background-color: rgba(var(--accent-rgb), 0.5);
  background-image: linear-gradient(180deg, rgba(255,255,255,0.35), rgba(255,255,255,0) 42%, rgba(0,0,0,0.22));
}
::-webkit-scrollbar-thumb:hover { background-color: rgba(var(--accent-rgb), 0.8); }

/* Blurred album-art background */
.bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: var(--bg); }
.bg-art {
  position: absolute; inset: -10%;
  background-size: cover; background-position: center;
  filter: blur(34px) saturate(1.3) brightness(0.82); transform: scale(1.12);
  opacity: 0; transition: opacity 0.9s ease;
}
.bg-art.on { opacity: 1; }
.bg-scrim {
  position: absolute; inset: 0;
  background: radial-gradient(130% 100% at 50% 0%,
    rgba(10,10,18,0.42), rgba(10,10,18,0.72) 55%, rgba(10,10,18,0.94));
}

/* Layout */
.app {
  max-width: 640px; margin: 0 auto; padding: 22px 16px 64px;
  display: flex; flex-direction: column; gap: 16px;
}

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 4px 2px; }
.brand { display: flex; align-items: center; gap: 13px; }
.logo {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  color: #fff; background: var(--grad);
  box-shadow: 0 8px 24px rgba(var(--accent-rgb), 0.45);
}
.logo svg { width: 26px; height: 26px; }
.topbar h1 { font-size: 20px; font-weight: 800; letter-spacing: -0.5px; margin: 0; }
.accent2 { color: var(--accent2); }
.room { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.top-right { display: flex; align-items: center; gap: 10px; }
.status {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted);
  background: var(--glass); border: 1px solid var(--glass-bd); padding: 7px 12px; border-radius: 99px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); transition: background .3s; }
.dot.online { background: var(--accent2); box-shadow: 0 0 10px var(--accent2); }
.dot.offline { background: var(--danger); box-shadow: 0 0 10px var(--danger); }

/* Glass panel */
.panel {
  background: var(--glass); border: 1px solid var(--glass-bd); border-radius: var(--radius);
  padding: 18px; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
  animation: slide-in .26s ease;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.label {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; color: var(--muted);
}
.label svg { width: 15px; height: 15px; color: var(--accent2); }

/* Now playing */
.now-inner { display: flex; gap: 16px; align-items: center; }
.art {
  position: relative; width: 104px; height: 104px; flex-shrink: 0; border-radius: 16px; overflow: hidden;
  background: linear-gradient(135deg, #221a44, #122e34); border: 1px solid var(--glass-bd);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.art-placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: rgba(255,255,255,0.3); }
.art-placeholder svg { width: 40px; height: 40px; }
.np-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.np-title { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-sub { color: var(--muted); font-size: 13px; margin: 3px 0 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.volume { display: flex; align-items: center; gap: 11px; }
.icon-btn { background: none; border: none; color: var(--fg); padding: 0; width: 24px; }
.icon-btn svg { width: 21px; height: 21px; }
.vol-val { width: 26px; text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; flex: 1; height: 6px; border-radius: 99px;
  background: rgba(255,255,255,0.12); outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 5px rgba(0,0,0,.5), 0 0 0 3px rgba(var(--accent-rgb), .5);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border: none; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .5);
}

/* Transport */
.controls { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 18px; }
.ctl {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%;
  background: var(--glass); border: 1px solid var(--glass-bd); color: var(--fg);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: transform .08s ease, background .15s ease;
}
.ctl svg { width: 20px; height: 20px; }
.ctl:hover { background: rgba(255,255,255,0.12); }
.ctl:active { transform: scale(0.92); }
.ctl.primary {
  width: 60px; height: 60px; border-color: transparent; color: #fff; background: var(--grad);
  box-shadow: 0 8px 24px rgba(var(--accent-rgb), 0.5);
}
.ctl.primary svg { width: 24px; height: 24px; }
.ctl.sm { width: 36px; height: 36px; }
.ctl.sm svg { width: 17px; height: 17px; }

/* Buttons */
.btn {
  border: none; border-radius: 13px; padding: 13px 16px; font-size: 14px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .08s ease, filter .15s ease;
}
.btn.primary { color: #fff; background: var(--grad); box-shadow: 0 8px 22px rgba(var(--accent-rgb), 0.32); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { color: var(--fg); background: var(--glass); border: 1px solid var(--glass-bd); }
.btn.sm { padding: 0 16px; min-height: 44px; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .6; cursor: progress; }

.text-btn { background: none; border: none; color: var(--accent3); font-size: 13.5px; font-weight: 700; }
.count { color: var(--muted); font-weight: 600; font-size: 12px; }

/* Search/add bar */
.searchbar {
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,0.28); border: 1px solid var(--glass-bd); border-radius: 16px;
  padding: 6px 6px 6px 14px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.searchbar:focus-within { border-color: var(--accent); }
.searchbar .sb-icon { color: var(--muted); flex-shrink: 0; }
.searchbar .sb-icon svg { width: 18px; height: 18px; }
.bare {
  flex: 1; min-width: 0; background: none; border: none; outline: none;
  color: var(--fg); font-size: 15px; padding: 9px 0;
}
.bare::placeholder { color: #6b6b8c; }

/* Plain inputs (fav form, pin) */
.input {
  width: 100%; font-size: 15px; padding: 13px 15px; border-radius: 14px;
  border: 1px solid var(--glass-bd); background: rgba(0,0,0,0.30); color: var(--fg); outline: none;
  transition: border-color .15s;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: #6b6b8c; }

.hint { margin: 13px 2px 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.hint code { font-family: var(--mono); background: rgba(0,0,0,0.3); padding: 1px 6px; border-radius: 6px; font-size: 11.5px; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 8px 0; margin: 0; }

/* Chips / badges */
.chip {
  border: 1px solid var(--glass-bd); background: rgba(255,255,255,0.05); color: var(--muted);
  font-size: 11.5px; font-weight: 700; padding: 5px 11px; border-radius: 99px;
}
.chip.live { color: #fff; background: var(--grad); border-color: transparent; }
.chip.err { color: var(--danger); border-color: rgba(var(--accent-rgb), 0); }

/* Queue */
.queue-list { display: flex; flex-direction: column; gap: 8px; }
.queue-item {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--glass-bd); border-radius: 13px;
}
.queue-item.current { border-color: rgba(var(--accent-rgb), 0.6); background: rgba(var(--accent-rgb), 0.12); }
.q-icon { width: 14px; color: var(--accent2); flex-shrink: 0; }
.q-icon svg { width: 13px; height: 13px; }
.q-meta { flex: 1; min-width: 0; }
.q-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-artist { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-del { background: none; border: none; color: var(--muted); font-size: 16px; line-height: 1; }
.q-del:hover { color: var(--danger); }

/* Favorites */
.fav-form { display: flex; gap: 9px; margin-bottom: 13px; }
.fav-form .input { flex: 1; }
.fav-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 9px; }
.fav {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: rgba(255,255,255,0.04); border: 1px solid var(--glass-bd); border-radius: 13px; padding: 11px 13px;
  transition: border-color .15s;
}
.fav:hover { border-color: rgba(var(--accent-rgb), 0.5); }
.fav-play { flex: 1; min-width: 0; background: none; border: none; color: var(--fg); text-align: left;
  font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fav-del { background: none; border: none; color: var(--muted); font-size: 15px; }
.fav-del:hover { color: var(--danger); }

/* Spinner */
.spinner { width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Jukebox status */
.jb-status { display: flex; flex-direction: column; gap: 12px; }
.jb-row { display: flex; align-items: center; gap: 10px; }
.jb-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.jb-dot.live { background: var(--accent2); box-shadow: 0 0 9px var(--accent2); animation: pulse 1.6s infinite; }
.jb-dot.err { background: var(--danger); }
.jb-dot.wait { background: var(--accent); animation: pulse 1.6s infinite; }
.jb-text { flex: 1; font-size: 14px; }
.jb-dc { min-height: 36px; padding: 0 14px; font-size: 13px; }
.jb-now {
  background: rgba(0,0,0,0.28); border: 1px solid var(--glass-bd); border-radius: 14px; padding: 12px 14px;
}
.jb-title { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.jb-meta { font-size: 12px; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums;
  font-family: var(--mono); }
.jb-tune { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.jb-tune-label { color: var(--fg); font-weight: 600; }
.jb-step { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--glass-bd);
  background: var(--glass); color: var(--fg); font-size: 19px; line-height: 1; }
.jb-step:active { background: var(--accent); border-color: transparent; transform: scale(0.94); }
.jb-bias { min-width: 46px; text-align: center; font-variant-numeric: tabular-nums; color: var(--fg);
  font-weight: 700; font-family: var(--mono); }
.jb-tune-hint { font-size: 11px; }

/* Login modal + PIN */
.overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px;
  background: rgba(6,6,14,0.6); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.modal {
  width: 100%; max-width: 340px; padding: 30px 26px; border-radius: 22px; text-align: center;
  background: linear-gradient(160deg, rgba(30,30,52,0.92), rgba(16,16,30,0.92));
  border: 1px solid var(--glass-bd);
  backdrop-filter: blur(26px) saturate(1.3); -webkit-backdrop-filter: blur(26px) saturate(1.3);
  box-shadow: 0 30px 80px rgba(0,0,0,0.6); animation: slide-in .22s ease;
  display: flex; flex-direction: column; gap: 14px;
}
.modal .logo.big { width: 58px; height: 58px; margin: 0 auto 2px; }
.modal .logo.big svg { width: 32px; height: 32px; }
.modal h2 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.4px; }
.pin-dots { display: flex; justify-content: center; gap: 13px; margin: 2px 0 6px; min-height: 14px; }
.pin-dot { width: 13px; height: 13px; border-radius: 50%; background: rgba(255,255,255,0.12);
  border: 1px solid var(--glass-bd); transition: background .15s, transform .15s, border-color .15s; }
.pin-dot.filled { background: var(--accent); border-color: transparent; transform: scale(1.14);
  box-shadow: 0 0 10px rgba(var(--accent-rgb), 0.6); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-pad button {
  height: 62px; border-radius: 16px; border: 1px solid var(--glass-bd);
  background: var(--glass); color: var(--fg); font-size: 23px; font-weight: 600;
  transition: transform .08s, background .15s; user-select: none;
}
.pin-pad button:hover { background: rgba(255,255,255,0.12); }
.pin-pad button:active { transform: scale(0.94); background: var(--accent); border-color: transparent; }
.pin-pad .pin-fn { font-size: 19px; color: var(--muted); background: transparent; border-color: transparent; }
.pin-pad .pin-fn:active { background: var(--glass); color: var(--fg); }
.login-err { color: var(--danger); font-size: 13px; margin: 2px 0 0; }
.modal.shake { animation: shake .42s; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  background: linear-gradient(160deg, rgba(30,30,52,0.95), rgba(16,16,30,0.95));
  border: 1px solid var(--glass-bd); color: var(--fg); padding: 13px 18px; border-radius: 14px; font-size: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  opacity: 0; transition: opacity .25s, transform .25s; max-width: 90vw; z-index: 120;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--danger); }
.toast.ok { border-color: var(--accent2); }

/* Settings modal + devices */
.modal.settings { max-width: 440px; text-align: left; gap: 16px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -0.4px; }
.dev-list { display: flex; flex-direction: column; gap: 10px; max-height: 44vh; overflow-y: auto; padding-right: 2px; }
.dev-card { background: rgba(255,255,255,0.04); border: 1px solid var(--glass-bd); border-radius: 15px; padding: 13px 14px; }
.dev-card.active { border-color: rgba(var(--accent-rgb), 0.6); background: rgba(var(--accent-rgb), 0.10); }
.dev-top { display: flex; align-items: center; gap: 9px; }
.dev-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.dev-dot.online { background: var(--accent2); box-shadow: 0 0 9px var(--accent2); }
.dev-dot.offline { background: var(--danger); }
.dev-name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.dev-badge { font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: #fff;
  background: var(--grad); padding: 2px 8px; border-radius: 99px; }
.dev-sub { color: var(--muted); font-size: 12.5px; margin-top: 5px; }
.dev-stats { color: var(--fg); font-size: 12.5px; margin-top: 5px; font-variant-numeric: tabular-nums; }
.dev-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.mono { font-family: var(--mono); }
.btn.xs { min-height: 32px; padding: 0 13px; font-size: 12.5px; font-weight: 700; border-radius: 10px; }
.btn.ghost.danger { color: var(--danger); }
.dev-add .label { margin-bottom: 9px; }
.dev-add-form { display: flex; flex-direction: column; gap: 9px; }
.dev-add-actions { display: flex; gap: 9px; }
.dev-msg { color: var(--danger); font-size: 12.5px; margin: 9px 0 0; }
.dev-refresh { width: 100%; }

/* Motion */
@keyframes slide-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-9px); } 40%,80% { transform: translateX(9px); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media (max-width: 520px) {
  .now-inner { flex-direction: column; text-align: center; }
  .art { width: 100%; height: 200px; }
  .np-title { white-space: normal; }
  .np-body { width: 100%; }
}
