/* ─── SportsHeart Song Wars — styles ───────────────────────────────────────
 * Uses the shared SportsHeart dark theme (red accent on near-black greys) so
 * this page matches the rest of the site instead of inventing its own palette.
 * ────────────────────────────────────────────────────────────────────────── */
:root {
  --bg: #121212;
  --bg-2: #1e1e1e;
  --panel: #1e1e1e;
  --panel-2: #2a2a2a;
  --line: #404040;
  --line-soft: #333333;
  --text: #ffffff;
  --muted: #cccccc;
  --muted-3: #999999;
  --accent: #dc2626;
  --accent-deep: #b91c1c;
  --accent-soft: rgba(220, 38, 38, 0.14);
  --accent-line: rgba(220, 38, 38, 0.4);
  --danger: #dc3545;
  --gold: #ffbf00;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

/* `[hidden]` must beat any `display` we set (e.g. .toggle is display:flex), or
 * hidden elements stay visible. This bit the group-count row. */
[hidden] {
  display: none !important;
}

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

body {
  font-family:
    "Inter",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Arial,
    sans-serif;
  background:
    radial-gradient(
      1200px 600px at 50% -10%,
      var(--accent-soft),
      transparent 60%
    ),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}

p {
  margin: 0;
}

.muted {
  color: var(--muted);
}

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

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 44px);
  border-bottom: 1px solid var(--line-soft);
  background: rgba(18, 18, 18, 0.72);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* The SportsHeart mark leads the header, matching the app's navbar. */
.brand-logo {
  width: 46px;
  height: 46px;
  object-fit: contain;
  flex: none;
}

.brand h1 {
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.brand p {
  color: var(--muted);
  font-size: 0.82rem;
}

.conn {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

.conn-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 3px rgba(153, 153, 153, 0.16);
}

.conn-dot.on {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2);
}

.conn-dot.bad {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(244, 99, 106, 0.2);
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 44px) 60px;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.screen[hidden] {
  display: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.panel-head {
  margin-bottom: 18px;
}

.panel-head h2 {
  font-size: 1.06rem;
  font-weight: 700;
}

.panel-head p {
  color: var(--muted);
  font-size: 0.87rem;
  margin-top: 5px;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 11px 20px;
  cursor: pointer;
  transition:
    transform 0.12s ease,
    background 0.15s ease,
    border-color 0.15s ease,
    opacity 0.15s ease;
  color: var(--text);
  background: var(--panel-2);
}

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

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: #24d562;
}

.btn-secondary {
  background: transparent;
  border-color: var(--line);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

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

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--panel-2);
}

.btn-sm {
  padding: 7px 14px;
  font-size: 0.82rem;
}

.btn-lg {
  padding: 14px 30px;
  font-size: 1rem;
}

/* ── Fields ──────────────────────────────────────────────────────────────── */
.field {
  display: block;
  margin-bottom: 14px;
}

.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 7px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"],
input[type="search"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s ease;
}

input[type="text"]:focus,
input[type="search"]:focus {
  border-color: var(--accent);
}

input::placeholder {
  color: #666666;
}

input:disabled {
  opacity: 0.5;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ── Callout / redirect URI ──────────────────────────────────────────────── */
.callout {
  margin-top: 18px;
  background: var(--bg-2);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 0.86rem;
  color: var(--muted);
}

.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
}

.copy-row code {
  flex: 1;
  overflow-x: auto;
  white-space: nowrap;
  background: #0a0a0a;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  color: var(--accent);
  font-size: 0.83rem;
}

/* ── Mode cards ──────────────────────────────────────────────────────────── */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 18px;
}

@media (max-width: 620px) {
  .mode-grid {
    grid-template-columns: 1fr;
  }
}

.mode-card {
  display: flex;
  gap: 12px;
  padding: 15px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
}

.mode-card:hover {
  border-color: #404040;
}

.mode-card:has(input:checked) {
  border-color: var(--accent);
  background: rgba(220, 38, 38, 0.07);
}

.mode-card input {
  margin-top: 3px;
  accent-color: var(--accent);
  width: 17px;
  height: 17px;
  flex: none;
}

.mode-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mode-body strong {
  font-size: 0.95rem;
}

.mode-body em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.82rem;
}

.mode-note {
  color: #777777;
  font-size: 0.76rem;
  margin-top: 2px;
}

/* ── Toggles ─────────────────────────────────────────────────────────────── */
.toggle {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 0;
  border-top: 1px solid var(--line-soft);
  cursor: pointer;
}

.toggle input {
  margin-top: 3px;
  accent-color: var(--accent);
  width: 17px;
  height: 17px;
  flex: none;
}

.toggle span {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 0.9rem;
}

.toggle em {
  color: var(--muted);
  font-style: normal;
  font-size: 0.81rem;
}

.toggle-label {
  flex: 1;
}

.select-sm {
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  outline: none;
  cursor: pointer;
  flex: none;
}

.select-sm:focus {
  border-color: var(--accent);
}

/* ── Album picker (random mode) ──────────────────────────────────────────── */
.album-panel-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 14px;
}

.album-artist {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  padding: 12px;
}

.album-artist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.album-artist-head strong {
  font-size: 0.92rem;
}

.album-count.on {
  color: var(--accent);
  border-color: var(--accent-line);
}

.album-list {
  display: grid;
  /* auto-fill keeps this working from phone width all the way up. */
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
}

.album-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  min-width: 0;
}

.album-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.album-item:has(input:checked) {
  border-color: var(--accent-line);
  background: rgba(220, 38, 38, 0.08);
}

.album-item input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  flex: none;
}

.album-thumb {
  width: 36px;
  height: 36px;
  border-radius: 5px;
  object-fit: cover;
  flex: none;
  background: var(--line);
}

.album-item .avatar-fallback {
  width: 36px;
  height: 36px;
  border-radius: 5px;
  flex: none;
}

.album-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.album-meta strong {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.album-meta span {
  color: var(--muted);
  font-size: 0.71rem;
  text-transform: capitalize;
}

/* ── Artist search ───────────────────────────────────────────────────────── */
.search-wrap {
  position: relative;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
  z-index: 30;
}

.search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.search-item:last-child {
  border-bottom: 0;
}

.search-item:hover,
.search-item:focus {
  background: rgba(220, 38, 38, 0.1);
  outline: none;
}

.search-item img,
.search-item .avatar-fallback {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  background: var(--line);
}

.avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.search-item .meta {
  min-width: 0;
  flex: 1;
}

.search-item .meta strong {
  display: block;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-item .meta span {
  color: var(--muted);
  font-size: 0.78rem;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-empty {
  padding: 14px;
  color: var(--muted);
  font-size: 0.86rem;
}

/* Genre discovery. Artist genre tags are sparse, so the page lets the user
 * supply the genre directly rather than deriving one.
 *
 * It MUST sit above the name search in the DOM: `.search-results` is an
 * absolutely-positioned dropdown anchored to `.search-wrap`, with `z-index: 30`,
 * so anything rendered after the search input is covered by it and unclickable
 * while the dropdown is open. */
.genre-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.genre-label {
  flex: none;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.genre-row input {
  flex: 1;
  min-width: 0;
}

.genre-row .btn {
  flex: none;
}

.or-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 700;
}

.or-divider::before,
.or-divider::after {
  content: "";
  height: 1px;
  background: var(--line);
  flex: 1;
}

@media (max-width: 520px) {
  .genre-row {
    flex-wrap: wrap;
  }

  .genre-row input {
    flex-basis: 100%;
    order: 2;
  }

  .genre-row .btn {
    order: 3;
  }
}

.spinner {
  position: absolute;
  right: 14px;
  top: 50%;
  width: 16px;
  height: 16px;
  margin-top: -8px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.selected-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 22px 0 10px;
}

.selected-head h3 {
  font-size: 0.92rem;
  font-weight: 700;
}

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.pill-accent {
  background: var(--accent-soft);
  border-color: rgba(220, 38, 38, 0.35);
  color: var(--accent);
}

.selected-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.selected-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}

.selected-list img,
.selected-list .avatar-fallback {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  background: var(--line);
}

.selected-list .name {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selected-list .genres {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 400;
  display: block;
}

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.icon-btn:hover {
  color: var(--danger);
  background: rgba(244, 99, 106, 0.1);
}

.placeholder-row {
  color: var(--muted);
  font-size: 0.86rem;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  text-align: center;
}

.actions-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.actions-bar.center {
  justify-content: center;
}

/* ── Tournament ──────────────────────────────────────────────────────────── */
.tourney-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.tourney-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.86rem;
}

.tourney-actions {
  display: flex;
  gap: 8px;
}

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}

#progressBarInner {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent));
  transition: width 0.3s ease;
}

/* ── League: group-stage progress + standings ────────────────────────────── */
.stage-progress {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.78rem;
}

.stage-progress[hidden] {
  display: none;
}

.stage-label {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 700;
  font-size: 0.7rem;
  white-space: nowrap;
}

.stage-progress .progress-track {
  flex: 1;
}

#stageBarInner {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent));
  transition: width 0.3s ease;
}

.league-count {
  margin-top: 8px;
}

.standings-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 820px) {
  .standings-wrap {
    grid-template-columns: 1fr;
  }
}

.standings {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  /* Grid items default to min-width:auto, so a wide table would stretch this
     box past its column instead of letting the table shrink. */
  min-width: 0;
}

.standings h3 {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.standings .qualify-note {
  font-size: 0.8rem;
  color: var(--text-tertiary);
  margin: 2px 0 8px;
}

/* A qualification line the table cannot separate; the tie-breaker settles it. */
.standings .qualify-note.contested {
  color: var(--accent);
}

.standings table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  /* Fixed layout keeps the table at 100% of its box. With auto layout the
     nowrap song/artist text below sets a min-content width wider than the
     phone viewport, which is what forced a horizontal scroll. */
  table-layout: fixed;
}

.standings th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 6px 6px 0;
  border-bottom: 1px solid var(--line-soft);
}

.standings th.num,
.standings td.num {
  text-align: right;
  width: 30px;
  padding-right: 10px;
}

/* The position column is a header like any other in the markup, so it carries
   no `.num` class and would otherwise take an equal share of the fixed layout
   and starve the song names. */
.standings th:first-child {
  width: 30px;
  padding-right: 10px;
}

.standings th:last-child,
.standings td:last-child {
  padding-right: 8px;
}

.standings td {
  padding: 6px 0 6px 0;
  border-bottom: 1px solid rgba(51, 51, 51, 0.5);
}

.standings tr.qualifies td {
  background: rgba(220, 38, 38, 0.06);
}

.standings tr.qualifies td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}

.standings tr.out td {
  opacity: 0.5;
}

/* The two songs currently head-to-head in this draw. */
.standings tr.playing td {
  background: rgba(240, 200, 40, 0.16);
  opacity: 1;
}

.standings tr.playing td:first-child {
  box-shadow: inset 3px 0 0 #f0c828;
}

.standings tr.playing .pts {
  color: #f5d75a;
}

.standings td.team {
  min-width: 0;
}

.standings td.team strong {
  display: block;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.standings td.team span {
  color: var(--muted);
  font-size: 0.72rem;
}

.standings td.pts {
  font-weight: 700;
  color: var(--accent);
}

.matchup {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 14px;
}

/* A playoff three-way adds one more card and one more badge. */
.matchup.three-way {
  grid-template-columns: 1fr auto 1fr auto 1fr;
}

/* Group tie-breaker panel: shown instead of a matchup when the table cannot
 * separate songs straddling a qualification line. */
.tie-panel {
  background-color: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tie-modes {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

/* Each option is a button plus the sentence explaining what it will do, so the
 * three ways of settling a level group are never a guess. */
.tie-mode {
  flex: 1 1 220px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
}

.tie-mode .btn {
  width: 100%;
}

.tie-mode-desc {
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
}

/* Manual picker: keep the instruction, the song bubbles and the confirm button
 * from crowding each other. */
.tie-body .tie-note {
  margin-bottom: 14px;
}

.tie-body .tie-songs {
  margin-bottom: 18px;
}

.tie-body .tie-confirm {
  margin-top: 4px;
}

.tie-body .tie-back {
  align-self: flex-start;
  margin-top: 6px;
}

/* Album cover inside a tie-break song bubble. */
.tie-song .tie-art {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  object-fit: cover;
  flex: none;
  background: var(--line);
}

.tie-song .tie-art.avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.tie-song .tie-song-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-width: 0;
}

.tie-song .tie-song-text strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ── Modal (album content confirmation) ──────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.66);
  backdrop-filter: blur(3px);
}

.modal-card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.content-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.content-choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease;
}

.content-choice:hover {
  border-color: var(--line);
}

.content-choice:has(input:checked) {
  border-color: var(--accent-line);
  background: rgba(220, 38, 38, 0.08);
}

.content-choice input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  margin-top: 2px;
  flex: none;
}

.content-choice span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.content-choice strong {
  font-size: 0.9rem;
}

.content-choice em {
  font-style: normal;
  font-size: 0.78rem;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.tie-matches {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.tie-match {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tie-match-head {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
}

.tie-songs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.tie-song {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
  background: transparent;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  font: inherit;
  transition:
    border-color 0.15s ease,
    background-color 0.15s ease;
}

.tie-song:hover:not(:disabled) {
  border-color: var(--accent);
}

.tie-song:disabled {
  cursor: default;
  opacity: 0.7;
}

.tie-song strong {
  font-weight: 700;
}

.tie-song span {
  font-size: 0.82rem;
  color: var(--text-tertiary);
}

.tie-song.won {
  border-color: var(--accent);
  background: rgba(var(--accent-rgb, 255, 255, 255), 0.08);
}

.tie-song.lost {
  opacity: 0.45;
}

.tie-order {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
}

/* ── Random draw (bingo-style reveal) ────────────────────────────────────── */
.draw-machine {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
}

.draw-drum {
  position: relative;
  width: 92px;
  height: 92px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--line);
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.12), transparent 60%),
    var(--bg-2);
  display: grid;
  place-items: center;
  overflow: hidden;
}

/* The drum "spins" by rotating a ring of dots behind the ball. */
.draw-drum::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 2px dashed var(--accent-line);
  opacity: 0;
}

.draw-drum.spinning::before {
  opacity: 1;
  animation: drawSpin 0.55s linear infinite;
}

.draw-ball {
  position: relative;
  z-index: 1;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.15rem;
  color: #ffffff;
  background: radial-gradient(circle at 32% 28%, #ff6b6b, var(--accent-deep));
  box-shadow: 0 6px 16px rgba(220, 38, 38, 0.4);
}

.draw-ball.pop {
  animation: drawPop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.draw-ball.settled {
  background: radial-gradient(circle at 32% 28%, #4ade80, #15803d);
  box-shadow: 0 6px 16px rgba(21, 128, 61, 0.45);
}

.draw-out {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  flex: 1 1 260px;
}

.draw-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--accent-line);
  border-radius: 999px;
  background: rgba(220, 38, 38, 0.08);
  animation: drawChipIn 0.35s ease both;
}

.draw-chip .tie-art {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  background: var(--line);
}

.draw-chip .tie-art.avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.draw-chip-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.draw-chip-text strong {
  font-size: 0.86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.draw-chip-text span {
  font-size: 0.74rem;
  color: var(--muted);
}

.draw-place {
  font-style: normal;
  font-weight: 800;
  font-size: 0.78rem;
  color: var(--accent);
}

@keyframes drawSpin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes drawPop {
  0% {
    transform: scale(0.6);
  }
  60% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes drawChipIn {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .draw-drum.spinning::before,
  .draw-ball.pop,
  .draw-chip {
    animation: none;
  }
}

/* stacked on narrow screens */
@media (max-width: 760px) {
  .matchup {
    grid-template-columns: 1fr;
  }

  .vs-badge {
    margin: 0 auto;
  }
}

.song-card {
  background-color: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 13px;
  transition:
    border-color 0.15s ease,
    transform 0.15s ease;
}

/* Album-derived tint, applied by JS once the cover art has been sampled.
 * --c1/--c2 are "r,g,b" triplets; without them there is simply no gradient.
 * Deliberately a plain background-image with no overlay element, no z-index and
 * no overflow changes — anything layered around the embed iframe risks
 * interfering with the player. */
.song-card.tinted {
  background-image: linear-gradient(
    135deg,
    rgba(var(--c1), 0.34),
    rgba(var(--c2), 0.08) 62%,
    transparent
  );
}

.song-card:hover {
  border-color: #404040;
}

.song-card.winner-picked {
  border-color: var(--accent);
  background: rgba(220, 38, 38, 0.06);
}

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

.song-head img,
.song-head .avatar-fallback {
  width: 54px;
  height: 54px;
  border-radius: 9px;
  object-fit: cover;
  flex: none;
  background: var(--line);
}

.song-head .t {
  min-width: 0;
}

.song-head .t strong {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}

.song-head .t span {
  color: var(--muted);
  font-size: 0.84rem;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}

.tag-primary {
  color: var(--accent);
  border-color: rgba(220, 38, 38, 0.32);
}

.embed-slot {
  border-radius: 12px;
  overflow: hidden;
  background: #080808;
  min-height: 152px;
}

.embed-slot iframe,
.embed-host,
.embed-host iframe {
  display: block;
  width: 100%;
  border: 0;
}

.embed-slot .embed-host {
  min-height: 152px;
}

/* ── Preview card ──────────────────────────────────────────────────────────
 * Laid out like a streaming player row: square artwork on the left, title and
 * credit stacked beside it, then a transport bar with the scrubber, a
 * countdown and the play button. The background is the album's own artwork
 * colour (`bgColor` from Apple), and `--pv-fg` is switched between black and
 * white so text stays legible on light and dark covers alike. */
.apple-preview-card {
  --pv-bg: #1e1e1e;
  --pv-fg: #ffffff;
  position: relative;
  display: grid;
  grid-template-columns: 152px minmax(0, 1fr);
  grid-template-rows: 1fr auto;
  column-gap: 20px;
  height: 152px;
  overflow: hidden;
  color: var(--pv-fg);
  background: var(--pv-bg);
  border-radius: 12px;
}

.apple-preview-card-large {
  grid-template-columns: 232px minmax(0, 1fr);
  height: 232px;
}

.apple-preview-art {
  grid-column: 1;
  grid-row: 1 / 3;
  align-self: center;
  justify-self: center;
  width: 120px;
  height: 120px;
  border-radius: 8px;
  object-fit: cover;
  background: rgba(0, 0, 0, 0.2);
}

.apple-preview-card-large .apple-preview-art {
  width: 200px;
  height: 200px;
  border-radius: 10px;
}

/* The brand mark sits in the top-right, as in the reference player. */
.apple-preview-brand {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 26px;
  height: 26px;
  object-fit: contain;
  opacity: 0.9;
  pointer-events: none;
}

/* The copy spans both rows so it centres against the artwork rather than
 * against the space left over above the transport bar, which made the title sit
 * visibly high on the tall champion card. The bar still occupies row 2; the
 * title and credit are single-line, so they never reach it. */
.apple-preview-copy {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
  min-width: 0;
  padding: 0 46px 0 0;
}

.apple-preview-title {
  display: block;
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.apple-preview-credit {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  min-width: 0;
}

.apple-preview-artist {
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0.82;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Explicit / release date / genre chips. */
.apple-preview-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.apple-chip {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(127, 127, 127, 0.28);
  color: inherit;
  white-space: nowrap;
}

.apple-chip-explicit {
  background: rgba(127, 127, 127, 0.45);
  padding: 3px 6px;
  font-size: 0.62rem;
}

.apple-preview-bar {
  grid-column: 2;
  grid-row: 2;
  align-self: end;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  /* Reserve room for the absolutely-positioned transport button so the
   * countdown never renders underneath it. */
  padding: 0 60px 0 0;
  margin-bottom: 16px;
}

.apple-preview-progress {
  flex: 1;
  min-width: 0;
  height: 4px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--pv-fg);
}

.apple-preview-time {
  flex: none;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.78;
}

/* Transport button, vertically centred on the right of the row. The bar above
   reserves room for it so the countdown never sits underneath. */
.apple-preview-play {
  position: absolute;
  right: 14px;
  bottom: 13px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: var(--pv-fg);
  color: var(--pv-bg);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.apple-preview-play:hover {
  transform: scale(1.06);
}

.apple-preview-card.is-playing .apple-preview-play {
  opacity: 0.92;
}

.preview-unavailable {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 152px;
  padding: 16px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px dashed var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}

/* Without artwork the first column would stay a 152px void, so collapse it and
   let the text block use the full width. */
.apple-preview-card.apple-preview-no-art {
  grid-template-columns: 0 minmax(0, 1fr);
  padding-left: 16px;
}

@media (max-width: 520px) {
  .apple-preview-card,
  .apple-preview-card-large {
    grid-template-columns: 104px minmax(0, 1fr);
    column-gap: 14px;
  }

  .apple-preview-card .apple-preview-art,
  .apple-preview-card-large .apple-preview-art {
    width: 88px;
    height: 88px;
  }

  .apple-preview-title {
    font-size: 1rem;
  }

  .apple-preview-chips {
    display: none;
  }
}

.clip-badge {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #ffffff;
  background: rgba(220, 38, 38, 0.9);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

/* Sits directly under the player: open-in-Apple-Music link + preview badge.
 * Kept outside the player slot so neither can overlap it. */
.player-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: -4px;
}

.open-in-apple {
  font-size: 0.74rem;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.open-in-apple:hover {
  color: var(--accent);
  border-bottom-color: var(--accent-line);
}

.embed-hero {
  margin-top: 20px;
  max-width: 620px;
  margin-left: auto;
  margin-right: auto;
}

.vote-btn {
  width: 100%;
  margin-top: auto;
}

.vs-badge {
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  text-align: center;
}

/* ── Bracket ─────────────────────────────────────────────────────────────── */
.bracket-details {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px 20px;
}

.bracket-details summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.92rem;
  list-style: none;
}

.bracket-details summary::-webkit-details-marker {
  display: none;
}

.bracket-details summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 8px;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.bracket-details[open] summary::before {
  transform: rotate(90deg);
}

.bracket-scroll {
  overflow-x: auto;
  padding-top: 16px;
}

.bracket {
  display: flex;
  gap: 22px;
  min-width: max-content;
  align-items: stretch;
}

.bracket-round {
  display: flex;
  flex-direction: column;
  min-width: 190px;
}

/* The heading must sit OUTSIDE the distributed area, otherwise flexbox spaces
 * the titles out too and every round drifts down the page. */
.bracket-round h4 {
  margin: 0 0 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 700;
  flex: none;
  line-height: 1.4;
}

/* space-around centres match i at (2i+1)/2n of the height. Because each round
 * halves the match count, that lands each match exactly between its two
 * feeders — so the rounds line up perfectly. Requires: equal container heights
 * (align-items: stretch), equal match heights, and NO extra gap. */
.bracket-matches {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}

/* Matches are a fixed minimum height, because the alignment maths below only
 * works when every match is the same height. `renderBracketView` also sets a
 * min-height on .bracket from the largest round; that is what creates the free
 * space `space-around` distributes. Without it the first round fills its column
 * exactly and its matches sit flush against one another. */
.bracket-match {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--bg-2);
  overflow: hidden;
  min-height: 62px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.bracket-match.active {
  border-color: rgba(220, 38, 38, 0.55);
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.12);
}

/* The pairing being played right now — a much stronger highlight, since in a
 * large bracket the active match is easy to lose. */
.bracket-match.playing {
  border-color: #f0c828;
  background: rgba(240, 200, 40, 0.09);
  box-shadow:
    0 0 0 2px rgba(240, 200, 40, 0.3),
    0 0 18px rgba(240, 200, 40, 0.18);
}

.bracket-match.playing .slot-name {
  color: #f5d75a;
}

.slot {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.3;
}

.slot + .slot {
  border-top: 1px solid var(--line-soft);
}

.slot .slot-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slot .slot-artist {
  color: #666666;
  font-size: 0.7rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 78px;
}

.slot.won {
  color: var(--text);
  font-weight: 600;
  background: rgba(220, 38, 38, 0.08);
}

.slot.lost {
  opacity: 0.42;
  text-decoration: line-through;
  text-decoration-color: rgba(153, 153, 153, 0.4);
}

.slot.empty {
  color: #4d4d4d;
  font-style: italic;
}

/* ── Champion ────────────────────────────────────────────────────────────── */
.champion-hero {
  text-align: center;
  padding: 34px 20px;
  background: linear-gradient(180deg, rgba(220, 38, 38, 0.12), transparent 85%);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}

.trophy {
  font-size: 3rem;
  display: block;
  margin-bottom: 8px;
}

.champion-kicker {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--accent);
}

.champion-hero h2 {
  font-size: clamp(1.5rem, 4vw, 2.3rem);
  font-weight: 800;
  margin-top: 8px;
  letter-spacing: -0.01em;
}

.champion-artist {
  color: var(--muted);
  margin-top: 6px;
  font-size: 1rem;
}

.podium {
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.podium li {
  font-size: 0.9rem;
}

.podium li span {
  color: var(--muted);
}

.podium li strong {
  font-weight: 600;
}

/* ── Visual podium ───────────────────────────────────────────────────────── */
/* 2nd | 1st | 3rd, with the placing encoded in pillar height. The 3D feel comes
 * from a shared perspective plus rotateX on each pillar, so the blocks appear to
 * lean back into the page, with a stacked-shadow "plinth" underneath. */
.podium-stage {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(6px, 2.5vw, 26px);
  padding: 26px 4px 8px;
  perspective: 900px;
  perspective-origin: 50% 30%;
}

.podium-stage:empty {
  display: none;
}

.podium-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex: 1 1 0;
  min-width: 0;
  max-width: 190px;
  /* Children keep their own transforms; the column just spaces them. */
  transform-style: preserve-3d;
}

/* The album cover. It floats because of the layered shadow + the lift on hover,
 * and the slow bob animation gives it life without needing any JS. */
.podium-art {
  position: relative;
  width: clamp(64px, 20vw, 118px);
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: #0a0a0a;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    0 18px 30px rgba(0, 0, 0, 0.55),
    0 0 0 1px rgba(0, 0, 0, 0.4);
  transform: translateZ(34px);
  animation: podium-float 5.5s ease-in-out infinite;
}

.place-1 .podium-art {
  width: clamp(78px, 24vw, 142px);
  animation-delay: -1.4s;
  box-shadow:
    0 22px 38px rgba(0, 0, 0, 0.6),
    0 0 34px rgba(220, 38, 38, 0.28);
}

.place-3 .podium-art {
  animation-delay: -2.8s;
}

.podium-art img,
.podium-art .avatar-fallback {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0;
  font-size: 1.6rem;
}

@keyframes podium-float {
  0%,
  100% {
    transform: translateZ(34px) translateY(0);
  }
  50% {
    transform: translateZ(52px) translateY(-9px);
  }
}

.podium-meta {
  text-align: center;
  max-width: 100%;
  min-width: 0;
}

.podium-meta strong {
  display: block;
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.podium-meta span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The pillar: a slab that leans back, with a cast shadow doing the 3D work. */
.podium-pillar {
  width: 100%;
  border-radius: 8px 8px 3px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  transform: rotateX(11deg);
  transform-origin: bottom center;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-bottom: 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.13),
    0 20px 26px -14px rgba(0, 0, 0, 0.85);
  background: linear-gradient(180deg, var(--panel-2), #141414);
}

.podium-pillar span {
  font-size: clamp(1.3rem, 4vw, 2.1rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
}

.podium-pillar em {
  font-style: normal;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

/* Heights encode the placing — the classic staggered podium. */
.place-1 .podium-pillar {
  height: clamp(104px, 26vw, 168px);
  background: linear-gradient(
    180deg,
    rgba(220, 38, 38, 0.42),
    rgba(220, 38, 38, 0.09) 70%,
    #141414
  );
  border-color: var(--accent-line);
}

.place-1 .podium-pillar span {
  color: #ffffff;
}

.place-2 .podium-pillar {
  height: clamp(74px, 19vw, 124px);
  background: linear-gradient(
    180deg,
    rgba(204, 204, 204, 0.28),
    rgba(204, 204, 204, 0.06) 70%,
    #141414
  );
  border-color: rgba(204, 204, 204, 0.28);
}

.place-2 .podium-pillar span {
  color: #d9d9d9;
}

.place-3 .podium-pillar {
  height: clamp(56px, 15vw, 96px);
  background: linear-gradient(
    180deg,
    rgba(190, 124, 71, 0.32),
    rgba(190, 124, 71, 0.07) 70%,
    #141414
  );
  border-color: rgba(190, 124, 71, 0.3);
}

.place-3 .podium-pillar span {
  color: #e6a877;
}

/* A bracket can produce two joint-third songs, so the stage may hold four
 * columns. The thirds share the same pillar height and sit either side of the
 * winner, which is why they are not merged into one column. */
.podium-col.place-3 {
  max-width: 150px;
}

.podium-col.place-3 + .podium-col.place-3 .podium-art {
  animation-delay: -4.2s;
}

/* Respect users who don't want motion. */
@media (prefers-reduced-motion: reduce) {
  .podium-art {
    animation: none;
  }
}

/* ── Footer ──────────────────────────────────────────────────────────────── */
.footer {
  text-align: center;
  color: #666666;
  font-size: 0.78rem;
  padding: 26px 20px 40px;
}

/* ── Responsive / mobile & tablet ─────────────────────────────────────────
 * Mobile-first corrections, in descending breakpoint order. The goals: nothing
 * may overflow horizontally, the header spans the full width, players scale
 * with the card, and the bracket stays readable instead of squashing.
 * ────────────────────────────────────────────────────────────────────────── */

/* Tablet and below: tighten the page chrome. */
@media (max-width: 900px) {
  main {
    padding-top: 20px;
  }

  .panel {
    padding: 18px;
  }

  .bracket-round {
    min-width: 168px;
  }
}

/* Phones and small tablets. */
@media (max-width: 760px) {
  /* Full-width header: the brand and the status stack instead of fighting for
     one row, which is what squeezed the title off-screen on narrow phones. */
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px;
    text-align: center;
  }

  .brand {
    justify-content: center;
    gap: 10px;
  }

  .brand p {
    display: none; /* the strapline is noise on a phone */
  }

  .conn {
    justify-content: center;
    flex-wrap: wrap;
    white-space: normal;
  }

  main {
    padding: 16px 14px 48px;
  }

  .panel {
    padding: 16px;
    border-radius: 12px;
  }

  .panel-head {
    margin-bottom: 14px;
  }

  /* Toggles: label above the control, so the select never squeezes the text. */
  .toggle {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .toggle input[type="checkbox"] {
    align-self: flex-start;
  }

  .select-sm {
    width: 100%;
  }

  .row {
    flex-direction: column;
  }

  .row .btn {
    width: 100%;
  }

  /* The matchup is already single-column at this width; centre it and let the
     cards use the full available width. */
  .matchup {
    gap: 12px;
  }

  .song-card {
    padding: 14px;
  }

  /* Players scale with the viewport but keep the 152px card shape. */
  .embed-slot,
  .embed-slot iframe,
  .embed-slot .embed-host {
    min-height: 152px;
    width: 100%;
  }

  .embed-hero,
  .embed-hero iframe,
  .embed-hero .embed-host {
    max-width: 100%;
    min-height: 232px;
  }

  /* Podium: keep every column on one row but shrink everything so 1st, 2nd and
     the joint thirds stay side by side. */
  .podium-stage {
    gap: 6px;
    padding-top: 18px;
  }

  .podium-col {
    max-width: 120px;
  }

  .podium-col.place-3 {
    max-width: 96px;
  }

  .podium-meta strong {
    font-size: 0.74rem;
  }

  .podium-meta span {
    font-size: 0.66rem;
  }

  .podium-pillar em {
    display: none; /* the number is enough at this size */
  }

  .actions-bar .btn,
  .tourney-actions .btn {
    width: 100%;
  }

  .tourney-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .tourney-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .standings {
    padding: 14px;
  }
}

/* Very narrow phones. */
@media (max-width: 420px) {
  .brand-logo {
    width: 36px;
    height: 36px;
  }

  .brand h1 {
    font-size: 1.02rem;
  }

  .panel {
    padding: 13px;
  }

  /* Album covers get small, so drop the name to one line and shrink the art. */
  .album-list {
    grid-template-columns: 1fr;
    max-height: 300px;
  }

  .podium-art {
    width: clamp(52px, 21vw, 72px);
  }

  .place-1 .podium-art {
    width: clamp(62px, 25vw, 88px);
  }

  .podium-pillar span {
    font-size: 1.15rem;
  }
}

/* Short landscape phones: don't waste vertical space on the podium. */
@media (max-height: 460px) and (orientation: landscape) {
  .podium-stage {
    padding-top: 10px;
  }

  .place-1 .podium-pillar {
    height: 74px;
  }

  .place-2 .podium-pillar {
    height: 56px;
  }

  .place-3 .podium-pillar {
    height: 44px;
  }
}

/* Touch devices: enlarge the tap targets that were sized for a mouse. */
@media (hover: none) and (pointer: coarse) {
  .icon-btn {
    min-width: 34px;
    min-height: 34px;
  }

  .btn-sm {
    padding: 9px 16px;
  }

  .album-item {
    padding: 9px;
  }

  .search-item {
    padding: 12px;
  }
}
