:root {
  --bg: #0a0a0f;
  --panel: #14141c;
  --panel2: #1b1b26;
  --line: #262635;
  --text: #f2f2f7;
  --muted: #8a8aa0;
  --pink: #ff5fa2;
  --purple: #c94bff;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(900px 520px at 12% -10%, rgba(255, 95, 162, 0.16), transparent 60%),
    radial-gradient(820px 520px at 88% 112%, rgba(139, 92, 246, 0.15), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1040px;
  width: 100%;
  margin: 0 auto;
  padding: 22px 24px 0;
}

.logo {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.22em;
}

.logo span {
  background: linear-gradient(135deg, var(--pink), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.volume {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 4px;
}

.btn.icon {
  display: grid;
  place-items: center;
  padding: 9px;
  line-height: 0;
}

.btn.icon .cross { display: none; }

.btn.icon.muted { color: var(--pink); border-color: rgba(255, 95, 162, 0.5); }

.btn.icon.muted .wave { display: none; }

.btn.icon.muted .cross { display: inline; }

.volume-slider {
  width: 92px;
  accent-color: var(--pink);
  cursor: pointer;
}

.btn {
  font: inherit;
  font-size: 0.85rem;
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s, opacity 0.15s, transform 0.15s;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

.btn.ghost:hover { color: var(--text); border-color: #3d3d58; }

.btn.primary {
  background: linear-gradient(135deg, var(--pink), var(--purple));
  border: none;
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover { transform: translateY(-1px); }

.btn:disabled { opacity: 0.35; cursor: default; }

/* ---------- layout ---------- */

.wrap {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 26px 24px 40px;
}

.meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

#roundLabel { color: var(--text); font-weight: 650; }

.dot { opacity: 0.5; }

.spacer { flex: 1; }

#leftLabel { font-variant-numeric: tabular-nums; }

.progress {
  margin-top: 10px;
  height: 6px;
  border-radius: 999px;
  background: #1c1c28;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--pink), var(--purple));
  transition: width 0.3s ease;
}

/* ---------- arena ---------- */

.arena {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 20px;
  align-items: stretch;
  margin-top: 22px;
}

.vs {
  display: grid;
  place-items: center;
  align-self: center;
}

.vs span {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  box-shadow: 0 10px 30px rgba(201, 75, 255, 0.35);
}

.song {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  cursor: pointer;
  user-select: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease,
    opacity 0.25s ease, filter 0.25s ease;
}

.song:hover,
.song:focus-visible {
  transform: translateY(-3px);
  border-color: rgba(255, 95, 162, 0.65);
  box-shadow: 0 14px 40px rgba(255, 95, 162, 0.14);
}

.song.winner {
  border-color: var(--pink);
  box-shadow: 0 0 0 1px var(--pink), 0 16px 50px rgba(255, 95, 162, 0.35);
  transform: translateY(-3px) scale(1.015);
}

.song.loser {
  opacity: 0.35;
  filter: grayscale(0.9);
  transform: scale(0.985);
}

.artwrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #0e0e15;
}

.art {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

.play {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(10, 10, 15, 0.55);
  backdrop-filter: blur(6px);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, opacity 0.15s;
}

.play:hover { background: var(--pink); border-color: var(--pink); transform: scale(1.06); }

.play.playing { background: var(--pink); border-color: var(--pink); }

.play.loading { cursor: progress; opacity: 0.65; }

.keyhint {
  position: absolute;
  left: 10px;
  top: 10px;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(10, 10, 15, 0.55);
  backdrop-filter: blur(6px);
  color: #cfcfe0;
  font-size: 0.7rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.song:hover .keyhint,
.song:focus-visible .keyhint { opacity: 1; }

.stitle {
  font-size: 1.12rem;
  font-weight: 650;
  line-height: 1.28;
  letter-spacing: -0.01em;
}

.salbum { margin-top: 3px; color: var(--muted); font-size: 0.85rem; }

.sdur {
  margin-top: 7px;
  color: #5d5d75;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.hint {
  margin: 22px 0 0;
  color: #62627c;
  font-size: 0.82rem;
  text-align: center;
}

kbd {
  font: inherit;
  font-size: 0.75rem;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
}

/* ---------- champion ---------- */

.champion { text-align: center; padding: 26px 0 60px; }

.champ-kicker {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.4em;
  color: var(--pink);
}

.champ-artwrap {
  width: min(360px, 70vw);
  margin: 20px auto 0;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 95, 162, 0.5), 0 30px 80px rgba(255, 95, 162, 0.25);
}

#champArt { display: block; width: 100%; }

#champTitle { margin: 20px 0 4px; font-size: clamp(1.6rem, 4vw, 2.2rem); }

.muted { color: var(--muted); margin: 4px 0; }

.champ-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
}

/* ---------- global leaderboard ---------- */

.leaderboard { max-width: 900px; margin: 0 auto; }

.lb-head {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 16px;
}

.lb-kicker {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.35em;
  color: var(--pink);
}

.lb-heading h2 { margin: 6px 0 2px; font-size: clamp(1.25rem, 3vw, 1.7rem); }

.lb-heading .muted { margin: 0; font-size: 0.85rem; }

.lb-status {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.lb-status.offline { color: #e0a44a; }

.lb-table {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  overflow: hidden;
  padding: 6px;
}

.lb-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 76px 136px 76px 56px;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 12px;
}

.lb-row:not(.lb-header-row):hover { background: rgba(255, 255, 255, 0.025); }

.lb-header-row {
  padding: 8px 12px 4px;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.lb-rank {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.lb-row.top .lb-rank { color: var(--pink); font-weight: 800; font-size: 1rem; }

.lb-song { display: flex; align-items: center; gap: 10px; min-width: 0; }

.lb-art {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  background: #0e0e15;
  flex: 0 0 auto;
}

.lb-names { min-width: 0; }

.lb-title {
  display: block;
  font-size: 0.94rem;
  font-weight: 620;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-album {
  display: block;
  font-size: 0.76rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-sub { display: none; }

.lb-rating {
  text-align: right;
  font-weight: 700;
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
}

.lb-win { display: flex; align-items: center; gap: 8px; }

.lb-bar {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: #1c1c28;
  overflow: hidden;
}

.lb-bar i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--pink), var(--purple));
}

.lb-pct {
  width: 36px;
  text-align: right;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.lb-record,
.lb-titles {
  text-align: right;
  color: var(--muted);
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
}

.lb-titles { text-align: center; }

.lb-note {
  margin: 14px 2px 0;
  color: #62627c;
  font-size: 0.78rem;
  text-align: center;
}

/* ---------- footer / toast ---------- */

.footer {
  padding: 18px 24px 26px;
  text-align: center;
  color: #4d4d63;
  font-size: 0.78rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(10px);
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #1d1d2b;
  color: var(--text);
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- responsive ---------- */

@media (max-width: 760px), (max-height: 560px) {
  html, body { height: 100%; }

  body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: max(10px, env(safe-area-inset-top)) 14px 0;
  }

  .logo { font-size: 1.15rem; letter-spacing: 0.18em; }

  .btn { font-size: 0.78rem; padding: 7px 11px; }

  .btn.icon { padding: 7px; }

  .volume { gap: 6px; margin-right: 0; }

  .volume-slider { width: 74px; }

  .wrap {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  }

  .game {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }

  .meta { font-size: 0.78rem; }

  .progress { margin-top: 8px; }

  .arena {
    flex: 1;
    min-height: 0;
    grid-template-columns: 1fr;
    align-content: center;
    align-content: safe center;
    gap: 10px;
    margin-top: 12px;
  }

  .song {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 14px;
  }

  .artwrap { flex: 0 0 auto; width: clamp(64px, 18vh, 160px); }

  .play { width: 32px; height: 32px; right: 5px; bottom: 5px; font-size: 11px; }

  .keyhint { display: none; }

  .info { min-width: 0; flex: 1; }

  .stitle {
    font-size: 0.98rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .salbum { font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .sdur { margin-top: 4px; font-size: 0.72rem; }

  .vs span { width: 36px; height: 36px; font-size: 0.68rem; }

  .hint, .footer { display: none; }

  .champion { padding: 6px 0 12px; }

  .champ-artwrap { width: min(340px, 60vw, 38vh); margin-top: 12px; }

  #champTitle { font-size: 1.45rem; margin: 14px 0 4px; }

  .champ-actions { margin-top: 16px; }
}

@media (min-width: 761px) and (min-height: 561px) {
  .song { width: 100%; max-width: min(100%, 46vh); justify-self: center; }
}

@media (max-width: 760px) {
  .lb-header-row { display: none; }

  .lb-row {
    grid-template-columns: 30px minmax(0, 1fr) auto;
    gap: 10px;
    padding: 8px;
  }

  .lb-win, .lb-record, .lb-titles { display: none; }

  .lb-sub {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.74rem;
  }

  .lb-art { width: 36px; height: 36px; }

  .lb-status { margin-left: 0; width: 100%; }
}

@media (hover: none) {
  .keyhint { display: none; }
}
