:root {
  --bg: #0d0b14;
  --bg-2: #15121f;
  --card: #1c1829;
  --card-2: #241f35;
  --line: #2f2944;
  --text: #f3f0fa;
  --muted: #a39cb8;
  --dim: #6e6787;
  --accent: #ff3d7f;
  --accent-2: #ffb020;
  --good: #34d399;
  --devil: #ff4d4d;
  --radius: 14px;
  --topbar-h: 60px;
  --bottom-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  background-image: radial-gradient(1200px 500px at 50% -200px, #2a1840 0%, transparent 70%);
  background-attachment: fixed;
  color: var(--text);
  font-family: 'Archivo', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h2, h3 { margin: 0; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 16px;
  background: rgba(13, 11, 20, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 900; letter-spacing: 0.02em; }
.brand-mark {
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1a0010; font-size: 18px;
}
.brand-name { font-size: 20px; text-transform: uppercase; }
.tabs { display: none; gap: 4px; margin-left: 12px; }
.tab {
  background: none; border: 0; padding: 8px 14px; border-radius: 999px;
  color: var(--muted); font-weight: 600;
}
.tab.active { color: var(--text); background: var(--card-2); }
.me-chip {
  margin-left: auto;
  background: var(--card); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: 14px;
  max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.me-chip.named::before { content: '● '; color: var(--good); }

/* ---------- Views ---------- */
main { padding-bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom)); }
.view { display: none; }
.view.active { display: block; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ---------- Browse ---------- */
.searchbar {
  position: sticky; top: var(--topbar-h); z-index: 20;
  background: var(--bg);
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--line);
}
.search-wrap { position: relative; }
.search-wrap svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; fill: none; stroke: var(--dim); stroke-width: 2; stroke-linecap: round;
}
#search {
  width: 100%; padding: 12px 12px 12px 40px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  font-size: 16px; outline: none;
}
#search:focus { border-color: var(--accent); }
.toolbar { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.toolbar select, .queue-tools select {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 14px;
}
.count { color: var(--dim); font-size: 13px; margin-top: 8px; }

.btn {
  border: 1px solid var(--line); background: var(--card);
  padding: 8px 14px; border-radius: 10px; font-weight: 600; font-size: 14px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: var(--card); }
.btn.danger { border-color: #5a2a3a; color: #ff8fa8; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 0; }
.icon-btn { background: none; border: 0; font-size: 18px; color: var(--muted); padding: 4px 8px; }
.badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; margin-left: 4px;
}

.song-list { list-style: none; margin: 0; padding: 8px 8px 24px; }
.song {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  padding: 12px 10px; border-radius: 12px;
  border-bottom: 1px solid rgba(47, 41, 68, 0.5);
}
.song:hover { background: var(--bg-2); }
.song-main { min-width: 0; }
.song-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.song-meta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.song-meta .sep { color: var(--dim); margin: 0 4px; }
.meters { grid-column: 1 / 2; display: flex; gap: 12px; flex-wrap: wrap; margin-top: 2px; }
.meter { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--dim); font-weight: 600; }
.meter.focus { color: var(--text); }
.meter.focus .dots { outline: 1px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.dots { display: inline-flex; gap: 2px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.dot.on { background: var(--text); }
.dots.devil .dot { background: var(--devil); box-shadow: 0 0 4px var(--devil); }
.dots.none { font-size: 11px; color: var(--dim); }
.warm { font-size: 10px; color: var(--dim); letter-spacing: 0.02em; }

.add-btn {
  grid-row: 1 / span 2; grid-column: 2;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card);
  font-size: 22px; line-height: 1; display: grid; place-items: center;
  transition: transform 0.12s ease, background 0.12s ease;
}
.add-btn:active { transform: scale(0.92); }
.add-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; font-size: 18px; }
.pickers { color: var(--accent-2); font-size: 12px; font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* ---------- Filters (mobile: bottom sheet) ---------- */
.filters {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  max-height: 85vh; overflow-y: auto;
  background: var(--bg-2); border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform 0.25s ease;
}
.filters.open { transform: none; }
.filters-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.filters-head h2 { font-size: 18px; margin-right: auto; }
.fgroup { padding: 12px 0; border-bottom: 1px solid var(--line); }
.fgroup h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 8px; }
.hint { text-transform: none; letter-spacing: 0; color: var(--dim); font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--card);
  padding: 6px 11px; border-radius: 999px; font-size: 13px; font-weight: 500;
}
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { color: var(--dim); font-size: 11px; margin-left: 3px; }
.chip.on .n { color: #555; }
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { flex: 1; background: none; border: 0; padding: 7px 4px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card-2); color: var(--text); }
.check { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.sheet-done { width: 100%; margin-top: 16px; padding: 12px; }

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 50; }

/* ---------- My list (mobile: bottom sheet) ---------- */
.mylist {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  max-height: 80vh; overflow-y: auto;
  background: var(--bg-2); border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform 0.25s ease;
}
.mylist.open { transform: none; }
.mylist-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.mylist-head h2 { font-size: 18px; margin-right: auto; }
.mylist-fab {
  position: fixed; right: 16px; bottom: calc(var(--bottom-h) + 16px + env(safe-area-inset-bottom)); z-index: 40;
  background: var(--accent); color: #fff; border: 0; border-radius: 999px;
  padding: 12px 18px; font-weight: 700; box-shadow: 0 8px 24px rgba(255, 61, 127, 0.4);
}
.mylist-fab span { background: rgba(255,255,255,0.25); border-radius: 999px; padding: 1px 8px; margin-left: 4px; }

.mini { list-style: none; margin: 0; padding: 0; }
.mini li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
}
.mini .mt { flex: 1; min-width: 0; }
.mini .mt b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini .mt span { color: var(--muted); font-size: 13px; }
.mini li.played .mt { opacity: 0.45; text-decoration: line-through; }
.x-btn { background: none; border: 0; color: var(--dim); font-size: 16px; padding: 6px; }
.vote-btn {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.vote-btn.on { color: var(--accent); border-color: var(--accent); }
.vote-btn:disabled { opacity: 0.6; cursor: default; }

/* ---------- Set lists ---------- */
.section-head { margin: 8px 0 12px; }
.section-head h2 { font-size: 22px; font-weight: 900; }
.sub { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.ranked { list-style: none; padding: 0; margin: 0 0 28px; counter-reset: r; }
.ranked li {
  counter-increment: r;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; background: var(--card); border-radius: 12px; margin-bottom: 6px;
}
.ranked li::before {
  content: counter(r); font-weight: 900; font-size: 18px; color: var(--accent-2); width: 24px; text-align: center;
}
.ranked .mt { flex: 1; min-width: 0; }
.ranked .mt b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranked .mt span { color: var(--muted); font-size: 13px; }
.score { font-weight: 700; color: var(--accent); font-size: 14px; white-space: nowrap; }
.ranked li.played { opacity: 0.5; }

.guest-grid { display: grid; gap: 12px; }
.guest-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.guest-card.me { border-color: var(--accent); }
.guest-card h3 { font-size: 17px; display: flex; align-items: baseline; gap: 8px; }
.guest-card h3 small { color: var(--dim); font-weight: 500; font-size: 13px; }

/* ---------- Queue ---------- */
.queue-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; justify-content: space-between; }
.queue-tools { display: flex; gap: 12px; align-items: center; }
.host-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.host-bar .host-tag { color: var(--good); font-weight: 700; font-size: 13px; margin-right: 4px; }
.letter {
  position: sticky; top: var(--topbar-h); z-index: 5;
  background: var(--bg); padding: 10px 4px 4px;
  font-weight: 900; color: var(--accent-2); font-size: 15px;
}
.qitem {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; background: var(--card); border-radius: 12px; margin-bottom: 6px;
}
.qitem.played { opacity: 0.45; }
.qitem.played .mt b { text-decoration: line-through; }
.qitem .mt { flex: 1; min-width: 0; }
.qitem .mt b { display: block; font-weight: 700; }
.qitem .mt span { color: var(--muted); font-size: 13px; }
.qitem .who { color: var(--accent-2); font-size: 12px; font-weight: 600; margin-top: 2px; }
.qitem { flex-wrap: wrap; }
.qitem .meters { flex-basis: 100%; padding-left: 42px; margin-top: 0; }
.song-list { padding-bottom: 96px; }
.played-box {
  width: 30px; height: 30px; flex: none; border-radius: 8px;
  border: 2px solid var(--line); background: none; display: grid; place-items: center; font-size: 16px;
}
.played-box.on { background: var(--good); border-color: var(--good); color: #0d0b14; }
.played-box:disabled { cursor: default; }

/* ---------- Dialogs ---------- */
dialog {
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 18px;
  padding: 22px; width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { font-size: 20px; }
#name-input {
  width: 100%; margin-top: 14px; padding: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; font-size: 16px;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.surprise-card .big { font-size: 24px; font-weight: 900; line-height: 1.15; margin: 6px 0 2px; }
.surprise-card .kicker { color: var(--accent-2); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; }
.surprise-card .meters { margin: 12px 0 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom-h) + 80px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-weight: 600; font-size: 14px; transition: all 0.2s ease; z-index: 100; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Bottom tabs (mobile) ---------- */
.bottom-tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  display: flex; height: calc(var(--bottom-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(21, 18, 31, 0.95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.bottom-tabs .tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 0; font-size: 12px;
}
.bottom-tabs .tab.active { background: none; color: var(--accent); }
.bottom-tabs .ti { font-size: 18px; line-height: 1; }

.sheet-close { display: inline-block; }

/* ---------- Desktop ---------- */
@media (min-width: 1000px) {
  .tabs { display: flex; }
  .bottom-tabs, .mylist-fab, .sheet-close, .sheet-done, .filters-btn { display: none !important; }
  main { padding-bottom: 0; }

  .view-browse.active {
    display: grid;
    grid-template-columns: 270px minmax(0, 1fr) 320px;
    max-width: 1500px; margin: 0 auto;
  }
  .filters, .mylist {
    position: sticky; top: var(--topbar-h);
    height: calc(100vh - var(--topbar-h)); max-height: none;
    transform: none; border-radius: 0; border-top: 0;
    background: transparent; z-index: auto;
  }
  .filters { border-right: 1px solid var(--line); padding: 16px 20px; }
  .mylist { border-left: 1px solid var(--line); padding: 16px 20px; }
  .searchbar { padding: 16px 20px 10px; }
  .song-list { padding: 8px 12px 40px; }
  .song { grid-template-columns: minmax(0, 1fr) auto auto; }
  .meters { grid-column: 2; grid-row: 1 / span 2; flex-wrap: nowrap; }
  .add-btn { grid-column: 3; }
  .qitem { flex-wrap: nowrap; }
  .qitem .meters { flex-basis: auto; padding-left: 0; }
  .guest-grid { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
  .toast { bottom: 32px; }
  .scrim { display: none !important; }
}

/* ---------- Tooltips (mouse/keyboard only) ---------- */
.tip {
  position: fixed; z-index: 200; pointer-events: none;
  max-width: 260px; padding: 7px 10px; border-radius: 8px;
  background: #f3f0fa; color: #0d0b14;
  font-size: 13px; font-weight: 600; line-height: 1.35;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  opacity: 0; transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}
.tip.show { opacity: 1; transform: none; }
.chips.locked .chip { opacity: 0.4; cursor: not-allowed; }

/* ---------- Suggest ---------- */
.wrap.narrow { max-width: 760px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.card-title { display: block; font-weight: 800; font-size: 17px; margin-bottom: 10px; }
.ai-card { background: linear-gradient(160deg, #2a1840 0%, var(--card) 60%); border-color: #4a2d6b; }
#ai-text {
  width: 100%; resize: vertical; min-height: 84px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; font: inherit; font-size: 16px; color: var(--text); outline: none;
}
#ai-text:focus { border-color: var(--accent); }
.ai-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.fine { color: var(--dim); font-size: 12px; }
.ai-status { font-size: 14px; color: var(--muted); margin-top: 8px; min-height: 0; }
.ai-status:empty { display: none; }
.ai-status.err { color: #ff8fa8; }
.ai-status .says { color: var(--text); font-weight: 600; }
.spinner {
  display: inline-block; width: 14px; height: 14px; margin-right: 6px; vertical-align: -2px;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.or { display: flex; align-items: center; gap: 12px; color: var(--dim); font-size: 13px; margin: 4px 0 16px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.wiz-steps { display: flex; gap: 6px; margin-bottom: 12px; }
.wiz-steps span { flex: 1; height: 4px; border-radius: 4px; background: var(--line); }
.wiz-steps span.done { background: var(--accent); }
.wiz-head h3 { font-size: 20px; font-weight: 900; }
.wiz-head .sub { margin-bottom: 14px; }
.wiz-nav { display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.wiz-nav #wiz-next { margin-left: auto; padding: 10px 18px; }
.wiz-q { margin-bottom: 16px; }
.wiz-q h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.inst-row { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 10px; margin-bottom: 8px; }
.inst-row b { font-size: 14px; }
.seg.wrap-seg { flex-wrap: wrap; }
.seg.wrap-seg button { flex: 1 0 auto; padding: 7px 8px; }

.results-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; justify-content: space-between; }
.results-head h3 { font-size: 20px; font-weight: 900; }
.results-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.summary-chips { margin: 12px 0 4px; }
.summary-chips .chip { cursor: default; font-size: 12px; padding: 4px 9px; }
.sug-list { list-style: none; margin: 8px 0 0; padding: 0; }
.sug {
  display: grid; grid-template-columns: 26px minmax(0, 1fr) auto auto; gap: 2px 10px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.sug:last-child { border-bottom: 0; }
.sug .num { color: var(--accent-2); font-weight: 900; text-align: center; }
.sug .mt b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sug .mt span { color: var(--muted); font-size: 13px; }
.sug .why { grid-column: 2 / -1; color: var(--accent-2); font-size: 12px; font-weight: 600; }
.sug .meters { grid-column: 2 / -1; }
.sug .add-btn { grid-row: auto; grid-column: auto; width: 38px; height: 38px; font-size: 19px; }
.swap-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg-2);
  font-size: 17px; color: var(--muted);
}
.note { color: var(--accent-2); font-size: 13px; margin-top: 8px; }
