:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e1ec;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --warn: #b45309;
  --bad: #b91c1c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 "Inter", "Segoe UI", "Microsoft YaHei", sans-serif;
}

button,
input,
select {
  font: inherit;
}

#app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  background: #111827;
  color: #f8fafc;
  padding: 24px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid #374151;
  background: #0f766e;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
}

.brand p,
.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.sidebar .brand p {
  color: #9ca3af;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item,
.icon-btn,
.toolbar button,
.pager button,
.ghost-btn,
.link-btn {
  border: 1px solid transparent;
  cursor: pointer;
}

.nav-item {
  width: 100%;
  padding: 11px 12px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: #1f2937;
  color: #fff;
  border-color: #374151;
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.topbar h2 {
  margin: 2px 0 0;
  font-size: 28px;
  letter-spacing: 0;
}

.icon-btn {
  width: 40px;
  height: 40px;
  background: var(--panel);
  border-color: var(--line);
  font-size: 20px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
}

.stat {
  padding: 16px;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
}

.talent-panel {
  margin-bottom: 16px;
}

.dashboard-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.dashboard-split .talent-panel {
  margin-bottom: 0;
}

.talent-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
}

.talent-stat {
  border: 1px solid var(--line);
  background: #f8fafc;
  padding: 13px;
}

.talent-stat span,
.talent-stat small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.talent-stat strong {
  display: block;
  margin: 6px 0 2px;
  font-size: 23px;
}

.distribution-list {
  display: grid;
  gap: 0;
}

.two-col,
.single-col {
  display: grid;
  gap: 16px;
}

.two-col {
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
}

.panel {
  padding: 16px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.panel h3 {
  margin: 0;
  font-size: 16px;
}

.run-card {
  display: grid;
  gap: 10px;
}

.run-line,
.mini-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 9px 0;
}

.run-line:last-child,
.mini-row:last-child {
  border-bottom: 0;
}

.toolbar {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.player-toolbar {
  grid-template-columns:
    minmax(150px, 1.1fr)
    minmax(150px, 1fr)
    minmax(130px, 0.9fr)
    minmax(110px, 0.7fr)
    minmax(120px, 0.8fr)
    minmax(120px, 0.8fr)
    82px
    82px;
}

.clan-toolbar {
  grid-template-columns: minmax(220px, 1fr) 90px 90px;
}

.toolbar input,
.toolbar select {
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 0 10px;
}

.toolbar button,
.pager button {
  height: 38px;
  background: var(--accent);
  color: #fff;
}

.toolbar .secondary-btn {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.arena-summary {
  display: none;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.arena-summary.active {
  display: grid;
}

.arena-summary div {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 11px 12px;
}

.arena-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.arena-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 17px;
}

.arena-summary small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.rank-link,
.rank-line {
  display: block;
  margin-top: 4px;
  font: inherit;
  font-weight: 800;
}

.rank-link {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-2);
  cursor: pointer;
}

.rank-line {
  color: var(--ink);
  font-style: normal;
}

.ranking-panel {
  display: none;
  margin-bottom: 12px;
}

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

.ranking-table {
  overflow: auto;
  max-height: 360px;
}

.ranking-table table {
  min-width: 760px;
}

.ghost-btn {
  height: 38px;
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
  padding: 0 12px;
}

.link-btn {
  background: transparent;
  color: var(--accent-2);
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 700;
  text-align: left;
}

.arena-group-link {
  margin-left: 4px;
}

.detail-head {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}

.detail-head h3 {
  margin: 0 0 3px;
  font-size: 18px;
}

.pager button:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--panel);
  max-height: calc(100vh - 210px);
}

table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef3f8;
  color: #344054;
  font-weight: 700;
}

.sort-btn {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  text-align: left;
  padding: 0;
}

#clans-view table {
  table-layout: fixed;
}

#clans-view .col-rank {
  width: 86px;
}

#clans-view .col-id {
  width: 92px;
}

#clans-view .col-clan-name {
  width: 150px;
  max-width: 150px;
}

#clans-view .col-count {
  width: 64px;
}

#clans-view .col-leader {
  width: 180px;
  max-width: 180px;
}

#clans-view td.col-leader {
  overflow: hidden;
  text-overflow: ellipsis;
}

.truncate {
  display: inline-block;
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

.truncate-clan {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sort-btn::after {
  content: "↕";
  margin-left: 6px;
  color: #94a3b8;
  font-size: 11px;
}

.sort-btn.active.asc::after {
  content: "↑";
  color: var(--accent);
}

.sort-btn.active.desc::after {
  content: "↓";
  color: var(--accent);
}

tbody tr:hover {
  background: #f8fafc;
}


.num {
  font-variant-numeric: tabular-nums;
}

.rank-col {
  color: var(--muted);
  font-weight: 700;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  background: #e0f2fe;
  color: #075985;
  border: 1px solid #bae6fd;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.pager button {
  min-width: 38px;
  padding: 0 10px;
}

.pager .page-num {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.pager .page-num.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.pager-ellipsis,
.pager-total {
  display: inline-flex;
  align-items: center;
  height: 38px;
  color: var(--muted);
}

.pager-jump {
  width: 76px;
  height: 38px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 0 8px;
}

@media (max-width: 980px) {
  #app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding: 14px;
  }

  .nav {
    grid-template-columns: repeat(4, 1fr);
  }

  .brand {
    margin-bottom: 14px;
  }

  .stats-grid,
  .talent-grid,
  .arena-summary,
  .dashboard-split,
  .two-col,
  .toolbar,
  .player-toolbar,
  .clan-toolbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1380px) {
  .player-toolbar {
    grid-template-columns: repeat(4, minmax(130px, 1fr));
  }

  .player-toolbar button {
    min-width: 82px;
  }
}
