/* ─────────────────────────────────────────────
   Design tokens
   ───────────────────────────────────────────── */
:root {
  /* Surfaces */
  --bg-1: #07090f;
  --bg-2: #0a0e1a;
  --surface-1: #11151f;
  --surface-2: #161b27;
  --surface-3: #1c2333;
  --border-1: #1f2533;
  --border-2: #2a3346;
  --border-3: #38445d;

  /* Text */
  --text-1: #e8ecf2;
  --text-2: #b4bccb;
  --text-3: #8c97a8;
  --text-4: #5b6373;

  /* Brand + semantic */
  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.16);
  --accent-glow: rgba(99, 102, 241, 0.45);
  --pink: #ec4899;
  --pink-soft: rgba(236, 72, 153, 0.16);
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.16);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.16);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.16);
  --cyan: #06b6d4;

  /* Radii + shadows */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-2: 0 8px 32px rgba(0, 0, 0, 0.45);
  --shadow-glow-accent: 0 0 0 1px rgba(99, 102, 241, 0.35), 0 8px 24px rgba(99, 102, 241, 0.2);

  /* Type */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 800px at 80% -20%, rgba(99, 102, 241, 0.08), transparent 60%),
    radial-gradient(900px 600px at -10% 20%, rgba(236, 72, 153, 0.05), transparent 50%),
    var(--bg-2);
  background-attachment: fixed;
  color: var(--text-1);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

button {
  font-family: inherit;
}

/* ─────────────────────────────────────────────
   App bar
   ───────────────────────────────────────────── */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: rgba(10, 14, 26, 0.78);
  backdrop-filter: saturate(140%) blur(16px);
  -webkit-backdrop-filter: saturate(140%) blur(16px);
  border-bottom: 1px solid var(--border-1);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--accent) 0%, var(--pink) 100%);
  color: #ffffff;
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.35);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 360px;
  margin-top: 2px;
}

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

.meta-line {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  max-width: 280px;
}

.phase-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  color: var(--text-2);
}

.phase-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--text-4);
  box-shadow: 0 0 0 0 currentColor;
  transition: background 0.3s;
}

.phase-pill[data-phase="downloading"] {
  background: var(--amber-soft);
  border-color: rgba(245, 158, 11, 0.4);
  color: var(--amber);
}
.phase-pill[data-phase="downloading"] .phase-dot {
  background: var(--amber);
  animation: pulse 1.6s infinite;
}

.phase-pill[data-phase="seeding"] {
  background: var(--pink-soft);
  border-color: rgba(236, 72, 153, 0.4);
  color: var(--pink);
}
.phase-pill[data-phase="seeding"] .phase-dot {
  background: var(--pink);
  animation: pulse 1.6s infinite;
}

.phase-pill[data-phase="placement"] {
  background: var(--accent-soft);
  border-color: rgba(99, 102, 241, 0.4);
  color: var(--accent);
}
.phase-pill[data-phase="placement"] .phase-dot {
  background: var(--accent);
  animation: pulse 1.6s infinite;
}

.phase-pill[data-phase="done"] {
  background: var(--green-soft);
  border-color: rgba(16, 185, 129, 0.4);
  color: var(--green);
}
.phase-pill[data-phase="done"] .phase-dot {
  background: var(--green);
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 currentColor; }
  50% { box-shadow: 0 0 0 6px transparent; opacity: 0.7; }
}

/* ─────────────────────────────────────────────
   Page layout
   ───────────────────────────────────────────── */
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 28px 100px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ─────────────────────────────────────────────
   Hero — live battles (1..N parallel)
   ───────────────────────────────────────────── */
.hero {
  position: relative;
  background: linear-gradient(135deg, var(--surface-1) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border-2);
  border-radius: var(--r-xl);
  padding: 22px 24px;
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(800px 200px at 50% -50%, var(--accent-soft), transparent 60%);
  pointer-events: none;
}

.hero-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.hero-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
}

.hero-count {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 3px 10px;
  border-radius: 999px;
}

.hero-empty {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 36px 0 16px;
  color: var(--text-3);
}

.hero-empty-icon {
  color: var(--text-4);
  opacity: 0.55;
}

.hero-empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-2);
}

.hero-empty-sub {
  font-size: 13px;
  color: var(--text-4);
}

/* Grid that adapts: 1 battle = full width, 2+ = auto-fit cards */
.hero-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 14px;
}

/* When only one card, let it span full width with breathing room */
.hero-grid.single {
  grid-template-columns: 1fr;
}

.battle-card {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.15s;
}

.battle-card:hover {
  border-color: var(--border-3);
}

/* Animated accent border */
.battle-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--r-lg);
  padding: 1px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--pink) 100%);
  opacity: 0;
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: card-glow 2.4s ease-in-out infinite;
  pointer-events: none;
}

@keyframes card-glow {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 0.7; }
}

.battle-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
  font-size: 11px;
}

.battle-card-source {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  color: var(--text-3);
}

.battle-card-source.seed {
  background: var(--pink-soft);
  color: var(--pink);
  border-color: rgba(236, 72, 153, 0.35);
}
.battle-card-source.placement {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(99, 102, 241, 0.35);
}
.battle-card-source.validation {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.35);
}

.battle-card-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  color: var(--green);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.battle-card-status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.4s infinite;
}

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

.battle-side {
  min-width: 0;
}

.battle-side[data-side="A"] {
  text-align: left;
}
.battle-side[data-side="B"] {
  text-align: right;
}

.battle-side-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  margin-bottom: 6px;
}

.battle-side[data-side="A"] .battle-side-tag {
  background: var(--accent-soft);
  color: var(--accent);
}
.battle-side[data-side="B"] .battle-side-tag {
  background: var(--pink-soft);
  color: var(--pink);
}

.battle-side-name {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
  word-break: break-word;
}

.battle-side-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
}

.battle-vs {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--pink));
  color: #ffffff;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
  flex-shrink: 0;
}

/* ─────────────────────────────────────────────
   Stats strip
   ───────────────────────────────────────────── */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
}

.stat {
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--r-md);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s, transform 0.1s;
}

.stat:hover {
  border-color: var(--border-2);
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  font-weight: 600;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-1);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.stat.warn .stat-value {
  color: var(--amber);
}

/* ─────────────────────────────────────────────
   Generic card
   ───────────────────────────────────────────── */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--r-lg);
  overflow: hidden;
}

.card-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-3);
}

.card-body {
  padding: 18px 20px;
}

/* ─────────────────────────────────────────────
   Last result
   ───────────────────────────────────────────── */
.last-empty {
  padding: 12px 0;
  font-style: italic;
  color: var(--text-3);
}

.last-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.winner-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  padding: 4px 12px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 13px;
  background: var(--accent);
  color: #0a0e1a;
}

.winner-badge[data-w="B"] {
  background: var(--pink);
}
.winner-badge[data-w="DRAW"] {
  background: var(--text-4);
  color: var(--text-1);
}

.last-summary {
  font-size: 14px;
  color: var(--text-2);
}

.last-summary strong {
  color: var(--text-1);
  font-weight: 600;
}

.last-conf {
  margin-left: auto;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 12px;
}

.last-reason {
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  padding: 12px 14px;
  font-style: italic;
  color: var(--text-2);
  line-height: 1.55;
  margin: 0 0 12px;
  font-size: 13px;
}

.last-deltas {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.delta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-1);
  border-radius: 999px;
  font-size: 12px;
}

.delta-name {
  color: var(--text-3);
  font-weight: 500;
}

.delta-change {
  color: var(--text-1);
  font-family: var(--font-mono);
  font-weight: 600;
}

.delta-arrow {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 11px;
}

.delta-arrow[data-dir="up"] {
  color: var(--green);
}

.delta-arrow[data-dir="down"] {
  color: var(--red);
}

/* ─────────────────────────────────────────────
   Tabs
   ───────────────────────────────────────────── */
.tabs-card {
  overflow: hidden;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-1);
  background: var(--surface-2);
  padding: 0 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 14px 16px;
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s;
}

.tab:hover {
  color: var(--text-2);
}

.tab.active {
  color: var(--text-1);
}

.tab.active::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 14px;
  right: 14px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}

.tab-icon {
  font-size: 14px;
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  margin-left: 2px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-3);
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.tab.active .tab-count {
  background: var(--accent-soft);
  color: var(--accent);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-1);
  background: var(--surface-2);
  flex-wrap: wrap;
}

.toolbar-info {
  font-size: 12px;
  color: var(--text-3);
  font-family: var(--font-mono);
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: var(--accent);
  font-size: 12px;
  max-width: 320px;
}

.filter-pill strong {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.filter-clear {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  border-radius: 4px;
}

.filter-clear:hover {
  color: var(--red);
}

/* ─────────────────────────────────────────────
   Ranking table
   ───────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
}

.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.rank-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-4);
  border-bottom: 1px solid var(--border-1);
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 1;
}

.rank-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-1);
  vertical-align: middle;
}

.rank-table tr:last-child td {
  border-bottom: none;
}

.rank-table tbody tr {
  transition: background 0.1s;
}

.rank-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.rank-table tr.current-fight {
  background: linear-gradient(90deg, rgba(99, 102, 241, 0.08), transparent 70%);
  position: relative;
}

.rank-table tr.current-fight td:first-child::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
}

.col-rank {
  width: 40px;
  font-family: var(--font-mono);
  color: var(--text-3);
  font-weight: 600;
}

.rank-table tbody .col-rank {
  font-size: 14px;
}

.rank-table tbody tr:nth-child(1) .col-rank {
  color: #fbbf24;
  font-weight: 800;
}
.rank-table tbody tr:nth-child(2) .col-rank {
  color: #cbd5e1;
  font-weight: 800;
}
.rank-table tbody tr:nth-child(3) .col-rank {
  color: #cd7f32;
  font-weight: 800;
}

.col-name {
  min-width: 200px;
}

.player-link {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-align: left;
  font-weight: 500;
  letter-spacing: -0.01em;
  transition: color 0.15s;
}

.player-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

.col-num {
  font-family: var(--font-mono);
  font-weight: 600;
}

.col-record {
  font-family: var(--font-mono);
  color: var(--text-3);
  font-size: 12px;
}

.col-actions {
  width: 110px;
  text-align: right;
}

.row-actions {
  display: inline-flex;
  gap: 6px;
}

.row-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 28px;
  padding: 0;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}

.row-btn:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--border-3);
  color: var(--text-1);
}

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

.row-btn.play.playing {
  background: var(--accent);
  color: #0a0e1a;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.row-btn.zip:hover:not(:disabled) {
  border-color: var(--pink);
  color: var(--pink);
}

/* Status pills */
.status-pill {
  display: inline-flex;
  padding: 2px 8px;
  font-size: 10px;
  border-radius: 999px;
  border: 1px solid var(--border-2);
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  background: var(--surface-2);
}

.status-pill.ranked {
  background: var(--green-soft);
  color: var(--green);
  border-color: rgba(16, 185, 129, 0.3);
}
.status-pill.placement {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(99, 102, 241, 0.3);
}
.status-pill.seed {
  background: var(--pink-soft);
  color: var(--pink);
  border-color: rgba(236, 72, 153, 0.3);
}
.status-pill.disabled {
  background: var(--red-soft);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.3);
}
.status-pill.new {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.3);
}
.status-pill.needs_review {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.3);
}

/* ─────────────────────────────────────────────
   Match history
   ───────────────────────────────────────────── */
.match-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 640px;
  overflow-y: auto;
}

.empty-li {
  padding: 30px;
  text-align: center;
  color: var(--text-4);
  font-style: italic;
  font-size: 13px;
}

.match-row {
  display: grid;
  grid-template-columns: 70px 90px 1fr 130px 60px;
  gap: 12px;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-1);
  cursor: pointer;
  transition: background 0.1s;
}

.match-row:hover {
  background: rgba(255, 255, 255, 0.02);
}

.match-row:last-child {
  border-bottom: none;
}

.match-row .time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
}

.match-row .source-pill {
  display: inline-flex;
  justify-content: center;
  padding: 3px 8px;
  font-size: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--text-3);
}

.match-row .source-pill.seed {
  color: var(--pink);
  border-color: rgba(236, 72, 153, 0.35);
}
.match-row .source-pill.placement {
  color: var(--accent);
  border-color: rgba(99, 102, 241, 0.35);
}
.match-row .source-pill.validation {
  color: var(--amber);
  border-color: rgba(245, 158, 11, 0.35);
}

.versus {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}

.versus .player-link {
  font-size: 13px;
  font-weight: 500;
}

.versus .player-link.winner {
  color: var(--green);
  font-weight: 600;
}

.versus .player-link.loser {
  color: var(--text-3);
  text-decoration: line-through;
  text-decoration-color: rgba(255, 255, 255, 0.15);
}

.vs-tiny {
  color: var(--text-4);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.match-row .scores {
  font-family: var(--font-mono);
  font-weight: 600;
  text-align: center;
  font-size: 13px;
  color: var(--text-2);
}

.match-row .scores .win {
  color: var(--green);
  font-weight: 700;
}

.winner-tag {
  display: inline-flex;
  justify-content: center;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  font-weight: 800;
  font-size: 11px;
  background: var(--accent);
  color: #0a0e1a;
  text-align: center;
}

.winner-tag[data-w="B"] {
  background: var(--pink);
}
.winner-tag[data-w="DRAW"] {
  background: var(--text-4);
  color: var(--text-1);
}

.match-detail {
  grid-column: 1 / -1;
  padding: 14px 16px;
  margin-top: 10px;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border-1);
  border-radius: var(--r-md);
  cursor: default;
}

.match-detail .reason {
  font-style: italic;
  color: var(--text-2);
  margin: 0 0 12px;
  line-height: 1.5;
  font-size: 13px;
}

.match-detail .rating-deltas {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-3);
  flex-wrap: wrap;
}

.match-detail .rating-deltas strong {
  color: var(--text-1);
  font-weight: 600;
}

.lowconf-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--amber-soft);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: var(--amber);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ─────────────────────────────────────────────
   Live event feed
   ───────────────────────────────────────────── */
.event-feed {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 640px;
  overflow-y: auto;
}

.event-feed li {
  display: grid;
  grid-template-columns: 70px 130px 1fr;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px dashed var(--border-1);
  align-items: flex-start;
  font-size: 13px;
}

.event-feed li:last-child {
  border-bottom: none;
}

.event-feed .ev-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-4);
}

.event-feed .ev-type {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-3);
}

.event-feed .ev-type.battle_judged { color: var(--green); background: var(--green-soft); }
.event-feed .ev-type.battle_started { color: var(--accent); background: var(--accent-soft); }
.event-feed .ev-type.battle_failed { color: var(--red); background: var(--red-soft); }
.event-feed .ev-type.audio_added { color: var(--amber); background: var(--amber-soft); }
.event-feed .ev-type.audio_skipped { color: var(--text-4); }
.event-feed .ev-type.audio_failed { color: var(--red); background: var(--red-soft); }
.event-feed .ev-type.placement_done { color: var(--green); background: var(--green-soft); }
.event-feed .ev-type.import_complete { color: var(--green); background: var(--green-soft); }
.event-feed .ev-type.competition_created { color: var(--cyan); }

.event-feed .ev-body {
  color: var(--text-2);
  word-break: break-word;
  line-height: 1.4;
}

/* ─────────────────────────────────────────────
   Sticky audio player
   ───────────────────────────────────────────── */
.player-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 24px;
  background: rgba(10, 14, 26, 0.95);
  border-top: 1px solid var(--border-2);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.4);
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.player-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--accent), var(--pink));
  color: #ffffff;
  font-weight: 700;
  font-size: 12px;
  font-family: var(--font-mono);
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.player-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 280px;
}

.player-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-1);
}

.player-sub {
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-audio {
  flex: 1;
  height: 36px;
  min-width: 0;
}

.player-close {
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text-3);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
}

.player-close:hover {
  color: var(--red);
  border-color: var(--red);
}

/* ─────────────────────────────────────────────
   Footer + toasts
   ───────────────────────────────────────────── */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px;
  border-top: 1px solid var(--border-1);
  color: var(--text-4);
  font-size: 11px;
  font-family: var(--font-mono);
  flex-wrap: wrap;
  gap: 8px;
}

.dim {
  opacity: 0.6;
}

.toasts {
  position: fixed;
  top: 80px;
  right: 24px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-1);
  box-shadow: var(--shadow-2);
  animation: toastIn 0.25s ease-out;
  min-width: 240px;
  max-width: 360px;
}

.toast[data-kind="success"] {
  border-left-color: var(--green);
}
.toast[data-kind="error"] {
  border-left-color: var(--red);
}
.toast[data-kind="warn"] {
  border-left-color: var(--amber);
}

.toast-title {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 2px;
}

.toast-body {
  font-size: 12px;
  color: var(--text-3);
  line-height: 1.4;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateX(20px); }
}

.toast.leaving {
  animation: toastOut 0.2s ease-in forwards;
}

/* Custom scrollbars */
.match-list::-webkit-scrollbar,
.event-feed::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.match-list::-webkit-scrollbar-thumb,
.event-feed::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 4px;
}

.match-list::-webkit-scrollbar-thumb:hover,
.event-feed::-webkit-scrollbar-thumb:hover,
.table-wrap::-webkit-scrollbar-thumb:hover {
  background: var(--border-3);
}

.match-list::-webkit-scrollbar-track,
.event-feed::-webkit-scrollbar-track,
.table-wrap::-webkit-scrollbar-track {
  background: transparent;
}

/* ─────────────────────────────────────────────
   Utilities
   ───────────────────────────────────────────── */
.hidden {
  display: none !important;
}

.loading-row td {
  color: var(--text-4);
  font-style: italic;
  text-align: center;
  padding: 30px;
}

/* ─────────────────────────────────────────────
   Responsive
   ───────────────────────────────────────────── */
@media (max-width: 1024px) {
  .stats-strip {
    grid-template-columns: repeat(3, 1fr);
  }
  .meta-line {
    display: none;
  }
}

@media (max-width: 768px) {
  .app-bar {
    padding: 12px 16px;
  }
  .page {
    padding: 16px 16px 120px;
    gap: 16px;
  }
  .hero {
    padding: 18px 16px;
  }
  .hero-grid {
    grid-template-columns: 1fr;
  }
  .battle-card-row {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 8px;
  }
  .battle-side[data-side="A"],
  .battle-side[data-side="B"] {
    text-align: center;
  }
  .stats-strip {
    grid-template-columns: repeat(2, 1fr);
  }
  .stat-value {
    font-size: 18px;
  }
  .hide-sm {
    display: none;
  }
  .match-row {
    grid-template-columns: 60px 1fr 60px;
    grid-template-areas:
      "time versus winner"
      "source scores scores";
    gap: 8px;
  }
  .match-row .time { grid-area: time; }
  .match-row .source-pill { grid-area: source; }
  .match-row .versus { grid-area: versus; }
  .match-row .scores { grid-area: scores; text-align: left; }
  .match-row .winner-tag { grid-area: winner; }
  .event-feed li {
    grid-template-columns: 60px 1fr;
  }
  .event-feed .ev-type {
    grid-column: 2;
  }
  .player-info {
    max-width: 140px;
  }
  .player-bar {
    padding: 10px 14px;
  }
  .toasts {
    top: auto;
    bottom: 80px;
    right: 16px;
    left: 16px;
  }
  .toast {
    max-width: none;
  }
}

@media (max-width: 540px) {
  .hide-md {
    display: none;
  }
  .brand-sub {
    max-width: 180px;
  }
  .stats-strip {
    grid-template-columns: repeat(2, 1fr);
  }
  .header-meta .phase-pill .phase-label {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
