/* ─── Design tokens ───────────────────────────────────────────────────────── */
:root {
  --bg:        #0F0F23;
  --surface:   #16162A;
  --card:      #1E1E3A;
  --border:    #2D2D5A;
  --primary:   #7C3AED;
  --primary-l: #9B5CF6;
  --accent:    #22D3EE;
  --accent-l:  #67E8F9;
  --green:     #10B981;
  --yellow:    #F59E0B;
  --red:       #EF4444;
  --text:      #E2E8F0;
  --muted:     #94A3B8;
  --faint:     #475569;
  --gold:      #FFD700;
  --silver:    #C0C0C0;
  --bronze:    #CD7F32;
  --radius:    12px;
  --radius-sm: 8px;
  --glow:      0 0 20px rgba(124,58,237,.45);
  --glow-a:    0 0 20px rgba(34,211,238,.35);
}

/* ─── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; scrollbar-gutter: stable; }
body {
  font-family: 'Fira Sans', 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  overflow-y: scroll;
}

/* ─── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ─── Navbar ──────────────────────────────────────────────────────────────── */
.navbar {
  position: sticky; top: 0; z-index: 100;
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 2rem;
  background: rgba(15,15,35,.92);
  border-bottom: 1px solid var(--border);
}
.navbar-brand {
  display: flex; align-items: center; gap: .6rem;
  font-family: 'Fira Code', monospace; font-size: 1.1rem; font-weight: 700;
  color: var(--text); text-decoration: none;
}
.navbar-brand .logo-ring {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; box-shadow: var(--glow);
}
.navbar-brand span { color: var(--primary); }
.nav-links { display: flex; gap: .25rem; margin-left: 1.5rem; }
.nav-links a {
  padding: .4rem .85rem; border-radius: var(--radius-sm);
  color: var(--muted); text-decoration: none; font-size: .875rem;
  border: 1px solid transparent;
  transition: background-color .2s, color .2s, border-color .2s;
}
.nav-links a:hover, .nav-links a.active {
  background: rgba(124,58,237,.18); color: var(--primary-l);
  border-color: rgba(124,58,237,.35);
}
.nav-links a.active { color: var(--accent); }
.navbar-spacer { flex: 1; }
.ws-status {
  display: flex; align-items: center; gap: .4rem;
  font-family: 'Fira Code', monospace; font-size: .75rem; color: var(--muted);
}
.ws-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--red); transition: background .3s;
}
.ws-dot.connected { background: var(--green); animation: pulse-dot 2s infinite; }
@keyframes pulse-dot { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ─── Layout ──────────────────────────────────────────────────────────────── */
.page { max-width: 1400px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }
.page-header { margin-bottom: 2rem; }
.page-title {
  font-size: 1.75rem; font-weight: 700;
  background: linear-gradient(135deg, var(--text), var(--primary-l));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.page-subtitle { color: var(--muted); margin-top: .3rem; font-size: .9rem; }

/* ─── Grid helpers ────────────────────────────────────────────────────────── */
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px,1fr)); gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px,1fr)); gap: 1.25rem; }

/* ─── Card ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem;
  transition: border-color .25s, box-shadow .25s;
}
.card:hover { border-color: rgba(124,58,237,.35); box-shadow: inset 0 0 0 1px rgba(124,58,237,.12); }
.card-title {
  font-family: 'Fira Code', monospace; font-size: .8rem; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 1rem;
}
.card-title .tag {
  display: inline-block; padding: .15rem .5rem; border-radius: 99px;
  font-size: .7rem; margin-left: .4rem;
}

/* ─── Stat card ───────────────────────────────────────────────────────────── */
.stat-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem 1.5rem;
  display: flex; flex-direction: column; gap: .3rem;
  transition: border-color .25s, box-shadow .25s;
}
.stat-card:hover { border-color: rgba(124,58,237,.35); box-shadow: inset 0 0 0 1px rgba(124,58,237,.12); }
.stat-label { font-size: .8rem; color: var(--muted); font-family: 'Fira Code', monospace; text-transform: uppercase; }
.stat-value { font-size: 2rem; font-weight: 800; font-family: 'Fira Code', monospace; line-height: 1; }
.stat-value.purple { color: var(--primary-l); }
.stat-value.cyan   { color: var(--accent); }
.stat-value.green  { color: var(--green); }
.stat-value.yellow { color: var(--yellow); }
.stat-sub  { font-size: .75rem; color: var(--faint); }

/* ─── Table ───────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead { background: var(--surface); position: sticky; top: 0; }
th {
  padding: .75rem 1rem; text-align: left; white-space: nowrap;
  color: var(--muted); font-family: 'Fira Code', monospace;
  font-size: .75rem; text-transform: uppercase; letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
}
td { padding: .75rem 1rem; border-bottom: 1px solid rgba(45,45,90,.5); }
tr:last-child td { border-bottom: none; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: rgba(124,58,237,.07); }
.rank-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  font-family: 'Fira Code', monospace; font-size: .8rem; font-weight: 700;
}
.rank-1 { background: linear-gradient(135deg,#FFD700,#FFA500); color: #000; }
.rank-2 { background: linear-gradient(135deg,#C0C0C0,#A8A8A8); color: #000; }
.rank-3 { background: linear-gradient(135deg,#CD7F32,#A0522D); color: #fff; }
.rank-n { background: var(--surface); color: var(--muted); }
.score-mono { font-family: 'Fira Code', monospace; font-weight: 700; color: var(--accent); }
.player-cell { display: flex; align-items: center; gap: .6rem; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; color: #fff; flex-shrink: 0;
}

/* ─── Tabs ────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; }
.tab-btn {
  padding: .5rem 1.1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--card);
  color: var(--muted); cursor: pointer; font-size: .875rem;
  transition: all .2s;
}
.tab-btn:hover, .tab-btn.active {
  background: rgba(124,58,237,.2); border-color: var(--primary);
  color: var(--primary-l);
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.25rem; border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 600; cursor: pointer;
  border: none; transition: all .2s; text-decoration: none;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-l); }
.btn-accent   { background: rgba(34,211,238,.15); color: var(--accent); border: 1px solid rgba(34,211,238,.3); }
.btn-accent:hover   { background: rgba(34,211,238,.25); }
.btn-danger   { background: rgba(239,68,68,.15); color: var(--red); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover   { background: rgba(239,68,68,.25); }
.btn-ghost    { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover    { border-color: var(--primary); color: var(--primary-l); }
.btn-sm { padding: .35rem .8rem; font-size: .8rem; }

/* ─── Form controls ───────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .4rem; }
.form-label { font-size: .8rem; color: var(--muted); font-family: 'Fira Code', monospace; text-transform: uppercase; }
.form-control {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .65rem 1rem;
  color: var(--text); font-size: .875rem; font-family: inherit;
  transition: border-color .2s, box-shadow .2s; outline: none; width: 100%;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124,58,237,.2); }
.form-row { display: flex; gap: .75rem; align-items: flex-end; }
.form-row .form-group { flex: 1; }

/* ─── Badge / tag ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .2rem .55rem; border-radius: 99px; font-size: .72rem; font-weight: 600;
}
.badge-green  { background: rgba(16,185,129,.15); color: var(--green); }
.badge-red    { background: rgba(239,68,68,.15);  color: var(--red);  }
.badge-yellow { background: rgba(245,158,11,.15); color: var(--yellow); }
.badge-purple { background: rgba(124,58,237,.15); color: var(--primary-l); }
.badge-cyan   { background: rgba(34,211,238,.15); color: var(--accent); }

/* ─── Online dot ──────────────────────────────────────────────────────────── */
.online-dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}
.online-dot.online  { background: var(--green); animation: pulse-dot 2s infinite; }
.online-dot.offline { background: var(--faint); }

/* ─── Modal ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  backdrop-filter: blur(6px); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 2rem;
  width: min(480px, 92vw);
  transform: translateY(16px) scale(.97); transition: transform .25s;
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 1.25rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.5rem; }

/* ─── Toast ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column; gap: .5rem; z-index: 999;
}
.toast {
  padding: .8rem 1.2rem; border-radius: var(--radius-sm);
  background: var(--card); border-left: 3px solid var(--green);
  color: var(--text); font-size: .875rem;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
  animation: toast-in .25s ease; max-width: 320px;
}
.toast.error  { border-color: var(--red); }
.toast.warn   { border-color: var(--yellow); }
@keyframes toast-in { from{opacity:0;transform:translateX(20px)} to{opacity:1;transform:translateX(0)} }

/* ─── Pagination ──────────────────────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: .4rem; justify-content: center; margin-top: 1.25rem; }
.page-btn {
  padding: .4rem .75rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--card);
  color: var(--muted); cursor: pointer; font-size: .8rem; transition: all .2s;
}
.page-btn:hover, .page-btn.active { background: rgba(124,58,237,.2); border-color: var(--primary); color: var(--primary-l); }
.page-btn:disabled { opacity: .35; cursor: default; }
.page-info { font-size: .8rem; color: var(--muted); font-family: 'Fira Code', monospace; }

/* ─── Search ──────────────────────────────────────────────────────────────── */
.search-wrap { position: relative; max-width: 280px; }
.search-wrap .form-control { padding-left: 2.25rem; }
.search-icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }

/* ─── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 3rem 1rem; color: var(--muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .75rem; opacity: .4; }
.empty-state p { font-size: .875rem; }

/* ─── Utility ─────────────────────────────────────────────────────────────── */
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-2 { gap: 1rem; }
.flex  { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }
.mono { font-family: 'Fira Code', monospace; font-size: .85em; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-muted { color: var(--muted); }
.text-xs { font-size: .75rem; }
.text-sm { font-size: .875rem; }

/* ─── Animations ──────────────────────────────────────────────────────────── */
@keyframes fade-in { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:translateY(0)} }
.fade-in { animation: fade-in .3s ease forwards; }

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .navbar { padding: .6rem 1rem; }
  .nav-links a { padding: .35rem .6rem; font-size: .8rem; }
  .page { padding: 1.25rem 1rem 3rem; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr 1fr; }
  .form-row { flex-direction: column; }
}
@media (max-width: 480px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}
