*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f13;
  --surface: #1a1a22;
  --surface-hover: #22222e;
  --border: #2a2a38;
  --text: #f0f0f5;
  --text-muted: #7070a0;
  --red: #c8102e;
  --red-dim: rgba(200, 16, 46, 0.15);
  --green: #2ecc71;
  --green-dim: rgba(46, 204, 113, 0.15);
  --radius: 16px;
  --transition: 0.18s ease;
}

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header h1 span {
  color: var(--red);
}

nav {
  display: flex;
  gap: 8px;
}

.nav-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition);
}

.nav-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.nav-btn.active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

/* Vote view */
#view-vote {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  gap: 28px;
}

.instruction {
  color: var(--text-muted);
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.arena {
  display: flex;
  align-items: stretch;
  gap: 24px;
  width: 100%;
  max-width: 860px;
}

.card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform var(--transition), background var(--transition), border-color var(--transition), box-shadow var(--transition);
  min-height: 240px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
  user-select: none;
}

.card:hover {
  background: var(--surface-hover);
  border-color: var(--red);
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(200, 16, 46, 0.18);
}

.card:active {
  transform: translateY(-1px);
}

.card.winner {
  background: var(--green-dim);
  border-color: var(--green);
  animation: pulse-win 0.35s ease;
}

.card.winner:hover {
  border-color: var(--green);
  box-shadow: none;
  transform: none;
}

.card.loser {
  background: var(--red-dim);
  border-color: transparent;
  opacity: 0.45;
}

.card.loser:hover {
  border-color: transparent;
  box-shadow: none;
  transform: none;
}

@keyframes pulse-win {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.03); }
  100% { transform: scale(1); }
}

/* Album art */
.card-art-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg);
  flex-shrink: 0;
}

.card-art {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.play-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.65);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: background var(--transition), transform var(--transition);
  z-index: 2;
}

.play-btn:hover {
  background: var(--red);
  transform: translateY(-50%) scale(1.1);
}

.play-btn.playing {
  background: var(--red);
}

.play-btn svg {
  width: 20px;
  height: 20px;
}

.card-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 20px 60px 24px 20px;
  text-align: center;
  flex: 1;
  justify-content: center;
}

.artist {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.title {
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.25;
}

.vs {
  display: flex;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  flex-shrink: 0;
}

.vote-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.vote-count strong {
  color: var(--text);
}

.genre-profile {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 26px;
}

.genre-pill {
  padding: 3px 11px;
  border-radius: 20px;
  font-size: 0.73rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  transition: opacity 0.3s;
}

.skip-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 28px;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition);
}

.skip-btn:hover {
  background: var(--surface-hover);
  border-color: var(--text-muted);
}

.phase-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.6;
}

/* Leaderboard view */
#view-leaderboard {
  flex: 1;
  padding: 40px 32px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

#view-leaderboard h2 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.board-note {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 28px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

tbody tr:hover {
  background: var(--surface);
}

tbody td {
  padding: 14px 12px;
  vertical-align: middle;
}

.rank-cell {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  width: 40px;
}

.rank-cell.top {
  color: var(--red);
  font-weight: 700;
}

.board-song-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.board-thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.board-thumb-empty {
  background: var(--border);
}

.song-title {
  font-weight: 600;
}

.song-artist {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.elo-cell {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.votes-cell {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.hidden {
  display: none !important;
}

/* Loading state */
.card.loading .card-inner,
.card.loading .card-art-wrap {
  opacity: 0.3;
}

@media (max-width: 600px) {
  header {
    padding: 12px 16px;
    gap: 10px;
  }

  header h1 {
    font-size: 1.05rem;
  }

  #view-vote {
    padding: 20px 12px;
    gap: 16px;
  }

  .arena {
    flex-direction: column;
    gap: 10px;
  }

  .vs {
    align-self: center;
    transform: none;
    padding: 0;
  }

  /* Horizontal card layout: thumbnail left, text right */
  .card {
    flex-direction: row;
    min-height: 0;
    align-items: center;
  }

  .card-art-wrap {
    width: 88px;
    height: 88px;
    aspect-ratio: unset;
    flex-shrink: 0;
  }

  .card-inner {
    padding: 10px 56px 10px 14px;
    align-items: flex-start;
    text-align: left;
    gap: 4px;
  }

  .title {
    font-size: 1.1rem;
  }

  .skip-btn {
    font-size: 0.85rem;
    padding: 8px 18px;
  }

  /* Leaderboard */
  #view-leaderboard {
    padding: 20px 12px;
  }

  /* Hide ELO and votes columns on small screens */
  thead th:nth-child(4),
  thead th:nth-child(5),
  tbody td:nth-child(4),
  tbody td:nth-child(5) {
    display: none;
  }

  .board-thumb {
    width: 36px;
    height: 36px;
  }
}
