/* ─ Reset ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
}
button { font-family: inherit; }
input { font-family: inherit; }

/* ─ Theme ───────────────────────────────────────── */
:root {
  --bg: #0a0b11;
  --bg-2: #12131b;
  --surface: #181a24;
  --surface-2: #1e2130;
  --surface-hover: #252939;
  --border: #262a3b;
  --border-light: #2f3447;

  --fg: #e8eaf2;
  --fg-dim: #9ca3b4;
  --fg-muted: #6b7186;

  --accent: #8b5cf6;
  --accent-2: #d946ef;
  --accent-glow: rgba(139, 92, 246, 0.15);

  --gold: #fbbf24;
  --silver: #cbd5e1;
  --bronze: #d97706;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
}

/* ─ Layout ──────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ─ Header ──────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(10, 11, 17, 0.8);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 20px;
  padding-bottom: 20px;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 24px var(--accent-glow);
  flex-shrink: 0;
}
.brand-text h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.02em;
}
.brand-sub {
  font-size: 12px;
  color: var(--fg-dim);
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}
.updated {
  color: var(--fg-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* ─ Button ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-light);
}
.btn:active { transform: scale(0.97); }
.btn.refreshing svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─ Toolbar ─────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 28px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.search-wrap {
  position: relative;
  flex: 1;
  min-width: 240px;
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg-muted);
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 11px 14px 11px 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#search::placeholder { color: var(--fg-muted); }
#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.stats-summary {
  display: flex;
  gap: 18px;
  font-size: 13px;
  color: var(--fg-dim);
}
.stats-summary span strong {
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  margin-right: 4px;
}

/* ─ Ranking List ────────────────────────────────── */
.ranking-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 40px;
}

.rank-row {
  display: grid;
  grid-template-columns: 64px 1fr 200px 180px;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s ease, transform 0.15s ease, background 0.15s ease;
}
.rank-row:hover {
  border-color: var(--border-light);
  background: var(--surface-2);
}

/* Top 3 highlight */
.rank-row.rank-1 {
  border-color: rgba(251, 191, 36, 0.35);
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.06), var(--surface) 40%);
}
.rank-row.rank-2 {
  border-color: rgba(203, 213, 225, 0.3);
  background: linear-gradient(90deg, rgba(203, 213, 225, 0.04), var(--surface) 40%);
}
.rank-row.rank-3 {
  border-color: rgba(217, 119, 6, 0.3);
  background: linear-gradient(90deg, rgba(217, 119, 6, 0.04), var(--surface) 40%);
}

/* Rank badge */
.rank-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--fg-dim);
  font-weight: 700;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}
.rank-1 .rank-badge {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #1a1305;
  box-shadow: 0 6px 18px rgba(251, 191, 36, 0.25);
}
.rank-2 .rank-badge {
  background: linear-gradient(135deg, #e5e7eb, #9ca3af);
  color: #0f1218;
}
.rank-3 .rank-badge {
  background: linear-gradient(135deg, #d97706, #92400e);
  color: #fff;
}

/* Profile */
.profile {
  min-width: 0;
}
.profile-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.profile-name .name-text {
  color: var(--fg);
}
.profile-name .user-id {
  color: var(--fg-muted);
  font-weight: 400;
  font-size: 12px;
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
  opacity: 0.6;
}
.profile-twitter {
  font-size: 12px;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-twitter a {
  color: var(--fg-muted);
  text-decoration: none;
  transition: color 0.15s ease;
}
.profile-twitter a:hover { color: var(--accent); }

/* Tier */
.tier {
  text-align: right;
}
.tier-name {
  font-size: 12px;
  color: var(--fg-dim);
  margin-bottom: 2px;
}
.tier-point {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.rank-1 .tier-point { color: var(--gold); }

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 10px;
  justify-content: end;
  font-size: 11px;
  color: var(--fg-muted);
  text-align: center;
}
.stat {
  min-width: 36px;
}
.stat-label {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
  color: var(--fg-muted);
  margin-bottom: 2px;
}
.stat-value {
  color: var(--fg-dim);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}
.stat.win .stat-value { color: #4ade80; }
.stat.lose .stat-value { color: #f87171; }
.stat.draw .stat-value { color: #94a3b8; }
.stat.streak .stat-value { color: var(--accent-2); }

/* ─ Loading / Empty / Error ──────────────────────── */
.loading, .empty, .error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  color: var(--fg-dim);
  gap: 16px;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.error { color: #f87171; }
.empty-icon {
  width: 48px;
  height: 48px;
  color: var(--fg-muted);
}

/* ─ Footer ──────────────────────────────────────── */
.footer {
  padding: 24px 0 40px;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}
.footer p {
  font-size: 12px;
  color: var(--fg-muted);
  text-align: center;
  margin: 0;
}

/* ─ Responsive ──────────────────────────────────── */
@media (max-width: 820px) {
  .rank-row {
    grid-template-columns: 52px 1fr auto;
    grid-template-rows: auto auto;
    gap: 10px 14px;
    padding: 14px 16px;
  }
  .rank-badge {
    width: 40px;
    height: 40px;
    font-size: 15px;
    grid-row: span 2;
  }
  .profile { grid-column: 2; }
  .tier {
    grid-column: 3;
    grid-row: 1;
  }
  .stats {
    grid-column: 2 / 4;
    grid-row: 2;
    justify-content: start;
    padding-top: 4px;
    border-top: 1px solid var(--border);
  }
}
@media (max-width: 520px) {
  .brand-text h1 { font-size: 16px; }
  .brand-sub { font-size: 10px; }
  .header-meta .btn span { display: none; }
  .header-meta .btn {
    padding: 9px;
    width: 36px;
    height: 36px;
    justify-content: center;
  }
  .updated { font-size: 12px; }
  .profile-name { font-size: 14px; }
  .tier-point { font-size: 16px; }
  .stats-summary { width: 100%; justify-content: space-between; }
}
