:root {
  --bg: #0b1220;
  --surface: #131e33;
  --surface-2: #1d2b44;
  --border: #2a3a57;
  --text: #f8fafc;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary-2: #3b82f6;
  --accent: #38bdf8;
  --green: #059669;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.hide { display: none !important; }

#app-root {
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 18, 32, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.top-pills {
  display: flex;
  gap: 6px;
  align-items: center;
}

.pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.pill-mode.single {
  border-color: #f59e0b66;
  background: #451a0366;
  color: #fcd34d;
}

.pill-mode.continuous {
  border-color: #10b98166;
  background: #064e3b66;
  color: #6ee7b7;
}

.main-view {
  flex: 1;
  padding: 12px 12px 140px;
}

.docked-player {
  padding: 10px 12px 0;
}

.docked-player .card {
  margin-bottom: 0;
  padding: 12px;
}

.docked-player .now-title {
  font-size: 17px;
  margin: 4px 0 2px;
}

.docked-player .transport {
  margin: 6px 0 8px;
}

.docked-player .mode-box {
  margin: 6px 0 6px;
}

.docked-player .sec-controls {
  margin-top: 8px;
  margin-bottom: 8px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

button, .btn {
  border: none;
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.08s ease, opacity 0.15s ease;
}

button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); }
.btn-green { background: var(--green); }
.btn-red { background: var(--red); }
.btn-amber { background: var(--amber); }
.btn-sm { padding: 7px 10px; font-size: 12px; border-radius: 10px; }
.btn-lg { padding: 14px 16px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-icon { width: 42px; height: 42px; padding: 0; border-radius: 12px; font-size: 16px; flex: 0 0 auto; }
.btn-icon.primary { background: var(--primary); }

input[type=text], input[type=url], input[type=password], input[type=number], select, textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--accent);
}

input[type=range] {
  width: 100%;
  height: 30px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Segmented Advance Mode Switch */
.mode-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 10px 0 6px;
}

.mode-btn {
  background: transparent;
  color: var(--muted);
  padding: 10px 8px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.25;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.mode-btn.act-single {
  background: #b45309;
  color: #fff;
  box-shadow: 0 2px 10px rgba(217, 119, 6, 0.3);
}

.mode-btn.act-continuous {
  background: #047857;
  color: #fff;
  box-shadow: 0 2px 10px rgba(5, 150, 105, 0.3);
}

.mode-hint {
  font-size: 12px;
  color: var(--accent);
  text-align: center;
  margin-bottom: 10px;
}

.now-title {
  font-size: 20px;
  font-weight: 800;
  margin: 6px 0 2px;
  word-break: break-word;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  background: var(--surface-2);
  color: var(--accent);
}

.badge.play { background: #065f46; color: #6ee7b7; }
.badge.pause { background: #78350f; color: #fcd34d; }
.badge.stop { background: var(--surface-2); color: var(--muted); }

.transport {
  display: grid;
  grid-template-columns: 1fr 1.6fr 1fr auto;
  gap: 8px;
  margin: 8px 0 12px;
}

.transport button,
.sec-controls button {
  min-width: 0;
}

.sec-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.ctrl-on {
  background: var(--green) !important;
  color: #fff !important;
}

.vol-row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 8px;
  align-items: center;
}

.vol-row input[type=range] {
  min-width: 0;
}

/* Lists & Track rows */
.track-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.track-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid transparent;
}

.track-item.cur {
  background: #172554;
  border-color: var(--primary-2);
}

.track-main {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.track-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.track-acts {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

/* Upload dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.5);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
}

/* Progress Bar */
.prog-wrap {
  width: 100%;
  height: 7px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}

.prog-bar {
  height: 100%;
  background: var(--accent);
  transition: width 0.2s ease;
}

/* Mini Player & Bottom Nav */
.mini-player {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(64px + env(safe-area-inset-bottom));
  width: calc(100% - 16px);
  max-width: 620px;
  z-index: 25;
  background: rgba(29, 43, 68, 0.96);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.mini-info {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.mini-title {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-sub {
  font-size: 11px;
  color: var(--accent);
}

.mini-actions {
  display: flex;
  gap: 6px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 640px;
  z-index: 30;
  background: rgba(11, 18, 32, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.bottom-nav.cols-4 {
  grid-template-columns: repeat(4, 1fr);
}

.nav-btn {
  background: transparent;
  color: var(--muted);
  flex-direction: column;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 10px;
  font-size: 18px;
}

.nav-btn small {
  font-size: 11px;
  font-weight: 700;
}

.nav-btn.act {
  color: #fff;
  background: var(--primary);
}

/* Modal & Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}

@media (min-width: 520px) {
  .modal-backdrop { align-items: center; }
}

.modal-box {
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px;
}

.toast-container {
  position: fixed;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  width: calc(100% - 24px);
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
  animation: fadeIn 0.15s ease;
}

.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); background: #450a0a; }

.qr-wrap {
  background: #fff;
  padding: 12px;
  border-radius: 14px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.health-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.health-tile {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}

.subtabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-bottom: 10px;
}

.subtab {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  white-space: nowrap;
}

.subtab.act {
  background: var(--primary);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 420px) {
  .top-bar {
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
    gap: 6px;
  }
  .brand-name { font-size: 15px; }
  .pill { padding: 4px 8px; font-size: 11px; }
  .main-view { padding: 10px 10px 136px; }
  .card { padding: 12px; }
  .transport { gap: 6px; }
  .transport button { padding: 10px 6px; font-size: 13px; }
  .transport .btn-lg { padding: 12px 8px; font-size: 14px; }
  .sec-controls { gap: 6px; }
  .sec-controls button { padding: 9px 6px; font-size: 12px; }
  .vol-row { gap: 6px; }
  .nav-btn { font-size: 16px; padding: 5px 2px; }
  .nav-btn small { font-size: 10px; }
}

@media (min-width: 768px) {
  #app-root,
  .bottom-nav {
    max-width: 720px;
  }
  .mini-player {
    max-width: 700px;
  }
}
