:root {
  --bg: #0e0f12;
  --surface: #181a20;
  --surface-2: #22242c;
  --gold: #e8c547;
  --gold-dim: #b4922e;
  --text: #f4f1ea;
  --muted: #9a958a;
  --line: rgba(244, 241, 234, 0.08);
  --line-strong: rgba(244, 241, 234, 0.16);
  --green: #6fcf97;
  --green-text: #9be3b8;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 620px at 85% -12%, rgba(232, 197, 71, 0.1), transparent 70%),
    radial-gradient(760px 620px at -10% 45%, rgba(43, 71, 122, 0.16), transparent 70%);
}

a { color: inherit; }

button { font-family: inherit; }

:focus-visible { outline: 2px solid rgba(232, 197, 71, 0.6); outline-offset: 2px; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.i {
  width: 1em;
  height: 1em;
  display: block;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(26, 22, 7, 0.25);
  border-top-color: #1a1607;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner.gold {
  width: 28px;
  height: 28px;
  border-color: rgba(232, 197, 71, 0.2);
  border-top-color: var(--gold);
}

@keyframes spin { to { transform: rotate(360deg); } }

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
}

/* ---------- login ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 20px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 34px 28px 28px;
  background: rgba(24, 26, 32, 0.92);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.login-logo {
  display: block;
  width: 60px;
  height: 60px;
  margin: 0 auto;
  border-radius: 14px;
}

.login-card h1 {
  margin: 18px 0 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-align: center;
}

.login-sub {
  margin: 6px 0 0;
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--muted);
  text-align: center;
}

.field {
  position: relative;
  display: block;
  margin-top: 12px;
}

.field:first-of-type { margin-top: 28px; }

.field input {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  transition: border-color 0.15s ease;
}

.field input::placeholder { color: var(--muted); }

.field input:focus {
  outline: none;
  border-color: var(--gold);
}

.field-password input { padding-right: 48px; }

.eye {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.eye .i { width: 20px; height: 20px; }

.eye:hover { color: var(--text); }

.btn-gold {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  height: 48px;
  margin-top: 20px;
  border: 0;
  border-radius: 12px;
  background: var(--gold);
  color: #1a1607;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-gold:hover { background: #f2d465; }

.btn-gold:disabled { cursor: default; opacity: 0.75; }

.login-hint {
  margin: 18px 0 0;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
  text-align: center;
}

/* ---------- topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding-top: env(safe-area-inset-top);
  background: rgba(14, 15, 18, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand img { border-radius: 9px; }

.brand-text b {
  display: block;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 1.5px;
}

.brand-text small {
  display: block;
  font-size: 8px;
  line-height: 1.2;
  letter-spacing: 2.6px;
  color: var(--gold-dim);
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 12px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(244, 241, 234, 0.08);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.live-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
}

.live-badge.connected {
  background: rgba(111, 207, 151, 0.12);
  border-color: rgba(111, 207, 151, 0.25);
  color: var(--green-text);
}

.live-badge.connected .dot { background: var(--green); }

.spacer { flex: 1; }

.user-email {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  color: var(--muted);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn .i { width: 20px; height: 20px; }

.icon-btn:hover { background: rgba(244, 241, 234, 0.05); color: var(--text); }

/* ---------- pages ---------- */

main { display: block; }

.page {
  margin: 0 auto;
  padding: 30px 20px 48px;
}

.page-devices { max-width: 820px; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.page-head h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
}

.page-head p {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.link-gold {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--gold);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.link-gold .i { width: 18px; height: 18px; }

.link-gold:hover { background: rgba(232, 197, 71, 0.08); }

.device-list {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.device-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(24, 26, 32, 0.88);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.device-card:hover { border-color: rgba(232, 197, 71, 0.32); }

.device-card:active { transform: translateY(1px); }

.device-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
}

.device-icon .i { width: 21px; height: 21px; }

.device-card.online .device-icon {
  background: rgba(232, 197, 71, 0.12);
  color: var(--gold);
}

.device-info { flex: 1; min-width: 0; }

.device-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15.5px;
  font-weight: 700;
}

.device-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.device-card.online .device-meta .dot,
.dev-status.online .dot { background: var(--green); }

.device-card.online .device-meta .status-text,
.dev-status.online .status-text { color: var(--green-text); }

.chevron { width: 20px; height: 20px; color: var(--muted); }

.empty {
  padding: 44px 24px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(24, 26, 32, 0.7);
  text-align: center;
}

.empty .i {
  width: 40px;
  height: 40px;
  margin: 0 auto;
  color: var(--muted);
}

.empty h3 {
  margin: 14px 0 0;
  font-size: 16px;
  font-weight: 700;
}

.empty p {
  max-width: 400px;
  margin: 8px auto 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--muted);
}

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  padding: 10px 6px 10px 14px;
  border: 1px solid rgba(255, 107, 107, 0.2);
  border-radius: 12px;
  background: rgba(255, 107, 107, 0.12);
  color: #ffc9c9;
  font-size: 13px;
}

.banner .i { width: 18px; height: 18px; color: #ff9b9b; }

.banner .banner-text { flex: 1; }

.banner .close {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.banner .close .i { width: 16px; height: 16px; color: var(--muted); }

#devices-error:empty, #player-error:empty { display: none; }

.footnote {
  margin: 24px 0 0;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
  text-align: center;
}

/* ---------- player ---------- */

.page-player {
  max-width: 720px;
  padding-top: 20px;
}

.player-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
}

.back { width: 40px; height: 40px; color: var(--text); }

.back .i { width: 22px; height: 22px; }

.player-title { flex: 1; min-width: 0; }

.player-title h2 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
  font-weight: 800;
}

.player-title p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.dev-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.artwork {
  display: grid;
  place-items: center;
  width: 216px;
  height: 216px;
  margin: 8px auto 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(135deg, #2a2410, #22242c);
}

#art-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#art-note { width: 64px; height: 64px; color: rgba(232, 197, 71, 0.4); }

#track-title {
  margin: 26px 0 0;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
}

#track-sub {
  margin: 8px 0 0;
  font-size: 13.5px;
  color: var(--muted);
  text-align: center;
}

.controls { margin-top: 28px; transition: opacity 0.2s ease; }

.controls.disabled { opacity: 0.45; pointer-events: none; }

.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  --fill: 0%;
}

.range:disabled {
  cursor: default;
  opacity: 0.4;
}

.range::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold) var(--fill), rgba(244, 241, 234, 0.08) var(--fill));
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5.5px;
  border: 0;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(232, 197, 71, 0.12);
}

.range::-moz-range-track {
  height: 3px;
  border-radius: 999px;
  background: rgba(244, 241, 234, 0.08);
}

.range::-moz-range-progress {
  height: 3px;
  border-radius: 999px;
  background: var(--gold);
}

.range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--gold);
}

.range:focus-visible { outline: none; }

.range:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 5px rgba(232, 197, 71, 0.25);
}

.times {
  display: flex;
  justify-content: space-between;
  padding: 0 4px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

.transport .icon-btn { width: 44px; height: 44px; }

#shuffle .i, #repeat .i { width: 22px; height: 22px; }

#shuffle.active, #repeat.active { color: var(--gold); }

#prev .i, #next .i { width: 30px; height: 30px; }

#prev, #next { color: var(--text); }

.play-btn {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  margin: 0 2px;
  border: 0;
  border-radius: 50%;
  background: var(--gold);
  color: #1a1607;
  cursor: pointer;
  box-shadow: 0 12px 26px -12px rgba(232, 197, 71, 0.85);
  transition: background 0.15s ease;
}

.play-btn:hover { background: #f2d465; }

.play-btn .i { width: 34px; height: 34px; }

.volume {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
}

.volume .vol { width: 20px; height: 20px; color: var(--muted); }

/* ---------- library ---------- */

.track-actions { display: flex; justify-content: center; margin-top: 16px; }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.ghost-btn .i { width: 18px; height: 18px; color: var(--gold); }

.ghost-btn:hover {
  border-color: rgba(232, 197, 71, 0.45);
  background: rgba(232, 197, 71, 0.08);
}

.ghost-btn:disabled {
  cursor: default;
  opacity: 0.45;
}

.ghost-btn:disabled:hover {
  border-color: var(--line);
  background: transparent;
}

.modal {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vv-top, 0px);
  z-index: 50;
  display: grid;
  place-items: center;
  height: var(--vv-h, 100vh);
  padding: 20px;
  background: rgba(6, 7, 9, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.modal-card {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: min(78vh, 720px);
  padding: 22px 22px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal-head h3 { margin: 0; font-size: 17px; font-weight: 800; }

.modal-sub { margin: 4px 0 0; font-size: 12px; color: var(--muted); }

.modal-tools { display: flex; gap: 4px; flex-shrink: 0; }

.library-search {
  position: relative;
  display: flex;
  align-items: center;
  margin: 16px 0 12px;
}

.library-search .i {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

.library-search input {
  width: 100%;
  height: 40px;
  padding: 0 12px 0 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.library-search input:focus { outline: none; border-color: var(--gold); }

.library-status {
  margin: 6px 0;
  padding: 22px 14px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
  color: var(--muted);
}

.library-list {
  flex: 1;
  min-height: 120px;
  overflow: auto;
  margin: 0 -6px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.lib-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.lib-row:hover { background: rgba(244, 241, 234, 0.05); }

.lib-row.active { background: rgba(232, 197, 71, 0.1); }

.lib-index {
  width: 24px;
  flex-shrink: 0;
  text-align: right;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.lib-row.active .lib-index { color: var(--gold); }

.lib-main { flex: 1; min-width: 0; }

.lib-title,
.lib-meta {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lib-title { font-size: 14px; }

.lib-row.active .lib-title { color: var(--gold); }

.lib-meta { margin-top: 2px; font-size: 12px; color: var(--muted); }

.lib-dur {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.modal-foot {
  margin: 12px 0 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
}

body.modal-open { overflow: hidden; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.45);
  transform: translateX(-50%);
}

@media (max-width: 640px) {
  .topbar-inner { padding: 10px 16px; }
  .user-email { display: none; }
  .page { padding: 22px 16px 40px; }
  .page-head h2 { font-size: 22px; }
  .artwork { width: 190px; height: 190px; }
  #track-title { font-size: 20px; }
  .modal { align-items: end; padding: 0; }
  .modal-card {
    width: 100%;
    max-height: calc(var(--vv-h, 100vh) - 16px);
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    padding: 18px 16px calc(10px + env(safe-area-inset-bottom));
  }
  .library-search { margin: 14px 0 10px; }
  .library-search input { font-size: 16px; }
  .library-list { min-height: 64px; }
  .modal-foot { margin-top: 8px; font-size: 11px; }
}

@media (max-width: 520px) {
  .login-card { padding: 28px 22px 24px; }
  .live-badge { display: none; }
  .player-head { gap: 4px; }
  .modal-card { padding: 16px 14px calc(10px + env(safe-area-inset-bottom)); }
  .modal-head h3 { font-size: 16px; }
}

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