:root {
  --bg: #0b0b0d;
  --surface: #131316;
  --surface-2: #1a1a1f;
  --border: #26262c;
  --border-strong: #37373f;
  --text: #ededee;
  --muted: #9a9aa3;
  --faint: #66666f;
  --accent: #e7e7ea;        /* near-white: active/voted states invert to this */
  --on-accent: #0b0b0d;
  --good: #6fcf97;
  --warn: #e0b341;
  --bad: #e06666;
  --radius: 12px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }

/* The [hidden] attribute must always win, even over display:grid/flex rules below. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
}

a { color: var(--text); }
button { font-family: inherit; }

.wrap {
  max-width: 660px;
  margin: 0 auto;
  padding: 20px 16px 96px;
}

svg.ic { display: block; }

/* ---------- Header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(11, 11, 13, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 660px;
  margin: 0 auto;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo {
  width: 34px; height: 34px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  display: grid; place-items: center;
  color: var(--text);
  flex: none;
}
.title-block { flex: 1; min-width: 0; }
.title-block h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.title-block p {
  margin: 1px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}
.whoami {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  flex: none;
  max-width: 130px;
}
.whoami b { color: var(--text); display: block; font-size: 13px; font-weight: 600; }
.whoami a { color: var(--faint); text-decoration: none; font-size: 11.5px; }
.whoami a:hover { color: var(--text); }

/* ---------- Quota chips ---------- */
.quota-row {
  display: flex;
  gap: 10px;
  margin: 18px 0 0;
}
.pill {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.pill .pill-num { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.pill .pill-lbl { font-size: 12px; color: var(--muted); }
.pill.empty .pill-num { color: var(--faint); }

/* ---------- Cards ---------- */
.search-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 14px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-head h2 {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.switch-mode {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
}
.switch-mode:hover { color: var(--text); }

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-box .s-icn {
  position: absolute; left: 13px;
  color: var(--faint);
  pointer-events: none;
  display: flex;
}
input[type="text"], input[type="password"], input[type="number"], input[type="url"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s;
}
.search-box input { padding-left: 42px; }
input::placeholder { color: var(--faint); }
input:focus { border-color: var(--muted); }
.spinner-mini {
  position: absolute; right: 13px;
  width: 15px; height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}
.search-box.loading .spinner-mini { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Search results ---------- */
.results {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
}
.result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s;
}
.result + .result { border-top: 1px solid var(--border); border-radius: 0; }
.result:hover, .result:focus-visible {
  background: var(--surface-2);
  border-color: transparent;
  outline: none;
}
.result img, .cover {
  width: 44px; height: 44px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--surface-2);
  flex: none;
}
.cover.placeholder { display: grid; place-items: center; color: var(--faint); }
.result .meta { flex: 1; min-width: 0; }
.result .meta .t {
  font-weight: 550; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.result .meta .s {
  font-size: 12.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.result .dur { font-size: 12px; color: var(--faint); flex: none; font-variant-numeric: tabular-nums; }
.result .add-btn {
  flex: none;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-weight: 550;
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
}
.result:hover .add-btn { border-color: var(--muted); }

.hint { font-size: 12.5px; color: var(--faint); margin: 10px 2px 0; }

/* ---------- Link form ---------- */
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.provider-line {
  margin-top: 8px;
  min-height: 18px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 7px;
}
.provider-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 11.5px;
  color: var(--text);
}
.provider-tag.bad { color: var(--bad); border-color: rgba(224,102,102,0.4); }

/* ---------- Section heading ---------- */
.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 28px 4px 12px;
}
.section-head h2 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -0.2px; }
.section-head .count { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Song list ---------- */
.songs { display: flex; flex-direction: column; gap: 8px; }
.song {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px;
}
.song.mine { border-color: var(--border-strong); }
.rank {
  width: 22px; flex: none;
  text-align: center;
  font-weight: 600;
  font-size: 13px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.rank.top { color: var(--text); }
.song .meta { flex: 1; min-width: 0; }
.song .meta .t {
  font-weight: 600; font-size: 14.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.song .meta .s {
  font-size: 12.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.song .meta .tags {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-top: 3px; font-size: 11.5px; color: var(--faint);
}
.tag-you {
  border: 1px solid var(--border-strong);
  color: var(--muted);
  padding: 0px 6px; border-radius: 999px;
  font-weight: 500;
}
.song .actions { display: flex; align-items: center; gap: 4px; flex: none; }
.song .remove, .song .open-link {
  background: none; border: none; color: var(--faint);
  cursor: pointer; padding: 6px; line-height: 0; border-radius: 6px;
}
.song .remove:hover { color: var(--bad); }
.song .open-link:hover { color: var(--text); }

/* vote button */
.vote {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  min-width: 50px;
  padding: 7px 6px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s;
}
.vote .num { font-size: 15px; font-weight: 650; color: var(--text); font-variant-numeric: tabular-nums; }
.vote:hover { border-color: var(--muted); }
.vote.voted {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.vote.voted .num { color: var(--on-accent); }
.vote.suggester {
  background: var(--surface-2);
  border-style: dashed;
  cursor: default;
  color: var(--muted);
}
.vote:disabled { cursor: default; }
.vote.pop { animation: pop 0.22s ease; }
@keyframes pop { 0%{transform:scale(1);} 45%{transform:scale(1.1);} 100%{transform:scale(1);} }

/* preview play btn on cover */
.cover-wrap { position: relative; flex: none; }
.cover-wrap .play {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(0,0,0,0.45);
  border-radius: 6px;
  opacity: 0; transition: opacity 0.12s;
  cursor: pointer; color: white; border: none;
}
.cover-wrap:hover .play { opacity: 1; }
.cover-wrap.playing .play { opacity: 1; }

/* ---------- Empty / banners ---------- */
.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--muted);
}
.empty .ic-wrap { color: var(--faint); margin-bottom: 12px; display: flex; justify-content: center; }
.empty h3 { margin: 0 0 5px; color: var(--text); font-size: 15px; font-weight: 600; }
.empty p { margin: 0; font-size: 13px; }

.banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13px;
  color: var(--muted);
  margin-top: 14px;
}
.banner.warn { border-color: rgba(224, 179, 65, 0.4); color: #e6cd8e; }

/* ---------- Name / login gate ---------- */
.gate {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(8, 8, 10, 0.9);
  backdrop-filter: blur(6px);
  display: grid; place-items: center;
  padding: 20px;
}
.gate-card {
  width: 100%; max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  text-align: center;
}
.gate-card .logo { width: 44px; height: 44px; margin: 0 auto 18px; border-radius: 11px; }
.gate-card h2 { margin: 0 0 6px; font-size: 19px; font-weight: 650; }
.gate-card p { margin: 0 0 20px; color: var(--muted); font-size: 13.5px; }
.gate-card input { text-align: center; margin-bottom: 12px; }

.btn-primary {
  width: 100%;
  background: var(--accent);
  border: 1px solid var(--accent);
  color: var(--on-accent);
  font-size: 15px;
  font-weight: 600;
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 13.5px; font-weight: 550;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px;
}
.btn-ghost:hover { border-color: var(--muted); }

/* ---------- Toast ---------- */
.toast-host {
  position: fixed; left: 0; right: 0; bottom: 22px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 200; pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px; font-weight: 500;
  animation: toastIn 0.18s ease;
  max-width: 90vw;
}
.toast.good { border-color: rgba(111, 207, 151, 0.5); }
.toast.bad { border-color: rgba(224, 102, 102, 0.5); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.footer-note {
  text-align: center;
  margin-top: 34px;
  font-size: 12px;
  color: var(--faint);
}
.footer-note a { color: var(--muted); text-decoration: none; }
.footer-note a:hover { color: var(--text); }

/* ===================================================================
   Admin dashboard
   =================================================================== */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 18px 0 0;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  text-align: center;
}
.stat .n { font-size: 23px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 11px; color: var(--muted); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.4px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 14px;
}
.panel h3 { margin: 0 0 4px; font-size: 14px; font-weight: 650; }
.panel > .sub { margin: 0 0 12px; font-size: 12.5px; color: var(--muted); }

.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.setting-row:last-child { border-bottom: none; }
.setting-row .lbl { font-size: 13.5px; }
.setting-row .lbl small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* toggle switch */
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: 999px;
  transition: background 0.18s; cursor: pointer;
}
.switch .track::before {
  content: ""; position: absolute; height: 16px; width: 16px;
  left: 3px; top: 3px; background: var(--muted); border-radius: 50%;
  transition: transform 0.18s, background 0.18s;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); background: var(--on-accent); }

.num-input { width: 64px; text-align: center; padding: 8px; }

.admin-song {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.admin-song:last-child { border-bottom: none; }
.admin-song .meta { flex: 1; min-width: 0; }
.admin-song .meta .t { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 7px; }
.admin-song .meta .s { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-song .meta .s a { color: var(--muted); }
.admin-song .vcount {
  flex: none; text-align: center; min-width: 40px;
  font-weight: 650; font-size: 15px; font-variant-numeric: tabular-nums;
}
.admin-song .vcount small { display: block; font-size: 10px; color: var(--muted); font-weight: 400; }
.badge {
  font-size: 10px; font-weight: 600; padding: 1px 7px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.3px; border: 1px solid var(--border-strong);
  color: var(--muted); flex: none;
}
.badge.kind-link { color: var(--text); }
.status-badge {
  font-size: 10px; font-weight: 600; padding: 1px 7px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.3px; flex: none;
}
.status-badge.approved { border: 1px solid rgba(111,207,151,0.4); color: var(--good); }
.status-badge.pending { border: 1px solid rgba(224,179,65,0.4); color: var(--warn); }
.status-badge.hidden { border: 1px solid var(--border-strong); color: var(--faint); }
.status-badge.played { border: 1px solid var(--border-strong); color: var(--muted); }
.admin-actions { display: flex; gap: 5px; flex: none; }
.icon-btn {
  background: var(--bg); border: 1px solid var(--border-strong);
  color: var(--muted); width: 30px; height: 30px;
  border-radius: 7px; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:hover { border-color: var(--muted); color: var(--text); }
.icon-btn.danger:hover { border-color: var(--bad); color: var(--bad); }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

.sort-toggle {
  display: flex; gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 3px;
}
.sort-toggle button {
  background: transparent; border: none; color: var(--muted);
  font-size: 12px; font-weight: 550; padding: 5px 10px;
  border-radius: 6px; cursor: pointer;
}
.sort-toggle button.active { background: var(--surface-2); color: var(--text); }

@media (max-width: 560px) {
  .admin-grid { grid-template-columns: repeat(2, 1fr); }
  .whoami { max-width: 96px; }
  .sort-toggle button { padding: 5px 8px; }
}
