:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --ok: #3fb950;
  --err: #f85149;
  --border: #262b35;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 1.25rem; margin: 0; }
.foryou {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
}
.foryou:hover { border-color: var(--accent); }
.foryou:disabled { opacity: 0.6; cursor: default; }
.status {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0.2rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.status.ready { color: var(--ok); border-color: var(--ok); }
.status.error, .status.unconfigured { color: var(--err); border-color: var(--err); }

.searchbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
}
.types { display: flex; gap: 0.5rem; }
.type {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
}
.type.active { color: var(--text); border-color: var(--accent); }

#search-form { display: flex; gap: 0.5rem; flex: 1; min-width: 240px; }
#q {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.8rem;
  font-size: 1rem;
}
button[type="submit"] {
  background: var(--accent);
  border: none;
  color: white;
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

main {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 1.5rem;
  padding: 0 1.5rem 2rem;
}
@media (max-width: 820px) {
  main { grid-template-columns: 1fr; }
  .queue { order: -1; }
}

.results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  align-content: start;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card { position: relative; }
.card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--panel-2);
}
.card .badge {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  background: rgba(63, 185, 80, 0.92);
  color: #06210d;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
}
.card.in-library img { opacity: 0.72; }

/* cover placeholders (missing or broken art) */
.ph {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-2);
  color: var(--muted);
}
.card-ph { width: 100%; aspect-ratio: 1; font-size: 2.6rem; }
.row-ph { width: 44px; height: 44px; border-radius: 5px; font-size: 1.1rem; flex: 0 0 auto; }
.artist-ph { width: 96px; height: 96px; border-radius: 50%; font-size: 2.2rem; flex: 0 0 auto; }

.section-head {
  grid-column: 1 / -1;
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin: 0.5rem 0 0.25rem;
}
.section-head h2 { margin: 0; font-size: 1.1rem; }
.section-head .sub { color: var(--muted); font-size: 0.85rem; }
.refreshbtn {
  margin-left: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.3rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.8rem;
}
.card .meta { padding: 0.6rem 0.7rem; flex: 1; }
.card .title { font-weight: 600; font-size: 0.9rem; line-height: 1.25; }
.card .sub { color: var(--muted); font-size: 0.8rem; margin-top: 0.2rem; }
.card button {
  margin: 0 0.7rem 0.7rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem;
  border-radius: 8px;
  cursor: pointer;
}
.card button:hover { border-color: var(--accent); }
.card button:disabled { opacity: 0.5; cursor: default; }

.queue {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  align-self: start;
  position: sticky;
  top: 1rem;
}
.queue h2 { margin: 0 0 0.8rem; font-size: 1rem; }

.queue-tabs { display: flex; gap: 0.4rem; margin-bottom: 0.8rem; }
.qtab {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
}
.qtab.active { color: var(--text); border-color: var(--accent); }
.qtab .count { opacity: 0.7; font-size: 0.78rem; }

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  max-height: 65vh;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.job {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  font-size: 0.85rem;
}
.job .jtitle { font-weight: 600; }
.job .jartist { color: var(--muted); font-size: 0.8rem; }
.job .jstate { font-size: 0.75rem; margin-top: 0.3rem; color: var(--muted); }
.bar {
  height: 6px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.45rem;
}
.bar > span { display: block; height: 100%; background: var(--accent); width: 0; transition: width 0.3s; }
.job.completed .bar > span { background: var(--ok); }
.job.failed .bar > span { background: var(--err); }
.empty { color: var(--muted); font-size: 0.85rem; }

/* artist detail view */
.artist-head {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.artist-head img {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--panel-2);
}
.artist-head .info { flex: 1; }
.artist-head h2 { margin: 0; font-size: 1.4rem; }
.artist-head .sub { color: var(--muted); font-size: 0.9rem; margin-top: 0.2rem; }
.backbtn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
}
.headbtn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
.headbtn:disabled { opacity: 0.6; cursor: default; }

/* song (track) rows */
.tracklist { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 0.5rem; }
.trackrow {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
}
.trackrow img { width: 44px; height: 44px; border-radius: 5px; object-fit: cover; background: var(--panel-2); }
.trackrow .tinfo { flex: 1; min-width: 0; }
.trackrow .tname { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trackrow .tsub { color: var(--muted); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trackrow .tdur { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.trackrow button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.4rem 0.7rem;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.trackrow button:hover { border-color: var(--accent); }
.trackrow button:disabled { opacity: 0.5; cursor: default; }
.trackrow.in-library { border-color: rgba(63, 185, 80, 0.4); }
.trackrow .owned { color: var(--ok); font-weight: 700; }
.tbtns { display: flex; gap: 0.35rem; flex: 0 0 auto; }

/* login overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
/* author display:flex above would otherwise override the [hidden] attribute */
.login-overlay[hidden] { display: none; }
.login-box {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.login-box h1 { margin: 0; font-size: 1.4rem; }
.login-sub { margin: 0; color: var(--muted); font-size: 0.9rem; }
.login-box input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.7rem 0.8rem;
  font-size: 1rem;
}
.login-box button {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 0.7rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  font-size: 1rem;
}
.login-err { color: var(--err); font-size: 0.85rem; min-height: 1.1em; }

/* mobile */
@media (max-width: 600px) {
  header { flex-wrap: wrap; padding: 0.8rem 1rem; gap: 0.6rem; }
  header h1 { font-size: 1.1rem; }
  .status { width: 100%; margin-left: 0; text-align: center; }
  .searchbar { padding: 0.8rem 1rem; gap: 0.7rem; }
  .types { width: 100%; }
  .type { flex: 1; }
  #search-form { width: 100%; }
  main { padding: 0 1rem 2rem; gap: 1rem; }
  .results { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .queue { position: static; }
  .queue-list { max-height: 45vh; }
  .artist-head { flex-wrap: wrap; }
  .artist-head .backbtn { order: -1; }
  .trackrow { flex-wrap: wrap; }
  .trackrow .tinfo { min-width: 60%; }
  .tbtns { width: 100%; }
  .tbtns button { flex: 1; }
}
