*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg2: #161b27;
  --bg3: #1e2535;
  --border: #2a3147;
  --accent: #ff4655;
  --accent2: #7b5ea7;
  --text: #e8eaf0;
  --text-muted: #8892a4;
  --green: #4ade80;
  --red: #f87171;
  --gold: #fbbf24;
  --radius: 10px;
}

body {
  font-family: 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Header ── */
header {
  background: linear-gradient(135deg, #1a0a0c 0%, #0f1117 60%);
  border-bottom: 2px solid var(--accent);
  padding: 20px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

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

.header-title h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fff;
}

.header-title h1 span { color: var(--accent); }

.header-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.header-meta strong { color: var(--text); }

.header-refresh-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-update-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}

.header-update-hint {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.7;
}

.header-update-hint code {
  background: var(--bg3);
  border-radius: 3px;
  padding: 0 4px;
  font-family: monospace;
  font-size: 10px;
  color: var(--accent);
}

#refresh-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}

#refresh-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.v-logo {
  width: 38px;
  height: 38px;
  background: var(--accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  letter-spacing: -2px;
}

/* ── Main layout ── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ── Section cards ── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.card-header h2 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
}

/* ── Controls row ── */
.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

input[type="text"],
select {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}

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

input[type="text"]::placeholder { color: var(--text-muted); }

#search-input { width: 220px; }

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

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
  font-size: 13px;
}

thead th {
  padding: 11px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  position: relative;
  white-space: nowrap;
}

thead th:hover { color: var(--text); background: var(--bg3); }

thead th.sorted-asc::after { content: " ▲"; color: var(--accent); }
thead th.sorted-desc::after { content: " ▼"; color: var(--accent); }

tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}

tbody tr:hover { background: var(--bg3); }
tbody tr.active { background: rgba(255,70,85,.08); border-left: 3px solid var(--accent); }

tbody td {
  padding: 10px 12px;
  color: var(--text);
}

.player-name-cell {
  display: flex;
  flex-direction: column;
}

.player-name-cell .p-name {
  font-weight: 700;
  color: #fff;
}

.player-name-cell .p-team {
  font-size: 11px;
  color: var(--text-muted);
}

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
}

.role-Duelist   { background: rgba(255,70,85,.18); color: #ff8a93; }
.role-Initiator { background: rgba(123,94,167,.18); color: #b09fd8; }
.role-Controller{ background: rgba(59,130,246,.18); color: #93c5fd; }
.role-Sentinel  { background: rgba(251,191,36,.18); color: #fde68a; }
.role-Unknown   { background: var(--bg3); color: var(--text-muted); }

.agent-chip {
  display: inline-block;
  background: var(--bg3);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
  color: var(--text-muted);
  margin-right: 2px;
}

.stat-val { font-variant-numeric: tabular-nums; }

.no-results {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Player Profile ── */
#profile-section { display: none; }

.profile-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
}

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

.profile-left {
  border-right: 1px solid var(--border);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.profile-right {
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Player identity */
.player-identity { display: flex; flex-direction: column; gap: 6px; }

.player-identity .p-name {
  font-size: 26px;
  font-weight: 900;
  color: #fff;
  letter-spacing: .5px;
}

.player-identity .p-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.archetype-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  background: linear-gradient(90deg, var(--accent), #ff8a93);
  color: #fff;
}

/* Strength bars */
.strength-bars { display: flex; flex-direction: column; gap: 10px; }

.strength-bars h3 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.score-label {
  width: 90px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}

.score-bar-bg {
  flex: 1;
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
}

.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .4s ease;
}

.bar-firepower { background: linear-gradient(90deg, #ff4655, #ff8a45); }
.bar-entry     { background: linear-gradient(90deg, #7b5ea7, #b09fd8); }
.bar-survival  { background: linear-gradient(90deg, #3b82f6, #93c5fd); }
.bar-clutch    { background: linear-gradient(90deg, #fbbf24, #fde68a); }
.bar-teamplay  { background: linear-gradient(90deg, #4ade80, #a7f3d0); }

.score-num {
  width: 32px;
  text-align: right;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

/* Radar chart */
.chart-wrap {
  position: relative;
  max-width: 300px;
  margin: 0 auto;
}

/* AI Summary */
.ai-summary {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
}

.ai-summary .section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.ai-summary ul {
  padding-left: 16px;
  margin: 4px 0 12px;
}

.ai-summary li { margin-bottom: 2px; }

.ai-summary .summary-text {
  color: var(--text-muted);
  font-style: italic;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 8px;
}

/* Role benchmark */
.benchmark-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.benchmark-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.benchmark-item .b-stat {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
}

.benchmark-item .b-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
}

.benchmark-item .b-delta {
  font-size: 12px;
  font-weight: 700;
}

.b-delta.positive { color: var(--green); }
.b-delta.negative { color: var(--red); }
.b-delta.neutral  { color: var(--text-muted); }

/* Stat details grid */
.stats-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}

.stat-box {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-box .s-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
}

.stat-box .s-val {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
}

/* ── Comparison section ── */
#comparison-section { display: none; }

.comparison-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.comparison-controls select { flex: 1; min-width: 160px; max-width: 260px; }

.vs-divider {
  font-size: 18px;
  font-weight: 900;
  color: var(--text-muted);
}

.comparison-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0;
  align-items: start;
}

.comparison-player {
  padding: 20px;
}

.comparison-player .cp-name {
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  margin-bottom: 4px;
}

.comparison-player .cp-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.comparison-vs-col {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.comparison-row {
  display: flex;
  align-items: center;
}

.cmp-val-a, .cmp-val-b {
  flex: 1;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cmp-val-a { text-align: right; }
.cmp-val-b { text-align: left; }

.cmp-stat-label {
  width: 80px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  padding: 9px 4px;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-top: 1px solid var(--border);
}

.cmp-val-a.winner, .cmp-val-b.winner { color: var(--green); }
.cmp-val-a.loser,  .cmp-val-b.loser  { color: var(--red); }

.cmp-comparison-row {
  display: grid;
  grid-template-columns: 1fr 80px 1fr;
  border-top: 1px solid var(--border);
}

.cmp-comparison-row:last-child { border-bottom: 1px solid var(--border); }

.comparison-radar-wrap {
  padding: 20px;
  display: flex;
  justify-content: center;
}

.cmp-summary {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.7;
  font-style: italic;
}

/* Subheadings inside profile */
.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

/* ── Modal ── */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.80);
  backdrop-filter: blur(5px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 980px;
  max-height: 92vh;
  overflow-y: auto;
  position: relative;
}

/* Modal header */
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.modal-header-left { display: flex; flex-direction: column; gap: 8px; }

.modal-player-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-player-name {
  font-size: 28px;
  font-weight: 900;
  color: #fff;
  letter-spacing: .5px;
  line-height: 1.1;
}

.vlr-profile-link {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid rgba(255,70,85,0.35);
  border-radius: 4px;
  padding: 3px 8px;
  transition: background .12s;
  white-space: nowrap;
}
.vlr-profile-link:hover { background: rgba(255,70,85,0.14); }

.modal-player-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-archetype-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-archetype-badge {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #fff;
}

.modal-archetype-sub {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.modal-role-focus {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.4px;
  margin-top: 4px;
}

.modal-close-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 18px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .12s, color .12s;
}
.modal-close-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Modal body — two-column top section */
.modal-body-top {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 0;
  border-bottom: 1px solid var(--border);
}

@media (max-width: 860px) {
  .modal-body-top { grid-template-columns: 1fr; }
}

.modal-radar-col {
  padding: 24px 20px;
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-radar-col canvas {
  width: 380px !important;
  height: 380px !important;
}

.modal-right-col {
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Summary text — prominent, at the top of right col */
.modal-summary-text {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.75;
  color: var(--text);
}

.modal-summary-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2px 0;
}

.modal-summary-zh {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.8;
}

.modal-strengths-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.modal-strengths-block { display: flex; flex-direction: column; gap: 4px; }

.modal-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.modal-strengths-block ul {
  padding-left: 14px;
  margin: 0;
}

.modal-strengths-block li {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 2px;
}

/* Modal bottom section */
.modal-body-bottom {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Highlights ── */
.hl-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.hl-top5 { display: flex; flex-direction: column; gap: 6px; }

.hl-rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.hl-rank-row:hover { border-color: var(--accent); background: #1e2638; }

.hl-rank-num {
  width: 28px;
  font-size: 13px;
  font-weight: 900;
  color: var(--text-muted);
  flex-shrink: 0;
}
.hl-rank-num.gold   { color: #fbbf24; }
.hl-rank-num.silver { color: #94a3b8; }
.hl-rank-num.bronze { color: #c2843a; }

.hl-rank-name { flex: 1; font-weight: 700; color: #fff; font-size: 14px; }
.hl-rank-team { font-size: 12px; color: var(--text-muted); width: 40px; }
.hl-rank-acs  { font-size: 17px; font-weight: 900; color: var(--accent); min-width: 42px; text-align: right; }

.hl-role-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
@media (max-width: 700px) { .hl-role-grid { grid-template-columns: 1fr 1fr; } }

.hl-role-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hl-role-card:hover { border-color: var(--accent); background: #1e2638; }

.hl-role-card .hl-card-acs {
  font-size: 30px;
  font-weight: 900;
  color: #fff;
  line-height: 1.1;
  margin-top: 4px;
}
.hl-role-card .hl-card-name { font-size: 15px; font-weight: 700; color: var(--text); }
.hl-role-card .hl-card-team { font-size: 11px; color: var(--text-muted); }

.hl-worst-card {
  background: rgba(248,113,113,0.06);
  border: 1px solid rgba(248,113,113,0.25);
  border-radius: 10px;
  padding: 16px 20px;
  cursor: pointer;
  transition: border-color .12s;
  display: flex;
  align-items: center;
  gap: 20px;
}
.hl-worst-card:hover { border-color: var(--red); }

.hl-worst-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--red);
  margin-bottom: 5px;
}
.hl-worst-name { font-size: 22px; font-weight: 900; color: #fff; }
.hl-worst-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.hl-worst-acs  {
  font-size: 40px;
  font-weight: 900;
  color: var(--red);
  margin-left: auto;
  opacity: 0.8;
  flex-shrink: 0;
}

/* ── Summary loading spinner ── */
.modal-summary-loading {
  color: var(--text-muted);
  font-size: 14px;
  font-style: italic;
  padding: 8px 0 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-summary-loading::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a4560; }
