:root {
  --bg: #08080f;
  --surface: rgba(20, 20, 32, 0.72);
  --surface-2: rgba(30, 30, 46, 0.6);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f2f2f7;
  --muted: #9a9ab0;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --danger: #fb7185;
  --radius: 22px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.aurora {
  position: fixed;
  inset: -30% -10% auto -10%;
  height: 70vh;
  background:
    radial-gradient(45% 60% at 20% 30%, rgba(124, 92, 255, 0.35), transparent 70%),
    radial-gradient(40% 55% at 75% 10%, rgba(34, 211, 238, 0.22), transparent 70%),
    radial-gradient(35% 50% at 55% 60%, rgba(236, 72, 153, 0.18), transparent 70%);
  filter: blur(60px);
  pointer-events: none;
  z-index: 0;
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px clamp(18px, 4vw, 46px) 10px;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, var(--accent), #4a2fd6 60%, #2a1d75);
  box-shadow: 0 10px 30px rgba(124, 92, 255, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.brand-mark svg { width: 24px; height: 24px; color: #fff; }

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 18px; letter-spacing: -0.02em; }
.brand-text span { font-size: 12px; color: var(--muted); }

.top-actions { display: flex; align-items: center; gap: 10px; }

.device-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  backdrop-filter: blur(14px);
  transition: border-color 0.2s, transform 0.2s;
}

.device-chip:hover { border-color: rgba(124, 92, 255, 0.55); transform: translateY(-1px); }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 4px rgba(154, 154, 176, 0.12);
}

.dot.online {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.16), 0 0 12px rgba(52, 211, 153, 0.75);
}

.device-ip { color: var(--muted); font-variant-numeric: tabular-nums; }

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  backdrop-filter: blur(14px);
  transition: color 0.2s, border-color 0.2s;
}

.icon-btn:hover { color: var(--text); border-color: rgba(124, 92, 255, 0.5); }
.icon-btn.small { width: 34px; height: 34px; border-radius: 10px; }
.icon-btn svg { width: 20px; height: 20px; }

.offline {
  position: relative;
  z-index: 2;
  margin: 6px clamp(18px, 4vw, 46px) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-radius: 16px;
  border: 1px solid rgba(251, 113, 133, 0.35);
  background: rgba(251, 113, 133, 0.08);
  font-size: 13px;
}

.offline div { display: flex; flex-direction: column; gap: 3px; }
.offline span { color: #fecdd3; }
.offline-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.offline-actions .ghost-btn { text-decoration: none; color: var(--text); }

.layout {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.95fr);
  gap: clamp(16px, 2vw, 26px);
  padding: 14px clamp(18px, 4vw, 46px) 24px;
  flex: 1;
  align-items: start;
}

.card {
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(24, 24, 38, 0.86), rgba(14, 14, 24, 0.9));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

/* ---------------- tabs / upload ---------------- */

.tabs { display: flex; gap: 6px; padding: 14px 14px 0; }

.tab {
  flex: 1;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.tab:hover { color: var(--text); }
.tab.active { background: rgba(124, 92, 255, 0.16); color: #cdbcff; }

.panel { display: none; padding: 18px; }
.panel.active { display: block; animation: fade 0.25s ease; }

@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.dropzone {
  border: 1.5px dashed rgba(255, 255, 255, 0.16);
  border-radius: 18px;
  padding: 38px 22px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
  background: radial-gradient(70% 90% at 50% 0%, rgba(124, 92, 255, 0.1), transparent 70%);
}

.dropzone:hover, .dropzone:focus-visible { border-color: rgba(124, 92, 255, 0.7); background: rgba(124, 92, 255, 0.07); outline: none; }
.dropzone.drag { border-color: var(--accent-2); background: rgba(34, 211, 238, 0.08); transform: scale(1.005); }

.drop-icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: rgba(124, 92, 255, 0.16);
  color: #c3b3ff;
}

.drop-icon svg { width: 26px; height: 26px; }
.drop-title { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.drop-sub { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }

.progress-box { margin-top: 16px; }
.progress-head { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.progress { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.25s ease;
}

.hint { margin: 14px 2px 0; font-size: 12px; color: var(--muted); line-height: 1.6; }

code {
  font-family: "JetBrains Mono", "SFMono-Regular", ui-monospace, monospace;
  font-size: 0.92em;
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #d9d4ff;
}

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }
.field span { font-size: 12px; color: var(--muted); }

input[type="url"], input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(8, 8, 16, 0.6);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="url"]:focus, input[type="text"]:focus {
  outline: none;
  border-color: rgba(124, 92, 255, 0.7);
  box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.14);
}

.primary-btn {
  width: 100%;
  padding: 12px 18px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #5b3fe0);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(124, 92, 255, 0.35);
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
}

.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 14px 32px rgba(124, 92, 255, 0.45); }
.primary-btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.ghost-btn {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.ghost-btn:hover { border-color: rgba(124, 92, 255, 0.5); background: rgba(124, 92, 255, 0.1); }

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

.library-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.lib-path {
  flex: 1;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
  text-align: center;
  font-family: "JetBrains Mono", ui-monospace, monospace;
}

.lib-list { display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow-y: auto; padding-right: 4px; }

.lib-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  font: inherit;
  color: var(--text);
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
}

.lib-item:hover { background: rgba(124, 92, 255, 0.12); border-color: rgba(124, 92, 255, 0.3); }
.lib-item .ico { width: 20px; text-align: center; color: var(--muted); flex: 0 0 20px; }
.lib-item .meta { flex: 1; min-width: 0; }
.lib-item .name { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-item .sub { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.lib-item .tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.empty { padding: 24px 10px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------------- playlist m3u ---------------- */

.m3u-actions { display: flex; gap: 8px; }
.m3u-actions .primary-btn { flex: 1; width: auto; }
.m3u-actions .ghost-btn { flex: 0 0 auto; }

.m3u-status { margin: 14px 2px 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.m3u-status strong { color: #cdbcff; font-weight: 600; }

.m3u-tools { display: flex; gap: 8px; margin-top: 12px; }
.m3u-tools input[type="search"] { flex: 1; }

input[type="search"], select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: rgba(8, 8, 16, 0.6);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

input[type="search"]:focus, select:focus {
  outline: none;
  border-color: rgba(124, 92, 255, 0.7);
  box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.14);
}

select { max-width: 46%; cursor: pointer; }

.m3u-list { display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow-y: auto; margin-top: 10px; padding-right: 4px; }

.chan-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.chan-item:hover { background: rgba(124, 92, 255, 0.12); border-color: rgba(124, 92, 255, 0.3); }

.chan-logo {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 9px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.06);
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  overflow: hidden;
}

.chan-meta { flex: 1; min-width: 0; }
.chan-name { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chan-group { display: block; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chan-play { font-size: 11px; color: #a99bff; flex: 0 0 auto; }

.more-btn { margin-top: 8px; width: 100%; }

/* ---------------- now playing ---------------- */

.now { padding: 20px; display: flex; flex-direction: column; position: sticky; top: 16px; }
.now-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.eyebrow { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }

.badge {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  text-transform: lowercase;
}

.badge.playing { background: rgba(52, 211, 153, 0.15); color: #6ee7b7; }
.badge.paused { background: rgba(251, 191, 36, 0.14); color: #fcd34d; }
.badge.buffering { background: rgba(34, 211, 238, 0.14); color: #67e8f9; }

.now-art {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: 16px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(124, 92, 255, 0.2), rgba(10, 10, 20, 0.9) 60%);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.now-art svg { width: 56px; height: 56px; color: rgba(255, 255, 255, 0.35); position: relative; z-index: 1; }

.now-glow {
  position: absolute;
  inset: -40%;
  background: radial-gradient(40% 40% at 50% 50%, rgba(124, 92, 255, 0.5), transparent 70%);
  filter: blur(30px);
  opacity: 0.7;
}

.now-title {
  margin: 16px 2px 4px;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.now-sub { margin: 0 2px; font-size: 12.5px; color: var(--muted); min-height: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.timeline { display: flex; align-items: center; gap: 10px; margin: 18px 2px 6px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline span { flex: 0 0 auto; min-width: 34px; }
.timeline span:last-child { text-align: right; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.25);
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb { width: 13px; height: 13px; border: 0; border-radius: 50%; background: #fff; }

.controls { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 14px 0 6px; }

.round-btn {
  min-width: 52px;
  height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}

.round-btn:hover { border-color: rgba(124, 92, 255, 0.5); background: rgba(124, 92, 255, 0.12); }
.round-btn:active { transform: scale(0.96); }

.play-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, #fff, #d8d2ff);
  color: #1a1230;
  cursor: pointer;
  box-shadow: 0 12px 34px rgba(124, 92, 255, 0.4);
  transition: transform 0.15s, box-shadow 0.2s;
}

.play-btn:hover { transform: scale(1.05); box-shadow: 0 16px 40px rgba(124, 92, 255, 0.55); }
.play-btn:active { transform: scale(0.97); }
.play-btn svg { width: 24px; height: 24px; }

.volume-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.volume-row span { font-size: 11px; color: var(--muted); min-width: 32px; text-align: right; font-variant-numeric: tabular-nums; }
.volume-row input[type="range"] { max-width: 160px; }

.foot {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px clamp(18px, 4vw, 46px) 22px;
  font-size: 11px;
  color: var(--muted);
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(10px);
  z-index: 20;
  padding: 12px 20px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(24, 24, 38, 0.96);
  box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  max-width: min(92vw, 520px);
  text-align: center;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: rgba(251, 113, 133, 0.5); color: #fecdd3; }
.toast.ok { border-color: rgba(52, 211, 153, 0.4); color: #bbf7d0; }

dialog {
  border: 1px solid var(--border);
  border-radius: 20px;
  background: #12121e;
  color: var(--text);
  padding: 0;
  width: min(440px, 92vw);
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); }
.dialog-body { padding: 22px; }
.dialog-body h3 { margin: 0 0 18px; font-size: 16px; }
.dialog-actions { display: flex; gap: 10px; }
.dialog-actions .primary-btn { width: auto; flex: 1; }
.dialog-actions .ghost-btn { flex: 1; }

.device-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.device-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
}
.device-option:hover { border-color: rgba(124, 92, 255, 0.5); }
.device-option small { color: var(--muted); margin-left: auto; font-size: 11px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .now { position: static; }
  .brand-text span { display: none; }
  .foot { flex-direction: column; gap: 4px; }
}
