:root {
  --bg: #121212;
  --bg-2: #1e1e1e;
  --bg-3: #2a2a2a;
  --fg: #ffffff;
  --fg-2: #b3b3b3;
  --accent: #1db954;
  --border: #333;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 8px 12px;
}

button:hover { background: var(--bg-3); border-radius: 4px; }

#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
#topbar h1 {
  flex: 1;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
}
#back-btn {
  font-size: 1.4rem;
}

#drawer {
  position: fixed;
  top: 56px; left: 0; bottom: 0;
  width: 240px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  z-index: 9;
  transform: translateX(0);
  transition: transform .2s;
  display: flex;
  flex-direction: column;
}
#drawer.hidden { transform: translateX(-100%); }

#drawer-backdrop {
  position: fixed;
  inset: 56px 0 0 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 8;
}
#drawer-backdrop.hidden { display: none !important; }
@media (min-width: 769px) {
  #drawer-backdrop { display: none !important; }
}

/* Drawer hero (now playing) */
#drawer-hero {
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  background: var(--bg-2);
  transition: background .15s;
}
#drawer-hero:hover { background: var(--bg-3); }
#drawer-hero.hidden { display: none !important; }
.dh-row { display: flex; gap: 10px; align-items: center; }
#dh-cover {
  width: 56px; height: 56px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--bg-3), var(--bg));
  object-fit: cover;
  flex-shrink: 0;
}
.dh-info { flex: 1; min-width: 0; overflow: hidden; }
#dh-title {
  font-size: 0.95rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#dh-artist {
  font-size: 0.8rem; color: var(--fg-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dh-progress {
  height: 3px; background: var(--bg-3); border-radius: 2px; overflow: hidden;
}
#dh-progress-bar {
  height: 100%; background: var(--accent); width: 0%;
  transition: width .15s linear;
}

/* Drawer nav */
#drawer ul {
  list-style: none;
  flex: 1;
  padding: 8px 0;
  margin: 0;
  overflow-y: auto;
}
#drawer li {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 0.95rem;
  min-height: 44px;
  position: relative;
  transition: background .12s, color .12s;
}
#drawer li:hover { background: var(--bg-3); }
#drawer li.active {
  background: var(--bg-3);
  color: var(--accent);
}
#drawer li.active::before {
  content: '';
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
#drawer li .d-icon { font-size: 1.15rem; width: 22px; text-align: center; flex-shrink: 0; }
#drawer li .d-label { flex: 1; }
#drawer li .d-count {
  font-size: 0.75rem;
  color: var(--fg-2);
  font-variant-numeric: tabular-nums;
}
#drawer li.active .d-count { color: var(--accent); }

/* Drawer footer */
.drawer-footer {
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  background: var(--bg-2);
}
.d-syncinfo {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 12px 16px;
  background: transparent;
  border: none;
  color: var(--fg-2);
  cursor: pointer;
  text-align: left;
  font-size: 0.75rem;
  line-height: 1.3;
}
.d-syncinfo:hover { background: var(--bg-3); color: var(--fg); }
.d-syncinfo-label { color: var(--fg-2); }
#d-syncage { color: var(--fg); font-size: 0.85rem; font-weight: 500; margin-top: 2px; }

#drawer-settings {
  padding: 14px 18px;
  font-size: 1.4rem;
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  cursor: pointer;
  color: var(--fg-2);
}
#drawer-settings:hover { color: var(--accent); background: var(--bg-3); }

#app {
  position: fixed;
  top: 56px; left: 240px; right: 0; bottom: 72px;
  overflow-y: auto;
  padding: 16px;
}

/* Botões do mini-player — SVG monocromáticos, estilo consistente */
.mp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--fg-2);
  transition: background .15s, color .15s, transform .1s;
}
.mp-btn svg {
  width: 20px;
  height: 20px;
  display: block;
}
.mp-btn:hover { background: var(--bg-3); color: var(--fg); border-radius: 50%; }
.mp-btn:active { transform: scale(0.92); }

/* Play/pause central — ligeiramente maior e com fundo sólido */
.mp-btn-play {
  width: 44px;
  height: 44px;
  background: var(--fg);
  color: #000;
}
.mp-btn-play svg { width: 22px; height: 22px; }
.mp-btn-play:hover {
  background: var(--fg);
  color: #000;
  transform: scale(1.05);
}

/* Shuffle — estado activo com cor de acento */
#mp-shuffle.active { color: var(--accent); }
#mp-shuffle.active:hover { color: var(--accent); background: var(--bg-3); }

/* Megashuffle — destaque subtil com sparkles */
#mp-megashuffle {
  color: var(--fg-2);
}
#mp-megashuffle:hover {
  color: var(--accent);
  background: var(--bg-3);
}
#mp-megashuffle.active {
  color: var(--accent);
}
#mp-megashuffle.loading {
  animation: mega-spin 0.8s linear infinite;
  pointer-events: none;
}
@keyframes mega-spin {
  to { transform: rotate(360deg); }
}

/* Banner MegaShuffle na view Fila */
.mega-banner {
  margin-top: 16px;
  padding: 24px;
  background: linear-gradient(135deg, var(--bg-2), var(--bg-3));
  border: 1px solid var(--accent);
  border-radius: 10px;
  text-align: center;
}
.mega-banner-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 6px;
}
.mega-banner-sub {
  color: var(--fg-2);
  font-size: 0.9rem;
  line-height: 1.5;
}

#mini-player {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  z-index: 10;
}
#mini-player.hidden { display: none !important; }

.mp-progress {
  height: 4px;
  background: var(--bg-3);
  cursor: pointer;
  position: relative;
}
.mp-progress:hover { height: 6px; }
.mp-progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width .15s linear;
}
.mp-row {
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 12px;
  height: 68px;
}
.mp-time {
  color: var(--fg-2);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 75px;
  text-align: right;
}
#mp-cover {
  width: 56px; height: 56px;
  background: var(--bg-3);
  border-radius: 4px;
  object-fit: cover;
}
.mp-info {
  flex: 1;
  overflow: hidden;
  line-height: 1.25;
}
.mp-info > div {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#mp-title { font-size: 0.9rem; font-weight: 500; }
#mp-album { font-size: 0.78rem; color: var(--fg-2); }
#mp-artist { font-size: 0.78rem; color: var(--fg-2); }

.mp-controls {
  display: flex;
  gap: 4px;
  align-items: center;
}
.mp-controls button {
  font-size: 1.35rem;
  padding: 8px 10px;
}

.hidden { display: none !important; }

/* Listas */
.list-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  gap: 12px;
  position: relative;
}
.list-item:hover { background: var(--bg-2); }

.playing-indicator {
  display: none;
  width: 18px;
  color: var(--accent);
  font-size: 1rem;
  text-align: center;
  animation: pulse 1.2s ease-in-out infinite;
}
.q-num {
  width: 28px;
  text-align: right;
  color: var(--fg-2);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.list-item.playing .q-num { display: none; }
.list-item.playing {
  background: var(--bg-2);
}
.list-item.playing .playing-indicator { display: block; }
.list-item.playing .primary { color: var(--accent); font-weight: 600; }

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}
.list-item img {
  width: 48px; height: 48px;
  border-radius: 4px;
  background: var(--bg-3);
  object-fit: cover;
  flex-shrink: 0;
}
.list-item .info { flex: 1; overflow: hidden; min-width: 0; }
.list-item .info .primary { font-weight: 500; }
.list-item .info .secondary { font-size: 0.85rem; color: var(--fg-2); }
.list-item .meta { color: var(--fg-2); font-size: 0.85rem; }

/* Botão + de adicionar à fila */
.btn-add {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: transparent;
  color: var(--fg-2);
  font-size: 1.4rem;
  line-height: 1;
  padding: 0;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-add:hover {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}
.btn-add.added {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.btn-icon {
  flex-shrink: 0;
  padding: 8px 12px;
  background: transparent;
  color: var(--fg-2);
  font-size: 1.2rem;
  border-radius: 4px;
}
.btn-icon:hover { background: var(--bg-3); color: var(--fg); }

.action-btn.secondary {
  background: var(--bg-3);
  color: var(--fg);
}

/* Search */
.search-box {
  padding: 12px 0 20px;
}
.search-box input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 24px;
  font-size: 1rem;
  outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-section { margin-bottom: 28px; }
.search-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-2);
  margin-bottom: 8px;
  padding: 0 4px;
}

/* Now playing / queue hero */
.np-hero {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 16px;
  background: var(--bg-2);
  border-radius: 8px;
  margin-bottom: 16px;
}
.np-cover {
  width: 120px; height: 120px;
  background: var(--bg-3);
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}
.np-info { flex: 1; min-width: 0; }
.np-title { font-size: 1.2rem; font-weight: 600; margin-bottom: 4px; }
.np-artist { color: var(--fg); margin-bottom: 2px; }
.np-album { color: var(--fg-2); font-size: 0.9rem; }
@media (max-width: 480px) {
  .np-cover { width: 88px; height: 88px; }
  .np-title { font-size: 1rem; }
}

/* Action danger variant */
.action-btn.danger {
  background: transparent;
  color: #f66;
  border: 1px solid #f66;
}
.action-btn.danger:hover { background: #f66; color: #000; }

/* Toast */
#cm-toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--accent);
  color: #000;
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
#cm-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}
.card {
  cursor: pointer;
}
.card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg-3);
}
.card .title {
  margin-top: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card .subtitle {
  font-size: 0.8rem;
  color: var(--fg-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Sync progress */
.sync-progress {
  padding: 20px;
  background: var(--bg-2);
  border-radius: 8px;
  text-align: center;
}
.sync-progress .bar {
  height: 4px;
  background: var(--bg-3);
  border-radius: 2px;
  margin-top: 12px;
  overflow: hidden;
}
.sync-progress .bar > div {
  height: 100%;
  background: var(--accent);
  transition: width .3s;
}

/* Desktop: drawer always visible, topbar e player alinhados com conteúdo */
@media (min-width: 769px) {
  #drawer { transform: translateX(0) !important; top: 0; }
  #topbar { left: 240px; }
  #mini-player { left: 240px; }
  #menu-btn { display: none; }
  #drawer ul { padding-top: 16px; }
  /* "a tocar" já aparece no mini-player em baixo — evitar duplicação */
  #drawer-hero { display: none !important; }
  /* Breadcrumb no topbar: "Géneros › Blues › Gary Moore › Álbum" */
  #topbar h1.breadcrumb {
    text-align: left;
    padding-left: 4px;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--fg-2);
    display: flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
    overflow: hidden;
    min-width: 0;
  }
  #topbar h1.breadcrumb .crumb {
    background: transparent;
    border: none;
    color: var(--fg-2);
    font: inherit;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background .12s, color .12s;
    white-space: nowrap;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #topbar h1.breadcrumb .crumb:hover {
    color: var(--fg);
    background: var(--bg-3);
  }
  #topbar h1.breadcrumb .crumb-sep {
    color: var(--fg-2);
    opacity: 0.5;
    padding: 0 2px;
    flex-shrink: 0;
  }
  #topbar h1.breadcrumb .crumb-current {
    color: var(--fg);
    font-weight: 600;
    padding: 4px 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }
}

/* Mobile */
@media (max-width: 768px) {
  #drawer { transform: translateX(-100%); bottom: 160px; }
  #drawer:not(.hidden) { transform: translateX(0); }
  #drawer-backdrop { inset: 56px 0 160px 0; }
  #app { left: 0; bottom: 160px; }

  /* Mini-player em mobile: 2 linhas, botões maiores */
  .mp-row {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px 12px;
    gap: 8px 12px;
  }
  #mp-cover { width: 56px; height: 56px; }
  .mp-info { flex: 1; min-width: 0; }
  .mp-time {
    font-size: 0.75rem;
    min-width: 0;
    padding-left: 4px;
  }
  .mp-controls {
    flex-basis: 100%;
    justify-content: space-around;
    gap: 8px;
    padding-top: 4px;
  }
  .mp-controls .mp-btn {
    width: 48px;
    height: 48px;
  }
  .mp-controls .mp-btn svg {
    width: 24px;
    height: 24px;
  }
  .mp-controls .mp-btn-play {
    width: 56px;
    height: 56px;
  }
  .mp-controls .mp-btn-play svg {
    width: 28px;
    height: 28px;
  }
}

/* Empty state */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--fg-2);
}
.empty h2 { margin-bottom: 12px; color: var(--fg); }
.empty button {
  margin-top: 16px;
  padding: 12px 24px;
  background: var(--accent);
  color: #000;
  font-weight: 600;
  border-radius: 24px;
}

/* "Todas as músicas" no topo de género/artista */
.all-item {
  background: var(--bg-2);
  border: 1px solid var(--accent);
  border-radius: 6px;
  margin-bottom: 12px;
}
.all-item .primary { color: var(--accent); }

/* Botões de ação no topo das listas de faixas */
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.action-btn {
  padding: 10px 18px;
  background: var(--accent);
  color: #000;
  font-weight: 600;
  border-radius: 24px;
  font-size: 0.9rem;
}
.action-btn:nth-child(2) {
  background: var(--bg-3);
  color: var(--fg);
}
.action-count {
  margin-left: auto;
  color: var(--fg-2);
  font-size: 0.85rem;
}

/* Login screen */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 100;
}
.login-box { text-align: center; padding: 40px; max-width: 360px; width: 100%; }
.login-box h1 { font-size: 2rem; margin-bottom: 8px; }
.login-box p { color: var(--fg-2); margin-bottom: 24px; }
.login-box form { display: flex; flex-direction: column; gap: 12px; }
.login-box input {
  padding: 14px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 6px;
  font-size: 1rem;
  outline: none;
}
.login-box input:focus { border-color: var(--accent); }
.login-box button[type="submit"] {
  padding: 14px;
  background: var(--accent);
  color: #000;
  font-weight: 600;
  border-radius: 24px;
  font-size: 1rem;
  cursor: pointer;
  border: none;
}
.login-error { color: #f66; font-size: 0.9rem; padding: 8px; }

/* Settings */
.settings-field {
  margin-bottom: 16px;
}
.settings-field label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--fg-2);
}
.settings-field input {
  width: 100%;
  padding: 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 4px;
  font-size: 0.95rem;
}

/* Botão + de adicionar a playlist (♫+ ) */
.btn-addpl {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: transparent;
  color: var(--fg-2);
  font-size: 1.05rem;
  line-height: 1;
  padding: 0;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s, border-color .15s;
  margin-left: 6px;
}
.btn-addpl:hover,
.btn-addpl.added {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

/* Modal de escolha de playlist */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 300;
}
.modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, 92vw);
  max-height: 80vh;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  z-index: 301;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.modal-new {
  width: 100%;
  text-align: left;
  padding: 12px;
  background: var(--bg-3);
  border-radius: 6px;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 0.95rem;
  border: none;
  cursor: pointer;
}
.modal-new:hover { background: var(--border); }
.playlist-list { list-style: none; padding: 0; margin: 0; }
.playlist-list li {
  padding: 12px;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.playlist-list li:hover { background: var(--bg-3); }
.playlist-list li .count { color: var(--fg-2); font-size: 0.85rem; }
.modal footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  text-align: right;
}
.modal footer button {
  padding: 8px 16px;
  background: transparent;
  color: var(--fg-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}
.modal footer button:hover { color: var(--fg); background: var(--bg-3); }
