:root {
  --bg: #121212;
  --bg-2: #181818;
  --bg-3: #242424;
  --bg-4: #2e2e2e;
  --text: #ffffff;
  --muted: #b3b3b3;
  --faint: #6a6a6a;
  --accent: #1db954;
  --accent-ink: #0b2e18;
  --plex: #e5a00d;
  --danger: #f15e6c;
  --radius: 10px;
  --gutter: 16px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 Inter, -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}
img { display: block; }
button { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* header + search */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 6px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; letter-spacing: -0.02em; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; border: 0; overflow: hidden;
  background: var(--bg-4); display: grid; place-items: center; font-weight: 700; cursor: pointer;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.searchbar {
  position: sticky; top: 0; z-index: 5;
  padding: 6px var(--gutter) 10px;
  background: rgba(18, 18, 18, 0.86);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
}
.search {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-3); border-radius: 999px; padding: 0 14px; height: 46px;
}
.search:focus-within { background: var(--bg-4); outline: 2px solid rgba(255,255,255,.18); }
.search svg { width: 20px; height: 20px; fill: var(--muted); flex: none; }
.search input {
  flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 16px; outline: none; -webkit-appearance: none; appearance: none;
}
.search input::placeholder { color: var(--faint); }
.search input::-webkit-search-cancel-button { display: none; }
#clear { border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; padding: 0 2px; cursor: pointer; }

.tabs { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: var(--bg-3); color: var(--text); padding: 7px 14px; border-radius: 999px;
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.tabs button.on { background: var(--text); color: #000; }

/* content blocks */
main { padding: 4px var(--gutter) 0; max-width: 1200px; margin: 0 auto; }
.block { margin: 14px 0 22px; }
.block h2 { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 12px; }
.note { color: var(--muted); padding: 24px 0; text-align: center; }

.grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.rail {
  display: flex; gap: 14px; overflow-x: auto; padding-bottom: 6px; margin: 0 calc(-1 * var(--gutter));
  padding-left: var(--gutter); padding-right: var(--gutter); scroll-snap-type: x proximity; scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.rail .card { flex: 0 0 150px; scroll-snap-align: start; }

/* cards */
.card {
  background: var(--bg-2); border-radius: var(--radius); padding: 10px; min-width: 0;
  display: flex; flex-direction: column; gap: 6px;
  transition: background .15s ease;
}
@media (hover: hover) { .card:hover { background: var(--bg-3); } }
.card .art { display: block; width: 100%; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--bg-4); }
.card img { width: 100%; height: 100%; object-fit: cover; }
.card img.empty { visibility: hidden; }
.card.round .art { border-radius: 50%; width: 82%; margin: 4px auto 2px; box-shadow: 0 8px 24px rgba(0,0,0,.45); }
.card h3 {
  margin: 4px 0 0; font-size: 14px; font-weight: 600; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card.round h3 { text-align: center; }
.card .sub {
  margin: 0; color: var(--muted); font-size: 12.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card.round .sub { text-align: center; }
.card .btn { margin-top: auto; align-self: flex-start; }
.card.round .btn { align-self: center; }

/* song rows */
.list { display: flex; flex-direction: column; gap: 4px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 8px; min-width: 0;
}
@media (hover: hover) { .row:hover { background: var(--bg-2); } }
.row img { width: 52px; height: 52px; border-radius: 6px; object-fit: cover; background: var(--bg-4); flex: none; }
.row img.empty { visibility: hidden; }
.row .meta { flex: 1; min-width: 0; }
.row .t { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 0 14px; border-radius: 999px; border: 0;
  font-weight: 700; font-size: 13px; white-space: nowrap; cursor: pointer; flex: none;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.96); }
.btn.get { background: var(--text); color: #000; }
.btn.get.busy { background: var(--bg-4); color: var(--muted); cursor: progress; }
.btn.ok { background: var(--accent); color: var(--accent-ink); }
.btn.ok::before { content: "✓"; }
.btn.busy { background: var(--bg-4); color: var(--muted); cursor: default; }
.btn.done { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); cursor: default; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  max-width: min(92vw, 520px); background: #fff; color: #000; padding: 12px 16px; border-radius: 10px;
  font-weight: 600; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* sign-in gate */
.gate {
  position: fixed; inset: 0; z-index: 30; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  padding: 32px var(--gutter);
}
.gate[hidden] { display: none; }
.gate h1 { font-size: 30px; letter-spacing: -0.03em; margin: 16px 0 8px; }
.gate p { color: var(--muted); max-width: 360px; margin: 0 0 24px; }
.gate .hint { font-size: 13px; color: var(--faint); margin: 18px 0 0; }
.plex {
  border: 0; border-radius: 999px; padding: 14px 28px; background: var(--plex); color: #1a1200;
  font-weight: 800; font-size: 16px; cursor: pointer;
}
.plex:disabled { opacity: .6; cursor: progress; }

/* account sheet */
.sheet { position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-card {
  width: 100%; max-width: 480px; background: var(--bg-3); border-radius: 16px 16px 0 0;
  padding: 18px var(--gutter) calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 4px;
}
.who { color: var(--muted); font-size: 13px; padding: 4px 8px 12px; }
.link { border: 0; background: transparent; text-align: left; padding: 12px 8px; border-radius: 8px; font-weight: 600; cursor: pointer; }
.link:hover { background: var(--bg-4); }
.link.muted { color: var(--muted); }

@media (min-width: 720px) {
  :root { --gutter: 28px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 18px; }
  .rail .card { flex-basis: 176px; }
  .block h2 { font-size: 22px; }
  .sheet { align-items: center; }
  .sheet-card { border-radius: 16px; }
}
